improved error handling in BASIC

This commit is contained in:
FeralChild64 committed 2020-07-12 11:04:45 +02:00
1 parent d1ac8ac371
commit 8b629816d7
8 files changed
+144 -95

No files matched your search

+1
View File
@@ -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
+3 -1
View File
@@ -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
@@ -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
+6 -84
View File
@@ -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
+126
View File
@@ -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
+3 -1
View File
@@ -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
+1 -7
View File
@@ -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 !+