;
.importzp ptr1, ptr2, ptr3, ptr4
;
.importzp ptr1, ptr2, ptr3, ptr4
; Check if the last block in the freelist is now at heap top. If so, remove
; this block from the freelist.
; Check if the last block in the freelist is now at heap top. If so, remove
; this block from the freelist.
; The block is not on top of the heap. Add it to the free list. This was
; formerly a separate function called __hadd that was implemented in C as
; The block is not on top of the heap. Add it to the free list. This was
; formerly a separate function called __hadd that was implemented in C as
; /* Merge with the right block */
; f->size += right->size;
; if (f->next = right->next) {
; /* Merge with the right block */
; f->size += right->size;
; if (f->next = right->next) {
; We have to search the free list. As we are doing so, check if it is possible
; to combine this block with another, already existing block. Beware: The
; block may be the "missing link" between two blocks.
; ptr3 contains _hfirst (the start value of the search) when execution reaches
; We have to search the free list. As we are doing so, check if it is possible
; to combine this block with another, already existing block. Beware: The
; block may be the "missing link" between two blocks.
; ptr3 contains _hfirst (the start value of the search) when execution reaches
; a merge. The new block is the new freelist end.
; A is zero when we come here, Y points to next+1
; a merge. The new block is the new freelist end.
; A is zero when we come here, Y points to next+1
; Since we have checked the case that the freelist is empty before, if the
; right pointer is NULL, the left *cannot* be NULL here. So skip the
; Since we have checked the case that the freelist is empty before, if the
; right pointer is NULL, the left *cannot* be NULL here. So skip the
; Set f->next = right->next and remember f->next in ptr1 (we don't need the
; size stored there any longer)
; Set f->next = right->next and remember f->next in ptr1 (we don't need the
; size stored there any longer)
- iny ; Points to next
- lda (ptr3),y ; Low byte of right->next
- sta (ptr2),y ; Store to low byte of f->next
+ iny ; Points to next
+ lda (ptr3),y ; Low byte of right->next
+ sta (ptr2),y ; Store to low byte of f->next
- iny ; Points to next+1
- lda (ptr3),y ; High byte of right->next
- sta (ptr2),y ; Store to high byte of f->next
+ iny ; Points to next+1
+ lda (ptr3),y ; High byte of right->next
+ sta (ptr2),y ; Store to high byte of f->next
- iny ; Points to prev
- lda ptr2 ; Low byte of f
- sta (ptr1),y ; Low byte of f->next->prev
- iny ; Points to prev+1
- lda ptr2+1 ; High byte of f
- sta (ptr1),y ; High byte of f->next->prev
- jmp CheckLeftMerge ; Done
+ iny ; Points to prev
+ lda ptr2 ; Low byte of f
+ sta (ptr1),y ; Low byte of f->next->prev
+ iny ; Points to prev+1
+ lda ptr2+1 ; High byte of f
+ sta (ptr1),y ; High byte of f->next->prev
+ jmp CheckLeftMerge ; Done
- ldy #size ; Calculate left + left->size
- lda (ptr4),y ; Low byte of left->size
+ ldy #freeblock_size ; Calculate left + left->size
+ lda (ptr4),y ; Low byte of left->size
; No merge of the left block, just set the link. Y points to size+1 if
; we come here. Do left->next = f.
NoLeftMerge:
; No merge of the left block, just set the link. Y points to size+1 if
; we come here. Do left->next = f.
NoLeftMerge: