- ldd xl,z+0
- ldd xh,z+1
- ldd yl,z+2
- ldd yh,z+3\r
-\r
- add xl,temp\r
- adc xh,temp2\r
- adc yl,_0\r
- adc yh,_0\r
-\r
- sts fat_ptr2fat ,xl\r
- sts fat_ptr2fat+1,xh\r
- sts fat_ptr2fat+2,yl\r
- sts fat_ptr2fat+3,yh\r
-\r
-.if FAT16_DEBUG > 1\r
- printstring "Begin of FAT 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
-.endif\r
-\r
-; Calculate begin of Root- Directory within the Volume\r
- ldiw z,fat_ptr2fat\r
- ldd xl,z+0\r
- ldd xh,z+1\r
- ldd yl,z+2\r
- ldd yh,z+3\r
-\r
- lds temp ,fat_secperfat\r
- lds temp2,fat_secperfat+1\r
- lds temp3,fat_numfatcp\r
-\r
-fat_calc_dp_loop:\r
- cp temp3,_0\r
- breq fat_calc_dp_lend\r
-\r
- add xl,temp\r
- adc xh,temp2\r
- adc yl,_0\r
- adc yh,_0\r
-\r
- dec temp3\r
-\r
- jmp fat_calc_dp_loop\r
-fat_calc_dp_lend:\r
-\r
- sts fat_ptr2dir ,xl\r
- sts fat_ptr2dir+1,xh\r
- sts fat_ptr2dir+2,yl\r
- sts fat_ptr2dir+3,yh\r
-\r
-\r
-.if FAT16_DEBUG > 1\r
- printstring "Begin of DIR 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
-.endif\r
-\r
-; Calculate begin of DATA Clusters within the Volume\r
-; Num. Dir.Sektors = (Num. of Dir. Entrys * 32) / Bytes per Sektor\r
-\r
-; Sectorsize is fixed at 512 Bytes, makes 16 Entrys per Sektor\r
-\r
- lds zl,fat_numdirentrys ; low byte\r
- lds zh,fat_numdirentrys+1 ; high byte\r
-\r
-; Num. Direntrys / 16\r
- lsr zh\r
- ror zl\r
- lsr zh\r
- ror zl\r
- lsr zh\r
- ror zl\r
- lsr zh\r
- ror zl\r
-\r
- lds xl,fat_ptr2dir\r
- lds xh,fat_ptr2dir+1\r
- lds yl,fat_ptr2dir+2\r
- lds yh,fat_ptr2dir+3\r
-\r
- add xl,zl\r
- adc xh,zh\r
- adc yl,_0\r
- adc yh,_0\r
-\r
- sts fat_ptr2dat ,xl\r
- sts fat_ptr2dat+1,xh\r
- sts fat_ptr2dat+2,yl\r
- sts fat_ptr2dat+3,yh\r
-\r
-.if FAT16_DEBUG > 1\r
- printstring "Begin of Data 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
-.endif\r
-\r
-; Here Starts the Scann of the Directory for valid image Files.\r
-\r
- lds xl,fat_ptr2dir\r
- lds xh,fat_ptr2dir+1\r
- lds yl,fat_ptr2dir+2\r
- lds yh,fat_ptr2dir+3\r
-\r
-; Load first sector from Directory
- call mmcReadSect
- tst temp
- breq fat_look_for_images\r
-\r
-; Read error: Block not found\r
- clr temp\r
- ret\r
-\r
-; Looks at a read directory block for image entrys\r
-fat_look_for_images:\r
- \r
- ldiw z,hostbuf\r
- ldi temp2,0\r
-\r
-fat_look_for_loop: \r
- ldd temp,z+0\r
- cpi temp,'C'\r
- brne fat_look_not_ok\r
- \r
- ldd temp,z+1\r
- cpi temp,'P'\r
- brne fat_look_not_ok\r
-\r
- ldd temp,z+2\r
- cpi temp,'M'\r
- brne fat_look_not_ok\r
-\r
- ldd temp,z+3\r
- cpi temp,'D'\r
- brne fat_look_not_ok\r
-\r
- ldd temp,z+4\r
- cpi temp,'S'\r
- brne fat_look_not_ok\r
-\r
- ldd temp,z+5\r
- cpi temp,'K'\r
- brne fat_look_not_ok\r
-\r
- ldd temp,z+6\r
- cpi temp,'_'\r
- brne fat_look_not_ok\r
-\r
- ldd temp,z+8\r
- cpi temp,'I'\r
- brne fat_look_not_ok\r
-\r
- ldd temp,z+9\r
- cpi temp,'M'\r
- brne fat_look_not_ok\r
-\r
- ldd temp,z+10\r
- cpi temp,'G'\r
- brne fat_look_not_ok\r
-\r
- jmp fat_store_new_entry\r
-\r
-fat_look_not_ok:\r
- \r
- //ldi temp,32\r
- addiw z,32 \r
-\r
- inc temp2\r
- cpi temp2,16 ; max entrys/sector\r
- breq fat_scan_next_sector\r
- jmp fat_look_for_loop\r
-\r
-fat_scan_next_sector:\r
-\r
- ret\r
-\r
-\r
-; Create new Partition Entry\r
-fat_store_new_entry:\r
-\r
-; Found a valid image\r
-.if FAT16_DEBUG > 1\r
- printstring "Found a valid Image ! ",0\r
- printnewline\r
-.endif\r
-\r
- ldiw y,hostparttbl\r
- lds temp,ndisks\r
-\r
-fat_look_store_loop:\r
- cp temp,_0\r
- breq fat_look_store\r
-\r
- adiw y,PARTENTRY_SIZE\r
- dec temp\r
- jmp fat_look_store_loop\r
-\r
-fat_look_store:\r
-; Set Type of Partition to FAT16- Fileimage\r
- ldi temp,dskType_FAT\r
- st y+,temp\r
-\r
+ ldd xl,z+0
+ ldd xh,z+1
+ ldd yl,z+2
+ ldd yh,z+3
+
+ add xl,temp
+ adc xh,temp2
+ adc yl,_0
+ adc yh,_0
+
+ sts fat_ptr2fat ,xl
+ sts fat_ptr2fat+1,xh
+ sts fat_ptr2fat+2,yl
+ sts fat_ptr2fat+3,yh
+
+.if FAT16_DEBUG > 1
+ printstring "Begin of FAT at___: ",0
+ mov temp ,yl
+ mov temp2,yh
+ rcall printhexw
+ mov temp ,xl
+ mov temp2,xh
+ rcall printhexw
+ printnewline
+.endif
+
+; 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
+
+fat_calc_dp_loop:
+ cp temp3,_0
+ breq fat_calc_dp_lend
+
+ add xl,temp
+ adc xh,temp2
+ adc yl,_0
+ adc yh,_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
+
+
+.if FAT16_DEBUG > 1
+ printstring "Begin of DIR at___: ",0
+ mov temp ,yl
+ mov temp2,yh
+ rcall printhexw
+ mov temp ,xl
+ mov temp2,xh
+ rcall printhexw
+ printnewline
+.endif
+
+; Calculate begin of DATA Clusters within the Volume
+; Num. Dir.Sektors = (Num. of Dir. Entrys * 32) / Bytes per Sektor
+
+; Sectorsize is fixed at 512 Bytes, makes 16 Entrys per Sektor
+
+ lds zl,fat_numdirentrys ; low byte
+ lds zh,fat_numdirentrys+1 ; high byte
+
+; Num. Direntrys / 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
+
+ sts fat_ptr2dat ,xl
+ sts fat_ptr2dat+1,xh
+ sts fat_ptr2dat+2,yl
+ sts fat_ptr2dat+3,yh
+
+.if FAT16_DEBUG > 1
+ printstring "Begin of Data at__: ",0
+ mov temp ,yl
+ mov temp2,yh
+ rcall printhexw
+ mov temp ,xl
+ mov temp2,xh
+ rcall 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:
+
+; 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_numdirentrys
+ sts fat_log_clust ,temp
+
+ lds temp,fat_numdirentrys+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
+
+; Add actual offset
+ lds temp,fat_clust_offset
+ add xl,temp
+ adc xh,_0
+ adc yl,_0
+ adc yh,_0
+
+; Load sector from Directory
+ lcall mmcReadSect
+ tst temp
+ breq fat_look_for_images
+
+; Read error: Block not found
+ clr temp
+ ret
+
+; Looks at a read directory block for image entrys
+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_clust_ptr ,zl
+ sts fat_clust_ptr+1,zh
+ sts fat_clust_ptr+2,temp2
+ rjmp fat_store_new_entry
+
+fat_scan_for_more:
+
+ lds zl ,fat_clust_ptr
+ lds zh ,fat_clust_ptr+1
+ lds temp2,fat_clust_ptr+2
+fat_look_not_ok:
+
+ adiw z,32
+
+ inc temp2
+ cpi temp2,16 ; max entrys/sector
+ breq fat_scan_next_sector
+ rjmp fat_look_for_loop
+
+fat_scan_next_sector:
+
+
+ lds temp3, fat_log_clust
+ lds temp4, fat_log_clust+1
+
+ sub temp3,temp2
+ sbc temp4,_0
+
+ sts fat_log_clust,temp3
+ sts fat_log_clust+1,temp4
+
+ cp temp3,_0
+ cpc temp4,_0
+ breq fat_scan_at_end
+
+ lds temp,fat_clust_offset
+ inc temp
+ sts fat_clust_offset,temp
+
+ rjmp fat_next_sector_loop
+
+fat_scan_at_end:
+
+ lds temp,fat_last_dsk
+ inc temp
+ sts fat_last_dsk,temp
+
+ ldi temp2,FAT16_LAST_IMAGENAME
+ cp temp,temp2
+ brge fat_scaned_last_disk
+
+ rjmp fat_scan_for_next_image
+
+fat_scaned_last_disk:
+
+ rjmp fat_scan_end
+
+
+; Create new Partition Entry
+fat_store_new_entry:
+
+; Found a valid image
+.if FAT16_DEBUG > 1
+ printstring "Found a valid Image ! Z=",0
+ mov temp ,zl
+ mov temp2,zh
+ rcall printhexw
+ printnewline
+.endif
+
+ ldiw y,hostparttbl
+ lds temp,ndisks
+
+fat_look_store_loop:
+ cp temp,_0
+ breq fat_look_store
+
+ adiw y,PARTENTRY_SIZE
+ dec temp
+ rjmp fat_look_store_loop
+
+fat_look_store:
+; Set Type of Partition to FAT16- Fileimage
+ ldi temp,dskType_FAT
+ st y+,temp
+
+