From 8101cc3f62d95f2764d3c84990f8f2c7c7193f89 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Sun, 27 Sep 2026 02:19:36 +0200 Subject: [PATCH] Config, CTRL+C, exit --- msbasic/defines_kilian.s | 35 +++++++++++++++++++++-------------- msbasic/inline.s | 2 +- msbasic/kilian_extra.s | 9 +++++++-- msbasic/print.s | 2 +- src/io.c | 5 +++++ src/main.c | 29 ++++++++++++++++++----------- 6 files changed, 53 insertions(+), 29 deletions(-) diff --git a/msbasic/defines_kilian.s b/msbasic/defines_kilian.s index 391d925..09c88b3 100644 --- a/msbasic/defines_kilian.s +++ b/msbasic/defines_kilian.s @@ -1,20 +1,27 @@ ; configuration -CONFIG_2A := 1 -CONFIG_SCRTCH_ORDER := 2 +CONFIG_2A := 1 -; zero page -ZP_START0 = $00 -ZP_START1 = $02 -ZP_START2 = $0C -ZP_START3 = $62 -ZP_START4 = $6D +CONFIG_DATAFLG := 1 +CONFIG_EASTER_EGG := 1 +CONFIG_NO_READ_Y_IS_ZERO_HACK := 1 +CONFIG_PEEK_SAVE_LINNUM := 1 +CONFIG_SCRTCH_ORDER := 2 + +; zero page -- CBM BASIC V2 layout +ZP_START1 = $02 +ZP_START2 = $0C +ZP_START3 = $12 +ZP_START4 = $1D + +; input buffer +INPUTBUFFER := $0200 ; 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/inline.s b/msbasic/inline.s index d28ed79..9d25b37 100644 --- a/msbasic/inline.s +++ b/msbasic/inline.s @@ -1,6 +1,6 @@ .segment "CODE" -.ifndef CONFIG_NO_INPUTBUFFER_ZP +.ifndef CONFIG_NO_LINE_EDITING L2420: .ifdef OSI jsr OUTDO diff --git a/msbasic/kilian_extra.s b/msbasic/kilian_extra.s index 8f96738..0955a7a 100644 --- a/msbasic/kilian_extra.s +++ b/msbasic/kilian_extra.s @@ -8,13 +8,18 @@ SAVE: rts ISCNTC: + lda $BC01 + cmp #$03 + beq @break rts +@break: + jmp STOP MONRDKEY: lda $BC01 - bmi MONRDKEY_SKIP_ECHO + bmi @skipped sta $BC00 ; echo -MONRDKEY_SKIP_ECHO: +@skipped: rts MONCOUT: diff --git a/msbasic/print.s b/msbasic/print.s index 6561348..972c9c2 100644 --- a/msbasic/print.s +++ b/msbasic/print.s @@ -93,7 +93,7 @@ LE878: .ifndef KBD L29B9: - .ifdef CBM2 + .ifdef CONFIG_INPUTBUFFER_0200 lda #$00 sta INPUTBUFFER,x ldx #<(INPUTBUFFER-1) diff --git a/src/io.c b/src/io.c index e73abbe..5b7d85c 100644 --- a/src/io.c +++ b/src/io.c @@ -1,6 +1,7 @@ #include "io.h" #include +#include int putChar(uint8_t c) { int _c = putchar(c); @@ -28,5 +29,9 @@ int getChar(void) { c = c - 'a' + 'A'; } + if (c == 0x07) { + exit(EXIT_SUCCESS); + } + return c; } \ No newline at end of file diff --git a/src/main.c b/src/main.c index 48ff9b0..08ba508 100644 --- a/src/main.c +++ b/src/main.c @@ -23,8 +23,10 @@ void set_nonblocking_input(void) { atexit(restore_terminal); raw = orig_termios; - raw.c_lflag &= ~(ICANON | ECHO); // disable line buffering and echo - raw.c_cc[VMIN] = 0; // don't block waiting for input + raw.c_lflag &= ~(ICANON | ECHO); // disable line buffering, echo + /* Ctrl+C becomes ordinary input byte 0x03 */ + raw.c_cc[VINTR] = _POSIX_VDISABLE; + raw.c_cc[VMIN] = 0; // don't block waiting for input raw.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSANOW, &raw); @@ -34,6 +36,9 @@ void set_nonblocking_input(void) { } int main(void) { + printf("6502PC Emulator with MS Basic\n"); + printf("CTRL + G to exit\n"); + uint8_t *ram = NULL; CPU cpu; @@ -43,26 +48,26 @@ int main(void) { if (createRAM(&ram) != 0) { printf("Could not create RAM\n"); - return 1; + exit(EXIT_FAILURE); } /* DEBUG */ - //FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_functional_test.bin", "rb"); - //FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_decimal_test.bin", "rb"); - //FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_functional_test.bin", "rb"); - //FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_decimal_test.bin", "rb"); + // FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_functional_test.bin", "rb"); + // FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_decimal_test.bin", "rb"); + // FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_functional_test.bin", "rb"); + // FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_decimal_test.bin", "rb"); /* if (!fp) { perror("fopen"); - return 1; + exit(EXIT_FAILURE); } fread(ram, 1, RAM_SIZE, fp); if (ferror(fp)) { perror("fread"); fclose(fp); - return 1; + exit(EXIT_FAILURE); } fclose(fp); @@ -76,8 +81,10 @@ int main(void) { while (1) { uint8_t sleep = runCycle(&cpu, ram, rom); if (sleep == 1) { - printf("opcode missing: 0x%X\n", ram[cpu.ProgrammeCounter - 1]); - return 1; + printf("Illegal opcode $%02X at $%04X " + "A=$%02X X=$%02X Y=$%02X SP=$%02X\n", + ram[cpu.ProgrammeCounter - 1], cpu.ProgrammeCounter - 1, cpu.Accumulator, cpu.X, cpu.Y, cpu.StackPointer); + exit(EXIT_FAILURE); } sleepTime.tv_sec = 0; sleepTime.tv_nsec = sleep * (1000 / MACHINE_SPEED_HZ);