Subversion Repositories Kolibri OS

Rev

Rev 183 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; int __stdcall DialogBox(DLGTEMPLATE* dlg, void* DlgProc);
  2. ;       int __stdcall DlgProc(int msg, int param1, int param2);
  3.  
  4. virtual at 0
  5. dlgtemplate:
  6. .flags          dd      ?
  7. .x              dd      ?
  8. .y              dd      ?
  9. .width          dd      ?
  10. .height         dd      ?
  11. .border_size_x  dd      ?
  12. .border_size_y  dd      ?
  13. .title          dd      ?
  14. .main_color     db      ?
  15. .border_color   db      ?
  16. .header_color   db      ?
  17.                 db      ?       ; align
  18. end virtual
  19.  
  20. DialogBox:
  21.         pushad
  22. ; some checks
  23.         mov     ebx, [esp+20h+4]
  24.         mov     eax, [ebx+dlgtemplate.x]
  25.         cmp     eax, 1
  26.         jl      .sizeerr
  27.         add     eax, [ebx+dlgtemplate.width]
  28.         cmp     eax, [cur_width]
  29.         jge     .sizeerr
  30.         mov     eax, [ebx+dlgtemplate.y]
  31.         cmp     eax, 1
  32.         jl      .sizeerr
  33.         add     eax, [ebx+dlgtemplate.height]
  34.         cmp     eax, [cur_height]
  35.         jge     .sizeerr
  36.         cmp     [ebx+dlgtemplate.border_size_x], 1
  37.         jl      .sizeerr
  38.         cmp     [ebx+dlgtemplate.border_size_y], 1
  39.         jge     .sizeok
  40. .sizeerr:
  41.         popad
  42.         or      eax, -1
  43.         ret     8
  44. .sizeok:
  45. ; allocate memory for data under dialog
  46.         mov     eax, [ebx+dlgtemplate.width]
  47.         add     eax, [ebx+dlgtemplate.border_size_x]
  48.         add     eax, [ebx+dlgtemplate.border_size_x]
  49.         inc     eax
  50.         inc     eax
  51.         mov     edx, [ebx+dlgtemplate.height]
  52.         add     edx, [ebx+dlgtemplate.border_size_y]
  53.         add     edx, [ebx+dlgtemplate.border_size_y]
  54.         inc     edx
  55.         mul     edx
  56.         add     eax, eax
  57.         call    mf_alloc
  58.         test    eax, eax
  59.         jnz     @f
  60. ; TODO: add error message
  61.         popad
  62.         or      eax, -1
  63.         ret     8
  64. @@:
  65.         mov     ebp, eax
  66. ; save data
  67.         mov     eax, [ebx+dlgtemplate.y]
  68.         add     eax, [ebx+dlgtemplate.height]
  69.         add     eax, [ebx+dlgtemplate.border_size_y]
  70.         inc     eax
  71.         push    eax
  72.         mov     eax, [ebx+dlgtemplate.x]
  73.         add     eax, [ebx+dlgtemplate.width]
  74.         add     eax, [ebx+dlgtemplate.border_size_x]
  75.         inc     eax
  76.         inc     eax
  77.         push    eax
  78.         mov     eax, [ebx+dlgtemplate.y]
  79.         sub     eax, [ebx+dlgtemplate.border_size_y]
  80.         push    eax
  81.         mov     eax, [ebx+dlgtemplate.x]
  82.         sub     eax, [ebx+dlgtemplate.border_size_x]
  83.         push    eax
  84.         call    save_console_data
  85. ; draw shadow
  86.         mov     eax, [ebx+dlgtemplate.x]
  87.         sub     eax, [ebx+dlgtemplate.border_size_x]
  88.         ja      @f
  89.         xor     eax, eax
  90. @@:
  91.         push    eax     ; save real window left
  92.         inc     eax
  93.         inc     eax
  94.         mov     edx, [ebx+dlgtemplate.y]
  95.         sub     edx, [ebx+dlgtemplate.border_size_y]
  96.         ja      @f
  97.         xor     edx, edx
  98. @@:
  99.         push    edx     ; save real window top
  100.         inc     edx
  101.         call    get_console_ptr
  102.         mov     ecx, [ebx+dlgtemplate.y]
  103.         add     ecx, [ebx+dlgtemplate.height]
  104.         add     ecx, [ebx+dlgtemplate.border_size_y]
  105.         inc     ecx
  106.         cmp     ecx, [cur_height]
  107.         jb      @f
  108.         mov     ecx, [cur_height]
  109. @@:
  110.         sub     ecx, edx
  111.         mov     edx, ecx
  112.         mov     ecx, [ebx+dlgtemplate.x]
  113.         add     ecx, [ebx+dlgtemplate.width]
  114.         add     ecx, [ebx+dlgtemplate.border_size_x]
  115.         inc     ecx
  116.         inc     ecx
  117.         cmp     ecx, [cur_width]
  118.         jb      @f
  119.         mov     ecx, [cur_width]
  120. @@:
  121.         sub     ecx, eax
  122.         mov     eax, ecx
  123. .shadow_loop:
  124.         mov     ecx, eax
  125.         push    edi
  126. .sl1:
  127.         inc     edi
  128.         test    byte [edi], 0x0F
  129.         jnz     @f
  130.         or      byte [edi], 8
  131. @@:
  132.         and     byte [edi], 0x0F
  133.         inc     edi
  134.         loop    .sl1
  135.         pop     edi
  136.         add     edi, [cur_width]
  137.         add     edi, [cur_width]
  138.         dec     edx
  139.         jnz     .shadow_loop
  140. ; draw area background
  141.         pop     edx
  142.         pop     eax
  143.         call    get_console_ptr
  144.         mov     ecx, [ebx+dlgtemplate.x]
  145.         add     ecx, [ebx+dlgtemplate.width]
  146.         add     ecx, [ebx+dlgtemplate.border_size_x]
  147.         cmp     ecx, [cur_width]
  148.         jb      @f
  149.         mov     ecx, [cur_width]
  150. @@:
  151.         sub     ecx, eax
  152.         mov     esi, ecx
  153.         mov     ecx, [ebx+dlgtemplate.y]
  154.         add     ecx, [ebx+dlgtemplate.height]
  155.         add     ecx, [ebx+dlgtemplate.border_size_y]
  156.         cmp     ecx, [cur_height]
  157.         jb      @f
  158.         mov     ecx, [cur_height]
  159. @@:
  160.         sub     ecx, edx
  161.         mov     edx, ecx
  162.         mov     al, ' '
  163.         mov     ah, [ebx+dlgtemplate.border_color]
  164. .1:
  165.         mov     ecx, esi
  166.         push    edi
  167.         rep     stosw
  168.         pop     edi
  169.         add     edi, [cur_width]
  170.         add     edi, [cur_width]
  171.         dec     edx
  172.         jnz     .1
  173. ; draw border
  174.         mov     eax, [ebx+dlgtemplate.x]
  175.         dec     eax
  176.         mov     edx, [ebx+dlgtemplate.y]
  177.         dec     edx
  178.         call    get_console_ptr
  179.         mov     edx, [ebx+dlgtemplate.height]
  180.         inc     edx
  181.         inc     edx
  182.         mov     ah, [ebx+dlgtemplate.border_color]
  183.         push    ebx
  184.         mov     ebx, [ebx+dlgtemplate.width]
  185.         inc     ebx
  186.         inc     ebx
  187.         call    draw_border
  188.         pop     ebx
  189. ; draw header
  190.         mov     esi, [ebx+dlgtemplate.title]
  191.         test    esi, esi
  192.         jz      .noheader
  193.         cmp     byte [esi], 0
  194.         jz      .noheader
  195.         push    esi
  196. @@:     lodsb
  197.         test    al, al
  198.         jnz     @b
  199.         mov     eax, esi
  200.         pop     esi
  201.         sub     eax, esi
  202.         inc     eax     ; eax = äëèíà çàãîëîâêà + 2
  203.         mov     ecx, [ebx+dlgtemplate.width]
  204.         cmp     eax, ecx
  205.         jbe     .fullhea
  206.         sub     ecx, 5
  207.         jb      .noheader
  208.         xor     edx, edx
  209.         jmp     .drawhea
  210. .fullhea:
  211.         mov     edx, ecx
  212.         sub     edx, eax
  213.         shr     edx, 1
  214. .drawhea:
  215.         mov     eax, [ebx+dlgtemplate.x]
  216.         add     eax, edx
  217.         mov     edx, [ebx+dlgtemplate.y]
  218.         dec     edx
  219.         call    get_console_ptr
  220.         mov     ah, [ebx+dlgtemplate.header_color]
  221.         mov     al, ' '
  222.         stosw
  223.         dec     ecx
  224. .2:
  225.         jecxz   .3
  226.         lodsb
  227.         test    al, al
  228.         jz      .4
  229.         stosw
  230.         jmp     .2
  231. .3:
  232.         mov     al, '.'
  233.         stosw
  234.         stosw
  235.         stosw
  236. .4:
  237.         mov     al, ' '
  238.         stosw
  239. .noheader:
  240. ; draw window background
  241.         mov     eax, [ebx+dlgtemplate.x]
  242.         mov     edx, [ebx+dlgtemplate.y]
  243.         call    get_console_ptr
  244.         mov     ah, [ebx+dlgtemplate.main_color]
  245.         mov     al, ' '
  246.         mov     edx, [ebx+dlgtemplate.height]
  247. @@:
  248.         mov     ecx, [ebx+dlgtemplate.width]
  249.         push    edi
  250.         rep     stosw
  251.         pop     edi
  252.         add     edi, [cur_width]
  253.         add     edi, [cur_width]
  254.         dec     edx
  255.         jnz     @b
  256. ; send redraw message
  257.         mov     eax, [esp+20h+8]
  258.         push    ebx ebp
  259.         push    0
  260.         push    0
  261.         push    1
  262.         call    eax
  263.         call    draw_image
  264.         pop     ebp ebx
  265. ; message loop
  266. .event:
  267.         push    10
  268.         pop     eax
  269.         int     40h
  270.         dec     eax
  271.         jz      .redraw
  272.         dec     eax
  273.         jz      .key
  274.         or      eax, -1
  275.         int     40h
  276. .redraw:
  277.         push    ebx ebp
  278.         call    draw_window
  279.         pop     ebp ebx
  280.         jmp     .event
  281. .key:
  282.         mov     al, 2
  283.         int     40h
  284.         shr     eax, 8
  285.         cmp     al, 0xE0
  286.         jnz     @f
  287.         mov     [bWasE0], 1
  288.         jmp     .event
  289. @@:
  290.         xchg    ah, [bWasE0]
  291.         cmp     al, 0x1D
  292.         jz      .ctrl_down
  293.         cmp     al, 0x9D
  294.         jz      .ctrl_up
  295.         cmp     al, 0x2A
  296.         jz      .lshift_down
  297.         cmp     al, 0xAA
  298.         jz      .lshift_up
  299.         cmp     al, 0x36
  300.         jz      .rshift_down
  301.         cmp     al, 0xB6
  302.         jz      .rshift_up
  303.         cmp     al, 0x38
  304.         jz      .alt_down
  305.         cmp     al, 0xB8
  306.         jz      .alt_up
  307.         mov     ecx, [esp+20h+8]
  308.         push    ebx ebp
  309.         push    0
  310.         push    eax
  311.         push    2
  312.         call    ecx
  313.         pop     ebp ebx
  314.         test    eax, eax
  315.         jz      .event
  316.         mov     [esp+28], eax
  317.         jmp     .exit
  318. .ctrl_down:
  319.         test    ah, ah
  320.         jnz     .rctrl_down
  321.         or      [ctrlstate], 4
  322.         jmp     .event
  323. .rctrl_down:
  324.         or      [ctrlstate], 8
  325.         jmp     .event
  326. .ctrl_up:
  327.         test    ah, ah
  328.         jnz     .rctrl_up
  329.         and     [ctrlstate], not 4
  330.         jmp     .event
  331. .rctrl_up:
  332.         and     [ctrlstate], not 8
  333.         jmp     .event
  334. .lshift_down:
  335.         test    ah, ah
  336.         jnz     @f
  337.         or      [ctrlstate], 1
  338. @@:     jmp     .event
  339. .lshift_up:
  340.         test    ah, ah
  341.         jnz     @b
  342.         and     [ctrlstate], not 1
  343.         jmp     @b
  344. .rshift_down:
  345.         or      [ctrlstate], 2
  346.         jmp     .event
  347. .rshift_up:
  348.         and     [ctrlstate], not 2
  349.         jmp     .event
  350. .alt_down:
  351.         test    ah, ah
  352.         jnz     .ralt_down
  353.         or      [ctrlstate], 0x10
  354.         jmp     .event
  355. .ralt_down:
  356.         or      [ctrlstate], 0x20
  357.         jmp     .event
  358. .alt_up:
  359.         test    ah, ah
  360.         jnz     .ralt_up
  361.         and     [ctrlstate], not 0x10
  362.         jmp     .event
  363. .ralt_up:
  364.         and     [ctrlstate], not 0x20
  365.         jmp     .event
  366. .exit:
  367. ; restore data
  368.         mov     eax, [ebx+dlgtemplate.y]
  369.         add     eax, [ebx+dlgtemplate.height]
  370.         add     eax, [ebx+dlgtemplate.border_size_y]
  371.         inc     eax
  372.         push    eax
  373.         mov     eax, [ebx+dlgtemplate.x]
  374.         add     eax, [ebx+dlgtemplate.width]
  375.         add     eax, [ebx+dlgtemplate.border_size_x]
  376.         inc     eax
  377.         inc     eax
  378.         push    eax
  379.         mov     eax, [ebx+dlgtemplate.y]
  380.         sub     eax, [ebx+dlgtemplate.border_size_y]
  381.         push    eax
  382.         mov     eax, [ebx+dlgtemplate.x]
  383.         sub     eax, [ebx+dlgtemplate.border_size_x]
  384.         push    eax
  385.         call    restore_console_data
  386.         call    draw_keybar
  387.         mov     eax, ebp
  388.         call    mf_free
  389.         call    draw_image
  390.         popad
  391.         ret     8
  392.  
  393. save_console_data:
  394.         cmp     dword [esp+4], 0
  395.         jge     @f
  396.         and     dword [esp+4], 0
  397. @@:
  398.         cmp     dword [esp+8], 0
  399.         jge     @f
  400.         and     dword [esp+8], 0
  401. @@:
  402.         mov     eax, [esp+12]
  403.         cmp     eax, [cur_width]
  404.         jbe     @f
  405.         mov     eax, [cur_width]
  406. @@:
  407.         sub     eax, [esp+4]
  408.         ja      @f
  409.         ret     16
  410. @@:
  411.         mov     [esp+12], eax
  412.         mov     eax, [esp+16]
  413.         cmp     eax, [cur_height]
  414.         jbe     @f
  415.         mov     eax, [cur_height]
  416. @@:
  417.         sub     eax, [esp+8]
  418.         ja      @f
  419.         ret     16
  420. @@:
  421.         mov     [esp+16], eax
  422.         mov     eax, [esp+4]
  423.         mov     edx, [esp+8]
  424.         call    get_console_ptr
  425.         mov     esi, edi
  426.         mov     edi, ebp
  427. .l:
  428.         mov     ecx, [esp+12]
  429.         push    esi
  430.         shr     ecx, 1
  431.         rep     movsd
  432.         adc     ecx, ecx
  433.         rep     movsw
  434.         pop     esi
  435.         add     esi, [cur_width]
  436.         add     esi, [cur_width]
  437.         dec     dword [esp+16]
  438.         jnz     .l
  439.         ret     16
  440.  
  441. restore_console_data:
  442.         cmp     dword [esp+4], 0
  443.         jge     @f
  444.         and     dword [esp+4], 0
  445. @@:
  446.         cmp     dword [esp+8], 0
  447.         jge     @f
  448.         and     dword [esp+8], 0
  449. @@:
  450.         mov     eax, [esp+12]
  451.         cmp     eax, [cur_width]
  452.         jbe     @f
  453.         mov     eax, [cur_width]
  454. @@:
  455.         sub     eax, [esp+4]
  456.         ja      @f
  457.         ret     16
  458. @@:
  459.         mov     [esp+12], eax
  460.         mov     eax, [esp+16]
  461.         cmp     eax, [cur_height]
  462.         jbe     @f
  463.         mov     eax, [cur_height]
  464. @@:
  465.         sub     eax, [esp+8]
  466.         ja      @f
  467.         ret     16
  468. @@:
  469.         mov     [esp+16], eax
  470.         mov     eax, [esp+4]
  471.         mov     edx, [esp+8]
  472.         call    get_console_ptr
  473.         mov     esi, ebp
  474. .l:
  475.         mov     ecx, [esp+12]
  476.         push    edi
  477.         shr     ecx, 1
  478.         rep     movsd
  479.         adc     ecx, ecx
  480.         rep     movsw
  481.         pop     edi
  482.         add     edi, [cur_width]
  483.         add     edi, [cur_width]
  484.         dec     dword [esp+16]
  485.         jnz     .l
  486.         ret     16
  487.  
  488. ; int __stdcall menu(void* variants, const char* title, unsigned flags);
  489. ; variants 㪠§ë¢ ¥â ­  ⥪ã騩 í«¥¬¥­â ¢ ¤¢ãá¢ï§­®¬ «¨­¥©­®¬ ᯨ᪥
  490. menu:
  491.         pop     eax
  492.         push    [cur_height]
  493.         push    [cur_width]
  494.         push    0
  495.         push    0
  496.         push    eax
  497.  
  498. ; int __stdcall menu_centered_in(unsigned left, unsigned top, unsigned width, unsigned height,
  499. ;       void* variants, const char* title, unsigned flags);
  500. menu_centered_in:
  501.         pushad
  502.         mov     eax, 56
  503. ; 36 bytes for dlgtemplate + additional:
  504. ; +36: dd cur_variant
  505. ; +40: dd num_variants
  506. ; +44: dd begin_variant
  507. ; +48: dd end_variant
  508. ; +52: dd cur_variant_idx
  509.         call    mf_alloc
  510.         test    eax, eax
  511.         jnz     @f
  512. .ret_bad:
  513.         popad
  514.         or      eax, -1
  515.         ret     28
  516. @@:
  517.         mov     ebx, eax
  518.         mov     eax, 1
  519.         test    byte [esp+20h+28], 1
  520.         jz      @f
  521.         mov     al, 3
  522. @@:
  523.         mov     [ebx+dlgtemplate.border_size_x], eax
  524.         inc     eax
  525.         shr     eax, 1
  526.         mov     [ebx+dlgtemplate.border_size_y], eax
  527. ;  å®¤¨¬ è¨à¨­ã ¨ ¢ëá®âã ®ª­ 
  528.         xor     eax, eax
  529.         xor     ecx, ecx
  530.         mov     esi, [esp+20h+20]
  531.         mov     [ebx+36], esi
  532.         and     dword [ebx+52], 0
  533. @@:
  534.         cmp     dword [esi+4], 0
  535.         jz      .find_width
  536.         mov     esi, [esi+4]
  537.         inc     dword [ebx+52]
  538.         jmp     @b
  539. .find_width:
  540.         mov     [ebx+44], esi
  541.         add     esi, 8
  542.         push    esi
  543.         xor     edx, edx
  544. .fw1:
  545.         cmp     byte [esi], '&'
  546.         jnz     @f
  547.         mov     dl, 1
  548. @@:
  549.         inc     esi
  550.         cmp     byte [esi-1], 0
  551.         jnz     .fw1
  552.         sub     esi, [esp]
  553.         sub     esi, edx
  554.         dec     esi
  555.         cmp     eax, esi
  556.         ja      @f
  557.         mov     eax, esi
  558. @@:
  559.         inc     ecx
  560.         pop     esi
  561.         mov     esi, [esi-8]
  562.         test    esi, esi
  563.         jnz     .find_width
  564.         add     eax, 3
  565.         add     eax, [ebx+dlgtemplate.border_size_x]
  566.         add     eax, [ebx+dlgtemplate.border_size_x]
  567.         cmp     eax, [cur_width]
  568.         jb      @f
  569.         mov     eax, [cur_width]
  570. @@:
  571.         sub     eax, [ebx+dlgtemplate.border_size_x]
  572.         sub     eax, [ebx+dlgtemplate.border_size_x]
  573.         mov     [ebx+dlgtemplate.width], eax
  574.         mov     [ebx+dlgtemplate.height], ecx
  575.         mov     [ebx+40], ecx
  576.         sub     eax, [esp+20h+12]
  577.         neg     eax
  578.         sar     eax, 1
  579.         add     eax, [esp+20h+4]
  580.         cmp     eax, [ebx+dlgtemplate.border_size_x]
  581.         jge     @f
  582.         mov     eax, [ebx+dlgtemplate.border_size_x]
  583. @@:
  584.         push    eax
  585.         add     eax, [ebx+dlgtemplate.width]
  586.         add     eax, [ebx+dlgtemplate.border_size_x]
  587.         cmp     eax, [cur_width]
  588.         jbe     @f
  589.         pop     eax
  590.         mov     eax, [cur_width]
  591.         sub     eax, [ebx+dlgtemplate.width]
  592.         sub     eax, [ebx+dlgtemplate.border_size_x]
  593.         push    eax
  594. @@:
  595.         pop     [ebx+dlgtemplate.x]
  596.         sub     ecx, [esp+20h+16]
  597.         neg     ecx
  598.         sar     ecx, 1
  599.         add     ecx, [esp+20h+8]
  600.         cmp     ecx, [ebx+dlgtemplate.border_size_y]
  601.         jge     @f
  602.         mov     ecx, [ebx+dlgtemplate.border_size_y]
  603. @@:
  604.         push    ecx
  605.         add     ecx, [ebx+dlgtemplate.height]
  606.         add     ecx, [ebx+dlgtemplate.border_size_y]
  607.         cmp     ecx, [cur_height]
  608.         jbe     @f
  609.         pop     ecx
  610.         mov     ecx, [cur_height]
  611.         sub     ecx, [ebx+dlgtemplate.height]
  612.         sub     ecx, [ebx+dlgtemplate.border_size_y]
  613.         push    ecx
  614. @@:
  615.         pop     [ebx+dlgtemplate.y]
  616.         mov     eax, [cur_height]
  617.         sub     eax, 6
  618.         cmp     [ebx+dlgtemplate.height], eax
  619.         jbe     .small_height
  620.         mov     [ebx+dlgtemplate.height], eax
  621.         mov     [ebx+dlgtemplate.y], 3
  622. .small_height:
  623.         mov     ecx, [ebx+dlgtemplate.height]
  624.         mov     eax, [ebx+36]
  625.         mov     [ebx+44], eax
  626.         dec     ecx
  627.         jz      .skip
  628.         push    ecx
  629. @@:
  630.         cmp     dword [eax+4], 0
  631.         jz      @f
  632.         mov     eax, [eax+4]
  633.         loop    @b
  634. @@:
  635.         mov     [ebx+44], eax
  636.         pop     ecx
  637. .loop:
  638.         mov     eax, [eax]
  639.         loop    .loop
  640. .skip:
  641.         mov     [ebx+48], eax
  642.         mov     eax, [esp+20h+24]
  643.         mov     [ebx+dlgtemplate.title], eax
  644.         mov     al, [menu_normal_color]
  645.         mov     [ebx+dlgtemplate.main_color], al
  646.         mov     al, [menu_border_color]
  647.         mov     [ebx+dlgtemplate.border_color], al
  648.         mov     al, [menu_header_color]
  649.         mov     [ebx+dlgtemplate.header_color], al
  650.         push    MenuDlgProc
  651.         push    ebx
  652.         call    DialogBox
  653.         mov     [esp+28], eax
  654.         mov     eax, ebx
  655.         call    mf_free
  656.         popad
  657.         ret     28
  658.  
  659. MenuDlgProc:
  660.         mov     eax, [esp+4]
  661.         cmp     al, 1
  662.         jz      .draw
  663.         cmp     al, 2
  664.         jz      .key
  665.         ret     12
  666. .draw:
  667.         call    .dodraw
  668.         ret     12
  669. .key:
  670.         mov     al, [esp+8]
  671.         cmp     al, 0x48
  672.         jz      .prev
  673.         cmp     al, 0x4B
  674.         jz      .prev
  675.         cmp     al, 0x4D
  676.         jz      .next
  677.         cmp     al, 0x50
  678.         jz      .next
  679.         cmp     al, 0x1C
  680.         jz      .enter
  681.         cmp     al, 1
  682.         jz      .esc
  683.         cmp     al, 0x47
  684.         jz      .home
  685.         cmp     al, 0x4F
  686.         jz      .end
  687.         cmp     al, 0x51
  688.         jz      .pgdn
  689.         cmp     al, 0x49
  690.         jz      .pgup
  691.         mov     edx, [ebx+36]
  692. @@:
  693.         cmp     dword [edx+4], 0
  694.         jz      @f
  695.         mov     edx, [edx+4]
  696.         jmp     @b
  697. @@:
  698. .l:
  699.         lea     esi, [edx+7]
  700. @@:
  701.         inc     esi
  702.         cmp     byte [esi], 0
  703.         jz      .n
  704.         cmp     byte [esi], '&'
  705.         jnz     @b
  706.         movzx   ecx, byte [esi+1]
  707.         cmp     [ascii2scan+ecx], al
  708.         jnz     .n
  709.         mov     eax, edx
  710.         ret     12
  711. .n:
  712.         mov     edx, [edx]
  713.         test    edx, edx
  714.         jnz     .l
  715. .ret:
  716.         xor     eax, eax
  717.         ret     12
  718. .pgup:
  719.         mov     eax, [ebx+36]
  720.         mov     ecx, [ebx+dlgtemplate.height]
  721. .pgupl:
  722.         cmp     dword [eax+4], 0
  723.         jz      .posret
  724.         call    .line_prev
  725.         loop    .pgupl
  726.         jmp     .posret
  727. .prev:
  728.         mov     eax, [ebx+36]
  729.         cmp     dword [eax+4], 0
  730.         jz      .end
  731.         call    .line_prev
  732. .posret:
  733.         mov     [ebx+36], eax
  734. .redraw:
  735.         call    .dodraw
  736.         call    draw_image
  737.         xor     eax, eax
  738.         ret     12
  739. .next:
  740.         mov     eax, [ebx+36]
  741.         cmp     dword [eax], 0
  742.         jz      .home
  743.         call    .line_next
  744.         jmp     .posret
  745. .pgdn:
  746.         mov     eax, [ebx+36]
  747.         mov     ecx, [ebx+dlgtemplate.height]
  748. .pgdnl:
  749.         cmp     dword [eax], 0
  750.         jz      .posret
  751.         call    .line_next
  752.         loop    .pgdnl
  753.         jmp     .posret
  754. .home:
  755.         mov     eax, [ebx+36]
  756. @@:
  757.         cmp     dword [eax+4], 0
  758.         jz      @f
  759.         mov     eax, [eax+4]
  760.         jmp     @b
  761. @@:
  762.         mov     [ebx+44], eax
  763.         push    eax
  764.         mov     ecx, [ebx+dlgtemplate.height]
  765.         dec     ecx
  766.         jz      .h1
  767. .h2:
  768.         mov     eax, [eax]
  769.         loop    .h2
  770. .h1:
  771.         mov     [ebx+48], eax
  772.         pop     eax
  773.         and     dword [ebx+52], 0
  774.         jmp     .posret
  775. .end:
  776.         mov     eax, [ebx+36]
  777. @@:
  778.         cmp     dword [eax], 0
  779.         jz      @f
  780.         mov     eax, [eax]
  781.         jmp     @b
  782. @@:
  783.         mov     [ebx+48], eax
  784.         push    eax
  785.         mov     ecx, [ebx+dlgtemplate.height]
  786.         dec     ecx
  787.         jz      .e1
  788. .e2:
  789.         mov     eax, [eax+4]
  790.         loop    .e2
  791. .e1:
  792.         mov     [ebx+44], eax
  793.         mov     eax, [ebx+40]
  794.         dec     eax
  795.         mov     [ebx+52], eax
  796.         pop     eax
  797.         jmp     .posret
  798. .esc:
  799.         or      eax, -1
  800.         ret     12
  801. .enter:
  802.         mov     eax, [ebx+36]
  803.         ret     12
  804.  
  805. .line_prev:
  806.         cmp     eax, [ebx+44]
  807.         jnz     @f
  808.         mov     edx, [ebx+44]
  809.         mov     edx, [edx+4]
  810.         mov     [ebx+44], edx
  811.         mov     edx, [ebx+48]
  812.         mov     edx, [edx+4]
  813.         mov     [ebx+48], edx
  814. @@:
  815.         mov     eax, [eax+4]
  816.         dec     dword [ebx+52]
  817.         ret
  818. .line_next:
  819.         cmp     eax, [ebx+48]
  820.         jnz     @f
  821.         mov     edx, [ebx+44]
  822.         mov     edx, [edx]
  823.         mov     [ebx+44], edx
  824.         mov     edx, [ebx+48]
  825.         mov     edx, [edx]
  826.         mov     [ebx+48], edx
  827. @@:
  828.         mov     eax, [eax]
  829.         inc     dword [ebx+52]
  830.         ret
  831.  
  832. .dodraw:
  833.         mov     eax, [ebx+dlgtemplate.x]
  834.         mov     edx, [ebx+dlgtemplate.y]
  835.         call    get_console_ptr
  836.         mov     esi, [ebx+44]
  837. .0:
  838.         xor     edx, edx
  839.         mov     ah, [menu_selected_color]
  840.         cmp     esi, [ebx+36]
  841.         jz      @f
  842.         mov     ah, [menu_normal_color]
  843. @@:
  844.         push    edi
  845.         mov     ecx, [ebx+dlgtemplate.width]
  846.         mov     al, ' '
  847.         stosw
  848.         dec     ecx
  849.         stosw
  850.         dec     ecx
  851.         dec     ecx
  852.         push    esi
  853.         add     esi, 8
  854. @@:
  855.         lodsb
  856.         test    al, al
  857.         jz      @f
  858.         cmp     al, '&'
  859.         jnz     .noamp
  860.         test    dl, dl
  861.         jnz     .noamp
  862.         mov     dl, 1
  863.         lodsb
  864.         push    eax
  865.         mov     ah, [menu_selected_highlight_color]
  866.         push    ecx
  867.         mov     ecx, [esp+8]
  868.         cmp     ecx, [ebx+36]
  869.         pop     ecx
  870.         jz      .amp1
  871.         mov     ah, [menu_highlight_color]
  872. .amp1:
  873.         stosw
  874.         pop     eax
  875.         jmp     .amp2
  876. .noamp:
  877.         stosw
  878. .amp2:
  879.         loop    @b
  880.         mov     al, ' '
  881.         cmp     byte [esi], 0
  882.         jnz     .1
  883.         lodsb
  884.         jmp     .1
  885. @@:
  886.         mov     al, ' '
  887. .1:
  888.         stosw
  889.         mov     al, ' '
  890.         rep     stosw
  891.         pop     esi edi
  892.         add     edi, [cur_width]
  893.         add     edi, [cur_width]
  894.         cmp     esi, [ebx+48]
  895.         jz      @f
  896.         mov     esi, [esi]
  897.         test    esi, esi
  898.         jnz     .0
  899. @@:
  900. ; ‹¨­¥©ª  ¯à®ªàã⪨
  901.         mov     ecx, [ebx+dlgtemplate.height]
  902.         cmp     ecx, [ebx+40]
  903.         jz      .noscrollbar
  904.         sub     ecx, 2
  905.         jbe     .noscrollbar
  906.         mov     eax, [ebx+52]
  907.         mul     ecx
  908.         div     dword [ebx+40]
  909.         push    eax
  910.         mov     eax, [ebx+dlgtemplate.x]
  911.         add     eax, [ebx+dlgtemplate.width]
  912.         mov     edx, [ebx+dlgtemplate.y]
  913.         call    get_console_ptr
  914.         pop     edx
  915.         inc     edx
  916.         mov     al, 0x1E
  917.         mov     ah, [menu_scrollbar_color]
  918.         mov     [edi], ax
  919.         add     edi, [cur_width]
  920.         add     edi, [cur_width]
  921. .2:
  922.         mov     al, 0xB2
  923.         dec     edx
  924.         jz      @f
  925.         mov     al, 0xB0
  926. @@:
  927.         mov     [edi], ax
  928.         add     edi, [cur_width]
  929.         add     edi, [cur_width]
  930.         loop    .2
  931.         mov     al, 0x1F
  932.         stosw
  933. .noscrollbar:
  934.         ret
  935.