]> cloudbase.mooo.com Git - avrcpm.git/commitdiff
* More changes for FAT16 support.
authorFrank Zoll <fzoll@web.de>
Fri, 1 Oct 2010 06:58:07 +0000 (06:58 +0000)
committerFrank Zoll <fzoll@web.de>
Fri, 1 Oct 2010 06:58:07 +0000 (06:58 +0000)
git-svn-id: svn://cu.loc/avr-cpm/trunk@107 57430480-672e-4586-8877-bcf8adbbf3b7

avrcpm/avr/8080int-jmp.asm
avrcpm/avr/config.inc
avrcpm/avr/dsk_fat16.asm
avrcpm/avr/init.asm
avrcpm/avr/mmc.asm

index 742a4ed964648c05a022bfc058ac334895779f41..eabe603230fe7fc63024f7e811299c9e590e0108 100644 (file)
@@ -651,7 +651,7 @@ do_store_am:
 
 do_op_inv:
        sbiw    z_pcl,1
-       rcall printregs
+       call printregs
        printstring "Invalid opcode! "
 
 haltinv:
index d65608780ad73048fed39de1bbc6692bb966bd09..5818fa4a87effb07dd73bbc5fb8121ddd040df9e 100644 (file)
@@ -26,7 +26,7 @@
 #define VMINOR 0
 
 #ifndef DRAM_8BIT
-  #define DRAM_8BIT 0          /* 1 = 8bit wide DRAM */
+  #define DRAM_8BIT 1          /* 1 = 8bit wide DRAM */
 #endif
 #ifndef F_CPU
   #define F_CPU  20000000      /* system clock in Hz; defaults to 20MHz */
index 0cc32af945e0c290cb75febdfcd7f2d93a541baf..9caf6baa4b04c08584deeabc8333550d88ecba44 100644 (file)
 ;    along with avrcpm.  If not, see <http://www.gnu.org/licenses/>.
 ;
 ;    $Id$
-;\r
-\r
-; ===========================================================================\r
-; Prelimitary !\r
-; °°°°°°°°°°°°°\r
-; Size of a Sector is fixed to 512 Bytes by Base - MMC Driver implementation\r
-; The Functions below therefore assume a fixed Size of 512 Bytes per Sector.\r
-; ===========================================================================\r
-\r
-#ifndef FAT16_SUPPORT\r
-       #define FAT16_SUPPORT 1\r
-       #define FAT16_DEBUG   2\r
-#endif\r
-\r
-#if FAT16_SUPPORT\r
-\r
-\r
+;
+
+; ===========================================================================
+; Prelimitary !
+; °°°°°°°°°°°°°
+; Size of a Sector is fixed to 512 Bytes by Base - MMC Driver implementation
+; The Functions below therefore assume a fixed Size of 512 Bytes per Sector.
+; ===========================================================================
+
+#ifndef FAT16_SUPPORT
+       #define FAT16_SUPPORT 1
+       #define FAT16_DEBUG   2
+#endif
+
+#if FAT16_SUPPORT
+
+
 ;-------------------------------- Defines for FAT16 Structures
-#define PARTID_FAT16 0x0E\r
-\r
-;#define FAT16_BSO_SECSIZE     0x0b            ; BootSectorOffset to Sectorsize Word\r
-#define FAT16_BSO_CLUSTSZ   0x0d        ; BootSectorOffset to Clustersize Byte\r
-#define FAT16_BSO_RESSECT   0x0e               ; BootSectorOffset to Number of Reserved Sectors\r
-#define FAT16_BSO_VOLPTR    0x1c        ; BootSectorOffset to First VolumeSector\r
-#define FAT16_BSO_SECPERFAT 0x16        ; BootSectorOffset to Number of Sectors per Fat\r
-#define FAT16_BSO_NUMFATCP  0x10               ; BootSectorOffset to Ammount of FAT Copys\r
-#define FAT16_BSO_NUMDIRENT 0x11               ; BootSectorOffset to Max. Root Dir. Entrys\r
-\r
+#define PARTID_FAT16 0x0E
+
+;#define FAT16_BSO_SECSIZE     0x0b            ; BootSectorOffset to Sectorsize Word
+#define FAT16_BSO_CLUSTSZ   0x0d        ; BootSectorOffset to Clustersize Byte
+#define FAT16_BSO_RESSECT   0x0e               ; BootSectorOffset to Number of Reserved Sectors
+#define FAT16_BSO_VOLPTR    0x1c        ; BootSectorOffset to First VolumeSector
+#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
+
 ;-------------------------------- Start of Data Segment
 
-       .dseg\r
-\r
+       .dseg
+
 fat_partfound:   .byte   1   ; (0= no fat partition found 1=found partition)
 fat_parttbl:    .byte   8       ; first fat16 partition entry (start sector, sector count)
