code size optimization in BASIC

This commit is contained in:
FeralChild64 committed 2020-07-31 16:48:35 +02:00
1 parent 07674b4e23
commit dd85061c47
6 files changed
+86 -55

No files matched your search

+1 -1
View File
@@ -144,7 +144,7 @@ tk_pack_loop_next:
cmp #TK__MAX_KEYWORD_LEN cmp #TK__MAX_KEYWORD_LEN
beq !+ // if max length reached - quit beq !+ // if max length reached - quit
// Check for characters that can only end the token // Check for characters that can only end the keyword
lda BUF-1, x lda BUF-1, x
cmp #$41 cmp #$41
+2 -15
View File
@@ -3,7 +3,7 @@
// #LAYOUT# * * #IGNORE // #LAYOUT# * * #IGNORE
// //
// Consummes assign operator in a BASIC code, Carry set if not found. Injests all spaces. // Consummes assign operator in a BASIC code, triggers error if not found
// //
@@ -11,19 +11,6 @@ injest_assign:
jsr fetch_character_skip_spaces jsr fetch_character_skip_spaces
cmp #$B2 // assign operator character cmp #$B2 // assign operator character
beq injest_assign_found bne_16 do_SYNTAX_error
// Not found
#if !HAS_OPCODES_65CE02
jsr unconsume_character
#else
dew TXTPTR
#endif
sec
rts
injest_assign_found:
clc
rts rts
+2 -10
View File
@@ -47,15 +47,10 @@ array_create_fetch_dims_loop:
inx inx
// Check if the stack has reasonable space free
jsr check_stack_space
// Fetch the dimension, increment it by 1, and put it on the stack; // Fetch the dimension, increment it by 1, and put it on the stack;
// confirmed with original ROM, that it also stores dimensions in the reverse order // confirmed with original ROM, that it also stores dimensions in the reverse order
jsr fetch_uint16 jsr helper_fetch_arr_coord
bcs_16 do_SYNTAX_error
#if !HAS_OPCODES_65CE02 #if !HAS_OPCODES_65CE02
inc LINNUM+0 inc LINNUM+0
@@ -75,11 +70,8 @@ array_create_fetch_dims_loop:
// Check if more dimensions are given // Check if more dimensions are given
jsr fetch_character_skip_spaces cpy #$00
cmp #$2C // ','
beq array_create_fetch_dims_loop beq array_create_fetch_dims_loop
cmp #$29 // ')'
bne_16 do_SYNTAX_error
// FALLTROUGH // FALLTROUGH
+35 -17
View File
@@ -5,26 +5,35 @@
assign_variable: assign_variable:
// Fetch variable name, should be followed by assign operator // Fetch variable/array name
jsr fetch_variable_name jsr fetch_variable_name
#if HAS_OPCODES_65CE02
bcs_16 do_SYNTAX_error
jsr injest_assign
bcs_16 do_SYNTAX_error bcs_16 do_SYNTAX_error
#else
bcs !+
jsr injest_assign jsr injest_assign
bcc !++
!:
jmp do_SYNTAX_error
!:
#endif // Check for array
lda DIMFLG
bpl assign_variable_not_array
// Retrieve all the dimensions
// XXX implement this
jmp do_NOT_IMPLEMENTED_error
// Fetch assignment operator and continue
jsr injest_assign
jmp_8 assign_variable_common
assign_variable_not_array:
// Require assignment operator
jsr injest_assign
// Check for special variables // Check for special variables
@@ -37,8 +46,14 @@ assign_variable:
jsr is_var_ST jsr is_var_ST
beq_16 do_SYNTAX_error beq_16 do_SYNTAX_error
// Push the VARNAM to the stack - it might get overridden // FALLTROUGH
assign_variable_common:
// Push the DIMFLG and VARNAM to the stack - it might get overridden
lda DIMFLG
pha
lda VARNAM+0 lda VARNAM+0
pha pha
lda VARNAM+1 lda VARNAM+1
@@ -48,15 +63,18 @@ assign_variable:
jsr FRMEVL jsr FRMEVL
// Restore VARNAM // Restore VARNAM and DIMFLG
pla pla
sta VARNAM+1 sta VARNAM+1
pla pla
sta VARNAM+0 sta VARNAM+0
pla
sta DIMFLG // XXX is it needed?
// XXX add array handling here
// Retrieve the variable address // Retrieve the variable address
// XXX add support for arrays
jsr fetch_variable_find_addr jsr fetch_variable_find_addr
@@ -27,27 +27,19 @@ fetch_variable_arr_fetch_coords_loop:
inx inx
// Check if the stack has reasonable space free // Fetch the coordinate and put it on the stack
jsr check_stack_space jsr helper_fetch_arr_coord
// Fetch the dimension and put it on the stack
jsr fetch_uint16
bcs_16 do_SYNTAX_error
lda LINNUM+0 lda LINNUM+0
pha pha
lda LINNUM+1 lda LINNUM+1
pha pha
// Check if more dimensions are given // If more coordinates given - next iteration
jsr fetch_character_skip_spaces cpy #$00
cmp #$2C // ','
beq fetch_variable_arr_fetch_coords_loop beq fetch_variable_arr_fetch_coords_loop
cmp #$29 // ')'
bne_16 do_SYNTAX_error
// FALLTROUGH // FALLTROUGH
@@ -0,0 +1,42 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Helper routine for fetching array coordinates
//
// If this was last coordinate, set .Y to $FF, otherwise to $00
//
helper_fetch_arr_coord:
// Check if the stack has reasonable space free
jsr check_stack_space
// Fetch the dimension
jsr fetch_uint16
bcs !+
jsr fetch_character_skip_spaces
cmp #$2C // ','
beq helper_fetch_arr_more
cmp #$29 // ')'
beq helper_fetch_arr_last
// FALLTROUGH
!:
jmp do_SYNTAX_error
helper_fetch_arr_more:
ldy #$00
rts
helper_fetch_arr_last:
ldy #$FF
rts