diff options
Diffstat (limited to 'source/cpumacro.h')
-rw-r--r-- | source/cpumacro.h | 488 |
1 files changed, 256 insertions, 232 deletions
diff --git a/source/cpumacro.h b/source/cpumacro.h index eb76b69..5868fed 100644 --- a/source/cpumacro.h +++ b/source/cpumacro.h @@ -3,50 +3,49 @@ #ifndef _CPUMACRO_H_ #define _CPUMACRO_H_ -static void SetZN16(uint16_t Work) +extern int32_t OpAddress; + +static inline void SetZN16(uint16_t Work) { ICPU._Zero = Work != 0; ICPU._Negative = (uint8_t)(Work >> 8); } -static void SetZN8(uint8_t Work) +static inline void SetZN8(uint8_t Work) { ICPU._Zero = Work; ICPU._Negative = Work; } -static void ADC8(int32_t Addr) +static inline void ADC8() { - uint8_t Work8 = S9xGetByte(Addr); + uint8_t Work8 = S9xGetByte(OpAddress); if (CheckDecimal()) { - uint8_t A1 = (ICPU.Registers.A.W) & 0xF; - uint8_t A2 = (ICPU.Registers.A.W >> 4) & 0xF; - uint8_t W1 = Work8 & 0xF; - uint8_t W2 = (Work8 >> 4) & 0xF; + uint8_t A1 = (ICPU.Registers.A.W) & 0x0f; + uint8_t A2 = (ICPU.Registers.A.W) & 0xf0; + uint8_t W1 = Work8 & 0x0f; + uint8_t W2 = Work8 & 0xf0; A1 += W1 + CheckCarry(); - if (A1 > 9) + if (A1 >= 0x0a) { - A1 -= 10; - A1 &= 0xF; - A2++; + A1 -= 0x0a; + A2 += 0x10; } A2 += W2; - if (A2 > 9) + if (A2 >= 0xa0) { - A2 -= 10; - A2 &= 0xF; + A2 -= 0xa0; SetCarry(); } else ClearCarry(); - int8_t Ans8 = (A2 << 4) | A1; - if (~(ICPU.Registers.AL ^ Work8) & - (Work8 ^ Ans8) & 0x80) + uint8_t Ans8 = A2 | A1; + if (~(ICPU.Registers.AL ^ Work8) & (Work8 ^ Ans8) & 0x80) SetOverflow(); else ClearOverflow(); @@ -54,12 +53,9 @@ static void ADC8(int32_t Addr) } else { - int16_t Ans16 = ICPU.Registers.AL + Work8 + CheckCarry(); - - ICPU._Carry = Ans16 >= 0x100; - - if (~(ICPU.Registers.AL ^ Work8) & - (Work8 ^ (uint8_t) Ans16) & 0x80) + uint16_t Ans16 = ICPU.Registers.AL + Work8 + CheckCarry(); + ICPU._Carry = Ans16 > 0xff; + if (~(ICPU.Registers.AL ^ Work8) & (Work8 ^ (uint8_t) Ans16) & 0x80) SetOverflow(); else ClearOverflow(); @@ -68,58 +64,53 @@ static void ADC8(int32_t Addr) SetZN8(ICPU.Registers.AL); } -static void ADC16(int32_t Addr) +static inline void ADC16() { - uint16_t Work16 = S9xGetWord(Addr); + uint16_t Work16 = S9xGetWord(OpAddress); if (CheckDecimal()) { - uint8_t A1 = (ICPU.Registers.A.W) & 0xF; - uint8_t A2 = (ICPU.Registers.A.W >> 4) & 0xF; - uint8_t A3 = (ICPU.Registers.A.W >> 8) & 0xF; - uint8_t A4 = (ICPU.Registers.A.W >> 12) & 0xF; - uint8_t W1 = Work16 & 0xF; - uint8_t W2 = (Work16 >> 4) & 0xF; - uint8_t W3 = (Work16 >> 8) & 0xF; - uint8_t W4 = (Work16 >> 12) & 0xF; + uint16_t A1 = ICPU.Registers.A.W & 0x000f; + uint16_t A2 = ICPU.Registers.A.W & 0x00f0; + uint16_t A3 = ICPU.Registers.A.W & 0x0f00; + uint16_t A4 = ICPU.Registers.A.W & 0xf000; + uint16_t W1 = Work16 & 0x000f; + uint16_t W2 = Work16 & 0x00f0; + uint16_t W3 = Work16 & 0x0f00; + uint16_t W4 = Work16 & 0xf000; A1 += W1 + CheckCarry(); - if (A1 > 9) + if (A1 >= 0x000a) { - A1 -= 10; - A1 &= 0xF; - A2++; + A1 -= 0x000a; + A2 += 0x0010; } A2 += W2; - if (A2 > 9) + if (A2 >= 0x00a0) { - A2 -= 10; - A2 &= 0xF; - A3++; + A2 -= 0x00a0; + A3 += 0x0100; } A3 += W3; - if (A3 > 9) + if (A3 >= 0x0a00) { - A3 -= 10; - A3 &= 0xF; - A4++; + A3 -= 0x0a00; + A4 += 0x1000; } A4 += W4; - if (A4 > 9) + if (A4 >= 0xa000) { - A4 -= 10; - A4 &= 0xF; + A4 -= 0xa000; SetCarry(); } else ClearCarry(); - uint16_t Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); - if (~(ICPU.Registers.A.W ^ Work16) & - (Work16 ^ Ans16) & 0x8000) + uint16_t Ans16 = A4 | A3 | A2 | A1; + if (~(ICPU.Registers.A.W ^ Work16) & (Work16 ^ Ans16) & 0x8000) SetOverflow(); else ClearOverflow(); @@ -129,10 +120,9 @@ static void ADC16(int32_t Addr) { uint32_t Ans32 = ICPU.Registers.A.W + Work16 + CheckCarry(); - ICPU._Carry = Ans32 >= 0x10000; + ICPU._Carry = Ans32 > 0xffff; - if (~(ICPU.Registers.A.W ^ Work16) & - (Work16 ^ (uint16_t) Ans32) & 0x8000) + if (~(ICPU.Registers.A.W ^ Work16) & (Work16 ^ (uint16_t) Ans32) & 0x8000) SetOverflow(); else ClearOverflow(); @@ -141,15 +131,15 @@ static void ADC16(int32_t Addr) SetZN16(ICPU.Registers.A.W); } -static void AND16(int32_t Addr) +static inline void AND16() { - ICPU.Registers.A.W &= S9xGetWord(Addr); + ICPU.Registers.A.W &= S9xGetWord(OpAddress); SetZN16(ICPU.Registers.A.W); } -static void AND8(int32_t Addr) +static inline void AND8() { - ICPU.Registers.AL &= S9xGetByte(Addr); + ICPU.Registers.AL &= S9xGetByte(OpAddress); SetZN8(ICPU.Registers.AL); } @@ -173,81 +163,85 @@ static inline void A_ASL8() SetZN8(ICPU.Registers.AL); } -static void ASL16(int32_t Addr) +static inline void ASL16() { - uint16_t Work16 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Carry = (Work16 & 0x8000) != 0; Work16 <<= 1; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); SetZN16(Work16); } -static void ASL8(int32_t Addr) +static inline void ASL8() { - uint8_t Work8 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Carry = (Work8 & 0x80) != 0; Work8 <<= 1; - S9xSetByte(Work8, Addr); + S9xSetByte(Work8, OpAddress); SetZN8(Work8); } -static void BIT16(int32_t Addr) +static inline void BIT16() { - uint16_t Work16 = S9xGetWord(Addr); + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Overflow = (Work16 & 0x4000) != 0; ICPU._Negative = (uint8_t)(Work16 >> 8); ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; } -static void BIT8(int32_t Addr) +static inline void BIT8() { - uint8_t Work8 = S9xGetByte(Addr); + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Overflow = (Work8 & 0x40) != 0; ICPU._Negative = Work8; ICPU._Zero = Work8 & ICPU.Registers.AL; } -static void CMP16(int32_t Addr) +static inline void CMP16() { - int32_t Int32 = (int32_t) ICPU.Registers.A.W - (int32_t) S9xGetWord(Addr); + int32_t Int32 = (int32_t) ICPU.Registers.A.W - (int32_t) S9xGetWord(OpAddress); ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); } -static void CMP8(int32_t Addr) +static inline void CMP8() { - int16_t Int16 = (int16_t) ICPU.Registers.AL - (int16_t) S9xGetByte(Addr); + int16_t Int16 = (int16_t) ICPU.Registers.AL - (int16_t) S9xGetByte(OpAddress); ICPU._Carry = Int16 >= 0; SetZN8((uint8_t) Int16); } -static void CMX16(int32_t Addr) +static inline void CMX16() { - int32_t Int32 = (int32_t) ICPU.Registers.X.W - (int32_t) S9xGetWord(Addr); + int32_t Int32 = (int32_t) ICPU.Registers.X.W - (int32_t) S9xGetWord(OpAddress); ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); } -static void CMX8(int32_t Addr) +static inline void CMX8() { - int16_t Int16 = (int16_t) ICPU.Registers.XL - - (int16_t) S9xGetByte(Addr); + int16_t Int16 = (int16_t) ICPU.Registers.XL - (int16_t) S9xGetByte(OpAddress); ICPU._Carry = Int16 >= 0; SetZN8((uint8_t) Int16); } -static void CMY16(int32_t Addr) +static inline void CMY16() { - int32_t Int32 = (int32_t) ICPU.Registers.Y.W - (int32_t) S9xGetWord(Addr); + int32_t Int32 = (int32_t) ICPU.Registers.Y.W - (int32_t) S9xGetWord(OpAddress); ICPU._Carry = Int32 >= 0; SetZN16((uint16_t) Int32); } -static void CMY8(int32_t Addr) +static inline void CMY8() { - int16_t Int16 = (int16_t) ICPU.Registers.YL - - (int16_t) S9xGetByte(Addr); + int16_t Int16 = (int16_t) ICPU.Registers.YL - (int16_t) S9xGetByte(OpAddress); ICPU._Carry = Int16 >= 0; SetZN8((uint8_t) Int16); } @@ -260,7 +254,6 @@ static inline void A_DEC16() #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.A.W--; SetZN16(ICPU.Registers.A.W); } @@ -273,43 +266,46 @@ static inline void A_DEC8() #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.AL--; SetZN8(ICPU.Registers.AL); } -static void DEC16(int32_t Addr) +static inline void DEC16() { +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - - uint16_t Work16 = S9xGetWord(Addr) - 1; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + uint16_t Work16 = S9xGetWord(OpAddress) - 1; + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); SetZN16(Work16); } -static void DEC8(int32_t Addr) +static inline void DEC8() { +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - - uint8_t Work8 = S9xGetByte(Addr) - 1; - S9xSetByte(Work8, Addr); + uint8_t Work8 = S9xGetByte(OpAddress) - 1; + S9xSetByte(Work8, OpAddress); SetZN8(Work8); } -static void EOR16(int32_t Addr) +static inline void EOR16() { - ICPU.Registers.A.W ^= S9xGetWord(Addr); + ICPU.Registers.A.W ^= S9xGetWord(OpAddress); SetZN16(ICPU.Registers.A.W); } -static void EOR8(int32_t Addr) +static inline void EOR8() { - ICPU.Registers.AL ^= S9xGetByte(Addr); + ICPU.Registers.AL ^= S9xGetByte(OpAddress); SetZN8(ICPU.Registers.AL); } @@ -321,7 +317,6 @@ static inline void A_INC16() #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.A.W++; SetZN16(ICPU.Registers.A.W); } @@ -334,67 +329,70 @@ static inline void A_INC8() #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - ICPU.Registers.AL++; SetZN8(ICPU.Registers.AL); } -static void INC16(int32_t Addr) +static inline void INC16() { +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - - uint16_t Work16 = S9xGetWord(Addr) + 1; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + uint16_t Work16 = S9xGetWord(OpAddress) + 1; + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); SetZN16(Work16); } -static void INC8(int32_t Addr) +static inline void INC8() { +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif #ifdef CPU_SHUTDOWN CPU.WaitAddress = NULL; #endif - - uint8_t Work8 = S9xGetByte(Addr) + 1; - S9xSetByte(Work8, Addr); + uint8_t Work8 = S9xGetByte(OpAddress) + 1; + S9xSetByte(Work8, OpAddress); SetZN8(Work8); } -static void LDA16(int32_t Addr) +static inline void LDA16() { - ICPU.Registers.A.W = S9xGetWord(Addr); + ICPU.Registers.A.W = S9xGetWord(OpAddress); SetZN16(ICPU.Registers.A.W); } -static void LDA8(int32_t Addr) +static inline void LDA8() { - ICPU.Registers.AL = S9xGetByte(Addr); + ICPU.Registers.AL = S9xGetByte(OpAddress); SetZN8(ICPU.Registers.AL); } -static void LDX16(int32_t Addr) +static inline void LDX16() { - ICPU.Registers.X.W = S9xGetWord(Addr); + ICPU.Registers.X.W = S9xGetWord(OpAddress); SetZN16(ICPU.Registers.X.W); } -static void LDX8(int32_t Addr) +static inline void LDX8() { - ICPU.Registers.XL = S9xGetByte(Addr); + ICPU.Registers.XL = S9xGetByte(OpAddress); SetZN8(ICPU.Registers.XL); } -static void LDY16(int32_t Addr) +static inline void LDY16() { - ICPU.Registers.Y.W = S9xGetWord(Addr); + ICPU.Registers.Y.W = S9xGetWord(OpAddress); SetZN16(ICPU.Registers.Y.W); } -static void LDY8(int32_t Addr) +static inline void LDY8() { - ICPU.Registers.YL = S9xGetByte(Addr); + ICPU.Registers.YL = S9xGetByte(OpAddress); SetZN8(ICPU.Registers.YL); } @@ -418,34 +416,40 @@ static inline void A_LSR8() SetZN8(ICPU.Registers.AL); } -static void LSR16(int32_t Addr) +static inline void LSR16() { - uint16_t Work16 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Carry = Work16 & 1; Work16 >>= 1; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); SetZN16(Work16); } -static void LSR8(int32_t Addr) +static inline void LSR8() { - uint8_t Work8 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Carry = Work8 & 1; Work8 >>= 1; - S9xSetByte(Work8, Addr); + S9xSetByte(Work8, OpAddress); SetZN8(Work8); } -static void ORA16(int32_t Addr) +static inline void ORA16() { - ICPU.Registers.A.W |= S9xGetWord(Addr); + ICPU.Registers.A.W |= S9xGetWord(OpAddress); SetZN16(ICPU.Registers.A.W); } -static void ORA8(int32_t Addr) +static inline void ORA8() { - ICPU.Registers.AL |= S9xGetByte(Addr); + ICPU.Registers.AL |= S9xGetByte(OpAddress); SetZN8(ICPU.Registers.AL); } @@ -455,7 +459,7 @@ static inline void A_ROL16() CPU.Cycles += ONE_CYCLE; #endif uint32_t Work32 = (ICPU.Registers.A.W << 1) | CheckCarry(); - ICPU._Carry = Work32 >= 0x10000; + ICPU._Carry = Work32 > 0xffff; ICPU.Registers.A.W = (uint16_t) Work32; SetZN16((uint16_t) Work32); } @@ -468,29 +472,35 @@ static inline void A_ROL8() uint16_t Work16 = ICPU.Registers.AL; Work16 <<= 1; Work16 |= CheckCarry(); - ICPU._Carry = Work16 >= 0x100; + ICPU._Carry = Work16 > 0xff; ICPU.Registers.AL = (uint8_t) Work16; SetZN8((uint8_t) Work16); } -static void ROL16(int32_t Addr) +static inline void ROL16() { - uint32_t Work32 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint32_t Work32 = S9xGetWord(OpAddress); Work32 <<= 1; Work32 |= CheckCarry(); - ICPU._Carry = Work32 >= 0x10000; - S9xSetByte((Work32 >> 8) & 0xFF, Addr + 1); - S9xSetByte(Work32 & 0xFF, Addr); + ICPU._Carry = Work32 > 0xffff; + S9xSetByte((Work32 >> 8) & 0xFF, OpAddress + 1); + S9xSetByte(Work32 & 0xFF, OpAddress); SetZN16((uint16_t) Work32); } -static void ROL8(int32_t Addr) +static inline void ROL8() { - uint16_t Work16 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetByte(OpAddress); Work16 <<= 1; Work16 |= CheckCarry(); - ICPU._Carry = Work16 >= 0x100; - S9xSetByte((uint8_t) Work16, Addr); + ICPU._Carry = Work16 > 0xff; + S9xSetByte((uint8_t) Work16, OpAddress); SetZN8((uint8_t) Work16); } @@ -519,215 +529,229 @@ static inline void A_ROR8() SetZN8((uint8_t) Work16); } -static void ROR16(int32_t Addr) +static inline void ROR16() { - uint32_t Work32 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint32_t Work32 = S9xGetWord(OpAddress); Work32 |= (int32_t) CheckCarry() << 16; ICPU._Carry = (uint8_t)(Work32 & 1); Work32 >>= 1; - S9xSetByte((Work32 >> 8) & 0x00FF, Addr + 1); - S9xSetByte(Work32 & 0x00FF, Addr); + S9xSetByte((Work32 >> 8) & 0x00FF, OpAddress + 1); + S9xSetByte(Work32 & 0x00FF, OpAddress); SetZN16((uint16_t) Work32); } -static void ROR8(int32_t Addr) +static inline void ROR8() { - uint16_t Work16 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetByte(OpAddress); Work16 |= (int32_t) CheckCarry() << 8; ICPU._Carry = (uint8_t)(Work16 & 1); Work16 >>= 1; - S9xSetByte((uint8_t) Work16, Addr); + S9xSetByte((uint8_t) Work16, OpAddress); SetZN8((uint8_t) Work16); } -static void SBC16(int32_t Addr) +static inline void SBC16() { - uint16_t Work16 = S9xGetWord(Addr); + uint16_t Work16 = S9xGetWord(OpAddress); if (CheckDecimal()) { - uint8_t A1 = (ICPU.Registers.A.W) & 0xF; - uint8_t A2 = (ICPU.Registers.A.W >> 4) & 0xF; - uint8_t A3 = (ICPU.Registers.A.W >> 8) & 0xF; - uint8_t A4 = (ICPU.Registers.A.W >> 12) & 0xF; - uint8_t W1 = Work16 & 0xF; - uint8_t W2 = (Work16 >> 4) & 0xF; - uint8_t W3 = (Work16 >> 8) & 0xF; - uint8_t W4 = (Work16 >> 12) & 0xF; + uint16_t A1 = ICPU.Registers.A.W & 0x000f; + uint16_t A2 = ICPU.Registers.A.W & 0x00f0; + uint16_t A3 = ICPU.Registers.A.W & 0x0f00; + uint16_t A4 = ICPU.Registers.A.W & 0xf000; + uint16_t W1 = Work16 & 0x000f; + uint16_t W2 = Work16 & 0x00f0; + uint16_t W3 = Work16 & 0x0f00; + uint16_t W4 = Work16 & 0xf000; A1 -= W1 + !CheckCarry(); A2 -= W2; A3 -= W3; A4 -= W4; - if (A1 > 9) + if (A1 > 0x000f) { - A1 += 10; - A2--; + A1 += 0x000a; + A1 &= 0x000f; + A2 -= 0x0010; } - if (A2 > 9) + if (A2 > 0x00f0) { - A2 += 10; - A3--; + A2 += 0x00a0; + A2 &= 0x00f0; + A3 -= 0x0100; } - if (A3 > 9) + if (A3 > 0x0f00) { - A3 += 10; - A4--; + A3 += 0x0a00; + A3 &= 0x0f00; + A4 -= 0x1000; } - if (A4 > 9) + if (A4 > 0xf000) { - A4 += 10; + A4 += 0xa000; + A4 &= 0xf000; ClearCarry(); } else SetCarry(); - uint16_t Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); - if ((ICPU.Registers.A.W ^ Work16) & - (ICPU.Registers.A.W ^ Ans16) & 0x8000) + uint16_t Ans16 = A4 | A3 | A2 | A1; + if ((ICPU.Registers.A.W ^ Work16) & (ICPU.Registers.A.W ^ Ans16) & 0x8000) SetOverflow(); else ClearOverflow(); ICPU.Registers.A.W = Ans16; - SetZN16(ICPU.Registers.A.W); } else { int32_t Int32 = (int32_t) ICPU.Registers.A.W - (int32_t) Work16 + (int32_t) CheckCarry() - 1; - ICPU._Carry = Int32 >= 0; - - if ((ICPU.Registers.A.W ^ Work16) & - (ICPU.Registers.A.W ^ (uint16_t) Int32) & 0x8000) + if ((ICPU.Registers.A.W ^ Work16) & (ICPU.Registers.A.W ^ (uint16_t) Int32) & 0x8000) SetOverflow(); else ClearOverflow(); ICPU.Registers.A.W = (uint16_t) Int32; - SetZN16(ICPU.Registers.A.W); } + SetZN16(ICPU.Registers.A.W); } -static void SBC8(int32_t Addr) +static inline void SBC8() { - uint8_t Work8 = S9xGetByte(Addr); + uint8_t Work8 = S9xGetByte(OpAddress); if (CheckDecimal()) { - uint8_t A1 = (ICPU.Registers.A.W) & 0xF; - uint8_t A2 = (ICPU.Registers.A.W >> 4) & 0xF; - uint8_t W1 = Work8 & 0xF; - uint8_t W2 = (Work8 >> 4) & 0xF; + uint8_t A1 = ICPU.Registers.A.W & 0x0f; + uint8_t A2 = ICPU.Registers.A.W & 0xf0; + uint8_t W1 = Work8 & 0x0f; + uint8_t W2 = Work8 & 0xf0; A1 -= W1 + !CheckCarry(); A2 -= W2; - if (A1 > 9) + if (A1 > 0x0f) { - A1 += 10; - A2--; + A1 += 0x0a; + A1 &= 0x0f; + A2 -= 0x10; } - if (A2 > 9) + if (A2 > 0xf0) { - A2 += 10; + A2 += 0xa0; + A2 &= 0xf0; ClearCarry(); } else SetCarry(); - uint8_t Ans8 = (A2 << 4) | A1; - if ((ICPU.Registers.AL ^ Work8) & - (ICPU.Registers.AL ^ Ans8) & 0x80) + uint8_t Ans8 = A2 | A1; + if ((ICPU.Registers.AL ^ Work8) & (ICPU.Registers.AL ^ Ans8) & 0x80) SetOverflow(); else ClearOverflow(); ICPU.Registers.AL = Ans8; - SetZN8(ICPU.Registers.AL); } else { - int16_t Int16 = (int16_t) ICPU.Registers.AL - (int16_t) Work8 + - (int16_t) CheckCarry() - 1; - + int16_t Int16 = (int16_t) ICPU.Registers.AL - (int16_t) Work8 + (int16_t) CheckCarry() - 1; ICPU._Carry = Int16 >= 0; - if ((ICPU.Registers.AL ^ Work8) & - (ICPU.Registers.AL ^ (uint8_t) Int16) & 0x80) + if ((ICPU.Registers.AL ^ Work8) & (ICPU.Registers.AL ^ (uint8_t) Int16) & 0x80) SetOverflow(); else ClearOverflow(); ICPU.Registers.AL = (uint8_t) Int16; - SetZN8(ICPU.Registers.AL); } + SetZN8(ICPU.Registers.AL); } -static void STA16(int32_t Addr) +static inline void STA16() { - S9xSetWord(ICPU.Registers.A.W, Addr); + S9xSetWord(ICPU.Registers.A.W, OpAddress); } -static void STA8(int32_t Addr) +static inline void STA8() { - S9xSetByte(ICPU.Registers.AL, Addr); + S9xSetByte(ICPU.Registers.AL, OpAddress); } -static void STX16(int32_t Addr) +static inline void STX16() { - S9xSetWord(ICPU.Registers.X.W, Addr); + S9xSetWord(ICPU.Registers.X.W, OpAddress); } -static void STX8(int32_t Addr) +static inline void STX8() { - S9xSetByte(ICPU.Registers.XL, Addr); + S9xSetByte(ICPU.Registers.XL, OpAddress); } -static void STY16(int32_t Addr) +static inline void STY16() { - S9xSetWord(ICPU.Registers.Y.W, Addr); + S9xSetWord(ICPU.Registers.Y.W, OpAddress); } -static void STY8(int32_t Addr) +static inline void STY8() { - S9xSetByte(ICPU.Registers.YL, Addr); + S9xSetByte(ICPU.Registers.YL, OpAddress); } -static void STZ16(int32_t Addr) +static inline void STZ16() { - S9xSetWord(0, Addr); + S9xSetWord(0, OpAddress); } -static void STZ8(int32_t Addr) +static inline void STZ8() { - S9xSetByte(0, Addr); + S9xSetByte(0, OpAddress); } -static void TSB16(int32_t Addr) +static inline void TSB16() { - uint16_t Work16 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; Work16 |= ICPU.Registers.A.W; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); } -static void TSB8(int32_t Addr) +static inline void TSB8() { - uint8_t Work8 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Zero = Work8 & ICPU.Registers.AL; Work8 |= ICPU.Registers.AL; - S9xSetByte(Work8, Addr); + S9xSetByte(Work8, OpAddress); } -static void TRB16(int32_t Addr) +static inline void TRB16() { - uint16_t Work16 = S9xGetWord(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint16_t Work16 = S9xGetWord(OpAddress); ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; Work16 &= ~ICPU.Registers.A.W; - S9xSetByte(Work16 >> 8, Addr + 1); - S9xSetByte(Work16 & 0xFF, Addr); + S9xSetByte(Work16 >> 8, OpAddress + 1); + S9xSetByte(Work16 & 0xFF, OpAddress); } -static void TRB8(int32_t Addr) +static inline void TRB8() { - uint8_t Work8 = S9xGetByte(Addr); +#ifndef SA1_OPCODES + CPU.Cycles += ONE_CYCLE; +#endif + uint8_t Work8 = S9xGetByte(OpAddress); ICPU._Zero = Work8 & ICPU.Registers.AL; Work8 &= ~ICPU.Registers.AL; - S9xSetByte(Work8, Addr); + S9xSetByte(Work8, OpAddress); } #endif |