-;fat_sectorsize:  .byte   2   ; size of sector in bytes\r
-fat_clustersize: .byte   1   ; sectors per cluster\r
-fat_ressectors:  .byte   2   ; number of reserved sectors\r
-fat_secperfat:   .byte   2   ; number of sectors per fat\r
-fat_numfatcp:    .byte   1   ; Number of FAT Copies\r
-fat_numdirentrys:.byte   2   ; Max. ammount of Directory Entrys within Rootdirektory\r
-fat_ptr2fat:     .byte   4   ; pointer to the first fat sector\r
-fat_ptr2dir:     .byte   4   ; pointer to the first root directory sector\r
-fat_ptr2dat:     .byte   4   ; pointer to the first data sector\r
-\r
+;fat_sectorsize:  .byte   2   ; size of sector in bytes
+fat_clustersize: .byte   1   ; sectors per cluster
+fat_ressectors:  .byte   2   ; number of reserved sectors
+fat_secperfat:   .byte   2   ; number of sectors per fat
+fat_numfatcp:    .byte   1   ; Number of FAT Copies
+fat_numdirentrys:.byte   2   ; Max. ammount of Directory Entrys within Rootdirektory
+fat_ptr2fat:     .byte   4   ; pointer to the first fat sector
+fat_ptr2dir:     .byte   4   ; pointer to the first root directory sector
+fat_ptr2dat:     .byte   4   ; pointer to the first data sector
+
+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
 ; ------------------------------- Start of Code Segment
-       .cseg\r
-\r
-; ====================================================================\r
+       .cseg
+
+; ====================================================================
 ; Function: Does a Disk read/write operation
-; ====================================================================\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_init_partitiontable:\r
-\r
-       sts fat_partfound,_0\r
-\r
-       ldiw    y,fat_parttbl\r
-       st      y+,_0\r
-       st      y+,_0\r
-       st      y+,_0\r
-       st      y+,_0\r
-       st      y+,_0\r
-       st      y+,_0\r
-       st      y+,_0\r
-       st      y+,_0\r
-       ret\r
-\r
-; ====================================================================\r
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : none
+; Variables  : [r] seekdsk             Number of Disk to Read
+;                         [r] seeksec          Sector to read
+;              [r] seektrk             Track  to read
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
+fat_init_partitiontable:
+
+       sts fat_partfound,_0
+
+       ldiw    y,fat_parttbl
+       st      y+,_0
+       st      y+,_0
+       st      y+,_0
+       st      y+,_0
+       st      y+,_0
+       st      y+,_0
+       st      y+,_0
+       st      y+,_0
+       ldi     yl,0xFF
+       sts fat_log_clust  ,yl
+       sts     fat_log_clust+1,yl
+       sts     fat_last_dsk   ,yl
+       ret
+
+; ====================================================================
 ; Function: Add's a FAT16 Partition for later Scanning
-; ====================================================================\r
-; Parameters\r
-; --------------------------------------------------------------------\r
-; Registers  : \r
-; Variables  : \r
-; --------------------------------------------------------------------\r
-; Description:\r
-; This funktion sets the internal Variables to set Start and Size\r
-; of a given FAT16 Paritition. This Information will be used for a\r
-; later scanning of the Partition. See Function "fat_scan_partition"\r
-; for more information. \r
-; ====================================================================\r
-fat_add_partition:\r
-       \r
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : 
+; Variables  : 
+; --------------------------------------------------------------------
+; Description:
+; This funktion sets the internal Variables to set Start and Size
+; of a given FAT16 Paritition. This Information will be used for a
+; later scanning of the Partition. See Function "fat_scan_partition"
+; for more information. 
+; ====================================================================
+fat_add_partition:
+       
 .if FAT16_DEBUG > 0
-       printstring "fat16 part found",0\r
-       printnewline\r
-.endif\r
-\r
-\r
-;   save variables on stack\r
-       push    yl\r
-       push    yh\r
-\r
-; set fat16 partition found flag\r
-       ldi     yl,1\r
-       sts     fat_partfound,yl\r
-\r
-;   save data from first fat16 partition\r
+       printstring "fat16 part found",0
+       printnewline
+.endif
+
+
+;   save variables on stack
+       push    yl
+       push    yh
+
+; set fat16 partition found flag
+       ldi     yl,1
+       sts     fat_partfound,yl
+
+;   save data from first fat16 partition
        ldiw    y,fat_parttbl
 
        ldd             temp,z+PART_START
@@ -141,580 +149,629 @@ fat_add_partition:
        ldd             temp,z+PART_SIZE+2
        st              y+,temp
        ldd             temp,z+PART_SIZE+3
