[list -]
%if 0

NASM structure definitions
Public Domain by E. C. Masloch, 2008--2012

%endif

%ifndef __lSTRUCT_MAC__
%assign __lSTRUCT_MAC__ 1

%include "lmacros2.mac"
[list -]


	struc BS
bsJump:	resb 3
bsOEM:	resb 8
bsBPB:
	endstruc

	struc EBPB		;        BPB sec
bpbBytesPerSector:	resw 1	; offset 00h 0Bh
bpbSectorsPerCluster:	resb 1	; offset 02h 0Dh
bpbReservedSectors:	resw 1	; offset 03h 0Eh
bpbNumFATs:		resb 1	; offset 05h 10h
bpbNumRootDirEnts:	resw 1	; offset 06h 11h -- 0 for FAT32
bpbTotalSectors:	resw 1	; offset 08h 13h
bpbMediaID:		resb 1	; offset 0Ah 15h
bpbSectorsPerFAT:	resw 1	; offset 0Bh 16h -- 0 for FAT32
bpbCHSSectors:		resw 1	; offset 0Dh 18h
bpbCHSHeads:		resw 1	; offset 0Fh 1Ah
bpbHiddenSectors:	resd 1	; offset 11h 1Ch
bpbTotalSectorsLarge:	resd 1	; offset 15h 20h
bpbNew:				; offset 19h 24h

ebpbSectorsPerFATLarge:	resd 1	; offset 19h 24h
ebpbFSFlags:		resw 1	; offset 1Dh 28h
ebpbFSVersion:		resw 1	; offset 1Fh 2Ah
ebpbRootCluster:	resd 1	; offset 21h 2Ch
ebpbFSINFOSector:	resw 1	; offset 25h 30h
ebpbBackupSector:	resw 1	; offset 27h 32h
ebpbReserved:		resb 12	; offset 29h 34h
ebpbNew:			; offset 35h 40h
	endstruc

	struc BPBN		; ofs B16 S16 B32 S32
bpbnBootUnit:		resb 1	; 00h 19h 24h 35h 40h
			resb 1	; 01h 1Ah 25h 36h 41h
bpbnExtBPBSignature:	resb 1	; 02h 1Bh 26h 37h 42h -- 29h for valid BPBN
bpbnSerialNumber:	resd 1	; 03h 1Ch 27h 38h 43h
bpbnVolumeLabel:	resb 11	; 07h 20h 2Bh 3Ch 47h
bpbnFilesystemID:	resb 8	; 12h 2Bh 36h 47h 52h
	endstruc		; 1Ah 33h 3Eh 4Fh 5Ah

lsvclSignature		equ "CL"
lsvclBufferLength	equ 256

	struc LOADSTACKVARS, -10h
lsvFirstCluster:	resd 1
lsvFATSector:		resd 1
lsvFATSeg:		resw 1
lsvLoadSeg:		resw 1
lsvDataStart:		resd 1
	endstruc

	struc LOADDATA, LOADSTACKVARS - 10h
ldMemoryTop:	resw 1
ldLoadTop:	resw 1
ldSectorSeg:	resw 1
ldFATType:	resb 1
ldFlags:
ldHasLBA:	resb 1
ldClusterSize:	resw 1
ldParaPerSector:resw 1
ldDirCluster:			; dword
ldLoadingSeg:		; word
ldQueryPatchValue:	; word
lsvCommandLine:		; word
.start:		equ $ - lsvclBufferLength
.signature:	resw 1
ldLoadUntilSeg:		; word
lsvExtra:		; word
.partition:	resb 1	; byte
.flags:		resb 1	; byte
	endstruc

	struc LOADDATA2, LOADDATA - 10h
ldRootSector:		resd 1
ldEntriesPerSector:	resw 1
ldLastAvailableSector:	resw 1
ldParasLeft:		resw 1
ldParasDone:		resw 1
ldBytesPerSector:	resw 1
	endstruc

	struc DIRENTRY
deName:		resb 8
deExt:		resb 3
deAttrib:	resb 1
		resb 8
deClusterHigh:	resw 1
deTime:		resw 1
deDate:		resw 1
deClusterLow:	resw 1
deSize:		resd 1
	endstruc

