Subversion Repositories Kolibri OS

Rev

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

  1. ; ”㭪樨 à ¡®âë á ª®­á®«ìî ¤«ï ¯à®£à ¬¬ Š®«¨¡à¨Ž‘
  2. ; diamond, 2006-2008
  3.  
  4.  
  5. format MS COFF
  6.  
  7. public EXPORTS
  8.  
  9. section '.flat' code readable align 16
  10.  
  11. include 'font.inc'
  12. include 'conscrl.inc'
  13.  
  14. ;void __stdcall START(dword state);
  15. START:
  16. ; N.B. The current kernel implementation does not require
  17. ;      evident heap initialization, because if DLL is loaded, heap is already initialized
  18. ;      (if heap was not initialized, loader does this implicitly).
  19. ;      So this action does nothing useful, but nothing harmful.
  20.         push    68
  21.         pop     eax
  22.         push    11
  23.         pop     ebx
  24.         int     0x40
  25.         or      eax, -1
  26.         ret     4
  27.  
  28. ; ˆ­¨æ¨ «¨§ æ¨ï ª®­á®«¨
  29. ; void __stdcall con_init(dword wnd_width, dword wnd_height,
  30. ;       dword scr_width, dword scr_height, const char* title);
  31.  
  32. align 4
  33. con_init:
  34.         pop     eax
  35.         pop     [con.wnd_width]
  36.         pop     [con.wnd_height]
  37.         pop     [con.scr_width]
  38.         pop     [con.scr_height]
  39.         pop     [con.title]
  40.         push    eax
  41.         mov     ecx, 4
  42.         mov     eax, con.wnd_width
  43.         mov     esi, con.def_wnd_width
  44. .1:
  45.         cmp     dword [eax], -1
  46.         jnz     @f
  47.         mov     ebx, [esi]
  48.         mov     [eax], ebx
  49. @@:
  50.         add     eax, 4
  51.         add     esi, 4
  52.         loop    .1
  53.         push    ebx
  54. ; allocate memory for console data & bitmap data
  55.         mov     eax, [con.scr_width]
  56.         mul     [con.scr_height]
  57.         lea     ecx, [eax+eax]
  58.         mov     eax, [con.wnd_width]
  59.         mul     [con.wnd_height]
  60.         imul    eax, font_width*font_height
  61.         mov     ebx, eax
  62.         push    ebx ecx
  63.         add     ecx, eax
  64.         push    68
  65.         pop     eax
  66.         push    12
  67.         pop     ebx
  68.         int     0x40
  69.         pop     ecx ebx
  70.         mov     edx, con.nomem_err
  71.         test    eax, eax
  72.         jz      con.fatal
  73.         mov     [con.data], eax
  74.         push    edi
  75.         mov     edi, eax
  76.         shr     ecx, 1
  77.         mov     ax, 0x0720
  78.         rep     stosw
  79.         mov     ecx, ebx
  80.         mov     [con.image], edi
  81.         xor     eax, eax
  82.         rep     stosb
  83.         pop     edi
  84.         and     byte [con_flags+1], not 2
  85. ; create console thread
  86.         push    51
  87.         pop     eax
  88.         xor     ebx, ebx
  89.         inc     ebx
  90.         mov     ecx, con.thread
  91.         mov     edx, con.stack_top
  92.         int     0x40
  93.         mov     edx, con.thread_err
  94.         test    eax, eax
  95.         js      con.fatal
  96.         mov     [con.console_tid], eax
  97.         pop     ebx
  98.         ret
  99. con.fatal:
  100. ; output string to debug board and die
  101.         mov     cl, [edx]
  102.         test    cl, cl
  103.         jz      @f
  104.         push    63
  105.         pop     eax
  106.         xor     ebx, ebx
  107.         inc     ebx
  108.         int     0x40
  109.         inc     edx
  110.         jmp     con.fatal
  111. @@:
  112.         or      eax, -1
  113.         int     0x40
  114.  
  115. ; dword __stdcall con_get_flags(void);
  116. con_get_flags:
  117.         mov     eax, [con_flags]
  118.         ret
  119.  
  120. ; dword __stdcall con_set_flags(dword flags);
  121. con_set_flags:
  122.         mov     eax, [esp+4]
  123.         and     ah, not 2
  124.         xchg    eax, [con_flags]
  125.         ret     4
  126.  
  127. ; dword __stdcall con_get_font_height(void);
  128. con_get_font_height:
  129.         mov     eax, font_height
  130.         ret
  131.  
  132. ; int __stdcall con_get_cursor_height(void);
  133. con_get_cursor_height:
  134.         mov     eax, [con.cursor_height]
  135.         ret
  136.  
  137. ; int __stdcall con_set_cursor_height(int new_height);
  138. con_set_cursor_height:
  139.         mov     eax, [esp+4]
  140.         cmp     eax, font_height
  141.         jae     @f
  142.         xchg    eax, [con.cursor_height]
  143.         ret     4
  144. @@:
  145.         mov     eax, [con.cursor_height]
  146.         ret     4
  147.  
  148. ; void __stdcall con_write_asciiz(const char* string);
  149. con_write_asciiz:
  150.         push    ebx esi
  151.         or      ebx, -1
  152.         mov     esi, [esp+12]
  153.         call    con.write
  154.         pop     esi ebx
  155.         ret     4
  156.  
  157. ; void __stdcall con_write_string(const char* string, dword length);
  158. con_write_length:
  159.         push    ebx esi
  160.         mov     esi, [esp+12]
  161.         mov     ebx, [esp+16]
  162.         call    con.write
  163.         pop     esi ebx
  164.         ret     8
  165.  
  166. ; Š ¦¤ë© ᨬ¢®« ª« áá¨ä¨æ¨àã¥âáï ª ª ®¤¨­ ¨§
  167. con.printfc.normal = 0   ; ­®à¬ «ì­ë© ᨬ¢®«
  168. con.printfc.percent = 1  ; '%'
  169. con.printfc.dot = 2      ; '.'
  170. con.printfc.asterisk = 3 ; '*'
  171. con.printfc.zero = 4     ; '0'
  172. con.printfc.digit = 5    ; ­¥­ã«¥¢ ï æ¨äà 
  173. con.printfc.plus = 6     ; '+'
  174. con.printfc.minus = 7    ; '-'
  175. con.printfc.sharp = 8    ; '#'
  176. con.printfc.space = 9    ; ' '
  177. con.printfc.long = 10    ; 'l' for 'long'
  178. con.printfc.short = 11   ; 'h' for 'short'
  179. con.printfc.dec = 12     ; 'd' = print decimal
  180. con.printfc.oct = 13     ; 'o' = print octal
  181. con.printfc.unsigned = 14 ; 'u' = print unsigned decimal
  182. con.printfc.hex = 15     ; 'x' = print hexadecimal
  183. con.printfc.pointer = 16 ; 'p' = print pointer
  184. con.printfc.char = 17    ; 'c' = print char
  185. con.printfc.string = 18  ; 's' = print string
  186.  
  187. macro set char,type
  188. {store byte con.printfc.#type at con.charcodes + char - ' '}
  189.  
  190. con.charcodes:
  191. times 'x'-' '+1         db      con.printfc.normal
  192.         set     '%', percent
  193.         set     '.', dot
  194.         set     '*', asterisk
  195.         set     '0', zero
  196.         set     '1', digit
  197.         set     '2', digit
  198.         set     '3', digit
  199.         set     '4', digit
  200.         set     '5', digit
  201.         set     '6', digit
  202.         set     '7', digit
  203.         set     '8', digit
  204.         set     '9', digit
  205.         set     ' ', space
  206.         set     '#', sharp
  207.         set     '+', plus
  208.         set     '-', minus
  209.         set     'X', hex
  210.         set     'x', hex
  211.         set     'c', char
  212.         set     'd', dec
  213.         set     'h', short
  214.         set     'i', dec
  215.         set     'l', long
  216.         set     'o', oct
  217.         set     'p', pointer
  218.         set     's', string
  219.         set     'u', unsigned
  220. purge set
  221. align 4
  222. con.charjump    dd      con_printf.normal
  223.         dd      con_printf.percent
  224.         dd      con_printf.dot
  225.         dd      con_printf.asterisk
  226.         dd      con_printf.zero
  227.         dd      con_printf.digit
  228.         dd      con_printf.plus
  229.         dd      con_printf.minus
  230.         dd      con_printf.sharp
  231.         dd      con_printf.space
  232.         dd      con_printf.long
  233.         dd      con_printf.short
  234.         dd      con_printf.dec
  235.         dd      con_printf.oct
  236.         dd      con_printf.unsigned
  237.         dd      con_printf.hex
  238.         dd      con_printf.pointer
  239.         dd      con_printf.char
  240.         dd      con_printf.string
  241.  
  242. ; int __cdecl con_printf(const char* format, ...)
  243. con_printf:
  244.         xor     eax, eax
  245.         pushad
  246.         call    con.get_data_ptr
  247.         lea     ebp, [esp+20h+8]
  248.         mov     esi, [ebp-4]
  249.         sub     esp, 64         ; reserve space for buffer
  250. .loop:
  251.         xor     eax, eax
  252.         lodsb
  253.         test    al, al
  254.         jz      .done
  255.         cmp     al, '%'
  256.         jz      .spec_begin
  257. .normal:
  258.         call    con.write_char_ex
  259.         inc     dword [esp+64+28]
  260.         jmp     .loop
  261. .errspec:
  262. .percent:
  263.         add     esp, 12
  264.         jmp     .normal
  265. .spec_begin:
  266.         xor     ebx, ebx
  267. ; bl = ⨯ ¯®§¨æ¨¨:
  268. ; 0 = ­ ç «®
  269. ; 1 = ¯à®ç¨â ­ ¢¥¤ã騩 0 ¢ ᯥæ¨ä¨ª æ¨¨ ä®à¬ â 
  270. ; 2 = ç¨â ¥¬ ¯®«¥ è¨à¨­ë
  271. ; 3 = ç¨â ¥¬ ¯®«¥ â®ç­®áâ¨
  272. ; 4 = ¯à®ç¨â ­® ¯®«¥ à §¬¥à   à£ã¬¥­â 
  273. ; 5 = ç¨â ¥¬ ¯®«¥ ⨯ 
  274. ; bh = ä« £¨:
  275. ; 1 = ä« £ '#', ¢ë¢®¤¨âì 0/0x/0X
  276. ; 2 = ä« £ '-', ¢ëà ¢­¨¢ ­¨¥ ¢«¥¢®
  277. ; 4 = ä« £ '0', ¤®¯®«­¥­¨¥ ­ã«ï¬¨
  278. ; 8 = ä« £ 'h', ª®à®âª¨©  à£ã¬¥­â
  279.         push    -1
  280. ; dword [esp+8] = precision
  281.         push    -1
  282. ; dword [esp+4] = width
  283.         push    0
  284. ; byte [esp] = ä« £ 0/'+'/' '
  285. .spec:
  286.         xor     eax, eax
  287.         lodsb
  288.         test    al, al
  289.         jz      .done
  290.         cmp     al, ' '
  291.         jb      .normal
  292.         cmp     al, 'x'
  293.         ja      .normal
  294.         movzx   ecx, byte [con.charcodes + eax - ' ']
  295.         jmp     [con.charjump + ecx*4]
  296.  
  297. .sharp:
  298.         test    bl, bl
  299.         jnz     .errspec
  300.         or      bh, 1
  301.         jmp     .spec
  302. .minus:
  303.         test    bl, bl
  304.         jnz     .errspec
  305.         or      bh, 2
  306.         jmp     .spec
  307. .plus:
  308. .space:
  309.         test    bl, bl
  310.         jnz     .errspec
  311.         cmp     byte [esp], '+'
  312.         jz      .spec
  313.         mov     byte [esp], al
  314.         jmp     .spec
  315. .zero:
  316.         test    bl, bl
  317.         jnz     .digit
  318.         test    bh, 2
  319.         jnz     .spec
  320.         or      bh, 4
  321.         inc     ebx
  322.         jmp     .spec
  323. .digit:
  324.         sub     al, '0'
  325.         cmp     bl, 2
  326.         ja      .precision
  327.         mov     bl, 2
  328.         xchg    eax, [esp+4]
  329.         test    eax, eax
  330.         js      .spec
  331.         lea     eax, [eax*5]
  332.         add     eax, eax
  333.         add     [esp+4], eax
  334.         jmp     .spec
  335. .precision:
  336.         cmp     bl, 3
  337.         jnz     .errspec
  338.         xchg    eax, [esp+8]
  339.         lea     eax, [eax*5]
  340.         add     eax, eax
  341.         add     [esp+8], eax
  342.         jmp     .spec
  343. .asterisk:
  344.         mov     eax, [ebp]
  345.         add     ebp, 4
  346.         cmp     bl, 2
  347.         ja      .asterisk_precision
  348.         test    eax, eax
  349.         jns     @f
  350.         neg     eax
  351.         or      bh, 2
  352. @@:
  353.         mov     [esp+4], eax
  354.         mov     bl, 3
  355.         jmp     .spec
  356. .asterisk_precision:
  357.         cmp     bl, 3
  358.         jnz     .errspec
  359.         mov     [esp+8], eax
  360.         inc     ebx
  361.         jmp     .spec
  362. .dot:
  363.         cmp     bl, 2
  364.         ja      .errspec
  365.         mov     bl, 3
  366.         and     dword [esp+8], 0
  367.         jmp     .spec
  368. .long:
  369.         cmp     bl, 3
  370.         ja      .errspec
  371.         mov     bl, 4
  372.         jmp     .spec
  373. .short:
  374.         cmp     bl, 3
  375.         ja      .errspec
  376.         mov     bl, 4
  377.         or      bh, 8
  378.         jmp     .spec
  379. .unsigned:
  380. .dec:
  381.         push    10
  382.         jmp     .write_number
  383. .pointer:
  384.         mov     dword [esp+12], 8
  385.         or      bh, 4
  386.         and     bh, not 8
  387. .hex:
  388.         push    16
  389.         jmp     @f
  390. .oct:
  391.         push    8
  392. @@:
  393.         mov     byte [esp+4], 0
  394. .write_number:
  395.         pop     ecx
  396.         push    edi
  397.         lea     edi, [esp+16+64-1]      ; edi -> end of buffer
  398.         mov     byte [edi], 0
  399.         push    edx
  400.         push    eax
  401.         mov     eax, [ebp]
  402.         add     ebp, 4
  403.         test    bh, 8
  404.         jz      @f
  405.         movzx   eax, ax
  406.         cmp     byte [esp], 'd'
  407.         jnz     @f
  408.         movsx   eax, ax
  409. @@:
  410.         xor     edx, edx
  411.         test    eax, eax
  412.         jns     @f
  413.         cmp     byte [esp], 'd'
  414.         jnz     @f
  415.         inc     edx
  416.         neg     eax
  417. @@:
  418.         push    edx
  419.         xor     edx, edx
  420. ; ç¨á«® ¢ eax, ®á­®¢ ­¨¥ á¨á⥬ë áç¨á«¥­¨ï ¢ ecx
  421. @@:
  422.         cmp     dword [esp+16+8], 0
  423.         jnz     .print_num
  424.         test    eax, eax
  425.         jz      .zeronum
  426. .print_num:
  427.         div     ecx
  428.         xchg    eax, edx
  429.         cmp     al, 10
  430.         sbb     al, 69h
  431.         das
  432.         cmp     byte [esp+4], 'x'
  433.         jnz     @f
  434.         or      al, 20h
  435. @@:
  436.         dec     edi
  437.         mov     [edi], al
  438.         xor     eax, eax
  439.         xchg    eax, edx
  440.         test    eax, eax
  441.         jnz     .print_num
  442. .zeronum:
  443.         push    0
  444.         mov     edx, [esp+12]
  445.         lea     eax, [esp+32+64-1]
  446.         sub     eax, edi
  447.         cmp     dword [esp+20+8], -1
  448.         jz      .noprec1
  449.         cmp     eax, [esp+20+8]
  450.         jae     .len_found1
  451.         mov     eax, [esp+20+8]
  452.         jmp     .len_found1
  453. .noprec1:
  454.         test    bh, 4
  455.         jnz     .do_print_num
  456. .len_found1:
  457.         test    bh, 2
  458.         jnz     .do_print_num
  459.         cmp     byte [esp+20], 0
  460.         jz      @f
  461.         inc     eax
  462. @@:
  463.         cmp     byte [esp+20], 0
  464.         jnz     @f
  465.         cmp     byte [esp+4], 0
  466.         jz      @f
  467.         inc     eax
  468. @@:
  469.         test    bh, 1
  470.         jz      .nosharp1
  471.         cmp     cl, 8
  472.         jnz     @f
  473.         inc     eax
  474.         jmp     .nosharp1
  475. @@:
  476.         cmp     cl, 16
  477.         jnz     .nosharp1
  478.         inc     eax
  479.         inc     eax
  480. .nosharp1:
  481.         cmp     dword [esp+20+4], -1
  482.         jz      .do_print_num
  483.         sub     eax, [esp+20+4]
  484.         jae     .do_print_num
  485.         push    ecx
  486.         mov     ecx, eax
  487.         mov     al, ' '
  488. @@:
  489.         xchg    edi, [esp+20]
  490.         call    con.write_char_ex
  491.         inc     dword [esp+24+12+64+28]
  492.         xchg    edi, [esp+20]
  493.         inc     dword [esp+4]
  494.         inc     ecx
  495.         jnz     @b
  496.         pop     ecx
  497. .do_print_num:
  498.         mov     al, '-'
  499.         cmp     byte [esp+4], 0
  500.         jnz     .write_sign
  501.         mov     al, [esp+20]
  502.         test    al, al
  503.         jz      .sign_written
  504. .write_sign:
  505.         call    .num_write_char
  506. .sign_written:
  507.         test    bh, 1
  508.         jz      .nosharp2
  509.         mov     al, '0'
  510.         cmp     cl, 8
  511.         jz      @f
  512.         cmp     cl, 16
  513.         jnz     .nosharp2
  514.         call    .num_write_char
  515.         mov     al, [esp+8]
  516. @@:
  517.         call    .num_write_char
  518. .nosharp2:
  519.         lea     ecx, [esp+32+64-1]
  520.         sub     ecx, edi
  521.         cmp     dword [esp+20+8], -1
  522.         jz      .noprec2
  523.         sub     ecx, [esp+20+8]
  524.         jmp     .lead_zeroes
  525. .noprec2:
  526.         test    bh, 4
  527.         jz      .do_print_num2
  528.         add     ecx, [esp]
  529.         sub     ecx, [esp+20+4]
  530. .lead_zeroes:
  531.         jae     .do_print_num2
  532. @@:
  533.         mov     al, '0'
  534.         call    .num_write_char
  535.         inc     ecx
  536.         jnz     @b
  537. .do_print_num2:
  538.         mov     al, [edi]
  539.         test    al, al
  540.         jz      .num_written
  541.         call    .num_write_char
  542.         inc     edi
  543.         jmp     .do_print_num2
  544. .num_written:
  545.         pop     ecx
  546.         mov     edi, [esp+12]
  547.         cmp     dword [esp+16+4], -1
  548.         jz      .num_written2
  549. @@:
  550.         cmp     ecx, [esp+16+4]
  551.         jae     .num_written2
  552.         mov     al, ' '
  553.         call    con.write_char
  554.         inc     ecx
  555.         jmp     @b
  556. .num_written2:
  557.         add     esp, 16
  558. .spec_done:
  559.         add     esp, 12
  560.         jmp     .loop
  561. .char:
  562.         mov     ecx, [esp+4]
  563.         cmp     ecx, -1
  564.         jnz     @f
  565.         inc     ecx
  566. @@:
  567.         test    ecx, ecx
  568.         jnz     @f
  569.         inc     ecx
  570. @@:
  571.         test    bh, 2
  572.         jnz     .char_left_pad
  573.         mov     al, ' '
  574.         dec     ecx
  575.         jz      .nowidth
  576.         add     [esp+12+64+28], ecx
  577. @@:
  578.         call    con.write_char
  579.         loop    @b
  580. .nowidth:
  581.         mov     al, [ebp]
  582.         add     ebp, 4
  583.         jmp     .percent
  584. .char_left_pad:
  585.         mov     al, [ebp]
  586.         add     ebp, 4
  587.         call    con.write_char_ex
  588.         add     [esp+12+64+28], ecx
  589.         dec     ecx
  590.         jz      .nowidth2
  591.         mov     al, ' '
  592. @@:
  593.         call    con.write_char
  594.         loop    @b
  595. .nowidth2:
  596.         jmp     .spec_done
  597. .string:
  598.         push    esi
  599.         mov     esi, [ebp]
  600.         test    esi, esi
  601.         jnz     @f
  602.         mov     esi, con.aNull
  603. @@:
  604.         add     ebp, 4
  605.         or      ecx, -1
  606. @@:
  607.         inc     ecx
  608.         cmp     byte [esi+ecx], 0
  609.         jnz     @b
  610.         cmp     ecx, [esp+12]
  611.         jb      @f
  612.         mov     ecx, [esp+12]
  613. @@:
  614.         test    bh, 2
  615.         jnz     .write_string
  616.         cmp     dword [esp+8], -1
  617.         jz      .write_string
  618.         push    ecx
  619.         sub     ecx, [esp+12]
  620.         jae     .nospace
  621.         mov     al, ' '
  622. @@:
  623.         call    con.write_char
  624.         inc     dword [esp+20+64+28]
  625.         inc     ecx
  626.         jnz     @b
  627. .nospace:
  628.         pop     ecx
  629. .write_string:
  630.         jecxz   .string_written
  631.         add     dword [esp+16+64+28], ecx
  632.         push    ecx
  633. @@:
  634.         lodsb
  635.         call    con.write_char_ex
  636.         loop    @b
  637.         pop     ecx
  638. .string_written:
  639.         pop     esi
  640.         test    bh, 2
  641.         jz      .spec_done
  642.         cmp     dword [esp+4], -1
  643.         jz      .spec_done
  644.         sub     ecx, [esp+4]
  645.         jae     .spec_done
  646.         mov     al, ' '
  647. @@:
  648.         call    con.write_char
  649.         inc     dword [esp+12+64+28]
  650.         inc     ecx
  651.         jnz     @b
  652.         jmp     .spec_done
  653. .done:
  654.         add     esp, 64
  655.         popad
  656.         jmp     con.update_screen
  657. .num_write_char:
  658.         xchg    edi, [esp+20]
  659.         call    con.write_char_ex
  660.         inc     dword [esp+24+12+64+28]
  661.         xchg    edi, [esp+20]
  662.         inc     dword [esp+4]
  663.         ret
  664.  
  665. con.write:
  666. ; esi = string, ebx = length (ebx=-1 for ASCIIZ strings)
  667.         push    edi
  668.         call    con.get_data_ptr
  669.         test    ebx, ebx
  670.         jz      .done
  671. .loop:
  672.         lodsb
  673.         cmp     ebx, -1
  674.         jnz     @f
  675.         test    al, al
  676.         jz      .done
  677. @@:
  678.         call    con.write_char_ex
  679. .next:
  680.         cmp     ebx, -1
  681.         jz      .loop
  682.         dec     ebx
  683.         jnz     .loop
  684. .done:
  685.         pop     edi
  686.         jmp     con.update_screen
  687.  
  688. con.get_data_ptr:
  689.         mov     edi, [con.cur_y]
  690.         imul    edi, [con.scr_width]
  691.         add     edi, [con.cur_x]
  692.         add     edi, edi
  693.         add     edi, [con.data]
  694.         ret
  695.  
  696. con.write_char_ex:
  697.         test    byte [con_flags+1], 1
  698.         jz      con.write_special_char
  699.  
  700. con.write_char:
  701.         push    eax
  702.         stosb
  703.         mov     al, byte [con_flags]
  704.         stosb
  705.         mov     eax, [con.cur_x]
  706.         inc     eax
  707.         mov     [con.cur_x], eax
  708.         cmp     eax, [con.scr_width]
  709.         jb      @f
  710.         and     [con.cur_x], 0
  711.         call    con.newline
  712. @@:
  713.         pop     eax
  714.         ret
  715.  
  716. con.write_special_char:
  717.         cmp     [con_esc], 0
  718.         jnz     .esc_mode
  719. .normal_mode:
  720.         cmp     al, 10
  721.         jz      .write_lf
  722.         cmp     al, 13
  723.         jz      .write_cr
  724.         cmp     al, 27
  725.         jz      .write_esc
  726.         cmp     al, 8
  727.         jz      .write_bs
  728.         cmp     al, 9
  729.         jnz     con.write_char
  730. .write_tab:
  731.         mov     al, ' '
  732.         call    con.write_char
  733.         test    [con.cur_x], 7
  734.         jnz     .write_tab
  735.         ret
  736. .write_cr:
  737.         and     [con.cur_x], 0
  738.         jmp     con.get_data_ptr
  739. .write_lf:
  740.         and     [con.cur_x], 0
  741.         jmp     con.newline
  742. .write_bs:
  743.         cmp     [con.cur_x], 0
  744.         jz      @f
  745.         dec     [con.cur_x]
  746.         dec     edi
  747.         dec     edi
  748.         ret
  749. @@:
  750.         push    eax
  751.         mov     eax, [con.cur_y]
  752.         dec     eax
  753.         js      @f
  754.         mov     [con.cur_y], eax
  755.         mov     eax, [con.scr_width]
  756.         dec     eax
  757.         mov     [con.cur_x], eax
  758.         dec     edi
  759.         dec     edi
  760. @@:
  761.         pop     eax
  762.         ret
  763. .write_esc:
  764.         mov     [con_esc], 1
  765.         mov     [con_esc_attr_n], 1
  766.         and     [con_esc_attrs], 0
  767.         ret
  768. .esc_mode:
  769.         cmp     [con_sci], 0
  770.         jnz     .esc_sci
  771.         cmp     al, '['
  772.         jnz     @f
  773.         mov     [con_sci], 1
  774.         ret
  775. @@:
  776.         push    eax
  777.         mov     al, 27
  778.         call    con.write_char
  779.         pop     eax
  780.         jmp     con.write_char
  781. .esc_sci:
  782. ; this is real Esc sequence
  783.         cmp     al, ';'
  784.         jz      .next_arg
  785.         cmp     al, '0'
  786.         jb      .not_digit
  787.         cmp     al, '9'
  788.         ja      .not_digit
  789.         push    eax ecx edx
  790.         sub     al, '0'
  791.         movzx   eax, al
  792.         mov     ecx, [con_esc_attr_n]
  793.         mov     edx, [con_esc_attrs+(ecx-1)*4]
  794.         lea     edx, [edx*5]
  795.         lea     edx, [edx*2+eax]
  796.         mov     [con_esc_attrs+(ecx-1)*4], edx
  797.         pop     edx ecx eax
  798.         ret
  799. .next_arg:
  800.         push    eax
  801.         mov     eax, [con_esc_attr_n]
  802.         inc     eax
  803.         cmp     al, 4
  804.         jbe     @f
  805.         dec     eax
  806. @@:
  807.         mov     [con_esc_attr_n], eax
  808.         and     [con_esc_attrs+(eax-1)*4], 0
  809.         pop     eax
  810.         ret
  811. .not_digit:
  812.         mov     [con_esc], 0
  813.         mov     [con_sci], 0    ; in any case, leave Esc mode
  814.         cmp     al, 'J'
  815.         jz      .cls
  816.         cmp     al, 'H'
  817.         jz      .setcursor
  818.         cmp     al, 'f'
  819.         jz      .setcursor
  820.         cmp     al, 'm'
  821.         jz      .set_attr
  822.         cmp     al, 'A'
  823.         jz      .cursor_up
  824.         cmp     al, 'B'
  825.         jz      .cursor_down
  826.         cmp     al, 'C'
  827.         jz      .cursor_right
  828.         cmp     al, 'D'
  829.         jz      .cursor_left
  830.         ret     ; simply skip unknown sequences
  831. .cls:
  832.         push    ecx
  833.         and     [con.cur_x], 0
  834.         and     [con.cur_y], 0
  835.         mov     edi, [con.data]
  836.         push    edi
  837.         mov     ecx, [con.scr_width]
  838.         imul    ecx, [con.scr_height]
  839.         mov     ax, 0720h
  840.         rep     stosw
  841.         pop     edi ecx
  842. .nosetcursor:
  843.         ret
  844. .setcursor:
  845.         cmp     [con_esc_attr_n], 2
  846.         jnz     .nosetcursor
  847.         mov     eax, [con_esc_attrs]
  848.         cmp     eax, [con.scr_width]
  849.         jae     @f
  850.         mov     [con.cur_x], eax
  851. @@:
  852.         mov     eax, [con_esc_attrs+4]
  853.         cmp     eax, [con.scr_height+4]
  854.         jae     @f
  855.         mov     [con.cur_y], eax
  856. .j_get_data:
  857.         jmp     con.get_data_ptr
  858. .cursor_up:
  859.         cmp     [con_esc_attr_n], 1
  860.         jnz     .nosetcursor
  861.         mov     eax, [con.cur_y]
  862.         sub     eax, [con_esc_attrs]
  863.         jnc     @f
  864.         xor     eax, eax
  865. @@:
  866.         mov     [con.cur_y], eax
  867.         jmp     .j_get_data
  868. .cursor_down:
  869.         cmp     [con_esc_attr_n], 1
  870.         jnz     .nosetcursor
  871.         mov     eax, [con.cur_y]
  872.         add     eax, [con_esc_attrs]
  873.         cmp     eax, [con.scr_height]
  874.         jb      @f
  875.         mov     eax, [con.scr_height]
  876.         dec     eax
  877. @@:
  878.         mov     [con.cur_y], eax
  879.         jmp     .j_get_data
  880. .cursor_right:
  881.         cmp     [con_esc_attr_n], 1
  882.         jnz     .nosetcursor
  883.         mov     eax, [con.cur_x]
  884.         add     eax, [con_esc_attrs]
  885.         cmp     eax, [con.scr_width]
  886.         jb      @f
  887.         mov     eax, [con.scr_width]
  888.         dec     eax
  889. @@:
  890.         mov     [con.cur_x], eax
  891.         jmp     .j_get_data
  892. .cursor_left:
  893.         cmp     [con_esc_attr_n], 1
  894.         jnz     .nosetcursor
  895.         mov     eax, [con.cur_x]
  896.         sub     eax, [con_esc_attrs]
  897.         jnc     @f
  898.         xor     eax, eax
  899. @@:
  900.         mov     [con.cur_x], eax
  901.         jmp     .j_get_data
  902. .set_attr:
  903.         push    eax ecx edx
  904.         xor     ecx, ecx
  905. .set_one_attr:
  906.         mov     eax, [con_esc_attrs+ecx*4]
  907.         cmp     al, 0
  908.         jz      .attr_normal
  909.         cmp     al, 1
  910.         jz      .attr_bold
  911.         cmp     al, 5
  912.         jz      .attr_bgr_bold
  913.         cmp     al, 7
  914.         jz      .attr_reversed
  915.         xor     edx, edx
  916.         cmp     al, 30
  917.         jz      .attr_color
  918.         mov     dl, 4
  919.         cmp     al, 31
  920.         jz      .attr_color
  921.         mov     dl, 2
  922.         cmp     al, 32
  923.         jz      .attr_color
  924.         mov     dl, 6
  925.         cmp     al, 33
  926.         jz      .attr_color
  927.         mov     dl, 1
  928.         cmp     al, 34
  929.         jz      .attr_color
  930.         mov     dl, 5
  931.         cmp     al, 35
  932.         jz      .attr_color
  933.         mov     dl, 3
  934.         cmp     al, 36
  935.         jz      .attr_color
  936.         mov     dl, 7
  937.         cmp     al, 37
  938.         jz      .attr_color
  939.         xor     edx, edx
  940.         cmp     al, 40
  941.         jz      .attr_bgr_color
  942.         mov     dl, 0x40
  943.         cmp     al, 41
  944.         jz      .attr_bgr_color
  945.         mov     dl, 0x20
  946.         cmp     al, 42
  947.         jz      .attr_bgr_color
  948.         mov     dl, 0x60
  949.         cmp     al, 43
  950.         jz      .attr_bgr_color
  951.         mov     dl, 0x10
  952.         cmp     al, 44
  953.         jz      .attr_bgr_color
  954.         mov     dl, 0x50
  955.         cmp     al, 45
  956.         jz      .attr_bgr_color
  957.         mov     dl, 0x30
  958.         cmp     al, 46
  959.         jz      .attr_bgr_color
  960.         mov     dl, 0x70
  961.         cmp     al, 47
  962.         jnz     .attr_continue
  963. .attr_bgr_color:
  964.         mov     eax, [con_flags]
  965.         and     al, 0x8F
  966.         or      al, dl
  967.         mov     [con_flags], eax
  968.         jmp     .attr_continue
  969. .attr_color:
  970.         mov     eax, [con_flags]
  971.         and     al, 0xF8
  972.         or      al, dl
  973.         mov     [con_flags], eax
  974.         jmp     .attr_continue
  975. .attr_normal:
  976.         mov     byte [con_flags], 7
  977.         jmp     .attr_continue
  978. .attr_reversed:
  979.         mov     byte [con_flags], 0x70
  980.         jmp     .attr_continue
  981. .attr_bold:
  982.         or      byte [con_flags], 8
  983.         jmp     .attr_continue
  984. .attr_bgr_bold:
  985.         or      byte [con_flags], 0x80
  986. .attr_continue:
  987.         inc     ecx
  988.         cmp     ecx, [con_esc_attr_n]
  989.         jb      .set_one_attr
  990.         pop     edx ecx eax
  991.         ret
  992.  
  993. con.newline:
  994.         mov     eax, [con.cur_y]
  995.         inc     eax
  996.         mov     [con.cur_y], eax
  997.         cmp     eax, [con.scr_height]
  998.         jb      @f
  999.         call    con.scr_scroll_up
  1000. @@:
  1001.         call    con.get_data_ptr
  1002.         ret
  1003.  
  1004. con.scr_scroll_up:
  1005.         pushad
  1006.         mov     edi, [con.data]
  1007.         mov     esi, edi
  1008.         add     esi, [con.scr_width]
  1009.         add     esi, [con.scr_width]
  1010.         dec     [con.cur_y]
  1011.         mov     ecx, [con.scr_height]
  1012.         dec     ecx
  1013.         imul    ecx, [con.scr_width]
  1014.         shr     ecx, 1
  1015.         rep     movsd
  1016.         adc     ecx, ecx
  1017.         rep     movsw
  1018.         mov     ax, 0x0720
  1019.         mov     ecx, [con.scr_width]
  1020.         rep     stosw
  1021.         popad
  1022.         ret
  1023.  
  1024. con.data2image:
  1025.         pushad
  1026.         mov     edi, [con.image]
  1027.         mov     esi, [con.data]
  1028.         mov     eax, [con.wnd_ypos]
  1029.         mul     [con.scr_width]
  1030.         add     eax, [con.wnd_xpos]
  1031.         lea     esi, [esi+eax*2]
  1032.         mov     ecx, [con.wnd_height]
  1033. .lh:
  1034.         push    ecx
  1035.         mov     ecx, [con.wnd_width]
  1036. .lw:
  1037.         push    ecx edi
  1038.         xor     eax, eax
  1039.         mov     al, [esi+1]
  1040.         push    eax
  1041.         and     al, 0xF
  1042.         mov     ebx, eax                ; 梥â ⥪áâ 
  1043.         pop     eax
  1044.         shr     al, 4
  1045.         mov     ebp, eax                ; 梥â ä®­ 
  1046.         sub     ebx, ebp
  1047.         lodsb
  1048.         inc     esi
  1049. if font_width > 8
  1050.         lea     edx, [eax+eax+font]
  1051. else
  1052.         lea     edx, [eax+font]
  1053. end if
  1054. .sh:
  1055.         mov     ecx, [edx]
  1056. repeat font_width
  1057.         shr     ecx, 1
  1058.         sbb     eax, eax
  1059.         and     eax, ebx
  1060.         add     eax, ebp
  1061.         mov     [edi+%-1], al
  1062. end repeat
  1063.         mov     eax, [con.wnd_width]
  1064. ;        imul    eax, font_width
  1065. ;        add     edi, eax
  1066. if font_width = 6
  1067.         lea     eax, [eax*2+eax]
  1068.         lea     edi, [edi+eax*2]
  1069. else if font_width = 7
  1070.         lea     edi, [edi+eax*8]
  1071.         sub     edi, eax
  1072. else if font_width = 8
  1073.         lea     edi, [edi+eax*8]
  1074. else if font_width = 9
  1075.         lea     edi, [edi+eax*8]
  1076.         add     edi, eax
  1077. else if font_width = 10
  1078.         lea     eax, [eax*4+eax]
  1079.         lea     edi, [edi+eax*2]
  1080. else
  1081. Unknown font_width value!
  1082. end if
  1083. if font_width > 8
  1084.         add     edx, 256*2
  1085.         cmp     edx, font+256*2*font_height
  1086. else
  1087.         add     edx, 256
  1088.         cmp     edx, font+256*font_height
  1089. end if
  1090.         jb      .sh
  1091.         pop     edi ecx
  1092.         add     edi, font_width
  1093.         sub     ecx, 1
  1094.         jnz     .lw
  1095.         mov     eax, [con.wnd_width]
  1096.         imul    eax, (font_height-1)*font_width
  1097.         add     edi, eax
  1098.         pop     ecx
  1099.         mov     eax, [con.scr_width]
  1100.         sub     eax, [con.wnd_width]
  1101.         lea     esi, [esi+eax*2]
  1102.         dec     ecx
  1103.         jnz     .lh
  1104.         mov     eax, [con.cur_y]
  1105.         sub     eax, [con.wnd_ypos]
  1106.         jb      .nocursor
  1107.         cmp     eax, [con.wnd_height]
  1108.         jae     .nocursor
  1109.         inc     eax
  1110.         mul     [con.wnd_width]
  1111.         imul    eax, font_height*font_width
  1112.         mov     edx, [con.cur_x]
  1113.         sub     edx, [con.wnd_xpos]
  1114.         jb      .nocursor
  1115.         cmp     edx, [con.wnd_width]
  1116.         jae     .nocursor
  1117.         inc     edx
  1118.         imul    edx, font_width
  1119.         add     eax, edx
  1120.         add     eax, [con.image]
  1121.         mov     edx, [con.wnd_width]
  1122.         imul    edx, font_width
  1123.         neg     edx
  1124.         mov     ecx, [con.cursor_height]
  1125.         jecxz   .nocursor
  1126. .cursor_loop:
  1127.         push    ecx
  1128.         mov     ecx, font_width
  1129.         add     eax, edx
  1130.         push    eax
  1131. @@:
  1132.         xor     byte [eax-1], 7
  1133.         dec     eax
  1134.         loop    @b
  1135.         pop     eax
  1136.         pop     ecx
  1137.         loop    .cursor_loop
  1138. .nocursor:
  1139.         popad
  1140.         ret
  1141.  
  1142. con_exit:
  1143.         cmp     byte [esp+4], 0
  1144.         jz      .noexit
  1145.         mov     [con.thread_op], 1
  1146.         call    con.wake
  1147.         ret     4
  1148. .noexit:
  1149.         push    esi
  1150.         mov     esi, [con.title]
  1151.         mov     edx, con.finished_title
  1152.         mov     ecx, 255
  1153.         call    .strcpy
  1154.         mov     esi, con.aFinished
  1155.         call    .strcpy
  1156.         mov     byte [edx], 0
  1157.         pop     esi
  1158.         and     [con.cursor_height], 0
  1159.         push    con.finished_title
  1160.         call    con_set_title
  1161.         ret     4
  1162. .strcpy:
  1163.         jecxz   .ret
  1164. @@:
  1165.         lodsb
  1166.         test    al, al
  1167.         jz      .ret
  1168.         mov     [edx], al
  1169.         inc     edx
  1170.         loop    @b
  1171. .ret:
  1172.         ret
  1173.  
  1174. con_set_title:
  1175.         mov     eax, [esp+4]
  1176.         mov     [con.title], eax
  1177.         mov     [con.thread_op], 2
  1178.         call    con.wake
  1179.         ret     4
  1180.  
  1181. ; int __stdcall con_kbhit(void);
  1182. con_kbhit:
  1183.         test    byte [con_flags+1], 2
  1184.         jnz     @f
  1185.         mov     eax, [con.input_start]
  1186.         cmp     eax, [con.input_end]
  1187. @@:
  1188.         setnz   al
  1189.         movzx   eax, al
  1190.         ret
  1191.  
  1192. con.force_entered_char:
  1193.         cmp     [con.entered_char], -1
  1194.         jnz     .ret
  1195.         mov     [con.thread_op], 4
  1196.         call    con.wake
  1197.         test    byte [con_flags+1], 2
  1198.         jnz     .ret
  1199. ; wait for response
  1200.         push    ebx
  1201.         push    5
  1202.         pop     eax
  1203.         push    2
  1204.         pop     ebx
  1205. @@:
  1206.         int     0x40
  1207.         cmp     [con.entered_char], -1
  1208.         jz      @b
  1209.         pop     ebx
  1210. .ret:
  1211.         ret
  1212.  
  1213. ; int __stdcall con_getch(void);
  1214. con_getch:
  1215.         call    con.force_entered_char
  1216.         test    byte [con_flags+1], 2
  1217.         jnz     con_getch_closed
  1218.         movzx   eax, byte [con.entered_char]
  1219.         sar     [con.entered_char], 8
  1220.         mov     byte [con.entered_char+1], 0xFF
  1221.         test    al, al
  1222.         jz      @f
  1223.         mov     byte [con.entered_char], 0xFF
  1224. @@:
  1225.         ret
  1226.  
  1227. con_getch_closed:
  1228.         or      eax, -1
  1229.         ret
  1230.  
  1231. ; int __stdcall con_getch2(void);
  1232. con_getch2:
  1233.         call    con.force_entered_char
  1234.         test    byte [con_flags+1], 2
  1235.         jnz     con_getch_closed
  1236.         mov     eax, 0xFFFF
  1237.         xchg    ax, [con.entered_char]
  1238.         ret
  1239.  
  1240. ; char* __stdcall con_gets(char* str, int n);
  1241. con_gets:
  1242.         pop     eax
  1243.         push    0
  1244.         push    eax
  1245. ; char* __stdcall con_gets2(con_gets2_callback callback, char* str, int n);
  1246. con_gets2:
  1247.         mov     eax, [esp+8]            ; str
  1248.         pushad
  1249.         mov     esi, eax                ; str
  1250.         mov     ebx, [esp+20h+12]       ; n
  1251.         sub     ebx, 1
  1252.         jle     .ret
  1253.         mov     byte [esi], 0
  1254.         xor     ecx, ecx                ; ¤«¨­  㦥 ¢¢¥¤ñ­­®© áâப¨
  1255.         call    con.get_data_ptr
  1256. .loop:
  1257.         call    con_getch2
  1258.         cmp     eax, -1
  1259.         jz      .closed
  1260.         test    al, al
  1261.         jz      .extended
  1262.         cmp     al, 8
  1263.         jz      .backspace
  1264.         cmp     al, 27
  1265.         jz      .esc
  1266.         cmp     al, 13
  1267.         jz      .enter
  1268.         cmp     al, 9
  1269.         jz      .tab
  1270.         inc     ecx
  1271.         mov     dl, al
  1272.         call    con.write_char_ex
  1273.         push    [con.cur_x]
  1274.         push    [con.cur_y]
  1275.         push    edi
  1276.         push    esi
  1277. @@:
  1278.         lodsb
  1279.         mov     [esi-1], dl
  1280.         mov     dl, al
  1281.         test    al, al
  1282.         jz      @f
  1283.         call    con.write_char_ex
  1284.         jmp     @b
  1285. @@:
  1286.         mov     [esi], dl
  1287.         pop     esi
  1288.         inc     esi
  1289.         pop     edi
  1290.         pop     [con.cur_y]
  1291.         pop     [con.cur_x]
  1292. .update_screen_and_loop:
  1293.         call    con.update_screen
  1294.         cmp     ecx, ebx
  1295.         jb      .loop
  1296. .ret_us:
  1297.         mov     edx, [con.cur_x]
  1298. @@:
  1299.         lodsb
  1300.         test    al, al
  1301.         jz      @f
  1302.         inc     edx
  1303.         cmp     edx, [con.scr_width]
  1304.         jb      @b
  1305.         xor     edx, edx
  1306.         call    con.newline
  1307.         jmp     @b
  1308. @@:
  1309.         mov     [con.cur_x], edx
  1310.         call    con.get_data_ptr
  1311.         call    con.update_screen
  1312.         jmp     .ret
  1313. .esc:
  1314.         mov     edx, [con.cur_x]
  1315. @@:
  1316.         lodsb
  1317.         test    al, al
  1318.         jz      @f
  1319.         inc     edx
  1320.         cmp     edx, [con.scr_width]
  1321.         jb      @b
  1322.         xor     edx, edx
  1323.         call    con.newline
  1324.         jmp     @b
  1325. @@:
  1326.         mov     [con.cur_x], edx
  1327.         call    con.get_data_ptr
  1328.         dec     esi
  1329.         xor     ecx, ecx
  1330. @@:
  1331.         mov     byte [esi], 0
  1332.         cmp     esi, [esp+20h+8]
  1333.         jbe     .update_screen_and_loop
  1334.         mov     al, 8
  1335.         call    con.write_special_char
  1336.         mov     al, ' '
  1337.         call    con.write_char
  1338.         mov     al, 8
  1339.         call    con.write_special_char
  1340.         dec     esi
  1341.         jmp     @b
  1342. .delete:
  1343.         cmp     byte [esi], 0
  1344.         jz      .loop
  1345.         lodsb
  1346.         call    con.write_char_ex
  1347. .backspace:
  1348.         cmp     esi, [esp+20h+8]
  1349.         jbe     .loop
  1350.         push    esi
  1351.         mov     edx, [con.cur_x]
  1352. @@:
  1353.         lodsb
  1354.         test    al, al
  1355.         jz      @f
  1356.         inc     edx
  1357.         cmp     edx, [con.scr_width]
  1358.         jb      @b
  1359.         xor     edx, edx
  1360.         call    con.newline
  1361.         jmp     @b
  1362. @@:
  1363.         mov     [con.cur_x], edx
  1364.         call    con.get_data_ptr
  1365.         dec     esi
  1366.         mov     al, 8
  1367.         call    con.write_special_char
  1368.         mov     al, ' '
  1369.         call    con.write_char
  1370.         mov     al, 8
  1371.         call    con.write_special_char
  1372.         mov     dl, 0
  1373. @@:
  1374.         cmp     esi, [esp]
  1375.         jbe     @f
  1376.         mov     al, 8
  1377.         call    con.write_special_char
  1378.         dec     esi
  1379.         xchg    dl, [esi]
  1380.         mov     al, dl
  1381.         call    con.write_char
  1382.         mov     al, 8
  1383.         call    con.write_special_char
  1384.         jmp     @b
  1385. @@:
  1386.         pop     esi
  1387.         dec     esi
  1388.         mov     [esi], dl
  1389.         dec     ecx
  1390.         jmp     .update_screen_and_loop
  1391. .enter:
  1392.         mov     edx, [con.cur_x]
  1393. @@:
  1394.         lodsb
  1395.         test    al, al
  1396.         jz      @f
  1397.         inc     edx
  1398.         cmp     edx, [con.scr_width]
  1399.         jb      @b
  1400.         xor     edx, edx
  1401.         call    con.newline
  1402.         jmp     @b
  1403. @@:
  1404.         mov     [con.cur_x], edx
  1405.         call    con.get_data_ptr
  1406.         mov     al, 10
  1407.         mov     [esi-1], al
  1408.         mov     byte [esi], 0
  1409.         call    con.write_special_char
  1410.         call    con.update_screen
  1411.         jmp     .ret
  1412. .tab:
  1413.         mov     al, 0
  1414.         mov     ah, 0xF
  1415. .extended:
  1416.         xchg    al, ah
  1417.         cmp     al, 0x4B
  1418.         jz      .left
  1419.         cmp     al, 0x4D
  1420.         jz      .right
  1421.         cmp     al, 0x47
  1422.         jz      .home
  1423.         cmp     al, 0x4F
  1424.         jz      .end
  1425.         cmp     al, 0x53
  1426.         jz      .delete
  1427. ; give control to callback function
  1428.         cmp     dword [esp+20h+4], 0
  1429.         jz      .loop
  1430. ; remember length of text before and length of text after
  1431. ; and advance cursor to the end of line
  1432.         push    ecx
  1433.         push    eax
  1434.         lea     edx, [esi+1]
  1435. @@:
  1436.         lodsb
  1437.         test    al, al
  1438.         jz      @f
  1439.         call    con.write_char_ex
  1440.         jmp     @b
  1441. @@:
  1442.         sub     esi, edx
  1443.         pop     eax
  1444.         push    esi
  1445.         dec     edx
  1446.         sub     edx, [esp+28h+8]
  1447.         push    edx
  1448.         push    esp             ; ppos
  1449.         mov     ecx, [esp+30h+4]
  1450.         lea     edx, [esp+30h+12]
  1451.         push    edx             ; pn
  1452.         lea     edx, [esp+34h+8]
  1453.         push    edx             ; pstr
  1454.         push    eax             ; keycode
  1455.         call    ecx
  1456.         call    con.get_data_ptr
  1457.         dec     eax
  1458.         js      .callback_nochange
  1459.         jz      .callback_del
  1460.         dec     eax
  1461.         jz      .callback_output
  1462. ; callback returned 2 - exit
  1463.         add     esp, 12
  1464.         jmp     .ret
  1465. .callback_nochange:
  1466. ; callback returned 0 - string was not changed, only restore cursor position
  1467.         pop     esi
  1468.         pop     ecx
  1469.         test    ecx, ecx
  1470.         jz      .cncs
  1471. @@:
  1472.         mov     al, 8
  1473.         call    con.write_special_char
  1474.         loop    @b
  1475. .cncs:
  1476.         pop     ecx
  1477.         add     esi, [esp+20h+8]
  1478.         jmp     .callback_done
  1479. .callback_del:
  1480. ; callback returned 1 - string was changed, delete old string and output new
  1481.         mov     ecx, [esp+8]
  1482.         test    ecx, ecx
  1483.         jz      .cds
  1484. @@:
  1485.         mov     al, 8
  1486.         call    con.write_special_char
  1487.         mov     al, ' '
  1488.         call    con.write_char_ex
  1489.         mov     al, 8
  1490.         call    con.write_special_char
  1491.         loop    @b
  1492. .cds:
  1493. .callback_output:
  1494. ; callback returned 2 - string was changed, output new string
  1495.         pop     edx
  1496.         pop     esi
  1497.         pop     ecx
  1498.         mov     esi, [esp+20h+8]
  1499.         xor     ecx, ecx
  1500. @@:
  1501.         lodsb
  1502.         test    al, al
  1503.         jz      @f
  1504.         call    con.write_char_ex
  1505.         inc     ecx
  1506.         jmp     @b
  1507. @@:
  1508.         dec     esi
  1509.         push    ecx
  1510.         sub     ecx, edx
  1511.         jz      .cos
  1512. @@:
  1513.         mov     al, 8
  1514.         call    con.write_special_char
  1515.         dec     esi
  1516.         loop    @b
  1517. .cos:
  1518.         pop     ecx
  1519. .callback_done:
  1520.         call    con.update_screen
  1521.         mov     ebx, [esp+20h+12]
  1522.         dec     ebx
  1523.         cmp     ecx, ebx
  1524.         jae     .ret_us
  1525.         jmp     .loop
  1526. .left:
  1527.         cmp     esi, [esp+20h+8]
  1528.         jbe     .loop
  1529.         dec     esi
  1530.         mov     al, 8
  1531.         call    con.write_special_char
  1532.         jmp     .update_screen_and_loop
  1533. .right:
  1534.         cmp     byte [esi], 0
  1535.         jz      .loop
  1536.         lodsb
  1537.         call    con.write_char_ex
  1538.         jmp     .update_screen_and_loop
  1539. .home:
  1540.         cmp     esi, [esp+20h+8]
  1541.         jz      .update_screen_and_loop
  1542.         dec     esi
  1543.         mov     al, 8
  1544.         call    con.write_special_char
  1545.         jmp     .home
  1546. .end:
  1547.         lodsb
  1548.         test    al, al
  1549.         jz      @f
  1550.         call    con.write_char_ex
  1551.         jmp     .end
  1552. @@:
  1553.         dec     esi
  1554.         jmp     .update_screen_and_loop
  1555. .closed:
  1556.         and     dword [esp+1Ch], 0
  1557. .ret:
  1558.         popad
  1559.         ret     12
  1560.  
  1561. ; void __stdcall con_cls();
  1562. con_cls:
  1563.         push    edi
  1564.         call    con.write_special_char.cls
  1565.         pop     edi
  1566.         call    con.update_screen
  1567.         ret
  1568.  
  1569. ; void __stdcall con_get_cursor_pos(int* px, int* py);
  1570. con_get_cursor_pos:
  1571.         push    eax ecx
  1572.         mov     eax, [esp+12]
  1573.         mov     ecx, [con.cur_x]
  1574.         mov     [eax], ecx
  1575.         mov     eax, [esp+16]
  1576.         mov     ecx, [con.cur_y]
  1577.         mov     [eax], ecx
  1578.         pop     ecx eax
  1579.         ret     8
  1580.  
  1581. ; void __stdcall con_set_cursor_pos(int px, int py);
  1582. con_set_cursor_pos:
  1583.         push    eax
  1584.         mov     eax, [esp+8]
  1585.         cmp     eax, [con.scr_width]
  1586.         jae     @f
  1587.         mov     [con.cur_x], eax
  1588. @@:
  1589.         mov     eax, [esp+12]
  1590.         cmp     eax, [con.scr_height]
  1591.         jae     @f
  1592.         mov     [con.cur_y], eax
  1593. @@:
  1594.         pop     eax
  1595.         call    con.update_screen
  1596.         ret     8
  1597.  
  1598. con.update_screen:
  1599.         push    eax
  1600.         mov     eax, [con.cur_y]
  1601.         sub     eax, [con.wnd_ypos]
  1602.         jb      .up
  1603.         cmp     eax, [con.wnd_height]
  1604.         jb      .done
  1605.         mov     eax, [con.cur_y]
  1606.         sub     eax, [con.wnd_height]
  1607.         inc     eax
  1608.         jmp     .set
  1609. .up:
  1610.         mov     eax, [con.cur_y]
  1611. .set:
  1612.         mov     [con.wnd_ypos], eax
  1613. .done:
  1614.         pop     eax
  1615.         mov     [con.thread_op], 3
  1616.  
  1617. con.wake:
  1618.         pushad
  1619.         mov     al, [con.thread_op]
  1620.         cmp     al, byte [con.ipc_buf+0x10]
  1621.         jz      .ret
  1622. @@:
  1623.         push    60
  1624.         pop     eax
  1625.         push    2
  1626.         pop     ebx
  1627.         mov     ecx, [con.console_tid]
  1628.         jecxz   .ret
  1629.         mov     edx, con.thread_op
  1630.         push    1
  1631.         pop     esi
  1632.         int     0x40
  1633.         test    eax, eax
  1634.         jz      @f
  1635.         push    5
  1636.         pop     eax
  1637.         mov     bl, 1
  1638.         int     0x40
  1639.         jmp     @b
  1640. @@:
  1641. .ret:
  1642.         popad
  1643.         ret
  1644.  
  1645. ; ®â®ª ®ª­  ª®­á®«¨. Ž¡à ¡ â뢠¥â ¢¢®¤ ¨ ¢ë¢®¤.
  1646. con.thread:
  1647. ; ®â®ª ॠ£¨àã¥â ­  IPC, ª®â®à®¥ ¨á¯®«ì§ã¥âáï ⮫쪮 ¤«ï ⮣®, çâ®¡ë ¥£® ¬®¦­® ¡ë«® "à §¡ã¤¨âì"
  1648.         push    40
  1649.         pop     eax
  1650.         push    0x67
  1651.         pop     ebx
  1652.         int     0x40
  1653.         mov     al, 60
  1654.         mov     bl, 1
  1655.         mov     ecx, con.ipc_buf
  1656.         push    0x11
  1657.         pop     edx
  1658.         int     0x40
  1659.         mov     al, 66
  1660.         mov     bl, 1
  1661.         mov     ecx, ebx
  1662.         int     0x40
  1663. con.redraw:
  1664.         call    con.draw_window
  1665. con.msg_loop:
  1666.         cmp     dword [con.bUpPressed], 0
  1667.         jnz     .wait_timeout
  1668.         push    10
  1669.         pop     eax
  1670.         jmp     @f
  1671. .wait_timeout:
  1672.         push    23
  1673.         pop     eax
  1674.         push    5
  1675.         pop     ebx
  1676. @@:
  1677.         int     0x40
  1678.         dec     eax
  1679.         jz      con.redraw
  1680.         dec     eax
  1681.         jz      con.key
  1682.         dec     eax
  1683.         jz      con.button
  1684.         cmp     al, 4
  1685.         jz      con.ipc
  1686.         jmp     con.mouse
  1687. con.button:
  1688. ; we have only one button, close
  1689. con.thread_exit:
  1690.         or      byte [con_flags+1], 2
  1691.         and     [con.console_tid], 0
  1692.         or      eax, -1
  1693.         int     0x40
  1694. con.key:
  1695.         mov     al, 2
  1696.         int     0x40
  1697. ; ah = scancode
  1698.         cmp     ah, 0xE0
  1699.         jnz     @f
  1700.         mov     [con.bWasE0], 1
  1701.         jmp     con.msg_loop
  1702. @@:
  1703.         shr     eax, 8
  1704.         xchg    ah, [con.bWasE0]
  1705.         test    al, al
  1706.         jle     con.msg_loop
  1707.         cmp     al, 0x1D
  1708.         jz      con.msg_loop
  1709.         cmp     al, 0x2A
  1710.         jz      con.msg_loop
  1711.         cmp     al, 0x36
  1712.         jz      con.msg_loop
  1713.         cmp     al, 0x38
  1714.         jz      con.msg_loop
  1715.         cmp     al, 0x3A
  1716.         jz      con.msg_loop
  1717.         cmp     al, 0x45
  1718.         jz      con.msg_loop
  1719.         cmp     al, 0x46
  1720.         jz      con.msg_loop
  1721.         mov     edx, eax
  1722.         push    66
  1723.         pop     eax
  1724.         push    3
  1725.         pop     ebx
  1726.         int     0x40    ; eax = control key state
  1727.         test    dh, dh
  1728.         jnz     .extended
  1729.         bt      [scan_has_ascii], edx
  1730.         jnc     .extended
  1731.         test    al, 0x30
  1732.         jnz     .extended
  1733. ; key has ASCII code
  1734.         push    eax edx
  1735.         push    2
  1736.         pop     ecx
  1737.         test    al, 3
  1738.         jnz     @f
  1739.         dec     ecx
  1740. @@:
  1741.         push    26
  1742.         pop     eax
  1743.         mov     bl, 2
  1744.         mov     edx, con.kbd_layout
  1745.         int     0x40
  1746.         pop     edx eax
  1747.         mov     dh, [con.kbd_layout+edx]
  1748.         test    al, 0xC
  1749.         jz      @f
  1750.         sub     dh, 0x60
  1751.         jmp     @f
  1752. .extended:
  1753.         mov     dh, 0   ; no ASCII code
  1754. @@:
  1755. ; dh contains ASCII-code; now convert scancode to extended key code
  1756.         mov     ecx, con.extended_alt
  1757.         test    al, 0x30
  1758.         jnz     .xlat
  1759.         mov     ecx, con.extended_shift
  1760.         test    al, 3
  1761.         jnz     .xlat
  1762.         mov     ecx, con.extended_ctrl
  1763.         test    al, 0xC
  1764.         jnz     .xlat
  1765.         xchg    dl, dh
  1766.         cmp     dh, 0x57
  1767.         jz      @f
  1768.         cmp     dh, 0x58
  1769.         jnz     .gotcode
  1770. @@:
  1771.         add     dh, 0x85-0x57
  1772.         jmp     .gotcode
  1773. .xlat:
  1774.         movzx   eax, dl
  1775.         mov     dl, dh
  1776.         mov     dh, [eax+ecx]
  1777. .gotcode:
  1778.         test    dh, dh
  1779.         jz      con.msg_loop
  1780.         cmp     dh, 0x94
  1781.         jnz     @f
  1782.         mov     dl, 0
  1783. @@:
  1784. ; dx contains full keycode
  1785.         cmp     [con.bGetchRequested], 0
  1786.         jz      @f
  1787.         mov     [con.entered_char], dx
  1788.         jmp     con.msg_loop
  1789. @@:
  1790.         mov     eax, [con.input_end]
  1791.         mov     ecx, eax
  1792.         add     eax, 2
  1793.         cmp     eax, con.input_buffer_end
  1794.         jnz     @f
  1795.         mov     eax, con.input_buffer
  1796. @@:
  1797.         cmp     eax, [con.input_start]
  1798.         jnz     @f
  1799. ; buffer overflow, make beep and continue
  1800.         push    55
  1801.         pop     eax
  1802.         mov     ebx, eax
  1803.         mov     esi, con.beep
  1804.         int     0x40
  1805.         jmp     con.msg_loop
  1806. @@:
  1807.         mov     [ecx], dx
  1808.         mov     [con.input_end], eax
  1809.         jmp     con.msg_loop
  1810. con.ipc:
  1811.         movzx   eax, byte [con.ipc_buf+0x10]
  1812.         mov     byte [con.ipc_buf+4], 8
  1813.         mov     byte [con.ipc_buf+0x10], 0
  1814.         dec     eax
  1815.         jz      con.thread_exit
  1816.         dec     eax
  1817.         jz      con.set_title
  1818.         dec     eax
  1819.         jz      con.redraw_image
  1820.         dec     eax
  1821.         jz      con.getch
  1822.         jmp     con.msg_loop
  1823. con.set_title:
  1824.         push    71
  1825.         pop     eax
  1826.         push    1
  1827.         pop     ebx
  1828.         mov     ecx, [con.title]
  1829.         int     0x40
  1830.         jmp     con.msg_loop
  1831. con.redraw_image:
  1832.         call    con.data2image
  1833.         call    con.draw_image
  1834.         jmp     con.msg_loop
  1835. con.getch:
  1836.         mov     eax, [con.input_start]
  1837.         cmp     eax, [con.input_end]
  1838.         jz      .noinput
  1839.         mov     ecx, [eax]
  1840.         mov     [con.entered_char], cx
  1841.         inc     eax
  1842.         inc     eax
  1843.         cmp     eax, con.input_buffer_end
  1844.         jnz     @f
  1845.         mov     eax, con.input_buffer
  1846. @@:
  1847.         mov     [con.input_start], eax
  1848.         jmp     con.msg_loop
  1849. .noinput:
  1850.         mov     [con.bGetchRequested], 1
  1851.         jmp     con.msg_loop
  1852. con.mouse:
  1853.         xor     eax, eax
  1854.         xchg    eax, dword [con.bUpPressed]
  1855.         mov     dword [con.bUpPressed_saved], eax
  1856.         push    37
  1857.         pop     eax
  1858.         push    2
  1859.         pop     ebx
  1860.         int     0x40
  1861.         test    al, 1
  1862.         jnz     @f
  1863.         cmp     [con.vscroll_pt], -1
  1864.         jz      .redraw_if_needed
  1865.         or      [con.vscroll_pt], -1
  1866. .redraw_if_needed:
  1867.         cmp     dword [con.bUpPressed_saved], 0
  1868.         jnz     con.redraw_image
  1869.         jmp     con.msg_loop
  1870. @@:
  1871.         mov     al, 37
  1872.         dec     ebx
  1873.         int     0x40
  1874.         movsx   ebx, ax
  1875.         sar     eax, 16
  1876.         cmp     [con.vscroll_pt], -1
  1877.         jnz     .vscrolling
  1878.         test    ebx, ebx
  1879.         js      .redraw_if_needed
  1880.         sub     ax, [con.data_width]
  1881.         jb      .redraw_if_needed
  1882.         cmp     eax, con.vscroll_width
  1883.         jae     .redraw_if_needed
  1884.         cmp     ebx, con.vscroll_btn_height
  1885.         jb      .up
  1886.         sub     bx, [con.data_height]
  1887.         jae     .redraw_if_needed
  1888.         cmp     bx, -con.vscroll_btn_height
  1889.         jge     .down
  1890.         add     bx, [con.data_height]
  1891.         sub     bx, word [con.vscrollbar_pos]
  1892.         jl      .vscroll_up
  1893.         cmp     bx, word [con.vscrollbar_size]
  1894.         jl      .vscroll
  1895. .vscroll_down:
  1896.         cmp     [con.bScrollingDown_saved], 0
  1897.         jz      .vscroll_down_first
  1898.         cmp     [con.bScrollingDown_saved], 1
  1899.         jz      .vscroll_down_wasfirst
  1900.         mov     [con.bScrollingDown], 2
  1901. .vscroll_down_do:
  1902.         mov     eax, [con.wnd_ypos]
  1903.         add     eax, [con.wnd_height]
  1904.         dec     eax
  1905.         mov     ebx, [con.scr_height]
  1906.         sub     ebx, [con.wnd_height]
  1907.         cmp     eax, ebx
  1908.         jb      @f
  1909.         mov     eax, ebx
  1910. @@:
  1911.         mov     [con.wnd_ypos], eax
  1912.         jmp     con.redraw_image
  1913. .vscroll_down_first:
  1914.         push    26
  1915.         pop     eax
  1916.         push    9
  1917.         pop     ebx
  1918.         int     0x40
  1919.         mov     [con.scroll_down_first_time], eax
  1920.         mov     [con.bScrollingDown], 1
  1921.         jmp     .vscroll_down_do
  1922. .vscroll_down_wasfirst:
  1923.         push    26
  1924.         pop     eax
  1925.         push    9
  1926.         pop     ebx
  1927.         int     0x40
  1928.         sub     eax, [con.scroll_down_first_time]
  1929.         cmp     eax, 25
  1930.         jb      @f
  1931.         mov     [con.bScrollingDown], 2
  1932.         jmp     .vscroll_down_do
  1933. @@:
  1934.         mov     [con.bScrollingDown], 1
  1935.         jmp     con.msg_loop
  1936. .vscroll_up:
  1937.         cmp     [con.bScrollingUp_saved], 0
  1938.         jz      .vscroll_up_first
  1939.         cmp     [con.bScrollingUp_saved], 1
  1940.         jz      .vscroll_up_wasfirst
  1941.         mov     [con.bScrollingUp], 2
  1942. .vscroll_up_do:
  1943.         mov     eax, [con.wnd_ypos]
  1944.         inc     eax
  1945.         sub     eax, [con.wnd_height]
  1946.         jns     @f
  1947.         xor     eax, eax
  1948. @@:
  1949.         mov     [con.wnd_ypos], eax
  1950.         jmp     con.redraw_image
  1951. .vscroll_up_first:
  1952.         push    26
  1953.         pop     eax
  1954.         push    9
  1955.         pop     ebx
  1956.         int     0x40
  1957.         mov     [con.scroll_up_first_time], eax
  1958.         mov     [con.bScrollingUp], 1
  1959.         jmp     .vscroll_up_do
  1960. .vscroll_up_wasfirst:
  1961.         push    26
  1962.         pop     eax
  1963.         push    9
  1964.         pop     ebx
  1965.         int     0x40
  1966.         sub     eax, [con.scroll_up_first_time]
  1967.         cmp     eax, 25
  1968.         jb      @f
  1969.         mov     [con.bScrollingUp], 2
  1970.         jmp     .vscroll_up_do
  1971. @@:
  1972.         mov     [con.bScrollingUp], 1
  1973.         jmp     con.msg_loop
  1974. .up:
  1975.         cmp     [con.bUpPressed_saved], 0
  1976.         jz      .up_first
  1977.         cmp     [con.bUpPressed_saved], 1
  1978.         jz      .up_wasfirst
  1979.         mov     [con.bUpPressed], 2
  1980. .up_do:
  1981.         mov     eax, [con.wnd_ypos]
  1982.         dec     eax
  1983.         js      @f
  1984.         mov     [con.wnd_ypos], eax
  1985. @@:
  1986.         jmp     con.redraw_image
  1987. .up_first:
  1988.         push    26
  1989.         pop     eax
  1990.         push    9
  1991.         pop     ebx
  1992.         int     0x40
  1993.         mov     [con.up_first_time], eax
  1994.         mov     [con.bUpPressed], 1
  1995.         jmp     .up_do
  1996. .up_wasfirst:
  1997.         push    26
  1998.         pop     eax
  1999.         push    9
  2000.         pop     ebx
  2001.         int     0x40
  2002.         sub     eax, [con.up_first_time]
  2003.         cmp     eax, 25
  2004.         jb      @f
  2005.         mov     [con.bUpPressed], 2
  2006.         jmp     .up_do
  2007. @@:
  2008.         mov     [con.bUpPressed], 1
  2009.         jmp     con.msg_loop
  2010. .down:
  2011.         cmp     [con.bDownPressed_saved], 0
  2012.         jz      .down_first
  2013.         cmp     [con.bDownPressed_saved], 1
  2014.         jz      .down_wasfirst
  2015.         mov     [con.bDownPressed], 2
  2016. .down_do:
  2017.         mov     eax, [con.scr_height]
  2018.         sub     eax, [con.wnd_height]
  2019.         jbe     con.redraw_image
  2020.         cmp     [con.wnd_ypos], eax
  2021.         jae     con.redraw_image
  2022.         inc     [con.wnd_ypos]
  2023.         jmp     con.redraw_image
  2024. .down_first:
  2025.         push    26
  2026.         pop     eax
  2027.         push    9
  2028.         pop     ebx
  2029.         int     0x40
  2030.         mov     [con.down_first_time], eax
  2031.         mov     [con.bDownPressed], 1
  2032.         jmp     .down_do
  2033. .down_wasfirst:
  2034.         push    26
  2035.         pop     eax
  2036.         push    9
  2037.         pop     ebx
  2038.         int     0x40
  2039.         sub     eax, [con.down_first_time]
  2040.         cmp     eax, 25
  2041.         jb      @f
  2042.         mov     [con.bDownPressed], 2
  2043.         jmp     .down_do
  2044. @@:
  2045.         mov     [con.bDownPressed], 1
  2046.         jmp     con.msg_loop
  2047. .vscroll:
  2048.         mov     [con.vscroll_pt], ebx
  2049.         call    con.draw_image
  2050.         jmp     con.msg_loop
  2051. .vscrolling:
  2052.         sub     ebx, [con.vscroll_pt]
  2053.         sub     ebx, con.vscroll_btn_height
  2054.         jge     @f
  2055.         xor     ebx, ebx
  2056. @@:
  2057.         movzx   eax, [con.data_height]
  2058.         sub     eax, 2*con.vscroll_btn_height
  2059.         sub     eax, [con.vscrollbar_size]
  2060.         cmp     ebx, eax
  2061.         jb      @f
  2062.         lea     ebx, [eax-1]
  2063. @@:
  2064.         xchg    eax, ebx
  2065.         mov     edx, [con.scr_height]
  2066.         sub     edx, [con.wnd_height]
  2067.         inc     edx
  2068.         mul     edx
  2069.         div     ebx
  2070.         cmp     [con.wnd_ypos], eax
  2071.         jz      con.msg_loop
  2072.         mov     [con.wnd_ypos], eax
  2073.         jmp     con.redraw_image
  2074.  
  2075. con.draw_window:
  2076.         push    12
  2077.         pop     eax
  2078.         xor     ebx, ebx
  2079.         inc     ebx
  2080.         int     0x40
  2081.         mov     al, 48
  2082.         mov     bl, 4
  2083.         int     0x40
  2084.         mov     ebx, [con.def_wnd_x-2]
  2085.         mov     bx, word [con.wnd_width]
  2086.         imul    bx, font_width
  2087.         add     bx, 5+5-1
  2088.         mov     ecx, [con.def_wnd_y-2]
  2089.         mov     cx, word [con.wnd_height]
  2090.         imul    cx, font_height
  2091.         lea     ecx, [ecx+eax+5-1]
  2092.         mov     edx, 0x33000000
  2093.         mov     edi, [con.title]
  2094. ; place for scrollbar
  2095.         mov     eax, [con.wnd_height]
  2096.         cmp     eax, [con.scr_height]
  2097.         jae     @f
  2098.         add     ebx, con.vscroll_width
  2099. @@:
  2100.         xor     eax, eax
  2101.         int     0x40
  2102.         call    con.draw_image
  2103.         push    12
  2104.         pop     eax
  2105.         push    2
  2106.         pop     ebx
  2107.         int     0x40
  2108.         ret
  2109.  
  2110. con.draw_image:
  2111.         xor     edx, edx
  2112.         mov     ecx, [con.wnd_width]
  2113.         imul    ecx, font_width
  2114.         mov     [con.data_width], cx
  2115.         shl     ecx, 16
  2116.         mov     cx, word [con.wnd_height]
  2117.         imul    cx, font_height
  2118.         mov     [con.data_height], cx
  2119.         mov     ebx, [con.image]
  2120.         push    65
  2121.         pop     eax
  2122.         xor     ebp, ebp
  2123.         mov     edi, con.colors
  2124.         push    8
  2125.         pop     esi
  2126.         int     0x40
  2127.         mov     al, 7
  2128.         mov     edx, [con.wnd_height]
  2129.         cmp     edx, [con.scr_height]
  2130.         jae     .skip_vscroll
  2131.         push    ecx
  2132.         mov     edx, ecx
  2133.         xor     dx, dx
  2134.         mov     ebx, con.vscroll_btn3
  2135.         cmp     [con.bUpPressed], 0
  2136.         jnz     @f
  2137.         mov     ebx, con.vscroll_btn1
  2138. @@:
  2139.         mov     ecx, con.vscroll_width*65536 + con.vscroll_btn_height
  2140.         int     0x40
  2141.         pop     edx
  2142.         sub     dx, con.vscroll_btn_height
  2143.         mov     ebx, con.vscroll_btn4
  2144.         cmp     [con.bDownPressed], 0
  2145.         jnz     @f
  2146.         mov     ebx, con.vscroll_btn2
  2147. @@:
  2148.         int     0x40
  2149.         push    edx
  2150. ; ‚ëç¨á«ï¥¬ ¢ëá®âã ¡¥£ã­ª 
  2151.         mov     ax, dx
  2152.         sub     eax, con.vscroll_btn_height
  2153.         mov     ecx, eax
  2154.         mul     [con.wnd_height]
  2155.         div     [con.scr_height]
  2156.         cmp     eax, 5
  2157.         jae     @f
  2158.         mov     al, 5
  2159. @@:
  2160. ; eax = ¢ëá®â  ¡¥£ã­ª . ‚ëç¨á«ï¥¬ ¯®«®¦¥­¨¥ ¡¥£ã­ª 
  2161.         mov     [con.vscrollbar_size], eax
  2162.         xchg    eax, ecx
  2163.         sub     eax, ecx
  2164.         mul     [con.wnd_ypos]
  2165.         mov     ebx, [con.scr_height]
  2166.         sub     ebx, [con.wnd_height]
  2167.         div     ebx
  2168.         pop     edx
  2169.         push    edx
  2170. ; ecx = ¢ëá®â  ¡¥£ã­ª , eax = ¯®«®¦¥­¨¥
  2171.         add     eax, con.vscroll_btn_height
  2172.         mov     [con.vscrollbar_pos], eax
  2173.         mov     ebx, con.vscroll_bgr2
  2174.         cmp     [con.bScrollingUp], 0
  2175.         jnz     @f
  2176.         mov     ebx, con.vscroll_bgr1
  2177. @@:
  2178.         mov     ecx, con.vscroll_width*65536 + con.vscroll_bgr_height
  2179.         push    eax
  2180.         push    7
  2181.         pop     eax
  2182.         mov     dx, con.vscroll_btn_height
  2183.         call    .vpattern
  2184.         mov     dx, word [con.vscrollbar_pos]
  2185.         add     dx, word [con.vscrollbar_size]
  2186.         mov     cx, con.vscroll_bgr_height
  2187.         mov     ebx, con.vscroll_bgr2
  2188.         cmp     [con.bScrollingDown], 0
  2189.         jnz     @f
  2190.         mov     ebx, con.vscroll_bgr1
  2191. @@:
  2192.         call    .vpattern
  2193.         mov     ecx, [con.vscrollbar_pos]
  2194.         mov     dx, cx
  2195.         add     ecx, [con.vscrollbar_size]
  2196.         sub     ecx, con.vscroll_bar_height3
  2197.         push    ecx
  2198.         mov     ebx, con.vscroll_bar1
  2199.         mov     ecx, con.vscroll_width*65536 + con.vscroll_bar_height1
  2200.         int     0x40
  2201.         add     dx, cx
  2202.         mov     cx, con.vscroll_bar_height2
  2203.         mov     ebx, con.vscroll_bar2
  2204.         call    .vpattern
  2205.         mov     ebx, con.vscroll_bar3
  2206.         mov     cx, con.vscroll_bar_height3
  2207.         int     0x40
  2208. .skip_vscroll:
  2209.         ret
  2210.  
  2211. .vpattern:
  2212.         push    edx
  2213.         add     dx, cx
  2214.         cmp     dx, [esp+8]
  2215.         pop     edx
  2216.         jbe     @f
  2217.         mov     cx, [esp+4]
  2218.         sub     cx, dx
  2219.         jz      .ret
  2220. @@:
  2221.         int     0x40
  2222.         add     dx, cx
  2223.         cmp     dx, [esp+4]
  2224.         jb      .vpattern
  2225. .ret:
  2226.         ret     4
  2227.  
  2228. align 4
  2229. con.colors      dd      0x000000, 0x000080, 0x008000, 0x008080
  2230.                 dd      0x800000, 0x800080, 0x808000, 0xC0C0C0
  2231.                 dd      0x808080, 0x0000FF, 0x00FF00, 0x00FFFF
  2232.                 dd      0xFF0000, 0xFF00FF, 0xFFFF00, 0xFFFFFF
  2233.  
  2234. scan_has_ascii:
  2235.         dd      11011111111111111111111111111110b
  2236.         dd      00000010001111111111101111111111b
  2237.         dd      00000000000000000000000000000000b
  2238.         dd      0
  2239.  
  2240. con.extended_alt:
  2241.         db      00h,01h,78h,79h,7Ah,7Bh,7Ch,7Dh,7Eh,7Fh,80h,81h,82h,83h,0Eh,0A5h
  2242.         db      10h,11h,12h,13h,14h,15h,16h,17h,18h,19h,1Ah,1Bh,1Ch,00h,1Eh,1Fh
  2243.         db      20h,21h,22h,23h,24h,25h,26h,27h,28h,29h,00h,2Bh,2Ch,2Dh,2Eh,2Fh
  2244.         db      30h,31h,32h,33h,34h,35h,00h,37h,00h,39h,00h,68h,69h,6Ah,6Bh,6Ch
  2245.         db      6Dh,6Eh,6Fh,70h,71h,00h,00h,97h,98h,99h,4Ah,9Bh,9Ch,9Dh,4Eh,9Fh
  2246.         db      0A0h,0A1h,0A2h,0A3h,00h,00h,00h,8Bh,8Ch,00h,00h,00h,00h,00h,00h,00h
  2247.         times 20h db 0
  2248. con.extended_ctrl:
  2249.         times 0Fh db %-1
  2250.         db      0x94
  2251.         times 2Bh db %-1
  2252.         db      5Eh,5Fh,60h,61h,62h,63h,64h,65h,66h,67h,00h,00h
  2253.         db      77h,8Dh,84h,8Eh,73h,8Fh,74h,90h,75h,91h,76h,92h,93h,00h,00h,00h,89h,8Ah
  2254.         times 0x80-0x59 db 0
  2255. con.extended_shift:
  2256.         times 3Bh db %-1
  2257.         db      54h,55h,56h,57h,58h,59h,5Ah,5Bh,5Ch,5Dh,00h,00h
  2258.         db      47h,48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh,50h,51h,52h,53h,00h,00h,00h,87h,88h
  2259.         times 0x80-0x59 db 0
  2260.  
  2261. ; ‚ ⥪ã饩 ॠ«¨§ æ¨¨ §­ ç¥­¨ï ¯® 㬮«ç ­¨î â ª®¢ë.
  2262. ; ‚ ¡ã¤ã饬 ®­¨, ¢®§¬®¦­®, ¡ã¤ãâ áç¨â뢠âìáï ª ª ¯ à ¬¥âàë ¨§ ini-ä ©«  console.ini.
  2263. con.def_wnd_width   dd    80
  2264. con.def_wnd_height  dd    25
  2265. con.def_scr_width   dd    80
  2266. con.def_scr_height  dd    300
  2267. con.def_wnd_x       dd    200
  2268. con.def_wnd_y       dd    50
  2269.  
  2270. con.vscroll_pt      dd    -1
  2271.  
  2272. align 16
  2273. EXPORTS:
  2274.         dd      szStart,                START
  2275.         dd      szVersion,              0x00020006
  2276.         dd      szcon_init,             con_init
  2277.         dd      szcon_write_asciiz,     con_write_asciiz
  2278.         dd      szcon_printf,           con_printf
  2279.         dd      szcon_exit,             con_exit
  2280.         dd      szcon_get_flags,        con_get_flags
  2281.         dd      szcon_set_flags,        con_set_flags
  2282.         dd      szcon_kbhit,            con_kbhit
  2283.         dd      szcon_getch,            con_getch
  2284.         dd      szcon_getch2,           con_getch2
  2285.         dd      szcon_gets,             con_gets
  2286.         dd      szcon_gets2,            con_gets2
  2287.         dd      szcon_get_font_height,  con_get_font_height
  2288.         dd      szcon_get_cursor_height,con_get_cursor_height
  2289.         dd      szcon_set_cursor_height,con_set_cursor_height
  2290.         dd      szcon_cls,              con_cls
  2291.         dd      szcon_get_cursor_pos,   con_get_cursor_pos
  2292.         dd      szcon_set_cursor_pos,   con_set_cursor_pos
  2293.         dd      0
  2294.  
  2295. con_flags       dd      7
  2296. con.cursor_height dd    (15*font_height+50)/100
  2297. con.input_start dd      con.input_buffer
  2298. con.input_end   dd      con.input_buffer
  2299.  
  2300. con_esc_attr_n  dd      0
  2301. con_esc_attrs   dd      0,0,0,0
  2302. con_esc         db      0
  2303. con_sci         db      0
  2304.  
  2305. con.entered_char dw     -1
  2306. con.bGetchRequested db  0
  2307. con.bWasE0       db     0
  2308.  
  2309. szStart                 db 'START',0
  2310.  
  2311. szcon_init              db 'con_init',0
  2312. szcon_write_asciiz      db 'con_write_asciiz',0
  2313. szcon_printf            db 'con_printf',0
  2314. szcon_exit              db 'con_exit',0
  2315. szVersion               db 'version',0
  2316. szcon_get_flags         db 'con_get_flags',0
  2317. szcon_set_flags         db 'con_set_flags',0
  2318. szcon_kbhit             db 'con_kbhit',0
  2319. szcon_getch             db 'con_getch',0
  2320. szcon_getch2            db 'con_getch2',0
  2321. szcon_gets              db 'con_gets',0
  2322. szcon_gets2             db 'con_gets2',0
  2323. szcon_get_font_height   db 'con_get_font_height',0
  2324. szcon_get_cursor_height db 'con_get_cursor_height',0
  2325. szcon_set_cursor_height db 'con_set_cursor_height',0
  2326. szcon_cls               db 'con_cls',0
  2327. szcon_get_cursor_pos    db 'con_get_cursor_pos',0
  2328. szcon_set_cursor_pos    db 'con_set_cursor_pos',0
  2329.  
  2330. con.thread_err      db 'Cannot create console thread!',13,10,0
  2331. con.nomem_err       db 'Not enough memory!',13,10,0
  2332. con.aFinished       db ' [Finished]',0
  2333. con.aNull           db '(null)',0
  2334. con.beep                db      0x90, 0x3C, 0x00
  2335. con.ipc_buf         dd 0,8,0,0
  2336.                     db 0
  2337.  
  2338. section '.data' data readable writable align 16
  2339.  
  2340. con.finished_title          rb 256
  2341.  
  2342. con.cur_x                   rd 1
  2343. con.cur_y                   rd 1
  2344. con.wnd_xpos                rd 1
  2345. con.wnd_ypos                rd 1
  2346.  
  2347. con.wnd_width               rd 1
  2348. con.wnd_height              rd 1
  2349. con.scr_width               rd 1
  2350. con.scr_height              rd 1
  2351. con.title                   rd 1
  2352. con.data                    rd 1
  2353. con.image                   rd 1
  2354. con.console_tid             rd 1
  2355. con.data_width              rw 1
  2356. con.data_height             rw 1
  2357. con.vscrollbar_size         rd 1
  2358. con.vscrollbar_pos          rd 1
  2359. con.up_first_time           rd 1
  2360. con.down_first_time         rd 1
  2361. con.scroll_up_first_time    rd 1
  2362. con.scroll_down_first_time  rd 1
  2363. con.bUpPressed_saved        rb 1
  2364. con.bDownPressed_saved      rb 1
  2365. con.bScrollingUp_saved      rb 1
  2366. con.bScrollingDown_saved    rb 1
  2367.  
  2368. con.input_buffer                rw      128
  2369. con.input_buffer_end = $
  2370.  
  2371. con.kbd_layout          rb      128
  2372.  
  2373. ; 1 = exit, 2 = set title, 3 = redraw, 4 = getch
  2374. con.thread_op               rb 1
  2375. con.bUpPressed              rb 1
  2376. con.bDownPressed            rb 1
  2377. con.bScrollingUp            rb 1
  2378. con.bScrollingDown          rb 1
  2379.  
  2380. con.stack                   rb 1024
  2381. con.stack_top = $
  2382.