From 7e5cfe9d920d5c6372917bbc9de8ff7eeb9c9d5a Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Wed, 29 Jul 2020 18:01:03 +0200 Subject: [PATCH] more work towards arrays support --- src/basic/engine_runtime/check_stack_space.s | 4 + src/basic/engine_variables/array_create.s | 2 - src/basic/engine_variables/fetch_variable.s | 21 ++-- .../engine_variables/fetch_variable_arr.s | 103 +++++++++++++++++- .../engine_variables/helper_varpnt_up_A.s | 18 +++ 5 files changed, 129 insertions(+), 19 deletions(-) create mode 100644 src/basic/engine_variables/helper_varpnt_up_A.s diff --git a/src/basic/engine_runtime/check_stack_space.s b/src/basic/engine_runtime/check_stack_space.s index 2aa2d8b3..9cbd5aa1 100644 --- a/src/basic/engine_runtime/check_stack_space.s +++ b/src/basic/engine_runtime/check_stack_space.s @@ -5,8 +5,12 @@ check_stack_space: + phx_trash_a + tsx cpx #$60 // XXX is this a safe threshold? bcc_16 do_FORMULA_TOO_COMPLEX_error + plx_trash_a + rts diff --git a/src/basic/engine_variables/array_create.s b/src/basic/engine_variables/array_create.s index a8de236a..b8fc146a 100644 --- a/src/basic/engine_variables/array_create.s +++ b/src/basic/engine_variables/array_create.s @@ -49,9 +49,7 @@ array_create_fetch_dims_loop: // Check if the stack has reasonable space free - phx_trash_a jsr check_stack_space - plx_trash_a // 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 diff --git a/src/basic/engine_variables/fetch_variable.s b/src/basic/engine_variables/fetch_variable.s index 7333ab14..083142ba 100644 --- a/src/basic/engine_variables/fetch_variable.s +++ b/src/basic/engine_variables/fetch_variable.s @@ -69,13 +69,9 @@ fetch_variable_adjust_VARPNT: #if !HAS_OPCODES_65CE02 - clc - lda VARPNT+0 - adc #$02 - sta VARPNT+0 - bcc !+ - inc VARPNT+1 -!: + lda #$02 + jsr helper_VARPNT_up_A + #else // HAS_OPCODES_65CE02 inw VARPNT @@ -91,13 +87,10 @@ fetch_variable_find_addr_next: // Increase VARPNT by 7 - constant value, each variable uses 7 bytes, see: // - https://sites.google.com/site/h2obsession/CBM/basic/variable-format - clc - lda VARPNT+0 - adc #$07 - sta VARPNT+0 - bcc fetch_variable_find_addr_loop - inc VARPNT+1 - bne fetch_variable_find_addr_loop // branch always + lda #$07 + jsr helper_VARPNT_up_A + + jmp_8 fetch_variable_find_addr_loop fetch_variable_alocate: diff --git a/src/basic/engine_variables/fetch_variable_arr.s b/src/basic/engine_variables/fetch_variable_arr.s index ae47cb7d..2c4fc5a8 100644 --- a/src/basic/engine_variables/fetch_variable_arr.s +++ b/src/basic/engine_variables/fetch_variable_arr.s @@ -10,13 +10,110 @@ fetch_variable_arr: // Array does not exist - we will have to create one with default parameters - lda #$00 - sta VARPNT+1 + // XXX implement this + + jmp do_NOT_IMPLEMENTED_error !: // Fetch the 'coordinates' + ldx #$00 // counts number of dimensions + + // FALLTROUGH + +fetch_variable_arr_fetch_coords_loop: + + inx + + // Check if the stack has reasonable space free + + jsr check_stack_space + + // Fetch the dimension and put it on the stack + + jsr fetch_uint16 + bcs_16 do_SYNTAX_error + + lda LINNUM+0 + pha + lda LINNUM+1 + pha + + // Check if more dimensions are given + + jsr fetch_character_skip_spaces + cmp #$2C // ',' + beq fetch_variable_arr_fetch_coords_loop + cmp #$29 // ')' + bne_16 do_SYNTAX_error + + // FALLTROUGH + +fetch_variable_arr_check_dimensions: + + // Check if the number of dimensions matches the stored ones + +#if CONFIG_MEMORY_MODEL_60K + + // XXX + // XXX + // XXX + +#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K + + // XXX + // XXX + // XXX + +#else // CONFIG_MEMORY_MODEL_38 + + ldy #$04 + txa + cmp (VARPNT), y + +#endif + + bne_16 do_BAD_SUBSCRIPT_error + + // FALLTROUGH + +fetch_variable_arr_calc_pos: + + // Move VARPNT po point to sizes in each dimension + + lda #$05 + jsr helper_VARPNT_up_A + + // Set previous dimension size as '1' + // XXX implement this - // XXX finish the implementation + // FALLTROUGH + +fetch_variable_arr_calc_pos_loop: + + // Fetch the coordinate from stack + + // XXX implement this + + // Compare current coordinate with current dimension size + + // XXX implement this + + // Multiply current coordinate with previous dimension + + // XXX implement this + + // Store current dimension, for the next iteration + + // XXX implement this + + // Check if there are more dimensions to handle + + dex + bne fetch_variable_arr_calc_pos_loop + + // Increment VARPNT by the calculated offset and quit + + // XXX implement this jmp do_NOT_IMPLEMENTED_error diff --git a/src/basic/engine_variables/helper_varpnt_up_A.s b/src/basic/engine_variables/helper_varpnt_up_A.s new file mode 100644 index 00000000..c6238dea --- /dev/null +++ b/src/basic/engine_variables/helper_varpnt_up_A.s @@ -0,0 +1,18 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Helper routine, used by various variable-related routines +// + + +helper_VARPNT_up_A: // .A - bytes to increment VARPNT + + clc + adc VARPNT+0 + sta VARPNT+0 + bcc !+ + inc VARPNT+1 +!: + rts