Subversion Repositories Kolibri OS

Rev

Rev 109 | Rev 6224 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;
2
;   MENU EXAMPLE
3
;
4
;   Compile with FASM for Menuet
5
;
6
 
7
  use32
8
  org    0x0
9
 
10
  db     'MENUET01'    ; 8 byte id
11
  dd     0x01          ; header version
12
  dd     START         ; start of code
13
  dd     I_END         ; size of image
14
  dd     0x1000        ; memory for app
15
  dd     0x1000        ; esp
16
  dd     0x0 , 0x0     ; I_Param , I_Icon
17
 
18
include  'lang.inc'
485 heavyiron 19
include  '..\..\..\..\macros.inc'
31 halyavin 20
 
21
START:                             ; start of execution
22
 
485 heavyiron 23
  red:
31 halyavin 24
    call draw_window               ; draw window
25
    call clear_data                ; clear status bar
26
 
27
still:
28
 
29
    mov  eax,10                    ; wait here for event
485 heavyiron 30
    mcall                      ; do it
31 halyavin 31
 
32
    cmp  eax,1                     ; redraw request ?
485 heavyiron 33
    jz   red                       ; yes jump to it
31 halyavin 34
    cmp  eax,2                     ; key in buffer ?
485 heavyiron 35
    jnz   button
31 halyavin 36
 
37
  key:                             ; key
38
    mov  eax,2                     ; just read it and ignore
485 heavyiron 39
    mcall                      ; do it
31 halyavin 40
    jmp  still                     ; start again
41
 
42
  button:                          ; button
43
    mov  eax,17                    ; get id
485 heavyiron 44
    mcall                      ; do it
31 halyavin 45
 
46
    cmp  ah,1                      ; is it the close button
47
    jne  noclose                   ; no then jump code
485 heavyiron 48
    or   eax,-1                    ; close this program
49
    mcall                      ; do it
31 halyavin 50
noclose:
51
 
52
    cmp  ah,100                    ; is it main menu
53
    jb   not_menu                  ; no then jump code
54
    cmp  ah,104                    ; is it main menu
55
    ja   not_menu                  ; no then jump code
56
    call draw_window               ; redraw window
57
    call clear_data                ; clear status info
58
    call draw_data                 ; update status info
59
    call write_sub                 ; draw a sub menu
60
    jmp  still                     ; start again
61
not_menu:
62
 
63
    cmp  ah,110                    ; is it a sub menu
64
    jb   not_sub                   ; no then jump code
65
    cmp  ah,145                    ; is it a sub menu
66
    ja   not_sub                   ; no then jump code
67
    call draw_window               ; redraw window
68
    call clear_data                ; clear status info
69
    mov  [button_press],1          ; sub button pressed
70
    call draw_data                 ; update status info
71
    mov  [button_press],0          ; clear pressed
72
    jmp  still                     ; start again
73
not_sub:
74
 
75
    jmp  still                     ; start again
76
 
77
 
78
;   *********************************************
79
;   *******  WINDOW DEFINITIONS AND DRAW ********
80
;   *********************************************
81
 
82
draw_window:
83
 
84
    push eax                       ; save register
85
 
86
    mov  eax,12                    ; function 12: tell os about windowdraw
87
    mov  ebx,1                     ; 1, start of draw
485 heavyiron 88
    mcall                      ; do it
31 halyavin 89
 
90
    mov  eax,0                     ; function 0: define and draw window
91
    mov  ebx,50*65536              ; [x start] *65536
92
    add  ebx,[x_size]              ; add [x size]
93
    mov  ecx,50*65536              ; [y start] *65536
94
    add  ecx,[y_size]              ; add [y size]
95
    mov  edx,0x80ffffff            ; colour of work area RRGGBB
96
    mov  esi,0x806688dd            ; grab bar colour. negative glide
485 heavyiron 97
    mcall                      ; do it
31 halyavin 98
 
99
    mov  eax,4                     ; function 4: write text to window
100
    mov  ebx,6*65536+7             ; [x start] *65536 + [y start]
101
    mov  ecx,0x00ffffff            ; text colour
102
    mov  edx,window_text           ; pointer to text beginning
103
    mov  esi,12                    ; text length
485 heavyiron 104
    mcall                      ; do it
31 halyavin 105
 
106
    mov  eax,8                     ; function 8: define and draw button
107
    mov  ebx,(381-18)*65536+13     ; [x start] *65536 + [x size]
108
    mov  ecx,4*65536+13            ; [y start] *65536 + [y size]
109
    mov  edx,1                     ; button id
110
    mov  esi,0x6688dd              ; button color RRGGBB
485 heavyiron 111
    mcall                      ; do it
