Subversion Repositories MB01 Project

Rev

Blame | Last modification | View Log | Download | RSS feed

;;
;; Copyright (c) 2016 Marco Granati <mg@unet.bz>
;;
;; Permission to use, copy, modify, and distribute this software for any
;; purpose with or without fee is hereby granted, provided that the above
;; copyright notice and this permission notice appear in all copies.
;;
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
;;

;; name: sys_fs.inc     
;; rev.: 2016/02/09
;; o.s. 65C816 version v1.0

.LIST on

;---------------------------------------------------------------------------

WKB     .EQU    ^FATSOFS        ; working bank

HPLMAX  .EQU    32      ; Max. subdirectory level

XBSTART .EQU    $0B40           ; first x-mem buffer
XBLST   .EQU    $0FFF           ; last x-mem buffer
XBCNT   .EQU    XBLST+1-XBSTART ; x-mem buffer's count
;BS     .EQU    XBCNT*2         ; word array size
;BCBCNT .EQU    XBCNT / 16
BCBCNT  .EQU    $200
BCBXBNK .EQU    $0C00
;XBUFH  .EQU    XMEMBUF

HASHMAX         .EQU    1024
HCBSTART        .EQU    $0008
HCBBNK          .EQU    4

FAT0X   .EQU    $E0
FAT1X   .EQU    $F0
DMACNT  .EQU    64

;---------------------------------------------------------------------------
; Logical Drive Table (LDT) -- page 0 offset's
;---------------------------------------------------------------------------

 STRUCT         LDT
ldt_fg1         .DB             ; logical volume flag's
                                ; <7>: device ready (fdc drive or ata device)
                                ; <6>: if=1->HD/CF else->FD
                                ; <0>: phisycal device number

ldt_fg2         .DB             ; <7>: valid volume (fat volume or cbm disk)
                                ; <6>: if=1->FAT else->CBM (FD only)
                                ; <5>: disk format checked
                                ; <1:0>: disk format (fdc only)

ldt_fp          LP              ; fat table buffer long pointer
ldt_fbuf        .DB             ; fat table: x-mem base bank/dma buffer 

