/
sys.mac
1957 lines (1927 loc) · 53.8 KB
/
sys.mac
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
TITLE MSX-DOS 2 - MSX-DOS.SYS copyright (1986) IS Systems Ltd.
SUBTTL BDOS and BIOS
;
.Z80
include MACROS.INC
include USEKMSG.MAC
;
;
FALSE EQU 0
TRUE EQU NOT FALSE
;
TEST EQU FALSE ; TRUE for testing version.
;
;
; This file contains all the code of MSX-DOS2.SYS once in memory. It is
; re-located to high memory on start up and is always put on a page boundary,
; so that the BIOS jump table can be on a page boundary.
;
; The re-location in memory is done by comparing linking the .REL file
; twice on page boundaries, and comparing the two images. Any differences are
; the high bytes of addresses that need re-locating (the low bytes being
; correct).
;
; For this reason, this file cannot be split into two or more .REL
; files and it must contain no global symbol declarations and no references to
; external symbols that would need relocation.
;
; The start of the file, which is the thing which must be on a page
; boundary, is the BIOS jump table. The first entry is jumped to in order to
; start MSX-DOS.SYS up properly. Below this on the next page boundary is the
; destination of the BDOS jump at 5. This jump is not included in MSX-DOS.SYS
; but is set up during the initialization. The 250 bytes or so between this
; jump and the BIOS jump table is used as the BDOS stack. The BIOS also needs
; to switch to a separate stack, although this one does not need to be so
; large.
;
START:
;
;
CODE MACRO OPCODE,ARG
.8080
DB (OPCODE ARG)
.Z80
ENDM
;
;
LF EQU 0AH
CR EQU 0DH
ESC EQU 1BH
;
;
P3BDOS EQU 0F37DH ; Disk BASIC BDOS entry point in page 3.
MFLAGS EQU 0F2EFH ; Miscellaneous flags
;
;
;
SUBTTL BIOS Table and Routines
;******************************************************************************
;
; This is the dummy CP/M BIOS jump table. The first entry, as in CP/M,
; is the cold start entry point and is jumped to by the loader code to
; actually start up MSX-DOS.SYS. It has to jump to the loaded code at a well
; known entry point because this code is not allowed to declare any externals.
;
; The character entry points just end up calling the BIOS entry points
; in the disk ROM, which then do all the dirty stuff necessary to call the MSX
; BIOS ROM.
;
;
BIOS_TAB:
JP STARTUP ; Initial start-up entry point.
JREBOOT:JP REBOOT ; Re-load COMMAND.COM.
JP CONST ; Console status.
JP CONIN ; Console input.
JP CONOUT ; Console output.
JP LIST ; Printer output.
JP PUNCH ; Auxiliary output.
JP READER ; Auxiliary input.
JP DISK ; Disk functions, return errors where possible.
JP DISK
JP DISK
JP DISK
JP DISK
JP DISK
JP DISK
JP LISTST ; Printer status.
JP DISK
;
;
DEFW VERMSG ; Pointer to version message.
VERNUM:
defb RELEASE##+(RELEASE##/256)*16
defb VERSION##
;
;
VERMSG: DEFB 'NEXTOR.SYS version '
DEFB VERSION##+'0', '.', RELEASE##/256+'0', RELEASE##+'0'
DEFB 0
;
;
;
;------------------------------------------------------------------------------
;
; This is the sign-on message that gets printed when MSX-DOS.SYS starts
; up. If the testing version is assembled, then extra text is included as a
; warning.
;
if 0
SIGNON: DEFB 'Nextor version '
DEFB VERSION##+'0', '.', RELEASE##/256+'0', RELEASE##+'0'
DEFB CR,LF
DEFB 'Copyright ('
DEFB CRYEAR##/1000 MOD 10 +'0'
DEFB CRYEAR##/ 100 MOD 10 +'0'
DEFB CRYEAR##/ 10 MOD 10 +'0'
DEFB CRYEAR## MOD 10 +'0'
DEFB ') Konamiman',CR,LF
;
IF TEST
DEFB CR,LF
DEFB '*** MZED-compatible testing version ***'
DEFB CR,LF
ENDIF
;
DEFB CR,LF
DEFB 0
endif
;
;
;------------------------------------------------------------------------------
;
; This is the initial start up entry point. As in CP/M, this is entered
; via the first BIOS jump and should not normally be re-entered. If it is,
; however, it will probably not do any real harm as the system will just
; re-start. It is assumed, however, that characters can be output without
; getting disk errors, which would otherwise cause the disk error & possibly
; the abort routine to be called, which are not yet defined. The sign-on and
; 'not enough memory' messages are printed by calling the disk BASIC BDOS
; entry point at F37D, since when these messages need printing the normal BDOS
; entry point is not yet set up properly.
;
; The disk BASIC entry point at F37D is not supported in MSX-DOS 2, and
; so once MSX-DOS.SYS has started up a jump is put at F37D to jump to the
; normal BDOS entry code. If anything is trying to call F37D, this stands more
; of a chance of working than anything else that could be done to F37D.
;
STARTUP:LD HL,P3BDOS ; Character outputs initially go through page 3
LD (OVEC),HL ; entry point.
;
if 0 ;v2.31
LD A,(NOTFIRST##) ; Print sign-on message through page 3 entry,
LD DE,SIGNON ; but only if the first time.
OR A
CALL Z,DSTR
;
endif
LD C,_DOSVER## ; Get the version number.
CALL P3BDOS ; In case it's an old system.
LD A,B
CP 2 ; Check KBDOS is 2.00 or later.
LD A,__BADVER## ; Print error & halt if not.
JP C,HANG
;
LD HL,SERIAL## ; Copy the serial number (will probably be
LD DE,SERNO ; wrong if this is entered a second time
LD BC,4 ; via the BIOS jump table, but that doesn't
LDIR ; particularly matter).
;
RESTART:LD HL,0 ; Zero main and secondary errors returned by
LD (ERROR2),HL ; process.
;
ifdef ver880722
LD DE,80H ; DE -> command line buffer.
LD A,(DE) ; Command (from _SYSTEM command from BASIC)?
OR A
JR NZ,BOOT ; Leave it there if it is.
;
endif
LD A,(BOOT_DRV##) ; Else set up AUTOEXEC.BAT if the first boot or
ADD A,'A'-1 ; REBOOT otherwise, with the boot drive as
LD (AUTPAT),A ; a parameter (so that the batch files can
LD (REBPAT),A ; access the boot drive as %1).
LD (AUTOCMD+1),A ; Load AUTOEXEC from the boot drive.
LD (REBCMD+1),A ; Load REBOOT from the boot drive.
LD (CMNDM),A ; Load COMMAND.COM from the boot drive.
;
ifndef ver880722
LD DE,80H ; DE -> command line buffer.
LD A,(DE) ; Command (from _SYSTEM command from BASIC)?
OR A
JR NZ,BOOT ; Leave it there if it is.
;
endif
LD HL,NOTFIRST## ; NZ => not the first boot.
LD A,(HL)
LD (HL),H ; (set flag => not first time any more)
;
LD HL,AUTOCMD
OR A
JR Z,COPYCMD
;
LD HL,REBCMD
COPYCMD:LD C,(HL) ; Get length of command.
INC C ; Include length byte (B=0 from above).
INC C ; Include null on end.
LDIR
;
JR BOOT ; Jump to re-booting code to load COMMAND.COM.
;
;
;
;------------------------------------------------------------------------------
;
; This is the re-booting code for the BIOS jump table entry. It gets
; entered when a transient program that was previously loaded terminates (by
; RETurning with the same stack, jumping to zero or one of the 101 other ways
; of terminating), and just loads COMMAND.COM at 100H and calls it (as a
; transient program). The standard MSX-DOS2 COMMAND.COM patches the BIOS jump
; table re-boot entry point to point to a bit of code in high memory that
; checksums the area of memory that COMMAND.COM was saved in so that it only
; re-loads it off disk if it has to.
;
; COMMAND.COM is executed as a standard CP/M transient program. The
; BIOS jump at 0 and the BDOS jump at 5 are set up appropriately and jump to
; addresses of the form xx03 and xx06 respectively as in CP/M. A command line
; was put there by whatever code loaded and executed MSX-DOS.SYS, and this is
; left intact for the command interpreter to look at. If no command was given,
; however, then MSX-DOS.SYS provides one. This is either AUTOEXEC.BAT or
; REBOOT.BAT, depending upon whether a variable is zero (first start-up) or
; non-zero (re-booting). Although a CP/M-compatible command line is provided,
; the default CP/M FCBs are not set up, as this is rather a lot of bother to
; do. The FCBs are instead just zeroed.
;
; In principle then it should be possible to rename any CP/M or MSX-DOS
; program as COMMAND.COM and MSX-DOS will boot up into it. The preferred
; method of doing this, however, is to load the program in the REBOOT batch
; file.
;
; The BOOT entry point below is used when booting COMMAND.COM for the
; first time after MSX-DOS.SYS is loaded. The REBOOT entry point is used when
; COMMAND.COM terminates, and it clears the command buffer which the first
; time contained a command to execute or a AUTOEXEC.BAT or REBOOT.BAT command.
;
; The error returned from the last process (as returned from the JOIN
; function call) is zeroed initially by STARTUP. After that, the error code
; will actually be the error code returned by the last invocation of COMMAND.
; If this is not .BADCMD or .OKCMD (or if the first time round) then COMMAND
; will simply be loaded from disk at 100H and executed. If however the error
; code was .BADCMD or .OKCMD , then it is assumed that COMMAND is still intact
; in memory and it simply gets jumped to at 100H without re-loading.
;
; This is a fiddle for the initial boot. COMMAND is passed the name of
; the batch file ('AUTOEXEC' or 'REBOOT') as a command to execute, and if it
; does not find the batch file then it returns .BADCMD. If the batch file was
; executed OK then it returns .OKCMD. The fiddle described above is done to
; prevent a re-load of COMMAND in this perfectly valid and not particularly
; uncommon case. COMMAND co-operates in this scheme by guaranteeing that if
; it terminates with .BADCMD or .OKCMD then it is still in memory.
;
;
REBOOT: XOR A ; Zero command in command buffer so that when
LD (80H),A ; it is re-loaded it does not get a command.
;
BOOT: CALL $DOSOFF## ; Set up page 1.
;
LD HL,DISK_ERROR ; Set up disk error handler vector.
LD (KDSK_VECT##),HL
LD HL,ABORT ; Set up abort routine vector.
LD (KAB_VECT##),HL
;
LD DE,0 ; Undefine user's routines.
CALL @DEFER
CALL @DEFAB
;
LD HL,REBOOT ; Make sure re-boot BIOS jump is set up.
LD (JREBOOT+1),HL
LD A,0FFH ; Initialize BDOS re-entrancy count.
LD (ENTERS),A
;
LD HL,0 ; Set up jump vectors at bottom of memory.
CODE MVI A
CODE JMP
LD (HL),A
INC HL
LD (HL),LOW BIOS_TAB+3
INC HL
LD (HL),HIGH BIOS_TAB
INC HL
LD (HL),0 ; I/O byte not implemented.
INC HL
INC HL ; Current drive set up later.
LD (HL),A ; 5 = BDOS jump, address set up later.
LD HL,JBDOS+8 ; Last byte of destination of JP at 5.
;
LD (HL),HIGH BDOS ; Set up jump address.
DEC HL
LD (HL),LOW BDOS
DEC HL
LD (HL),A ; Set up actual JP opcode.
LD (6),HL ; Set up address in jump at 5.
DEC HL
EX DE,HL ; Copy serial number which was copied to SERNO
LD HL,SERNO+3 ; from the start of the MSX-DOS.SYS file.
LD BC,4
LDDR
EX DE,HL
LD (HL),22 ; Put in CP/M version number.
DEC HL
LD (HL),0
;
LD A,H ; If out of page 3, then print out of memory
CP 0C0H ; error & hang.
JR NC,MEMOK
;
LD A,__NOMEM## ; Get DE -> message.
HANG: CALL MESSAGE
CALL DERRM ; Print error.
CALL CRLF
DI
HALT
;
MEMOK: LD SP,BIOS_STACK ; Use MSX-DOS.SYS's own stack in page 3.
LD HL,BDOS ; OK to use the normal BDOS entry point now.
LD (OVEC),HL
;
LD C,_CURDRV## ; Get the current drive and put it at 4 for
CALL BDOS ; CP/M compatibility.
LD (4),A
;
if 0 ;Hal_F
LD HL,(6) ; Make the F37D entry point jump to the same
LD (P3BDOS+1),HL ; place as the normal entry point at 5.
CODE MVI A
CODE JMP
LD (P3BDOS),A
endif
;
LD A,(ERROR) ; Get error code from COMMAND without doing a
CP .BADCMD## ; JOIN, and don't reload if .BADCMD or .OKCMD
JR Z,LOADOK ; =>COMMAND is still in memory. Go with NC.
;
CP .OKCMD## ; (ERROR will be 0 first time round)
JR Z,LOADOK ; Go with NC.
;
CP .BATEND## ; Means AUTOEXEC/REBOOT were terminated by the
JR Z,LOADOK ; user. Go with NC.
;
REJOIN: LD BC,0*256+_JOIN##; Reset file handles etc.
CALL BDOS
JR NZ,REJOIN ; May fail first time, but should then be OK.
;
OR B ; Any error from previous process?
JR Z,NPERR ; Go if not.
;
CALL DERR ; Else print error message.
CALL CRLF
NPERR: LD DE,CMNDM ; DE -> '\COMMAND.COM'.
LD C,_OPEN##
XOR A
CALL BDOS ; Attempt to open COMMAND.COM.
JR NZ,LDERR ; Go if error.
;
LD DE,100H ; Else load program to here.
LD HL,JBDOS-100H ; Maximum number of bytes loadable.
PUSH HL
PUSH BC ; Save file handle.
LD C,_READ##
CALL BDOS ; Read COMMAND.COM to 100H.
POP BC ; Restore file handle.
POP DE ; Restore maximum number of bytes usable.
JR NZ,LDERR ; Go if error.
;
SBC HL,DE ; All of memory filled up?
LD A,.NORAM## ; (should not really occur)
JR Z,LDERR ; Print 'Not enough memory' if yes.
;
LD C,_CLOSE## ; Close file handle.
CALL BDOS
JR NZ,LDERR
;
SCF ; Cy => set LOAD_FLAG to FF.
LOADOK: ; COMMAND.COM is sitting at 100H.
PUSH AF ; Save LOAD_FLAG.
LD HL,5CH ; Zero CP/M FCBs.
LD B,H ; B=0 for later.
ZLOOP: LD (HL),H
INC L
JP P,ZLOOP ; Zero until 80H, which is the command line.
;
EX DE,HL ; Set up default DMA address to 80H.
LD C,_SETDTA##
CALL BDOS
;
POP AF ; Set LOAD_FLAG to FF if a real load => loaded
SBC A,A ; by MSX-DOS.SYS.
LD (LOAD_FLAG##),A
;
XOR A ; Put address 0 on the stack so that when
LD L,A ; the COMMAND terminates MSX-DOS.SYS
LD H,A ; re-loads and executes it.
PUSH HL
LD DE,BIOS_TAB-1 ; CP/M seems to execute transient programs
LD C,0FFH ; with the registers set up this way.
LD B,A
JP 100H ; Jump to the program.
;
;
AUTOCMD:DEFB 18,'A:\AUTOEXEC.BAT ' ; A: patched to the boot drive.
AUTPAT: DEFB 'A:',0 ; A: patched to the boot drive.
REBCMD: DEFB 16,'A:\REBOOT.BAT ' ; A: patched to the boot drive.
REBPAT: DEFB 'A:',0 ; A: patched to the boot drive.
;
CMNDM: DEFB 'A:\COMMAND2.COM',0 ; A: patched to the boot drive.
CMDLEN EQU $-CMNDM
;
;
LDERR: ; Error during re-loading - A=error code.
CP .NOFILE## ; If 'file not found', then suppress error
LD B,A ; message & just prompt for COMMAND disk.
CALL NZ,DERR
CALL CRLF
LD A,__INSERT##
CALL DMSG ; Print 'Insert COMMAND.COM disk' etc.
LD C,_CURDRV##
CALL BDOS ; Get current drive.
ADD A,'A' ; Convert to drive letter and print it.
CALL OUTCH
LD A,__INSDRV## ; Print rest of message (':' in English).
CALL DMSG
CALL CRLF
LD A,__PAUSE## ; Print 'Press any key to continue' etc.
CALL DMSG
CALL INCH ; Wait for a keypress.
JP REBOOT ; Try again.
;
;
;
;------------------------------------------------------------------------------
;
; The BIOS character I/O routines follow. These are fairly simple
; because all they really do is call the disk ROM, which has suitable entry
; points for the BIOS routines.
;
;
CONST: LD HL,KCONST##
JR BIOS
;
CONIN: LD HL,KCONIN##
JR BIOS
;
CONOUT: LD HL,KCONOUT##
JR BIOS
;
LIST: LD HL,KLIST##
JR BIOS
;
PUNCH: LD HL,KPUNCH##
JR BIOS
;
READER: LD HL,KREADER##
JR BIOS
;
LISTST: LD HL,KLISTST##
;
BIOS: LD (BIOS_SP),SP ; Save user's stack and switch to
LD SP,BIOS_STACK ; stack in page 3.
;
CALL GO_BIOS##
;
LD SP,(BIOS_SP) ; Restore user's stack.
RET
;
;
;
;------------------------------------------------------------------------------
;
; This is the routine entered for the disk BIOS functions, which are
; not supported. They return errors where possible but otherwise just return.
; No CP/M program calling one of these is going to work in any sensible way
; anyway.
;
;
DISK: XOR A
LD L,A ; HL = 0 => error from SELDSK function.
LD H,A
DEC A ; A = FF => error from read/write.
RET
;
;
;
SUBTTL BDOS Entry/Exit Code.
;******************************************************************************
;
; When a program does a BDOS call, it calls location 5. This contains a
; jump to another jump at an address of the form xx06 (for CP/M compatibility)
; which then jumps to here. This code can then call the KBDOS.
;
;
; If a user's disk error routine is defined and a disk error occurs,
; then it is likely to want to do character I/O calls. Thus this entry code
; has to be re-entrant for at least the direct console I/O function, although
; no steps are taken to prevent an attempted re-entry of other functions. The
; reason they may not work is that another disk error could occur. It is
; inadvisable to call even the other character functions re-entrantly since
; these can still result in a disk error through re-direction and so on.
;
; During a BDOS call, the ABORT routine may be jumped to. This gets
; jumped to with an error code in A from somewhere within the mysterious
; depths of the KBDOS. When this happens, the user's abort routine (if
; defined) is called also with the error code in A. If that returns, then the
; error code (which may have been modified) is stored in the ERROR variable.
; If it chooses not to return, then ERROR is zero because it is zeroed before
; calling a transient program. ERROR2 is treated similarly, but contains the
; secondary error code.
;
; In order to ensure that the user's routine is called in a state where
; he may return or may continue, the user's error routine is called by
; patching the 'RET' at the end of the BDOS return code to a NOP, so execution
; falls through to the code below which does the actual calling. This ensures
; that the stack etc. is OK.
;
;
; When the KBDOS performs a read or write, it uses the segments defined
; by the variables P0_TPA..P3_TPA. These are set up when a stack switched
; occurs (ie. when the BDOS is called non-reentrantly) but not at other times.
; On return, the paging will always by set up to P0_TPA..P3_TPA. On return
; from a re-entrant call from a disk error routine therefore the paging will
; be set up to the paging state when the BDOS was first called.
;
; For all calls, all other parameters must either be in registers or in
; page 3 RAM. Since many BDOS calls pass pointers etc., the items that are
; pointed to are copied to a page 3 buffer, and pointers to this buffer passed
; to the KBDOS. The things which are copied are FCBs, ASCIIZ
; drive/path/filename strings, File Info Blocks and strings to be printed.
; Since the latter is of arbitrary length, a little print string routine is
; implemented here.
;
; All other copied data structures are 64 bytes or less, although some
; functions require more than one thing to be copied.
;
; A few functions alter the values of IX and IY. These are pushed onto
; the stack immediately before the return address when calling the function
; routines, and so these functions can change them in a slightly naughty way.
;
; On every BDOS call, the fixed page 3 variable LOAD_FLAG is set to
; zero. This is used by COMMAND.COM and specially-written programs to check
; whether it was loaded from COMMAND.COM or MSX-DOS.SYS.
;
BDOS:
LD (A_SAVE),A ; Save A parameter to function.
LD A,(ENTERS) ; Get re-entrancy count.
INC A ; First entry?
LD (ENTERS),A
if 1
jr z,BDOS05
ld (BIOS_SP),sp
ld sp,BIOS_STACK-100
push hl
push bc
ld hl,(BDOS_STACK##)
ld bc,(BIOS_SP)
or a
sbc hl,bc
jr c,BDOS02
ld bc,BDS_SZ##
sbc hl,bc
ccf
BDOS02: pop bc
pop hl
ld sp,(BIOS_SP)
jr nc,BDOS10
xor a
ld (ENTERS),a
BDOS05:
else
JR NZ,BDOS10 ; Go if not, else switch stacks.
endif
;
LD (LOAD_FLAG##),A ; Gets set to 0 on every BDOS call.
LD (BDOS_SP),SP
LD SP,(BDOS_STACK##)
;
BDOS10: EX AF,AF' ; Save alternate register set, as the KBDOS
PUSH AF ; doesn't.
EXX ; Save BDOS parameters in alternate registers.
PUSH HL
PUSH DE
PUSH BC
LD HL,(SP_SAVE) ; Save SP_SAVE for re-entrancy reasons.
PUSH HL
PUSH IX ; A couple of routines below change the values
PUSH IY ; of these saved IX and IYs.
LD (SP_SAVE),SP ; Save SP for abort entry.
if 1 ;v2.30
LD HL,DISK_ERROR ; Set up disk error handler vector.
LD (KDSK_VECT##),HL
LD HL,ABORT ; Set up abort routine vector.
LD (KAB_VECT##),HL
endif
LD HL,BDOS_DONE ; Call KBDOS then return to BDOS_DONE.
PUSH HL
;
EXX ; Get back BDOS call parameters.
PUSH HL
LD A,C ; Get function number.
CP MAXFN ; If function number is greater than we know
JR C,OKFN ; about, then just pass it through to KBDOS.
;
LD A,BADNO
OKFN: LD HL,FNTAB ; HL -> table of function routine addresses.
ADD A,A ; *2 (addresses in table are 2 bytes)
ADD A,L
LD L,A
JR NC,NOINC
;
INC H
NOINC: LD A,(HL)
INC HL
LD H,(HL)
LD L,A
EX (SP),HL ; Save routine address, get HL back.
CODE MVI A ; Get A back again.
A_SAVE: DEFB 0
RET ; Jump to routine for this function.
;
;
BDOS_DONE:
EX AF,AF' ; Save returned A.
CODE MVI A ; Ensure final 'RET' is set up.
CODE RET
LD (RETPAT),A
EX AF,AF'
BDOS_RET:
CODE LXI SP
SP_SAVE: DEFW 0 ; Restore stack pointer.
EXX ; Save returned registers.
EX AF,AF'
POP IY ; Restore index registers.
POP IX
POP HL
LD (SP_SAVE),HL ; Restore saved value of SP_SAVE.
POP BC ; Restore saved alternate register set.
POP DE
POP HL
EXX
POP AF
EX AF,AF'
PUSH AF
;
LD A,(ENTERS) ; Switch back to user's stack if
DEC A ; returning from first call.
LD (ENTERS),A
JP P,BDOS20
;
POP AF ; Pop AF again over stack switch.
LD SP,(BDOS_SP)
PUSH AF
BDOS20:
POP AF ; Restore A returned from KBDOS.
OR A ; Set flags.
RETPAT: RET ; Patched to a 'NOP' for abort.
;
; ;
;
;
JP_ABORT: ; Abort user's BDOS or BIOS call.
PUSH HL
PUSH AF ; Save error code.
LD HL,(ABORT_VECT) ; Get user's abort routine address.
LD A,H
OR L
POP HL ; H=error code.
LD A,H ; AF=error code.
POP HL
CODE CNZ ; Call user's routine if defined.
ABORT_VECT:
DEFW 0
LD (ERROR),A ; Save error and re-boot if no user routine or
LD A,B ; if it returned the error.
LD (ERROR2),A ; Save secondary error code.
;
; Simulate DOS1 compatible Control-C handler.
;
ld a,(ERROR)
or a
JR Z,GO_REBOOT
;
OLD_BREAK:
ld hl,(BREAKVECT##)
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
jp (hl)
;
GO_REBOOT:
JP 0
;
;
;------------------------------------------------------------------------------
;
FNTAB: ; Table of routine addresses for the functions.
DEFW @TERM0 ; Terminate program with no error.
DEFW @CONIN ; Console input.
DEFW @CONOUT ; Console output.
DEFW @AUXIN ; Auxiliary input.
DEFW @AUXOUT ; Auxiliary output.
DEFW @LSTOUT ; List output.
DEFW @DIRIO ; Direct console I/O.
DEFW @DIRIN ; Direct console input, no echo.
DEFW @INNOE ; Console input, no echo.
DEFW @STROUT ; String output.
DEFW @BUFIN ; Buffered line input.
DEFW @CONST ; Console status.
;
DEFW @CPMVER ; Return CP/M version number.
DEFW @DSKRST ; Disk reset.
DEFW @SELDSK ; Select disk.
;
DEFW @FOPEN ; Open file (FCB).
DEFW @FCLOSE ; Close file (FCB).
DEFW @SFIRST ; Search for first (FCB).
DEFW @SNEXT ; Search fir next (FCB).
DEFW @FDEL ; Delete file (FCB).
DEFW @RDSEQ ; Read sequential (FCB).
DEFW @WRSEQ ; Write sequential (FCB).
DEFW @FMAKE ; Create file (FCB).
DEFW @FREN ; Rename file (FCB).
;
DEFW @LOGIN ; Get login vector.
DEFW @CURDRV ; Get current drive.
DEFW @SETDTA ; Set disk transfer address.
DEFW @ALLOC ; Get allocation information.
;
DEFW @BADCPM ; Write protect disk in CP/M.
DEFW @BADCPM ; Get read only vector in CP/M.
DEFW @BADCPM ; Set file attributes in CP/M.
DEFW @BADCPM ; Get Disk Parameter Block in CP/M.
DEFW @BADCPM ; Get/set user code in CP/M.
;
DEFW @RDRND ; Read random (FCB).
DEFW @WRRND ; Write random (FCB).
DEFW @FSIZE ; Get file size (FCB).
DEFW @SETRND ; Set random record (FCB).
DEFW @BADFN ; Undefined function in CP/M.
DEFW @WRBLK ; Write random block (FCB).
DEFW @RDBLK ; Read random block (FCB).
DEFW @WRZER ; Write random with zero fill (FCB).
DEFW @BADFN ; Unused.
;
DEFW @GDATE ; Get date.
DEFW @SDATE ; Set date.
DEFW @GTIME ; Get time.
DEFW @STIME ; Set time.
DEFW @VERIFY ; Set/reset verify flag.
;
DEFW @RDABS ; Absolute sector read.
DEFW @WRABS ; Absolute sector write.
;
DEFW @DPARM ; Get disk parameters.
;
BADNO EQU 32H ; Function no. used for un-implemented fns.
DEFW @BADFN ; Un-implemented functions.
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
DEFW @BADFN
;
; Start of MSX-DOS 2 functions.
DEFW @FFIRST ; Find first entry.
DEFW @FNEXT ; Find next entry.
DEFW @FNEW ; Find new entry.
;
DEFW @OPEN ; Open file handle.
DEFW @CREATE ; Create file and open file handle.
DEFW @CLOSE ; Close file handle.
DEFW @ENSURE ; Ensure file handle.
DEFW @DUP ; Duplicate file handle.
DEFW @READ ; Read from file handle.
DEFW @WRITE ; Write to file handle.
DEFW @SEEK ; Seek (position file pointer).
DEFW @IOCTL ; I/O control for devices.
DEFW @HTEST ; Test file handle.
;
DEFW @DELETE ; Delete file or sub-directory.
DEFW @RENAME ; Rename file or sub-directory.
DEFW @MOVE ; Move file or sub-directory.
DEFW @ATTR ; Get/set file attributes.
DEFW @FTIME ; Get/set file time.
;
DEFW @HDELETE ; Delete file handle.
DEFW @HRENAME ; Rename file handle.
DEFW @HMOVE ; Move file handle.
DEFW @HATTR ; Get/set file handle attributes.
DEFW @HFTIME ; Get/set file handle time.
;
DEFW @GETDTA ; Get disk transfer address.
DEFW @GETVFY ; Get verify flag setting.
DEFW @GETCD ; Get current directory.
DEFW @CHDIR ; Set current directory.
DEFW @PARSE ; Parse path-name string.
DEFW @PFILE ; Parse filename.
DEFW @CHKCHR ; Check character.
DEFW @WPATH ; Get whole path string.
DEFW @FLUSH ; Flush disk buffers.
;
DEFW @FORK ; Fork to process.
DEFW @JOIN ; Join to process.
DEFW @TERM ; Terminate with error code.
DEFW @DEFAB ; Define abort exit routine.
DEFW @DEFER ; Define critical error handler routine.
DEFW @ERROR ; Get previous error code.
DEFW @EXPLAIN ; Explain error code.
DEFW @FORMAT ; Format a disk.
DEFW @RAMD ; Create or destroy RAM-disk.
DEFW @BUFFER ; Allocate sector buffers.
DEFW @ASSIGN ; Logical drive assignment.
;
DEFW @GENV ; Get environment string.
DEFW @SENV ; Set environment string.
DEFW @FENV ; Find environment name.
;
DEFW @DSKCHK ; Get/set disk check status.
DEFW @DOSVER ; Get version number.
DEFW @REDIR ; Get/set redirection status (missing in the original???)
DEFW @FOUT ; Get/set fast STROUT mode.
DEFW @ZSTROUT ; Zero-terminated string output.
DEFW @RDDRV ; Absolute drive sector read.
DEFW @WRDRV ; Absolute drive sector write.
DEFW @RALLOC ; Get/set reduced allocation information mode vector
DEFW @DSPACE ; Get disk space information
DEFW @LOCK ; Lock/unlock drive
DEFW @GDRVR ; Get driver information
DEFW @GDLI ; Get drive letter information
DEFW @GPART ; Get information about disk partition
DEFW @CDRVR ; Call a routine in a disk driver
DEFW @MAPDRV ; Map a drive to a driver/device/LUN/sector
DEFW @Z80MODE ; Enable or disable the Z80 access mode for a driver
DEFW @GETCLUS ; Get information about a cluster in a FAT drive
;
MAXFN EQU ($-FNTAB)/2 ; Largest function number.
;
;
;
SUBTTL BDOS CP/M Character I/O Functions
;******************************************************************************
;
@CONIN:
@CONOUT:
@AUXIN:
@AUXOUT:
@LSTOUT:
@DIRIO:
@DIRIN:
@INNOE:
@CONST:
@CPMVER:
if 0
@DSKRST:
@SELDSK:
endif
@SNEXT:
@LOGIN:
@CURDRV:
@SETDTA:
@VERIFY:
@BADCPM:
CALL KBDOS
LD A,L ; Get value to return in A, L.
LD B,H ; Get value to return in B, H.
RET
;
;
if 1
@DSKRST:
LD E,0
@SELDSK:
PUSH DE ; Save drive over call.
CALL KBDOS
POP DE
OR A
LD A,E
JR NZ,BAD_DRIVE ; If drive was good put it at 4 for
LD (4),A ; CP/M compatibility.
BAD_DRIVE:
LD A,L
LD B,H
RET
endif
;
;
;------------------------------------------------------------------------------
;
@STROUT:
ld a,(MFLAGS)
and 1
jr z,strout_slow ;If fast STROUT not enabled, use the slow version.
;--- STROUT, fast version
ex de,hl
ld de,($SECBUF##)
ld bc,511
ldir
ld a,"$"
ld (de),a
ld c,_STROUT##
call KBDOS
jr CPMRET
;--- STROUT, slow version
strout_slow:
do_strout KBDOS,CPMRET,1 ;Macro defined in macros.inc
;
;
;------------------------------------------------------------------------------
;
@BUFIN: PUSH DE
LD A,(DE) ; Copy only the max. length byte at the start.
LD DE,BUFF1 ; Use this as the input buffer.
LD (DE),A
CALL KBDOS
POP DE ; Copy the characters back again.
LD A,(DE) ; Copy back the number of characters specified
INC DE ; by the max. length byte+1 for the actual
LD HL,BUFF1+1 ; length byte. Cannot just copy the right
LD C,A ; number of characters because there is a
LD B,0 ; CR character on the end which may or may
INC BC ; not be there.
LDIR
;
CPMRET: XOR A
LD B,A
LD L,A
LD H,A
RET
;
;
;
;------------------------------------------------------------------------------
;
;
@ZSTROUT:
ld a,(MFLAGS)
and 1
jr z,zstr_slow ;If fast STROUT not enabled, use the slow version.
;--- ZSTROUT, fast version
ex de,hl
ld de,($SECBUF##)
ld bc,511
ldir
xor a
ld (de),a
ld c,_ZSTROUT##
call KBDOS
xor a
ret
;--- ZSTROUT, slow version
zstr_slow:
LD A,(DE) ;Cannot call the KBDOS routine because the
INC DE ; string may be any length so cannot be
or a
ret z
PUSH DE
LD E,A
LD C,_CONOUT##
CALL KBDOS
POP DE
JR zstr_slow
;
;
SUBTTL BDOS CP/M FCB File Functions
;******************************************************************************
;
; Most of the CP/M file functions involve copying FCBs backwards and
; forwards. For the sequential operations, 33 bytes need to by copied. For