From 436d726febba609ab582d4475af5e41feceb284d Mon Sep 17 00:00:00 2001 From: RenDev <34013705+sonich2401@users.noreply.github.com> Date: Tue, 13 Dec 2022 23:31:49 -0800 Subject: [PATCH] Err detection fixes and Makefile Improvements --- Makefile | 4 ++-- bus.c | 1 + cpu.c | 37 +++++++++++++++++++------------------ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 4c9c913..cdcb4c8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CC = clang +CC = cc CFLAGS = -g -DDEBUG -static RM = rm -rf OUTFILE = exec @@ -7,7 +7,7 @@ OUTFILE = exec default: all all: - $(CC) bus.c cpu.c cartridge.c -o $(OUTFILE) + $(CC) bus.c cpu.c cartridge.c ppu.c -Ofast -o $(OUTFILE) clean: $(RM) $(OUTFILE) diff --git a/bus.c b/bus.c index 1b97d0b..50998f7 100644 --- a/bus.c +++ b/bus.c @@ -91,6 +91,7 @@ byte debug_read_do_not_use_pls(word address){ static inline void debug_print_instruction(CPU* __restrict__ cpu, byte opcode){ + handleErrors(cpu); printf("\n--name: %s opcode: %02X address: %04X %d %p\n", cpu->opcodes[opcode].name, opcode, diff --git a/cpu.c b/cpu.c index f55ca50..fd41d21 100644 --- a/cpu.c +++ b/cpu.c @@ -1800,6 +1800,21 @@ void printCpu(CPU * __restrict__ cpu){ #undef BYTE_TO_BINARY } +enum ERRORS{ + NORMAL, + OPCODES_OB, + BUS_OB, + UNALLOC_MICRO, + UNALLOC_MODE, + UNALLOC_NAME, + UNALLOC_OP, + UNALLOC_INST, + UNALLOC_CPU, + UNKNOWN_MICRO, + UNKNOWN_MODE, + UNKNOWN_BYTES, + UNKNOWN_CYCLES +}; void raiseError(unsigned int err, CPU * __restrict__ cpu){ const char * ERROR_STR[13]= { @@ -1822,7 +1837,10 @@ void raiseError(unsigned int err, CPU * __restrict__ cpu){ fprintf(stderr, "CRASH!!!!\n\n"); fprintf(stderr, "\tLOCATION: %#06x\n", cpu->PC); fprintf(stderr, "\tOPCODE: %#06x\n", busRead8(cpu->PC)); - fprintf(stderr, "\tNAME: \"%s\"\n", cpu->opcodes[busRead8(cpu->PC)].name); + if(err != UNALLOC_NAME && err != UNALLOC_MICRO) + fprintf(stderr, "\tNAME: \"%s\"\n", cpu->opcodes[busRead8(cpu->PC)].name); + else + fprintf(stderr, "\tNAME: \"%s\"\n", NULL); fprintf(stderr, "\tMICRO: %p\n", cpu->opcodes[busRead8(cpu->PC)].microcode); fprintf(stderr, "\tMODE: %p\n", cpu->opcodes[busRead8(cpu->PC)].mode); exit(err); @@ -1844,23 +1862,6 @@ void print_stack(CPU * __restrict__ cpu){ } void handleErrors(CPU * __restrict__ cpu){ - enum ERRORS{ - NORMAL, - OPCODES_OB, - BUS_OB, - UNALLOC_MICRO, - UNALLOC_MODE, - UNALLOC_NAME, - UNALLOC_OP, - UNALLOC_INST, - UNALLOC_CPU, - UNKNOWN_MICRO, - UNKNOWN_MODE, - UNKNOWN_BYTES, - UNKNOWN_CYCLES - }; - - if(cpu == NULL){ raiseError(UNALLOC_CPU, cpu); }