;
; Heap.equ
;
; Heap memory managment module equates
;
; Copyright © 1989 Claris Corporation
;
; 1-25-89 Begun by Kevin A. Watts
;
;--------------------------------------------------------------

H_MAX_FREE_LIST	equ	64	; maximum data size of blocks in free lists
H_BLOCK_GRAN	equ	2	; must be a power of 2
H_N_FREE_LISTS	equ	(H_MAX_FREE_LIST/H_BLOCK_GRAN+1)


H_HeaderRec	RECORD	0	; Structure of a heap header block

Header		DS.L 1	; handle to the header block
Version		DS.L 1	; heap version # (at offset 4 for compatability)
HeaderPtr		DS.L 1	; pointer to the header block
NumISegments	DS.W 1	; # of index segments
NumDSegments	DS.W 1	; # of data segments
FreeIndex		DS.L 1	; index free list head
EndIndex		DS.W 1	; offset to never used portion of newest index segment

ZHEADER_SHORT_SIZE	equ	*

FreeListArray	DS.L 1	; = HeaderPtr + FreeLists
ISegHandleLo	DS.L 1	; = HeaderPtr + ISegHandle
ISegHandleHi	DS.L 1	; = HeaderPtr + ISegHandle+2
DSegHandleLo	DS.L 1	; = HeaderPtr + DSegHandle
DSegHandleHi	DS.L 1	; = HeaderPtr + DSegHandle+2
ISegPtrLo		DS.L 1	; = HeaderPtr + ISegPtr
ISegPtrHi		DS.L 1	; = HeaderPtr + ISegPtr+2
DSegPtrLo		DS.L 1	; = HeaderPtr + DSegPtr
DSegPtrHi		DS.L 1	; = HeaderPtr + DSegPtr+2

ZHEADER_SIZE	equ	*

FreeLists		DS.W H_N_FREE_LISTS
			; free list heads for each block size (segment #s)
HANDLE_ARRAY	equ	*

;Array of index segment handles	DS.L	H_MaxSegments
;Array of index segment pointers	DS.L	H_MaxSegments
;Array of data segment handles	DS.L	H_MaxSegments
;Array of data segment pointers	DS.L	H_MaxSegments

	ENDR	; H_HeaderRec
	
;------------
H_VariablesRec	RECORD	H_HeaderRec.ZHEADER_SIZE	; Heap variables

; 'Globals' - maintain value across heap calls
H_ZPptr		DS.L	1	; Pointer to zero page
H_IsLocked	DS.W	1	; Flag - is current heap locked?
H_MaxSegments	DS.W	1	; Maximum number each of index & data segments
H_HeaderSize	DS.W	1	; Size of heap header
H_DSegHOffsetLo	DS.W	1	; Offset to array of handles to data segments
H_DSegHOffsetHi	DS.W	1	;   " + 2
H_ISegPOffsetLo	DS.W	1	; Offset to array of pointers to index segments
H_ISegPOffsetHi	DS.W	1	;   " + 2
H_DSegPOffsetLo	DS.W	1	; Offset to array of pointers to data segments
H_DSegPOffsetHi	DS.W	1	;   " + 2

; 'Locals' - not assumed to maintain value across heap calls
BlockSize		DS.W	1	; = DataSize + H_BLOCK_OVERHEAD
CopyHdr		DS.W	1	; Flag to control header copying
DP		DS.W	1	; place to store save direct page value
DataSize		DS.L	1	; size of data block
EndPtr		DS.L	1	; Pointer to end of used portion of index table
ErrorFlag		DS.W	1
FreeListOffset	DS.W	1	; Offset into an array of free lists
HasMoved		DS.W	1	; Flag - has heap header moved?
Index		DS.L	1	; an index
ISegPtr		DS.L	1	; pointer to an index segment
SkipLastResort	DS.W	1	; Flag - skip last resort allocation?
MaxFreeSeg	DS.W	1	; segment with most free space
MaxFreeSpace	DS.W	1	; free space in MaxFreeSeg
NewHeap		DS.L	1	; handle of heap to set
Offset		DS.W	1	; block offset within a segment
OldIndex		DS.L	1	; an index
OldPtr		DS.L	1	; a pointer
OldSize		DS.L	1	; size of data block
Ptr		DS.L	1	; generic ptr (usually to a data block)
SegHandle		DS.L	1	; handle of a data segment
Segment		DS.W	1	; a segment number
SegPtr		DS.L	1	; pointer to a data segment
SegSize		DS.W	1	; segment size

VARIABLE_SPACE	equ	*	; total size of variables

	ENDR	; H_Globals ----------------------

;------------
H_ZPSIZE	equ	H_HeaderRec.ZHEADER_SIZE+H_VariablesRec.VARIABLE_SPACE-H_VariablesRec
H_ZPATTR	equ	attrBank+attrFixed+attrLocked+attrPage

	IMPORT	D_ZeroBlock
