More updates to support testsuite

This commit is contained in:
Aaron Culliney 2014-01-25 22:10:33 -08:00
parent 17440949bf
commit 8976808568
6 changed files with 56 additions and 48 deletions

View File

@ -101,10 +101,13 @@
* Save CPU state when returning from being called from C * Save CPU state when returning from being called from C
*/ */
#define SaveState \ #define SaveState \
xorl %eax, %eax; \
movw EffectiveAddr, DebugCurrEA; \ movw EffectiveAddr, DebugCurrEA; \
movw PC_Reg, SN(cpu65_current); \ movw PC_Reg, SN(cpu65_current); \
movb A_Reg, SN(cpu65_current)+2; \ movb A_Reg, SN(cpu65_current)+2; \
movb F_Reg, SN(cpu65_current)+3; \ movb F_Reg, %al; \
movb SN(cpu65_flags_encode)(,%eax,1), %al; \
movb %al, SN(cpu65_current)+3; \
movb X_Reg, SN(cpu65_current)+4; \ movb X_Reg, SN(cpu65_current)+4; \
movb Y_Reg, SN(cpu65_current)+5; \ movb Y_Reg, SN(cpu65_current)+5; \
movb SP_Reg_L, SN(cpu65_current)+6; movb SP_Reg_L, SN(cpu65_current)+6;
@ -129,7 +132,8 @@
movw DebugCurrEA, EffectiveAddr; \ movw DebugCurrEA, EffectiveAddr; \
movw SN(cpu65_current), PC_Reg; \ movw SN(cpu65_current), PC_Reg; \
movb SN(cpu65_current)+2, A_Reg; \ movb SN(cpu65_current)+2, A_Reg; \
movb SN(cpu65_current)+3, F_Reg; \ movb SN(cpu65_current)+3, %al; \
movb SN(cpu65_flags_decode)(,%eax,1), F_Reg; \
movb SN(cpu65_current)+4, X_Reg; \ movb SN(cpu65_current)+4, X_Reg; \
movb SN(cpu65_current)+5, Y_Reg; \ movb SN(cpu65_current)+5, Y_Reg; \
movb SN(cpu65_current)+6, SP_Reg_L; \ movb SN(cpu65_current)+6, SP_Reg_L; \
@ -339,6 +343,7 @@
adcb %al, A_Reg; \ adcb %al, A_Reg; \
FlagNVZC FlagNVZC
// REFACTOR:
#define DoADC_d GetFromEA_B \ #define DoADC_d GetFromEA_B \
bt $C_Flag_Bit, FF_Reg; \ bt $C_Flag_Bit, FF_Reg; \
adcb A_Reg, %al; \ adcb A_Reg, %al; \
@ -490,7 +495,7 @@ op_ADC_dec:
DoADC_d DoADC_d
Continue Continue
op_ADC_imm: op_ADC_imm: // 0x69
GetImm GetImm
testb $D_Flag, F_Reg // Decimal mode? testb $D_Flag, F_Reg // Decimal mode?
jnz op_ADC_dec // Yes, jump to decimal version jnz op_ADC_dec // Yes, jump to decimal version
@ -513,7 +518,7 @@ op_ADC_zpage_x:
// UNIMPLEMENTED : W65C02S datasheet // UNIMPLEMENTED : W65C02S datasheet
op_ADC_zpage_y: op_ADC_zpage_y:
hlt jmp op_NOP
op_ADC_abs: op_ADC_abs:
GetAbs GetAbs
@ -580,7 +585,7 @@ op_AND_zpage_x:
// UNIMPLEMENTED : W65C02S datasheet // UNIMPLEMENTED : W65C02S datasheet
op_AND_zpage_y: op_AND_zpage_y:
hlt jmp op_NOP
op_AND_abs: op_AND_abs:
GetAbs GetAbs
@ -944,7 +949,7 @@ op_CMP_zpage_x:
// UNIMPLEMENTED : W65C02S datasheet // UNIMPLEMENTED : W65C02S datasheet
op_CMP_zpage_y: op_CMP_zpage_y:
hlt jmp op_NOP
op_CMP_abs: op_CMP_abs:
GetAbs GetAbs
@ -1092,7 +1097,7 @@ op_EOR_zpage_x:
// UNIMPLEMENTED : W65C02S datasheet // UNIMPLEMENTED : W65C02S datasheet
op_EOR_zpage_y: op_EOR_zpage_y:
hlt jmp op_NOP
op_EOR_abs: op_EOR_abs:
GetAbs GetAbs
@ -1266,7 +1271,7 @@ op_LDA_zpage_x:
// UNIMPLEMENTED : W65C02S datasheet // UNIMPLEMENTED : W65C02S datasheet
op_LDA_zpage_y: op_LDA_zpage_y:
hlt jmp op_NOP
op_LDA_abs: op_LDA_abs:
GetAbs GetAbs
@ -1415,7 +1420,7 @@ op_ORA_zpage_x:
// UNIMPLEMENTED : W65C02S datasheet // UNIMPLEMENTED : W65C02S datasheet
op_ORA_zpage_y: op_ORA_zpage_y:
hlt jmp op_NOP
op_ORA_abs: op_ORA_abs:
GetAbs GetAbs
@ -1644,7 +1649,7 @@ op_SBC_zpage_x:
// UNIMPLEMENTED : W65C02S datasheet // UNIMPLEMENTED : W65C02S datasheet
op_SBC_zpage_y: op_SBC_zpage_y:
hlt jmp op_NOP
op_SBC_abs: op_SBC_abs:
GetAbs GetAbs
@ -1764,7 +1769,7 @@ op_STA_zpage_x:
// UNIMPLEMENTED : W65C02S datasheet // UNIMPLEMENTED : W65C02S datasheet
op_STA_zpage_y: op_STA_zpage_y:
hlt jmp op_NOP
op_STA_abs: op_STA_abs:
GetAbs GetAbs
@ -2782,7 +2787,6 @@ emul_reinit: movb $0, SN(cpu65__signal) // Return to timing
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
ex_step: orb $~DebugStepSig, SN(cpu65__signal) ex_step: orb $~DebugStepSig, SN(cpu65__signal)
xorl %eax, %eax
SaveState SaveState
call SN(c_stepping_yield) call SN(c_stepping_yield)
RestoreState RestoreState

