From 07bbc21e50cf086514359f37ea94db4823905eb7 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 26 Jul 2020 18:06:01 +0200 Subject: [PATCH] small code reorganization for arrays support --- src/basic/engine_runtime/check_stack_space.s | 12 +++ src/basic/engine_runtime/frmevl.s | 4 +- src/basic/engine_variables/array_create.s | 94 ++++++++++++++++--- .../helper_array_create_mul.s | 6 +- .../helper_index_up_a_38K_60K.s | 2 +- .../helper_index_up_a_46K_50K.s | 2 +- 6 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 src/basic/engine_runtime/check_stack_space.s diff --git a/src/basic/engine_runtime/check_stack_space.s b/src/basic/engine_runtime/check_stack_space.s new file mode 100644 index 00000000..2aa2d8b3 --- /dev/null +++ b/src/basic/engine_runtime/check_stack_space.s @@ -0,0 +1,12 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +check_stack_space: + + tsx + cpx #$60 // XXX is this a safe threshold? + bcc_16 do_FORMULA_TOO_COMPLEX_error + + rts diff --git a/src/basic/engine_runtime/frmevl.s b/src/basic/engine_runtime/frmevl.s index fd42ecdc..c2b24bdd 100644 --- a/src/basic/engine_runtime/frmevl.s +++ b/src/basic/engine_runtime/frmevl.s @@ -323,9 +323,7 @@ FRMEVL_push_operator_address: // Check if there is enough stack space; this could not have been done earlier, // as this is the place where unary operator support calls - tsx - cpx #$60 // XXX is this a safe threshold? - bcc_16 do_FORMULA_TOO_COMPLEX_error + jsr check_stack_space // Push the operator address to stack, in a form // suitable for RTS diff --git a/src/basic/engine_variables/array_create.s b/src/basic/engine_variables/array_create.s index 6994ed3b..d63106e9 100644 --- a/src/basic/engine_variables/array_create.s +++ b/src/basic/engine_variables/array_create.s @@ -44,15 +44,26 @@ array_create_fetch_dims_loop: inx - // XXX check if stack has reasonable space free + // Check if the stack has reasonable space free - // Fetch the dimension, put it on the stack - confirmed with orioginal ROM, - // that it also stores dimensions in the reverse order + jsr check_stack_space + + // Fetch the dimension, increment it by 1, and put it on the stack; + // confirmed with original ROM, that it also stores dimensions in the reverse order jsr fetch_uint16 bcs_16 do_SYNTAX_error - // XXX we probably need to increment LINNUM first +#if !HAS_OPCODES_65CE02 + inc LINNUM+0 + bne !+ + inc LINNUM+1 +!: +#else + inw LINNUM +#endif + + beq_16 do_OUT_OF_MEMORY_error lda LINNUM+0 pha @@ -144,7 +155,7 @@ array_create_store_dims_done: // Restore FOUR6, calculate number of bytes needed for storage pha - sta FOUR6 // XXX do we need to store this value in FOUR6? + sta FOUR6 // XXX do we need to store this value in FOUR6? is it still needed? sta __FAC1+2 stx __FAC1+3 // .X is 0 at this point @@ -152,15 +163,76 @@ array_create_store_dims_done: // XXX check if we have enough memory - // XXX retrieve and store array name + // Retrieve and store array name - // XXX calculate and store offset to the next array + ldy #$00 - // XXX clear area +#if CONFIG_MEMORY_MODEL_60K + + // XXX + // XXX: implement this + // XXX - // XXX adjust STREND +#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K - // XXX adjust offset of the previous array + pla + sta (STREND), y + iny + pla + sta (STREND), y + +#endif + + // Calculate and store offset to the next array + + lda #$02 + jsr helper_INDEX_up_A + +#if CONFIG_MEMORY_MODEL_60K + + // XXX + // XXX: implement this + // XXX + +#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K + + // XXX + // XXX: implement this + // XXX + +#else // CONFIG_MEMORY_MODEL_38K + + ldy #$04 + lda (STREND), y + +#endif + + asl + jsr helper_INDEX_up_A + +#if CONFIG_MEMORY_MODEL_60K + + // XXX + // XXX: implement this + // XXX + +#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K + + ldy #$02 + lda INDEX+0 + sta (STREND), y + iny + lda INDEX+1 + sta (STREND), y + +#endif + + // Clear newly alocated area + + // XXX implement this + + // Adjust STREND + + // XXX implement this jmp do_NOT_IMPLEMENTED_error - diff --git a/src/basic/engine_variables/helper_array_create_mul.s b/src/basic/engine_variables/helper_array_create_mul.s index 3be777ec..1d42e218 100644 --- a/src/basic/engine_variables/helper_array_create_mul.s +++ b/src/basic/engine_variables/helper_array_create_mul.s @@ -54,14 +54,14 @@ helper_array_create_mul_error: helper_array_create_mul_success: lda INDEX+0 - sta __FAC+0 + sta __FAC1+0 lda INDEX+1 - sta __FAC+1 + sta __FAC1+1 plx_trash_a rts -helper_array_create_mul_add: +helper_array_create_mul_8x8_add: jsr mul_FAC2_FAC1_8x8 diff --git a/src/basic/engine_variables/helper_index_up_a_38K_60K.s b/src/basic/engine_variables/helper_index_up_a_38K_60K.s index 259453da..54198e25 100644 --- a/src/basic/engine_variables/helper_index_up_a_38K_60K.s +++ b/src/basic/engine_variables/helper_index_up_a_38K_60K.s @@ -3,7 +3,7 @@ // #LAYOUT# * * #IGNORE // -// Helper routine, used by garbage collector and string concatenation +// Helper routine, used in several places // #if CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_60K diff --git a/src/basic/engine_variables/helper_index_up_a_46K_50K.s b/src/basic/engine_variables/helper_index_up_a_46K_50K.s index e5b09d35..38ede00c 100644 --- a/src/basic/engine_variables/helper_index_up_a_46K_50K.s +++ b/src/basic/engine_variables/helper_index_up_a_46K_50K.s @@ -5,7 +5,7 @@ // This has to go $E000 or above - it can be used by routines which bank out the main BASIC ROM! // -// Helper routine, used by garbage collector and string concatenation +// Helper routine, used in several places // #if CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K