Skip to content

Commit

Permalink
TAMi TMAi TRB TSB TST opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jul 2, 2024
1 parent 3b75a81 commit 0173f6b
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
"typeinfo": "cpp",
"optional": "cpp"
}
}
5 changes: 5 additions & 0 deletions src/huc6280.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ class HuC6280
void OPCodes_Store(EightBitRegister* reg, u16 address);
void OPCodes_STZ(u16 address);
void OPCodes_Swap(EightBitRegister* reg1, EightBitRegister* reg2);
void OPCodes_TAM();
void OPCodes_TMA();
void OPCodes_Transfer(EightBitRegister* source, EightBitRegister* dest);
void OPCodes_TRB(u16 address);
void OPCodes_TSB(u16 address);
void OPCodes_TST(u8 value, u16 address);

void InitOPCodeFunctors();

Expand Down
64 changes: 34 additions & 30 deletions src/huc6280_opcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ void HuC6280::OPCode0x03()

void HuC6280::OPCode0x04()
{
// UNOFFICIAL
// NOP $n
UnofficialOPCode();
// OK
// TSB ZZ
OPCodes_TSB(ZeroPageAddressing());
}

void HuC6280::OPCode0x05()
Expand Down Expand Up @@ -110,9 +110,9 @@ void HuC6280::OPCode0x0B()

void HuC6280::OPCode0x0C()
{
// UNOFFICIAL
// NOP $nn
UnofficialOPCode();
// OK
// TSB hhll
OPCodes_TSB(AbsoluteAddressing());
}

void HuC6280::OPCode0x0D()
Expand Down Expand Up @@ -167,9 +167,9 @@ void HuC6280::OPCode0x13()

void HuC6280::OPCode0x14()
{
// UNOFFICIAL
// NOP $n,X
UnofficialOPCode();
// OK
// TRB ZZ
OPCodes_TRB(ZeroPageAddressing());
}

void HuC6280::OPCode0x15()
Expand Down Expand Up @@ -222,9 +222,9 @@ void HuC6280::OPCode0x1B()

void HuC6280::OPCode0x1C()
{
// UNOFFICIAL
// NOP $nn,X
UnofficialOPCode();
// OK
// TRB hhll
OPCodes_TRB(AbsoluteAddressing());
}

void HuC6280::OPCode0x1D()
Expand Down Expand Up @@ -504,9 +504,9 @@ void HuC6280::OPCode0x42()

void HuC6280::OPCode0x43()
{
// UNOFFICIAL
// SRE $(nn,X);
UnofficialOPCode();
// OK
// TMA
OPCodes_TMA();
}

void HuC6280::OPCode0x44()
Expand Down Expand Up @@ -617,9 +617,9 @@ void HuC6280::OPCode0x52()

void HuC6280::OPCode0x53()
{
// UNOFFICIAL
// SRE ($n),Y
UnofficialOPCode();
// OK
// TAM
OPCodes_TAM();
}

void HuC6280::OPCode0x54()
Expand Down Expand Up @@ -967,9 +967,10 @@ void HuC6280::OPCode0x82()

void HuC6280::OPCode0x83()
{
// UNOFFICIAL
// SAX $(nn,X)
UnofficialOPCode();
// OK
// TST #nn,ZZ
u8 nn = Fetch8();
OPCodes_TST(nn, m_memory->Read(ZeroPageAddressing()));
}

void HuC6280::OPCode0x84()
Expand Down Expand Up @@ -1080,9 +1081,10 @@ void HuC6280::OPCode0x92()

void HuC6280::OPCode0x93()
{
// UNOFFICIAL
// AHX ($n),Y
UnofficialOPCode();
// OK
// TST #nn,hhll
u8 nn = Fetch8();
OPCodes_TST(nn, m_memory->Read(AbsoluteAddressing()));
}

void HuC6280::OPCode0x94()
Expand Down Expand Up @@ -1192,9 +1194,10 @@ void HuC6280::OPCode0xA2()

