some cleanup, BASIC line finding now properly uses stack

This commit is contained in:
FeralChild64 committed 2020-06-28 04:06:04 +02:00
1 parent bd9211e1ea
commit 5db25db3b5
20 files changed
+116 -86

No files matched your search

+1 -1
View File
@@ -20,6 +20,7 @@ SRCDIR_BASIC = $(SRCDIR_COMMON) \
src/basic/basic_functions \ src/basic/basic_functions \
src/basic/board_m65 \ src/basic/board_m65 \
src/basic/board_x16 \ src/basic/board_x16 \
src/basic/editor \
src/basic/engine \ src/basic/engine \
src/basic/init \ src/basic/init \
src/basic/math \ src/basic/math \
@@ -28,7 +29,6 @@ SRCDIR_BASIC = $(SRCDIR_COMMON) \
src/basic/memory \ src/basic/memory \
src/basic/print \ src/basic/print \
src/basic/rom_revision \ src/basic/rom_revision \
src/basic/tokenizer \
src/basic/wedge src/basic/wedge
SRCDIR_KERNAL = $(SRCDIR_COMMON) \ SRCDIR_KERNAL = $(SRCDIR_COMMON) \
+1 -1
View File
@@ -31,7 +31,7 @@ list_loop:
// LIST terminates any running program, // LIST terminates any running program,
// because it has fiddled with the current line pointer. // because it has fiddled with the current line pointer.
// (Confirmed by testing on a C64) // (Confirmed by testing on a C64)
jmp basic_main_loop jmp shell_main_loop
list_more_lines: list_more_lines:
lda STKEY lda STKEY
+1 -1
View File
@@ -80,4 +80,4 @@ cmd_load_no_error:
cmd_load_end: cmd_load_end:
jmp basic_main_loop jmp shell_main_loop
+1 -1
View File
@@ -9,4 +9,4 @@ cmd_new:
// NEW command terminates execution (confirmed on a C64) // NEW command terminates execution (confirmed on a C64)
jmp basic_main_loop jmp shell_main_loop
+1 -1
View File
@@ -18,7 +18,7 @@ cmd_goto:
bcs !+ bcs !+
jsr basic_parse_line_number jsr basic_parse_line_number
jsr basic_find_line jsr find_line
bcc !+ bcc !+
// Line does not exist, so report error // Line does not exist, so report error
jmp do_UNDEFD_STATEMENT_error jmp do_UNDEFD_STATEMENT_error
+1 -1
View File
@@ -27,4 +27,4 @@ cmd_stop:
cmd_end: cmd_end:
jmp basic_main_loop jmp shell_main_loop
@@ -39,4 +39,4 @@ cmd_bload:
// XXX when number parsing is done, change to continue execution // XXX when number parsing is done, change to continue execution
jmp basic_main_loop jmp shell_main_loop
+1 -1
View File
@@ -50,4 +50,4 @@ cmd_merge_no_error:
// XXX when number parsing is done, change to continue execution // XXX when number parsing is done, change to continue execution
jmp basic_main_loop jmp shell_main_loop
+1 -1
View File
@@ -3,7 +3,7 @@
// #LAYOUT# * * #IGNORE // #LAYOUT# * * #IGNORE
// Delete the current BASIC line, which is assumed to have already // Delete the current BASIC line, which is assumed to have already
// been found with basic_find_line. // been found with find_line.
// Really only consists of copying memory down. // Really only consists of copying memory down.
// The only complication is that we have to do the copy with ROMs // The only complication is that we have to do the copy with ROMs
// banked out. Oh, yes, and we have to update all the links in // banked out. Oh, yes, and we have to update all the links in
@@ -5,19 +5,24 @@
// Find the BASIC line with number LINNUM // 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_line:
basic_find_line:
// Get pointer to start of BASIC text // Get pointer to start of BASIC text
lda TXTTAB+0 lda TXTTAB+0
sta OLDTXT+0 sta OLDTXT+0
lda TXTTAB+1 lda TXTTAB+1
sta OLDTXT+1 sta OLDTXT+1
basic_find_line_loop: // FALLTROUGH
// Then search for line number
// Line number find_line_loop:
ldy #3 // Fetch the high byte of line number and compare
ldy #$03
#if CONFIG_MEMORY_MODEL_60K #if CONFIG_MEMORY_MODEL_60K
ldx #<OLDTXT+0 ldx #<OLDTXT+0
@@ -30,10 +35,11 @@ basic_find_line_loop:
cmp LINNUM+1 cmp LINNUM+1
beq !+ beq !+
bcs line_num_too_high bcs find_line_fail // branch if line number too high
bne not_this_line bne find_line_next
!: !:
// Fetch the low byte of line number and compare
dey dey
#if CONFIG_MEMORY_MODEL_60K #if CONFIG_MEMORY_MODEL_60K
@@ -45,27 +51,23 @@ basic_find_line_loop:
#endif #endif
cmp LINNUM+0 cmp LINNUM+0
beq !+ beq find_line_success
bcs line_num_too_high bcs find_line_fail // branch if line number too high
bne not_this_line bne find_line_next
!:
find_line_success:
clc clc
rts rts
not_this_line:
// Not this line, so advance to next line find_line_next:
// Advance to the next line
jsr peek_line_pointer_null_check jsr peek_line_pointer_null_check
bcs more_lines_exist bcc find_line_fail // branch in no more lines exist
// no more lines exist, return failure ldy #$00
line_num_too_high:
sec
rts
more_lines_exist:
// XXX - Add program mangled check here to be triggered
// if the link goes backwards.
// Follow link to next line
ldy #0
#if CONFIG_MEMORY_MODEL_60K #if CONFIG_MEMORY_MODEL_60K
ldx #<OLDTXT+0 ldx #<OLDTXT+0
@@ -76,7 +78,7 @@ more_lines_exist:
lda (OLDTXT),y lda (OLDTXT),y
#endif #endif
sta $0100 pha
iny iny
#if CONFIG_MEMORY_MODEL_60K #if CONFIG_MEMORY_MODEL_60K
@@ -88,7 +90,16 @@ more_lines_exist:
#endif #endif
sta OLDTXT+1 sta OLDTXT+1
lda $0100 pla
sta OLDTXT+0 sta OLDTXT+0
jmp basic_find_line_loop #if HAS_OPCODES_65C02
bra find_line_loop
#else
jmp find_line_loop
#endif
find_line_fail:
sec
rts
@@ -3,7 +3,7 @@
// #LAYOUT# * * #IGNORE // #LAYOUT# * * #IGNORE
basic_main_loop: shell_main_loop:
// Tell user we are ready // Tell user we are ready
ldx #IDX__STR_READY ldx #IDX__STR_READY
@@ -13,87 +13,104 @@ basic_main_loop:
lda #$80 lda #$80
jsr JSETMSG jsr JSETMSG
basic_read_next_line: shell_read_next_line:
// Read a line of input // Read a line of input
ldx #$00 ldx #$00
read_line_loop: !:
jsr JCHRIN jsr JCHRIN
bcs read_line_loop bcs !-
cmp #$0d // Check for RETURN key
beq got_line_of_input cmp #$0D
beq shell_got_line
// Not carriage return, so try to append to line so far // Not carriage return, so try to append to line so far
cpx #80 cpx #80
bcs_16 do_STRING_TOO_LONG_error // see Computes Mapping the 64 p93 bcs_16 do_STRING_TOO_LONG_error // see Computes Mapping the 64 p93
sta BUF,x sta BUF,x
inx inx
jmp read_line_loop jmp !-
got_line_of_input: shell_got_line:
// Store length of input buffer ready for tokenising // Store length of input buffer ready for tokenising
stx __tokenise_work1 stx __tokenise_work1
// XXX we should probably store 0 at the end of used BUF
// FALLTROUGH
shell_strip_leading_spaces:
// Strip leading spaces from the line // Strip leading spaces from the line
remove_leading_spaces:
lda BUF lda BUF
cmp #$20 cmp #$20
bne !+ bne shell_process_line // branch if no more leading spaces
ldx #1
rsl_l1: // We have a leading space - strip it away
ldx #$01
!:
lda BUF,x lda BUF,x
sta BUF-1,x sta BUF-1,x
inx inx
cpx __tokenise_work1 cpx __tokenise_work1
bne rsl_l1 bne !-
// Reduce length of input by one // Reduce length of input by one
dec __tokenise_work1 dec __tokenise_work1
// Stop trying to rim if we run out of input // Stop trying to rim if we run out of input
bne remove_leading_spaces bne shell_strip_leading_spaces
!:
// Do printing of the new line // FALLTROUGH
shell_process_line:
// Print a new line
jsr print_return jsr print_return
// Ignore empty lines // Ignore empty lines
lda __tokenise_work1 lda __tokenise_work1
beq basic_read_next_line beq shell_read_next_line
// Check if a wedge should take over // Check if a wedge should take over
#if CONFIG_DOS_WEDGE || CONFIG_TAPE_WEDGE #if CONFIG_DOS_WEDGE || CONFIG_TAPE_WEDGE
ldx __tokenise_work1 // here is the size of input ldx __tokenise_work1 // size of the input, wedges need this XXX this should not be needed
// Check if DOS wedge should take over // Check if DOS wedge should take over
lda BUF lda BUF
#if CONFIG_DOS_WEDGE #if CONFIG_DOS_WEDGE
cmp #$40 // '@' cmp #$40 // '@'
beq_16 wedge_dos beq_16 wedge_dos
#endif #endif
#if CONFIG_TAPE_WEDGE #if CONFIG_TAPE_WEDGE
cmp #$5F // left arrow cmp #$5F // left arrow
beq_16 wedge_tape beq_16 wedge_tape
#endif #endif
#endif #endif
// Else, tokenise the line // Tokenise the line
jsr tokenise_line jsr tokenise_line
// Has the user entered a line of BASIC beginning with a number? // Has the user entered a line of BASIC beginning with a number?
lda BUF lda BUF
cmp #$30 cmp #$30
bcc not_a_line bcc shell_execute_line
cmp #$39 cmp #$39
bcs not_a_line bcs shell_execute_line
// Yes, the line begins with a number. // Yes, the line begins with a number - parse it and check validity
// Parse the line number and check validity
// injest_number follows __tokenise_work1 as the offset into the line, // The injest_number follows __tokenise_work1 as the offset into the line,
// so remember the line length somewhere else for now. // so remember the line length somewhere else for now.
lda __tokenise_work1 lda __tokenise_work1
sta __tokenise_work2 sta __tokenise_work2
@@ -112,26 +129,30 @@ rsl_l1:
lda TXTPTR+0 lda TXTPTR+0
sta __tokenise_work1 sta __tokenise_work1
// Got a valid line number -- so do add/del line // Got a valid line number - we will be adding/deleting a new line
// Skip any spaces after the line number // Skip any spaces after the line number
ldx __tokenise_work1 ldx __tokenise_work1
skip_spaces: !:
lda BUF,x lda BUF,x
cmp #$20 cmp #$20
bne !+ bne !+
inx inx
bne skip_spaces bne !-
!: stx __tokenise_work1 !:
stx __tokenise_work1
// First, clear all variables, so that we only have to shove BASIC text around. // FALLTROUGH
// (We could later remove this requirement, and the only effect should be
// to slow things down, and that you might have to either CLR if there is no shell_add_delete_line:
// memory free, or else it would auto CLR when you ran out of program space).
// First, clear all variables, so that we only have to shove BASIC text around
jsr basic_do_clr jsr basic_do_clr
.break
// Delete line if present // Delete line if present
jsr basic_find_line jsr find_line
// XXX
bcs !+ bcs !+
@@ -147,11 +168,10 @@ skip_spaces:
jsr basic_insert_line jsr basic_insert_line
!: !:
// No READY message after entering or deleting a line of BASIC // No READY message after entering or deleting a line of BASIC
jmp basic_read_next_line jmp shell_read_next_line
not_a_line:
// Actually interpret the line shell_execute_line:
// Setup pointer to the statement // Setup pointer to the statement
lda #<BUF lda #<BUF
@@ -165,8 +185,7 @@ not_a_line:
sta OLDTXT+1 sta OLDTXT+1
// Put invalid line number in current line number value, // Put invalid line number in current line number value,
// so that we know we are in direct mode // so that we know we are in direct mode (Computes Mapping the 64 p19)
// (Computes Mapping the 64 p19)
lda #$FF lda #$FF
sta CURLIN+1 sta CURLIN+1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1 -1
View File
@@ -196,4 +196,4 @@ do_basic_error: // error code in .X
ldx #$FE ldx #$FE
txs txs
jmp basic_main_loop jmp shell_main_loop
+3 -3
View File
@@ -164,7 +164,7 @@ execute_statements_end_of_line:
ldx CURLIN+1 ldx CURLIN+1
inx inx
beq_16 basic_main_loop beq_16 shell_main_loop
// Advance to the next line - first copy the line number // Advance to the next line - first copy the line number
// to previous line number // to previous line number
@@ -181,7 +181,7 @@ execute_statements_end_of_line:
lda OLDTXT+0 lda OLDTXT+0
ora OLDTXT+1 ora OLDTXT+1
beq_16 basic_main_loop beq_16 shell_main_loop
// FALLTROUGH // FALLTROUGH
@@ -191,7 +191,7 @@ execute_line:
ldy #0 ldy #0
jsr peek_line_pointer_null_check jsr peek_line_pointer_null_check
bcc_16 basic_main_loop // branch if end of program reached bcc_16 shell_main_loop // branch if end of program reached
// Skip pointer and line number to get address of first statement // Skip pointer and line number to get address of first statement
+1 -1
View File
@@ -27,4 +27,4 @@ basic_warm_start_real:
lda CMP0+0 lda CMP0+0
jsr print_hex_byte jsr print_hex_byte
!: !:
jmp basic_main_loop jmp shell_main_loop
+2 -2
View File
@@ -96,7 +96,7 @@ wedge_dos_change_drive:
jmp do_ILLEGAL_DEVICE_NUMBER_error jmp do_ILLEGAL_DEVICE_NUMBER_error
!: !:
sta FA sta FA
jmp basic_main_loop jmp shell_main_loop
wedge_dos_status_get: wedge_dos_status_get:
@@ -238,7 +238,7 @@ wedge_dos_directory_display:
wedge_dos_clean_exit: wedge_dos_clean_exit:
jsr JCLALL jsr JCLALL
jmp basic_main_loop jmp shell_main_loop
wedge_dos_basic_error: wedge_dos_basic_error:
pha pha