;
; Copyright (C) 2010 Frank Zoll
; Copyright (C) 2010 Sprite_tm
-; Copyright (C) 2010 Leo C.
+; Copyright (C) 2010,2013 Leo C.
;
; This file is part of avrcpm.
;
.dseg
+fat_vars:
fat_partfound: .byte 1 ; (partition: 0= no found 0xff=found )
fat_parttbl: .byte 4 ; first fat16 partition entry
; only startsector is needed
fat_clustersize: .byte 1 ; sectors per cluster
-fat_numdirentries:.byte 2 ; Max. num. of entries within Rootdirektory
fat_ptr2fat: .byte 4 ; pointer to the first fat sector
fat_ptr2dat: .byte 4 ; pointer to the first data sector
/*These variables define a cache that holds the last Cluster and Sector
- thats been searched vor. To save some of the valuabe SRAM- Space these
- variables also are used as temporary variables by the function
- fat_scan_partition.
+ thats been searched vor.
*/
fat_last_dsk: .byte 1 ; number of disk with entry in cache
fat_log_clust: .byte 2 ; last searched logical cluster
fat_clust_offset: .byte 1 ; offset within the cluster
fat_clust_ptr: .byte 4 ; sector of last real cluster
-/* This Variable is only needed within the scanning of the directory
-for tempoary variable storage.. todo: optimize away :-) */
-fat_temp: .byte 3 ; for tempoary use
+ .equ o_fat_partfound = 0
+ .equ o_fat_parttbl = 1
+ .equ o_fat_clustersize = 5
+ .equ o_fat_ptr2fat = 6
+ .equ o_fat_ptr2dat = 10
+ .equ o_fat_last_dsk = 14
+ .equ o_fat_log_clust = 15
+ .equ o_fat_clust_offset= 17
+ .equ o_fat_clust_ptr = 18
+
; ############################################################################
; Start of Code Segment
; ############################################################################
+
.cseg
+fat_cfname: .db FAT16_IMAGENAME_PREFIX, 0
+fat_cfext: .db FAT16_IMAGENAME_SUFFIX, 0
+
+
; ============================================================================
; Function: Initialize internal FAT-Partition Variables
; ============================================================================
; ============================================================================
fat_init_partitiontable:
- sts fat_partfound,_0
-
- ldiw y,fat_parttbl
- st y+,_0
- st y+,_0
- st y+,_0
- st y+,_0
+ ldiw y,fat_vars
+ std y+o_fat_partfound, _0
+ std y+o_fat_parttbl+0, _0
+ std y+o_fat_parttbl+1, _0
+ std y+o_fat_parttbl+2, _0
+ std y+o_fat_parttbl+3, _0
ret
+
; ============================================================================
; Function: Resets the Cache
; ============================================================================
; the FAT16-Partition for the given sector.
; ============================================================================
fat_reset_cache:
- sts fat_log_clust ,_255
- sts fat_log_clust+1,_255
- sts fat_last_dsk ,_255
+ ldiw y,fat_vars
+ std y+o_fat_log_clust ,_255
+ std y+o_fat_log_clust+1,_255
+ std y+o_fat_last_dsk ,_255
ret
; ============================================================================
printnewline
.endif
-
-; save variables on stack
- push yl
- push yh
+ ldiw y,fat_vars
; set fat16 partition found flag
- sts fat_partfound,_255
-; save data from first fat16 partition
- ldiw y,fat_parttbl
+ std y+o_fat_partfound,_255
+
+; save data from first fat16 partition
ldd temp,z+PART_START
- st y+,temp
+ std y+o_fat_parttbl,temp
ldd temp,z+PART_START+1
- st y+,temp
+ std y+o_fat_parttbl+1,temp
ldd temp,z+PART_START+2
- st y+,temp
+ std y+o_fat_parttbl+2,temp
ldd temp,z+PART_START+3
- st y+,temp
-
-; reload variables from stack
- pop yh
- pop yl
+ std y+o_fat_parttbl+3,temp
ret
; Check for free entries in partition table
lds yl,ndisks
cpi yl,MAXDISKS
- breq fat_scan_error
+ brge fat_scan_error
.if FAT16_DEBUG > 0
printstring "read fat bootblock."
printnewline
.endif
+ ldiw y,fat_vars
+ ldiw z,hostbuf
+
; get sectors per cluster from bootblock
- ldiw z,hostbuf+FAT16_BSO_CLUSTSZ
- ld temp,z
- sts fat_clustersize,temp
+ ldd temp,z+FAT16_BSO_CLUSTSZ
+ std y+o_fat_clustersize,temp
.if FAT16_DEBUG > 0
printstring "Sectors per Cluster "
printnewline
.endif
-; get num of FAT Tables from bootblock
- ldiw z,hostbuf+FAT16_BSO_NUMFATCP
- ld temp,z
- sts fat_last_dsk,temp ; low byte
-
-.if FAT16_DEBUG > 0
- printstring "Ammount of FAT copies: "
- lcall printhex
- printnewline
-.endif
-
; get max num of entries in root direktory from bootblock
- ldiw z,hostbuf+FAT16_BSO_NUMDIRENT
- ld temp,z+
- sts fat_numdirentries,temp ; low byte
- ld temp2,z
- sts fat_numdirentries+1,temp2 ; high byte
+ ldd temp ,z+FAT16_BSO_NUMDIRENT
+ ldd temp2,z+FAT16_BSO_NUMDIRENT+1
.if FAT16_DEBUG > 0
printstring "Max. entries in rootdir.: "
lcall printhexw
- printnewline
.endif
-; Print begin of Volume
-.if FAT16_DEBUG > 1
+; Calculate begin of DATA Clusters within the Volume
+; Num. Dir.Sektors = (Num. of Dir. entries * 32) / Bytes per Sektor
- ldiw z,fat_parttbl
- ldd xl,z+0
- ldd xh,z+1
- ldd yl,z+2
- ldd yh,z+3
+; Sectorsize is fixed at 512 bytes, makes 16 entries per sector
- printstring "Begin of Volume at: "
- movw temp ,y
- lcall printhexw
- movw temp ,x
- lcall printhexw
- printnewline
-.endif
-; get num of sectors per FAT-Table from bootblock
- ldiw z,hostbuf+FAT16_BSO_SECPERFAT
- ld temp,z+
- sts fat_log_clust,temp ; low byte
- ld temp2,z
- sts fat_log_clust+1,temp2 ; high byte
+; Num. Direntries / 16
+ lsr temp2
+ ror temp
+ lsr temp2
+ ror temp
+ lsr temp2
+ ror temp
+ lsr temp2
+ ror temp
+
+ push temp ;save # of rootdir sectors
.if FAT16_DEBUG > 0
- printstring "Sectors per FAT__: "
+ printstring " ("
+ movw temp,_tmp0
+ lcall printhex
+ printstring " sectors)"
+ printnewline
+.endif
+
+.if FAT16_DEBUG > 1
+; Print begin of Volume
+ printstring "Begin of Volume at: "
+ ldd temp, y+o_fat_parttbl+2
+ ldd temp2,y+o_fat_parttbl+3
+ lcall printhexw
+ ldd temp, y+o_fat_parttbl+0
+ ldd temp2,y+o_fat_parttbl+1
lcall printhexw
printnewline
.endif
; get num of reseved sectors from bootblock
- ldiw z,hostbuf+FAT16_BSO_RESSECT
- ld temp,z+
- ld temp2,z
+ ldd _tmp0,z+FAT16_BSO_RESSECT
+ ldd _tmp1,z+FAT16_BSO_RESSECT+1
; Calculate begin of FAT within the Volume
- ldiw z,fat_parttbl
- ldd xl,z+0
- ldd xh,z+1
- ldd yl,z+2
- ldd yh,z+3
+ ldd xl,y+o_fat_parttbl+0
+ ldd xh,y+o_fat_parttbl+1
+ ldd temp,y+o_fat_parttbl+2
+ ldd temp2,y+o_fat_parttbl+3
- add xl,temp
- adc xh,temp2
- adc yl,_0
- adc yh,_0
+ add xl,_tmp0
+ adc xh,_tmp1
+ adc temp,_0
+ adc temp2,_0
- sts fat_ptr2fat ,xl
- sts fat_ptr2fat+1,xh
- sts fat_ptr2fat+2,yl
- sts fat_ptr2fat+3,yh
+ std y+o_fat_ptr2fat ,xl
+ std y+o_fat_ptr2fat+1,xh
+ std y+o_fat_ptr2fat+2,temp
+ std y+o_fat_ptr2fat+3,temp2
.if FAT16_DEBUG > 1
printstring "Begin of FAT at___: "
- movw temp ,y
lcall printhexw
movw temp ,x
lcall printhexw
printnewline
.endif
+; get num of sectors per FAT-Table from bootblock
+ ldd temp, z+FAT16_BSO_SECPERFAT
+ ldd temp2,z+FAT16_BSO_SECPERFAT+1
+
+.if FAT16_DEBUG > 0
+ printstring "Sectors per FAT___: "
+ lcall printhexw
+ printnewline
+.endif
+
+; get num of FAT Tables from bootblock
+ ldd temp3,z+FAT16_BSO_NUMFATCP
+
+.if FAT16_DEBUG > 0
+ printstring "Ammount of FAT copies: "
+ push temp
+ mov temp,temp3
+ lcall printhex
+ pop temp
+ printnewline
+.endif
+
+ movw _tmp0,temp
+
; Calculate begin of Root- Directory within the Volume
- ldiw z,fat_ptr2fat
- ldd xl,z+0
- ldd xh,z+1
- ldd yl,z+2
- ldd yh,z+3
- lds temp ,fat_log_clust
- lds temp2,fat_log_clust+1
- lds temp3,fat_last_dsk
+ ldd xl, y+o_fat_ptr2fat+0
+ ldd xh, y+o_fat_ptr2fat+1
+ ldd temp, y+o_fat_ptr2fat+2
+ ldd temp2,y+o_fat_ptr2fat+3
fat_calc_dp_loop:
cp temp3,_0
breq fat_calc_dp_lend
- add xl,temp
- adc xh,temp2
- adc yl,_0
- adc yh,_0
-
+ add xl,_tmp0
+ adc xh,_tmp1
+ adc temp,_0
+ adc temp2,_0
dec temp3
-
rjmp fat_calc_dp_loop
-fat_calc_dp_lend:
-
- sts fat_clust_ptr ,xl
- sts fat_clust_ptr+1,xh
- sts fat_clust_ptr+2,yl
- sts fat_clust_ptr+3,yh
+fat_calc_dp_lend:
.if FAT16_DEBUG > 1
printstring "Begin of DIR at___: "
- movw temp ,y
lcall printhexw
- movw temp ,x
+ push temp2
+ push temp
+ movw temp,x
lcall printhexw
+ pop temp
+ pop temp2
printnewline
.endif
-; Calculate begin of DATA Clusters within the Volume
-; Num. Dir.Sektors = (Num. of Dir. entries * 32) / Bytes per Sektor
+ pop temp3 ;number of rootdir sectors
-; Sectorsize is fixed at 512 bytes, makes 16 entries per sector
-
- lds zl,fat_numdirentries ; low byte
- lds zh,fat_numdirentries+1 ; high byte
-
-; Num. Direntries / 16
- lsr zh
- ror zl
- lsr zh
- ror zl
- lsr zh
- ror zl
- lsr zh
- ror zl
-
- lds xl,fat_clust_ptr
- lds xh,fat_clust_ptr+1
- lds yl,fat_clust_ptr+2
- lds yh,fat_clust_ptr+3
-
- add xl,zl
- adc xh,zh
- adc yl,_0
- adc yh,_0
+ add xl,temp3
+ adc xh,_0
+ adc temp,_0
+ adc temp2,_0
- sts fat_ptr2dat ,xl
- sts fat_ptr2dat+1,xh
- sts fat_ptr2dat+2,yl
- sts fat_ptr2dat+3,yh
+ std y+o_fat_ptr2dat ,xl
+ std y+o_fat_ptr2dat+1,xh
+ std y+o_fat_ptr2dat+2,temp
+ std y+o_fat_ptr2dat+3,temp2
.if FAT16_DEBUG > 1
printstring "Begin of Data at__: "
- movw temp ,y
lcall printhexw
movw temp ,x
lcall printhexw
printnewline
.endif
-; Here Starts the Scann of the Directory for valid image Files.
-
-; Init Image-Namecounter
- ldi temp,FAT16_FIRST_IMAGENAME
- sts fat_last_dsk,temp
-
-fat_scan_for_next_image:
+;-------------------------------------------------------------------------------
+; Here starts the scan of the directory for valid image files.
-; Init Offset into Directory-Sectors
- ldi temp,0
- sts fat_clust_offset,temp
-
-; Init counter for number of entry left to scan
- lds temp,fat_numdirentries
- sts fat_log_clust ,temp
-
- lds temp,fat_numdirentries+1
- sts fat_log_clust+1,temp
fat_next_sector_loop:
-; Get a Pointer to the first Directory sector
- lds xl,fat_clust_ptr
- lds xh,fat_clust_ptr+1
- lds yl,fat_clust_ptr+2
- lds yh,fat_clust_ptr+3
+
+; Get a pointer to the last+1 directory sector
+ lds xl,fat_ptr2dat
+ lds xh,fat_ptr2dat+1
+ lds yl,fat_ptr2dat+2
+ lds yh,fat_ptr2dat+3
; Add actual offset
- lds temp,fat_clust_offset
- add xl,temp
- adc xh,_0
- adc yl,_0
- adc yh,_0
+ sub xl,temp3
+ sbc xh,_0
+ sbc yl,_0
+ sbc yh,_0
; Load sector from Directory
lcall mmcReadSect
; Looks at a read directory block for image entries
fat_look_for_images:
- ldiw z,hostbuf
- ldi temp2,0
-
-fat_look_for_loop:
- ldd temp,z+0
- cpi temp,'C'
- brne fat_look_not_ok
-
- ldd temp,z+1
- cpi temp,'P'
- brne fat_look_not_ok
-
- ldd temp,z+2
- cpi temp,'M'
- brne fat_look_not_ok
-
- ldd temp,z+3
- cpi temp,'D'
- brne fat_look_not_ok
-
- ldd temp,z+4
- cpi temp,'S'
- brne fat_look_not_ok
-
- ldd temp,z+5
- cpi temp,'K'
- brne fat_look_not_ok
-
- ldd temp,z+6
- cpi temp,'_'
- brne fat_look_not_ok
-
- lds temp3,fat_last_dsk ; Get actual Diskname (A to Z)
- ldd temp,z+7
- cp temp,temp3
- brne fat_look_not_ok
-
- ldd temp,z+8
- cpi temp,'I'
- brne fat_look_not_ok
-
- ldd temp,z+9
- cpi temp,'M'
- brne fat_look_not_ok
-
- ldd temp,z+10
- cpi temp,'G'
- brne fat_look_not_ok
-
- sts fat_temp ,zl
- sts fat_temp+1,zh
- sts fat_temp+2,temp2
- rjmp fat_store_new_entry
-
-fat_scan_for_more:
-
- lds zl ,fat_temp
- lds zh ,fat_temp+1
- lds temp2,fat_temp+2
-fat_look_not_ok:
-
- adiw z,32
-
- inc temp2
- cpi temp2,16 ; max entries/sector
- breq fat_scan_next_sector
- rjmp fat_look_for_loop
-
-fat_scan_next_sector:
+ ldiw x,hostbuf
-
- lds _tmp0, fat_log_clust
- lds _tmp1, fat_log_clust+1
+fat_look_for_loop:
- sub _tmp0,temp2
- sbc _tmp1,_0
+ movw y,x
+ ldiw z,fat_cfname*2
+ ldi temp2,STRLEN(FAT16_IMAGENAME_PREFIX)
+ lcall strncmp_p
+ brne fat_look_continue
- sts fat_log_clust,_tmp0
- sts fat_log_clust+1,_tmp1
-
- cp _tmp0,_0
- cpc _tmp1,_0
- breq fat_scan_at_end
+ adiw y,1
+ adiw z,1
+ ldi temp2,STRLEN(FAT16_IMAGENAME_SUFFIX)
+ lcall strncmp_p
+ brne fat_look_continue
- lds temp,fat_clust_offset
+ movw y,x
+ ldd temp2,y+STRLEN(FAT16_IMAGENAME_PREFIX)
+ ldi temp,FAT16_FIRST_IMAGENAME
+fat_look_imgname_loop:
+ cp temp,temp2
+ breq fat_look_imgname_match
inc temp
- sts fat_clust_offset,temp
+ cpi temp,FAT16_LAST_IMAGENAME+1
+ brlo fat_look_imgname_loop
+ rjmp fat_look_continue
- rjmp fat_next_sector_loop
+fat_look_imgname_match:
+ rcall fat_store_new_entry
+ movw x,y
-fat_scan_at_end:
+fat_look_continue:
- lds temp,fat_last_dsk
- inc temp
- sts fat_last_dsk,temp
+ adiw x,32
+ ldi temp,high(hostbuf+HOSTSIZE)
+ cpi xl,low(hostbuf+HOSTSIZE)
+ cpc xh,temp
+ brne fat_look_for_loop
- ldi temp2,FAT16_LAST_IMAGENAME
- cp temp,temp2
- brge fat_scaned_last_disk
+fat_scan_next_sector:
+
+ dec temp3
+ brne fat_next_sector_loop
- rjmp fat_scan_for_next_image
+ ret
-fat_scaned_last_disk:
- rjmp fat_scan_end
+#if 0
+dbg_print_parttbl_raw:
+ push zh
+ push zl
+ push temp2
+ push temp
+ ldiw z,hostparttbl
+dbg_pptblraw_lp:
+ lcall dbg_hexdump_line
+ adiw z,PARTENTRY_SIZE
+ cpi zl,low(hostparttbltop)
+ ldi temp,high(hostparttbltop)
+ cpc zh,temp
+ brne dbg_pptblraw_lp
+ pop temp
+ pop temp2
+ pop zl
+ pop zh
+ ret
+#endif
+;-------------------------------------------------------------------------------
; Create new Partition Entry
+; ============================================================================
+; Function: Create new Partition Entry
+; ============================================================================
+; Parameters: [in] yh,yl Directory entry
+;
+; ----------------------------------------------------------------------------
+; Registers :
+; Variables : [used]
+; [changes] temp
+; ----------------------------------------------------------------------------
+; Description:
+;
+; ============================================================================
+
fat_store_new_entry:
; Found a valid image
.if FAT16_DEBUG > 1
- printstring "Found a valid Image! Z="
- movw temp ,z
+ printnewline
+ printstring "Found a valid Image! Y="
+ push temp2
+ push temp
+ movw temp ,y
lcall printhexw
+ pop temp
+ pop temp2
printnewline
.endif
- ldiw y,hostparttbl
- lds temp3,ndisks
+#if 0
+;;;;
+ printstring "Insert entry in Tab: --> "
+ mov temp,temp2
+ lcall uartputc
+ printnewline
+ printstring "Tab before:"
-fat_look_store_loop:
- tst temp3
- breq fat_look_store
+ rcall dbg_print_parttbl_raw
+ printnewline
+;;;;
+#endif
+ ldiw z,hostparttbl
- adiw y,PARTENTRY_SIZE
- dec temp3
- rjmp fat_look_store_loop
+fat_st_searchpos:
+ ldd temp,z+PTAB_TYPE
+ tst temp
+ breq fat_st_insert_slot
+ sbrs temp,log2(dskType_FAT)
+ rjmp fat_st_search_next
+
+ ldd temp,z+PTAB_START+2
+ cp temp2,temp
+ brlo fat_st_ins_before
+
+fat_st_search_next:
+ adiw z,PARTENTRY_SIZE
+ cpi zl,low(hostparttbltop)
+ ldi temp,high(hostparttbltop)
+ cpc zh,temp
+ brne fat_st_searchpos
+
+; Table is full.
+#if 0
+;;;;
+ push temp2
+ push temp
+ printstring "Table is full. --> ptr: "
+ movw temp,z
+ lcall printhexw
+ printnewline
+ pop temp
+ pop temp2
+;;;;
+#endif
+ ret
+
+fat_st_ins_before:
+ movw x,z
+ ldiw z,hostparttbltop-PARTENTRY_SIZE
+fat_st_insert_mkslotloop:
+ cp zl,xl
+ cpc zh,xh
+ breq fat_st_insert_slot
+
+ ld _tmp0,-z
+ std z+PARTENTRY_SIZE,_tmp0
+ rjmp fat_st_insert_mkslotloop
+
+fat_st_insert_slot:
-fat_look_store:
; Set Type of Partition to FAT16- Fileimage
ldi temp,dskType_FAT
- std y+0,temp
-
+ std z+PTAB_TYPE,temp
; Offset to Startcluster + 2
- ldd temp,z+0x1A
- std y+1,temp
-
- ldd temp,z+0x1B
- std y+2,temp
+ ldd _tmp0,y+0x1A
+ ldd _tmp1,y+0x1B
+ std z+PTAB_START, _tmp0
+ std z+PTAB_START+1,_tmp1
- ldi temp,0
- std y+3,temp
- std y+4,temp
+ std z+PTAB_START+2,temp2
+ std z+PTAB_START+3,_0
; Convert Filesize to ammount of sectors
; (calc with 512byte/sector)
- ldd _tmp0,z+0x1C
- ldd xl,z+0x1D
- ldd xh,z+0x1E
- ldd zl,z+0x1F
-; mov zh,_0
+ ldd _tmp0,y+0x1C
+ ldd xl, y+0x1D
+ ldd xh, y+0x1E
+ ldd temp, y+0x1F
clc
cpse _tmp0,_0 ;round up
adiw x,1
- adc zl,_0
+ adc temp,_0
- lsr zl
+ lsr temp
ror xh
ror xl
adc xl,_0
adc xh,_0
- adc zl,_0
+ adc temp,_0
; store ammount of sectors in partitiontable
- tst zl ;file size larger than 65535 sectors?
+ tst temp ;file size larger than 65535 sectors?
breq fat_add_noprune
ldi xl,255
ldi xh,255
fat_add_noprune:
- std y+5,xl
- std y+6,xh
+ std z+PTAB_SIZE, xl
+ std z+PTAB_SIZE+1,xh
.if FAT16_DEBUG > 1
; Test finding of the first sector
-
- ldd xl,y+1
- ldd xh,y+2
+
+ push yh
+ push yl
+ ldd xl,z+1
+ ldd xh,z+2
rcall fat_gethostsec
movw temp ,x
lcall printhexw
printnewline
-
+ pop yl
+ pop yh
.endif
-; Check for another free entry in partition table
+
+
+; Table counts one more entry if it was'nt allready full
+
lds temp,ndisks
+ cpi temp,MAXDISKS
+ breq fat_add_nomore
inc temp
sts ndisks,temp
-
- cpi temp,MAXDISKS
- breq fat_scan_end
- rjmp fat_scan_for_more
+fat_add_nomore:
-fat_scan_end:
-
+#if 0
+;;;;
+ printnewline
+ printstring "Table now:"
+ rcall dbg_print_parttbl_raw
+ printnewline
+;;;;
+#endif
ret
; ============================================================================
; Function: Cluster to HostSector
; ============================================================================
-; Parameters: [in] xh,xl Cluster Number
-; [out] yh,yl,xh,xl Sector Number on Disk
-; ----------------------------------------------------------------------------
-; Registers :
-; Variables : [used] fat_clustersize Ammount of Sectors per Cluster
-; [changes] temp
-; ----------------------------------------------------------------------------
-; Description:
-; ! Only works with Clustersizes 2,4,8,16,32,64,128 !
-; ============================================================================
-fat_gethostsec:
-
-; Get Offset into Data area of Disk
- rcall fat_clusttosec
-
-
-; add begin of data area to offset
- lds temp,fat_ptr2dat+0
- add xl,temp
- lds temp,fat_ptr2dat+1
- adc xh,temp
- lds temp,fat_ptr2dat+2
- adc yl,temp
- lds temp,fat_ptr2dat+3
- adc yh,temp
- ret
-
-; ============================================================================
-; Function: Cluster to Sector
-; ============================================================================
; Registers: [in] xl,xh Cluster Number
-; [out] xl,xh,yl,yh Sector Number
+; [out] yh,yl,xh,xl Sector Number on Disk
; Variables: [in] fat_clustersize Ammount of Sectors per Cluster
; [out] temp =0
; ----------------------------------------------------------------------------
;
; ! Only works with Clustersizes 2,4,8,16,32,64,128 !
; ============================================================================
-fat_clusttosec:
- clr yl
- clr yh
+fat_gethostsec:
+
+ ldiw y,fat_vars
+
+; Get Offset into Data area of Disk
+
+ clr _tmp0
+ clr _tmp1
sbiw x,2 ; Substract the 2 reserved clusters
- lds temp,fat_clustersize
+ ldd temp,y+o_fat_clustersize
lsr temp
fat_c2s_loop:
tst temp
lsl xl
rol xh
- rol yl
- rol yh
+ rol _tmp0
+ rol _tmp1
rjmp fat_c2s_loop
-
fat_c2s_end:
+
+; Add begin of data area to offset
+
+ ldd temp,y+o_fat_ptr2dat+0
+ add xl,temp
+ ldd temp,y+o_fat_ptr2dat+1
+ adc xh,temp
+ ldd temp,y+o_fat_ptr2dat+2
+ adc _tmp0,temp
+ ldd temp,y+o_fat_ptr2dat+3
+ adc _tmp1,temp
+ movw y,_tmp0
+
ret
; ====================================================================
cp xl,_0
cpc xh,_0
breq fat_found_phsy_clust
+
; Get Next Cluster from Fat
; Trick: 512 Bytes Per Sector equals to 256 FAT- entries per Sector
; in zh,zl: Pointer to Word within the Sector to read
; in yh..xl: Start sector number (LBA)
; out zh,zl : word thats been read
+
push xl
push xh
movw y,z
; Check next logical Cluster
- ldi zl,1
- sub xl,zl
- sbc xh,_0
+
+ sbiw x,1
rjmp fat_next_phsy_clust
; Found the physical cluster
; ============================================================================
; Function: This Routine searches for the Sector within an Imagefile
; ============================================================================
-; Registers: [out] xl,xh,yl,yh Pointer to the Sector on the SD-Card
-; [out] temp Error- Variable (0= No Error)
+; Registers: [out] xl,xh,yl,yh Pointer to the sector on the SD-Card
+; [out] temp Error variable (0= No Error)
; Variables: [in] hostdsk host disk #, (partition #)
; [in] hostlba host block #, relative to part.start
; [in] fat_last_dsk number of disk with entry in cache
; [in] fat_clust_ptr sector of last real cluster
; ----------------------------------------------------------------------------
; Description:
-; This Routine uses the variables hostdsk and hostlba to find an Sector
-; in the Imagefile.
-; The CP/M Sector given within "hostlba" are splited to a logical Cluster-
-; Number and the Subsector within this logical Cluster.
-; logical Cluster Number = hostlba / fat_clustersize
-; The logical Cluster Number will be compared to the logical Cluster- Number
-; within the Cache. When this Clusters are the same and the DiskID's are
-; also the same, then the cached physical Sector will be used.
-; When the Clusters or the Disks don't match, a seek for the physical
-; Cluster is performed. This seek is done thru an access over the FAT of
-; the FAT16 Partition. The Routine starts at the first Cluster of the
-; Imagefile and goes along the linked list of Clusternumber till it reaches
-; the searched cluster. The found Clusternumber will be used to calculate
-; the Sektor where this Cluster lies on the SD- Card. Both the found physical
-; Cluster and the logical Cluster together with the physical Sectornumber
+; This routine uses the variables hostdsk and hostlba to find an sector
+; in the imagefile.
+; The CP/M sector given within "hostlba" are splited to a logical cluster-
+; number and the subsector within this logical cluster.
+; logical cluster number = hostlba / fat_clustersize
+; The logical cluster number will be compared to the logical cluster number
+; within the cache. When this clusters are the same and the diskid's are
+; also the same, then the cached physical sector will be used.
+; When the clusters or the disks don't match, a seek for the physical
+; cluster is performed. This seek is done thru an access over the fat of
+; the fat16 partition. the routine starts at the first cluster of the
+; imagefile and goes along the linked list of clusternumber till it reaches
+; the searched cluster. The found clusternumber will be used to calculate
+; the sektor where this cluster lies on the sd card. Both the found physical
+; cluster and the logical cluster together with the physical sectornumber
; are stored in the cache.
-; The last step done is to add the SubSectorOffset to the found physical
-; Sector. This gives the pointer to the Sector to be read and or written.
+; The last step done is to add the subsectoroffset to the found physical
+; sector. this gives the pointer to the sector to be read and or written.
; ============================================================================
fat_hostparam:
fat_found_clst:
; at this point xh and xl are carying the logical cluster number
; printstring "find subsector"
-; ################# Get Subsector within the logical Cluster for later use
+; ################# Get subsector within the logical cluster for later use
mov yl,xl
lds zl,fat_clustersize
lsr zl
lds yh,fat_log_clust+1
cp yl,xl
- brne fat_wrong_cache_clst
- cp yh,xh
+ cpc yh,xh
brne fat_wrong_cache_clst
-; Last Cluster = searched Cluster -> get Sectornumber from cache
+; Last Cluster = searched Cluster -> get Sectornumber from cache
lds xl,fat_clust_ptr
lds xh,fat_clust_ptr+1
lds yl,fat_clust_ptr+2