diff --git a/src/basic/basic_commands/cmd_run_goto.s b/src/basic/basic_commands/cmd_run_goto.s index c5e88994..4f181c7a 100644 --- a/src/basic/basic_commands/cmd_run_goto.s +++ b/src/basic/basic_commands/cmd_run_goto.s @@ -6,32 +6,83 @@ cmd_run: // RUN clears all variables + jsr do_clr -cmd_goto: + // Initialize OLDTXT pointer, disable Kernal messages - // XXX optimize this: deduplicate last part (and init_oldtxt) with load/verify, - // if line number greater than current line - find line backwards - - // Disable Kernal messages + jsr init_oldtxt lda #$00 jsr JSETMSG - // Reset line pointer to first line of program. - jsr init_oldtxt + // Check if we have any paramenters jsr is_end_of_statement - bcs !+ + bcs cmd_run_goto_launch + + // FALLTROUGH + +cmd_goto: + + // GOTO requires line number jsr fetch_line_number bcs_16 do_SYNTAX_error - jsr find_line - bcc !+ - // Line does not exist, so report error - jmp do_UNDEFD_STATEMENT_error + + // Check for direct mode + + lda CURLIN+1 + bmi cmd_goto_direct + + // Not a direct mode - compare desired line number (LINNUM) with the current one (CURLIN) + + lda LINNUM+1 + cmp CURLIN+1 + bne !+ + lda LINNUM+0 + cmp CURLIN+0 !: + // If desired line number is lower - search line number from start + + bcc cmd_goto_from_start + + // Else - search from the current line + + jsr find_line_from_current + +#if HAS_OPCODES_65C02 + bra cmd_goto_check +#else + jmp cmd_goto_check +#endif + +cmd_goto_direct: + + // Disable Kernal messages + + lda #$00 + jsr JSETMSG + + // FALLTROUGH + +cmd_goto_from_start: + + // Direct mode - find the line from the beginning + + jsr find_line_from_start + + // FALLTROUGH + +cmd_goto_check: + + bcs_16 do_UNDEFD_STATEMENT_error + + // FALLTROUGH + +cmd_run_goto_launch: + // Run it! - + pha pha jmp execute_line diff --git a/src/basic/editor/find_line.s b/src/basic/editor/find_line.s index 47569971..9487e432 100644 --- a/src/basic/editor/find_line.s +++ b/src/basic/editor/find_line.s @@ -3,23 +3,17 @@ // #LAYOUT# * * #IGNORE -// Find the BASIC line with number LINNUM - -// XXX it should be possible to start from the current line (OLDTXT), or from the startup, -// depending on the current and target line number +// Find the BASIC line with number in LINNUM -find_line: +find_line_from_start: // Get pointer to start of BASIC text - lda TXTTAB+0 - sta OLDTXT+0 - lda TXTTAB+1 - sta OLDTXT+1 + jsr init_oldtxt // FALLTROUGH -find_line_loop: +find_line_from_current: // Check if line is not empty @@ -100,9 +94,9 @@ find_line_next: sta OLDTXT+0 #if HAS_OPCODES_65C02 - bra find_line_loop + bra find_line_from_current #else - jmp find_line_loop + jmp find_line_from_current #endif find_line_fail: diff --git a/src/basic/editor/insert_line.s b/src/basic/editor/insert_line.s index 790f9c58..a0a5bfc4 100644 --- a/src/basic/editor/insert_line.s +++ b/src/basic/editor/insert_line.s @@ -13,7 +13,7 @@ insert_line: - // ASSUMES find_line has been called to set the insert point. + // ASSUMES find_line_from_start has been called to set the insert point. // jsr printf // .text "INSERTING LINE AT $" diff --git a/src/basic/editor/shell.s b/src/basic/editor/shell.s index 3634e177..edc127b4 100644 --- a/src/basic/editor/shell.s +++ b/src/basic/editor/shell.s @@ -169,12 +169,12 @@ shell_add_delete_line: jsr update_VARTAB_do_clr // Check if line already present - jsr find_line + jsr find_line_from_start bcs !+ // Line already present - delete it jsr delete_line - jsr find_line // refresh OLDTXT + jsr find_line_from_start // refresh OLDTXT !: // Insert new line if non-zero length, i.e., that // we are not just deleting the line.