]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - dsk_fsys.asm
Test branch for FAT16
[avrcpm.git] / dsk_fsys.asm
index 60d6d73cfba63190674aadfa3ddd3685b07db0cd..aa91ce40dfdc3526f888059709a9061b638cfb4b 100644 (file)
@@ -23,6 +23,7 @@
 
 ; ---------------- Defines for the Filesystem Interface -------
 
+
 ;*****************************************************
 ;*        Disk-Manager constants                     *
 ;*****************************************************
@@ -34,7 +35,7 @@
 ;*****************************************************
 ;*         CP/M to host disk constants               *
 ;*****************************************************
-       .equ    MAXDISKS  = 6                   ;Max number of Disks (partitions)
+       .equ    MAXDISKS  = 6                   ;Max number of Disks (partitions)\r
        .equ    PARTENTRY_SIZE = 9              ;Size of a Partitiontableentry
        .equ    blksize = 1024                  ;CP/M allocation size
        .equ    hostsize = 512                  ;host disk sector size
        .equ    WRDIR = 1               ;write to directory
        .equ    WRUAL = 2               ;write to unallocated
        .equ    WRTMSK= 3               ;write type mask
-
-       .equ    READ_FUNC  = 7
-       .equ    WRITE_FUNC = 6
-       .equ    BOOT_FUNC  = 5
-       .equ    HOME_FUNC  = 4
-
 ;----------------------------------------------- Start of Data Segment
 
        .dseg
 
-; The following 3 variables are copied from DRAM.
-; Don't change order.
-
-biosdrvtbl:    .byte   2       ;
-biosdirbuf:    .byte   2       ;
-biosenddat:    .byte   2       ;
+ndisks:                        .byte   1               ;Number of CP/M disks
 
-ndisks:                .byte   1               ;Number of CP/M disks
+seekdsk:               .byte   1               ;seek disk number
+seektrk:               .byte   2               ;seek track number
+seeksec:               .byte   1               ;seek sector number
 
-; The following 5 variables are accessed from 8080/z80 via the
-; virtual port interface. Don't change order.
+unacnt:                        .byte   1               ;unalloc rec cnt
+unadsk:                        .byte   1               ;last unalloc disk
+unatrk:                        .byte   2               ;last unalloc track
+unasec:                        .byte   1               ;last unalloc sector
 
-biospar_base:
-bcbadr:                .byte   2               ;adr of BiosControlBlock
-seekdsk:       .byte   1               ;seek disk number
-seektrk:       .byte   2               ;seek track number
-seeksec:       .byte   2               ;seek sector number
-dmaadr:                .byte   2               ;last dma address
+erflag:                        .byte   1               ;error reporting
+wrtype:                        .byte   1               ;write operation type
+dmaadr:                        .byte   2               ;last dma address
 
-unacnt:                .byte   1               ;unalloc rec cnt
-unadsk:                .byte   1               ;last unalloc disk
-unatrk:                .byte   2               ;last unalloc track
-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
-hosttype:      .byte   1               ;host disk type (same entry as 1 parition entry)
-hostlba:       .byte   3               ;host sector number (relative to partition start)
+hostdsk:               .byte   1               ;host disk number
+hosttype:              .byte   1               ;host disk type (same entry as 1 parition entry)
+hostlba:               .byte   3               ;host sector number (relative to partition start)
 
 
 ; ------------------------------- Start of Code Segment
        .cseg
 
 ; ====================================================================
-; Function: Virtual Port Interface
+; Function: Get a Pointer to a Partitiontable entry
 ; ====================================================================
 ; Parameters
 ; --------------------------------------------------------------------
-; Registers  : 
-; Variables  : 
-;              
+; Registers  : [w] z                   Pointer to the Partitionentry
+;              [r] xl                  Number of Diskentry to Read
 ; --------------------------------------------------------------------
 ; Description:
 ; ====================================================================
+dsk_getpartentry:
+       
+       ldiw    z,hostparttbl
+       mov             temp,xl
 
