fat16 working

This commit is contained in:
Dennis Gunia
2024-01-25 00:12:46 +01:00
parent 507eb3a017
commit 488efa3907
33 changed files with 10561 additions and 6941 deletions

View File

@@ -7,24 +7,42 @@ MEM_FAT_AMOUNT: ; Amount of FATs (1byte)
defs 1
MEM_FAT_SECTORS: ; Length of FAT (2byte)
defs 2
MEM_FAT_CLUSTERLEN: ; Length of Cluster (1byte)
defs 1
MEM_FAT_COUNT1: ; Counter Var for reading FAT (2byte)
defs 1
MEM_FAT_TMPPOINTER: ; Temporary working pointer
defs 4
MEM_FAT_TMPPOINTER1: ; Temporary working pointer
MEM_FAT_DATASTART: ; Start of data area
defs 4
MEM_FAT_ROOTSTART: ; Start of Root directory
defs 4
MEM_FAT_FILEREMAIN: ; Remaining sectors in file
defs 4
MEM_FAT_DIRSEC: ; Sectors per directory
defs 2
MEM_FAT_TMPFNAME: ; Temporary filename
defs 16
MEM_FAT_CURDIR: ; Current Directory
defs 80
MEM_FAT_OF0_ATTRIBUTE: ;Current file attribute
defw 0
MEM_FAT_OF0_CCLUST: ;Current cluster of file
defw 0
MEM_FAT_OF0_FATSEC: ;Current sector in FAT
defs 4
MEM_FAT_OF0_DATSEC: ;Current sector in Data
defs 4
MEM_FAT_OF0_DATREM: ;Remaining sector in Data
defs 2
MEM_FAT_OF0_DATREM: ;Remaining bytes in Data
defs 4
MEM_FAT_CURRDIR: ;Current directory
defs 4
MEM_FAT_EXEC_CURR:
defw 0
MEM_FAT_EXEC_COUNT:
defw 0
MEM_FAT_EXEC_START:
defw 0
dephase
@@ -34,10 +52,10 @@ MEM_FAT_OF0_DATREM: ;Remaining sector in Data
fat_get_root_table:
call fat_reset_pointer ;reset fat pointer
;call fat_print_dbg
; Load first sector on active partition
LD HL, MEM_IDE_POINTER ; pointer to LBA address
LD A,1 ;read 1 sector
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
; check for valid Boot sector
@@ -45,13 +63,10 @@ fat_get_root_table:
cp 0xEB ;first byte should be 0xEB
jp nz, _fat_get_root_table_invalid
;debug sector
;ld hl, MEM_IDE_BUFFER
;ld b,20
;call dump_pretty
; Read and store FS Properties
LD IX,MEM_IDE_BUFFER
LD A,(IX+0x0D)
LD (MEM_FAT_CLUSTERLEN),A
LD A,(IX+0x0E)
LD (MEM_FAT_RESERVED),A
LD A,(IX+0x0F)
@@ -63,28 +78,95 @@ fat_get_root_table:
LD A,(IX+0x17)
LD (MEM_FAT_SECTORS+1),A
;Get Root FAT
LD A, (MEM_FAT_SECTORS+1) ; load FAT Sector size to DE
LD D,A
LD A, (MEM_FAT_SECTORS)
LD E,A
XOR A ; clear HL
LD H,A
LD L,A
LD A,(MEM_FAT_AMOUNT) ; Load counter for multiplication
LD B,A
_fat_get_root_table_loop: ; multiply
ADD HL,DE
DJNZ _fat_get_root_table_loop
;Get Data Start Sector
;calculate fat length
ld bc,(MEM_FAT_SECTORS)
ld a,(MEM_FAT_AMOUNT) ;add fat to cluster number
ld d,0
ld e,a
call _fat_math_mul32
; BCHL contains result -> store to PTR.MEM_FAT_ROOTSTART
ld (MEM_FAT_ROOTSTART+0),hl
ld (MEM_FAT_ROOTSTART+2),bc
; add reserved sectors
LD D,0
LD A,(MEM_FAT_RESERVED)
LD E,A
ADD HL,DE
;add offset (reserved sectors)
ld hl,(MEM_IDE_BUFFER +0x0E) ; load sectors into hl
ld (MEM_FAT_TMPPOINTER), hl
xor a
ld (MEM_FAT_TMPPOINTER+2),a
ld (MEM_FAT_TMPPOINTER+3),a
ld bc,[MEM_FAT_ROOTSTART]
ld de,[MEM_FAT_TMPPOINTER]
call _fat_math_add32 ;MEM_FAT_ROOTSTART now contains the first sector
;of the Root directory
;add offset (partition location)
call ideif_get_drv_pointer
inc ix
inc ix
push ix
pop de ;copy poiter to hl
ld bc,[MEM_FAT_ROOTSTART]
call _fat_math_add32 ;MEM_FAT_OF0_DATSEC now contains the first sector
;of the cluster
;copy value from MEM_FAT_ROOTSTART to MEM_IDE_POINTER
ld hl,MEM_FAT_ROOTSTART
ld de,MEM_IDE_POINTER
ldi
ldi
ldi
ldi
;copy value from MEM_FAT_ROOTSTART to MEM_IDE_POINTER
ld hl,MEM_FAT_ROOTSTART
ld de,MEM_FAT_DATASTART
ldi
ldi
ldi
ldi
ld hl,MEM_FAT_ROOTSTART
ld de,MEM_FAT_CURRDIR
ldi
ldi
ldi
ldi
;add offset to data area
;multiply cluster by length of cluster
;calculate sectors for root dir
ld hl,(MEM_IDE_BUFFER+0x11) ;load Maximum root directory entries
ld a,h
ld l,a
xor a ;set a 0, clear carry flag
ld h,a ;shift right by 8 bit = /512
;last step: multiply by 16
ex de,hl
ld bc,16
call _fat_math_mul32
; BCHL contains result -> store to PTR.MEM_FAT_TMPPOINTER
ld (MEM_FAT_TMPPOINTER+0),hl
ld (MEM_FAT_TMPPOINTER+2),bc
ld (MEM_FAT_DIRSEC),hl
; add offset to MEM_FAT_DATASTART
ld de,[MEM_FAT_TMPPOINTER]
ld bc,[MEM_FAT_DATASTART]
call _fat_math_add32 ;MEM_FAT_DATASTART now contains the correct sector
;at teh beginnig of the data area
;done all FS vars populated
;navigate to root directory
ld a,'\'
ld(MEM_FAT_CURDIR),a
xor a
ld(MEM_FAT_CURDIR+1),a
; add
call _fat_math_sector_add_16
ret
_fat_get_root_table_invalid:
@@ -95,14 +177,21 @@ _fat_get_root_table_invalid:
ret
;-------------------------------------
; Print current fat directory of MEM_IDE_POINTER
; Print current fat directory of MEM_FAT_CURRDIR
;-------------------------------------
fat_print_directory:
ld hl,MEM_FAT_CURRDIR
ld de,MEM_IDE_POINTER
ldi
ldi
ldi
ldi
LD DE,(MEM_FAT_SECTORS)
LD (MEM_FAT_COUNT1),DE
LD HL,MEM_IDE_POINTER ;read first sector
LD B,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
call PRINTINLINE
@@ -209,6 +298,8 @@ _fat_print_directory_loop_next_sector: ; end fo sector. read next sector from d
LD HL,MEM_IDE_POINTER ;read next sector
LD B,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
LD HL, MEM_IDE_BUFFER ;set buffer start
@@ -226,83 +317,165 @@ _fat_print_directory_loop_break_dirty
; call print_str ;print
ret
;-------------------------------------
; FAT locate file startcluster
;
; DE pointer to file name
;-------------------------------------
fat_lfs:
PUSH DE
LD HL,[MEM_FAT_TMPFNAME] ; prepare filename
CALL format_filename_fat16
LD A,16 ;init counter for FAT sectors
LD (MEM_FAT_COUNT1),A
LD HL,MEM_IDE_POINTER ;read first sector
LD B,1
call read_lba_sector
LD HL, MEM_IDE_BUFFER ;set buffer start
LD C,16 ;set entries counter
_fat_lfs_loop:
POP DE
PUSH DE
CALL compare_filename
JR C, _fat_lfs_loop_compare_match ;on match
; prepare next entry
DEC C ;next sector after 16 entries
JR Z,_fat_lfs_loop_compare_next_sector
LD DE, 32 ;length of entry
ADD HL,DE ;increment
JP _fat_lfs_loop
_fat_lfs_loop_compare_next_sector:
LD H,0
LD L,1
call _fat_math_sector_add_16 ;increment sector
LD A,(MEM_FAT_COUNT1) ; decrement sector count (max FAT length)
DEC A
LD (MEM_FAT_COUNT1),A
JP Z, _fat_lfs_loop_compare_end ; if DE is 0, mmax is reached. End here
;call print_a_hex
LD HL,MEM_IDE_POINTER ;read next sector
LD B,1
call read_lba_sector
LD HL, MEM_IDE_BUFFER ;set buffer start
LD C,16 ;set entries counter
JP _fat_lfs_loop
_fat_lfs_loop_compare_end:
POP DE
LD HL, [str_file_notfound]
CALL print_str ;print
RET
_fat_lfs_loop_compare_match:
; get entry
POP DE
LD B,8
call print_str_fixed
ld A,'.'
call print_char
LD B,3
call print_str_fixed
LD HL, [str_file_found]
CALL print_str ;print
RET
; fat change directory
; relative path
; DE pointer to path
fat_cd_single:
push de
; check if user wants to go back (input = '..')
ld a,(de)
cp '.'
jr nz, _fat_cd_navigate; if not, skip
inc de ;check next
ld a,(de)
cp '.'
jr nz, _fat_cd_navigate; if not, skip
ld a,(var_dir+79) ;last byte contains depth
or a; Test if 0
jp z, _fat_cd_navigate_error ;cannot go back any more (already at root)
; check if .. exists in directory
ld a,'.' ;prepare filename buffer
ld hl,[MEM_FAT_TMPFNAME]
ld (hl),a
inc hl
ld (hl),a
inc hl
ld a,0x20 ;clear char 3-11
ld b,11
_fat_cd_navigate_goback_fl:
ld (hl),a
inc hl
djnz _fat_cd_navigate_goback_fl ;fill loop end
call fat_openfile_noprepare ;load file table (only 1st sector needed)
or a ;check for error
jp nz, _fat_cd_navigate_error ;entry not found exception
; find end of path
ld hl,[var_dir+3] ;current position
ld bc,76
ld a,0x00 ;termination char
cpir ;find end
jp po,_fat_cd_navigate_inerror ;in case of error, abort
;hl is now at end of string
ld bc,76
ld a,'\' ;seperation char
cpdr ;serach backwards for "/"
jp po,_fat_cd_navigate_inerror ;in case of error, abort
;hl is now at end of string
inc hl
xor a
ld (hl),a ;set termination char
inc hl
ld (hl),a ;set termination char
ld a,(var_dir+79)
dec a
ld (var_dir+79),a ;decrement dir depth counter
pop de
ld hl,[var_dir+2]
ld a,'\'
ld (hl),a ;set first /
ld hl,MEM_FAT_OF0_DATSEC ;setup directory pointer
ld de,MEM_FAT_CURRDIR
ldi
ldi
ldi
ldi
ret
_fat_cd_navigate
pop de ;get pointer to directory namme
push de ;and re-store it for next use
call fat_openfile ;find 'file' in current directory
_fat_cd_navigate_findsec
or a
jp nz, _fat_cd_navigate_error ;entry not found
ld a, (MEM_FAT_OF0_ATTRIBUTE)
cp 0x10
jp nz, _fat_cd_navigate_errfile
ld a,(var_dir+79)
inc a
ld (var_dir+79),a ;increment dir depth counter
ld hl,[var_dir+2] ;load start of path string
ld a,0 ;load termination char
ld bc,76 ;max length of string
cpir ;find end of path string
dec hl
jp po,_fat_cd_navigate_inerror ;in case of error, abort
;HL now has last element, BC has remaining max length
ld a,(var_dir+79) ;last byte contains depth
cp 1 ;if first path, skip /
jr z, _fat_cd_navigate_findsec_skipslash
ld a,'\'
ld (hl),a
inc hl
_fat_cd_navigate_findsec_skipslash
pop de ;get argument from stack
ex de,hl
push de ;store start to stack
;HL now has start of input string, DE has end of current path
ld bc,09 ;maximum length of directory name +1
_fat_cd_navigate_l2: ;copy new subdirectory
ldi ;copy
jp po,_fat_cd_navigate_inerrorS ;in case of error, abort
ld a,(hl) ;check next char
cp '\' ;end at '\'
jr z, _fat_cd_navigate_end ;else next byte
or a ;or and at 0x00
jr z, _fat_cd_navigate_end ;else next byte
jr _fat_cd_navigate_l2
_fat_cd_navigate_end:
xor a
ld (de),a ;set last byte to 0x00 (termination)
ld hl,MEM_FAT_OF0_DATSEC
;setup directory pointer
ld de,MEM_FAT_CURRDIR
ldi
ldi
ldi
ldi
pop de ;stack cleanup
ret
_fat_cd_navigate_error:
ld hl,[_fat_cd_navigate_error_str]
call print_str
pop de
ret
_fat_cd_navigate_inerrorS: ;with path reset
pop de ;restore former path
dec de ;change pointer to remove previous '\' as well
xor a ;clear a to 0x00
ld (de),a ;set last byte to 0x00 (termination)
jr _fat_cd_navigate_inerrore
_fat_cd_navigate_inerror: ;without path reset
pop de
_fat_cd_navigate_inerrore:
ld hl,[_fat_cd_navigate_inputerr_str]
call print_str
ret
_fat_cd_navigate_errfile:
pop de
ld hl,[_fat_cd_navigate_errfile_str]
call print_str
ret
_fat_cd_navigate_error_str:
db 10,13,"No such directory!",10,13,0
_fat_cd_navigate_inputerr_str:
db 10,13,"Invalid input!",10,13,0
_fat_cd_navigate_errfile_str:
db 10,13,"Cannot cd to file!",10,13,0
;=================== UTIL Functions ===========================
; 32 Bit addition to pointer
; HL has value
;deprecated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
_fat_math_sector_add_16:
ld (MEM_FAT_TMPPOINTER), hl
xor a
@@ -313,7 +486,26 @@ _fat_math_sector_add_16:
ld bc,[MEM_IDE_POINTER]
call _fat_math_add32
ret
;deprecated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;hl contains pointer
_fat_increment_32
ld a,(HL) ; byte 0
add 1
ld (hl),a
inc hl
ld a,(HL) ; byte 1
adc 0
ld (hl),a
inc hl
ld a,(HL) ; byte 2
adc 0
ld (hl),a
inc hl
ld a,(HL) ; byte 3
adc 0
ld (hl),a
ret
;bc contains pointer to a (also result)
;de contains pointer to b
_fat_math_add32
@@ -369,6 +561,30 @@ _fat_math_add32
pop hl
ret
; Multiply 16-bit values (with 32-bit result)
; Operands BC, DE
; Result -> BCHL
_fat_math_mul32:
ld a,c
ld c,b
ld hl,0
ld b,16
_fat_math_mul32_l:
add hl,hl
rla
rl c
jr nc,_fat_math_mul32_noadd
add hl,de
adc a,0
jp nc,_fat_math_mul32_noadd
inc c
_fat_math_mul32_noadd:
djnz _fat_math_mul32_l
ld b,c
ld c,a
ret
; reset LBA pointer to first sector in selected partition
fat_reset_pointer:
call ideif_get_drv_pointer
@@ -390,73 +606,3 @@ fat_copy_lba_pointer:
POP BC
ret
; compares filenames
; HL points to name1
; DE points to name2
; Carry is set if match
; Destroys DE, AF
compare_filename:
PUSH HL
PUSH BC
LD B, 11 ;Counter
_compare_filename_loop:
LD A,(DE)
LD C,A
LD A,(HL)
XOR C ;check if identical (should return 0)
JR NZ, _compare_filename_nomatch
DEC B ;decrement counter
JR NZ, _compare_filename_loop ;if not last, continue
POP BC ;if last, it matches
POP HL
SCF
RET
_compare_filename_nomatch:
POP BC
POP HL
SCF
CCF
RET
; formats filename to 8+3 format
; DE points to source filename to string
; HL points to destination
format_filename_fat16:
LD B, 11 ;counter
PUSH HL
XOR A
_format_filename_fat16_clean:
LD (HL),A
INC HL
DJNZ _format_filename_fat16_clean
POP HL ; continue with copy
LD B, 13
_format_filename_fat16_loop:
LD A, (DE) ; load byte
OR A
RET Z ;exit on 0byte
DEC B ;reduce counter
RET Z ;exit after 12 bytes 8+.+3
CP '.' ; check if dot
JR NZ, _format_filename_fat16_loop_copy ; if not continue as usual
INC DE ;else skip char
_format_filename_fat16_loop_skip_8:
LD A,B
CP 5
JR C, _format_filename_fat16_loop
INC HL
DEC B
JR _format_filename_fat16_loop_skip_8
_format_filename_fat16_loop_copy:
LD A, (DE) ; load byte
LD (HL), A ; copy byte
INC HL
INC DE
JP _format_filename_fat16_loop
str_file_notfound:
db "File not found!",13,10,0
str_file_found:
db " File located!",13,10,0

