Subversion Repositories Kolibri OS

Rev

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

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