more work on variables support
This commit is contained in:
1 parent
50da40a4f1
commit
6e90102f76
5 files changed
+214
-11
No files matched your search
@@ -47,7 +47,7 @@
|
|||||||
.label DATPTR = $41 // $41-$42 pointer for READ/DATA copmmands
|
.label DATPTR = $41 // $41-$42 pointer for READ/DATA copmmands
|
||||||
.label INPPTR = $43 // $43-$44 -- NOT IMPLEMENTED --
|
.label INPPTR = $43 // $43-$44 -- NOT IMPLEMENTED --
|
||||||
.label VARNAM = $45 // $45-$46 current variable name
|
.label VARNAM = $45 // $45-$46 current variable name
|
||||||
.label VARPNT = $47 // $47-$48 -- NOT IMPLEMENTED --
|
.label VARPNT = $47 // $47-$48 current variable/descriptor pointer
|
||||||
.label FORPNT = $49 // $49-$4A -- NOT IMPLEMENTED --
|
.label FORPNT = $49 // $49-$4A -- NOT IMPLEMENTED --
|
||||||
.label OPPTR = $4B // $4B-$4C helper variable for expression computation, [!] our usage details are different
|
.label OPPTR = $4B // $4B-$4C helper variable for expression computation, [!] our usage details are different
|
||||||
.label OPMASK = $4D // -- NOT IMPLEMENTED --
|
.label OPMASK = $4D // -- NOT IMPLEMENTED --
|
||||||
|
|||||||
@@ -12,6 +12,73 @@ cmd_let:
|
|||||||
jsr injest_assign
|
jsr injest_assign
|
||||||
bcs_16 do_SYNTAX_error
|
bcs_16 do_SYNTAX_error
|
||||||
|
|
||||||
|
// Determine variable type and push it to the stack
|
||||||
|
|
||||||
|
lda #$00
|
||||||
|
clc
|
||||||
|
bit VARNAM+0
|
||||||
|
bpl !+
|
||||||
|
adc #$01
|
||||||
|
!:
|
||||||
|
bit VARNAM+1
|
||||||
|
bpl !+
|
||||||
|
adc #$80
|
||||||
|
!:
|
||||||
|
pha
|
||||||
|
|
||||||
|
// Push the VARPNT to the stack - it might get overridden
|
||||||
|
|
||||||
|
lda VARPNT+0
|
||||||
|
pha
|
||||||
|
lda VARPNT+1
|
||||||
|
pha
|
||||||
|
|
||||||
|
// Evaluate the expression
|
||||||
|
|
||||||
|
jsr FRMEVL
|
||||||
|
|
||||||
|
// Restore VARPNT
|
||||||
|
|
||||||
|
pla
|
||||||
|
sta VARPNT+1
|
||||||
|
pla
|
||||||
|
sta VARPNT+0
|
||||||
|
|
||||||
|
// Determine what to assign
|
||||||
|
|
||||||
|
pla
|
||||||
|
bmi cmd_let_assign_string
|
||||||
|
beq cmd_let_assign_float
|
||||||
|
|
||||||
|
// FALLTROUGH
|
||||||
|
|
||||||
|
// XXX integer and float probably have much in common
|
||||||
|
|
||||||
|
cmd_let_assign_integer:
|
||||||
|
|
||||||
|
lda VALTYP
|
||||||
|
bmi_16 do_TYPE_MISMATCH_error
|
||||||
|
|
||||||
|
// XXX finish the implementation
|
||||||
|
|
||||||
|
jmp do_NOT_IMPLEMENTED_error
|
||||||
|
|
||||||
|
cmd_let_assign_float:
|
||||||
|
|
||||||
|
lda VALTYP
|
||||||
|
bmi_16 do_TYPE_MISMATCH_error
|
||||||
|
|
||||||
|
// XXX finish the implementation
|
||||||
|
|
||||||
|
jmp do_NOT_IMPLEMENTED_error
|
||||||
|
|
||||||
|
cmd_let_assign_string:
|
||||||
|
|
||||||
|
// Check if value type matches
|
||||||
|
|
||||||
|
lda VALTYP
|
||||||
|
bpl_16 do_TYPE_MISMATCH_error
|
||||||
|
|
||||||
// XXX finish the implementation
|
// XXX finish the implementation
|
||||||
|
|
||||||
jmp do_NOT_IMPLEMENTED_error
|
jmp do_NOT_IMPLEMENTED_error
|
||||||
@@ -77,8 +77,135 @@ fetch_variable_type_string:
|
|||||||
|
|
||||||
fetch_variable_find_addr:
|
fetch_variable_find_addr:
|
||||||
|
|
||||||
// Now try to find variable address
|
// Now try to find variable address between VARTAB and ARYTAB, see
|
||||||
|
// - https://www.c64-wiki.com/wiki/Memory_(BASIC)
|
||||||
|
|
||||||
|
lda VARTAB+0
|
||||||
|
sta VARPNT+0
|
||||||
|
lda VARTAB+1
|
||||||
|
sta VARPNT+1
|
||||||
|
|
||||||
|
// FALLTROUGH
|
||||||
|
|
||||||
|
fetch_variable_find_addr_loop:
|
||||||
|
|
||||||
|
// Check if end of search loop
|
||||||
|
|
||||||
|
lda VARPNT+1
|
||||||
|
cmp ARYTAB+1
|
||||||
|
bne !+
|
||||||
|
lda VARPNT+0
|
||||||
|
cmp VARPNT+0
|
||||||
|
beq fetch_variable_alocate
|
||||||
|
!:
|
||||||
|
// Compare current variable name with searched one
|
||||||
|
// XXX consider creating optimized version for 46K/50K memory models
|
||||||
|
|
||||||
|
ldy #$00
|
||||||
|
|
||||||
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
ldx #<VARPNT
|
||||||
|
jsr peek_under_roms
|
||||||
|
#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
||||||
|
jsr peek_under_roms_via_VARPNT
|
||||||
|
#else // CONFIG_MEMORY_MODEL_38K
|
||||||
|
lda (VARPNT),y
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cmp VARNAM+0
|
||||||
|
bne fetch_variable_find_addr_next
|
||||||
|
|
||||||
|
iny
|
||||||
|
|
||||||
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
jsr peek_under_roms
|
||||||
|
#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
||||||
|
jsr peek_under_roms_via_VARPNT
|
||||||
|
#else // CONFIG_MEMORY_MODEL_38K
|
||||||
|
lda (VARPNT),y
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cmp VARNAM+1
|
||||||
|
bne fetch_variable_find_addr_next
|
||||||
|
|
||||||
|
// FALLTROUGH
|
||||||
|
|
||||||
|
fetch_variable_adjust_VARPNT:
|
||||||
|
|
||||||
|
// Adjust VARPNT to point just after variable name and quit
|
||||||
|
|
||||||
|
#if !HAS_OPCODES_65CE02
|
||||||
|
|
||||||
|
clc
|
||||||
|
lda VARPNT+0
|
||||||
|
adc #$02
|
||||||
|
sta VARPNT+0
|
||||||
|
bcc !+
|
||||||
|
inc VARPNT+1
|
||||||
|
!:
|
||||||
|
#else // HAS_OPCODES_65CE02
|
||||||
|
|
||||||
|
inw VARPNT
|
||||||
|
inw VARPNT
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
fetch_variable_find_addr_next:
|
||||||
|
|
||||||
|
// Increase VARPNT by 7 - constant value, each variable uses 7 bytes, see:
|
||||||
|
// - https://sites.google.com/site/h2obsession/CBM/basic/variable-format
|
||||||
|
|
||||||
|
clc
|
||||||
|
lda VARPNT+0
|
||||||
|
adc #$07
|
||||||
|
sta VARPNT+0
|
||||||
|
bcc fetch_variable_find_addr_loop
|
||||||
|
inc VARPNT+1
|
||||||
|
bne fetch_variable_find_addr_loop // branch always
|
||||||
|
|
||||||
|
fetch_variable_alocate:
|
||||||
|
|
||||||
|
// First check if we have enough space for a new descriptor
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
|
|
||||||
rts
|
// If needed, move all the arrays up
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
|
||||||
|
// Set pointer to new variable
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
|
||||||
|
// Fill-in the new variable name, descriptor (it is enough to zero first 2 bytes of content)
|
||||||
|
|
||||||
|
ldy #$00
|
||||||
|
|
||||||
|
#if CONFIG_MEMORY_MODEL_60K
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
|
||||||
|
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
|
||||||
|
|
||||||
|
lda VARNAM+0
|
||||||
|
sta (VARPNT),y
|
||||||
|
iny
|
||||||
|
lda VARNAM+1
|
||||||
|
sta (VARPNT),y
|
||||||
|
iny
|
||||||
|
lda #$00
|
||||||
|
sta (VARPNT),y
|
||||||
|
iny
|
||||||
|
sta (VARPNT),y
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Adjust variable pointer and quit
|
||||||
|
|
||||||
|
#if HAS_OPCODES_65C02
|
||||||
|
bra fetch_variable_adjust_VARPNT
|
||||||
|
#else
|
||||||
|
jmp fetch_variable_adjust_VARPNT
|
||||||
|
#endif
|
||||||
@@ -259,11 +259,7 @@ varstr_garbage_collect_check_bptr:
|
|||||||
|
|
||||||
// Next iteration
|
// Next iteration
|
||||||
|
|
||||||
#if HAS_OPCODES_65C02
|
|
||||||
bra varstr_garbage_collect_loop
|
|
||||||
#else
|
|
||||||
jmp varstr_garbage_collect_loop
|
jmp varstr_garbage_collect_loop
|
||||||
#endif
|
|
||||||
|
|
||||||
varstr_garbage_collect_unused:
|
varstr_garbage_collect_unused:
|
||||||
|
|
||||||
@@ -299,11 +295,7 @@ varstr_garbage_collect_unused:
|
|||||||
|
|
||||||
// Next iteration
|
// Next iteration
|
||||||
|
|
||||||
#if HAS_OPCODES_65C02
|
|
||||||
bra varstr_garbage_collect_loop
|
|
||||||
#else
|
|
||||||
jmp varstr_garbage_collect_loop
|
jmp varstr_garbage_collect_loop
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,23 @@ peek_under_roms_via_OLDTXT:
|
|||||||
jmp peek_under_roms_finalize
|
jmp peek_under_roms_finalize
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
peek_under_roms_via_VARPNT:
|
||||||
|
|
||||||
|
// Unmap BASIC lower ROM
|
||||||
|
|
||||||
|
lda #$26
|
||||||
|
sta CPU_R6510
|
||||||
|
|
||||||
|
// Retrieve value from under ROMs
|
||||||
|
|
||||||
|
lda (VARPNT), y
|
||||||
|
|
||||||
|
#if HAS_OPCODES_65C02
|
||||||
|
bra peek_under_roms_finalize
|
||||||
|
#else
|
||||||
|
jmp peek_under_roms_finalize
|
||||||
|
#endif
|
||||||
|
|
||||||
peek_under_roms_via_DSCPNT:
|
peek_under_roms_via_DSCPNT:
|
||||||
|
|
||||||
// Unmap BASIC lower ROM
|
// Unmap BASIC lower ROM
|
||||||
|
|||||||
Reference in new issue
Block a user