-
Notifications
You must be signed in to change notification settings - Fork 1
/
QCRT.ASM
1825 lines (1672 loc) · 34.7 KB
/
QCRT.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Copyright 1990-2021, Jerome Shidel
; Released Under Mozilla Public License 2.0
; This project and related files are subject to the terms of the Mozilla Public
; License, v. 2.0. If a copy of the MPL was not distributed with this file, You
; can obtain one at http://mozilla.org/MPL/2.0/.
; QCrt 9.1
; For DOS, Nasm and Pascal 16-bit edition.
; This assembly language library uses the pascal calling convention. All calls
; are far calls. Data parameters passed to procedure and functions are pushed
; onto the stack in reverse order and are popped automatically by the function
; or procedure on their return. Simple function return values are usually set
; in AL, AX or in the DX:AX pair. DS, SS, SP, BP are preserved. However, the
; state of all other registers are not guaranteed. So, if calling this library
; from a language other than Pascal, such as from more assembly code, you must
; take care of preserving any registers and values you wish to retain yourself!
%idefine QCrt 9.1
%ifndef TargetOS
%idefine TargetOS DOS
%endif
%ifndef TargetCPU
%idefine TargetCPU 8086
%endif
%ifndef QDefines
%include "QDEFINES.INC"
%endif
; Internal Data Segment
section Section_DATA
VideoPtr:
VideoOfs:
DW 0
VideoSeg:
DW 0
VideoPage:
DB 0
DoubleWide:
DB 0
UserFont:
DB 0
CurrentXY:
CurrentX:
DB 0
CurrentY:
DB 0
CurrentCursor:
DW 0
FirstMode:
DW 0
FirstCursor:
DW 0
FirstAttr:
DB 0
DelayData:
DW 0
%ifdef EnableMouse
MouseMask:
DW 0
MouseHandler:
DW 0, 0
MouseLastState:
DW 0, 0, 0 ; Button State, X, Y
MouseFrozen:
DB 0
MouseCheckState:
DW 0, 0, 0
MouseShowLevel:
DW 0
MouseHiddenFlag:
DW 0
MouseButtonTrack:
times 16 DW 0
MouseDoubleFlag:
DB 0
%endif
%ifidn __OUTPUT_FORMAT__, obj
section Section_SHARED
extern CheckBreak ; : boolean; { Enable Ctrl-Break }
extern CheckEOF ; : boolean; { Enable Ctrl-Z }
extern DirectVideo ; : boolean; { Enable direct video addressing }
extern CheckSnow ; : boolean; { Enable snow filtering }
extern LastMode ; : word; { Current text mode }
extern TextAttr ; : byte; { Current text attribute }
extern WindMin ; : word; { Window upper left coordinates }
extern WindMax ; : word; { Window lower right coordinates }
extern Check101Key ; : boolean; { If 101-Key Keyboard is present }
extern CheckScroll ; : boolean; { false causes window wrapping }
extern UserFontHeight ; : byte; { Height of user defined font }
extern UserFontPtr ; : pointer; { pointer to user defined font }
extern TabWidth ; : byte; { Spaces per tab }
extern ScreenMax ; : word; { Screen lower right coordinates }
%ifdef EnableMouse
extern MouseButtons ; : integer; { Number of buttons, 0 if no mouse }
extern MouseVisible ; : boolean; { Visible state of mouse }
extern MouseCellX ; : word; { Value to slow down movement }
extern MouseCellY ; : word; { Value to slow down movement }
extern MouseClickSpeed ; : word; { Mouse double click speed }
extern MouseHomeX ; : integer; { X Home position of mouse }
extern MouseHomeY ; : integer; { Y Home position of mouse }
%endif
extern IdleCPU ; : boolean; { Idle CPU during Idle Process }
extern IdleProc ; : pointer; { Idle procedure chain }
%else
CheckBreak: DB FALSE
CheckEOF: DB FALSE
DirectVideo: DB FALSE
CheckSnow: DB FALSE
LastMode: DW 0
TextAttr: DB 0
WindMin: DW 0
WindMax: DW 0
ScreenMax: DW 0
Check101Key: DB FALSE
CheckScroll: DB FALSE
UserFontHeight: DB 0
UserFontPtr: DD 0
TabWidth: DB 0
%ifdef EnableMouse
MouseButtons DB 0
MouseVisible DB FALSE
MouseCellX DW 0
MouseCellY DW 0
MouseClickSpeed DW 0
MouseHomeX DB 0
MouseHomeY DB 0
%endif
%endif
section Section_CODE
; ------------------- Internal Functions; Don't call them directly !!!!
%ifdef EnableMouse
; Mouse Interrupt Handler Needs to be able to find program data segment
MouseDS:
dw 0
%endif
%imacro PreWriteXY 0
%ifdef EnableMouse
pushf
cli
push ax
push bx
mov ax, [CurrentXY]
mov bl, [MouseLastState + 2]
mov bh, [MouseLastState + 4]
cmp ax, bx
jne %%Safe
mov [MouseHiddenFlag], byte TRUE
call MouseHidePointer
%%Safe:
pop bx
pop ax
popf
%endif
%endmacro
%imacro PreWrite 0
%ifdef EnableMouse
pushf
cli
push ax
mov [MouseHiddenFlag], byte TRUE
call MouseHidePointer
pop ax
popf
%endif
%endmacro
%imacro PostWriteXY 0
%ifdef EnableMouse
pushf
cli
push ax
mov al, [MouseHiddenFlag]
mov [MouseHiddenFlag], byte FALSE
cmp al, TRUE
jne %%Safe
call MouseShowPointer
%%Safe:
pop ax
popf
%endif
%endmacro
%imacro PostWrite 0
%ifdef EnableMouse
pushf
cli
push ax
mov al, [MouseHiddenFlag]
mov [MouseHiddenFlag], byte FALSE
cmp al, TRUE
call MouseShowPointer
%%Safe:
pop ax
popf
%endif
%endmacro
; Internal Crt Variable Data Initialization, called at any video mode change
InitCrtData:
mov [WindMin], word 0x0000
; set current video text mode data
MemByte 0x0040, 0x0049
mov bl, al
MemByte 0x0040, 0x0085
mov bh, al
mov al, [DoubleWide]
cmp al, TRUE
jne .NotDouble
or bh, 0x80
.NotDouble:
mov al, [UserFont]
cmp al, TRUE
jne .NotUserFont
or bh, 0x40
.NotUserFont:
mov [LastMode], bx
; figure out screen dimensions
MemWord 0x0040, 0x004A
dec ax
mov ah, al
MemByte 0x0040, 0x0084
xchg al, ah
mov [ScreenMax], ax
mov [WindMax], ax
MemByte 0x0040, 0x0062
mov [VideoPage], al
; get cursor position and shape
call ReadCursor
; detect direct video memory address
MemWord 0x0040, 0x004E
mov [VideoOfs], ax
mov [VideoSeg], word 0xB800
mov [DirectVideo], byte FALSE
mov ax, [LastMode]
and ax, 0x00FF
cmp ax, 0x07
jne .NotMono
mov [VideoSeg], word 0xB000
.NotMono:
cmp ax, 0x03
jg .NoDirectVideo
%ifdef DVSupport
%warning Direct Video Not Yet Implemented
mov [DirectVideo], byte TRUE
%elifdef DirectVideoOnly
%warning Compiling without BIOS Video Support
%elifdef BiosVideoOnly
%warning Compiling without Direct Video Support
%else
%fatal Neither Direct or BIOS level video support active.
%endif
.NoDirectVideo:
ret
; internal read cursor data
ReadCursor:
mov ah, 0x03
mov bh, [VideoPage]
int 0x10
mov [CurrentCursor], cx
mov [CurrentX], dl
mov [CurrentY], dh
ret
; Internal Actual procedure that moves the cursor
MoveCursorActual:
mov ah, 0x02
mov bx, [WindMin]
mov dl, [CurrentX]
mov dh, [CurrentY]
add dl, bl
add dh, bh
mov bh, [VideoPage]
int 0x10
ret
; Internal Post write cursor movement
MoveCursorNow:
mov ah, [DirectVideo]
cmp ah, TRUE
jne MoveCursorActual
mov ax, [CurrentCursor]
cmp ax, 0x2000
jne MoveCursorActual
ret
; internal cursor movement to CurrentX, CurrentY
MoveCursorMaybe:
mov ah, [DirectVideo]
cmp ah, TRUE
jne MoveCursorActual
ret
; internal next character movement
MoveCursorNext:
mov bx, [WindMin]
mov dx, [WindMax]
mov al, [CurrentX]
inc al
mov [CurrentX], al
mov ah, [CurrentY]
add al, bl
cmp al, dl
jle .InsideWindow
mov al, 0x00
mov [CurrentX], al
inc ah
mov [CurrentY], ah
add ah, bh
cmp ah, dh
jle .InsideWindow
mov ah, 0x00
mov [CurrentY], ah
mov ah, [CheckScroll]
cmp ah, FALSE
je .InsideWindow
sub dh, bh
mov [CurrentY], dh
xcall LineFeed
.InsideWindow:
call MoveCursorMaybe
ret
; internal Write Character to Screen
WriteRawCrtChar:
pushy ax, bx, cx, dx
PreWriteXY
%ifdef DVSupport
mov ah, [DirectVideo]
cmp ah, TRUE
jne .BiosMode
pushy es, si
mov ah, [TextAttr]
push ax
xCalcScreenPtr
pop ax
es mov [SI+BX], AX
poppy si, es
jmp .Done
.BiosMode:
%endif
%ifdef BVSupport
mov ah, 0x09
mov bh, [VideoPage]
mov bl, [TextAttr]
mov cx, 0x0001
int 0x10
%endif
.Done:
PostWriteXY
call MoveCursorNext
poppy dx, cx, bx, ax
ret
; internal Font setting routine
SetFontMode:
mov [DoubleWide], byte FALSE
mov [UserFont], byte FALSE
mov cx, ax
cmp ch, 0
je .Done
mov bl, 0
mov ah, 0x11
mov al, 0x12
cmp ch, 0x08
je .LoadROMFont
mov al, 0x11
cmp ch, 0x0E
je .LoadROMFont
mov al, 0x14
cmp ch, 0x10
je .LoadROMFont
test ch, 0x40
jz .Done
mov [UserFont], byte TRUE
test ch, 0x80
jz .NotDoubleWide
mov [DoubleWide], byte TRUE
.NotDoubleWide:
; set user font
push bp
push es
mov ax, 0x1110
mov bl, 0x00
mov cx, 0x00FF
mov dx, 0x0000
mov bh, [UserFontHeight]
les bp, [UserFontPtr]
int 0x10
pop es
pop bp
%ifdef DoubleFonts
; here will be code to set other half of double wide user font.
%fatal "Double Wide Fonts have not been implemented"
%endif
jmp .Done
.LoadROMFont:
int 0x10
jmp .Done
.Done:
ret
%ifdef EnableMouse
SwapMouseHandler:
mov ax, [MouseButtons]
cmp ax, 0x0000
je .NoMouse
push es
mov dx, [MouseHandler+2]
push dx
pop es
mov dx, [MouseHandler]
mov cx, [MouseMask]
mov ax, 0x0014
int 0x33
mov [MouseMask], cx
mov [MouseHandler], dx
push es
pop dx
mov [MouseHandler+2], dx
pop es
.NoMouse:
ret
MouseEventHandler:
; AX = Event Flag
; BX = Button State
; CX = X coor
; DX = Y Coor
; SI = X Movement
; DI = Y Movement
; DS = Mouse Driver Data Segment
pushf
cli
push ds
push es
%ifidn TargetCPU, 8086
push ax
push bx
push cx
push dx
push si
push di
push bp
%else
pusha
%endif
mov bp, sp
mov ax, [CS:MouseDS]
push ax
pop ds
push bx
; Mouse Y
mov ax, dx
xor dx, dx
mov bx, [MouseCellY]
div bx
push ax
; Mouse X
mov ax, cx
xor dx, dx
mov bx, [MouseCellX]
div bx
mov cx, ax
pop dx
pop bx
mov ax, [MouseLastState + 2]
cmp ax, cx
jne .Changes
mov ax, [MouseLastState + 4]
cmp ax, dx
jne .Changes
mov ax, [MouseLastState]
cmp ax, bx
je .NoChange
.Changes:
; Update Software Mouse Position
mov [MouseLastState], bx
mov [MouseLastState + 2], cx
mov [MouseLastState + 4], dx
mov al, [MouseFrozen]
cmp al, TRUE
je .Frozen
mov ax, [MouseCheckState]
cmp ax, bx
je .NoFreeze
mov [MouseFrozen], byte TRUE
mov [MouseCheckState + 2], cx
mov [MouseCheckState + 4], dx
.NoFreeze:
mov [MouseCheckState], bx
.Frozen:
.NoChange:
mov sp, bp
%ifidn TargetCPU, 8086
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
%else
popa
%endif
pop es
pop ds
popf
retf
MouseHidePointer:
pushf
cli
mov ax, [MouseButtons]
cmp ax, 0x0000
je MouseSetVisible
mov ax, [MouseShowLevel]
dec ax
mov [MouseShowLevel], ax
cmp ax, 0
jne MouseSetVisible
mov ax, 0x0002
int 0x33
jmp MouseSetVisible
MouseShowPointer:
pushf
cli
mov ax, [MouseButtons]
cmp ax, 0x0000
je MouseSetVisible
mov ax, [MouseShowLevel]
inc ax
mov [MouseShowLevel], ax
cmp ax, 1
jne MouseSetVisible
mov ax, 0x0001
int 0x33
jmp MouseSetVisible
MouseSetVisible:
mov ax, [MouseShowLevel]
cmp ax, 0
jg .SetVisible
mov [MouseVisible], byte FALSE
popf
ret
.SetVisible:
mov [MouseVisible], byte TRUE
popf
ret
MouseSetPosition:
pushf
cli
mov ax, [MouseLastState + 2]
mov cx, [MouseCellX]
mul cx
mov cx, ax
mov ax, [MouseLastState + 4]
mov dx, [MouseCellY]
mul dx
mov dx, ax
mov ax, 0x0004
int 0x33
popf
ret
MouseHome:
pushf
cli
mov ax, [MouseHomeX]
mov [MouseLastState + 2], ax
mov ax, [MouseHomeY]
mov [MouseLastState + 4], ax
call MouseSetPosition
xor ax, ax
mov [MouseLastState], ax
popf
ret
MouseInit:
pushf
cli
push cs
pop ax
mov [MouseHandler + 2], ax
mov ax, MouseEventHandler
mov [MouseHandler], ax
mov ax, 01111111b
mov [MouseMask], ax
jmp MouseActivate
MouseReset:
mov ax, [MouseButtons]
cmp ax, 0x0000
jne .MousePresent
popf
ret
.MousePresent:
call SwapMouseHandler
MouseActivate:
mov ax, [MouseButtons]
cmp ax, 0x0000
je .NoMouse
mov ax, 0x0000
int 0x33
mov [MouseFrozen], byte FALSE
mov [MouseDoubleFlag], byte FALSE
mov [MouseClickSpeed], word 0x0010
mov [MouseVisible], byte FALSE
mov [MouseShowLevel], word 0
mov [MouseCellX], word 0x0008
; Check for 40 Column Display
mov ax, [LastMode]
cmp al, 0x01
ja .NormalWidth
;mov ax, 0x0010
;mov [MouseCellX], ax
mov ax, 0x08
mov dx, 40 ; Decimal Column max
mul dx
mov dx, ax
dec dx
xor cx, cx ; Minimum Column
mov ax, 0x0007
int 0x33
.NormalWidth:
mov [MouseCellY], word 0x0008
xor ax, ax
mov al, [ScreenMax]
shr ax, 1
mov [MouseHomeX], ax
mov al, [ScreenMax+1]
shr ax, 1
mov [MouseHomeY], ax
call SwapMouseHandler
call MouseHome
call MouseShowPointer
.NoMouse:
popf
ret
%endif
; ------------------------------- QCrt Interface Functions and Procedures
; function InitQCrt : boolean; external;
xfunction InitQCrt, boolean
mov [IdleCPU], byte FALSE
mov [IdleProc], word 0x0000
mov [IdleProc + 2], word 0x0000
mov [CheckBreak], byte FALSE
mov [CheckScroll], byte TRUE
mov [DoubleWide], byte FALSE
mov [UserFont], byte FALSE
mov [CheckSnow], byte FALSE
mov [CheckEOF], byte FALSE
mov [Check101Key], byte FALSE
mov [TabWidth], byte 0x08
%ifdef EnableMouse
push ds
pop ax
mov [cs:MouseDS], ax
mov [MouseButtons], word 0x0000
mov [MouseVisible], byte FALSE
mov [MouseShowLevel], word 0
mov [MouseClickSpeed], word 0x0002
; first test valid Mouse Interrupt Vector
push es
push di
mov ax, 0x0033
mov cx, 0x0004
mul cx
mov di, cx
xor cx, cx
mov ax, [es:di + 2]
mov bx, [es:di]
cmp ax, cx
jne .MouseIRQTest
cmp bx, cx
je .MouseFailed
.MouseIRQTest:
push ax
pop es
mov al, [es:bx]
cmp al, 0xcf
jne .MouseCheck
.MouseFailed:
pop di
pop es
jmp .NoMousePresent
.MouseCheck:
pop di
pop es
xor ax, ax
int 0x33
cmp ax, 0xffff
jne .NoMousePresent
mov ax, 0x0002
cmp bx, 0xffff
je .MousePresent
mov ax, bx
cmp bx, 0x0000
jne .MousePresent
mov ax, 0x0001
.MousePresent:
mov [MouseButtons], ax
.NoMousePresent:
%endif
; Read ega 814 font and set as default user font
%ifdef DirectVideoOnly
%warning "Default UserFontPtr set to Nil"
xor ax, ax
mov [UserFontHeight], al
mov [UserFontPtr], ax
mov [UserFontPtr + 2], ax
%else
mov [UserFontHeight], byte 0x0E
mov ax, 0x1130
mov bh, 0x02
push es
push bp
int 0x10
mov [UserFontPtr], bp
mov [UserFontPtr + 2], es
pop bp
pop es
%endif
; test for 101 Key keyboard support
MemByte 0x0040, 0x0096
test al, 0x10
jz .Not101Key
mov [Check101Key], byte TRUE
.Not101Key:
call InitCrtData
mov ax, [LastMode]
mov [FirstMode], ax
mov ax, [CurrentCursor]
mov [FirstCursor], ax
mov [TextAttr], byte 0x07
mov al, [TextAttr]
mov [FirstAttr], al
%ifdef EnableMouse
call MouseInit
%endif
mov ax, TRUE
cmp ax, TRUE
xret
; procedure DoneQCrt;
xprocedure DoneQCrt
%ifdef EnableMouse
mov ax, [MouseButtons]
cmp ax, 0x0000
je .NoMouse
call MouseHidePointer
call SwapMouseHandler
xor ax, ax
mov [MouseButtons], ax
; mov ax, 0x0000
int 0x33
.NoMouse:
%endif
mov al, [FirstAttr]
mov [TextAttr], al
mov ax, [FirstMode]
mov bx, [LastMode]
cmp ax, bx
je .ValidMode
pushcall TextMode, ax
.ValidMode:
mov ax, [FirstCursor]
mov bx, [CurrentCursor]
cmp ax, bx
je .ValidCursor
pushcall SetCursor, ax
.ValidCursor:
mov [DirectVideo], byte FALSE
call MoveCursorNow
pushcall NoSound
xret
; function KeyPressed : boolean; external;
xfunction KeyPressed, boolean
mov ah, 0x01
int 0x16
mov al, FALSE
jz .Done
mov al, TRUE
.Done:
xor ah, ah
cmp al, TRUE
xret
; function ReadKey : char; external;
xfunction ReadKey, char
mov ah, 0x00
int 0x16
xor ah, ah
xret
; function KeyPressedEnhanced : boolean; external;
xfunction KeyPressedEnhanced, boolean
mov ah, 0x11
int 0x16
mov al, FALSE
jz .Done
mov al, TRUE
.Done:
xor ah, ah
cmp al, TRUE
xret
; function ReadKeyEnhanced : word; external;
xfunction ReadKeyEnhanced, word
mov ah, 0x10
int 0x16
cmp al, 0x00
je .Done
cmp al, 0xE0
je .ClearLow
mov ah, 0x00
jmp .Done
.ClearLow:
mov al, 0x00
.Done:
xret
; procedure TextMode(Mode : integer); external;
xprocedure TextMode, 2
mov ax, [STACKBP + 0]
push ax
xor ah, ah
int 0x10
pop ax
call SetFontMode
call InitCrtData
%ifdef EnableMouse
call MouseReset
%endif
xret
; procedure Window(X1, Y1, X2, Y2 : byte); external;
xprocedure Window, 8
mov al, [STACKBP + 6]
mov ah, [STACKBP + 4]
mov dl, [STACKBP + 2]
mov dh, [STACKBP + 0]
mov bx, [ScreenMax]
dec al
dec ah
dec dl
dec dh
cmp al, dl
jg .Invalid
cmp ah, dh
jg .Invalid
cmp dl, bl
jg .Invalid
cmp dh, bh
jg .Invalid
mov [WindMin], ax
mov [WindMax], dx
mov ax, 0x01
push ax
push ax
xcall GotoXY
.Invalid:
xret
; procedure GotoXY(X, Y : byte); external;
xprocedure GotoXY, 4
mov al, [STACKBP + 2]
mov ah, [STACKBP + 0]
dec al
dec ah
; bounds checking
mov bx, [WindMax]
mov cx, [WindMin]
sub bh, ch
sub bl, cl
inc bl
inc bh
.BadX:
cmp al, bl
jl .BadY
sub al, bl
jmp .BadX
.BadY:
cmp ah, bh
jl .AllGood
sub ah, bh
jmp .BadY
.AllGood:
mov [CurrentX], al
mov [CurrentY], ah
.Done:
call MoveCursorNow
xret
; function WhereX: byte; external;
xfunction WhereX, byte
mov al, [CurrentX]
inc al
xor ah, ah
xret
; function WhereY: byte; external;
xfunction WhereY, byte
mov al, [CurrentY]
inc al
xor ah, ah
xret
; procedure TextColor(Color : byte); external;
xprocedure TextColor, 2
mov al, [TextAttr]
and al, 0xF0
mov ah, [STACKBP + 0]
and ah, 0x0F
or al, ah
mov [TextAttr], al
xret
; procedure TextBackground(Color : byte); external;
xprocedure TextBackground, 2
mov al, [TextAttr]
and al, 0x0F
mov ah, [STACKBP + 0]
and ah, 0x0F
%ifidn TargetCPU, 8086
mov cl, 4