-       st              y+,temp\r
-\r
-\r
-;   reload variables from stack\r
-       pop             yh\r
-       pop     yl\r
+       st              y+,temp
+
+
+;   reload variables from stack
+       pop             yh
+       pop     yl
 
        ret
-\r
-; --------------------------------------------------------------------------- \r
+
+; --------------------------------------------------------------------------- 
 ; Read and Scann a FAT16 Partition for Imagedatefiles 
-; --------------------------------------------------------------------------- \r
-; This Routine reads the Bootblock and scanns it for a Diskimage\r
-; Input Registers  : none\r
-; Output Registers : none\r
-; Changes Variables: none\r
-; --------------------------------------------------------------------------- \r
-\r
-\r
-fat_scan_partition:\r
-\r
+; --------------------------------------------------------------------------- 
+; This Routine reads the Bootblock and scanns it for a Diskimage
+; Input Registers  : none
+; Output Registers : none
+; Changes Variables: none
+; --------------------------------------------------------------------------- 
+
+
+fat_scan_partition:
+
 .if FAT16_DEBUG > 0
-       printstring "fat16 scanning",0\r
-       printnewline\r
-.endif\r
-\r
-; Check if a FAT16 Partition was realy found\r
-       lds             yl,fat_partfound\r
-       cpi     yl,1    \r
-       brne    fat_scan_error \r
-\r
-\r
+       printstring "fat16 scanning",0
+       printnewline
+.endif
+
+; Check if a FAT16 Partition was realy found
+       lds             yl,fat_partfound
+       cpi     yl,1    
+       brne    fat_scan_error 
+
+
 .if FAT16_DEBUG > 0
-       printstring "free entrys in ptable ?",0\r
-       printnewline\r
-.endif\r
-\r
-; Check for free Entrys in Partition table\r
-       lds             yl,ndisks\r
-       cpi             yl,MAXDISKS\r
-       breq    fat_scan_error\r
-\r
+       printstring "free entrys in ptable ?",0
+       printnewline
+.endif
+
+; Check for free Entrys in Partition table
+       lds             yl,ndisks
+       cpi             yl,MAXDISKS
+       breq    fat_scan_error
+
 .if FAT16_DEBUG > 0
-       printstring "read fat bootblock.",0\r
-       printnewline\r
-.endif\r
-\r
-; Scan partition start\r
+       printstring "read fat bootblock.",0
+       printnewline
+.endif
+
+; Scan partition start
        ldiw    z,fat_parttbl   
        ldd             xl,z+0          
        ldd             xh,z+1
        ldd             yl,z+2
-       ldd             yh,z+3\r
-\r
+       ldd             yh,z+3
+
 ; Load first sector from Partition
        rcall   mmcReadSect
        tst         temp
-       breq    fat_bootblock_check\r
-\r
-; Read error: Block not found\r
-fat_scan_error:\r
-       clr temp\r
-       ret\r
-\r
-fat_bootblock_check:\r
-\r
+       breq    fat_bootblock_check
+
+; Read error: Block not found
+fat_scan_error:
+       clr temp
+       ret
+
+fat_bootblock_check:
+
+.if FAT16_DEBUG > 0
+       printstring "fat16 bootblock check",0
+       printnewline
+.endif
+
+; -> Size of Sectors fixed at 512 Bytes
+;   Get ammount of Bytes per Sector
+;      ldiw    z,hostbuf+FAT16_BSO_SECSIZE
+;      ldiw    y,fat_sectorsize
+;      ld          temp,z
+;      st      y+, temp
+;      ldd         temp2,z+1
+;      st      y , temp2
+;
+;.if FAT16_DEBUG > 0
+;      printstring "Bytes per Sector ",0
+;      rcall printhexw
+;      printnewline
+;.endif
+
+;   Anzahl der Sectoren pro Cluster lesen
+       ldiw    z,hostbuf+FAT16_BSO_CLUSTSZ
+       ld              temp,z
+       sts     fat_clustersize,temp
+
 .if FAT16_DEBUG > 0
