From 164d090a43711ff984107e5c669f25d0511ee059 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 2 Jul 2020 17:24:34 +0200 Subject: [PATCH] some preparations for string variables, added BASIC command COLD --- doc/Extended-BASIC.md | 4 + src/aliases/,aliases_ram_lowmem.s | 8 +- src/basic/,imports.s | 1 + .../basic_commands_CC/cmd__jumptable_CC.s | 3 +- src/basic/basic_commands_CC/cmd_cold.s | 12 ++ .../basic_commands_CC/helper_ask_if_sure.s | 65 +++++++++++ src/basic/basic_operators/oper_add.s | 2 +- src/basic/editor/shell.s | 5 + src/basic/engine/alloc_temp_string.s | 26 ----- src/basic/engine/varstr_alloc.s | 106 ++++++++++++++++++ src/basic/engine/varstr_dealloc.s | 9 ++ src/basic/engine/varstr_garbage_collect.s | 8 ++ src/basic/memory/shift_mem_adapt_pointers.s | 6 +- src/basic/memory/shift_mem_aliases.s | 9 ++ src/basic/memory/shift_mem_down.s | 2 +- src/basic/memory/shift_mem_up.s | 2 +- src/kernal/init/fffc.vector_reset.s | 2 + src/kernal/interrupts/fffa.vector_nmi.s | 2 + src/kernal/interrupts/fffe.vector_irq.s | 2 + testsuite/testdisk.d64 | Bin 174848 -> 174848 bytes tools/generate_strings.cc | 8 +- 21 files changed, 240 insertions(+), 42 deletions(-) create mode 100644 src/basic/basic_commands_CC/cmd_cold.s create mode 100644 src/basic/basic_commands_CC/helper_ask_if_sure.s delete mode 100644 src/basic/engine/alloc_temp_string.s create mode 100644 src/basic/engine/varstr_alloc.s create mode 100644 src/basic/engine/varstr_dealloc.s create mode 100644 src/basic/engine/varstr_garbage_collect.s create mode 100644 src/basic/memory/shift_mem_aliases.s diff --git a/doc/Extended-BASIC.md b/doc/Extended-BASIC.md index dd48b323..5837fe4c 100644 --- a/doc/Extended-BASIC.md +++ b/doc/Extended-BASIC.md @@ -41,6 +41,10 @@ Launches a built-in tape head alignment tool. Destorys program in memory. Press ## Additional BASIC commands +### `COLD` + +Resets the machine. In direct mode asks for confirmation firsts. + ### `FAST` Tries to switch the machine to turbo mode - details differ depending on the configured machine / motherboard. diff --git a/src/aliases/,aliases_ram_lowmem.s b/src/aliases/,aliases_ram_lowmem.s index eb492b70..6468f572 100644 --- a/src/aliases/,aliases_ram_lowmem.s +++ b/src/aliases/,aliases_ram_lowmem.s @@ -52,7 +52,7 @@ .label OPPTR = $4B // $4B-$4C helper variable for expression computation, [!] our usage details are different .label OPMASK = $4D // -- NOT IMPLEMENTED -- .label DEFPNT = $4E // $4E-$4F -- NOT IMPLEMENTED -- - .label DSCPNT = $50 // $50-$52 -- NOT IMPLEMENTED -- + .label DSCPNT = $50 // $50-$52 temporary area fro string handling, [!] our usage might differ .label FOUR6 = $53 // -- NOT IMPLEMENTED -- .label JMPER = $54 // $54-$56 -- NOT IMPLEMENTED -- .label TEMPF1 = $57 // $57-$5B BASIC numeric work area @@ -71,12 +71,6 @@ .label FAC2_mantissa = $6A // $6A - $6D .label FAC2_sign = $6E - // We re-use FAC2 for memory move pointers, since we cannot be doing calculations while moving memory - .label memmove__src = $69 - .label memmove__dst = $6B - .label memmove__size = $6D - - .label ARISGN = $6F // -- NOT IMPLEMENTED -- .label FACOV = $70 // FAC1 low order mantissa .label FBUFPT = $71 // $71-$72 -- NOT IMPLEMENTED -- diff --git a/src/basic/,imports.s b/src/basic/,imports.s index 8b3c1e45..cbe1dc6f 100644 --- a/src/basic/,imports.s +++ b/src/basic/,imports.s @@ -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 diff --git a/src/basic/basic_commands_CC/cmd__jumptable_CC.s b/src/basic/basic_commands_CC/cmd__jumptable_CC.s index 52a9cb50..cc85d4f9 100644 --- a/src/basic/basic_commands_CC/cmd__jumptable_CC.s +++ b/src/basic/basic_commands_CC/cmd__jumptable_CC.s @@ -15,7 +15,8 @@ cmd_bsave, cmd_bverify, - cmd_old + cmd_old, + cmd_cold ) diff --git a/src/basic/basic_commands_CC/cmd_cold.s b/src/basic/basic_commands_CC/cmd_cold.s new file mode 100644 index 00000000..fe197941 --- /dev/null +++ b/src/basic/basic_commands_CC/cmd_cold.s @@ -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 diff --git a/src/basic/basic_commands_CC/helper_ask_if_sure.s b/src/basic/basic_commands_CC/helper_ask_if_sure.s new file mode 100644 index 00000000..f68a92f9 --- /dev/null +++ b/src/basic/basic_commands_CC/helper_ask_if_sure.s @@ -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 diff --git a/src/basic/basic_operators/oper_add.s b/src/basic/basic_operators/oper_add.s index 2670de2e..2b3a0632 100644 --- a/src/basic/basic_operators/oper_add.s +++ b/src/basic/basic_operators/oper_add.s @@ -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 diff --git a/src/basic/editor/shell.s b/src/basic/editor/shell.s index 94e093c5..5d66c48b 100644 --- a/src/basic/editor/shell.s +++ b/src/basic/editor/shell.s @@ -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 diff --git a/src/basic/engine/alloc_temp_string.s b/src/basic/engine/alloc_temp_string.s deleted file mode 100644 index 1701c78d..00000000 --- a/src/basic/engine/alloc_temp_string.s +++ /dev/null @@ -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 diff --git a/src/basic/engine/varstr_alloc.s b/src/basic/engine/varstr_alloc.s new file mode 100644 index 00000000..b44efd1e --- /dev/null +++ b/src/basic/engine/varstr_alloc.s @@ -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 diff --git a/src/basic/engine/varstr_dealloc.s b/src/basic/engine/varstr_dealloc.s new file mode 100644 index 00000000..a3912f4b --- /dev/null +++ b/src/basic/engine/varstr_dealloc.s @@ -0,0 +1,9 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +varstr_dealloc: + + rts // XXX implement this + \ No newline at end of file diff --git a/src/basic/engine/varstr_garbage_collect.s b/src/basic/engine/varstr_garbage_collect.s new file mode 100644 index 00000000..7683d587 --- /dev/null +++ b/src/basic/engine/varstr_garbage_collect.s @@ -0,0 +1,8 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +varstr_garbage_collect: + + rts // XXX implement this diff --git a/src/basic/memory/shift_mem_adapt_pointers.s b/src/basic/memory/shift_mem_adapt_pointers.s index 072615a3..497b66bb 100644 --- a/src/basic/memory/shift_mem_adapt_pointers.s +++ b/src/basic/memory/shift_mem_adapt_pointers.s @@ -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 diff --git a/src/basic/memory/shift_mem_aliases.s b/src/basic/memory/shift_mem_aliases.s new file mode 100644 index 00000000..6acd142f --- /dev/null +++ b/src/basic/memory/shift_mem_aliases.s @@ -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 diff --git a/src/basic/memory/shift_mem_down.s b/src/basic/memory/shift_mem_down.s index 7a6e41df..7e5c4c02 100644 --- a/src/basic/memory/shift_mem_down.s +++ b/src/basic/memory/shift_mem_down.s @@ -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. // diff --git a/src/basic/memory/shift_mem_up.s b/src/basic/memory/shift_mem_up.s index 320c01db..7af21766 100644 --- a/src/basic/memory/shift_mem_up.s +++ b/src/basic/memory/shift_mem_up.s @@ -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. // diff --git a/src/kernal/init/fffc.vector_reset.s b/src/kernal/init/fffc.vector_reset.s index c8322445..32fb6c03 100644 --- a/src/kernal/init/fffc.vector_reset.s +++ b/src/kernal/init/fffc.vector_reset.s @@ -6,4 +6,6 @@ // $FFFC - CPU Reset Vector // Uncontrovertial, as it is a CPU requirement, and nothing else. +vector_reset: + .word hw_entry_reset diff --git a/src/kernal/interrupts/fffa.vector_nmi.s b/src/kernal/interrupts/fffa.vector_nmi.s index c33c2602..16089345 100644 --- a/src/kernal/interrupts/fffa.vector_nmi.s +++ b/src/kernal/interrupts/fffa.vector_nmi.s @@ -6,4 +6,6 @@ // $FFFA - CPU NMI Hanlder // Uncontrovertial as this is also a CPU requirement. +vector_nmi: + .word hw_entry_nmi diff --git a/src/kernal/interrupts/fffe.vector_irq.s b/src/kernal/interrupts/fffe.vector_irq.s index 755e9c57..ba5a1f6f 100644 --- a/src/kernal/interrupts/fffe.vector_irq.s +++ b/src/kernal/interrupts/fffe.vector_irq.s @@ -7,4 +7,6 @@ // This is non-controvertial, as it is a 6502 CPU requirement, and we just have to point // it to whatever IRQ routine we make. +vector_irq: + .word hw_entry_irq diff --git a/testsuite/testdisk.d64 b/testsuite/testdisk.d64 index a455d2ee8fc3863fbc0022af6383ad7b1d85193c..5cb877cf82a0d821e7743b9efdb8672310be58bf 100644 GIT binary patch delta 98 zcmZp;#?=5sTNoJw#ibZI#5lMZ7#yuYKw+kmBM2yMWPHJ~EsD{Fn@#Y~Z+^i))BREz g#il2uG9Hp`5@ZZ<4Gvj=1Q=j|v5|2rBjZ6A0GI_Gs{jB1 delta 44 zcmZp;#?=5sTNoJwH!}a{*cQd;!p$c1?>E2TpXq+7jAGLhQW+05vTS8xyypS{ei{&Q diff --git a/tools/generate_strings.cc b/tools/generate_strings.cc index bfbd08e0..2bddb6e7 100644 --- a/tools/generate_strings.cc +++ b/tools/generate_strings.cc @@ -178,11 +178,14 @@ const StringEntryList GLOBAL_Keywords_V2 = { ListType::KEYWORDS, "keywords_V2", const StringEntryList GLOBAL_Keywords_CC = { ListType::KEYWORDS, "keywords_CC", { // STD M65 U64 X16 - { true, true, true, true, "KCC_01", "MERGE", }, // OpenROMs specific, not present in CBM BASIC dialects + { true, true, true, true, "KCC_01", "MERGE", }, // Not present in CBM BASIC dialects, but common to some extensions (*) { true, true, true, true, "KCC_02", "BLOAD", }, // http://www.antonis.de/qbebooks/gwbasman/bload.html { true, true, true, true, "KCC_03", "BSAVE", }, // http://www.antonis.de/qbebooks/gwbasman/bsave.html { true, true, true, true, "KCC_04", "BVERIFY", }, - { true, true, true, true, "KCC_05", "OLD", }, // OpenROMs specific, not present in CBM BASIC dialects + { true, true, true, true, "KCC_05", "OLD", }, // Not present in CBM BASIC dialects, but common to some extensions (*) + { true, true, true, true, "KCC_06", "COLD", }, // Not present in CBM BASIC dialects, but common to some extensions (*) + + // (*) see https://sourceforge.net/p/vice-emu/code/HEAD/tree/trunk/vice/src/petcat.c } }; // extended BASIC keywords - reserved for BASIC commands likely making sense on most C64-compatible machines @@ -310,6 +313,7 @@ const StringEntryList GLOBAL_MiscStrings = { ListType::STRINGS_BASIC, "misc", { true, true, true, true, "STR_READY", "\rREADY.\r" }, // https://www.ibm.com/support/knowledgecenter/zosbasics/com.ibm.zos.zconcepts/zconc_whatistsonative.htm https://github.com/stefanhaustein/expressionparser { true, true, true, true, "STR_ERROR", " ERROR" }, // simply the word error that is attached to the other parts of messages https://fjkraan.home.xs4all.nl/comp/apple2faq/app2asoftfaq.html { true, true, true, true, "STR_IN", " IN " }, + { true, true, true, true, "STR_IF_SURE", "\rARE YOU SURE? " }, // https://docs.microsoft.com/en-us/windows/win32/uxguide/mess-confirm // STD M65 U64 X16 --- misc strings specific to OpenROMs, not present in CBM ROMs { true, true, true, true, "STR_BRK_AT", "\rBRK AT $" }, // Note: depending on configuration, additional strings will be added here