mirror of
https://github.com/antoinevignau/source.git
synced 2025-02-02 09:32:53 +00:00
1 line
54 KiB
Plaintext
1 line
54 KiB
Plaintext
|
;
; Block.aii
;
; Heap block allocation and deallocation routines
;
; Copyright <20> 1989 Claris Corporation
;
; 1/25/89 Begun by Kevin A. Watts
;
;--------------------------------------------------------------
; Routines: all operate on the current heap
;
; H_NewBlock(Size:xy): Index:ax ; allocate a new block and index
; H_DisposeBlock(Index:xy) ; dispose of a block
; H_ResizeBlock(Index:l,DataSize:xy): Ptr:ax ; resize a block
; H_CopyBlock(OldIndex:xy): Index:ax, Ptr:l ; copy a block
; H_GetBlockPtr(Index:xy): Ptr:ax ; get pointer to block
; H_GetBlockSize(Index:xy): Size:ax ; get size of block
; H_TruncHeap() ; shrink the heap to its minimum size
;
; NewIndex() ; allocate a new index
; DisposeIndex() ; dispose of an index
; NewBlock() ; allocate a new block
; DisposeBlock() ; dispose of a block
; CompactMoveBlock() ; move a block in SqueezeHeap or CompactSegment
; SqueezeHeap(DisposeFlag:x) ; squeeze the heap into as few segments as possible
; CompactSegment() ; compact a data segment
; NewDataSegment() ; create and initialize a new data segment
; VerifyIndex() ; verify the index in Index
;--------------------------------------------------------------
PRINT PUSH
PRINT OFF
LOAD 'Macros.Dump'
gblc &__FILE__
&__FILE__ setc 'Block'
include 'Heap.mac'
include 'HeapPrivate.equ'
include 'm16.profile'
include 'Driver.equ'
ENTRY H_NewBlock
ENTRY H_DisposeBlock
ENTRY H_ResizeBlock
ENTRY H_CopyBlock
ENTRY H_GetBlockPtr
ENTRY H_GetBlockSize
ENTRY H_TruncHeap
ENTRY NewIndex
ENTRY DisposeIndex
ENTRY NewBlock
ENTRY DisposeBlock
IF Squeezing THEN
ENTRY SqueezeHeap
ENDIF
ENTRY CompactSegment
ENTRY NewDataSegment
IF ErrorCheck THEN
ENTRY VerifyIndex
ENDIF
PRINT POP
;<3B>;--------------------------------------------------------------
; H_NewBlock(DataSize:xy): Index:ax, NewBlockPtr:l
; error status returned in y, with x used to indicate
; error in index (-1) or block (0) allocation
;
; Allocate a new block of the specified size in the current heap.
; NewBlockPtr and Index are invalid if any error occurs.
; Zpage variables modified:
; DataSize
; NewIndex()
; NewBlock()
; DisposeIndex()
H_NewBlock PROC EXPORT
BeginZ
NewBlockPtr equ 6
; stack frame w/offsets:
; 1: return address (3 bytes)
; 4: saved direct page (2 bytes)
; 6: space for returned pointer (4 bytes)
MoveLong xy,DataSize ; save the requested block size
jsr NewIndex
bcs noIndex
IF UseLastResort THEN
stz SkipLastResort
ENDIF
jsr NewBlock
bcs noBlock
sta NewBlockPtr,s
txa
sta NewBlockPtr+2,s
MoveLong Index,ax
;ldy #0 - y = 0 after NewBlock without error
ReturnZ
noIndex
IF VerboseErrors THEN
phy
Call D_AlertBox,in=(#OkBox:w,#NoIndexMesg:l),out=(a:w)
ply
sec
DEBRK3
ENDIF
ldx #-1
ReturnZ
noBlock
phy
jsr DisposeIndex
IF VerboseErrors THEN
Call D_AlertBox,in=(#OkBox:w,#NoBlockMesg:l),out=(a:w)
DEBRK3
ENDIF
ply
ldx #0
sec
ReturnZ
IF VerboseErrors THEN
NoIndexMesg str 'H_NewBlock: Unable to allocate index'
NoBlockMesg str 'H_NewBlock: Unable to allocate block'
ENDIF
ENDP
;<3B>;--------------------------------------------------------------
; H_DisposeBlock(Index:xy)
; no error status is returned
;
; Dispose of the specified block in the current heap.
; Zpage variables modified:
; Index
; ISegPtr
; DisposeBlock()
; DisposeIndex()
H_DisposeBlock PROC EXPORT
BeginZ
MoveLong xy,Index ; save the index
tya
beq disposeZeroError
IF Profile THEN
ProfileIn 9,_H
ldx Index
ENDIF
; get ptr to index segment
lda [H_ISegPtrHi],y
sta ISegPtr+2
lda [H_ISegPtrLo],y
sta ISegPtr
jsr DisposeBlock
jsr DisposeIndex
ProfileOut 9,_H
IF (ErrorCheck = 0) THEN
disposeZeroError
ENDIF
ReturnZ
IF ErrorCheck THEN
disposeZeroError
SpaceWord
PushWord #OkBox
PushLong #dzMesg
jsl D_AlertBox
pla
DEBRK2
ReturnZ
dzMesg str 'H_DisposeBlock: Attempt to dispose of index $00xx!'
ENDIF ; ErrorCheck
ENDP
;<3B>;--------------------------------------------------------------
; H_ResizeBlock(Index:l,DataSize:xy): Ptr:ax
; error status returned in y
;
; Resize the specified blo
|