-dsk_param_getadr:
-       ldiw    z,biospar_base
-       add     zl,temp3
-       adc     zh,_0
-       ret
-
-dsk_param_wr:
-       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:
-       cpi     temp3,seekdsk-biospar_base
-       breq    dskDiskCheck
-       rcall   dsk_param_getadr
-       ld      temp,z
+dsk_getpartentryloop:
+       cp              temp,_0
+       breq    dsk_getpartentryloopend
+       adiw    z,PARTENTRY_SIZE
+       dec             temp
+       rjmp            dsk_getpartentryloop
+dsk_getpartentryloopend:
        ret
 
+; ====================================================================
+; Function: 
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers  : none
+; Variables  : [r] seeksec             Sector to read
+;              [r] seektrk             Track  to read
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
 dskDiskCheck:
        lds             temp2,seekdsk
        cpi             temp2,RAMDISKNR
@@ -144,46 +126,18 @@ dskDiskCheck:
 ; Check if selected disk # is less then # of disks.
 
        lds             temp,ndisks     
-       tst     temp                            ;0 disks?
+       tst             temp
        brne    dsk_dchpart1
 
-; No disks yet, need to init
+; Need to init
 
-       rcall   mgr_init_partitions             ;disk chanched?
-       sbrs    temp,7  
-        rjmp   dsk_dchpart0
-       push    temp
-       rcall   dsk_drvtblinit
-       rcall   dbg_prdrvtbl
-       pop     temp
-dsk_dchpart0:
+       rcall   mgr_init_partitions
        cbr             temp,0x80
        lds             temp2,seekdsk
        
 dsk_dchpart1:
        cp              temp2,temp
        brsh    dsk_dcher
-
-       printnewline
-       printstring "Select: "
-       mov     temp,temp2
-       rcall   printhex
-
-       lds     xl,biosdrvtbl
-       lds     xh,biosdrvtbl+1
-       lsl     temp2                   ;drive #
-       add     xl,temp2
-       adc     xh,_0
-       rcall   dram_readw_pp
-
-       printstring ", "
-       rcall   printhexw
-
-       or      temp,temp2
-       brne    dsk_dchend
-       lds     temp,seekdsk
-       rcall   dsk_diskinit
-       brne    dsk_dcher
        
 dsk_dchend:
        ldi             temp,0
@@ -202,362 +156,30 @@ dskErrorRet:
        lds             temp,erflag
        ret
 
-SetBCB:
-       lds     xl,bcbadr
-       mov     xh,temp
-       ldiw    z,biosdrvtbl
-       ldi     temp3,6
-sbcb_l:
-       rcall   dram_read_pp
-       st      z+,temp
-       dec     temp3
-       brne    sbcb_l
-       
-       rcall   dbg_print_biosd
-       rcall   dsk_drvtblinit
-
+dskDiskSel:
+       sts     seekdsk,temp
        ret
 
-;---------------------------------------------------------------------
-
-dbg_prdrvtbl:
-       push    xh
-       push    xl
-       push    temp3
-       push    temp2
-       push    temp
-       printnewline
-       printstring "drvtbl ("
-       lds     xl,biosdrvtbl
-       lds     xh,biosdrvtbl+1
-       movw    temp,x
-       rcall   printhexw
-       printstring "): "
-       ldi     temp3,16
-dbg_pcpel:
-       rcall   dram_readw_pp
-       rcall   printhexw
-       printstring " "
-       dec     temp3
-       brne    dbg_pcpel
-       pop     temp
-       pop     temp2
-       pop     temp3
-       pop     xl
-       pop     xh
+dskTrackSel_l:
+       sts     seektrk,temp
+       sts     seektrk+1,_0
        ret
-               
-; -------------------------------------------------------------------
-dbg_print_biosd:
-       printnewline
-       lds     temp,bcbadr
-       lds     temp2,bcbadr+1
-       rcall   printhexw
-       printstring "  "
-       lds     temp,biosdrvtbl
-       lds     temp2,biosdrvtbl+1
-       rcall   printhexw
-       printstring "  "
-       lds     temp,biosdirbuf
-       lds     temp2,biosdirbuf+1
-       rcall   printhexw
-       printstring "  "
-       lds     temp,biosenddat
-       lds     temp2,biosenddat+1
-       rcall   printhexw
-       printstring "  "
-       
-       ret
-       
-               
-; -------------------------------------------------------------------
 
