From e708c127fa51beab567a9ce0e3ab53b58c997773 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 18 Dec 2012 22:53:49 -0500 Subject: Un-inline a bunch of stuff. With the MIPS instruction cache, this means that two consecutive SNES CPU instructions using e.g. the same addressing style or the same opcode have a chance that the second one will use the first one's code and that it will be cached. --- source/cpumacro.h | 124 +++++++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) (limited to 'source/cpumacro.h') diff --git a/source/cpumacro.h b/source/cpumacro.h index d97aa53..5b4e15b 100644 --- a/source/cpumacro.h +++ b/source/cpumacro.h @@ -90,19 +90,19 @@ #ifndef _CPUMACRO_H_ #define _CPUMACRO_H_ -STATIC inline void SetZN16 (uint16 Work) +void SetZN16 (uint16 Work) { ICPU._Zero = Work != 0; ICPU._Negative = (uint8) (Work >> 8); } -STATIC inline void SetZN8 (uint8 Work) +void SetZN8 (uint8 Work) { ICPU._Zero = Work; ICPU._Negative = Work; } -STATIC inline void ADC8 () +void ADC8 () { Work8 = S9xGetByte (OpAddress); @@ -159,7 +159,7 @@ STATIC inline void ADC8 () } } -STATIC inline void ADC16 () +void ADC16 () { Work16 = S9xGetWord (OpAddress); @@ -235,19 +235,19 @@ STATIC inline void ADC16 () } } -STATIC inline void AND16 () +void AND16 () { Registers.A.W &= S9xGetWord (OpAddress); SetZN16 (Registers.A.W); } -STATIC inline void AND8 () +void AND8 () { Registers.AL &= S9xGetByte (OpAddress); SetZN8 (Registers.AL); } -STATIC inline void A_ASL16 () +void A_ASL16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -257,7 +257,7 @@ STATIC inline void A_ASL16 () SetZN16 (Registers.A.W); } -STATIC inline void A_ASL8 () +void A_ASL8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -267,7 +267,7 @@ STATIC inline void A_ASL8 () SetZN8 (Registers.AL); } -STATIC inline void ASL16 () +void ASL16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -281,7 +281,7 @@ STATIC inline void ASL16 () SetZN16 (Work16); } -STATIC inline void ASL8 () +void ASL8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -293,7 +293,7 @@ STATIC inline void ASL8 () SetZN8 (Work8); } -STATIC inline void BIT16 () +void BIT16 () { Work16 = S9xGetWord (OpAddress); ICPU._Overflow = (Work16 & 0x4000) != 0; @@ -301,7 +301,7 @@ STATIC inline void BIT16 () ICPU._Zero = (Work16 & Registers.A.W) != 0; } -STATIC inline void BIT8 () +void BIT8 () { Work8 = S9xGetByte (OpAddress); ICPU._Overflow = (Work8 & 0x40) != 0; @@ -309,7 +309,7 @@ STATIC inline void BIT8 () ICPU._Zero = Work8 & Registers.AL; } -STATIC inline void CMP16 () +void CMP16 () { Int32 = (long) Registers.A.W - (long) S9xGetWord (OpAddress); @@ -317,7 +317,7 @@ STATIC inline void CMP16 () SetZN16 ((uint16) Int32); } -STATIC inline void CMP8 () +void CMP8 () { Int16 = (short) Registers.AL - (short) S9xGetByte (OpAddress); @@ -325,7 +325,7 @@ STATIC inline void CMP8 () SetZN8 ((uint8) Int16); } -STATIC inline void CMX16 () +void CMX16 () { Int32 = (long) Registers.X.W - (long) S9xGetWord (OpAddress); @@ -333,7 +333,7 @@ STATIC inline void CMX16 () SetZN16 ((uint16) Int32); } -STATIC inline void CMX8 () +void CMX8 () { Int16 = (short) Registers.XL - (short) S9xGetByte (OpAddress); @@ -341,7 +341,7 @@ STATIC inline void CMX8 () SetZN8 ((uint8) Int16); } -STATIC inline void CMY16 () +void CMY16 () { Int32 = (long) Registers.Y.W - (long) S9xGetWord (OpAddress); @@ -349,7 +349,7 @@ STATIC inline void CMY16 () SetZN16 ((uint16) Int32); } -STATIC inline void CMY8 () +void CMY8 () { Int16 = (short) Registers.YL - (short) S9xGetByte (OpAddress); @@ -357,7 +357,7 @@ STATIC inline void CMY8 () SetZN8 ((uint8) Int16); } -STATIC inline void A_DEC16 () +void A_DEC16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -370,7 +370,7 @@ STATIC inline void A_DEC16 () SetZN16 (Registers.A.W); } -STATIC inline void A_DEC8 () +void A_DEC8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -383,7 +383,7 @@ STATIC inline void A_DEC8 () SetZN8 (Registers.AL); } -STATIC inline void DEC16 () +void DEC16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -399,7 +399,7 @@ STATIC inline void DEC16 () SetZN16 (Work16); } -STATIC inline void DEC8 () +void DEC8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -413,19 +413,19 @@ STATIC inline void DEC8 () SetZN8 (Work8); } -STATIC inline void EOR16 () +void EOR16 () { Registers.A.W ^= S9xGetWord (OpAddress); SetZN16 (Registers.A.W); } -STATIC inline void EOR8 () +void EOR8 () { Registers.AL ^= S9xGetByte (OpAddress); SetZN8 (Registers.AL); } -STATIC inline void A_INC16 () +void A_INC16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -438,7 +438,7 @@ STATIC inline void A_INC16 () SetZN16 (Registers.A.W); } -STATIC inline void A_INC8 () +void A_INC8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -451,7 +451,7 @@ STATIC inline void A_INC8 () SetZN8 (Registers.AL); } -STATIC inline void INC16 () +void INC16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -467,7 +467,7 @@ STATIC inline void INC16 () SetZN16 (Work16); } -STATIC inline void INC8 () +void INC8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -481,43 +481,43 @@ STATIC inline void INC8 () SetZN8 (Work8); } -STATIC inline void LDA16 () +void LDA16 () { Registers.A.W = S9xGetWord (OpAddress); SetZN16 (Registers.A.W); } -STATIC inline void LDA8 () +void LDA8 () { Registers.AL = S9xGetByte (OpAddress); SetZN8 (Registers.AL); } -STATIC inline void LDX16 () +void LDX16 () { Registers.X.W = S9xGetWord (OpAddress); SetZN16 (Registers.X.W); } -STATIC inline void LDX8 () +void LDX8 () { Registers.XL = S9xGetByte (OpAddress); SetZN8 (Registers.XL); } -STATIC inline void LDY16 () +void LDY16 () { Registers.Y.W = S9xGetWord (OpAddress); SetZN16 (Registers.Y.W); } -STATIC inline void LDY8 () +void LDY8 () { Registers.YL = S9xGetByte (OpAddress); SetZN8 (Registers.YL); } -STATIC inline void A_LSR16 () +void A_LSR16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -527,7 +527,7 @@ STATIC inline void A_LSR16 () SetZN16 (Registers.A.W); } -STATIC inline void A_LSR8 () +void A_LSR8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -537,7 +537,7 @@ STATIC inline void A_LSR8 () SetZN8 (Registers.AL); } -STATIC inline void LSR16 () +void LSR16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -551,7 +551,7 @@ STATIC inline void LSR16 () SetZN16 (Work16); } -STATIC inline void LSR8 () +void LSR8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -563,19 +563,19 @@ STATIC inline void LSR8 () SetZN8 (Work8); } -STATIC inline void ORA16 () +void ORA16 () { Registers.A.W |= S9xGetWord (OpAddress); SetZN16 (Registers.A.W); } -STATIC inline void ORA8 () +void ORA8 () { Registers.AL |= S9xGetByte (OpAddress); SetZN8 (Registers.AL); } -STATIC inline void A_ROL16 () +void A_ROL16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -586,7 +586,7 @@ STATIC inline void A_ROL16 () SetZN16 ((uint16) Work32); } -STATIC inline void A_ROL8 () +void A_ROL8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -599,7 +599,7 @@ STATIC inline void A_ROL8 () SetZN8 ((uint8) Work16); } -STATIC inline void ROL16 () +void ROL16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -614,7 +614,7 @@ STATIC inline void ROL16 () SetZN16 ((uint16) Work32); } -STATIC inline void ROL8 () +void ROL8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -627,7 +627,7 @@ STATIC inline void ROL8 () SetZN8 ((uint8) Work16); } -STATIC inline void A_ROR16 () +void A_ROR16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -640,7 +640,7 @@ STATIC inline void A_ROR16 () SetZN16 ((uint16) Work32); } -STATIC inline void A_ROR8 () +void A_ROR8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -652,7 +652,7 @@ STATIC inline void A_ROR8 () SetZN8 ((uint8) Work16); } -STATIC inline void ROR16 () +void ROR16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -667,7 +667,7 @@ STATIC inline void ROR16 () SetZN16 ((uint16) Work32); } -STATIC inline void ROR8 () +void ROR8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -680,7 +680,7 @@ STATIC inline void ROR8 () SetZN8 ((uint8) Work16); } -STATIC inline void SBC16 () +void SBC16 () { Work16 = S9xGetWord (OpAddress); @@ -750,7 +750,7 @@ STATIC inline void SBC16 () } } -STATIC inline void SBC8 () +void SBC8 () { Work8 = S9xGetByte (OpAddress); if (CheckDecimal ()) @@ -801,47 +801,47 @@ STATIC inline void SBC8 () } } -STATIC inline void STA16 () +void STA16 () { S9xSetWord (Registers.A.W, OpAddress); } -STATIC inline void STA8 () +void STA8 () { S9xSetByte (Registers.AL, OpAddress); } -STATIC inline void STX16 () +void STX16 () { S9xSetWord (Registers.X.W, OpAddress); } -STATIC inline void STX8 () +void STX8 () { S9xSetByte (Registers.XL, OpAddress); } -STATIC inline void STY16 () +void STY16 () { S9xSetWord (Registers.Y.W, OpAddress); } -STATIC inline void STY8 () +void STY8 () { S9xSetByte (Registers.YL, OpAddress); } -STATIC inline void STZ16 () +void STZ16 () { S9xSetWord (0, OpAddress); } -STATIC inline void STZ8 () +void STZ8 () { S9xSetByte (0, OpAddress); } -STATIC inline void TSB16 () +void TSB16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -854,7 +854,7 @@ STATIC inline void TSB16 () S9xSetByte (Work16&0xFF, OpAddress); } -STATIC inline void TSB8 () +void TSB8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -865,7 +865,7 @@ STATIC inline void TSB8 () S9xSetByte (Work8, OpAddress); } -STATIC inline void TRB16 () +void TRB16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -878,7 +878,7 @@ STATIC inline void TRB16 () S9xSetByte (Work16&0xFF, OpAddress); } -STATIC inline void TRB8 () +void TRB8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; -- cgit v1.2.3 From d1fe64aef0298514150e543b1b13fbf03f33c3e1 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Sun, 23 Dec 2012 16:13:54 -0500 Subject: Various optimisations in the CPU emulation. Run the opcode as a tail call from the address calculation. This cuts on the needed return instructions. Pass the opcode address as a parameter; this keeps it in a register most of the time and avoids memory stores. --- source/cpumacro.h | 284 +++++++++++++++++++++++++++--------------------------- 1 file changed, 142 insertions(+), 142 deletions(-) (limited to 'source/cpumacro.h') diff --git a/source/cpumacro.h b/source/cpumacro.h index 5b4e15b..335576a 100644 --- a/source/cpumacro.h +++ b/source/cpumacro.h @@ -90,21 +90,21 @@ #ifndef _CPUMACRO_H_ #define _CPUMACRO_H_ -void SetZN16 (uint16 Work) +static void SetZN16 (uint16 Work) { ICPU._Zero = Work != 0; ICPU._Negative = (uint8) (Work >> 8); } -void SetZN8 (uint8 Work) +static void SetZN8 (uint8 Work) { ICPU._Zero = Work; ICPU._Negative = Work; } -void ADC8 () +static void ADC8 (long Addr) { - Work8 = S9xGetByte (OpAddress); + Work8 = S9xGetByte (Addr); if (CheckDecimal ()) { @@ -159,9 +159,9 @@ void ADC8 () } } -void ADC16 () +static void ADC16 (long Addr) { - Work16 = S9xGetWord (OpAddress); + Work16 = S9xGetWord (Addr); if (CheckDecimal ()) { @@ -235,19 +235,19 @@ void ADC16 () } } -void AND16 () +static void AND16 (long Addr) { - Registers.A.W &= S9xGetWord (OpAddress); + Registers.A.W &= S9xGetWord (Addr); SetZN16 (Registers.A.W); } -void AND8 () +static void AND8 (long Addr) { - Registers.AL &= S9xGetByte (OpAddress); + Registers.AL &= S9xGetByte (Addr); SetZN8 (Registers.AL); } -void A_ASL16 () +static inline void A_ASL16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -257,7 +257,7 @@ void A_ASL16 () SetZN16 (Registers.A.W); } -void A_ASL8 () +static inline void A_ASL8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -267,97 +267,97 @@ void A_ASL8 () SetZN8 (Registers.AL); } -void ASL16 () +static void ASL16 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetWord (OpAddress); + Work16 = S9xGetWord (Addr); ICPU._Carry = (Work16 & 0x8000) != 0; Work16 <<= 1; - //S9xSetWord (Work16, OpAddress); - S9xSetByte(Work16>>8, OpAddress+1); - S9xSetByte(Work16&0xFF, OpAddress); + //S9xSetWord (Work16, Addr); + S9xSetByte(Work16>>8, Addr+1); + S9xSetByte(Work16&0xFF, Addr); SetZN16 (Work16); } -void ASL8 () +static void ASL8 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work8 = S9xGetByte (OpAddress); + Work8 = S9xGetByte (Addr); ICPU._Carry = (Work8 & 0x80) != 0; Work8 <<= 1; - S9xSetByte (Work8, OpAddress); + S9xSetByte (Work8, Addr); SetZN8 (Work8); } -void BIT16 () +static void BIT16 (long Addr) { - Work16 = S9xGetWord (OpAddress); + Work16 = S9xGetWord (Addr); ICPU._Overflow = (Work16 & 0x4000) != 0; ICPU._Negative = (uint8) (Work16 >> 8); ICPU._Zero = (Work16 & Registers.A.W) != 0; } -void BIT8 () +static void BIT8 (long Addr) { - Work8 = S9xGetByte (OpAddress); + Work8 = S9xGetByte (Addr); ICPU._Overflow = (Work8 & 0x40) != 0; ICPU._Negative = Work8; ICPU._Zero = Work8 & Registers.AL; } -void CMP16 () +static void CMP16 (long Addr) { Int32 = (long) Registers.A.W - - (long) S9xGetWord (OpAddress); + (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); } -void CMP8 () +static void CMP8 (long Addr) { Int16 = (short) Registers.AL - - (short) S9xGetByte (OpAddress); + (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); } -void CMX16 () +static void CMX16 (long Addr) { Int32 = (long) Registers.X.W - - (long) S9xGetWord (OpAddress); + (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); } -void CMX8 () +static void CMX8 (long Addr) { Int16 = (short) Registers.XL - - (short) S9xGetByte (OpAddress); + (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); } -void CMY16 () +static void CMY16 (long Addr) { Int32 = (long) Registers.Y.W - - (long) S9xGetWord (OpAddress); + (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); } -void CMY8 () +static void CMY8 (long Addr) { Int16 = (short) Registers.YL - - (short) S9xGetByte (OpAddress); + (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); } -void A_DEC16 () +static inline void A_DEC16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -370,7 +370,7 @@ void A_DEC16 () SetZN16 (Registers.A.W); } -void A_DEC8 () +static inline void A_DEC8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -383,7 +383,7 @@ void A_DEC8 () SetZN8 (Registers.AL); } -void DEC16 () +static void DEC16 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -392,14 +392,14 @@ void DEC16 () CPU.WaitAddress = NULL; #endif - Work16 = S9xGetWord (OpAddress) - 1; - //S9xSetWord (Work16, OpAddress); - S9xSetByte (Work16>>8, OpAddress+1); - S9xSetByte (Work16&0xFF, OpAddress); + Work16 = S9xGetWord (Addr) - 1; + //S9xSetWord (Work16, Addr); + S9xSetByte (Work16>>8, Addr+1); + S9xSetByte (Work16&0xFF, Addr); SetZN16 (Work16); } -void DEC8 () +static void DEC8 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -408,24 +408,24 @@ void DEC8 () CPU.WaitAddress = NULL; #endif - Work8 = S9xGetByte (OpAddress) - 1; - S9xSetByte (Work8, OpAddress); + Work8 = S9xGetByte (Addr) - 1; + S9xSetByte (Work8, Addr); SetZN8 (Work8); } -void EOR16 () +static void EOR16 (long Addr) { - Registers.A.W ^= S9xGetWord (OpAddress); + Registers.A.W ^= S9xGetWord (Addr); SetZN16 (Registers.A.W); } -void EOR8 () +static void EOR8 (long Addr) { - Registers.AL ^= S9xGetByte (OpAddress); + Registers.AL ^= S9xGetByte (Addr); SetZN8 (Registers.AL); } -void A_INC16 () +static inline void A_INC16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -438,7 +438,7 @@ void A_INC16 () SetZN16 (Registers.A.W); } -void A_INC8 () +static inline void A_INC8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -451,7 +451,7 @@ void A_INC8 () SetZN8 (Registers.AL); } -void INC16 () +static void INC16 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -460,14 +460,14 @@ void INC16 () CPU.WaitAddress = NULL; #endif - Work16 = S9xGetWord (OpAddress) + 1; - //S9xSetWord (Work16, OpAddress); - S9xSetByte (Work16>>8, OpAddress+1); - S9xSetByte (Work16&0xFF, OpAddress); + Work16 = S9xGetWord (Addr) + 1; + //S9xSetWord (Work16, Addr); + S9xSetByte (Work16>>8, Addr+1); + S9xSetByte (Work16&0xFF, Addr); SetZN16 (Work16); } -void INC8 () +static void INC8 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -476,48 +476,48 @@ void INC8 () CPU.WaitAddress = NULL; #endif - Work8 = S9xGetByte (OpAddress) + 1; - S9xSetByte (Work8, OpAddress); + Work8 = S9xGetByte (Addr) + 1; + S9xSetByte (Work8, Addr); SetZN8 (Work8); } -void LDA16 () +static void LDA16 (long Addr) { - Registers.A.W = S9xGetWord (OpAddress); + Registers.A.W = S9xGetWord (Addr); SetZN16 (Registers.A.W); } -void LDA8 () +static void LDA8 (long Addr) { - Registers.AL = S9xGetByte (OpAddress); + Registers.AL = S9xGetByte (Addr); SetZN8 (Registers.AL); } -void LDX16 () +static void LDX16 (long Addr) { - Registers.X.W = S9xGetWord (OpAddress); + Registers.X.W = S9xGetWord (Addr); SetZN16 (Registers.X.W); } -void LDX8 () +static void LDX8 (long Addr) { - Registers.XL = S9xGetByte (OpAddress); + Registers.XL = S9xGetByte (Addr); SetZN8 (Registers.XL); } -void LDY16 () +static void LDY16 (long Addr) { - Registers.Y.W = S9xGetWord (OpAddress); + Registers.Y.W = S9xGetWord (Addr); SetZN16 (Registers.Y.W); } -void LDY8 () +static void LDY8 (long Addr) { - Registers.YL = S9xGetByte (OpAddress); + Registers.YL = S9xGetByte (Addr); SetZN8 (Registers.YL); } -void A_LSR16 () +static inline void A_LSR16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -527,7 +527,7 @@ void A_LSR16 () SetZN16 (Registers.A.W); } -void A_LSR8 () +static inline void A_LSR8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -537,45 +537,45 @@ void A_LSR8 () SetZN8 (Registers.AL); } -void LSR16 () +static void LSR16 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetWord (OpAddress); + Work16 = S9xGetWord (Addr); ICPU._Carry = Work16 & 1; Work16 >>= 1; - //S9xSetWord (Work16, OpAddress); - S9xSetByte (Work16>>8, OpAddress+1); - S9xSetByte (Work16&0xFF, OpAddress); + //S9xSetWord (Work16, Addr); + S9xSetByte (Work16>>8, Addr+1); + S9xSetByte (Work16&0xFF, Addr); SetZN16 (Work16); } -void LSR8 () +static void LSR8 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work8 = S9xGetByte (OpAddress); + Work8 = S9xGetByte (Addr); ICPU._Carry = Work8 & 1; Work8 >>= 1; - S9xSetByte (Work8, OpAddress); + S9xSetByte (Work8, Addr); SetZN8 (Work8); } -void ORA16 () +static void ORA16 (long Addr) { - Registers.A.W |= S9xGetWord (OpAddress); + Registers.A.W |= S9xGetWord (Addr); SetZN16 (Registers.A.W); } -void ORA8 () +static void ORA8 (long Addr) { - Registers.AL |= S9xGetByte (OpAddress); + Registers.AL |= S9xGetByte (Addr); SetZN8 (Registers.AL); } -void A_ROL16 () +static inline void A_ROL16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -586,7 +586,7 @@ void A_ROL16 () SetZN16 ((uint16) Work32); } -void A_ROL8 () +static inline void A_ROL8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -599,35 +599,35 @@ void A_ROL8 () SetZN8 ((uint8) Work16); } -void ROL16 () +static void ROL16 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work32 = S9xGetWord (OpAddress); + Work32 = S9xGetWord (Addr); Work32 <<= 1; Work32 |= CheckCarry(); ICPU._Carry = Work32 >= 0x10000; - //S9xSetWord ((uint16) Work32, OpAddress); - S9xSetByte((Work32>>8)&0xFF, OpAddress+1); - S9xSetByte(Work32&0xFF, OpAddress); + //S9xSetWord ((uint16) Work32, Addr); + S9xSetByte((Work32>>8)&0xFF, Addr+1); + S9xSetByte(Work32&0xFF, Addr); SetZN16 ((uint16) Work32); } -void ROL8 () +static void ROL8 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetByte (OpAddress); + Work16 = S9xGetByte (Addr); Work16 <<= 1; Work16 |= CheckCarry (); ICPU._Carry = Work16 >= 0x100; - S9xSetByte ((uint8) Work16, OpAddress); + S9xSetByte ((uint8) Work16, Addr); SetZN8 ((uint8) Work16); } -void A_ROR16 () +static inline void A_ROR16 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -640,7 +640,7 @@ void A_ROR16 () SetZN16 ((uint16) Work32); } -void A_ROR8 () +static inline void A_ROR8 () { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; @@ -652,37 +652,37 @@ void A_ROR8 () SetZN8 ((uint8) Work16); } -void ROR16 () +static void ROR16 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work32 = S9xGetWord (OpAddress); + Work32 = S9xGetWord (Addr); Work32 |= (int) CheckCarry() << 16; ICPU._Carry = (uint8) (Work32 & 1); Work32 >>= 1; - //S9xSetWord ((uint16) Work32, OpAddress); - S9xSetByte ( (Work32>>8)&0x00FF, OpAddress+1); - S9xSetByte (Work32&0x00FF, OpAddress); + //S9xSetWord ((uint16) Work32, Addr); + S9xSetByte ( (Work32>>8)&0x00FF, Addr+1); + S9xSetByte (Work32&0x00FF, Addr); SetZN16 ((uint16) Work32); } -void ROR8 () +static void ROR8 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetByte (OpAddress); + Work16 = S9xGetByte (Addr); Work16 |= (int) CheckCarry () << 8; ICPU._Carry = (uint8) (Work16 & 1); Work16 >>= 1; - S9xSetByte ((uint8) Work16, OpAddress); + S9xSetByte ((uint8) Work16, Addr); SetZN8 ((uint8) Work16); } -void SBC16 () +static void SBC16 (long Addr) { - Work16 = S9xGetWord (OpAddress); + Work16 = S9xGetWord (Addr); if (CheckDecimal ()) { @@ -750,9 +750,9 @@ void SBC16 () } } -void SBC8 () +static void SBC8 (long Addr) { - Work8 = S9xGetByte (OpAddress); + Work8 = S9xGetByte (Addr); if (CheckDecimal ()) { A1 = (Registers.A.W) & 0xF; @@ -801,92 +801,92 @@ void SBC8 () } } -void STA16 () +static void STA16 (long Addr) { - S9xSetWord (Registers.A.W, OpAddress); + S9xSetWord (Registers.A.W, Addr); } -void STA8 () +static void STA8 (long Addr) { - S9xSetByte (Registers.AL, OpAddress); + S9xSetByte (Registers.AL, Addr); } -void STX16 () +static void STX16 (long Addr) { - S9xSetWord (Registers.X.W, OpAddress); + S9xSetWord (Registers.X.W, Addr); } -void STX8 () +static void STX8 (long Addr) { - S9xSetByte (Registers.XL, OpAddress); + S9xSetByte (Registers.XL, Addr); } -void STY16 () +static void STY16 (long Addr) { - S9xSetWord (Registers.Y.W, OpAddress); + S9xSetWord (Registers.Y.W, Addr); } -void STY8 () +static void STY8 (long Addr) { - S9xSetByte (Registers.YL, OpAddress); + S9xSetByte (Registers.YL, Addr); } -void STZ16 () +static void STZ16 (long Addr) { - S9xSetWord (0, OpAddress); + S9xSetWord (0, Addr); } -void STZ8 () +static void STZ8 (long Addr) { - S9xSetByte (0, OpAddress); + S9xSetByte (0, Addr); } -void TSB16 () +static void TSB16 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetWord (OpAddress); + Work16 = S9xGetWord (Addr); ICPU._Zero = (Work16 & Registers.A.W) != 0; Work16 |= Registers.A.W; - //S9xSetWord (Work16, OpAddress); - S9xSetByte (Work16>>8, OpAddress+1); - S9xSetByte (Work16&0xFF, OpAddress); + //S9xSetWord (Work16, Addr); + S9xSetByte (Work16>>8, Addr+1); + S9xSetByte (Work16&0xFF, Addr); } -void TSB8 () +static void TSB8 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work8 = S9xGetByte (OpAddress); + Work8 = S9xGetByte (Addr); ICPU._Zero = Work8 & Registers.AL; Work8 |= Registers.AL; - S9xSetByte (Work8, OpAddress); + S9xSetByte (Work8, Addr); } -void TRB16 () +static void TRB16 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetWord (OpAddress); + Work16 = S9xGetWord (Addr); ICPU._Zero = (Work16 & Registers.A.W) != 0; Work16 &= ~Registers.A.W; - //S9xSetWord (Work16, OpAddress); - S9xSetByte (Work16>>8, OpAddress+1); - S9xSetByte (Work16&0xFF, OpAddress); + //S9xSetWord (Work16, Addr); + S9xSetByte (Work16>>8, Addr+1); + S9xSetByte (Work16&0xFF, Addr); } -void TRB8 () +static void TRB8 (long Addr) { #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work8 = S9xGetByte (OpAddress); + Work8 = S9xGetByte (Addr); ICPU._Zero = Work8 & Registers.AL; Work8 &= ~Registers.AL; - S9xSetByte (Work8, OpAddress); + S9xSetByte (Work8, Addr); } #endif -- cgit v1.2.3 From f29c76dc58689fe55f4ece494a0d3d44c831203f Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Mon, 24 Dec 2012 03:53:20 -0500 Subject: End the use of global variables for CPU emulation. This creates fewer memory store instructions in many SNES, SA1 and APU opcodes. Fix the APU half-carry bug, which may be audible. globals.cpp: Get rid of A1, A2, A3, A4, W1, W2, W3, W4, Int8, Int16, Int32, Work8, Work16, Work32, Ans8, Ans16, Ans32. --- source/cpumacro.h | 128 +++++++++++++++++++++++++++--------------------------- 1 file changed, 64 insertions(+), 64 deletions(-) (limited to 'source/cpumacro.h') diff --git a/source/cpumacro.h b/source/cpumacro.h index 335576a..1bd5d2f 100644 --- a/source/cpumacro.h +++ b/source/cpumacro.h @@ -104,14 +104,14 @@ static void SetZN8 (uint8 Work) static void ADC8 (long Addr) { - Work8 = S9xGetByte (Addr); + uint8 Work8 = S9xGetByte (Addr); if (CheckDecimal ()) { - A1 = (Registers.A.W) & 0xF; - A2 = (Registers.A.W >> 4) & 0xF; - W1 = Work8 & 0xF; - W2 = (Work8 >> 4) & 0xF; + uint8 A1 = (Registers.A.W) & 0xF; + uint8 A2 = (Registers.A.W >> 4) & 0xF; + uint8 W1 = Work8 & 0xF; + uint8 W2 = (Work8 >> 4) & 0xF; A1 += W1 + CheckCarry(); if (A1 > 9) @@ -133,7 +133,7 @@ static void ADC8 (long Addr) ClearCarry (); } - Ans8 = (A2 << 4) | A1; + int8 Ans8 = (A2 << 4) | A1; if (~(Registers.AL ^ Work8) & (Work8 ^ Ans8) & 0x80) SetOverflow(); @@ -144,7 +144,7 @@ static void ADC8 (long Addr) } else { - Ans16 = Registers.AL + Work8 + CheckCarry(); + int16 Ans16 = Registers.AL + Work8 + CheckCarry(); ICPU._Carry = Ans16 >= 0x100; @@ -161,18 +161,18 @@ static void ADC8 (long Addr) static void ADC16 (long Addr) { - Work16 = S9xGetWord (Addr); + uint16 Work16 = S9xGetWord (Addr); if (CheckDecimal ()) { - A1 = (Registers.A.W) & 0xF; - A2 = (Registers.A.W >> 4) & 0xF; - A3 = (Registers.A.W >> 8) & 0xF; - A4 = (Registers.A.W >> 12) & 0xF; - W1 = Work16 & 0xF; - W2 = (Work16 >> 4) & 0xF; - W3 = (Work16 >> 8) & 0xF; - W4 = (Work16 >> 12) & 0xF; + uint8 A1 = (Registers.A.W) & 0xF; + uint8 A2 = (Registers.A.W >> 4) & 0xF; + uint8 A3 = (Registers.A.W >> 8) & 0xF; + uint8 A4 = (Registers.A.W >> 12) & 0xF; + uint8 W1 = Work16 & 0xF; + uint8 W2 = (Work16 >> 4) & 0xF; + uint8 W3 = (Work16 >> 8) & 0xF; + uint8 W4 = (Work16 >> 12) & 0xF; A1 += W1 + CheckCarry (); if (A1 > 9) @@ -210,7 +210,7 @@ static void ADC16 (long Addr) ClearCarry (); } - Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); + uint16 Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); if (~(Registers.A.W ^ Work16) & (Work16 ^ Ans16) & 0x8000) SetOverflow(); @@ -221,7 +221,7 @@ static void ADC16 (long Addr) } else { - Ans32 = Registers.A.W + Work16 + CheckCarry(); + uint32 Ans32 = Registers.A.W + Work16 + CheckCarry(); ICPU._Carry = Ans32 >= 0x10000; @@ -272,7 +272,7 @@ static void ASL16 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetWord (Addr); + uint16 Work16 = S9xGetWord (Addr); ICPU._Carry = (Work16 & 0x8000) != 0; Work16 <<= 1; //S9xSetWord (Work16, Addr); @@ -286,7 +286,7 @@ static void ASL8 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work8 = S9xGetByte (Addr); + uint8 Work8 = S9xGetByte (Addr); ICPU._Carry = (Work8 & 0x80) != 0; Work8 <<= 1; S9xSetByte (Work8, Addr); @@ -295,7 +295,7 @@ static void ASL8 (long Addr) static void BIT16 (long Addr) { - Work16 = S9xGetWord (Addr); + uint16 Work16 = S9xGetWord (Addr); ICPU._Overflow = (Work16 & 0x4000) != 0; ICPU._Negative = (uint8) (Work16 >> 8); ICPU._Zero = (Work16 & Registers.A.W) != 0; @@ -303,7 +303,7 @@ static void BIT16 (long Addr) static void BIT8 (long Addr) { - Work8 = S9xGetByte (Addr); + uint8 Work8 = S9xGetByte (Addr); ICPU._Overflow = (Work8 & 0x40) != 0; ICPU._Negative = Work8; ICPU._Zero = Work8 & Registers.AL; @@ -311,7 +311,7 @@ static void BIT8 (long Addr) static void CMP16 (long Addr) { - Int32 = (long) Registers.A.W - + int32 Int32 = (long) Registers.A.W - (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); @@ -319,7 +319,7 @@ static void CMP16 (long Addr) static void CMP8 (long Addr) { - Int16 = (short) Registers.AL - + int16 Int16 = (short) Registers.AL - (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); @@ -327,7 +327,7 @@ static void CMP8 (long Addr) static void CMX16 (long Addr) { - Int32 = (long) Registers.X.W - + int32 Int32 = (long) Registers.X.W - (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); @@ -335,7 +335,7 @@ static void CMX16 (long Addr) static void CMX8 (long Addr) { - Int16 = (short) Registers.XL - + int16 Int16 = (short) Registers.XL - (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); @@ -343,7 +343,7 @@ static void CMX8 (long Addr) static void CMY16 (long Addr) { - Int32 = (long) Registers.Y.W - + int32 Int32 = (long) Registers.Y.W - (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); @@ -351,7 +351,7 @@ static void CMY16 (long Addr) static void CMY8 (long Addr) { - Int16 = (short) Registers.YL - + int16 Int16 = (short) Registers.YL - (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); @@ -392,7 +392,7 @@ static void DEC16 (long Addr) CPU.WaitAddress = NULL; #endif - Work16 = S9xGetWord (Addr) - 1; + uint16 Work16 = S9xGetWord (Addr) - 1; //S9xSetWord (Work16, Addr); S9xSetByte (Work16>>8, Addr+1); S9xSetByte (Work16&0xFF, Addr); @@ -408,7 +408,7 @@ static void DEC8 (long Addr) CPU.WaitAddress = NULL; #endif - Work8 = S9xGetByte (Addr) - 1; + uint8 Work8 = S9xGetByte (Addr) - 1; S9xSetByte (Work8, Addr); SetZN8 (Work8); } @@ -460,7 +460,7 @@ static void INC16 (long Addr) CPU.WaitAddress = NULL; #endif - Work16 = S9xGetWord (Addr) + 1; + uint16 Work16 = S9xGetWord (Addr) + 1; //S9xSetWord (Work16, Addr); S9xSetByte (Work16>>8, Addr+1); S9xSetByte (Work16&0xFF, Addr); @@ -476,7 +476,7 @@ static void INC8 (long Addr) CPU.WaitAddress = NULL; #endif - Work8 = S9xGetByte (Addr) + 1; + uint8 Work8 = S9xGetByte (Addr) + 1; S9xSetByte (Work8, Addr); SetZN8 (Work8); } @@ -542,7 +542,7 @@ static void LSR16 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetWord (Addr); + uint16 Work16 = S9xGetWord (Addr); ICPU._Carry = Work16 & 1; Work16 >>= 1; //S9xSetWord (Work16, Addr); @@ -556,7 +556,7 @@ static void LSR8 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work8 = S9xGetByte (Addr); + uint8 Work8 = S9xGetByte (Addr); ICPU._Carry = Work8 & 1; Work8 >>= 1; S9xSetByte (Work8, Addr); @@ -580,7 +580,7 @@ static inline void A_ROL16 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work32 = (Registers.A.W << 1) | CheckCarry(); + uint32 Work32 = (Registers.A.W << 1) | CheckCarry(); ICPU._Carry = Work32 >= 0x10000; Registers.A.W = (uint16) Work32; SetZN16 ((uint16) Work32); @@ -591,7 +591,7 @@ static inline void A_ROL8 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = Registers.AL; + uint16 Work16 = Registers.AL; Work16 <<= 1; Work16 |= CheckCarry(); ICPU._Carry = Work16 >= 0x100; @@ -604,7 +604,7 @@ static void ROL16 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work32 = S9xGetWord (Addr); + uint32 Work32 = S9xGetWord (Addr); Work32 <<= 1; Work32 |= CheckCarry(); ICPU._Carry = Work32 >= 0x10000; @@ -619,7 +619,7 @@ static void ROL8 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetByte (Addr); + uint16 Work16 = S9xGetByte (Addr); Work16 <<= 1; Work16 |= CheckCarry (); ICPU._Carry = Work16 >= 0x100; @@ -632,7 +632,7 @@ static inline void A_ROR16 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work32 = Registers.A.W; + uint32 Work32 = Registers.A.W; Work32 |= (int) CheckCarry() << 16; ICPU._Carry = (uint8) (Work32 & 1); Work32 >>= 1; @@ -645,7 +645,7 @@ static inline void A_ROR8 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = Registers.AL | ((uint16) CheckCarry() << 8); + uint16 Work16 = Registers.AL | ((uint16) CheckCarry() << 8); ICPU._Carry = (uint8) Work16 & 1; Work16 >>= 1; Registers.AL = (uint8) Work16; @@ -657,7 +657,7 @@ static void ROR16 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work32 = S9xGetWord (Addr); + uint32 Work32 = S9xGetWord (Addr); Work32 |= (int) CheckCarry() << 16; ICPU._Carry = (uint8) (Work32 & 1); Work32 >>= 1; @@ -672,7 +672,7 @@ static void ROR8 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetByte (Addr); + uint16 Work16 = S9xGetByte (Addr); Work16 |= (int) CheckCarry () << 8; ICPU._Carry = (uint8) (Work16 & 1); Work16 >>= 1; @@ -682,18 +682,18 @@ static void ROR8 (long Addr) static void SBC16 (long Addr) { - Work16 = S9xGetWord (Addr); + uint16 Work16 = S9xGetWord (Addr); if (CheckDecimal ()) { - A1 = (Registers.A.W) & 0xF; - A2 = (Registers.A.W >> 4) & 0xF; - A3 = (Registers.A.W >> 8) & 0xF; - A4 = (Registers.A.W >> 12) & 0xF; - W1 = Work16 & 0xF; - W2 = (Work16 >> 4) & 0xF; - W3 = (Work16 >> 8) & 0xF; - W4 = (Work16 >> 12) & 0xF; + uint8 A1 = (Registers.A.W) & 0xF; + uint8 A2 = (Registers.A.W >> 4) & 0xF; + uint8 A3 = (Registers.A.W >> 8) & 0xF; + uint8 A4 = (Registers.A.W >> 12) & 0xF; + uint8 W1 = Work16 & 0xF; + uint8 W2 = (Work16 >> 4) & 0xF; + uint8 W3 = (Work16 >> 8) & 0xF; + uint8 W4 = (Work16 >> 12) & 0xF; A1 -= W1 + !CheckCarry (); A2 -= W2; @@ -724,7 +724,7 @@ static void SBC16 (long Addr) SetCarry (); } - Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); + uint16 Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); if ((Registers.A.W ^ Work16) & (Registers.A.W ^ Ans16) & 0x8000) SetOverflow(); @@ -736,7 +736,7 @@ static void SBC16 (long Addr) else { - Int32 = (long) Registers.A.W - (long) Work16 + (long) CheckCarry() - 1; + int32 Int32 = (long) Registers.A.W - (long) Work16 + (long) CheckCarry() - 1; ICPU._Carry = Int32 >= 0; @@ -752,13 +752,13 @@ static void SBC16 (long Addr) static void SBC8 (long Addr) { - Work8 = S9xGetByte (Addr); + uint8 Work8 = S9xGetByte (Addr); if (CheckDecimal ()) { - A1 = (Registers.A.W) & 0xF; - A2 = (Registers.A.W >> 4) & 0xF; - W1 = Work8 & 0xF; - W2 = (Work8 >> 4) & 0xF; + uint8 A1 = (Registers.A.W) & 0xF; + uint8 A2 = (Registers.A.W >> 4) & 0xF; + uint8 W1 = Work8 & 0xF; + uint8 W2 = (Work8 >> 4) & 0xF; A1 -= W1 + !CheckCarry (); A2 -= W2; @@ -777,7 +777,7 @@ static void SBC8 (long Addr) SetCarry (); } - Ans8 = (A2 << 4) | A1; + uint8 Ans8 = (A2 << 4) | A1; if ((Registers.AL ^ Work8) & (Registers.AL ^ Ans8) & 0x80) SetOverflow (); @@ -788,7 +788,7 @@ static void SBC8 (long Addr) } else { - Int16 = (short) Registers.AL - (short) Work8 + (short) CheckCarry() - 1; + int16 Int16 = (short) Registers.AL - (short) Work8 + (short) CheckCarry() - 1; ICPU._Carry = Int16 >= 0; if ((Registers.AL ^ Work8) & @@ -846,7 +846,7 @@ static void TSB16 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetWord (Addr); + uint16 Work16 = S9xGetWord (Addr); ICPU._Zero = (Work16 & Registers.A.W) != 0; Work16 |= Registers.A.W; //S9xSetWord (Work16, Addr); @@ -859,7 +859,7 @@ static void TSB8 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work8 = S9xGetByte (Addr); + uint8 Work8 = S9xGetByte (Addr); ICPU._Zero = Work8 & Registers.AL; Work8 |= Registers.AL; S9xSetByte (Work8, Addr); @@ -870,7 +870,7 @@ static void TRB16 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work16 = S9xGetWord (Addr); + uint16 Work16 = S9xGetWord (Addr); ICPU._Zero = (Work16 & Registers.A.W) != 0; Work16 &= ~Registers.A.W; //S9xSetWord (Work16, Addr); @@ -883,7 +883,7 @@ static void TRB8 (long Addr) #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - Work8 = S9xGetByte (Addr); + uint8 Work8 = S9xGetByte (Addr); ICPU._Zero = Work8 & Registers.AL; Work8 &= ~Registers.AL; S9xSetByte (Work8, Addr); -- cgit v1.2.3 From e5869adc4469115c7eac9abf70145fc178e017de Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Wed, 26 Dec 2012 14:42:02 -0500 Subject: Merge Registers structures into their respective CPUs to avoid additional memory addresses being loaded every opcode. --- source/cpumacro.h | 236 +++++++++++++++++++++++++++--------------------------- 1 file changed, 118 insertions(+), 118 deletions(-) (limited to 'source/cpumacro.h') diff --git a/source/cpumacro.h b/source/cpumacro.h index 1bd5d2f..c70c2ba 100644 --- a/source/cpumacro.h +++ b/source/cpumacro.h @@ -108,8 +108,8 @@ static void ADC8 (long Addr) if (CheckDecimal ()) { - uint8 A1 = (Registers.A.W) & 0xF; - uint8 A2 = (Registers.A.W >> 4) & 0xF; + uint8 A1 = (ICPU.Registers.A.W) & 0xF; + uint8 A2 = (ICPU.Registers.A.W >> 4) & 0xF; uint8 W1 = Work8 & 0xF; uint8 W2 = (Work8 >> 4) & 0xF; @@ -134,27 +134,27 @@ static void ADC8 (long Addr) } int8 Ans8 = (A2 << 4) | A1; - if (~(Registers.AL ^ Work8) & + if (~(ICPU.Registers.AL ^ Work8) & (Work8 ^ Ans8) & 0x80) SetOverflow(); else ClearOverflow(); - Registers.AL = Ans8; - SetZN8 (Registers.AL); + ICPU.Registers.AL = Ans8; + SetZN8 (ICPU.Registers.AL); } else { - int16 Ans16 = Registers.AL + Work8 + CheckCarry(); + int16 Ans16 = ICPU.Registers.AL + Work8 + CheckCarry(); ICPU._Carry = Ans16 >= 0x100; - if (~(Registers.AL ^ Work8) & + if (~(ICPU.Registers.AL ^ Work8) & (Work8 ^ (uint8) Ans16) & 0x80) SetOverflow(); else ClearOverflow(); - Registers.AL = (uint8) Ans16; - SetZN8 (Registers.AL); + ICPU.Registers.AL = (uint8) Ans16; + SetZN8 (ICPU.Registers.AL); } } @@ -165,10 +165,10 @@ static void ADC16 (long Addr) if (CheckDecimal ()) { - uint8 A1 = (Registers.A.W) & 0xF; - uint8 A2 = (Registers.A.W >> 4) & 0xF; - uint8 A3 = (Registers.A.W >> 8) & 0xF; - uint8 A4 = (Registers.A.W >> 12) & 0xF; + uint8 A1 = (ICPU.Registers.A.W) & 0xF; + uint8 A2 = (ICPU.Registers.A.W >> 4) & 0xF; + uint8 A3 = (ICPU.Registers.A.W >> 8) & 0xF; + uint8 A4 = (ICPU.Registers.A.W >> 12) & 0xF; uint8 W1 = Work16 & 0xF; uint8 W2 = (Work16 >> 4) & 0xF; uint8 W3 = (Work16 >> 8) & 0xF; @@ -211,40 +211,40 @@ static void ADC16 (long Addr) } uint16 Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); - if (~(Registers.A.W ^ Work16) & + if (~(ICPU.Registers.A.W ^ Work16) & (Work16 ^ Ans16) & 0x8000) SetOverflow(); else ClearOverflow(); - Registers.A.W = Ans16; - SetZN16 (Registers.A.W); + ICPU.Registers.A.W = Ans16; + SetZN16 (ICPU.Registers.A.W); } else { - uint32 Ans32 = Registers.A.W + Work16 + CheckCarry(); + uint32 Ans32 = ICPU.Registers.A.W + Work16 + CheckCarry(); ICPU._Carry = Ans32 >= 0x10000; - if (~(Registers.A.W ^ Work16) & + if (~(ICPU.Registers.A.W ^ Work16) & (Work16 ^ (uint16) Ans32) & 0x8000) SetOverflow(); else ClearOverflow(); - Registers.A.W = (uint16) Ans32; - SetZN16 (Registers.A.W); + ICPU.Registers.A.W = (uint16) Ans32; + SetZN16 (ICPU.Registers.A.W); } } static void AND16 (long Addr) { - Registers.A.W &= S9xGetWord (Addr); - SetZN16 (Registers.A.W); + ICPU.Registers.A.W &= S9xGetWord (Addr); + SetZN16 (ICPU.Registers.A.W); } static void AND8 (long Addr) { - Registers.AL &= S9xGetByte (Addr); - SetZN8 (Registers.AL); + ICPU.Registers.AL &= S9xGetByte (Addr); + SetZN8 (ICPU.Registers.AL); } static inline void A_ASL16 () @@ -252,9 +252,9 @@ static inline void A_ASL16 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - ICPU._Carry = (Registers.AH & 0x80) != 0; - Registers.A.W <<= 1; - SetZN16 (Registers.A.W); + ICPU._Carry = (ICPU.Registers.AH & 0x80) != 0; + ICPU.Registers.A.W <<= 1; + SetZN16 (ICPU.Registers.A.W); } static inline void A_ASL8 () @@ -262,9 +262,9 @@ static inline void A_ASL8 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - ICPU._Carry = (Registers.AL & 0x80) != 0; - Registers.AL <<= 1; - SetZN8 (Registers.AL); + ICPU._Carry = (ICPU.Registers.AL & 0x80) != 0; + ICPU.Registers.AL <<= 1; + SetZN8 (ICPU.Registers.AL); } static void ASL16 (long Addr) @@ -298,7 +298,7 @@ static void BIT16 (long Addr) uint16 Work16 = S9xGetWord (Addr); ICPU._Overflow = (Work16 & 0x4000) != 0; ICPU._Negative = (uint8) (Work16 >> 8); - ICPU._Zero = (Work16 & Registers.A.W) != 0; + ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; } static void BIT8 (long Addr) @@ -306,12 +306,12 @@ static void BIT8 (long Addr) uint8 Work8 = S9xGetByte (Addr); ICPU._Overflow = (Work8 & 0x40) != 0; ICPU._Negative = Work8; - ICPU._Zero = Work8 & Registers.AL; + ICPU._Zero = Work8 & ICPU.Registers.AL; } static void CMP16 (long Addr) { - int32 Int32 = (long) Registers.A.W - + int32 Int32 = (long) ICPU.Registers.A.W - (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); @@ -319,7 +319,7 @@ static void CMP16 (long Addr) static void CMP8 (long Addr) { - int16 Int16 = (short) Registers.AL - + int16 Int16 = (short) ICPU.Registers.AL - (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); @@ -327,7 +327,7 @@ static void CMP8 (long Addr) static void CMX16 (long Addr) { - int32 Int32 = (long) Registers.X.W - + int32 Int32 = (long) ICPU.Registers.X.W - (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); @@ -335,7 +335,7 @@ static void CMX16 (long Addr) static void CMX8 (long Addr) { - int16 Int16 = (short) Registers.XL - + int16 Int16 = (short) ICPU.Registers.XL - (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); @@ -343,7 +343,7 @@ static void CMX8 (long Addr) static void CMY16 (long Addr) { - int32 Int32 = (long) Registers.Y.W - + int32 Int32 = (long) ICPU.Registers.Y.W - (long) S9xGetWord (Addr); ICPU._Carry = Int32 >= 0; SetZN16 ((uint16) Int32); @@ -351,7 +351,7 @@ static void CMY16 (long Addr) static void CMY8 (long Addr) { - int16 Int16 = (short) Registers.YL - + int16 Int16 = (short) ICPU.Registers.YL - (short) S9xGetByte (Addr); ICPU._Carry = Int16 >= 0; SetZN8 ((uint8) Int16); @@ -366,8 +366,8 @@ static inline void A_DEC16 () CPU.WaitAddress = NULL; #endif - Registers.A.W--; - SetZN16 (Registers.A.W); + ICPU.Registers.A.W--; + SetZN16 (ICPU.Registers.A.W); } static inline void A_DEC8 () @@ -379,8 +379,8 @@ static inline void A_DEC8 () CPU.WaitAddress = NULL; #endif - Registers.AL--; - SetZN8 (Registers.AL); + ICPU.Registers.AL--; + SetZN8 (ICPU.Registers.AL); } static void DEC16 (long Addr) @@ -415,14 +415,14 @@ static void DEC8 (long Addr) static void EOR16 (long Addr) { - Registers.A.W ^= S9xGetWord (Addr); - SetZN16 (Registers.A.W); + ICPU.Registers.A.W ^= S9xGetWord (Addr); + SetZN16 (ICPU.Registers.A.W); } static void EOR8 (long Addr) { - Registers.AL ^= S9xGetByte (Addr); - SetZN8 (Registers.AL); + ICPU.Registers.AL ^= S9xGetByte (Addr); + SetZN8 (ICPU.Registers.AL); } static inline void A_INC16 () @@ -434,8 +434,8 @@ static inline void A_INC16 () CPU.WaitAddress = NULL; #endif - Registers.A.W++; - SetZN16 (Registers.A.W); + ICPU.Registers.A.W++; + SetZN16 (ICPU.Registers.A.W); } static inline void A_INC8 () @@ -447,8 +447,8 @@ static inline void A_INC8 () CPU.WaitAddress = NULL; #endif - Registers.AL++; - SetZN8 (Registers.AL); + ICPU.Registers.AL++; + SetZN8 (ICPU.Registers.AL); } static void INC16 (long Addr) @@ -483,38 +483,38 @@ static void INC8 (long Addr) static void LDA16 (long Addr) { - Registers.A.W = S9xGetWord (Addr); - SetZN16 (Registers.A.W); + ICPU.Registers.A.W = S9xGetWord (Addr); + SetZN16 (ICPU.Registers.A.W); } static void LDA8 (long Addr) { - Registers.AL = S9xGetByte (Addr); - SetZN8 (Registers.AL); + ICPU.Registers.AL = S9xGetByte (Addr); + SetZN8 (ICPU.Registers.AL); } static void LDX16 (long Addr) { - Registers.X.W = S9xGetWord (Addr); - SetZN16 (Registers.X.W); + ICPU.Registers.X.W = S9xGetWord (Addr); + SetZN16 (ICPU.Registers.X.W); } static void LDX8 (long Addr) { - Registers.XL = S9xGetByte (Addr); - SetZN8 (Registers.XL); + ICPU.Registers.XL = S9xGetByte (Addr); + SetZN8 (ICPU.Registers.XL); } static void LDY16 (long Addr) { - Registers.Y.W = S9xGetWord (Addr); - SetZN16 (Registers.Y.W); + ICPU.Registers.Y.W = S9xGetWord (Addr); + SetZN16 (ICPU.Registers.Y.W); } static void LDY8 (long Addr) { - Registers.YL = S9xGetByte (Addr); - SetZN8 (Registers.YL); + ICPU.Registers.YL = S9xGetByte (Addr); + SetZN8 (ICPU.Registers.YL); } static inline void A_LSR16 () @@ -522,9 +522,9 @@ static inline void A_LSR16 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - ICPU._Carry = Registers.AL & 1; - Registers.A.W >>= 1; - SetZN16 (Registers.A.W); + ICPU._Carry = ICPU.Registers.AL & 1; + ICPU.Registers.A.W >>= 1; + SetZN16 (ICPU.Registers.A.W); } static inline void A_LSR8 () @@ -532,9 +532,9 @@ static inline void A_LSR8 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - ICPU._Carry = Registers.AL & 1; - Registers.AL >>= 1; - SetZN8 (Registers.AL); + ICPU._Carry = ICPU.Registers.AL & 1; + ICPU.Registers.AL >>= 1; + SetZN8 (ICPU.Registers.AL); } static void LSR16 (long Addr) @@ -565,14 +565,14 @@ static void LSR8 (long Addr) static void ORA16 (long Addr) { - Registers.A.W |= S9xGetWord (Addr); - SetZN16 (Registers.A.W); + ICPU.Registers.A.W |= S9xGetWord (Addr); + SetZN16 (ICPU.Registers.A.W); } static void ORA8 (long Addr) { - Registers.AL |= S9xGetByte (Addr); - SetZN8 (Registers.AL); + ICPU.Registers.AL |= S9xGetByte (Addr); + SetZN8 (ICPU.Registers.AL); } static inline void A_ROL16 () @@ -580,9 +580,9 @@ static inline void A_ROL16 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - uint32 Work32 = (Registers.A.W << 1) | CheckCarry(); + uint32 Work32 = (ICPU.Registers.A.W << 1) | CheckCarry(); ICPU._Carry = Work32 >= 0x10000; - Registers.A.W = (uint16) Work32; + ICPU.Registers.A.W = (uint16) Work32; SetZN16 ((uint16) Work32); } @@ -591,11 +591,11 @@ static inline void A_ROL8 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - uint16 Work16 = Registers.AL; + uint16 Work16 = ICPU.Registers.AL; Work16 <<= 1; Work16 |= CheckCarry(); ICPU._Carry = Work16 >= 0x100; - Registers.AL = (uint8) Work16; + ICPU.Registers.AL = (uint8) Work16; SetZN8 ((uint8) Work16); } @@ -632,11 +632,11 @@ static inline void A_ROR16 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - uint32 Work32 = Registers.A.W; + uint32 Work32 = ICPU.Registers.A.W; Work32 |= (int) CheckCarry() << 16; ICPU._Carry = (uint8) (Work32 & 1); Work32 >>= 1; - Registers.A.W = (uint16) Work32; + ICPU.Registers.A.W = (uint16) Work32; SetZN16 ((uint16) Work32); } @@ -645,10 +645,10 @@ static inline void A_ROR8 () #ifndef SA1_OPCODES CPU.Cycles += ONE_CYCLE; #endif - uint16 Work16 = Registers.AL | ((uint16) CheckCarry() << 8); + uint16 Work16 = ICPU.Registers.AL | ((uint16) CheckCarry() << 8); ICPU._Carry = (uint8) Work16 & 1; Work16 >>= 1; - Registers.AL = (uint8) Work16; + ICPU.Registers.AL = (uint8) Work16; SetZN8 ((uint8) Work16); } @@ -686,10 +686,10 @@ static void SBC16 (long Addr) if (CheckDecimal ()) { - uint8 A1 = (Registers.A.W) & 0xF; - uint8 A2 = (Registers.A.W >> 4) & 0xF; - uint8 A3 = (Registers.A.W >> 8) & 0xF; - uint8 A4 = (Registers.A.W >> 12) & 0xF; + uint8 A1 = (ICPU.Registers.A.W) & 0xF; + uint8 A2 = (ICPU.Registers.A.W >> 4) & 0xF; + uint8 A3 = (ICPU.Registers.A.W >> 8) & 0xF; + uint8 A4 = (ICPU.Registers.A.W >> 12) & 0xF; uint8 W1 = Work16 & 0xF; uint8 W2 = (Work16 >> 4) & 0xF; uint8 W3 = (Work16 >> 8) & 0xF; @@ -725,28 +725,28 @@ static void SBC16 (long Addr) } uint16 Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1); - if ((Registers.A.W ^ Work16) & - (Registers.A.W ^ Ans16) & 0x8000) + if ((ICPU.Registers.A.W ^ Work16) & + (ICPU.Registers.A.W ^ Ans16) & 0x8000) SetOverflow(); else ClearOverflow(); - Registers.A.W = Ans16; - SetZN16 (Registers.A.W); + ICPU.Registers.A.W = Ans16; + SetZN16 (ICPU.Registers.A.W); } else { - int32 Int32 = (long) Registers.A.W - (long) Work16 + (long) CheckCarry() - 1; + int32 Int32 = (long) ICPU.Registers.A.W - (long) Work16 + (long) CheckCarry() - 1; ICPU._Carry = Int32 >= 0; - if ((Registers.A.W ^ Work16) & - (Registers.A.W ^ (uint16) Int32) & 0x8000) + if ((ICPU.Registers.A.W ^ Work16) & + (ICPU.Registers.A.W ^ (uint16) Int32) & 0x8000) SetOverflow(); else ClearOverflow (); - Registers.A.W = (uint16) Int32; - SetZN16 (Registers.A.W); + ICPU.Registers.A.W = (uint16) Int32; + SetZN16 (ICPU.Registers.A.W); } } @@ -755,8 +755,8 @@ static void SBC8 (long Addr) uint8 Work8 = S9xGetByte (Addr); if (CheckDecimal ()) { - uint8 A1 = (Registers.A.W) & 0xF; - uint8 A2 = (Registers.A.W >> 4) & 0xF; + uint8 A1 = (ICPU.Registers.A.W) & 0xF; + uint8 A2 = (ICPU.Registers.A.W >> 4) & 0xF; uint8 W1 = Work8 & 0xF; uint8 W2 = (Work8 >> 4) & 0xF; @@ -778,57 +778,57 @@ static void SBC8 (long Addr) } uint8 Ans8 = (A2 << 4) | A1; - if ((Registers.AL ^ Work8) & - (Registers.AL ^ Ans8) & 0x80) + if ((ICPU.Registers.AL ^ Work8) & + (ICPU.Registers.AL ^ Ans8) & 0x80) SetOverflow (); else ClearOverflow (); - Registers.AL = Ans8; - SetZN8 (Registers.AL); + ICPU.Registers.AL = Ans8; + SetZN8 (ICPU.Registers.AL); } else { - int16 Int16 = (short) Registers.AL - (short) Work8 + (short) CheckCarry() - 1; + int16 Int16 = (short) ICPU.Registers.AL - (short) Work8 + (short) CheckCarry() - 1; ICPU._Carry = Int16 >= 0; - if ((Registers.AL ^ Work8) & - (Registers.AL ^ (uint8) Int16) & 0x80) + if ((ICPU.Registers.AL ^ Work8) & + (ICPU.Registers.AL ^ (uint8) Int16) & 0x80) SetOverflow (); else ClearOverflow (); - Registers.AL = (uint8) Int16; - SetZN8 (Registers.AL); + ICPU.Registers.AL = (uint8) Int16; + SetZN8 (ICPU.Registers.AL); } } static void STA16 (long Addr) { - S9xSetWord (Registers.A.W, Addr); + S9xSetWord (ICPU.Registers.A.W, Addr); } static void STA8 (long Addr) { - S9xSetByte (Registers.AL, Addr); + S9xSetByte (ICPU.Registers.AL, Addr); } static void STX16 (long Addr) { - S9xSetWord (Registers.X.W, Addr); + S9xSetWord (ICPU.Registers.X.W, Addr); } static void STX8 (long Addr) { - S9xSetByte (Registers.XL, Addr); + S9xSetByte (ICPU.Registers.XL, Addr); } static void STY16 (long Addr) { - S9xSetWord (Registers.Y.W, Addr); + S9xSetWord (ICPU.Registers.Y.W, Addr); } static void STY8 (long Addr) { - S9xSetByte (Registers.YL, Addr); + S9xSetByte (ICPU.Registers.YL, Addr); } static void STZ16 (long Addr) @@ -847,8 +847,8 @@ static void TSB16 (long Addr) CPU.Cycles += ONE_CYCLE; #endif uint16 Work16 = S9xGetWord (Addr); - ICPU._Zero = (Work16 & Registers.A.W) != 0; - Work16 |= Registers.A.W; + ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; + Work16 |= ICPU.Registers.A.W; //S9xSetWord (Work16, Addr); S9xSetByte (Work16>>8, Addr+1); S9xSetByte (Work16&0xFF, Addr); @@ -860,8 +860,8 @@ static void TSB8 (long Addr) CPU.Cycles += ONE_CYCLE; #endif uint8 Work8 = S9xGetByte (Addr); - ICPU._Zero = Work8 & Registers.AL; - Work8 |= Registers.AL; + ICPU._Zero = Work8 & ICPU.Registers.AL; + Work8 |= ICPU.Registers.AL; S9xSetByte (Work8, Addr); } @@ -871,8 +871,8 @@ static void TRB16 (long Addr) CPU.Cycles += ONE_CYCLE; #endif uint16 Work16 = S9xGetWord (Addr); - ICPU._Zero = (Work16 & Registers.A.W) != 0; - Work16 &= ~Registers.A.W; + ICPU._Zero = (Work16 & ICPU.Registers.A.W) != 0; + Work16 &= ~ICPU.Registers.A.W; //S9xSetWord (Work16, Addr); S9xSetByte (Work16>>8, Addr+1); S9xSetByte (Work16&0xFF, Addr); @@ -884,8 +884,8 @@ static void TRB8 (long Addr) CPU.Cycles += ONE_CYCLE; #endif uint8 Work8 = S9xGetByte (Addr); - ICPU._Zero = Work8 & Registers.AL; - Work8 &= ~Registers.AL; + ICPU._Zero = Work8 & ICPU.Registers.AL; + Work8 &= ~ICPU.Registers.AL; S9xSetByte (Work8, Addr); } #endif -- cgit v1.2.3