From 8976808568c0f46d7e83e1adb365172ad864b73e Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sat, 25 Jan 2014 22:10:33 -0800 Subject: [PATCH] More updates to support testsuite --- src/asm386/cpu.S | 28 ++++++++++++++++------------ src/common.h | 15 +++++++-------- src/cpu-supp.c | 12 +----------- src/cpu.h | 14 +++++++++++++- src/meta/debugger.c | 32 ++++++++++++++++---------------- src/misc.c | 3 +++ 6 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/asm386/cpu.S b/src/asm386/cpu.S index 91130c13..df129d7b 100644 --- a/src/asm386/cpu.S +++ b/src/asm386/cpu.S @@ -101,10 +101,13 @@ * Save CPU state when returning from being called from C */ #define SaveState \ + xorl %eax, %eax; \ movw EffectiveAddr, DebugCurrEA; \ movw PC_Reg, SN(cpu65_current); \ 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 Y_Reg, SN(cpu65_current)+5; \ movb SP_Reg_L, SN(cpu65_current)+6; @@ -129,7 +132,8 @@ movw DebugCurrEA, EffectiveAddr; \ movw SN(cpu65_current), PC_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)+5, Y_Reg; \ movb SN(cpu65_current)+6, SP_Reg_L; \ @@ -339,6 +343,7 @@ adcb %al, A_Reg; \ FlagNVZC +// REFACTOR: #define DoADC_d GetFromEA_B \ bt $C_Flag_Bit, FF_Reg; \ adcb A_Reg, %al; \ @@ -490,7 +495,7 @@ op_ADC_dec: DoADC_d Continue -op_ADC_imm: +op_ADC_imm: // 0x69 GetImm testb $D_Flag, F_Reg // Decimal mode? jnz op_ADC_dec // Yes, jump to decimal version @@ -513,7 +518,7 @@ op_ADC_zpage_x: // UNIMPLEMENTED : W65C02S datasheet op_ADC_zpage_y: - hlt + jmp op_NOP op_ADC_abs: GetAbs @@ -580,7 +585,7 @@ op_AND_zpage_x: // UNIMPLEMENTED : W65C02S datasheet op_AND_zpage_y: - hlt + jmp op_NOP op_AND_abs: GetAbs @@ -944,7 +949,7 @@ op_CMP_zpage_x: // UNIMPLEMENTED : W65C02S datasheet op_CMP_zpage_y: - hlt + jmp op_NOP op_CMP_abs: GetAbs @@ -1092,7 +1097,7 @@ op_EOR_zpage_x: // UNIMPLEMENTED : W65C02S datasheet op_EOR_zpage_y: - hlt + jmp op_NOP op_EOR_abs: GetAbs @@ -1266,7 +1271,7 @@ op_LDA_zpage_x: // UNIMPLEMENTED : W65C02S datasheet op_LDA_zpage_y: - hlt + jmp op_NOP op_LDA_abs: GetAbs @@ -1415,7 +1420,7 @@ op_ORA_zpage_x: // UNIMPLEMENTED : W65C02S datasheet op_ORA_zpage_y: - hlt + jmp op_NOP op_ORA_abs: GetAbs @@ -1644,7 +1649,7 @@ op_SBC_zpage_x: // UNIMPLEMENTED : W65C02S datasheet op_SBC_zpage_y: - hlt + jmp op_NOP op_SBC_abs: GetAbs @@ -1764,7 +1769,7 @@ op_STA_zpage_x: // UNIMPLEMENTED : W65C02S datasheet op_STA_zpage_y: - hlt + jmp op_NOP op_STA_abs: GetAbs @@ -2782,7 +2787,6 @@ emul_reinit: movb $0, SN(cpu65__signal) // Return to timing ------------------------------------------------------------------------- */ ex_step: orb $~DebugStepSig, SN(cpu65__signal) - xorl %eax, %eax SaveState call SN(c_stepping_yield) RestoreState diff --git a/src/common.h b/src/common.h index ba745347..8755ded1 100644 --- a/src/common.h +++ b/src/common.h @@ -73,9 +73,10 @@ # pragma clang diagnostic ignored "-Wunused-variable" # endif -static FILE *error_log=0; +extern bool do_logging; +extern FILE *error_log; #define ERRLOG(/* err message format string, args */...) \ - do { \ + if (do_logging) { \ int saverr = errno; errno = 0; \ fprintf(error_log ? error_log : stderr, "%s:%d - ", __FILE__, __LINE__); \ 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, "\n"); \ - } while(0); + } #define ERRQUIT(...) \ - do { \ + if (do_logging) { \ ERRLOG(__VA_ARGS__); \ exit(1); \ - } while(0); + } #else // NDEBUG @@ -100,9 +101,7 @@ static FILE *error_log=0; #endif #define ERRLOG(...) \ - do \ - { \ - } while(0); + do { } while(0); #endif diff --git a/src/cpu-supp.c b/src/cpu-supp.c index 38469619..885ed1cb 100644 --- a/src/cpu-supp.c +++ b/src/cpu-supp.c @@ -16,16 +16,6 @@ #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_extra cpu65_debug; @@ -82,7 +72,7 @@ static void initialize_code_tables() val |= N_Flag_6502; } - cpu65_flags_encode[ i ] = val | 0x20; + cpu65_flags_encode[ i ] = val/* | 0x20 WTF?*/; cpu65_flags_decode[ val ] = i; } } diff --git a/src/cpu.h b/src/cpu.h index 33335a37..602692ef 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -36,7 +36,7 @@ struct cpu65_state { uint16_t pc; /* Program counter */ 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 y; /* Y Index register */ uint8_t sp; /* Stack Pointer */ @@ -116,6 +116,18 @@ extern uint8_t emul_reinitialize; #define Z_Flag_Bit 14 /* 6502 Zero */ #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 Y_Reg %bh /* 6502 Y register in %bh */ #define XY_Regs_32 %ebx /* 6502 X&Y flags */ diff --git a/src/meta/debugger.c b/src/meta/debugger.c index 99aab412..65b325e4 100644 --- a/src/meta/debugger.c +++ b/src/meta/debugger.c @@ -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); 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'; } - if (cpu65_current.f & X_Flag) + if (cpu65_current.f & X_Flag_6502) { 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'; } - if (cpu65_current.f & V_Flag) + if (cpu65_current.f & V_Flag_6502) { 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'; } - if (cpu65_current.f & D_Flag) + if (cpu65_current.f & D_Flag_6502) { 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'; } - if (cpu65_current.f & N_Flag) + if (cpu65_current.f & N_Flag_6502) { second_buf[num_buffer_lines][7]='N'; } @@ -693,23 +693,23 @@ static int will_branch() { switch (op) { case 0x10: /* BPL */ - return (int) !(cpu65_current.f & N_Flag); + return (int) !(cpu65_current.f & N_Flag_6502); case 0x30: /* BMI */ - return (int) (cpu65_current.f & N_Flag); + return (int) (cpu65_current.f & N_Flag_6502); case 0x50: /* BVC */ - return (int) !(cpu65_current.f & V_Flag); + return (int) !(cpu65_current.f & V_Flag_6502); case 0x70: /* BVS */ - return (int) (cpu65_current.f & V_Flag); + return (int) (cpu65_current.f & V_Flag_6502); case 0x80: /* BRA */ return 1; case 0x90: /* BCC */ - return (int) !(cpu65_current.f & C_Flag); + return (int) !(cpu65_current.f & C_Flag_6502); case 0xb0: /* BCS */ - return (int) (cpu65_current.f & C_Flag); + return (int) (cpu65_current.f & C_Flag_6502); case 0xd0: /* BNE */ - return (int) !(cpu65_current.f & Z_Flag); + return (int) !(cpu65_current.f & Z_Flag_6502); case 0xf0: /* BEQ */ - return (int) (cpu65_current.f & Z_Flag); + return (int) (cpu65_current.f & Z_Flag_6502); } return -1; diff --git a/src/misc.c b/src/misc.c index b81504e4..c4379da8 100644 --- a/src/misc.c +++ b/src/misc.c @@ -23,6 +23,9 @@ static unsigned char apple_ii_rom[12288]; static unsigned char apple_iie_rom[32768]; /* //e */ +bool do_logging = true; // also controlled by NDEBUG +FILE *error_log = NULL; + /* in debugger.c */ extern int breakpoints[]; extern int watchpoints[];