-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpcbios.a86
4028 lines (3875 loc) · 87.1 KB
/
pcbios.a86
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
;*********************************************
;* *
;* IBM-PC Basic I/O System (PCBIOS) *
;* *
;* For CPM-86 v1.1 *
;* *
;*********************************************
;
; 31/12/1998
;
; Code/data yet to comment....
;1. 3fef - setting i/o routines pointer (byte 47e1)
;2. SOSTATC TEST CL,AH
;3. VIDCOM -label calls to
;4. 4980 offset ??
;5. chkcp3 - comment
;6. chkcp4 - comment
;7. 2be5
;8. 3d52
;
; BUGS in original code
; ---------------------
; 1. labeled 'BUG DI' - Incorrectly using DI instead of SI
;
;#rcpmx.xxx
;
; Start End
;139D:0000 139D:47FF
;#l2500,47ff
; Ascii characters
CTRLC EQU 03H
BEL EQU 07H
BS EQU 08H
LF EQU 0AH
CR EQU 0DH
ESC EQU 1BH
; Logical
TRUE EQU 0FFH
FALSE EQU 0
; Addresses
CCP_OFFSET EQU 0000H
BDOS_OFST EQU 0B06H ; BDOS entry point
BIOS_CODE EQU 2500H
;*********************************************
;* *
;* Dummy Data Section *
;* *
;* for Interrupt Vectors *
;* *
;*********************************************
DSEG 0 ; MEMORY ZERO PAGE
ORG 0 ;
ZEROOFF RW 1 ; DIV BY ZERO OFFSET
ZEROSEG RW 1 ; AND SEGMENT
ORG 4*01BH
BREAKOFF RW 1 ; USER BREAK OFFSET
BREAKSEG RW 1 ; AND SEGMENT
TIMEROFF RW 1 ; TIMER INT OFFSET
TIMERSEG RW 1 ; AND SEGMENT
ORG 4*01EH
I1EOFF RW 1 ; DISK PARM POINTER OFFSET
I1ESEG RW 1 ; AND SEGMENT
ORG 4*0E0H
BDOSOFF RW 1 ; BDOS ENTRY OFFSET
BDOSSEG RW 1 ; AND SEGMENT
ORG 4*0E6H
UNDSKOFF RW 1 ; UNKNOWN DISK DRIVE INT OFFSET
UNDSKSEG RW 1 ; AND SEGMENT
;*********************************************
;* *
;* Dummy Data Section *
;* *
;* for Page 0040H *
;* *
;*********************************************
DSEG
ORG 10H
BIOSHDW RB 1 ; BIOS hardware setting
;*********************************************
;* *
;* Dummy Data Section *
;* *
;* for BDOS Data *
;* *
;*********************************************
DSEG
ORG 24A5h
BDOSUSER RB 1 ; USER NUM HIDES HERE
ORG 24AFh
BDOSMODABT RB 1 ; BDOS ABORT MODE
ORG 24B7h
BDOSCURDRV RB 1 ; BDOS CURRENT DRIVE
ORG 24BDh
DHOUR RB 1 ; DECIMAL HOURS
DMINUTE RB 1 ; DECIMAL MINUTES
DSECOND RB 1 ; DECIMAL SECONDS
;
AMONTH RW 1 ; ASCII MONTH
RB 1 ; /
ADAY RW 1 ; ASCII DAY
RB 1 ; /
AYEAR RW 1 ; ASCII YEAR
RB 1 ; ,
AHOUR RW 1 ; ASCII HOURS
RB 1 ; :
AMINUTE RW 1 ; ASCII MINUTES
RB 1 ; :
ASECOND RW 1 ; ASCII SECONDS
RB 1
SYSMESSAGE RB 14 ; SYS STATUS MESSAGE
BDOSCONWID RB 1 ; BDOS CONSOLE WIDTH
;*********************************************
;* *
;* Dummy Code Section *
;* *
;* for CCP entry points *
;* *
;*********************************************
CSEG
ORG CCPOFFSET
CCP:
;*********************************************
;* *
;* Code Section *
;* *
;* BIOS Jump Vector for Individual Routines *
;* *
;*********************************************
CSEG
ORG BIOS_CODE
JMP INIT ; Enter from BOOT ROM or LOADER
JMP WBOOT ; Arrive here from BDOS call 0
JMP CONST ; Return console keyboard status
JMP CONIN ; Return console keyboard char
JMP CONOUT ; Write char to console device
JMP LISTOUT ; Write character to list device
JMP PUNCH ; Write character to punch device
JMP READER ; Return char from reader device
JMP HOME ; Move to trk 00 on cur sel drive
JMP SELDSK ; Select disk for next rd/write
JMP SETTRK ; Set track for next rd/write
JMP SETSEC ; Set sector for next rd/write
JMP SETDMA ; Set offset for user buff (DMA)
JMP READ ; Read a 128 byte sector
JMP WRITE ; Write a 128 byte sector
JMP LISTST ; Return list status
JMP SECTRAN ; Xlate logical->physical sector
JMP SETDMAB ; Set seg base for buff (DMA)
JMP GETSEGT ; Return offset of Mem Desc Table
JMP GETIOB ; Return I/O map byte (IOBYTE)
JMP SETIOB ; Set I/O map byte (IOBYTE)
RS 15 ; Reserved - 5 more JMP's
; Pointers to
DW Offset PFKTABLE ; - Function keys data
DW Offset DISK ; - Disk parameters
DW Offset SER1 ; - Serial port init parameters
DB 010h,033h ; - Device data
DW Offset FIDDSMEM ; - FIDD data
DW Offset CRTMOD ; - Screen data
DB 'Copyright (C) 1983, Digital Research'
;----------------------------------------
; Arrive here from BDOS call 0
;
WBOOT:
MOV Byte Ptr X3A70,0 ; Default drive on startup ?
MOV Byte Ptr X3A6D,0FFh ; Disk error or change ???
JMP CCP+6 ; Jump to cold start entry of CCP
;*********************************************
;* *
;* CP/M Character I/O Interface Routines *
;* *
;*********************************************
; Return console keyboard char
;
; Input: none
; Output: AL:=char AND 07FH
;
CONIN:
MOV AX,Word Ptr SYS_CONI
JMPS XINPUT
;
; Write char to console device
;
; Input: CL:=char
; Output: none
;
CONOUT:
MOV AX,Word Ptr SYS_CONO
JMPS XOUTPUT
;
; Return console keyboard status
;
; Input: none
; Output: IF ready THEN AL:=0FFH
; ELSE AL:=00
;
CONST:
MOV AX,Word Ptr SYS_CONI
MOV CL,01h
JMPS XOSTATUS
;
; Return char from reader device
;
; Input: none
; Output: AL:=char AND 07FH
;
READER:
MOV AX,Word Ptr SYS_AUXI
JMPS XINPUT
;
; Write character to punch device
;
; Input: CL:=char
; Output: none
;
PUNCH:
MOV AX,Word Ptr SYS_AUXO
JMPS XOUTPUT
;
; Write character to list device
;
; Input: CL:=char
; Output: none
;
LISTOUT:
MOV AX,Word Ptr SYS_LST
JMPS XOUTPUT
;
; Return list status
;
; Input: none
; Output: IF ready THEN AL:=0FFH
; ELSE AL:=00
;
LISTST:
MOV AX,Word Ptr SYS_LST
MOV CL,20h
JMPS XOSTATUS
;
; Common character input routine
;
XINPUT: CLD
MOV BX,Offset INROUTINES
MOV CX,11 ; Only 11 possible routines
SUB DX,DX
XINPUT1:
ROR AX,1h
JNB XINPUT2
JMP Word Ptr [BX] ; Transfer to first routine
XINPUT2:
INC BX ; Next routine
INC BX
LOOP XINPUT1
JMP KEYIN ; No more - assume keyboard
;
; Common character output routine
;
XOUTPUT:
CLD
MOV BX,Offset OUTROUTINES
MOV CH,11 ; Only 11 possible routines
XOUTPUT1:
ROR AX,1 ; Is this it
JNB XOUTPUT2 ; No
PUSH AX
PUSH BX
PUSH CX
SUB DX,DX
CALL Word Ptr [BX] ; Transfer to that routine
POP CX
POP BX
POP AX
XOUTPUT2:
INC BX ; Check for next
INC BX
DEC CH ; Any more?
JNZ XOUTPUT1 ; Try again
RET ; Now leave
;
;
; Common input status
;
; Routine to return status of CONSOLE or LIST device
;
XOSTATUS:
MOV BX,Offset OUTSTATUS
MOV CH,0Bh
SUB DX,DX
XOSTAT1:
ROR AL,1
JB XOSTAT2
INC BX
INC BX
DEC CH
JNZ XOSTAT1
MOV AL,0FFh
RET
XOSTAT2:
JMP Word Ptr [BX]
;
;
; Keyboard status
; Exit: AL = 0ffh if char ready
; AL = 0 if not ready
;
KEYSTAT:
PUSH SI
MOV SI,Word Ptr KEYPTR ; Check PFK buffer
MOV AL,[SI] ; Char from buffer
POP SI
TEST AL,AL ; Valid if not zero
JNZ KEYSTAT1 ; Skip if readys
;
MOV AH,01h ; Read keyboard status
INT 16h ; PC ROM BIOS Keyboard Service
MOV AL,0 ; Assume not readys
JZ KEYSTAT2
KEYSTAT1:
MOV AL,0FFh ; Character readys
KEYSTAT2:
RET
;
;
; Keyboard input
; Exit: AL = char
;
KEYIN: PUSH SI
KEYIN1: MOV SI,Word Ptr KEYPTR ; Check key buffer
LODSB ; Get the character
TEST AL,AL ; Return buf char
JZ KEYIN3 ; Else read keyboard
MOV Word Ptr KEYPTR,SI
KEYIN2: POP SI
RET
KEYIN3: SUB AH,AH ; Read char from keyboard
INT 16h ; PC ROM BIOS Keyboard Service
AND AL,7Fh
JNZ KEYIN2 ; Return if ascii
;
; Check for programmable function keys
;
PUSH CX
PUSH DI
PUSH ES
MOV AL,AH ; Get key code
CALL GETPFK ; AX -> pfk entry
JC KEYIN4 ; C set if illegal
;
MOV SI,AX ; Table pointer
MOV DI,Offset KEYBUF
MOV Word Ptr KEYPTR,DI ; Checked at entry
REP MOVSB ; Move to keybuffer
KEYIN4: POP ES
POP DI
POP CX
JMP KEYIN1 ; Start it
;
; Point to PFK entry
; Entry: AL = key code
; Exit: AX = pointer to table entry
; CX = Length of table entry
; Carry = not a legal PFK
;
GETPFK: MOV DI,CS
MOV ES,DI
MOV DI,Offset PFKSCAN ; Function key scancode table ?
MOV CX,20
REPNE SCASB
STC ; Assume illegal
JNZ GETPFK2 ; Exit if not found
;
MOV AX,20
MUL CL
ADD AX,Offset PFKTABLE ; Offset to table entry
MOV CX,20 ; Length of table entry
GETPFK2:
RET
;
;
; Video output routine
;
VIDOUT: JMP Word Ptr STATE
;
;
; Null output routine
;
NULLST:
MOV AL,0FFh
RET
;
; Normal ascii video vector
; Character is in the AL register (CL on entry)
;
VIDNORM:
MOV AL,CL
VIDNORM1:
MOV DX,Word Ptr CURSOR ; Collect cursor position
CMP AL,BS
JZ VIDBS ; Back space
CMP AL,LF
JZ VIDLF ; Line feed
CMP AL,CR
JZ VIDCR ; Carriage return
CMP AL,ESC
JZ VIDESC ; Escape
CMP AL,BEL
JZ VIDBEL ; Beep
;
; Printable ascii characters fall through
;
VIDASCII:
MOV AH,09h ; Write code
MOV BH,0 ; Page 0
MOV CX,1 ; One copy of char
MOV BL,Byte Ptr ATTRIB ; Attribute
CALL VIDCOM ; Write it
;
INC DL ; Next column
CMP DL,Byte Ptr CRTCOL ; Past the edge ?
JB SETCURSOR ; If not, skip
;
; Test for end of line wrap around
;
TEST Byte Ptr WRAPFLAG,TRUE
JZ VIDRETURN ; If no wrap, done
;
CALL VIDCR ; Else, do a return
; Fall into a line feed
;
; Video line feed
;
VIDLF: INC DH ; Next line
CMP DH,18h ; At page end?
JB SETCURSOR ; If not, skip
MOV AX,0601h ; Scroll one line
SUB CX,CX ; Upper left corner
JMP VDASLIN2 ; Do it
;
; Video carriage return
;
VIDCR: MOV DL,0 ; First column
;
SETCURSOR:
MOV Word Ptr CURSOR,DX ; Update our copy
MOV AH,2 ; Set cursor code
MOV BH,0 ; Page 0
CALL VIDCOM
RET
;
; Video back space
;
VIDBS: DEC DL ; Back one column
JNS SETCURSOR ; If pos, no prob
;
TEST Byte Ptr WRAPFLAG,TRUE ; If no wrap around
JZ VIDRETURN ; Then forget it
;
DEC DH ; If top row,
JS VIDRETURN ; Then forget it
MOV DL,Byte Ptr CRTCOL ; Else wrap around
DEC DL
JMPS SETCURSOR
VIDBEL: MOV SI,Offset SNDTBL1
JMP BEEP
;
; Video escape - set up state vector
;
VIDESC: MOV Word Ptr STATE,Offset VIDESC1
;
VIDRETURN:
RET
;
; Character after escape comes here
;
VIDESC1:
CALL VPCOMP ; Clear the STATE incase
DISPATCH:
MOV DX,Word Ptr CURSOR ; Setup the cursor
PUSH DI
PUSH ES
MOV DI,CS
MOV ES,DI
MOV DI,Offset ESCTBL ; Point to search table
MOV AL,CL
MOV CX,0029h
REPNE SCASB ; Search ESC char table
POP ES
POP DI
JZ DISPATCH1 ; Found
JMP VIDASCII ; No, must be printable
DISPATCH1:
MOV BX,Offset ESCJMP ; Point to routine table
ADD CX,CX
SUB BX,CX
JMP Word Ptr [BX] ; Transfer to it
;
; ESC H - home cursor
;
VHOME:
SUB DX,DX ; 0,0 = Top left
SETCUR: JMP SETCURSOR ; For local short
;
; ESC E - erase screen and home cursor
;
VEOSALL:
CALL VHOME ; Get to top left
SUB CX,CX
MOV DH,17h
MOV DL,Byte Ptr CRTCOL
DEC DL
JMP VEOLEND1 ; Erase to end of screen
;
; ESC A - cursor up
;
VUP: DEC DH ; Row = row - 1
JNS SETCUR ; If pos, set cursor
RET ; Else forget it
;
; ESC B - cursor down
;
VDOWN: INC DH ; Row = row + 1
CMP DH,18h ; Too far ?
JB SETCUR ; If not, set cursor
RET ; Else ignore
;
; ESC C - cursor forward (right)
;
VFORW: INC DL ; Col = col + 1
CMP DL,Byte Ptr CRTCOL ; Too far ?
JB SETCUR ; If not, set cursor
RET ; Else ignore
;
; ESC D - cursor back (left)
;
VBACK: DEC DL ; Col = col - 1
JNS SETCUR ; Not to far, set cursor
RET ; Else ignore
;
; ESC I - cursor up (scroll at top)
;
VUPSAT: TEST DH,DH ; Top of screen ?
JNZ VUP ; No, cursor up
JMP VIASLIN ; Yes, insert line and scroll down
;
; ESC j - save cursor position
;
VSAVCUR:
MOV Word Ptr SAVECURSOR,DX ; Stash it
RET
;
; ESC k - restore (saved) cursor position
;
VRSTCUR:
MOV DX,Word Ptr SAVECURSOR ; Get it back
JMP SETCUR ; and set it
;
; ESC Y - set cursor position
;
VSETCUR:
MOV Word Ptr STATE,Offset VSET1
RET ; Look for next char
;
; ESC Y part 1 - set cursor row
;
VSET1: SUB CL,20h ; Correct
JNS VSET1A ; Skip if positive
MOV CL,0 ; Else top row
VSET1A: CMP CL,18h
JB VSET1B ; Skip if ok
MOV CL,17h ; Else page bottom
VSET1B: MOV Byte Ptr CURROW,CL ; Save cursor row
MOV Word Ptr STATE,Offset VSET2
RET ; Ready for column
;
; ESC Y part 2 - set cursor column
;
VSET2: SUB CL,20h ; Correct
JNS VSET2A ; Skip if positive
MOV CL,0 ; Else first col
VSET2A: CMP CL,Byte Ptr CRTCOL
JB VSET2B ; Skip if ok
MOV CL,Byte Ptr CRTCOL ; Else last col
DEC CL
VSET2B: MOV DX,Word Ptr CURSOR ; Get the value
MOV DL,CL ; Update row
CALL VPCOMP ; Reset STATE
JMP SETCURSOR ; Move cursor now
;
; ESC J - erase to end of screen (from cursor)
;
VEOSEND:
PUSH DX ; Save cursor
CALL VEOLEND ; Erase to end of line
POP DX
CMP DH,17h
JB VEOSEND1
RET
;
VEOSEND1:
INC DH
MOV CH,DH
MOV CL,0
MOV DH,17h
MOV DL,Byte Ptr CRTCOL
DEC DL
JMPS VEOLEND1 ; Erase to end of screen
;
; ESC l - Erase current line (all characters)
;
VECLIN:
MOV CH,DH
MOV CL,0
MOV DL,Byte Ptr CRTCOL
DEC DL
JMPS VEOLEND1 ; Erase to end of line
;
; ESC o - erase beginning of line to cursor
;
VEOLBEG:
MOV CH,DH
MOV CL,0
DEC DL
JNS VEOLEND1 ; Erase to end of screen
RET
;
; ESC K - erase to end of line
;
VEOLEND:
MOV CX,DX
MOV DL,Byte Ptr CRTCOL
DEC DL
VEOLEND1:
MOV BH,Byte Ptr ATTRIB
AND BH,Byte Ptr X36B8
MOV AX,0700h
JMP VIDCOM
;
; ESC L - insert line and scroll down
;
VIASLIN:
MOV AX,0701h
JMPS VDASLIN1
;
; ESC M - delete line and scroll up
;
VDASLIN:
MOV AX,0601h
;
VDASLIN1:
CMP DH,17h
JZ VECLIN ; Erase current line (all characters)
MOV CH,DH
MOV CL,0
;
VDASLIN2:
MOV DH,17h
MOV DL,Byte Ptr CRTCOL
DEC DL
MOV BH,Byte Ptr ATTRIB
AND BH,Byte Ptr X36B8
JMP VIDCOM
;
; ESC N - delete character at cursor (moving other charcters to fill gap)
;
VDELCHR:
MOV AL,Byte Ptr CRTCOL
SUB AL,DL
CBW
MOV DI,AX
CALL VSETCUR3
MOV DL,Byte Ptr CRTCOL
DEC DL
MOV SI,0720h
MOV BH,0
MOV CX,0001h
VDELCHR1:
MOV AH,02h
CALL VIDCOM
MOV AH,08h
CALL VIDCOM
XCHG AX,SI
MOV BL,AH
MOV AH,09h
CALL VIDCOM
DEC DL
DEC DI
JNZ VDELCHR1
JMP VRSTCPT ; Restore cursor posn and type
;
; ESC a - set video mode
;
VSETMODE:
MOV Word Ptr STATE,Offset VSETMODE1
RET ; Get next char
;
; ESC a (mode) - set video mode
;
VSETMODE1:
MOV AL,CL ; Required mode
CALL SETCURCRT ; Set current video details
CALL VSETCUR3
PUSH ES
MOV AX,0040h
MOV ES,AX
MOV AL,ES:Byte Ptr BIOSHDW
AND AL,0CFh
OR AL,Byte Ptr CRTBVM ; Set BIOS video mode
MOV ES:Byte Ptr BIOSHDW,AL ; Store BIOS equipment work
POP ES
MOV AL,Byte Ptr CRTMOD ; Mode
MOV AH,0
CALL VIDCOM
CALL VEOSALL ; Erase screen and home cursor
CALL CLRBOS1 ; Clear status line
CALL VRSTCPT ; Restore cursor posn and type
JMP VPCOMP ; Reset STATE
;
; ESC b - set foreground colour
;
VFRGND: MOV Word Ptr STATE,Offset VFRGND1
RET ; Get next char
;
; ESC b (colour) - set foreground colour
;
VFRGND1:
MOV AL,CL
MOV AH,Byte Ptr ATTRIB
JMPS VFGBG ; Common routine
;
; ESC c - set background colour
;
VBKGND: MOV Word Ptr STATE,Offset VBKGND1
RET ; Get next char
;
; ESC c (colour) - set background colour
;
VBKGND1:
MOV AH,CL
MOV CL,04h
ROL AH,CL ; Move to MSB's
MOV AL,Byte Ptr ATTRIB
VFGBG: AND AL,0Fh ; LSB's only
AND AH,0F0h ; MSB's only
OR AL,AH ; Mash 'em
MOV Byte Ptr ATTRIB,AL
JMP VPCOMP ; Reset STATE
;
; ESC d - redirect console input
;
VNEWCONI:
MOV AX,Offset SYS_CONI
JMPS VNEW
;
; ESC e - redirect console output
;
VNEWCONO:
MOV AX,Offset SYS_CONO
JMPS VNEW
;
; ESC f - redirect auxilary input
;
VNEWAUXI:
MOV AX,Offset SYS_AUXI
JMPS VNEW
;
; ESC g - redirect auxilary output
;
VNEWAUXO:
MOV AX,Offset SYS_AUXO
JMPS VNEW
;
; ESC h - redirect list output
;
VNEWLST:
MOV AX,Offset SYS_LST
; ;JMPS VNEW ; Fall through
;
; Redirect any i/o device vector
; Entry: AX -> a particular vector
;
VNEW: MOV Word Ptr DELTAVEC,AX ; Vector to change
MOV Word Ptr STATE,Offset VNEW1
RET ; Wait for next char
;
; Next state
;
VNEW1: MOV Byte Ptr DELTALO,CL
MOV Word Ptr STATE,Offset VNEW2 ; Next time
RET ; Wait for one more
;
; Last state
;
VNEW2: MOV BX,Word Ptr DELTAVEC ; Get the vector to change
MOV AH,CL
MOV AL,Byte Ptr DELTALO
AND AX,7F7Fh ; Mask off
MOV Word Ptr [BX],AX ; Set vector
JMP VPCOMP ; Reset STATE
;
; ESC m - turn cursor on
;
VCURON: MOV CX,Word Ptr CURLON ; Normal lines (on)
JMPS VSETCUR1
;
; ESC n - turn cursor off
;
VCUROFF:
MOV CX,Word Ptr CURLOFF ; Cursor lines (off)
;
VSETCUR1:
MOV Word Ptr CURCUR,CX ; Save current cursor type
VSETCUR2:
MOV AH,1 ; Set cursor type
JMP VIDCOM ; Do it
;
VSETCUR3:
MOV CX,Word Ptr CURLOFF
JMPS VSETCUR2
;
; Restore cursor position and type
;
VRSTCPT:
MOV DX,Word Ptr CURSOR
CALL SETCURSOR
MOV CX,Word Ptr CURCUR ; Current (in use) cursor type
JMPS VSETCUR2
;
; ESC p - reverse video on
;
VREVON: AND Byte Ptr ATTRIB,0F8h ; Black foreground
OR Byte Ptr ATTRIB,070h ; White background
RET
;
; ESC q - reverse video off
;
VREVOFF:
AND Byte Ptr ATTRIB,8Fh
OR Byte Ptr ATTRIB,07h
RET
;
; ESC s - turn blinking text on
;
VBLINKON:
OR Byte Ptr ATTRIB,80h
RET
;
; ESC t - turn blinking text off
;
VBLINKOFF:
AND Byte Ptr ATTRIB,7Fh
RET
;
; ESC r - turn high intensity text on
;
VINTON: MOV AL,0Eh
JMPS VINTCHG
;
; ESC u - turn high intensity text off
;
VINTOFF:
MOV AL,07h
VINTCHG:
AND Byte Ptr ATTRIB,0F0h
OR Byte Ptr ATTRIB,AL
RET
;
; ESC v - text wrap at end of line
;
VWRAP: MOV Byte Ptr WRAPFLAG,TRUE
RET
;
; ESC w - no text wrap at end of line
;
VNOWRAP:
MOV Byte Ptr WRAPFLAG,0
RET
;
; ESC x - set MONO80 mode
;
VMON80:
MOV CL,03h
JMP VSETMODE1
;
; ESC y - set COL80 mode
;
VCOL80:
MOV CL,07h
JMP VSETMODE1
;
; ESC / - perform INT 10h function 0Bh
;
VSETPAL:
MOV Word Ptr STATE,Offset VSETPAL1
RET ; Ready for next char
VSETPAL1:
MOV Byte Ptr VSETPALBH,CL ; Save BH value
MOV Word Ptr STATE,Offset VSETPAL2
RET
VSETPAL2:
MOV BL,CL ; Get BL value
MOV BH,Byte Ptr VSETPALBH ; and BH value
AND BX,7F7Fh
MOV AH,0Bh
CALL VIDCOM
JMP VPCOMP ; Reset STATE and return
;
; ESC : - set programmable function keys
;
;
VPFK: MOV Word Ptr STATE,Offset EPFK1
RET ; Ready for key code
;
; Get key scan code
;
EPFK1: CALL VPCOMP ; Reset STATE (default)
PUSH DI
PUSH ES
MOV AL,CL
CALL GETPFK ; AX -> pfk entry
JC EPFK1A ; C set if illegal
;
MOV Word Ptr EPFKPTR,AX ; Save pointer
MOV Byte Ptr EPFKCOUNT,CL ; Save char count
MOV Word Ptr STATE,Offset EPFK2
EPFK1A: POP ES
POP DI
RET
;
; Get the string
;
EPFK2: MOV BX,Word Ptr EPFKPTR ; Point to entry
MOV Byte Ptr [BX],CL ; Store char
;
DEC Byte Ptr EPFKCOUNT
JZ EPFK2A ; Skip if failed
;
TEST CL,CL ; Or if char = 0
JZ EPFK2A
;
INC BX ; Bump the pointer for next time
MOV Word Ptr EPFKPTR,BX
RET ; Keep VIDSTATE
;
; Process complete
;
EPFK2A: JMPS VPCOMP ; Reset STATE to normalcy
;
; ESC 1 - TURN ON/CLEAR STATUS LINE AT BOTTOM OF SCREEN
;
VBOSON:
MOV AL,Byte Ptr CRTMOD ; Current mode
MUL Byte Ptr CRTTEL