-       printstring "fat16 bootblock check",0\r
-       printnewline\r
-.endif\r
-\r
-; -> Size of Sectors fixed at 512 Bytes\r
-;   Get ammount of Bytes per Sector\r
-;      ldiw    z,hostbuf+FAT16_BSO_SECSIZE\r
-;      ldiw    y,fat_sectorsize\r
-;      ld          temp,z\r
-;      st      y+, temp\r
-;      ldd         temp2,z+1\r
-;      st      y , temp2\r
-;\r
-;.if FAT16_DEBUG > 0\r
-;      printstring "Bytes per Sector ",0\r
-;      rcall printhexw\r
-;      printnewline\r
-;.endif\r
-\r
-;   Anzahl der Sectoren pro Cluster lesen\r
-       ldiw    z,hostbuf+FAT16_BSO_CLUSTSZ\r
-       ld              temp,z\r
-       sts     fat_clustersize,temp\r
-\r
-.if FAT16_DEBUG > 0\r
-       printstring "Sectors per Cluster ",0\r
-       rcall printhex\r
-       printnewline\r
-.endif\r
-\r
-;   Anzahl der reservierten Sectoren\r
-       ldiw    z,hostbuf+FAT16_BSO_RESSECT\r
-       ld              temp,z+\r
-       sts     fat_ressectors,temp                     ; low byte\r
-       ld              temp2,z\r
-       sts             fat_ressectors+1,temp2          ; high byte\r
-\r
-.if FAT16_DEBUG > 0\r
-       printstring "Reserved Sectors__: ",0\r
-       rcall printhexw\r
-       printnewline\r
-.endif\r
-\r
-;   Anzahl der Sectoren pro FAT\r
-       ldiw    z,hostbuf+FAT16_BSO_SECPERFAT\r
-       ld              temp,z+\r
-       sts     fat_secperfat,temp                      ; low byte\r
-       ld              temp2,z\r
-       sts             fat_secperfat+1,temp2           ; high byte\r
-\r
-.if FAT16_DEBUG > 0\r
-       printstring "Sectors per FAT__: ",0\r
-       rcall printhexw\r
-       printnewline\r
-.endif\r
-\r
-;   Anzahl der FAT kopien\r
-       ldiw    z,hostbuf+FAT16_BSO_NUMFATCP\r
-       ld              temp,z\r
-       sts     fat_numfatcp,temp                       ; low byte\r
-\r
-.if FAT16_DEBUG > 0\r
-       printstring "Ammount of FAT copies: ",0\r
-       rcall printhex\r
-       printnewline\r
-.endif\r
-\r
-;   Max. Anzahl der Dir. Enträge im Root Verz.\r
-       ldiw    z,hostbuf+FAT16_BSO_NUMDIRENT\r
-       ld              temp,z+\r
-       sts     fat_numdirentrys,temp                   ; low byte\r
-       ld              temp2,z\r
-       sts             fat_numdirentrys+1,temp2                ; high byte\r
-\r
-.if FAT16_DEBUG > 0\r
-       printstring "Max. entrys in Rootdir.: ",0\r
-       rcall printhexw\r
-       printnewline\r
-.endif\r
-\r
-; Print begin of Volume\r
-.if FAT16_DEBUG > 1\r
-\r
+       printstring "Sectors per Cluster ",0
+       rcall printhex
+       printnewline
+.endif
+
+;   Anzahl der reservierten Sectoren
+       ldiw    z,hostbuf+FAT16_BSO_RESSECT
+       ld              temp,z+
+       sts     fat_ressectors,temp                     ; low byte
+       ld              temp2,z
+       sts             fat_ressectors+1,temp2          ; high byte
+
+.if FAT16_DEBUG > 0
+       printstring "Reserved Sectors__: ",0
+       rcall printhexw
+       printnewline
+.endif
+
+;   Anzahl der Sectoren pro FAT
+       ldiw    z,hostbuf+FAT16_BSO_SECPERFAT
+       ld              temp,z+
+       sts     fat_secperfat,temp                      ; low byte
+       ld              temp2,z
+       sts             fat_secperfat+1,temp2           ; high byte
+
+.if FAT16_DEBUG > 0
+       printstring "Sectors per FAT__: ",0
+       rcall printhexw
+       printnewline
+.endif
+
+;   Anzahl der FAT kopien
+       ldiw    z,hostbuf+FAT16_BSO_NUMFATCP
+       ld              temp,z
+       sts     fat_numfatcp,temp                       ; low byte
+
+.if FAT16_DEBUG > 0
+       printstring "Ammount of FAT copies: ",0
+       rcall printhex
+       printnewline
+.endif
+
+;   Max. Anzahl der Dir. Enträge im Root Verz.
+       ldiw    z,hostbuf+FAT16_BSO_NUMDIRENT
+       ld              temp,z+
+       sts     fat_numdirentrys,temp                   ; low byte
+       ld              temp2,z
+       sts             fat_numdirentrys+1,temp2                ; high byte
+
+.if FAT16_DEBUG > 0
+       printstring "Max. entrys in Rootdir.: ",0
+       rcall printhexw
+       printnewline
+.endif
+
+; Print begin of Volume
+.if FAT16_DEBUG > 1
+
        ldiw    z,fat_parttbl   
        ldd             xl,z+0          
        ldd             xh,z+1
        ldd             yl,z+2
