]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avrcpm/avr/dsk_fsys.asm
* Limit partition, resp. file image size to only 32MB. This frees up 2 bytes per...
[avrcpm.git] / avrcpm / avr / dsk_fsys.asm
index 1f3a1950b246c50bd2c0ebb6ee28d6ad382cf72c..4e472a881e270bfbb16c5059633449e0137168aa 100644 (file)
 ;*****************************************************
 ;*        Disk-Manager constants                     *
 ;*****************************************************
-       .equ    dskType_None            = 0
-       .equ    dskType_CPM             = 1
-       .equ    dskType_FAT             = 2
-;      .equ    dskType_RAM             = 3
+       .equ    dskType_None            = 0*16
+       .equ    dskType_CPM             = 1*16
+       .equ    dskType_FAT             = 2*16
+;      .equ    dskType_RAM             = 3*16
+       .equ    dskType_MASK            = 0xf*16
 
 ;*****************************************************
 ;*         CP/M to host disk constants               *
@@ -90,7 +91,7 @@ unasec:               .byte   1               ;last unalloc sector
 erflag:                .byte   1               ;error reporting
 wrtype:                .byte   1               ;write operation type
 
-hostbuf:       .byte   hostsize ;host buffer (from/to SD-card)
+hostbuf:       .byte   hostsize        ;host buffer (from/to SD-card)
 hostparttbl:   .byte   PARTENTRY_SIZE*MAXDISKS ;host partition table (type, start sector, sector count)
 hostparttbltop:
 hostdsk:       .byte   1               ;host disk number
@@ -222,7 +223,7 @@ sbcb_l:
        brne    sbcb_l
        
 ;      rcall   dbg_print_biosd
-       rcall   dsk_drvtblinit
+       rcall   dpb_drvtblinit
 ;      rcall   dbg_prdrvtbl
 
        ret
@@ -240,20 +241,20 @@ sbcb_l:
 ; Description:
 ; ====================================================================
 dskDiskCheck:
-       lds     temp,ndisks
-       lds     temp2,seekdsk
+       lds     temp2,ndisks
+       lds     temp,seekdsk
 .if    DSKSEL_DEBUG
        printnewline
        printstring "DiskCheck: "
        rcall   printhexw
 .endif
-       cpi     temp2,RAMDISKNR
+       cpi     temp,RAMDISKNR
        brsh    dsk_dchrd                       ;maybe ramdisk
 
 ; Check if selected disk # is less then # of disks.
 
-       lds     temp,ndisks     
-       tst     temp                            ;0 disks?
+       lds     temp2,ndisks    
+       tst     temp2                           ;0 disks?
        brne    dsk_dchpart1
 
 ; No disks yet, need to init
@@ -262,43 +263,34 @@ dskDiskCheck:
 ;      sbrs    temp,7  
 ;       rjmp   dsk_dchpart0
        push    temp
-       rcall   dsk_drvtblinit
+       rcall   dpb_drvtblinit
 ;      rcall   dbg_prdrvtbl
-       pop     temp
+       pop     temp2
 dsk_dchpart0:
-       cbr     temp,0x80
-       lds     temp2,seekdsk
+       cbr     temp2,0x80
+       lds     temp,seekdsk
        
 dsk_dchpart1:
-       cp      temp2,temp
+       cp      temp,temp2
        brsh    dsk_dch_err
 
 .if    DSKSEL_DEBUG
        printnewline
        printstring "Select: "
-       mov     temp,temp2
        rcall   printhex
 .endif
-       ldsw    x,biosdrvtbl
-       lsl     temp2                   ;drive #
-       add     xl,temp2
-       adc     xh,_0
-       rcall   dram_readw_pp           ;get drive table entry
-
+       rcall   dpb_drvtbl_entry_get
        or      temp,temp2              ;if !0, drive is allready initialized
        brne    dsk_dchend
        lds     temp,seekdsk
-       rcall   dsk_diskinit
+       rcall   dpb_diskinit
        
 dsk_dchend:
 .if    DSKSEL_DEBUG
        push    temp
-       ldsw    x,biosdrvtbl
        lds     temp,seekdsk
-       lsl     temp                    ;drive #
-       add     xl,temp
-       adc     xh,_0
-       rcall   dram_readw_pp
+       rcall   dpb_drvtbl_entry_get
+
        printstring ", "
        rcall   printhexw
        pop     temp
@@ -445,7 +437,7 @@ dpblist:
 #endif
 
 ; Test
-cpy_dpb:
+dpb_copy:
        push    zh
        push    zl
        push    yh