View File

@ -73,9 +73,10 @@
# pragma clang diagnostic ignored "-Wunused-variable" # pragma clang diagnostic ignored "-Wunused-variable"
# endif # endif
static FILE *error_log=0; extern bool do_logging;
extern FILE *error_log;
#define ERRLOG(/* err message format string, args */...) \ #define ERRLOG(/* err message format string, args */...) \
do { \ if (do_logging) { \
int saverr = errno; errno = 0; \ int saverr = errno; errno = 0; \
fprintf(error_log ? error_log : stderr, "%s:%d - ", __FILE__, __LINE__); \ fprintf(error_log ? error_log : stderr, "%s:%d - ", __FILE__, __LINE__); \
fprintf(error_log ? error_log : stderr, __VA_ARGS__); \ fprintf(error_log ? error_log : stderr, __VA_ARGS__); \
@ -83,13 +84,13 @@ static FILE *error_log=0;
fprintf(error_log ? error_log : stderr, " (syserr: %s)", strerror(saverr)); \ fprintf(error_log ? error_log : stderr, " (syserr: %s)", strerror(saverr)); \
} \ } \
fprintf(error_log ? error_log : stderr, "\n"); \ fprintf(error_log ? error_log : stderr, "\n"); \
} while(0); }
#define ERRQUIT(...) \ #define ERRQUIT(...) \
do { \ if (do_logging) { \
ERRLOG(__VA_ARGS__); \ ERRLOG(__VA_ARGS__); \
exit(1); \ exit(1); \
} while(0); }
#else // NDEBUG #else // NDEBUG
@ -100,9 +101,7 @@ static FILE *error_log=0;
#endif #endif
#define ERRLOG(...) \ #define ERRLOG(...) \
do \ do { } while(0);
{ \
} while(0);
#endif #endif

