From 6b8c9ded30fff3026c299c113bf96a99d8bfe6da Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sat, 6 Jun 2020 12:57:03 +0200 Subject: [PATCH] fixes and optimizations of BASIC error reporting --- c64/basic/basic_do_error.s | 41 ----------------- c64/basic/basic_main_loop.s | 2 +- c64/basic/commands/cmd_load_verify.s | 11 +---- .../{do_basic_error.s => engine/do_error.s} | 45 ++++++++++++++----- c64/basic/engine/fetch_character.s | 11 ++++- c64/basic/wedge/wedge_dos.s | 5 +-- c64/basic/wedge/wedge_tape.s | 3 +- tools/compress_text.c | 2 +- 8 files changed, 49 insertions(+), 71 deletions(-) delete mode 100644 c64/basic/basic_do_error.s rename c64/basic/{do_basic_error.s => engine/do_error.s} (86%) diff --git a/c64/basic/basic_do_error.s b/c64/basic/basic_do_error.s deleted file mode 100644 index f4f21fd4..00000000 --- a/c64/basic/basic_do_error.s +++ /dev/null @@ -1,41 +0,0 @@ -// #LAYOUT# STD * #TAKE -// #LAYOUT# * BASIC_0 #TAKE -// #LAYOUT# * * #IGNORE - -// Computes Mapping the 64 p93 - -basic_do_error: - - // Save error number - phx_trash_a - -#if ROM_LAYOUT_M65 - // Restore normal memory map - jsr map_NORMAL -#endif - - // Print ? at start - jsr print_return - lda #$3F - jsr JCHROUT - - // Print main part of error message - plx_trash_a - jsr print_packed_message - - // Print ERROR at end - jsr print_space - ldx #33 - jsr print_packed_message - - // XXX print IN if not in direct mode - - // XXX print line number if not in direct mode - - jsr print_return - jsr print_return - - // Reset stack, and go back to main loop - ldx #$FE - txs - jmp basic_main_loop diff --git a/c64/basic/basic_main_loop.s b/c64/basic/basic_main_loop.s index 575a98e5..e0abca56 100644 --- a/c64/basic/basic_main_loop.s +++ b/c64/basic/basic_main_loop.s @@ -31,7 +31,7 @@ read_line_loop: bcc !+ // Report STRING TOO LONG error (Computes Mapping the 64 p93) ldx #22 - jmp basic_do_error + jmp do_basic_error !: sta BUF,x inx diff --git a/c64/basic/commands/cmd_load_verify.s b/c64/basic/commands/cmd_load_verify.s index ba07cfdf..5ba69324 100644 --- a/c64/basic/commands/cmd_load_verify.s +++ b/c64/basic/commands/cmd_load_verify.s @@ -61,16 +61,7 @@ cmd_load_got_params: // input for tape wedge jsr print_return pla plp - bcc cmd_load_no_error - - // .A = KERNAL error code, also almost matches BASIC error codes - - tax - dex - bpl !+ - ldx #B_ERR_BREAK -!: - jmp do_basic_error + bcs_16 do_kernal_error cmd_load_no_error: diff --git a/c64/basic/do_basic_error.s b/c64/basic/engine/do_error.s similarity index 86% rename from c64/basic/do_basic_error.s rename to c64/basic/engine/do_error.s index 6bf58362..c64ee734 100644 --- a/c64/basic/do_basic_error.s +++ b/c64/basic/engine/do_error.s @@ -32,6 +32,22 @@ // message. This compares favourably to the 3 bytes per error // message that the $2C method would result in. + +do_kernal_error: // .A = KERNAL error code, also almost matches BASIC error codes + + // Convert to BASIC error code + + tax + dex + bpl do_basic_error + + // FALLTROUGN + +do_BREAK_error: + + ldx #B_ERR_BREAK + bpl do_basic_error // branch always + do_NOT_IMPLEMENTED_error: .byte $E6 do_MEMORY_CORRUPT_error: @@ -107,7 +123,8 @@ do_FILE_OPEN_error: do_TO_MANY_FILES_error: .byte $EA - // Now get the error # and restore $E6 to its correct value + // Now get the error id and restore $E6 to its correct value + lda $E6 pha and #$80 @@ -121,39 +138,39 @@ do_TO_MANY_FILES_error: // Restore $EA to correct value in case the NOP above is used // as an argument to the preceeding INC $nn (opcode $E6). + lda $EA and #$80 sta $EA - // FALL THROUGH + // FALLTHROUGH - // Error # in X +do_basic_error: // error code in .X -do_basic_error: // "?" txa pha jsr print_return - lda #$3f + lda #$3F jsr JCHROUT pla tax - // Error message text + // Error message text + " ERROR" + jsr print_packed_message - // A space between error name and word error - jsr print_space - - // "ERROR" ldx #33 jsr print_packed_message + // Check if direct mode + lda CURLIN+1 - cmp #$ff + cmp #$FF beq !+ // We were in a program, so show IN + ldx #31 jsr print_packed_message @@ -162,10 +179,14 @@ do_basic_error: jsr print_integer !: // New lines + jsr print_return lda #$00 jsr JCHROUT - // XXX - Restore stack depth first? + // Reset stack, and go back to main loop + + ldx #$FE + txs jmp basic_main_loop diff --git a/c64/basic/engine/fetch_character.s b/c64/basic/engine/fetch_character.s index 5edb7984..ddef18b5 100644 --- a/c64/basic/engine/fetch_character.s +++ b/c64/basic/engine/fetch_character.s @@ -28,8 +28,17 @@ consume_character: // Advance basic text pointer +#if !HAS_OPCODES_65CE02 + inc TXTPTR+0 bne !+ inc TXTPTR+1 !: - rts \ No newline at end of file + +#else // HAS_OPCODES_65CE02 + + inw TXTPTR + +#endif + + rts diff --git a/c64/basic/wedge/wedge_dos.s b/c64/basic/wedge/wedge_dos.s index 7b7db2a6..ca493471 100644 --- a/c64/basic/wedge/wedge_dos.s +++ b/c64/basic/wedge/wedge_dos.s @@ -241,9 +241,8 @@ wedge_dos_clean_exit: wedge_dos_basic_error: pha jsr JCLALL - plx_trash_a - dex - jmp do_basic_error + pla + jmp do_kernal_error wedge_dos_setnam: // Now determine the length of the 'file' name diff --git a/c64/basic/wedge/wedge_tape.s b/c64/basic/wedge/wedge_tape.s index 5f5c5fac..ac89415d 100644 --- a/c64/basic/wedge/wedge_tape.s +++ b/c64/basic/wedge/wedge_tape.s @@ -58,8 +58,7 @@ wedge_arrow_H: jsr tape_head_align jsr print_return - ldx #B_ERR_BREAK - jmp do_basic_error + jmp do_BREAK_error #endif diff --git a/tools/compress_text.c b/tools/compress_text.c index 6f7b0daf..156a56db 100644 --- a/tools/compress_text.c +++ b/tools/compress_text.c @@ -162,7 +162,7 @@ char *error_list[]={ "BREAK", // #30 " IN ", // #31 "BRK AT $", // #32 - "ERROR", // #33 // Simply the word error that is attached to the other parts of messages https://fjkraan.home.xs4all.nl/comp/apple2faq/app2asoftfaq.html + " ERROR", // #33 // Simply the word error that is attached to the other parts of messages https://fjkraan.home.xs4all.nl/comp/apple2faq/app2asoftfaq.html " BASIC BYTES FREE", // #34 // https://github.com/stefanhaustein/expressionparser "MEMORY CORRUPT", // #35 "NOT IMPLEMENTED", // #36