ATTR_READONLY	equ 1
ATTR_HIDDEN	equ 2
ATTR_SYSTEM	equ 4
ATTR_VOLLABEL	equ 8
ATTR_DIRECTORY	equ 10h
ATTR_ARCHIVE	equ 20h

	struc LBAPACKET
lpSize:		resw 1
lpCount:	resw 1
lpBuffer:	resd 1
lpSector:	resq 1
	endstruc

	struc PARTINFO
piBoot:		resb 1
piStartCHS:	resb 3
piType:		resb 1
piEndCHS:	resb 3
piStart:	resd 1
piLength:	resd 1
	endstruc

ptEmpty:		equ 0
ptFAT12:		equ 1
ptFAT16_16BIT_CHS:	equ 4
ptExtendedCHS:		equ 5
ptFAT16_CHS:		equ 6
ptFAT32_CHS:		equ 0Bh
ptFAT32:		equ 0Ch
ptFAT16:		equ 0Eh
ptExtended:		equ 0Fh
ptLinux:		equ 83h
ptExtendedLinux:	equ 85h

	struc MCB
mcbSignature:	resb 1
mcbOwner:	resw 1
mcbSize:	resw 1
mcbReserved:	resb 3
mcbName:
smcbName:	resb 2		; (always "S" for S MCBs)
smcbType:	resb 1
smcbReserved2:	resb 1
smcbLink:	resw 1
smbcReserved3:	resw 1
	endstruc

		; Values for smcbType
S_OTHER		equ 00h					; Other/Undefined
						; DOS internal
S_DOSENTRY	equ 01h					; DOSENTRY section
S_DOSCODE	equ 02h					; DOSCODE section
S_DOSDATA	equ 03h					; DOSDATA section
S_IRQSCODE	equ 04h					; IRQ stack code
S_IRQSDATA	equ 05h					; IRQ stack data
S_CDS		equ 06h					; CDS
S_LFNCDS	equ 07h					; LFN CDSes
S_DPB		equ 08h					; DPBs
S_UPB		equ 09h					; UPBs
S_SFT		equ 0Ah					; SFTs
S_FCBSFT	equ 0Bh					; FCB SFTs
S_CCB		equ 0Ch					; CCBs
S_IRT		equ 0Dh					; IRTs
S_SECTOR	equ 0Eh					; Single sector buffer
S_NLS		equ 0Fh					; NLS related
S_EBDA		equ 10h					; EBDA
						; System initialization
S_INITFCBSFT	equ 16h
S_INITSTACK	equ 17h
S_INITCDS	equ 18h
S_INITCONFIG	equ 19h
S_INITFATSEG	equ 1Ah
S_INITSECTORSEG	equ 1Bh
S_INITSTACKBPB	equ 1Ch
S_INITPSP	equ 1Dh					; Initialization PSP
S_ENVIRONMENT	equ 1Eh					; Master environment
S_INITIALIZE	equ 1Fh					; DOSINITIALIZE, data
S_INITIALISE	equ 1Fh					; DOSINITIALISE, data
S_INIT		equ 1Fh
						; Device drivers
S_DEVICE	equ 20h					; Device
S_DEVICEMEMORY	equ 21h					; Allocated by device
						; Memory management
S_EXCLDUMA	equ 30h					; Excluded UMA
S_EXCLDUMASUB	equ 31h					; Excluded UMA with sub-chain of used MCBs
S_EXCLDLH	equ 32h					; Excluded by LH
S_EXCLDDOS	equ 33h					; Excluded by DOS (usually 21.4B or 21.714B)
S_EXCLDALTAH	equ 34h
						; Values F0h-FFh are defined by other software.
						; smcbLink then contains an address of either a
						; valid MCB or PSP. Other software mustn't
						; recognize an S MCB with smcbType solely using
						; this value, it must also insure that smcbLink
						; points to an owner known to the software.
						; Undefined or other allocations not associated
						; or accessed by other software shouldn't use
						; F0h-FFh but S_OTHER.

	struc HMCB
hmcbSignature:	resw 1
hmcbOwner:	resw 1
hmcbSize:	resw 1
hmcbNext:	resw 1
hmcbReserved:
hmcbName:	resb 8
	endstruc

	; DOS flags, indicate to init2_relocate_(device|end)
	;  where to relocate specific items to.