31 halyavin 112
 
113
    mov  eax,13                    ; function 13: draw bar
114
    mov  ebx,1*65536               ; [x start] *65536
115
    add  ebx,[x_size]              ; add [x size]
116
    dec  ebx                       ; x size - 1
117
    mov  ecx,[y_size]              ; [y start] *65536
118
    sub  ecx,17                    ; minus height
119
    shl  ecx,16                    ; *65536
120
    add  ecx,17                    ; add height
121
    mov  edx,0x006688dd            ; bar colour
485 heavyiron 122
    mcall                      ; do it
31 halyavin 123
 
124
    mov  eax,4                     ; function 4 : write text to window
125
    mov  ebx,5*65536               ; [x start] *65536
126
    add  ebx,[y_size]              ; add [y start]
127
    sub  ebx,12                    ; move up
128
    xor  ecx,ecx                   ; text colour
129
    mov  edx,button_no             ; pointer to text beginning
130
    mov  esi,14                    ; text length
485 heavyiron 131
    mcall                      ; do it
31 halyavin 132
 
133
    add  ebx,95*65536              ; move xy position
134
    mov  edx,menu_text             ; pointer to text beginning
485 heavyiron 135
    mcall                      ; do it
31 halyavin 136
 
137
    call write_main                ; draw menu
138
 
139
    mov  eax,12                    ; function 12: tell os about windowdraw
140
    mov  ebx,2                     ; 2, end of draw
485 heavyiron 141
    mcall                      ; do it
31 halyavin 142
 
143
    pop  eax                       ; restore register
144
    ret                            ; return
145
 
146
 ; ************* WRITE MAIN *************
147
 
148
write_main:
149
 
150
    mov  eax,13                    ; function 13: draw bar
151
    mov  ebx,1*65536               ; [x start] *65536
152
    add  ebx,[x_size]              ; +[x_size]
153
    dec  ebx                       ; x size - 1
154
    mov  ecx,21*65536+17           ; [y start] *65536 +[y size]
155
    mov  edx,[menu_colour]         ; menu colour
485 heavyiron 156
    mcall                      ; do it
31 halyavin 157
 
158
    mov  [main_pos],1              ; start position first button
159
    xor  edi,edi                   ; data offset = 0
160
 
161
next_main_item:
162
    mov  al,[MENU_DATA+edi]        ; get byte at menu_data + offset
163
    cmp  al,'E'                    ; is it the END
164
    je   main_get_out              ; yes then exit
165
    cmp  al,'0'                    ; is it a main menu item
166
    jne  not_main_menu             ; no then jump code
167
 
168
main_menu:
169
    mov  al,[MENU_DATA+edi+1]      ; get byte at menu_data + offset + 1
170
    cmp  al,'0'                    ; is it a divider
171
    je   is_main_bar               ; yes then jump code
172
    mov  eax,8                     ; function 8: define button
173
    mov  ebx,[main_pos]            ; [x start]
174
    shl  ebx,16                    ; *65536
175
    add  bl,75                     ; +[x size]
176
    mov  ecx,21*65536+16           ; [y start] *65536 +[y size]
177
    xor  edx,edx                   ; clear register
178
    mov  dl,[MENU_DATA+edi+2]      ; get byte button id number
179
    mov  esi,[menu_colour]         ; button colour
485 heavyiron 180
    mcall                      ; do it
31 halyavin 181
    mov  eax,4                     ; function 4: write text to window
182
    add  ebx,6*65536-49            ; move xy position
183
    xor  ecx,ecx                   ; text colour
184
    mov  edx,MENU_DATA+3           ; point at menu text
185
    add  edx,edi                   ; add our offset
186
    mov  esi,11                    ; number of characters
485 heavyiron 187
    mcall                      ; do it
31 halyavin 188
 
189
is_main_bar:
190
    add  [main_pos],76             ; update button position
191
 
192
not_main_menu:
193
    add  edi,14                    ; update offset
194
    jmp  next_main_item            ; do next menu item
195
 
196
main_get_out:
197
 
198
    ret                            ; return
199
 
200
; *********** DRAW DATA ***********
201
 
202
draw_data:
203
 
204
    push eax                       ; save register
205
    mov  ebx,0x00030000            ; display 3 decimal characters
206
    xor  ecx,ecx                   ; clear register
207
    mov  cl,ah                     ; swap data
208
    mov  eax,47                    ; function 47: display number to window
209
    mov  edx,70*65536              ; [x start] *65536
210
    add  edx,[y_size]              ; +[y start]
211
    sub  edx,12                    ; move position
212
    xor  esi,esi                   ; text colour
485 heavyiron 213
    mcall                      ; do it
