more work on variables support

This commit is contained in:
FeralChild64 committed 2020-07-11 20:08:36 +02:00
1 parent 50da40a4f1
commit 6e90102f76
5 files changed
+214 -11

No files matched your search

+129 -2
View File
@@ -77,8 +77,135 @@ fetch_variable_type_string:
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
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