diff --git a/src/basic/basic_commands/cmd_run_goto.s b/src/basic/basic_commands/cmd_run_goto.s index a2f0bb10..4ef839a0 100644 --- a/src/basic/basic_commands/cmd_run_goto.s +++ b/src/basic/basic_commands/cmd_run_goto.s @@ -24,6 +24,7 @@ cmd_goto: bcs !+ jsr fetch_line_number + bcs_16 do_SYNTAX_error jsr find_line bcc !+ // Line does not exist, so report error diff --git a/src/basic/basic_commands/cmd_sys.s b/src/basic/basic_commands/cmd_sys.s index 258e1c25..fc326360 100644 --- a/src/basic/basic_commands/cmd_sys.s +++ b/src/basic/basic_commands/cmd_sys.s @@ -41,7 +41,9 @@ cmd_sys_hack_not_needed: // XXX End of hack // - jsr fetch_line_number + lda #IDX__EV2_0B // 'SYNTAX ERROR' + jsr fetch_uint16 + bcs_16 do_SYNTAX_error cmd_sys_setup_call: lda #$4C // JMP opcode diff --git a/src/basic/basic_commands_CC/helper_bload_fetch_address.s b/src/basic/basic_commands_CC/helper_bload_fetch_address.s index a470e974..e4a28e6d 100644 --- a/src/basic/basic_commands_CC/helper_bload_fetch_address.s +++ b/src/basic/basic_commands_CC/helper_bload_fetch_address.s @@ -12,7 +12,9 @@ helper_bload_fetch_address: jsr injest_comma bcs_16 do_SYNTAX_error - jsr fetch_line_number // XXX detect errors here + lda #IDX__EV2_0B // 'SYNTAX ERROR' + jsr fetch_uint16 + bcs_16 do_SYNTAX_error ldx LINNUM+0 ldy LINNUM+1 diff --git a/src/basic/engine/fetch_line_number.s b/src/basic/engine/fetch_line_number.s index 21e998fa..2078f296 100644 --- a/src/basic/engine/fetch_line_number.s +++ b/src/basic/engine/fetch_line_number.s @@ -3,97 +3,19 @@ // #LAYOUT# * * #IGNORE // -// Fetches line number, stores it in LINNUM, sets Carry to indicate failure (not a number), prints SYNTAX ERROR if above 65535 +// Fetches line number, stores it in LINNUM, sets Carry to indicate failure (not a number) // // Preserves both .X and .Y // fetch_line_number: - // Fetch the first character (skip spaces), check if 0-9 - - jsr fetch_character - cmp #$20 - beq fetch_line_number - - jsr convert_PETSCII_to_digit - bcs fetch_line_number_rts - - // First character seems to be correct - store it - - sta LINNUM+0 - lda #$00 - sta LINNUM+1 - - // FALLTROUGH - -fetch_line_number_loop: - - // Try to fetch another digit - - jsr fetch_character - jsr convert_PETSCII_to_digit - bcs fetch_line_number_end - - // We got another digit - store it - - pha - - // Multiply current LINNUM by 10 (x * 10 = (x * 2) + (x * 2) * 4) - - jsr fetch_line_number_mul_LINNUM_2 + lda #IDX__EV7_26 // 'LINE NUMBER TOO LARGE' + jsr fetch_uint16 + bcs_16 do_SYNTAX_error lda LINNUM+1 - pha - lda LINNUM+0 - pha - - jsr fetch_line_number_mul_LINNUM_2 - jsr fetch_line_number_mul_LINNUM_2 - - clc - pla - adc LINNUM+0 - sta LINNUM+0 - pla - adc LINNUM+1 - sta LINNUM+1 - bcs_16 do_SYNTAX_error - - // Add the new digit to LINNUM - - pla - clc - adc LINNUM+0 - sta LINNUM+0 - lda LINNUM+1 - adc #$00 - sta LINNUM+1 - bcs_16 do_SYNTAX_error - - // Next iteration - -#if HAS_OPCODES_65C02 - bra fetch_line_number_loop -#else - jmp fetch_line_number_loop -#endif - -fetch_line_number_end: - - jsr unconsume_character - clc - - // FALLTROUGH - -fetch_line_number_rts: - - rts - -fetch_line_number_mul_LINNUM_2: - - asl LINNUM+0 - rol LINNUM+1 - bcs_16 do_SYNTAX_error + cmp #$FF + beq_16 do_LINE_NUMBER_TOO_LARGE_error rts diff --git a/src/basic/engine/fetch_uint16.s b/src/basic/engine/fetch_uint16.s new file mode 100644 index 00000000..d6bd568a --- /dev/null +++ b/src/basic/engine/fetch_uint16.s @@ -0,0 +1,126 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Fetches unsigned 16-bit integer, stores it in LINNUM, sets Carry to indicate failure (not a number) +// +// If value above 65535, error depends on .A opn entry +// +// Preserves both .X and .Y +// + +fetch_uint16: + + // Push the error code to stack + + pha + + // Fetch the first character (skip spaces), check if 0-9 + + jsr fetch_character + cmp #$20 + beq fetch_uint16 + + jsr convert_PETSCII_to_digit + bcs fetch_uint16_rts + + // First character seems to be correct - store it + + sta LINNUM+0 + lda #$00 + sta LINNUM+1 + + // FALLTROUGH + +fetch_uint16_loop: + + // Try to fetch another digit + + jsr fetch_character + jsr convert_PETSCII_to_digit + bcs fetch_uint16_end + + // We got another digit - store it + + pha + + // Multiply current LINNUM by 10 (x * 10 = (x * 2) + (x * 2) * 4) + + jsr fetch_uint16_mul_LINNUM_2 + bcs fetch_uint16_1PLA_error + + lda LINNUM+1 + pha + lda LINNUM+0 + pha + + jsr fetch_uint16_mul_LINNUM_2 + bcs fetch_uint16_3PLA_error + jsr fetch_uint16_mul_LINNUM_2 + bcs fetch_uint16_3PLA_error + + clc + pla + adc LINNUM+0 + sta LINNUM+0 + pla + adc LINNUM+1 + sta LINNUM+1 + bcs fetch_uint16_1PLA_error + + // Add the new digit to LINNUM + + pla + clc + adc LINNUM+0 + sta LINNUM+0 + lda LINNUM+1 + adc #$00 + sta LINNUM+1 + bcs fetch_uint16_error + + // Next iteration + +#if HAS_OPCODES_65C02 + bra fetch_uint16_loop +#else + jmp fetch_uint16_loop +#endif + +fetch_uint16_end: + + jsr unconsume_character + clc + + // FALLTROUGH + +fetch_uint16_rts: + + pla + rts + +fetch_uint16_mul_LINNUM_2: + + asl LINNUM+0 + rol LINNUM+1 + + rts + +fetch_uint16_3PLA_error: + + pla + pla + + // FALLTROUGH + +fetch_uint16_1PLA_error: + + pla + + // FALLTROUGH + +fetch_uint16_error: + + plx_trash_a + jmp do_basic_error diff --git a/src/basic/engine/fetch_uint8.s b/src/basic/engine/fetch_uint8.s index 3d92fa6b..2660ea0f 100644 --- a/src/basic/engine/fetch_uint8.s +++ b/src/basic/engine/fetch_uint8.s @@ -17,7 +17,9 @@ fetch_coma_uint8: fetch_uint8: jsr injest_spaces - jsr fetch_line_number // XXX detect errors here + lda #IDX__EV2_0E // 'ILLEGAL QUANTITY ERROR' + jsr fetch_uint16 + bcs !+ lda LINNUM+1 bne_16 do_ILLEGAL_QUANTITY_error lda LINNUM+0 diff --git a/src/basic/wedge/wedge_dos.s b/src/basic/wedge/wedge_dos.s index 6e587554..5a9eea52 100644 --- a/src/basic/wedge/wedge_dos.s +++ b/src/basic/wedge/wedge_dos.s @@ -83,13 +83,7 @@ wedge_dos_command: wedge_dos_change_drive: - // Reuse the line number parser for device number retrieval - jsr fetch_line_number - lda LINNUM+1 - beq !+ - jmp do_ILLEGAL_QUANTITY_error -!: - lda LINNUM+0 + jsr fetch_uint8 cmp #$08 bpl !+ bcs !+ diff --git a/tools/generate_strings.cc b/tools/generate_strings.cc index 62075488..c7b83226 100644 --- a/tools/generate_strings.cc +++ b/tools/generate_strings.cc @@ -298,7 +298,7 @@ const StringEntryList GLOBAL_Errors = { ListType::STRINGS_BASIC, "errors", { false, false, false, false, "EV7_23", "NO GRAPHICS AREA" }, // not used for now { false, false, false, false, "EV7_24", "BAD DISK" }, // not used for now { false, false, false, false, "EV7_25", "BEND NOT FOUND" }, // not used for now - { false, false, false, false, "EV7_26", "LINE NUMBER TOO LARGE" }, // not used for now + { true, true, true, true, "EV7_26", "LINE NUMBER TOO LARGE" }, { false, false, false, false, "EV7_27", "UNRESOLVED REFERENCE" }, // not used for now { true, true, true, true, "EV7_28", "NOT IMPLEMENTED" }, // this message actually differs from the CBM one { false, false, false, false, "EV7_29", "FILE READ" }, // not used for now