separated commands from functions

This commit is contained in:
FeralChild64 committed 2020-06-08 18:26:38 +02:00
1 parent 5a2f847cb6
commit 0c8c0d6ad4
34 files changed
+215 -209

No files matched your search

+98
View File
@@ -0,0 +1,98 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Jumptable for all known BASIC commands
//
.const command_list = List().add(
// $80 - $8F
cmd_end,
cmd_for,
cmd_next,
cmd_data,
cmd_inputhash,
cmd_input,
cmd_dim,
cmd_read,
cmd_let,
cmd_goto,
cmd_run,
cmd_if,
cmd_restore,
cmd_gosub,
cmd_return,
cmd_rem,
// $90-$9F
cmd_stop,
cmd_on,
cmd_wait,
cmd_load,
cmd_save,
cmd_verify,
cmd_def,
cmd_poke,
cmd_printhash,
cmd_print,
cmd_cont,
cmd_list,
cmd_clr,
cmd_cmd,
cmd_sys,
cmd_open,
// $A0-$A6
cmd_close,
cmd_get,
cmd_new,
cmd_tab, // XXX this token probably does not belong here
do_SYNTAX_error, // 'TO' is not a standalone command
do_SYNTAX_error, // 'FN' is not a standalone command
cmd_spc, // XXX this token probably does not belong here
// 'THEN' ($A7) and 'STEP' ($A9) are not standalone commands
// 'NOT' ($A8) is an operator, not a command
// $CB, but remapped to $A7
cmd_go
)
#if !HAS_OPCODES_65C02
command_jumptable_lo:
put_jumptable_lo(command_list)
command_jumptable_hi:
put_jumptable_hi(command_list)
#else // HAS_OPCODES_65C02
__before_command_jumptable:
.if (mod(*, $2) == 1) { brk } // align code so that vector never crosses page boundary
command_jumptable:
put_jumptable(command_list)
// Make sure routine size is always the same - build system limitation
.if (__before_command_jumptable == command_jumptable) { brk }
#endif
@@ -0,0 +1,65 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Default handler for all not-yet-implemented commands
//
// Note: NOPs are here just to make debugging easier (no duplicated labels)!
//
cmd_for:
nop
cmd_next:
nop
cmd_data:
nop
cmd_inputhash:
nop
cmd_input:
nop
cmd_dim:
nop
cmd_read:
nop
cmd_let:
nop
cmd_if:
nop
cmd_restore:
nop
cmd_gosub:
nop
cmd_return:
nop
cmd_on:
nop
cmd_wait:
nop
cmd_def:
nop
cmd_poke:
nop
cmd_printhash:
nop
cmd_cont:
nop
cmd_cmd:
nop
cmd_open:
nop
cmd_close:
nop
cmd_get:
nop
cmd_tab:
nop
cmd_spc:
nop
cmd_go:
nop
// Unimplemented tokens
jmp do_NOT_IMPLEMENTED_error
+12
View File
@@ -0,0 +1,12 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_clr:
jsr basic_do_clr
// CLR command does not stop execution (confirmed on a C64)
jmp execute_statements
+44
View File
@@ -0,0 +1,44 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
// LIST basic text.
// XXX - Does not currently support line number ranges
cmd_list:
// Set current line pointer to start of memory
jsr init_oldtxt
// Always start with empty line, for readability
jsr print_return
list_loop:
ldy #1
#if CONFIG_MEMORY_MODEL_60K
ldx #<OLDTXT+0
jsr peek_under_roms
cmp #$00
#else // CONFIG_MEMORY_MODEL_38K
lda (OLDTXT),y
#endif
bne list_more_lines
// LIST terminates any running program,
// because it has fiddled with the current line pointer.
// (Confirmed by testing on a C64)
jmp basic_main_loop
list_more_lines:
lda STKEY
bmi !+
jmp cmd_stop
!:
jsr list_single_line
// Now link to the next line
jsr basic_find_next_line
jmp list_loop
+112
View File
@@ -0,0 +1,112 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_verify:
// LOAD and VERIFY are very similar, from BASIC perspective there is almost no difference;
// just different parameter passed to Kernal and different error message in case of failure
lda #$01 // mark operation as VERIFY
skip_2_bytes_trash_nvz
cmd_load:
lda #$00 // mark operation as LOAD
sta VERCKB
// Set default device and secondary address; channel is not important now
jsr select_device
ldy #$00 // secondary address
jsr JSETFLS
// Fetch the file name
jsr fetch_filename
bcs cmd_load_no_filename
// Try to fetch device and secondary address
jsr fetch_device_secondary
jmp cmd_load_got_params
cmd_load_no_filename:
// If no file name is supplied, try to load first file from disc
lda #$01 // name length
ldx #<filename_any
ldy #>filename_any
jsr JSETNAM
// FALLTROUGH
cmd_load_got_params: // input for tape wedge
// Perform loading
ldy TXTTAB+1
ldx TXTTAB+0
lda VERCKB // LOAD or VERIFY
jsr JLOAD
jsr cmd_load_save_handle_result
cmd_load_no_error:
// Store last loaded address
stx VARTAB+0
sty VARTAB+1
// For VERIFY - this is it
lda VERCKB
bne_16 execute_statements
// C64 BASIC apparently does not clear variables after a LOAD in the
// middle of a program. For safety, we do.
jsr basic_do_clr
// Now relink the loaded program, as we cannot trust the line
// links supplied. For example, the VICE virtual drive emulation
// always supplies $0101 as the address of the next line
jsr LINKPRG
// Now we either start the program from the beginning,
// or go back to the READY prompt if LOAD was called from direct mode.
// Reset to start of program
jsr init_oldtxt
// If loading was done when running a program - run it
ldx CURLIN+1
inx
beq cmd_load_end // branch if direct mode
jmp execute_line
cmd_load_end:
jmp basic_main_loop
//
// Handle result from Kernal - common for LOAD/VERIFY/SAVE
//
cmd_load_save_handle_result:
php
pha
jsr print_return
pla
plp
bcs_16 do_kernal_error
rts
+12
View File
@@ -0,0 +1,12 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_new:
jsr basic_do_new
// NEW command terminates execution (confirmed on a C64)
jmp basic_main_loop
+88
View File
@@ -0,0 +1,88 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_print:
// First check if we have anything to print
jsr end_of_statement_check
bcs cmd_print_new_line_done
jsr fetch_character
cmp #$3B // semicolon
beq cmd_print_done
// FALLTROUGH
cmd_print_loop:
jsr unconsume_character
// FALLTROUGH
cmd_print_after_comma:
// Now evaluate the expression
jsr FRMEVL
lda VALTYP
bpl cmd_print_float
// FALLTROUGH
cmd_print_string:
// Print a string value
ldy #$00
!:
cpy __FAC1 + 0
beq cmd_print_next_arg
#if CONFIG_MEMORY_MODEL_60K
ldx #<(__FAC1 + 1)
jsr peek_under_roms
#else // CONFIG_MEMORY_MODEL_38K
lda (__FAC1 + 1), y
#endif
jsr JCHROUT
iny
jmp !-
cmd_print_float:
// XXX probably we should also check INTFLG here
// XXX provide implementation
// FALLTROUGH
cmd_print_next_arg:
// Look for the next argument
jsr end_of_statement_check
bcs cmd_print_new_line_done
cmp #$2C // comma XXX on C64 behavior is more complicated, fix it
beq cmd_print_after_comma
cmp #$3B // semicolon
beq cmd_print_done
bne cmd_print_loop
cmd_print_new_line_done:
jsr print_return
// FALLTROUGH
cmd_print_done:
jmp execute_statements
+10
View File
@@ -0,0 +1,10 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
// REM statement just skips to the next line
cmd_rem:
jmp execute_statements_end_of_line
+27
View File
@@ -0,0 +1,27 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_run:
// RUN clears all variables
jsr basic_do_clr
cmd_goto:
// Disable Kernal messages
lda #$00
jsr JSETMSG
// Reset line pointer to first line of program.
jsr init_oldtxt
jsr end_of_statement_check
bcs !+
jsr basic_parse_line_number
jsr basic_find_line
bcc !+
// Line does not exist, so report error
jmp do_UNDEFD_STATEMENT_error
!:
// Run it!
jmp execute_line
+39
View File
@@ -0,0 +1,39 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_save:
// Set default device and secondary address; channel is not important now
jsr select_device
ldy #$00
jsr JSETFLS
// Fetch the file name
jsr fetch_filename
bcs_16 do_MISSING_FILENAME_error
// Try to fetch device
jsr fetch_device_secondary
// Setup the start and end addresses
lda #TXTTAB
// Setup the end address
ldx VARTAB+0
ldy VARTAB+1
// Perform saving
jsr JSAVE
jsr cmd_load_save_handle_result
// The end
jmp execute_statements
+27
View File
@@ -0,0 +1,27 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_stop:
ldx #30 // "BREAK"
jsr print_packed_message
// Are we in direct mode
lda CURLIN+1
cmp #$FF
beq !+
// Not direct mode
ldx #31
jsr print_packed_message
lda CURLIN+1
ldx CURLIN+0
jsr print_integer
!:
jsr print_return
cmd_end:
jmp basic_main_loop
+73
View File
@@ -0,0 +1,73 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_sys:
jsr end_of_statement_check
bcc !+
// SYS requires an argument
jmp do_SYNTAX_error
!:
//
// XXX Temporary ugly hack to support 'SYS PI*656'
//
ldy #$00
cmd_sys_hack_loop:
lda (TXTPTR), y
cmp cmd_sys_hack_str, y
bne cmd_sys_hack_not_needed
lda (TXTPTR), y
beq cmd_sys_hack_apply
iny
bne cmd_sys_hack_loop // branch always
cmd_sys_hack_apply:
lda #<2060
sta LINNUM+0
lda #>2060
sta LINNUM+1
bne cmd_sys_setup_call // always jumps
cmd_sys_hack_not_needed:
//
// XXX End of hack
//
jsr basic_parse_line_number
cmd_sys_setup_call:
lda #$4C // JMP opcode
sta USRPOK
lda LINNUM+0
sta USRADD+0
lda LINNUM+1
sta USRADD+1
// Setup the register values
lda SPREG
pha
ldy SYREG
ldx SXREG
lda SAREG
plp
// Call the routine.
jsr USRPOK
jmp execute_statements
//
// XXX Temporary ugly hack to support 'SYS PI*656'
//
cmd_sys_hack_str:
.byte $FF, $AC, $36, $35, $36, $00