]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avr/dsk_fat16.asm
* More fixes, spelling corrections, minor enhancements.
[avrcpm.git] / avr / dsk_fat16.asm
index 34f793367e47d8944dd525f1cae9bb607a7559c2..f3fd518e42815f41a94ccfa33b043f540ef11be6 100644 (file)
 
 /*These are the Offsets to the Variables within the Bootsector of a FAT16
   Partition.
- */
+*/
 ;#define FAT16_BSO_SECSIZE     0x0b    ; Offset to Sectorsize Word
 #define FAT16_BSO_CLUSTSZ      0x0d    ; Offset to Clustersize Byte
 #define FAT16_BSO_RESSECT      0x0e    ; Offset to Number of Reserved Sectors
 #define FAT16_BSO_VOLPTR       0x1c    ; Offset to First VolumeSector
 #define FAT16_BSO_SECPERFAT    0x16    ; Offset to Number of Sectors per Fat
 #define FAT16_BSO_NUMFATCP     0x10    ; Offset to Ammount of FAT Copys
-#define FAT16_BSO_NUMDIRENT    0x11    ; Offset to Max. Root Dir. Entrys
-#define        FAT16_FIRST_IMAGENAME   'A'     ; First letter of filename to search 
-#define FAT16_LAST_IMAGENAME    'Z'    ; Last letter of filename to 
-/*
-#define FAT16_LAST_IMAGENAME    'A'+MAXDISKS-1 ; Last letter of filename to 
-                                               ; search 
-*/
+#define FAT16_BSO_NUMDIRENT    0x11    ; Offset to Max. Root Dir. entries
+
+#define        FAT16_FIRST_IMAGENAME 'A'       /* First letter of filename to search */
+#define FAT16_LAST_IMAGENAME  'Z'      /* Last letter of filename to */
+#define FAT16_IMAGENAME_PREFIX "CPMDSK_"
+#define FAT16_IMAGENAME_SUFFIX "IMG"
 
 ; ############################################################################ 
 ;                              Start of Data Segment
 ; ############################################################################ 
+
        .dseg
 
 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_numdirentrys:.byte   2     ; Max. num. of entrys within Rootdirektory
+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
 
@@ -70,7 +70,7 @@ fat_ptr2dat:     .byte   4    ; pointer to the first data 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.
-  */
+*/
 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
@@ -143,6 +143,7 @@ fat_reset_cache:
 ; later scanning of the Partition. See Function "fat_scan_partition"
 ; for more information. 
 ; ============================================================================
+
 fat_add_partition:
        
 .if FAT16_DEBUG > 0
@@ -200,11 +201,11 @@ fat_scan_partition:
 
 
 .if FAT16_DEBUG > 0
-       printstring "free entrys in ptable ?"
+       printstring "free entries in ptable ?"
        printnewline
 .endif
 
-; Check for free Entrys in Partition table
+; Check for free entries in partition table
        lds     yl,ndisks
        cpi     yl,MAXDISKS
        breq    fat_scan_error
@@ -245,7 +246,7 @@ fat_bootblock_check:
 
 .if FAT16_DEBUG > 0
        printstring "Sectors per Cluster "
-       rcall printhex
+       lcall   printhex
        printnewline
 .endif
 
@@ -256,20 +257,20 @@ fat_bootblock_check:
 
 .if FAT16_DEBUG > 0
        printstring "Ammount of FAT copies: "
-       rcall printhex
+       lcall   printhex
        printnewline
 .endif
 
-;      get max num of entrys in root direktory from bootblock
+;      get max num of entries in root direktory from bootblock
        ldiw    z,hostbuf+FAT16_BSO_NUMDIRENT
        ld      temp,z+
-       sts     fat_numdirentrys,temp           ; low byte
+       sts     fat_numdirentries,temp          ; low byte
        ld      temp2,z
-       sts     fat_numdirentrys+1,temp2        ; high byte
+       sts     fat_numdirentries+1,temp2       ; high byte
 
 .if FAT16_DEBUG > 0
-       printstring "Max. entrys in Rootdir.: "
-       rcall printhexw
+       printstring "Max. entries in rootdir.: "
+       lcall   printhexw
        printnewline
 .endif
 
