From 86c61c88f47675241d00ba1b13bded03801f26bb Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Tue, 7 Jul 2020 18:24:27 +0200 Subject: [PATCH] more work on garbage collector --- src/basic/engine/varstr_garbage_collect.s | 128 +++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/src/basic/engine/varstr_garbage_collect.s b/src/basic/engine/varstr_garbage_collect.s index 7683d587..1285b288 100644 --- a/src/basic/engine/varstr_garbage_collect.s +++ b/src/basic/engine/varstr_garbage_collect.s @@ -2,7 +2,133 @@ // #LAYOUT# * BASIC_0 #TAKE // #LAYOUT# * * #IGNORE +// XXX test this routine varstr_garbage_collect: - rts // XXX implement this + // The routine utilizes the 'shift_mem_up' - which leaves INDEX+0 and INDEX+1 + // free to be used, but INDEX+2 and beyond would be overwritten + + // We will reuse TXTPTR as the moving pointer, so store it on the stack + + lda TXTPTR+0 + pha + lda TXTPTR+1 + pha + + // INDEX+0 and INDEX+1 will be our cumulative shift counter + + lda #$00 + sta INDEX+0 + sta INDEX+1 + + // Start from the highest string and go downwards + + lda MEMSIZ+0 + sta TXTPTR+0 + lda MEMSIZ+1 + sta TXTPTR+1 + +varstr_garbage_collect_loop: + + // Check whether we reached FRETOP + + lda TXTPTR+0 + cmp FRETOP+0 + bne varstr_garbage_collect_check_bptr + lda TXTPTR+1 + cmp FRETOP+1 + bne varstr_garbage_collect_check_bptr + + // End of strings - nothing more to do + + // FALLTROUGH + +varstr_garbage_collect_end: + + // Restore TXTPTR and quit + + pla + sta TXTPTR+1 + pla + sta TXTPTR+0 + + rts + +varstr_garbage_collect_check_bptr: + + // Decrement TXTPTR by 2, so that it points to the back-pointer + +#if !HAS_OPCODES_65CE02 + + lda #$02 + jsr varstr_TXTPTR_down_A + +#else // HAS_OPCODES_65CE02 + + dew TXTPTR + dew TXTPTR + +#endif + + // Check whether the back-pointer is NULL + + ldy #$00 + +#if CONFIG_MEMORY_MODEL_60K + ldx #