]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avr/dsk_fsys.asm
* FAT buffer on ATmega328
[avrcpm.git] / avr / dsk_fsys.asm
index b9458ec1bab44a818a27c8294590703a6a6c8f08..d298019e768547fa59328baf723ebe40bfe34b27 100644 (file)
@@ -371,10 +371,6 @@ dskErrorRet:
 ; ====================================================================
 
 
-       .dseg
-tmpdpb:        .byte   16
-
-       .cseg
 
 str_CPM_Disk:
        .db     10,"<CPM_Disk>",0
@@ -434,34 +430,6 @@ dpbdat_simhd:                      ;
 #endif
 
 
-; Copy the dpb data from flash memory, pointed to by Z, to temp ram.
-
-dpb_copy_p:
-       push    yh
-       push    yl
-       ldi     temp2,16
-       ldiw    y,tmpdpb
-cpydpb_pl:
-       lpm     temp,z+
-       st      y+,temp
-       dec     temp2
-       brne    cpydpb_pl
-       pop     yl
-       pop     yh
-       ret
-
-; Copy the dpb data, pointed to by Z to temp ram.
-
-dpb_copy:      
-       st      y+,temp
-       ldi     temp2,15
-cpydpb_l:
-       ld      temp,z+
-       st      y+,temp
-       dec     temp2
-       brne    cpydpb_l
-       ret
-
 
 ; ====================================================================
 ; Function: get drive table entry pointer for drive # in temp
@@ -598,10 +566,10 @@ dsk_tst_yaze:
        lcall   strncmp_p
        brne    dsk_tyze_not
        
-       ldiw    z,hostbuf+32
-       ldiw    y,tmpdpb
+       ldiw    z,hostbuf+31
+       clt                             ;dpb in RAM
        ldi     temp,1                  ;1 sector header size
-       rcall   dpb_copy        
+       st      z,temp
 
        ori     temp,0xff
        ret
@@ -643,6 +611,8 @@ dsk_tmyz80_loop:
        dec     temp2
        brne    dsk_tmyz80_loop
 
+       ldiw    z,dpbdat_myz80*2
+       set
        ori     temp,0xff
        ret
 
@@ -693,6 +663,8 @@ dsk_tsimhd_loop:
        brne    dsk_tsimhd_loop
 
 dsk_tsimhd_found:
+       ldiw    z,dpbdat_simhd*2
+       set
        ori     temp,0xff
        ret
 
@@ -732,22 +704,19 @@ dsk_format_get:
 ; Test for simhd format.
 
        rcall   dsk_tst_simhd
-       ldiw    z,dpbdat_simhd*2
-       brne    dsk_imgt_fixed
+       brne    dsk_imgt_done
 
 ; Test for MyZ80 format.
 
        rcall   dsk_tst_myz80
-       ldiw    z,dpbdat_myz80*2
-       brne    dsk_imgt_fixed
+       brne    dsk_imgt_done
        
 ; No special image found. Use avrcpm.
 
        ldiw    z,dpbdat_avrcpm*2
-
-dsk_imgt_fixed:
-       rcall   dpb_copy_p
+       set
        ori     temp,0xff
+
 dsk_imgt_done:
        ret     
 
@@ -769,30 +738,38 @@ dpb_imgdata_get:
        rcall   dsk_format_get  
        breq    dpb_imgd_err            ;no known format detected
 
-;
+dpb_imgd_0:
+       brtc    dpb_imgd_variable
+dpb_imgd_fixed:
+       lpm     temp, z+                ;image header
+       lpm     yl,z+                   ;low(SPT)
+       lpm     yh,z+                   ;high(SPT)
+       lpm     temp2,z+                ;BSH
+       rjmp    dpb_imgd_common
+
+dpb_imgd_variable:
+       ld      temp, z+                ;image header
+       ld      yl,z+                   ;low(SPT)
+       ld      yh,z+                   ;high(SPT)
+       ld      temp2,z+                ;BSH
+
+dpb_imgd_common:
        mov     zl,temp3
        rcall   dsk_getpartentry        ;get partition entry
