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/board_m65 \
src/basic/board_x16 \
src/basic/editor \
src/basic/engine \
src/basic/init \
src/basic/math \
@@ -28,7 +29,6 @@ SRCDIR_BASIC = $(SRCDIR_COMMON) \
src/basic/memory \
src/basic/print \
src/basic/rom_revision \
src/basic/tokenizer \
src/basic/wedge
SRCDIR_KERNAL = $(SRCDIR_COMMON) \
+1 -1
View File
@@ -31,7 +31,7 @@ list_loop:
// LIST terminates any running program,
// because it has fiddled with the current line pointer.
// (Confirmed by testing on a C64)
jmp basic_main_loop
jmp shell_main_loop
list_more_lines:
lda STKEY
+1 -1
View File
@@ -80,4 +80,4 @@ cmd_load_no_error:
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)
jmp basic_main_loop
jmp shell_main_loop
+1 -1
View File
@@ -18,7 +18,7 @@ cmd_goto:
bcs !+
jsr basic_parse_line_number
jsr basic_find_line
jsr find_line
bcc !+
// Line does not exist, so report error
jmp do_UNDEFD_STATEMENT_error
+1 -1
View File
@@ -27,4 +27,4 @@ cmd_stop:
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
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
jmp basic_main_loop
jmp shell_main_loop
+1 -1
View File
@@ -3,7 +3,7 @@
// #LAYOUT# * * #IGNORE
// 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.
// 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
@@ -5,19 +5,24 @@
// 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
lda TXTTAB+0
sta OLDTXT+0
lda TXTTAB+1
sta OLDTXT+1
basic_find_line_loop:
// Then search for line number
// Line number
ldy #3
// FALLTROUGH
find_line_loop:
// Fetch the high byte of line number and compare
ldy #$03
#if CONFIG_MEMORY_MODEL_60K
ldx #<OLDTXT+0
@@ -30,10 +35,11 @@ basic_find_line_loop:
cmp LINNUM+1
beq !+
bcs line_num_too_high
bne not_this_line
bcs find_line_fail // branch if line number too high
bne find_line_next
!:
// Fetch the low byte of line number and compare
dey
#if CONFIG_MEMORY_MODEL_60K
@@ -45,27 +51,23 @@ basic_find_line_loop:
#endif
cmp LINNUM+0
beq !+
bcs line_num_too_high
bne not_this_line
!:
beq find_line_success
bcs find_line_fail // branch if line number too high
bne find_line_next
find_line_success:
clc
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
bcs more_lines_exist
bcc find_line_fail // branch in no more lines exist
// no more lines exist, return failure
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
ldy #$00
#if CONFIG_MEMORY_MODEL_60K
ldx #<OLDTXT+0
@@ -76,7 +78,7 @@ more_lines_exist:
lda (OLDTXT),y
#endif
sta $0100
pha
iny
#if CONFIG_MEMORY_MODEL_60K
@@ -88,7 +90,16 @@ more_lines_exist:
#endif
sta OLDTXT+1
lda $0100
pla
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
basic_main_loop:
shell_main_loop:
// Tell user we are ready
ldx #IDX__STR_READY
@@ -13,87 +13,104 @@ basic_main_loop:
lda #$80
jsr JSETMSG
basic_read_next_line:
shell_read_next_line:
// Read a line of input
ldx #$00
read_line_loop:
!:
jsr JCHRIN
bcs read_line_loop
bcs !-
cmp #$0d
beq got_line_of_input
// Check for RETURN key
cmp #$0D
beq shell_got_line
// Not carriage return, so try to append to line so far
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
inx
jmp read_line_loop
jmp !-
got_line_of_input:
shell_got_line:
// Store length of input buffer ready for tokenising
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
remove_leading_spaces:
lda BUF
cmp #$20
bne !+
ldx #1
rsl_l1:
bne shell_process_line // branch if no more leading spaces
// We have a leading space - strip it away
ldx #$01
!:
lda BUF,x
sta BUF-1,x
inx
cpx __tokenise_work1
bne rsl_l1
bne !-
// Reduce length of input by one
dec __tokenise_work1
// Stop trying to rim if we run out of input
bne remove_leading_spaces
!:
// Do printing of the new line
bne shell_strip_leading_spaces
// FALLTROUGH
shell_process_line:
// Print a new line
jsr print_return
// Ignore empty lines
lda __tokenise_work1
beq basic_read_next_line
beq shell_read_next_line
// Check if a wedge should take over
#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
lda BUF
#if CONFIG_DOS_WEDGE
cmp #$40 // '@'
beq_16 wedge_dos
#endif
#if CONFIG_TAPE_WEDGE
cmp #$5F // left arrow
beq_16 wedge_tape
#endif
#endif
// Else, tokenise the line
// Tokenise the line
jsr tokenise_line
// Has the user entered a line of BASIC beginning with a number?
lda BUF
cmp #$30
bcc not_a_line
bcc shell_execute_line
cmp #$39
bcs not_a_line
bcs shell_execute_line
// Yes, the line begins with a number.
// Parse the line number and check validity
// Yes, the line begins with a number - parse it 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.
lda __tokenise_work1
sta __tokenise_work2
@@ -112,26 +129,30 @@ rsl_l1:
lda TXTPTR+0
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
ldx __tokenise_work1
skip_spaces:
!:
lda BUF,x
cmp #$20
bne !+
inx
bne skip_spaces
!: stx __tokenise_work1
bne !-
!:
stx __tokenise_work1
// First, clear all variables, so that we only have to shove BASIC text around.
// (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
// memory free, or else it would auto CLR when you ran out of program space).
// FALLTROUGH
shell_add_delete_line:
// First, clear all variables, so that we only have to shove BASIC text around
jsr basic_do_clr
.break
// Delete line if present
jsr basic_find_line
jsr find_line
// XXX
bcs !+
@@ -147,11 +168,10 @@ skip_spaces:
jsr basic_insert_line
!:
// 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
lda #<BUF
@@ -165,8 +185,7 @@ not_a_line:
sta OLDTXT+1
// Put invalid line number in current line number value,
// so that we know we are in direct mode
// (Computes Mapping the 64 p19)
// so that we know we are in direct mode (Computes Mapping the 64 p19)
lda #$FF
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
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
inx
beq_16 basic_main_loop
beq_16 shell_main_loop
// Advance to the next line - first copy the line number
// to previous line number
@@ -181,7 +181,7 @@ execute_statements_end_of_line:
lda OLDTXT+0
ora OLDTXT+1
beq_16 basic_main_loop
beq_16 shell_main_loop
// FALLTROUGH
@@ -191,7 +191,7 @@ execute_line:
ldy #0
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
+1 -1
View File
@@ -27,4 +27,4 @@ basic_warm_start_real:
lda CMP0+0
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
!:
sta FA
jmp basic_main_loop
jmp shell_main_loop
wedge_dos_status_get:
@@ -238,7 +238,7 @@ wedge_dos_directory_display:
wedge_dos_clean_exit:
jsr JCLALL
jmp basic_main_loop
jmp shell_main_loop
wedge_dos_basic_error:
pha