View File

@ -16,16 +16,6 @@
#include "common.h" #include "common.h"
// These match the bit positions of the 6502 P-register, they are not the same as in cpu.h -- see note there
#define C_Flag_6502 0x1 // [C]arry
#define X_Flag_6502 0x20 // [X]tra (reserved)...
#define I_Flag_6502 0x4 // [I]nterrupt
#define V_Flag_6502 0x40 // o[V]erfly
#define B_Flag_6502 0x10 // [B]reak
#define D_Flag_6502 0x8 // [D]ecimal
#define Z_Flag_6502 0x2 // [Z]ero
#define N_Flag_6502 0x80 // [N]egative
struct cpu65_state cpu65_current; struct cpu65_state cpu65_current;
struct cpu65_extra cpu65_debug; struct cpu65_extra cpu65_debug;
@ -82,7 +72,7 @@ static void initialize_code_tables()
val |= N_Flag_6502; val |= N_Flag_6502;
} }
cpu65_flags_encode[ i ] = val | 0x20; cpu65_flags_encode[ i ] = val/* | 0x20 WTF?*/;
cpu65_flags_decode[ val ] = i; cpu65_flags_decode[ val ] = i;
} }
} }

View File

@ -36,7 +36,7 @@ struct cpu65_state
{ {
uint16_t pc; /* Program counter */ uint16_t pc; /* Program counter */
uint8_t a; /* Accumulator */ uint8_t a; /* Accumulator */
uint8_t f; /* Flags (order not same as in real 6502) */ uint8_t f; /* Flags (host-order) */
uint8_t x; /* X Index register */ uint8_t x; /* X Index register */
uint8_t y; /* Y Index register */ uint8_t y; /* Y Index register */
uint8_t sp; /* Stack Pointer */ uint8_t sp; /* Stack Pointer */
@ -116,6 +116,18 @@ extern uint8_t emul_reinitialize;
#define Z_Flag_Bit 14 /* 6502 Zero */ #define Z_Flag_Bit 14 /* 6502 Zero */
#define N_Flag_Bit 15 /* 6502 Neg */ #define N_Flag_Bit 15 /* 6502 Neg */
/*
* These are the 6502 Flags bit positions
*/
#define C_Flag_6502 0x1 // [C]arry
#define Z_Flag_6502 0x2 // [Z]ero
#define I_Flag_6502 0x4 // [I]nterrupt
#define D_Flag_6502 0x8 // [D]ecimal
#define B_Flag_6502 0x10 // [B]reak
#define X_Flag_6502 0x20 // [X]tra (reserved)...
#define V_Flag_6502 0x40 // o[V]erflow
#define N_Flag_6502 0x80 // [N]egative
#define X_Reg %bl /* 6502 X register in %bl */ #define X_Reg %bl /* 6502 X register in %bl */
#define Y_Reg %bh /* 6502 Y register in %bh */ #define Y_Reg %bh /* 6502 Y register in %bh */
#define XY_Regs_32 %ebx /* 6502 X&Y flags */ #define XY_Regs_32 %ebx /* 6502 X&Y flags */

View File

@ -637,42 +637,42 @@ void show_regs() {
sprintf(second_buf[num_buffer_lines++], "X = %02X Y = %02X A = %02X F = %02X", cpu65_current.x, cpu65_current.y, cpu65_current.a, cpu65_current.f); sprintf(second_buf[num_buffer_lines++], "X = %02X Y = %02X A = %02X F = %02X", cpu65_current.x, cpu65_current.y, cpu65_current.a, cpu65_current.f);
memset(second_buf[num_buffer_lines], ' ', BUF_X); memset(second_buf[num_buffer_lines], ' ', BUF_X);
if (cpu65_current.f & C_Flag) if (cpu65_current.f & C_Flag_6502)
{ {
second_buf[num_buffer_lines][0]='C'; second_buf[num_buffer_lines][0]='C';
} }
if (cpu65_current.f & X_Flag) if (cpu65_current.f & X_Flag_6502)
{ {
second_buf[num_buffer_lines][1]='X'; second_buf[num_buffer_lines][1]='X';
} }
if (cpu65_current.f & I_Flag) if (cpu65_current.f & I_Flag_6502)
{ {
second_buf[num_buffer_lines][2]='I'; second_buf[num_buffer_lines][2]='I';
} }
if (cpu65_current.f & V_Flag) if (cpu65_current.f & V_Flag_6502)
{ {
second_buf[num_buffer_lines][3]='V'; second_buf[num_buffer_lines][3]='V';
} }
if (cpu65_current.f & B_Flag) if (cpu65_current.f & B_Flag_6502)
{ {
second_buf[num_buffer_lines][4]='B'; second_buf[num_buffer_lines][4]='B';
} }
if (cpu65_current.f & D_Flag) if (cpu65_current.f & D_Flag_6502)
{ {
second_buf[num_buffer_lines][5]='D'; second_buf[num_buffer_lines][5]='D';
} }
if (cpu65_current.f & Z_Flag) if (cpu65_current.f & Z_Flag_6502)
{ {
second_buf[num_buffer_lines][6]='Z'; second_buf[num_buffer_lines][6]='Z';
} }
if (cpu65_current.f & N_Flag) if (cpu65_current.f & N_Flag_6502)
{ {
second_buf[num_buffer_lines][7]='N'; second_buf[num_buffer_lines][7]='N';
} }
@ -693,23 +693,23 @@ static int will_branch() {
switch (op) switch (op)
{ {
case 0x10: /* BPL */ case 0x10: /* BPL */
return (int) !(cpu65_current.f & N_Flag); return (int) !(cpu65_current.f & N_Flag_6502);
case 0x30: /* BMI */ case 0x30: /* BMI */
return (int) (cpu65_current.f & N_Flag); return (int) (cpu65_current.f & N_Flag_6502);
case 0x50: /* BVC */ case 0x50: /* BVC */
return (int) !(cpu65_current.f & V_Flag); return (int) !(cpu65_current.f & V_Flag_6502);
case 0x70: /* BVS */ case 0x70: /* BVS */
return (int) (cpu65_current.f & V_Flag); return (int) (cpu65_current.f & V_Flag_6502);
case 0x80: /* BRA */ case 0x80: /* BRA */
return 1; return 1;
case 0x90: /* BCC */ case 0x90: /* BCC */
return (int) !(cpu65_current.f & C_Flag); return (int) !(cpu65_current.f & C_Flag_6502);
case 0xb0: /* BCS */ case 0xb0: /* BCS */
return (int) (cpu65_current.f & C_Flag); return (int) (cpu65_current.f & C_Flag_6502);
case 0xd0: /* BNE */ case 0xd0: /* BNE */
return (int) !(cpu65_current.f & Z_Flag); return (int) !(cpu65_current.f & Z_Flag_6502);
case 0xf0: /* BEQ */ case 0xf0: /* BEQ */
return (int) (cpu65_current.f & Z_Flag); return (int) (cpu65_current.f & Z_Flag_6502);
} }
return -1; return -1;

View File

@ -23,6 +23,9 @@
static unsigned char apple_ii_rom[12288]; static unsigned char apple_ii_rom[12288];
static unsigned char apple_iie_rom[32768]; /* //e */ static unsigned char apple_iie_rom[32768]; /* //e */
bool do_logging = true; // also controlled by NDEBUG
FILE *error_log = NULL;
/* in debugger.c */ /* in debugger.c */
extern int breakpoints[]; extern int breakpoints[];
extern int watchpoints[]; extern int watchpoints[];