diff --git a/src/basic/basic_commands/cmd_let.s b/src/basic/basic_commands/cmd_let.s index 880893d8..02c811ae 100644 --- a/src/basic/basic_commands/cmd_let.s +++ b/src/basic/basic_commands/cmd_let.s @@ -171,12 +171,10 @@ cmd_let_assign_string: lda __FAC1+0 bne cmd_let_assign_string_not_empty - // Yes, it is empty - check if the old one is, free it if necessary + // Yes, it is empty - free the old one - lda DSCPNT+0 - bne !+ jsr varstr_free -!: + // Set the new variable as empty string ldy #$00 @@ -276,9 +274,7 @@ cmd_let_assign_string_not_text_area: // No special case optimization is possible // Free the memory belonging to the old string - // XXX - // jsr varstr_free - + jsr varstr_free // And allocate memory for the new string diff --git a/src/basic/engine/varstr_cmp_fretop.s b/src/basic/engine/varstr_cmp_fretop.s new file mode 100644 index 00000000..fda23d4e --- /dev/null +++ b/src/basic/engine/varstr_cmp_fretop.s @@ -0,0 +1,23 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Check string address (DSCPNT+1/+2) vs FRETOP +// +// Output: +// - Zero flag set - this is the first variable of the string area +// - Carry flag set - this string belongs to the string area + + +varstr_cmp_fretop: + + lda DSCPNT+2 + cmp FRETOP+1 + beq !+ + rts +!: + lda DSCPNT+2 + cmp FRETOP+1 + rts + diff --git a/src/basic/engine/varstr_free.s b/src/basic/engine/varstr_free.s index a2705e8d..e9a30778 100644 --- a/src/basic/engine/varstr_free.s +++ b/src/basic/engine/varstr_free.s @@ -6,27 +6,32 @@ // Releases back memory used by string // // Input: +// - DSCPNT+0 - string size // - DSCPNT+1, DSCPNT+2 - pointer to string // // XXX test this routine -// XXX check if this entry point is needed varstr_free: - // XXX consider moving size check (DSCPNT+0) here + // Check the string size - do not do anything if 0 - // XXX - // XXX check if string is located above FRETOP, handle case if it is not - // XXX + lda DSCPNT+0 + bne !+ + rts +!: + // Check if string is above FRETOP (in string area) - // Quick check - is the string the lowest one? + jsr varstr_cmp_fretop + bcs !+ + + // No, it does not belong to string area - quit + + rts +!: + // Check if this is the lowest string - cmp FRETOP+0 - bne varstr_free_inside - lda DSCPNT+2 - cmp FRETOP+1 bne varstr_free_inside // This is the lowest string - so just increase FRETOP, this way