Subversion Repositories Kolibri OS

Rev

Rev 9105 | Rev 9127 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
836 diamond 1
; Функции работы с консолью для программ КолибриОС
852 diamond 2
; diamond, 2006-2008
836 diamond 3
 
4
 
5
format MS COFF
6
 
7
public EXPORTS
8
 
9
section '.flat' code readable align 16
10
include 'font.inc'
11
include 'conscrl.inc'
12
 
9105 hidnplayr 13
struc process_info
14
{
15
  .cpu_usage              dd ?  ; +0
16
  .window_stack_position  dw ?  ; +4
17
  .window_stack_value     dw ?  ; +6
18
                          dw ?  ; +8
19
  .process_name           rb 12 ; +10
20
  .memory_start           dd ?  ; +22
21
  .used_memory            dd ?  ; +26
22
  .PID                    dd ?  ; +30
23
  .box.x                  dd ?  ; +34
24
  .box.y                  dd ?  ; +38
25
  .box.width              dd ?  ; +42
26
  .box.height             dd ?  ; +46
27
  .slot_state             dw ?  ; +50
28
                          dw ?  ; +52
29
  .client_box.x           dd ?  ; +54
30
  .client_box.y           dd ?  ; +58
31
  .client_box.width       dd ?  ; +62
32
  .client_box.height      dd ?  ; +66
33
  .wnd_state              db ?  ; +70
34
  rb (1024-71)
35
}
36
 
37
OP_EXIT         = 1
38
OP_SET_TITLE    = 2
39
OP_REDRAW       = 3
40
OP_GETCH        = 4
41
OP_RESIZE       = 5
42
 
836 diamond 43
;void __stdcall START(dword state);
44
START:
45
; N.B. The current kernel implementation does not require
46
;      evident heap initialization, because if DLL is loaded, heap is already initialized
47
;      (if heap was not initialized, loader does this implicitly).
48
;      So this action does nothing useful, but nothing harmful.
6067 serge 49
        push    ebx
836 diamond 50
        push    68
51
        pop     eax
52
        push    11
53
        pop     ebx
54
        int     0x40
6067 serge 55
        pop     ebx
836 diamond 56
        or      eax, -1
57
        ret     4
58
 
59
; Инициализация консоли
60
; void __stdcall con_init(dword wnd_width, dword wnd_height,
61
;       dword scr_width, dword scr_height, const char* title);
62
 
63
align 4
64
con_init:
6067 serge 65
 
836 diamond 66
        pop     eax
67
        pop     [con.wnd_width]
68
        pop     [con.wnd_height]
9105 hidnplayr 69
        pop     [con.main_scr_width]
70
        pop     [con.main_scr_height]
836 diamond 71
        pop     [con.title]
72
        push    eax
2170 serge 73
 
9105 hidnplayr 74
        push    ebx
2170 serge 75
 
9105 hidnplayr 76
        mov     [con.init_cmd],1
6067 serge 77
 
836 diamond 78
        mov     ecx, 4
79
        mov     eax, con.wnd_width
2170 serge 80
        mov     edx, con.def_wnd_width
9105 hidnplayr 81
  .1:
836 diamond 82
        cmp     dword [eax], -1
83
        jnz     @f
2170 serge 84
        mov     ebx, [edx]
836 diamond 85
        mov     [eax], ebx
9105 hidnplayr 86
  @@:
836 diamond 87
        add     eax, 4
2170 serge 88
        add     edx, 4
836 diamond 89
        loop    .1
9105 hidnplayr 90
 
91
; Allocate memory for console data & bitmap data
92
; First, calculate required amount of bytes
93
 
94
; Main buffer
95
        mov     eax, [con.main_scr_width]
96
        mul     [con.main_scr_height]
97
;       2 bytes per on-screen character (1 flags and 1 ascii)
836 diamond 98
        lea     ecx, [eax+eax]
9105 hidnplayr 99
 
100
; Alternate buffer
101
        mov     [con.altbuffer], ecx
836 diamond 102
        mov     eax, [con.wnd_width]
103
        mul     [con.wnd_height]
9105 hidnplayr 104
;       2 bytes per on-screen character (1 flags and 1 ascii)
105
        lea     ecx, [ecx+2*eax]
106
 
107
; Bitmap data
108
        mov     eax, [con.wnd_width]
109
        mul     [con.wnd_height]
836 diamond 110
        imul    eax, font_width*font_height
111
        mov     ebx, eax
112
        push    ebx ecx
113
        add     ecx, eax
9105 hidnplayr 114
 
115
; malloc
836 diamond 116
        push    68
117
        pop     eax
118
        push    12
119
        pop     ebx
120
        int     0x40
121
        pop     ecx ebx
122
        mov     edx, con.nomem_err
123
        test    eax, eax
9105 hidnplayr 124
        jz      .fatal
125
 
126
; Set pointers to the buffers
127
        mov     [con.mainbuffer], eax
128
        add     [con.altbuffer], eax
129
 
130
; Set active buffer pointer and dimensions
836 diamond 131
        mov     [con.data], eax
9105 hidnplayr 132
 
133
        push    [con.main_scr_width]
134
        pop     [con.scr_width]
135
 
136
        push    [con.main_scr_height]
137
        pop     [con.scr_height]
138
 
139
; Clear text buffers
836 diamond 140
        push    edi
141
        mov     edi, eax
142
        shr     ecx, 1
143
        mov     ax, 0x0720
144
        rep     stosw
9105 hidnplayr 145
 
146
; Clear bitmap buffer
836 diamond 147
        mov     ecx, ebx
148
        mov     [con.image], edi
149
        xor     eax, eax
150
        rep     stosb
151
        pop     edi
1133 diamond 152
        and     byte [con_flags+1], not 2
9105 hidnplayr 153
 
836 diamond 154
; create console thread
155
        push    51
156
        pop     eax
157
        xor     ebx, ebx
158
        inc     ebx
159
        mov     ecx, con.thread
160
        mov     edx, con.stack_top
161
        int     0x40
162
        mov     edx, con.thread_err
163
        test    eax, eax
9105 hidnplayr 164
        js      .fatal
836 diamond 165
        mov     [con.console_tid], eax
166
        pop     ebx
167
        ret
9105 hidnplayr 168
 
169
  .fatal:
836 diamond 170
; output string to debug board and die
171
        mov     cl, [edx]
172
        test    cl, cl
173
        jz      @f
174
        push    63
175
        pop     eax
176
        xor     ebx, ebx
177
        inc     ebx
178
        int     0x40
179
        inc     edx
9105 hidnplayr 180
        jmp     .fatal
181
  @@:
836 diamond 182
        or      eax, -1
183
        int     0x40
184
 
185
; dword __stdcall con_get_flags(void);
186
con_get_flags:
187
        mov     eax, [con_flags]
188
        ret
189
 
190
; dword __stdcall con_set_flags(dword flags);
191
con_set_flags:
192
        mov     eax, [esp+4]
1133 diamond 193
        and     ah, not 2
836 diamond 194
        xchg    eax, [con_flags]
195
        ret     4
196
 
197
; dword __stdcall con_get_font_height(void);
198
con_get_font_height:
199
        mov     eax, font_height
200
        ret
201
 
202
; int __stdcall con_get_cursor_height(void);
203
con_get_cursor_height:
204
        mov     eax, [con.cursor_height]
205
        ret
206
 
207
; int __stdcall con_set_cursor_height(int new_height);
208
con_set_cursor_height:
209
        mov     eax, [esp+4]
210
        cmp     eax, font_height
211
        jae     @f
212
        xchg    eax, [con.cursor_height]
213
        ret     4
9105 hidnplayr 214
  @@:
836 diamond 215
        mov     eax, [con.cursor_height]
216
        ret     4
217
 
5835 pavelyakov 218
con_init_check:
9105 hidnplayr 219
        mov     ah, [con.init_cmd]
220
        test    ah, ah
221
        jne     .yes
6067 serge 222
 
9105 hidnplayr 223
        push    con.title_init_console
224
        push    -1
225
        push    -1
226
        push    -1
227
        push    -1
6067 serge 228
 
9105 hidnplayr 229
        call    con_init
230
  .yes:
231
        ret
6067 serge 232
 
836 diamond 233
; void __stdcall con_write_asciiz(const char* string);
234
con_write_asciiz:
9105 hidnplayr 235
 
236
        call    con_init_check
237
 
836 diamond 238
        push    ebx esi
239
        or      ebx, -1
240
        mov     esi, [esp+12]
241
        call    con.write
242
        pop     esi ebx
243
        ret     4
244
 
245
; void __stdcall con_write_string(const char* string, dword length);
246
con_write_length:
9105 hidnplayr 247
 
836 diamond 248
        push    ebx esi
249
        mov     esi, [esp+12]
250
        mov     ebx, [esp+16]
251
        call    con.write
252
        pop     esi ebx
253
        ret     8
254
 
255
; Каждый символ классифицируется как один из
256
con.printfc.normal = 0   ; нормальный символ
257
con.printfc.percent = 1  ; '%'
258
con.printfc.dot = 2      ; '.'
259
con.printfc.asterisk = 3 ; '*'
260
con.printfc.zero = 4     ; '0'
261
con.printfc.digit = 5    ; ненулевая цифра
262
con.printfc.plus = 6     ; '+'
263
con.printfc.minus = 7    ; '-'
264
con.printfc.sharp = 8    ; '#'
265
con.printfc.space = 9    ; ' '
266
con.printfc.long = 10    ; 'l' for 'long'
267
con.printfc.short = 11   ; 'h' for 'short'
268
con.printfc.dec = 12     ; 'd' = print decimal
269
con.printfc.oct = 13     ; 'o' = print octal
270
con.printfc.unsigned = 14 ; 'u' = print unsigned decimal
271
con.printfc.hex = 15     ; 'x' = print hexadecimal
272
con.printfc.pointer = 16 ; 'p' = print pointer
273
con.printfc.char = 17    ; 'c' = print char
274
con.printfc.string = 18  ; 's' = print string
275
 
