some preparations for string variables, added BASIC command COLD

This commit is contained in:
FeralChild64 committed 2020-07-02 17:24:34 +02:00
1 parent 34b56b1fd5
commit 164d090a43
21 files changed
+240 -42

No files matched your search

+1
View File
@@ -32,6 +32,7 @@
.label panic = KERNAL().panic
#endif
.label vector_reset = KERNAL().vector_reset
.label hw_entry_reset = KERNAL().hw_entry_reset
#if CONFIG_DBG_PRINTF
@@ -15,7 +15,8 @@
cmd_bsave,
cmd_bverify,
cmd_old
cmd_old,
cmd_cold
)
+12
View File
@@ -0,0 +1,12 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
cmd_cold:
jsr helper_ask_if_sure
bcs_16 execute_statements
jsr JCLALL // for extra safety
jmp (vector_reset) // hardware CPU vector
@@ -0,0 +1,65 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// For direct mode, asks the user if he is sure (sets Carry if not);
// otherwise returns with Carry clear
//
helper_ask_if_sure:
// First check, if we are in direct mode,; if not, do not ask
ldx CURLIN+1
inx
bne helper_ask_if_sure_ok // branch if not direct mode
// Not direct mode - display the question
ldx #IDX__STR_IF_SURE
jsr print_packed_misc_str
// Clear the keyboard queue
lda #$00
sta NDX
// Enable cursor, fetch the answer
lda #$00
sta BLNSW
!:
jsr JGETIN
cmp #$00
beq !-
// Check if 'Y'
cmp #$59
beq !+
lda #$4E // 'N'
jsr JCHROUT
sec
rts
!:
// Display 'Y' and wait a short moment for a better user experience
jsr JCHROUT
clc
lda TIME+0
adc #$0C
!:
cmp TIME+0
bne !-
// FALLTROUGH
helper_ask_if_sure_ok:
clc
rts
+1 -1
View File
@@ -58,7 +58,7 @@ oper_add_strings:
adc __FAC2+0
bcs_16 do_STRING_TOO_LONG_error
jsr alloc_temp_string
// jsr alloc_temp_string
.break
+5
View File
@@ -9,6 +9,11 @@ shell_main_loop:
ldx #IDX__STR_READY
jsr print_packed_misc_str
// Mark mode as direct
lda #$FF
sta CURLIN+1
// Enable Kernal messages
lda #$80
jsr JSETMSG
-26
View File
@@ -1,26 +0,0 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Allocates area for a temporary string
//
// Input:
// - .A - string length
//
// XXX - finish the implementation once string memory handling is done
alloc_temp_string:
// Check if temporary descriptor stack has a free slot
ldx LASTPT
cpx #$1F
bcs_16 do_FORMULA_TOO_COMPLEX_error
// XXX
jmp do_NOT_IMPLEMENTED_error
+106
View File
@@ -0,0 +1,106 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Allocates memory for string - lowers FRETOP (but not below STREND)
//
// Note: We are not going to use the C64-style memory management here, as it implies
// a very slow garbage collector. Instead, we are using a scheme similar to used in
// BASIC V3.5 and later, with 'back-pointers' after each string, telling about the
// location of the string descriptor.
//
// See:
// - https://www.c64-wiki.com/wiki/Memory_(BASIC)
// - https://sites.google.com/site/h2obsession/CBM/basic/variable-format
//
// Input:
// - DSCPNT+0, DSCPNT+1 - pointer to string descriptor, first pointed byte should contain desired length
//
varstr_alloc:
// Mark garbage collector as not run yet
lda #$00
// FALLTROUGH
varstr_alloc_retry:
sta GARBFL // Computes Mapping the Commodore 64, page 10
// Backup FRETOP in case of alocation problems
lda FRETOP+0
sta INDEX+0
lda FRETOP+1
sta INDEX+1
// Lower FRETOP to make space for string descriptor
#if !HAS_OPCODES_65CE02
lda #$02
jsr varstr_FRETOP_down
#else // HAS_OPCODES_65CE02
dew FRETOP
dew FRETOP
#endif
jsr varstr_FRETOP_check
bcs varstr_alloc_fail
// XXX finish this
varstr_alloc_fail:
// Unable to alocate memory - restore FRETOP value
lda INDEX+0
sta FRETOP+0
lda INDEX+1
sta FRETOP+1
// Check if it is worth to perform garbage collection and retry
bit GARBFL
// XXX finish this
// XXX move these helper routines to a better place
varstr_FRETOP_down: // memmove__tmp - length to lower FRETOP
sec
lda FRETOP+0
sbc memmove__tmp
sta FRETOP+0
bcs !+
dec FRETOP+1
!:
rts
varstr_FRETOP_check:
// Check if FRETOP > STREND, Carry set if not
lda STREND+1
cmp FRETOP+1
beq !+
rts
!:
lda STREND+0
cmp FRETOP+0
rts
+9
View File
@@ -0,0 +1,9 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
varstr_dealloc:
rts // XXX implement this
@@ -0,0 +1,8 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
varstr_garbage_collect:
rts // XXX implement this
+3 -3
View File
@@ -9,13 +9,13 @@
shift_mem_adapt_pointers:
sty RESHO+4
sty memmove__tmp
// Adapt source pointer
sec
lda memmove__src+0
sbc RESHO+4
sbc memmove__tmp
sta memmove__src+0
bcs !+
dec memmove__src+1
@@ -24,7 +24,7 @@ shift_mem_adapt_pointers:
sec
lda memmove__dst+0
sbc RESHO+4
sbc memmove__tmp
sta memmove__dst+0
bcs !+
dec memmove__dst+1
+9
View File
@@ -0,0 +1,9 @@
//
// Aliases for memory locations for memory block copy routines
//
.label memmove__src = INDEX+2
.label memmove__dst = RESHO+0
.label memmove__size = RESHO+2
.label memmove__tmp = RESHO+4
+1 -1
View File
@@ -11,7 +11,7 @@
// - memmove__dst - pointer to the first byte of destination
// - memmove__size - number of bytes to copy
//
// All the input variables, .A, and .Y register, are destroyed. Also uses RESHO+4 variable.
// All the input variables, .A, and .Y register, are destroyed. Also uses memmove__tmp variable.
//
+1 -1
View File
@@ -11,7 +11,7 @@
// - memmove__dst - pointer to the last byte of destination
// - memmove__size - number of bytes to copy
//
// All the input variables, .A, and .Y register, are destroyed. Also uses RESHO+4 variable.
// All the input variables, .A, and .Y register, are destroyed. Also uses memmove__tmp variable.
//