summaryrefslogtreecommitdiff
path: root/emu/6502.c
diff options
context:
space:
mode:
Diffstat (limited to 'emu/6502.c')
-rw-r--r--emu/6502.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/emu/6502.c b/emu/6502.c
index 5baaf32..ce1f0d3 100644
--- a/emu/6502.c
+++ b/emu/6502.c
@@ -11,7 +11,7 @@ static const uint16_t SP_base = 0x100;
void cpu_6502_init( cpu_6502_t *cpu, struct memory_t *memory )
{
cpu->memory = memory;
- cpu->debug = false;
+ cpu->debug_flags = 0;
}
uint16_t cpu_6502_read_word( cpu_6502_t *cpu, uint16_t addr )
@@ -78,8 +78,14 @@ 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 )
{
- for( int i = 0; i < steps; i++ ) {
- cpu_6502_step( cpu );
+ if( steps != -1 ) {
+ for( int i = 0; i < steps; i++ ) {
+ cpu_6502_step( cpu );
+ }
+ } else {
+ while( true ) {
+ cpu_6502_step( cpu );
+ }
}
}
@@ -184,9 +190,13 @@ void cpu_6502_step( cpu_6502_t *cpu )
opcode = cpu_6502_read_byte( cpu, cpu->PC );
cpu->PC++;
- if( cpu->debug ) {
+ if( cpu->debug_flags & DEBUG_STATUS ) {
cpu_6502_print_state( cpu, opcode );
+ }
+ if( cpu->debug_flags & DEBUG_STACK ) {
cpu_6502_print_stack( cpu );
+ }
+ if( cpu->debug_flags & DEBUG_ZERO_PAGE ) {
cpu_6502_print_zerop_page( cpu );
}
@@ -236,7 +246,7 @@ void cpu_6502_step( cpu_6502_t *cpu )
case STX_ABS:
operand16 = cpu_6502_read_word( cpu, cpu->PC );
cpu->PC += 2;
- cpu_6502_write_word( cpu, operand16, cpu->X );
+ cpu_6502_write_byte( cpu, operand16, cpu->X );
break;
case DEY_IMPL: