Subversion Repositories Kolibri OS

Rev

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