DOSFLAGS_RELOCATE_DOSCODE_UMA:	equ 1
DOSFLAGS_RELOCATE_DOSCODE_HMA:	equ 2
DOSFLAGS_RELOCATE_DOSDATA_UMA:	equ 4
DOSFLAGS_LINK_UMB:		equ 8
DOSFLAGS_RELOCATE_SFT_UMA:	equ 10h
DOSFLAGS_RELOCATE_CDS_UMA:	equ 20h
DOSFLAGS_RELOCATE_LFNCDS_UMA:	equ 40h

DOSFLAGS_RELOCATE_ALL_UMA:	equ (DOSFLAGS_RELOCATE_DOSCODE_UMA \
					| DOSFLAGS_RELOCATE_DOSDATA_UMA \
					| DOSFLAGS_RELOCATE_SFT_UMA \
					| DOSFLAGS_RELOCATE_CDS_UMA \
					| DOSFLAGS_RELOCATE_LFNCDS_UMA \
					)
DOSFLAGS_RELOCATE_ALL_HMA:	equ (DOSFLAGS_RELOCATE_DOSCODE_HMA)


	; Error Flags, set in word [DOSDATA:error_flags]
EF_InvalidAllocStrategy:	equ 1
EF_MultipleAllocAreas:		equ 2
EF_InvalidUMBLink:		equ 4
EF_NoUMBsToLink:		equ 8

		; SFT container
	struc SFTC
sftcNext:		resd 1	; -> next SFT container, unless offset is -1
sftcEntries:		resw 1	; number of SFTs in this SFT container
	endstruc

		; Actual SFT structure. May differ from compatible one.
	struc ASFT
exact_struc_at 00h,	asftReferences:		resw 1
exact_struc_at 02h,	asftMode:		resw 1
exact_struc_at 04h,	asftAttrib:		resb 1
exact_struc_at 05h,	asftInfo:		resw 1
exact_struc_at 07h,	asftRedirector1_6Bytes:
exact_struc_at 07h,	asftDevice:
exact_struc_at 07h,	asftDPB:		resd 1	; (redir specific)
exact_struc_at 0Bh,	asftStartCluster16Bit:	resw 1	; (redir specific)
exact_struc_at 0Dh,	asftTime:		resw 1
exact_struc_at 0Fh,	asftDate:		resw 1
exact_struc_at 11h,	asftSize32Bit:		resd 1
exact_struc_at 15h,	asftSeek32Bit:		resd 1
exact_struc_at 19h,	asftRedirector2_7Bytes:
exact_struc_at 19h,	asftRelCurCluster16Bit:	resw 1	; (redir specific)
exact_struc_at 1Bh,	asftDirSector:		resd 1	; (redir specific)
exact_struc_at 1Fh,	asftDirIndex:		resb 1	; (redir specific)
		; instead of the above, in EDR-DOS this is:
		;  DirCluster16Bit, unused byte, DirIndexHigh, DirIndex8Bit
exact_struc_at 20h,	asftName:		resb 8
exact_struc_at 28h,	asftExtension:		resb 3
exact_struc_at 2Bh,	asftShareNext:		resd 1
exact_struc_at 2Fh,	asftMachine:		resw 1
exact_struc_at 31h,	asftOwner:		resw 1
exact_struc_at 33h,	asftShareRecord:	resw 1
exact_struc_at 35h,	asftRedirector3_6Bytes:
exact_struc_at 35h,	asftAbsCurCluster16Bit:	resw 1	; (redir specific)
exact_struc_at 37h,	asftIFSPointer:		resd 1	; (redir specific)
exact_struc_at 3Bh,	SFT_FAT16_32BITSEEK_SIZE:
		; The following fields are compatible to EDR-DOS 7.01.08 WIP
		;  Refer to its DRDOS/doshndl.def
exact_struc_at 3Bh,	asftStartClusterHigh:	resw 1
exact_struc_at 3Dh,	asftRelCurClusterHigh:	resw 1
exact_struc_at 3Fh,				resw 1	; EDR-DOS: DirClusterHigh
exact_struc_at 41h,	asftAbsCurClusterHigh:	resw 1
exact_struc_at 43h,	SFT_FAT32_32BITSEEK_SIZE:
exact_struc_at 43h,	asftSizeHigh32Bit:	resd 1
exact_struc_at 47h,	asftSeekHigh32Bit:	resd 1
exact_struc_at 4Bh,	SFT_FAT32_64BITSEEK_SIZE:
	endstruc

