]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avr/dsk_fsys.asm
* cpm/ipl.mac
[avrcpm.git] / avr / dsk_fsys.asm
index 2bf9d80aca763fae1715ecb4d4f1e5c2104ce5ff..46389d2e68273d21066bd09c16b298eb7d461b2d 100644 (file)
@@ -98,13 +98,13 @@ secpblk:    .byte   1               ;sectors per block (alloc size)
 unacnt:                .byte   1               ;unalloc rec cnt
 unadsk:                .byte   1               ;last unalloc disk
 unatrk:                .byte   2               ;last unalloc track
-unasec:                .byte   1               ;last unalloc sector
+unasec:                .byte   2               ;last unalloc sector
 
 erflag:                .byte   1               ;error reporting
 wrtype:                .byte   1               ;write operation type
 
 hostdsk:       .byte   1               ;host disk number
-hostlba:       .byte   3               ;host sector number (relative to partition start)
+hostlba:       .byte   2               ;host sector number (relative to partition start)
 hostparttbl:   .byte   PARTENTRY_SIZE*MAXDISKS ;host partition table (type, start sector, sector count)
 hostparttbltop:
 hostbuf:       .byte   HOSTSIZE        ;host buffer (from/to SD-card)
@@ -165,6 +165,7 @@ dbg_print_biosd:
        ret
 .endif
        
+; ====================================================================
 ; ====================================================================
 ; Function: Get a Pointer to a Partitiontable entry
 ; ====================================================================
@@ -186,6 +187,7 @@ dsk_getpartentry:
        add     zh,_tmp1
        ret
 
+; ====================================================================
 ; ====================================================================
 ; Function: Virtual Port Interface
 ; ====================================================================
@@ -204,18 +206,14 @@ dsk_param_getadr:
        adc     zh,_0
        ret
 
-dsk_param_wr:
+dsk_param_set:
        rcall   dsk_param_getadr
        st      z,temp
-       cpi     temp3,bcbadr+1-seektrk
-       brne    dsk_param_wr1
-       std     z+1,_0
-dsk_param_wr1: 
        cpi     temp3,bcbadr+1-biospar_base
        breq    SetBCB
        ret
 
-dsk_param_rd:
+dsk_param_get:
        cpi     temp3,seekdsk-biospar_base
        breq    dskDiskCheck
        rcall   dsk_param_getadr
@@ -234,7 +232,7 @@ sbcb_l:
        brne    sbcb_l
        
 ;      rcall   dbg_print_biosd
-       rcall   dpb_drvtblinit
+       rcall   dpb_drvtblclear
 ;      rcall   dbg_prdrvtbl
 
        ret
@@ -262,25 +260,38 @@ dskDiskCheck:
        cpi     temp,RAMDISKNR
        brsh    dsk_dchrd                       ;maybe ramdisk
 
-; Check if selected disk # is less then # of disks.
-
-       lds     temp2,ndisks    
        tst     temp2                           ;0 disks?
        brne    dsk_dchpart1
 
 ; No disks yet, need to init
 
+       rcall   dpb_drvtblclear
+.if 0
+       ldi     temp2,0x40
+       ldi     temp,1
+       lcall   clockput
+.endif
        rcall   mgr_init_partitions             ;disk chanched?
+       push    temp
+.if 0
+       ldi     temp2,0x40
+       ldi     temp,2
+       lcall   clockput
 ;      sbrs    temp,7  
 ;       rjmp   dsk_dchpart0
-       push    temp
-       rcall   dpb_drvtblinit
+
+       lcall   mgr_prnt_parttbl
+       printnewline
+.endif
+
 ;      rcall   dbg_prdrvtbl
        pop     temp2
 dsk_dchpart0:
        cbr     temp2,0x80
        lds     temp,seekdsk
        
+; Check if selected disk # is less then # of disks.
+
 dsk_dchpart1:
        cp      temp,temp2
        brsh    dsk_dch_err
@@ -293,10 +304,11 @@ dsk_dchpart1:
        rcall   dpb_drvtbl_entry_get
        or      temp,temp2              ;if !0, drive is allready initialized
        brne    dsk_dchend
-       lds     temp,seekdsk
-       rcall   dpb_diskinit
-       
+       lds     temp3,seekdsk
+       mov     temp,temp3
+       rcall   dpb_biosdph_get
 dsk_dchend:
+
 .if    DSKSEL_DEBUG
        push    temp
        lds     temp,seekdsk
@@ -343,7 +355,8 @@ dskErrorRet:
        ret
 
                
-; -------------------------------------------------------------------
+; ====================================================================
+; ====================================================================
 
 
        .dseg
