mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-02 02:05:26 +00:00
Solving bugs with the immediate addressing mode
This commit is contained in:
+18
-10
@@ -205,7 +205,7 @@ namespace ComSquare::CPU
|
||||
|
||||
case Instructions::RTI: this->RTI(); return 6 + !this->_isEmulationMode;
|
||||
|
||||
case Instructions::ADC_IM: this->ADC(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::ADC_IM: this->ADC(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::ADC_ABS: this->ADC(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::ADC_ABSl: this->ADC(this->_getAbsoluteLongAddr()); return 5 + !this->_registers.p.m;
|
||||
case Instructions::ADC_DP: this->ADC(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
@@ -249,7 +249,7 @@ namespace ComSquare::CPU
|
||||
case Instructions::STZ_ABSX: this->STX(this->_getAbsoluteIndexedByXAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::STZ_DPX: this->STX(this->_getDirectIndexedByXAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
|
||||
case Instructions::LDA_IM: this->LDA(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::LDA_IM: this->LDA(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::LDA_ABS: this->LDA(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::LDA_ABSl: this->LDA(this->_getAbsoluteLongAddr()); return 5 + !this->_registers.p.m;
|
||||
case Instructions::LDA_DP: this->LDA(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
@@ -265,21 +265,21 @@ namespace ComSquare::CPU
|
||||
case Instructions::LDA_SR: this->LDA(this->_getStackRelativeAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::LDA_SRYi: this->LDA(this->_getStackRelativeIndirectIndexedYAddr()); return 7 + !this->_registers.p.m;
|
||||
|
||||
case Instructions::LDX_IM: this->LDX(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::LDX_IM: this->LDX(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::LDX_ABS: this->LDX(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::LDX_DP: this->LDX(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDX_ABSY: this->LDX(this->_getAbsoluteIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_hasIndexCrossedPageBoundary;
|
||||
case Instructions::LDX_DPY: this->LDX(this->_getDirectIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
|
||||
case Instructions::LDY_IM: this->LDY(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::LDY_IM: this->LDY(this->_getImmediateAddrForX()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::LDY_ABS: this->LDY(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::LDY_DP: this->LDY(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDY_ABSY: this->LDY(this->_getAbsoluteIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_hasIndexCrossedPageBoundary;
|
||||
case Instructions::LDY_DPY: this->LDY(this->_getDirectIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
|
||||
case Instructions::SEP: this->SEP(this->_getImmediateAddr()); return 3;
|
||||
case Instructions::SEP: this->SEP(this->_bus->read(this->_registers.pc++)); return 3;
|
||||
|
||||
case Instructions::REP: this->REP(this->_getImmediateAddr()); return 3;
|
||||
case Instructions::REP: this->REP(this->_bus->read(this->_registers.pc++)); return 3;
|
||||
|
||||
case Instructions::PHA: this->PHA(); return 3 + !this->_registers.p.m;
|
||||
case Instructions::PHB: this->PHB(); return 3;
|
||||
@@ -299,7 +299,7 @@ namespace ComSquare::CPU
|
||||
case Instructions::JSR_ABS: this->JSR(this->_getAbsoluteAddr()); return 6;
|
||||
case Instructions::JSR_ABSXi: this->JSR(this->_getAbsoluteIndirectIndexedByXAddr()); return 8;
|
||||
|
||||
case Instructions::JSL: this->JSR(this->_getAbsoluteLongAddr()); return 8;
|
||||
case Instructions::JSL: this->JSL(this->_getAbsoluteLongAddr()); return 8;
|
||||
|
||||
case Instructions::CLC: this->CLC(); return 2;
|
||||
case Instructions::CLI: this->CLI(); return 2;
|
||||
@@ -310,7 +310,7 @@ namespace ComSquare::CPU
|
||||
case Instructions::SED: this->SED(); return 2;
|
||||
case Instructions::SEI: this->SEI(); return 2;
|
||||
|
||||
case Instructions::AND_IM: this->AND(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::AND_IM: this->AND(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::AND_ABS: this->AND(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::AND_ABSl: this->AND(this->_getAbsoluteLongAddr()); return 5 + !this->_registers.p.m;
|
||||
case Instructions::AND_DP: this->AND(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
@@ -328,7 +328,7 @@ namespace ComSquare::CPU
|
||||
|
||||
case Instructions::XCE: this->XCE(); return 2;
|
||||
|
||||
case Instructions::SBC_IM: this->SBC(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::SBC_IM: this->SBC(this->_getImmediateAddrForA()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::SBC_ABS: this->SBC(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::SBC_ABSl: this->SBC(this->_getAbsoluteLongAddr()); return 5 + !this->_registers.p.m;
|
||||
case Instructions::SBC_DP: this->SBC(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
@@ -378,7 +378,7 @@ namespace ComSquare::CPU
|
||||
/// Addressing modes
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint24_t CPU::_getImmediateAddr()
|
||||
uint24_t CPU::_getImmediateAddrForA()
|
||||
{
|
||||
uint24_t effective = this->_registers.pac++;
|
||||
if (!this->_registers.p.m)
|
||||
@@ -386,6 +386,14 @@ namespace ComSquare::CPU
|
||||
return effective;
|
||||
}
|
||||
|
||||
uint24_t CPU::_getImmediateAddrForX()
|
||||
{
|
||||
uint24_t effective = this->_registers.pac++;
|
||||
if (!this->_registers.p.x_b)
|
||||
this->_registers.pac++;
|
||||
return effective;
|
||||
}
|
||||
|
||||
uint24_t CPU::_getDirectAddr()
|
||||
{
|
||||
uint8_t addr = this->_bus->read(this->_registers.pac++);
|
||||
|
||||
+4
-2
@@ -350,8 +350,10 @@ namespace ComSquare::CPU
|
||||
//! @brief True if an addressing mode with an iterator (x, y) has crossed the page. (Used because crossing the page boundary take one more cycle to run certain instructions).
|
||||
bool _hasIndexCrossedPageBoundary = false;
|
||||
|
||||
//! @brief Immediate address mode is specified with a value. (This functions returns the 24bit space address of the value).
|
||||
uint24_t _getImmediateAddr();
|
||||
//! @brief Immediate address mode is specified with a value in 8 or 16 bits. The value is 16 bits if the m flag is unset. (This functions returns the 24bit space address of the value).
|
||||
uint24_t _getImmediateAddrForA();
|
||||
//! @brief Immediate address mode is specified with a value in 8 or 16 bits. The value is 16 bits if the x flag is unset. (This functions returns the 24bit space address of the value).
|
||||
uint24_t _getImmediateAddrForX();
|
||||
//! @brief The destination is formed by adding the direct page register with the 8-bit address to form an effective address. (This functions returns the 24bit space address of the value).
|
||||
uint24_t _getDirectAddr();
|
||||
//! @brief The effective address is formed by DBR:<16-bit exp>. (This functions returns the 24bit space address of the value).
|
||||
|
||||
@@ -41,32 +41,32 @@ namespace ComSquare::CPU
|
||||
this->_registers.p.v = false;
|
||||
}
|
||||
|
||||
void CPU::SEP(uint24_t valueAddr)
|
||||
void CPU::SEP(uint24_t value)
|
||||
{
|
||||
this->_registers.p.flags |= this->_bus->read(valueAddr);
|
||||
this->_registers.p.flags |= value;
|
||||
}
|
||||
|
||||
void CPU::REP(uint24_t valueAddr)
|
||||
void CPU::REP(uint24_t value)
|
||||
{
|
||||
this->_registers.p.flags &= ~this->_bus->read(valueAddr);
|
||||
this->_registers.p.flags &= ~value;
|
||||
if (this->_isEmulationMode) {
|
||||
this->_registers.p.x_b = true;
|
||||
this->_registers.p.m = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CPU::JSR(uint24_t valueAddr)
|
||||
void CPU::JSR(uint24_t value)
|
||||
{
|
||||
this->_push(--this->_registers.pc);
|
||||
this->_registers.pc = this->_bus->read(valueAddr) + (this->_bus->read(valueAddr + 1) << 8u);
|
||||
this->_registers.pc = value;
|
||||
}
|
||||
|
||||
void CPU::JSL(uint24_t valueAddr)
|
||||
void CPU::JSL(uint24_t value)
|
||||
{
|
||||
this->_registers.pac--;
|
||||
this->_push(this->_registers.pbr);
|
||||
this->_push(this->_registers.pc);
|
||||
this->_registers.pc = this->_bus->read(valueAddr) + (this->_bus->read(valueAddr + 1) << 8u);
|
||||
this->_registers.pac = value;
|
||||
}
|
||||
|
||||
void CPU::PHA()
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace ComSquare::Debugger
|
||||
this->_ui.directBankLineEdit->setText(Utility::to_hex(this->_registers.dbr).c_str());
|
||||
this->_ui.directPageLineEdit->setText(Utility::to_hex(this->_registers.d).c_str());
|
||||
this->_ui.stackPointerLineEdit->setText(Utility::to_hex(this->_registers.s).c_str());
|
||||
if (this->_registers.p.x_b) {
|
||||
if (!this->_registers.p.x_b) {
|
||||
this->_ui.xIndexLineEdit->setText(Utility::to_hex(this->_registers.x).c_str());
|
||||
this->_ui.yIndexLineEdit->setText(Utility::to_hex(this->_registers.y).c_str());
|
||||
} else {
|
||||
@@ -117,7 +117,7 @@ namespace ComSquare::Debugger
|
||||
this->_ui.logger->clear();
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getImmediateValue(uint24_t pc)
|
||||
std::string CPUDebug::_getImmediateValueForA(uint24_t pc)
|
||||
{
|
||||
unsigned value = this->_bus->read(pc);
|
||||
|
||||
@@ -128,6 +128,24 @@ namespace ComSquare::Debugger
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getImmediateValueForX(uint24_t pc)
|
||||
{
|
||||
unsigned value = this->_bus->read(pc);
|
||||
|
||||
if (!this->_registers.p.x_b)
|
||||
value += this->_bus->read(pc + 1) << 8u;
|
||||
std::stringstream ss;
|
||||
ss << "#$" << std::hex << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getImmediateValue8Bits(uint24_t pc)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "#$" << std::hex << static_cast<int>(this->_bus->read(pc));
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getDirectValue(uint24_t pc)
|
||||
{
|
||||
std::stringstream ss;
|
||||
@@ -142,6 +160,17 @@ namespace ComSquare::Debugger
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getAbsoluteLongValue(uint24_t pc)
|
||||
{
|
||||
unsigned value = this->_bus->read(pc++);
|
||||
value += this->_bus->read(pc++) << 8u;
|
||||
value += this->_bus->read(pc) << 16u;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "$" << std::hex << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getInstructionString(uint24_t pc)
|
||||
{
|
||||
uint8_t opcode = this->_bus->read(pc++);
|
||||
@@ -153,9 +182,9 @@ namespace ComSquare::Debugger
|
||||
|
||||
case Instructions::RTI: return "RTI";
|
||||
|
||||
case Instructions::ADC_IM: return "ADC " + this->_getImmediateValue(pc);
|
||||
case Instructions::ADC_IM: return "ADC " + this->_getImmediateValueForA(pc);
|
||||
case Instructions::ADC_ABS: return "ADC " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::ADC_ABSl: return "ADC";
|
||||
case Instructions::ADC_ABSl: return "ADC " + this->_getAbsoluteLongValue(pc);
|
||||
case Instructions::ADC_DP: return "ADC " + this->_getDirectValue(pc);
|
||||
case Instructions::ADC_DPi: return "ADC";
|
||||
case Instructions::ADC_DPil: return "ADC";
|
||||
@@ -170,7 +199,7 @@ namespace ComSquare::Debugger
|
||||
case Instructions::ADC_SRYi: return "ADC";
|
||||
|
||||
case Instructions::STA_ABS: return "STA " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::STA_ABSl: return "STA";
|
||||
case Instructions::STA_ABSl: return "STA " + this->_getAbsoluteLongValue(pc);
|
||||
case Instructions::STA_DP: return "STA " + this->_getDirectValue(pc);
|
||||
case Instructions::STA_DPi: return "STA";
|
||||
case Instructions::STA_DPil: return "STA";
|
||||
@@ -188,18 +217,18 @@ namespace ComSquare::Debugger
|
||||
case Instructions::STX_DP: return "STX " + this->_getDirectValue(pc);
|
||||
case Instructions::STX_DPY: return "STX";
|
||||
|
||||
case Instructions::STY_ABS: return "STX " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::STY_DP: return "STX " + this->_getDirectValue(pc);
|
||||
case Instructions::STY_DPX: return "STX";
|
||||
case Instructions::STY_ABS: return "STY " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::STY_DP: return "STY " + this->_getDirectValue(pc);
|
||||
case Instructions::STY_DPX: return "STY";
|
||||
|
||||
case Instructions::STZ_ABS: return "STX " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::STZ_DP: return "STX " + this->_getDirectValue(pc);
|
||||
case Instructions::STZ_ABSX: return "STX";
|
||||
case Instructions::STZ_DPX: return "STX";
|
||||
case Instructions::STZ_ABS: return "STZ " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::STZ_DP: return "STZ " + this->_getDirectValue(pc);
|
||||
case Instructions::STZ_ABSX: return "STZ";
|
||||
case Instructions::STZ_DPX: return "STZ";
|
||||
|
||||
case Instructions::LDA_IM: return "LDA " + this->_getImmediateValue(pc);
|
||||
case Instructions::LDA_IM: return "LDA " + this->_getImmediateValueForA(pc);
|
||||
case Instructions::LDA_ABS: return "LDA " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::LDA_ABSl: return "LDA";
|
||||
case Instructions::LDA_ABSl: return "LDA " + this->_getAbsoluteLongValue(pc);
|
||||
case Instructions::LDA_DP: return "LDA " + this->_getDirectValue(pc);
|
||||
case Instructions::LDA_DPi: return "LDA";
|
||||
case Instructions::LDA_DPil: return "LDA";
|
||||
@@ -213,21 +242,21 @@ namespace ComSquare::Debugger
|
||||
case Instructions::LDA_SR: return "LDA";
|
||||
case Instructions::LDA_SRYi: return "LDA";
|
||||
|
||||
case Instructions::LDX_IM: return "LDX " + this->_getImmediateValue(pc);
|
||||
case Instructions::LDX_IM: return "LDX " + this->_getImmediateValueForX(pc);
|
||||
case Instructions::LDX_ABS: return "LDX " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::LDX_DP: return "LDX " + this->_getDirectValue(pc);
|
||||
case Instructions::LDX_ABSY: return "LDX";
|
||||
case Instructions::LDX_DPY: return "LDX";
|
||||
|
||||
case Instructions::LDY_IM: return "LDY " + this->_getImmediateValue(pc);
|
||||
case Instructions::LDY_IM: return "LDY " + this->_getImmediateValueForX(pc);
|
||||
case Instructions::LDY_ABS: return "LDY " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::LDY_DP: return "LDY " + this->_getDirectValue(pc);
|
||||
case Instructions::LDY_ABSY: return "LDY";
|
||||
case Instructions::LDY_DPY: return "LDY";
|
||||
|
||||
case Instructions::SEP: return "SEP " + this->_getImmediateValue(pc);
|
||||
case Instructions::SEP: return "SEP " + this->_getImmediateValue8Bits(pc);
|
||||
|
||||
case Instructions::REP: return "REP " + this->_getImmediateValue(pc);
|
||||
case Instructions::REP: return "REP " + this->_getImmediateValue8Bits(pc);
|
||||
|
||||
case Instructions::PHA: return "PHA";
|
||||
case Instructions::PHB: return "PHB";
|
||||
@@ -247,7 +276,7 @@ namespace ComSquare::Debugger
|
||||
case Instructions::JSR_ABS: return "JSR " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::JSR_ABSXi: return "JSR";
|
||||
|
||||
case Instructions::JSL: return "JSR";
|
||||
case Instructions::JSL: return "JSL " + this->_getAbsoluteLongValue(pc);
|
||||
|
||||
case Instructions::CLC: return "CLC";
|
||||
case Instructions::CLI: return "CLI";
|
||||
@@ -258,9 +287,9 @@ namespace ComSquare::Debugger
|
||||
case Instructions::SED: return "SED";
|
||||
case Instructions::SEI: return "SEI";
|
||||
|
||||
case Instructions::AND_IM: return "AND " + this->_getImmediateValue(pc);
|
||||
case Instructions::AND_IM: return "AND " + this->_getImmediateValueForA(pc);
|
||||
case Instructions::AND_ABS: return "AND " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::AND_ABSl: return "AND";
|
||||
case Instructions::AND_ABSl: return "AND " + this->_getAbsoluteLongValue(pc);
|
||||
case Instructions::AND_DP: return "AND " + this->_getDirectValue(pc);
|
||||
case Instructions::AND_DPi: return "AND";
|
||||
case Instructions::AND_DPil: return "AND";
|
||||
@@ -276,9 +305,9 @@ namespace ComSquare::Debugger
|
||||
|
||||
case Instructions::XCE: return "XCE";
|
||||
|
||||
case Instructions::SBC_IM: return "SBC " + this->_getImmediateValue(pc);
|
||||
case Instructions::SBC_IM: return "SBC " + this->_getImmediateValueForA(pc);
|
||||
case Instructions::SBC_ABS: return "SBC " + this->_getAbsoluteValue(pc);
|
||||
case Instructions::SBC_ABSl: return "SBC";
|
||||
case Instructions::SBC_ABSl: return "SBC " + this->_getAbsoluteLongValue(pc);
|
||||
case Instructions::SBC_DP: return "SBC " + this->_getDirectValue(pc);
|
||||
case Instructions::SBC_DPi: return "SBC";
|
||||
case Instructions::SBC_DPil: return "SBC";
|
||||
|
||||
@@ -32,12 +32,18 @@ namespace ComSquare::Debugger
|
||||
//! @brief Update the register's panel (accumulator, stack pointer...)
|
||||
void _updateRegistersPanel();
|
||||
|
||||
//! @brief Return a printable string corresponding to the value of an immediate addressing mode.
|
||||
std::string _getImmediateValue(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of an immediate addressing mode for a.
|
||||
std::string _getImmediateValueForA(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of an immediate addressing mode for x.
|
||||
std::string _getImmediateValueForX(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of a 8bits immediate addressing mode (used only with SEP and REP).
|
||||
std::string _getImmediateValue8Bits(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of a direct addressing mode.
|
||||
std::string _getDirectValue(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of an absolute addressing mode.
|
||||
std::string _getAbsoluteValue(uint24_t pc);
|
||||
//! @brief Return a printable string corresponding to the value of an absolute long addressing mode.
|
||||
std::string _getAbsoluteLongValue(uint24_t pc);
|
||||
|
||||
public slots:
|
||||
//! @brief Pause/Resume the CPU.
|
||||
|
||||
@@ -22,7 +22,7 @@ Test(AddrMode, Immediate)
|
||||
pair.second.cpu->_registers.pac = 0x000015;
|
||||
pair.second.cpu->_isEmulationMode = true;
|
||||
pair.second.cpu->_registers.p.m = false;
|
||||
cr_assert_eq(pair.second.cpu->_getImmediateAddr(), 0x000015, "Got %x, Expected 0x000015");
|
||||
cr_assert_eq(pair.second.cpu->_getImmediateAddrForA(), 0x000015, "Got %x, Expected 0x000015");
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x000017);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ Test(AddrMode, ImmediateMemoryFlag)
|
||||
pair.second.cpu->_isEmulationMode = true;
|
||||
pair.second.cpu->_registers.pac = 0x000015;
|
||||
pair.second.cpu->_registers.p.m = false;
|
||||
cr_assert_eq(pair.second.cpu->_getImmediateAddr(), 0x000015, "Got %x, Expected 0x000015");
|
||||
cr_assert_eq(pair.second.cpu->_getImmediateAddrForA(), 0x000015, "Got %x, Expected 0x000015");
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x000017);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ Test(AddrMode, ImmediateBankChange)
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.pac = 0x00FFFF;
|
||||
pair.second.cpu->_registers.p.m = true;
|
||||
cr_assert_eq(pair.second.cpu->_getImmediateAddr(), 0x00FFFF);
|
||||
cr_assert_eq(pair.second.cpu->_getImmediateAddrForA(), 0x00FFFF);
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x010000);
|
||||
}
|
||||
|
||||
|
||||
+10
-20
@@ -13,8 +13,7 @@ using namespace ComSquare;
|
||||
Test(SEP, setall)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.wram->_data[0] = 0xFF;
|
||||
pair.second.cpu->SEP(0x0);
|
||||
pair.second.cpu->SEP(0xFF);
|
||||
auto data = pair.second.cpu->_registers.p.flags;
|
||||
cr_assert_eq(data, 0xFF, "The flag should be 0xFF but it was %x", data);
|
||||
}
|
||||
@@ -22,9 +21,8 @@ Test(SEP, setall)
|
||||
Test(SEP, setsome)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.wram->_data[0] = 0b10110101;
|
||||
pair.second.cpu->_registers.p.flags = 0b01000000;
|
||||
pair.second.cpu->SEP(0x0);
|
||||
pair.second.cpu->SEP(0b10110101);
|
||||
auto data = pair.second.cpu->_registers.p.flags;
|
||||
cr_assert_eq(data, 0b11110101, "The flag should be 245 but it was %i", data);
|
||||
}
|
||||
@@ -33,8 +31,7 @@ Test(REP, resetall)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_isEmulationMode = false;
|
||||
pair.second.wram->_data[0] = 0xFF;
|
||||
pair.second.cpu->REP(0x0);
|
||||
pair.second.cpu->REP(0xFF);
|
||||
auto data = pair.second.cpu->_registers.p.flags;
|
||||
cr_assert_eq(data, 0x00, "The flag should be 0x00 but it was %x", data);
|
||||
}
|
||||
@@ -43,9 +40,8 @@ Test(REP, resetsome)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_isEmulationMode = false;
|
||||
pair.second.wram->_data[0] = 0b01000000;
|
||||
pair.second.cpu->_registers.p.flags = 0b01000000;
|
||||
pair.second.cpu->REP(0x0);
|
||||
pair.second.cpu->REP(0b01000000);
|
||||
auto data = pair.second.cpu->_registers.p.flags;
|
||||
cr_assert_eq(data, 0x0, "The flag should be 0 but it was %x", data);
|
||||
}
|
||||
@@ -54,8 +50,7 @@ Test(REP, resetallEmulation)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_isEmulationMode = true;
|
||||
pair.second.wram->_data[0] = 0xFF;
|
||||
pair.second.cpu->REP(0x0);
|
||||
pair.second.cpu->REP(0xFF);
|
||||
auto data = pair.second.cpu->_registers.p.flags;
|
||||
cr_assert_eq(data, 0b00110000, "The flag should be 0b00110000 but it was %x", data);
|
||||
}
|
||||
@@ -64,9 +59,8 @@ Test(REP, resetsomeEmulation)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_isEmulationMode = true;
|
||||
pair.second.wram->_data[0] = 0b01000001;
|
||||
pair.second.cpu->_registers.p.flags = 0b01000101;
|
||||
pair.second.cpu->REP(0x0);
|
||||
pair.second.cpu->REP(0b01000001);
|
||||
auto data = pair.second.cpu->_registers.p.flags;
|
||||
cr_assert_eq(data, 0b00110100, "The flag should be 0b00110100 but it was %x", data);
|
||||
}
|
||||
@@ -76,9 +70,7 @@ Test(JSR, jump)
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.pc = 0xABCD;
|
||||
pair.second.cpu->_registers.s = 0x0123;
|
||||
pair.second.wram->_data[0] = 0xFF;
|
||||
pair.second.wram->_data[1] = 0xAB;
|
||||
pair.second.cpu->JSR(0x0);
|
||||
pair.second.cpu->JSR(0xABFF);
|
||||
auto pc = pair.second.cpu->_registers.pc;
|
||||
cr_assert_eq(pc, 0xABFF, "The PC should be 0xABFF but it was %x", pc);
|
||||
cr_assert_eq(pair.second.cpu->_registers.s, 0x0121, "The stack pointer should be 0x0121 but it was %x", pair.second.cpu->_registers.s);
|
||||
@@ -92,11 +84,9 @@ Test(JSL, jump)
|
||||
pair.second.cpu->_registers.pbr = 0xFF;
|
||||
pair.second.cpu->_registers.pc = 0xABCD;
|
||||
pair.second.cpu->_registers.s = 0x0123;
|
||||
pair.second.wram->_data[0] = 0xFF;
|
||||
pair.second.wram->_data[1] = 0xAB;
|
||||
pair.second.cpu->JSL(0x0);
|
||||
auto pc = pair.second.cpu->_registers.pc;
|
||||
cr_assert_eq(pc, 0xABFF, "The PC should be 0xABFF but it was %x", pc);
|
||||
pair.second.cpu->JSL(0xCDABFF);
|
||||
auto pac = pair.second.cpu->_registers.pac;
|
||||
cr_assert_eq(pac, 0xCDABFF, "The PC should be 0xCDABFF but it was %x", pac);
|
||||
cr_assert_eq(pair.second.cpu->_registers.s, 0x0120, "The stack pointer should be 0x0120 but it was %x", pair.second.cpu->_registers.s);
|
||||
auto pushed = pair.second.cpu->_pop16() + (pair.second.cpu->_pop() << 16u);
|
||||
cr_assert_eq(pushed, 0xFFABCC, "The value pushed to the stack should be 0xFFABCD but it was %x", pushed);
|
||||
|
||||
Reference in New Issue
Block a user