summaryrefslogtreecommitdiff
path: root/emu/6502.c
diff options
context:
space:
mode:
Diffstat (limited to 'emu/6502.c')
-rw-r--r--emu/6502.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/emu/6502.c b/emu/6502.c
index c52373f..139b6f6 100644
--- a/emu/6502.c
+++ b/emu/6502.c
@@ -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++;