#define FAT16_BSO_SECPERFAT 0x16 ; BootSectorOffset to Number of Sectors per Fat
#define FAT16_BSO_NUMFATCP 0x10 ; BootSectorOffset to Ammount of FAT Copys
#define FAT16_BSO_NUMDIRENT 0x11 ; BootSectorOffset to Max. Root Dir. Entrys
+#define FAT16_FIRST_IMAGENAME 'A'\r
+#define FAT16_LAST_IMAGENAME 'Z'\r
;-------------------------------- Start of Data Segment
st y+,_0
st y+,_0
st y+,_0
+ ret\r
+\r
+; ====================================================================\r
+; Function: Resets the Cache
+; ====================================================================\r
+; Parameters\r
+; --------------------------------------------------------------------\r
+; Registers : none\r
+; Variables : [r] seekdsk Number of Disk to Read\r
+; [r] seeksec Sector to read\r
+; [r] seektrk Track to read\r
+; --------------------------------------------------------------------\r
+; Description:\r
+; ====================================================================\r
+fat_reset_cache:\r
+ push yl\r
ldi yl,0xFF
sts fat_log_clust ,yl
sts fat_log_clust+1,yl
sts fat_last_dsk ,yl
+ pop yl\r
ret
; ====================================================================
; Here Starts the Scann of the Directory for valid image Files.
+; Init Image-Namecounter\r
+ ldi temp,FAT16_FIRST_IMAGENAME\r
+ sts fat_last_dsk,temp\r
+\r
+fat_scan_for_next_image:\r
+\r
+; Init Offset into Directory-Sectors\r
+ ldi temp,0\r
+ sts fat_clust_offset,temp\r
+\r
+; Init counter for number of entry left to scan\r
+ lds temp,fat_numdirentrys\r
+ sts fat_log_clust ,temp\r
+\r
+ lds temp,fat_numdirentrys+1\r
+ sts fat_log_clust+1,temp\r
+\r
+fat_next_sector_loop:\r
+; Get a Pointer to the first Directory sector\r
lds xl,fat_ptr2dir
lds xh,fat_ptr2dir+1
lds yl,fat_ptr2dir+2
lds yh,fat_ptr2dir+3
-; Load first sector from Directory
+; Add actual offset\r
+ lds temp,fat_clust_offset\r
+ add xl,temp\r
+ adc xh,_0\r
+ adc yl,_0\r
+ adc yh,_0\r
+\r
+; Load sector from Directory
call mmcReadSect
tst temp
breq fat_look_for_images
cpi temp,'_'
brne fat_look_not_ok
+ lds temp3,fat_last_dsk ; Get actual Diskname (A to Z)\r
+ ldd temp,z+7\r
+ cp temp,temp3\r
+ brne fat_look_not_ok\r
ldd temp,z+8
cpi temp,'I'
brne fat_look_not_ok
cpi temp,'G'
brne fat_look_not_ok
+ sts fat_clust_ptr ,zl\r
+ sts fat_clust_ptr+1,zh\r
+ sts fat_clust_ptr+2,temp2\r
jmp fat_store_new_entry
+fat_scan_for_more:\r
+\r
+\r
+.if FAT16_DEBUG > 1\r
+ printstring "At:Scann for more ",0\r
+ printnewline\r
+.endif\r
+\r
+ lds zl ,fat_clust_ptr\r
+ lds zh ,fat_clust_ptr+1\r
+ lds temp2,fat_clust_ptr+2\r
fat_look_not_ok:
- //ldi temp,32
- addiw z,32
+.if FAT16_DEBUG > 1\r
+ printstring "+",0\r
+.endif\r
+ \r
+ adiw z,32\r
inc temp2
cpi temp2,16 ; max entrys/sector
fat_scan_next_sector:
- ret
+.if FAT16_DEBUG > 1\r
+ printstring "At:Scan next Sector",0\r
+ printnewline\r
+.endif\r
+ \r
+ lds temp3, fat_log_clust\r
+ lds temp4, fat_log_clust+1\r
+\r
+ sub temp3,temp2\r
+ sbc temp4,_0\r
+\r
+ sts fat_log_clust,temp3\r
+ sts fat_log_clust+1,temp4\r
+ \r
+ cp temp3,_0\r
+ cpc temp4,_0\r
+ breq fat_scan_at_end \r
+\r
+ lds temp,fat_clust_offset\r
+ inc temp\r
+ sts fat_clust_offset,temp\r
+\r
+ rjmp fat_next_sector_loop\r
+\r
+fat_scan_at_end:\r
+\r
+.if FAT16_DEBUG > 1\r
+ printstring "At:Scan at end",0\r
+ printnewline\r
+.endif\r
+\r
+ lds temp,fat_last_dsk\r
+ inc temp\r
+ sts fat_last_dsk,temp\r
+\r
+ ldi temp2,FAT16_LAST_IMAGENAME\r
+ cp temp,temp2\r
+ brge fat_scaned_last_disk\r
+\r
+ rjmp fat_scan_for_next_image\r
+\r
+fat_scaned_last_disk:\r
+\r
+ rjmp fat_scan_end\r
; Create new Partition Entry
; Found a valid image
.if FAT16_DEBUG > 1
- printstring "Found a valid Image ! ",0
+ printstring "Found a valid Image ! Z=",0\r
+ mov temp ,zl\r
+ mov temp2,zh\r
+ rcall printhexw\r
printnewline
.endif
ldi temp,dskType_FAT
st y+,temp
+.if FAT16_DEBUG > 1\r
+ printstring "ClusterID",0\r
+.endif\r
; Offset to Startcluster + 2
ldd temp,z+0x1A
st y+,temp
+.if FAT16_DEBUG > 1\r
+ rcall printhex\r
+.endif
ldd temp,z+0x1B
st y+,temp
+.if FAT16_DEBUG > 1\r
+ rcall printhex\r
+.endif
ldi temp,0
st y+,temp
st y+,temp
+.if FAT16_DEBUG > 1\r
+ printnewline\r
+.endif
-; Filesize in Bytes - 2,4,8,16,32,64,128,256,512
+; Filesize in Bytes\r
; ldd temp,z+0x1C
; st y+,temp
; ldd temp,z+0x1D
st y+,zl
st y+,zh
+.if FAT16_DEBUG > 1\r
+; Test finding of the first sector\r
+ \r
+ ldd xl,z+0x1A\r
+ ldd xh,z+0x1B\r
+\r
+ rcall fat_gethostsec\r
+\r
+ printstring "Begin of Image at: ",0\r
+ mov temp ,yl\r
+ mov temp2,yh\r
+ rcall printhexw\r
+ mov temp ,xl\r
+ mov temp2,xh\r
+ rcall printhexw\r
+ printnewline\r
+\r
+.endif\r
; Check for another free entry in partition table
lds temp,ndisks
inc temp
sts ndisks,temp
+ cpi temp,MAXDISKS\r
+ breq fat_scan_end \r
-; Test finding of the first sector
- ldd xl,z+0x1A
- ldd xh,z+0x1B
- ldi zl,0
-
- rcall fat_gethostsec
-
-.if FAT16_DEBUG > 1
- printstring "Begin of Image at: ",0
- mov temp ,yl
- mov temp2,yh
- rcall printhexw
- mov temp ,xl
- mov temp2,xh
- rcall printhexw
- printnewline
+ jmp fat_scan_for_more \r
-.endif
-
-; cp temp,MAXDISKS
-; brne fat_scan_for_more
+fat_scan_end:\r
ret