From 127b71f67f4e8bc18214e73a3692f8f1f370701e Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Wed, 15 Jul 2020 19:54:22 +0200 Subject: [PATCH] string handling fixes --- src/basic/basic_commands/cmd_let.s | 25 ++++- src/basic/engine/ad9e.frmevl.s | 16 +++- src/basic/engine/fetch_variable.s | 107 +++++++++++++--------- src/basic/engine/varstr_alloc.s | 2 +- src/basic/engine/varstr_alloc_fretop.s | 2 + src/basic/engine/varstr_free.s | 3 +- src/basic/engine/varstr_free_fretop.s | 2 + src/basic/engine/varstr_garbage_collect.s | 3 +- 8 files changed, 107 insertions(+), 53 deletions(-) diff --git a/src/basic/basic_commands/cmd_let.s b/src/basic/basic_commands/cmd_let.s index 2d36d6e7..706ea931 100644 --- a/src/basic/basic_commands/cmd_let.s +++ b/src/basic/basic_commands/cmd_let.s @@ -9,6 +9,7 @@ cmd_let: // Fetch variable name, should be followed by assign operator jsr fetch_variable + bcs_16 do_SYNTAX_error jsr injest_assign bcs_16 do_SYNTAX_error @@ -148,15 +149,35 @@ cmd_let_assign_string: // First special case - check if the new string has size 0 + lda DSCPNT+0 + bne cmd_let_assign_string_not_empty + + // XXX free old string data + + // Set the new variable as size 0 + +#if CONFIG_MEMORY_MODEL_60K + // XXX + // XXX: implement this + // XXX + +#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K + + +#endif + + rts + +cmd_let_assign_string_not_empty: // Check if the source and destination strings are the same (VARPNT should now point just after variable name) - lda VARPNT+1 + lda VARPNT+0 cmp __FAC1+1 bne !+ iny - lda VARPNT+2 + lda VARPNT+1 cmp __FAC1+2 bne !+ diff --git a/src/basic/engine/ad9e.frmevl.s b/src/basic/engine/ad9e.frmevl.s index c831e153..447f746d 100644 --- a/src/basic/engine/ad9e.frmevl.s +++ b/src/basic/engine/ad9e.frmevl.s @@ -68,9 +68,19 @@ FRMEVL_loop: // $7F has to be a function cmp #$80 // check for a token - bcc FRMEVL_execute_function + bcs FRMEVL_execute_function - // There are 2 possibilities left - a floating point value or a variable + // Check for a variable + +#if !HAS_OPCODES_65CE02 + jsr unconsume_character +#else + dew TXTPTR +#endif + jsr fetch_variable + bcc FRMEVL_got_value + + // There is one possibility left - a floating point value // XXX implement this part @@ -279,7 +289,7 @@ FRMEVL_push_operator_address: // as this is the place where unary operator support calls tsx - cpx #$40 // XXX is this a safe threshold? + cpx #$60 // XXX is this a safe threshold? bcc_16 do_FORMULA_TOO_COMPLEX_error // Push the operator address to stack, in a form diff --git a/src/basic/engine/fetch_variable.s b/src/basic/engine/fetch_variable.s index a452ec9e..995aaff2 100644 --- a/src/basic/engine/fetch_variable.s +++ b/src/basic/engine/fetch_variable.s @@ -2,6 +2,10 @@ // #LAYOUT# * BASIC_0 #TAKE // #LAYOUT# * * #IGNORE +// +// Carry set = failure, not recognized variable name +// + fetch_variable: @@ -14,8 +18,17 @@ fetch_variable: jsr fetch_character_skip_spaces jsr is_AZ - bcs_16 do_SYNTAX_error + bcc !+ +#if !HAS_OPCODES_65CE02 + jsr unconsume_character +#else + dew TXTPTR +#endif + + sec + rts +!: sta VARNAM+0 // Fetch the (optional) second character @@ -96,7 +109,7 @@ fetch_variable_find_addr_loop: cmp ARYTAB+1 bne !+ lda VARPNT+0 - cmp VARPNT+0 + cmp ARYTAB+0 beq fetch_variable_alocate !: // Compare current variable name with searched one @@ -151,6 +164,7 @@ fetch_variable_adjust_VARPNT: #endif + clc rts fetch_variable_find_addr_next: @@ -168,82 +182,87 @@ fetch_variable_find_addr_next: fetch_variable_alocate: - // First check if we have enough space for a new descriptor + // First check if we have enough space for a new descriptor (if FRETOP - STREND >= 7) -#if CONFIG_MEMORY_MODEL_60K - - // XXX - // XXX: implement this - // XXX + sec + lda FRETOP+0 + sbc STREND+0 + pha + lda FRETOP+1 + sbc STREND+1 + bne !+ // branch if high byte of result > 0 -#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K - // XXX consider optimized version without multiple JSRs + pla + cmp #$07 + bcs fetch_variable_alocate_space_OK - // XXX - // XXX: implement this - // XXX + jmp do_OUT_OF_MEMORY_error +!: + pla -#else // CONFIG_MEMORY_MODEL_38K + // FALLTROUGH - // XXX - // XXX: implement this - // XXX - -#endif +fetch_variable_alocate_space_OK: // If needed, move all the arrays up #if CONFIG_MEMORY_MODEL_60K // XXX - // XXX: implement this + // XXX: implement this for arrays // XXX #elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K // XXX consider optimized version without multiple JSRs // XXX - // XXX: implement this + // XXX: implement this for arrays // XXX #else // CONFIG_MEMORY_MODEL_38K // XXX - // XXX: implement this + // XXX: implement this for arrays // XXX #endif - // Set pointer to new variable + // Adjust ARYTAB and STREND -#if CONFIG_MEMORY_MODEL_60K - - // XXX - // XXX: implement this - // XXX + clc + lda STREND+0 + adc #$07 + sta STREND+0 + bcc !+ + inc STREND+1 +!: -#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K - // XXX consider optimized version without multiple JSRs - - // XXX - // XXX: implement this - // XXX - -#else // CONFIG_MEMORY_MODEL_38K - - // XXX - // XXX: implement this - // XXX - -#endif + clc + lda ARYTAB+0 + adc #$07 + sta ARYTAB+0 + bcc !+ + inc ARYTAB+1 +!: + // VARPNT already points to the start of the variable descriptor // Fill-in the new variable name, descriptor (it is enough to zero first 2 bytes of content) ldy #$00 #if CONFIG_MEMORY_MODEL_60K - - // XXX + + ldx #