Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- address: .EQUATE 6
- v: .EQUATE 2
- current: .EQUATE 0
- free: nop0
- subsp 4, i
- lda address, s
- ;;;; Get the size from the memory to be deallocated
- ldx address, s
- subx 2, i
- stx address, s
- ldx address, sf
- ;;;; Fill the deallocated memory with '??'s
- qfill: nop0
- sta v, s
- lda 0x3F3F, i
- sta v, sf
- lda v, s
- adda 2, i
- subx 2, i
- brgt qfill
- ;;;; Traverse the linked list
- lda Hhead, d
- sta current, s
- linkloop: nop0
- cpa 0, i
- breq mERROR2
- sta HEA, d
- lda HEA, n ;;;; ...until we find a node with an flink
- cpa address, s ;;;; who's higher in memory than our deallocated space is.
- brge lldone ;;;; This is the node we're going to link to.
- sta current, s
- br linkloop
- lldone: nop0
- ;;;; load our deallocated size into X now, because we're going to overwrite it
- ldx address, sf
- sta address, sf ;;;; put the address to the next link into the flink of our new link
- ;;;; add 2 to address to point to the size field
- lda address, s
- adda 2, i
- sta address, s
- ;;;; we have the deallocated amount - 2 space left
- ;;;; (since 4 bytes are used by the structure)
- subx 2, i
- stx address, sf ;;;; and we put that into where the size goes
- ;;;; lastly, let's put the address of where our new link is into
- suba 4, i
- sta HEA, n ;;;; into the flink of the previous node
- mERROR2: ret4 ;;;; On error, just return.
- .END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement