From f2e5b49a6e2ce198ff88ea307dd092548d3808fa Mon Sep 17 00:00:00 2001 From: Tamas Rudnai Date: Thu, 12 Sep 2019 00:30:22 -0700 Subject: [PATCH] - Speed optimizations - Carry Flag bugfix --- A2Mac/common.h | 4 ++-- A2Mac/instructions/6502_instr_arithmetic.h | 6 +++++- A2Mac/instructions/6502_instr_compare_test.h | 6 +++--- A2Mac/instructions/6502_instr_inc_dec.h | 4 ++-- A2Mac/instructions/6502_instr_misc.h | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/A2Mac/common.h b/A2Mac/common.h index 436de28..74ab6d4 100644 --- a/A2Mac/common.h +++ b/A2Mac/common.h @@ -56,7 +56,7 @@ static inline void set_flags_Z( const uint8_t test ) { dbgPrintf("%c", m6502.flags.Z ? 'Z' : 'z'); } -static inline void set_flags_C( const int test ) { +static inline void set_flags_C( const int16_t test ) { m6502.flags.C = test >= 0; dbgPrintf("%c", m6502.flags.C ? 'C' : 'c'); } @@ -76,7 +76,7 @@ static inline void set_flags_NVZ( const uint8_t test ) { set_flags_V(test); } -static inline void set_flags_NZC( const int test ) { +static inline void set_flags_NZC( const int16_t test ) { set_flags_NZ(test); set_flags_C(test); } diff --git a/A2Mac/instructions/6502_instr_arithmetic.h b/A2Mac/instructions/6502_instr_arithmetic.h index 425edcf..5599581 100644 --- a/A2Mac/instructions/6502_instr_arithmetic.h +++ b/A2Mac/instructions/6502_instr_arithmetic.h @@ -31,7 +31,11 @@ **/ static inline void ADC( uint8_t imm ) { dbgPrintf("ADC(%02X) A:%02X + %02X ", imm, m6502.A, imm); - set_flags_NZCV( m6502.A += imm + m6502.flags.C ); + + int16_t tmp; + set_flags_NVZ( m6502.A = tmp = (int16_t)m6502.A + imm + m6502.flags.C ); + m6502.flags.C = tmp > 0xFF; + dbgPrintf("-> A:%02X ", m6502.A); } diff --git a/A2Mac/instructions/6502_instr_compare_test.h b/A2Mac/instructions/6502_instr_compare_test.h index ff6fb05..05d8cd2 100644 --- a/A2Mac/instructions/6502_instr_compare_test.h +++ b/A2Mac/instructions/6502_instr_compare_test.h @@ -49,7 +49,7 @@ static inline void BIT( uint8_t imm ) { **/ static inline void CMP( uint8_t imm ) { dbgPrintf("CMP(%02X) ", imm); - set_flags_NZC( (int)m6502.A - imm ); + set_flags_NZC( (int16_t)m6502.A - imm ); } /** @@ -66,7 +66,7 @@ static inline void CMP( uint8_t imm ) { **/ static inline void CPX( uint8_t imm ) { dbgPrintf("CPX(%02X) ", imm); - set_flags_NZC( (int)m6502.X - imm ); + set_flags_NZC( (int16_t)m6502.X - imm ); } /** @@ -83,7 +83,7 @@ static inline void CPX( uint8_t imm ) { **/ static inline void CPY( uint8_t imm ) { dbgPrintf("CPY(%02X) ", imm); - set_flags_NZC( (int)m6502.Y - imm ); + set_flags_NZC( (int16_t)m6502.Y - imm ); } #endif // __6502_INSTR_COMPARE_TEST_H__ diff --git a/A2Mac/instructions/6502_instr_inc_dec.h b/A2Mac/instructions/6502_instr_inc_dec.h index ca98382..f018a86 100644 --- a/A2Mac/instructions/6502_instr_inc_dec.h +++ b/A2Mac/instructions/6502_instr_inc_dec.h @@ -33,7 +33,7 @@ static inline void INC( uint8_t * dst ) { INX Increment Index X by One X + 1 -> X N Z C I D V - + + - - - - + + + - - - - addressing assembler opc bytes cyles -------------------------------------------- @@ -49,7 +49,7 @@ static inline void INX() { INY Increment Index Y by One Y + 1 -> Y N Z C I D V - + + - - - - + + + - - - - addressing assembler opc bytes cyles -------------------------------------------- diff --git a/A2Mac/instructions/6502_instr_misc.h b/A2Mac/instructions/6502_instr_misc.h index dec91f0..0a697a4 100644 --- a/A2Mac/instructions/6502_instr_misc.h +++ b/A2Mac/instructions/6502_instr_misc.h @@ -28,7 +28,7 @@ static inline void BRK() { NOP No Operation --- N Z C I D V - - - - - - - + - - - - - - addressing assembler opc bytes cyles --------------------------------------------