@@ -283,12 +284,10 @@ fat_bootblock_check:
        ldd     yh,z+3
 
        printstring "Begin of Volume at: "
-       mov     temp ,yl
-       mov     temp2,yh
-       rcall   printhexw
-       mov     temp ,xl
-       mov     temp2,xh
-       rcall   printhexw
+       movw    temp ,y
+       lcall   printhexw
+       movw    temp ,x
+       lcall   printhexw
        printnewline
 .endif
 
@@ -301,7 +300,7 @@ fat_bootblock_check:
 
 .if FAT16_DEBUG > 0
        printstring "Sectors per FAT__: "
-       rcall printhexw
+       lcall   printhexw
        printnewline
 .endif
 
@@ -329,12 +328,10 @@ fat_bootblock_check:
 
 .if FAT16_DEBUG > 1
        printstring "Begin of FAT at___: "
-       mov     temp ,yl
-       mov     temp2,yh
-       rcall   printhexw
-       mov     temp ,xl
-       mov     temp2,xh
-       rcall   printhexw
+       movw    temp ,y
+       lcall   printhexw
+       movw    temp ,x
+       lcall   printhexw
        printnewline
 .endif
 
@@ -371,24 +368,22 @@ fat_calc_dp_lend:
 
 .if FAT16_DEBUG > 1
        printstring "Begin of DIR at___: "
-       mov     temp ,yl
-       mov     temp2,yh
-       rcall   printhexw
-       mov     temp ,xl
-       mov     temp2,xh
-       rcall   printhexw
+       movw    temp ,y
+       lcall   printhexw
+       movw    temp ,x
+       lcall   printhexw
        printnewline
 .endif
 
 ; Calculate begin of DATA Clusters within the Volume
-; Num. Dir.Sektors = (Num. of Dir. Entrys * 32) / Bytes per Sektor
+; Num. Dir.Sektors = (Num. of Dir. entries * 32) / Bytes per Sektor
 
-; Sectorsize is fixed at 512 Bytes, makes 16 Entrys per Sektor
+; Sectorsize is fixed at 512 bytes, makes 16 entries per sector
 
-       lds     zl,fat_numdirentrys             ; low byte
-       lds     zh,fat_numdirentrys+1           ; high byte
+       lds     zl,fat_numdirentries            ; low byte
+       lds     zh,fat_numdirentries+1          ; high byte
 
-;   Num. Direntrys / 16
+;   Num. Direntries / 16
        lsr     zh
        ror     zl
        lsr     zh
@@ -415,12 +410,10 @@ fat_calc_dp_lend:
 
 .if FAT16_DEBUG > 1
        printstring "Begin of Data at__: "
-       mov     temp ,yl
-       mov     temp2,yh
-       rcall   printhexw
-       mov     temp ,xl
-       mov     temp2,xh
-       rcall   printhexw
+       movw    temp ,y
+       lcall   printhexw
+       movw    temp ,x
+       lcall   printhexw
        printnewline
 .endif
 
@@ -437,10 +430,10 @@ fat_scan_for_next_image:
        sts     fat_clust_offset,temp
 
 ;      Init counter for number of entry left to scan
-       lds     temp,fat_numdirentrys
+       lds     temp,fat_numdirentries
        sts     fat_log_clust  ,temp
 
-       lds     temp,fat_numdirentrys+1
+       lds     temp,fat_numdirentries+1
        sts     fat_log_clust+1,temp
 
 fat_next_sector_loop:
@@ -466,7 +459,7 @@ fat_next_sector_loop:
        clr     temp
        ret
 
-; Looks at a read directory block for image entrys
+; Looks at a read directory block for image entries
 fat_look_for_images:
        
        ldiw    z,hostbuf
@@ -533,7 +526,7 @@ fat_look_not_ok:
        adiw    z,32
 
        inc     temp2
-       cpi     temp2,16                                ; max entrys/sector
+       cpi     temp2,16                                ; max entries/sector
        breq    fat_scan_next_sector
        rjmp    fat_look_for_loop
 
@@ -582,9 +575,8 @@ fat_store_new_entry:
 ;   Found a valid image
 .if FAT16_DEBUG > 1
        printstring "Found a valid Image! Z="
