Subversion Repositories Kolibri OS

Rev

Rev 7848 | Rev 8484 | 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.  
  447.         ; Leency: store vars for case when attachement=top
  448.         pusha
  449.         mov [prior_thread_selected_y_end], bl
  450.         mcall   9,procinfo,-1
  451.         m2m     [prior_thread_y], dword[procinfo+38]
  452.         m2m     [prior_thread_h], dword[procinfo+46]
  453.         popa
  454.  
  455.         movzx   eax,al
  456.         mov     [buffer],eax            ; thread id in buffer
  457.         movzx   ebx,bl
  458.         push    edx
  459.         mov     eax,BTN_HEIGHT
  460.         mul     ebx
  461.         sub     cx,ax     ; new y_end for new thread
  462.         pop     edx
  463.         mov     [edx + y_end],cx    ; store y_end
  464.         mov     edi,esi
  465.         call    backconvert           ; get number of this process (al)
  466.         mov     [edx + parent],al   ; store number of parent process
  467.  
  468.         mov     al,[edx + rows]
  469.         mov     [edx + cur_sel],al  ; clear current selected element
  470.         mov     [edx + prev_sel],al ; clear previous selected element
  471.         mov     [edx + child],0
  472.        
  473.         mcall   68,12,0x1000    ; stack of each thread is allocated 4 KB
  474.         add     eax,0x1000      ; set the stack pointer to the desired position
  475.         mov     edx,eax
  476.         mcall   51,1,thread     ; Go ahead!
  477.         jmp     searchexit
  478. ;------------------------------------------------------------------------------
  479. align 4
  480. mouse:        ; MOUSE EVENT HANDLER
  481.         mcall   37,0
  482.         mov     [screen_mouse_position],eax ; eax = [ Y | X ] relative to screen
  483.  
  484.         mcall   37,2
  485.         test    eax,eax    ; check buttons state
  486.         jnz     click
  487.         mcall   37,1
  488.         ror     eax,16    ; eax = [ Y | X ] relative to window
  489.         cmp     ax,BTN_WIDTH       ; pointer in window?
  490.         ja      noinwindow
  491. ; *** in window ***
  492.         shr     eax,16    ; eax = [ 0 | Y ]
  493.         xor     edx,edx
  494.         mov     ebx,BTN_HEIGHT
  495.         div     ebx
  496.         inc     eax               ; number of "button" in eax
  497.         movzx   ebx,[edi + rows]    ; total strings in ebx
  498.         cmp     eax,ebx
  499.         ja      noinwindow
  500.         cmp     [edi + cur_sel],al
  501.         je      noredrawbut
  502.         mov     bl,[edi + cur_sel]
  503. ;;;;;;
  504.         cmp     [edi + child],0
  505.         jne     noredrawbut
  506. ;;;;;;
  507.         mov     [edi + cur_sel],al
  508.         mov     [edi + prev_sel],bl
  509. ;--------------------------------------
  510. align 4
  511. redrawbut:
  512.         call    draw_only_needed_buttons
  513. ;--------------------------------------
  514. align 4
  515. noredrawbut:
  516.         call    backconvert
  517.         bts     [mousemask],eax
  518.         jmp     still
  519. ;--------------------------------------
  520. align 4
  521. noinwindow:
  522.         call    backconvert
  523.         btr     [mousemask],eax
  524.         jmp     still
  525. ;------------------------------------------------------------------------------
  526. align 4
  527. click:
  528.         cmp     [mousemask],0  ; not in a window (i.e. menu)
  529.         jne     still
  530. ; checking for pressing 'MENU' on the taskbar  
  531.         mov     eax,[screen_mouse_position]
  532.        
  533.         cmp     [panel_attachment],byte 1
  534.         je      @f
  535.  
  536.         xor     ebx,ebx
  537.         jmp     .check_y
  538. ;--------------------------------------
  539. align 4
  540. @@:
  541.         mov     ebx,[screen_size]
  542.         sub     bx,word [panel_height]  ;PANEL_HEIGHT
  543. ;--------------------------------------
  544. align 4
  545. .check_y:
  546.         add     bx,word [menu_button_y.start]
  547.         cmp     bx,ax
  548.         ja      close
  549.  
  550.         add     bx,word [menu_button_y.size]
  551.         cmp     bx,ax
  552.         jb      close
  553.        
  554.         shr     eax,16
  555.        
  556.         mov     ebx,[menu_button_x.start]
  557.         cmp     bx,ax   ; MENU_BOTTON_X_SIZE
  558.         ja      close
  559.        
  560.         add     bx,[menu_button_x.size]
  561.         cmp     bx,ax   ; MENU_BOTTON_X_POS
  562.         ja      still
  563. ;------------------------------------------------------------------------------
  564. align 4
  565. close:
  566.        
  567.         movzx   ebx,[edi+parent]       ; parent id
  568.         shl     ebx,4
  569.         add     ebx,[menu_data]          ; ebx = base of parent info
  570.         call    backconvert
  571.         cmp     [ebx + child],al       ; if i am the child of my parent...
  572.         jnz     @f
  573.         mov     [ebx + child],-1       ; ...my parent now has no children
  574. ;--------------------------------------
  575. align 4
  576. @@:
  577.         or      eax,-1                 ; close this thread
  578.         mov     [edi + child],al       ; my child is not mine
  579.        
  580.         call    free_area_if_set_mutex
  581.         call    set_mutex_for_free_area
  582.        
  583.         mcall
  584. ;--------------------------------------
  585. align 4
  586. backconvert:              ; convert from pointer to process id
  587.         mov     eax,edi
  588.         sub     eax,[menu_data]
  589.         shr     eax,4
  590.         ret
  591. ;------------------------------------------------------------------------------
  592. align 4
  593. set_mutex_for_free_area:
  594. ; set mutex for free thread stack area 
  595.         push    eax ebx
  596. ;--------------------------------------
  597. align 4
  598. .wait_lock:
  599.         cmp     [free_my_area_lock], 0
  600.         je      .get_lock
  601.         mcall   68,1
  602.         jmp     .wait_lock
  603. ;--------------------------------------
  604. align 4
  605. .get_lock:
  606.         mov     eax, 1
  607.         xchg    eax, [free_my_area_lock]
  608.         test    eax, eax
  609.         jnz     .wait_lock
  610.         mov     [free_my_area],ebp
  611.         pop     ebx eax
  612.         ret
  613. ;------------------------------------------------------------------------------
  614. align 4
  615. free_area_if_set_mutex:
  616.         cmp     [free_my_area_lock],0
  617.         je      .end
  618.  
  619.         push    eax ebx ecx
  620.         mov     ecx,[free_my_area]
  621.  
  622.         test    ecx,ecx
  623.         jz      @f
  624.         mcall   68,13
  625. ;--------------------------------------
  626. align 4
  627. @@:
  628.         xor     eax,eax
  629.         mov     [free_my_area_lock],eax
  630.         pop     ecx ebx eax
  631. ;--------------------------------------
  632. align 4
  633. .end:  
  634.         ret
  635. ;------------------------------------------------------------------------------
  636. ;==================================
  637. ; get_number
  638. ;    load number from [edi] to ebx
  639. ;==================================
  640. align 4
  641. get_number:
  642.         push    edi
  643.         xor     eax,eax
  644.         xor     ebx,ebx
  645. ;--------------------------------------
  646. align 4
  647. .get_next_char:
  648.         mov     al,[edi]
  649.         inc     edi
  650.         cmp     al, '0'
  651.         jb      .finish
  652.         cmp     al, '9'
  653.         ja      .finish
  654.         sub     al, '0'
  655.         imul    ebx,10
  656.         add     ebx,eax
  657.         jmp     .get_next_char
  658. ;-------------------------------------
  659. align 4
  660. .finish:
  661.         pop     edi
  662.         ret
  663. ;------------------------------------------------------------------------------
  664. align 4
  665. get_process_ID:
  666.         mcall   9,procinfo,-1
  667.         mov     edx,eax
  668.         mov     ecx,[ebx+30]    ; PID
  669.         ret
  670. ;------------------------------------------------------------------------------
  671. align 4
  672. program_exist:
  673.         call    get_process_ID
  674.         mov     [main_process_ID],ecx
  675.         mcall   18,21
  676.         mov     [active_process],eax    ; WINDOW SLOT
  677.         mov     ecx,edx
  678.         xor     edx,edx
  679. ;-----------------------------------------
  680. align 4
  681. .loop:
  682.         push    ecx
  683.         mcall   9,procinfo
  684.         mov     eax,[menu_mame]
  685.         cmp     [ebx+10],eax
  686.         jne     @f
  687.         mov     ax,[menu_mame+4]
  688.         cmp     [ebx+14],ax
  689.         jne     @f
  690.         cmp     ecx,[active_process]
  691.         je      @f
  692. ; dph ecx
  693.         mcall   18,2
  694.         mov     edx,1
  695. ;--------------------------------------
  696. align 4
  697. @@:
  698.         pop     ecx
  699.         loop    .loop
  700.  
  701.         test    edx,edx
  702.         jz      @f
  703.         mcall   -1
  704. ;--------------------------------------
  705. align 4
  706. @@:
  707.         ret
  708. ;------------------------------------------------------------------------------
  709. ;   *********************************************
  710. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  711. ;   *********************************************
  712. align 4
  713. draw_window:
  714.         mcall   48,5
  715.         mov     [x_working_area],eax
  716.         mov     [y_working_area],ebx
  717.  
  718.         mcall   12,1    ; 1,start of draw
  719.         movzx   ebx,[edi + rows]
  720.         imul    eax,ebx,BTN_HEIGHT          ; eax = height of window
  721.         movzx   ecx,[edi + y_end]
  722.         cmp     [panel_attachment],byte 1
  723.         je      @f
  724.        
  725.        
  726.         ;cmp    ebp,0x000 ; if this is first started thread
  727.         ;je .1            ; then show it at the very top
  728.        
  729.         push  ebx eax
  730.         ; if attachement=top
  731.         ; then NEW_WIN_Y = PRIOR_WIN_Y + PRIOR_WIN_H - ITEM_H + 1 - SEL_ITEM_Y
  732.  
  733.         mov ecx, [prior_thread_y]
  734.         add ecx, [prior_thread_h]
  735.         sub ecx, BTN_HEIGHT
  736.         inc ecx
  737.  
  738.         xor eax, eax
  739.         mov al, [prior_thread_selected_y_end]
  740.         mov ebx, BTN_HEIGHT
  741.         mul ebx
  742.                
  743.         sub ecx, eax
  744.  
  745.         mov     [edi + cur_sel],1 ;if attachement=top then set item=1 selected
  746.        
  747.         pop eax ebx
  748.  
  749.         jmp     .1
  750. ;--------------------------------------
  751. align 4
  752. @@:    
  753.         sub     ecx,eax     ; ecx = Y_START
  754. ;--------------------------------------
  755. align 4
  756. .1:
  757.         shl     ecx,16
  758.         add     ecx,eax     ; ecx = [ Y_START | Y_SIZE ]
  759.         dec ecx
  760.  
  761.         movzx   ebx,[edi + x_start]
  762.         shl     ebx,16
  763.         mov     bx,BTN_WIDTH        ; ebx = [ X_START | X_SIZE ]
  764.         mov     edx,0x01000000       ; color of work area RRGGBB,8->color gl
  765.         mov     esi,edx     ; unmovable window
  766.        
  767.         mov     eax,[y_working_area]
  768.         shr     eax,16
  769.         ror     ecx,16
  770.         test    cx,0x8000
  771.         jz      @f
  772.         mov     cx,ax
  773. ;--------------------------------------
  774. align 4
  775. @@:
  776.         cmp     cx,ax
  777.         ja      @f
  778.         mov     cx,ax  
  779. ;--------------------------------------
  780. align 4
  781. @@:
  782.         rol     ecx,16
  783.         xor     eax,eax     ; function 0 : define and draw window
  784.         mcall
  785.        
  786. ;       dps     "[ Y_START | Y_SIZE ] : "
  787. ;       dph     ecx
  788. ;       newline
  789.  
  790. ;       dps     "[ X_START | X_SIZE ] : "
  791. ;       dph     ebx
  792. ;       newline
  793.  
  794.         call    draw_all_buttons
  795.         mcall   12,2
  796.         ret
  797. ;------------------------------------------------------------------------------
  798. align 4
  799. draw_all_buttons:
  800.         xor     edx,edx
  801. ;--------------------------------------
  802. align 4
  803. .new_button:
  804.         call    draw_one_button
  805.         inc     edx
  806.         cmp     dl,[edi + rows]
  807.         jb      .new_button
  808.         ret
  809. ;------------------------------------------------------------------------------
  810. align 4
  811. draw_only_needed_buttons:
  812.         xor     edx,edx
  813.         mov     dl,[edi + cur_sel]
  814.         dec     dl
  815.         call    draw_one_button
  816.         mov     dl,[edi + prev_sel]
  817.         dec     dl
  818.         call    draw_one_button
  819.         ret
  820. ;------------------------------------------------------------------------------
  821. align 4
  822. draw_one_button:
  823. ; receives number of button in dl
  824.         push    edx
  825.         mov     eax,8
  826.         mov     ebx,BTN_WIDTH
  827.         movzx   ecx,dl
  828.         imul    ecx,BTN_HEIGHT
  829.         mov [draw_y], ecx
  830.         shl     ecx,16
  831.         add     ecx,BTN_HEIGHT
  832. ; edx = button identifier
  833.         mov     esi,[sc.work]
  834.         cmp     esi,0xdfdfdf
  835.         jb      nocorrect
  836.         sub     esi,0x1b1b1b
  837.        
  838. ;--------------------------------------
  839. align 4
  840. nocorrect:
  841.         inc     dl
  842.         cmp     [edi + cur_sel],dl
  843.         jne     .nohighlight
  844.         cmp esi,0
  845.         jne @f
  846.         mov esi,0x2a2a2a
  847. @@:
  848.         add     esi,0x1a1a1a
  849. ;--------------------------------------
  850. align 4
  851. .nohighlight:
  852.         or      edx,BT_NOFRAME + BT_HIDE
  853.                                 ; dunkaist[
  854.         add     edx,0xd1ff00    ; This makes first menu buttons differ
  855.                                 ; from system close button with 0x000001 id
  856.                                 ; dunkaist]
  857.         mcall
  858.         pusha
  859.        
  860.         mov edx, esi
  861.         mcall 13
  862.        
  863.         mcall   , BTN_WIDTH,     <[draw_y],1>,            [sc.work_light]
  864.         mcall   , 1,             <[draw_y],BTN_HEIGHT>
  865.         mcall   , <BTN_WIDTH,1>, <[draw_y],BTN_HEIGHT+1>, [sc.work_dark]
  866.         add [draw_y], BTN_HEIGHT-1
  867.         mcall   , BTN_WIDTH,     <[draw_y],1>
  868.        
  869.         popa
  870.         movzx   edx,dl
  871.         dec     dl
  872.         imul    ebx,edx,BTN_HEIGHT
  873.         add     ebx,(4 shl 16) + TXT_Y
  874.         movzx   ecx,dl
  875.         inc     ecx
  876.         mov     edx,[edi + pointer]
  877. ;--------------------------------------
  878. align 4
  879. .findline:
  880.         cmp     byte [edx],13
  881.         je      .linefound
  882.         inc     edx
  883.         jmp     .findline
  884. ;------------------------------------------------------------------------------
  885. align 4
  886. .linefound:
  887.         inc     edx
  888.         cmp     byte [edx],10
  889.         jne     .findline
  890.         dec     ecx
  891.         jnz     .findline
  892.        
  893.         mcall   4,,[sc.work_text],,21
  894.         pop     edx
  895.         ret
  896. ;------------------------------------------------------------------------------
  897. align 4
  898. searchstartstring:
  899.         mov     ecx,40
  900.         mov     al,13
  901.         cld
  902.         repne   scasb
  903.         cmp     byte [edi],10
  904.         jne     searchstartstring
  905.         ret
  906. ;------------------------------------------------------------------------------
  907. ;*** DATA AREA ****************************************************************
  908. menu_mame:
  909.         db '@MENU',0
  910.  
  911. align 4
  912. free_my_area_lock       dd 0
  913. free_my_area    dd 0
  914.  
  915. processes      dd 0
  916. ;--------------------------------------
  917. menu_button_x:
  918. .start: dd MENU_BOTTON_X_POS
  919. .size:  dd MENU_BOTTON_X_SIZE
  920. ;--------------------------------------
  921. menu_button_y:
  922. .start: dd 2
  923. .size:  dd 18
  924. ;--------------------------------------
  925. panel_height:           dd PANEL_HEIGHT
  926. panel_attachment:       dd 1
  927. ;--------------------------------------
  928. align 4
  929. fileinfo:
  930.  .subfunction    dd 5           ; 5 - file info; 0 - file read
  931.  .start          dd 0           ; start byte
  932.  .size_high      dd 0           ; rezerved
  933.  .size           dd 0           ; bytes to read
  934.  .return         dd procinfo    ; return data pointer
  935.  .name:
  936.      db   '/SYS/SETTINGS/MENU.DAT',0   ; ASCIIZ dir & filename
  937. ;--------------------------------------
  938. align 4
  939. fileinfo_start:
  940.  .subfunction   dd 7    ; 7=START APPLICATION
  941.  .flags         dd 0    ; flags
  942.  .params        dd 0x0  ; nop
  943.  .rezerved      dd 0x0  ; nop
  944.  .rezerved_1    dd 0x0  ; nop
  945.  .name:
  946.    times 50 db ' '
  947. ;------------------------------------------------------------------------------
  948. IM_END:
  949. ;------------------------------------------------------------------------------
  950. align 4
  951. close_now       dd ?   ; close all processes immediately
  952. end_pointer     dd ?
  953. buffer          dd ?
  954. mousemask       dd ?   ; mask for mouse pointer location
  955.  
  956. active_process  dd ?
  957. main_process_ID dd ?
  958. ;--------------------------------------
  959. screen_mouse_position:
  960. .y      dw ?
  961. .x      dw ?
  962. ;--------------------------------------
  963. screen_size:
  964. .y      dw ?
  965. .x      dw ?
  966. ;--------------------------------------
  967. draw_y dd ?
  968. ;--------------------------------------
  969. x_working_area:
  970. .right:         dw ?
  971. .left:          dw ?
  972. y_working_area:
  973. .bottom:        dw ?
  974. .top:           dw ?
  975. ;--------------------------------------
  976. sc system_colors
  977. ;--------------------------------------
  978. last_key        db ?
  979. prior_thread_y dd ?
  980. prior_thread_h dd ?
  981. prior_thread_selected_y_end db ?
  982. ;------------------------------------------------------------------------------
  983. align 4
  984. menu_data       dd ?
  985. ;--------------------------------------
  986. virtual at 0          ; PROCESSES TABLE (located at menu_data)
  987.   pointer       dd ?   ; +0    pointer in file
  988.   rows          db ?    ; +4    numer of strings
  989.   x_start       dw ?   ; +5    x start
  990.   y_end         dw ?   ; +7    y end
  991.   child         db ?   ; +9    id of child menu
  992.   parent        db ?   ; +10   id of parent menu
  993.   cur_sel       db ?   ; +11   current selection
  994.   prev_sel      db ?   ; +12   previous selection
  995.   rb            16-$+1 ; [16 bytes per element]
  996. end virtual
  997. ;------------------------------------------------------------------------------
  998. align 4
  999. bootparam:
  1000. procinfo:
  1001.         rb 1024
  1002. ;------------------------------------------------------------------------------
  1003. align 4
  1004.         rb 0x1000
  1005. stack_area:
  1006. ;------------------------------------------------------------------------------
  1007. mem_end:
  1008. ;------------------------------------------------------------------------------
  1009.