summaryrefslogtreecommitdiff
path: root/emu/6502.c
diff options
context:
space:
mode:
Diffstat (limited to 'emu/6502.c')
-rw-r--r--emu/6502.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/emu/6502.c b/emu/6502.c
index 139b6f6..ff178f9 100644
--- a/emu/6502.c
+++ b/emu/6502.c
@@ -116,37 +116,37 @@ static void handle_sign( cpu_6502_t *cpu, uint8_t x )
}
}
-static bool is_negative( cpu_6502_t *cpu )
+bool cpu_6502_is_negative( cpu_6502_t *cpu )
{
return cpu->PS & PS_N;
}
-static bool is_overflow( cpu_6502_t *cpu )
+bool cpu_6502_is_overflow( cpu_6502_t *cpu )
{
return cpu->PS & PS_V;
}
-static bool is_brk( cpu_6502_t *cpu )
+bool cpu_6502_is_brk( cpu_6502_t *cpu )
{
return cpu->PS & PS_B;
}
-static bool is_decimal( cpu_6502_t *cpu )
+bool cpu_6502_is_decimal( cpu_6502_t *cpu )
{
return cpu->PS & PS_D;
}
-static bool is_interrupt( cpu_6502_t *cpu )
+bool cpu_6502_is_interrupt( cpu_6502_t *cpu )
{
return cpu->PS & PS_I;
}
-static bool is_zero( cpu_6502_t *cpu )
+bool cpu_6502_is_zero( cpu_6502_t *cpu )
{
return cpu->PS & PS_Z;
}
-static bool is_carry( cpu_6502_t *cpu )
+bool cpu_6502_is_carry( cpu_6502_t *cpu )
{
return cpu->PS & PS_C;
}
@@ -198,6 +198,19 @@ void cpu_6502_get_opcode_mnemonic( cpu_6502_t *cpu, char *buf, int buflen, uint1
snprintf( buf, buflen, "%s (%02X)", mnemonic[opcode], opcode );
}
+
+void cpu_6502_print_debug( cpu_6502_t *cpu )
+{
+ if( cpu->debug_flags & DEBUG_STATUS ) {
+ cpu_6502_print_state( cpu, cpu->PC-1 );
+ }
+ if( cpu->debug_flags & DEBUG_STACK ) {
+ cpu_6502_print_stack( cpu );
+ }
+ if( cpu->debug_flags & DEBUG_ZERO_PAGE ) {
+ cpu_6502_print_zerop_page( cpu );
+ }
+}
void cpu_6502_print_state( cpu_6502_t *cpu, uint16_t addr )
{
@@ -207,13 +220,13 @@ void cpu_6502_print_state( cpu_6502_t *cpu, uint16_t addr )
fprintf( stderr, "PC: %04X SP: 01%02X PS: %02X %c%c-%c%c%c%c%c A: %02X X: %02X Y: %02X steps: %d OP: %s\n",
cpu->PC, cpu->SP, cpu->PS,
- is_negative( cpu ) ? 'N' : 'n',
- is_overflow( cpu ) ? 'V' : 'v',
- is_brk( cpu ) ? 'B' : 'b',
- is_decimal( cpu ) ? 'D' : 'd',
- is_interrupt( cpu ) ? 'I' : 'i',
- is_zero( cpu ) ? 'Z' : 'z',
- is_carry( cpu ) ? 'C' : 'c',
+ cpu_6502_is_negative( cpu ) ? 'N' : 'n',
+ cpu_6502_is_overflow( cpu ) ? 'V' : 'v',
+ cpu_6502_is_brk( cpu ) ? 'B' : 'b',
+ cpu_6502_is_decimal( cpu ) ? 'D' : 'd',
+ cpu_6502_is_interrupt( cpu ) ? 'I' : 'i',
+ cpu_6502_is_zero( cpu ) ? 'Z' : 'z',
+ cpu_6502_is_carry( cpu ) ? 'C' : 'c',
cpu->A, cpu->X, cpu->Y, cpu->steps,
opcode_str );
}
@@ -251,16 +264,8 @@ void cpu_6502_step( cpu_6502_t *cpu )
opcode = cpu_6502_read_byte( cpu, cpu->PC );
cpu->PC++;
-
- if( cpu->debug_flags & DEBUG_STATUS ) {
- cpu_6502_print_state( cpu, cpu->PC-1 );
- }
- if( cpu->debug_flags & DEBUG_STACK ) {
- cpu_6502_print_stack( cpu );
- }
- if( cpu->debug_flags & DEBUG_ZERO_PAGE ) {
- cpu_6502_print_zerop_page( cpu );
- }
+
+ cpu_6502_print_debug( cpu );
switch( opcode ) {
case LDX_IMM:
@@ -342,7 +347,7 @@ void cpu_6502_step( cpu_6502_t *cpu )
break;
case ROL_ACC:
- tmp = ( cpu->A << 1 ) | is_carry( cpu );
+ tmp = ( cpu->A << 1 ) | cpu_6502_is_carry( cpu );
if( tmp & 0xFF00 ) {
cpu->PS |= PS_C;
} else {
@@ -367,7 +372,7 @@ void cpu_6502_step( cpu_6502_t *cpu )
case SBC_IMM:
operand8 = cpu_6502_read_byte( cpu, cpu->PC );
cpu->PC++;
- tmp = cpu->A - operand8 - ( is_carry( cpu ) ? 0 : 1 );
+ tmp = cpu->A - operand8 - ( cpu_6502_is_carry( cpu ) ? 0 : 1 );
update_negative_and_sign( cpu, tmp );
if( tmp & 0xFF00 ) {
cpu->PS |= PS_C;
@@ -385,7 +390,7 @@ void cpu_6502_step( cpu_6502_t *cpu )
case BNE_REL:
operand8 = cpu_6502_read_byte( cpu, cpu->PC );
cpu->PC++;
- if( !is_zero( cpu ) ) {
+ if( !cpu_6502_is_zero( cpu ) ) {
cpu->PC += (int8_t)operand8;
}
break;
@@ -393,7 +398,7 @@ void cpu_6502_step( cpu_6502_t *cpu )
case BCC_REL:
operand8 = cpu_6502_read_byte( cpu, cpu->PC );
cpu->PC++;
- if( !is_carry( cpu ) ) {
+ if( !cpu_6502_is_carry( cpu ) ) {
cpu->PC += (int8_t)operand8;
}
break;
@@ -401,7 +406,7 @@ void cpu_6502_step( cpu_6502_t *cpu )
case BCS_REL:
operand8 = cpu_6502_read_byte( cpu, cpu->PC );
cpu->PC++;
- if( is_carry( cpu ) ) {
+ if( cpu_6502_is_carry( cpu ) ) {
cpu->PC += (int8_t)operand8;
}
break;