-
-       .dseg
-tmpdpb:        .byte   15
-
-       .cseg
-
-; init bios disk tables. 
-; leave drive 'A' out for now
-
-
-       rcall   dbg_prdrvtbl
-
-       rcall   dsk_drvtblinit
-       rcall   dbg_prdrvtbl
-
-       lds     temp,biosenddat
-       lds     temp2,biosenddat+1
-       rcall   heap_init
-       
-       ldi     temp,1
-dsk_pdil:      
-       cp      temp,temp2
-       brsh    dsk_pdie
-       push    temp2
-       push    temp
-       rcall   dsk_diskinit
-       pop     temp
-       pop     temp2
-       inc     temp
-       rjmp    dsk_pdil
-       
-       
-
-dsk_pdie:
-       mov     temp,temp2
-; Test DPBs (avrcpm format)
-
-dpblist:
-;dpb243        
-       .db 0x1A,0x00           ;spt
-       .db 0x03,0x07           ;block shift, bock mask
-       .db 0x00,0xF2           ;extent mask, low(disk size -1), 
-       .db 0x00,0x3F           ;high(disk size -1), low(dir max)
-       .db 0x00,0xC0           ;high(dir max), alloc0
-       .db 0x00,0x10           ;alloc1, low(chk size)
-       .db 0x00,0x02           ;high(chk size), low(offset)
-       .db 0x00,0x00           ;high(offset), fill
-;dpb243        
-       .db 0x1A,0x00           ;spt
-       .db 0x03,0x07           ;block shift, bock mask
-       .db 0x00,0xF2           ;extent mask, low(disk size -1), 
-       .db 0x00,0x3F           ;high(disk size -1), low(dir max)
-       .db 0x00,0xC0           ;high(dir max), alloc0
-       .db 0x00,0x10           ;alloc1, low(chk size)
-       .db 0x00,0x02           ;high(chk size), low(offset)
-       .db 0x00,0x00           ;high(offset), fill
-;dpb243        
-       .db 0x1A,0x00           ;spt
-       .db 0x03,0x07           ;block shift, bock mask
-       .db 0x00,0xF2           ;extent mask, low(disk size -1), 
-       .db 0x00,0x3F           ;high(disk size -1), low(dir max)
-       .db 0x00,0xC0           ;high(dir max), alloc0
-       .db 0x00,0x10           ;alloc1, low(chk size)
-       .db 0x00,0x02           ;high(chk size), low(offset)
-       .db 0x00,0x00           ;high(offset), fill
-;dpb243        
-       .db 0x1A,0x00           ;spt
-       .db 0x03,0x07           ;block shift, bock mask
-       .db 0x00,0xF2           ;extent mask, low(disk size -1), 
-       .db 0x00,0x3F           ;high(disk size -1), low(dir max)
-       .db 0x00,0xC0           ;high(dir max), alloc0
-       .db 0x00,0x10           ;alloc1, low(chk size)
-       .db 0x00,0x02           ;high(chk size), low(offset)
-       .db 0x00,0x00           ;high(offset), fill
-#if 0
-;rd1016        
-       .db 0x20,0x00           ;spt
-       .db 0x04,0x0F           ;block shift, bock mask
-       .db 0x00,0xFB           ;extent mask, low(disk size -1), 
-       .db 0x01,0xBF           ;high(disk size -1), low(dir max)
-       .db 0x00,0xE0           ;high(dir max), alloc0
-       .db 0x00,0x30           ;alloc1, low(chk size)
-       .db 0x00,0x02           ;high(chk size), low(offset)
-       .db 0x00,0x00           ;high(offset), fill
-;rd9192s
-       .db 0x20,0x00           ;spt
-       .db 0x05,0x1F           ;block shift, bock mask
-       .db 0x01,0xFD           ;extent mask, low(disk size -1), 
-       .db 0x07,0xFF           ;high(disk size -1), low(dir max)
-       .db 0x01,0xF0           ;high(dir max), alloc0
-       .db 0x00,0x80           ;alloc1, low(chk size)
-       .db 0x00,0x02           ;high(chk size), low(offset)
-       .db 0x00,0x00           ;high(offset), fill
-#endif
-
-; Test
-cpy_dpb:
-       push    zh
-       push    zl
-       push    yh
-       push    yl
-       ldiw    z,dpblist*2
-       ldi     temp2,16
-       mul     temp,temp2
-       add     zl,_tmp0
-       adc     zh,_tmp1
-       ldiw    y,tmpdpb
-cpydpb_l:
-       lpm     temp,z+
-       st      y+,temp
-       cpi     yl,low(tmpdpb + 15)
-       brne    cpydpb_l
-       pop     yl
-       pop     yh
-       pop     zl
-       pop     zh
+dskTrackSel_h:
+       sts     seektrk+1,temp
        ret
