From 9e6a96f93a59af8ae45eaefbade11c61e6654f59 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Sun, 27 Sep 2026 01:21:42 +0200 Subject: [PATCH] Fix BASIC --- msbasic/defines_kilian.s | 25 ++++++++++++------------ msbasic/init.s | 8 ++++++++ src/io.c | 15 +++++++++++++++ src/memoryMap.c | 41 ++++++++++++++++++++++++---------------- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/msbasic/defines_kilian.s b/msbasic/defines_kilian.s index c55b11a..391d925 100644 --- a/msbasic/defines_kilian.s +++ b/msbasic/defines_kilian.s @@ -1,21 +1,20 @@ ; configuration -CONFIG_2A := 1 +CONFIG_2A := 1 CONFIG_SCRTCH_ORDER := 2 ; zero page -ZP_START0 = $00 -ZP_START1 = $02 -ZP_START2 = $0C -ZP_START3 = $62 -ZP_START4 = $6D +ZP_START0 = $00 +ZP_START1 = $02 +ZP_START2 = $0C +ZP_START3 = $62 +ZP_START4 = $6D ; extra/override ZP variables -USR := GORESTART ; XXX +USR := GORESTART ; XXX ; constants -SPACE_FOR_GOSUB := $3E -STACK_TOP := $FA -WIDTH := 40 -WIDTH2 := 30 - -RAMSTART2 := $0400 +SPACE_FOR_GOSUB := $3E +STACK_TOP := $FA +WIDTH := 40 +WIDTH2 := 30 +RAMSTART2 := $0400 diff --git a/msbasic/init.s b/msbasic/init.s index 077d981..f1de786 100644 --- a/msbasic/init.s +++ b/msbasic/init.s @@ -204,9 +204,17 @@ L4098: ldx #TEMPST stx TEMPPT .ifndef CONFIG_CBM_ALL + .ifdef KILIAN + lda #<$BC00 + sta MEMSIZ + lda #>$BC00 + sta MEMSIZ+1 + jmp L4106 + .else lda #QT_MEMORY_SIZE jsr STROUT + .endif .ifdef APPLE jsr INLINX .else diff --git a/src/io.c b/src/io.c index 1cf8616..e73abbe 100644 --- a/src/io.c +++ b/src/io.c @@ -13,5 +13,20 @@ int getChar(void) { int c = getchar(); + // Specifically send FF for EOF to trigger echo cancellation + if (c == EOF) { + return 0xFF; + } + + // BASIC expects CR always + if (c == '\n') { + return '\r'; + } + + // BASIC is uppercase only + if (c >= 'a' && c <= 'z') { + c = c - 'a' + 'A'; + } + return c; } \ No newline at end of file diff --git a/src/memoryMap.c b/src/memoryMap.c index 3f7de6c..a056d42 100644 --- a/src/memoryMap.c +++ b/src/memoryMap.c @@ -26,25 +26,34 @@ uint8_t readMemory(uint16_t address, uint8_t *ram, uint8_t *rom) { } void writeMemory(uint16_t address, uint8_t value, uint8_t *ram) { - if ((address < RAM_SIZE && address < IO_BASE) || address >= ROM_BASE) { - if (address < ROM_BASE && ram[IO_BASE + ROM_BANKED_OUT] != 0) { + /* Normal RAM */ + if (address < IO_BASE) { + ram[address] = value; + return; + } + + /* ROM area */ + if (address >= ROM_BASE) { + if (ram[IO_BASE + ROM_BANKED_OUT] != 0) { ram[address] = value; } - } else { - uint16_t _address = address - IO_BASE; - switch (_address) { - case SCREEN_ADDRESS: { - putChar(value); - break; - } - case ROM_BANKED_OUT: { - ram[IO_BASE + ROM_BANKED_OUT] = value; - break; - } + return; + } - default: - break; - } + /* I/O area */ + uint16_t _address = address - IO_BASE; + + switch (_address) { + case SCREEN_ADDRESS: + putChar(value); + break; + + case ROM_BANKED_OUT: + ram[IO_BASE + ROM_BANKED_OUT] = value; + break; + + default: + break; } }