]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avr/dsk_fat16.asm
* FAT buffer on ATmega328
[avrcpm.git] / avr / dsk_fat16.asm
index 61f81652999c37c1aa8057f717839f7cfc84715a..d8ecd6fb8652dec05fd2cbfec35c2f2ddeff16fe 100644 (file)
@@ -84,6 +84,14 @@ fat_clust_ptr:         .byte  4      ; sector of last real cluster
        .equ    o_fat_clust_offset= 17
        .equ    o_fat_clust_ptr   = 18
 
+.if SRAM_SIZE > 1024
+
+fat_last_fatsect:      .byte   1
+       .equ    o_fat_last_fatsect = 22
+
+fat_buf:       .byte   512
+
+.endif
 
 ; ############################################################################ 
 ;                              Start of Code Segment
@@ -137,6 +145,10 @@ fat_reset_cache:
        std     y+o_fat_log_clust  ,_255
        std     y+o_fat_log_clust+1,_255
        std     y+o_fat_last_dsk   ,_255
+.if SRAM_SIZE > 1024
+       std     y+o_fat_last_fatsect,_255
+.endif
+
        ret
 
 ; ============================================================================
@@ -225,6 +237,7 @@ fat_scan_partition:
        ldd     xh,z+1
        ldd     yl,z+2
        ldd     yh,z+3
+       ldiw    z,hostbuf
 
 ; Load first sector from Partition
        rcall   mmcReadSect
@@ -426,6 +439,7 @@ fat_next_sector_loop:
        sbc     yh,_0
 
 ;  Load sector from Directory
+       ldiw    z,hostbuf
        lcall   mmcReadSect
        tst     temp
        breq    fat_look_for_images
@@ -784,28 +798,62 @@ fat_next_phsy_clust:
        push    xl
        push    xh
 
-;   Create FAT Offset Value
+; Create FAT Offset Value
+
        clr     zh
        mov     zl,yl
        lsl     zl
        rol     zh
-;   Get FAT Start
        mov     temp,yh
-       lds     xl,fat_ptr2fat
+
+.if SRAM_SIZE > 1024
+
+; Check, if required fat sector allready in buffer
+
+       lds     temp2,fat_last_fatsect
+       sts     fat_last_fatsect,temp
+       cp      temp,temp2
+       breq    fat_phys_1
+
+; Not in buffer, get fat sector
+
+       lds     xl,fat_ptr2fat                  ;get FAT start
        lds     xh,fat_ptr2fat+1
        lds     yl,fat_ptr2fat+2
        lds     yh,fat_ptr2fat+3
-;   Add Cluster offset within sector
-       add     xl,temp
+       add     xl,temp                         ;add cluster offset within sector
+       adc     xh,_0
+       adc     yl,_0
+       adc     yh,_0
+       push    zl
+       push    zh
+       ldiw    z,fat_buf
+       lcall   mmcReadSect
+       pop     zh
+       pop     zl
+
+fat_phys_1:
+       ldiw    y,fat_buf
+       add     zl,yl
+       adc     zh,yh
+       ldd     yl,z+0
+       ldd     yh,z+1
+.else
+
+       lds     xl,fat_ptr2fat                  ;get FAT start
+       lds     xh,fat_ptr2fat+1
+       lds     yl,fat_ptr2fat+2
+       lds     yh,fat_ptr2fat+3
+       add     xl,temp                         ;add cluster offset within sector
        adc     xh,_0
        adc     yl,_0
        adc     yh,_0
        lcall   mmcReadWord
-
+       movw    y,z
+.endif
        pop     xh
        pop     xl
 
-       movw    y,z
 
 ;      Check next logical Cluster