-       ldd             yh,z+3\r
-\r
-       printstring "Begin of Volume 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 FAT within the Volume\r
-       lds             temp ,fat_ressectors\r
-       lds             temp2,fat_ressectors+1\r
-\r
+       ldd             yh,z+3
+
+       printstring "Begin of Volume at: ",0
+       mov             temp ,yl
+       mov             temp2,yh
+       rcall printhexw
+       mov             temp ,xl
+       mov             temp2,xh
+       rcall printhexw
+       printnewline
+.endif
+
+; Calculate begin of FAT within the Volume
+       lds             temp ,fat_ressectors
+       lds             temp2,fat_ressectors+1
+
        ldiw    z,fat_parttbl   
        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
+       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_secperfat
+       lds             temp2,fat_secperfat+1
+       lds             temp3,fat_numfatcp
+
+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
+
+       jmp             fat_calc_dp_loop
+fat_calc_dp_lend:
+
+       sts             fat_ptr2dir  ,xl
+       sts             fat_ptr2dir+1,xh
+       sts             fat_ptr2dir+2,yl
+       sts             fat_ptr2dir+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_ptr2dir
+       lds             xh,fat_ptr2dir+1
+       lds             yl,fat_ptr2dir+2
+       lds             yh,fat_ptr2dir+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.
+
+       lds             xl,fat_ptr2dir
+       lds             xh,fat_ptr2dir+1
+       lds             yl,fat_ptr2dir+2
+       lds             yh,fat_ptr2dir+3
+
 ;  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
+       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
+
+       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
+
+       jmp             fat_store_new_entry
+
+fat_look_not_ok:
+       
+       //ldi           temp,32
+       addiw   z,32                    
+
+       inc             temp2
+       cpi             temp2,16                                ; max entrys/sector
+       breq    fat_scan_next_sector
+       jmp     fat_look_for_loop
+
+fat_scan_next_sector:
+
+       ret
+
+
+;      Create new Partition Entry
+fat_store_new_entry:
+
+;   Found a valid image
+.if FAT16_DEBUG > 1
+       printstring "Found a valid Image ! ",0
+       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
+       jmp             fat_look_store_loop
+
+fat_look_store:
+;   Set Type of Partition to FAT16- Fileimage
+       ldi temp,dskType_FAT
+       st      y+,temp
+
 ;   Offset to Startcluster + 2
        ldd     temp,z+0x1A
        st      y+,temp
        ldd     temp,z+0x1B
-       st      y+,temp \r
-       ldi     temp,0\r
+       st      y+,temp 
+       ldi     temp,0
        st      y+,temp
-       st      y+,temp\r
-\r
-;   Filesize in Bytes - 2,4,8,16,32,64,128,256,512 \r
-;      ldd     temp,z+0x1C\r
+       st      y+,temp
+
+;   Filesize in Bytes - 2,4,8,16,32,64,128,256,512 
+;      ldd     temp,z+0x1C
 ;      st      y+,temp
-;      ldd     temp,z+0x1D\r
+;      ldd     temp,z+0x1D
 ;      st      y+,temp
-;      ldd     temp,z+0x1E\r
+;      ldd     temp,z+0x1E
 ;      st      y+,temp
-;      ldd     temp,z+0x1F\r
-;      st      y+,temp\r
-\r
-;   Convert Filesize to ammount of sectors\r
-       ldd     xl,z+0x1D\r
-       ldd     xh,z+0x1E\r
-       ldd     zl,z+0x1F\r
-       mov     zh,_0\r
-\r
-       lsr     zh\r
-       ror zl\r
-       ror xh\r
-       ror xl\r
-\r
-;   store ammount of sectors in partitiontable \r
+;      ldd     temp,z+0x1F
+;      st      y+,temp
+
+;   Convert Filesize to ammount of sectors
+       ldd     xl,z+0x1D
+       ldd     xh,z+0x1E
+       ldd     zl,z+0x1F
+       mov     zh,_0
+
+       lsr     zh
+       ror zl
+       ror xh
+       ror xl
+
+;   store ammount of sectors in partitiontable 
        st  y+,xl
        st  y+,xh
        st  y+,zl
        st  y+,zh
