Subversion Repositories Kolibri OS

Rev

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