forked from z80playground/cpm-fat
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ccp.asm
1459 lines (1410 loc) · 32.4 KB
/
ccp.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
;**************************************************************
;*
;* C P / M version 2.2
;*
;* Reconstructed from memory image on February 27, 1981
;*
;* by Clark A. Calkins
;*
;* This file contains just the CCP and has slight
;* modifications by John Squires.
;* It assembles to less than 3k in size.
;* It is designed to be used on the Z80 Playground.
;* See 8bitStack.co.uk for more details.
;*
;**************************************************************
;
; Set memory limit here. This is the amount of contiguous
; ram starting from 0000. CP/M will reside at the end of this space.
;
include "locations.asm"
; Set origin for CP/M
ORG CCP_START
IOBYTE EQU 3 ;i/o definition byte.
TDRIVE EQU 4 ;current drive name and user number.
ENTRY EQU 5 ;entry point for the cp/m bdos.
TFCB EQU 5CH ;default file control block.
TBUFF EQU 80H ;i/o buffer and command line storage.
TBASE EQU 100H ;transient program storage area.
;
; Set control character equates.
;
CNTRLC EQU 3 ;control-c
CNTRLE EQU 05H ;control-e
BS EQU 08H ;backspace
TAB EQU 09H ;tab
LF EQU 0AH ;line feed
FF EQU 0CH ;form feed
CR EQU 0DH ;carriage return
CNTRLP EQU 10H ;control-p
CNTRLR EQU 12H ;control-r
CNTRLS EQU 13H ;control-s
CNTRLU EQU 15H ;control-u
CNTRLX EQU 18H ;control-x
CNTRLZ EQU 1AH ;control-z (end-of-file mark)
DEL EQU 7FH ;rubout
;
;**************************************************************
;
; THIS IS THE START OF THE CCP
;
;**************************************************************
;
CBASE:
JP COMMAND ;execute command processor (ccp).
JP CLEARBUF ;entry to empty input buffer before starting ccp.
;
; Standard cp/m ccp input buffer. Format is (max length),
; (actual length), (char #1), (char #2), (char #3), etc.
;
INBUFF: DEFB 127 ;length of input buffer.
DEFB 0 ;current length of contents.
DEFB 'Copyright'
DEFB ' 1979 (c) by Digital Research '
DEFB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DEFB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DEFB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DEFB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
INPOINT:DEFW INBUFF+2 ;input line pointer
NAMEPNT:DEFW 0 ;input line pointer used for error message. Points to
; ;start of name in error.
;
; Routine to print (A) on the console. All registers used.
;
PRINT: LD E,A ;setup bdos call.
LD C,2
JP ENTRY
;
; Routine to print (A) on the console and to save (BC).
;
PRINTB: PUSH BC
CALL PRINT
POP BC
RET
;
; Routine to send a carriage return, line feed combination
; to the console.
;
CRLF: LD A,CR
CALL PRINTB
LD A,LF
JP PRINTB
;
; Routine to send one space to the console and save (BC).
;
SPACE: LD A,' '
JP PRINTB
;
; Routine to print character string pointed to be (BC) on the
; console. It must terminate with a null byte.
;
PLINE: PUSH BC
CALL CRLF
POP HL
PLINE2: LD A,(HL)
OR A
RET Z
INC HL
PUSH HL
CALL PRINT
POP HL
JP PLINE2
;
; Routine to reset the disk system.
;
RESDSK: LD C,13
JP ENTRY
;
; Routine to select disk (A).
;
DSKSEL: LD E,A
LD C,14
JP ENTRY
;
; Routine to call bdos and save the return code. The zero
; flag is set on a return of 0ffh.
;
ENTRY1: CALL ENTRY
LD (RTNCODE),A ;save return code.
INC A ;set zero if 0ffh returned.
RET
;
; Routine to open a file. (DE) must point to the FCB.
;
OPEN: LD C,15
JP ENTRY1
;
; Routine to open file at (FCB).
;
; This is used either for loading-files, or for finding files for TYPE
;
OPENFCB:XOR A ;clear the record number byte at fcb+32
LD (FCB+32),A
LD DE,FCB
LD C,15
CALL ENTRY
LD (RTNCODE),A ;save return code.
INC A ;set zero if 0ffh returned.
JP NZ,OPEN_OK ;no error finding the file.
;; Open Failed - if we have no search-path configured then
;; restore our A/F and return
LD HL,SEARCH_DRIVE
LD A,(HL)
CP 0
JP Z,NO_SEARCH
;; OK we have a search drive setup, and now we should use it.
LD DE,FCB
LD (DE),A
LD C,15
CALL ENTRY
LD (RTNCODE),A ;save return code.
INC A ;set zero if 0ffh returned.
OPEN_OK:
RET
NO_SEARCH:
LD A,(RTNCODE)
INC A
RET
;
; Routine to close a file. (DE) points to FCB.
;
CLOSE: LD C,16
JP ENTRY1
;
; Routine to search for the first file with ambigueous name
; (DE).
;
SRCHFST:LD C,17
JP ENTRY1
;
; Search for the next ambigeous file name.
;
SRCHNXT:LD C,18
JP ENTRY1
;
; Search for file at (FCB).
;
SRCHFCB:LD DE,FCB
JP SRCHFST
;
; Routine to delete a file pointed to by (DE).
;
DELETE: LD C,19
JP ENTRY
;
; Routine to call the bdos and set the zero flag if a zero
; status is returned.
;
ENTRY2: CALL ENTRY
OR A ;set zero flag if appropriate.
RET
;
; Routine to read the next record from a sequential file.
; (DE) points to the FCB.
;
RDREC: LD C,20
JP ENTRY2
;
; Routine to read file at (FCB).
;
READFCB:LD DE,FCB
JP RDREC
;
; Routine to write the next record of a sequential file.
; (DE) points to the FCB.
;
WRTREC: LD C,21
JP ENTRY2
;
; Routine to create the file pointed to by (DE).
;
CREATE: LD C,22
JP ENTRY1
;
; Routine to rename the file pointed to by (DE). Note that
; the new name starts at (DE+16).
;
RENAM: LD C,23
JP ENTRY
;
; Get the current user code.
;
GETUSR: LD E,0FFH
;
; Routne to get or set the current user code.
; If (E) is FF then this is a GET, else it is a SET.
;
GETSETUC:
LD C,32
JP ENTRY
;
; Routine to set the current drive byte at (TDRIVE).
;
SETCDRV:CALL GETUSR ;get user number
ADD A,A ;and shift into the upper 4 bits.
ADD A,A
ADD A,A
ADD A,A
LD HL,CDRIVE ;now add in the current drive number.
OR (HL)
LD (TDRIVE),A ;and save.
RET
;
; Move currently active drive down to (TDRIVE).
;
MOVECD: LD A,(CDRIVE)
LD (TDRIVE),A
RET
;
; Routine to convert (A) into upper case ascii. Only letters
; are affected.
;
UPPER: CP 'a' ;check for letters in the range of 'a' to 'z'.
RET C
CP '{'
RET NC
AND 5FH ;convert it if found.
RET
;
; Routine to get a line of input. We must check to see if the
; user is in (BATCH) mode. If so, then read the input from file
; ($$$.SUB). At the end, reset to console input.
;
GETINP:
LD A,(BATCH) ;if =0, then use console input.
OR A
JP Z,GETINP1
;
; Use the submit file ($$$.sub) which is prepared by a
; SUBMIT run. It must be on drive (A) and it will be deleted
; if and error occures (like eof).
;
LD A,(CDRIVE) ;select drive 0 if need be.
OR A
LD A,0 ;always use drive A for submit.
CALL NZ,DSKSEL ;select it if required.
LD DE,BATCHFCB
CALL OPEN ;look for it.
JP Z,GETINP1 ;if not there, use normal input.
LD A,(BATCHFCB+15) ;get last record number+1.
DEC A
LD (BATCHFCB+32),A
LD DE,BATCHFCB
CALL RDREC ;read last record.
JP NZ,GETINP1 ;quit on end of file.
;
; Move this record into input buffer.
;
LD DE,INBUFF+1
LD HL,TBUFF ;data was read into buffer here.
LD B,128 ;all 128 characters may be used.
CALL HL2DE ;(HL) to (DE), (B) bytes.
LD HL,BATCHFCB+14
LD (HL),0 ;zero out the 's2' byte.
INC HL ;and decrement the record count.
DEC (HL)
LD DE,BATCHFCB ;close the batch file now.
CALL CLOSE
JP Z,GETINP1 ;quit on an error.
LD A,(CDRIVE) ;re-select previous drive if need be.
OR A
CALL NZ,DSKSEL ;don't do needless selects.
;
; Print line just read on console.
;
LD HL,INBUFF+2
CALL PLINE2
CALL CHKCON ;check console, quit on a key.
JP Z,GETINP2 ;jump if no key is pressed.
;
; Terminate the submit job on any keyboard input. Delete this
; file such that it is not re-started and jump to normal keyboard
; input section.
;
CALL DELBATCH ;delete the batch file.
JP CMMND1 ;and restart command input.
;
; Get here for normal keyboard input. Delete the submit file
; incase there was one.
;
GETINP1:CALL DELBATCH ;delete file ($$$.sub).
CALL SETCDRV ;reset active disk.
LD C,10 ;get line from console device.
LD DE,INBUFF
CALL ENTRY
CALL MOVECD ;reset current drive (again).
;
; Convert input line to upper case.
;
GETINP2:LD HL,INBUFF+1
LD B,(HL) ;(B)=character counter.
GETINP3:INC HL
LD A,B ;end of the line?
OR A
JP Z,GETINP4
LD A,(HL) ;convert to upper case.
CALL UPPER
LD (HL),A
DEC B ;adjust character count.
JP GETINP3
GETINP4:LD (HL),A ;add trailing null.
LD HL,INBUFF+2
LD (INPOINT),HL ;reset input line pointer.
RET
;
; Routine to check the console for a key pressed. The zero
; flag is set is none, else the character is returned in (A).
;
CHKCON: LD C,11 ;check console.
CALL ENTRY
OR A
RET Z ;return if nothing.
LD C,1 ;else get character.
CALL ENTRY
OR A ;clear zero flag and return.
RET
;
; Routine to get the currently active drive number.
;
GETDSK: LD C,25
JP ENTRY
;
; Set the stabdard dma address.
;
STDDMA: LD DE,TBUFF
;
; Routine to set the dma address to (DE).
;
DMASET: LD C,26
JP ENTRY
;
; Delete the batch file created by SUBMIT.
;
DELBATCH: LD HL,BATCH ;is batch active?
LD A,(HL)
OR A
RET Z
LD (HL),0 ;yes, de-activate it.
XOR A
CALL DSKSEL ;select drive 0 for sure.
LD DE,BATCHFCB ;and delete this file.
CALL DELETE
LD A,(CDRIVE) ;reset current drive.
JP DSKSEL
;
; Print back file name with a '?' to indicate a syntax error.
;
SYNERR: CALL CRLF ;end current line.
LD HL,(NAMEPNT) ;this points to name in error.
SYNERR1:LD A,(HL) ;print it until a space or null is found.
CP ' '
JP Z,SYNERR2
OR A
JP Z,SYNERR2
PUSH HL
CALL PRINT
POP HL
INC HL
JP SYNERR1
SYNERR2:LD A,'?' ;add trailing '?'.
CALL PRINT
CALL CRLF
CALL DELBATCH ;delete any batch file.
JP CMMND1 ;and restart from console input.
;
; Check character at (DE) for legal command input. Note that the
; zero flag is set if the character is a delimiter.
;
CHECK: LD A,(DE)
OR A
RET Z
CP ' ' ;control characters are not legal here.
JP C,SYNERR
RET Z ;check for valid delimiter.
CP '='
RET Z
CP '_'
RET Z
CP '.'
RET Z
CP ':'
RET Z
CP ';'
RET Z
CP '<'
RET Z
CP '>'
RET Z
RET
;
; Get the next non-blank character from (DE).
;
NONBLANK: LD A,(DE)
OR A ;string ends with a null.
RET Z
CP ' '
RET NZ
INC DE
JP NONBLANK
;
; Add (HL)=(HL)+(A)
;
ADDHL: ADD A,L
LD L,A
RET NC ;take care of any carry.
INC H
RET
;
; Convert the first name in (FCB).
;
CONVFST:LD A,0
;
; Format a file name (convert * to '?', etc.). On return,
; (A)=0 is an unambigeous name was specified. Enter with (A) equal to
; the position within the fcb for the name (either 0 or 16).
;
CONVERT:LD HL,FCB
CALL ADDHL
PUSH HL
PUSH HL
XOR A
LD (CHGDRV),A ;initialize drive change flag.
LD HL,(INPOINT) ;set (HL) as pointer into input line.
EX DE,HL
CALL NONBLANK ;get next non-blank character.
EX DE,HL
LD (NAMEPNT),HL ;save pointer here for any error message.
EX DE,HL
POP HL
LD A,(DE) ;get first character.
OR A
JP Z,CONVRT1
SBC A,'A'-1 ;might be a drive name, convert to binary.
LD B,A ;and save.
INC DE ;check next character for a ':'.
LD A,(DE)
CP ':'
JP Z,CONVRT2
DEC DE ;nope, move pointer back to the start of the line.
CONVRT1:LD A,(CDRIVE)
LD (HL),A
JP CONVRT3
CONVRT2:LD A,B
LD (CHGDRV),A ;set change in drives flag.
LD (HL),B
INC DE
;
; Convert the basic file name.
;
CONVRT3:LD B,08H
CONVRT4:CALL CHECK
JP Z,CONVRT8
INC HL
CP '*' ;note that an '*' will fill the remaining
JP NZ,CONVRT5 ;field with '?'.
LD (HL),'?'
JP CONVRT6
CONVRT5:LD (HL),A
INC DE
CONVRT6:DEC B
JP NZ,CONVRT4
CONVRT7:CALL CHECK ;get next delimiter.
JP Z,GETEXT
INC DE
JP CONVRT7
CONVRT8:INC HL ;blank fill the file name.
LD (HL),' '
DEC B
JP NZ,CONVRT8
;
; Get the extension and convert it.
;
GETEXT: LD B,03H
CP '.'
JP NZ,GETEXT5
INC DE
GETEXT1:CALL CHECK
JP Z,GETEXT5
INC HL
CP '*'
JP NZ,GETEXT2
LD (HL),'?'
JP GETEXT3
GETEXT2:LD (HL),A
INC DE
GETEXT3:DEC B
JP NZ,GETEXT1
GETEXT4:CALL CHECK
JP Z,GETEXT6
INC DE
JP GETEXT4
GETEXT5:INC HL
LD (HL),' '
DEC B
JP NZ,GETEXT5
GETEXT6:LD B,3
GETEXT7:INC HL
LD (HL),0
DEC B
JP NZ,GETEXT7
EX DE,HL
LD (INPOINT),HL ;save input line pointer.
POP HL
;
; Check to see if this is an ambigeous file name specification.
; Set the (A) register to non zero if it is.
;
LD BC,11 ;set name length.
GETEXT8:INC HL
LD A,(HL)
CP '?' ;any question marks?
JP NZ,GETEXT9
INC B ;count them.
GETEXT9:DEC C
JP NZ,GETEXT8
LD A,B
OR A
RET
;
; CP/M command table. Note commands can be either 3 or 4 characters long.
;
NUMCMDS EQU ( CMDEND - CMDTBL ) / 4 ;number of commands
CMDTBL: DEFB 'DIR '
DEFB 'ERA '
DEFB 'TYPE'
DEFB 'SAVE'
DEFB 'REN '
DEFB 'USER'
DEFB 'DU ' ; John's Disk Usage command
DEFB 'SRCH' ; Steve's search-path command
DEFB 'CLS ' ; Steve's CLS command
CMDEND:
;
;
; Search the command table for a match with what has just
; been entered. If a match is found, then we jump to the
; proper section. Else jump to (UNKNOWN).
; On return, the (C) register is set to the command number
; that matched (or NUMCMDS+1 if no match).
;
SEARCH: LD HL,CMDTBL
LD C,0
SEARCH1:LD A,C
CP NUMCMDS ;this commands exists.
RET NC
LD DE,FCB+1 ;check this one.
LD B,4 ;max command length.
SEARCH2:LD A,(DE)
CP (HL)
JP NZ,SEARCH3 ;not a match.
INC DE
INC HL
DEC B
JP NZ,SEARCH2
LD A,(DE) ;allow a 3 character command to match.
CP ' '
JP NZ,SEARCH4
LD A,C ;set return register for this command.
RET
SEARCH3:INC HL
DEC B
JP NZ,SEARCH3
SEARCH4:INC C
JP SEARCH1
;
; Set the input buffer to empty and then start the command
; processor (ccp).
;
CLEARBUF:
XOR A
LD (INBUFF+1),A ;second byte is actual length.
;
;**************************************************************
;*
;*
;* C C P - C o n s o l e C o m m a n d P r o c e s s o r
;*
;**************************************************************
;*
COMMAND:
LD SP,CCPSTACK ;setup stack area.
PUSH BC ;note that (C) should be equal to:
LD A,C ;(uuuudddd) where 'uuuu' is the user number
RRA ;and 'dddd' is the drive number.
RRA
RRA
RRA
AND 0FH ;isolate the user number.
LD E,A
CALL GETSETUC ;and set it.
CALL RESDSK ;reset the disk system.
LD (BATCH),A ;set/clear batch mode flag.
POP BC
LD A,C
AND 0FH ;isolate the drive number.
LD (CDRIVE),A ;and save.
CALL DSKSEL ;...and select.
LD A,(INBUFF+1)
OR A ;anything in input buffer already?
JP NZ,CMMND2 ;yes, we just process it.
;
; Entry point to get a command line from the console.
;
CMMND1: LD SP,CCPSTACK ;set stack straight.
CALL CRLF ;start a new line on the screen.
CALL GETDSK ;get current drive.
ADD A,'A'
CALL PRINT ;print current drive.
LD A,'>'
CALL PRINT ;and add prompt.
CALL GETINP ;get line from user.
;
; Process command line here.
;
CMMND2: LD DE,TBUFF
CALL DMASET ;set standard dma address.
CALL GETDSK
LD (CDRIVE),A ;set current drive.
CALL CONVFST ;convert name typed in.
CALL NZ,SYNERR ;wild cards are not allowed.
LD A,(CHGDRV) ;if a change in drives was indicated,
OR A ;then treat this as an unknown command
JP NZ,UNKNOWN ;which gets executed.
CALL SEARCH ;else search command table for a match.
;
; Note that an unknown command returns
; with (A) pointing to the last address
; in our table which is (UNKNOWN).
;
LD HL,CMDADR ;now, look thru our address table for command (A).
LD E,A ;set (DE) to command number.
LD D,0
ADD HL,DE
ADD HL,DE ;(HL)=(CMDADR)+2*(command number).
LD A,(HL) ;now pick out this address.
INC HL
LD H,(HL)
LD L,A
JP (HL) ;now execute it.
;
; CP/M command address table.
;
CMDADR: DEFW DIRECT,ERASE,TYPE,SAVE
DEFW RENAME,USER,DU_COMMAND,SEARCH_COMMAND,CLS_COMMAND,UNKNOWN
;
; Halt the system. Reason for this is unknown at present.
;
HALTX: LD HL,76F3H ;'DI HLT' instructions.
LD (CBASE),HL
LD HL,CBASE
JP (HL)
;
; Read error while TYPEing a file.
;
RDERROR:LD BC,RDERR
JP PLINE
RDERR: DEFB 'Read error',0
;
; Required file was not located.
;
NONE: LD BC,NOFILE
JP PLINE
NOFILE: DEFB 'No file',0
;
; Decode a command of the form 'A>filename number{ filename}.
; Note that a drive specifier is not allowed on the first file
; name. On return, the number is in register (A). Any error
; causes 'filename?' to be printed and the command is aborted.
;
DECODE: CALL CONVFST ;convert filename.
LD A,(CHGDRV) ;do not allow a drive to be specified.
OR A
JP NZ,SYNERR
LD HL,FCB+1 ;convert number now.
LD BC,11 ;(B)=sum register, (C)=max digit count.
DECODE1:LD A,(HL)
CP ' ' ;a space terminates the numeral.
JP Z,DECODE3
INC HL
SUB '0' ;make binary from ascii.
CP 10 ;legal digit?
JP NC,SYNERR
LD D,A ;yes, save it in (D).
LD A,B ;compute (B)=(B)*10 and check for overflow.
AND 0E0H
JP NZ,SYNERR
LD A,B
RLCA
RLCA
RLCA ;(A)=(B)*8
ADD A,B ;.......*9
JP C,SYNERR
ADD A,B ;.......*10
JP C,SYNERR
ADD A,D ;add in new digit now.
DECODE2:JP C,SYNERR
LD B,A ;and save result.
DEC C ;only look at 11 digits.
JP NZ,DECODE1
RET
DECODE3:LD A,(HL) ;spaces must follow (why?).
CP ' '
JP NZ,SYNERR
INC HL
DECODE4:DEC C
JP NZ,DECODE3
LD A,B ;set (A)=the numeric value entered.
RET
;
; Move 3 bytes from (HL) to (DE). Note that there is only
; one reference to this at (A2D5h).
;
MOVE3: LD B,3
;
; Move (B) bytes from (HL) to (DE).
;
HL2DE: LD A,(HL)
LD (DE),A
INC HL
INC DE
DEC B
JP NZ,HL2DE
RET
;
; Compute (HL)=(TBUFF)+(A)+(C) and get the byte that's here.
;
EXTRACT:LD HL,TBUFF
ADD A,C
CALL ADDHL
LD A,(HL)
RET
;
; Check drive specified. If it means a change, then the new
; drive will be selected. In any case, the drive byte of the
; fcb will be set to null (means use current drive).
;
DSELECT:XOR A ;null out first byte of fcb.
LD (FCB),A
LD A,(CHGDRV) ;a drive change indicated?
OR A
RET Z
DEC A ;yes, is it the same as the current drive?
LD HL,CDRIVE
CP (HL)
RET Z
JP DSKSEL ;no. Select it then.
;
; Check the drive selection and reset it to the previous
; drive if it was changed for the preceeding command.
;
RESETDR:LD A,(CHGDRV) ;drive change indicated?
OR A
RET Z
DEC A ;yes, was it a different drive?
LD HL,CDRIVE
CP (HL)
RET Z
LD A,(CDRIVE) ;yes, re-select our old drive.
JP DSKSEL
;
;**************************************************************
;*
;* D I R E C T O R Y C O M M A N D
;*
;**************************************************************
;
DIRECT:
CALL CONVFST ;convert file name.
CALL DSELECT ;select indicated drive.
LD HL,FCB+1 ;was any file indicated?
LD A,(HL)
CP ' '
JP NZ,DIRECT2
LD B,11 ;no. Fill field with '?' - same as *.*.
DIRECT1:LD (HL),'?'
INC HL
DEC B
JP NZ,DIRECT1
DIRECT2:LD E,0 ;set initial cursor position.
PUSH DE
CALL SRCHFCB ;get first file name.
CALL Z,NONE ;none found at all?
DIRECT3:
JP Z,DIRECT9 ;terminate if no more names.
LD A,(RTNCODE) ;get file's position in segment (0-3).
RRCA
RRCA
RRCA
AND 60H ;(A)=position*32
LD C,A
LD A,10
CALL EXTRACT ;extract the tenth entry in fcb.
RLA ;check system file status bit.
JP C,DIRECT8 ;we don't list them.
POP DE
LD A,E ;bump name count.
INC E
PUSH DE
AND 03H ;at end of line?
PUSH AF
JP NZ,DIRECT4
CALL CRLF ;yes, end this line and start another.
PUSH BC
CALL GETDSK ;start line with ('A:').
POP BC
ADD A,'A'
CALL PRINTB
LD A,':'
CALL PRINTB
JP DIRECT5
DIRECT4:
CALL SPACE ;add seperator between file names.
LD A,'|' ; [JSS: Changed this from colon to pipe]
CALL PRINTB
DIRECT5:CALL SPACE
LD B,1 ;'extract' each file name character at a time.
DIRECT6:LD A,B
CALL EXTRACT
AND 7FH ;strip bit 7 (status bit).
CP ' ' ;are we at the end of the name?
JP NZ,DRECT65
POP AF ;yes, don't print spaces at the end of a line.
PUSH AF
CP 3
JP NZ,DRECT63
LD A,9 ;first check for no extension.
CALL EXTRACT
AND 7FH
CP ' '
JP Z,DIRECT7 ;don't print spaces.
DRECT63:
LD A,' ' ;else print them.
DRECT65:
CALL PRINTB
INC B ;bump to next character position.
LD A,B
CP 12 ;end of the name?
JP NC,DIRECT7
CP 9 ;nope, starting extension?
JP NZ,DIRECT6
LD A,'.' ; [JSS: Changed this from space to dot]
CALL PRINTB
JP DIRECT6
DIRECT7:
POP AF ;get the next file name.
DIRECT8:
;CALL CHKCON ;first check console, quit on anything.
;JP NZ,DIRECT9
CALL SRCHNXT ;get next name.
JP DIRECT3 ;and continue with our list.
DIRECT9:
POP DE ;restore the stack and return to command level.
JP GETBACK
;
;**************************************************************
;*
;* E R A S E C O M M A N D
;*
;**************************************************************
;
ERASE: CALL CONVFST ;convert file name.
CP 11 ;was '*.*' entered?
JP NZ,ERASE1
LD BC,YESNO ;yes, ask for confirmation.
CALL PLINE
CALL GETINP
LD HL,INBUFF+1
DEC (HL) ;must be exactly 'y'.
JP NZ,CMMND1
INC HL
LD A,(HL)
CP 'Y'
JP NZ,CMMND1
INC HL
LD (INPOINT),HL ;save input line pointer.
ERASE1: CALL DSELECT ;select desired disk.
LD DE,FCB
CALL DELETE ;delete the file.
INC A
CALL Z,NONE ;not there?
JP GETBACK ;return to command level now.
YESNO: DEFB 'All (y/n)?',0
;
;**************************************************************
;*
;* T Y P E C O M M A N D
;*
;**************************************************************
;
TYPE: CALL CONVFST ;convert file name.
JP NZ,SYNERR ;wild cards not allowed.
CALL DSELECT ;select indicated drive.
CALL OPENFCB ;open the file.
JP Z,TYPE5 ;not there?
CALL CRLF ;ok, start a new line on the screen.
LD HL,NBYTES ;initialize byte counter.
LD (HL),0FFH ;set to read first sector.
TYPE1: LD HL,NBYTES
TYPE2: LD A,(HL) ;have we written the entire sector?
CP 128
JP C,TYPE3
PUSH HL ;yes, read in the next one.
CALL READFCB
POP HL
JP NZ,TYPE4 ;end or error?
XOR A ;ok, clear byte counter.
LD (HL),A
TYPE3: INC (HL) ;count this byte.
LD HL,TBUFF ;and get the (A)th one from the buffer (TBUFF).
CALL ADDHL
LD A,(HL)
CP CNTRLZ ;end of file mark?
JP Z,GETBACK
CALL PRINT ;no, print it.
CALL CHKCON ;check console, quit if anything ready.
JP NZ,GETBACK
JP TYPE1
;
; Get here on an end of file or read error.
;
TYPE4: DEC A ;read error?
JP Z,GETBACK
CALL RDERROR ;yes, print message.
TYPE5: CALL RESETDR ;and reset proper drive
JP SYNERR ;now print file name with problem.
;
;**************************************************************
;*
;* S A V E C O M M A N D
;*
;**************************************************************
;
SAVE: CALL DECODE ;get numeric number that follows SAVE.
PUSH AF ;save number of pages to write.
CALL CONVFST ;convert file name.
JP NZ,SYNERR ;wild cards not allowed.
CALL DSELECT ;select specified drive.
LD DE,FCB ;now delete this file.
PUSH DE
CALL DELETE
POP DE