-       mov     temp ,zl
-       mov     temp2,zh
-       rcall   printhexw
+       movw    temp ,z
+       lcall   printhexw
        printnewline
 .endif
 
@@ -624,6 +616,7 @@ fat_look_store:
        ldd     zl,z+0x1F
 ;      mov     zh,_0
 
+       clc
        cpse    _tmp0,_0                ;round up
        adiw    x,1
        adc     zl,_0
@@ -650,18 +643,16 @@ fat_add_noprune:
 .if FAT16_DEBUG > 1
 ; Test finding of the first sector
        
-       ldd     xl,z+0x1A
-       ldd     xh,z+0x1B
+       ldd     xl,y+1
+       ldd     xh,y+2
 
        rcall   fat_gethostsec
 
-       printstring "Begin of Image at: "
-       mov     temp ,yl
-       mov     temp2,yh
-       rcall   printhexw
-       mov     temp ,xl
-       mov     temp2,xh
-       rcall   printhexw
+       printstring "Begin of image at: "
+       movw    temp ,y
+       lcall   printhexw
+       movw    temp ,x
+       lcall   printhexw
        printnewline
 
 .endif
@@ -764,15 +755,13 @@ fat_find_phsy_clust:
        ldd     yh,z+2
 
 .if FAT16_DBG_FAT > 0
-       printstring "Search log. Cluster "
-       mov     temp,xl
-       mov     temp2,xh
+       printstring "Search log. cluster "
+       movw    temp,x
        lcall   printhexw
        printnewline
                
-       printstring "Search phys. Cluster "
-       mov     temp ,yl
-       mov     temp2,yh
+       printstring "Search phys. cluster "
+       movw    temp ,y
        lcall   printhexw
        printnewline
 .endif
@@ -783,9 +772,9 @@ fat_next_phsy_clust:
        breq    fat_found_phsy_clust
 ;      Get Next Cluster from Fat
 
-; Trick: 512 Bytes Per Sector equals to 256 FAT- Entrys per Sector
+; Trick: 512 Bytes Per Sector equals to 256 FAT- entries per Sector
 ; so given:  yl is the Offset within the FAT Sector
-;            yh is the number off se FAT sector to Read 
+;            yh is the number off the FAT sector to Read 
 
 ;      in      zh,zl:          Pointer to Word within the Sector to read       
 ;   in yh..xl: Start sector number (LBA)
@@ -795,11 +784,11 @@ fat_next_phsy_clust:
 
 ;   Create FAT Offset Value
        clr     zh
-       mov     zl,yl
+       mov     zl,yl
        lsl     zl
        rol     zh
 ;   Get FAT Start
-       mov     temp,yh
+       mov     temp,yh
        lds     xl,fat_ptr2fat
        lds     xh,fat_ptr2fat+1
        lds     yl,fat_ptr2fat+2
@@ -814,8 +803,7 @@ fat_next_phsy_clust:
        pop     xh
        pop     xl
 
-       mov     yl,zl
-       mov     yh,zh
+       movw    y,z
 
 ;      Check next logical Cluster
        ldi     zl,1
@@ -828,8 +816,7 @@ fat_found_phsy_clust:
        
 .if FAT16_DBG_FAT > 0
        printstring "Found phys. Cluster at:"
-       mov     temp,yl
-       mov     temp2,yh
+       movw    temp,y
        lcall   printhexw
        printnewline
 .endif 
@@ -892,8 +879,7 @@ fat_hp1:
 ; ################# Get logical Number of Cluster within the imagefile
 ;      printstring "calc log sector"
 ; Get logical Sectornumber from temp
-       mov     xl,temp
-       mov     xh,temp2
+       movw    x,temp
        mov     yl,_0
        mov     yh,_0
 ; Divide logical Sectornumber by size of Cluster in sectors
@@ -1067,7 +1053,7 @@ fat_rdwr_err:
 ;              [out]   hostbuf         Sector read by this routine
 ; ----------------------------------------------------------------------------
 ; Description:
-; This Routine reads a Sector from the Imagefile inside an FAT16 Partition. 
+; This Routine reads a Sector from the Imagefile inside a FAT16 Partition. 
 ; ============================================================================
 
 fat_readhost: