Subversion Repositories Kolibri OS

Rev

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