Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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