diff options
Diffstat (limited to 'emu/6502.c')
-rw-r--r-- | emu/6502.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -2,7 +2,6 @@ #include "memory.h" #include <stdio.h> -#include <stdlib.h> static const uint16_t reset_vector = 0xFFFC; static const uint16_t ZP_base = 0x0; @@ -13,6 +12,7 @@ void cpu_6502_init( cpu_6502_t *cpu, bus_t *bus, bool initialize ) cpu->bus = bus; cpu->debug_flags = 0; cpu->steps = 0; + cpu->error_state = ERROR_STATE_OK; if( initialize ) { cpu->PC = 0x0000; @@ -88,11 +88,11 @@ void cpu_6502_write_word( cpu_6502_t *cpu, uint16_t addr, uint16_t data ) void cpu_6502_run( cpu_6502_t *cpu, int steps ) { if( steps != -1 ) { - for( int i = 0; i < steps; i++ ) { + for( int i = 1; i <= steps && cpu->error_state == ERROR_STATE_OK; i++ ) { cpu_6502_step( cpu ); } } else { - while( true ) { + while( cpu->error_state == ERROR_STATE_OK ) { cpu_6502_step( cpu ); } } @@ -429,7 +429,7 @@ void cpu_6502_step( cpu_6502_t *cpu ) default: fprintf( stderr, "ERROR: Illegal opcode %02X at PC %04X\n", opcode, cpu->PC ); - exit( EXIT_FAILURE ); + cpu->error_state |= ERROR_STATE_ILLEGAL_OPCODE; } cpu->steps++; |