Subversion Repositories Kolibri OS

Rev

Rev 7548 | Rev 7848 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;******************************************************************************
  2. ;   MAIN MENU
  3. ;******************************************************************************
  4. ; last update:  17/04/2012
  5. ; changed by:   Marat Zakiyanov aka Mario79, aka Mario
  6. ; changes:      Support for boot parameters.
  7. ;------------------------------------------------------------------------------
  8. ; last update:  22/03/2012
  9. ; changed by:   Marat Zakiyanov aka Mario79, aka Mario
  10. ; changes:      Global optimization! The program uses
  11. ;               only 32 KB of memory instead of 128 kb is now.
  12. ;------------------------------------------------------------------------------
  13. ; last update:  19/09/2011
  14. ; changed by:   Marat Zakiyanov aka Mario79, aka Mario
  15. ; changes:      Checking for program exist to memory
  16. ;               Added processing of keys: left and right arrow
  17. ;------------------------------------------------------------------------------
  18. ;   MAIN MENU by lisovin@26.ru
  19. ;   Some parts of code rewritten by Ivan Poddubny <ivan-yar@bk.ru>
  20. ;
  21. ;   Compile with FASM for Menuet
  22. ;******************************************************************************
  23.   BTN_HEIGHT  = 22
  24.   BTN_WIDTH   = 140
  25.   TXT_Y       = (BTN_HEIGHT)/2-4
  26.  
  27.   PANEL_HEIGHT  = 20
  28.   MENU_BOTTON_X_POS     = 10
  29.   MENU_BOTTON_X_SIZE    = 50
  30. ;------------------------------------------------------------------------------
  31.         use32
  32.         org 0x0
  33.  
  34.         db 'MENUET01'   ; 8 byte id
  35.         dd 0x01         ; header version
  36.         dd START        ; start of code
  37.         dd IM_END       ; size of image
  38.         dd mem_end      ; memory for app
  39.         dd stack_area   ; esp
  40.         dd bootparam    ; boot parameters
  41.         dd 0x0          ; path
  42. ;------------------------------------------------------------------------------
  43. include "..\..\..\macros.inc"
  44. include "..\..\..\gui_patterns.inc"
  45. ;include "../../../debug.inc"             ; debug macros
  46. ;------------------------------------------------------------------------------
  47. align 4
  48. conversion_ASCII_to_HEX:
  49.         xor     ebx,ebx
  50.         cld
  51.         lodsd
  52.         mov     ecx,4
  53. ;--------------------------------------
  54. align 4
  55. .loop:
  56.         cmp     al,0x60 ; check for ABCDEF
  57.         ja      @f
  58.         sub     al,0x30 ; 0-9
  59.         jmp     .store
  60. ;--------------------------------------
  61. align 4
  62. @@:
  63.         sub     al,0x57 ; A-F
  64. ;--------------------------------------
  65. align 4
  66. .store:
  67.         and     al,0xf
  68.         rol     ebx,4
  69.         add     bl,al
  70.         ror     eax,8
  71.         dec     ecx
  72.         jnz     .loop
  73.  
  74.         ret
  75. ;------------------------------------------------------------------------------
  76. align 4
  77. START:                 ; start of execution
  78.         mcall   68,11
  79.  
  80.         mov     esi,bootparam  
  81.         cmp     [esi],byte 0
  82.         je      .no_boot_parameters
  83. ; boot params - hex
  84. ; db '9999'     ; +0    Menu button X
  85. ; db '9999'     ; +4    Menu button X size
  86. ; db '9999'     ; +8    Menu button Y
  87. ; db '9999'     ; +12   Menu button Y size
  88. ; db '9999'     ; +16   Panel height
  89. ; db '1000'     ; +20   Panel attachment
  90.  
  91. ;       mov     edx,bootparam
  92. ;       call    debug_outstr
  93. ;       newline
  94.  
  95.         call    conversion_ASCII_to_HEX
  96.         mov     [menu_button_x.start],ebx
  97.        
  98. ;       dps     "menu_button_x.start: "
  99. ;       dpd     ebx
  100. ;       newline
  101.  
  102.         call    conversion_ASCII_to_HEX
  103.         mov     [menu_button_x.size],ebx
  104.  
  105. ;       dps     "menu_button_x.size: "
  106. ;       dpd     ebx
  107. ;       newline
  108.  
  109.         call    conversion_ASCII_to_HEX
  110.         mov     [menu_button_y.start],ebx
  111.  
  112. ;       dps     "menu_button_y.start: "
  113. ;       dpd     ebx
  114. ;       newline
  115.        
  116.         call    conversion_ASCII_to_HEX
  117.         mov     [menu_button_y.size],ebx
  118.        
  119. ;       dps     "menu_button_y.size: "
  120. ;       dpd     ebx
  121. ;       newline
  122.        
  123.         call    conversion_ASCII_to_HEX
  124.         mov     [panel_height],ebx
  125.  
  126. ;       dps     "panel_height: "
  127. ;       dpd     ebx
  128. ;       newline
  129.        
  130.         call    conversion_ASCII_to_HEX
  131.         mov     [panel_attachment],ebx
  132.        
  133. ;       dps     "panel_attachment: "
  134. ;       dpd     ebx
  135. ;       newline
  136. ;--------------------------------------
  137. align 4
  138. .no_boot_parameters:
  139.         call    program_exist
  140.         mcall   14
  141.         mov     [screen_size],eax
  142.        
  143.         mcall   48,3,sc,sizeof.system_colors    ; load system colors
  144.        
  145. ; get size of file MENU.DAT
  146.         mcall   70,fileinfo
  147.         test    eax,eax
  148.         jnz     close
  149. ; get memory for MENU.DAT
  150.         mov     ecx,[procinfo+32]
  151.         mov     [fileinfo.size],ecx
  152.         mcall   68,12
  153.         mov     [fileinfo.return],eax
  154.         mcall   68
  155.         mov     [menu_data],eax
  156. ; load MENU.DAT
  157.         mov     [fileinfo],dword 0
  158.         mcall   70,fileinfo
  159.         test    eax,eax
  160.         jnz     close
  161.  
  162.         test    ebx,ebx    ; length = 0 ?
  163.         jz      close
  164.         mov     ecx,ebx
  165.         mov     edi,[fileinfo.return]   ;mem_end
  166. ;--------------------------------------
  167. align 4
  168. newsearch:
  169.         mov     al,'#'
  170.         cld
  171.         repne   scasb
  172.         test    ecx,ecx    ; if not found
  173.         jz      close
  174.         call    get_number
  175.         test    ebx,ebx
  176.         jnz     .number
  177.         cmp     al,'#'
  178.         je      search_end
  179. ;--------------------------------------
  180. align 4
  181. .number:
  182.         shl     ebx,4
  183.         add     ebx,[menu_data]     ; pointer to process table
  184.         mov     [ebx],edi
  185.         inc     [processes]
  186.         jmp     newsearch
  187. ;--------------------------------------
  188. align 4
  189. search_end:
  190.         mov     [end_pointer],edi
  191.         mov     ebx,[processes]
  192.         dec     ebx
  193.         shl     ebx,4
  194.         add     ebx,[menu_data]
  195. ;--------------------------------------
  196. align 4
  197. newprocess:
  198.         xor     edx,edx
  199.         mov     ecx,edi
  200.         sub     ecx,[ebx]
  201.         mov     al,10
  202. ;--------------------------------------
  203. align 4
  204. newsearch1:
  205.         std
  206.         repne   scasb
  207.         test    ecx,ecx
  208.         je      endprocess
  209.         cmp     [edi],byte 13
  210.         jne     newsearch1
  211.         inc     edx
  212.         jmp     newsearch1
  213. ;--------------------------------------
  214. align 4
  215. endprocess:
  216.         mov     esi,ebx
  217.         add     esi,4
  218.         dec     edx
  219.         mov     [esi],dl
  220.         cmp     ebx,[menu_data]
  221.         jbe     search_end1
  222.         sub     ebx,16
  223.         jmp     newprocess
  224. ;--------------------------------------
  225. align 4
  226. search_end1:
  227.         mcall   14
  228.         cmp     [panel_attachment],byte 1
  229.         je      @f
  230.         xor     ax,ax
  231.         jmp     .store
  232. ;--------------------------------------
  233. align 4
  234. @@:
  235.         sub     ax,[panel_height]       ;20
  236. .store:
  237.         mov     ebx,[menu_data]
  238.         mov     [ebx + y_end],ax
  239.         mov     [ebx + x_start],5
  240.         mov     al,[ebx + rows]
  241.         mov     [ebx + cur_sel],al       ; clear selection
  242.         mov     [ebx + prev_sel],al
  243.         mov     [buffer],0
  244. ;------------------------------------------------------------------------------
  245. align 4
  246. thread:
  247.         mov     ebp,esp
  248.         sub     ebp,0x1000
  249.         cmp     ebp,0x2000 ; if this is first started thread
  250.         ja      @f
  251.         xor     ebp,ebp ; not free area
  252. ;--------------------------------------
  253. align 4
  254. @@:
  255.         mov     eax,[buffer]      ; identifier
  256.         shl     eax,4
  257.         add     eax,[menu_data]
  258.         mov     edi,eax
  259.         mcall   40,100111b      ; mouse + button + key + redraw
  260. ;------------------------------------------------------------------------------
  261. align 4
  262. red:   
  263.         call    draw_window     ; redraw
  264. ;------------------------------------------------------------------------------
  265. align 4
  266. still:
  267.         call    free_area_if_set_mutex
  268.  
  269.         mcall   23,5    ; wait here for event
  270.         test    [close_now],1      ; is close flag set?
  271.         jnz     close
  272.        
  273.         cmp     eax,1   ; redraw request ?
  274.         je      red
  275.         cmp     eax,2   ; key pressed ?
  276.         je      key
  277.         cmp     eax,3   ; button in buffer ?
  278.         je      button
  279.         cmp     eax,6   ; mouse event ?
  280.         je      mouse
  281.         cmp     edi,[menu_data]
  282.         je      still        ; if main process-ignored
  283.        
  284.         movzx   ebx,[edi + parent]       ; parent id
  285.         shl     ebx,4
  286.         add     ebx,[menu_data]      ; ebx = base of parent info
  287.         call    backconvert          ; get my id in al
  288.         cmp     al,[ebx + child]    ; if I'm not child of my parent, I shall die :)
  289.         jne     close
  290.        
  291.         jmp     still
  292. ;------------------------------------------------------------------------------
  293. align 4
  294. key:
  295.         mcall   2
  296.         mov     [last_key],ah
  297.         mov     al,[edi + rows]     ; number of buttons
  298.         cmp     ah,178    ; KEY_UP
  299.         jne     .noup
  300.        
  301.         mov     ah,[edi+cur_sel]
  302.         mov     [edi+prev_sel],ah
  303.         dec     byte [edi+cur_sel]
  304.         jnz     redrawbut
  305.         mov     [edi+cur_sel],al
  306.         jmp     redrawbut
  307. ;--------------------------------------
  308. align 4
  309. .noup:
  310.         cmp     ah,177   ; KEY_DOWN
  311.         jne     .nodn
  312.        
  313.         mov     ah,[edi + cur_sel]
  314.         mov     [edi + prev_sel],ah
  315.         inc     [edi + cur_sel]
  316.         cmp     [edi + cur_sel],al
  317.         jna     redrawbut
  318.         mov     [edi + cur_sel],1
  319.         jmp     redrawbut
  320. ;--------------------------------------
  321. align 4
  322. .nodn:
  323.         cmp     ah,179   ; KEY_LEFT
  324.         je      @f
  325.         cmp     ah,13    ; ENTER
  326.         jne     .noenter
  327. @@:
  328.         mov     ah,[edi + cur_sel]
  329.         jmp     button1
  330. ;--------------------------------------
  331. align 4
  332. .noenter:
  333.         cmp     ah,176   ; KEY_RIGHT
  334.         je      @f
  335.         cmp     ah,27    ; ESC
  336.         jne     still
  337.         jmp     close
  338. ;--------------------------------------
  339. align 4
  340. @@:
  341.         call    get_process_ID
  342.         cmp     [main_process_ID],ecx
  343.         jne     close
  344.         jmp     still
  345. ;------------------------------------------------------------------------------
  346. align 4
  347. button: ; BUTTON HANDLER
  348.         mcall   17      ; get id
  349.                                 ; dunkaist[
  350.         test    eax,0xfffffe00  ; is it system close button? (close signal from @taskbar)
  351.         setz    byte[close_now] ; set (or not set) close_recursive flag
  352.         jz      close           ; if so,close all menus
  353.                                 ; dunkaist]
  354. ;--------------------------------------
  355. align 4
  356. button1:
  357.         mov     esi,edi
  358.         push    edi
  359.         mov     edi,[edi + pointer]
  360. ; print "hello"
  361.         mov     al,[esi + cur_sel]
  362.         mov     [esi + prev_sel],al
  363.         mov     [esi + cur_sel],ah
  364.        
  365.         pushad
  366.         mov     edi,esi
  367. ; dph eax
  368.         call    draw_only_needed_buttons
  369.         popad
  370. ; look for the next line <ah> times; <ah> = button_id
  371.         push    eax
  372. ;--------------------------------------
  373. align 4
  374. .next_string:
  375.         call    searchstartstring
  376.         dec     ah
  377.         jnz     .next_string
  378.         pop     eax
  379.        
  380.         mov     ecx,40
  381.         mov     al,'/'
  382.         cld
  383.         repne   scasb
  384.         test    ecx,ecx   ; if '/' not found
  385.         je      searchexit
  386.        
  387.         cmp     [edi],byte '@'     ; check for submenu
  388.         je      runthread
  389.        
  390.         cmp     [last_key],179
  391.         je      searchexit
  392.        
  393.         dec     edi
  394.         push    edi                     ; pointer to start of filename
  395.         call    searchstartstring       ; search for next string
  396.         sub     edi,2           ; to last byte of string
  397.        
  398.         mov     ecx,edi
  399.         pop     esi
  400.         sub     ecx,esi
  401.         inc     ecx              ; length of filename
  402.         mov     edi, fileinfo_start.name
  403.         rep     movsb              ; copy string
  404.         mov     [edi],byte 0           ; store terminator
  405.         mcall   70,fileinfo_start       ; start program
  406.         or      [close_now],1      ; set close flag
  407.         pop     edi
  408.         mov     [mousemask],0
  409.         jmp     close
  410. ;--------------------------------------
  411. align 4
  412. searchexit:
  413.         pop     edi
  414.         jmp     still
  415. ;------------------------------------------------------------------------------
  416. align 4
  417. runthread:
  418.         inc     edi
  419.        
  420.         push    eax
  421.         call    get_number           ; get number of this process
  422.         pop     eax
  423.        
  424.         test    ebx,ebx    ; returned zero - main menu or not number
  425.         jz      searchexit
  426.        
  427.         mov     al,bl
  428.        
  429.         mov     ebx,[processes]
  430.         dec     bl
  431.         cmp     al,bl
  432.         ja      searchexit             ; such process doesnt exist
  433.         cmp     al,[esi + child]
  434.         je      searchexit             ; such process already exists
  435.        
  436.         mov     [esi + child],al    ; this is my child
  437.         mov     cx,[esi + x_start]
  438.         add     cx,141    ; new x_start in cx
  439.         movzx   edx,al
  440.         shl     edx,4
  441.         add     edx,[menu_data]       ; edx points to child's base address
  442.         mov     [edx + x_start],cx  ; xstart for new thread
  443.         mov     cx,[esi + y_end]   ; y_end in cx
  444.         mov     bl,[esi + rows]    ; number of buttons in bl
  445.         sub     bl,ah     ; number of btn from bottom
  446.         movzx   eax,al
  447.         mov     [buffer],eax            ; thread id in buffer
  448.         movzx   ebx,bl
  449.         push    edx
  450.         mov     eax,BTN_HEIGHT
  451.         mul     ebx
  452.         sub     cx,ax     ; new y_end for new thread
  453.         pop     edx
  454.         mov     [edx + y_end],cx    ; store y_end
  455.         mov     edi,esi
  456.         call    backconvert           ; get number of this process (al)
  457.         mov     [edx + parent],al   ; store number of parent process
  458.         mov     al,[edx + rows]
  459.         mov     [edx + cur_sel],al  ; clear current selected element
  460.         mov     [edx + prev_sel],al ; clear previous selected element
  461.         mov     [edx + child],0
  462.        
  463.         mcall   68,12,0x1000    ; stack of each thread is allocated 4 KB
  464.         add     eax,0x1000      ; set the stack pointer to the desired position
  465.         mov     edx,eax
  466.         mcall   51,1,thread     ; Go ahead!
  467.         jmp     searchexit
  468. ;------------------------------------------------------------------------------
  469. align 4
  470. mouse:        ; MOUSE EVENT HANDLER
  471.         mcall   37,0
  472.         mov     [screen_mouse_position],eax ; eax = [ Y | X ] relative to screen
  473.  
  474.         mcall   37,2
  475.         test    eax,eax    ; check buttons state
  476.         jnz     click
  477.         mcall   37,1
  478.         ror     eax,16    ; eax = [ Y | X ] relative to window
  479.         cmp     ax,BTN_WIDTH       ; pointer in window?
  480.         ja      noinwindow
  481. ; *** in window ***
  482.         shr     eax,16    ; eax = [ 0 | Y ]
  483.         xor     edx,edx
  484.         mov     ebx,BTN_HEIGHT
  485.         div     ebx
  486.         inc     eax               ; number of "button" in eax
  487.         movzx   ebx,[edi + rows]    ; total strings in ebx
  488.         cmp     eax,ebx
  489.         ja      noinwindow
  490.         cmp     [edi + cur_sel],al
  491.         je      noredrawbut
  492.         mov     bl,[edi + cur_sel]
  493. ;;;;;;
  494.         cmp     [edi + child],0
  495.         jne     noredrawbut
  496. ;;;;;;
  497.         mov     [edi + cur_sel],al
  498.         mov     [edi + prev_sel],bl
  499. ;--------------------------------------
  500. align 4
  501. redrawbut:
  502.         call    draw_only_needed_buttons
  503. ;--------------------------------------
  504. align 4
  505. noredrawbut:
  506.         call    backconvert
  507.         bts     [mousemask],eax
  508.         jmp     still
  509. ;--------------------------------------
  510. align 4
  511. noinwindow:
  512.         call    backconvert
  513.         btr     [mousemask],eax
  514.         jmp     still
  515. ;------------------------------------------------------------------------------
  516. align 4
  517. click:
  518.         cmp     [mousemask],0  ; not in a window (i.e. menu)
  519.         jne     still
  520. ; checking for pressing 'MENU' on the taskbar  
  521.         mov     eax,[screen_mouse_position]
  522.        
  523.         cmp     [panel_attachment],byte 1
  524.         je      @f
  525.  
  526.         xor     ebx,ebx
  527.         jmp     .check_y
  528. ;--------------------------------------
  529. align 4
  530. @@:
  531.         mov     ebx,[screen_size]
  532.         sub     bx,word [panel_height]  ;PANEL_HEIGHT
  533. ;--------------------------------------
  534. align 4
  535. .check_y:
  536.         add     bx,word [menu_button_y.start]
  537.         cmp     bx,ax
  538.         ja      close
  539.  
  540.         add     bx,word [menu_button_y.size]
  541.         cmp     bx,ax
  542.         jb      close
  543.        
  544.         shr     eax,16
  545.        
  546.         mov     ebx,[menu_button_x.start]
  547.         cmp     bx,ax   ; MENU_BOTTON_X_SIZE
  548.         ja      close
  549.        
  550.         add     bx,[menu_button_x.size]
  551.         cmp     bx,ax   ; MENU_BOTTON_X_POS
  552.         ja      still
  553. ;------------------------------------------------------------------------------
  554. align 4
  555. close:
  556.        
  557.         movzx   ebx,[edi+parent]       ; parent id
  558.         shl     ebx,4
  559.         add     ebx,[menu_data]          ; ebx = base of parent info
  560.         call    backconvert
  561.         cmp     [ebx + child],al       ; if i am the child of my parent...
  562.         jnz     @f
  563.         mov     [ebx + child],-1       ; ...my parent now has no children
  564. ;--------------------------------------
  565. align 4
  566. @@:
  567.         or      eax,-1                 ; close this thread
  568.         mov     [edi + child],al       ; my child is not mine
  569.        
  570.         call    free_area_if_set_mutex
  571.         call    set_mutex_for_free_area
  572.        
  573.         mcall
  574. ;--------------------------------------
  575. align 4
  576. backconvert:              ; convert from pointer to process id
  577.         mov     eax,edi
  578.         sub     eax,[menu_data]
  579.         shr     eax,4
  580.         ret
  581. ;------------------------------------------------------------------------------
  582. align 4
  583. set_mutex_for_free_area:
  584. ; set mutex for free thread stack area 
  585.         push    eax ebx
  586. ;--------------------------------------
  587. align 4
  588. .wait_lock:
  589.         cmp     [free_my_area_lock], 0
  590.         je      .get_lock
  591.         mcall   68,1
  592.         jmp     .wait_lock
  593. ;--------------------------------------
  594. align 4
  595. .get_lock:
  596.         mov     eax, 1
  597.         xchg    eax, [free_my_area_lock]
  598.         test    eax, eax
  599.         jnz     .wait_lock
  600.         mov     [free_my_area],ebp
  601.         pop     ebx eax
  602.         ret
  603. ;------------------------------------------------------------------------------
  604. align 4
  605. free_area_if_set_mutex:
  606.         cmp     [free_my_area_lock],0
  607.         je      .end
  608.  
  609.         push    eax ebx ecx
  610.         mov     ecx,[free_my_area]
  611.  
  612.         test    ecx,ecx
  613.         jz      @f
  614.         mcall   68,13
  615. ;--------------------------------------
  616. align 4
  617. @@:
  618.         xor     eax,eax
  619.         mov     [free_my_area_lock],eax
  620.         pop     ecx ebx eax
  621. ;--------------------------------------
  622. align 4
  623. .end:  
  624.         ret
  625. ;------------------------------------------------------------------------------
  626. ;==================================
  627. ; get_number
  628. ;    load number from [edi] to ebx
  629. ;==================================
  630. align 4
  631. get_number:
  632.         push    edi
  633.         xor     eax,eax
  634.         xor     ebx,ebx
  635. ;--------------------------------------
  636. align 4
  637. .get_next_char:
  638.         mov     al,[edi]
  639.         inc     edi
  640.         cmp     al, '0'
  641.         jb      .finish
  642.         cmp     al, '9'
  643.         ja      .finish
  644.         sub     al, '0'
  645.         imul    ebx,10
  646.         add     ebx,eax
  647.         jmp     .get_next_char
  648. ;-------------------------------------
  649. align 4
  650. .finish:
  651.         pop     edi
  652.         ret
  653. ;------------------------------------------------------------------------------
  654. align 4
  655. get_process_ID:
  656.         mcall   9,procinfo,-1
  657.         mov     edx,eax
  658.         mov     ecx,[ebx+30]    ; PID
  659.         ret
  660. ;------------------------------------------------------------------------------
  661. align 4
  662. program_exist:
  663.         call    get_process_ID
  664.         mov     [main_process_ID],ecx
  665.         mcall   18,21
  666.         mov     [active_process],eax    ; WINDOW SLOT
  667.         mov     ecx,edx
  668.         xor     edx,edx
  669. ;-----------------------------------------
  670. align 4
  671. .loop:
  672.         push    ecx
  673.         mcall   9,procinfo
  674.         mov     eax,[menu_mame]
  675.         cmp     [ebx+10],eax
  676.         jne     @f
  677.         mov     ax,[menu_mame+4]
  678.         cmp     [ebx+14],ax
  679.         jne     @f
  680.         cmp     ecx,[active_process]
  681.         je      @f
  682. ; dph ecx
  683.         mcall   18,2
  684.         mov     edx,1
  685. ;--------------------------------------
  686. align 4
  687. @@:
  688.         pop     ecx
  689.         loop    .loop
  690.  
  691.         test    edx,edx
  692.         jz      @f
  693.         mcall   -1
  694. ;--------------------------------------
  695. align 4
  696. @@:
  697.         ret
  698. ;------------------------------------------------------------------------------
  699. ;   *********************************************
  700. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  701. ;   *********************************************
  702. align 4
  703. draw_window:
  704.         mcall   48,5
  705.         mov     [x_working_area],eax
  706.         mov     [y_working_area],ebx
  707.  
  708.         mcall   12,1    ; 1,start of draw
  709.         movzx   ebx,[edi + rows]
  710.         imul    eax,ebx,BTN_HEIGHT          ; eax = height of window
  711.         movzx   ecx,[edi + y_end]
  712.         cmp     [panel_attachment],byte 1
  713.         je      @f
  714. ;       add     ecx,eax
  715. ;       sub     ecx,BTN_HEIGHT
  716.         jmp     .1
  717. ;--------------------------------------
  718. align 4
  719. @@:    
  720.         sub     ecx,eax     ; ecx = Y_START
  721. ;--------------------------------------
  722. align 4
  723. .1:
  724.         shl     ecx,16
  725.         add     ecx,eax     ; ecx = [ Y_START | Y_SIZE ]
  726.         dec ecx
  727.  
  728.         movzx   ebx,[edi + x_start]
  729.         shl     ebx,16
  730.         mov     bx,BTN_WIDTH        ; ebx = [ X_START | X_SIZE ]
  731.         mov     edx,0x01000000       ; color of work area RRGGBB,8->color gl
  732.         mov     esi,edx     ; unmovable window
  733.        
  734.         mov     eax,[y_working_area]
  735.         shr     eax,16
  736.         ror     ecx,16
  737.         test    cx,0x8000
  738.         jz      @f
  739.         mov     cx,ax
  740. ;--------------------------------------
  741. align 4
  742. @@:
  743.         cmp     cx,ax
  744.         ja      @f
  745.         mov     cx,ax  
  746. ;--------------------------------------
  747. align 4
  748. @@:
  749.         rol     ecx,16
  750.         xor     eax,eax     ; function 0 : define and draw window
  751.         mcall
  752.        
  753. ;       dps     "[ Y_START | Y_SIZE ] : "
  754. ;       dph     ecx
  755. ;       newline
  756.  
  757. ;       dps     "[ X_START | X_SIZE ] : "
  758. ;       dph     ebx
  759. ;       newline
  760.  
  761.         call    draw_all_buttons
  762.         mcall   12,2
  763.         ret
  764. ;------------------------------------------------------------------------------
  765. align 4
  766. draw_all_buttons:
  767.         xor     edx,edx
  768. ;--------------------------------------
  769. align 4
  770. .new_button:
  771.         call    draw_one_button
  772.         inc     edx
  773.         cmp     dl,[edi + rows]
  774.         jb      .new_button
  775.         ret
  776. ;------------------------------------------------------------------------------
  777. align 4
  778. draw_only_needed_buttons:
  779.         xor     edx,edx
  780.         mov     dl,[edi + cur_sel]
  781.         dec     dl
  782.         call    draw_one_button
  783.         mov     dl,[edi + prev_sel]
  784.         dec     dl
  785.         call    draw_one_button
  786.         ret
  787. ;------------------------------------------------------------------------------
  788. align 4
  789. draw_one_button:
  790. ; receives number of button in dl
  791.         push    edx
  792.         mov     eax,8
  793.         mov     ebx,BTN_WIDTH
  794.         movzx   ecx,dl
  795.         imul    ecx,BTN_HEIGHT
  796.         mov [draw_y], ecx
  797.         shl     ecx,16
  798.         add     ecx,BTN_HEIGHT
  799. ; edx = button identifier
  800.         mov     esi,[sc.work]
  801.         cmp     esi,0xdfdfdf
  802.         jb      nocorrect
  803.         sub     esi,0x1b1b1b
  804.        
  805. ;--------------------------------------
  806. align 4
  807. nocorrect:
  808.         inc     dl
  809.         cmp     [edi + cur_sel],dl
  810.         jne     .nohighlight
  811.         add     esi,0x1a1a1a
  812. ;--------------------------------------
  813. align 4
  814. .nohighlight:
  815.         or      edx,BT_NOFRAME + BT_HIDE
  816.                                 ; dunkaist[
  817.         add     edx,0xd1ff00    ; This makes first menu buttons differ
  818.                                 ; from system close button with 0x000001 id
  819.                                 ; dunkaist]
  820.         mcall
  821.         pusha
  822.        
  823.         mov edx, esi
  824.         mcall 13
  825.        
  826.         mcall   , BTN_WIDTH,     <[draw_y],1>,            [sc.work_light]
  827.         mcall   , 1,             <[draw_y],BTN_HEIGHT>
  828.         mcall   , <BTN_WIDTH,1>, <[draw_y],BTN_HEIGHT+1>, [sc.work_dark]
  829.         add [draw_y], BTN_HEIGHT-1
  830.         mcall   , BTN_WIDTH,     <[draw_y],1>
  831.        
  832.         popa
  833.         movzx   edx,dl
  834.         dec     dl
  835.         imul    ebx,edx,BTN_HEIGHT
  836.         add     ebx,(4 shl 16) + TXT_Y
  837.         movzx   ecx,dl
  838.         inc     ecx
  839.         mov     edx,[edi + pointer]
  840. ;--------------------------------------
  841. align 4
  842. .findline:
  843.         cmp     byte [edx],13
  844.         je      .linefound
  845.         inc     edx
  846.         jmp     .findline
  847. ;------------------------------------------------------------------------------
  848. align 4
  849. .linefound:
  850.         inc     edx
  851.         cmp     byte [edx],10
  852.         jne     .findline
  853.         dec     ecx
  854.         jnz     .findline
  855.        
  856.         mcall   4,,[sc.work_text],,21
  857.         pop     edx
  858.         ret
  859. ;------------------------------------------------------------------------------
  860. align 4
  861. searchstartstring:
  862.         mov     ecx,40
  863.         mov     al,13
  864.         cld
  865.         repne   scasb
  866.         cmp     byte [edi],10
  867.         jne     searchstartstring
  868.         ret
  869. ;------------------------------------------------------------------------------
  870. ;*** DATA AREA ****************************************************************
  871. menu_mame:
  872.         db '@MENU',0
  873.  
  874. align 4
  875. free_my_area_lock       dd 0
  876. free_my_area    dd 0
  877.  
  878. processes      dd 0
  879. ;--------------------------------------
  880. menu_button_x:
  881. .start: dd MENU_BOTTON_X_POS
  882. .size:  dd MENU_BOTTON_X_SIZE
  883. ;--------------------------------------
  884. menu_button_y:
  885. .start: dd 2
  886. .size:  dd 18
  887. ;--------------------------------------
  888. panel_height:           dd PANEL_HEIGHT
  889. panel_attachment:       dd 1
  890. ;--------------------------------------
  891. align 4
  892. fileinfo:
  893.  .subfunction    dd 5           ; 5 - file info; 0 - file read
  894.  .start          dd 0           ; start byte
  895.  .size_high      dd 0           ; rezerved
  896.  .size           dd 0           ; bytes to read
  897.  .return         dd procinfo    ; return data pointer
  898.  .name:
  899.      db   '/SYS/SETTINGS/MENU.DAT',0   ; ASCIIZ dir & filename
  900. ;--------------------------------------
  901. align 4
  902. fileinfo_start:
  903.  .subfunction   dd 7    ; 7=START APPLICATION
  904.  .flags         dd 0    ; flags
  905.  .params        dd 0x0  ; nop
  906.  .rezerved      dd 0x0  ; nop
  907.  .rezerved_1    dd 0x0  ; nop
  908.  .name:
  909.    times 50 db ' '
  910. ;------------------------------------------------------------------------------
  911. IM_END:
  912. ;------------------------------------------------------------------------------
  913. align 4
  914. close_now       dd ?   ; close all processes immediately
  915. end_pointer     dd ?
  916. buffer          dd ?
  917. mousemask       dd ?   ; mask for mouse pointer location
  918.  
  919. active_process  dd ?
  920. main_process_ID dd ?
  921. ;--------------------------------------
  922. screen_mouse_position:
  923. .y      dw ?
  924. .x      dw ?
  925. ;--------------------------------------
  926. screen_size:
  927. .y      dw ?
  928. .x      dw ?
  929. ;--------------------------------------
  930. draw_y dd ?
  931. ;--------------------------------------
  932. x_working_area:
  933. .right:         dw ?
  934. .left:          dw ?
  935. y_working_area:
  936. .bottom:        dw ?
  937. .top:           dw ?
  938. ;--------------------------------------
  939. sc system_colors
  940. ;--------------------------------------
  941. last_key        db ?
  942. ;------------------------------------------------------------------------------
  943. align 4
  944. menu_data       dd ?
  945. ;--------------------------------------
  946. virtual at 0          ; PROCESSES TABLE (located at menu_data)
  947.   pointer       dd ?   ; +0    pointer in file
  948.   rows          db ?    ; +4    numer of strings
  949.   x_start       dw ?   ; +5    x start
  950.   y_end         dw ?   ; +7    y end
  951.   child         db ?   ; +9    id of child menu
  952.   parent        db ?   ; +10   id of parent menu
  953.   cur_sel       db ?   ; +11   current selection
  954.   prev_sel      db ?   ; +12   previous selection
  955.   rb            16-$+1 ; [16 bytes per element]
  956. end virtual
  957. ;------------------------------------------------------------------------------
  958. align 4
  959. bootparam:
  960. procinfo:
  961.         rb 1024
  962. ;------------------------------------------------------------------------------
  963. align 4
  964.         rb 0x1000
  965. stack_area:
  966. ;------------------------------------------------------------------------------
  967. mem_end:
  968. ;------------------------------------------------------------------------------
  969.