sftiNoInherit		equ 1000h
sftiDevice		equ 0080h

	; (if sftiDevice clear)
sftiRedirector		equ 8000h
sftiNoSetTime		equ 4000h
sftiNotRemovable	equ 0800h
sftiFileNotWritten:	equ 0040h
sftiDriveMask:		equ 003Fh

	; (if sftiDevice set)
sftiDeviceIOCTL:	equ 4000h
sftiDeviceOutputTilBusy:equ 2000h
sftiDeviceOpenClose:	equ 0800h
sftiDeviceEOFOnInput:	equ 0040h
sftiDeviceRawMode:	equ 0020h
sftiDeviceInt29:	equ 0010h
sftiDeviceClock:	equ 0008h
sftiDeviceNul:		equ 0004h
sftiDeviceStdOut:	equ 0002h
sftiDeviceStdIn:	equ 0001h


	struc ERRORCODES
exact_struc_at 00h,	errorNoError:		resb 1
exact_struc_at 01h,	errorInvalidFunction:	resb 1
exact_struc_at 02h,	errorFileNotFound:	resb 1
exact_struc_at 03h,	errorPathNotFound:	resb 1
exact_struc_at 04h,	errorNoHandlesAvailable:resb 1
exact_struc_at 05h,	errorAccessDenied:	resb 1
exact_struc_at 06h,	errorInvalidHandle:	resb 1
exact_struc_at 07h,	errorMCBDestroyed:	resb 1
exact_struc_at 08h,	errorInsufficientMemory:resb 1
exact_struc_at 09h,	errorMCBInvalid:	resb 1
exact_struc_at 0Ah,	errorEnvironmentInvalid:resb 1
exact_struc_at 0Bh,	errorFormatInvalid:	resb 1
exact_struc_at 0Ch,	errorAccessCodeInvalid:	resb 1
exact_struc_at 0Dh,	errorDataInvalid:	resb 1
exact_struc_at 0Eh,	errorFixupOverflow:	resb 1
exact_struc_at 0Fh,	errorInvalidDrive:	resb 1
exact_struc_at 10h,	errorAttemptedToRemoveCurrentDirectory:	resb 1
exact_struc_at 11h,	errorNotSameDevice:	resb 1
exact_struc_at 12h,	errorNoMoreFiles:	resb 1
exact_struc_at 13h
struc_at 0FDh,		errorSFTLoops:
struc_at 0FEh,		errorMCBLoops:
struc_at 100h,		errorBehindLastDirectErrorCode:
	endstruc

	struc PSP
exact_struc_at 00h, pspCall0:		resw 1
exact_struc_at 02h, pspEndSegment:	resw 1
					resb 1
exact_struc_at 05h, pspCall5:		resb 1
exact_struc_at 06h, pspSegmentSize:	resw 1
					resw 1
exact_struc_at 0Ah, pspInt22:		resd 1
exact_struc_at 0Eh, pspInt23:		resd 1
exact_struc_at 12h, pspInt24:		resd 1
exact_struc_at 16h, pspParent:		resw 1
exact_struc_at 18h, pspPHT:		resb 20
				endarea pspPHT
exact_struc_at 2Ch, pspEnvironment:	resw 1
exact_struc_at 2Eh, pspStack:		resd 1
exact_struc_at 32h, pspPHTEntries:	resw 1
exact_struc_at 34h, pspPHTAddress:	resd 1
exact_struc_at 38h, pspShareNext:	resd 1
exact_struc_at 3Ch, pspInterimFlag:	resb 1
exact_struc_at 3Dh, pspTruenameFlag:	resb 1
					resb 2
exact_struc_at 40h, pspVersion:		resw 1
exact_struc_at 42h, pspMSWNext1:	resw 1
exact_struc_at 44h, pspMSWPartition:	resw 1
exact_struc_at 46h, pspMSWNext2:	resw 1
exact_struc_at 48h, pspMSWFlag:		resb 1
					resb 1
					resb 2