@@ -406,7 +419,7 @@ dpbdat_simhd:                       ;
 #endif
 
 
-; Copy the dpb data in flash memory, pointed to by Z to temp ram.
+; Copy the dpb data from flash memory, pointed to by Z, to temp ram.
 
 dpb_copy_p:
        push    yh
@@ -520,36 +533,44 @@ dpb_drvtbl_entry_get:
 
 ;
 
-dpb_drvtblinit:
+dpb_drvtblclear:
        ldsw    x,biosdrvtbl
-;      adiw    x,2
+       sbiw    x,0
+       breq    dpb_drvi_ex
+       
+dpb_drvi_1:
        ldi     temp3,8
-dpb_drvi_l:
+dpb_drvi_lp:
        ldi     temp,0
        ldi     temp2,0
        rcall   dram_writew_pp
        dec     temp3
-       brne    dpb_drvi_l
+       brne    dpb_drvi_lp
        
        lds     temp,biosenddat
        lds     temp2,biosenddat+1
+       cp      temp,_0
+       cpc     temp2,_0
+       breq    dpb_drvi_ex
+
        rcall   heap_init
+dpb_drvi_ex:
        clr     temp
        ret
 
 ; ====================================================================
-; Function: 
+; Function: Test disk format: avrcpmhd
 ; ====================================================================
 ; Parameters
 ; --------------------------------------------------------------------
 ; Registers  : temp            drive #
 ;              
 ; --------------------------------------------------------------------
-; Description:
+; Description: Not implemented yet.
 ; ====================================================================
 
 dsk_tst_avrcpmhd:
-       ori     temp,0xff       ; Test, return 'not found' for now.
+       clr     temp            ; Test, return 'not found' for now.
        ret
 
 
@@ -603,11 +624,11 @@ dsk_tst_yaze:
        ldi     temp,1                  ;1 sector header size
        rcall   dpb_copy        
 
-       clr     temp
+       ori     temp,0xff
        ret
 
 dsk_tyze_not:
-       ori     temp,0xff       ;Not a YAZE disk image.
+       clr     temp                    ;Not a YAZE disk image.
        ret
        
 ; ====================================================================
@@ -642,11 +663,11 @@ dsk_tmyz80_loop:
        dec     temp2
        brne    dsk_tmyz80_loop
 
-       clr     temp
+       ori     temp,0xff
        ret
 
 dsk_tmyz80_not:
-       ori     temp,0xff       ;Not a MyZ80 hard disk image.
+       clr     temp                    ;Not a MyZ80 hard disk image.
        ret
        
 ; ====================================================================
@@ -686,11 +707,11 @@ dsk_tsimhd_loop:
        dec     temp2
        brne    dsk_tsimhd_loop
 
-       clr     temp
+       ori     temp,0xff
        ret
 
 dsk_tsimhd_not:
-       ori     temp,0xff       ;Not a simhd hard disk image.
+       clr     temp                    ;Not a simhd hard disk image.
        ret
        
 ; ====================================================================
@@ -698,60 +719,73 @@ dsk_tsimhd_not:
 ; ====================================================================
 ; Parameters
 ; --------------------------------------------------------------------
-; Registers  : temp            drive #
+; Registers  : temp3           drive #
 ;              
 ; --------------------------------------------------------------------
 ; Description:
 ; ====================================================================
 
-dsk_img_type:
-
-; todo: flush hostbuf!
-; todo: flush hostbuf!
+dsk_format_get:
 
 ; Get first sector (512 byte) of current drive into hostbuf.
 
-       push    temp3                   
-       mov     temp3,temp
+       push    temp3
        ldi     temp,0                  
        ldi     temp2,0                 ;
        rcall   dsk_readhost_lba
        
-       pop     temp3
-       push    temp3
-       
 ; Test for variable format avrcpmhd.
 
        rcall   dsk_tst_avrcpmhd
-       breq    dsk_img_prep
+       brne    dsk_imgt_done
 
 ; Test for YAZE formats.
 
        rcall   dsk_tst_yaze
-       breq    dsk_img_prep
+       brne    dsk_imgt_done
 
 ; Test for simhd format.
 
        rcall   dsk_tst_simhd
        ldiw    z,dpbdat_simhd*2
-       breq    dsk_img_fix
+       brne    dsk_imgt_fixed
 
 ; Test for MyZ80 format.
 
        rcall   dsk_tst_myz80
        ldiw    z,dpbdat_myz80*2
-       breq    dsk_img_fix
+       brne    dsk_imgt_fixed
        
 ; No special image found. Use avrcpm.
 
        ldiw    z,dpbdat_avrcpm*2
 
