mirror of
https://github.com/cc65/cc65.git
synced 2024-10-01 15:54:59 +00:00
Use macpack for debugging, cosmetic changes
git-svn-id: svn://svn.cc65.org/cc65/trunk@171 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
0b7aae0f07
commit
bb4f3c4475
@ -64,42 +64,46 @@
|
|||||||
.import pushax, __hadd
|
.import pushax, __hadd
|
||||||
.export _free
|
.export _free
|
||||||
|
|
||||||
; Offsets into struct freeblock
|
.macpack generic
|
||||||
|
|
||||||
|
; Offsets into struct freeblock and other constant stuff
|
||||||
|
|
||||||
|
size = 0
|
||||||
|
next = 2
|
||||||
|
prev = 4
|
||||||
|
admin_space = 2
|
||||||
|
min_size = 6
|
||||||
|
|
||||||
size = 0
|
|
||||||
next = 2
|
|
||||||
prev = 4
|
|
||||||
|
|
||||||
; Code
|
; Code
|
||||||
|
|
||||||
_free: sta ptr1
|
_free: sta ptr1
|
||||||
stx ptr1+1 ; Save block
|
stx ptr1+1 ; Save block
|
||||||
|
|
||||||
; Is the argument NULL?
|
; Is the argument NULL?
|
||||||
|
|
||||||
ora ptr1+1 ; Is the argument NULL?
|
ora ptr1+1 ; Is the argument NULL?
|
||||||
beq @L9 ; Jump if yes
|
beq @L9 ; Jump if yes
|
||||||
|
|
||||||
; Decrement the given pointer by 2. The size of the block is stored there.
|
; Decrement the given pointer by the admin space amount, so it points to the
|
||||||
|
; real block allocated. The size of the block is stored in the admin space.
|
||||||
; Remember the block size in ptr2.
|
; Remember the block size in ptr2.
|
||||||
|
|
||||||
sec
|
|
||||||
lda ptr1
|
lda ptr1
|
||||||
sbc #2
|
sub #admin_space
|
||||||
sta ptr1
|
sta ptr1
|
||||||
bcs @L1
|
bcs @L1
|
||||||
dec ptr1+1
|
dec ptr1+1
|
||||||
@L1: ldy #size+1
|
@L1: ldy #size+1
|
||||||
lda (ptr1),y ; High byte of size
|
lda (ptr1),y ; High byte of size
|
||||||
sta ptr2+1 ; Save it
|
sta ptr2+1 ; Save it
|
||||||
dey
|
dey
|
||||||
lda (ptr1),y
|
lda (ptr1),y
|
||||||
sta ptr2
|
sta ptr2
|
||||||
|
|
||||||
; Check if the block is on top of the heap
|
; Check if the block is on top of the heap
|
||||||
|
|
||||||
clc
|
add ptr1
|
||||||
adc ptr1
|
|
||||||
tay
|
tay
|
||||||
lda ptr1+1
|
lda ptr1+1
|
||||||
adc ptr2+1
|
adc ptr2+1
|
||||||
@ -126,12 +130,11 @@ _free: sta ptr1
|
|||||||
lda __hlast+1
|
lda __hlast+1
|
||||||
sta ptr2+1 ; Pointer to last block now in ptr2
|
sta ptr2+1 ; Pointer to last block now in ptr2
|
||||||
|
|
||||||
clc
|
|
||||||
ldy #size
|
ldy #size
|
||||||
lda (ptr2),y ; Low byte of block size
|
lda (ptr2),y ; Low byte of block size
|
||||||
adc ptr2
|
add ptr2
|
||||||
tax
|
tax
|
||||||
iny ; High byte of block size
|
iny ; High byte of block size
|
||||||
lda (ptr2),y
|
lda (ptr2),y
|
||||||
adc ptr2+1
|
adc ptr2+1
|
||||||
|
|
||||||
@ -151,14 +154,14 @@ _free: sta ptr1
|
|||||||
|
|
||||||
ldy #prev+1 ; Offset of ->prev field
|
ldy #prev+1 ; Offset of ->prev field
|
||||||
lda (ptr2),y
|
lda (ptr2),y
|
||||||
sta ptr1+1 ; Remember f->prev in ptr1
|
sta ptr1+1 ; Remember f->prev in ptr1
|
||||||
sta __hlast+1
|
sta __hlast+1
|
||||||
dey
|
dey
|
||||||
lda (ptr2),y
|
lda (ptr2),y
|
||||||
sta ptr1 ; Remember f->prev in ptr1
|
sta ptr1 ; Remember f->prev in ptr1
|
||||||
sta __hlast
|
sta __hlast
|
||||||
ora __hlast+1 ; -> prev == 0?
|
ora __hlast+1 ; -> prev == 0?
|
||||||
bne @L8 ; Jump if free list not empty
|
bne @L8 ; Jump if free list not empty
|
||||||
|
|
||||||
; Free list is now empty (A = 0)
|
; Free list is now empty (A = 0)
|
||||||
|
|
||||||
@ -172,11 +175,11 @@ _free: sta ptr1
|
|||||||
; Block before is now last block. ptr1 points to f->prev.
|
; Block before is now last block. ptr1 points to f->prev.
|
||||||
|
|
||||||
@L8: lda #$00
|
@L8: lda #$00
|
||||||
dey ; Points to high byte of ->next
|
dey ; Points to high byte of ->next
|
||||||
sta (ptr1),y
|
sta (ptr1),y
|
||||||
dey ; Low byte of f->prev->next
|
dey ; Low byte of f->prev->next
|
||||||
sta (ptr1),y
|
sta (ptr1),y
|
||||||
rts ; Done
|
rts ; Done
|
||||||
|
|
||||||
; The block is not on top of the heap. Add it to the free list.
|
; The block is not on top of the heap. Add it to the free list.
|
||||||
|
|
||||||
@ -191,3 +194,4 @@ _free: sta ptr1
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user