31 halyavin 214
    pop  eax                       ; restore register
215
 
216
    cmp  [button_press],1          ; has a sub button been pressed
217
    je   draw_get_out              ; then jump code
218
 
219
    push eax                       ; save register
220
    xor  edx,edx                   ; clear register
221
    shr  ax,8                      ; move button id into al
222
    sub  eax,100                   ; subtract 100
223
    mov  dx,14                     ; use record length as multiplier
224
    mul  dx                        ; multiply
225
    mov  edx,eax                   ; swap registers
226
    add  edx,MENU_DATA             ; add offset
227
    inc  edx                       ; add 1
228
    mov  ebx,188*65536             ; [x start] *65536
229
    add  ebx,[y_size]              ; +[y start]
230
    sub  ebx,12                    ; move position
231
    mov  esi,1                     ; 1 character
232
    mov  eax,4                     ; function 4: write text to window
233
    xor  ecx,ecx                   ; text colour
485 heavyiron 234
    mcall                      ; do it
31 halyavin 235
    pop  eax                       ; restore register
236
 
237
draw_get_out:
238
    ret                            ; return
239
 
240
; **************** CLEAR DATA ******************
241
 
242
clear_data:
243
 
244
    push eax                       ; save register
245
    mov  eax,13                    ; function 13: draw bar
246
    mov  ebx,67*65536+23           ; [x start] *65536 +[x size]
247
    mov  ecx,[y_size]              ; [y start]
248
    sub  ecx,15                    ; move position
249
    shl  ecx,16                    ; *65536
250
    add  ecx,13                    ; [y size]
251
    mov  edx,0x00aaaaaa            ; bar colour
485 heavyiron 252
    mcall                      ; do it
31 halyavin 253
    mov  ebx,185*65536+11          ; move position
485 heavyiron 254
    mcall                      ; do it again
31 halyavin 255
 
256
    pop  eax                       ; restore register
257
    ret                            ; return
258
 
259
 ; ************* WRITE SUB *************
260
 
261
write_sub:
262
 
263
    push eax                       ; save register
264
    mov  [but_pos],38              ; y start position offset
265
    mov  [sub_pos],1               ; x start position offset
266
    xor  edx,edx                   ; clear register
267
    shr  ax,8                      ; move button id into al
268
    sub  eax,100                   ; subtract 100
269
    mov  dx,76                     ; menu width + 1
270
    mul  dx                        ; multiply
271
    add  [sub_pos],eax             ; add menu position to offset
272
    pop  eax                       ; restore register
273
 
274
    xor  edx,edx                   ; clear register
275
    shr  ax,8                      ; move button id into al
276
    sub  eax,100                   ; subtract 100
277
    mov  dx,14                     ; use record length as multiplier
278
    mul  dx                        ; multiply
279
    add  eax,MENU_DATA             ; add offset
280
    inc  eax                       ; plus 1
281
    mov  al,[eax]                  ; get menu number byte
282
    mov  [menu_number],al          ; save it
283
 
284
    xor  edi,edi                   ; clear offset
285
 
286
next_sub_item:
287
    mov  al,[MENU_DATA+edi]        ; get byte at menu_data + offset
288
    cmp  al,'E'                    ; is it the END
289
    je   sub_get_out               ; yes then exit
290
    cmp  al,[menu_number]          ; is it sub menu item
291
    jne  not_sub_menu              ; no then jump code
292
 
293
sub_menu:
294
    mov  al,[MENU_DATA+edi+1]      ; get byte at menu_data + offset + 1
295
    cmp  al,'0'                    ; is it a divider
296
    jne  is_sub_button             ; no then jump code
297
    mov  eax,13                    ; function 13: draw bar
298
    mov  edx,[menu_colour]         ; bar colour
299
    mov  ebx,[sub_pos]             ; [x start]
300
    shl  ebx,16                    ; *65536
301
    add  ebx,76                    ; [x size]
302
    mov  ecx,[but_pos]             ; [y start]
303
    shl  ecx,16                    ; *65536
304
    add  ecx,17                    ; [y size]
485 heavyiron 305
    mcall                      ; do it
31 halyavin 306
    jmp  is_sub_bar                ; jump button code
307
 
308
is_sub_button:
309
    mov  eax,8                     ; function 8: define and draw button
310
    xor  edx,edx                   ; clear register
311
    mov  dl,[MENU_DATA+edi+2]      ; get byte button id number
312
    mov  ebx,[sub_pos]             ; [x start]
313
    shl  ebx,16                    ; *65536
314
    add  ebx,75                    ; [x size]
315
    mov  ecx,[but_pos]             ; [y start]
316
    shl  ecx,16                    ; *65536
