mirror of
https://github.com/antoinevignau/source.git
synced 2025-02-07 13:30:47 +00:00
1 line
30 KiB
Plaintext
1 line
30 KiB
Plaintext
|
;
; Heap.aii
;
; Heap memory managment module
;
; Copyright <20> 1989 Claris Corporation
;
; 1-13-89 Begun by Kevin A. Watts
;
; Heap routines:
;
; H_Init() ; Initialize heap code when loaded.
; H_SegLoaded() ; Called when the heap code is loaded.
; H_SegUnloaded() ; Called when the heap code is unloaded.
; H_CurrentHeap(): HeapID:ax ; Return the ID of the current heap.
; H_SetHeap(HeapID:xy) ; Set the current heap.
; H_UnsetHeap() ; Unset the current heap.
; H_ResetHeap() ; Reset (relock) the current heap.
; H_NewHeap(): HeapID:ax ; Create a new heap, make it current & return its ID.
; H_DisposeHeap() ; Dispose of the current heap.
; H_WriteHeap(FileID:x) ; Write the current heap to disk.
; H_ReadHeap(FileID:x): HeapID:ax ; Read the current heap from disk.
; CalcHeaderPtrs ; Calculate pointers to arrays within the header.
;--------------------------------------------------------------
PRINT PUSH
PRINT OFF
LOAD 'Macros.Dump'
gblc &__FILE__
&__FILE__ setc 'Heap'
include 'Heap.mac'
include 'HeapPrivate.equ'
include 'Heap.aii.i'
include 'm16.profile' ; must be after H.equ
include 'Driver.equ'
IMPORT D_Deref
ENTRY H_Init
IF DriverSupport = 0 THEN
ENTRY H_SegLoaded
ENTRY H_SegUnloaded
ENDIF
IF ErrorCheck THEN
ENTRY H_CurrentHeap
ENDIF
ENTRY H_SetHeap
ENTRY H_UnsetHeap
ENTRY H_ResetHeap
ENTRY H_NewHeap
ENTRY H_DisposeHeap
ENTRY H_ReadHeap
ENTRY H_WriteHeap
ENTRY CalcHeaderPtrs
PRINT POP
ProfileData 16,_H
ProfileCode _H
;<3B>;--------------------------------------------------------------
; H_Init()
; no error status returned
;
; Store the address of the heap zero page into the other heap routines
; prologue.
; THIS ROUTINE MUST BE CALLED BEFORE ANY OTHER HEAP ROUTINE IS CALLED!!
; i.e. immediately after the code segment is loaded.
; Zpage variables modified:
; H_ZPptr
H_Init PROC EXPORT
ProfileInit _H
; get the Zpage address from the driver global
IMPORT D_HeapZPage
lda >D_HeapZPage
phd
; store the Zpage address in the Zpage
tcd ; set up the Zpage
sta H_ZPptr
stz H_ZPptr+2 ; redundant, but so what?
; determine the maximum possible number of data or index segments and thus header size.
; we allow the same # of each type of segment, equal to
; _TotalMem / H_DSEG_SIZE
; H_MaxSegments will be 3 times this (3/4, *4 bytes/segment handle).
; The 3/4 is based upon H_ISEG_SIZE = 1/4 H_DSEG_SIZE, and will allow the heap
; to use 15/16 of _TotalMem. This should be sufficient.
SpaceLong
_TotalMem
pla ; discard low word
pla ; # of banks
sta H_MaxSegments ; multiply by 3
asl a
asl a
sec
sbc H_MaxSegments
MulByPwr2 a,($10000/H_DSEG_SIZE) ; # of banks * (64K/H_DSEG_SIZE)
cmp #$1000 ; ensure high nibble unused
blt @1
lda #$1000-4
@1 sta H_MaxSegments
lda #HANDLE_ARRAY ; offset to **index_seg[]
clc
adc H_MaxSegments
sta H_DSegHOffsetLo ; offset to **data_seg[]
tax
inx
inx
stx H_DSegHOffsetHi
clc
adc H_MaxSegments
sta H_ISegPOffsetLo ; offset to *index_seg[]
tax
inx
inx
stx H_ISegPOffsetHi
clc
adc H_MaxSegments
sta H_DSegPOffsetLo ; offset to *data_seg[]
tax
inx
inx
stx H_DSegPOffsetHi
clc
adc H_MaxSegments
sta H_HeaderSize ; total size of heap header
tdc ; load accumulator with Heap Zpage
pld
; embed the ZP address in the other routines
; DefineZ will correctly modify any routine using BeginZ as a prologue.
; set data bank to code bank
phb
phk
plb
IF ErrorCheck THEN
DefineZ H_CurrentHeap
ENDIF
DefineZ H_SetHeap
DefineZ H_UnsetHeap
DefineZ H_ResetHeap
DefineZ H_NewHeap
DefineZ H_DisposeHeap
IF HeapIO AND 1 THEN
DefineZ H_WriteHeap
ENDIF
IF HeapIO AND 2 THEN
DefineZ H_ReadHeap
ENDIF
DefineZ H_TruncHeap
DefineZ H_NewBlock
DefineZ H_DisposeBlock
DefineZ H_ResizeBlock
DefineZ H_CopyBlock
DefineZ H_GetBlockPtr
DefineZ H_GetBlockSize
plb ; restore data bank
rtl
ENDP
;<3B>;--------------------------------------------------------------
IF DriverSupport = 0 THEN
; H_SegLoaded()
; errors returned in accumulator (via ErrFlag)
;
; Allocate a zero page block for later use and store its address
; in
|