@@ -38,7 +38,6 @@ include 'macros.inc'
38
38
virtual at 0
39
39
FAT_SUCCESS rb 1
40
40
FAT_ERROR_INVALID_PARAM rb 1
41
- FAT_ERROR_NOT_SUPPORTED rb 1
42
41
FAT_ERROR_INVALID_CLUSTER rb 1
43
42
FAT_ERROR_INVALID_POSITION rb 1
44
43
FAT_ERROR_NOT_FOUND rb 1
@@ -51,6 +50,9 @@ virtual at 0
51
50
FAT_ERROR_RDONLY rb 1
52
51
FAT_ERROR_RW_FAILED rb 1
53
52
FAT_ERROR_INVALID_FILESYSTEM rb 1
53
+ FAT_ERROR_INVALID_SIZE rb 1
54
+ FAT_ERROR_INVALID_MAGIC rb 1
55
+ FAT_ERROR_INVALID_SIGNATURE rb 1
54
56
FAT_ERROR_NO_MORE_ENTRIES rb 1
55
57
end virtual
56
58
virtual at 0
@@ -172,21 +174,26 @@ fat_Open:
172
174
xor a , a
173
175
sbc hl , hl
174
176
call util_read_fat_block ; read fat zero block
177
+ jr z , .read_zero_block
175
178
ld hl , FAT_ERROR_RW_FAILED
176
- jq nz , .error
179
+ pop ix
180
+ ret
181
+ .read_zero_block:
177
182
lea ix , yf at .buffer
178
183
ld a , (ix + 12 )
179
184
cp a , (ix + 16 ) ; ensure 512 byte blocks and 2 FATs
180
- jq nz , .error
185
+ jr z , .goodf at
186
+ ld hl , FAT_ERROR_INVALID_FILESYSTEM
187
+ pop ix
188
+ ret
189
+ .goodf at :
181
190
ld a , (ix + 39 )
182
191
or a , a ; can't support reallllly big drives (BPB_FAT32_FATSz32 high)
183
- jq nz , .error
184
- ld a , (ix + 66 )
185
- cp a , $ 28 ; check fat32 signature
186
- jr z , .goodsig
187
- cp a , $ 29
188
- jq nz , .error
189
- .goodsig:
192
+ jr z , .goodsize
193
+ ld hl , FAT_ERROR_INVALID_SIZE
194
+ pop ix
195
+ ret
196
+ .goodsize:
190
197
xor a , a
191
198
ld b , a
192
199
ld hl , (ix + 14 )
@@ -226,14 +233,26 @@ fat_Open:
226
233
ld (yf at .fs_info) , hl
227
234
xor a , a
228
235
call util_read_fat_block
229
- jr nz , .error
236
+ jr z , .check_magic
237
+ ld hl , FAT_ERROR_RW_FAILED
238
+ pop ix
239
+ ret
240
+ .check_magic:
230
241
call util_checkmagic
231
- jr nz , .error ; uh oh!
242
+ jr z , .goodmagic
243
+ ld hl , FAT_ERROR_INVALID_MAGIC
244
+ pop ix
245
+ ret
246
+ .goodmagic:
232
247
ld hl , (ix + 0 ) ; ix should still point to the temp block...
233
248
ld bc , $ 615252 ; don't bother comparing $41 byte...
234
249
xor a , a
235
250
sbc hl , bc
236
- jr nz , .error
251
+ jr z , .goodsig
252
+ ld hl , FAT_ERROR_INVALID_SIGNATURE
253
+ pop ix
254
+ ret
255
+ .goodsig:
237
256
scf
238
257
sbc hl , hl
239
258
ex de , hl
@@ -253,10 +272,6 @@ fat_Open:
253
272
xor a , a
254
273
sbc hl , hl ; return success
255
274
ret
256
- .error:
257
- ld hl , FAT_ERROR_INVALID_FILESYSTEM
258
- pop ix
259
- ret
260
275
261
276
;-------------------------------------------------------------------------------
262
277
fat_Close:
@@ -540,10 +555,14 @@ fat_GetVolumeLabel:
540
555
ld (yf at .working_block) , a , hl
541
556
ld b , (yf at .blocks_per_cluster)
542
557
.findblock:
543
- push bc
544
558
ld (yf at .working_block) , a , hl
559
+ push bc
545
560
call util_read_fat_block
546
- jq nz , .rw_error
561
+ jr z , .rd_success
562
+ pop bc
563
+ ld hl , FAT_ERROR_RW_FAILED
564
+ ret
565
+ .rd_success:
547
566
lea hl , yf at .buffer + 11
548
567
ld b , 16
549
568
ld de , 32
@@ -584,11 +603,7 @@ fat_GetVolumeLabel:
584
603
jq .removetrailingspaces
585
604
.done:
586
605
xor a , a
587
- sbc hl , hl
588
- ret
589
- .rw_error:
590
- pop bc
591
- ld hl , FAT_ERROR_RW_FAILED
606
+ sbc hl , hl ; return success
592
607
ret
593
608
594
609
;-------------------------------------------------------------------------------
@@ -608,7 +623,10 @@ fat_OpenFile:
608
623
ld iy , (iy + 3 )
609
624
call util_locate_entry
610
625
pop iy
611
- jq z , .error
626
+ jr nz , .found
627
+ ld hl , FAT_ERROR_NOT_FOUND
628
+ ret
629
+ .found:
612
630
ld bc , (iy + 3 )
613
631
ld iy , (iy + 12 )
614
632
ld (yfatFile.f at ) , bc
@@ -644,9 +662,6 @@ fat_OpenFile:
644
662
ld (yfatFile.cluster_block) , a
645
663
ld (yfatFile.block_pos) , hl ; return success
646
664
ret
647
- .error:
648
- ld hl , FAT_ERROR_NOT_FOUND
649
- ret
650
665
651
666
;-------------------------------------------------------------------------------
652
667
fat_SetFileSize:
@@ -718,7 +733,10 @@ fat_SetFileSize:
718
733
call util_next_cluster
719
734
compare_auhl_zero
720
735
pop bc
721
- jq z , .failedchain ; the filesystem is screwed up
736
+ jr nz , .goodchain ; the filesystem is screwed up
737
+ ld hl , FAT_ERROR_CLUSTER_CHAIN
738
+ ret
739
+ .goodchain:
722
740
dec bc
723
741
.entertraverseclusters:
724
742
compare_bc_zero
@@ -748,11 +766,14 @@ fat_SetFileSize:
748
766
compare_auhl_zero
749
767
pop iy
750
768
pop hl
751
- jq z , .failedalloc
769
+ jr nz , .goodalloc
770
+ ld hl , FAT_ERROR_FAILED_ALLOC
771
+ ret
772
+ .goodalloc:
752
773
dec hl
753
774
compare_hl_zero
754
775
jq nz , .allocateclusters
755
- jq .success
776
+ ; jq .success
756
777
.success:
757
778
ld iy , (iy + 3 )
758
779
ld a , hl , (yfatFile.entry_block) ; read the entry again for open
@@ -790,15 +811,7 @@ fat_SetFileSize:
790
811
call util_ceil_byte_size_to_blocks_per_cluster
791
812
pop iy
792
813
ret
793
- .failedchain:
794
- ld hl , FAT_ERROR_CLUSTER_CHAIN
795
- ret
796
- .invalidpath:
797
- ld hl , FAT_ERROR_INVALID_PATH
798
- ret
799
- .failedalloc:
800
- ld hl , FAT_ERROR_FAILED_ALLOC
801
- ret
814
+
802
815
.currentcluster:
803
816
dd 0
804
817
0 commit comments