; st y+,temp
; Convert Filesize to ammount of sectors
+; (calc with 512byte/sector)
ldd xl,z+0x1D
ldd xh,z+0x1E
ldd zl,z+0x1F
sts ndisks,temp
-.if FAT16_DEBUG > 1
; Test finding of the first sector
ldd xl,z+0x1A
ldd xh,z+0x1B
rcall fat_gethostsec
+.if FAT16_DEBUG > 1
printstring "Begin of Image at: ",0
mov temp ,yl
mov temp2,yh
sbc xh,_0
lds temp,fat_clustersize
+ lsr temp
fat_c2s_loop:
tst temp
; Get First FAT- Cluster Number of Diskimage
- ldd xl,z+1
- ldd xh,z+2
+ ldd yl,z+1
+ ldd yh,z+2
+
+.if FAT16_DBG_FAT > 0
+ printstring "Search log. Cluster ",0
+ mov temp,xl
+ mov temp2,xh
+ rcall printhexw
+ printnewline
+
+ printstring "Search phys. Cluster ",0
+ mov temp ,yl
+ mov temp2,yh
+ rcall printhexw
+ printnewline
+.endif
fat_next_phsy_clust:
cp xl,_0
lds xh,fat_ptr2fat+1
lds yl,fat_ptr2fat+2
lds yh,fat_ptr2fat+3
-; Add Sector offset
+; Add Cluster offset within sector
add xl,temp
adc xh,_0
adc yl,_0
; Found the physical cluster
fat_found_phsy_clust:
+.if FAT16_DBG_FAT > 0
+ printstring "Found phys. Cluster at:",0
+ mov temp,yl
+ mov temp2,yh
+ rcall printhexw
+ printnewline
+.endif
+
ret
; ====================================================================
fat_hostparam:
lds xl,hostdsk
-.if HOSTRW_DEBUG
- mov temp,xl
- subi temp,-('A')
- rcall uartputc
- printstring ": "
-.endif
rcall dsk_getpartentry ; get partition entry
lds temp2,hostlba+1
lds temp3,hostlba+2
-.if HOSTRW_DEBUG
- printstring "lba: "
- clr temp4
- rcall print_ultoa
-.endif
ldd xl,z+5 ; get size of disk in sectors
ldd xh,z+6
cpc temp3,yl
brcs fat_hp1
-.if HOSTRW_DEBUG
- printstring ", max: "
- push temp4
- push temp3
- push temp2
- push temp
- movw temp,x
- mov temp3,yl
- clr temp4
- rcall print_ultoa
- pop temp
- pop temp2
- pop temp3
- pop temp4
- printstring " "
-.endif
-
clr temp
ret
mov yh,_0
; Divide logical Sectornumber by size of Cluster in sectors
lds zl, fat_clustersize
+ lsr zl
fat_search_clst_lp:
tst zl
breq fat_found_clst
; ################# Get Subsector within the logical Cluster for later use
mov yl,xl
lds zl, fat_clustersize
+ lsr zl
fat_search_clst_lp2:
tst zl
breq fat_found_subsec
mov xl,yl
mov xh,yh
rcall fat_gethostsec
+; Found the physical sector
+.if FAT16_DBG_FAT > 0
+ printstring "Found phys. Sector at:",0
+ mov temp,yl
+ mov temp2,yh
+ rcall printhexw
+ mov temp,xl
+ mov temp2,xh
+ rcall printhexw
+ printnewline
+.endif
; Save the found Sector for later use into cache
sts fat_clust_ptr ,xl
adc yl,_0
adc yh,_0
-.if HOSTRW_DEBUG
- printstring ", abs:"
- push temp4
- push temp3
- push temp2
- push temp
- movw temp,x
- movw temp3,y
- rcall print_ultoa
- pop temp
- pop temp2
- pop temp3
- pop temp4
- printstring " "
+; Found the physical sector
+.if FAT16_DBG_FAT > 0
+ printstring "Sector with Offset at:",0
+ mov temp,yl
+ mov temp2,yh
+ rcall printhexw
+ mov temp,xl
+ mov temp2,xh
+ rcall printhexw
+ printnewline
.endif
ori temp,255
; ====================================================================
fat_writehost:
-.if HOSTRW_DEBUG
+.if FAT16_RWDEBUG > 1
printnewline
printstring "host write "
.endif
brne fat_rdwr_err
rjmp fat_rdwr_ok
+fat_rdwr_ok:
+ sts erflag,_0
+ ret
+
+fat_rdwr_err:
+ sts erflag,_255
+ ret
; ====================================================================
; Function: Does a Disk read operation
; ====================================================================
; ====================================================================
fat_readhost:
-.if HOSTRW_DEBUG
+.if FAT16_RWDEBUG > 1
printnewline
printstring "host read "
.endif
breq fat_rdwr_err
+.if FAT16_RWDEBUG > 0
printstring "Read Image Sector:"
push temp4
push temp3
pop temp2
pop temp3
pop temp4
- printstring " "
+ printnewline
+.endif
call mmcReadSect
tst temp
tst temp
brne fat_rdwr_err
-fat_rdwr_ok:
- sts erflag,_0
- ret
-
-fat_rdwr_err:
- sts erflag,_255
- ret
#endif