-       ldiw    y,tmpdpb
-       
-;      std     y+12,_0                 ;Test: set check size to 0
-;      std     y+13,_0
+       std     z+PTAB_SPT,yl
+       tst     yh                      ;more then 256 sectors per track?
+       brne    dsk_imgprp_err          ;todo: support 16 bit sector numbers
+
+       andi    temp2,0x0f
+       swap    temp2
+       std     z+PTAB_BSH,temp2
        
-       ldd     temp,y+0
        andi    temp,~dskType_MASK
        ldd     temp2,z+PTAB_TYPE
        andi    temp2,dskType_MASK
        or      temp,temp2
        std     z+PTAB_TYPE,temp
-       ldd     temp,y+1
-       std     z+PTAB_SPT,temp
-       ldd     temp,y+2
-       tst     temp                    ;more then 256 sectors per track?
-       brne    dsk_imgprp_err          ;todo: support 16 bit sector numbers
-       ldd     temp2,y+3
-       andi    temp2,0x0f
-       swap    temp2
-       std     z+PTAB_BSH,temp2
-       
+
        ori     temp,255
        ret
 
@@ -866,22 +843,43 @@ dpb_di_1:
        breq    dpb_di_err_p1
        movw    x,temp
        
-       ldiw    z,tmpdpb+1              ;skip sector offset byte
+       adiw    z,1                     ;skip sector offset byte
+       push    temp3
+       ldi     temp3,15
 dpb_dicpl:
-       ld      temp,z+
+       brtc    PC+2                    ;
+        lpm    temp,z+
+       brts    PC+2                    ;
+        ld     temp,z+
        rcall   dram_write_pp
-       cpi     zl,low(tmpdpb + 16)
+       dec     temp3
        brne    dpb_dicpl
+       pop     temp3
        sbiw    x,15
+       sbiw    z,15
        movw    temp,x
        movw    x,y
        adiw    x,10
        rcall   dram_writew_pp          ;DPB
-       
+
+       brtc    dpb_dicks_variable
+dpb_dicks_fixed:
+       adiw    z,5
+       lpm     _tmp0,z+                ;dsm
+       lpm     _tmp1,z+
+       adiw    z,11-5-2
+       lpm     temp,z+                 ;cks
+       lpm     temp2,z+
+       rjmp    dpb_dicks_common
+dpb_dicks_variable:
+       ldd     _tmp0,z+5               ;dsm
+       ldd     _tmp1,z+5+1
+       ldd     temp,z+11               ;cks
+       ldd     temp2,z+11+1
+
 ; get mem for dir check vector
 
-       lds     temp,tmpdpb+12          ;cks
-       lds     temp2,tmpdpb+12+1
+dpb_dicks_common:
        cp      temp,_0
        cpc     temp2,_0
        breq    dpb_dicks0
@@ -892,8 +890,7 @@ dpb_dicks0:
 
 ; get mem for alloc vector
 
-       lds     temp,tmpdpb+6           ;dsm
-       lds     temp2,tmpdpb+6+1
+       movw    temp,_tmp0
        subi    temp, low (-8)
        sbci    temp2,high(-8)
        lsr     temp2
@@ -1374,12 +1371,18 @@ dsk_match:
 dsk_writehost:
 
 .if HOSTRW_DEBUG
+.if DISK_DEBUG == 0
+       printnewline
+       printstring "Host write: "
+.else
        printstring ", hst WR "
+.endif
 .endif
 
        rcall   dsk_hostparam
        breq    dsk_hstwr_err
        
+       ldiw    z,hostbuf
        rcall   mmcWriteSect
        tst     temp
        brne    dsk_hstwr_err
@@ -1408,12 +1411,18 @@ dsk_hstwr_err:
 dsk_readhost:
 
 .if HOSTRW_DEBUG
+.if DISK_DEBUG == 0
+       printnewline
+       printstring "Host read:  "
+.else
        printstring ", hst RD "
+.endif
 .endif
 
        rcall   dsk_hostparam
        breq    dsk_hstrd_err
        
+       ldiw    z,hostbuf
        rcall   mmcReadSect
        tst     temp
        brne    dsk_hstrd_err