-\r
-; Check for another free entry in partition table\r
-       lds     temp,ndisks\r
-       inc     temp\r
-       sts     ndisks,temp\r
-       \r
-\r
-.if FAT16_DEBUG > 1\r
-; Test finding of the first sector\r
-       ldd     xl,z+0x1A\r
-       ldd     xh,z+0x1B\r
-       ldi     zl,0\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
-       \r
-;      cp              temp,MAXDISKS\r
-;      brne    fat_scan_for_more       \r
-               \r
-       ret\r
-\r
-\r
-; ====================================================================\r
-; Function: Cluster+Offset to HostSector 
-; ====================================================================\r
-; Parameters: [in]     xh,xl                   Cluster Number\r
-;                        [in]  zl                              Offset\r
-;                        [out] yh,yl,xh,xl             Sector Number on Disk\r
-; --------------------------------------------------------------------\r
-; Registers  :         \r
-; Variables  :         [used]  fat_clustersize Ammount of Sectors per Cluster\r
-;                              [changes] temp\r
-; --------------------------------------------------------------------\r
-; Description:\r
-; ! Only works with Clustersizes 1,2,4,8,16,32,64,128 !\r
-; ====================================================================\r
-fat_gethostsec:\r
-\r
-;      Get Offset into Data area of Disk\r
-       rcall   fat_clusttosec\r
-\r
-;      add given offset\r
-       add             xl,zl\r
-       adc             xh,_0\r
-       adc             yl,_0\r
-       adc             yh,_0\r
-\r
-;      add begin of data area to offset\r
-       lds             temp,fat_ptr2dat+0\r
-       add             xl,temp\r
-       lds             temp,fat_ptr2dat+1\r
-       adc             xh,temp\r
-       lds             temp,fat_ptr2dat+2\r
-       adc             yl,temp\r
-       lds             temp,fat_ptr2dat+3\r
-       adc             yh,temp\r
-       ret\r
-\r
-; ====================================================================\r
+
+; Check for another free entry in partition table
+       lds     temp,ndisks
+       inc     temp
+       sts     ndisks,temp
+       
+
+.if FAT16_DEBUG > 1
+; Test finding of the first sector
+       ldd     xl,z+0x1A
+       ldd     xh,z+0x1B
+       ldi     zl,0
+
+       rcall   fat_gethostsec
+
+       printstring "Begin of Image at: ",0
+       mov             temp ,yl
+       mov             temp2,yh
+       rcall printhexw
+       mov             temp ,xl
+       mov             temp2,xh
+       rcall printhexw
+       printnewline
+
+.endif
+       
+;      cp              temp,MAXDISKS
+;      brne    fat_scan_for_more       
+               
+       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 
-; ====================================================================\r
-; Parameters: [in]     xl,xh                   Cluster Number\r
-;                        [out] xl,xh,yl,yh             Sector Number\r
-; --------------------------------------------------------------------\r
-; Registers  :         \r
-; Variables  :         [used]  fat_clustersize Ammount of Sectors per Cluster\r
-;                              [changes] temp\r
-; --------------------------------------------------------------------\r
-; Description:\r
-; ! Only works with Clustersizes 1,2,4,8,16,32,64,128 !\r
-; ====================================================================\r
-fat_clusttosec:\r
-       clr     yl\r
-       clr             yh\r
-\r
-       ldi             temp,2\r
-       sub             xl,temp         ; Substract the 2 reserved clusters\r
-       sbc             xh,_0\r
-\r
-       lds             temp,fat_clustersize\r
-\r
-fat_c2s_loop:\r
-       lsr             temp\r
-       tst             temp\r
-       breq    fat_c2s_end\r
-\r
-       lsl             xl\r
-       rol             xh\r
-       rol             yl\r
-       rol             yh\r
-       rjmp    fat_c2s_loop\r
-\r
-fat_c2s_end:\r
-       ret\r
-\r
-; ====================================================================\r
-; Function: CP/M Sector to Cluster & Offset 
-; ====================================================================\r
-; Parameters: [in]     xl,xh                   Cluster Number\r
-;                        [out] xl,xh,yl,yh             Sector Number\r
-; --------------------------------------------------------------------\r
-; Registers  :         \r
-; Variables  :         [used]  fat_clustersize Ammount of Sectors per Cluster\r
-;                              [changes] temp\r
-; --------------------------------------------------------------------\r
-; Description:\r
-; ! Only works with Clustersizes 1,2,4,8,16,32,64,128 !\r
-; ====================================================================\r
-fat_cpmtoclust:\r
-\r
-       ret\r
-\r
-; ====================================================================\r
+; ====================================================================
+; Parameters: [in]     xl,xh                   Cluster Number
+;                        [out] xl,xh,yl,yh             Sector Number
+; --------------------------------------------------------------------
+; 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_clusttosec:
+       clr     yl
+       clr             yh
+
+       ldi             temp,2
+       sub             xl,temp         ; Substract the 2 reserved clusters
+       sbc             xh,_0
+
+       lds             temp,fat_clustersize
+
+fat_c2s_loop:
+       tst             temp
+       breq    fat_c2s_end
+       lsr             temp
+
+       lsl             xl
+       rol             xh
+       rol             yl
+       rol             yh
+       rjmp    fat_c2s_loop
+
+fat_c2s_end:
+       ret
+
+; ====================================================================
+; Function: Searches a physical Cluster, given the logical Cluster
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : [r] xh,xl               logical- Cluster 
+;                         [w] yh,yl            physical- Cluster
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
+fat_find_phsy_clust:
+       mov     temp2,xl
+       lds             xl,hostdsk
+
+       rcall   dsk_getpartentry        ; get partition entry
+       mov     xl,temp2
+
+;      Get First FAT- Cluster Number of Diskimage
+       
+       ldd             xl,z+1
+       ldd             xh,z+2
+
+fat_next_phsy_clust:   
+       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- Entrys per Sector
+; so given:  yl is the Offset within the FAT Sector
+;            yh is the number off se FAT sector to Read 
+
+;      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
+
+;   Create FAT Offset Value
+       clr     zh
+       mov zl,yl
+       lsl     zl
+       rol zh
+;   Get FAT Start
+       mov temp,yh
+       lds xl,fat_ptr2fat
+       lds xh,fat_ptr2fat+1
+       lds yl,fat_ptr2fat+2
+       lds yh,fat_ptr2fat+3
+;   Add Sector offset
+       add     xl,temp
+       adc     xh,_0
+       adc yl,_0
+       adc yh,_0
+       call mmcReadWord
+
+       pop xh
+       pop xl
+
+       mov yl,zl
+       mov yh,zh
+
+;      Check next logical Cluster
+       ldi             zl,1
+       sub             xl,zl
+       sbc             xh,_0
+       rjmp    fat_next_phsy_clust
+       
+; Found the physical cluster
+fat_found_phsy_clust:  
+       ret
+
+; ====================================================================
 ; Function: Does a Disk write operation
