summaryrefslogtreecommitdiff
path: root/programs/sub-suite/libc.s
diff options
context:
space:
mode:
Diffstat (limited to 'programs/sub-suite/libc.s')
-rw-r--r--programs/sub-suite/libc.s499
1 files changed, 205 insertions, 294 deletions
diff --git a/programs/sub-suite/libc.s b/programs/sub-suite/libc.s
index ae35146..53e936a 100644
--- a/programs/sub-suite/libc.s
+++ b/programs/sub-suite/libc.s
@@ -17,12 +17,10 @@ strtoull:
pla ; Get the character back.
beq @end ; No, so we're done.
@alpha:
- sec ; Yes, so prepare for a non borrowing subtract.
- sbc #'a'-10 ; Get the numeric value from this digit.
+ sub #'a'-10 ; Yes, so get the numeric value from this digit.
bra @chkbase ; Check if the value matches the base.
@digit:
- sec ; Prepare for a non borrowing subtract.
- sbc #'0' ; Get the numeric value from this digit.
+ sub #'0' ; Get the numeric value from this digit.
@chkbase:
cmp sp+25 ; Does the value match the base?
bcs @end ; No, so we're done.
@@ -30,8 +28,7 @@ strtoull:
tab ; Save the digit value.
lda.q sp+1 ; Get the value from the value buffer.
mul sp+25 ; Multiply the value by the base.
- clc ; Prepare for a non carrying add.
- adc b ; Add the digit value to the total value.
+ add a, b ; Add the digit value to the total value.
sta.q sp+1 ; Place the value in the value buffer.
iny ; Increment the string index.
and #0 ; Reset A.
@@ -44,80 +41,72 @@ strtoull:
strlen:
- phy.q ; Preserve Y.
- pha.q ; Set the temp variable to the argument.
and #0 ; Reset A.
- tay ; Reset Y.
@loop:
- lda (sp+1), y ; Are we at the end of the string?
- beq @end ; Yes, so we're done.
- iny ; No, so increment the index.
- bra @loop ; Keep looping.
+ inc ; Increment the index.
+ cmp (d+a-1), #0 ; Are we at the end of the string?
+ bne @loop ; No, so keep looping.
@end:
- pla.q ; Get the argument back.
- tya ; Get the return value.
- ply.q ; Get the preserved value back.
+ dec ; Decrement the length to not include the terminator.
rts ; End of strlen.
strcmp:
- ldb #0 ; Reset B.
- tba ; Reset A.
+ phb.q ; Preserve B.
+ phx.q ; Preserve X.
phy.q ; Preserve Y.
+ and #0 ; Reset A.
+ tab ; Reset B.
+ tax ; Reset X.
tay ; Reset Y.
@loop:
- ldb #0 ; Set the islong flag to false.
- lda (sp+25), y ; Are we at the end of the first string?
+ ldx #0 ; Set the islong flag to false.
+ mov a, (d+y) ; Are we at the end of the first string?
beq cmpr ; Yes, so check if we're too short, or too long.
- ldb #1 ; No, so set the islong flag to true.
- cmp (sp+19), y ; Is the character of both strings, the same?
+ ldx #1 ; No, so set the islong flag to true.
+ cmp a, (s+y) ; Is the character of both strings, the same?
bne cmpr ; No, so check if we're too short, or too long.
iny ; Yes, so increment the index.
bra @loop ; Keep looping.
-strccmp:
strcasecmp:
- ldb #0 ; Reset B.
- tba ; Reset A.
+ phb.q ; Preserve B.
+ phx.q ; Preserve X.
phy.q ; Preserve Y.
+ and #0 ; Reset A.
+ tab ; Reset B.
+ tax ; Reset X.
+ inx ; Set X to 1.
tay ; Reset Y.
@loop:
- ldb #0 ; Set the islong flag to false.
- lda (sp+25), y ; Are we at the end of the first string?
+ dex ; Set the islong flag to false.
+ mov a, (d+y) ; Are we at the end of the first string?
beq cmpr ; Yes, so check if we're too short, or too long.
- ldb #1 ; No, so set the islong flag to true.
+ inx ; No, so set the islong flag to true.
jsr tolower ; Convert the character of string 1 to lowercase.
- phb ; Preserve the islong flag.
- pha ; Preserve the converted character.
- lda (sp+19), y ; Get the character of the second string.
+ tab ; Save the converted character.
+ mov a, (s+y) ; Get the character of the second string.
jsr tolower ; Convert the character of string 2 to lowercase.
- tab ; Place it in B.
- pla ; Get the character of string 1 back.
cmp b ; Is the character of both strings, the same?
- plb ; Get the islong flag back.
bne cmpr ; No, so check if we're too short, or too long.
iny ; Yes, so increment the index.
bra @loop ; Keep looping.
cmpr:
- lda (sp+17), y ; Are we at the end of the second string?
+ mov a, (s+y) ; Are we at the end of the second string?
beq @islong ; Yes, so check the islong flag.
@isshort:
- lda (sp+25), y ; No, but are we at the end of the first string?
- beq @short ; Yes, so return -1.
-@islong:
- cpb #1 ; Is the islong flag true?
- bne @equ ; No, so return 0.
-@long:
- lda #1 ; Yes, so return 1.
+ mov a, (d+y) ; No, but are we at the end of the first string?
+ bne @islong ; No, so check if the islong flag is true.
+ lda #$FF ; Yes, so return -1.
bra @end ; We are done.
-@equ:
- lda #0 ; Return 0.
- bra @end ; We are done.
-@short:
- lda #$FF ; Return -1.
+@islong:
+ cpx #1 ; Is the islong flag true?
+ set a, eq ; Return true if it is.
@end:
- ply.q ; Get the preserved value back.
+ ply.q ; Restore Y.
+ plx.q ; Restore X.
+ plb.q ; Restore B.
rts ; End of cmpr.
@@ -195,304 +184,226 @@ toupper:
; malloc: Dynamically allocate memory.
-; Input: A = size in bytes to allocate.
+; Input: D = size in bytes to allocate.
; Output: A = Pointer to allocated memory.
-; Caller preserved registers: none.
-; Callie preserved registers: Y.
+; Caller preserved registers: D.
+; Callie preserved registers: B, X, Y.
malloc:
- phy.q ; Preserve Y.
- pha.q ; Preserve the size.
- and #0 ; Reset A.
- tay ; Reset Y.
- sbs #$10 ; Allocate 2 local variables onto the stack.
- lda.q sp+17 ; Get the size.
- ora.d sp+21 ; Is the size zero?
- beq @end ; Yes, so we're done.
- lda.q sp+17 ; No, so get back the size.
- clc ; Prepare for a non carrying add.
- adc #ublk ; Add the size of a used block struct, to the size.
- sta.q sp+17 ; Set the actual size.
- lda.q heapf ; Get the first heap entry.
- sta.q sp+9 ; Save it in the second local variable.
- bra @checkblk ; Check the block.
+ phb.q ; Preserve B.
+ phx.q ; Preserve X.
+ phy.q ; Preserve Y.
+ xor b, b ; Reset B.
+ mov x, b ; Reset X.
+ txy ; Reset Y.
+ mov a, d ; Get the size.
+ beq @end ; The size is zero, so we're done.
+ add #ublk ; Add the size of a used block struct, to the size.
+ cmp #ublk ; Is the total size smaller than the size of a used block struct?
+ bcs @getheapf ; No, so get the first heap entry.
+@toosmall:
+ lda #ublk ; Yes, so set the total size to the size of a used block struct.
+@getheapf:
+ mov d, a ; Place the new size into the passed size.
+ ldb.q heapf ; Get the first heap entry.
+ bra @checkblk ; Check the block.
@findfblk:
- ldy #fblk.size ; Get the size of this free block.
- lda.q (sp+9), y ;
- sec ; Prepare for a non borrowing subtract.
- sbc.q sp+17 ; Subtract the size of this free block, with the passed size.
- bcs @blkfound ; The result is less than, or equal to the free size, so return the found block.
- ldy #fblk.next ; Get the next free block.
- lda.q (sp+9), y ;
- sta.q sp+9 ; Set the current free block, to the next free block.
+ mov.q a, (b+fblk.size) ; Get the size of this free block.
+ sub a, d ; Subtract the size of this free block, with the passed size.
+ bcs @blkfound ; The result is less than, or equal to the free size, so return the found block.
+ mov.q b, (b+fblk.next) ; Set the current free block, to the next free block.
@checkblk:
- ora.d sp+13 ; Is the address of this block, zero?
- bne @findfblk ; No, so keep looping.
- lda.q heapptr ; Yes, so get the current top of the heap.
- clc ; Prepare for a non carrying add.
- adc.q sp+17 ; Add the top of the heap, with the passed size.
- bcs @outofspace ; The result overflowed, so return zero.
- cmp.q heapend ; Is the top of the heap, less than, or equal to the max heap size?
- bcc @inctop ; Yes, so increase the current top of the heap.
- beq @inctop ;
+ bne @findfblk ; The address of this block is non NULL, so keep looping.
+ mov a, d ; Get the passed size.
+ add.q heapptr ; Add the top of the heap, with the passed size.
+; mov d, a ; Save the new size.
+ bcs @outofspace ; The result overflowed, so return zero.
+ cmp.q heapend ; Is the top of the heap, less than, or equal to the max heap size?
+ bcc @inctop ; Yes, so increase the current top of the heap.
+ beq @inctop ;
@outofspace:
- and #0 ; Return zero.
- bra @end ; We are done.
+ and #0 ; Return zero.
+ bra @end ; We are done.
@inctop:
- pha.q ; Preserve heapptr + size.
- lda.q heapptr ; Get the previous top of the heap.
- sta.q sp+17 ; Set the current free block to the previous top of the heap.
- pla.q ; Restore heapptr + size.
- sta.q heapptr ; Increment the current top of the heap by the passed size.
- bra @setsize ; Set the size, and start address into the used space of the block.
+
+ ldb.q heapptr ; Set the current free block to the previous top of the heap.
+ sta.q heapptr ; Increment the current top of the heap by the passed size.
+ bra @setsize ; Set the size, and start address into the used space of the block.
@blkfound:
- bne @sliceblk ; The block is big enough to slice.
- cmp #fblk ; Is the block big enough to slice?
- bcs @sliceblk ; Yes, so slice the block.
- ldy #fblk.prev ; No, so get the previous free block.
- lda.q (sp+9), y ;
- sta.q sp+1 ; Set the third local variable, to the previous free block.
- ora.d sp+5 ; Is the previous block, set to zero?
- beq @setheapf ; Yes, so set the first block.
- ldy #fblk.next ; No, so get the next free block.
- lda.q (sp+9), y ;
- sta.q (sp+1), y ; Set the previous block's next block, to the next block.
- bra @chknxtblk ; Check the next block.
+ bne @sliceblk ; The block is big enough to slice.
+ cmp #fblk ; Is the block big enough to slice?
+ bcs @sliceblk ; Yes, so slice the block.
+ mov.q x, (b+fblk.prev) ; Get the previous free block.
+ beq @setheapf ; The previous block is NULL, so set the first block.
+ ldy #fblk.next ; No, so set the offset to the next free block.
+ mov.q (x+y), (b+y) ; Set the previous block's next block, to the next block.
+ bra @chknxtblk ; Check the next block.
@setheapf:
- lda.q (sp+9), y ; Get the next block.
- sta.q heapf ; Set the first heap entry to it.
+ ldy #fblk.next ; Set the offset to the next block.
+ mov.q heapf, (b+y) ; Set the first heap entry to the next block.
@chknxtblk:
- lda.q (sp+9), y ; Get the next free block.
- sta.q sp+1 ; Set the third local variable to the next free block.
- ora.d sp+5 ; Is the next block, zero?
- beq @setheapl ; Yes, so set the least heap entry.
- ldy #fblk.prev ; No, so get the current previous block.
- lda.q (sp+9), y ;
- sta.q (sp+1), y ; Set the next block's previous block to the current previous block.
- bra @retptr ; Return the pointer.
+ mov.q x, (b+y) ; Get the next free block.
+ beq @setheapl ; The next block is NULL, so set the least heap entry.
+ ldy #fblk.prev ; Get the current previous block.
+ mov.q (x+y), (b+y) ; Set the next block's previous block to the current previous block.
+ bra @retptr ; Return the pointer.
@setheapl:
- ldy #fblk.prev ; Get the current previous block.
- lda.q (sp+9), y ;
- sta.q heapl ; Set the last heap entry to the current previous block.
- bra @retptr ; Return the pointer.
+ ldy #fblk.prev ; Get the current previous block.
+ mov.q heapl, (b+y) ; Set the last heap entry to the current previous block.
+ bra @retptr ; Return the pointer.
@sliceblk:
- ldy #fblk.size ; Get the size of the current block.
- lda.q (sp+9), y ;
- sec ; Prepare for a non borrowing subtract.
- sbc.q sp+17 ; Subtract the current block's size from the passed size.
- sta.q (sp+9), y ; Set the current block's size to the subtracted size.
- clc ; Prepare for a non carrying add.
- adc.q sp+9 ; Add the current block's size to the pointer of the current block.
- sta.q sp+9 ; Set the current block to the space above it (return value).
+ ldy #fblk.size ; Get the size of the current block.
+ sub.q (b+y), d ; Subtract the current block's size from the passed size.
+ add.q b, (b+y) ; Add the current block's size to the pointer of the current block.
@setsize:
- ldy #ublk.size ; Start setting the used block's size, to the passed size.
- lda.q sp+17 ; Get the passed size.
- sta.q (sp+9), y ; Set the used block's size to the passed size.
+ mov.q (b+ublk.size), d ; Set the used block's size to the passed size.
@retptr:
- ldy #ublk.start ; Start setting the used block's starting address, to the used block.
- lda.q sp+9 ; Get the used block.
- sta.q (sp+9), y ; Set the used block's starting address, to the used block.
- clc ; Prepare for a non carrying add.
- adc #ublk ; Return the pointer to the real memory block.
+ mov.q (b+ublk.start), b ; Set the used block's starting address, to the used block.
+ add b, #ublk ; Get the pointer to the real memory block.
+ tba ; Return the pointer to the real memory block.
@end:
- ads #$18 ; Clean up the stack frame.
- ply.q ; Restore Y.
- rts ; End of malloc.
+ ply.q ; Restore Y.
+ plx.q ; Restore X.
+ plb.q ; Restore B.
+ rts ; End of malloc.
; free: Free allocated memory.
-; Input: A = Pointer to allocated memory.
+; Input: D = Pointer to allocated memory.
; Output: none.
-; Caller preserved registers: none.
-; Callie preserved registers: A, B, Y.
+; Caller preserved registers: D.
+; Callie preserved registers: A, B, X, Y, E.
free:
- pha.q ; Preserve A.
- phb.q ; Preserve B.
- phy.q ; Preserve Y.
- pha.q ; Push the pointer argument to the stack.
- and #0 ; Reset A.
- tay ; Reset Y.
- sbs #$18 ; Allocate 3 local variables onto the stack.
- lda.q sp+25 ; Get the passed pointer.
- ora.d sp+29 ; Is the passed pointer NULL?
- bne @getrealblk ; No, so get the real block.
- bra @end ; Yes, so we're done.
+ pha.q ; Preserve A.
+ phb.q ; Preserve B.
+ phx.q ; Preserve X.
+ phy.q ; Preserve Y.
+ phe.q ; Preserve E.
+ and #0 ; Reset A.
+ tab ; Reset B.
+ tax ; Reset X.
+ tay ; Reset Y.
+ mov a, d ; Get the passed pointer.
+ bne @getrealblk ; The pointer isn't NULL, so get the real block.
+ bra @end ; The pointer is NULL, so we're done.
@getrealblk:
- lda.q sp+25 ; Get the passed pointer.
- sec ; Prepare for a non borrowing subtract.
- sbc #8 ; Move the passed pointer back by one.
- sta.q sp+25 ; Set the first local variable to the start of the used block.
- lda.q (sp+25) ; Get the real block address.
- sta.q sp+25 ; Set the passed pointer to the start of the real block.
- ldy #ublk.size ; Get the size of the real block.
- lda.q (sp+25), y;
- sta.q sp+17 ; Save the size of the real block.
- clc ; Prepare for a non carrying add.
- adc.q sp+25 ; Add the size of the real block with the start of the real block.
- cmp.q heapptr ; Is this block on top of the heap?
- bne @heapadd ; No, so add it to the free block list.
+ sub #8 ; Get the start of the used block.
+ mov.q a, (a) ; Get the start of the real block.
+ mov.q b, (a+ublk.size) ; Get the size of the real block.
+ lea e, (a+b) ; Add the size of the real block with the start of the real block.
+ cpe.q heapptr ; Is this block on top of the heap?
+ bne @heapadd ; No, so add it to the free block list.
@dectop:
- lda.q sp+25 ; Get the block.
- sta.q heapptr ; Set the top of the heap to it.
+ sta.q heapptr ; Set the top of the heap to the start of the current real block.
@chklastblk:
- lda.q heapl ; Get the last free list entry.
- sta.q sp+17 ; Copy it into the second local variable.
- ora.d sp+21 ; Is the free list empty?
- beq @end ; Yes, so we're done.
- lda.q sp+17 ; No, so Get the last free list entry.
- ldy #fblk.size ; Get the size of the block.
- lda.q (sp+17), y;
- clc ; Prepare for a non carrying add.
- adc.q sp+17 ; Add the size of the block, with the address of the block entry.
- cmp.q heapptr ; Is the last block on top of the heap?
- bne @end ; No, so we're done.
+ ldb.q heapl ; Get the last free list entry.
+ beq @end ; The free list is empty, so we're done.
+ ldy #fblk.size ; Get the size of the block.
+ mov.q a, (b+fblk.size) ; Get the size of the block.
+ lea e, (a+b) ; Add the size of the block, with the address of the block entry.
+ cpe.q heapptr ; Is the last block on top of the heap?
+ bne @end ; No, so we're done.
@delblk:
- lda.q sp+17 ; Yes, so remove the last block.
- sta.q heapptr ;
+ stb.q heapptr ; Yes, so remove the last block.
@correctblk:
- ldy #fblk.prev ; Get the previous block.
- lda.q (sp+17), y;
- sta.q sp+25 ; Save the previous block for now.
- sta.q heapl ; Set the last block to the previous block.
- ora.d sp+29 ; Is the previous block non NULL?
- bne @delnxtblk ; Yes, so delete the next block.
- sta.q heapf ; No, so empty the free list.
- bra @end ; We are done.
+ mov.q a, (b+fblk.prev) ; Get the previous block.
+ sta.q heapl ; Set the last block to the previous block.
+ bne @delnxtblk ; The previous block isn't NULL, so delete the next block.
+ sta.q heapf ; The previous block is NULL, so empty the free list.
+ bra @end ; We are done.
@delnxtblk:
- and #0 ; Reset A.
- ldy #fblk.next ; Delete the next block.
- sta.q (sp+25), y;
+ lea e, (a+fblk.next) ; Delete the next block.
+ stz.q (e) ;
@end:
- ads #$20 ; Clean up the stack frame.
- ply.q ; Restore Y.
- plb.q ; Restore B.
- pla.q ; Restore A.
- rts ; End of free.
+ ple.q ; Restore E.
+ ply.q ; Restore Y.
+ plx.q ; Restore X.
+ plb.q ; Restore B.
+ pla.q ; Restore A.
+ rts ; End of free.
@heapadd:
- lda.q heapf ; Get the first block.
- sta.q sp+9 ; Copy it into the third local variable.
- ora.d sp+13 ; Is the free list empty?
- bne @srchflst ; No, so start searching the free list.
+ ldy.q heapf ; Get the first block.
+ bne @srchflst ; The Free list isn't empty, so start searching the free list.
@empty:
- ldy #fblk.next ; Clear the next block.
- sta.q (sp+25), y;
- ldy #fblk.prev ; Clear the previous block.
- sta.q (sp+25), y;
- lda.q sp+25 ; Reset A.
- sta.q heapf ; Clear the first block entry.
- sta.q heapf ; Clear the last block entry.
- bra @end ; We are done.
+ mov.q (a+fblk.next), y ; Clear the next block.
+ mov.q (a+fblk.prev), y ; Clear the previous block.
+ sta.q heapf ; Set the first block entry to the current block.
+ sta.q heapl ; Set the last block entry to the current block.
+ bra @end ; We are done.
@srchflst:
- and #0 ; Reset A.
- sta.q sp+1 ; Reset the left pointer.
- ldy #fblk.next ; Setup for the loop.
@loop:
- lda.q sp+9 ; Get the right pointer.
- cmp.q sp+25 ; Is the right pointer at, or below the current block?
- beq @nextright ; Yes, so get the next right pointer.
- bcs @chkrmerge ; No, so do the right block merge.
+ cmp y, a ; Is the right pointer at, or below the current block?
+ beq @nextright ; Yes, so get the next right pointer.
+ bcs @chkrmerge ; No, so do the right block merge.
@nextright:
- sta.q sp+1 ; Set the left pointer, to the right pointer.
- lda.q (sp+9), y ; Get the next right pointer.
- sta.q sp+9 ; Set the current right pointer to the next right pointer.
- ora.d sp+13 ; Is the next right pointer NULL?
- bne @loop ; No, so keep looping.
+ tyx ; Set the left pointer, to the right pointer.
+ mov.q y, (y+fblk.next) ; Set the current right pointer to the next right pointer.
+ bne @loop ; The next right pointer isn't NULL, so keep looping.
@st_lmerge2:
- sta.q (sp+25), y; Clear the next block.
- lda.q sp+25 ; Get the current block.
- sta.q heapl ; Set the last free block entry to it.
- bra @chklmerge2 ; Do the left block merge.
+ mov.q (a+fblk.next), y ; Clear the next block.
+ sta.q heapl ; Set the last free block entry to it.
+ bra @chklmerge2 ; Do the left block merge.
@chkrmerge:
- lda.q sp+25 ; Get the current block.
- clc ; Prepare for a non carrying add.
- adc.q sp+17 ; Add the size of the current block, to the current block.
- cmp.q sp+9 ; Is the right pointer NULL?
- bne @normerge ; No, so don't merge the right block.
+ lea e, (a+b) ; Add the size of the current block, to the current block.
+ cmp e, y ; Is the current block the same as the right block?
+ bne @normerge ; No, so don't merge the right block.
@rmerge:
- ldy #fblk.size ; Get the size of the right pointer.
- lda.q sp+17 ; Get the size of the current block.
- clc ; Prepare for a non carrying add.
- adc.q (sp+9), y ; Add the size of the current block, with the size of the right pointer.
- sta.q (sp+25), y; Set the size of the current block, to the new size.
+ mov e, b ; Get the size of the current block.
+ add.q e, (y+fblk.size) ; Add the size of the current block, with the size of the right pointer.
+ mov.q (a+fblk.size), e ; Set the size of the current block, to the new size.
@rmerge2:
- ldy #fblk.next ; Get the next right pointer.
- lda.q (sp+9), y ;
- sta.q (sp+25), y; Set the next block, to the next right pointer.
- sta.q sp+17 ; Save the next block in the second local variable.
- ora.d sp+21 ; Is the next block NULL?
- beq @setheapl ; Yes, so set the last block.
+ lea fblk.next ; Get the next right pointer.
+ mov.q (a+e), (y+e) ; Set the next block, to the next right pointer.
+ mov.q b, (y+e) ; Save the next block.
+ beq @setheapl ; The next block is NULL, so set the last block.
@setprev:
- lda.q sp+25 ; Get the current block.
- ldy #fblk.prev ; Set the previous block to the current block.
- sta.q (sp+17), y;
- bra @chklmerge ; Do the left block merge.
+ mov.q (b+fblk.prev), a ; Set the previous block to the current block.
+ bra @chklmerge ; Do the left block merge.
@setheapl:
- lda.q sp+25 ; Get the current block.
- sta.q heapl ; Set the last block to the current block.
- bra @chklmerge ; Do the left block merge.
+ sta.q heapl ; Set the last block to the current block.
+ bra @chklmerge ; Do the left block merge.
@normerge:
- lda.q sp+9 ; Get the right pointer.
- ldy #fblk.next ; Set the next block to the right pointer.
- sta.q (sp+25), y;
- lda.q sp+25 ; Get the current block.
- ldy #fblk.prev ; Set the previous right pointer to the current block.
- lda.q (sp+9), y ;
+ mov.q (a+fblk.next), y ; Set the next block to the right pointer.
+ mov.q (y+fblk.prev), a ; Set the previous right pointer to the current block.
@chklmerge:
- lda.q sp+1 ; Get the left pointer.
- ora.d sp+5 ; Is the left pointer NULL?
- bne @chklmerge2 ; No, so keep checking.
+ and x, x ; Is the left pointer NULL?
+ bne @chklmerge2 ; No, so keep checking.
@newstart:
- ldy #fblk.prev ; Clear the previous block.
- sta.q (sp+25), y;
- lda.q sp+25 ; Get the current block.
- sta.q heapf ; Set the first block, to the current block.
- bra @end2 ; We are done.
+ mov.q (a+fblk.prev), x ;
+ sta.q heapf ; Set the first block, to the current block.
+ bra @end2 ; We are done.
@chklmerge2:
- ldy #fblk.size ; Get the size of the left block.
- lda.q (sp+1), y ;
- clc ; Prepare for a non carrying add.
- adc.q sp+1 ; Add the size of the left block, to the left pointer.
- cmp.q sp+25 ; Is the left block adjacent?
- bne @nolmerge ; No, so don't merge the left block.
+ mov.q e, (x+fblk.size) ; Get the size of the left block.
+ add e, x ; Add the size of the left block, to the left pointer.
+ cmp e, a ; Is the left block adjacent?
+ bne @nolmerge ; No, so don't merge the left block.
@lmerge:
- lda.q (sp+1), y ; Get the size of the left block.
- clc ; Prepare for a non carrying add.
- ldb.q (sp+25), y; Get the size of the current block.
- adc b ; Add the size of the left block, with the size of the current block.
- sta.q (sp+1), y ; Set the size of the left block to the new size.
+ lea fblk.size ; Set the offset to the block size.
+ add.q (x+e), (a+e) ; Add the size of the left block, with the size of the current block.
@lmerge2:
- ldy #fblk.next ; Get the next block.
- lda.q (sp+25), y;
- sta.q (sp+1), y ; Set the next left pointer, to the next block.
- sta.q sp+17 ; Set the second local variable to the next block.
- ora.d sp+21 ; Is the next left pointer NULL?
- beq @newlast ; Yes, so set the last block.
+ lea fblk.next ; Set the offset to the next block.
+ mov.q (x+e), (a+e) ; Set the next left pointer, to the next block.
+ mov.q b, (a+e) ; Get the next block.
+ beq @newlast ; The next block is NULL, so set the last block.
@lprev:
- lda.q sp+1 ; Get the left pointer.
- ldy #fblk.prev ; Set the next left pointer's previous pointer to the left pointer.
- sta.q (sp+17), y;
- bra @end2 ; We are done.
+ mov.q (b+fblk.prev), x ; Set the next left pointer's previous pointer to the left pointer.
+ bra @end2 ; We are done.
@newlast:
- lda.q sp+1 ; Get the left pointer.
- sta.q heapl ; Set the last block, to the left pointer.
- bra @end2 ; We are done.
+ stx.q heapl ; Set the last block, to the left pointer.
+ bra @end2 ; We are done.
@nolmerge:
- lda.q sp+25 ; Get the current block.
- ldy #fblk.next ; Set the next left pointer, to the current block.
- sta.q (sp+1), y ;
+ mov.q (x+fblk.next), a ; Set the next left pointer, to the current block.
@nolmerge2:
- lda.q sp+1 ; Get the left pointer.
- ldy #fblk.prev ; Set the previous block, to the left pointer.
- sta.q (sp+25), y;
+ mov.q (a+fblk.prev), x ; Set the previous block, to the left pointer.
@end2:
- ads #$20 ; Clean up the stack frame.
- ply.q ; Restore Y.
- plb.q ; Restore B.
- pla.q ; Restore A.
- rts ; End of free.
+ ple.q ; Restore E.
+ ply.q ; Restore Y.
+ plb.q ; Restore B.
+ pla.q ; Restore A.
+ rts ; End of free.
; memcpy: memory to memory copy.