-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdos1x.asm
9342 lines (8509 loc) · 278 KB
/
dos1x.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
; ------------------------------------------------------------------------------
; dos1x.asm
; DOS version 1.5 (non official version number)
; Based on:
; DOS 1.03 kernel (latest version known, SONY HB-F1XV)
; FAT swapper and other DOS 1 enhancements by SOLiD
;
; Code Copyrighted by ASCII, SOLiD and maybe others
; DOS 1.03 kernel source origin is the msxsyssrc repository by Arjen Zeilemaker
; Restructure, modifications and additional comments by H.J. Berends
;
; Sourcecode supplied for STUDY ONLY
; Recreation NOT permitted without authorisation of the copyrightholders
; ------------------------------------------------------------------------------
; Modifications:
; + FAT swapper to support disks that are larger than 16MB
; + DOS 1 enhancements (IDEDOS1)
; + Optional FAT16 for DOS1 (FAT16DOS1)
; x Removed BEER 1.9 legacy dependencies
INCLUDE "disk.inc" ; Assembler directives
INCLUDE "msx.inc" ; MSX constants and definitions
SECTION DISK
ORG 04000H
; Routines which can be used by the disk hardware driver
PUBLIC PROMPT ; Prints a message for two drive emulation on a single drive.
PUBLIC GETSLT ; Get disk driver's slot address.
PUBLIC GETWRK ; Get address of disk driver's work area.
PUBLIC DIV16 ; BC:=BC/DE, remainder in HL.
PUBLIC ENASLT ; Enables a slot a address specified by A:HL.
PUBLIC XFER ; Eactly emulates an LDIR.. ..used when transferring data to/fro page-1.
PUBLIC SETINT ; Setup routine at (HL) as a timer interrupt routine (50Hz/60Hz0.
PUBLIC PRVINT ; Calls previous timer interrupt routine...
; Symbols which must be defined by the disk hardware driver
EXTERN INIHRD ; Initialize hardware
EXTERN DRIVES ; Return number of drives in system
EXTERN INIENV ; Initialize work area
EXTERN DSKIO ; Sector read and write
EXTERN DSKCHG ; Get disk change status
EXTERN GETDPB ; Get disk parameter block (DPB)
EXTERN CHOICE ; Return format choice string
EXTERN DSKFMT ; Format a disk
EXTERN MTOFF ; Turn drive motors off
EXTERN OEMSTA ; Used for system expansion (OEMSTATEMENT)
EXTERN MYSIZE ; Size of the page-3 RAM work area required by the driver in bytes.
EXTERN SECLEN ; Maximum sector size for media supported by this driver (512).
EXTERN DEFDPB ; Base address of a 21 byte "default" DPB for this driver.
IFDEF IDEDOS1
; Additional symbol defined by the ide driver module
EXTERN BOOTMENU
ENDIF
; rem: _RST MACRO replaced with labels
R_SYNCHR EQU 08H
R_CHRGTR EQU 10H
R_OUTDO EQU 18H
R_DCOMPR EQU 20H
R_GETYPR EQU 28H
R_CALLF EQU 30H
; ------------------------------------------------------------------------------
; ROM Header at address $4000
; ------------------------------------------------------------------------------
defb "AB"
defw A576F ; EXTENSION ROM INIT handler
defw A6576 ; EXTENSION ROM CALL statement handler
defw 0
defw 0
defs 6
; disk hardware driver entries
T4010: jp DSKIO ; DSKIO entrypoint
T4013: jp DSKCHG ; DSKCHG entrypoint
T4016: jp GETDPB ; GETDPB entrypoint
T4019: jp CHOICE ; CHOICE entrypoint
T401C: jp DSKFMT ; DSKFMT entrypoint
T401F: jp MTOFF ; MTOFF entrypoint
; kernel entries
A4022: jp A5B3A ; start DiskBasic entrypoint
A4025: scf ; format disk entrypoint (workarea must be supplied)
jp A60B1
A4029: jp A620D ; stop all disks entry point
db 0
GETSLT:
A402D: jp GetMySlot ; get slotid entrypoint
; Subroutine get MSX-DOS system bottom
; Inputs -
; Outputs HL = lowest address used by the base MSX-DOS system
; _DOSCP 4030H
DOS_SINIT:
A4030: ld hl,(DOSHIM)
ret
; Subroutine check if keyboardinput available
; Inputs -
; Outputs Zx set if no input, Zx reset if input, A = input
; _DOSCP 4034H
DOS_SSBIOS:
A4034: push ix
ld ix,BREAKX
call A40AB ; BREAKX BIOS call
pop ix ; CTRL-STOP pressed ?
jr nc,A404B ; nope,
ld a,003H
ld (KEYVLD),a ; saved input available
ld (KEYCHR),a ; CTRL-C
and a ; flag NZ
ret
A404B: ld a,(KEYVLD)
and a ; saved input available ?
ld a,(KEYCHR)
ret nz ; yep, return it (flag NZ)
push ix
ld ix,CHSNS
call A40AB ; CHSNS BIOS call
pop ix ; any chars in the keyboard buffer ?
ret z ; nope, quit (flag Z)
ld a,0FFH
ld (KEYVLD),a ; flag saved input available
push ix
ld ix,CHGET
call A40AB ; CHGET BIOS call
pop ix ; get char from keyboard buffer
ld (KEYCHR),a ; save char
push bc
ld b,000H
inc b
pop bc ; flag NZ
ret
; Subroutine get keyboardinput
; Inputs -
; Outputs A = input
; _DOSCP 4078H
DOS_SIN:
A4078: push hl
ld hl,KEYVLD
xor a
cp (hl) ; saved input available ?
ld (hl),a ; not anymore!
inc hl
ld a,(hl)
pop hl
ret nz ; yep, return it
push ix
ld ix,CHGET
call A40AB ; CHGET BIOS call
pop ix ; get char
ret
; Subroutine output to screen
; Inputs A = output
; Outputs -
; _DOSCP 408FH
DOS_SOUT:
A408F: push ix
ld ix,CHPUT
call A40AB ; CHPUT BIOS call
pop ix
ret
; Subroutine output to printer
; Inputs A = output
; Outputs -
A409B: push ix
ld ix,LPTOUT
call A40AB ; LPTOUT BIOS call
pop ix
ret
; Subroutine BDOS 00 (system reset)
; Inputs
; Outputs ________________________
A40A7: ld ix,READYR ; restart BASIC
; Subroutine MSX-BIOS call
; Inputs IX = bios call, others depends on the bios call
; Outputs depends on the bios call
A40AB: push iy
ld iy,(EXPTBL-1+0)
call CALSLT
ei
pop iy
ret
; Subroutine check for and initialize clockchip
; Inputs -
; Outputs -
A40B8: ld a,13
out (0B4H),a
ld a,00AH
out (0B5H),a ; alarm off, clock running, bank 2
xor a
out (0B4H),a ; pos 0
ld b,00FH
A40C5: in a,(0B5H) ; read data
and 00FH
xor b
out (0B5H),a ; change it and write back
ld c,a
nop ; wait (orginal had 2x EX (SP),HL but by saving one byte all routine after this routine stay alligned)
in a,(0B5H)
and 00FH
cp c ; correctly readback ?
ret nz ; nope, no clockchip!
xor b
out (0B5H),a ; restore orginal data
djnz A40C5 ; try all values
ld a,0FFH
ld (TIMFLG),a ; flag use clockchip
ld a,13
out (0B4H),a
ld a,009H
out (0B5H),a ; alarm off, clock running, bank 1
ld a,10
out (0B4H),a ; pos 10
ld a,1
out (0B5H),a ; 24 hour system
ld a,13
out (0B4H),a
xor a
out (0B5H),a ; alarm off, clock paused, bank 0
ld bc,00D00H
A40F8: ld a,c
out (0B4H),a
in a,(0B5H)
push af
inc c
djnz A40F8 ; save time registers
ld a,14
out (0B4H),a
xor a
out (0B5H),a ; clear testbits
ld b,00DH
A410A: dec c
ld a,c
out (0B4H),a
pop af
out (0B5H),a
djnz A410A ; restore time registers
jr A414E ; put clock in running mode
; Subroutine store date
; Inputs
; Outputs -
A4115: ld (CURDAT),hl
ld a,(TIMFLG)
and a ; use clockchip ?
ret z ; no, quit
ld a,(YEAR)
ld b,a
ld a,(MONTH)
ld c,a
ld a,(DAY)
ld d,a ; current day
ld e,007H ; nibble 7 (date)
call A4159 ; pause clock, select bank 0
jr A4142
; Subroutine store time
; Inputs
; Outputs -
A4130: ld a,(TIMFLG)
and a ; use clockchip ?
ret z ; no, quit
ld e,000H ; nibble 0 (time)
call A4159 ; pause clock, select bank 0
ld a,00FH
out (0B4H),a
ld a,002H
out (0B5H),a ; time reset
A4142: ld h,d
call A4160 ; write clockchip byte
ld h,c
call A4160 ; write clockchip byte
ld h,b
call A4160 ; write clockchip byte
; Subroutine put clockchip in running mode
; Inputs -
; Outputs -
A414E: ld a,13
out (0B4H),a
in a,(0B5H)
or 008H
A4156: out (0B5H),a
ret
; Subroutine pause clockchip and select bank 0
; Inputs -
; Outputs -
A4159: call A414E ; clock in running mode
and 004H
jr A4156 ; clock paused, select bank 0
; Subroutine write byte to clockchip
; Inputs H = data, E = nibblenumber
; Outputs E = updated nibblenumber (+2)
A4160: xor a
ld l,8
A4163: rlc h
adc a,a
daa
dec l
jr nz,A4163 ; convert to BCD
call A4171
rrca
rrca
rrca
rrca
A4171: push af
ld a,e
inc e
out (0B4H),a
pop af
jr A4156
; Subroutine get date and time
; Inputs
; Outputs Cx set if from clockchip,
A4179: ld a,(TIMFLG)
and a ; use clockchip ?
ld b,a
ld c,a
ld d,a
ld e,a ; 00:00:00
ld hl,(CURDAT) ; days since 1-1-1980
ret z ; no clockchip, quit
call A4159 ; clock paused, select bank 0
ld e,12+1
call A41AD ; read byte from clockchip
call A5523 ; setup days in februari
call A41AD ; read byte from clockchip
ld (MONTH),a ; current month
call A41AD ; read byte from clockchip
ld (DAY),a ; current day
dec e ; nibble 5
call A41AD ; read byte from clockchip
ld b,a
call A41AD ; read byte from clockchip
ld c,a
call A41AD ; read byte from clockchip
call A414E ; clock in running mode
scf
ret
; Subroutine read byte from clockchip
; Inputs E = nibblenumber+1
; Outputs E = updated nibblenumber (-2), A = data
A41AD: xor a
call A41B5
add a,a
add a,a
add a,d
add a,a
A41B5: ld d,a
dec e
ld a,e
out (0B4H),a
in a,(0B5H)
and 00FH
add a,d
ld d,a
ret
; Identification string (not used)
IFDEF IDEDOS1
Q41C1: defb " MSX-DOS 1 for BEER PPI IDE and SODA CF IDE "
ELSE
Q41C1: defb " MSX-DOS ver. 2.2 Copyright 1984 by Microsoft "
ENDIF
; Subroutine BDOS 0C (return version number)
; Inputs
; Outputs ________________________
; _DOSCP 41EFH
DOS_CPMVER:
A41EF: ld b,000H ; machinetype 8080, plain CP/M
ld a,022H ; CP/M version 2.2
ret
; Subroutine get FAT entry content
; Inputs HL = cluster number, IX = pointer to DPB
; Outputs HL = cluster entry content, Zx set if entry is free, DE = pointer to FAT buffer
; A41F4
GETFAT: ld e,(ix+19)
ld d,(ix+20) ; pointer to FAT buffer of drive
A41FA:
IFDEF IDEDOS1
jp NewGetFAT
OldGetFAT:
ELSE
call H_UNPA
ENDIF
push de ; store pointer to FAT buffer of drive
ld e,l
ld d,h ; cluster number
srl h
rr l ; /2
rra ; remainer in b7
add hl,de ; * 1.5
pop de ; restore pointer to FAT buffer of drive
add hl,de ; pointer in FAT buffer
rla ; remainer in Cx
ld a,(hl)
inc hl
ld h,(hl) ; FAT entry content
jr nc,A421A ; even entry, skip shift
srl h
rra
srl h
rra
srl h
rra
srl h
rra ; shift 4 bits right
A421A: ld l,a
ld a,h
and 00FH ; FAT entry content to 12 bit
ld h,a
or l ; Zx set if entry is free
ret
; Subroutine set FAT entry content
; Inputs HL = clusternumber, DE = pointer to FAT buffer, BC = clusterentry content
; Outputs -
A4221:
PutFAT:
IFDEF FAT16DOS1
jp F16P02
OldPutFAT:
ELSE
push de ; store pointer to FAT buffer
ld e,l
ld d,h ; store cluster number
ENDIF
srl h
rr l ; /2
rra ; store remainer in b7
add hl,de ; * 1.5
pop de ; restore FAT buffer
add hl,de ; pointer in FAT buffer
rla ; remainer in Cx
jr nc,A4247 ; even entry,
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b
ld a,(hl)
and 00FH
or c
ld (hl),a
inc hl
ld (hl),b
ret
A4247: ld (hl),c
inc hl
ld a,(hl)
and 0F0H
or b
ld (hl),a
ret
; Subroutine compare with filename1
; Inputs HL = pointer to buffer, B = size
; Outputs Zx set if equal
A424F: ld de,NAME1
; Subroutine compare
; Inputs DE = pointer to buffer1, HL = pointer to buffer2, B = size
; Outputs Zx set if equal
A4252: ld a,(de)
cp (hl)
inc hl
inc de
ret nz
djnz A4252
ret
; Subroutine check if devicename
; Inputs
; Outputs ________________________
A425A: call H_DEVN
ld hl,IONAME ; table with devicenames
ld c,5 ; 5 devices
A4262: ld b,4 ; only check 4 bytes (because devicenames are only 4 chars long)
call A424F ; compare with filename1
jr nz,A4298 ; not this device, try the next
ld b,4
A426B: ld a,(de)
inc de
cp ' '
jr nz,A42A3 ; last 4 bytes of filename not spaces, not a device
djnz A426B
ld a,c
neg
ld (DEVDIR+11),a ; devicecode
ld hl,NAME1
ld de,DEVDIR
ld bc,4
ldir ; copy of devicename
call A5496 ; get time and date (dirformat)
ld (DEVDIR+24),bc
ld (DEVDIR+22),de
ld hl,DEVDIR
push hl
pop iy
or 001H ; Cx reset, Zx reset
ret
A4298: dec b
ld a,l
add a,b
ld l,a
ld a,h
adc a,000H
ld h,a
dec c
jr nz,A4262
; Zx set
A42A3: scf
ret
; Subroutine validate FCB, clear S2 and find direntry
; Inputs
; Outputs ________________________
A42A5: push de
ld hl,14
add hl,de
ld (hl),0 ; FCB S2 (extent high byte)
call A42B1 ; validate FCB drive and filename and find direntry
pop de
ret
A42B1: call A440E ; validate FCB drive and filename
ret c ; invalid, quit
; Subroutine find first directoryentry
; Inputs
; Outputs ________________________
A42B5: call A425A ; check if devicename
ret nc ; yep, quit with pointer to fake device direntry
call A44D3 ; reset direntry search and get latest FAT
; Subroutine find next directoryentry
; Inputs
; Outputs ________________________
A42BC: call H_CONT
call A430E ; get next direntry
ret c ; no more, quit
A42C3: ld a,(hl)
or a
jr z,A42FC ; unused entry,
cp 0E5H
jr z,A42FC ; deleted entry,
push hl
ld b,11
ld de,NAME1
A42D1: call A4252 ; compare with fcb filename
jr z,A42DC ; equal, found!
cp '?'
jr nz,A42F5 ; on difference no wildcard, try next
djnz A42D1 ; wildcard pos ignored, check rest
A42DC: pop hl
push hl
pop iy
ld a,(ATTRIB)
xor 080H
bit 7,a
ret z ; orginal FCB DR byte had b7 set, ignore direntryattribute
ld a,(iy+11)
and 01EH
ret z ; files with archive or read-only bit set are ok, quit
ld a,(CREATI)
or a ; include special fileattribute flag set ?
ret nz ; yep, every direntry is ok, quit
jr A42F6
A42F5: pop hl
A42F6: call A4348 ; get next direntry (while searching)
jr nc,A42C3 ; ok, check it
ret
A42FC: ld a,(ENTFRE)
inc a ; already found a free direntry ?
jr nz,A4308
ld a,(LASTEN)
ld (ENTFRE),a ; nope, register it
A4308: ld a,(hl)
or a ; unused direntry ?
jr nz,A42F6 ; nope, the search goes on!
scf
ret
; Subroutine get next direntry (at start of search)
; Inputs
; Outputs ________________________
A430E: ld a,(LASTEN)
inc a
cp (ix+11) ; last direntry ?
jr nc,A4367 ; yep, update directory of disk when needed and quit
; Subroutine get direntry
; Inputs
; Outputs ________________________
A4317: call H_GETE
ld (LASTEN),a
ld c,a
and (ix+4) ; dirmask
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
add hl,hl
add hl,hl
ld de,(SDIRBU) ; dirsector buffer
add hl,de
ld b,(ix+5) ; dirshift
A4331: srl c
djnz A4331
ld a,(DIRBFI)
cp c ; same as dirsector currently in buffer ?
jr nz,A4342 ; nope, go get it
ld a,(DIRBFD)
cp (ix+0) ; same driveid as dirsector buffer owner ?
ret z ; yep, do nothing
A4342: push hl
call A46A4 ; read dirsector
pop hl
ret
; Subroutine get next direntry (while searching)
; Inputs
; Outputs ________________________
A4348: call H_NEXT
ld a,(LASTEN)
inc a
cp (ix+11) ; last direntry ?
jr nc,A4367 ; yep, update directory of disk when needed and quit
ld (LASTEN),a
ld de,00020H
add hl,de
and (ix+4) ; dirmask
ret nz
inc c
call A46A4 ; read dirsector
ld hl,(SDIRBU) ; dirsector buffer
ret
; Subroutine at end of directory
; Inputs
; Outputs ________________________
A4367: call A4743 ; flush directory buffer
scf
ret
; Subroutine BDOS 13 (delete file)
; Inputs
; Outputs ________________________
; _DOSCP 436CH
DOS_DELETE:
A436C: call A440E ; validate FCB drive and filename
call nc,A42B5 ; valid, find first directoryentry
ld a,0FFH
ret c ; invalid or not found, quit with error
ret nz ; device, quit with error
A4376: ld a,0E5H
ld (DIRTYD),a ; flag directory buffer dirty
ld (hl),a ; deleted direntry
ld l,(iy+26)
ld h,(iy+27)
ld a,h ; file has start cluster ?
or l
call nz,A4F9B ; yep, release cluster chain
call A42BC ; find next directoryentry
jr nc,A4376 ; found, delete next file
call A4403 ; update directory of disk (SHOULD BE: CALL A4748)
jp A45CF ; write FAT buffer (SHOULD BE: JP A45C4, flush FAT buffer)
; Subroutine BDOS 17 (rename file)
; Inputs
; Outputs ________________________
; _DOSCP 4392H
DOS_RENAME:
A4392: call A440E ; validate FCB drive and filename
jr c,A440B ; invalid, quit with error
ld de,00005H
add hl,de ; to new filename
ld de,NAME2 ; new filenamebuffer
call LODNAM ; validate FCB filename (new filename)
call nc,A42B5 ; new filename valid, find first directoryentry
jr c,A440B ; invalid or not found, quit with error
jr nz,A440B
ld hl,NAME1
ld de,NAME3
ld bc,11+1
ldir ; save filename (search specifier) + orginal DR byte
A43B3: ld hl,NAME2 ; new filename
ld de,NAME1
ld b,11
A43BB: ld a,(hl)
cp '?' ; wildcard char ?
jr nz,A43C3 ; nope, use the char of the new filename
ld a,(iy+0) ; yep, use the char of the orginal filename
A43C3: ld (de),a
inc hl
inc de
inc iy
djnz A43BB
ld a,080H
ld (de),a ; orginal DR byte b7 set (ignore fileattribute)
call A425A ; check if devicename
jr nc,A4408 ; yep, end rename with error
ld a,(LASTEN)
push af
ld a,0FFH
ld (LASTEN),a ; flag direntry search start at the begin
call A42BC ; find next directoryentry
pop bc
jr nc,A4408 ; found, so resulting filename does already exist. end rename with error
ld a,b
call A4317 ; get direntry which get renamed
ex de,hl
ld hl,NAME1
ld bc,11
ldir ; replace filename with new one
ld a,0FFH
ld (DIRTYD),a ; flag directory buffer dirty
ld hl,NAME3
ld de,NAME1
ld bc,11+1
ldir ; restore filename (search specifier) + orginal DR byte
call A42BC ; find next directoryentry
jr nc,A43B3 ; found, rename next file
A4403: call A4743 ; flush directory buffer
xor a ; no error
ret
A4408: call A4743 ; flush directory buffer
A440B: ld a,0FFH ; error
ret
; Subroutine validate FCB drive and filename
; Inputs
; Outputs ________________________
A440E: call H_MOVN
xor a
ld (CREATI),a ; do not include special fileattributes
ex de,hl
ld a,(hl)
inc hl
ld (ATTRIB),a ; save FCB DR byte
and 00FH ; only use b3-b0 for drive
call A4427 ; validate fcb driveid
ret c
ld de,NAME1
jp LODNAM ; validate FCB filename
; Subroutine Validate driveid (FCB style)
; Inputs A = driveid
; Outputs ________________________
A4427: ld c,a
ld a,(SNUMDR)
cp c
ret c
ld a,c
dec a
jp p,A4435
ld a,(CURDRV) ; default driveid
A4435: ld (THISDR),a ; set current driveid
ret
; Subroutine get max record and extent
; Inputs
; Outputs ________________________
A4439: ld a,(iy+31)
or a
jr nz,A445E ; filesize > 16777215, use max value
ld a,(iy+28)
ld c,(iy+29)
ld b,(iy+30)
add a,a
rl c
rl b ; number of records (128 bytes)
jr c,A445E ; >65535, use max value
or a ; is filesize a multiply of 128 ?
jr z,A4457
inc bc ; nope, increase the recordnumber
ld a,b
or c ; does that fit ?
jr z,A445E ; nope, use max value
A4457: ld a,c
res 7,c ; c = max recordnumber (0-127)
add a,a
rl b ; b = max extent
ret nc ; does fit, quit
A445E: ld bc,0FF7FH ; extent 255, record 127
ret
; Subroutine BDOS 0F (open file)
; Inputs
; Outputs ________________________
; _DOSCP 4462H
DOS_OPEN:
A4462: call A42A5 ; validate FCB, clear S2 and find direntry
jr c,A440B ; error, quit with error
call A4439 ; get max record and extent
ld a,(FCBEXT) ; original FCB EX byte
inc b ; ?? correct for large files (filesize > 4177919 where extend is 0FFH)
cp b ; is extent of file big enough ?
jr nc,A440B ; nope, quit with error
A4471: call H_DOOP
ex de,hl
ld bc,0000FH
add hl,bc
call A4439 ; get max record and extent
ld a,(FCBEXT)
cp b ; orginal FCB EX byte same as max extent ?
jr z,A4488 ; same, use RC=max recordnumber (means extent is not full)
ld c,080H
jr c,A4488 ; smaller, use RC=128 (means extend is full)
ld c,000H ; bigger, use RC=0 (means extend is empty)
A4488: ld (hl),c ; RC
inc hl
ex de,hl
ld bc,0001CH
add hl,bc
ld c,004H
ldir ; copy filesize
ld bc,0FFF8H
add hl,bc
ldi
ldi ; creation date
ld c,0FCH
add hl,bc
ldi
ldi ; creation time
ld a,(iy+11)
bit 7,a
jr nz,A44AE ; device,
ld a,(ix+0) ; driveid
or 040H ; flag diskfile unchanged
A44AE: ld (de),a ; devicecode
inc de
ld a,(LASTEN)
ld (de),a ; direntry number
inc de
ld a,(iy+26)
ld (de),a
inc de
inc de
ld (de),a
dec de
ld a,(iy+27)
ld (de),a
inc de
inc de
ld (de),a ; start cluster and last cluster accessed
inc de
xor a
ld (de),a
inc de
ld (de),a ; last cluster accessed, relative
ret
; Subroutine handle DSKCHG error
; Inputs
; Outputs ________________________
A44CA: ld c,a
ld a,(THISDR) ; current driveid
call A470A ; start diskerror handler
jr A44DB ; get latest FAT (try again)
; Subroutine reset direntry search and get latest FAT
; Inputs
; Outputs ________________________
A44D3: ld a,0FFH
ld (LASTEN),a ; invalid latest direntry (search from the begin)
ld (ENTFRE),a ; not found a free direntry
; Subroutine get latest FAT
; Inputs
; Outputs ________________________
A44DB: call H_FATR
call A4555 ; get pointer to DPB of current drive
ld a,(THISDR) ; current driveid
ld c,(ix+1) ; mediadesciptor
ld b,0
or a
call A6067 ; DSKCHG (DiskChg_all)
jr c,A44CA ; error,
call SetDPBAdr ; update pointer to DPB of current drive
ld l,(ix+19)
ld h,(ix+20) ; pointer to FAT buffer of drive
dec hl
ld a,b ; DSKCHG status
or (hl) ; combined with the FAT buffer dirty flag
ld a,(THISDR) ; current driveid
ld hl,(BUFDRN)
jp m,A450A ; FAT buffer invalid OR diskchange unknown, read the FAT
ret nz ; FAT buffer dirty OR disk unchanged, do not read the FAT and quit
cp l ; current drive same as datasector buffer owner ?
jr nz,A4516 ; nope, read the FAT
dec h ; datasector buffer changed ?
ret z ; yep, do not read the FAT and quit
A450A: sub l ; current drive same as datasector buffer owner ?
jr nz,A4516 ; nope, leave the datasector buffer alone
ld l,a
ld h,a
dec l
ld (BUFDRN),hl ; invalid datasector buffer
A4516: ld a,0FFH
ld (DIRBFD),a ; invalid dirsector buffer
IFDEF IDEDOS1
jp NewGetFATbuf
ds 0bh,0 ; Unused code
ELSE
call GetFATbuf ; get FAT parameters
dec hl
ld (hl),0 ; FAT buffer clean
inc hl
A4522: push af
call A46D7 ; read FAT sectors
jr c,A4541 ; error, try the next FAT copy
pop af
ENDIF
; A4529
DPB_change_entry:
ld b,(hl) ; mediabyte of FAT sector
ld a,(THISDR) ; current driveid
ld c,(ix+1) ; mediadescriptor