-; ====================================================================\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
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : none
+; Variables  : [r] seekdsk             Number of Disk to Read
+;                         [r] seeksec          Sector to read
+;              [r] seektrk             Track  to read
 ; hostdsk = host disk #,  (partition #)
 ; hostlba = host block #, relative to partition start 
-; Read/Write "hostsize" bytes to/from hostbuf\r
-; --------------------------------------------------------------------\r
-; Description:\r
+; Read/Write "hostsize" bytes to/from hostbuf
+; --------------------------------------------------------------------
+; Description:
 ; ====================================================================
 
 fat_hostparam:
        lds             xl,hostdsk
-\r
+
 .if HOSTRW_DEBUG
        mov     temp,xl
        subi    temp,-('A')
        rcall   uartputc
        printstring ": "
 .endif
-\r
+
        rcall dsk_getpartentry  ; get partition entry
-\r
-fat_hostlend:\r
+
+fat_hostlend:
        lds             temp ,hostlba
        lds             temp2,hostlba+1
        lds             temp3,hostlba+2
@@ -755,15 +812,97 @@ fat_hostlend:
        ret
 
 fat_hp1:
-       ldd             xl,z+1                  ; startsector
-       ldd             xh,z+2
-       ldd             yl,z+3
-       ldd             yh,z+4
+; ################# Get logical Number of Cluster within the imagefile
+;      printstring "calc log sector"
+; Get logical Sectornumber from temp
+       mov     xl,temp
+       mov     xh,temp2
+       mov     yl,temp3
+       mov     yh,_0
+; Divide logical Sectornumber by size of Cluster in sectors
+       lds             zl,     fat_clustersize
+fat_search_clst_lp:
+       tst             zl
+       breq    fat_found_clst
 
-       add             xl,temp                 ; startsector + offset
-       adc             xh,temp2
-       adc             yl,temp3
-       adc             yh,_0\r
+       lsr             yh
+       ror             yl
+       ror             xh
+       ror             xl
+       
+       lsr             zl
+
+       rjmp    fat_search_clst_lp      
+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
+       mov             yl,xl
+       lds             zl,     fat_clustersize
+fat_search_clst_lp2:
+       tst             zl
+       breq    fat_found_subsec
+       lsl             yl
+
+       lsr             zl
+       rjmp    fat_search_clst_lp2             
+
+fat_found_subsec:
+       mov             zl,temp
+       sub             zl,yl
+       sts             fat_clust_offset,zl
+
+; Check against last HOSTDISK searched
+       lds             yl,fat_last_dsk
+       lds             yh,hostdsk
+       cp              yl,yh
+       brne    fat_wrong_cache_clst
+
+; Check against last Cluster searched
+       lds             yl,fat_log_clust
+       lds             yh,fat_log_clust+1
+
+       cp              yl,xl
+       brne    fat_wrong_cache_clst
+       cp              yh,xh
+       brne    fat_wrong_cache_clst
+
+;   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
+       lds             yh,fat_clust_ptr+3
+
+       rjmp    fat_add_offset
+
+; ################# Cluster is not in cache, so we must search for it
+fat_wrong_cache_clst:
+       lds             yl,hostdsk
+       sts             fat_last_dsk,yl
+       sts             fat_log_clust,xl
+       sts             fat_log_clust+1,xh
+
+; ################# Map Logical Cluster-Number to "Physical" Cluster Number using the FAT
+       rcall   fat_find_phsy_clust
+
+; ################# Get StartSector of "physical" Cluster
+       mov     xl,yl
+       mov             xh,yh
+       rcall   fat_gethostsec
+
+;   Save the found Sector for later use into cache
+       sts             fat_clust_ptr  ,xl
+       sts             fat_clust_ptr+1,xh
+       sts             fat_clust_ptr+2,yl
+       sts             fat_clust_ptr+3,yh
+
+;   Add- Subsector to Startsector 
+fat_add_offset:
+       lds             zl,fat_clust_offset
+       add             xl,zl
+       adc             xh,_0
+       adc             yl,_0
+       adc             yh,_0
 
 .if HOSTRW_DEBUG
        printstring ", abs:"
