Err detection fixes and Makefile Improvements

main
RenDev 3 years ago
parent ad59ac8042
commit 436d726feb
  1. 4
      Makefile
  2. 1
      bus.c
  3. 35
      cpu.c

@ -1,4 +1,4 @@
CC = clang CC = cc
CFLAGS = -g -DDEBUG -static CFLAGS = -g -DDEBUG -static
RM = rm -rf RM = rm -rf
OUTFILE = exec OUTFILE = exec
@ -7,7 +7,7 @@ OUTFILE = exec
default: all default: all
all: all:
$(CC) bus.c cpu.c cartridge.c -o $(OUTFILE) $(CC) bus.c cpu.c cartridge.c ppu.c -Ofast -o $(OUTFILE)
clean: clean:
$(RM) $(OUTFILE) $(RM) $(OUTFILE)

@ -91,6 +91,7 @@ byte debug_read_do_not_use_pls(word address){
static inline void debug_print_instruction(CPU* __restrict__ cpu, byte opcode){ static inline void debug_print_instruction(CPU* __restrict__ cpu, byte opcode){
handleErrors(cpu);
printf("\n--name: %s opcode: %02X address: %04X %d %p\n", printf("\n--name: %s opcode: %02X address: %04X %d %p\n",
cpu->opcodes[opcode].name, cpu->opcodes[opcode].name,
opcode, opcode,

35
cpu.c

@ -1800,6 +1800,21 @@ void printCpu(CPU * __restrict__ cpu){
#undef BYTE_TO_BINARY #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){ void raiseError(unsigned int err, CPU * __restrict__ cpu){
const char * ERROR_STR[13]= { const char * ERROR_STR[13]= {
@ -1822,7 +1837,10 @@ void raiseError(unsigned int err, CPU * __restrict__ cpu){
fprintf(stderr, "CRASH!!!!\n\n"); fprintf(stderr, "CRASH!!!!\n\n");
fprintf(stderr, "\tLOCATION: %#06x\n", cpu->PC); fprintf(stderr, "\tLOCATION: %#06x\n", cpu->PC);
fprintf(stderr, "\tOPCODE: %#06x\n", busRead8(cpu->PC)); fprintf(stderr, "\tOPCODE: %#06x\n", busRead8(cpu->PC));
if(err != UNALLOC_NAME && err != UNALLOC_MICRO)
fprintf(stderr, "\tNAME: \"%s\"\n", cpu->opcodes[busRead8(cpu->PC)].name); 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, "\tMICRO: %p\n", cpu->opcodes[busRead8(cpu->PC)].microcode);
fprintf(stderr, "\tMODE: %p\n", cpu->opcodes[busRead8(cpu->PC)].mode); fprintf(stderr, "\tMODE: %p\n", cpu->opcodes[busRead8(cpu->PC)].mode);
exit(err); exit(err);
@ -1844,23 +1862,6 @@ void print_stack(CPU * __restrict__ cpu){
} }
void handleErrors(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){ if(cpu == NULL){
raiseError(UNALLOC_CPU, cpu); raiseError(UNALLOC_CPU, cpu);
} }

Loading…
Cancel
Save