@@ -467,6 +459,45 @@ cpydpb_l:
        pop     zh
        ret
        
+; ====================================================================
+; Function: get drive table entry pointer for drive # in temp
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : 
+; Variables  : 
+;              
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
+
+dpb_drvtbl_entry_p:
+
+       ldsw    x,biosdrvtbl
+       lsl     temp                    ;drive #
+       add     xl,temp
+       adc     xh,_0
+       ret
+       
+
+; ====================================================================
+; Function: get drive table entry for drive # in temp
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : 
+; Variables  : 
+;              
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
+
+dpb_drvtbl_entry_get:
+
+       rcall   dpb_drvtbl_entry_p
+       ljmp    dram_readw_pp           
+
+
 ; ====================================================================
 ; Function: Clear drive table
 ; ====================================================================
@@ -481,16 +512,16 @@ cpydpb_l:
 
 ; For now, only  entries 1 - 7 are cleared.
 
-dsk_drvtblinit:
+dpb_drvtblinit:
        ldsw    x,biosdrvtbl
        adiw    x,2
        ldi     temp3,7
-dsk_drvi_l:
+dpb_drvi_l:
        ldi     temp,0
        ldi     temp2,0
        rcall   dram_writew_pp
        dec     temp3
-       brne    dsk_drvi_l
+       brne    dpb_drvi_l
        
        lds     temp,biosenddat
        lds     temp2,biosenddat+1
@@ -507,12 +538,12 @@ dsk_drvi_l:
 ;              0 on error
 
 
-dsk_diskinit:
+dpb_diskinit:
        mov     temp3,temp              ;save disk #
 
 
 ; Test
-       rcall   cpy_dpb
+       rcall   dpb_copy
        
        
 
@@ -526,11 +557,11 @@ dsk_diskinit:
        ldi     temp, low (16)
        ldi     temp2,high(16)
        rcall   heap_get
-       brne    dsk_di_1
-       rjmp    dsk_di_err              ;
-dsk_di_1:
+       brne    dpb_di_1
+       rjmp    dpb_di_err              ;
+dpb_di_1:
        movw    x,temp
-       movw    y,temp
+       movw    y,temp                  ;save dph pointer
        ldi     temp,0
        ldi     temp2,0
        rcall   dram_writew_pp          ;XLT
@@ -540,23 +571,23 @@ dsk_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    
+;         -------------------------------------------------------------
+; DPB:    |  SPT  |BSH|BLM|EXM|  DSM  |  DRM  |AL0|AL1|  CKS  |  OFF  |
+;         -------------------------------------------------------------
+;             0                   5       7              11      13    
        
        ldi     temp, low (15)
        ldi     temp2,high(15)
        rcall   heap_get
-       breq    dsk_di_err_p1
+       breq    dpb_di_err_p1
        movw    x,temp
        
        ldiw    z,tmpdpb
-dsk_dicpl:
+dpb_dicpl:
        ld      temp,z+
        rcall   dram_write_pp
        cpi     zl,low(tmpdpb + 15)
-       brne    dsk_dicpl
+       brne    dpb_dicpl
        sbiw    x,15
        movw    temp,x
        movw    x,y
@@ -569,10 +600,10 @@ dsk_dicpl:
        lds     temp2,tmpdpb+11+1
        cp      temp,_0
        cpc     temp2,_0
-       breq    dsk_dicks0
+       breq    dpb_dicks0
        rcall   heap_get
-       breq    dsk_di_err_p1
-dsk_dicks0:
+       breq    dpb_di_err_p1
+dpb_dicks0:
        rcall   dram_writew_pp          ;CSV
 
 ; get mem for alloc vector
@@ -588,16 +619,13 @@ dsk_dicks0:
        lsr     temp2
        ror     temp                    ;(dsm+1+7)/8
        rcall   heap_get
-       breq    dsk_di_err_p1
+       breq    dpb_di_err_p1
        rcall   dram_writew_pp          ;ALV
 
 ; success, insert DPH into drvtbl
 
-       lds     xl,biosdrvtbl
-       lds     xh,biosdrvtbl+1
-       lsl     temp3                   ;drive #
-       add     xl,temp3
-       adc     xh,_0
+       mov     temp,temp3
+       rcall   dpb_drvtbl_entry_p
        movw    temp,y
        rcall   dram_writew_pp  
        ori     temp,0xff               ;return ok
@@ -605,10 +633,10 @@ dsk_dicks0:
 
 ; error, free mem
 