void HuC6280::OPCode0xA3()
{
// UNOFFICIAL
// LAX $(nn,X)
UnofficialOPCode();
// OK
// TST #nn,ZZ,X
u8 nn = Fetch8();
OPCodes_TST(nn, m_memory->Read(ZeroPageAddressing(&m_X)));
}

void HuC6280::OPCode0xA4()
Expand Down Expand Up @@ -1304,9 +1307,10 @@ void HuC6280::OPCode0xB2()

void HuC6280::OPCode0xB3()
{
// UNOFFICIAL
// LAX ($n),Y
UnofficialOPCode();
// OK
// TST #nn,hhll,X
u8 nn = Fetch8();
OPCodes_TST(nn, m_memory->Read(AbsoluteAddressing(&m_X)));
}

void HuC6280::OPCode0xB4()
Expand Down
76 changes: 76 additions & 0 deletions src/huc6280_opcodes_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,48 @@ inline void HuC6280::OPCodes_Swap(EightBitRegister* reg1, EightBitRegister* reg2
reg2->SetValue(temp);
}

inline void HuC6280::OPCodes_TAM()
{
// TODO
ClearFlag(FLAG_MEMORY);
u8 bit = Fetch8();
int index = 0;
if (bit != 0)
{
while ((bit & 1) == 0)
{
bit >>= 1;
index++;
}
m_memory->SetMpr(index, m_A.GetValue());
}
else
{
Debug("Invalid TAM bit: %02X", bit);
}
}

inline void HuC6280::OPCodes_TMA()
{
// TODO
ClearFlag(FLAG_MEMORY);
u8 bit = Fetch8();
int index = 0;
if (bit != 0)
{
while ((bit & 1) == 0)
{
bit >>= 1;
index++;
}
m_A.SetValue(m_memory->GetMpr(index));
}
else
{
Debug("Invalid TMA bit: %02X", bit);
}
}

