From 44493d40cbbf6ad2a33b3fdb3545641d44359e0c Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Fri, 10 Jul 2020 17:01:04 +0200 Subject: [PATCH] started work on LET command --- src/aliases/,aliases_ram_lowmem.s | 2 +- src/basic/basic_commands/cmd__unimplemented.s | 2 - src/basic/basic_commands/cmd_let.s | 17 ++++ src/basic/engine/execute_line_statements.s | 23 ++--- src/basic/engine/fetch_variable.s | 84 +++++++++++++++++++ src/basic/engine/fetch_variable_is_09_AZ.s | 35 ++++++++ src/basic/engine/injest_assign.s | 27 ++++++ 7 files changed, 176 insertions(+), 14 deletions(-) create mode 100644 src/basic/basic_commands/cmd_let.s create mode 100644 src/basic/engine/fetch_variable.s create mode 100644 src/basic/engine/fetch_variable_is_09_AZ.s create mode 100644 src/basic/engine/injest_assign.s diff --git a/src/aliases/,aliases_ram_lowmem.s b/src/aliases/,aliases_ram_lowmem.s index 6468f572..5cdbda36 100644 --- a/src/aliases/,aliases_ram_lowmem.s +++ b/src/aliases/,aliases_ram_lowmem.s @@ -46,7 +46,7 @@ .label DATLIN = $3F // $3F-$40 -- NOT IMPLEMENTED -- .label DATPTR = $41 // $41-$42 pointer for READ/DATA copmmands .label INPPTR = $43 // $43-$44 -- NOT IMPLEMENTED -- - .label VARNAM = $45 // $45-$46 -- NOT IMPLEMENTED -- + .label VARNAM = $45 // $45-$46 current variable name .label VARPNT = $47 // $47-$48 -- NOT IMPLEMENTED -- .label FORPNT = $49 // $49-$4A -- NOT IMPLEMENTED -- .label OPPTR = $4B // $4B-$4C helper variable for expression computation, [!] our usage details are different diff --git a/src/basic/basic_commands/cmd__unimplemented.s b/src/basic/basic_commands/cmd__unimplemented.s index 6495feb6..ffa3d866 100644 --- a/src/basic/basic_commands/cmd__unimplemented.s +++ b/src/basic/basic_commands/cmd__unimplemented.s @@ -23,8 +23,6 @@ cmd_dim: nop cmd_read: nop -cmd_let: - nop cmd_if: nop cmd_gosub: diff --git a/src/basic/basic_commands/cmd_let.s b/src/basic/basic_commands/cmd_let.s new file mode 100644 index 00000000..7150e9af --- /dev/null +++ b/src/basic/basic_commands/cmd_let.s @@ -0,0 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + + +cmd_let: + + // Fetch variable name, should be followed by assign operator + + jsr fetch_variable + jsr injest_assign + bcs_16 do_SYNTAX_error + + // XXX finish the implementation + + jmp do_NOT_IMPLEMENTED_error diff --git a/src/basic/engine/execute_line_statements.s b/src/basic/engine/execute_line_statements.s index fa8a23be..e63e952c 100644 --- a/src/basic/engine/execute_line_statements.s +++ b/src/basic/engine/execute_line_statements.s @@ -37,22 +37,22 @@ execute_statements: ldx #$19 stx TEMPPT - // Check if token is valid for execution - - cmp #$7F - bcc_16 execute_statements_var_assign // not a token - try variable assign - // Move token code to .X tax - // A token - first push the 'end_of_statement' address for RTS + // Push the 'end_of_statement' address for RTS lda #>(end_of_statement - 1) pha lda #<(end_of_statement - 1) pha + // Check if token is valid for execution + + cpx #$7F + bcc_16 execute_statements_var_assign // not a token - try variable assign + cpx #$A6 bcs execute_statements_extended @@ -243,17 +243,18 @@ execute_line: execute_statements_var_assign: - // XXX here we should handle variable assignments, probably in a separate file - // Prevent wedges from being executed within a program #if CONFIG_TAPE_WEDGE - cmp #$40 + cpx #$40 beq_16 do_DIRECT_MODE_ONLY_error #endif #if CONFIG_DOS_WEDGE - cmp #$5F + cpx #$5F beq_16 do_DIRECT_MODE_ONLY_error #endif - jmp do_SYNTAX_error + // Try variable assignment - execute as LET command + + jsr unconsume_character + jmp cmd_let diff --git a/src/basic/engine/fetch_variable.s b/src/basic/engine/fetch_variable.s new file mode 100644 index 00000000..ce3e2430 --- /dev/null +++ b/src/basic/engine/fetch_variable.s @@ -0,0 +1,84 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +fetch_variable: + + // Fetch variable name + + lda #$00 + sta VARNAM+1 + + // Fetch the first character +!: + jsr fetch_character + cmp #$20 // ignore all the spaces + beq !- + + jsr fetch_variable_is_AZ + bcs_16 do_SYNTAX_error + + sta VARNAM+0 + + // Fetch the (optional) second character + + jsr fetch_character + jsr fetch_variable_is_09_AZ + bcs fetch_variable_check_type + + sta VARNAM+1 + + // Fetch the remaining variable characters - ignore them +!: + jsr fetch_character + jsr fetch_variable_is_09_AZ + bcc !- + + // FALLTROUGH + +fetch_variable_check_type: + + // Encode variable type within name, as documented in: + // - https://sites.google.com/site/h2obsession/CBM/basic/variable-format + + cmp #$24 // '$' + beq fetch_variable_type_string + cmp #$25 // '%' + beq fetch_variable_type_integer + + // FALLTORUGH + +fetch_variable_type_float: + + jsr unconsume_character + +#if HAS_OPCODES_65C02 + bra fetch_variable_find_addr +#else + jmp fetch_variable_find_addr +#endif + +fetch_variable_type_integer: + + lda VARNAM+0 + ora #$80 + sta VARNAM+0 + + // FALLTROUGH + +fetch_variable_type_string: + + lda VARNAM+1 + ora #$80 + sta VARNAM+1 + + // FALLTROUGH + +fetch_variable_find_addr: + + // Now try to find variable address + + // XXX + + rts diff --git a/src/basic/engine/fetch_variable_is_09_AZ.s b/src/basic/engine/fetch_variable_is_09_AZ.s new file mode 100644 index 00000000..9c1b1188 --- /dev/null +++ b/src/basic/engine/fetch_variable_is_09_AZ.s @@ -0,0 +1,35 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Check .A content, if within 0-9, A-Z ranges, sets Carry if check fails +// + +fetch_variable_is_09_AZ: + + cmp #$41 // fail if below '0' + bcc fetch_variable_cmp_fail + + cmp #$3A // continue checking if above '9' + bcc fetch_variable_cmp_rts + + // FALLTROUGH + +fetch_variable_is_AZ: + + cmp #$41 // fail if below 'A' + bcc fetch_variable_cmp_fail + + cmp #$7B // fail if above 'Z' + + // FALLTROUGH + +fetch_variable_cmp_rts: + + rts + +fetch_variable_cmp_fail: + + sec + rts diff --git a/src/basic/engine/injest_assign.s b/src/basic/engine/injest_assign.s new file mode 100644 index 00000000..c07898a7 --- /dev/null +++ b/src/basic/engine/injest_assign.s @@ -0,0 +1,27 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Consummes assign operator in a BASIC code, Carry set if not found. Injests all spaces. +// + + +injest_assign: + + jsr fetch_character + cmp #$B2 // assign operator character + beq injest_assign_found + cmp #$20 // space, can always be skipped + beq injest_assign + + // Not found + jsr unconsume_character + + sec + rts + +injest_assign_found: + + clc + rts