;-------------------------------------------------------------------------------
; FATware - firmware and file system driver for ZX Spectrum divIDE interface
; Copyright (c) 2005-2009 Milos Bazelides (baze)
;-------------------------------------------------------------------------------
; This software is provided "as is" without warranties or conditions of any
; kind, either express or implied. In no event shall the author(s) be held
; liable for any damages arising from the use of this software.
; See accompanying "licence.txt" file for copyright and terms of use.
;-------------------------------------------------------------------------------
; This file contains constants and macros specifically related to a particular
; Z80 implementation of the FAT filesystem driver.
;-------------------------------------------------------------------------------

;-------------------------------------------------------------------------------
; Volume Descriptor structure
;-------------------------------------------------------------------------------

; NOTE: number of cylinders is not needed for LBA->CHS conversion

vdLetter	equ	0	; BYTE  - volume letter (DON'T CHANGE!)
vdDevice	equ	1	; BYTE  - device number (including LBA bit)
vdHeads		equ	2	; BYTE  - number of heads
vdSecs		equ	3	; BYTE  - number of sectors
vdSecsPerClus	equ	4	; BYTE  - number of sectors per cluster
vdStart		equ	5	; DWORD - volume start (boot sector) LBA	; NEEDED?
vdFatLBA	equ	9	; DWORD - FAT region start
vdFatSize	equ	13	; DWORD - FAT size in sectors (reserved also for FAT32)
vdRootLBA	equ	17	; DWORD - Root Directory start LBA
vdRootSize	equ	21	; WORD  - Root Directory size in bytes
vdDataLBA	equ	23	; DWORD - Data Region start LBA
vdDataClus	equ	27	; WORD  - total number of data clusters
vdFreeClus	equ	29	; WORD  - number of free clusters		; NEEDED?
vdFstFreeClus	equ	31	; WORD  - number of the first free cluster
vdDirClus	equ	33	; WORD  - current directory cluster

vdSizeOf	equ	35

;-------------------------------------------------------------------------------
; File Descriptor structure
;-------------------------------------------------------------------------------

fdMode		equ	0	; BYTE  - file opening mode (DON'T CHANGE!)
fdVolume	equ	1	; WORD  - address of volume descriptor
fdAttr		equ	3	; BYTE  - attributes
fdStartClus	equ	4	; WORD  - starting cluster
fdSize		equ	6	; DWORD - file size in bytes
fdDirClus	equ	10	; WORD  - TODO: LBA of file's dir entry and it's offset?
fdDirEntry	equ	12	; WORD	- number of file's dir entry (WORD is OK)
fdClus		equ	14	; WORD  - current cluster
fdBytePos	equ	16	; WORD  - linear byte position in cluster
fdClusPos	equ	18	; WORD  - linear cluster position in file
fdPrevClus	equ	20	; WORD  - previous cluster
fdWritePos	equ	22	; DWORD - target position where write takes place

fdSizeOf	equ	26

; driver constants

MAX_VOL_DESC	equ	8	; maximum number of volume descriptors
MAX_FILE_DESC	equ	8	; maximum number of file descriptors
MAX_CACHED_SECS	equ	8	; maximum number of cached sectors
MAX_LFN_ENTRIES	equ	21

ERROR_TIMEOUT	equ	50

; DRIVER ERROR CODES

ERR_OK			equ	00h
ERR_INVALID_FUNC	equ	01h

; device errors

ERR_DEVICE_BUSY		equ	10h
ERR_DEV_NOT_READY	equ	11h
ERR_READ_ERROR		equ	12h
ERR_WRITE_ERROR		equ	13h

; filesystem errors

ERR_FILE_NOT_FOUND	equ	20h
ERR_FILE_NOT_OPEN	equ	21h
ERR_INVALID_VOLUME	equ	22h
ERR_INVALID_PATH	equ	23h

; out of range errors

ERR_TOO_MANY_FILES	equ	30h
ERR_VOLUME_FULL		equ	31h
ERR_DIRECTORY_FULL	equ	32h
