-
Notifications
You must be signed in to change notification settings - Fork 0
/
BDOS2.A99
1178 lines (1159 loc) · 31.7 KB
/
BDOS2.A99
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
;
;---------------------------------------------------------
;
; BDOS FOR THE 9900
;
; WRITTEN BY A.CAMERON
;
; DURING JULY 1983.
; 2019 BDOS IS CONFIGURED TO SHARE CALLING PROGRAMME WORKSPACE AND STACK
; THAT IS IT DOES NOT DEFINE ITS OWN STACK
;
;
;-----------------------------------------------------------
;
; DEFINE XOP FUNCTIONS
; THESE XOP ARE DEFINED IN THE MONITOR.
; BECAUSE THE XOP WORKSPACES OVERLAP,
; THEN R0 TO R7 ARE SHARED WHEN A CALL FUNCTION OCCURS.
;
;
;
;
; DEFINE SOME XOP'S DEFINED IN MONITOR
;
DXOP PUSHREG,4
DXOP POPREG,5
DXOP CALL,6
DXOP RET,7
DXOP PUSH,8
DXOP POP,9
; DXOP WHEX,10 ;WRITE OUT A 16 BIT HEX VALUE
; DXOP RHEX,11 ;READ IN A 16 BIT HEX VALUE
; DXOP WRITE,12 ;WRITE CHAR IN MSB
; DXOP READ,13 ;READ CHAR IN MSB
; DXOP MESG,14 ;OUTPUT NULL TERMINATED MESSAGE
;
; REGISTER EQUATES
;
R0 EQU 0
R1 EQU 1
R2 EQU 2
R3 EQU 3
R4 EQU 4
R5 EQU 5
R6 EQU 6
R7 EQU 7
R8 EQU 8
;
; OPERATING SYSTEM EQUATES
;
MONITOR EQU 0F000H
BDOS EQU 0D100H
; ;
AORG BDOS
;
; BDOS ENTRY POINT; BDOS IS CALLED VIA XOP CALL SO THAT
;
SLA R2,1 ;ADJUST FOR JUMP
CI R2,2*40 ;MAKE SURE IT A LEGAL VALUE
JH EXIT
MOV @FUN00(R2),R0
B *R0
;
;#define GETPOS 36 /* get number of current sector */
;#define GOCPM 00 /* go to CP/M */
;#define LSTOUT 05 /* list output */
;#define POSEND 35 /* position file to end */
;#define RDRINP 03 /* reader input */
;
; JUMP TABLE - ENTER WITH VALUE IN R3
;
FUN00 WORD BDOS0 ;WARM BOOT
FUN01 WORD CIN ;CONSOLE INPUT
FUN02 WORD COUT ;CONSOLE OUTPUT (OUTPUT LSB OF R3)
FUN03 WORD EXIT
FUN04 WORD EXIT
FUN05 WORD EXIT
FUN06 WORD DCONIO ;DIRECT CONSOLE IO
FUN07 WORD EXIT
FUN08 WORD EXIT
FUN09 WORD EXIT
FUN10 WORD EXIT
FUN11 WORD EXIT
FUN12 WORD EXIT
FUN13 WORD EXIT
FUN14 WORD DSKFUN ;SELECT A DISK
FUN15 WORD FOPEN ;OPEN A FILE
FUN16 WORD FCLOSE ;CLOSE A FILE
FUN17 WORD SEARCH1 ;LOOK FOR A FILE
FUN18 WORD SEARCH2 ;SEARCH NEXT
FUN19 WORD ERAFIL ;ERASE A FILE
FUN20 WORD RDSEQ ;READ SQUENTIAL
FUN21 WORD WRSEQ ;WRITE SQUENTIAL
FUN22 WORD MAKFIL ;MAKE A FILE
FUN23 WORD RENAME ;RENAME A FILE
FUN24 WORD EXIT
FUN25 WORD CDFUNC ;RETURN CURRENT DISK
FUN26 WORD DMAFUN ;SET DMA ADDRESS
FUN27 WORD EXIT ;
FUN28 WORD EXIT ;
FUN29 WORD EXIT ;
FUN30 WORD EXIT ;
FUN31 WORD EXIT ;
FUN32 WORD EXIT ;
FUN33 WORD RDRND ;READ A RANDOM RECORD
FUN34 WORD WRRND ;WRITE A RANDOM RECORD
FUN35 WORD GETSIZ ;GET FILE SIZE
FUN36 WORD SETREL ;SET RELATIVE RECORD
FUN37 WORD EXIT
FUN38 WORD EXIT
FUN39 WORD EXIT
FUN40 WORD EXIT
EXIT SETO R1 ;ERROR
RET
;
; BIOS EQUATES
;
;
;TEMPORARY TESTING ADDRESS TO MIMIC MONITOR BEING AT LOCATION F000
MON_PTR EQU 086H ;LOW MEMORY POINTER TO MONITOR
;
; BIOS VECTORS ARRANGED AS N*L WHERE
;
; N IS THE NTH VECTOR IN THE MONITOR, AND
; L IS THE NUMBER OF BYTES PER VECTOR
;
;MCONIN
MCONIN EQU MONITOR+2*4 ;CONSOLE IN
MCONOUT EQU MONITOR+3*4 ;CONSOLE OUT
MSELDSK EQU MONITOR+4*4 ;SET CURRENT LOGGED DRIVE
MRDREC EQU MONITOR+7*4 ;READ A STANDARD RECOR0D
MWRREC EQU MONITOR+8*4 ;WRITE A STANDARD RECORD
MRECAL EQU MONITOR+5*4
MSEEK EQU MONITOR+6*4
MRDID EQU MONITOR+9*4
MWBOOT EQU MONITOR+10*4 ;WARM BOOT
;
;************************************************************************************************************
;
; FCB EQUATES
;
; THE FCB CONSISTS OF 32 BYTES OF DATA:
; BYTES 0 TO 31 ARE AN EXACT COPY OF THE DIRECTORY
;
;
; BYTES FUNCTION
; ----- --------
; 0 -7 FILENAME
; 8 -10 FILENAME EXTENSION
; 11 FTY - FILE TYPE
; 12-13 FSB - FILE'S STARTING BLOCK
; 14-15 FSZ - FILE SIZE IN RECORDS (A RECORD IS EQUIVALENT TO A SECTOR)
; 16-17 FLA - FILE LOAD ADDRESS - USED TO DETERMINE WHERE FILE WILL LOAD
; 18-19 FSZBH - FILE SIZE IN BYTES HIGH WORD
; 20-21 FSZBL - FILE SIZE IN BYTES LOW WORD
; 22-23 SPARE COULD MAKE THIS DATE - DAYS FROM 1/1/1900)
; 24-25 CBN - FILE'S CURRENT BLOCK NUMBER
; 26-27 CRN - CURRENT RECORD NUMBER
; 28-29 RELB - RELATIVE BLOCK NUMBER
; 30-31 RELR - RELATIVE RECORD NUMBER FILE WILL LOAD.
; 32 OVERFLOW FOR RELR
; 33 DRIVE
; 34-35 LBUFCNT - NUMBER BYTES IN LAST BUFFER. ALLOWS TO MANAGE BINARY FILES SO CPMEOF IS NOT NEEDED
;
;
; DISC STRUCTURE
; [S1] [S2] [S3] [S4] [S5] [S6] [S7] [S8] <-------FILES BEGIN AT BLOCK 2
; [BOOT][BAT1][BAT2][BAT3][DIR1][DIR2][DIR3][DIR4][REC1BLK2,REC2BLK2,RECS3BLK2,REC4BLK2][REC1BLCK3...ETC]
; <-----BLOCK 0----------><-------BLOCK 1--------><-----------BLOCK 2------------------>
;
; EACH BLOCK IS 4 SECTORS OR 2048 Bytes
;
; BLOCK ALLOCATION TABLE [BAT] SECTORS ARE INITIALISED TO 0, THUS AVAILABLE BLOCKS ARE INDICATED BY THE VALUE OF 0000H.
; WITH THE LAST AVAILABLE BLOCK BEING SET TO -1 IN THE LAST BAT PAGE.
; ALLOCATED BLOCKS HAVE A NON ZERO BLOCK NUMBER POINTING TO THE NEXT BLOCK IN THE LINK AND THE FINAL BLOCK
; IN THE LINK INDICATED BY A BLOCK NUMBER VALUE OF FF80H WHICH IS A SIMPLE INVERSION OF THE FIRST 9 BITS
; WHICH ARE UNUSED.
;
; FOR EXAMPLE, BAT 1 WOULD LOOK LIKE THIS
;
; BAT 1
; BLOCK NUMBER VALUE COMMENT
;
; [ 0 FF80 ] BOOT SECTOR, PLUS BATs OCCUPY A SINGLE BLOCK (BLOCK 0)
; [ 1 FF80 ] DIRECTORY SECTORS OCCUPY A SINGLE BLOCK (BLOCK 1)
; [ 2 0003 ] POINTS TO NEXT BLOCK IN LINK. FILE IS SHELL.SYS (2 BLOCKS IN SIZE)
; [ 3 FF80 ] LAST BLOCK IN THE FILE
; [ 4 0005 ] POINTS TO NEXT BLOCK IN LINK. FILE IS BDOS.SYS (2 BLOCKS IN SIZE)
; [ 5 FF80 ] LAST BLOCK IN THE LINK
; [ 6 0007 ] TEST FILE 3 BLOCKS LONG
; [ 7 0008 ] 2ND BLOCK
; [ 8 FF80 ] LAST BLOCK IN FILE
; [ 9 0000 ]
; [ 9 0000 ]
; ETC
;
; FOR THIS REASON THE FCB MUST CONTAIN THE FILE STARTING BLOCK (FSB) SO THE START OF THE LINK
; CAN BE FOUND.
;
; BAT SECTORS ARE ORGANSIED AS FOLLOWS:
;
; BAT SECTOR 1[BLK0,BLK1,BLK2,BLK3.......BLK255]
; BAT SECTOR 2[BLK256,BLK257,BLK258,.......BLK511]
; BAT SECTOR 2[BLK512,BLK513,BLK514.....BLK719,-1]
;
;
; NOTE: CPM/TDOS OPERATES AT THE RECORD LEVEL SO THE TASK OF TDOS IS TO BE ABLE TO
; MAP BETWEEN FILE RECORDS LOCATION WITHIN A BLOCK ON THE DISC TRACK AND SECTOR NUMBER
;
; BAT SECTORS ARE ORGANSISED AS 3 BAT PAGES/SECTOR
; [PAGE3][PAGE2][PAGE1][ 0 0 0 0 0 0 0 0].
; SO THE LSB 8 BITS REPRESENT THE ACTUAL BLOCK NUMBER AND THE NEXT 3 BITS THE BAT PAGE NUMBERS
; BAT 0 = 000, BAT 1 = 001, BAT 2 = 010 AND BAT 3 = 011.
;
; SO SHIFTING THE BLOCK NUMBER BY 8 SHIFT COUNT AND APPLYING THE MASK 00FFH YIELDS THE PAGE NUMBER
; TO WHICH THE BLOCK NUMBER BELONGS.
;
;**********************************************************************************************************************
;
NAM EQU 0
FTY EQU 11 ;TYPE
FLA EQU 16 ;FILES LOAD ADDRESS
CRN EQU 26 ;NEXT RECORD TO READ/WRITE
CBN EQU 24 ;CURRENT BLOCK NUMBER
RELB EQU 28 ;RANDOM ACCESS RELATIVE BLOCK NUMBER
RELR EQU 30 ;RELATIVE RECORD NUMBER
FSB EQU 12 ;FILE STARTING BLOCK
FSZ EQU 14 ;FILE SIZE IN SECTORS
FSZBH EQU 18 ;FILE SIZE IN BYTES HIGH BYTE
FSZBL EQU 20 ;FILE SIZE IN BYTES LOW BYTE
;
; MEDIA TYPE 00FDH
;
TRKDSK EQU 80 ;TRACKS PER DISK
SECTRK EQU 18 ;SECTORS PER TRACK
BYTSEC EQU 512 ;BYTES PER SECTOR
SECBLK EQU 4 ;SECTOR PER BLOCK THIS MEANS THERE ARE 2 BAT SECTORS
; 80*18*2/SECBLK = 720 IE 2*512 SECTORS REQUIRED
RSVDSEC EQU 1 ;RESERVED SECTORS FOR BOOT SECTOR
NSIDES EQU 2 ;NUMBER OF SIDES
SECDSK EQU NSIDES*SECTRK*TRKDSK ;SECTORS ON DISK
NBATS EQU 1 ;NO OF BAT ENTRIES ie backup etc
NDSECT EQU 4 ;NO OF DIRECTORY SECTORS PER DISK
FBATSEC EQU RSVDSEC+1 ;FIRST BAT SECTOR OFFSET FROM 0
FDIRRN EQU 4 ;FIRST DIRECTORY RECORD NUMBER ()
DIRTRK EQU 0 ;DIRECTORY STARTS HERE
BATTRK EQU 0
BATSF EQU 8 ;DETERMINES THE BAT PAGE (SEE EXPLANATION ABOVE)
;BATMSK EQU 01FFH ;BASED ON BYTSEC/2 ENTRIES PER BAT PAGE - USED IN GETBATP
;BATMSK SHOULD BE 00FF
BATMSK EQU 0FFH ;BASED ON BYTSEC/2 ENTRIES PER BAT PAGE - USED IN GETBATP
LASTBLK EQU 0FF80H ;INDICATES LAST BLOCK IN A FILE
BUFSIZ EQU BYTSEC ;DISK BUFFER SIZE
;
NAMSIZ EQU 11 ;FILENAME SIZE IN BYTES
NAMEOFF2 EQU 18 ;2ND NAME OFFSET INTO FCB
DIRSIZ EQU 32 ;NO. OF BYTES PER ENTRY
RDCMD EQU 1 ;READ COMMAND
WRCMD EQU 2 ;WRITE COMMAND
MINUS1 EQU -1 ;USED FOR GENERAL ERROR
WILD BYTE '?'
ALLONES BYTE -1 ;;USED FOR GENERAL ERROR
EVEN
;
DISK WORD 0 ;CURRENTLY SELECTED DISK LS BYTE USED
CAB WORD 0 ;CURRENTLY ALLOCATED BLOCK NUMBER
CBP WORD 0 ;CURRENT BAT LOCATION POINTER
CBO WORD 0 ;CURRENT OFFSET INTO BLOCK
CBSECT WORD -1 ;CURRENT BAT SECTOR IN MEMORY
DIRENT WORD 0 ;USED IN DIRECTORY SEARCH
ADDR WORD DIRBUFF ;CURRENT DMA ADDRESS
IOPTR WORD 0 ;CURRENT IOPTR OR DMA ADDRESS FOR MONITOR
TRACK WORD 0
SECTOR WORD 0
CDSECT WORD 0 ;CURRENT DIRECTORY SECTOR
CCMD WORD 0 ;CURRENT COMMAND
;
;******************************
;
; WARM BOOT INTERCEPT
;
;*******************************
;
BDOS0 RET
CLR R0 ;CLEAR CHANGE AND WRITE FLAGS IN BM
CLR @BATCHG ;ZERO CAUSES A BATTO BE READ IN
B @MWBOOT ;CALL MONITOR
;
;*******************************
;
; CONSOLE OUTPUT
; CHAR IN R3 LSB
;********************************
;
;
COUT SWPB R3 ;MOVE CHAR TO UPPER MSB FOR MCONOUT
MOVB R3,R2 ;CHAR IN MSB OF R2
CALL @MCONOUT
RET
;
;********************************
;
; CONSOLE INPUT INTO LSB OF R1
; NOTE ALL OTHER SYSTEMS USE MSB
;
;********************************
;
CIN ;MOV @MON_PTR,R0 ;MONITOR ADDRESS
;AI R0, MCONIN ;ADD THE OFFSET INTO THE MONITOR
CALL @MCONIN ;(R0) ;INPUT CHAR IN R1
SWPB R1
RET ;RETURN CHAR IN MSB OF R1
;
;-----------------------------------
;
; DIRECT CONSOLE IO - BYPASS ANY CHARACTER
; CHECKING.
;
; IF R3 = FF00H THEN INPUT A CHAR
; IF R3 = IS LESS THAN 00FFH THEN OUTPUT THE CHAR IN MSB
;
;-----------------------------------------------------
;
DCONIO MOVB @ALLONES,R0
CB R3,R0
JEQ CIN
JMP COUT
;
;*************************
;
; SELECT A DISK
;
;*************************
;
DSKFUN MOV R3,R2 ;FOR MONITOR
MOV R3,@DISK
B @MSELDSK
;
;*************************
;
; GET CURRENT DISK
; RETURN IN MSB OF R1
;
;*************************
;
CDFUNC MOV @DISK,R1 ;FOR MONITOR
RET
;******************************
;
; BDOS SET THE DMA ADDRESS
;
;******************************
;
DMAFUN
MOV R3,@ADDR ;COPY FOR WRSEQ
MOV R3,@IOPTR
RET
;******************************
;
; MONITOR SET THE DMA ADDRESS IN R2
;
;******************************
;
_SETDMA MOV R2,@IOPTR
RET
;
;--------------------------------------------------------------------------
;
; OPEN A FILE (FUNCTION 15)
;
; R3 -> FCB
;
; THIS FUNCION TRANSFERS ALL THE FILE'S DIRECTORY DATA
; TO THE FCB. IF THE FILE IS NOT FOUND -1 IS RETURNED IN
; REGISTER R1. NOTE THAT THIS FUNCTION WILL NOT CREATE AN
; ENTRY IF ONE DOESN'T EXIST. 'MAKEFIL(FUNCTION 22) MUST
; FIRST BE CALLED, HOWEVER IF 'MAKEFIL' IS CALLED THEN
; OPEN DOES NOT NEED TO BE CALLED EXPLICITLY IN THIS
; INSTANCE.
;
;
;----------------------------------------------------------------------------
;
FOPEN: MOV R3,R8 ;COPY FCB POINTER FOR INTERNAL USE
CALL @SEARCH1 ;OPEN THE DIRECTORY
MOV R1,R1 ;SUCCESSFUL OPEN ?
JLT OPENA
MOV R8,R1
MOV R3,R2 ;DONT TOUCH DIRECTORY POINTER
AI R1,NAMSIZ ;POINT TO FDE
AI R2,NAMSIZ ;R2 -> DIRECTORY ENTRY
LI R0,DIRSIZ-NAMSIZ ;NO OF BYTES TO TRANSFER
OPENB: MOVB *R2+,*R1+ ;TRANSFER ENTRIES
DEC R0
JNE OPENB
;
; 'MAKFIL' ENTERS HERE ALSO
;
OPENENT: CLR R1
MOV R1,@CBN(R8) ;ZERO CURRENT BLOCK FIELD
MOV R1,@CRN(R8)
MOV R1,@RELR(R8)
MOV R1,@RELB(R8)
MOV R1,@FSZBH(R8)
MOV R1,@FSZBL(R8)
RET
OPENA: SETO R1
RET
;
;******************************
;
; CLOSE A FILE (FUNCTION 16)
;
; R3 -> FCB
;
; SIMILAR TO OPEN FUNCTION EXCEPT THAT THE FILE SHOULD
; HAVE BEEN PREVIOUSLY EITHER OPENED USING 'OPEN' OR
; CREATED USING 'MAKFIL'. ANY OTHER METHOD OF CALLING
; WILL TRANSFER JUNK TO THE DIRECTORY - NOT A PLEASANT
; THOUGHT.
;
; CLOSE ALSO ZERO'S THE CRN & CBN WORDS SO THAT OPEN DOES
; NOT HAVE TO INITIALISE THESE TWO VALUES.
;
;******************************
;
FCLOSE: MOV R3,R8 ;COPY FCB POINTER
CALL @SEARCH1 ;MAKE SURE IT'S HERE
MOV R1,R1 ;ERROR ?
JLT CLOSEB ;YES
MOV R8,R1 ;FCB POINTER
MOV R3,R2 ;DONT TOUCH R3
AI R1,NAMSIZ ;ENTRY DATA POINTER
AI R2,NAMSIZ ;DIR ENTRY POINTER
LI R0,DIRSIZ-NAMSIZ
FCLOSE1: MOVB *R1+,*R2+ ;UPDATE DIRECTORY ENTRY
DEC R0
JNE FCLOSE1
;
; UPDATE DIRECTORY ENTRY
;
CALL @WRREC ;ALL POINTERS ARE UNTOUCHED FROM SEARCH1
CALL @RECLAIM ;TRY TO RECLAIM UNUSED BLOCKS
CLOSEB RET
;
;***************************************************
;
; WRITE SEQUENTIALLY (FUNCTION 21)
;
; R3 -> FCB
;
; THIS FUNCTION IS CONTROLLED MAINLY BY
; THE CRN (NEXT RECORD TO READ) COUNTER.
;
;
;*****************************************************
;
WRSEQ:
MOV R3,R8 ;SAVE FCB POINTER
CALL @CRNTBC ;CRN TO RELATIVE BLOCK & REMAINDER
MOV R3,@CBO ;SAVE OFFSET
;
; IF WE COULD TRACE FROM EXISTING POSITION WE COULD SPEED THINGS UP AND STOP THRASHING
; TRACE1 WILL USE CRN
;
MOV R2,R3 ;UPDATE
CALL @TRACE
C R1,R2 ;IF ALLOCATED CONTINUE
JEQ WRSEQ0
;
; AT THIS POINT WE HAVE THE CBP FROM TRACE
; NXTBLK WILL FIND A BLOCK AND ALLOCATE IT (LINK)
; BASED ON CBP
;
CALL @NXTBLK ;LOCATE A BLOCK AND RETURN IN R7
MOV R1,R1 ;ANY BLOCKS LEFT ?
JLT WRSEQ1 ;NO - SHOW ERROR
;
; IN CASE WE CROSS BAT BOUNDARIES WE NEED TO ALLOCATE LAST BLOCK FIRST
; AND THEN POSTFIX THE CAB FOUND IN TRACE. TRACE HAS FILLED THE CBP AND
; CAB WHICH NEED TO BE UPDATED. R7 IS THE CURRENT BLOCK POINTER AND
; R6 CONTAINS THE FREE BLOCK NUMBER
;
LI R1,LASTBLK ;ALLOCATE THIS BLOCK TO THIS FILE
MOV R1,*R7 ;NEW END OF LINK IN CURRENT BAT FROM NXTBLK
MOV R7,@CBP ;AND KEEP CBP UPDATED
SETO @BATCHG ;FORCE AN UPDATE TO THE BAT
PUSH R6 ;PUSH NEW ALLOCATED BLOCK CAB
;
; NOW UPDATE PREVIOUS LAST BLOCK TO POINT NOW TO THE NEW LAST BLOCK
;
MOV @CAB,R3 ;GET PREVIOUS LAST BLOCK RETURNED FROM TRACE
CALL @GETBATP ;FIND THE BAT AND GET THE POINTER FROM THE INDEX
POP R6
MOV R6,*R7 ;UPDATE TO NEW END OF LINK
MOV R6,@CAB ;UPDATED FROM NXTBLK
SETO @BATCHG ;FORCE AN UPDATE TO THE BAT
;
WRSEQ0 MOV @CAB,R2 ;RECOVER DISK BLOCK
MOV @CBO,R3 ;AND OFFSET
LI R0,WRCMD
MOV R0,@CCMD ;CURRENT COMMAND
CALL @RWREC
MOV R1,R1
JLT WRSEQ1
INC @FSZ(R8) ;BUMP THE SECTOR COUNT
INC @CRN(R8) ;BUMP CURRENT RECORD
CLR R1
WRSEQ1 RET
;
;********************************
;
; READ SEQUENTIALLY
; R3 -> FCB
;
;********************************
;
RDSEQ: MOV R3,R8 ;COPY ADDRESS OF FCB
C @CRN(R8),@FSZ(R8) ;END OF FILE ?
JHE RDSEQ1 ;YES
CALL @CRNTBC ;CONVERT CRN TO A RELATIVE BLOCK NUMBER
MOV R3,@CBO ;SAVE OFFSET AND USE BLOCK IN R2 TO
CALL @TRACE ;TRACE THROUGH THE LINKED ALLOCATION LIST
MOV @CBO,R3 ;RECOVER VARIABLES FOR RWREC
MOV @CAB,R2
LI R0,RDCMD
MOV R0,@CCMD ;CURRENT COMMAND
CALL @RWREC
INC @CRN(R8) ;BUMP TO NEXT RECORD
CLR R1
RET
RDSEQ1 SETO R1
RET
;
;*******************************
;
; READ RANDOM RECORD
;
;********************************
;
RDRND: MOV @RELB(R3),@CBN(R3) ;TRANSER RECORD NUMBER
MOV @RELR(R3),@CRN(R3)
CALL @RDSEQ
DEC @CRN(R8) ;READ RANDOM CAN'T INCREMENT THE CRN
RET
;
;*******************************
;
; WRITE RANDOM RECORD
; R3 -> FCB
; (R3)RELR MUST HOLD THE RECORD TO WRITE TO
;
;*******************************
;
WRRND: MOV @RELB(R3),@CBN(R3) ;TRANSEFER RECORD NUMBER
MOV @RELR(R3),@CRN(R3)
JMP WRSEQ ;NORMAL SEQUENTIAL WRITE
;
;*******************************
;
; COMMON READ WRITE ENTRY
;
; R8 --> FCB
; R2 = DISK BLOCK
; R3 = RECORD OFFSET
;*******************************
;
RWREC: MOV R2,R1 ;BLOCK TO CONVERT
CALL @BTTSC ;CONVERT BLOCK TO TRK/SECT(R2/R3)
CALL @SETTRK ;R2 HOLDS TRACK
MOV R3,@SECTOR ;SET THE SECTOR USE
MOV @ADDR,R2 ;THIS IS THE LOCAL COPY OF DMA ADDR
CALL @_SETDMA ;CAUGHT WITH CALLS THROUGH DMAFUN VALUE IN R4 FOR MONITOR
MOV @CCMD,R0 ;GET TYPE
CI R0,WRCMD ;READ ?
JNE RWREC_R ;TRY FOR WRITE
B @WRREC ;RETURN FROM RDREC
RWREC_R: B @RDREC ;ASSSUME READ
;
;***************************************************************
;
; SEARCH FIRST( LOOK FOR DIRECTORY ENTRY)
;
; NORMAL DIRECTORY SEARCH BEGINNING AT THE
; START OF THE DIRECTORY CONTINUING TILL END.
;
; E5 => DELETED ENTRY
; 00 => END OF DIRECTORY
; R3 -> FCB
;
; RETURN
; R1 = MINUS ONE FOR BAD RESULT
; R3 -> CURRENT DIRECTORY ENTRY
;
;***************************************************************
;
SEARCH1:
MOV R3,R8 ;SAVE FCB FOR DIROPN
SETO @DIRENT ;SET CURRENT SECTOR DIRECTORY INDEX
CLR @CDSECT ;BEGIN SEARCHING AT FIRST SECTOR
CALL @DIROPN ;OPEN THE DIRECTORY
JMP DLOOK ;RETURN FROM DLOOK
;
;***************************************************************
;
; SEARCH NEXT (SEARCH2)
;
; SIMILAR TO CPM - BASICALLY CONTINUES
; WHERE LAST SEARCH LEFT OFF. THAT IS IT
; SIMPLY DOES NOT ALTER THE VALUE OF THE
; DIRENT AND CDSECT VARIABLES.
;
;**************************************************************
;
SEARCH2: MOV R3,R8
CALL @DIROPN ;OPEN THE DIRECTORY
JMP DLOOK
;
;-------------------------------------------------
;
; FUCTION 35 - GET FILE SIZE
;
; R2 = FUNCTION NUMBER
; R3 -> FCB
;
; PURPOSE - MOVE THE ADDRESS OF THE LAST RECORD
; TO THE RELATIVE FIELDS
;
;-------------------------------------------------
;
GETSIZ: MOV R3,R8 ;COPY FCB POINTER FOR INTERNAL USE
CALL @SEARCH1 ;OPEN THE DIRECTORY
MOV R1,R1 ;SUCCESSFUL OPEN ?
JLT GETSIZ1
MOV @FSZ(R8),@RELR(R8) ;TRANSFER THE FILE SIZE
GETSIZ1: RET
;
;--------------------------------------------------
;
; FUCTION 36 - SET RELATIVE RECORD
; R2 = FUNCTION NUMBER
; R3 -> FCB
;
; PURPOSE - THE RELATIVE RECORD FIELD IS SET TO THE
; SAME FILE ADDRESS AS THE CURRENT BLOCK AND
; CURRENT RECORD.
;
;---------------------------------------------------
;
SETREL: MOV @CBN(R3),@RELB(R3) ;TRANSFER RECORD POINTERS
MOV @CRN(R3),@RELR(R3)
RET
;
;*****************************************
;
; GENERAL DIRECTORY SEARCH SUBROUTINE
; R8 = PTR TO FCB
; MUST CHECK FILE ATTRIBUTES FOR FILE TYPE
;
;******************************************
;
DLOOK: CALL @DIRBLK ;GET NEXT ENTRY PNTR IN R3
JLT NONTRY ;NOT FOUND
DLOOK1 MOV R3,R2 ;SAVE PNTR
MOVB *R2,R0 ;TEST FOR EOD
JLT DLOOK ;DELETED ENTRY
JGT DLOOK4 ;VALID
CLR R3 ;SHOW END OF DIRECTORY REACHED
JMP NONTRY
DLOOK4 LI R0,NAMSIZ ;NUMBER OF CHARS TO MATCH
MOV R8,R5 ;SAVE FCB PNTR
NXTLTR CB *R5,@WILD ;? WILL MATCH ALL (LIKE CPM)
JNE DLOOK5 ;PROCESS NORMALLY
INC R5 ;ELSE ASSUME MATCH SO BUMP POINTERS
INC R2
JMP DLOOK6
DLOOK5 CB *R2+,*R5+ ;MATCH ?
JNE DLOOK ;NO SO - KEEP LOOKING
DLOOK6 DEC R0
JNE NXTLTR ;CONTINUE
CLR R1 ;SHOW GOOD RESULT
RET
NONTRY SETO R1
RET ;SHOW NOT FOUND
;
;********************************
;
; CREATE A DIRECTORY ENTRY (FUNCTION 22)
;
; ENTRY: R3 -> FCB
; R2 = 22
;
; RETURN: R1 = 0 EMPTY DIRECTORY FOUND
; R1 = FF NO EMPTY DIRECTORY AVAILABLE
;
; THIS FUNCTION SHOULD BE CALLED ONLY WITH THE
; FILENAME IN THE FIRST 10 BYTES OF THE FCB. 'MAKFIL'
; MAKES A POINT OF ZEROING ALL BAR THE FILENAME WITH
; THE DIRECTORY ENTRY BEFORE WRITING IT TO DISK. HENCE
; YOU MUST CALL CLOSE TO PROPERLY TRANSFER ANY FILE
; ATTRIBUTES ETC. ALSO NOTE THAT THE FSB WILL BE RETURNED
; HOWEVER ALL OTHER FCB ENTRIES WILL BE ZEROED.
;
;
;******************************
;
MAKFIL: MOV R3,R8 ;LOCAL FCB COPY
CALL @NXTBLK ;FIND A SECTOR FOR FSB AND PLACE IN CAB
MOV R1,R1 ;ERROR ?
JLT MAKERR ;LOOKS LIKE DISK FULL
MOV R6,@CAB ;UPDATE BLOCK VECTORS ETC
MOV R7,@CBP
SETO @DIRENT ;SIMILAR TO SEARCH1
CLR @CDSECT ;MUST SET THESE VARIABLES
CALL @DIROPN ;OPEN THE DIRECTORY
NTHR CALL @DIRBLK ;GET ENTRY THROUGH R3
JLT MAKERR ;END OF DIRECTORY
MOVB *R3,R0 ;CHECK ENTRY
JGT NTHR ;VALID ENTRY
;
; ASSUME R3 POINTS TO DIR ENTRY
;
CLR R0
MOV R8,R5
AI R5,FTY ;FLUSH FROM FILE TYPE ENTRY
LI R2,DIRSIZ-NAMSIZ ;NUMBER OF BYTES TO ZERO
MKFIL2 MOVB R0,*R5+
DEC R2
JNE MKFIL2
MOV @CAB,@FSB(R8) ;TRANSFER FSB
LI R1,LASTBLK ;MARK AS FIRST AND LAST BLOCK IN BAT
MOV @CBP,R0
MOV R1,*R0 ;SHOW ITS THE LAST BLOCK AS WELL AS THE FIRST
;
; NOW CREATE THE ZERO LENGTH FILE
;
LI R2,DIRSIZ ;TRANSFER FILENAME + FSB TO DIRECTORY
MOV R8,R5 ;SAVE FCB VECTOR
MKFIL1 MOVB *R5+,*R3+ ;TRANSER FCB ENTRY TO DIRECTRY
DEC R2
JNE MKFIL1
CALL @WRREC ;WRITE THE DIRECTORY
CALL @WRBAT ;UPDATE BAT AS DIRECTORY ENTRY IS VALID
MOV R1,R1 ;IF NO ERROR SIMULATE 'OPEN'
JLT MAKERR
B @OPENENT
MAKERR SETO R1
RET
;
;*************************************************
;
; RENAME A FILE
;
; R3 -> FCB BYTES 0 - 17 OLD NAME
; BYTES 18- 27 NEW NAME
;
;*************************************************
;
RENAME: MOV R3,R8
CALL @SEARCH1 ;CHECK TO SEE IF THE FILE EXITS
MOV R1,R1
JLT RENAM2 ;NOT FOUND
LI R0,NAMSIZ ;FILENAME SIZE
MOV R3,R2 ;R2 -> DIRECTORY ENTRY
MOV R8,R1
AI R1,NAMEOFF2 ;POINT TO 2ND FILE NAME
RENAM1 MOVB *R1+,*R2+ ;COPY NEW FILE NAME OVER OLD ONE
DEC R0
JNE RENAM1 ;JUMP IF NOT DONE
;
; NOW WRITE THE NEW DIRECTORY ENTRY BACK
;
CALL @WRREC ;ALL DIRECTORY POINTERS UNTOUCHED FROM SEARCH1
RENAM2 RET
;
;******************************
;
; ERASE A DIRECTORY ENTRY
;
; R3 -> FCB
;
; ON RETURN R1 = 0 FOR DIRECTORY ENTRY FOUND
; = -1 FOR NO DIRECTORY ENTRY FOUND
;
;*******************************
;
ERAFIL: MOV R3,R8
CALL @SEARCH1 ;LOOK FOR THE FILE ENTRY
MOV R1,R1 ;DID WE FIND IT ?
JLT ERAERR ;NO
LI R1,8000H ;R3->DIR ENTRY
SOCB R1,@NAM(R3) ;MAKE DELETED
MOV @FSB(R3),@FSB(R8) ;NB RECOVER BAT POINTER
CLR @FSZ(R8) ;FORCE RE-ALLOCATION OF USED BLOCK
CALL @WRREC ;WRITE FDE BACK TO DISK
;
;---NOW RELEASE ALLOCATED BLOCKS
;
RECLAIM: CLR R3 ;START AT FIRST BAT SECTOR
CALL @GETBATP ;READ IN THE BAT TABLE
MOV @FSZ(R8),R3 ;GET FILE SIZE FOR AND
CALL @RECTBC ;CONVERT FILE SIZE TO BLOCKS
CALL @TRACE ;TRACE THROUGH TO TO BLOCK NUMBER
LI R1,LASTBLK
MOV *R7,R3 ;RECOVER BAT INDEX
MOV R1,*R7 ;ASSUME LAST LINK ENTRY
MOV @FSZ(R8),R0 ;ZERO FILE SIZE IE RECLAIM ALL BLOCKS?
JNE ERA00 ;NO
CLR *R7 ;YES SO ZERO LAST LINK
ERA00 C R3,R1 ;LAST LINK ?
JEQ ERA02 ;YES
ERA01 CALL @GETBATP ;GET INDEX (IN R5) TO NEXT BAT
MOV *R7,R3 ;NEXT INDEX VALUE
CLR *R7 ;ZERO TO SHOW BLOCK IS FREE
C R3,R1 ;CHECK FOR FINAL LINK
JEQ ERA02 ;YES - SO WE'RE FINISHED
JMP ERA01 ;KEEP GOING
ERA02 CALL @WRBAT ;UPDATE DISK VERSION OF BAT
CLR R1 ;DONE
RET
ERAERR SETO R1
RET
;
;*********************************
;
; READ IN THE DIRECTORY
;
; R8 -> FCB
;
;*********************************
;
DIROPN: MOV @CDSECT,R3 ;ASSUME THIS HAS BEEN SET
AI R3,FDIRRN ;FIRST DIRECTORY RECORD NUMBER
CALL @RECTBC ;CONVERT TO A BLOCK NUMBER
MOV R2,R1 ;BLOCK TO FIND
CALL @BTTSC ;CONVERT TO TRACK/SECTOR
CALL @SETTRK ;BIOS CALL
MOV R3,@SECTOR ;SET THE SECTOR TO READ
LI R2,DIRBUFF ;BUFFER TO USE
CALL @_SETDMA ;BIOS DMA
CALL @RDREC ;READ IN DIRECTORY
LI R3,DIRBUFF ;USE SAME BUFFER
RET
;
;==============================================================
; FIND THE NEXT DIRECTORY ENTRY
; DIRENT IS JUST AN OFFSET INTO THE
; DIRECTORY BUFFER. ITS VALUUE DEPENDS ON
; THE BLOCK SIZE.
;
; R3 -> TO FILE DIRECTORY CONTENTS
;===============================================================
;
DIRBLK: INC @DIRENT ;UP THE LAST ENTRY
MOV @DIRENT,R3
SLA R3,5 ;*32 IE 32 BYTES DIRECTORY ENTRY
AI R3,DIRBUFF ;POINT TO NEXT ENTRY
CI R3,DIRBUFF+BUFSIZ ;HAVE WE REACHED THE END OF THE BUFFER
JL DIRB01 ;NO
INC @CDSECT ;NOW - TRY NEXT SECTOR
MOV @CDSECT,R3 ;R3 HOLDS RECORD OFFSET WITHIN BLOCK
CI R3,NDSECT ;NUMBER OF SECTORS ALLOCATED TO DIRECTORY
JHE DIRB03 ;SHOW END OF DIRECTORY
AI R3,FDIRRN ;FIRST DIRECTORY RECORD NUMBER
CALL @RECTBC ;CONVERT TO A BLOCK NUMBER
MOV R2,R1 ;BLOCK TO FIND
CALL @BTTSC ;CONVERT TO TRACK/SECTOR
CALL @SETTRK ;BIOS CALL TO SET TRACK
MOV R3,@SECTOR ;SET THE SECTOR
LI R2,DIRBUFF ;UPDATE DMA ADDRESS
CALL @_SETDMA
CALL @RDREC ;READ NEXT SECTOR
;
;SHOULD THIS BE SET TO ONE OR CLR'D?
; CLR @DIRENT ;RESET FOR NEXT TIME
SETO @DIRENT ;RESET FOR NEXT TIME
LI R3,DIRBUFF ;-->DIRECTORY ENTRY
DIRB01: CLR R1 ;FLAG SET
DIRB02: MOV R1,R1 ;SET STATUS
RET
DIRB03: SETO R1
JMP DIRB02
;
;******************************
;
; CONVERT CRN TO BLOCK NUMBER (CRNTBC)
;
; THIS ROUTINE SIMPLY DIVIDES RECORD NUMBER
; BY BLOCK SIZE TO GIVE A RELATIVE BLOCK NO
; SO THAT THE BAT MAY BE INDEXED VIA RESULT
; IN R2.
;
;*******************************
;
CRNTBC: MOV @CRN(R8),R3 ;NEXT RECORD TO READ
;
; ENTER HERE IF GENERAL RELATIVE CONVERSION REQUIRED
; R3 MUST HOLD RECORD NUMBER - NOTE RELATIVE OFFSET WITHIN BLOCK IS FOUND
; RECORDS BEGIN AT 1
; BLOCKS BEGIN AT 0
;
RECTBC CLR R2 ;FOR DIVIDE
LI R0,SECBLK ;SECTORS/BLOCK
DIV R0,R2 ;R2 & R3 HOLD RESULT
RECTBC1 RET
;
;------------------------------------------------------------------------
;
; BLOCK NO. TO TRK/SECT CONVERSION
;
; THIS ROUTINE WILL CONVERT A GIVEN BLOCK AND
; AND RECORD NUMBER WITHIN A FILE TO A PHYSICAL
; TRACK AND SECTOR. I.E. YOU MAY WISH TO LOCATE
; THE TRACK/SECTOR OF SAY RECORD 3 WITHIN BLOCK
; 10 ETC.
;
; THIS ROUTINE IS NORMALLY CALLED AFTER A CALL
; TO CRNTBC/RECTBC WITHIN RDSEQ ,WRSEQ ETC.
;
; R1 = BLOCK NO.
; R3 = RECORD OFFSET WITHIN BLOCK
;
; RECORDS BEGIN AT 1
; BLOCKS BEGIN AT 0
;
; RETURN WITH R2=TRACK,R3=SECTOR
;
; TRK = INT((BLK*SECBLK + R3)/SECTRK)
; SECT = REMAINDER(BLK...)+1
;
; R2 = TRK, R3 = SECT
;
; NOTE NEEDED TO REMOVE THE MULTIPY AS IT HAS A BUG. SEE 99105 ERRATA
;------------------------------------------------------------------------
;
;REVISED MULTIPLY TO AVOID 99105 MULTIPLY BUG
;
BTTSC LI R0,SECBLK
CLR R2
JEQ BTTSC2
BTTSC1 A R1,R2 ;R2=BLK*SECBLK
DEC R0
JNE BTTSC1
BTTSC2 A R2,R3 ;R3=BLK*SECBLK+R3
CLR R2 ;MSB OF QUOTIENT
LI R0,SECTRK ;SECTORS/TRACK
DIV R0,R2 ;R2=TRK,R3=SECT (R2+R3)/R0
INC R3 ;TAKES CARE OF ZERO OFFSET FOR CRN
BTTSC0 RET
;
;*******************************
;
;
; FIND A FREE BLOCK
; NXTBLK WILL TRAVERSE THE BAT LOOKING FOR A ZEROED
; BAT ENTRY. ONCE FOUND NO CHANGE TO THE BAT WILL BE
; MADE AND ONLY THE POINTERS TO THE ENTRY WILL BE RETURNED.
; IT IS THEN UP TO THE CALLING PROGRAMME TO INSERT THE NEW
; LINKS.
;
; NOTE: RDBAT WILL PULL IN THE APPROPRIATE BAT SECTOR AS REQUIRED
;
; R8 -> FCB
;
; R1 = -1 (ERROR)
; R1 = 0 (GOOD RESULT)
;
;
;****************************************************************
;
NXTBLK: MOV @CAB,R0 ;BEGIN AT LAST BLOCK TO SPEED THINGS UP AND TO STOP THRASHING
;TO TO LOOK AT LATER WRAPPING BACK TO BEGINING
NXTBLK2 MOV R0,R3
CALL @GETBATP ;FIND THE BAT AND GET THE POINTER FROM THE INDEX
MOV *R7,R1 ;POINTER IS IN R7
JEQ NXTBLK4 ;ANY FREE ? YES
CI R1,-1 ;LAST AVAILABLE BLOCK ?
JEQ NXTBLK3 ;YES
INC R0 ;NEXT BLOCK
JMP NXTBLK2 ;KEEP LOOKING
;
; R7 -> FREE BLOCK
; R6 = FREE BLOCK NUMBER
;
NXTBLK4 MOV R0,R6 ;COPY FREE BLOCK NUMBER HERE