-dsk_di_err_p1:
+dpb_di_err_p1:
        movw    temp,y
        rcall   heap_release
-dsk_di_err:
+dpb_di_err:
        eor     temp,temp               ;return 0 (+ Z-flag)
        ret
        
@@ -706,8 +734,8 @@ dsk_home:
 ; Description:
 ; ====================================================================
 dsk_read:
-       sts             erflag,_0
-       sbi             flags,readop            ; Set read operation flag
+       sts     erflag,_0
+       sbi     flags,readop            ; Set read operation flag
 
        ;RAM disk?
        lds     xl,seekdsk
@@ -717,18 +745,19 @@ dsk_read:
         rjmp   rdsk_read
 #endif
        rcall   dsk_getpartentry        ; Get Paritiontableentry
-       ld      temp,z                          ; Get Partitiontype
+       ld      temp,z                  ; Get Partitiontype
+       andi    temp,dskType_MASK
 
 ; Isn't it a Disk ?
        cpi             temp,dskType_None
        brne    PC+2
        rjmp    dsk_read_err
 ; It must be a FAT16-Imagefile or CP/M Partition.
-       sts             unacnt,_0
-       sbi             flags,rsflag            ;must read data
-       ldi             temp,WRUAL                      ;write type
-       sts             wrtype,temp                     ;treat as unalloc
-       rjmp    dsk_rwoper                      ;to perform the read
+       sts     unacnt,_0
+       sbi     flags,rsflag            ;must read data
+       ldi     temp,WRUAL              ;write type
+       sts     wrtype,temp             ;treat as unalloc
+       rjmp    dsk_rwoper              ;to perform the read
 
 dsk_read_err:
        ret
@@ -747,8 +776,8 @@ dsk_read_err:
 ; ====================================================================
 dsk_write:
        ;write the selected sector
-       sts             erflag,_0
-       cbi             flags,readop            ; not a read operation
+       sts     erflag,_0
+       cbi     flags,readop            ; not a read operation
        ;RAM disk?
        lds     xl,seekdsk
 #if RAMDISKCNT
@@ -758,6 +787,7 @@ dsk_write:
 #endif
        rcall   dsk_getpartentry        ; Get Paritiontableentry
        ld      temp2,z                         ; Get Partitiontype
+       andi    temp,dskType_MASK
 
 ; Isn't it a Disk ?
        cpi     temp2,dskType_None
@@ -767,12 +797,12 @@ dsk_write:
 
 ; It must be a FAT16-Imagefile or CP/M Partition.
 
-       cbi             flags,readop            ;not a read operation
+       cbi     flags,readop            ;not a read operation
 
        andi    temp,WRTMSK
-       sts             wrtype,temp                     ;save write type
+       sts     wrtype,temp                     ;save write type
 
-       cpi             temp,WRUAL                      ;write unallocated?
+       cpi     temp,WRUAL                      ;write unallocated?
        brne    dsk_chkuna                      ;check for unalloc
 
 ;      write to unallocated, set parameters
@@ -1009,19 +1039,20 @@ dsk_wdir1:
 ; Description:
 ; ====================================================================
 dsk_writehost:
-       lds    xl,hostdsk
-       rcall  dsk_getpartentry
-       ld     temp,z
+       lds     xl,hostdsk
+       rcall   dsk_getpartentry
+       ld      temp,z
+       andi    temp,dskType_MASK
 
 #if FAT16_SUPPORT
 ; Is it a FAT16 Diskimage ?
-       cpi             temp,dskType_FAT
+       cpi     temp,dskType_FAT
        brne    PC+2
        rjmp    fat_writehost
 #endif
 
 ; Is it a CP/M Partition ?
-       cpi             temp,dskType_CPM
+       cpi     temp,dskType_CPM
        brne    PC+2
        rjmp    cpm_writehost
 ; Disktype not supported -> Return 
@@ -1043,16 +1074,17 @@ dsk_readhost:
        lds    xl,hostdsk
        rcall  dsk_getpartentry
        ld     temp,z
+       andi    temp,dskType_MASK
 
 #if FAT16_SUPPORT
 ; Is it a FAT16 Diskimage ?
-       cpi             temp,dskType_FAT
+       cpi     temp,dskType_FAT
        brne    PC+2
        rjmp    fat_readhost
 #endif
 
 ; Is it a CP/M Partition ?
-       cpi             temp,dskType_CPM
+       cpi     temp,dskType_CPM
        brne    PC+2
        rjmp    cpm_readhost
 ; Disktype not supported -> Return