Subversion Repositories Kolibri OS

Rev

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