Subversion Repositories Kolibri OS

Rev

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