more BASIC cleanup
This commit is contained in:
1 parent
cdeaf05ccd
commit
08f6fe9ed7
14 files changed
+142
-182
No files matched your search
@@ -1,164 +0,0 @@
|
|||||||
// #LAYOUT# STD * #TAKE
|
|
||||||
// #LAYOUT# * BASIC_0 #TAKE
|
|
||||||
// #LAYOUT# * * #IGNORE
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tries to execute the statement, and all the subsequent ones
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
basic_execute_statement:
|
|
||||||
|
|
||||||
// Check for RUN/STOP
|
|
||||||
|
|
||||||
lda STKEY
|
|
||||||
bpl_16 cmd_stop
|
|
||||||
|
|
||||||
// Skip over any white spaces and colons (':')
|
|
||||||
!:
|
|
||||||
jsr fetch_character
|
|
||||||
cmp #$20 // space, can be skipped
|
|
||||||
beq !-
|
|
||||||
cmp #$3A // colon, can be skipped
|
|
||||||
beq !-
|
|
||||||
|
|
||||||
// Check if end of the line
|
|
||||||
|
|
||||||
cmp #$00
|
|
||||||
beq basic_end_of_line
|
|
||||||
|
|
||||||
// Not end of the line - we actually have something to execute
|
|
||||||
|
|
||||||
// XXX continue rework from here
|
|
||||||
|
|
||||||
pha
|
|
||||||
jsr unconsume_character
|
|
||||||
pla
|
|
||||||
|
|
||||||
// The checks should be done in order of frequency, so that we are as
|
|
||||||
// fast as possible.
|
|
||||||
|
|
||||||
cmp #$7f
|
|
||||||
bcc not_a_token
|
|
||||||
|
|
||||||
// It is a token - consume this character
|
|
||||||
|
|
||||||
jsr consume_character
|
|
||||||
|
|
||||||
#if !HAS_OPCODES_65C02
|
|
||||||
|
|
||||||
// Get the jump table entry for it, push it on the stack, and then RTS to start it.
|
|
||||||
|
|
||||||
tax
|
|
||||||
lda command_jumptable_hi - $80, x
|
|
||||||
pha
|
|
||||||
lda command_jumptable_lo - $80, x
|
|
||||||
pha
|
|
||||||
|
|
||||||
rts
|
|
||||||
|
|
||||||
#else // HAS_OPCODES_65C02
|
|
||||||
|
|
||||||
asl
|
|
||||||
tax
|
|
||||||
jmp (command_jumptable, x)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
not_a_token:
|
|
||||||
// Space, which we can also just ignore
|
|
||||||
cmp #$20
|
|
||||||
beq basic_skip_char
|
|
||||||
// End of line?
|
|
||||||
cmp #$00
|
|
||||||
beq basic_end_of_line
|
|
||||||
// :, i.e., statement separator, which we can simply ignore
|
|
||||||
cmp #$3a
|
|
||||||
beq basic_skip_char
|
|
||||||
|
|
||||||
// If all else fails, it is a syntax error
|
|
||||||
jmp do_SYNTAX_error
|
|
||||||
|
|
||||||
basic_skip_char:
|
|
||||||
jsr consume_character
|
|
||||||
jmp basic_execute_statement
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
basic_end_of_line:
|
|
||||||
|
|
||||||
// If we reach the end are in direct mode, then
|
|
||||||
// go back to reading input, else look for the
|
|
||||||
// next line, and advance to that, or else
|
|
||||||
// return to READY prompt because we have run out
|
|
||||||
// of program.
|
|
||||||
|
|
||||||
// XXX - If not in direct mode, then advance to next line, if there is
|
|
||||||
// one.
|
|
||||||
|
|
||||||
// Are we in direct mode
|
|
||||||
lda CURLIN+1
|
|
||||||
cmp #$ff
|
|
||||||
bne basic_not_direct_mode
|
|
||||||
|
|
||||||
// Yes, we were in direct mode, so stop now
|
|
||||||
jmp basic_main_loop
|
|
||||||
|
|
||||||
basic_not_direct_mode:
|
|
||||||
// Copy line number to previous line number
|
|
||||||
lda CURLIN+0
|
|
||||||
sta OLDLIN+0
|
|
||||||
lda CURLIN+1
|
|
||||||
sta OLDLIN+1
|
|
||||||
|
|
||||||
// Advance the basic line pointer to the next line
|
|
||||||
jsr basic_follow_link_to_next_line
|
|
||||||
|
|
||||||
// Are we at the end of the program?
|
|
||||||
lda OLDTXT+0
|
|
||||||
ora OLDTXT+1
|
|
||||||
bne basic_execute_from_current_line
|
|
||||||
|
|
||||||
// End of program found
|
|
||||||
jmp basic_main_loop
|
|
||||||
|
|
||||||
basic_execute_from_current_line:
|
|
||||||
// Check if pointer is null, if so, we are at the end of
|
|
||||||
// the program.
|
|
||||||
ldy #0
|
|
||||||
jsr peek_line_pointer_null_check
|
|
||||||
bcs !+
|
|
||||||
// End of program reached
|
|
||||||
jmp basic_main_loop
|
|
||||||
!:
|
|
||||||
// Skip pointer and line number to get address of first statement
|
|
||||||
lda OLDTXT+0
|
|
||||||
clc
|
|
||||||
adc #4
|
|
||||||
sta TXTPTR+0
|
|
||||||
lda OLDTXT+1
|
|
||||||
adc #0
|
|
||||||
sta TXTPTR+1
|
|
||||||
|
|
||||||
ldy #2
|
|
||||||
|
|
||||||
#if CONFIG_MEMORY_MODEL_60K
|
|
||||||
ldx #<OLDTXT
|
|
||||||
jsr peek_under_roms
|
|
||||||
#else // CONFIG_MEMORY_MODEL_38K
|
|
||||||
lda (OLDTXT),y
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sta CURLIN+0
|
|
||||||
iny
|
|
||||||
|
|
||||||
#if CONFIG_MEMORY_MODEL_60K
|
|
||||||
jsr peek_under_roms
|
|
||||||
#else // CONFIG_MEMORY_MODEL_38K
|
|
||||||
lda (OLDTXT),y
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sta CURLIN+1
|
|
||||||
|
|
||||||
jmp basic_execute_statement
|
|
||||||
@@ -5,10 +5,6 @@
|
|||||||
|
|
||||||
basic_main_loop:
|
basic_main_loop:
|
||||||
|
|
||||||
// XXX - Check if direct or program mode, and get next line of input
|
|
||||||
// the appropriate way.
|
|
||||||
// XXX - For now, it is hard coded to direct mode
|
|
||||||
|
|
||||||
// Tell user we are ready
|
// Tell user we are ready
|
||||||
jsr ready_message
|
jsr ready_message
|
||||||
|
|
||||||
@@ -177,4 +173,4 @@ not_a_line:
|
|||||||
lda #$FF
|
lda #$FF
|
||||||
sta CURLIN+1
|
sta CURLIN+1
|
||||||
|
|
||||||
jmp basic_execute_statement
|
jmp execute_statements
|
||||||
@@ -7,6 +7,6 @@ cmd_clr:
|
|||||||
|
|
||||||
jsr basic_do_clr
|
jsr basic_do_clr
|
||||||
|
|
||||||
// CLR command does not stop execution
|
// CLR command does not stop execution (confirmed on a C64)
|
||||||
// (Cconfirmed on a c64)
|
|
||||||
jmp basic_execute_statement
|
jmp execute_statements
|
||||||
@@ -65,7 +65,7 @@ cmd_load_no_error:
|
|||||||
// For VERIFY - this is it
|
// For VERIFY - this is it
|
||||||
|
|
||||||
lda VERCKB
|
lda VERCKB
|
||||||
bne_16 basic_execute_statement
|
bne_16 execute_statements
|
||||||
|
|
||||||
// C64 BASIC apparently does not clear variables after a LOAD in the
|
// C64 BASIC apparently does not clear variables after a LOAD in the
|
||||||
// middle of a program. For safety, we do.
|
// middle of a program. For safety, we do.
|
||||||
@@ -89,7 +89,7 @@ cmd_load_no_error:
|
|||||||
inx
|
inx
|
||||||
beq cmd_load_end // branch if direct mode
|
beq cmd_load_end // branch if direct mode
|
||||||
|
|
||||||
jmp basic_execute_from_current_line
|
jmp execute_line
|
||||||
|
|
||||||
cmd_load_end:
|
cmd_load_end:
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ cmd_new:
|
|||||||
|
|
||||||
jsr basic_do_new
|
jsr basic_do_new
|
||||||
|
|
||||||
// NEW command terminates execution
|
// NEW command terminates execution (confirmed on a C64)
|
||||||
// (Confirmed on a C64)
|
|
||||||
jmp basic_main_loop
|
jmp basic_main_loop
|
||||||
@@ -85,4 +85,4 @@ cmd_print_new_line_done:
|
|||||||
|
|
||||||
cmd_print_done:
|
cmd_print_done:
|
||||||
|
|
||||||
jmp basic_execute_statement
|
jmp execute_statements
|
||||||
@@ -6,4 +6,5 @@
|
|||||||
// REM statement just skips to the next line
|
// REM statement just skips to the next line
|
||||||
|
|
||||||
cmd_rem:
|
cmd_rem:
|
||||||
jmp basic_end_of_line
|
|
||||||
|
jmp execute_statements_end_of_line
|
||||||
@@ -24,4 +24,4 @@ cmd_goto:
|
|||||||
jmp do_UNDEFD_STATEMENT_error
|
jmp do_UNDEFD_STATEMENT_error
|
||||||
!:
|
!:
|
||||||
// Run it!
|
// Run it!
|
||||||
jmp basic_execute_from_current_line
|
jmp execute_line
|
||||||
@@ -36,4 +36,4 @@ cmd_save:
|
|||||||
|
|
||||||
// The end
|
// The end
|
||||||
|
|
||||||
jmp basic_execute_statement
|
jmp execute_statements
|
||||||
@@ -62,7 +62,7 @@ cmd_sys_setup_call:
|
|||||||
// Call the routine.
|
// Call the routine.
|
||||||
jsr USRPOK
|
jsr USRPOK
|
||||||
|
|
||||||
jmp basic_execute_statement
|
jmp execute_statements
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
// XXX use separate jumptables for commands and functions
|
||||||
|
|
||||||
|
|
||||||
.const command_list = List().add(
|
.const command_list = List().add(
|
||||||
|
|
||||||
// $80 - $8F
|
// $80 - $8F
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
// #LAYOUT# STD * #TAKE
|
||||||
|
// #LAYOUT# * BASIC_0 #TAKE
|
||||||
|
// #LAYOUT# * * #IGNORE
|
||||||
|
|
||||||
|
//
|
||||||
|
// Tries to execute the statement, and all the subsequent ones
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
execute_statements:
|
||||||
|
|
||||||
|
// Check for RUN/STOP
|
||||||
|
|
||||||
|
lda STKEY
|
||||||
|
bpl_16 cmd_stop
|
||||||
|
|
||||||
|
// Skip over any white spaces and colons (':')
|
||||||
|
!:
|
||||||
|
jsr fetch_character
|
||||||
|
cmp #$20 // space, can be skipped
|
||||||
|
beq !-
|
||||||
|
cmp #$3A // colon, can be skipped
|
||||||
|
beq !-
|
||||||
|
|
||||||
|
// Check if end of the line
|
||||||
|
|
||||||
|
cmp #$00
|
||||||
|
beq execute_statements_end_of_line
|
||||||
|
|
||||||
|
// Not end of the line - it seems we actually have something to execute
|
||||||
|
|
||||||
|
cmp #$7F
|
||||||
|
bcc_16 do_SYNTAX_error // branch if not a token XXX here we should handle variable assignments
|
||||||
|
|
||||||
|
#if !HAS_OPCODES_65C02
|
||||||
|
|
||||||
|
// Get the jump table entry for it, push it on the stack, and then RTS to start it.
|
||||||
|
|
||||||
|
tax
|
||||||
|
lda command_jumptable_hi - $80, x
|
||||||
|
pha
|
||||||
|
lda command_jumptable_lo - $80, x
|
||||||
|
pha
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
#else // HAS_OPCODES_65C02
|
||||||
|
|
||||||
|
// Use jumptable to go to the token
|
||||||
|
|
||||||
|
asl
|
||||||
|
tax
|
||||||
|
jmp (command_jumptable, x)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
execute_statements_end_of_line:
|
||||||
|
|
||||||
|
// First check, if we are in direct mode - if so,
|
||||||
|
// end the execution and go to main loop
|
||||||
|
|
||||||
|
ldx CURLIN+1
|
||||||
|
inx
|
||||||
|
beq_16 basic_main_loop
|
||||||
|
|
||||||
|
// Advance to the next line - first copy the line number
|
||||||
|
// to previous line number
|
||||||
|
|
||||||
|
lda CURLIN+0
|
||||||
|
sta OLDLIN+0
|
||||||
|
lda CURLIN+1
|
||||||
|
sta OLDLIN+1
|
||||||
|
|
||||||
|
// Advance the basic line pointer to the next line; if end,
|
||||||
|
// go to the main loop
|
||||||
|
|
||||||
|
jsr basic_follow_link_to_next_line
|
||||||
|
|
||||||
|
lda OLDTXT+0
|
||||||
|
ora OLDTXT+1
|
||||||
|
beq_16 basic_main_loop
|
||||||
|
|
||||||
|
// FALLTROUGH
|
||||||
|
|
||||||
|
execute_line:
|
||||||
|
|
||||||
|
// Check if pointer is null, if so, we are at the end of the program
|
||||||
|
|
||||||
|
ldy #0
|
||||||
|
jsr peek_line_pointer_null_check
|
||||||
|
bcc_16 basic_main_loop // branch if end of program reached
|
||||||
|
|
||||||
|
// Skip pointer and line number to get address of first statement
|
||||||
|
|
||||||
|
lda OLDTXT+0
|
||||||
|
clc
|
||||||
|
adc #$04
|
||||||
|
sta TXTPTR+0
|
||||||
|
lda OLDTXT+1
|
||||||
|
adc #$00
|
||||||
|
sta TXTPTR+1
|
||||||
|
|
||||||
|
ldy #$02
|
||||||
|
|
||||||
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
ldx #<OLDTXT
|
||||||
|
jsr peek_under_roms
|
||||||
|
#else // CONFIG_MEMORY_MODEL_38K
|
||||||
|
lda (OLDTXT),y
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sta CURLIN+0
|
||||||
|
iny
|
||||||
|
|
||||||
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
jsr peek_under_roms
|
||||||
|
#else // CONFIG_MEMORY_MODEL_38K
|
||||||
|
lda (OLDTXT),y
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sta CURLIN+1
|
||||||
|
|
||||||
|
jmp execute_statements
|
||||||
File renamed without changes.
@@ -98,7 +98,7 @@ wedge_dos_change_drive:
|
|||||||
!:
|
!:
|
||||||
sta FA
|
sta FA
|
||||||
jsr print_return
|
jsr print_return
|
||||||
jmp basic_end_of_line
|
jmp basic_main_loop
|
||||||
|
|
||||||
wedge_dos_status_get:
|
wedge_dos_status_get:
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user