#include #include #include #include #include #include #include #include extern uint32_t instructions; extern void reset6502(void); extern void step6502(void); uint8_t *ram, *screen, *a000, *b000, *c000, *d000, *e000, *f000; uint8_t read6502(uint16_t address) { if (address == 0xf27e) { printf("DONE\n"); exit(0); } uint8_t value = 0x00; if (address < 0x4000) { // emulate memory error in uppermost page if (address >= 0x3ff0) { value = ram[address] & 0xf7; } else { value = ram[address]; } printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else if (address >= 0x8000 && address <= 0x8fff) { // screen buffer is mirrored 4 times, discard upper 2 bytes value = screen[address & 0x03ff]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else if (address >= 0xa000 && address <= 0xafff) { value = a000[address-0xa000]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else if (address >= 0xb000 && address <= 0xbfff) { value = b000[address-0xb000]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else if (address >= 0xc000 && address <= 0xcfff) { value = c000[address-0xc000]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else if (address >= 0xd000 && address <= 0xdfff) { value = d000[address-0xd000]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else if (address >= 0xe000 && address <= 0xe7ff) { value = e000[address-0xe000]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else if (address >= 0xf000) { value = f000[address-0xf000]; printf("%08x: READ %04x -> %02x\n", instructions, address, value); } else { printf("%08x: READ %04x -> not implemented\n", instructions, address); } return value; } void write6502(uint16_t address, uint8_t value) { if (address < 0x4000) { printf("%08x: WRITE %04x <- %02x\n", instructions, address, value); ram[address] = value; } else if (address >= 0x800 && address <= 0x8fff) { printf("%08x: WRITE %04x <- %02x, SCREEN(%d,%d)\n", instructions, address, value, (address&0x03ff)%40, (address&0x03ff)/40); screen[address & 0x03ff] = value; } else { printf("%08x: WRITE %04x <- %02x; READONLY\n", instructions, address, value); } } int main() { ram = (uint8_t*) malloc(0x4000); screen = (uint8_t*) malloc(0x400); memset(screen, 'X', 0x400); int afd = open("memtest-9000.901465.bin", O_RDONLY); a000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, afd, 0); int bfd = open("memtest-9000.901465.bin", O_RDONLY); b000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, bfd, 0); int cfd = open("basic-2-c000.901465-01.bin", O_RDONLY); c000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, cfd, 0); int dfd = open("basic-2-d000.901465-02.bin", O_RDONLY); d000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, dfd, 0); int efd = open("edit-2-n.901447-24.bin", O_RDONLY); e000 = mmap(0, 0x0800, PROT_READ, MAP_PRIVATE, efd, 0); //int ffd = open("kernal-2.901465-03.bin", O_RDONLY); int ffd = open("memtest-f000.901465+ascii.bin", O_RDONLY); f000 = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE, ffd, 0); reset6502(); while (1) { usleep(1); step6502(); printf("pass: %02x, address: %02x%02x\n", ram[4], ram[1], ram[2]); printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n"); for (uint8_t row = 0; row < 25; ++row) { printf("┃%.40s┃\n", screen + 40*row); } printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n"); } }