Add SIGINT handler to emulator to trigger an NMI

This commit is contained in:
s3lph 2022-02-07 10:35:04 +01:00
parent 289266dccc
commit a6b4a97ebe

View file

@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <malloc.h>
#include <string.h>
@ -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();