inline void HuC6280::OPCodes_Transfer(EightBitRegister* source, EightBitRegister* dest)
{
ClearFlag(FLAG_MEMORY);
Expand All @@ -478,4 +520,38 @@ inline void HuC6280::OPCodes_Transfer(EightBitRegister* source, EightBitRegister
SetNegativeFlagFromResult(value);
}

inline void HuC6280::OPCodes_TRB(u16 address)
{
// TODO
ClearFlag(FLAG_MEMORY);
u8 value = m_memory->Read(address);
u8 result = ~m_A.GetValue() & value;
SetZeroFlagFromResult(result);
SetNegativeFlagFromResult(result);
SetOverflowFlagFromResult(result);
m_memory->Write(address, result);
}

inline void HuC6280::OPCodes_TSB(u16 address)
{
// TODO
ClearFlag(FLAG_MEMORY);
u8 value = m_memory->Read(address);
u8 result = m_A.GetValue() | value;
SetZeroFlagFromResult(result);
SetNegativeFlagFromResult(result);
SetOverflowFlagFromResult(result);
m_memory->Write(address, result);
}

inline void HuC6280::OPCodes_TST(u8 value, u16 address)
{
ClearFlag(FLAG_MEMORY);
u8 mem = m_memory->Read(address);
u8 result = value & mem;
SetZeroFlagFromResult(result);
SetNegativeFlagFromResult(result);
SetOverflowFlagFromResult(result);
}

#endif /* HUC6280_OPCODES_INLINE_H */
28 changes: 14 additions & 14 deletions src/huc6280_timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
const u8 k_opcode_tstates[256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
/* 0x00 */ 8, 7, 3, 8, 3, 4, 6, 7, 3, 2, 2, 2, 4, 5, 7, 6,
/* 0x10 */ 2, 7, 7, 8, 4, 4, 6, 7, 2, 5, 2, 7, 4, 5, 7, 6,
/* 0x00 */ 8, 7, 3, 8, 6, 4, 6, 7, 3, 2, 2, 2, 7, 5, 7, 6,
/* 0x10 */ 2, 7, 7, 8, 6, 4, 6, 7, 2, 5, 2, 7, 7, 5, 7, 6,
/* 0x20 */ 7, 7, 3, 8, 4, 4, 6, 7, 4, 2, 2, 2, 5, 5, 7, 6,
/* 0x30 */ 2, 7, 7, 8, 4, 4, 6, 7, 2, 5, 2, 7, 5, 5, 7, 6,
/* 0x40 */ 7, 7, 3, 8, 8, 4, 6, 7, 3, 2, 2, 2, 4, 5, 7, 6,
/* 0x50 */ 2, 7, 7, 8, 4, 4, 6, 7, 2, 5, 3, 7, 4, 5, 7, 6,
/* 0x40 */ 7, 7, 3, 4, 8, 4, 6, 7, 3, 2, 2, 2, 4, 5, 7, 6,
/* 0x50 */ 2, 7, 7, 5, 4, 4, 6, 7, 2, 5, 3, 7, 4, 5, 7, 6,
/* 0x60 */ 7, 7, 2, 8, 4, 4, 6, 7, 4, 2, 2, 2, 7, 5, 7, 6,
/* 0x70 */ 2, 7, 7, 8, 4, 4, 6, 7, 2, 5, 4, 7, 7, 5, 7, 6,
/* 0x80 */ 2, 7, 2, 6, 4, 4, 4, 7, 2, 2, 2, 2, 5, 5, 5, 6,
/* 0x90 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/* 0x60 */ 1, 2, 1, 0, 2, 2, 2, 2, 1, 2, 1, 0, 3, 3, 3, 3,
/* 0x70 */ 2, 2, 2, 0, 2, 2, 2, 2, 1, 3, 1, 0, 3, 3, 3, 3,
/* 0x80 */ 2, 2, 1, 0, 2, 2, 2, 2, 1, 2, 1, 0, 3, 3, 3, 3,
/* 0x90 */ 2, 2, 2, 0, 2, 2, 2, 2, 1, 3, 1, 0, 3, 3, 3, 3,
/* 0xA0 */ 2, 2, 2, 0, 2, 2, 2, 2, 1, 2, 1, 0, 3, 3, 3, 3,
/* 0xB0 */ 2, 2, 2, 0, 2, 2, 2, 2, 1, 3, 1, 0, 3, 3, 3, 3,
/* 0x80 */ 2, 2, 1, 3, 2, 2, 2, 2, 1, 2, 1, 0, 3, 3, 3, 3,
/* 0x90 */ 2, 2, 2, 4, 2, 2, 2, 2, 1, 3, 1, 0, 3, 3, 3, 3,
/* 0xA0 */ 2, 2, 2, 3, 2, 2, 2, 2, 1, 2, 1, 0, 3, 3, 3, 3,
/* 0xB0 */ 2, 2, 2, 4, 2, 2, 2, 2, 1, 3, 1, 0, 3, 3, 3, 3,
/* 0xC0 */ 2, 2, 1, 0, 2, 2, 2, 2, 1, 2, 1, 0, 3, 3, 3, 3,
/* 0xD0 */ 2, 2, 2, 0, 2, 2, 2, 2, 1, 3, 1, 0, 3, 3, 3, 3,
/* 0xE0 */ 2, 2, 0, 0, 2, 2, 2, 2, 1, 2, 1, 0, 3, 3, 3, 3,
Expand Down
4 changes: 2 additions & 2 deletions src/memory_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ inline void Memory::Write(u16 address, u8 value)

inline void Memory::SetMpr(u8 index, u8 value)
{
m_mpr[index] = value;
m_mpr[index & 0x07] = value;
}

inline u8 Memory::GetMpr(u8 index)
{
return m_mpr[index];
return m_mpr[index & 0x07];
}

inline u32 Memory::GetPhysicalAddress(u16 address)
Expand Down

0 comments on commit 0173f6b

Please sign in to comment.