-
Notifications
You must be signed in to change notification settings - Fork 14
/
cpm.asm
1493 lines (1493 loc) · 21.6 KB
/
cpm.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
; TITLE BBC BASIC (C) R.T.RUSSELL 1984
;
;PATCH FOR BBC BASIC TO CP/M 2.2 & 3.0
;* PLAIN VANILLA CP/M VERSION *
;(C) COPYRIGHT R.T.RUSSELL, 25-12-1986
;
;** NEW TO THIS VERSION
;
PUBLIC OSINIT
PUBLIC OSRDCH
PUBLIC OSWRCH
PUBLIC OSLINE
PUBLIC OSSAVE
PUBLIC OSLOAD
PUBLIC OSOPEN
PUBLIC OSSHUT
PUBLIC OSBGET
PUBLIC OSBPUT
PUBLIC OSSTAT
PUBLIC GETEXT
PUBLIC GETPTR
PUBLIC PUTPTR
PUBLIC PROMPT
PUBLIC RESET
PUBLIC LTRAP
PUBLIC OSCLI
PUBLIC TRAP
PUBLIC OSKEY
PUBLIC OSCALL
;
EXTERN ESCAPE
EXTERN EXTERR
EXTERN CHECK
EXTERN CRLF
EXTERN TELL
;
EXTERN ACCS
EXTERN FREE
EXTERN HIMEM
EXTERN ERRLIN
EXTERN USER
;
;OSSAVE - Save an area of memory to a file.
; Inputs: HL addresses filename (term CR)
; DE = start address of data to save
; BC = length of data to save (bytes)
; Destroys: A,B,C,D,E,H,L,F
;
STSAVE: CALL SAVLOD ;*SAVE
JP C,HUH ;"Bad command"
PUSH HL
JR OSS1
;
OSSAVE: PUSH BC ;SAVE
CALL SETUP0
OSS1: EX DE,HL
CALL CREATE
JR NZ,SAVE
DIRFUL: LD A,190
CALL EXTERR
DEFM "Directory full"
DEFB 0
SAVE: CALL WRITE
ADD HL,BC
EX (SP),HL
SBC HL,BC
EX (SP),HL
JR Z,SAVE1
JR NC,SAVE
SAVE1: POP BC
CLOSE: LD A,16
CALL BDOS1
INC A
RET NZ
LD A,200
CALL EXTERR
DEFM "Close error"
DEFB 0
;
;OSSHUT - Close disk file(s).
; Inputs: E = file channel
; If E=0 all files are closed (except SPOOL)
; Destroys: A,B,C,D,E,H,L,F
;
OSSHUT: LD A,E
OR A
JR NZ,SHUT1
SHUT0: INC E
BIT 3,E
RET NZ
PUSH DE
CALL SHUT1
POP DE
JR SHUT0
;
SESHUT: LD HL,FLAGS
RES 0,(HL) ;STOP EXEC
RES 1,(HL) ;STOP SPOOL
LD E,8 ;SPOOL/EXEC CHANNEL
SHUT1: CALL FIND1
RET Z
XOR A
LD (HL),A
DEC HL
LD (HL),A
LD HL,37
ADD HL,DE
BIT 7,(HL)
INC HL
CALL NZ,WRITE
LD HL,FCBSIZ
ADD HL,DE
LD BC,(FREE)
SBC HL,BC
JR NZ,CLOSE
LD (FREE),DE ;RELEASE SPACE
JR CLOSE
;
;TYPE - *TYPE command.
;Types file to console output.
;
TYPE: SCF ;*TYPE
CALL OSOPEN
OR A
JR Z,NOTFND
LD E,A
TYPE1: LD A,(FLAGS) ;TEST
BIT 7,A ;FOR
JR NZ,TYPESC ;ESCape
CALL OSBGET
CALL OSWRCH ;N.B. CALLS "TEST"
JR NC,TYPE1
JR OSSHUT
;
TYPESC: CALL OSSHUT ;CLOSE!
JP ABORT
;
;OSLOAD - Load an area of memory from a file.
; Inputs: HL addresses filename (term CR)
; DE = address at which to load
; BC = maximum allowed size (bytes)
; Outputs: Carry reset indicates no room for file.
; Destroys: A,B,C,D,E,H,L,F
;
STLOAD: CALL SAVLOD ;*LOAD
PUSH HL
JR OSL1
;
OSLOAD: PUSH BC ;LOAD
CALL SETUP0
OSL1: EX DE,HL
CALL OPEN
JR NZ,LOAD0
NOTFND: LD A,214
CALL EXTERR
DEFM "File not found"
DEFB 0
LOAD: CALL READ
JR NZ,LOAD1
CALL INCSEC
ADD HL,BC
LOAD0: EX (SP),HL
SBC HL,BC
EX (SP),HL
JR NC,LOAD
LOAD1: POP BC
PUSH AF
CALL CLOSE
POP AF
CCF
OSCALL: RET
;
;OSOPEN - Open a file for reading or writing.
; Inputs: HL addresses filename (term CR)
; Carry set for OPENIN, cleared for OPENOUT.
; Outputs: A = file channel (=0 if cannot open)
; DE = file FCB
; Destroys: A,B,C,D,E,H,L,F
;
OPENIT: PUSH AF ;SAVE CARRY
CALL SETUP0
POP AF
CALL NC,CREATE
CALL C,OPEN
RET
;
OSOPEN: CALL OPENIT
RET Z ;ERROR
LD B,7 ;MAX. NUMBER OF FILES
LD HL,TABLE+15
OPEN1: LD A,(HL)
DEC HL
OR (HL)
JR Z,OPEN2 ;FREE CHANNEL
DEC HL
DJNZ OPEN1
LD A,192
CALL EXTERR
DEFM "Too many open files"
DEFB 0
;
OPEN2: LD DE,(FREE) ;FREE SPACE POINTER
LD (HL),E
INC HL
LD (HL),D
LD A,B ;CHANNEL (1-7)
LD HL,FCBSIZ
ADD HL,DE ;RESERVE SPACE
LD (FREE),HL
OPEN3: LD HL,FCB ;ENTRY FROM SPOOL/EXEC
PUSH DE
LD BC,36
LDIR ;COPY FCB
EX DE,HL
INC HL
LD (HL),C ;CLEAR PTR
INC HL
POP DE
LD B,A
CALL RDF ;READ OR FILL
LD A,B
JP CHECK
;
;OSBPUT - Write a byte to a random disk file.
; Inputs: E = file channel
; A = byte to write
; Destroys: A,B,C,F
;
OSBPUT: PUSH DE
PUSH HL
LD B,A
CALL FIND
LD A,B
LD B,0
DEC HL
LD (HL),B ;CLEAR EOF
INC HL
LD C,(HL)
RES 7,C
SET 7,(HL)
INC (HL)
INC HL
PUSH HL
ADD HL,BC
LD (HL),A
POP HL
CALL Z,WRRDF ;WRITE THEN READ/FILL
POP HL
POP DE
RET
;
;OSBGET - Read a byte from a random disk file.
; Inputs: E = file channel
; Outputs: A = byte read
; Carry set if LAST BYTE of file
; Destroys: A,B,C,F
;
OSBGET: PUSH DE
PUSH HL
CALL FIND
LD C,(HL)
RES 7,C
INC (HL)
INC HL
PUSH HL
LD B,0
ADD HL,BC
LD B,(HL)
POP HL
CALL PE,INCRDF ;INC SECTOR THEN READ
CALL Z,WRRDF ;WRITE THEN READ/FILL
LD A,B
POP HL
POP DE
RET
;
;OSSTAT - Read file status.
; Inputs: E = file channel
; Outputs: Z flag set - EOF
; (If Z then A=0)
; DE = address of file block.
; Destroys: A,D,E,H,L,F
;
OSSTAT: CALL FIND
DEC HL
LD A,(HL)
INC A
RET
;
;GETEXT - Find file size.
; Inputs: E = file channel
; Outputs: DEHL = file size (0-&800000)
; Destroys: A,B,C,D,E,H,L,F
;
GETEXT: CALL FIND
EX DE,HL
LD DE,FCB
LD BC,36
PUSH DE
LDIR ;COPY FCB
EX DE,HL
EX (SP),HL
EX DE,HL
LD A,35
CALL BDOS1 ;COMPUTE SIZE
POP HL
XOR A
JR GETPT1
;
;GETPTR - Return file pointer.
; Inputs: E = file channel
; Outputs: DEHL = pointer (0-&7FFFFF)
; Destroys: A,B,C,D,E,H,L,F
;
GETPTR: CALL FIND
LD A,(HL)
ADD A,A
DEC HL
GETPT1: DEC HL
LD D,(HL)
DEC HL
LD E,(HL)
DEC HL
LD H,(HL)
LD L,A
SRL D
RR E
RR H
RR L
RET
;
;PUTPTR - Update file pointer.
; Inputs: A = file channel
; DEHL = new pointer (0-&7FFFFF)
; Destroys: A,B,C,D,E,H,L,F
;
PUTPTR: LD D,L
ADD HL,HL
RL E
LD B,E
LD C,H
LD E,A ;CHANNEL
PUSH DE
CALL FIND
POP AF
AND 7FH
BIT 7,(HL) ;PENDING WRITE?
JR Z,PUTPT1
OR 80H
PUTPT1: LD (HL),A
PUSH DE
PUSH HL
DEC HL
DEC HL
DEC HL
LD D,(HL)
DEC HL
LD E,(HL)
EX DE,HL
OR A
SBC HL,BC
POP HL
POP DE
RET Z
INC HL
OR A
CALL M,WRITE
PUSH HL
DEC HL
DEC HL
DEC HL
LD (HL),0
DEC HL
LD (HL),B
DEC HL
LD (HL),C ;NEW RECORD NO.
POP HL
JR RDF
;
;WRRDF - Write, read; if EOF fill with zeroes.
;RDF - Read; if EOF fill with zeroes.
; Inputs: DE address FCB.
; HL addresses data buffer.
; Outputs: A=0, Z-flag set.
; Carry set if fill done (EOF)
; Destroys: A,H,L,F
;
WRRDF: CALL WRITE
RDF: CALL READ
DEC HL
RES 7,(HL)
DEC HL
LD (HL),A ;CLEAR EOF FLAG
RET Z
LD (HL),-1 ;SET EOF FLAG
INC HL
INC HL
PUSH BC
XOR A
LD B,128
FILL: LD (HL),A
INC HL
DJNZ FILL
POP BC
SCF
RET
;
;INCRDF - Increment record, read; if EOF fill.
; Inputs: DE addresses FCB.
; HL addresses data buffer.
; Outputs: A=1, Z-flag reset.
; Carry set if fill done (EOF)
; Destroys: A,H,L,F
;
INCRDF: CALL INCSEC
CALL RDF
INC A
RET
;
;READ - Read a record from a disk file.
; Inputs: DE addresses FCB.
; HL = address to store data.
; Outputs: A<>0 & Z-flag reset indicates EOF.
; Carry = 0
; Destroys: A,F
;
;BDOS1 - CP/M BDOS call.
; Inputs: A = function number
; DE = parameter
; Outputs: AF = result (carry=0)
; Destroys: A,F
;
READ: CALL SETDMA
LD A,33
BDOS1: CALL BDOS0 ;*
JR NZ,CPMERR ;*
OR A ;*
RET ;*
CPMERR: LD A,255 ;* CP/M 3
CALL EXTERR ;* BDOS ERROR
DEFM "CP/M Error" ;*
DEFB 0 ;*
;
BDOS0: PUSH BC
PUSH DE
PUSH HL
PUSH IX
PUSH IY
LD C,A
CALL BDOS
INC H ;* TEST H
DEC H ;* CP/M 3 ONLY
POP IY
POP IX
POP HL
POP DE
POP BC
RET
;
;WRITE - Write a record to a disk file.
; Inputs: DE addresses FCB.
; HL = address to get data.
; Destroys: A,F
;
WRITE: CALL SETDMA
LD A,40
CALL BDOS1
JR Z,INCSEC
LD A,198
CALL EXTERR
DEFM "Disk full"
DEFB 0
;
;INCSEC - Increment random record number.
; Inputs: DE addresses FCB.
; Destroys: F
;
INCSEC: PUSH HL
LD HL,33
ADD HL,DE
INCS1: INC (HL)
INC HL
JR Z,INCS1
POP HL
RET
;
;OPEN - Open a file for access.
; Inputs: FCB set up.
; Outputs: DE = FCB
; A=0 & Z-flag set indicates Not Found.
; Carry = 0
; Destroys: A,D,E,F
;
OPEN: LD DE,FCB
LD A,15
CALL BDOS1
INC A
RET
;
;CREATE - Create a disk file for writing.
; Inputs: FCB set up.
; Outputs: DE = FCB
; A=0 & Z-flag set indicates directory full.
; Carry = 0
; Destroys: A,D,E,F
;
CREATE: CALL CHKAMB
LD DE,FCB
LD A,19
CALL BDOS1 ;DELETE
LD A,22
CALL BDOS1 ;MAKE
INC A
RET
;
;CHKAMB - Check for ambiguous filename.
; Destroys: A,D,E,F
;
CHKAMB: PUSH BC
LD DE,FCB
LD B,12
CHKAM1: LD A,(DE)
CP '?'
JR Z,AMBIG ;AMBIGUOUS
INC DE
DJNZ CHKAM1
POP BC
RET
AMBIG: LD A,204
CALL EXTERR
DEFM "Bad name"
DEFB 0
;
;SETDMA - Set "DMA" address.
; Inputs: HL = address
; Destroys: A,F
;
SETDMA: LD A,26
EX DE,HL
CALL BDOS0
EX DE,HL
RET
;
;FIND - Find file parameters from channel.
; Inputs: E = channel
; Outputs: DE addresses FCB
; HL addresses pointer byte (FCB+37)
; Destroys: A,D,E,H,L,F
;
FIND: CALL FIND1
LD HL,37
ADD HL,DE
RET NZ
LD A,222
CALL EXTERR
DEFM "Channel"
DEFB 0
;
;FIND1 - Look up file table.
; Inputs: E = channel
; Outputs: Z-flag set = file not opened
; If NZ, DE addresses FCB
; HL points into table
; Destroys: A,D,E,H,L,F
;
FIND1: LD A,E
AND 7
ADD A,A
LD E,A
LD D,0
LD HL,TABLE
ADD HL,DE
LD E,(HL)
INC HL
LD D,(HL)
LD A,D
OR E
RET
;
;SETUP - Set up File Control Block.
; Inputs: HL addresses filename
; Format [A:]FILENAME[.EXT]
; Device defaults to current drive
; Extension defaults to .BBC
; A = fill character
; Outputs: HL updated
; A = terminator
; BC = 128
; Destroys: A,B,C,H,L,F
;
;FCB FORMAT (36 BYTES TOTAL):
; 0 0=SAME DISK, 1=DISK A, 2=DISK B (ETC.)
; 1-8 FILENAME, PADDED WITH SPACES
; 9-11 EXTENSION, PADDED WITH SPACES
; 12 CURRENT EXTENT, SET TO ZERO
; 32-35 CLEARED TO ZERO
;
SETUP0: LD A,' '
SETUP: PUSH DE
PUSH HL
LD DE,FCB+9
LD HL,BBC
LD BC,3
LDIR
LD HL,FCB+32
LD B,4
SETUP1: LD (HL),C
INC HL
DJNZ SETUP1
POP HL
LD C,A
XOR A
LD (DE),A
POP DE
CALL SKIPSP
CP '"'
JR NZ,SETUP2
INC HL
CALL SKIPSP
CALL SETUP2
CP '"'
INC HL
JR Z,SKIPSP
BADSTR: LD A,253
CALL EXTERR
DEFM "Bad string"
DEFB 0
;
PARSE: LD A,(HL)
INC HL
CP '`'
RET NC
CP '?'
RET C
XOR 40H
RET
;
SETUP2: PUSH DE
INC HL
LD A,(HL)
CP ':'
DEC HL
LD A,B
JR NZ,DEVICE
LD A,(HL) ;DRIVE
AND 31
INC HL
INC HL
DEVICE: LD DE,FCB
LD (DE),A
INC DE
LD B,8
COPYF: LD A,(HL)
CP '.'
JR Z,COPYF1
CP ' '
JR Z,COPYF1
CP CR
JR Z,COPYF1
CP '='
JR Z,COPYF1
CP '"'
JR Z,COPYF1
LD C,'?'
CP '*'
JR Z,COPYF1
LD C,' '
INC HL
CP '|'
JR NZ,COPYF2
CALL PARSE
JR COPYF0
COPYF1: LD A,C
COPYF2: CALL UPPRC
COPYF0: LD (DE),A
INC DE
DJNZ COPYF
COPYF3: LD A,(HL)
INC HL
CP '*'
JR Z,COPYF3
CP '.'
LD BC,3*256+' '
LD DE,FCB+9
JR Z,COPYF
DEC HL
POP DE
LD BC,128
SKIPSP: LD A,(HL)
CP ' '
RET NZ
INC HL
JR SKIPSP
;
BBC: DEFM "BBC"
;
;HEX - Read a hex string and convert to binary.
; Inputs: HL = text pointer
; Outputs: HL = updated text pointer
; DE = value
; A = terminator (spaces skipped)
; Destroys: A,D,E,H,L,F
;
HEX: LD DE,0 ;INITIALISE
CALL SKIPSP
HEX1: LD A,(HL)
CALL UPPRC
CP '0'
JR C,SKIPSP
CP '9'+1
JR C,HEX2
CP 'A'
JR C,SKIPSP
CP 'F'+1
JR NC,SKIPSP
SUB 7
HEX2: AND 0FH
EX DE,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL
EX DE,HL
OR E
LD E,A
INC HL
JR HEX1
;
;OSCLI - Process an "operating system" command
;
OSCLI: CALL SKIPSP
CP CR
RET Z
CP '|'
RET Z
CP '.'
JP Z,DOT ;*.
EX DE,HL
LD HL,COMDS
OSCLI0: LD A,(DE)
CALL UPPRC
CP (HL)
JR Z,OSCLI2
JR C,HUH
OSCLI1: BIT 7,(HL)
INC HL
JR Z,OSCLI1
INC HL
INC HL
JR OSCLI0
;
OSCLI2: PUSH DE
OSCLI3: INC DE
INC HL
LD A,(DE)
CALL UPPRC
CP '.' ;ABBREVIATED?
JR Z,OSCLI4
XOR (HL)
JR Z,OSCLI3
CP 80H
JR Z,OSCLI4
POP DE
JR OSCLI1
;
OSCLI4: POP AF
INC DE
OSCLI5: BIT 7,(HL)
INC HL
JR Z,OSCLI5
LD A,(HL)
INC HL
LD H,(HL)
LD L,A
PUSH HL
EX DE,HL
JP SKIPSP
;
;
ERA: CALL SETUP0 ;*ERA, *ERASE
LD C,19
JR XEQ ;"DELETE"
;
RES: LD C,13 ;*RESET
JR XEQ ;"RESET"
;
DRV: CALL SETUP0 ;*DRIVE
LD A,(FCB)
DEC A
JP M,HUH
LD E,A
LD C,14
JR XEQ0
;
REN: CALL SETUP0 ;*REN, *RENAME
CP '='
JR NZ,HUH
INC HL ;SKIP "="
PUSH HL
CALL EXISTS
LD HL,FCB
LD DE,FCB+16
LD BC,12
LDIR
POP HL
CALL SETUP0
CALL CHKAMB
LD C,23
XEQ: LD DE,FCB
XEQ0: LD A,(HL)
CP CR
JR NZ,HUH
BDC: LD A,C
CALL BDOS1
RET P
HUH: LD A,254
CALL EXTERR
DEFM "Bad command"
DEFB 0
;
EXISTS: LD HL,DSKBUF
CALL SETDMA
LD DE,FCB
LD A,17
CALL BDOS1 ;SEARCH
INC A
RET Z
LD A,196
CALL EXTERR
DEFM "File exists"
DEFB 0
;
SAVLOD: CALL SETUP0 ;PART OF *SAVE, *LOAD
CALL HEX
CP '+'
PUSH AF
PUSH DE
JR NZ,SAVLO1
INC HL
SAVLO1: CALL HEX
CP CR
JR NZ,HUH
EX DE,HL
POP DE
POP AF
RET Z
OR A
SBC HL,DE
RET NZ
JR HUH
;
DOT: INC HL
DIR: LD A,'?' ;*DIR
CALL SETUP
CP CR
JR NZ,HUH
LD C,17
DIR0: LD B,4
DIR1: CALL LTRAP
LD DE,FCB
LD HL,DSKBUF
CALL SETDMA
LD A,C
CALL BDOS1 ;SEARCH DIRECTORY
JP M,CRLF
RRCA
RRCA
RRCA
AND 60H
LD E,A
LD D,0
LD HL,DSKBUF+1
ADD HL,DE
PUSH HL
LD DE,8 ;**
ADD HL,DE
LD E,(HL) ;**
INC HL ;**
BIT 7,(HL) ;SYSTEM FILE?
POP HL
LD C,18
JR NZ,DIR1
PUSH BC
LD A,(FCB)
DEC A
LD C,25
CALL M,BDC
ADD A,'A'
CALL OSWRCH
LD B,8
LD A,' ' ;**
BIT 7,E ;** READ ONLY?
JR Z,DIR3 ;**
LD A,'*' ;**
DIR3: CALL CPTEXT
LD B,3
LD A,' ' ;**
CALL SPTEXT
POP BC
DJNZ DIR2
CALL CRLF
JR DIR0
;
DIR2: PUSH BC
LD B,5
PAD: LD A,' '
CALL OSWRCH
DJNZ PAD
POP BC
JR DIR1
;
OPT: CALL HEX ;*OPT
LD A,E
AND 3
SETOPT: LD (OPTVAL),A
RET
;
RESET: XOR A
JR SETOPT
;
EXEC: LD A,00000001B ;*EXEC
DEFB 1 ;SKIP 2 BYTES (LD BC)
SPOOL: LD A,00000010B ;*SPOOL
PUSH AF
PUSH HL
CALL SESHUT ;STOP SPOOL/EXEC
POP HL
POP BC
LD A,(HL)
CP CR ;JUST SHUT?
RET Z
LD A,(FLAGS)
OR B
LD (FLAGS),A ;SPOOL/EXEC FLAG
RRA ;CARRY=1 FOR EXEC
CALL OPENIT ;OPEN SPOOL/EXEC FILE
RET Z ;DIR FULL / NOT FOUND
POP IX ;RETURN ADDRESS
LD HL,(HIMEM)
OR A
SBC HL,SP ;SP=HIMEM?
ADD HL,SP
JR NZ,JPIX ;ABORT
LD BC,-FCBSIZ
ADD HL,BC ;HL=HL-FCBSIZ
LD (HIMEM),HL ;NEW HIMEM
LD (TABLE),HL ;FCB/BUFFER
LD SP,HL ;NEW SP
EX DE,HL
CALL OPEN3 ;FINISH OPEN OPERATION
JPIX: JP (IX) ;"RETURN"
;
UPPRC: AND 7FH
CP '`'
RET C
AND 5FH ;CONVERT TO UPPER CASE
RET
;
;*ESC COMMAND
;
ESCCTL: LD A,(HL)
CALL UPPRC ;**
CP 'O'
JR NZ,ESCC1
INC HL
ESCC1: CALL HEX
LD A,E
OR A
LD HL,FLAGS
RES 6,(HL) ;ENABLE ESCAPE
RET Z
SET 6,(HL) ;DISABLE ESCAPE
RET
;
;
COMDS: DEFM "BY"
DEFB 'E'+80H
DEFW BYE
DEFM "CP"
DEFB 'M'+80H
DEFW BYE
DEFM "DI"
DEFB 'R'+80H
DEFW DIR
DEFM "DRIV"
DEFB 'E'+80H
DEFW DRV
DEFM "ERAS"
DEFB 'E'+80H
DEFW ERA
DEFM "ER"
DEFB 'A'+80H
DEFW ERA
DEFM "ES"
DEFB 'C'+80H
DEFW ESCCTL
DEFM "EXE"
DEFB 'C'+80H
DEFW EXEC
DEFM "LOA"