-       
-; clear drive table
-; for now, only  entries 1 - 3 are cleared.
 
-; ====================================================================
-; Function: Clear drive table
-; ====================================================================
-; Parameters
-; --------------------------------------------------------------------
-; Registers  : 
-; Variables  : 
-;              
-; --------------------------------------------------------------------
-; Description:
-; ====================================================================
-
-; For now, only  entries 1 - 3 are cleared.
-
-dsk_drvtblinit:
-       ldsw    x,biosdrvtbl
-       adiw    x,2
-       ldi     temp3,3
-dsk_drvi_l:
-       ldi     temp,0
-       ldi     temp2,0
-       rcall   dram_writew_pp
-       dec     temp3
-       brne    dsk_drvi_l
-       
-       lds     temp,biosenddat
-       lds     temp2,biosenddat+1
-       rcall   heap_init
-       clr     temp
+dskSecSel:
+       sts     seeksec,temp
        ret
 
-       
-; ----------------------------------------------------------------------
-; Init CP/M data structures 
-;      temp = drive #
-;
-
-
-dsk_diskinit:
-       mov     temp3,temp              ;save disk #
-
-
-; Test
-       rcall   cpy_dpb
-       
-       
-
-
-; 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
-       brne    dsk_di_1
-       rjmp    dsk_di_err              ;
-dsk_di_1:
-       movw    x,temp
-       movw    y,temp
-       ldi     temp,0
-       ldi     temp2,0
-       rcall   dram_writew_pp          ;XLT
-       adiw    x,6
-       lds     temp,biosdirbuf
-       lds     temp2,biosdirbuf+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)
-       rcall   heap_get
-       breq    dsk_di_err_p1
-       movw    x,temp
-       
-       ldiw    z,tmpdpb
-dsk_dicpl:
-       ld      temp,z+
-       rcall   dram_write_pp
-       cpi     zl,low(tmpdpb + 15)
-       brne    dsk_dicpl
-       sbiw    x,15
-       movw    temp,x
-       movw    x,y
-       adiw    x,10
-       rcall   dram_writew_pp          ;DPB
-       
-; get mem for dir check vector
-
-       lds     temp,tmpdpb+11          ;cks
-       lds     temp2,tmpdpb+11+1
-       cp      temp,_0
-       cpc     temp2,_0
-       breq    dsk_dicks0
-       rcall   heap_get
-       breq    dsk_di_err_p1
-dsk_dicks0:
-       rcall   dram_writew_pp          ;CSV
-
-; get mem for alloc vector
-
-       lds     temp,tmpdpb+5           ;dsm
-       lds     temp2,tmpdpb+5+1
-       subi    temp, low (-8)
-       sbci    temp2,high(-8)
-       lsr     temp2
-       ror     temp
-       lsr     temp2
-       ror     temp
-       lsr     temp2
-       ror     temp                    ;(dsm+1+7)/8
-       rcall   heap_get
-       breq    dsk_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
-       movw    temp,y
-       rcall   dram_writew_pp  
-       clr     temp
+dskDmal:
+       sts     dmaadr,temp
        ret
 