-dsk_img_fix:
+dsk_imgt_fixed:
        rcall   dpb_copy_p
-       
-dsk_img_prep:
+       ori     temp,0xff
+dsk_imgt_done:
+       pop temp3
+       ret     
 
-       pop     temp3
+; ====================================================================
+; Function: Add CP/M image format data to partition table data
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : temp3           drive #
+;              
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
+
+dpb_imgdata_get:
+
+; Test for known CP/M formats 
+
+       rcall   dsk_format_get  
+       breq    dpb_imgd_err            ;no known format detected
+
+;
        mov     zl,temp3
        rcall   dsk_getpartentry        ;get partition entry
        ldiw    y,tmpdpb
@@ -786,35 +820,47 @@ dsk_imgprp_err:
        printstring ": Format not supported: Too much sectors per track! "
        printnewline
 
+dpb_imgd_err:
        clr     temp
        ret
 
-; ----------------------------------------------------------------------
-; Init CP/M data structures 
-;      temp = drive #
+; ====================================================================
+; Function: 
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : temp            drive #
+;              
+;                      return !0 if ok
+;                              0 on error
+; --------------------------------------------------------------------
+; Description: Init CP/M data structures 
 ;
-;      return !0 if ok
-;              0 on error
-
+;         -----------------------------------------------------------------
+; DPH:    |  XLT  |       |       |       |DIRBUF |  DPB  |  CSV  |  ALV  |
+;         -----------------------------------------------------------------
+;offset:      0       2       4       6       8      10      12      14
+;
+;         -------------------------------------------------------------
+; DPB:    |  SPT  |BSH|BLM|EXM|  DSM  |  DRM  |AL0|AL1|  CKS  |  OFF  |
+;         -------------------------------------------------------------
+;offset:      0                   5       7              11      13    
+; ====================================================================
 
-dpb_diskinit:
+dpb_biosdph_get:
        mov     temp3,temp              ;save disk #
 
-       rcall   dsk_img_type
+       rcall   dsk_format_get  
        brne    dpb_di_0
        rjmp    dpb_di_err
 
 dpb_di_0:
 
 ; get mem for DPH 
-;         -----------------------------------------------------------------
-; DPH:    |  XLT  |       |       |       |DIRBUF |  DPB  |  CSV  |  ALV  |
-;         -----------------------------------------------------------------
-;(offset)     0       2       4       6       8      10      12      14
 
        ldi     temp, low (16)
        ldi     temp2,high(16)
-       rcall   heap_get
+       rcall   heap_get                ;returns ptr to dph mem
        brne    dpb_di_1
        rjmp    dpb_di_err              ;
 dpb_di_1:
@@ -829,10 +875,6 @@ dpb_di_1:
        rcall   dram_writew_pp          ;DIRBUF
 
 ; get mem for DPB      
-;         -------------------------------------------------------------
-; DPB:    |  SPT  |BSH|BLM|EXM|  DSM  |  DRM  |AL0|AL1|  CKS  |  OFF  |
-;         -------------------------------------------------------------
-;             0                   5       7              11      13    
        
        ldi     temp, low (15)
        ldi     temp2,high(15)
@@ -1079,7 +1121,7 @@ dsk_write:
 #endif
        rcall   dsk_getpartentry        ; Get Paritiontableentry
        ld      temp2,z                 ; Get Partitiontype
-       andi    temp,dskType_MASK
+       andi    temp2,dskType_MASK
 
 ; Isn't it a Disk ?
        cpi     temp2,dskType_None
@@ -1091,8 +1133,6 @@ dsk_write:
 
        rcall   dsk_setdrvparam         ;todo: do this only if needed (disk change)
 
-       cbi     flags,readop            ;not a read operation
-
        andi    temp,WRTMSK
        sts     wrtype,temp             ;save write type
 
@@ -1188,8 +1228,6 @@ dsk_rwoper:
        in      temp,flags
        rcall   printhex
 .endif
-       sts     erflag,_0       ;no errors (yet)
-
        ;Convert track/sector to an LBA address (in 128byte blocks)
 
        lds     xl,seeksec              ;
@@ -1220,53 +1258,11 @@ dsk_sh1:
        ror     xl
        dec     temp
        brne    dsk_sh1
