small cleanup in BASIC

This commit is contained in:
FeralChild64 committed 2020-06-05 22:26:08 +02:00
1 parent 580cd65941
commit 0436b5c62e
13 files changed
+319 -278

No files matched your search

+3 -1
View File
@@ -16,12 +16,14 @@ SRCDIR_BASIC = $(SRCDIR_COMMON) \
c64/basic/board_m65 \
c64/basic/board_x16 \
c64/basic/commands \
c64/basic/engine \
c64/basic/init \
c64/basic/math \
c64/basic/math_consts \
c64/basic/math_mov \
c64/basic/print \
c64/basic/rom_revision
c64/basic/rom_revision \
c64/basic/wedge
SRCDIR_KERNAL = $(SRCDIR_COMMON) \
c64/kernal \
+3 -177
View File
@@ -6,34 +6,6 @@
// after first checking that we have a colon
// or $00 char
basic_end_of_statement_check:
ldy #0
#if CONFIG_MEMORY_MODEL_60K
ldx #<TXTPTR
jsr peek_under_roms
#else // CONFIG_MEMORY_MODEL_38K
lda (TXTPTR),y
#endif
// Consume any spaces
cmp #$20
bne no_space_to_skip
jsr basic_consume_character
jmp basic_end_of_statement_check
no_space_to_skip:
cmp #$00
beq !+
cmp #$3a
beq !+
// not end of statement
clc
rts
!:
sec
rts
basic_execute_statement:
@@ -52,7 +24,7 @@ basic_execute_statement:
lda (TXTPTR),y
#endif
jsr basic_end_of_statement_check
jsr end_of_statement_check
bcs basic_end_of_line
// jsr printf
@@ -95,9 +67,9 @@ basic_execute_statement:
// and then RTS to start it.
asl
tax
lda basic_command_jump_table+1,x
lda command_jumptable+1,x
pha
lda basic_command_jump_table+0,x
lda command_jumptable+0,x
pha
// Now consume the character
@@ -223,149 +195,3 @@ basic_execute_from_current_line:
sta CURLIN+1
jmp basic_execute_statement
basic_command_jump_table:
// $80 - $8F
.word cmd_end-1
.word cmd_for-1
.word cmd_next-1
.word cmd_data-1
.word cmd_inputhash-1
.word cmd_input-1
.word cmd_dim-1
.word cmd_read-1
.word cmd_let-1
.word cmd_goto-1
.word cmd_run-1
.word cmd_if-1
.word cmd_restore-1
.word cmd_gosub-1
.word cmd_return-1
.word cmd_rem-1
// $90-$9F
.word cmd_stop-1
.word cmd_on-1
.word cmd_wait-1
.word cmd_load-1
.word cmd_save-1
.word cmd_verify-1
.word cmd_def-1
.word cmd_poke-1
.word cmd_printhash-1
.word cmd_print-1
.word cmd_cont-1
.word cmd_list-1
.word cmd_clr-1
.word cmd_cmd-1
.word cmd_sys-1
.word cmd_open-1
// $A0-$AF
.word cmd_close-1
.word cmd_get-1
.word cmd_new-1
.word cmd_tab-1
.word cmd_to-1
.word cmd_fn-1
.word cmd_spc-1
.word cmd_then-1
.word cmd_not-1
.word cmd_step-1
.word cmd_plus-1
.word cmd_minus-1
.word cmd_mult-1
.word cmd_div-1
.word cmd_exponent-1
.word cmd_and-1
// $B0-$BF
.word cmd_or-1
.word cmd_greater-1
.word cmd_equal-1
.word cmd_less-1
.word cmd_sgn-1
.word cmd_int-1
.word cmd_abs-1
.word cmd_usr-1
.word cmd_fre-1
.word cmd_pos-1
.word cmd_sqr-1
.word cmd_rnd-1
.word cmd_log-1
.word cmd_exp-1
.word cmd_cos-1
.word cmd_sin-1
// $C0-$CF
.word cmd_tan-1
.word cmd_atn-1
.word cmd_peek-1
.word cmd_len-1
.word cmd_str-1
.word cmd_val-1
.word cmd_asc-1
.word cmd_chr-1
.word cmd_left-1
.word cmd_right-1
.word cmd_mid-1
.word cmd_go-1
// Undefined tokens
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
// $D0-$DF
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
// $E0-$EF
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
// $F0-$FF
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
+3 -88
View File
@@ -27,18 +27,14 @@ cmd_load:
ldy #$00 // secondary address
jsr JSETFLS
// Check if file name is supplied
jsr basic_end_of_statement_check
bcs cmd_load_no_filename
// Fetch the file name
jsr cmd_load_fetch_filename
jsr fetch_filename
bcs cmd_load_no_filename
// Try to fetch secondary address
jsr cmd_load_fetch_dev_secondary
jsr fetch_device_secondary
jmp cmd_load_got_params
cmd_load_no_filename:
@@ -108,84 +104,3 @@ cmd_load_no_error:
// XXX move functions below to separate files, change names to neuytral
cmd_load_fetch_filename:
// Search for opening quote
jsr basic_fetch_and_consume_character
cmp #$22
bne_16 do_SYNTAX_error
!:
// Filename starts here so set pointer
lda TXTPTR+0
sta FNADDR+0
lda TXTPTR+1
sta FNADDR+1
// Now search for end of line or closing quote
// so that we know the length of the filename
lda #$00
sta FNLEN
!:
jsr basic_fetch_and_consume_character
cmp #$22
beq cmd_load_fetch_filename_done
cmp #$00
beq !+
inc FNLEN
bne !-
!:
jsr basic_unconsume_character
// FALLTROUGH
cmd_load_fetch_filename_done:
rts
cmd_load_fetch_dev_secondary:
// Fetch the device number
jsr injest_comma
bcs cmd_load_fetch_dev_secondary
jsr basic_parse_line_number
lda LINNUM+1
bne_16 do_ILLEGAL_QUANTITY_error
lda LINNUM+0
sta FA
// FALLTROUGH
cmd_load_fetch_secondary:
// Fetch secondary address
jsr injest_comma
bcs cmd_load_fetch_dev_secondary_done
jsr basic_parse_line_number
lda LINNUM+1
bne_16 do_ILLEGAL_QUANTITY_error
lda LINNUM+0
sta SA
// FALLTROUGH
cmd_load_fetch_dev_secondary_done:
rts
+1 -1
View File
@@ -14,7 +14,7 @@ cmd_goto:
// Reset line pointer to first line of program.
jsr init_oldtxt
jsr basic_end_of_statement_check
jsr end_of_statement_check
bcs !+
jsr basic_parse_line_number
+2 -6
View File
@@ -11,14 +11,10 @@ cmd_save:
ldy #$00 // secondary address
jsr JSETFLS
// Check if file name is supplied
jsr basic_end_of_statement_check
bcs_16 do_MISSING_FILENAME_error
// Fetch the file name
jsr cmd_load_fetch_filename
jsr fetch_filename
bcs_16 do_MISSING_FILENAME_error
+1 -1
View File
@@ -5,7 +5,7 @@
cmd_sys:
jsr basic_end_of_statement_check
jsr end_of_statement_check
bcc !+
// SYS requires an argument
+155
View File
@@ -0,0 +1,155 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Jumptable for all known BASIC commands and functions
//
command_jumptable:
// $80 - $8F
.word cmd_end-1
.word cmd_for-1
.word cmd_next-1
.word cmd_data-1
.word cmd_inputhash-1
.word cmd_input-1
.word cmd_dim-1
.word cmd_read-1
.word cmd_let-1
.word cmd_goto-1
.word cmd_run-1
.word cmd_if-1
.word cmd_restore-1
.word cmd_gosub-1
.word cmd_return-1
.word cmd_rem-1
// $90-$9F
.word cmd_stop-1
.word cmd_on-1
.word cmd_wait-1
.word cmd_load-1
.word cmd_save-1
.word cmd_verify-1
.word cmd_def-1
.word cmd_poke-1
.word cmd_printhash-1
.word cmd_print-1
.word cmd_cont-1
.word cmd_list-1
.word cmd_clr-1
.word cmd_cmd-1
.word cmd_sys-1
.word cmd_open-1
// $A0-$AF
.word cmd_close-1
.word cmd_get-1
.word cmd_new-1
.word cmd_tab-1
.word cmd_to-1
.word cmd_fn-1
.word cmd_spc-1
.word cmd_then-1
.word cmd_not-1
.word cmd_step-1
.word cmd_plus-1
.word cmd_minus-1
.word cmd_mult-1
.word cmd_div-1
.word cmd_exponent-1
.word cmd_and-1
// $B0-$BF
.word cmd_or-1
.word cmd_greater-1
.word cmd_equal-1
.word cmd_less-1
.word cmd_sgn-1
.word cmd_int-1
.word cmd_abs-1
.word cmd_usr-1
.word cmd_fre-1
.word cmd_pos-1
.word cmd_sqr-1
.word cmd_rnd-1
.word cmd_log-1
.word cmd_exp-1
.word cmd_cos-1
.word cmd_sin-1
// $C0-$CF
.word cmd_tan-1
.word cmd_atn-1
.word cmd_peek-1
.word cmd_len-1
.word cmd_str-1
.word cmd_val-1
.word cmd_asc-1
.word cmd_chr-1
.word cmd_left-1
.word cmd_right-1
.word cmd_mid-1
.word cmd_go-1
// Undefined tokens
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
// $D0-$DF
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
// $E0-$EF
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
// $F0-$FF
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
.word cmd_unimplemented-1
+41
View File
@@ -0,0 +1,41 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Check for end of statement, sets Carry if so. Injests all spaces.
//
end_of_statement_check:
ldy #0
#if CONFIG_MEMORY_MODEL_60K
ldx #<TXTPTR
jsr peek_under_roms
#else // CONFIG_MEMORY_MODEL_38K
lda (TXTPTR),y
#endif
// Injest any spaces
cmp #$20
bne !+
jsr basic_consume_character
jmp end_of_statement_check
!:
cmp #$00
beq !+
cmp #$3a
beq !+
// Not end of statement
clc
rts
!:
// End of statement
sec
rts
+44
View File
@@ -0,0 +1,44 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Fetches device number and secondary address - if they are present
//
fetch_device_secondary:
// Fetch the device number
jsr injest_comma
bcs fetch_secondary
jsr basic_parse_line_number
lda LINNUM+1
bne_16 do_ILLEGAL_QUANTITY_error
lda LINNUM+0
sta FA
// FALLTROUGH
fetch_secondary:
// Fetch secondary address
jsr injest_comma
bcs fetch_device_secondary_done
jsr basic_parse_line_number
lda LINNUM+1
bne_16 do_ILLEGAL_QUANTITY_error
lda LINNUM+0
sta SA
// FALLTROUGH
fetch_device_secondary_done:
rts
+58
View File
@@ -0,0 +1,58 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Fetches file name, Carry set if not found
//
fetch_filename:
// Check if end of statement
jsr end_of_statement_check
bcs fetch_filename_rts
// Search for opening quote
jsr basic_fetch_and_consume_character
cmp #$22
bne_16 do_SYNTAX_error
// Filename starts here so set pointer
lda TXTPTR+0
sta FNADDR+0
lda TXTPTR+1
sta FNADDR+1
// Now search for end of line or closing quote
// so that we know the length of the filename
lda #$00
sta FNLEN
!:
jsr basic_fetch_and_consume_character
cmp #$22
beq fetch_filename_done
cmp #$00
beq !+
inc FNLEN
bne !-
!:
jsr basic_unconsume_character
// FALLTROUGH
fetch_filename_done:
clc
// FALLTROUGH
fetch_filename_rts:
rts
@@ -2,22 +2,26 @@
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Consummes a comma in a BASIC code, Carry set if not found. Injests all spaces.
//
// Consummes a comma in a BASIC code, C set for no coma found
injest_comma:
jsr basic_fetch_and_consume_character
cmp #$2C // comma character
cmp #$2C // comma character
beq injest_comma_found
cmp #$20 // space, can always be skipped
cmp #$20 // space, can always be skipped
beq injest_comma
// not found
// Not found
jsr basic_unconsume_character
sec
rts
injest_comma_found:
clc
rts
File renamed without changes.
File renamed without changes.