317
    add  ecx,16                    ; [y size]
318
    mov  esi,[menu_colour]         ; button colour
485 heavyiron 319
    mcall                      ; do it
31 halyavin 320
 
321
    mov  ebx,[sub_pos]             ; [x start]
322
    shl  ebx,16                    ; *65536
323
    add  ebx,6*65536               ; move position
324
    add  ebx,[but_pos]             ; [y start]
325
    add  bl,5                      ; move position
326
    xor  ecx,ecx                   ; clear register
327
    mov  edx,MENU_DATA+3           ; point to button text
328
    add  edx,edi                   ; add offset
329
    mov  esi,11                    ; number of characters
330
    mov  eax,4                     ; function 4: write text to window
485 heavyiron 331
    mcall                      ; do it
31 halyavin 332
is_sub_bar:
333
    add  [but_pos],17              ; move y position
334
 
335
not_sub_menu:
336
    add  edi,14                    ; move offset
337
    jmp  next_sub_item             ; do next button
338
 
339
sub_get_out:
340
 
341
    ret                            ; return
342
 
343
; ***************** DATA AREA ******************
344
 
345
x_size:       dd 381               ; window x size
346
y_size:       dd 200               ; window y size
347
 
348
window_text   db 'MENU EXAMPLE'    ; grab bar text
349
button_no     db 'BUTTON No:    '  ; status bar text
350
menu_text     db 'MENU SELECTED:'  ; status bar text
351
 
352
button_press  dd 0
353
 
354
menu_colour   dd 0x00aaaaaa        ; menu & button colour
355
 
356
menu_number   db '0'               ; menu selection
357
 
358
sub_pos       dd 1                 ; sub menu x position
359
but_pos       dd 38                ; sub menu y position
360
 
361
main_pos      dd 1                 ; main menu x position
362
 
363
MENU_DATA:    db '01'              ; MAIN MENU = 0 - 1 = menu
364
              db 100               ; button id
365
              db 'FILE       '     ; button text
366
              db '02'              ; MAIN MENU = 0 - 2 = menu
367
              db 101               ; button id
368
              db 'EDIT       '     ; button text
369
              db '04'              ; MAIN MENU = 0 - 3 = menu
370
              db 102               ; button id
371
              db 'TEST       '     ; button text
372
              db '00'              ; MAIN MENU = 0 - 0 = divider
373
              db 103               ; SPACER ID
374
              db '           '     ; SPACER TEXT padding
375
              db '03'              ; MAIN MENU = 0 - 4 = menu
376
              db 104               ; button id
377
              db 'HELP       '     ; button text
378
 
379
              db '11'              ; menu level = 1 - 1 = button
380
              db 110               ; button id
381
              db 'LOAD       '     ; button text
382
              db '11'              ; menu level = 1 - 1 = button
383
              db 111               ; button id
384
              db 'SAVE       '     ; button text
385
              db '10'              ; menu level = 1 - 0 = divider
386
              db 112               ; SPACER ID
387
              db '           '     ; SPACER TEXT padding
388
              db '11'              ; menu level = 1 - 1 = button
389
              db 113               ; button id
390
              db 'QUIT       '     ; button text
391
 
392
              db '21'              ; menu level = 2 - 1 = button
393
              db 120               ; button id
394
              db 'COPY       '     ; button text
395
              db '21'              ; menu level = 2 - 1 = button
396
              db 121               ; button id
397
              db 'PASTE      '     ; button text
398
 
399
              db '31'              ; menu level = 3 - 1 = button
400
              db 130               ; button id
401
              db 'SETUP      '     ; button text
402
              db '31'              ; menu level = 3 - 1 = button
403
              db 131               ; button id
404
              db 'ABOUT..    '     ; button text
405
 
406
              db '41'              ; menu level = 3 - 1 = button
407
              db 140               ; button id
408
              db 'TEST 1     '     ; button text
409
              db '41'              ; menu level = 3 - 1 = button
410
              db 141               ; button id
411
              db 'TEST 2     '     ; button text
412
              db '41'              ; menu level = 3 - 1 = button
413
              db 142               ; button id
414
              db 'TEST 3     '     ; button text
415
              db '41'              ; menu level = 3 - 1 = button
416
              db 143               ; button id
417
              db 'TEST 4     '     ; button text
418
              db '41'              ; menu level = 3 - 1 = button
419
              db 144               ; button id
420
              db 'TEST 5     '     ; button text
421
              db '41'              ; menu level = 3 - 1 = button
422
              db 145               ; button id
423
              db 'TEST 6     '     ; button text
424
 
425
              db 'END'             ; IMPORTANT need an END
426
I_END: