Solving mistakes about the m flag

This commit is contained in:
Anonymus Raccoon
2020-02-28 00:37:17 +01:00
parent 4394c7625e
commit 6c3c832539
11 changed files with 84 additions and 50 deletions
+60 -32
View File
@@ -51,9 +51,10 @@ namespace ComSquare::Debugger
this->_isStepping = false;
this->_isPaused = true;
}
this->_ui.logger->append(CPUDebug::_getInstructionString(opcode).c_str());
this->_ui.logger->append((CPUDebug::_getInstructionString(this->_registers.pac - 1) + " - " + Utility::to_hex(opcode)).c_str());
unsigned ret = CPU::_executeInstruction(opcode);
this->_updateRegistersPanel();
return CPU::_executeInstruction(opcode);
return ret;
}
void CPUDebug::pause()
@@ -110,8 +111,35 @@ namespace ComSquare::Debugger
return str;
}
std::string CPUDebug::_getInstructionString(uint8_t opcode)
std::string CPUDebug::_getImmediateValue(uint24_t pc)
{
unsigned value = this->_bus->read(pc);
if (!this->_registers.p.m)
value += this->_bus->read(pc + 1) << 8u;
std::stringstream ss;
ss << "#$" << std::hex << value;
return ss.str();
}
std::string CPUDebug::_getDirectValue(uint24_t pc)
{
std::stringstream ss;
ss << "$" << std::hex << static_cast<int>(this->_bus->read(pc));
return ss.str();
}
std::string CPUDebug::_getAbsoluteValue(uint24_t pc)
{
std::stringstream ss;
ss << "$" << std::hex << (this->_bus->read(pc) + (this->_bus->read(pc + 1) << 8u));
return ss.str();
}
std::string CPUDebug::_getInstructionString(uint24_t pc)
{
uint8_t opcode = this->_bus->read(pc++);
switch (opcode) {
case Instructions::BRK: return "BRK";
@@ -119,10 +147,10 @@ namespace ComSquare::Debugger
case Instructions::RTI: return "RTI";
case Instructions::ADC_IM: return "ADC";
case Instructions::ADC_ABS: return "ADC";
case Instructions::ADC_IM: return "ADC " + this->_getImmediateValue(pc);
case Instructions::ADC_ABS: return "ADC " + this->_getAbsoluteValue(pc);
case Instructions::ADC_ABSl: return "ADC";
case Instructions::ADC_DP: return "ADC";
case Instructions::ADC_DP: return "ADC " + this->_getDirectValue(pc);
case Instructions::ADC_DPi: return "ADC";
case Instructions::ADC_DPil: return "ADC";
case Instructions::ADC_ABSX: return "ADC";
@@ -135,9 +163,9 @@ namespace ComSquare::Debugger
case Instructions::ADC_SR: return "ADC";
case Instructions::ADC_SRYi: return "ADC";
case Instructions::STA_ABS: return "STA";
case Instructions::STA_ABS: return "STA " + this->_getAbsoluteValue(pc);
case Instructions::STA_ABSl: return "STA";
case Instructions::STA_DP: return "STA";
case Instructions::STA_DP: return "STA " + this->_getDirectValue(pc);
case Instructions::STA_DPi: return "STA";
case Instructions::STA_DPil: return "STA";
case Instructions::STA_ABSX: return "STA";
@@ -150,23 +178,23 @@ namespace ComSquare::Debugger
case Instructions::STA_SR: return "STA";
case Instructions::STA_SRYi: return "STA";
case Instructions::STX_ABS: return "STX";
case Instructions::STX_DP: return "STX";
case Instructions::STX_ABS: return "STX " + this->_getAbsoluteValue(pc);
case Instructions::STX_DP: return "STX " + this->_getDirectValue(pc);
case Instructions::STX_DPY: return "STX";
case Instructions::STY_ABS: return "STX";
case Instructions::STY_DP: 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::STZ_ABS: return "STX";
case Instructions::STZ_DP: return "STX";
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::LDA_IM: return "LDA";
case Instructions::LDA_ABS: return "LDA";
case Instructions::LDA_IM: return "LDA " + this->_getImmediateValue(pc);
case Instructions::LDA_ABS: return "LDA " + this->_getAbsoluteValue(pc);
case Instructions::LDA_ABSl: return "LDA";
case Instructions::LDA_DP: return "LDA";
case Instructions::LDA_DP: return "LDA " + this->_getDirectValue(pc);
case Instructions::LDA_DPi: return "LDA";
case Instructions::LDA_DPil: return "LDA";
case Instructions::LDA_ABSX: return "LDA";
@@ -179,21 +207,21 @@ namespace ComSquare::Debugger
case Instructions::LDA_SR: return "LDA";
case Instructions::LDA_SRYi: return "LDA";
case Instructions::LDX_IM: return "LDX";
case Instructions::LDX_ABS: return "LDX";
case Instructions::LDX_DP: return "LDX";
case Instructions::LDX_IM: return "LDX " + this->_getImmediateValue(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";
case Instructions::LDY_ABS: return "LDY";
case Instructions::LDY_DP: return "LDY";
case Instructions::LDY_IM: return "LDY " + this->_getImmediateValue(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";
case Instructions::SEP: return "SEP " + this->_getImmediateValue(pc);
case Instructions::REP: return "REP";
case Instructions::REP: return "REP " + this->_getImmediateValue(pc);
case Instructions::PHA: return "PHA";
case Instructions::PHB: return "PHB";
@@ -210,7 +238,7 @@ namespace ComSquare::Debugger
case Instructions::PLX: return "PLX";
case Instructions::PLY: return "PLY";
case Instructions::JSR_ABS: return "JSR";
case Instructions::JSR_ABS: return "JSR " + this->_getAbsoluteValue(pc);
case Instructions::JSR_ABSXi: return "JSR";
case Instructions::JSL: return "JSR";
@@ -224,10 +252,10 @@ namespace ComSquare::Debugger
case Instructions::SED: return "SED";
case Instructions::SEI: return "SEI";
case Instructions::AND_IM: return "AND";
case Instructions::AND_ABS: return "AND";
case Instructions::AND_IM: return "AND " + this->_getImmediateValue(pc);
case Instructions::AND_ABS: return "AND " + this->_getAbsoluteValue(pc);
case Instructions::AND_ABSl: return "AND";
case Instructions::AND_DP: return "AND";
case Instructions::AND_DP: return "AND " + this->_getDirectValue(pc);
case Instructions::AND_DPi: return "AND";
case Instructions::AND_DPil: return "AND";
case Instructions::AND_ABSX: return "AND";
@@ -242,10 +270,10 @@ namespace ComSquare::Debugger
case Instructions::XCE: return "XCE";
case Instructions::SBC_IM: return "SBC";
case Instructions::SBC_ABS: return "SBC";
case Instructions::SBC_IM: return "SBC " + this->_getImmediateValue(pc);
case Instructions::SBC_ABS: return "SBC " + this->_getAbsoluteValue(pc);
case Instructions::SBC_ABSl: return "SBC";
case Instructions::SBC_DP: return "SBC";
case Instructions::SBC_DP: return "SBC " + this->_getDirectValue(pc);
case Instructions::SBC_DPi: return "SBC";
case Instructions::SBC_DPil: return "SBC";
case Instructions::SBC_ABSX: return "SBC";
+10 -2
View File
@@ -25,12 +25,20 @@ namespace ComSquare::Debugger
SNES &_snes;
//! @brief Reimplement the basic instruction execution method to log instructions inside the logger view.
unsigned _executeInstruction(uint8_t opcode) override;
//! @brief Get a printable string representing an instruction.
static std::string _getInstructionString(uint8_t opcode);
//! @brief Get a printable string representing an instruction at the program counter given as parameter.
std::string _getInstructionString(uint24_t pc);
//! @brief Get a printable string representing the flags.
std::string _getFlagsString();
//! @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 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);
public slots:
//! @brief Pause/Resume the CPU.
void pause();