ldt_root        .DW             ; lba of root dir
ldt_fat1        .DW             ; lba of fat1 table
ldt_fat2        .DW             ; lba of fat2 table
ldt_cls         .DW             ; lba of first data cluster
ldt_max         .DW             ; max usable cluster + 1
ldt_csiz        .DB             ; cluster size (1,2,4,8,16,32,64)
ldt_cshf        .DB             ; cluster shift (0,1,2,3,4,5,6)
ldt_fsiz        .DB             ; fat table size (if 0 -> 256)
ldt_rsiz        .DB             ; root dir. size (sector's)
ldt_rent        .DW             ; root dir. max. entries
ldt_cent        .DW             ; max. entries in dir. cluster
ldt_eoc         .DW             ; end of cluster chain marker
ldt_mcls        .DB             ; mask for clust. module: 00,01,03,07,0F,1F,3F
ldt_fmt         .DB             ; floppy disk format (0,1,2,FF if ata device)
ldt_cdlp        .DW             ; current working dir list pointer
ldt_cdcls       .DW             ; current working dir start cluster
ldt_free        .DW             ; count of free cluster's
ldt_nxt         .DW             ; next free cluster
ldt_cdlvl       .DB             ; current working dir level count
ldt_pbr         LP              ; long pointer to PBR cache buffer
 ESTRUCT        LDT

;---------------------------------------------------------------------------
; Hierarchical Path List (HPL) -- 16 bit offset's
;---------------------------------------------------------------------------

 LSTRUCT        HPL
hpl_cls         .DW             ; parent cluster
hpl_ix          .DW             ; entry index in parent cluster
hpl_fcb         .DS     11      ; fcb name
hpl_lst         .DB             ; unused
 ESTRUCT        HPL

;--------------------------------------------------------------------------- 
; Buffer Control Block (BCB) -- 16 bit offset's
;---------------------------------------------------------------------------

 LSTRUCT        BCB
bcb_next        .DW             ; next logical linked BCB 
bcb_drv         .DB             ; logical drive
bcb_sec         .DB             ; sector offset
bcb_cls         .DW             ; cluster
bcb_lba         .DW             ; sector lba address
bcb_lbah        .DW             ; lba high
bcb_head        .EQU    bcb_lbah        ; floppy head
bcb_buf         .DW             ; x-mem buffer number
bcb_trk         .EQU    bcb_buf ; floppy track(low) & sector(hi)
bcb_ptr         .DW             ; buffer pointer
bcb_xbnk        .DW             ; buffer pointer hi & x-mem bank
bcb_dma         .EQU    bcb_xbnk        ; buffer pointer hi & dma buffer
 ESTRUCT        BCB

;---------------------------------------------------------------------------  
; FAT Working Segment
;--------------------------------------------------------------------------- 

_FATS:  .SECTION ref_only, common, offset FATSOFS, range $010000 $01FFFF ;FAT Struct's
_FATS_START     .DS     0

; current working directory HPL  
cwdl0           .DS     (HPLSIZE*HPLMAX)
cwdl1           .DS     (HPLSIZE*HPLMAX)
cwdl2           .DS     (HPLSIZE*HPLMAX)
cwdl3           .DS     (HPLSIZE*HPLMAX)

; current building path HPL
cbpl            .DS     (HPLSIZE*HPLMAX)
HPL_CLS         .EQU    hpl_cls+cbpl
HPL_IX          .EQU    hpl_ix+cbpl
HPL_FCB         .EQU    hpl_fcb+cbpl

; BCB list's
bcbstart        .DS     (BCBCNT*BCBSIZE)
bcbend          .DS     0
dmastart        .DS     (DMACNT*BCBSIZE)
dmaend          .DS     0
dma0s           .DS     (17*BCBSIZE)
dma1s           .DS     (17*BCBSIZE)

_FATS_END       .DS     0
FATSSIZ         .EQU    (_FATS_END-_FATS_START)
.ENDS

;---------------------------------------------------------------------------

; segment for store HCB struct's (Hash Control Block)
_HCBS:  .SECTION ref_only, common, offset HCBSST, range HCBSST HCBSEND  ;HCB Struct's
hcb_next        .DW             ; pointer to next HCB
hcb_cls         .DW             ; cluster number
hcb_seq         .DW             ; sequence number + logical drive number
hcb_cnt         .DW             ; number of hashed entries
hcb_data        .DS     0        ; hash buffer data
.ENDS

;---------------------------------------------------------------------------
; direct page for LDT var's 
;---------------------------------------------------------------------------

DPLDT:  .SECTION page0, common, ref_only, offset 0      ;LDT D.P.

ldt0            .DS     LDTSIZE
ldt1            .DS     LDTSIZE
ldt2            .DS     LDTSIZE
ldt3            .DS     LDTSIZE

ldtp            .DS     4       ; pointer to LDT's in DPLDT page
sysbuf          .DS     2       ; floppy track 0 cache buffer
bpath           .DS     80

bpath1          .DS     0
.ENDS

;---------------------------------------------------------------------------
; direct page for FAT var's 
;---------------------------------------------------------------------------

DPFAT:  .SECTION page0, common, ref_only, offset 0      ;FAT D.P.

ostos           .DW             ; saved top of stack
ioerr           .DB             ; i/o error
ioerr2          .DB             ; extended i/o error
hcbroot         .DW             ; HCB struct's list
hcblst          .DW             ; the last one HCB
hsiz            .DB             ; how many sector's an HCB can hold
hlog2           .DB             ; shift count related to hsiz
bcbroot         .DW             ; BCB buffer's list
bcblst          .DW             ; the last one BCB
dmaroot         .DW             ; dma BCB buffer's list
dmalst          .DW             ; the last one dma BCB
dmabcb          .DW             ; BCB list for floppy root, cluster#2,#3&#4
fspt            .DB             ; sector per track (floppy)
pdrive          .DB             ; phisycal drive number
bplvl           .DB             ; subdir level while build path
defdrv          .DB             ; default drive

; the first block of ldt_ var's is copied from the LDT struct
ldtfg1          .DB             ; logical volume flag's
                                ; <7>: device ready (fdc drive or ata device)
                                ; <6>: if=1->HD/CF else->FD
                                ; <0>: phisycal device number

ldtfg2          .DB             ; <7>: valid volume (fat volume or cbm disk)
                                ; <6>: if=1->FAT else->CBM (FD only)
                                ; <5>: disk format checked
                                ; <1:0>: disk format (fdc only)

ldtfp           LP              ; fat table buffer long pointer
ldtfbuf         .DB             ; fat table: x-mem base bank/dma buffer

ldtroot         .DW             ; lba of root dir
ldtfat1         .DW             ; lba of fat1 table
ldtfat2         .DW             ; lba of fat2 table
ldtcls          .DW             ; lba of first data cluster
ldtmax          .DW             ; max usable cluster + 1
ldtcsiz         .DB             ; cluster size (1,2,4,8,16,32,64)
ldtcshf         .DB             ; cluster shift (0,1,2,3,4,5,6)
ldtfsiz         .DB             ; fat table size (if 0 -> 256)
ldtrsiz         .DB             ; root dir. size (sector's)
ldtrent         .DW             ; root dir. max. entries
ldtcent         .DW             ; max. entries in dir. cluster
ldteoc          .DW             ; end of cluster chain marker
ldtmcls         .DB             ; mask for clust. module: 00,01,03,07,0F,1F,3F
ldtfmt          .DB             ; floppy disk format (0,1,2, FF if ata device)
ldtcdlp         .DW             ; current working dir list pointer
ldtcdcls        .DW             ; current working dir start cluster
ldtfree         .DW             ; count of free cluster's
ldtnxt          .DW             ; next free cluster
ldtcdlvl        .DB             ; current working dir level count
ldtpbr          LP              ; long pointer to PBR cache buffer

chdcls          .DW             ; last accessed chained dir. cluster
clsofs          .DW             ; cluster's offset from start of chain

; not change order of the 2 following var's: will be accessed as 16 bit var
entofs          .DB             ; entry offset from start of sector
secofs          .DB             ; sector's offset from start of cluster

dircls          .DW             ; directory cluster 
dcnt            .DW             ; directory entry counter 
lba             .DW             ; lba sector address
lbah            .DW             ; lba is 24 bit's only
xbuf            .DW             ; x-mem buffer transfer number

fhead           .EQU    lbah    ; fd head
ftrack          .EQU    xbuf    ; fd track
fsec            .EQU    xbuf+1  ; fd sector

dfcbtyp         .DB             ; FCB type to search 
dfcbatt         .DB             ; attribute of found FCB

curdrv          .DB             ; current logical drive
fcbs            .DS     11      ; file control block name

;dcmask         .DW             ; mask to start of cluster
                                ; FFF0, FFE0, FFC0, FF80, FF00, FE00

fcbp            .DW             ; FCB buffer long pointer
                .DW             ; low=fcbp+2, high=x-mem bank or dma buffer
dmabuf          .EQU    fcbp+3  ; dma buffer #
xmbank          .EQU    fcbp+3  ; x-mem bank #

; temp area
hcbseq          .DB
hcbdrv          .DB
bcbcls          .DW
bcbdrv          .DB
bcbsec          .DB

thash           .DW
hcbrec  .EQU    thash
wtmp    .EQU    thash

hlast           .DW
hcbcls          .DW
hcbx            .DW
hcby            .DW
tmpp    .EQU    hlast   ; temp. long pointer
tmpx    .EQU    hcbx
wild    .EQU    hcbx+1
fsiz    .EQU    hcby
fptr    .EQU    hcby+1
ldrv    .EQU    hcbx
tmpldt  .EQU    hcbx+1

fhash           .DW
fcbofs          .DW
bcbload         .DB
xstart          .DB
xend            .DB
seccnt          .DB
maxseq          .DB
dsiz            .DB

haswld          .DB
strix           .DB
pathp           LP              ; long pointer to path string

; TEMP
quot            .DW
dvsor           .DW
troot           .DW
tlst            .DW
bdmask          .DW
bcmask          .DW

.ENDS

.LIST off