Subversion Repositories Kolibri OS

Rev

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 ; 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 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.         pop     edi
  466.         or      [close_now],1      ; set close flag
  467.         mov     [mousemask],0
  468.         ; if program run failed then start /sys/@open with param
  469.         test    eax,eax
  470.         jns     close
  471.         mov     eax, fileinfo_start.name
  472.         mov [file_open.params], eax
  473.         mcall   70,file_open   
  474.         jmp     close
  475. ;--------------------------------------
  476. align 4
  477. searchexit:
  478.         pop     edi
  479.         jmp     still
  480. ;------------------------------------------------------------------------------
  481. align 4
  482. runthread:
  483.         inc     edi
  484.        
  485.         push    eax
  486.         call    get_number           ; get number of this process
  487.         pop     eax
  488.        
  489.         test    ebx,ebx    ; returned zero - main menu or not number
  490.         jz      searchexit
  491.        
  492.         mov     al,bl
  493.        
  494.         mov     ebx,[processes]
  495.         dec     bl
  496.         cmp     al,bl
  497.         ja      searchexit             ; such process doesnt exist
  498.         cmp     al,[esi + child]
  499.         je      searchexit             ; such process already exists
  500.        
  501.         mov     [esi + child],al    ; this is my child
  502.         mov     cx,[esi + x_start]
  503.         add     cx,BTN_WIDTH+1    ; new x_start in cx
  504.         movzx   edx,al
  505.         shl     edx,4
  506.         add     edx,[menu_data]       ; edx points to child's base address
  507.         mov     [edx + x_start],cx  ; xstart for new thread
  508.         mov     cx,[esi + y_end]   ; y_end in cx
  509.         mov     bl,[esi + rows]    ; number of buttons in bl
  510.         sub     bl,ah     ; number of btn from bottom
  511.  
  512.         ; Leency: store vars for case when attachement=top
  513.         pusha
  514.         mov [prior_thread_selected_y_end], bl
  515.         mcall   9,procinfo,-1
  516.         m2m     [prior_thread_y], dword[procinfo+38]
  517.         m2m     [prior_thread_h], dword[procinfo+46]
  518.         popa
  519.  
  520.         movzx   eax,al
  521.         mov     [buffer],eax            ; thread id in buffer
  522.         movzx   ebx,bl
  523.         push    edx
  524.         mov     eax,BTN_HEIGHT
  525.         mul     ebx
  526.         sub     cx,ax     ; new y_end for new thread
  527.         pop     edx
  528.         mov     [edx + y_end],cx    ; store y_end
  529.         mov     edi,esi
  530.         call    backconvert           ; get number of this process (al)
  531.         mov     [edx + parent],al   ; store number of parent process
  532.  
  533.         mov     al,[edx + rows]
  534.         mov     [edx + cur_sel],al  ; clear current selected element
  535.         mov     [edx + prev_sel],al ; clear previous selected element
  536.         mov     [edx + child],0
  537.        
  538.         mcall   68,12,0x1000    ; stack of each thread is allocated 4 KB
  539.         add     eax,0x1000      ; set the stack pointer to the desired position
  540.         mov     edx,eax
  541.         mcall   51,1,thread     ; Go ahead!
  542.         jmp     searchexit
  543. ;------------------------------------------------------------------------------
  544. align 4
  545. mouse:        ; MOUSE EVENT HANDLER
  546.         mcall   37,0
  547.         mov     [screen_mouse_position],eax ; eax = [ Y | X ] relative to screen
  548.  
  549.         mcall   37,2
  550.         test    eax,eax    ; check buttons state
  551.         jnz     click
  552.         mcall   37,1
  553.         ror     eax,16    ; eax = [ Y | X ] relative to window
  554.         cmp     ax,BTN_WIDTH       ; pointer in window?
  555.         ja      noinwindow
  556. ; *** in window ***
  557.         shr     eax,16    ; eax = [ 0 | Y ]
  558.         xor     edx,edx
  559.         mov     ebx,BTN_HEIGHT
  560.         div     ebx
  561.         inc     eax               ; number of "button" in eax
  562.         movzx   ebx,[edi + rows]    ; total strings in ebx
  563.         cmp     eax,ebx
  564.         ja      noinwindow
  565.         cmp     [edi + cur_sel],al
  566.         je      noredrawbut
  567.         mov     bl,[edi + cur_sel]
  568. ;;;;;;
  569.         cmp     [edi + child],0
  570.         jne     noredrawbut
  571. ;;;;;;
  572.         mov     [edi + cur_sel],al
  573.         mov     [edi + prev_sel],bl
  574. ;--------------------------------------
  575. align 4
  576. redrawbut:
  577.         call    draw_only_needed_buttons
  578. ;--------------------------------------
  579. align 4
  580. noredrawbut:
  581.         call    backconvert
  582.         bts     [mousemask],eax
  583.         jmp     still
  584. ;--------------------------------------
  585. align 4
  586. noinwindow:
  587.         call    backconvert
  588.         btr     [mousemask],eax
  589.         jmp     still
  590. ;------------------------------------------------------------------------------
  591. align 4
  592. click:
  593.         cmp     [mousemask],0  ; not in a window (i.e. menu)
  594.         jne     still
  595. ; checking for pressing 'MENU' on the taskbar  
  596.         mov     eax,[screen_mouse_position]
  597.        
  598.         cmp     [panel_attachment],byte 1
  599.         je      @f
  600.  
  601.         xor     ebx,ebx
  602.         jmp     .check_y
  603. ;--------------------------------------
  604. align 4
  605. @@:
  606.         mov     ebx,[screen_size]
  607.         sub     bx,word [panel_height]  ;PANEL_HEIGHT
  608. ;--------------------------------------
  609. align 4
  610. .check_y:
  611.         add     bx,word [menu_button_y.start]
  612.         cmp     bx,ax
  613.         ja      close
  614.  
  615.         add     bx,word [menu_button_y.size]
  616.         cmp     bx,ax
  617.         jb      close
  618.        
  619.         shr     eax,16
  620.        
  621.         mov     ebx,[menu_button_x.start]
  622.         cmp     bx,ax   ; MENU_BOTTON_X_SIZE
  623.         ja      close
  624.        
  625.         add     bx,[menu_button_x.size]
  626.         cmp     bx,ax   ; MENU_BOTTON_X_POS
  627.         ja      still
  628. ;------------------------------------------------------------------------------
  629. align 4
  630. close:
  631.        
  632.         movzx   ebx,[edi+parent]       ; parent id
  633.         shl     ebx,4
  634.         add     ebx,[menu_data]          ; ebx = base of parent info
  635.         call    backconvert
  636.         cmp     [ebx + child],al       ; if i am the child of my parent...
  637.         jnz     @f
  638.         mov     [ebx + child],-1       ; ...my parent now has no children
  639. ;--------------------------------------
  640. align 4
  641. @@:
  642.         or      eax,-1                 ; close this thread
  643.         mov     [edi + child],al       ; my child is not mine
  644.        
  645.         call    free_area_if_set_mutex
  646.         call    set_mutex_for_free_area
  647.        
  648.         mcall
  649. ;--------------------------------------
  650. align 4
  651. backconvert:              ; convert from pointer to process id
  652.         mov     eax,edi
  653.         sub     eax,[menu_data]
  654.         shr     eax,4
  655.         ret
  656. ;------------------------------------------------------------------------------
  657. align 4
  658. set_mutex_for_free_area:
  659. ; set mutex for free thread stack area 
  660.         push    eax ebx
  661. ;--------------------------------------
  662. align 4
  663. .wait_lock:
  664.         cmp     [free_my_area_lock], 0
  665.         je      .get_lock
  666.         mcall   68,1
  667.         jmp     .wait_lock
  668. ;--------------------------------------
  669. align 4
  670. .get_lock:
  671.         mov     eax, 1
  672.         xchg    eax, [free_my_area_lock]
  673.         test    eax, eax
  674.         jnz     .wait_lock
  675.         mov     [free_my_area],ebp
  676.         pop     ebx eax
  677.         ret
  678. ;------------------------------------------------------------------------------
  679. align 4
  680. free_area_if_set_mutex:
  681.         cmp     [free_my_area_lock],0
  682.         je      .end
  683.  
  684.         push    eax ebx ecx
  685.         mov     ecx,[free_my_area]
  686.  
  687.         test    ecx,ecx
  688.         jz      @f
  689.         mcall   68,13
  690. ;--------------------------------------
  691. align 4
  692. @@:
  693.         xor     eax,eax
  694.         mov     [free_my_area_lock],eax
  695.         pop     ecx ebx eax
  696. ;--------------------------------------
  697. align 4
  698. .end:  
  699.         ret
  700. ;------------------------------------------------------------------------------
  701. ;==================================
  702. ; get_number
  703. ;    load number from [edi] to ebx
  704. ;==================================
  705. align 4
  706. get_number:
  707.         push    edi
  708.         xor     eax,eax
  709.         xor     ebx,ebx
  710. ;--------------------------------------
  711. align 4
  712. .get_next_char:
  713.         mov     al,[edi]
  714.         inc     edi
  715.         cmp     al, '0'
  716.         jb      .finish
  717.         cmp     al, '9'
  718.         ja      .finish
  719.         sub     al, '0'
  720.         imul    ebx,10
  721.         add     ebx,eax
  722.         jmp     .get_next_char
  723. ;-------------------------------------
  724. align 4
  725. .finish:
  726.         pop     edi
  727.         ret
  728. ;------------------------------------------------------------------------------
  729. align 4
  730. get_process_ID:
  731.         mcall   9,procinfo,-1
  732.         mov     edx,eax
  733.         mov     ecx,[ebx+30]    ; PID
  734.         ret
  735. ;------------------------------------------------------------------------------
  736. align 4
  737. program_exist:
  738.         call    get_process_ID
  739.         mov     [main_process_ID],ecx
  740.         mcall   18,21
  741.         mov     [active_process],eax    ; WINDOW SLOT
  742.         mov     ecx,edx
  743.         xor     edx,edx
  744. ;-----------------------------------------
  745. align 4
  746. .loop:
  747.         push    ecx
  748.         mcall   9,procinfo
  749.         mov     eax,[menu_mame]
  750.         cmp     [ebx+10],eax
  751.         jne     @f
  752.         ; temporary to fit into 3 IMG sectors
  753.         ;mov    ax,[menu_mame+4]
  754.         ;cmp    [ebx+14],ax
  755.         ;jne    @f
  756.         cmp     ecx,[active_process]
  757.         je      @f
  758. ; dph ecx
  759.         mcall   18,2
  760.         mov     edx,1
  761. ;--------------------------------------
  762. align 4
  763. @@:
  764.         pop     ecx
  765.         loop    .loop
  766.  
  767.         test    edx,edx
  768.         jz      @f
  769.         mcall   -1
  770. ;--------------------------------------
  771. align 4
  772. @@:
  773.         ret
  774. ;------------------------------------------------------------------------------
  775. ;   *********************************************
  776. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  777. ;   *********************************************
  778. align 4
  779. draw_window:
  780.         mcall   48,5 ; get working area
  781.         mov     [x_working_area],eax
  782.         mov     [y_working_area],ebx
  783.  
  784.         mcall   12,1    ; 1,start of draw
  785.         movzx   ebx,[edi + rows]
  786.         imul    eax,ebx,BTN_HEIGHT          ; eax = height of window
  787.         movzx   ecx,[edi + y_end]
  788.         cmp     [panel_attachment],byte 1
  789.         je      @f
  790.        
  791.        
  792.         ;cmp    ebp,0x000 ; if this is first started thread
  793.         ;je .1            ; then show it at the very top
  794.        
  795.         push  ebx eax
  796.         ; if attachement=top
  797.         ; then NEW_WIN_Y = PRIOR_WIN_Y + PRIOR_WIN_H - ITEM_H + 1 - SEL_ITEM_Y
  798.  
  799.         mov ecx, [prior_thread_y]
  800.         add ecx, [prior_thread_h]
  801.         sub ecx, BTN_HEIGHT
  802.         inc ecx
  803.  
  804.         xor eax, eax
  805.         mov al, [prior_thread_selected_y_end]
  806.         mov ebx, BTN_HEIGHT
  807.         mul ebx
  808.                
  809.         sub ecx, eax
  810.  
  811.         mov     [edi + cur_sel],1 ;if attachement=top then set item=1 selected
  812.        
  813.         pop eax ebx
  814.  
  815.         jmp     .1
  816. ;--------------------------------------
  817. align 4
  818. @@:    
  819.         sub     ecx,eax     ; ecx = Y_START
  820. ;--------------------------------------
  821. align 4
  822. .1:
  823.         shl     ecx,16
  824.         add     ecx,eax     ; ecx = [ Y_START | Y_SIZE ]
  825.         dec ecx
  826.  
  827.         movzx   ebx,[edi + x_start]
  828.         shl     ebx,16
  829.         mov     bx,BTN_WIDTH        ; ebx = [ X_START | X_SIZE ]
  830.         mov     edx,0x01000000       ; color of work area RRGGBB,8->color gl
  831.         mov     esi,edx     ; unmovable window
  832.        
  833.         mov     eax,[y_working_area]
  834.         shr     eax,16
  835.         ror     ecx,16
  836.         test    cx,0x8000
  837.         jz      @f
  838.         mov     cx,ax
  839. ;--------------------------------------
  840. align 4
  841. @@:
  842.         cmp     cx,ax
  843.         ja      @f
  844.         mov     cx,ax  
  845. ;--------------------------------------
  846. align 4
  847. @@:
  848.         rol     ecx,16
  849.         xor     eax,eax     ; function 0 : define and draw window
  850.         mcall
  851.        
  852. ;       dps     "[ Y_START | Y_SIZE ] : "
  853. ;       dph     ecx
  854. ;       newline
  855.  
  856. ;       dps     "[ X_START | X_SIZE ] : "
  857. ;       dph     ebx
  858. ;       newline
  859.  
  860.         call    draw_all_buttons
  861.         mcall   12,2
  862.         ret
  863. ;------------------------------------------------------------------------------
  864. align 4
  865. draw_all_buttons:
  866.         xor     edx,edx
  867. ;--------------------------------------
  868. align 4
  869. .new_button:
  870.         call    draw_one_button
  871.         inc     edx
  872.         cmp     dl,[edi + rows]
  873.         jb      .new_button
  874.         ret
  875. ;------------------------------------------------------------------------------
  876. align 4
  877. draw_only_needed_buttons:
  878.         xor     edx,edx
  879.         mov     dl,[edi + cur_sel]
  880.         dec     dl
  881.         call    draw_one_button
  882.         mov     dl,[edi + prev_sel]
  883.         dec     dl
  884.         call    draw_one_button
  885.         ret
  886. ;------------------------------------------------------------------------------
  887. align 4
  888. draw_one_button:
  889. ; receives number of button in dl
  890.         push    edx
  891.         mov     eax,8
  892.         mov     ebx,BTN_WIDTH
  893.         movzx   ecx,dl
  894.         imul    ecx,BTN_HEIGHT
  895.         mov [draw_y], ecx
  896.         shl     ecx,16
  897.         add     ecx,BTN_HEIGHT
  898. ; edx = button identifier
  899.         mov     esi,[sc.work]
  900.         cmp     esi,0xdfdfdf
  901.         jb      nocorrect
  902.         sub     esi,0x1b1b1b
  903.        
  904. ;--------------------------------------
  905. align 4
  906. nocorrect:
  907.         mov [is_icon_active], 0
  908.         inc     dl
  909.         cmp     [edi + cur_sel],dl
  910.         jne     .nohighlight
  911.         mov [is_icon_active], 1
  912.         cmp esi,0
  913.         jne @f
  914.         mov esi,0x2a2a2a
  915. @@:
  916.         add     esi,0x1a1a1a
  917. ;--------------------------------------
  918. align 4
  919. .nohighlight:
  920.         or      edx,BT_NOFRAME + BT_HIDE
  921.                                 ; dunkaist[
  922.         add     edx,0xd1ff00    ; This makes first menu buttons differ
  923.                                 ; from system close button with 0x000001 id
  924.                                 ; dunkaist]
  925.         mcall
  926.         push edx
  927.        
  928.         mov edx, esi
  929.         mcall 13 ; draw rect
  930.        
  931.         mcall , BTN_WIDTH,<[draw_y],1>,[sc.work_light]
  932.         add     ecx, BTN_HEIGHT-1
  933.         mcall , 1
  934.         inc     ecx
  935.         mcall , <BTN_WIDTH,1>, , [sc.work_dark]
  936.         add     [draw_y], BTN_HEIGHT-1
  937.         mcall , BTN_WIDTH,<[draw_y],1>
  938.        
  939.         pop edx
  940.         movzx   edx,dl
  941.         dec     dl
  942.         imul    ebx,edx,BTN_HEIGHT
  943.         add     ebx,((4 + 18) shl 16) + TXT_Y ; added + 18 (icon size)
  944.         movzx   ecx,dl
  945.         inc     ecx
  946.         mov     edx,[edi + pointer]
  947. ;--------------------------------------
  948. align 4
  949. .findline:
  950.         cmp     byte [edx],13 ; if \r encountered => line found
  951.         je      .linefound
  952.         inc     edx ; go to next char
  953.         jmp     .findline
  954. ;------------------------------------------------------------------------------
  955. align 4
  956. .linefound:
  957.         inc     edx ; go to next char after \r
  958.         cmp     byte [edx],10 ; if it is not \n then again findline
  959.         jne     .findline
  960.         dec     ecx ; TODO what in ecx? button number?
  961.         jnz     .findline
  962.        
  963.         mov ecx, [sc.work_text]
  964.         add ecx, FONT_TYPE
  965.  
  966.         push ecx esi edi ebp
  967.         push ebx ; preserve ebx, it stores coordinates
  968.         mov [tmp], edx
  969.         mov [has_icon], 1
  970.         xor ebx, ebx
  971. @@: ; parse icon number
  972.         inc     edx
  973.         mov     al,[edx]
  974.         ; DEBUGF DBG_INFO, "(%u)\n", al
  975.         cmp     al, '0'
  976.         jb      @f
  977.         cmp     al, '9'
  978.         ja      @f
  979.         sub     al, '0'
  980.         imul    ebx,10
  981.         add     ebx,eax
  982.         jmp @b
  983. @@:
  984.         ; DEBUGF DBG_INFO, "icon_number = %x al = %u\n", ebx, al
  985.         mov [icon_number], ebx
  986.         cmp al, ' '
  987.         je @f
  988.         ; if no space after number then consider that number is a part of caption
  989.         mov edx, [tmp] ; restore edx
  990.         mov [has_icon], 0 ; no icon
  991. @@:
  992.         pop ebx
  993.  
  994.         mcall   4,,,,21 ; draw menu element caption
  995.  
  996.         cmp [no_shared_resources], 1
  997.         je @f
  998.         cmp [has_icon], 1
  999.         jne @f
  1000.         ; draw icon:
  1001.         mov eax, ebx
  1002.         shr eax, 16
  1003.         sub eax, 18 ; 18 - icon width
  1004.         movzx ebx, bx
  1005.  
  1006.         sub ebx, 2
  1007.         shl eax, 16
  1008.         add eax, ebx
  1009.         add eax, 1 shl 16
  1010.         mov [tmp], eax
  1011.         mov ebx, [icon_number]
  1012.         imul ebx, 18*18*4
  1013.  
  1014.         mov ecx, [shared_icons_ptr]
  1015.         ; DEBUGF DBG_INFO, "is_icon_active = %x\n", [is_icon_active]
  1016.         cmp [is_icon_active], 1
  1017.         jne .not_active_icon
  1018.         mov ecx, [shared_icons_active_ptr]
  1019. .not_active_icon:      
  1020.         add ebx, ecx
  1021.         mcall 65, ebx, <18,18>, [tmp], 32, 0, 0
  1022.  
  1023. @@:
  1024.         pop ebp edi esi ecx
  1025.        
  1026.         pop     edx
  1027.         ret
  1028. ;------------------------------------------------------------------------------
  1029. align 4
  1030. searchstartstring:
  1031.         mov     ecx,40
  1032.         mov     al,13
  1033.         cld
  1034.         repne   scasb
  1035.         cmp     byte [edi],10
  1036.         jne     searchstartstring
  1037.         ret
  1038. ;------------------------------------------------------------------------------
  1039. ;*** DATA AREA ****************************************************************
  1040. menu_mame:   db '@MENU',0
  1041. default_dir: db '/sys',0
  1042.  
  1043. align 4
  1044. free_my_area_lock       dd 0
  1045. free_my_area    dd 0
  1046.  
  1047. processes      dd 0
  1048. ;--------------------------------------
  1049. menu_button_x:
  1050. .start: dd MENU_BOTTON_X_POS
  1051. .size:  dd MENU_BOTTON_X_SIZE
  1052. ;--------------------------------------
  1053. menu_button_y:
  1054. .start: dd 2
  1055. .size:  dd 18
  1056. ;--------------------------------------
  1057. panel_height:           dd PANEL_HEIGHT
  1058. panel_attachment:       dd 1
  1059. ;--------------------------------------
  1060. align 4
  1061. fileinfo:
  1062.  .subfunction    dd 5           ; 5 - file info; 0 - file read
  1063.  .start          dd 0           ; start byte
  1064.  .size_high      dd 0           ; rezerved
  1065.  .size           dd 0           ; bytes to read
  1066.  .return         dd procinfo    ; return data pointer
  1067.  .name:
  1068.      db   'SETTINGS/MENU.DAT',0   ; ASCIIZ dir & filename
  1069. ;--------------------------------------
  1070. align 4
  1071. fileinfo_start:
  1072.  .subfunction   dd 7    ; 7=START APPLICATION
  1073.  .flags         dd 0    ; flags
  1074.  .params        dd 0x0  ; nop
  1075.  .rezerved      dd 0x0  ; nop
  1076.  .rezerved_1    dd 0x0  ; nop
  1077.  .name:
  1078.    times 50 db ' '
  1079. ;--------------------------------------
  1080. align 4
  1081. file_open:
  1082.  .subfunction   dd 7    ; 7=START /SYS/@OPEN APP WITH PARAM
  1083.  .flags         dd 0    ; flags
  1084.  .params        dd 0x0  ; nop
  1085.  .rezerved      dd 0x0  ; nop
  1086.  .rezerved_1    dd 0x0  ; nop
  1087.  .name:
  1088.    db   '/SYS/@OPEN',0
  1089. ;------------------------------------------------------------------------------
  1090. IM_END:
  1091. ;------------------------------------------------------------------------------
  1092. align 4
  1093. close_now       dd ?   ; close all processes immediately
  1094. end_pointer     dd ?
  1095. buffer          dd ?
  1096. mousemask       dd ?   ; mask for mouse pointer location
  1097.  
  1098. active_process  dd ?
  1099. main_process_ID dd ?
  1100. ;--------------------------------------
  1101. screen_mouse_position:
  1102. .y      dw ?
  1103. .x      dw ?
  1104. ;--------------------------------------
  1105. screen_size:
  1106. .y      dw ?
  1107. .x      dw ?
  1108. ;--------------------------------------
  1109. draw_y dd ?
  1110. ;--------------------------------------
  1111. x_working_area:
  1112. .right:         dw ?
  1113. .left:          dw ?
  1114. y_working_area:
  1115. .bottom:        dw ?
  1116. .top:           dw ?
  1117. ;--------------------------------------
  1118. sc system_colors
  1119. ;--------------------------------------
  1120. last_key        db ?
  1121. prior_thread_y dd ?
  1122. prior_thread_h dd ?
  1123. prior_thread_selected_y_end db ?
  1124. ;------------------------------------------------------------------------------
  1125. align 4
  1126. menu_data   dd ?
  1127. ;--------------------------------------
  1128. virtual     at 0       ; PROCESSES TABLE (located at menu_data)
  1129.   pointer   dd ?   ; +0    pointer in file
  1130.   rows      db ?   ; +4    numer of strings
  1131.   x_start   dw ?   ; +5    x start
  1132.   y_end     dw ?   ; +7    y end
  1133.   child     db ?   ; +9    id of child menu
  1134.   parent    db ?   ; +10   id of parent menu
  1135.   cur_sel   db ?   ; +11   current selection
  1136.   prev_sel  db ?   ; +12   previous selection
  1137.   rb        16-$+1 ; [16 bytes per element]
  1138. end virtual
  1139.  
  1140. include_debug_strings ; for debug-fdo
  1141.  
  1142. icons_resname db 'ICONS18W', 0
  1143. shared_icons_ptr dd ?
  1144. shared_icons_active_ptr dd ?
  1145. shared_icons_size dd ?
  1146. has_icon db ?
  1147. icon_number dd ?
  1148. is_icon_active dd ?
  1149. no_shared_resources dd 0
  1150. tmp dd ?
  1151. ;------------------------------------------------------------------------------
  1152. align 4
  1153. bootparam:
  1154. procinfo:
  1155.         rb 1024
  1156. ;------------------------------------------------------------------------------
  1157. align 4
  1158.         rb 0x1000
  1159. stack_area:
  1160. ;------------------------------------------------------------------------------
  1161. mem_end:
  1162. ;------------------------------------------------------------------------------
  1163.