From a6b4a97ebee1a3da459e23dac36c1805048ee414 Mon Sep 17 00:00:00 2001 From: s3lph Date: Mon, 7 Feb 2022 10:35:04 +0100 Subject: [PATCH] Add SIGINT handler to emulator to trigger an NMI --- src/emu6502.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/emu6502.c b/src/emu6502.c index a831984..0cc2e27 100644 --- a/src/emu6502.c +++ b/src/emu6502.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -12,6 +13,7 @@ extern uint32_t instructions; extern void reset6502(void); extern void step6502(void); +extern void nmi6502(void); uint8_t *ram, *screen, *f000; @@ -56,6 +58,10 @@ void write6502(uint16_t address, uint8_t value) { ram[address] = value; } } else if (address >= 0x8000 && address <= 0x8fff) { + // Replace non-printable characters with dot + if (value < 32 || value > 126) { + value = '.'; + } printf("%08x: WRITE %04x <- %02x, SCREEN(%d,%d)\n", instructions, address, value, (address&0x03ff)%40, (address&0x03ff)/40); screen[address & 0x03ff] = value; } else { @@ -63,6 +69,11 @@ void write6502(uint16_t address, uint8_t value) { } } +// Trigger a NMI on SIGINT +void intv(int foo) { + nmi6502(); +} + int main() { ram = (uint8_t*) malloc(RAMSIZE); screen = (uint8_t*) malloc(0x400); @@ -71,6 +82,7 @@ int main() { f000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, ffd, 0); reset6502(); + signal(SIGINT, intv); while (1) { usleep(1); step6502();