276
macro set char,type
277
{store byte con.printfc.#type at con.charcodes + char - ' '}
278
 
279
con.charcodes:
280
times 'x'-' '+1         db      con.printfc.normal
281
        set     '%', percent
282
        set     '.', dot
283
        set     '*', asterisk
284
        set     '0', zero
285
        set     '1', digit
286
        set     '2', digit
287
        set     '3', digit
288
        set     '4', digit
289
        set     '5', digit
290
        set     '6', digit
291
        set     '7', digit
292
        set     '8', digit
293
        set     '9', digit
294
        set     ' ', space
295
        set     '#', sharp
296
        set     '+', plus
297
        set     '-', minus
298
        set     'X', hex
299
        set     'x', hex
300
        set     'c', char
301
        set     'd', dec
302
        set     'h', short
303
        set     'i', dec
304
        set     'l', long
305
        set     'o', oct
306
        set     'p', pointer
307
        set     's', string
308
        set     'u', unsigned
309
purge set
310
align 4
3690 hidnplayr 311
con.charjump:
312
        dd      con_printf.normal
836 diamond 313
        dd      con_printf.percent
314
        dd      con_printf.dot
315
        dd      con_printf.asterisk
316
        dd      con_printf.zero
317
        dd      con_printf.digit
318
        dd      con_printf.plus
319
        dd      con_printf.minus
320
        dd      con_printf.sharp
321
        dd      con_printf.space
322
        dd      con_printf.long
323
        dd      con_printf.short
324
        dd      con_printf.dec
325
        dd      con_printf.oct
326
        dd      con_printf.unsigned
327
        dd      con_printf.hex
328
        dd      con_printf.pointer
329
        dd      con_printf.char
330
        dd      con_printf.string
331
 
332
; int __cdecl con_printf(const char* format, ...)
333
con_printf:
9105 hidnplayr 334
 
335
        call    con_init_check
336
 
836 diamond 337
        xor     eax, eax
338
        pushad
339
        call    con.get_data_ptr
340
        lea     ebp, [esp+20h+8]
341
        mov     esi, [ebp-4]
342
        sub     esp, 64         ; reserve space for buffer
9105 hidnplayr 343
  .loop:
836 diamond 344
        xor     eax, eax
345
        lodsb
346
        test    al, al
347
        jz      .done
348
        cmp     al, '%'
349
        jz      .spec_begin
9105 hidnplayr 350
  .normal:
836 diamond 351
        call    con.write_char_ex
352
        inc     dword [esp+64+28]
353
        jmp     .loop
9105 hidnplayr 354
  .errspec:
355
  .percent:
836 diamond 356
        add     esp, 12
357
        jmp     .normal
9105 hidnplayr 358
  .spec_begin:
836 diamond 359
        xor     ebx, ebx
360
; bl = тип позиции:
361
; 0 = начало
362
; 1 = прочитан ведущий 0 в спецификации формата
363
; 2 = читаем поле ширины
364
; 3 = читаем поле точности
365
; 4 = прочитано поле размера аргумента
366
; 5 = читаем поле типа
367
; bh = флаги:
368
; 1 = флаг '#', выводить 0/0x/0X
369
; 2 = флаг '-', выравнивание влево
370
; 4 = флаг '0', дополнение нулями
371
; 8 = флаг 'h', короткий аргумент
372
        push    -1
373
; dword [esp+8] = precision
374
        push    -1
375
; dword [esp+4] = width
376
        push    0
377
; byte [esp] = флаг 0/'+'/' '
9105 hidnplayr 378
  .spec:
836 diamond 379
        xor     eax, eax
380
        lodsb
381
        test    al, al
382
        jz      .done
383
        cmp     al, ' '
384
        jb      .normal
385
        cmp     al, 'x'
386
        ja      .normal
387
        movzx   ecx, byte [con.charcodes + eax - ' ']
3690 hidnplayr 388
        jmp     dword[con.charjump + ecx*4]
836 diamond 389
 
9105 hidnplayr 390
  .sharp:
836 diamond 391
        test    bl, bl
392
        jnz     .errspec
393
        or      bh, 1
394
        jmp     .spec
9105 hidnplayr 395
  .minus:
836 diamond 396
        test    bl, bl
397
        jnz     .errspec
398
        or      bh, 2
399
        jmp     .spec
9105 hidnplayr 400
  .plus:
401
  .space:
836 diamond 402
        test    bl, bl
403
        jnz     .errspec
404
        cmp     byte [esp], '+'
405
        jz      .spec
406
        mov     byte [esp], al
407
        jmp     .spec
9105 hidnplayr 408
  .zero:
836 diamond 409
        test    bl, bl
410
        jnz     .digit
411
        test    bh, 2
412
        jnz     .spec
413
        or      bh, 4
414
        inc     ebx
415
        jmp     .spec
9105 hidnplayr 416
  .digit:
836 diamond 417
        sub     al, '0'
418
        cmp     bl, 2
419
        ja      .precision
420
        mov     bl, 2
421
        xchg    eax, [esp+4]
422
        test    eax, eax
423
        js      .spec
424
        lea     eax, [eax*5]
425
        add     eax, eax
426
        add     [esp+4], eax
427
        jmp     .spec
9105 hidnplayr 428
  .precision:
836 diamond 429
        cmp     bl, 3
430
        jnz     .errspec
431
        xchg    eax, [esp+8]
432
        lea     eax, [eax*5]
433
        add     eax, eax
434
        add     [esp+8], eax
435
        jmp     .spec
9105 hidnplayr 436
  .asterisk:
836 diamond 437
        mov     eax, [ebp]
438
        add     ebp, 4
439
        cmp     bl, 2
440
        ja      .asterisk_precision
441
        test    eax, eax
442
        jns     @f
443
        neg     eax
444
        or      bh, 2
9105 hidnplayr 445
  @@:
836 diamond 446
        mov     [esp+4], eax
447
        mov     bl, 3
448
        jmp     .spec
9105 hidnplayr 449
  .asterisk_precision:
836 diamond 450
        cmp     bl, 3
451
        jnz     .errspec
452
        mov     [esp+8], eax
453
        inc     ebx
454
        jmp     .spec
9105 hidnplayr 455
  .dot:
836 diamond 456
        cmp     bl, 2
457
        ja      .errspec
458
        mov     bl, 3
459
        and     dword [esp+8], 0
460
        jmp     .spec
9105 hidnplayr 461
  .long:
836 diamond 462
        cmp     bl, 3
463
        ja      .errspec
464
        mov     bl, 4
465
        jmp     .spec
9105 hidnplayr 466
  .short:
836 diamond 467
        cmp     bl, 3
468
        ja      .errspec
469
        mov     bl, 4
470
        or      bh, 8
471
        jmp     .spec
9105 hidnplayr 472
  .unsigned:
473
  .dec:
836 diamond 474
        push    10
475
        jmp     .write_number
9105 hidnplayr 476
  .pointer:
836 diamond 477
        mov     dword [esp+12], 8
478
        or      bh, 4
479
        and     bh, not 8
9105 hidnplayr 480
  .hex:
836 diamond 481
        push    16
482
        jmp     @f
9105 hidnplayr 483
  .oct:
836 diamond 484
        push    8
9105 hidnplayr 485
  @@:
836 diamond 486
        mov     byte [esp+4], 0
9105 hidnplayr 487
  .write_number:
836 diamond 488
        pop     ecx
489
        push    edi
490
        lea     edi, [esp+16+64-1]      ; edi -> end of buffer
491
        mov     byte [edi], 0
492
        push    edx
493
        push    eax
494
        mov     eax, [ebp]
495
        add     ebp, 4
496
        test    bh, 8
497
        jz      @f
498
        movzx   eax, ax
499
        cmp     byte [esp], 'd'
500
        jnz     @f
501
        movsx   eax, ax
9105 hidnplayr 502
  @@:
836 diamond 503
        xor     edx, edx
504
        test    eax, eax
505
        jns     @f
506
        cmp     byte [esp], 'd'
507
        jnz     @f
508
        inc     edx
509
        neg     eax
9105 hidnplayr 510
  @@:
836 diamond 511
        push    edx
512
        xor     edx, edx
513
; число в eax, основание системы счисления в ecx
9105 hidnplayr 514
  @@:
836 diamond 515
        cmp     dword [esp+16+8], 0
516
        jnz     .print_num
517
        test    eax, eax
518
        jz      .zeronum
9105 hidnplayr 519
  .print_num:
836 diamond 520
        div     ecx
521
        xchg    eax, edx
522
        cmp     al, 10
523
        sbb     al, 69h
524
        das
525
        cmp     byte [esp+4], 'x'
526
        jnz     @f
527
        or      al, 20h
9105 hidnplayr 528
  @@:
836 diamond 529
        dec     edi
530
        mov     [edi], al
531
        xor     eax, eax
532
        xchg    eax, edx
533
        test    eax, eax
534
        jnz     .print_num
9105 hidnplayr 535
  .zeronum:
836 diamond 536
        push    0
537
        mov     edx, [esp+12]
538
        lea     eax, [esp+32+64-1]
539
        sub     eax, edi
540
        cmp     dword [esp+20+8], -1
541
        jz      .noprec1
542
        cmp     eax, [esp+20+8]
543
        jae     .len_found1
544
        mov     eax, [esp+20+8]
545
        jmp     .len_found1
9105 hidnplayr 546
  .noprec1:
836 diamond 547
        test    bh, 4
548
        jnz     .do_print_num
9105 hidnplayr 549
  .len_found1:
836 diamond 550
        test    bh, 2
551
        jnz     .do_print_num
552
        cmp     byte [esp+20], 0
553
        jz      @f
554
        inc     eax
9105 hidnplayr 555
  @@:
836 diamond 556
        cmp     byte [esp+20], 0
557
        jnz     @f
558
        cmp     byte [esp+4], 0
559
        jz      @f
560
        inc     eax
9105 hidnplayr 561
  @@:
836 diamond 562
        test    bh, 1
563
        jz      .nosharp1
564
        cmp     cl, 8
565
        jnz     @f
566
        inc     eax
567
        jmp     .nosharp1
9105 hidnplayr 568
  @@:
836 diamond 569
        cmp     cl, 16
570
        jnz     .nosharp1
571
        inc     eax
572
        inc     eax
9105 hidnplayr 573
  .nosharp1:
836 diamond 574
        cmp     dword [esp+20+4], -1
575
        jz      .do_print_num
576
        sub     eax, [esp+20+4]
577
        jae     .do_print_num
578
        push    ecx
579
        mov     ecx, eax
580
        mov     al, ' '
9105 hidnplayr 581
  @@:
836 diamond 582
        xchg    edi, [esp+20]
583
        call    con.write_char_ex
584
        inc     dword [esp+24+12+64+28]
585
        xchg    edi, [esp+20]
586
        inc     dword [esp+4]
587
        inc     ecx
588
        jnz     @b
589
        pop     ecx
9105 hidnplayr 590
  .do_print_num:
836 diamond 591
        mov     al, '-'
592
        cmp     byte [esp+4], 0
593
        jnz     .write_sign
594
        mov     al, [esp+20]
595
        test    al, al
596
        jz      .sign_written
9105 hidnplayr 597
  .write_sign:
836 diamond 598
        call    .num_write_char
9105 hidnplayr 599
  .sign_written:
836 diamond 600
        test    bh, 1
601
        jz      .nosharp2
602
        mov     al, '0'
603
        cmp     cl, 8
604
        jz      @f
605
        cmp     cl, 16
606
        jnz     .nosharp2
607
        call    .num_write_char
608
        mov     al, [esp+8]
9105 hidnplayr 609
  @@:
836 diamond 610
        call    .num_write_char
9105 hidnplayr 611
  .nosharp2:
836 diamond 612
        lea     ecx, [esp+32+64-1]
613
        sub     ecx, edi
614
        cmp     dword [esp+20+8], -1
615
        jz      .noprec2
616
        sub     ecx, [esp+20+8]
617
        jmp     .lead_zeroes
9105 hidnplayr 618
  .noprec2:
836 diamond 619
        test    bh, 4
620
        jz      .do_print_num2
621
        add     ecx, [esp]
622
        sub     ecx, [esp+20+4]
9105 hidnplayr 623
  .lead_zeroes:
836 diamond 624
        jae     .do_print_num2
9105 hidnplayr 625
  @@:
836 diamond 626
        mov     al, '0'
627
        call    .num_write_char
628
        inc     ecx
629
        jnz     @b
9105 hidnplayr 630
  .do_print_num2:
836 diamond 631
        mov     al, [edi]
632
        test    al, al
633
        jz      .num_written
634
        call    .num_write_char
635
        inc     edi
636
        jmp     .do_print_num2
9105 hidnplayr 637
  .num_written:
836 diamond 638
        pop     ecx
639
        mov     edi, [esp+12]
640
        cmp     dword [esp+16+4], -1
641
        jz      .num_written2
9105 hidnplayr 642
  @@:
836 diamond 643
        cmp     ecx, [esp+16+4]
644
        jae     .num_written2
645
        mov     al, ' '
646
        call    con.write_char
647
        inc     ecx
648
        jmp     @b
9105 hidnplayr 649
  .num_written2:
836 diamond 650
        add     esp, 16
9105 hidnplayr 651
  .spec_done:
836 diamond 652
        add     esp, 12
653
        jmp     .loop
9105 hidnplayr 654
  .char:
836 diamond 655
        mov     ecx, [esp+4]
656
        cmp     ecx, -1
657
        jnz     @f
658
        inc     ecx
9105 hidnplayr 659
  @@:
836 diamond 660
        test    ecx, ecx
661
        jnz     @f
662
        inc     ecx
9105 hidnplayr 663
  @@:
836 diamond 664
        test    bh, 2
665
        jnz     .char_left_pad
666
        mov     al, ' '
667
        dec     ecx
668
        jz      .nowidth
669
        add     [esp+12+64+28], ecx
9105 hidnplayr 670
  @@:
836 diamond 671
        call    con.write_char
672
        loop    @b
9105 hidnplayr 673
  .nowidth:
836 diamond 674
        mov     al, [ebp]
675
        add     ebp, 4
676
        jmp     .percent
9105 hidnplayr 677
  .char_left_pad:
836 diamond 678
        mov     al, [ebp]
679
        add     ebp, 4
680
        call    con.write_char_ex
681
        add     [esp+12+64+28], ecx
682
        dec     ecx
683
        jz      .nowidth2
684
        mov     al, ' '
9105 hidnplayr 685
  @@:
836 diamond 686
        call    con.write_char
687
        loop    @b
9105 hidnplayr 688
  .nowidth2:
836 diamond 689
        jmp     .spec_done
9105 hidnplayr 690
  .string:
836 diamond 691
        push    esi
692
        mov     esi, [ebp]
693
        test    esi, esi
694
        jnz     @f
695
        mov     esi, con.aNull
9105 hidnplayr 696
  @@:
836 diamond 697
        add     ebp, 4
698
        or      ecx, -1
9105 hidnplayr 699
  @@:
836 diamond 700
        inc     ecx
701
        cmp     byte [esi+ecx], 0
702
        jnz     @b
703
        cmp     ecx, [esp+12]
704
        jb      @f
705
        mov     ecx, [esp+12]
9105 hidnplayr 706
  @@:
836 diamond 707
        test    bh, 2
708
        jnz     .write_string
709
        cmp     dword [esp+8], -1
710
        jz      .write_string
711
        push    ecx
712
        sub     ecx, [esp+12]
713
        jae     .nospace
714
        mov     al, ' '
9105 hidnplayr 715
  @@:
836 diamond 716
        call    con.write_char
717
        inc     dword [esp+20+64+28]
718
        inc     ecx
719
        jnz     @b
9105 hidnplayr 720
  .nospace:
836 diamond 721
        pop     ecx
9105 hidnplayr 722
  .write_string:
836 diamond 723
        jecxz   .string_written
724
        add     dword [esp+16+64+28], ecx
725
        push    ecx
9105 hidnplayr 726
  @@:
836 diamond 727
        lodsb
728
        call    con.write_char_ex
729
        loop    @b
730
        pop     ecx
9105 hidnplayr 731
  .string_written:
836 diamond 732
        pop     esi
733
        test    bh, 2
734
        jz      .spec_done
735
        cmp     dword [esp+4], -1
736
        jz      .spec_done
737
        sub     ecx, [esp+4]
738
        jae     .spec_done
739
        mov     al, ' '
9105 hidnplayr 740
  @@:
836 diamond 741
        call    con.write_char
742
        inc     dword [esp+12+64+28]
743
        inc     ecx
744
        jnz     @b
745
        jmp     .spec_done
9105 hidnplayr 746
  .done:
836 diamond 747
        add     esp, 64
748
        popad
749
        jmp     con.update_screen
9105 hidnplayr 750
  .num_write_char:
836 diamond 751
        xchg    edi, [esp+20]
752
        call    con.write_char_ex
753
        inc     dword [esp+24+12+64+28]
754
        xchg    edi, [esp+20]
755
        inc     dword [esp+4]
756
        ret
757
 
758
con.write:
759
; esi = string, ebx = length (ebx=-1 for ASCIIZ strings)
760
        push    edi
761
        call    con.get_data_ptr
762
        test    ebx, ebx
763
        jz      .done
9105 hidnplayr 764
  .loop:
836 diamond 765
        lodsb
766
        cmp     ebx, -1
767
        jnz     @f
768
        test    al, al
769
        jz      .done
9105 hidnplayr 770
  @@:
836 diamond 771
        call    con.write_char_ex
9105 hidnplayr 772
  .next:
836 diamond 773
        cmp     ebx, -1
774
        jz      .loop
775
        dec     ebx
776
        jnz     .loop
9105 hidnplayr 777
  .done:
836 diamond 778
        pop     edi
779
        jmp     con.update_screen
780
 
781
con.get_data_ptr:
782
        mov     edi, [con.cur_y]
783
        imul    edi, [con.scr_width]
784
        add     edi, [con.cur_x]
785
        add     edi, edi
786
        add     edi, [con.data]
787
        ret
788
 
789
con.write_char_ex:
790
        test    byte [con_flags+1], 1
791
        jz      con.write_special_char
792
 
793
con.write_char:
794
        push    eax
3690 hidnplayr 795
 
796
        mov     eax, [con.cur_x]
797
        cmp     eax, [con.scr_width]
798
        jb      @f
799
        and     [con.cur_x], 0
800
        call    con.newline
9105 hidnplayr 801
  @@:
3690 hidnplayr 802
        mov     eax, [esp]
836 diamond 803
        stosb
804
        mov     al, byte [con_flags]
805
        stosb
3690 hidnplayr 806
 
836 diamond 807
        mov     eax, [con.cur_x]
808
        inc     eax
809
        mov     [con.cur_x], eax
3690 hidnplayr 810
 
836 diamond 811
        pop     eax
812
        ret
813
 
814
con.write_special_char:
815
        cmp     [con_esc], 0
816
        jnz     .esc_mode
9105 hidnplayr 817
  .normal_mode:
836 diamond 818
        cmp     al, 10
819
        jz      .write_lf
820
        cmp     al, 13
821
        jz      .write_cr
822
        cmp     al, 27
823
        jz      .write_esc
824
        cmp     al, 8
825
        jz      .write_bs
9096 hidnplayr 826
        cmp     al, 7
827
        jz      .bell
836 diamond 828
        cmp     al, 9
829
        jnz     con.write_char
9105 hidnplayr 830
  .write_tab:
836 diamond 831
        mov     al, ' '
832
        call    con.write_char
833
        test    [con.cur_x], 7
834
        jnz     .write_tab
835
        ret
9105 hidnplayr 836
  .write_cr:
836 diamond 837
        and     [con.cur_x], 0
838
        jmp     con.get_data_ptr
9105 hidnplayr 839
  .write_lf:
836 diamond 840
        and     [con.cur_x], 0
841
        jmp     con.newline
9105 hidnplayr 842
  .write_bs:
836 diamond 843
        cmp     [con.cur_x], 0
844
        jz      @f
845
        dec     [con.cur_x]
846
        dec     edi
847
        dec     edi
848
        ret
9105 hidnplayr 849
  @@:
836 diamond 850
        push    eax
851
        mov     eax, [con.cur_y]
852
        dec     eax
853
        js      @f
854
        mov     [con.cur_y], eax
855
        mov     eax, [con.scr_width]
856
        dec     eax
857
        mov     [con.cur_x], eax
858
        dec     edi
859
        dec     edi
9105 hidnplayr 860
  @@:
836 diamond 861
        pop     eax
862
        ret
9105 hidnplayr 863
  .bell:
9096 hidnplayr 864
        pusha
865
        push    55
866
        pop     eax
867
        mov     ebx, eax
9105 hidnplayr 868
        mov     esi, con.bell
9096 hidnplayr 869
        int     0x40
870
        popa
871
        ret
9105 hidnplayr 872
  .write_esc:
836 diamond 873
        mov     [con_esc], 1
874
        mov     [con_esc_attr_n], 1
875
        and     [con_esc_attrs], 0
876
        ret
9105 hidnplayr 877
 
878
  .esc_mode:
836 diamond 879
        cmp     [con_sci], 0
880
        jnz     .esc_sci
9125 hidnplayr 881
        cmp     al, '['         ; CSI - Control Sequence Introducer
9105 hidnplayr 882
        je      .esc_sqro
9125 hidnplayr 883
        cmp     al, ']'         ; OSC - Operating System Command
9105 hidnplayr 884
        je      .esc_sqrc
9125 hidnplayr 885
        cmp     al, '('         ; Designate G0 Character Set, VT100, ISO 2022.
9105 hidnplayr 886
        je      .esc_rndo
9125 hidnplayr 887
        cmp     al, '>'         ; Normal Keypad (DECKPNM), VT100.
9105 hidnplayr 888
        je      .keypm_norm
9125 hidnplayr 889
        cmp     al, '='         ; Application Keypad (DECKPAM).
9105 hidnplayr 890
        je      .keypm_alt
9125 hidnplayr 891
; Control characters
892
        cmp     al, 'G'
893
        je      .bell
894
        cmp     al, 'H'
895
        je      .write_bs
896
        cmp     al, 'I'
897
        je      .write_tab
898
        cmp     al, 'J'
899
        je      .write_lf
900
        cmp     al, 'M'
901
        je      .write_cr
9105 hidnplayr 902
; Unrecognized escape sequence, print it to screen
836 diamond 903
        push    eax
904
        mov     al, 27
905
        call    con.write_char
906
        pop     eax
907
        jmp     con.write_char
9105 hidnplayr 908
 
909
  .esc_sqro:
910
        mov     [con_sci], 1
911
        ret
912
  .esc_sqrc:
913
        mov     [con_sci], 2
914
        ret
915
  .esc_rndo:
916
        mov     [con_sci], 4
917
        ret
918
 
919
.keypm_norm:
920
; TODO: turn numlock on
921
        mov     [con_esc], 0
922
        ret
923
 
924
.keypm_alt:
925
; TODO: turn numlock off
926
        mov     [con_esc], 0
927
        ret
928
 
836 diamond 929
.esc_sci:
9105 hidnplayr 930
        cmp     [con_sci], 3
931
        je      .string
932
        cmp     [con_sci], 4
933
        je      .g0charset
836 diamond 934
; this is real Esc sequence
3886 hidnplayr 935
        cmp     al, '?'         ; DEC private mode (DECSET/DECRST sequences)
936
        je      .questionmark
836 diamond 937
        cmp     al, ';'
938
        jz      .next_arg
939
        cmp     al, '0'
940
        jb      .not_digit
941
        cmp     al, '9'
942
        ja      .not_digit
943
        push    eax ecx edx
944
        sub     al, '0'
945
        movzx   eax, al
946
        mov     ecx, [con_esc_attr_n]
947
        mov     edx, [con_esc_attrs+(ecx-1)*4]
948
        lea     edx, [edx*5]
949
        lea     edx, [edx*2+eax]
950
        mov     [con_esc_attrs+(ecx-1)*4], edx
951
        pop     edx ecx eax
952
        ret
9105 hidnplayr 953
.g0charset:
954
; Designate G0 Character Set
955
; Unimplemented: read and ignore.
956
        mov     [con_sci], 0
957
        mov     [con_esc], 0
958
        ret
959
.string:
960
        cmp     al, 0x07        ; bell
961
        je      .string_end
962
        cmp     al, 0x9C        ; string terminator
963
        je      .string_end
964
        push    ecx
965
        mov     ecx, [con_osc_strlen]
966
        cmp     ecx, 255
967
        jae     @f
968
        mov     [con_osc_str+ecx], al
969
        inc     [con_osc_strlen]
970
@@:
971
        pop     ecx
972
        ret
973
.string_end:
974
        mov     [con_sci], 0
975
        mov     [con_esc], 0
976
        pusha
977
        mov     ecx, [con_osc_strlen]
978
        mov     byte[con_osc_str+ecx], 0
979
        cmp     [con_esc_attrs+0], 0            ; Set Icon and Window Title
980
        je      .set_title
981
        cmp     [con_esc_attrs+0], 2            ; Set Window Title
982
        je      .set_title
983
        ret
984
.set_title:
985
        push    con_osc_str
986
        call    con_set_title
987
        popa
988
        ret
3886 hidnplayr 989
.questionmark:
990
        push    ecx
991
        mov     ecx, [con_esc_attr_n]
992
        mov     dword[con_esc_attrs+(ecx-1)*4], 0xffffffff
993
        pop     ecx
836 diamond 994
.next_arg:
995
        push    eax
996
        mov     eax, [con_esc_attr_n]
997
        inc     eax
998
        cmp     al, 4
999
        jbe     @f
1000
        dec     eax
1001
@@:
1002
        mov     [con_esc_attr_n], eax
1003
        and     [con_esc_attrs+(eax-1)*4], 0
9105 hidnplayr 1004
; Check for operating system command
1005
        cmp     [con_sci], 2
1006
        jne     @f
1007
        cmp     [con_esc_attr_n], 2
1008
        jne     @f
1009
; Next argument is string
1010
        mov     [con_sci], 3
1011
        mov     [con_osc_strlen], 0
1012
@@:
836 diamond 1013
        pop     eax
1014
        ret
1015
.not_digit:
1016
        mov     [con_esc], 0
1017
        mov     [con_sci], 0    ; in any case, leave Esc mode
9105 hidnplayr 1018
 
1019
;        cmp     al, '@'
1020
;        je      .insert_chars
853 diamond 1021
        cmp     al, 'A'
9105 hidnplayr 1022
        je      .cursor_up
853 diamond 1023
        cmp     al, 'B'
9105 hidnplayr 1024
        je      .cursor_down
853 diamond 1025
        cmp     al, 'C'
9105 hidnplayr 1026
        je      .cursor_right
853 diamond 1027
        cmp     al, 'D'
9105 hidnplayr 1028
        je      .cursor_left
1029
;        cmp     al, 'E'
1030
;        je      .cursor_next_line
1031
;        cmp     al, 'F'
1032
;        je      .cursor_prev_line
1033
;        cmp     al, 'G'
1034
;        je      .cursor_next_line
1035
;        cmp     al, 'S'
1036
;        je      .scroll_page_up
1037
;        cmp     al, 'T'
1038
;        je      .scroll_page_down
1039
        cmp     al, 'H'
1040
        je      .cursor_position
1041
        cmp     al, 'J'
1042
        je      .erase_in_display
9096 hidnplayr 1043
        cmp     al, 'K'
1044
        je      .erase_in_line
9105 hidnplayr 1045
        cmp     al, 'L'
1046
        je      .insert_lines
1047
        cmp     al, 'M'
1048
        je      .delete_lines
1049
        cmp     al, 'P'
1050
        je      .delete_chars
1051
        cmp     al, 'X'
1052
        je      .erase_chars
1053
 
1054
        cmp     al, 'd'
1055
        je      .line_position_abs
1056
;        cmp     al, 'e'
1057
;        je      .line_position_rel
1058
        cmp     al, 'f'
1059
        je      .cursor_position
1060
        cmp     al, 'h'
1061
        je      .set_mode
1062
        cmp     al, 'l'
1063
        je      .reset_mode
1064
        cmp     al, 'm'
1065
        je      .set_attr
1066
        cmp     al, 'r'
1067
        je      .scroll_region
1068
;        cmp     al, 's'
1069
;        je      .save_cursor_pos
1070
;        cmp     al, 't'
1071
;        je      .window_manip
1072
;        cmp     al, 'u'
1073
;        je      .restore_cursor_pos
1074
 
836 diamond 1075
        ret     ; simply skip unknown sequences
3886 hidnplayr 1076
 
9105 hidnplayr 1077
.insert_lines:
1078
 
1079
        push    eax ebx ecx esi
1080
        mov     eax, [con_esc_attrs+0]  ; amount of lines to scroll down
1081
        test    eax, eax
1082
        jnz     @f                      ; default is 1
1083
        inc     eax
1084
  @@:
1085
; Check that we are inside the scroll region
1086
        mov     ebx, [con.cur_y]
1087
        cmp     ebx, [con.scroll_top]
1088
        jb      .no_insert_lines
1089
        add     ebx, eax
1090
        cmp     ebx, [con.scroll_bot]
1091
        ja      .no_insert_lines
1092
; Move cursor to the left
1093
        mov     [con.cur_x], 0
1094
        call    con.get_data_ptr
1095
; Calc amount of chars in requested numer of lines
1096
        mov     ebx, [con.scr_width]
1097
        imul    ebx, eax
1098
; Move the lines down (in backwards order)
1099
        push    edi
1100
        mov     ecx, [con.scroll_bot]
1101
        sub     ecx, [con.cur_y]
1102
        sub     ecx, eax
1103
        imul    ecx, [con.scr_width]
1104
        lea     esi, [edi + 2*ecx - 2]
1105
        lea     edi, [esi + 2*ebx]
1106
        std
1107
        rep     movsw
1108
        cld
1109
        pop     edi
1110
; Insert empty lines
1111
        push    edi
1112
        mov     ecx, ebx
1113
        mov     ah, byte[con_flags]
1114
        mov     al, ' '
1115
        rep     stosw
1116
        pop     edi
1117
.no_insert_lines:
1118
        pop     esi ecx ebx eax
1119
        ret
1120
 
1121
.delete_lines:
1122
 
1123
        push    eax ebx ecx esi
1124
        mov     eax, [con_esc_attrs+0]  ; amount of lines to scroll up
1125
        test    eax, eax
1126
        jnz     @f                      ; default is 1
1127
        inc     eax
1128
  @@:
1129
; Check that we are inside the scroll region
1130
        mov     ebx, [con.cur_y]
1131
        cmp     ebx, [con.scroll_top]
1132
        jb      .no_delete_lines
1133
        add     ebx, eax
1134
        cmp     ebx, [con.scroll_bot]
1135
        ja      .no_delete_lines
1136
; Move cursor to the left
1137
        mov     [con.cur_x], 0
1138
        call    con.get_data_ptr
1139
; Calc amount of chars in requested numer of lines
1140
        mov     ebx, [con.scr_width]
1141
        imul    ebx, eax
1142
; Move the lines up
1143
        mov     ecx, [con.scroll_bot]
1144
        sub     ecx, [con.cur_y]
1145
        imul    ecx, [con.scr_width]
1146
        lea     esi, [edi + 2*ebx]
1147
        rep     movsw
1148
; Set new cursor row position
1149
        add     [con.cur_y], eax
1150
; Add empty lines till end of scroll region
1151
        push    edi
1152
        mov     ecx, ebx
1153
        mov     ah, byte[con_flags]
1154
        mov     al, ' '
1155
        rep     stosw
1156
        pop     edi
1157
.no_delete_lines:
1158
        pop     esi ecx ebx eax
1159
        ret
1160
 
1161
.scroll_region:
1162
        push    eax ebx
1163
        cmp     [con_esc_attr_n], 2
1164
        jb      .no_scroll_region
1165
        mov     eax, [con_esc_attrs+0]  ; top
1166
        dec     eax
1167
        js      .no_scroll_region
1168
        cmp     eax, [con.wnd_height]
1169
        ja      .no_scroll_region
1170
 
1171
        mov     ebx, [con_esc_attrs+4]  ; bottom
1172
        dec     ebx
1173
        js      .no_scroll_region
1174
        cmp     ebx, [con.wnd_height]
1175
        ja      .no_scroll_region
1176
 
1177
        cmp     eax, ebx
1178
        ja      .no_scroll_region
1179
 
1180
        mov     [con.scroll_top], eax
1181
        mov     [con.scroll_bot], ebx
1182
 
1183
.no_scroll_region:
1184
        pop     ebx eax
1185
        ret
1186
 
1187
.reset_mode:
3886 hidnplayr 1188
        mov     eax, [con_esc_attrs]
1189
        cmp     eax, 0xffffffff
1190
        jne     .no_dec_rst
1191
        mov     eax, [con_esc_attrs+4]
9105 hidnplayr 1192
        cmp     eax, 1
1193
        je      .dec_rst_app_cursor_keys
1194
;        cmp     eax, 7
1195
;        je      .dec_rst_wraparound
1196
;        cmp     eax, 12
1197
;        je      .dec_rst_cursor_blink
3886 hidnplayr 1198
        cmp     eax, 25
9105 hidnplayr 1199
        je      .dec_rst_cursor
1200
;        cmp     eax, 1000
1201
;        je      .dec_rst_mouse
1202
;        cmp     eax, 1002
1203
;        je      .dec_rst_buttons
1204
;        cmp     eax, 1006
1205
;        je      .dec_rst_mouse_sgr
1206
        cmp     eax, 1049
1207
        je      .dec_rst_altbuff
1208
;        cmp     eax, 2004
1209
;        je      .dec_rst_brck_paste
3886 hidnplayr 1210
.no_dec_rst:
9105 hidnplayr 1211
;        cmp     eax, 2
1212
;        je      .rst_keyb_action_mode
1213
;        cmp     eax, 4
1214
;        je      .set_replace_mode
3886 hidnplayr 1215
        ret
1216
 
9105 hidnplayr 1217
.set_mode:
3886 hidnplayr 1218
        mov     eax, [con_esc_attrs]
1219
        cmp     eax, 0xffffffff
1220
        jne     .no_dec_set
1221
        mov     eax, [con_esc_attrs+4]
9105 hidnplayr 1222
        cmp     eax, 1
1223
        je      .dec_set_app_cursor_keys
1224
;        cmp     eax, 7
1225
;        je      .dec_set_wraparound
1226
;        cmp     eax, 12
1227
;        je      .dec_set_cursor_blink
3886 hidnplayr 1228
        cmp     eax, 25
9105 hidnplayr 1229
        je      .dec_set_cursor
1230
;        cmp     eax, 1000
1231
;        je      .dec_set_mouse
1232
;        cmp     eax, 1002
1233
;        je      .set_buttons
1234
;        cmp     eax, 1006
1235
;        je      .dec_rst_mouse_sgr
1236
        cmp     eax, 1049
1237
        je      .dec_set_altbuff
1238
;        cmp     eax, 2004
1239
;        je      .dec_set_brck_paste
3886 hidnplayr 1240
.no_dec_set:
9105 hidnplayr 1241
;        cmp     eax, 2
1242
;        je      .set_keyb_action_mode
1243
;        cmp     eax, 4
1244
;        je      .set_insert_mode
3886 hidnplayr 1245
        ret
1246
 
9105 hidnplayr 1247
.dec_set_app_cursor_keys:
1248
        mov     [cursor_esc], 27 + ('O' shl 8)
1249
        ret
1250
 
1251
.dec_rst_app_cursor_keys:
1252
        mov     [cursor_esc], 27 + ('[' shl 8)
1253
        ret
1254
 
1255
.dec_set_cursor:
3886 hidnplayr 1256
        mov     [con.cursor_height], (15*font_height+50)/100    ; default height
1257
        ret
9096 hidnplayr 1258
 
9105 hidnplayr 1259
.dec_rst_cursor:
1260
        mov     [con.cursor_height], 0
1261
        ret
1262
 
1263
.dec_set_altbuff:
1264
; Switch buffer
1265
        push    [con.altbuffer]
1266
        pop     [con.data]
1267
; Set new buffer size
1268
        push    [con.wnd_width]
1269
        pop     [con.scr_width]
1270
        push    [con.wnd_height]
1271
        pop     [con.scr_height]
1272
; Save cursor
1273
        push    [con.cur_x]
1274
        pop     [con.main_cur_x]
1275
        push    [con.cur_y]
1276
        pop     [con.main_cur_y]
1277
; Save window position
1278
        push    [con.wnd_xpos]
1279
        pop     [con.main_wnd_xpos]
1280
        push    [con.wnd_ypos]
1281
        pop     [con.main_wnd_ypos]
1282
; Clear screen
1283
        mov     edi, [con.altbuffer]
1284
        mov     eax, [con.wnd_width]
1285
        mul     [con.wnd_height]
1286
        mov     ecx, eax
1287
        mov     ah, byte[con_flags]
1288
        mov     al, ' '
1289
        rep     stosw
1290
; Reset cursor position
1291
        mov     [con.cur_x], 0
1292
        mov     [con.cur_y], 0
1293
; Reset window position
1294
        mov     [con.wnd_xpos], 0
1295
        mov     [con.wnd_ypos], 0
1296
; Get new data ptr so we can sart writing to new buffer
1297
        call    con.get_data_ptr
1298
; Finally, tell the GUI the window has been resized
1299
; (Redraw scrollbar and image)
1300
        mov     [con.thread_op], OP_RESIZE
1301
        jmp     con.wake
1302
 
1303
.dec_rst_altbuff:
1304
; Switch buffer
1305
        push    [con.mainbuffer]
1306
        pop     [con.data]
1307
; Set new buffer size
1308
        push    [con.main_scr_width]
1309
        pop     [con.scr_width]
1310
        push    [con.main_scr_height]
1311
        pop     [con.scr_height]
1312
; Restore cursor
1313
        push    [con.main_cur_x]
1314
        pop     [con.cur_x]
1315
        push    [con.main_cur_y]
1316
        pop     [con.cur_y]
1317
; Restore window position
1318
        push    [con.main_wnd_xpos]
1319
        pop     [con.wnd_xpos]
1320
        push    [con.main_wnd_ypos]
1321
        pop     [con.wnd_ypos]
1322
; Get new data ptr so we can sart writing to new buffer
1323
        call    con.get_data_ptr
1324
; Finally, tell the GUI the window has been resized
1325
; (Redraw scrollbar and image)
1326
        mov     [con.thread_op], OP_RESIZE
1327
        jmp     con.wake
1328
 
1329
.erase_chars:
1330
        push    edi ecx
1331
        mov     ecx, [con_esc_attrs]
1332
        test    ecx, ecx
1333
        jnz     @f
1334
        inc     ecx
1335
@@:
1336
        mov     ah, byte[con_flags]
1337
        mov     al, ' '
1338
        rep     stosw
1339
        pop     ecx edi
1340
        ; Unclear where cursor should point to now..
1341
        ret
1342
 
1343
.delete_chars:
1344
        push    edi ecx
1345
        mov     ecx, [con_esc_attrs]
1346
        test    ecx, ecx
1347
        jnz     @f
1348
        inc     ecx
1349
@@:
1350
        sub     edi, 2
1351
        mov     ah, byte[con_flags]
1352
        mov     al, ' '
1353
        std
1354
        rep     stosw
1355
        cld
1356
        pop     ecx edi
1357
        ret
1358
 
9096 hidnplayr 1359
.erase_in_line:
1360
        mov     eax, [con_esc_attrs]
1361
        test    eax, eax
9105 hidnplayr 1362
        jz      .erase_after                    ; [0K (or [K)
9096 hidnplayr 1363
        dec     eax
9105 hidnplayr 1364
        jz      .erase_before                   ; [1K
9096 hidnplayr 1365
        dec     eax
1366
        je      .erase_current_line             ; [2K
1367
        ret     ; unknown sequence
1368
 
9105 hidnplayr 1369
.erase_after:
9096 hidnplayr 1370
        push    edi ecx
1371
        mov     ecx, [con.scr_width]
1372
        sub     ecx, [con.cur_x]
1373
        mov     ah, byte[con_flags]
1374
        mov     al, ' '
1375
        rep     stosw
1376
        pop     ecx edi
1377
        ret
1378
 
9105 hidnplayr 1379
.erase_before:
9096 hidnplayr 1380
        push    edi ecx
1381
        mov     edi, [con.cur_y]
1382
        imul    edi, [con.scr_width]
1383
        shl     edi, 1
1384
        add     edi, [con.data]
1385
        mov     ecx, [con.cur_y]
1386
        mov     ah, byte[con_flags]
1387
        mov     al, ' '
1388
        rep     stosw
1389
        pop     ecx edi
1390
        ret
1391
 
1392
.erase_current_line:
1393
        push    edi ecx
1394
        mov     edi, [con.cur_y]
1395
        imul    edi, [con.scr_width]
1396
        shl     edi, 1
1397
        add     edi, [con.data]
1398
        mov     ecx, [con.scr_width]
1399
        mov     ah, byte[con_flags]
1400
        mov     al, ' '
1401
        rep     stosw
1402
        pop     ecx edi
1403
        ret
1404
 
9105 hidnplayr 1405
.erase_in_display:
3885 hidnplayr 1406
        mov     eax, [con_esc_attrs]
1407
        test    eax, eax
9105 hidnplayr 1408
        jz      .erase_below            ; [0J (or [J)
3885 hidnplayr 1409
        dec     eax
9105 hidnplayr 1410
        jz      .erase_above            ; [1J
3885 hidnplayr 1411
        dec     eax
9105 hidnplayr 1412
        je      .erase_all              ; [2J
3885 hidnplayr 1413
        ret     ; unknown sequence
1414
 
9105 hidnplayr 1415
.erase_below:
3885 hidnplayr 1416
        push    edi ecx
1417
        mov     ecx, [con.scr_width]
1418
        imul    ecx, [con.scr_height]
1419
 
1420
        mov     edi, [con.cur_y]
1421
        imul    edi, [con.scr_width]
1422
        add     edi, [con.cur_x]
1423
 
1424
        sub     ecx, edi
1425
        shl     edi, 1
1426
        add     edi, [con.data]
1427
        mov     ah, byte[con_flags]
1428
        mov     al, ' '
1429
        rep     stosw
1430
 
1431
        and     [con.cur_x], 0
1432
        and     [con.cur_y], 0
1433
        pop     ecx edi
1434
        ret
1435
 
9105 hidnplayr 1436
.erase_above:
3885 hidnplayr 1437
        push    edi ecx
1438
        mov     ecx, [con.cur_y]
1439
        imul    ecx, [con.scr_width]
1440
        add     ecx, [con.cur_x]
1441
        mov     edi, [con.data]
1442
        mov     ah, byte[con_flags]
1443
        mov     al, ' '
1444
        rep     stosw
1445
        pop     ecx edi
1446
        ret
1447
 
9105 hidnplayr 1448
.erase_all:   ; clear screen completely
853 diamond 1449
        push    ecx
1450
        and     [con.cur_x], 0
1451
        and     [con.cur_y], 0
1452
        mov     edi, [con.data]
1453
        push    edi
1454
        mov     ecx, [con.scr_width]
1455
        imul    ecx, [con.scr_height]
1456
        mov     ax, 0720h
1457
        rep     stosw
1458
        pop     edi ecx
1459
.nosetcursor:
1460
        ret
9105 hidnplayr 1461
.line_position_abs:
1462
        mov     eax, [con_esc_attrs]
1463
        dec     eax
1464
        jns     @f
1465
        inc     eax
1466
@@:
1467
        cmp     eax, [con.scr_height]
1468
        jae     .nolinepos
3688 hidnplayr 1469
        mov     [con.cur_y], eax
9105 hidnplayr 1470
        jmp     con.get_data_ptr
1471
.nolinepos:
1472
        ret
1473
.cursor_position:
1474
; We always have at least one con_esc_attr, defaulting to 0
1475
; Coordinates however are 1-based
1476
; First comes Y (row) and then X (column)
1477
        mov     eax, [con_esc_attrs]
1478
        dec     eax
1479
        jns     @f
1480
        inc     eax
3686 hidnplayr 1481
@@:
9105 hidnplayr 1482
        cmp     eax, [con.scr_height]
1483
        jae     .no_y
1484
        mov     [con.cur_y], eax
1485
.no_y:
1486
        cmp     [con_esc_attr_n], 2
1487
        jb      .no_x
1488
        mov     eax, [con_esc_attrs+4]
1489
        dec     eax
1490
        jns     @f
1491
        inc     eax
1492
@@:
853 diamond 1493
        cmp     eax, [con.scr_width]
9105 hidnplayr 1494
        jae     .no_x
853 diamond 1495
        mov     [con.cur_x], eax
9105 hidnplayr 1496
.no_x:
853 diamond 1497
.j_get_data:
1498
        jmp     con.get_data_ptr
1499
.cursor_up:
9105 hidnplayr 1500
        mov     eax, [con_esc_attrs]
1501
        test    eax, eax
1502
        jnz     @f
1503
        inc     eax     ; default = 1
853 diamond 1504
@@:
9105 hidnplayr 1505
        sub     [con.cur_y], eax
1506
        jns     .j_get_data
1507
        mov     [con.cur_y], 0
853 diamond 1508
        jmp     .j_get_data
1509
.cursor_down:
9105 hidnplayr 1510
        mov     eax, [con_esc_attrs]
1511
        test    eax, eax
1512
        jnz     @f
1513
        inc     eax     ; default = 1
1514
@@:
1515
        add     eax, [con.cur_y]
853 diamond 1516
        cmp     eax, [con.scr_height]
9105 hidnplayr 1517
        ja      @f
1518
        mov     [con.cur_y], eax
1519
        jmp     .j_get_data
1520
@@:
853 diamond 1521
        mov     eax, [con.scr_height]
1522
        mov     [con.cur_y], eax
1523
        jmp     .j_get_data
1524
.cursor_right:
9105 hidnplayr 1525
        mov     eax, [con_esc_attrs]
1526
        test    eax, eax
1527
        jnz     @f
1528
        inc     eax     ; default = 1
1529
@@:
1530
        add     eax, [con.cur_x]
853 diamond 1531
        cmp     eax, [con.scr_width]
9105 hidnplayr 1532
        ja      @f
1533
        mov     [con.cur_x], eax
1534
        jmp     .j_get_data
1535
@@:
853 diamond 1536
        mov     eax, [con.scr_width]
1537
        mov     [con.cur_x], eax
1538
        jmp     .j_get_data
1539
.cursor_left:
9105 hidnplayr 1540
        test    eax, eax
1541
        jnz     @f
1542
        inc     eax     ; default = 1
853 diamond 1543
@@:
9105 hidnplayr 1544
        sub     [con.cur_x], eax
1545
        jns     .j_get_data
1546
        mov     [con.cur_x], 0
853 diamond 1547
        jmp     .j_get_data
836 diamond 1548
.set_attr:
1549
        push    eax ecx edx
1550
        xor     ecx, ecx
1551
.set_one_attr:
1552
        mov     eax, [con_esc_attrs+ecx*4]
1553
        cmp     al, 0
1554
        jz      .attr_normal
1555
        cmp     al, 1
1556
        jz      .attr_bold
1557
        cmp     al, 5
1558
        jz      .attr_bgr_bold
1559
        cmp     al, 7
1560
        jz      .attr_reversed
9105 hidnplayr 1561
;        cmp     al, 8
1562
;        jz      .attr_invisible
1563
        cmp     al, 27
1564
        jz      .attr_normal    ; FIXME: not inverse
1565
;        cmp     al, 28
1566
;        jz      .attr_visible
3690 hidnplayr 1567
 
9105 hidnplayr 1568
; Forground colors
836 diamond 1569
        xor     edx, edx
9105 hidnplayr 1570
        cmp     al, 30          ; Black
836 diamond 1571
        jz      .attr_color
1572
        mov     dl, 4
9105 hidnplayr 1573
        cmp     al, 31          ; Red
836 diamond 1574
        jz      .attr_color
1575
        mov     dl, 2
9105 hidnplayr 1576
        cmp     al, 32          ; Green
836 diamond 1577
        jz      .attr_color
1578
        mov     dl, 6
9105 hidnplayr 1579
        cmp     al, 33          ; Yellow
836 diamond 1580
        jz      .attr_color
1581
        mov     dl, 1
9105 hidnplayr 1582
        cmp     al, 34          ; Blue
836 diamond 1583
        jz      .attr_color
1584
        mov     dl, 5
9105 hidnplayr 1585
        cmp     al, 35          ; Purple
836 diamond 1586
        jz      .attr_color
1587
        mov     dl, 3
9105 hidnplayr 1588
        cmp     al, 36          ; Cyan
836 diamond 1589
        jz      .attr_color
1590
        mov     dl, 7
9105 hidnplayr 1591
        cmp     al, 37          ; White
836 diamond 1592
        jz      .attr_color
9105 hidnplayr 1593
        mov     dl, 7
1594
        cmp     al, 39          ; Default - White
1595
        jz      .attr_color
3690 hidnplayr 1596
 
9105 hidnplayr 1597
; Background colors
836 diamond 1598
        xor     edx, edx
9105 hidnplayr 1599
        cmp     al, 40          ; Black
836 diamond 1600
        jz      .attr_bgr_color
1601
        mov     dl, 0x40
9105 hidnplayr 1602
        cmp     al, 41          ; Red
836 diamond 1603
        jz      .attr_bgr_color
1604
        mov     dl, 0x20
9105 hidnplayr 1605
        cmp     al, 42          ; Green
836 diamond 1606
        jz      .attr_bgr_color
1607
        mov     dl, 0x60
9105 hidnplayr 1608
        cmp     al, 43          ; Yellow
836 diamond 1609
        jz      .attr_bgr_color
1610
        mov     dl, 0x10
9105 hidnplayr 1611
        cmp     al, 44          ; Blue
836 diamond 1612
        jz      .attr_bgr_color
1613
        mov     dl, 0x50
9105 hidnplayr 1614
        cmp     al, 45          ; Magenta
836 diamond 1615
        jz      .attr_bgr_color
1616
        mov     dl, 0x30
9105 hidnplayr 1617
        cmp     al, 46          ; Cyan
836 diamond 1618
        jz      .attr_bgr_color
1619
        mov     dl, 0x70
9105 hidnplayr 1620
        cmp     al, 47          ; White
3690 hidnplayr 1621
        jz      .attr_bgr_color
9105 hidnplayr 1622
        mov     dl, 0
1623
        cmp     al, 49          ; Default - Black
1624
        jz      .attr_bgr_color
3690 hidnplayr 1625
 
9105 hidnplayr 1626
; 16-color support, bright colors follow
1627
; Foreground colors
3690 hidnplayr 1628
        mov     dl, 0x08
9105 hidnplayr 1629
        cmp     al, 90          ; Black
3690 hidnplayr 1630
        jz      .attr_color
1631
        mov     dl, 4 + 8
9105 hidnplayr 1632
        cmp     al, 91          ; Red
3690 hidnplayr 1633
        jz      .attr_color
1634
        mov     dl, 2 + 8
9105 hidnplayr 1635
        cmp     al, 92          ; Green
3690 hidnplayr 1636
        jz      .attr_color
1637
        mov     dl, 6 + 8
9105 hidnplayr 1638
        cmp     al, 93          ; Yellow
3690 hidnplayr 1639
        jz      .attr_color
1640
        mov     dl, 1 + 8
9105 hidnplayr 1641
        cmp     al, 94          ; Blue
3690 hidnplayr 1642
        jz      .attr_color
1643
        mov     dl, 5 + 8
9105 hidnplayr 1644
        cmp     al, 95          ; Magenta
3690 hidnplayr 1645
        jz      .attr_color
1646
        mov     dl, 3 + 8
9105 hidnplayr 1647
        cmp     al, 96          ; Cyan
3690 hidnplayr 1648
        jz      .attr_color
1649
        mov     dl, 7 + 8
9105 hidnplayr 1650
        cmp     al, 97          ; White
3690 hidnplayr 1651
        jz      .attr_color
1652
 
9105 hidnplayr 1653
; Background colors
3690 hidnplayr 1654
        mov     dl, 0x80
9105 hidnplayr 1655
        cmp     al, 100         ; Black
3690 hidnplayr 1656
        jz      .attr_bgr_color
1657
        mov     dl, 0x80 + 0x40
9105 hidnplayr 1658
        cmp     al, 101         ; Red
3690 hidnplayr 1659
        jz      .attr_bgr_color
1660
        mov     dl, 0x80 + 0x20
9105 hidnplayr 1661
        cmp     al, 102         ; Green
3690 hidnplayr 1662
        jz      .attr_bgr_color
1663
        mov     dl, 0x80 + 0x60
9105 hidnplayr 1664
        cmp     al, 103         ; Yellow
3690 hidnplayr 1665
        jz      .attr_bgr_color
1666
        mov     dl, 0x80 + 0x10
9105 hidnplayr 1667
        cmp     al, 104         ; Blue
3690 hidnplayr 1668
        jz      .attr_bgr_color
1669
        mov     dl, 0x80 + 0x50
9105 hidnplayr 1670
        cmp     al, 105         ; Magenta
3690 hidnplayr 1671
        jz      .attr_bgr_color
1672
        mov     dl, 0x80 + 0x30
9105 hidnplayr 1673
        cmp     al, 106         ; Cyan
3690 hidnplayr 1674
        jz      .attr_bgr_color
1675
        mov     dl, 0x80 + 0x70
9105 hidnplayr 1676
        cmp     al, 107         ; White
836 diamond 1677
        jnz     .attr_continue
3690 hidnplayr 1678
 
836 diamond 1679
.attr_bgr_color:
1680
        mov     eax, [con_flags]
3690 hidnplayr 1681
        and     al, 0x0F
9105 hidnplayr 1682
        or      al, byte [con_flags_attr]
836 diamond 1683
        or      al, dl
1684
        mov     [con_flags], eax
1685
        jmp     .attr_continue
1686
.attr_color:
1687
        mov     eax, [con_flags]
3690 hidnplayr 1688
        and     al, 0xF0
9105 hidnplayr 1689
        or      al, byte [con_flags_attr]
836 diamond 1690
        or      al, dl
1691
        mov     [con_flags], eax
1692
        jmp     .attr_continue
1693
.attr_normal:
9105 hidnplayr 1694
        mov     byte [con_flags_attr], 0
1695
        mov     byte [con_flags], 0x07
836 diamond 1696
        jmp     .attr_continue
1697
.attr_reversed:
1698
        mov     byte [con_flags], 0x70
1699
        jmp     .attr_continue
1700
.attr_bold:
9105 hidnplayr 1701
        or      byte [con_flags_attr], 0x08
836 diamond 1702
        jmp     .attr_continue
1703
.attr_bgr_bold:
9105 hidnplayr 1704
        or      byte [con_flags_attr], 0x80
836 diamond 1705
.attr_continue:
1706
        inc     ecx
1707
        cmp     ecx, [con_esc_attr_n]
1708
        jb      .set_one_attr
1709
        pop     edx ecx eax
1710
        ret
1711
 
1712
con.newline:
1713
        mov     eax, [con.cur_y]
1714
        inc     eax
1715
        mov     [con.cur_y], eax
1716
        cmp     eax, [con.scr_height]
1717
        jb      @f
1718
        call    con.scr_scroll_up
1719
@@:
1720
        call    con.get_data_ptr
1721
        ret
1722
 
1723
con.scr_scroll_up:
1724
        pushad
1725
        mov     edi, [con.data]
1726
        mov     esi, edi
1727
        add     esi, [con.scr_width]
1728
        add     esi, [con.scr_width]
1729
        dec     [con.cur_y]
1730
        mov     ecx, [con.scr_height]
1731
        dec     ecx
1732
        imul    ecx, [con.scr_width]
1733
        shr     ecx, 1
1734
        rep     movsd
1735
        adc     ecx, ecx
1736
        rep     movsw
1737
        mov     ax, 0x0720
1738
        mov     ecx, [con.scr_width]
1739
        rep     stosw
1740
        popad
1741
        ret
1742
 
1743
con.data2image:
1744
        pushad
1745
        mov     edi, [con.image]
1746
        mov     esi, [con.data]
1747
        mov     eax, [con.wnd_ypos]
1748
        mul     [con.scr_width]
1749
        add     eax, [con.wnd_xpos]
1750
        lea     esi, [esi+eax*2]
1751
        mov     ecx, [con.wnd_height]
1752
.lh:
1753
        push    ecx
1754
        mov     ecx, [con.wnd_width]
1755
.lw:
1756
        push    ecx edi
1757
        xor     eax, eax
1758
        mov     al, [esi+1]
1759
        push    eax
1760
        and     al, 0xF
1761
        mov     ebx, eax                ; цвет текста
1762
        pop     eax
1763
        shr     al, 4
1764
        mov     ebp, eax                ; цвет фона
1765
        sub     ebx, ebp
1766
        lodsb
1767
        inc     esi
1768
if font_width > 8
1769
        lea     edx, [eax+eax+font]
1770
else
1771
        lea     edx, [eax+font]
1772
end if
1773
.sh:
1774
        mov     ecx, [edx]
1775
repeat font_width
1776
        shr     ecx, 1
1777
        sbb     eax, eax
1778
        and     eax, ebx
1779
        add     eax, ebp
1780
        mov     [edi+%-1], al
1781
end repeat
1782
        mov     eax, [con.wnd_width]
1783
;        imul    eax, font_width
1784
;        add     edi, eax
1785
if font_width = 6
1786
        lea     eax, [eax*2+eax]
1787
        lea     edi, [edi+eax*2]
1788
else if font_width = 7
1789
        lea     edi, [edi+eax*8]
1790
        sub     edi, eax
1791
else if font_width = 8
1792
        lea     edi, [edi+eax*8]
1793
else if font_width = 9
1794
        lea     edi, [edi+eax*8]
1795
        add     edi, eax
1796
else if font_width = 10
1797
        lea     eax, [eax*4+eax]
1798
        lea     edi, [edi+eax*2]
1799
else
1800
Unknown font_width value!
1801
end if
1802
if font_width > 8
1803
        add     edx, 256*2
1804
        cmp     edx, font+256*2*font_height
1805
else
1806
        add     edx, 256
1807
        cmp     edx, font+256*font_height
1808
end if
1809
        jb      .sh
1810
        pop     edi ecx
1811
        add     edi, font_width
1812
        sub     ecx, 1
1813
        jnz     .lw
1814
        mov     eax, [con.wnd_width]
1815
        imul    eax, (font_height-1)*font_width
1816
        add     edi, eax
1817
        pop     ecx
1818
        mov     eax, [con.scr_width]
1819
        sub     eax, [con.wnd_width]
1820
        lea     esi, [esi+eax*2]
1821
        dec     ecx
1822
        jnz     .lh
1823
        mov     eax, [con.cur_y]
1824
        sub     eax, [con.wnd_ypos]
1825
        jb      .nocursor
1826
        cmp     eax, [con.wnd_height]
1827
        jae     .nocursor
1828
        inc     eax
1829
        mul     [con.wnd_width]
1830
        imul    eax, font_height*font_width
1831
        mov     edx, [con.cur_x]
1832
        sub     edx, [con.wnd_xpos]
1833
        jb      .nocursor
1834
        cmp     edx, [con.wnd_width]
1835
        jae     .nocursor
1836
        inc     edx
1837
        imul    edx, font_width
1838
        add     eax, edx
1839
        add     eax, [con.image]
1840
        mov     edx, [con.wnd_width]
1841
        imul    edx, font_width
1842
        neg     edx
1843
        mov     ecx, [con.cursor_height]
1844
        jecxz   .nocursor
1845
.cursor_loop:
1846
        push    ecx
1847
        mov     ecx, font_width
1848
        add     eax, edx
1849
        push    eax
1850
@@:
1851
        xor     byte [eax-1], 7
1852
        dec     eax
1853
        loop    @b
1854
        pop     eax
1855
        pop     ecx
1856
        loop    .cursor_loop
1857
.nocursor:
1858
        popad
1859
        ret
1860
 
1861
con_exit:
9096 hidnplayr 1862
 
9105 hidnplayr 1863
        mov     ah, [con.init_cmd]
1864
        test    ah, ah
1865
        je      .ret
5835 pavelyakov 1866
 
836 diamond 1867
        cmp     byte [esp+4], 0
1868
        jz      .noexit
9105 hidnplayr 1869
        mov     [con.thread_op], OP_EXIT
836 diamond 1870
        call    con.wake
9096 hidnplayr 1871
 
836 diamond 1872
        ret     4
1873
.noexit:
1874
        push    esi
1875
        mov     esi, [con.title]
1876
        mov     edx, con.finished_title
1877
        mov     ecx, 255
1878
        call    .strcpy
1879
        mov     esi, con.aFinished
1880
        call    .strcpy
1881
        mov     byte [edx], 0
1882
        pop     esi
1883
        and     [con.cursor_height], 0
1884
        push    con.finished_title
1885
        call    con_set_title
1886
        ret     4
1887
.strcpy:
1888
        jecxz   .ret
1889
@@:
1890
        lodsb
1891
        test    al, al
1892
        jz      .ret
1893
        mov     [edx], al
1894
        inc     edx
1895
        loop    @b
1896
.ret:
1897
        ret
1898
 
1899
con_set_title:
1900
        mov     eax, [esp+4]
1901
        mov     [con.title], eax
9105 hidnplayr 1902
        mov     [con.thread_op], OP_SET_TITLE
836 diamond 1903
        call    con.wake
1904
        ret     4
1905
 
1906
; int __stdcall con_kbhit(void);
1907
con_kbhit:
1133 diamond 1908
        test    byte [con_flags+1], 2
1909
        jnz     @f
836 diamond 1910
        mov     eax, [con.input_start]
1911
        cmp     eax, [con.input_end]
1133 diamond 1912
@@:
836 diamond 1913
        setnz   al
1914
        movzx   eax, al
1915
        ret
1916
 
1917
con.force_entered_char:
1918
        cmp     [con.entered_char], -1
1919
        jnz     .ret
9105 hidnplayr 1920
        mov     [con.thread_op], OP_GETCH
836 diamond 1921
        call    con.wake
1133 diamond 1922
        test    byte [con_flags+1], 2
1923
        jnz     .ret
836 diamond 1924
; wait for response
1925
        push    ebx
1926
        push    5
1927
        pop     eax
1928
        push    2
1929
        pop     ebx
1930
@@:
1931
        int     0x40
1932
        cmp     [con.entered_char], -1
1933
        jz      @b
1934
        pop     ebx
1935
.ret:
1936
        ret
1937
 
1938
; int __stdcall con_getch(void);
1939
con_getch:
9105 hidnplayr 1940
        call    con_init_check
836 diamond 1941
        call    con.force_entered_char
1133 diamond 1942
        test    byte [con_flags+1], 2
1943
        jnz     con_getch_closed
836 diamond 1944
        movzx   eax, byte [con.entered_char]
1945
        sar     [con.entered_char], 8
1946
        mov     byte [con.entered_char+1], 0xFF
1947
        test    al, al
1948
        jz      @f
1949
        mov     byte [con.entered_char], 0xFF
1950
@@:
1951
        ret
1952
 
1133 diamond 1953
con_getch_closed:
1145 diamond 1954
        xor     eax, eax
1133 diamond 1955
        ret
1956
 
836 diamond 1957
; int __stdcall con_getch2(void);
1958
con_getch2:
9105 hidnplayr 1959
        call    con_init_check
836 diamond 1960
        call    con.force_entered_char
1133 diamond 1961
        test    byte [con_flags+1], 2
1962
        jnz     con_getch_closed
836 diamond 1963
        mov     eax, 0xFFFF
1964
        xchg    ax, [con.entered_char]
1965
        ret
1966
 
9105 hidnplayr 1967
; int __stdcall con_get_input(int *bufptr, int buflen);
1968
con_get_input:
1969
        call    con_init_check
1970
; Wait for input available
1971
        call    con.force_entered_char
1972
        test    byte [con_flags+1], 2
1973
        jnz     .none
1974
 
1975
        push    ebx
9125 hidnplayr 1976
        mov     ebx, [esp+8]
9105 hidnplayr 1977
  .check_more:
1978
; Avoid buffer overflow
9125 hidnplayr 1979
        cmp     dword[esp+12], 16
9105 hidnplayr 1980
        jl      .no_more
1981
; Check element available
1982
        cmp     [con.entered_char], 0xFFFF
1983
        je      .no_more
1984
; Get an element from the input queue
1985
        mov     eax, 0xFFFF
1986
        xchg    ax, [con.entered_char]
1987
; Function keys F1-F4
1988
        cmp     ah, 0x3B
1989
        jb      @f
1990
        cmp     ah, 0x3E
1991
        jbe     .f1_4
1992
  @@:
1993
; Function keys F5-F8
1994
        cmp     ah, 0x3F
1995
        jb      @f
1996
        je      .f5
1997
        cmp     ah, 0x42
1998
        jbe     .f6_8
1999
  @@:
2000
; Function keys F9-F12
2001
        cmp     ah, 0x43
2002
        je      .f9
2003
        cmp     ah, 0x44
2004
        je      .f10
2005
        cmp     ah, 0x57
2006
        je      .f11
2007
        cmp     ah, 0x58
2008
        je      .f12
2009
; Cursor keys
2010
        cmp     ah, 0x47
2011
        je      .home
2012
        cmp     ah, 0x48
2013
        je      .up
2014
        cmp     ah, 0x49
2015
        je      .pgup
2016
;        cmp     ah, 0x4a
2017
;        je      .minus
2018
        cmp     ah, 0x4b
2019
        je      .left
2020
        cmp     ah, 0x4c
2021
        je      .begin
2022
        cmp     ah, 0x4d
2023
        je      .right
2024
;        cmp     ah, 0x4e
2025
;        je      .plus
2026
        cmp     ah, 0x4f
2027
        je      .end
2028
        cmp     ah, 0x50
2029
        je      .down
2030
        cmp     ah, 0x51
2031
        je      .pgdown
2032
        cmp     ah, 0x52
2033
        je      .insert
2034
        cmp     ah, 0x53
2035
        je      .delete
2036
; regular ASCII
2037
        mov     byte[ebx], al
2038
        mov     eax, 1
2039
  .got_input:
2040
        and     eax, 0xff
9125 hidnplayr 2041
        sub     [esp+12], eax
9105 hidnplayr 2042
        add     ebx, eax
2043
        jmp     .check_more
2044
  .no_more:
2045
        mov     eax, ebx
9125 hidnplayr 2046
        sub     eax, [esp+8]
9105 hidnplayr 2047
        pop     ebx
2048
        ret     8
2049
 
2050
  .none:
2051
        xor     eax, eax
2052
        ret     8
2053
 
2054
  .f1_4:
2055
; F1 = SSR P, F2 = SS3 Q ..
2056
; SS3 = 0x8f (8bit) or 0x1b + 'O' (7-bit)
2057
        mov     word[ebx], 27 + ('O' shl 8)
2058
        add     ah, 'P' - 59
2059
        mov     byte[ebx+2], ah
2060
        mov     al, 3
2061
        jmp     .got_input
2062
  .f5:
2063
; CSI = 0x9b (8bit) or 0x1b + '[' (7-bit)
2064
        mov     byte[ebx], 27
2065
        mov     dword[ebx+1], '[15~'
2066
        mov     al, 5
2067
        jmp     .got_input
2068
  .f6_8:
2069
        mov     byte[ebx], 27
2070
        xor     al, al
2071
        shl     eax, 8
2072
        add     eax, '[17~' - (0x40 shl 16)
2073
        mov     dword[ebx+1], eax
2074
        mov     al, 5
2075
        jmp     .got_input
2076
  .f9:
2077
        mov     byte[ebx], 27
2078
        mov     dword[ebx+1], '[20~'
2079
        mov     al, 5
2080
        jmp     .got_input
2081
  .f10:
2082
        mov     byte[ebx], 27
2083
        mov     dword[ebx+1], '[21~'
2084
        mov     al, 5
2085
        jmp     .got_input
2086
  .f11:
2087
        mov     byte[ebx], 27
2088
        mov     dword[ebx+1], '[23~'
2089
        mov     al, 5
2090
        jmp     .got_input
2091
  .f12:
2092
        mov     byte[ebx], 27
2093
        mov     dword[ebx+1], '[24~'
2094
        mov     al, 5
2095
        jmp     .got_input
2096
  .up:
2097
        mov     eax, 'A' shl 16
2098
        add     eax, [cursor_esc]
2099
        mov     dword[ebx], eax
2100
        mov     al, 3
2101
        jmp     .got_input
2102
  .down:
2103
        mov     eax, 'B' shl 16
2104
        add     eax, [cursor_esc]
2105
        mov     dword[ebx], eax
2106
        mov     al, 3
2107
        jmp     .got_input
2108
  .right:
2109
        mov     eax, 'C' shl 16
2110
        add     eax, [cursor_esc]
2111
        mov     dword[ebx], eax
2112
        mov     al, 3
2113
        jmp     .got_input
2114
  .left:
2115
        mov     eax, 'D' shl 16
2116
        add     eax, [cursor_esc]
2117
        mov     dword[ebx], eax
2118
        mov     al, 3
2119
        jmp     .got_input
2120
  .home:
2121
        mov     eax, 'H' shl 16
2122
        add     eax, [cursor_esc]
2123
        mov     dword[ebx], eax
2124
        mov     al, 3
2125
        jmp     .got_input
2126
  .end:
2127
        mov     eax, 'F' shl 16
2128
        add     eax, [cursor_esc]
2129
        mov     dword[ebx], eax
2130
        mov     al, 3
2131
        jmp     .got_input
2132
  .insert:
2133
        mov     dword[ebx], 27 + ('[2~' shl 8)
2134
        mov     al, 4
2135
        jmp     .got_input
2136
  .delete:
2137
        mov     dword[ebx], 27 + ('[3~' shl 8)
2138
        mov     al, 4
2139
        jmp     .got_input
2140
  .pgup:
2141
        mov     dword[ebx], 27 + ('[5~' shl 8)
2142
        mov     al, 4
2143
        jmp     .got_input
2144
  .pgdown:
2145
        mov     dword[ebx], 27 + ('[6~' shl 8)
2146
        mov     al, 4
2147
        jmp     .got_input
2148
  .begin:
2149
        mov     dword[ebx], 27 + ('[E' shl 8)
2150
        mov     al, 3
2151
        jmp     .got_input
2152
 
2153
 
2154
 
1133 diamond 2155
; char* __stdcall con_gets(char* str, int n);
836 diamond 2156
con_gets:
852 diamond 2157
        pop     eax
2158
        push    0
2159
        push    eax
1133 diamond 2160
; char* __stdcall con_gets2(con_gets2_callback callback, char* str, int n);
852 diamond 2161
con_gets2:
9105 hidnplayr 2162
        call    con_init_check
1133 diamond 2163
        mov     eax, [esp+8]            ; str
836 diamond 2164
        pushad
1133 diamond 2165
        mov     esi, eax                ; str
852 diamond 2166
        mov     ebx, [esp+20h+12]       ; n
836 diamond 2167
        sub     ebx, 1
2168
        jle     .ret
2169
        mov     byte [esi], 0
2170
        xor     ecx, ecx                ; длина уже введённой строки
2171
        call    con.get_data_ptr
2172
.loop:
852 diamond 2173
        call    con_getch2
836 diamond 2174
        test    al, al
2175
        jz      .extended
2176
        cmp     al, 8
2177
        jz      .backspace
2178
        cmp     al, 27
2179
        jz      .esc
2180
        cmp     al, 13
2181
        jz      .enter
852 diamond 2182
        cmp     al, 9
2183
        jz      .tab
836 diamond 2184
        inc     ecx
2185
        mov     dl, al
2186
        call    con.write_char_ex
2187
        push    [con.cur_x]
2188
        push    [con.cur_y]
2189
        push    edi
2190
        push    esi
2191
@@:
2192
        lodsb
2193
        mov     [esi-1], dl
2194
        mov     dl, al
2195
        test    al, al
2196
        jz      @f
2197
        call    con.write_char_ex
2198
        jmp     @b
2199
@@:
2200
        mov     [esi], dl
2201
        pop     esi
2202
        inc     esi
2203
        pop     edi
2204
        pop     [con.cur_y]
2205
        pop     [con.cur_x]
2206
.update_screen_and_loop:
2207
        call    con.update_screen
2208
        cmp     ecx, ebx
2209
        jb      .loop
852 diamond 2210
.ret_us:
836 diamond 2211
        mov     edx, [con.cur_x]
2212
@@:
2213
        lodsb
2214
        test    al, al
2215
        jz      @f
2216
        inc     edx
2217
        cmp     edx, [con.scr_width]
2218
        jb      @b
2219
        xor     edx, edx
2220
        call    con.newline
2221
        jmp     @b
2222
@@:
2223
        mov     [con.cur_x], edx
2224
        call    con.get_data_ptr
2225
        call    con.update_screen
2226
        jmp     .ret
2227
.esc:
2228
        mov     edx, [con.cur_x]
2229
@@:
2230
        lodsb
2231
        test    al, al
2232
        jz      @f
2233
        inc     edx
2234
        cmp     edx, [con.scr_width]
2235
        jb      @b
2236
        xor     edx, edx
2237
        call    con.newline
2238
        jmp     @b
2239
@@:
2240
        mov     [con.cur_x], edx
2241
        call    con.get_data_ptr
2242
        dec     esi
2243
        xor     ecx, ecx
2244
@@:
2245
        mov     byte [esi], 0
852 diamond 2246
        cmp     esi, [esp+20h+8]
836 diamond 2247
        jbe     .update_screen_and_loop
2248
        mov     al, 8
2249
        call    con.write_special_char
2250
        mov     al, ' '
2251
        call    con.write_char
2252
        mov     al, 8
2253
        call    con.write_special_char
2254
        dec     esi
2255
        jmp     @b
2256
.delete:
2257
        cmp     byte [esi], 0
2258
        jz      .loop
2259
        lodsb
2260
        call    con.write_char_ex
2261
.backspace:
852 diamond 2262
        cmp     esi, [esp+20h+8]
836 diamond 2263
        jbe     .loop
2264
        push    esi
2265
        mov     edx, [con.cur_x]
2266
@@:
2267
        lodsb
2268
        test    al, al
2269
        jz      @f
2270
        inc     edx
2271
        cmp     edx, [con.scr_width]
2272
        jb      @b
2273
        xor     edx, edx
2274
        call    con.newline
2275
        jmp     @b
2276
@@:
2277
        mov     [con.cur_x], edx
2278
        call    con.get_data_ptr
2279
        dec     esi
2280
        mov     al, 8
2281
        call    con.write_special_char
2282
        mov     al, ' '
2283
        call    con.write_char
2284
        mov     al, 8
2285
        call    con.write_special_char
2286
        mov     dl, 0
2287
@@:
2288
        cmp     esi, [esp]
2289
        jbe     @f
2290
        mov     al, 8
2291
        call    con.write_special_char
2292
        dec     esi
2293
        xchg    dl, [esi]
2294
        mov     al, dl
2295
        call    con.write_char
2296
        mov     al, 8
2297
        call    con.write_special_char
2298
        jmp     @b
2299
@@:
2300
        pop     esi
2301
        dec     esi
2302
        mov     [esi], dl
2303
        dec     ecx
2304
        jmp     .update_screen_and_loop
2305
.enter:
2306
        mov     edx, [con.cur_x]
2307
@@:
2308
        lodsb
2309
        test    al, al
2310
        jz      @f
2311
        inc     edx
2312
        cmp     edx, [con.scr_width]
2313
        jb      @b
2314
        xor     edx, edx
2315
        call    con.newline
2316
        jmp     @b
2317
@@:
2318
        mov     [con.cur_x], edx
2319
        call    con.get_data_ptr
2320
        mov     al, 10
2321
        mov     [esi-1], al
2322
        mov     byte [esi], 0
2323
        call    con.write_special_char
2324
        call    con.update_screen
2325
        jmp     .ret
852 diamond 2326
.tab:
2327
        mov     al, 0
2328
        mov     ah, 0xF
836 diamond 2329
.extended:
1145 diamond 2330
        test    ah, ah
2331
        jz      .closed
852 diamond 2332
        xchg    al, ah
836 diamond 2333
        cmp     al, 0x4B
2334
        jz      .left
2335
        cmp     al, 0x4D
2336
        jz      .right
2337
        cmp     al, 0x47
2338
        jz      .home
2339
        cmp     al, 0x4F
2340
        jz      .end
2341
        cmp     al, 0x53
2342
        jz      .delete
852 diamond 2343
; give control to callback function
2344
        cmp     dword [esp+20h+4], 0
2345
        jz      .loop
2346
; remember length of text before and length of text after
2347
; and advance cursor to the end of line
2348
        push    ecx
2349
        push    eax
2350
        lea     edx, [esi+1]
2351
@@:
2352
        lodsb
2353
        test    al, al
2354
        jz      @f
2355
        call    con.write_char_ex
2356
        jmp     @b
2357
@@:
2358
        sub     esi, edx
2359
        pop     eax
2360
        push    esi
2361
        dec     edx
2362
        sub     edx, [esp+28h+8]
2363
        push    edx
2364
        push    esp             ; ppos
2365
        mov     ecx, [esp+30h+4]
2366
        lea     edx, [esp+30h+12]
2367
        push    edx             ; pn
2368
        lea     edx, [esp+34h+8]
2369
        push    edx             ; pstr
2370
        push    eax             ; keycode
2371
        call    ecx
2372
        call    con.get_data_ptr
2373
        dec     eax
2374
        js      .callback_nochange
2375
        jz      .callback_del
2376
        dec     eax
2377
        jz      .callback_output
2378
; callback returned 2 - exit
2379
        add     esp, 12
2380
        jmp     .ret
2381
.callback_nochange:
2382
; callback returned 0 - string was not changed, only restore cursor position
2383
        pop     esi
2384
        pop     ecx
2385
        test    ecx, ecx
2386
        jz      .cncs
2387
@@:
2388
        mov     al, 8
2389
        call    con.write_special_char
2390
        loop    @b
2391
.cncs:
2392
        pop     ecx
2393
        add     esi, [esp+20h+8]
2394
        jmp     .callback_done
2395
.callback_del:
2396
; callback returned 1 - string was changed, delete old string and output new
2397
        mov     ecx, [esp+8]
2398
        test    ecx, ecx
2399
        jz      .cds
2400
@@:
2401
        mov     al, 8
2402
        call    con.write_special_char
2403
        mov     al, ' '
2404
        call    con.write_char_ex
2405
        mov     al, 8
2406
        call    con.write_special_char
2407
        loop    @b
2408
.cds:
2409
.callback_output:
2410
; callback returned 2 - string was changed, output new string
2411
        pop     edx
2412
        pop     esi
2413
        pop     ecx
2414
        mov     esi, [esp+20h+8]
2415
        xor     ecx, ecx
2416
@@:
2417
        lodsb
2418
        test    al, al
2419
        jz      @f
2420
        call    con.write_char_ex
2421
        inc     ecx
2422
        jmp     @b
2423
@@:
2424
        dec     esi
2425
        push    ecx
2426
        sub     ecx, edx
2427
        jz      .cos
2428
@@:
2429
        mov     al, 8
2430
        call    con.write_special_char
2431
        dec     esi
2432
        loop    @b
2433
.cos:
2434
        pop     ecx
2435
.callback_done:
2436
        call    con.update_screen
2437
        mov     ebx, [esp+20h+12]
2438
        dec     ebx
2439
        cmp     ecx, ebx
2440
        jae     .ret_us
836 diamond 2441
        jmp     .loop
2442
.left:
852 diamond 2443
        cmp     esi, [esp+20h+8]
836 diamond 2444
        jbe     .loop
2445
        dec     esi
2446
        mov     al, 8
2447
        call    con.write_special_char
2448
        jmp     .update_screen_and_loop
2449
.right:
2450
        cmp     byte [esi], 0
2451
        jz      .loop
2452
        lodsb
2453
        call    con.write_char_ex
2454
        jmp     .update_screen_and_loop
2455
.home:
852 diamond 2456
        cmp     esi, [esp+20h+8]
836 diamond 2457
        jz      .update_screen_and_loop
2458
        dec     esi
2459
        mov     al, 8
2460
        call    con.write_special_char
2461
        jmp     .home
2462
.end:
2463
        lodsb
2464
        test    al, al
2465
        jz      @f
2466
        call    con.write_char_ex
2467
        jmp     .end
2468
@@:
2469
        dec     esi
2470
        jmp     .update_screen_and_loop
1133 diamond 2471
.closed:
2472
        and     dword [esp+1Ch], 0
836 diamond 2473
.ret:
2474
        popad
852 diamond 2475
        ret     12
836 diamond 2476
 
853 diamond 2477
; void __stdcall con_cls();
2478
con_cls:
9105 hidnplayr 2479
        mov     ah, [con.init_cmd]
2480
        test    ah, ah
2481
        je      cmd_init_no
9096 hidnplayr 2482
 
853 diamond 2483
        push    edi
9105 hidnplayr 2484
        call    con.write_special_char.erase_all
853 diamond 2485
        pop     edi
2486
        call    con.update_screen
9096 hidnplayr 2487
 
9105 hidnplayr 2488
        ret
9096 hidnplayr 2489
 
9105 hidnplayr 2490
cmd_init_no:
9096 hidnplayr 2491
 
9105 hidnplayr 2492
        push    con.title_init_console
2493
        push    -1
2494
        push    -1
2495
        push    -1
2496
        push    -1
9096 hidnplayr 2497
 
9105 hidnplayr 2498
        call    con_init
9096 hidnplayr 2499
 
853 diamond 2500
        ret
2501
 
2502
; void __stdcall con_get_cursor_pos(int* px, int* py);
2503
con_get_cursor_pos:
2504
        push    eax ecx
2505
        mov     eax, [esp+12]
2506
        mov     ecx, [con.cur_x]
2507
        mov     [eax], ecx
2508
        mov     eax, [esp+16]
2509
        mov     ecx, [con.cur_y]
2510
        mov     [eax], ecx
2511
        pop     ecx eax
2512
        ret     8
2513
 
2514
; void __stdcall con_set_cursor_pos(int px, int py);
2515
con_set_cursor_pos:
2516
        push    eax
2517
        mov     eax, [esp+8]
2518
        cmp     eax, [con.scr_width]
2519
        jae     @f
2520
        mov     [con.cur_x], eax
2521
@@:
2522
        mov     eax, [esp+12]
2523
        cmp     eax, [con.scr_height]
2524
        jae     @f
2525
        mov     [con.cur_y], eax
2526
@@:
2527
        pop     eax
2528
        call    con.update_screen
2529
        ret     8
2530
 
836 diamond 2531
con.update_screen:
2532
        push    eax
2533
        mov     eax, [con.cur_y]
2534
        sub     eax, [con.wnd_ypos]
2535
        jb      .up
2536
        cmp     eax, [con.wnd_height]
2537
        jb      .done
2538
        mov     eax, [con.cur_y]
2539
        sub     eax, [con.wnd_height]
2540
        inc     eax
2541
        jmp     .set
2542
.up:
2543
        mov     eax, [con.cur_y]
2544
.set:
2545
        mov     [con.wnd_ypos], eax
2546
.done:
2547
        pop     eax
9105 hidnplayr 2548
        mov     [con.thread_op], OP_REDRAW
836 diamond 2549
 
2550
con.wake:
2551
        pushad
2552
        mov     al, [con.thread_op]
2553
        cmp     al, byte [con.ipc_buf+0x10]
2554
        jz      .ret
2555
@@:
2556
        push    60
2557
        pop     eax
2558
        push    2
2559
        pop     ebx
2560
        mov     ecx, [con.console_tid]
1133 diamond 2561
        jecxz   .ret
836 diamond 2562
        mov     edx, con.thread_op
2563
        push    1
2564
        pop     esi
2565
        int     0x40
2566
        test    eax, eax
2567
        jz      @f
2568
        push    5
2569
        pop     eax
2570
        mov     bl, 1
2571
        int     0x40
2572
        jmp     @b
2573
@@:
2574
.ret:
2575
        popad
2576
        ret
2577
 
2578
; Поток окна консоли. Обрабатывает ввод и вывод.
2579
con.thread:
2580
; Поток реагирует на IPC, которое используется только для того, чтобы его можно было "разбудить"
2581
        push    40
2582
        pop     eax
2583
        push    0x67
2584
        pop     ebx
2585
        int     0x40
2586
        mov     al, 60
2587
        mov     bl, 1
2588
        mov     ecx, con.ipc_buf
2589
        push    0x11
2590
        pop     edx
2591
        int     0x40
2592
        mov     al, 66
2593
        mov     bl, 1
2594
        mov     ecx, ebx
2595
        int     0x40
2596
con.redraw:
2597
        call    con.draw_window
2598
con.msg_loop:
2599
        cmp     dword [con.bUpPressed], 0
2600
        jnz     .wait_timeout
2601
        push    10
2602
        pop     eax
2603
        jmp     @f
2604
.wait_timeout:
2605
        push    23
2606
        pop     eax
2607
        push    5
2608
        pop     ebx
2609
@@:
2610
        int     0x40
2611
        dec     eax
2612
        jz      con.redraw
2613
        dec     eax
2614
        jz      con.key
2615
        dec     eax
2616
        jz      con.button
2617
        cmp     al, 4
2618
        jz      con.ipc
2619
        jmp     con.mouse
2620
con.button:
2621
; we have only one button, close
8328 superturbo 2622
        mov     eax, 18
2623
        mov     ebx, 18
2624
        mov     ecx,[process_info_buffer+30]
2625
        dec     ecx
2626
        int     0x40 ; kill parent process
2627
 
836 diamond 2628
con.thread_exit:
1133 diamond 2629
        or      byte [con_flags+1], 2
2630
        and     [con.console_tid], 0
1134 diamond 2631
        and     [con.entered_char], 0
836 diamond 2632
        or      eax, -1
2633
        int     0x40
2634
con.key:
2635
        mov     al, 2
2636
        int     0x40
5618 hidnplayr 2637
        and     eax, 0xffff ; supress scancodes
836 diamond 2638
; ah = scancode
2639
        cmp     ah, 0xE0
2640
        jnz     @f
2641
        mov     [con.bWasE0], 1
2642
        jmp     con.msg_loop
2643
@@:
2644
        shr     eax, 8
2645
        xchg    ah, [con.bWasE0]
2646
        test    al, al
2647
        jle     con.msg_loop
2648
        cmp     al, 0x1D
2649
        jz      con.msg_loop
2650
        cmp     al, 0x2A
2651
        jz      con.msg_loop
2652
        cmp     al, 0x36
2653
        jz      con.msg_loop
2654
        cmp     al, 0x38
2655
        jz      con.msg_loop
2656
        cmp     al, 0x3A
2657
        jz      con.msg_loop
2658
        cmp     al, 0x45
2659
        jz      con.msg_loop
2660
        cmp     al, 0x46
2661
        jz      con.msg_loop
2662
        mov     edx, eax
4402 hidnplayr 2663
        cmp     dl, 0x4e
2664
        je      .numpad
2665
        cmp     dl, 0x4a
2666
        je      .numpad
836 diamond 2667
        push    66
2668
        pop     eax
2669
        push    3
2670
        pop     ebx
2671
        int     0x40    ; eax = control key state
2672
        test    dh, dh
2673
        jnz     .extended
4306 hidnplayr 2674
        test    al, 0x80        ; numlock
2675
        jnz     .numlock
836 diamond 2676
        bt      [scan_has_ascii], edx
2677
        jnc     .extended
4306 hidnplayr 2678
        test    al, 0x30        ; alt
836 diamond 2679
        jnz     .extended
4306 hidnplayr 2680
        test    al, 0x80        ; numlock
2681
        jz      .no_numlock
2682
  .numlock:
2683
        cmp     dl, 71
2684
        jb      .no_numlock
2685
        cmp     dl, 83
2686
        ja      .no_numlock
4402 hidnplayr 2687
  .numpad:
4306 hidnplayr 2688
        mov     dh, [con.extended_numlock+edx-71]
2689
        xchg    dl, dh
2690
        jmp     .gotcode
2691
  .no_numlock:
836 diamond 2692
; key has ASCII code
2693
        push    eax edx
2694
        push    2
2695
        pop     ecx
2696
        test    al, 3
2697
        jnz     @f
2698
        dec     ecx
2699
@@:
2700
        push    26
2701
        pop     eax
2702
        mov     bl, 2
2703
        mov     edx, con.kbd_layout
2704
        int     0x40
2705
        pop     edx eax
2706
        mov     dh, [con.kbd_layout+edx]
2707
        test    al, 0xC
2708
        jz      @f
2709
        sub     dh, 0x60
2710
        jmp     @f
2711
.extended:
2712
        mov     dh, 0   ; no ASCII code
2713
@@:
2714
; dh contains ASCII-code; now convert scancode to extended key code
2715
        mov     ecx, con.extended_alt
2716
        test    al, 0x30
2717
        jnz     .xlat
4384 hidnplayr 2718
 
836 diamond 2719
        mov     ecx, con.extended_shift
2720
        test    al, 3
2721
        jnz     .xlat
4384 hidnplayr 2722
 
836 diamond 2723
        mov     ecx, con.extended_ctrl
2724
        test    al, 0xC
2725
        jnz     .xlat
4384 hidnplayr 2726
 
2727
        cmp     dl, 28
2728
        jne     @f
2729
        shl     dx, 8
2730
        mov     dl, 13
2731
        jmp     .gotcode
2732
@@:
2733
        cmp     dl, 53
2734
        jne     @f
2735
        shl     dx, 8
2736
        mov     dl, '/'
2737
        jmp     .gotcode
2738
@@:
2739
        cmp     dl, 55
2740
        jne     @f
2741
        shl     dx, 8
2742
        mov     dl, '*'
2743
        jmp     .gotcode
2744
@@:
836 diamond 2745
        xchg    dl, dh
2746
        cmp     dh, 0x57
2747
        jz      @f
2748
        cmp     dh, 0x58
2749
        jnz     .gotcode
2750
@@:
2751
        add     dh, 0x85-0x57
2752
        jmp     .gotcode
2753
.xlat:
2754
        movzx   eax, dl
2755
        mov     dl, dh
2756
        mov     dh, [eax+ecx]
2757
.gotcode:
2758
        test    dh, dh
2759
        jz      con.msg_loop
2760
        cmp     dh, 0x94
2761
        jnz     @f
2762
        mov     dl, 0
2763
@@:
2764
; dx contains full keycode
2765
        cmp     [con.bGetchRequested], 0
2766
        jz      @f
2767
        mov     [con.entered_char], dx
2768
        jmp     con.msg_loop
2769
@@:
2770
        mov     eax, [con.input_end]
2771
        mov     ecx, eax
2772
        add     eax, 2
2773
        cmp     eax, con.input_buffer_end
2774
        jnz     @f
2775
        mov     eax, con.input_buffer
2776
@@:
2777
        cmp     eax, [con.input_start]
2778
        jnz     @f
2779
; buffer overflow, make beep and continue
2780
        push    55
2781
        pop     eax
2782
        mov     ebx, eax
2783
        mov     esi, con.beep
2784
        int     0x40
2785
        jmp     con.msg_loop
2786
@@:
2787
        mov     [ecx], dx
2788
        mov     [con.input_end], eax
2789
        jmp     con.msg_loop
2790
con.ipc:
2791
        movzx   eax, byte [con.ipc_buf+0x10]
2792
        mov     byte [con.ipc_buf+4], 8
2793
        mov     byte [con.ipc_buf+0x10], 0
2794
        dec     eax
2795
        jz      con.thread_exit
2796
        dec     eax
2797
        jz      con.set_title
2798
        dec     eax
2799
        jz      con.redraw_image
2800
        dec     eax
2801
        jz      con.getch
9105 hidnplayr 2802
        dec     eax
2803
        jz      con.resize
836 diamond 2804
        jmp     con.msg_loop
9105 hidnplayr 2805
con.resize:
2806
        push    48
2807
        pop     eax
2808
        push    4
2809
        pop     ebx
2810
        int     0x40
2811
 
2812
        mov     edx, [con.def_wnd_x-2]
2813
        mov     edx, [con.wnd_width]
2814
        imul    edx, font_width
2815
        add     edx, 5+5-1
2816
 
2817
        mov     esi, [con.def_wnd_y-2]
2818
        mov     esi, [con.wnd_height]
2819
        imul    esi, font_height
2820
        lea     esi, [eax + esi + 5-1]
2821
; place for scrollbar
2822
        mov     eax, [con.wnd_height]
2823
        cmp     eax, [con.scr_height]
2824
        jae     @f
2825
        add     edx, con.vscroll_width
2826
@@:
2827
        push    67
2828
        pop     eax
2829
        mov     ebx, -1
2830
        mov     ecx, ebx
2831
        int     0x40
2832
        call    con.draw_window
2833
        jmp     con.msg_loop
836 diamond 2834
con.set_title:
2835
        push    71
2836
        pop     eax
2837
        push    1
2838
        pop     ebx
2839
        mov     ecx, [con.title]
2840
        int     0x40
2841
        jmp     con.msg_loop
2842
con.redraw_image:
2843
        call    con.data2image
2844
        call    con.draw_image
2845
        jmp     con.msg_loop
2846
con.getch:
2847
        mov     eax, [con.input_start]
2848
        cmp     eax, [con.input_end]
2849
        jz      .noinput
2850
        mov     ecx, [eax]
2851
        mov     [con.entered_char], cx
2852
        inc     eax
2853
        inc     eax
2854
        cmp     eax, con.input_buffer_end
2855
        jnz     @f
2856
        mov     eax, con.input_buffer
2857
@@:
2858
        mov     [con.input_start], eax
2859
        jmp     con.msg_loop
2860
.noinput:
2861
        mov     [con.bGetchRequested], 1
2862
        jmp     con.msg_loop
2863
con.mouse:
5618 hidnplayr 2864
        push    37
2865
        pop     eax
2866
        push    7
2867
        pop     ebx
2868
        int     0x40
2869
        test    eax, eax
2870
        jz      .no_scrollmouse
2871
        cwde
2872
        add     eax, [con.wnd_ypos]
2873
        jg      @f
836 diamond 2874
        xor     eax, eax
5618 hidnplayr 2875
@@:
2876
        mov     ebx, [con.scr_height]
2877
        sub     ebx, [con.wnd_height]
2878
        cmp     eax, ebx
2879
        jb      @f
2880
        mov     eax, ebx
2881
@@:
2882
        mov     [con.wnd_ypos], eax
2883
        jmp     con.redraw_image
2884
.no_scrollmouse:
2885
        xor     eax, eax
836 diamond 2886
        xchg    eax, dword [con.bUpPressed]
2887
        mov     dword [con.bUpPressed_saved], eax
2888
        push    37
2889
        pop     eax
2890
        push    2
2891
        pop     ebx
2892
        int     0x40
2893
        test    al, 1
2894
        jnz     @f
2895
        cmp     [con.vscroll_pt], -1
2896
        jz      .redraw_if_needed
2897
        or      [con.vscroll_pt], -1
2898
.redraw_if_needed:
2899
        cmp     dword [con.bUpPressed_saved], 0
2900
        jnz     con.redraw_image
2901
        jmp     con.msg_loop
2902
@@:
2903
        mov     al, 37
2904
        dec     ebx
2905
        int     0x40
2906
        movsx   ebx, ax
2907
        sar     eax, 16
2908
        cmp     [con.vscroll_pt], -1
2909
        jnz     .vscrolling
2910
        test    ebx, ebx
2911
        js      .redraw_if_needed
2912
        sub     ax, [con.data_width]
2913
        jb      .redraw_if_needed
2914
        cmp     eax, con.vscroll_width
2915
        jae     .redraw_if_needed
2916
        cmp     ebx, con.vscroll_btn_height
2917
        jb      .up
2918
        sub     bx, [con.data_height]
2919
        jae     .redraw_if_needed
2920
        cmp     bx, -con.vscroll_btn_height
2921
        jge     .down
2922
        add     bx, [con.data_height]
2923
        sub     bx, word [con.vscrollbar_pos]
2924
        jl      .vscroll_up
2925
        cmp     bx, word [con.vscrollbar_size]
2926
        jl      .vscroll
2927
.vscroll_down:
2928
        cmp     [con.bScrollingDown_saved], 0
2929
        jz      .vscroll_down_first
2930
        cmp     [con.bScrollingDown_saved], 1
2931
        jz      .vscroll_down_wasfirst
2932
        mov     [con.bScrollingDown], 2
2933
.vscroll_down_do:
2934
        mov     eax, [con.wnd_ypos]
2935
        add     eax, [con.wnd_height]
2936
        dec     eax
2937
        mov     ebx, [con.scr_height]
2938
        sub     ebx, [con.wnd_height]
2939
        cmp     eax, ebx
2940
        jb      @f
2941
        mov     eax, ebx
2942
@@:
2943
        mov     [con.wnd_ypos], eax
2944
        jmp     con.redraw_image
2945
.vscroll_down_first:
2946
        push    26
2947
        pop     eax
2948
        push    9
2949
        pop     ebx
2950
        int     0x40
2951
        mov     [con.scroll_down_first_time], eax
2952
        mov     [con.bScrollingDown], 1
2953
        jmp     .vscroll_down_do
2954
.vscroll_down_wasfirst:
2955
        push    26
2956
        pop     eax
2957
        push    9
2958
        pop     ebx
2959
        int     0x40
2960
        sub     eax, [con.scroll_down_first_time]
2961
        cmp     eax, 25
2962
        jb      @f
2963
        mov     [con.bScrollingDown], 2
2964
        jmp     .vscroll_down_do
2965
@@:
2966
        mov     [con.bScrollingDown], 1
2967
        jmp     con.msg_loop
2968
.vscroll_up:
2969
        cmp     [con.bScrollingUp_saved], 0
2970
        jz      .vscroll_up_first
2971
        cmp     [con.bScrollingUp_saved], 1
2972
        jz      .vscroll_up_wasfirst
2973
        mov     [con.bScrollingUp], 2
2974
.vscroll_up_do:
2975
        mov     eax, [con.wnd_ypos]
2976
        inc     eax
2977
        sub     eax, [con.wnd_height]
2978
        jns     @f
2979
        xor     eax, eax
2980
@@:
2981
        mov     [con.wnd_ypos], eax
2982
        jmp     con.redraw_image
2983
.vscroll_up_first:
2984
        push    26
2985
        pop     eax
2986
        push    9
2987
        pop     ebx
2988
        int     0x40
2989
        mov     [con.scroll_up_first_time], eax
2990
        mov     [con.bScrollingUp], 1
2991
        jmp     .vscroll_up_do
2992
.vscroll_up_wasfirst:
2993
        push    26
2994
        pop     eax
2995
        push    9
2996
        pop     ebx
2997
        int     0x40
2998
        sub     eax, [con.scroll_up_first_time]
2999
        cmp     eax, 25
3000
        jb      @f
3001
        mov     [con.bScrollingUp], 2
3002
        jmp     .vscroll_up_do
3003
@@:
3004
        mov     [con.bScrollingUp], 1
3005
        jmp     con.msg_loop
3006
.up:
3007
        cmp     [con.bUpPressed_saved], 0
3008
        jz      .up_first
3009
        cmp     [con.bUpPressed_saved], 1
3010
        jz      .up_wasfirst
3011
        mov     [con.bUpPressed], 2
3012
.up_do:
3013
        mov     eax, [con.wnd_ypos]
3014
        dec     eax
3015
        js      @f
3016
        mov     [con.wnd_ypos], eax
3017
@@:
3018
        jmp     con.redraw_image
3019
.up_first:
3020
        push    26
3021
        pop     eax
3022
        push    9
3023
        pop     ebx
3024
        int     0x40
3025
        mov     [con.up_first_time], eax
3026
        mov     [con.bUpPressed], 1
3027
        jmp     .up_do
3028
.up_wasfirst:
3029
        push    26
3030
        pop     eax
3031
        push    9
3032
        pop     ebx
3033
        int     0x40
3034
        sub     eax, [con.up_first_time]
3035
        cmp     eax, 25
3036
        jb      @f
3037
        mov     [con.bUpPressed], 2
3038
        jmp     .up_do
3039
@@:
3040
        mov     [con.bUpPressed], 1
3041
        jmp     con.msg_loop
3042
.down:
3043
        cmp     [con.bDownPressed_saved], 0
3044
        jz      .down_first
3045
        cmp     [con.bDownPressed_saved], 1
3046
        jz      .down_wasfirst
3047
        mov     [con.bDownPressed], 2
3048
.down_do:
3049
        mov     eax, [con.scr_height]
3050
        sub     eax, [con.wnd_height]
3051
        jbe     con.redraw_image
3052
        cmp     [con.wnd_ypos], eax
3053
        jae     con.redraw_image
3054
        inc     [con.wnd_ypos]
3055
        jmp     con.redraw_image
3056
.down_first:
3057
        push    26
3058
        pop     eax
3059
        push    9
3060
        pop     ebx
3061
        int     0x40
3062
        mov     [con.down_first_time], eax
3063
        mov     [con.bDownPressed], 1
3064
        jmp     .down_do
3065
.down_wasfirst:
3066
        push    26
3067
        pop     eax
3068
        push    9
3069
        pop     ebx
3070
        int     0x40
3071
        sub     eax, [con.down_first_time]
3072
        cmp     eax, 25
3073
        jb      @f
3074
        mov     [con.bDownPressed], 2
3075
        jmp     .down_do
3076
@@:
3077
        mov     [con.bDownPressed], 1
3078
        jmp     con.msg_loop
3079
.vscroll:
3080
        mov     [con.vscroll_pt], ebx
3081
        call    con.draw_image
3082
        jmp     con.msg_loop
3083
.vscrolling:
3084
        sub     ebx, [con.vscroll_pt]
3085
        sub     ebx, con.vscroll_btn_height
3086
        jge     @f
3087
        xor     ebx, ebx
3088
@@:
3089
        movzx   eax, [con.data_height]
3090
        sub     eax, 2*con.vscroll_btn_height
3091
        sub     eax, [con.vscrollbar_size]
3092
        cmp     ebx, eax
3093
        jb      @f
3094
        lea     ebx, [eax-1]
3095
@@:
3096
        xchg    eax, ebx
3097
        mov     edx, [con.scr_height]
3098
        sub     edx, [con.wnd_height]
3099
        inc     edx
3100
        mul     edx
3101
        div     ebx
3102
        cmp     [con.wnd_ypos], eax
3103
        jz      con.msg_loop
3104
        mov     [con.wnd_ypos], eax
3105
        jmp     con.redraw_image
3106
 
3107
con.draw_window:
3108
        push    12
3109
        pop     eax
3110
        xor     ebx, ebx
3111
        inc     ebx
3112
        int     0x40
9105 hidnplayr 3113
 
836 diamond 3114
        mov     al, 48
3115
        mov     bl, 4
3116
        int     0x40
3117
        mov     ebx, [con.def_wnd_x-2]
3118
        mov     bx, word [con.wnd_width]
3119
        imul    bx, font_width
3120
        add     bx, 5+5-1
3121
        mov     ecx, [con.def_wnd_y-2]
3122
        mov     cx, word [con.wnd_height]
3123
        imul    cx, font_height
3124
        lea     ecx, [ecx+eax+5-1]
2530 leency 3125
        mov     edx, 0x74000000
836 diamond 3126
        mov     edi, [con.title]
3127
; place for scrollbar
3128
        mov     eax, [con.wnd_height]
3129
        cmp     eax, [con.scr_height]
3130
        jae     @f
3131
        add     ebx, con.vscroll_width
3132
@@:
3133
        xor     eax, eax
3134
        int     0x40
9105 hidnplayr 3135
 
3136
        mov     eax, 9
3137
        mov     ebx, process_info_buffer
3138
        mov     ecx, -1
3034 leency 3139
        int     0x40
9105 hidnplayr 3140
        test    [process_info_buffer.wnd_state], 110b   ; window is rolled up or minimized to panel
3034 leency 3141
        jnz     .exit
9105 hidnplayr 3142
 
836 diamond 3143
        call    con.draw_image
3034 leency 3144
 
3145
.exit:
836 diamond 3146
        push    12
3147
        pop     eax
3148
        push    2
3149
        pop     ebx
3150
        int     0x40
3686 hidnplayr 3151
 
836 diamond 3152
        ret
3153
 
3154
con.draw_image:
3155
        xor     edx, edx
3156
        mov     ecx, [con.wnd_width]
3157
        imul    ecx, font_width
3158
        mov     [con.data_width], cx
3159
        shl     ecx, 16
3160
        mov     cx, word [con.wnd_height]
3161
        imul    cx, font_height
3162
        mov     [con.data_height], cx
3163
        mov     ebx, [con.image]
3164
        push    65
3165
        pop     eax
3166
        xor     ebp, ebp
3167
        mov     edi, con.colors
3168
        push    8
3169
        pop     esi
3170
        int     0x40
3171
        mov     al, 7
3172
        mov     edx, [con.wnd_height]
3173
        cmp     edx, [con.scr_height]
3174
        jae     .skip_vscroll
3175
        push    ecx
3176
        mov     edx, ecx
3177
        xor     dx, dx
3178
        mov     ebx, con.vscroll_btn3
3179
        cmp     [con.bUpPressed], 0
3180
        jnz     @f
3181
        mov     ebx, con.vscroll_btn1
3182
@@:
3183
        mov     ecx, con.vscroll_width*65536 + con.vscroll_btn_height
3184
        int     0x40
3185
        pop     edx
3186
        sub     dx, con.vscroll_btn_height
3187
        mov     ebx, con.vscroll_btn4
3188
        cmp     [con.bDownPressed], 0
3189
        jnz     @f
3190
        mov     ebx, con.vscroll_btn2
3191
@@:
3192
        int     0x40
3193
        push    edx
3194
; Вычисляем высоту бегунка
3195
        mov     ax, dx
3196
        sub     eax, con.vscroll_btn_height
3197
        mov     ecx, eax
3198
        mul     [con.wnd_height]
3199
        div     [con.scr_height]
3200
        cmp     eax, 5
3201
        jae     @f
3202
        mov     al, 5
3203
@@:
3204
; eax = высота бегунка. Вычисляем положение бегунка
3205
        mov     [con.vscrollbar_size], eax
3206
        xchg    eax, ecx
3207
        sub     eax, ecx
3208
        mul     [con.wnd_ypos]
3209
        mov     ebx, [con.scr_height]
3210
        sub     ebx, [con.wnd_height]
3211
        div     ebx
3212
        pop     edx
3213
        push    edx
3214
; ecx = высота бегунка, eax = положение
3215
        add     eax, con.vscroll_btn_height
3216
        mov     [con.vscrollbar_pos], eax
3217
        mov     ebx, con.vscroll_bgr2
3218
        cmp     [con.bScrollingUp], 0
3219
        jnz     @f
3220
        mov     ebx, con.vscroll_bgr1
3221
@@:
3222
        mov     ecx, con.vscroll_width*65536 + con.vscroll_bgr_height
3223
        push    eax
3224
        push    7
3225
        pop     eax
3226
        mov     dx, con.vscroll_btn_height
3227
        call    .vpattern
3228
        mov     dx, word [con.vscrollbar_pos]
3229
        add     dx, word [con.vscrollbar_size]
3230
        mov     cx, con.vscroll_bgr_height
3231
        mov     ebx, con.vscroll_bgr2
3232
        cmp     [con.bScrollingDown], 0
3233
        jnz     @f
3234
        mov     ebx, con.vscroll_bgr1
3235
@@:
3236
        call    .vpattern
3237
        mov     ecx, [con.vscrollbar_pos]
3238
        mov     dx, cx
3239
        add     ecx, [con.vscrollbar_size]
3240
        sub     ecx, con.vscroll_bar_height3
3241
        push    ecx
3242
        mov     ebx, con.vscroll_bar1
3243
        mov     ecx, con.vscroll_width*65536 + con.vscroll_bar_height1
3244
        int     0x40
3245
        add     dx, cx
3246
        mov     cx, con.vscroll_bar_height2
3247
        mov     ebx, con.vscroll_bar2
3248
        call    .vpattern
3249
        mov     ebx, con.vscroll_bar3
3250
        mov     cx, con.vscroll_bar_height3
3251
        int     0x40
3252
.skip_vscroll:
3253
        ret
3254
 
3255
.vpattern:
3256
        push    edx
3257
        add     dx, cx
3258
        cmp     dx, [esp+8]
3259
        pop     edx
3260
        jbe     @f
3261
        mov     cx, [esp+4]
3262
        sub     cx, dx
3263
        jz      .ret
3264
@@:
3265
        int     0x40
3266
        add     dx, cx
3267
        cmp     dx, [esp+4]
3268
        jb      .vpattern
3269
.ret:
3270
        ret     4
3271
 
3272
align 4
3273
con.colors      dd      0x000000, 0x000080, 0x008000, 0x008080
3274
                dd      0x800000, 0x800080, 0x808000, 0xC0C0C0
3275
                dd      0x808080, 0x0000FF, 0x00FF00, 0x00FFFF
3276
                dd      0xFF0000, 0xFF00FF, 0xFFFF00, 0xFFFFFF
3277
 
3278
scan_has_ascii:
3279
        dd      11011111111111111111111111111110b
3280
        dd      00000010001111111111101111111111b
3281
        dd      00000000000000000000000000000000b
3282
        dd      0
3283
 
3284
con.extended_alt:
3285
        db      00h,01h,78h,79h,7Ah,7Bh,7Ch,7Dh,7Eh,7Fh,80h,81h,82h,83h,0Eh,0A5h
3286
        db      10h,11h,12h,13h,14h,15h,16h,17h,18h,19h,1Ah,1Bh,1Ch,00h,1Eh,1Fh
3287
        db      20h,21h,22h,23h,24h,25h,26h,27h,28h,29h,00h,2Bh,2Ch,2Dh,2Eh,2Fh
3288
        db      30h,31h,32h,33h,34h,35h,00h,37h,00h,39h,00h,68h,69h,6Ah,6Bh,6Ch
3289
        db      6Dh,6Eh,6Fh,70h,71h,00h,00h,97h,98h,99h,4Ah,9Bh,9Ch,9Dh,4Eh,9Fh
3290
        db      0A0h,0A1h,0A2h,0A3h,00h,00h,00h,8Bh,8Ch,00h,00h,00h,00h,00h,00h,00h
3291
        times 20h db 0
3292
con.extended_ctrl:
3293
        times 0Fh db %-1
3294
        db      0x94
3295
        times 2Bh db %-1
3296
        db      5Eh,5Fh,60h,61h,62h,63h,64h,65h,66h,67h,00h,00h
3297
        db      77h,8Dh,84h,8Eh,73h,8Fh,74h,90h,75h,91h,76h,92h,93h,00h,00h,00h,89h,8Ah
3298
        times 0x80-0x59 db 0
3299
con.extended_shift:
3300
        times 3Bh db %-1
3301
        db      54h,55h,56h,57h,58h,59h,5Ah,5Bh,5Ch,5Dh,00h,00h
3302
        db      47h,48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh,50h,51h,52h,53h,00h,00h,00h,87h,88h
3303
        times 0x80-0x59 db 0
4306 hidnplayr 3304
con.extended_numlock:
3305
        db      '7', '8', '9', '-'
3306
        db      '4', '5', '6', '+'
3307
        db      '1', '2', '3'
3308
        db      '0', '.'
836 diamond 3309
 
9105 hidnplayr 3310
 
3311
cursor_esc      dd 27 + ('[' shl 8)
3312
 
836 diamond 3313
; В текущей реализации значения по умолчанию таковы.
3314
; В будущем они, возможно, будут считываться как параметры из ini-файла console.ini.
3315
con.def_wnd_width   dd    80
3316
con.def_wnd_height  dd    25
3317
con.def_scr_width   dd    80
3318
con.def_scr_height  dd    300
3319
con.def_wnd_x       dd    200
3320
con.def_wnd_y       dd    50
3321
 
5835 pavelyakov 3322
con.init_cmd db 0
3323
con.title_init_console db "Console",0
836 diamond 3324
con.vscroll_pt      dd    -1
3325
 
3326
align 16
3327
EXPORTS:
3328
        dd      szStart,                START
9105 hidnplayr 3329
        dd      szVersion,              0x00020009
836 diamond 3330
        dd      szcon_init,             con_init
3331
        dd      szcon_write_asciiz,     con_write_asciiz
3686 hidnplayr 3332
        dd      szcon_write_string,     con_write_length
836 diamond 3333
        dd      szcon_printf,           con_printf
3334
        dd      szcon_exit,             con_exit
3335
        dd      szcon_get_flags,        con_get_flags
3336
        dd      szcon_set_flags,        con_set_flags
3337
        dd      szcon_kbhit,            con_kbhit
3338
        dd      szcon_getch,            con_getch
3339
        dd      szcon_getch2,           con_getch2
3340
        dd      szcon_gets,             con_gets
852 diamond 3341
        dd      szcon_gets2,            con_gets2
836 diamond 3342
        dd      szcon_get_font_height,  con_get_font_height
3343
        dd      szcon_get_cursor_height,con_get_cursor_height
3344
        dd      szcon_set_cursor_height,con_set_cursor_height
853 diamond 3345
        dd      szcon_cls,              con_cls
3346
        dd      szcon_get_cursor_pos,   con_get_cursor_pos
3347
        dd      szcon_set_cursor_pos,   con_set_cursor_pos
6603 0CodErr 3348
        dd      szcon_set_title,        con_set_title
9105 hidnplayr 3349
        dd      szcon_get_input,        con_get_input
836 diamond 3350
        dd      0
3351
 
9105 hidnplayr 3352
con_flags       dd      0x07    ; black on white
3353
con_flags_attr  dd      0       ; Modifiers (for example, high intensity colors)
836 diamond 3354
con.cursor_height dd    (15*font_height+50)/100
3355
con.input_start dd      con.input_buffer
3356
con.input_end   dd      con.input_buffer
3357
 
3358
con_esc_attr_n  dd      0
3359
con_esc_attrs   dd      0,0,0,0
3360
con_esc         db      0
3361
con_sci         db      0
9105 hidnplayr 3362
con_osc_str     rb      256
3363
con_osc_strlen  dd      0
836 diamond 3364
 
3365
con.entered_char dw     -1
3366
con.bGetchRequested db  0
3367
con.bWasE0       db     0
3368
 
3369
szStart                 db 'START',0
3370
 
3371
szcon_init              db 'con_init',0
3372
szcon_write_asciiz      db 'con_write_asciiz',0
3686 hidnplayr 3373
szcon_write_string      db 'con_write_string',0
836 diamond 3374
szcon_printf            db 'con_printf',0
3375
szcon_exit              db 'con_exit',0
3376
szVersion               db 'version',0
3377
szcon_get_flags         db 'con_get_flags',0
3378
szcon_set_flags         db 'con_set_flags',0
3379
szcon_kbhit             db 'con_kbhit',0
3380
szcon_getch             db 'con_getch',0
3381
szcon_getch2            db 'con_getch2',0
3382
szcon_gets              db 'con_gets',0
852 diamond 3383
szcon_gets2             db 'con_gets2',0
836 diamond 3384
szcon_get_font_height   db 'con_get_font_height',0
3385
szcon_get_cursor_height db 'con_get_cursor_height',0
3386
szcon_set_cursor_height db 'con_set_cursor_height',0
853 diamond 3387
szcon_cls               db 'con_cls',0
3388
szcon_get_cursor_pos    db 'con_get_cursor_pos',0
3389
szcon_set_cursor_pos    db 'con_set_cursor_pos',0
6603 0CodErr 3390
szcon_set_title         db 'con_set_title',0
9105 hidnplayr 3391
szcon_get_input         db 'con_get_input',0
836 diamond 3392
 
3393
con.thread_err      db 'Cannot create console thread!',13,10,0
3394
con.nomem_err       db 'Not enough memory!',13,10,0
3395
con.aFinished       db ' [Finished]',0
3396
con.aNull           db '(null)',0
9096 hidnplayr 3397
con.beep            db 0x90, 0x3C, 0x00
9105 hidnplayr 3398
con.bell            db 0x85, 0x25, 0x85, 0x40, 0x00
836 diamond 3399
con.ipc_buf         dd 0,8,0,0
3400
                    db 0
3401
 
3402
section '.data' data readable writable align 16
3403
 
9105 hidnplayr 3404
process_info_buffer         process_info
3405
 
836 diamond 3406
con.finished_title          rb 256
3407
 
9105 hidnplayr 3408
con.cur_x                   dd ?        ; Active cursor column (0 based)
3409
con.cur_y                   dd ?        ; Active cursor row (0 based)
3410
con.main_cur_x              dd ?        ; Saved cursor position for main buffer
3411
con.main_cur_y              dd ?        ; Saved cursor position for main buffer
3412
con.wnd_xpos                dd ?        ; Active window position in active buffer
3413
con.wnd_ypos                dd ?        ; Active window position in active buffer
3414
con.main_wnd_xpos           dd ?        ; Saved window position for main buffer
3415
con.main_wnd_ypos           dd ?        ; Saved window position for main buffer
3416
con.scroll_top              dd ?        ; VT100 scroll region
3417
con.scroll_bot              dd ?        ; VT100 scroll region
836 diamond 3418
 
9105 hidnplayr 3419
con.wnd_width               dd ?        ; window width (= alt buffer width)
3420
con.wnd_height              dd ?        ; window height (= alt buffer height)
3421
con.main_scr_width          dd ?        ; main buffer width
3422
con.main_scr_height         dd ?        ; main buffer height
3423
con.scr_width               dd ?        ; active buffer width
3424
con.scr_height              dd ?        ; active buffer height
3425
con.title                   dd ?
3426
con.data                    dd ?        ; active buffer ptr
3427
con.mainbuffer              dd ?
3428
con.altbuffer               dd ?
3429
con.image                   dd ?
3430
con.console_tid             dd ?
3431
con.data_width              dw ?        ; width in pixels
3432
con.data_height             dw ?        ; height in pixels
3433
con.vscrollbar_size         dd ?
3434
con.vscrollbar_pos          dd ?
3435
con.up_first_time           dd ?
3436
con.down_first_time         dd ?
3437
con.scroll_up_first_time    dd ?
3438
con.scroll_down_first_time  dd ?
3439
con.bUpPressed_saved        db ?
3440
con.bDownPressed_saved      db ?
3441
con.bScrollingUp_saved      db ?
3442
con.bScrollingDown_saved    db ?
836 diamond 3443
 
9105 hidnplayr 3444
con.input_buffer            rw 128
836 diamond 3445
con.input_buffer_end = $
3446
 
9105 hidnplayr 3447
con.kbd_layout              rb 128
836 diamond 3448
 
9105 hidnplayr 3449
con.thread_op               db ?
3450
con.bUpPressed              db ?
3451
con.bDownPressed            db ?
3452
con.bScrollingUp            db ?
3453
con.bScrollingDown          db ?
836 diamond 3454
 
3455
con.stack                   rb 1024
3456
con.stack_top = $