@@ -779,23 +918,23 @@ fat_hp1:
        pop             temp3
        pop             temp4
        printstring " "
-.endif\r
+.endif
 
        ori             temp,255
 fat_hpex:
        ret
 
-; ====================================================================\r
+; ====================================================================
 ; Function: Does a Disk write operation
-; ====================================================================\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
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : none
+; Variables  : [r] seekdsk             Number of Disk to Read
+;                         [r] seeksec          Sector to read
+;              [r] seektrk             Track  to read
+; --------------------------------------------------------------------
+; Description:
 ; ====================================================================
 
 fat_writehost:
@@ -821,28 +960,43 @@ fat_writehost:
        brne    fat_rdwr_err
        rjmp    fat_rdwr_ok
 
-; ====================================================================\r
+; ====================================================================
 ; Function: Does a Disk read operation
-; ====================================================================\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
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : none
+; Variables  : [r] seekdsk             Number of Disk to Read
+;                         [r] seeksec          Sector to read
+;              [r] seektrk             Track  to read
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
 
 fat_readhost:
 .if HOSTRW_DEBUG
        printnewline
        printstring "host read  "
-.endif\r
+.endif
 
        rcall   fat_hostparam
        breq    fat_rdwr_err
        
+       \r
+       printstring "Read Image Sector:"
+       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 " "
+       
        call    mmcReadSect
        tst             temp
        breq    fat_rdwr_ok
@@ -863,5 +1017,5 @@ fat_rdwr_ok:
 
 fat_rdwr_err:
        sts             erflag,_255
-       ret\r
-#endif\r
+       ret
+#endif
index 50e1fa24e6d5f1c6e3f5099e7abe362b9834718f..374bdd24bc785d9ff0014ca8c8bee838d4a8e670 100644 (file)
@@ -226,6 +226,8 @@ boot_ipl2:
        printnewline
        printstring "Partinit done."
 
+       rcall   dsk_cboot               ;init (de)blocking buffer\r
+
 ; Read first sector of first CP/M partition
 
        lds     xl,hostparttbl+1
index 49a1b9cd716a874542bedcf2d0ee2626c892c9cf..e3d75eb2d3e5192225dab2a64374d62d04366184 100644 (file)
@@ -600,7 +600,7 @@ mmc_rdex:
 ;
 ;      in      zh,zl:          Pointer to Word within the Sector to read       
 ;   in yh..xl: Start sector number (LBA)
-;      out     xh,xl   : word thats been read\r
+;      out     zh,zl   : word thats been read\r
 
 mmcReadWord:
 .if MMC_DEBUG > 1
@@ -644,14 +644,31 @@ mmc_rcvw_start:
 mmc_rcvw_rl:
        sbiw    yl,1
        breq    mmc_rcvw_rle
-       //st            z+,temp
+       cp              zl,_0\r
+       cpc             zh,_0\r
+       breq    mmc_rcvw_sto\r
+\r
+       sbiw    zl,1\r
        spi_waitm
        in              temp,SPDR
        out             SPDR,_255
        rjmp    mmc_rcvw_rl
 
+mmc_rcvw_sto:\r
+       mov     zl,temp\r
+       spi_waitm
+       in              temp,SPDR
+       out             SPDR,_255
+       mov     zh,temp\r
+\r
+mmc_rcvw_rl2:
+       sbiw    yl,1
+       breq    mmc_rcvw_rle
+       spi_waitm
+       in              temp,SPDR
+       out             SPDR,_255
+       rjmp    mmc_rcvw_rl2\r
 mmc_rcvw_rle:
-       //st            z+,temp                 ;Store last byte in buffer 
        rcall   spi_wait                ;      while SPI module shifts in crc part1.
        rcall   spi_rcvr                ;Read second crc.