-                                       ;yl:xh:xl = host block to seek
-;      active host sector?
-       in      _tmp0,flags             ;host active flag
-       sbi     flags,hostact           ;always becomes 1
-       sbrs    _tmp0,hostact           ;was it already?
-       rjmp    dsk_filhst              ;fill host if not
-
-;      host buffer active, same as seek buffer?
-       lds     temp,seekdsk
-       lds     temp2,hostdsk           ;same disk?
-       cp      temp,temp2              ;seekdsk = hostdsk?
-       brne    dsk_nomatch
-
-;      same disk, same block?
-       lds     temp,hostlba
-       lds     temp2,hostlba+1
-       lds     temp3,hostlba+2
-       cp      xl,temp
-       cpc     xh,temp2
-       cpc     yl,temp3
-       breq    dsk_match
-;
-dsk_nomatch:
-       ;proper disk, but not correct sector
-       sbis    flags,hostwrt           ;host written?
-       rjmp    dsk_filhst
-       push    xl
-       push    xh
-       push    yl
-       rcall   dsk_writehost           ;clear host buff
-       pop     yl
-       pop     xh
-       pop     xl
-
-dsk_filhst:
-       ;may have to fill the host buffer
-       lds     temp,seekdsk
-       sts     hostdsk,temp
-       sts     hostlba,xl
-       sts     hostlba+1,xh
-       sts     hostlba+2,yl
-
-       sbic    flags,rsflag            ;need to read?
-       rcall   dsk_readhost            ;yes, if 1
-       cbi     flags,hostwrt           ;no pending write
-
-dsk_match:
+                                       ;todo: yl should be 0 here. 
+                                       ;xh:xl = host block to seek
+       movw    temp,x
+       lds     temp3,seekdsk
+       rcall   dsk_rw_hostbuf
 
        ;copy data to or from buffer
        ldiw    z,hostbuf
@@ -1277,11 +1273,8 @@ dsk_match:
        adc     zh,r1
 
 .if DISK_DEBUG > 2
-       push    r0
-       push    r1
+       movw    temp,r0
        printstring "; host buf adr: "
-       pop     temp2
-       pop     temp
        rcall   printhexw
 .endif
 
@@ -1336,16 +1329,73 @@ dsk_wdir1:
 ; Description:
 ; ====================================================================
 dsk_readhost_lba:
-       sts     hostlba+0,temp
-       sts     hostlba+1,temp2
-       sts     hostlba+2,_0
-       sts     hostdsk,temp3
-#if 0  
+#if 0
        printnewline
        printstring "readhst lba"
 #endif
-       rjmp    dsk_readhost            ;returns 0, if ok
+       sbi     flags,rsflag            ;must read data
+       rcall   dsk_rw_hostbuf
+       lds     temp,erflag             ;returns 0, if ok
+       tst     temp
+       ret
 
+; ====================================================================
+; Function: Get physical disk sector in hostbuf.
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : temp2:temp      host block to read/write (lba)
+;              temp3           disk #
+;              
+; --------------------------------------------------------------------
+; Description: 
+; ====================================================================
+dsk_rw_hostbuf:
+                                       ;xh:xl = host block to seek
+       sts     erflag,_0               ;no errors (yet)
+
+;      active host sector?
+       in      _tmp0,flags             ;host active flag
+       sbi     flags,hostact           ;always becomes 1
+       sbrs    _tmp0,hostact           ;was it already?
+       rjmp    dsk_filhst              ;fill host if not
+
+;      host buffer active, same as seek buffer?
+       lds     _tmp0,hostdsk           ;same disk?
+       cp      temp3,_tmp0             ;seekdsk = hostdsk?
+       brne    dsk_nomatch
+
+;      same disk, same block?
+       lds     _tmp0,hostlba
+       lds     _tmp1,hostlba+1
+       cp      temp,_tmp0
+       cpc     temp2,_tmp1
+       breq    dsk_match
+
+dsk_nomatch:
+       ;proper disk, but not correct sector
+       sbis    flags,hostwrt           ;host written?
+       rjmp    dsk_filhst
+       push    temp3
+       push    temp2
+       push    temp
+       rcall   dsk_writehost           ;clear host buff
+       pop     temp
+       pop     temp2
+       pop     temp3
+
+dsk_filhst:
+       ;may have to fill the host buffer
+       sts     hostlba,temp
+       sts     hostlba+1,temp2
+       sts     hostdsk,temp3
+
+       sbic    flags,rsflag            ;need to read?
+       rcall   dsk_readhost            ;yes, if 1
+       cbi     flags,hostwrt           ;no pending write
+
+dsk_match:
+       ret
 
 ; ====================================================================
 ; Function: Does a Disk write operation
@@ -1421,3 +1471,6 @@ dsk_readhost:
 ; Disktype not supported -> Return 
        ret
 
+
+; vim:set ts=8 noet nowrap
+