summaryrefslogtreecommitdiff
path: root/emu/6502.c
diff options
context:
space:
mode:
Diffstat (limited to 'emu/6502.c')
-rw-r--r--emu/6502.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/emu/6502.c b/emu/6502.c
index 0bb1993..8b24901 100644
--- a/emu/6502.c
+++ b/emu/6502.c
@@ -76,9 +76,9 @@ void cpu_6502_write_word( cpu_6502_t *cpu, uint16_t addr, uint16_t data )
cpu->memory->write( cpu->memory, addr + 1, ( data && 0x00FF ) );
}
-void cpu_6502_run( cpu_6502_t *cpu )
+void cpu_6502_run( cpu_6502_t *cpu, int steps )
{
- while( true ) {
+ for( int i = 0; i < steps; i++ ) {
cpu_6502_step( cpu );
}
}
@@ -138,7 +138,7 @@ static bool is_carry( cpu_6502_t *cpu )
void cpu_6502_print_state( cpu_6502_t *cpu, uint8_t opcode )
{
- fprintf( stderr, "PC: %04X SP: 01%02X PS: %02X %c%c-%c%c%c%c%c A: %02X X: %02X Y: %02X OP: %02X\n",
+ fprintf( stderr, "PC: %04X SP: 01%02X PS: %02X %c%c-%c%c%c%c%c A: %02X X: %02X Y: %02X OP: %02X steps: %d\n",
cpu->PC, cpu->SP, cpu->PS,
is_negative( cpu ) ? 'N' : 'n',
is_overflow( cpu ) ? 'V' : 'v',
@@ -147,7 +147,7 @@ void cpu_6502_print_state( cpu_6502_t *cpu, uint8_t opcode )
is_interrupt( cpu ) ? 'I' : 'i',
is_zero( cpu ) ? 'Z' : 'z',
is_carry( cpu ) ? 'C' : 'c',
- cpu->A, cpu->X, cpu->Y, opcode );
+ cpu->A, cpu->X, cpu->Y, opcode, cpu->steps );
}
static void update_negative_and_sign( cpu_6502_t *cpu, uint8_t x )
@@ -253,4 +253,6 @@ void cpu_6502_step( cpu_6502_t *cpu )
fprintf( stderr, "ERROR: Illegal opcode %02X at PC %04X\n", opcode, cpu->PC );
exit( EXIT_FAILURE );
}
+
+ cpu->steps++;
}