exact_struc_at 4Ch, pspMSWStack:	resw 1
					resb 2
exact_struc_at 50h, pspInt21Far:	resb 3
					resb 9
exact_struc_at 5Ch, pspFCB1:		resb 16
exact_struc_at 6Ch, pspFCB2:		resb 16
exact_struc_at 7Ch,			resb 4
exact_struc_at 80h, pspCommandLine:
		    pspDefaultDTA:	resb 128
exact_struc_at 100h
	endstruc


	struc BDA
bdaBaseSerial1:	resw 1			; 00h
bdaBaseSerial2:	resw 1			; 02h
bdaBaseSerial3:	resw 1			; 04h
bdaBaseSerial4:	resw 1			; 06h
bdaBaseParallel1:	resw 1		; 08h
bdaBaseParallel2:	resw 1		; 0Ah
bdaBaseParallel3:	resw 1		; 0Ch
bdaBaseParallel4:
bdaEBDASegment:		resw 1		; 0Eh

bdaInstalledHardware:	resw 1		; 10h
			resb 1		; 12h
bdaMemorySizeKiB:	resw 1		; 13h
			resb 1		; 15h
			resb 1		; 16h
bdaKeybStatusFlags1:	resb 1		; 17h
bdaKeybStatusFlags2:	resb 1		; 18h
			resb 1		; 19h
bdaKeybBufferNext:	resw 1		; 1Ah
bdaKeybBufferFree:	resw 1		; 1Ch
bdaKeybBuffer:		resw 16		; 1Eh
			resb 1		; 3Eh
			resb 1		; 3Fh
bdaDisketteMotorOffTime:resb 1		; 40h
bdaDisketteLastStatus:	resb 1		; 41h
			resb 7		; 42h
bdaVideoMode:		resb 1		; 49h
bdaVideoColumns:	resw 1		; 4Ah
			resw 1		; 4Ch
			resw 1		; 4Eh
bdaVideoCursorPositions:resw 8		; 50h
			resw 1		; 60h
bdaVideoCurrentPage:	resb 1		; 62h
bdaVideoBase:		resw 1		; 63h
			resb 1		; 65h
			resb 1		; 66h
bdaResetRestartAddress:	resd 1		; 67h
			resb 1		; 6Bh
bdaTimerTicks:		resd 1		; 6Ch
bdaTimerOverflow:	resb 1		; 70h
bdaCtrlBreakFlag:	resb 1		; 71h
bdaPOSTResetFlag:	resw 1		; 72h
bdaFixedDiskLastStatus:	resb 1		; 74h
bdaNumberFixedDisks:	resb 1		; 75h
			resb 1		; 76h
			resb 1		; 77h
bdaTimeoutParallel1:	resb 1		; 78h
bdaTimeoutParallel2:	resb 1		; 79h
bdaTimeoutParallel3:	resb 1		; 7Ah
bdaTimeoutParallel4:
bdaInt4BFlags:		resb 1		; 7Bh
bdaTimeoutSerial1:	resb 1		; 7Ch
bdaTimeoutSerial2:	resb 1		; 7Dh
bdaTimeoutSerial3:	resb 1		; 7Eh
bdaTimeoutSerial4:	resb 1		; 7Fh
bdaKeybBufferStart:	resw 1		; 80h
bdaKeybBufferEnd:	resw 1		; 82h
bdaVideoRowsMinusOne:	resb 1		; 84h
bdaVideoCharHeight:	resw 1		; 85h
bdaVideoControlFlags:	resb 1		; 87h
bdaVideoSwitches:	resb 1		; 88h
			resb 1		; 89h
			resb 1		; 8Ah
			resb 1		; 8Bh
			resb 1		; 8Ch
			resb 1		; 8Dh
			resb 1		; 8Eh
			resb 1		; 8Fh
			resb 1		; 90h
			resb 1		; 91h
			resb 1		; 92h
			resb 1		; 93h
			resb 1		; 94h
			resb 1		; 95h
bdaKeybStatusByte1:	resb 1		; 96h
bdaKeybStatusByte2:	resb 1		; 97h
			resb (256 - ($-$$))
	endstruc

%endif
[list +]
