From 54a6daa2c1d7614b222769673ae7eaa4d1dc9f90 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 19 Jul 2020 19:10:55 +0200 Subject: [PATCH] one more string aloccation optimization - for extended ROM machines --- src/aliases/,aliases_config.s | 7 + src/basic/engine_variables/assign_variable.s | 145 +++++++++++++++++- .../helper_index_up_a_38K_60K.s | 2 +- .../helper_index_up_a_46K_50K.s | 2 +- 4 files changed, 148 insertions(+), 8 deletions(-) diff --git a/src/aliases/,aliases_config.s b/src/aliases/,aliases_config.s index 42c8166b..ae1798de 100644 --- a/src/aliases/,aliases_config.s +++ b/src/aliases/,aliases_config.s @@ -364,3 +364,10 @@ .const CONFIG_COLOR_TXT = $01 #endif + + +// Determine if we need space-savings in BASIC code + +#if !ROM_LAYOUT_M65 +#define HAS_SMALL_BASIC +#endif diff --git a/src/basic/engine_variables/assign_variable.s b/src/basic/engine_variables/assign_variable.s index 849cf50b..896b895b 100644 --- a/src/basic/engine_variables/assign_variable.s +++ b/src/basic/engine_variables/assign_variable.s @@ -243,14 +243,15 @@ assign_string_not_same: assign_string_not_text_area: - // Check if the new string is a temporary one - if so, reuse alocation - - // XXX - // Check if the old string belongs to the string area (is above FRETOP) jsr helper_cmp_fretop + +#if HAS_SMALL_BASIC bcc assign_string_no_optimizations +#else + bcc assign_string_try_takeover +#endif // FALLTROUGH @@ -261,18 +262,27 @@ assign_string_try_reuse: lda DSCPNT+0 cmp __FAC1+0 +#if HAS_SMALL_BASIC + // If size of both string equals - simply reuse it beq_16 helper_strvarcpy -assign_string_try_reuse_unsuccesful: - // No special case optimization is possible - but first get rid of the old string jsr varstr_free // FALLTROUGH +#else + + // If size of both string equals - simply reuse it + + bne assign_string_try_takeover_free + jmp helper_strvarcpy + +#endif + assign_string_no_optimizations: // Allocate memory for the new string @@ -296,3 +306,126 @@ assign_string_no_optimizations: // Copy the string and quit jmp helper_strvarcpy + + +#if !HAS_SMALL_BASIC + +assign_string_try_takeover_free: + + jsr varstr_free + + // FALLTROUGH + +assign_string_try_takeover: + + // Check if the new string is a temporary one - if so, takeover the allocation + + ldx #$19 + + // FALLTROUGH + +assign_string_tmp_check_loop: + + cpx TEMPPT + beq assign_string_no_optimizations // branch if this is not a temporary string + + lda $01, x + cmp __FAC1+1 + bne assign_string_tmp_check_next + + lda $02, x + cmp __FAC1+2 + bne assign_string_tmp_check_next + + lda $01, x + beq assign_string_tmp_check_next + + // This is a temporary string - takeover the content + +#if CONFIG_MEMORY_MODEL_60K + + ldy #$00 + phx_trash_a + lda $00, x + ldx #