fixed NEW/CLR commands, implemented RESTORE

This commit is contained in:
FeralChild64 committed 2020-06-28 11:35:29 +02:00
1 parent 2ddfacd8e9
commit 0460777fe9
15 files changed
+191 -115

No files matched your search

@@ -27,8 +27,6 @@ cmd_let:
nop
cmd_if:
nop
cmd_restore:
nop
cmd_gosub:
nop
cmd_return:
+1 -1
View File
@@ -5,7 +5,7 @@
cmd_clr:
jsr basic_do_clr
jsr do_clr
// CLR command does not stop execution (confirmed on a C64)
+1 -1
View File
@@ -56,7 +56,7 @@ cmd_load_no_error:
// C64 BASIC apparently does not clear variables after a LOAD in the
// middle of a program. For safety, we do.
jsr basic_do_clr
jsr do_clr
// Now relink the loaded program, as we cannot trust the line
// links supplied. For example, the VICE virtual drive emulation
+1 -1
View File
@@ -5,7 +5,7 @@
cmd_new:
jsr basic_do_new
jsr do_new
// NEW command terminates execution (confirmed on a C64)
+12
View File
@@ -0,0 +1,12 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_restore:
jsr do_restore
// RESTORE command does not stop execution (confirmed on a C64)
jmp execute_statements
+1 -1
View File
@@ -5,7 +5,7 @@
cmd_run:
// RUN clears all variables
jsr basic_do_clr
jsr do_clr
cmd_goto:
// Disable Kernal messages
lda #$00
+1 -1
View File
@@ -40,7 +40,7 @@ cmd_merge_no_error:
sty VARTAB+1
// Clear the variables
jsr basic_do_clr
jsr do_clr
// Now relink the loaded program, line links supplied are almost certainly wrong
-99
View File
@@ -1,99 +0,0 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# M65 * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
basic_do_new:
#if (ROM_LAYOUT_M65 && SEGMENT_BASIC_0)
jsr map_BASIC_1
jsr_ind VB1__basic_do_new
jmp map_NORMAL
basic_do_clr:
jsr map_BASIC_1
jsr_ind VB1__basic_do_clr
jmp map_NORMAL
#else
// Setup pointers to memory storage XXX should depend on text start vector
lda #<$0801
sta TXTTAB+0
lda #>$0801
sta TXTTAB+1
sta VARTAB+1
lda #<$0803
sta VARTAB+0
// Zero line pointer
// XXX - We should also zero $0800, i.e., TXTTAB - 1
ldy #$00
tya
sta (TXTTAB),y
iny
sta (TXTTAB),y
// Get top of memory.
// If a cart is present, then it is $7FFF,
// if not, then it is $F7FF, since we support having
// programs and variables under ROM.
// i.e., we support 56KB RAM for BASIC, keeping some space
// free for some optimisation structures, e.g., FOR/NEXT loop
// records (without them going on the stack), GOSUB stack
// (same story), expression value cache?
sec // Read, not write value
jsr JMEMTOP
cpx #$80
beq !+
#if CONFIG_MEMORY_MODEL_60K
lda #>$F7FF
#elif CONFIG_MEMORY_MODEL_50K
lda #>$D000
#elif CONFIG_MEMORY_MODEL_46K
lda #>$C000
#else // CONFIG_MEMORY_MODEL_38K
lda #>$A000
#endif
skip_2_bytes_trash_nvz
!:
lda #>$8000
sta MEMSIZ+1
sta FRETOP+1
#if CONFIG_MEMORY_MODEL_60K
cpx #$80
beq !+
lda #$FF
skip_2_bytes_trash_nvz
!:
lda #<$00
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
lda #<$00
#endif
sta MEMSIZ+0
sta FRETOP+0
// FALLTHROUGH
basic_do_clr:
// XXX shouldnt FRETOP go here?
// Clear variables, arrays and strings
lda VARTAB+0
sta ARYTAB+0
sta STREND+0
lda VARTAB+1
sta ARYTAB+1
sta STREND+1
rts
#endif // ROM layout
@@ -17,8 +17,9 @@
.label VB1__list_single_line = $4000 + 2 * 3
.label VB1__print_packed_error = $4000 + 2 * 4
.label VB1__print_packed_misc_str = $4000 + 2 * 5
.label VB1__basic_do_clr = $4000 + 2 * 6
.label VB1__basic_do_new = $4000 + 2 * 7
.label VB1__do_new = $4000 + 2 * 6
.label VB1__do_clr = $4000 + 2 * 7
.label VB1__do_restore = $4000 + 2 * 8
#else
@@ -30,7 +31,8 @@
.word list_single_line
.word print_packed_error
.word print_packed_misc_str
.word basic_do_clr
.word basic_do_new
.word do_new
.word do_clr
.word do_restore
#endif
+1
View File
@@ -11,6 +11,7 @@
.label peek_via_OLDTXT = BASIC_0.proxy_B1_peek_via_OLDTXT
.label poke_via_OLDTXT = BASIC_0.proxy_B1_poke_via_OLDTXT
.label JCHROUT = BASIC_0.proxy_B1_JCHROUT
.label JCLALL = BASIC_0.proxy_B1_JCLALL
.label JMEMTOP = KERNAL_0.JMEMTOP
.label plot_set = KERNAL_0.plot_set
.label init_oldtxt = BASIC_0.init_oldtxt
+8
View File
@@ -30,6 +30,13 @@ proxy_B1_poke_via_OLDTXT:
jmp map_BASIC_1
proxy_B1_JCLALL:
jsr map_NORMAL
jsr JCLALL
jmp map_BASIC_1
proxy_B1_JCHROUT:
jsr map_NORMAL
@@ -57,6 +64,7 @@ proxy_B1_print_space:
jsr print_space
jmp map_BASIC_1
#if CONFIG_SHOW_FEATURES
proxy_B1_print_features:
+1 -1
View File
@@ -147,7 +147,7 @@ shell_process_line:
shell_add_delete_line:
// First, clear all variables, so that we only have to shove BASIC text around
jsr basic_do_clr
jsr do_clr
// Check if line already present
jsr find_line
+103
View File
@@ -0,0 +1,103 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# M65 * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
// See https://www.c64-wiki.com/wiki/Memory_(BASIC) for BASIC memory organization
do_new:
#if (ROM_LAYOUT_M65 && SEGMENT_BASIC_0)
jsr map_BASIC_1
jsr_ind VB1__do_new
jmp map_NORMAL
do_clr:
jsr map_BASIC_1
jsr_ind VB1__do_clr
jmp map_NORMAL
do_restore:
jsr map_BASIC_1
jsr_ind VB1__do_restore
jmp map_NORMAL
#else
// See Computes Mapping the Commodore 64 - page 96
ldy #$00
tya
sta (TXTTAB),y
iny
sta (TXTTAB),y
// The book does not mention this, but IMHO it is necessary to initialize VARTAB here too
clc
lda TXTTAB+0
adc #$02
sta VARTAB+0
lda TXTTAB+1
adc #$00
sta VARTAB+1
do_clr:
// See Computes Mapping the Commodore 64 - page 96
// XXX check on real ROMs that it is being done too when entering new line
jsr JCLALL
lda MEMSIZ+0
sta FRETOP+0
lda MEMSIZ+1
sta FRETOP+1
// The book is not precise here $31-$32 is definitely not the end of BASIC text
lda VARTAB+0
sta ARYTAB+0
sta STREND+0
lda VARTAB+1
sta ARYTAB+1
sta STREND+1
// FALLTROUGH (confirmed on real C64 that CLR indeed resets DATPTR)
do_restore:
// See Computes Mapping the Commodore 64 - page 98
// Initial DATPTR value checked on real C64
#if HAS_OPCODES_65CE02
lda TXTTAB+0
sta DATPTR+0
lda TXTTAB+1
sta DATPTR+1
dew DATPTR
#else
sec
lda TXTTAB+0
sbc #$01
sta DATPTR+0
lda TXTTAB+1
sbc #$00
sta DATPTR+1
#endif
rts
#endif // ROM layout
+53 -2
View File
@@ -10,7 +10,59 @@
initmsg_bytes_free:
jsr basic_do_new
// Setup pointers to BASIC memory storage
lda #<$0801
sta TXTTAB+0
lda #>$0801
sta TXTTAB+1
// Get top of memory.
// If a cart is present, then it is $7FFF,
// if not, then it is $F7FF, since we support having
// programs and variables under ROM.
// i.e., we support 56KB RAM for BASIC, keeping some space
// free for some optimisation structures, e.g., FOR/NEXT loop
// records (without them going on the stack), GOSUB stack
// (same story), expression value cache?
sec // Read, not write value
jsr JMEMTOP
cpx #$80
beq !+
#if CONFIG_MEMORY_MODEL_60K
lda #>$F7FF
#elif CONFIG_MEMORY_MODEL_50K
lda #>$D000
#elif CONFIG_MEMORY_MODEL_46K
lda #>$C000
#else // CONFIG_MEMORY_MODEL_38K
lda #>$A000
#endif
skip_2_bytes_trash_nvz
!:
lda #>$8000
sta MEMSIZ+1
#if CONFIG_MEMORY_MODEL_60K
cpx #$80
beq !+
lda #$FF
skip_2_bytes_trash_nvz
!:
lda #<$00
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
lda #<$00
#endif
sta MEMSIZ+0
// XXX move the part above to a more suitable place
// Initialize other variables by performing NEW
jsr do_new
// Print number of bytes free
sec
lda MEMSIZ+0
sbc TXTTAB+0
@@ -20,6 +72,5 @@ initmsg_bytes_free:
jsr print_integer
// Print rest of the start up message
ldx #IDX__STR_BYTES
jmp print_packed_misc_str