forked from Konamiman/NestorFilesystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NFS.ASM
2036 lines (1623 loc) · 32.6 KB
/
NFS.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
;Filesystem driver infrastructure AKA NestorFilesystem v0.1
;By Konamiman, 5-2017
;This is the skeleton of a resident program that installs
;in page 3 + one RAM segment and uses the H_BDOS (0F252h) hook
;to intercept the file access related MSX-DOS function calls.
;This allows to develop a custom filesystem driver, that is,
;a program that supplies custom implementations for
;file search/open/read/write/create/rename/delete functions.
;
;Search TODO: comments for instructions on how to convert
;this skeleton into a working implementation for your
;device/hardware.
;
;This is a very early version that:
;- Installs the driver on drive G: always
;- Doesn't allow installing more than one driver
;- Implements the file search and current directory functions only
;
;Assemble with Compass or with Sjasm v0.39h
;(https://github.com/Konamiman/Sjasm/releases/tag/v0.39h)
;
;Works on MSX-DOS 2 and Nextor.
;***************************************
;--- BEGIN of macros and constants ---
;***************************************
IDNES: equ 22h ;ID for extended BIOS
IDNFS: equ 4
;Min and max function calls that will be hooked,
;apart from some that will be treated as special cases
MINFN: equ 40h ;_FFIRST
MAXFN: equ 5Ah ;_CHDIR
MAX_PATH_LEN: equ 63
SLASH: equ 5Ch
dos: macro
call 5
endm
;*** Hooks and system variables
ENDTPA: equ 0006h
HIGHMEM: equ 0F349h
EXTBIO: equ 0FFCAh
CALSLT: equ 001Ch
ENASLT: equ 0024h
EXPTBL: equ 0FCC1h
CUR_DRV: equ 0F23Ch
H_BDOS: equ 0F252h
;*** MSX-DOS functions
_STROUT: equ 09h
_SELDSK: equ 0EH
_LOGIN: equ 18h
_ALLOC: equ 1Bh
_CURDRV: equ 19h
_FFIRST: equ 40h
_FNEXT: equ 41h
_GETCD: equ 59h
_CHDIR: equ 5Ah
_WPATH: equ 5Eh
_TERM: equ 62h
_DOSVER: equ 6Fh
;*** MSX-DOS error codes
__IATTR: equ 0CFh
__NODIR: equ 0D6h
__NOFIL: equ 0D7h
__PLONG: equ 0D8h
__IPATH: equ 0D9h
__DISK: equ 0FDh
__IFORM: equ 0F0h ;Used for testing
;*************************************
;--- END of macros and constants ---
;*************************************
;****************************
;--- BEGIN of installer ---
;****************************
org 100h
ld de,PRESENT_s
ld c,_STROUT
dos
;--- Check if DOS 2 or Nextor
ld c,_DOSVER
dos
ld a,b
cp 2
jr nc,OKDOS2
NODOS2: ld de,NOD2STR
ld c,_STROUT
dos
ret
NOD2STR: db 13,10,"*** MSX-DOS 2 required",13,10,"$"
OKDOS2: ;
;--- Check for enough TPA ((0006h) >= 0C200h)
ld a,(ENDTPA+1)
cp 0C2h
jr nc,OKTPA
ld de,NOTPAS
ld c,_STROUT
dos
jp FIN
NOTPAS: db 13,10,"*** TPA is too small (end of TPA must be at least 0C200h).",13,10,"$"
OKTPA: ;
;--- Get mapper support routines
ld de,0402h
call EXTBIO
ld a,b ;also set mapper slot for page 3 code
and %10001111
ld (RESCODE1+11),a
ld (RESCODE2+11),a
ld de,ALL_SEG
ld bc,30h
ldir
;--- Check if already installed, if so and parameter is U, go to uninstall
ld de,IDNFS+256*IDNES
call EXTBIO
cp IDNES
jp z,DESINST
;--- TODO: check if the required hardware/device is present
; and abort install if not, e.g.
;call CHECK_DEVICE
;jr nc,OKDEVICE
;ld de,NODEVICE
;ld c,_STROUT
;dos
;jp FIN
;NODEVICE: db "*** Device not found!",13,10,"$"
OKDEVICE:
;--- So let's install: start by allocating a RAM segment
ld b,0
ld a,1
call ALL_SEG
jp nc,OKRESEG
ld de,NOFSTR
ld c,_STROUT
dos
FIN: ld b,0
ld c,_TERM
dos
ret
NOFSTR: db 13,10,"*** No free RAM segments on primary mapper.",13,10,"$"
OKRESEG: ld (RESCODE1+12),a
ld (RESCODE2+12),a
;--- Backup existing hooks into page 3 code
di
ld hl,H_BDOS
ld de,RESCODE1+8
ld bc,3
ldir
ld hl,H_BDOS
ld de,RESCODE2+8
ld bc,3
ldir
ld hl,EXTBIO
ld de,RESCODE1+3
ld bc,5
ldir
ld hl,EXTBIO
ld de,RESCODE2+3
ld bc,5
ldir
;--- Allocate page 3 space and copy page 3 code
ld hl,(HIGHMEM)
ld (RESCODE1+21),hl
ld (RESCODE2+21),hl
ld bc,RESCODE2-RESCODE1
or a
sbc hl,bc
ld (HIGHMEM),hl
ld (RESCODE1+19),hl
ld (RESCODE2+19),hl
ld hl,PUT_P1 ;PUT_P1 + GET_P1
push hl
ld de,RESCODE1+13
ld bc,6
ldir
pop hl
ld de,RESCODE2+13
ld bc,6
ldir
ld hl,RESCODE1
ld de,RESCODE2
ld ix,(RESCODE1+19)
ld bc,RESCODE2-RESCODE1
call REUBICA
;--- Copy segment code into the allocated segment
call GET_P1
push af
ld a,(RESCODE1+12)
call PUT_P1
ld hl,PARTRE2
ld de,4000h
ld bc,PARTRE2!-4000h
ldir
pop af
call PUT_P1
;--- Set the new hooks
di
ld hl,(HIGHMEM)
ld de,EXTBIO
ld bc,5
ldir
ld bc,23-5
add hl,bc
ld a,0C3h
ld (H_BDOS),a
ld (H_BDOS+1),hl
;--- Install done, do a BASIC + CALL SYSTEM
ei
ld de,INSSTR
ld c,_STROUT
dos
ld hl,0081h
jp CALSYS
INSSTR:
db "Installed. Have fun!",13,10,"$"
;--- Uninstall if parameter is "U"
DESINST: ld hl,0081h
SRCH_U: ld a,(hl)
inc hl
cp 32 ;Skip spaces
jr z, SRCH_U
or a
jr nz,CHKU
NODES:
ld de,YAINSTR ;0 found: no parameters
ld c,_STROUT
dos
jp FIN
YAINSTR: db "*** Already installed. Run with U to uninstall.",13,10,"$"
CHKU: and %11011111 ;If something is found, it must be U
cp "U"
jr nz,NODES
ld (POS2COM),hl ;Save position after "U"
ld de,IDNFS+IDNES*256 ;Check if current HIGHMEM is the same
call EXTBIO ;as HIGHMEM when we were installed,
ld de,(HIGHMEM) ;otherwise uninstall is not possible.
or a
sbc hl,de
ld a,h
or l
jp z,OKHMEM
ld de,NOKHMEMS
ld c,_STROUT
dos
jp FIN
NOKHMEMS: db "*** Other resident program was installed after I was.",13,10
db "Please remove it and try again.",13,10,"$"
OKHMEM: push ix
ld a,c
call FRE_SEG
ld hl,(HIGHMEM)
ld bc,3
add hl,bc
di
ld de,EXTBIO
ld bc,5
ldir
ld de,H_BDOS
ld bc,3
ldir
pop ix
ld (HIGHMEM),ix
ld de,DESSTR
ld c,_STROUT
dos
ld hl,(POS2COM)
jp CALSYS
DESSTR: db "Uninstalled, please come back!",13,10,"$"
POS2COM: dw 0
RESTHOOK: ldir
ld bc,5
ret
;--- Code reallocation routine
; Input: HL = First copy of code
; DE = Second copy of code
; IX = Destination address
; BC = Code length
REUBICA: push bc,de,hl ;First copy code unchanged
push ix ;(HL->IX, length BC)
pop de
ldir
pop hl,de
push de
pop iy ;IY = Second copy
ld b,h
ld c,l
push ix
pop hl
or a
sbc hl,bc
ld b,h
ld c,l ;BC = Distance to sum (IX - HL)
exx
pop bc
exx
;In this point: IX = Destination
; IY = Second copy
; BC = Distance to sum (new address - the copy)
; BC'= Length
BUCLE: ld a,(ix)
cp (iy)
jr z,NEXT ;If no differences go to next byte
ld l,a
ld h,(ix+1) ;HL = Data to change
add hl,bc ;HL = Changed data
ld (ix),l ;IX = Address of data to change
ld (ix+1),h
call CHKCOMP
jr z,FINREUB
inc ix
inc iy
NEXT: inc ix ;Next byte to compare
inc iy ;(if we have replaced, we need to increment by 2)
call CHKCOMP
jr nz,BUCLE
FINREUB ret
CHKCOMP: exx
dec bc ;Decrement counter, and if 0
ld a,b ;return with Z=1
or c
exx
ret
;--- BASIC + CALL SYSTEM
; Input: HL = command to be executed after CALL SYSTEM
CALSYS: ld ix,SysCom
BUCSYSCOM: ld a,(hl) ;Search first character or terminating 0
inc hl
or a
jr z,OKBSC
cp " "
jr z,BUCSYSCOM
dec hl
BUCSYS2: ld (ix),a ;Copy characters until we find 0
inc ix
inc hl
ld a,(hl)
cp "&"
jr nz,NOANGLUNO
ld a,"^"
NOANGLUNO: or a
jr nz,BUCSYS2
ld (ix),34
ld (ix+1),")"
ld (ix+2),0
OKBSC:
;Do the CALL SYSTEM
ld hl,SystemProg
ld de,08000h
ld bc,0200h
ldir
jp 08000h
SystemProg:
ld a,(0FCC1h)
push af
ld h,0
call 024h
pop af
ld h,040h
call 024h
xor a
ld hl,0F41Fh
ld (0F860h),hl
ld hl,0F423h
ld (0F41Fh),hl
ld (hl),a
ld hl,0F52Ch
ld (0F421h),hl
ld (hl),a
ld hl,0F42Ch
ld (0F862h),hl
ld hl,08030h
jp 04601h
SysTxT: defb 03Ah,0CAh
defb "SYSTEM(",34
SysCom: db 34,")"
defb 0,01Ah
;--- Mapper support routines
ALL_SEG: ds 3
FRE_SEG: ds 3
RD_SEG: ds 3
WR_SEG: ds 3
CAL_SEG: ds 3
CALLS: ds 3
PUT_PH: ds 3
GET_PH: ds 3
PUT_P0: ds 3
GET_P0: ds 3
PUT_P1: ds 3
GET_P1: ds 3
PUT_P2: ds 3
GET_P2: ds 3
PUT_P3: ds 3
GET_P3: ds 3
;--- Strings
;TODO: Put your thing name here and get some credit!
PRESENT_s:
db "Filesystem driver for (YOUR HARDWARE/DEVICE HERE) 1.0",13,10
db "By (YOUR NAME HERE) and Konamiman, 5/2017",13,10
db 13,10
db "$"
TEMP: ds 5
;**************************
;--- END of installer ---
;**************************
;******************************
;--- BEGIN of page 3 code ---
;******************************
PARTRES: macro
INIRES@sym:
NEWBIO@sym: jp _NEWBIO@sym ;+0
OLDBIO@sym: ds 5 ;+3
OLDHBDOS@sym: ds 3 ;+8
RESLOT@sym: db 0 ;+11
RESEG@sym: db 0 ;+12
PUT_P1@sym: jp 0000h ;+13
GET_P1@sym: jp 0000h ;+16
NEWHM@sym: dw 0 ;+19
OLDHM@sym: dw 0 ;+21
;--- New H_BDOS hook
_NEWBDOS@sym: ;+23
ex af,af
ld a,c
cp _LOGIN
jr nz,NOLOGIN@sym
pop hl
ld de,NEXTLOGIN@sym
push de
jp (hl)
NEXTLOGIN@sym:
set 6,l ;WARNING: This depends on drive letter!
ret
NOLOGIN@sym:
push iy
ld a,c
cp _SELDSK
jr z,OKGO@sym
;cp _CURDRV
;jr z,OKGO@sym
cp _ALLOC
jr z,OKGO@sym
cp _WPATH
jr z,OKGO@sym
cp MINFN
jr c,POPEXRET@sym
cp MAXFN+1
jr c,OKGO@sym
POPEXRET@sym:
ex af,af
jr POPRET@sym
OKGO@sym:
call GETSLOT1@sym
push af
call GET_P1@sym
push af
ex af,af
push af,bc,de,hl,ix
ld a,(RESLOT@sym)
ld h,40h
call ENASLT
ld a,(RESEG@sym)
call PUT_P1@sym
pop ix,hl,de,bc,af
call DOSENTRY
ex af,af
ld a,iyl
or a
jp nz,PROCESSED@sym
ENDPROC@sym:
pop af
call PUT_P1@sym
ex af,af
pop iy
push af,bc,de,hl,ix
ld a,iyh
ld h,40h
call ENASLT
pop ix,hl,de,bc,af
POPRET@sym:
pop iy
ei
jp OLDHBDOS@sym
PROCESSED@sym:
exx
pop de ;segment
pop bc ;slot
pop hl ;original iy
pop iy ;ret from hook
inc iy ;skip CALL KBDOS in DOS code
inc iy
inc iy
push iy,hl,bc,de
exx
jp ENDPROC@sym
;--- New EXTBIO hook
; Input: D = IDNES
; E = IDNFS
; Output: HL= New HIGHMEM
; IX= Old HIGHMEM
; B = Slot of allocated segment
; C = Allocated segment number
; A = IDNES
; Modifiess: IX, IY, alternate regs
_NEWBIO@sym: push af
ld a,d
cp IDNES
jr nz,NOBIOS@sym
ld a,e
cp IDNFS
jr z,OKBIOS@sym
NOBIOS@sym: pop af
jp OLDBIO@sym
OKBIOS@sym: pop af
ld hl,(NEWHM@sym)
ld ix,(OLDHM@sym)
ld a,(RESLOT@sym)
ld b,a
ld a,(RESEG@sym)
ld c,a
ld a,IDNES
ret
;--- Get slot in page 1
GETSLOT1@sym:
exx
in a,(0A8h)
ld e,a
and %00001100
sra a
sra a
ld c,a ;C = Slot
ld b,0
ld hl,EXPTBL
add hl,bc
bit 7,(hl)
jr z,NOEXP@sym
EXP@sym: inc hl
inc hl
inc hl
inc hl
ld a,(hl)
and %00001100
or c
or 80h
ld c,a
NOEXP@sym: ld a,c
exx
ret
ENDRES@sym:
endm
RESCODE1: PARTRES
RESCODE2: PARTRES
;******************************
;--- END of page 3 code ---
;******************************
;*******************************
;--- BEGIN of segment code ---
;*******************************
PARTRE2: org 4000h
;---------------------------------------------------------------
;>>>>>>> HEADER - do NOT change as emulators hook here <<<<<<<
;---------------------------------------------------------------
db "FileSysDriver",0
db 0,1 ;Specification version complied, main+sec
ds 16
JMP_ALLOC: jp IMPL_ALLOC
JMP_FFIRST: jp IMPL_FFIRST
JMP_FNEXT: jp IMPL_FNEXT
JMP_CHDIR: jp IMPL_CHDIR
JMP_GETCD: jp IMPL_GETCD
JMP_GETVOL: jp IMPL_GETVOL
;----------------------------------
;>>>>>>> H_BDOS hook code <<<<<<<
;----------------------------------
DOSENTRY:
ld iy,DOESNTRY_END
push iy
ex af,af
ld a,c
cp _SELDSK
jp z,DO_SELDSK
;cp _CURDRV
;jp z,DO_CURDRV
cp _ALLOC
jp z,DO_ALLOC
cp _FFIRST
jp z,DO_FFIRST
cp _FNEXT
jp z,DO_FNEXT
cp _GETCD
jp z,DO_GETCD
cp _CHDIR
jp z,DO_CHDIR
cp _WPATH
jp z,DO_WPATH
pop iy
DONOTHING: ;Non-hooked function: do nothing
ld iy,0
EX_AND_RET:
ex af,af
ret
DOESNTRY_END:
ex af,af
ld a,iyl
or a
jr z,EX_AND_RET
;In case of disk error (A >= F0h), clear caches
ex af,af
exx
ld d,a
and 0F0h
cp 0F0h
ld a,d
exx
ret nz
ex af,af
xor a
ld (CURDIR_IS_CACHED),a
ld (VOLABEL_IS_CACHED),a
ex af,af
ret
;-------------------------------------------
;>>>>>>> DOS function replacements <<<<<<<
;-------------------------------------------
;These are executed INSTEAD OF the original DOS functions implementations.
;Input/output is similar, but not always identical, to the public API
;(DOS does some processing before calling the hook).
;Code in this section is device/hardware independent,
;so you do NOT need to change it.
;They all return IY=0 if the function was not processed
;(so DOS needs to handle it) or IY=1 if the function
;was processed (so DOS must skip it).
;--- SELECT DISK (0EH)
; Parameters: C = 0EH (_SELDSK)
; E = Drive number. 0=A: 1=B: etc.
; Results: A = Error code
; L = Number of drives (1...8)
DO_SELDSK:
ex af,af
ld a,e
and %11111000
ld iy,0
ret nz ;Bad drive number
ld a,(INDRIVE0) ;Setting my drive as current?
cp e
jr z,SELDSK_ISMINE
xor a
ld (CUR_IS_MINE),a ;No: CUR_IS_MINE=false and let DOS handle it
ret
SELDSK_ISMINE:
ld a,e
inc a
ld (CUR_DRV),a
ld a,0FFh
ld (CUR_IS_MINE),a ;Yes: CUR_IS_MINE=false and DON'T let DOS handle it
inc iy ;(since that could cause "Invalid drive" error)
ld hl,(0F347h)
xor a
ld h,a
ret
;--- GET CURRENT DRIVE (19H)
; Parameters: C = 19H (_CURDRV)
; Results: A = Error code
; L = Current drive (0=A: etc)
DO_CURDRV:
ex af,af
ld a,(CUR_IS_MINE)
ld iy,0
or a
ret z
ld hl,(INDRIVE0)
xor a
ld l,a
inc iy
ret
;--- GET ALLOCATION INFORMATION (1BH)
; Parameters: C = 1BH (_ALLOC)
; E = drive number (0=default)
; Results: A = Error code
; C = Sectors/cluster (0FFh if any error)
; DE = Total number of clusters
; HL = Number of free clusters
; IX = Pointer to MSX-DOS 1.0 compatible DPB (NO!)
; IY = Pointer to first FAT sector in a page-3 buffer (NO!)
DO_ALLOC:
ex af,af
ld a,e
call ISMYDRIVE
ld iy,0
ret nz
call JMP_ALLOC
ld iy,1
ret
;--- FIND FIRST ENTRY (40H)
; Parameters: C = 40H (_FFIRST)
; DE = Drive/path/file ASCIIZ string
; or fileinfo block pointer
; HL = filename ASCIIZ string (only if
; DE = fileinfo pointer)
; B = Search attributes
; IX = Pointer to new fileinfo block
; Results: A = Error
; (IX) = Filled in with matching entry
DO_FFIRST:
ex af,af
xor a
ld (FIND_STAT),a ;Assume not for me, or error, to start with
ld hl,(LAST_FIB_SERIAL)
inc hl
ld (ix+28),l
ld (ix+29),h
ld a,(de)
cp 0FFh
jr z,FFIRST_FIB
;--- Path/file based search, DE points past the drive if any
push hl
call DRV_IN_PATH_MINE
pop hl
ld iy,0
ret nz
bit 3,b
jp nz,FFIRST_GETVOL
FFIRST_PATH:
ld hl,FFIRST_BUF
push de,bc,ix
call PROCESS
pop ix,bc,de
or a
ret nz
push de
ld hl,FFIRST_BUF
ld de,WPATH_BUF
ld bc,MAX_PATH_LEN+1
ldir
pop de
ld iy,FFIRST_BUF
push ix
call JMP_FFIRST
pop ix
ld iy,1
or a
jr z,FFIRST_PATH_OK
cp __PLONG
ret nz
ld b,a
ld a,2
ld (FIND_STAT),a
ld a,b
ret
FFIRST_PATH_OK:
jr FFIRST_END
;--- FIB based search
FFIRST_FIB:
push de
pop iy
ld a,(INDRIVE1)
cp (iy+25)
ld a,(iy+14)
ld iy,0
ret nz
ld c,a
bit 4,c ;FIB must specify a directory
ld a,__IATTR
ret z
bit 3,c ;FIB can't specify a volume name
ret nz
push de,hl
ld hl,WPATH_BUF
ld bc,(WPATH_LEN)
add hl,bc
ld (hl),SLASH
inc hl
ex de,hl ;HL = filename, DE = end of WPATH
pop hl
ld a,(hl)
or a
jr nz,FFIRST_NOEMP
ld hl,AST_DOT_AST
FFIRST_NOEMP:
push hl
ld bc,13
ldir ;append filename to WPATH
pop hl,de
push ix
ld iy,WPATH_BUF
call JMP_FFIRST
pop ix
ld iy,1
or a
ret nz
;--- Common wrapup
FFIRST_END:
ld d,a
ld de,WPATH_BUF
call STRLEN
ld a,__PLONG
ret c
ld a,d
ld (WPATH_LEN),bc
ld de,WPATH_BUF
call GLAST
ld de,WPATH_BUF
or a
sbc hl,de
ld (WPATH_PATH_LEN),hl
FFIRST_END2:
ld a,(INDRIVE1)
ld (ix+25),a
ld a,1
ld (FIND_STAT),a