Subversion Repositories Kolibri OS

Rev

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