-; error, free mem
-
-dsk_di_err_p1:
-       movw    temp,y
-       rcall   heap_release
-dsk_di_err:
-       ldi     temp,1
-       or      temp,temp
+dskDmah:
+       sts     dmaadr+1,temp
        ret
-       
-; ====================================================================
-; Function: Get a Pointer to a Partitiontable entry
-; ====================================================================
-; Parameters
-; --------------------------------------------------------------------
-; Registers  : [w] z                   Pointer to the Partitionentry
-;              [r] xl                  Number of Diskentry to Read
-;             [w] _tmp0                scratch
-;             [w] _tmp1                "
-; --------------------------------------------------------------------
-; Description:
-; ====================================================================
-dsk_getpartentry:
-       
-       ldi     zl,PARTENTRY_SIZE
-       mul     xl,zl
-       ldiw    z,hostparttbl
-       add     zl,_tmp0
-       add     zh,_tmp1
-       ret
-
 
 ; ====================================================================
 ; Function: Does a Disk interaction
@@ -644,9 +266,9 @@ dsk_home:
 ; ====================================================================
 ; Parameters
 ; --------------------------------------------------------------------
-; Registers  : in: temp                        
+; Registers  : none
 ; Variables  : [r] seekdsk             Number of Disk to Read
-;             [r] seeksec              Sector to read
+;                         [r] seeksec          Sector to read
 ;              [r] seektrk             Track  to read
 ; --------------------------------------------------------------------
 ; Description:
@@ -654,27 +276,23 @@ dsk_home:
 dsk_read:
        sts             erflag,_0
        sbi             flags,readop            ; Set read operation flag
-
-       ;RAM disk?
-       lds     xl,seekdsk
-#if RAMDISKCNT
-       cpi     xl,RAMDISKNR
-       brlt    PC+2
-        rjmp   rdsk_read
-#endif
+       lds     xl,seekdsk
        rcall   dsk_getpartentry        ; Get Paritiontableentry
-       ld      temp,z                  ; Get Partitiontype
+       ld      temp,z                          ; Get Partitiontype
 
 ; Isn't it a Disk ?
-       cpi     temp,dskType_None
+       cpi             temp,dskType_None
        brne    PC+2
        rjmp    dsk_read_err
-
+; Is it a RamDisk ?
+       cpi             temp,dskType_RAM
+       brne    PC+2
+       rjmp    rdsk_read
 ; 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
+       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:
@@ -685,41 +303,39 @@ dsk_read_err:
 ; ====================================================================
 ; Parameters
 ; --------------------------------------------------------------------
-; Registers  : in: temp                Write type      
-; Variables  : [r] seekdsk     Number of Disk to Read
-;             [r] seeksec      Sector to read
-;              [r] seektrk     Track  to read
+; Registers  : none
+; Variables  : [r] seekdsk             Number of Disk to Read
+;                         [r] seeksec          Sector to read
+;              [r] seektrk             Track  to read
 ; --------------------------------------------------------------------
 ; Description:
 ; ====================================================================
 dsk_write:
        ;write the selected sector
-       sts     erflag,_0
-       cbi     flags,readop            ; not a read operation
-
-       ;RAM disk?
-       lds     xl,seekdsk
-#if RAMDISKCNT
-       cpi     xl,RAMDISKNR
-       brlt    PC+2
-        rjmp   rdsk_write
-#endif
+       sts             erflag,_0
+       cbi             flags,readop            ; not a read operation
+       lds     xl,seekdsk
        rcall   dsk_getpartentry        ; Get Paritiontableentry
-       ld      temp2,z                         ; Get Partitiontype
+       ld      temp,z                          ; Get Partitiontype
 
 ; Isn't it a Disk ?
-       cpi     temp2,dskType_None
+       cpi             temp,dskType_None
        brne    PC+2
        rjmp    dsk_write_err
 
+; Is it a RamDisk ?
+       cpi             temp,dskType_RAM
+       brne    PC+2
+       rjmp    rdsk_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