View File

@@ -11,10 +11,23 @@
; store result in MEM_FAT_OF0_FATSEC
; stores next cluster in MEM_FAT_OF0_CCLUST
fat_getfatsec:
ld HL,(MEM_FAT_OF0_CCLUST) ;load cluster
ld a,h ;if not 0x0000
or l
jp nz, _fat_getfatsec_notroot
;if 0x0000, goto root directory
ld hl,MEM_FAT_ROOTSTART
ld de,MEM_FAT_OF0_DATSEC
ldi ;quick and dirty hack to go back to root directory
ldi
ldi
ldi
ret
_fat_getfatsec_notroot:
ld HL,(MEM_FAT_OF0_CCLUST) ;load cluster
;each sector contains 256 clusters
;first 8bits are not needed (/256)
ld a,h ;divide by 256
ld l,a
xor a
@@ -22,7 +35,7 @@ fat_getfatsec:
ld bc,(MEM_FAT_RESERVED) ;add reserved sectors
add hl,bc
ld(MEM_FAT_OF0_FATSEC+0),hl;store sector to MEM_FAT_TMPPOINTER1
ld(MEM_FAT_OF0_FATSEC+0),hl;store sector
xor a
ld(MEM_FAT_OF0_FATSEC+2),a
ld(MEM_FAT_OF0_FATSEC+3),a
@@ -36,17 +49,40 @@ fat_getfatsec:
call _fat_math_add32 ;MEM_FAT_OF0_FATSEC now contains the correct sector
;in the FAT
call fat_print_dbg
;read FAT sector
ld hl,MEM_FAT_OF0_FATSEC ;read next sector
ld b,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
ld hl, MEM_IDE_BUFFER
ld b,20
call dump_pretty
;calculate data sector
;multiply cluster by length of cluster
xor a ;clear carry
ld a,(MEM_FAT_CLUSTERLEN)
ld b,0
ld c,a
ld de,(MEM_FAT_OF0_CCLUST) ;load cluster number
dec de ; sub 2 becaus fat starts at 3
dec de
call _fat_math_mul32
; BCHL contains result -> store to PTR.MEM_FAT_OF0_DATSEC
ld (MEM_FAT_OF0_DATSEC+0),hl
ld (MEM_FAT_OF0_DATSEC+2),bc
; add start of data region to addr
ld bc,[MEM_FAT_OF0_DATSEC]
ld de,[MEM_FAT_DATASTART]
call _fat_math_add32 ;MEM_FAT_OF0_FATSEC now contains the correct sector
;in the FAT
;MEM_FAT_OF0_DATSEC now has the first sector of the selected cluster
;reset MEM_FAT_OF0_DATREM to default cluster length
ld a,(MEM_FAT_CLUSTERLEN)
ld l,a
ld h,0
ld (MEM_FAT_OF0_DATREM), hl
;get next cluster
;calculate offset address
ld a,(MEM_FAT_OF0_CCLUST)
RLA ;shift to left (x2)
@@ -56,14 +92,234 @@ fat_getfatsec:
ld h,a
ld de,MEM_IDE_BUFFER
add hl,de
;copy pointer
;copy pointer (hl to de)
ld de,MEM_FAT_OF0_CCLUST
ldi ;copy byte for next cluster from FAT
ldi
call fat_print_dbg
ret
;store data
; reads single sector of file
; must run fat_readfilesec before to initialize
; if a ix 0x00, success
; if a is 0xFF, end reached
fat_readfilesec:
call fat_print_dbg
ld hl,[MEM_FAT_OF0_DATSEC]
ld b,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector ;read sectore
ld hl,[MEM_FAT_OF0_DATSEC] ;increment pointer to next sector
call _fat_increment_32 ;***
ld hl,(MEM_FAT_OF0_DATREM) ;reduce counter
xor a
ld de,1
sbc hl,de ;decrement counter
ld (MEM_FAT_OF0_DATREM),hl ;store decremented counter
ret nz ;when not zero, exit function
;if zero:
ld a, 0xFF ;preload error code
ld hl,(MEM_FAT_OF0_CCLUST) ;check next chunk
ld de,0xFFFF ;end mark
sbc hl,de ;if Z match
ret z ;If 0xFFFF, end is reched. Return
;if next cluster available:
xor a
call fat_getfatsec ; read next cluster information
ret
;-------------------------------------
; FAT open file
;
; DE pointer to file name
;-------------------------------------
fat_openfile:
PUSH DE
;MEM_FAT_TMPFNAME now has valid text to compare
LD HL,[MEM_FAT_TMPFNAME]
call format_filename_fat16
POP DE
fat_openfile_noprepare:
PUSH DE
;prepare pointer
ld hl,MEM_FAT_CURRDIR
ld de,MEM_IDE_POINTER
ldi
ldi
ldi
ldi
LD A,(MEM_FAT_DIRSEC) ;init counter for FAT sectors
LD (MEM_FAT_COUNT1),A
LD HL,MEM_IDE_POINTER ;read first sector
LD B,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
;LD HL,MEM_IDE_BUFFER ;Dump IDE Buffer
;LD B,32
;call dump_pretty
;LD HL,MEM_FAT_TMPFNAME ;Dump IDE Buffer
;LD B,1
;call dump_pretty
LD HL, MEM_IDE_BUFFER ;set buffer start
LD C,16 ;set entries counter
_fat_lfs_loop:
LD DE,[MEM_FAT_TMPFNAME]
CALL compare_filename
JR C, _fat_lfs_loop_compare_match ;on match
; prepare next entry
DEC C ;next sector after 16 entries
JR Z,_fat_lfs_loop_compare_next_sector
LD DE, 32 ;length of entry
ADD HL,DE ;increment
JP _fat_lfs_loop
_fat_lfs_loop_compare_next_sector:
ld hl,[MEM_IDE_POINTER]
call _fat_increment_32 ;increment sector
LD A,(MEM_FAT_COUNT1) ; decrement sector count (max FAT length)
DEC A
LD (MEM_FAT_COUNT1),A
JP Z, _fat_lfs_loop_compare_end ; if DE is 0, mmax is reached. End here
;call print_a_hex
LD HL,MEM_IDE_POINTER ;read next sector
LD B,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
LD HL, MEM_IDE_BUFFER ;set buffer start
LD C,16 ;set entries counter
ld a,(HL)
or a
jp z, _fat_lfs_loop_compare_end ;skip empty sectors
JP _fat_lfs_loop
_fat_lfs_loop_compare_end:
POP DE
;LD HL, [str_file_notfound]
;CALL print_str ;print
ld a,0xFF
RET
_fat_lfs_loop_compare_match:
; get entry
POP DE
; HL points to Start of Table item
PUSH HL
POP IX
; get important information
ld a,(ix+0x1B) ;first cluster number
ld (MEM_FAT_OF0_CCLUST+1),a
ld a,(ix+0x1A)
ld (MEM_FAT_OF0_CCLUST+0),a
ld a,(ix+0x0B)
ld (MEM_FAT_OF0_ATTRIBUTE+0),a
xor a ;clear carry ;set MEM_FAT_OF0_DATREM to remaining sectors
ld a,(ix+0x1F) ;cluste length shift by 256
rra
ld (MEM_FAT_FILEREMAIN+2),a
ld a,(ix+0x1E)
rra
ld (MEM_FAT_FILEREMAIN+1),a
ld a,(ix+0x1D)
rra
ld (MEM_FAT_FILEREMAIN+0),a
ld a,0
ld (MEM_FAT_FILEREMAIN+3),a
call fat_getfatsec ;get sector information
;call print_newLine
;LD B,8
;call print_str_fixed
;ld A,'.'
;call print_char
;LD B,3
;call print_str_fixed
;LD HL, [str_file_found]
;CALL print_str ;print
xor a
RET
; compares filenames
; HL points to name1
; DE points to name2
; Carry is set if match
; Destroys DE, AF
compare_filename:
PUSH HL
push BC
LD B, 11 ;Counter
_compare_filename_loop:
LD A,(DE)
LD C,A
LD A,(HL)
INC HL
INC DE
XOR C ;check if identical (should return 0)
JR NZ, _compare_filename_nomatch
djnz _compare_filename_loop ;if not last, continue
POP BC
POP HL
SCF
RET
_compare_filename_nomatch:
POP BC
POP HL
XOR A ; clear carry flag
RET
; formats filename to 8+3 format
; DE points to source filename to string
; HL points to destination
format_filename_fat16:
LD B, 11 ;counter
PUSH HL
LD A, ' '
_format_filename_fat16_clean:
LD (HL),A
INC HL
DJNZ _format_filename_fat16_clean
POP HL ; continue with copy
LD B, 13
_format_filename_fat16_loop:
LD A, (DE) ; load byte
OR A
RET Z ;exit on 0byte
DEC B ;reduce counter
RET Z ;exit after 12 bytes 8+.+3
CP '.' ; check if dot
JR NZ, _format_filename_fat16_loop_copy ; if not continue as usual
INC DE ;else skip char
_format_filename_fat16_loop_skip_8:
LD A,B
CP 5
JR C, _format_filename_fat16_loop
INC HL
DEC B
JR _format_filename_fat16_loop_skip_8
_format_filename_fat16_loop_copy:
LD A, (DE) ; load byte
LD (HL), A ; copy byte
INC HL
INC DE
JP _format_filename_fat16_loop
str_file_notfound:
db "File not found!",13,10,0
str_file_found:
db " File located!",13,10,0