From 2126085899baa8aef58d66fd396a5a0ae73e967e Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 30 Jul 2020 18:35:32 +0200 Subject: [PATCH] more work towards arrays --- src/basic/engine_variables/assign_variable.s | 2 + .../engine_variables/fetch_variable_arr.s | 100 +++++++++++++++--- 2 files changed, 87 insertions(+), 15 deletions(-) diff --git a/src/basic/engine_variables/assign_variable.s b/src/basic/engine_variables/assign_variable.s index 896b895b..6956affd 100644 --- a/src/basic/engine_variables/assign_variable.s +++ b/src/basic/engine_variables/assign_variable.s @@ -37,6 +37,8 @@ assign_variable: jsr is_var_ST beq_16 do_SYNTAX_error + // XXX add support for arrays + // Retrieve the variable address jsr fetch_variable_find_addr diff --git a/src/basic/engine_variables/fetch_variable_arr.s b/src/basic/engine_variables/fetch_variable_arr.s index 2c4fc5a8..8c17b36e 100644 --- a/src/basic/engine_variables/fetch_variable_arr.s +++ b/src/basic/engine_variables/fetch_variable_arr.s @@ -16,6 +16,9 @@ fetch_variable_arr: !: // Fetch the 'coordinates' + lda FOUR6 + pha // FOUR6 might get overridden, but we'll need it + ldx #$00 // counts number of dimensions // FALLTROUGH @@ -74,6 +77,10 @@ fetch_variable_arr_check_dimensions: bne_16 do_BAD_SUBSCRIPT_error + // Store number of dimensions, will be needed later + + stx __FAC1+0 + // FALLTROUGH fetch_variable_arr_calc_pos: @@ -83,37 +90,100 @@ fetch_variable_arr_calc_pos: lda #$05 jsr helper_VARPNT_up_A - // Set previous dimension size as '1' + // Set the initial offset as '0' - // XXX implement this + lda #$00 + sta __FAC1+1 + sta __FAC1+2 // FALLTROUGH fetch_variable_arr_calc_pos_loop: - // Fetch the coordinate from stack + // Fetch the current dimension - // XXX implement this + dex + txa + asl + tay + +#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 + + lda (VARPNT), y + sta __FAC1+3 + iny + lda (VARPNT), y + sta __FAC1+4 + iny + +#endif + + // Multiply offset by current dimension + + jsr helper_array_create_mul + + // Fetch the coordinate from stack; also add it to offset + + clc + pla + sta INDEX+0 + adc __FAC1+1 + sta __FAC1+1 + pla + sta INDEX+1 + adc __FAC1+2 + sta __FAC1+2 // Compare current coordinate with current dimension size + // XXX // XXX implement this - - // Multiply current coordinate with previous dimension - - // XXX implement this - - // Store current dimension, for the next iteration - - // XXX implement this + // XXX // Check if there are more dimensions to handle - dex + cpx #$00 bne fetch_variable_arr_calc_pos_loop + // FALLTROUGH + +fetch_variable_arr_calc_pos_loop_done: + + // Retrieve FOUR6, use it to calculate final offset + + pla + sta FOUR6 // XXX is it needed? + sta __FAC1+3 + stx __FAC1+4 // .X is 0 at this moment + + jsr helper_array_create_mul + + // Increment VARPNT by number of dimensions * 2, to point start of data + + lda __FAC1+0 + asl + jsr helper_VARPNT_up_A + // Increment VARPNT by the calculated offset and quit - // XXX implement this + clc + lda __FAC1+1 + adc VARPNT+0 + sta VARPNT+0 + lda __FAC1+2 + adc VARPNT+1 + sta VARPNT+1 - jmp do_NOT_IMPLEMENTED_error + rts