Subversion Repositories Kolibri OS

Rev

Rev 2530 | Rev 3686 | 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.         jnz     .nosetcursor
  849.         mov     eax, [con_esc_attrs]
  850.         cmp     eax, [con.scr_width]
  851.         jae     @f
  852.         mov     [con.cur_x], eax
  853. @@:
  854.         mov     eax, [con_esc_attrs+4]
  855.         cmp     eax, [con.scr_height+4]
  856.         jae     @f
  857.         mov     [con.cur_y], eax
  858. .j_get_data:
  859.         jmp     con.get_data_ptr
  860. .cursor_up:
  861.         cmp     [con_esc_attr_n], 1
  862.         jnz     .nosetcursor
  863.         mov     eax, [con.cur_y]
  864.         sub     eax, [con_esc_attrs]
  865.         jnc     @f
  866.         xor     eax, eax
  867. @@:
  868.         mov     [con.cur_y], eax
  869.         jmp     .j_get_data
  870. .cursor_down:
  871.         cmp     [con_esc_attr_n], 1
  872.         jnz     .nosetcursor
  873.         mov     eax, [con.cur_y]
  874.         add     eax, [con_esc_attrs]
  875.         cmp     eax, [con.scr_height]
  876.         jb      @f
  877.         mov     eax, [con.scr_height]
  878.         dec     eax
  879. @@:
  880.         mov     [con.cur_y], eax
  881.         jmp     .j_get_data
  882. .cursor_right:
  883.         cmp     [con_esc_attr_n], 1
  884.         jnz     .nosetcursor
  885.         mov     eax, [con.cur_x]
  886.         add     eax, [con_esc_attrs]
  887.         cmp     eax, [con.scr_width]
  888.         jb      @f
  889.         mov     eax, [con.scr_width]
  890.         dec     eax
  891. @@:
  892.         mov     [con.cur_x], eax
  893.         jmp     .j_get_data
  894. .cursor_left:
  895.         cmp     [con_esc_attr_n], 1
  896.         jnz     .nosetcursor
  897.         mov     eax, [con.cur_x]
  898.         sub     eax, [con_esc_attrs]
  899.         jnc     @f
  900.         xor     eax, eax
  901. @@:
  902.         mov     [con.cur_x], eax
  903.         jmp     .j_get_data
  904. .set_attr:
  905.         push    eax ecx edx
  906.         xor     ecx, ecx
  907. .set_one_attr:
  908.         mov     eax, [con_esc_attrs+ecx*4]
  909.         cmp     al, 0
  910.         jz      .attr_normal
  911.         cmp     al, 1
  912.         jz      .attr_bold
  913.         cmp     al, 5
  914.         jz      .attr_bgr_bold
  915.         cmp     al, 7
  916.         jz      .attr_reversed
  917.         xor     edx, edx
  918.         cmp     al, 30
  919.         jz      .attr_color
  920.         mov     dl, 4
  921.         cmp     al, 31
  922.         jz      .attr_color
  923.         mov     dl, 2
  924.         cmp     al, 32
  925.         jz      .attr_color
  926.         mov     dl, 6
  927.         cmp     al, 33
  928.         jz      .attr_color
  929.         mov     dl, 1
  930.         cmp     al, 34
  931.         jz      .attr_color
  932.         mov     dl, 5
  933.         cmp     al, 35
  934.         jz      .attr_color
  935.         mov     dl, 3
  936.         cmp     al, 36
  937.         jz      .attr_color
  938.         mov     dl, 7
  939.         cmp     al, 37
  940.         jz      .attr_color
  941.         xor     edx, edx
  942.         cmp     al, 40
  943.         jz      .attr_bgr_color
  944.         mov     dl, 0x40
  945.         cmp     al, 41
  946.         jz      .attr_bgr_color
  947.         mov     dl, 0x20
  948.         cmp     al, 42
  949.         jz      .attr_bgr_color
  950.         mov     dl, 0x60
  951.         cmp     al, 43
  952.         jz      .attr_bgr_color
  953.         mov     dl, 0x10
  954.         cmp     al, 44
  955.         jz      .attr_bgr_color
  956.         mov     dl, 0x50
  957.         cmp     al, 45
  958.         jz      .attr_bgr_color
  959.         mov     dl, 0x30
  960.         cmp     al, 46
  961.         jz      .attr_bgr_color
  962.         mov     dl, 0x70
  963.         cmp     al, 47
  964.         jnz     .attr_continue
  965. .attr_bgr_color:
  966.         mov     eax, [con_flags]
  967.         and     al, 0x8F
  968.         or      al, dl
  969.         mov     [con_flags], eax
  970.         jmp     .attr_continue
  971. .attr_color:
  972.         mov     eax, [con_flags]
  973.         and     al, 0xF8
  974.         or      al, dl
  975.         mov     [con_flags], eax
  976.         jmp     .attr_continue
  977. .attr_normal:
  978.         mov     byte [con_flags], 7
  979.         jmp     .attr_continue
  980. .attr_reversed:
  981.         mov     byte [con_flags], 0x70
  982.         jmp     .attr_continue
  983. .attr_bold:
  984.         or      byte [con_flags], 8
  985.         jmp     .attr_continue
  986. .attr_bgr_bold:
  987.         or      byte [con_flags], 0x80
  988. .attr_continue:
  989.         inc     ecx
  990.         cmp     ecx, [con_esc_attr_n]
  991.         jb      .set_one_attr
  992.         pop     edx ecx eax
  993.         ret
  994.  
  995. con.newline:
  996.         mov     eax, [con.cur_y]
  997.         inc     eax
  998.         mov     [con.cur_y], eax
  999.         cmp     eax, [con.scr_height]
  1000.         jb      @f
  1001.         call    con.scr_scroll_up
  1002. @@:
  1003.         call    con.get_data_ptr
  1004.         ret
  1005.  
  1006. con.scr_scroll_up:
  1007.         pushad
  1008.         mov     edi, [con.data]
  1009.         mov     esi, edi
  1010.         add     esi, [con.scr_width]
  1011.         add     esi, [con.scr_width]
  1012.         dec     [con.cur_y]
  1013.         mov     ecx, [con.scr_height]
  1014.         dec     ecx
  1015.         imul    ecx, [con.scr_width]
  1016.         shr     ecx, 1
  1017.         rep     movsd
  1018.         adc     ecx, ecx
  1019.         rep     movsw
  1020.         mov     ax, 0x0720
  1021.         mov     ecx, [con.scr_width]
  1022.         rep     stosw
  1023.         popad
  1024.         ret
  1025.  
  1026. con.data2image:
  1027.         pushad
  1028.         mov     edi, [con.image]
  1029.         mov     esi, [con.data]
  1030.         mov     eax, [con.wnd_ypos]
  1031.         mul     [con.scr_width]
  1032.         add     eax, [con.wnd_xpos]
  1033.         lea     esi, [esi+eax*2]
  1034.         mov     ecx, [con.wnd_height]
  1035. .lh:
  1036.         push    ecx
  1037.         mov     ecx, [con.wnd_width]
  1038. .lw:
  1039.         push    ecx edi
  1040.         xor     eax, eax
  1041.         mov     al, [esi+1]
  1042.         push    eax
  1043.         and     al, 0xF
  1044.         mov     ebx, eax                ; 梥â ⥪áâ 
  1045.         pop     eax
  1046.         shr     al, 4
  1047.         mov     ebp, eax                ; 梥â ä®­ 
  1048.         sub     ebx, ebp
  1049.         lodsb
  1050.         inc     esi
  1051. if font_width > 8
  1052.         lea     edx, [eax+eax+font]
  1053. else
  1054.         lea     edx, [eax+font]
  1055. end if
  1056. .sh:
  1057.         mov     ecx, [edx]
  1058. repeat font_width
  1059.         shr     ecx, 1
  1060.         sbb     eax, eax
  1061.         and     eax, ebx
  1062.         add     eax, ebp
  1063.         mov     [edi+%-1], al
  1064. end repeat
  1065.         mov     eax, [con.wnd_width]
  1066. ;        imul    eax, font_width
  1067. ;        add     edi, eax
  1068. if font_width = 6
  1069.         lea     eax, [eax*2+eax]
  1070.         lea     edi, [edi+eax*2]
  1071. else if font_width = 7
  1072.         lea     edi, [edi+eax*8]
  1073.         sub     edi, eax
  1074. else if font_width = 8
  1075.         lea     edi, [edi+eax*8]
  1076. else if font_width = 9
  1077.         lea     edi, [edi+eax*8]
  1078.         add     edi, eax
  1079. else if font_width = 10
  1080.         lea     eax, [eax*4+eax]
  1081.         lea     edi, [edi+eax*2]
  1082. else
  1083. Unknown font_width value!
  1084. end if
  1085. if font_width > 8
  1086.         add     edx, 256*2
  1087.         cmp     edx, font+256*2*font_height
  1088. else
  1089.         add     edx, 256
  1090.         cmp     edx, font+256*font_height
  1091. end if
  1092.         jb      .sh
  1093.         pop     edi ecx
  1094.         add     edi, font_width
  1095.         sub     ecx, 1
  1096.         jnz     .lw
  1097.         mov     eax, [con.wnd_width]
  1098.         imul    eax, (font_height-1)*font_width
  1099.         add     edi, eax
  1100.         pop     ecx
  1101.         mov     eax, [con.scr_width]
  1102.         sub     eax, [con.wnd_width]
  1103.         lea     esi, [esi+eax*2]
  1104.         dec     ecx
  1105.         jnz     .lh
  1106.         mov     eax, [con.cur_y]
  1107.         sub     eax, [con.wnd_ypos]
  1108.         jb      .nocursor
  1109.         cmp     eax, [con.wnd_height]
  1110.         jae     .nocursor
  1111.         inc     eax
  1112.         mul     [con.wnd_width]
  1113.         imul    eax, font_height*font_width
  1114.         mov     edx, [con.cur_x]
  1115.         sub     edx, [con.wnd_xpos]
  1116.         jb      .nocursor
  1117.         cmp     edx, [con.wnd_width]
  1118.         jae     .nocursor
  1119.         inc     edx
  1120.         imul    edx, font_width
  1121.         add     eax, edx
  1122.         add     eax, [con.image]
  1123.         mov     edx, [con.wnd_width]
  1124.         imul    edx, font_width
  1125.         neg     edx
  1126.         mov     ecx, [con.cursor_height]
  1127.         jecxz   .nocursor
  1128. .cursor_loop:
  1129.         push    ecx
  1130.         mov     ecx, font_width
  1131.         add     eax, edx
  1132.         push    eax
  1133. @@:
  1134.         xor     byte [eax-1], 7
  1135.         dec     eax
  1136.         loop    @b
  1137.         pop     eax
  1138.         pop     ecx
  1139.         loop    .cursor_loop
  1140. .nocursor:
  1141.         popad
  1142.         ret
  1143.  
  1144. con_exit:
  1145.         cmp     byte [esp+4], 0
  1146.         jz      .noexit
  1147.         mov     [con.thread_op], 1
  1148.         call    con.wake
  1149.         ret     4
  1150. .noexit:
  1151.         push    esi
  1152.         mov     esi, [con.title]
  1153.         mov     edx, con.finished_title
  1154.         mov     ecx, 255
  1155.         call    .strcpy
  1156.         mov     esi, con.aFinished
  1157.         call    .strcpy
  1158.         mov     byte [edx], 0
  1159.         pop     esi
  1160.         and     [con.cursor_height], 0
  1161.         push    con.finished_title
  1162.         call    con_set_title
  1163.         ret     4
  1164. .strcpy:
  1165.         jecxz   .ret
  1166. @@:
  1167.         lodsb
  1168.         test    al, al
  1169.         jz      .ret
  1170.         mov     [edx], al
  1171.         inc     edx
  1172.         loop    @b
  1173. .ret:
  1174.         ret
  1175.  
  1176. con_set_title:
  1177.         mov     eax, [esp+4]
  1178.         mov     [con.title], eax
  1179.         mov     [con.thread_op], 2
  1180.         call    con.wake
  1181.         ret     4
  1182.  
  1183. ; int __stdcall con_kbhit(void);
  1184. con_kbhit:
  1185.         test    byte [con_flags+1], 2
  1186.         jnz     @f
  1187.         mov     eax, [con.input_start]
  1188.         cmp     eax, [con.input_end]
  1189. @@:
  1190.         setnz   al
  1191.         movzx   eax, al
  1192.         ret
  1193.  
  1194. con.force_entered_char:
  1195.         cmp     [con.entered_char], -1
  1196.         jnz     .ret
  1197.         mov     [con.thread_op], 4
  1198.         call    con.wake
  1199.         test    byte [con_flags+1], 2
  1200.         jnz     .ret
  1201. ; wait for response
  1202.         push    ebx
  1203.         push    5
  1204.         pop     eax
  1205.         push    2
  1206.         pop     ebx
  1207. @@:
  1208.         int     0x40
  1209.         cmp     [con.entered_char], -1
  1210.         jz      @b
  1211.         pop     ebx
  1212. .ret:
  1213.         ret
  1214.  
  1215. ; int __stdcall con_getch(void);
  1216. con_getch:
  1217.         call    con.force_entered_char
  1218.         test    byte [con_flags+1], 2
  1219.         jnz     con_getch_closed
  1220.         movzx   eax, byte [con.entered_char]
  1221.         sar     [con.entered_char], 8
  1222.         mov     byte [con.entered_char+1], 0xFF
  1223.         test    al, al
  1224.         jz      @f
  1225.         mov     byte [con.entered_char], 0xFF
  1226. @@:
  1227.         ret
  1228.  
  1229. con_getch_closed:
  1230.         xor     eax, eax
  1231.         ret
  1232.  
  1233. ; int __stdcall con_getch2(void);
  1234. con_getch2:
  1235.         call    con.force_entered_char
  1236.         test    byte [con_flags+1], 2
  1237.         jnz     con_getch_closed
  1238.         mov     eax, 0xFFFF
  1239.         xchg    ax, [con.entered_char]
  1240.         ret
  1241.  
  1242. ; char* __stdcall con_gets(char* str, int n);
  1243. con_gets:
  1244.         pop     eax
  1245.         push    0
  1246.         push    eax
  1247. ; char* __stdcall con_gets2(con_gets2_callback callback, char* str, int n);
  1248. con_gets2:
  1249.         mov     eax, [esp+8]            ; str
  1250.         pushad
  1251.         mov     esi, eax                ; str
  1252.         mov     ebx, [esp+20h+12]       ; n
  1253.         sub     ebx, 1
  1254.         jle     .ret
  1255.         mov     byte [esi], 0
  1256.         xor     ecx, ecx                ; ¤«¨­  㦥 ¢¢¥¤ñ­­®© áâப¨
  1257.         call    con.get_data_ptr
  1258. .loop:
  1259.         call    con_getch2
  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.         test    ah, ah
  1417.         jz      .closed
  1418.         xchg    al, ah
  1419.         cmp     al, 0x4B
  1420.         jz      .left
  1421.         cmp     al, 0x4D
  1422.         jz      .right
  1423.         cmp     al, 0x47
  1424.         jz      .home
  1425.         cmp     al, 0x4F
  1426.         jz      .end
  1427.         cmp     al, 0x53
  1428.         jz      .delete
  1429. ; give control to callback function
  1430.         cmp     dword [esp+20h+4], 0
  1431.         jz      .loop
  1432. ; remember length of text before and length of text after
  1433. ; and advance cursor to the end of line
  1434.         push    ecx
  1435.         push    eax
  1436.         lea     edx, [esi+1]
  1437. @@:
  1438.         lodsb
  1439.         test    al, al
  1440.         jz      @f
  1441.         call    con.write_char_ex
  1442.         jmp     @b
  1443. @@:
  1444.         sub     esi, edx
  1445.         pop     eax
  1446.         push    esi
  1447.         dec     edx
  1448.         sub     edx, [esp+28h+8]
  1449.         push    edx
  1450.         push    esp             ; ppos
  1451.         mov     ecx, [esp+30h+4]
  1452.         lea     edx, [esp+30h+12]
  1453.         push    edx             ; pn
  1454.         lea     edx, [esp+34h+8]
  1455.         push    edx             ; pstr
  1456.         push    eax             ; keycode
  1457.         call    ecx
  1458.         call    con.get_data_ptr
  1459.         dec     eax
  1460.         js      .callback_nochange
  1461.         jz      .callback_del
  1462.         dec     eax
  1463.         jz      .callback_output
  1464. ; callback returned 2 - exit
  1465.         add     esp, 12
  1466.         jmp     .ret
  1467. .callback_nochange:
  1468. ; callback returned 0 - string was not changed, only restore cursor position
  1469.         pop     esi
  1470.         pop     ecx
  1471.         test    ecx, ecx
  1472.         jz      .cncs
  1473. @@:
  1474.         mov     al, 8
  1475.         call    con.write_special_char
  1476.         loop    @b
  1477. .cncs:
  1478.         pop     ecx
  1479.         add     esi, [esp+20h+8]
  1480.         jmp     .callback_done
  1481. .callback_del:
  1482. ; callback returned 1 - string was changed, delete old string and output new
  1483.         mov     ecx, [esp+8]
  1484.         test    ecx, ecx
  1485.         jz      .cds
  1486. @@:
  1487.         mov     al, 8
  1488.         call    con.write_special_char
  1489.         mov     al, ' '
  1490.         call    con.write_char_ex
  1491.         mov     al, 8
  1492.         call    con.write_special_char
  1493.         loop    @b
  1494. .cds:
  1495. .callback_output:
  1496. ; callback returned 2 - string was changed, output new string
  1497.         pop     edx
  1498.         pop     esi
  1499.         pop     ecx
  1500.         mov     esi, [esp+20h+8]
  1501.         xor     ecx, ecx
  1502. @@:
  1503.         lodsb
  1504.         test    al, al
  1505.         jz      @f
  1506.         call    con.write_char_ex
  1507.         inc     ecx
  1508.         jmp     @b
  1509. @@:
  1510.         dec     esi
  1511.         push    ecx
  1512.         sub     ecx, edx
  1513.         jz      .cos
  1514. @@:
  1515.         mov     al, 8
  1516.         call    con.write_special_char
  1517.         dec     esi
  1518.         loop    @b
  1519. .cos:
  1520.         pop     ecx
  1521. .callback_done:
  1522.         call    con.update_screen
  1523.         mov     ebx, [esp+20h+12]
  1524.         dec     ebx
  1525.         cmp     ecx, ebx
  1526.         jae     .ret_us
  1527.         jmp     .loop
  1528. .left:
  1529.         cmp     esi, [esp+20h+8]
  1530.         jbe     .loop
  1531.         dec     esi
  1532.         mov     al, 8
  1533.         call    con.write_special_char
  1534.         jmp     .update_screen_and_loop
  1535. .right:
  1536.         cmp     byte [esi], 0
  1537.         jz      .loop
  1538.         lodsb
  1539.         call    con.write_char_ex
  1540.         jmp     .update_screen_and_loop
  1541. .home:
  1542.         cmp     esi, [esp+20h+8]
  1543.         jz      .update_screen_and_loop
  1544.         dec     esi
  1545.         mov     al, 8
  1546.         call    con.write_special_char
  1547.         jmp     .home
  1548. .end:
  1549.         lodsb
  1550.         test    al, al
  1551.         jz      @f
  1552.         call    con.write_char_ex
  1553.         jmp     .end
  1554. @@:
  1555.         dec     esi
  1556.         jmp     .update_screen_and_loop
  1557. .closed:
  1558.         and     dword [esp+1Ch], 0
  1559. .ret:
  1560.         popad
  1561.         ret     12
  1562.  
  1563. ; void __stdcall con_cls();
  1564. con_cls:
  1565.         push    edi
  1566.         call    con.write_special_char.cls
  1567.         pop     edi
  1568.         call    con.update_screen
  1569.         ret
  1570.  
  1571. ; void __stdcall con_get_cursor_pos(int* px, int* py);
  1572. con_get_cursor_pos:
  1573.         push    eax ecx
  1574.         mov     eax, [esp+12]
  1575.         mov     ecx, [con.cur_x]
  1576.         mov     [eax], ecx
  1577.         mov     eax, [esp+16]
  1578.         mov     ecx, [con.cur_y]
  1579.         mov     [eax], ecx
  1580.         pop     ecx eax
  1581.         ret     8
  1582.  
  1583. ; void __stdcall con_set_cursor_pos(int px, int py);
  1584. con_set_cursor_pos:
  1585.         push    eax
  1586.         mov     eax, [esp+8]
  1587.         cmp     eax, [con.scr_width]
  1588.         jae     @f
  1589.         mov     [con.cur_x], eax
  1590. @@:
  1591.         mov     eax, [esp+12]
  1592.         cmp     eax, [con.scr_height]
  1593.         jae     @f
  1594.         mov     [con.cur_y], eax
  1595. @@:
  1596.         pop     eax
  1597.         call    con.update_screen
  1598.         ret     8
  1599.  
  1600. con.update_screen:
  1601.         push    eax
  1602.         mov     eax, [con.cur_y]
  1603.         sub     eax, [con.wnd_ypos]
  1604.         jb      .up
  1605.         cmp     eax, [con.wnd_height]
  1606.         jb      .done
  1607.         mov     eax, [con.cur_y]
  1608.         sub     eax, [con.wnd_height]
  1609.         inc     eax
  1610.         jmp     .set
  1611. .up:
  1612.         mov     eax, [con.cur_y]
  1613. .set:
  1614.         mov     [con.wnd_ypos], eax
  1615. .done:
  1616.         pop     eax
  1617.         mov     [con.thread_op], 3
  1618.  
  1619. con.wake:
  1620.         pushad
  1621.         mov     al, [con.thread_op]
  1622.         cmp     al, byte [con.ipc_buf+0x10]
  1623.         jz      .ret
  1624. @@:
  1625.         push    60
  1626.         pop     eax
  1627.         push    2
  1628.         pop     ebx
  1629.         mov     ecx, [con.console_tid]
  1630.         jecxz   .ret
  1631.         mov     edx, con.thread_op
  1632.         push    1
  1633.         pop     esi
  1634.         int     0x40
  1635.         test    eax, eax
  1636.         jz      @f
  1637.         push    5
  1638.         pop     eax
  1639.         mov     bl, 1
  1640.         int     0x40
  1641.         jmp     @b
  1642. @@:
  1643. .ret:
  1644.         popad
  1645.         ret
  1646.  
  1647. ; ®â®ª ®ª­  ª®­á®«¨. Ž¡à ¡ â뢠¥â ¢¢®¤ ¨ ¢ë¢®¤.
  1648. con.thread:
  1649. ; ®â®ª ॠ£¨àã¥â ­  IPC, ª®â®à®¥ ¨á¯®«ì§ã¥âáï ⮫쪮 ¤«ï ⮣®, çâ®¡ë ¥£® ¬®¦­® ¡ë«® "à §¡ã¤¨âì"
  1650.         push    40
  1651.         pop     eax
  1652.         push    0x67
  1653.         pop     ebx
  1654.         int     0x40
  1655.         mov     al, 60
  1656.         mov     bl, 1
  1657.         mov     ecx, con.ipc_buf
  1658.         push    0x11
  1659.         pop     edx
  1660.         int     0x40
  1661.         mov     al, 66
  1662.         mov     bl, 1
  1663.         mov     ecx, ebx
  1664.         int     0x40
  1665. con.redraw:
  1666.         call    con.draw_window
  1667. con.msg_loop:
  1668.         cmp     dword [con.bUpPressed], 0
  1669.         jnz     .wait_timeout
  1670.         push    10
  1671.         pop     eax
  1672.         jmp     @f
  1673. .wait_timeout:
  1674.         push    23
  1675.         pop     eax
  1676.         push    5
  1677.         pop     ebx
  1678. @@:
  1679.         int     0x40
  1680.         dec     eax
  1681.         jz      con.redraw
  1682.         dec     eax
  1683.         jz      con.key
  1684.         dec     eax
  1685.         jz      con.button
  1686.         cmp     al, 4
  1687.         jz      con.ipc
  1688.         jmp     con.mouse
  1689. con.button:
  1690. ; we have only one button, close
  1691. con.thread_exit:
  1692.         or      byte [con_flags+1], 2
  1693.         and     [con.console_tid], 0
  1694.         and     [con.entered_char], 0
  1695.         or      eax, -1
  1696.         int     0x40
  1697. con.key:
  1698.         mov     al, 2
  1699.         int     0x40
  1700. ; ah = scancode
  1701.         cmp     ah, 0xE0
  1702.         jnz     @f
  1703.         mov     [con.bWasE0], 1
  1704.         jmp     con.msg_loop
  1705. @@:
  1706.         shr     eax, 8
  1707.         xchg    ah, [con.bWasE0]
  1708.         test    al, al
  1709.         jle     con.msg_loop
  1710.         cmp     al, 0x1D
  1711.         jz      con.msg_loop
  1712.         cmp     al, 0x2A
  1713.         jz      con.msg_loop
  1714.         cmp     al, 0x36
  1715.         jz      con.msg_loop
  1716.         cmp     al, 0x38
  1717.         jz      con.msg_loop
  1718.         cmp     al, 0x3A
  1719.         jz      con.msg_loop
  1720.         cmp     al, 0x45
  1721.         jz      con.msg_loop
  1722.         cmp     al, 0x46
  1723.         jz      con.msg_loop
  1724.         mov     edx, eax
  1725.         push    66
  1726.         pop     eax
  1727.         push    3
  1728.         pop     ebx
  1729.         int     0x40    ; eax = control key state
  1730.         test    dh, dh
  1731.         jnz     .extended
  1732.         bt      [scan_has_ascii], edx
  1733.         jnc     .extended
  1734.         test    al, 0x30
  1735.         jnz     .extended
  1736. ; key has ASCII code
  1737.         push    eax edx
  1738.         push    2
  1739.         pop     ecx
  1740.         test    al, 3
  1741.         jnz     @f
  1742.         dec     ecx
  1743. @@:
  1744.         push    26
  1745.         pop     eax
  1746.         mov     bl, 2
  1747.         mov     edx, con.kbd_layout
  1748.         int     0x40
  1749.         pop     edx eax
  1750.         mov     dh, [con.kbd_layout+edx]
  1751.         test    al, 0xC
  1752.         jz      @f
  1753.         sub     dh, 0x60
  1754.         jmp     @f
  1755. .extended:
  1756.         mov     dh, 0   ; no ASCII code
  1757. @@:
  1758. ; dh contains ASCII-code; now convert scancode to extended key code
  1759.         mov     ecx, con.extended_alt
  1760.         test    al, 0x30
  1761.         jnz     .xlat
  1762.         mov     ecx, con.extended_shift
  1763.         test    al, 3
  1764.         jnz     .xlat
  1765.         mov     ecx, con.extended_ctrl
  1766.         test    al, 0xC
  1767.         jnz     .xlat
  1768.         xchg    dl, dh
  1769.         cmp     dh, 0x57
  1770.         jz      @f
  1771.         cmp     dh, 0x58
  1772.         jnz     .gotcode
  1773. @@:
  1774.         add     dh, 0x85-0x57
  1775.         jmp     .gotcode
  1776. .xlat:
  1777.         movzx   eax, dl
  1778.         mov     dl, dh
  1779.         mov     dh, [eax+ecx]
  1780. .gotcode:
  1781.         test    dh, dh
  1782.         jz      con.msg_loop
  1783.         cmp     dh, 0x94
  1784.         jnz     @f
  1785.         mov     dl, 0
  1786. @@:
  1787. ; dx contains full keycode
  1788.         cmp     [con.bGetchRequested], 0
  1789.         jz      @f
  1790.         mov     [con.entered_char], dx
  1791.         jmp     con.msg_loop
  1792. @@:
  1793.         mov     eax, [con.input_end]
  1794.         mov     ecx, eax
  1795.         add     eax, 2
  1796.         cmp     eax, con.input_buffer_end
  1797.         jnz     @f
  1798.         mov     eax, con.input_buffer
  1799. @@:
  1800.         cmp     eax, [con.input_start]
  1801.         jnz     @f
  1802. ; buffer overflow, make beep and continue
  1803.         push    55
  1804.         pop     eax
  1805.         mov     ebx, eax
  1806.         mov     esi, con.beep
  1807.         int     0x40
  1808.         jmp     con.msg_loop
  1809. @@:
  1810.         mov     [ecx], dx
  1811.         mov     [con.input_end], eax
  1812.         jmp     con.msg_loop
  1813. con.ipc:
  1814.         movzx   eax, byte [con.ipc_buf+0x10]
  1815.         mov     byte [con.ipc_buf+4], 8
  1816.         mov     byte [con.ipc_buf+0x10], 0
  1817.         dec     eax
  1818.         jz      con.thread_exit
  1819.         dec     eax
  1820.         jz      con.set_title
  1821.         dec     eax
  1822.         jz      con.redraw_image
  1823.         dec     eax
  1824.         jz      con.getch
  1825.         jmp     con.msg_loop
  1826. con.set_title:
  1827.         push    71
  1828.         pop     eax
  1829.         push    1
  1830.         pop     ebx
  1831.         mov     ecx, [con.title]
  1832.         int     0x40
  1833.         jmp     con.msg_loop
  1834. con.redraw_image:
  1835.         call    con.data2image
  1836.         call    con.draw_image
  1837.         jmp     con.msg_loop
  1838. con.getch:
  1839.         mov     eax, [con.input_start]
  1840.         cmp     eax, [con.input_end]
  1841.         jz      .noinput
  1842.         mov     ecx, [eax]
  1843.         mov     [con.entered_char], cx
  1844.         inc     eax
  1845.         inc     eax
  1846.         cmp     eax, con.input_buffer_end
  1847.         jnz     @f
  1848.         mov     eax, con.input_buffer
  1849. @@:
  1850.         mov     [con.input_start], eax
  1851.         jmp     con.msg_loop
  1852. .noinput:
  1853.         mov     [con.bGetchRequested], 1
  1854.         jmp     con.msg_loop
  1855. con.mouse:
  1856.         xor     eax, eax
  1857.         xchg    eax, dword [con.bUpPressed]
  1858.         mov     dword [con.bUpPressed_saved], eax
  1859.         push    37
  1860.         pop     eax
  1861.         push    2
  1862.         pop     ebx
  1863.         int     0x40
  1864.         test    al, 1
  1865.         jnz     @f
  1866.         cmp     [con.vscroll_pt], -1
  1867.         jz      .redraw_if_needed
  1868.         or      [con.vscroll_pt], -1
  1869. .redraw_if_needed:
  1870.         cmp     dword [con.bUpPressed_saved], 0
  1871.         jnz     con.redraw_image
  1872.         jmp     con.msg_loop
  1873. @@:
  1874.         mov     al, 37
  1875.         dec     ebx
  1876.         int     0x40
  1877.         movsx   ebx, ax
  1878.         sar     eax, 16
  1879.         cmp     [con.vscroll_pt], -1
  1880.         jnz     .vscrolling
  1881.         test    ebx, ebx
  1882.         js      .redraw_if_needed
  1883.         sub     ax, [con.data_width]
  1884.         jb      .redraw_if_needed
  1885.         cmp     eax, con.vscroll_width
  1886.         jae     .redraw_if_needed
  1887.         cmp     ebx, con.vscroll_btn_height
  1888.         jb      .up
  1889.         sub     bx, [con.data_height]
  1890.         jae     .redraw_if_needed
  1891.         cmp     bx, -con.vscroll_btn_height
  1892.         jge     .down
  1893.         add     bx, [con.data_height]
  1894.         sub     bx, word [con.vscrollbar_pos]
  1895.         jl      .vscroll_up
  1896.         cmp     bx, word [con.vscrollbar_size]
  1897.         jl      .vscroll
  1898. .vscroll_down:
  1899.         cmp     [con.bScrollingDown_saved], 0
  1900.         jz      .vscroll_down_first
  1901.         cmp     [con.bScrollingDown_saved], 1
  1902.         jz      .vscroll_down_wasfirst
  1903.         mov     [con.bScrollingDown], 2
  1904. .vscroll_down_do:
  1905.         mov     eax, [con.wnd_ypos]
  1906.         add     eax, [con.wnd_height]
  1907.         dec     eax
  1908.         mov     ebx, [con.scr_height]
  1909.         sub     ebx, [con.wnd_height]
  1910.         cmp     eax, ebx
  1911.         jb      @f
  1912.         mov     eax, ebx
  1913. @@:
  1914.         mov     [con.wnd_ypos], eax
  1915.         jmp     con.redraw_image
  1916. .vscroll_down_first:
  1917.         push    26
  1918.         pop     eax
  1919.         push    9
  1920.         pop     ebx
  1921.         int     0x40
  1922.         mov     [con.scroll_down_first_time], eax
  1923.         mov     [con.bScrollingDown], 1
  1924.         jmp     .vscroll_down_do
  1925. .vscroll_down_wasfirst:
  1926.         push    26
  1927.         pop     eax
  1928.         push    9
  1929.         pop     ebx
  1930.         int     0x40
  1931.         sub     eax, [con.scroll_down_first_time]
  1932.         cmp     eax, 25
  1933.         jb      @f
  1934.         mov     [con.bScrollingDown], 2
  1935.         jmp     .vscroll_down_do
  1936. @@:
  1937.         mov     [con.bScrollingDown], 1
  1938.         jmp     con.msg_loop
  1939. .vscroll_up:
  1940.         cmp     [con.bScrollingUp_saved], 0
  1941.         jz      .vscroll_up_first
  1942.         cmp     [con.bScrollingUp_saved], 1
  1943.         jz      .vscroll_up_wasfirst
  1944.         mov     [con.bScrollingUp], 2
  1945. .vscroll_up_do:
  1946.         mov     eax, [con.wnd_ypos]
  1947.         inc     eax
  1948.         sub     eax, [con.wnd_height]
  1949.         jns     @f
  1950.         xor     eax, eax
  1951. @@:
  1952.         mov     [con.wnd_ypos], eax
  1953.         jmp     con.redraw_image
  1954. .vscroll_up_first:
  1955.         push    26
  1956.         pop     eax
  1957.         push    9
  1958.         pop     ebx
  1959.         int     0x40
  1960.         mov     [con.scroll_up_first_time], eax
  1961.         mov     [con.bScrollingUp], 1
  1962.         jmp     .vscroll_up_do
  1963. .vscroll_up_wasfirst:
  1964.         push    26
  1965.         pop     eax
  1966.         push    9
  1967.         pop     ebx
  1968.         int     0x40
  1969.         sub     eax, [con.scroll_up_first_time]
  1970.         cmp     eax, 25
  1971.         jb      @f
  1972.         mov     [con.bScrollingUp], 2
  1973.         jmp     .vscroll_up_do
  1974. @@:
  1975.         mov     [con.bScrollingUp], 1
  1976.         jmp     con.msg_loop
  1977. .up:
  1978.         cmp     [con.bUpPressed_saved], 0
  1979.         jz      .up_first
  1980.         cmp     [con.bUpPressed_saved], 1
  1981.         jz      .up_wasfirst
  1982.         mov     [con.bUpPressed], 2
  1983. .up_do:
  1984.         mov     eax, [con.wnd_ypos]
  1985.         dec     eax
  1986.         js      @f
  1987.         mov     [con.wnd_ypos], eax
  1988. @@:
  1989.         jmp     con.redraw_image
  1990. .up_first:
  1991.         push    26
  1992.         pop     eax
  1993.         push    9
  1994.         pop     ebx
  1995.         int     0x40
  1996.         mov     [con.up_first_time], eax
  1997.         mov     [con.bUpPressed], 1
  1998.         jmp     .up_do
  1999. .up_wasfirst:
  2000.         push    26
  2001.         pop     eax
  2002.         push    9
  2003.         pop     ebx
  2004.         int     0x40
  2005.         sub     eax, [con.up_first_time]
  2006.         cmp     eax, 25
  2007.         jb      @f
  2008.         mov     [con.bUpPressed], 2
  2009.         jmp     .up_do
  2010. @@:
  2011.         mov     [con.bUpPressed], 1
  2012.         jmp     con.msg_loop
  2013. .down:
  2014.         cmp     [con.bDownPressed_saved], 0
  2015.         jz      .down_first
  2016.         cmp     [con.bDownPressed_saved], 1
  2017.         jz      .down_wasfirst
  2018.         mov     [con.bDownPressed], 2
  2019. .down_do:
  2020.         mov     eax, [con.scr_height]
  2021.         sub     eax, [con.wnd_height]
  2022.         jbe     con.redraw_image
  2023.         cmp     [con.wnd_ypos], eax
  2024.         jae     con.redraw_image
  2025.         inc     [con.wnd_ypos]
  2026.         jmp     con.redraw_image
  2027. .down_first:
  2028.         push    26
  2029.         pop     eax
  2030.         push    9
  2031.         pop     ebx
  2032.         int     0x40
  2033.         mov     [con.down_first_time], eax
  2034.         mov     [con.bDownPressed], 1
  2035.         jmp     .down_do
  2036. .down_wasfirst:
  2037.         push    26
  2038.         pop     eax
  2039.         push    9
  2040.         pop     ebx
  2041.         int     0x40
  2042.         sub     eax, [con.down_first_time]
  2043.         cmp     eax, 25
  2044.         jb      @f
  2045.         mov     [con.bDownPressed], 2
  2046.         jmp     .down_do
  2047. @@:
  2048.         mov     [con.bDownPressed], 1
  2049.         jmp     con.msg_loop
  2050. .vscroll:
  2051.         mov     [con.vscroll_pt], ebx
  2052.         call    con.draw_image
  2053.         jmp     con.msg_loop
  2054. .vscrolling:
  2055.         sub     ebx, [con.vscroll_pt]
  2056.         sub     ebx, con.vscroll_btn_height
  2057.         jge     @f
  2058.         xor     ebx, ebx
  2059. @@:
  2060.         movzx   eax, [con.data_height]
  2061.         sub     eax, 2*con.vscroll_btn_height
  2062.         sub     eax, [con.vscrollbar_size]
  2063.         cmp     ebx, eax
  2064.         jb      @f
  2065.         lea     ebx, [eax-1]
  2066. @@:
  2067.         xchg    eax, ebx
  2068.         mov     edx, [con.scr_height]
  2069.         sub     edx, [con.wnd_height]
  2070.         inc     edx
  2071.         mul     edx
  2072.         div     ebx
  2073.         cmp     [con.wnd_ypos], eax
  2074.         jz      con.msg_loop
  2075.         mov     [con.wnd_ypos], eax
  2076.         jmp     con.redraw_image
  2077.  
  2078. con.draw_window:
  2079.         push    12
  2080.         pop     eax
  2081.         xor     ebx, ebx
  2082.         inc     ebx
  2083.         int     0x40
  2084.         mov     al, 48
  2085.         mov     bl, 4
  2086.         int     0x40
  2087.         mov     ebx, [con.def_wnd_x-2]
  2088.         mov     bx, word [con.wnd_width]
  2089.         imul    bx, font_width
  2090.         add     bx, 5+5-1
  2091.         mov     ecx, [con.def_wnd_y-2]
  2092.         mov     cx, word [con.wnd_height]
  2093.         imul    cx, font_height
  2094.         lea     ecx, [ecx+eax+5-1]
  2095.         mov     edx, 0x74000000
  2096.         mov     edi, [con.title]
  2097. ; place for scrollbar
  2098.         mov     eax, [con.wnd_height]
  2099.         cmp     eax, [con.scr_height]
  2100.         jae     @f
  2101.         add     ebx, con.vscroll_width
  2102. @@:
  2103.         xor     eax, eax
  2104.         int     0x40
  2105.         ;Leency{
  2106.         mov     eax,9
  2107.         mov     ebx,process_info_buffer
  2108.         mov     ecx,-1
  2109.         int     0x40
  2110.         mov     eax,[ebx+70]
  2111.         mov     [window_status],eax
  2112.                 test    [window_status],100b   ; window is rolled up
  2113.         jnz     .exit
  2114.         test    [window_status],10b    ; window is minimized to panel
  2115.         jnz     .exit
  2116.         ;}Leency - I'm in diamond code...
  2117.         call    con.draw_image
  2118.  
  2119. .exit:
  2120.         push    12
  2121.         pop     eax
  2122.         push    2
  2123.         pop     ebx
  2124.         int     0x40
  2125.                
  2126.         ret
  2127.  
  2128. con.draw_image:
  2129.         xor     edx, edx
  2130.         mov     ecx, [con.wnd_width]
  2131.         imul    ecx, font_width
  2132.         mov     [con.data_width], cx
  2133.         shl     ecx, 16
  2134.         mov     cx, word [con.wnd_height]
  2135.         imul    cx, font_height
  2136.         mov     [con.data_height], cx
  2137.         mov     ebx, [con.image]
  2138.         push    65
  2139.         pop     eax
  2140.         xor     ebp, ebp
  2141.         mov     edi, con.colors
  2142.         push    8
  2143.         pop     esi
  2144.         int     0x40
  2145.         mov     al, 7
  2146.         mov     edx, [con.wnd_height]
  2147.         cmp     edx, [con.scr_height]
  2148.         jae     .skip_vscroll
  2149.         push    ecx
  2150.         mov     edx, ecx
  2151.         xor     dx, dx
  2152.         mov     ebx, con.vscroll_btn3
  2153.         cmp     [con.bUpPressed], 0
  2154.         jnz     @f
  2155.         mov     ebx, con.vscroll_btn1
  2156. @@:
  2157.         mov     ecx, con.vscroll_width*65536 + con.vscroll_btn_height
  2158.         int     0x40
  2159.         pop     edx
  2160.         sub     dx, con.vscroll_btn_height
  2161.         mov     ebx, con.vscroll_btn4
  2162.         cmp     [con.bDownPressed], 0
  2163.         jnz     @f
  2164.         mov     ebx, con.vscroll_btn2
  2165. @@:
  2166.         int     0x40
  2167.         push    edx
  2168. ; ‚ëç¨á«ï¥¬ ¢ëá®âã ¡¥£ã­ª 
  2169.         mov     ax, dx
  2170.         sub     eax, con.vscroll_btn_height
  2171.         mov     ecx, eax
  2172.         mul     [con.wnd_height]
  2173.         div     [con.scr_height]
  2174.         cmp     eax, 5
  2175.         jae     @f
  2176.         mov     al, 5
  2177. @@:
  2178. ; eax = ¢ëá®â  ¡¥£ã­ª . ‚ëç¨á«ï¥¬ ¯®«®¦¥­¨¥ ¡¥£ã­ª 
  2179.         mov     [con.vscrollbar_size], eax
  2180.         xchg    eax, ecx
  2181.         sub     eax, ecx
  2182.         mul     [con.wnd_ypos]
  2183.         mov     ebx, [con.scr_height]
  2184.         sub     ebx, [con.wnd_height]
  2185.         div     ebx
  2186.         pop     edx
  2187.         push    edx
  2188. ; ecx = ¢ëá®â  ¡¥£ã­ª , eax = ¯®«®¦¥­¨¥
  2189.         add     eax, con.vscroll_btn_height
  2190.         mov     [con.vscrollbar_pos], eax
  2191.         mov     ebx, con.vscroll_bgr2
  2192.         cmp     [con.bScrollingUp], 0
  2193.         jnz     @f
  2194.         mov     ebx, con.vscroll_bgr1
  2195. @@:
  2196.         mov     ecx, con.vscroll_width*65536 + con.vscroll_bgr_height
  2197.         push    eax
  2198.         push    7
  2199.         pop     eax
  2200.         mov     dx, con.vscroll_btn_height
  2201.         call    .vpattern
  2202.         mov     dx, word [con.vscrollbar_pos]
  2203.         add     dx, word [con.vscrollbar_size]
  2204.         mov     cx, con.vscroll_bgr_height
  2205.         mov     ebx, con.vscroll_bgr2
  2206.         cmp     [con.bScrollingDown], 0
  2207.         jnz     @f
  2208.         mov     ebx, con.vscroll_bgr1
  2209. @@:
  2210.         call    .vpattern
  2211.         mov     ecx, [con.vscrollbar_pos]
  2212.         mov     dx, cx
  2213.         add     ecx, [con.vscrollbar_size]
  2214.         sub     ecx, con.vscroll_bar_height3
  2215.         push    ecx
  2216.         mov     ebx, con.vscroll_bar1
  2217.         mov     ecx, con.vscroll_width*65536 + con.vscroll_bar_height1
  2218.         int     0x40
  2219.         add     dx, cx
  2220.         mov     cx, con.vscroll_bar_height2
  2221.         mov     ebx, con.vscroll_bar2
  2222.         call    .vpattern
  2223.         mov     ebx, con.vscroll_bar3
  2224.         mov     cx, con.vscroll_bar_height3
  2225.         int     0x40
  2226. .skip_vscroll:
  2227.         ret
  2228.  
  2229. .vpattern:
  2230.         push    edx
  2231.         add     dx, cx
  2232.         cmp     dx, [esp+8]
  2233.         pop     edx
  2234.         jbe     @f
  2235.         mov     cx, [esp+4]
  2236.         sub     cx, dx
  2237.         jz      .ret
  2238. @@:
  2239.         int     0x40
  2240.         add     dx, cx
  2241.         cmp     dx, [esp+4]
  2242.         jb      .vpattern
  2243. .ret:
  2244.         ret     4
  2245.  
  2246. align 4
  2247. con.colors      dd      0x000000, 0x000080, 0x008000, 0x008080
  2248.                 dd      0x800000, 0x800080, 0x808000, 0xC0C0C0
  2249.                 dd      0x808080, 0x0000FF, 0x00FF00, 0x00FFFF
  2250.                 dd      0xFF0000, 0xFF00FF, 0xFFFF00, 0xFFFFFF
  2251.  
  2252. scan_has_ascii:
  2253.         dd      11011111111111111111111111111110b
  2254.         dd      00000010001111111111101111111111b
  2255.         dd      00000000000000000000000000000000b
  2256.         dd      0
  2257.  
  2258. con.extended_alt:
  2259.         db      00h,01h,78h,79h,7Ah,7Bh,7Ch,7Dh,7Eh,7Fh,80h,81h,82h,83h,0Eh,0A5h
  2260.         db      10h,11h,12h,13h,14h,15h,16h,17h,18h,19h,1Ah,1Bh,1Ch,00h,1Eh,1Fh
  2261.         db      20h,21h,22h,23h,24h,25h,26h,27h,28h,29h,00h,2Bh,2Ch,2Dh,2Eh,2Fh
  2262.         db      30h,31h,32h,33h,34h,35h,00h,37h,00h,39h,00h,68h,69h,6Ah,6Bh,6Ch
  2263.         db      6Dh,6Eh,6Fh,70h,71h,00h,00h,97h,98h,99h,4Ah,9Bh,9Ch,9Dh,4Eh,9Fh
  2264.         db      0A0h,0A1h,0A2h,0A3h,00h,00h,00h,8Bh,8Ch,00h,00h,00h,00h,00h,00h,00h
  2265.         times 20h db 0
  2266. con.extended_ctrl:
  2267.         times 0Fh db %-1
  2268.         db      0x94
  2269.         times 2Bh db %-1
  2270.         db      5Eh,5Fh,60h,61h,62h,63h,64h,65h,66h,67h,00h,00h
  2271.         db      77h,8Dh,84h,8Eh,73h,8Fh,74h,90h,75h,91h,76h,92h,93h,00h,00h,00h,89h,8Ah
  2272.         times 0x80-0x59 db 0
  2273. con.extended_shift:
  2274.         times 3Bh db %-1
  2275.         db      54h,55h,56h,57h,58h,59h,5Ah,5Bh,5Ch,5Dh,00h,00h
  2276.         db      47h,48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh,50h,51h,52h,53h,00h,00h,00h,87h,88h
  2277.         times 0x80-0x59 db 0
  2278.  
  2279. ; ‚ ⥪ã饩 ॠ«¨§ æ¨¨ §­ ç¥­¨ï ¯® 㬮«ç ­¨î â ª®¢ë.
  2280. ; ‚ ¡ã¤ã饬 ®­¨, ¢®§¬®¦­®, ¡ã¤ãâ áç¨â뢠âìáï ª ª ¯ à ¬¥âàë ¨§ ini-ä ©«  console.ini.
  2281. con.def_wnd_width   dd    80
  2282. con.def_wnd_height  dd    25
  2283. con.def_scr_width   dd    80
  2284. con.def_scr_height  dd    300
  2285. con.def_wnd_x       dd    200
  2286. con.def_wnd_y       dd    50
  2287.  
  2288.  
  2289. struc process_info
  2290. {
  2291.   cpu_usage               dd ?  ; +0
  2292.   window_stack_position   dw ?  ; +4
  2293.   window_stack_value      dw ?  ; +6
  2294.                           dw ?  ; +8
  2295.   process_name            rb 12 ; +10
  2296.   memory_start            dd ?  ; +22
  2297.   used_memory             dd ?  ; +26
  2298.   PID                     dd ?  ; +30
  2299.   box.x                   dd ?  ; +34
  2300.   box.y                   dd ?  ; +38
  2301.   box.width               dd ?  ; +42
  2302.   box.height              dd ?  ; +46
  2303.   slot_state              dw ?  ; +50
  2304.                           dw ?  ; +52
  2305.   client_box.x            dd ?  ; +54
  2306.   client_box.y            dd ?  ; +58
  2307.   client_box.width        dd ?  ; +62
  2308.   client_box.height       dd ?  ; +66
  2309.   wnd_state               db ?  ; +70
  2310.   rb (1024-71)
  2311. }
  2312. process_info_buffer process_info
  2313. window_status           rd 1
  2314.  
  2315. con.vscroll_pt      dd    -1
  2316.  
  2317. align 16
  2318. EXPORTS:
  2319.         dd      szStart,                START
  2320.         dd      szVersion,              0x00020007
  2321.         dd      szcon_init,             con_init
  2322.         dd      szcon_write_asciiz,     con_write_asciiz
  2323.         dd      szcon_write_string,     con_write_length
  2324.         dd      szcon_printf,           con_printf
  2325.         dd      szcon_exit,             con_exit
  2326.         dd      szcon_get_flags,        con_get_flags
  2327.         dd      szcon_set_flags,        con_set_flags
  2328.         dd      szcon_kbhit,            con_kbhit
  2329.         dd      szcon_getch,            con_getch
  2330.         dd      szcon_getch2,           con_getch2
  2331.         dd      szcon_gets,             con_gets
  2332.         dd      szcon_gets2,            con_gets2
  2333.         dd      szcon_get_font_height,  con_get_font_height
  2334.         dd      szcon_get_cursor_height,con_get_cursor_height
  2335.         dd      szcon_set_cursor_height,con_set_cursor_height
  2336.         dd      szcon_cls,              con_cls
  2337.         dd      szcon_get_cursor_pos,   con_get_cursor_pos
  2338.         dd      szcon_set_cursor_pos,   con_set_cursor_pos
  2339.         dd      0
  2340.  
  2341. con_flags       dd      7
  2342. con.cursor_height dd    (15*font_height+50)/100
  2343. con.input_start dd      con.input_buffer
  2344. con.input_end   dd      con.input_buffer
  2345.  
  2346. con_esc_attr_n  dd      0
  2347. con_esc_attrs   dd      0,0,0,0
  2348. con_esc         db      0
  2349. con_sci         db      0
  2350.  
  2351. con.entered_char dw     -1
  2352. con.bGetchRequested db  0
  2353. con.bWasE0       db     0
  2354.  
  2355. szStart                 db 'START',0
  2356.  
  2357. szcon_init              db 'con_init',0
  2358. szcon_write_asciiz      db 'con_write_asciiz',0
  2359. szcon_write_string      db 'con_write_string',0
  2360. szcon_printf            db 'con_printf',0
  2361. szcon_exit              db 'con_exit',0
  2362. szVersion               db 'version',0
  2363. szcon_get_flags         db 'con_get_flags',0
  2364. szcon_set_flags         db 'con_set_flags',0
  2365. szcon_kbhit             db 'con_kbhit',0
  2366. szcon_getch             db 'con_getch',0
  2367. szcon_getch2            db 'con_getch2',0
  2368. szcon_gets              db 'con_gets',0
  2369. szcon_gets2             db 'con_gets2',0
  2370. szcon_get_font_height   db 'con_get_font_height',0
  2371. szcon_get_cursor_height db 'con_get_cursor_height',0
  2372. szcon_set_cursor_height db 'con_set_cursor_height',0
  2373. szcon_cls               db 'con_cls',0
  2374. szcon_get_cursor_pos    db 'con_get_cursor_pos',0
  2375. szcon_set_cursor_pos    db 'con_set_cursor_pos',0
  2376.  
  2377. con.thread_err      db 'Cannot create console thread!',13,10,0
  2378. con.nomem_err       db 'Not enough memory!',13,10,0
  2379. con.aFinished       db ' [Finished]',0
  2380. con.aNull           db '(null)',0
  2381. con.beep                db      0x90, 0x3C, 0x00
  2382. con.ipc_buf         dd 0,8,0,0
  2383.                     db 0
  2384.  
  2385. section '.data' data readable writable align 16
  2386.  
  2387. con.finished_title          rb 256
  2388.  
  2389. con.cur_x                   rd 1
  2390. con.cur_y                   rd 1
  2391. con.wnd_xpos                rd 1
  2392. con.wnd_ypos                rd 1
  2393.  
  2394. con.wnd_width               rd 1
  2395. con.wnd_height              rd 1
  2396. con.scr_width               rd 1
  2397. con.scr_height              rd 1
  2398. con.title                   rd 1
  2399. con.data                    rd 1
  2400. con.image                   rd 1
  2401. con.console_tid             rd 1
  2402. con.data_width              rw 1
  2403. con.data_height             rw 1
  2404. con.vscrollbar_size         rd 1
  2405. con.vscrollbar_pos          rd 1
  2406. con.up_first_time           rd 1
  2407. con.down_first_time         rd 1
  2408. con.scroll_up_first_time    rd 1
  2409. con.scroll_down_first_time  rd 1
  2410. con.bUpPressed_saved        rb 1
  2411. con.bDownPressed_saved      rb 1
  2412. con.bScrollingUp_saved      rb 1
  2413. con.bScrollingDown_saved    rb 1
  2414.  
  2415. con.input_buffer                rw      128
  2416. con.input_buffer_end = $
  2417.  
  2418. con.kbd_layout          rb      128
  2419.  
  2420. ; 1 = exit, 2 = set title, 3 = redraw, 4 = getch
  2421. con.thread_op               rb 1
  2422. con.bUpPressed              rb 1
  2423. con.bDownPressed            rb 1
  2424. con.bScrollingUp            rb 1
  2425. con.bScrollingDown          rb 1
  2426.  
  2427. con.stack                   rb 1024
  2428. con.stack_top = $
  2429.