APU's start boot is working !

This commit is contained in:
Melefo
2020-04-09 17:29:39 +02:00
parent 63917b3d49
commit 62daa00390
5 changed files with 78 additions and 77 deletions

View File

@@ -192,7 +192,7 @@ namespace ComSquare::APU
case 0x02: case 0x02:
return this->SET1(this->_getDirectAddr(), 0); return this->SET1(this->_getDirectAddr(), 0);
case 0x03: case 0x03:
return this->BBS(this->_getDirectAddr(), 0); return this->BBS(this->_getDirectAddr(), this->_getImmediateData(), 0);
case 0x04: case 0x04:
return this->ORacc(this->_getDirectAddr(), 3); return this->ORacc(this->_getDirectAddr(), 3);
case 0x05: case 0x05:
@@ -218,13 +218,13 @@ namespace ComSquare::APU
case 0x0F: case 0x0F:
return this->BRK(); return this->BRK();
case 0x10: case 0x10:
return this->BPL(); return this->BPL(this->_getImmediateData());
case 0x11: case 0x11:
return this->TCALL(1); return this->TCALL(1);
case 0x12: case 0x12:
return this->CLR1(this->_getDirectAddr(), 0); return this->CLR1(this->_getDirectAddr(), 0);
case 0x13: case 0x13:
return this->BBC(this->_getDirectAddr(), 0); return this->BBC(this->_getDirectAddr(), this->_getImmediateData(), 0);
case 0x14: case 0x14:
return this->ORacc(this->_getDirectAddrByX(), 4); return this->ORacc(this->_getDirectAddrByX(), 4);
case 0x15: case 0x15:
@@ -256,7 +256,7 @@ namespace ComSquare::APU
case 0x22: case 0x22:
return this->SET1(this->_getDirectAddr(), 1); return this->SET1(this->_getDirectAddr(), 1);
case 0x23: case 0x23:
return this->BBS(this->_getDirectAddr(), 1); return this->BBS(this->_getDirectAddr(), this->_getImmediateData(), 1);
case 0x24: case 0x24:
return this->ANDacc(this->_getDirectAddr(), 3); return this->ANDacc(this->_getDirectAddr(), 3);
case 0x25: case 0x25:
@@ -278,17 +278,17 @@ namespace ComSquare::APU
case 0x2D: case 0x2D:
return this->PUSH(this->_internalRegisters.a); return this->PUSH(this->_internalRegisters.a);
case 0x2E: case 0x2E:
return this->CBNE(this->_getImmediateData()); return this->CBNE(this->_getImmediateData(), this->_getImmediateData());
case 0x2F: case 0x2F:
return this->BRA(); return this->BRA(this->_getImmediateData());
case 0x30: case 0x30:
return this->BMI(); return this->BMI(this->_getImmediateData());
case 0x31: case 0x31:
return this->TCALL(3); return this->TCALL(3);
case 0x32: case 0x32:
return this->CLR1(this->_getDirectAddr(), 1); return this->CLR1(this->_getDirectAddr(), 1);
case 0x33: case 0x33:
return this->BBC(this->_getDirectAddr(), 1); return this->BBC(this->_getDirectAddr(), this->_getImmediateData(), 1);
case 0x34: case 0x34:
return this->ANDacc(this->_getDirectAddrByX(), 4); return this->ANDacc(this->_getDirectAddrByX(), 4);
case 0x35: case 0x35:
@@ -320,7 +320,7 @@ namespace ComSquare::APU
case 0x42: case 0x42:
return this->SET1(this->_getDirectAddr(), 2); return this->SET1(this->_getDirectAddr(), 2);
case 0x43: case 0x43:
return this->BBS(this->_getDirectAddr(), 2); return this->BBS(this->_getDirectAddr(), this->_getImmediateData(), 2);
case 0x44: case 0x44:
return this->EORacc(this->_getDirectAddr(), 3); return this->EORacc(this->_getDirectAddr(), 3);
case 0x45: case 0x45:
@@ -346,13 +346,13 @@ namespace ComSquare::APU
case 0x4F: case 0x4F:
return this->PCALL(); return this->PCALL();
case 0x50: case 0x50:
return this->BVC(); return this->BVC(this->_getImmediateData());
case 0x51: case 0x51:
return this->TCALL(5); return this->TCALL(5);
case 0x52: case 0x52:
return this->CLR1(this->_getDirectAddr(), 2); return this->CLR1(this->_getDirectAddr(), 2);
case 0x53: case 0x53:
return this->BBC(this->_getDirectAddr(), 2); return this->BBC(this->_getDirectAddr(), this->_getImmediateData(), 2);
case 0x54: case 0x54:
return this->EORacc(this->_getDirectAddrByX(), 4); return this->EORacc(this->_getDirectAddrByX(), 4);
case 0x55: case 0x55:
@@ -384,7 +384,7 @@ namespace ComSquare::APU
case 0x62: case 0x62:
return this->SET1(this->_getDirectAddr(), 3); return this->SET1(this->_getDirectAddr(), 3);
case 0x63: case 0x63:
return this->BBS(this->_getDirectAddr(), 3); return this->BBS(this->_getDirectAddr(), this->_getImmediateData(), 3);
case 0x64: case 0x64:
return this->CMPreg(this->_internalRegisters.a, this->_getDirectAddr(), 3); return this->CMPreg(this->_internalRegisters.a, this->_getDirectAddr(), 3);
case 0x65: case 0x65:
@@ -406,17 +406,17 @@ namespace ComSquare::APU
case 0x6D: case 0x6D:
return this->PUSH(this->_internalRegisters.y); return this->PUSH(this->_internalRegisters.y);
case 0x6E: case 0x6E:
return this->DBNZ(true); return this->DBNZ(this->_getImmediateData(), true);
case 0x6F: case 0x6F:
return this->RET(); return this->RET();
case 0x70: case 0x70:
return this->BVS(); return this->BVS(this->_getImmediateData());
case 0x71: case 0x71:
return this->TCALL(7); return this->TCALL(7);
case 0x72: case 0x72:
return this->CLR1(this->_getDirectAddr(), 3); return this->CLR1(this->_getDirectAddr(), 3);
case 0x73: case 0x73:
return this->BBC(this->_getDirectAddr(), 3); return this->BBC(this->_getDirectAddr(), this->_getImmediateData(), 3);
case 0x74: case 0x74:
return this->CMPreg(this->_internalRegisters.a, this->_getDirectAddrByX(), 4); return this->CMPreg(this->_internalRegisters.a, this->_getDirectAddrByX(), 4);
case 0x75: case 0x75:
@@ -448,7 +448,7 @@ namespace ComSquare::APU
case 0x82: case 0x82:
return this->SET1(this->_getDirectAddr(), 4); return this->SET1(this->_getDirectAddr(), 4);
case 0x83: case 0x83:
return this->BBS(this->_getDirectAddr(), 4); return this->BBS(this->_getDirectAddr(), this->_getImmediateData(), 4);
case 0x84: case 0x84:
return this->ADCacc(this->_getDirectAddr(), 3); return this->ADCacc(this->_getDirectAddr(), 3);
case 0x85: case 0x85:
@@ -474,13 +474,13 @@ namespace ComSquare::APU
case 0x8F: case 0x8F:
return this->MOV(this->_getImmediateData(), this->_getDirectAddr()); return this->MOV(this->_getImmediateData(), this->_getDirectAddr());
case 0x90: case 0x90:
return this->BCC(); return this->BCC(this->_getImmediateData());
case 0x91: case 0x91:
return this->TCALL(9); return this->TCALL(9);
case 0x92: case 0x92:
return this->CLR1(this->_getDirectAddr(), 4); return this->CLR1(this->_getDirectAddr(), 4);
case 0x93: case 0x93:
return this->BBC(this->_getDirectAddr(), 4); return this->BBC(this->_getDirectAddr(), this->_getImmediateData(), 4);
case 0x94: case 0x94:
return this->ADCacc(this->_getDirectAddrByX(), 4); return this->ADCacc(this->_getDirectAddrByX(), 4);
case 0x95: case 0x95:
@@ -512,7 +512,7 @@ namespace ComSquare::APU
case 0xA2: case 0xA2:
return this->SET1(this->_getDirectAddr(), 5); return this->SET1(this->_getDirectAddr(), 5);
case 0xA3: case 0xA3:
return this->BBS(this->_getDirectAddr(), 5); return this->BBS(this->_getDirectAddr(), this->_getImmediateData(), 5);
case 0xA4: case 0xA4:
return this->SBCacc(this->_getDirectAddr(), 3); return this->SBCacc(this->_getDirectAddr(), 3);
case 0xA5: case 0xA5:
@@ -538,13 +538,13 @@ namespace ComSquare::APU
case 0xAF: case 0xAF:
return this->MOV(this->_internalRegisters.a, this->_getIndexXAddr(), 4, true); return this->MOV(this->_internalRegisters.a, this->_getIndexXAddr(), 4, true);
case 0xB0: case 0xB0:
return this->BCS(); return this->BCS(this->_getImmediateData());
case 0xB1: case 0xB1:
return this->TCALL(11); return this->TCALL(11);
case 0xB2: case 0xB2:
return this->CLR1(this->_getDirectAddr(), 5); return this->CLR1(this->_getDirectAddr(), 5);
case 0xB3: case 0xB3:
return this->BBC(this->_getDirectAddr(), 5); return this->BBC(this->_getDirectAddr(), this->_getImmediateData(), 5);
case 0xB4: case 0xB4:
return this->SBCacc(this->_getDirectAddrByX(), 4); return this->SBCacc(this->_getDirectAddrByX(), 4);
case 0xB5: case 0xB5:
@@ -576,7 +576,7 @@ namespace ComSquare::APU
case 0xC2: case 0xC2:
return this->SET1(this->_getDirectAddr(), 6); return this->SET1(this->_getDirectAddr(), 6);
case 0xC3: case 0xC3:
return this->BBS(this->_getDirectAddr(), 6); return this->BBS(this->_getDirectAddr(), this->_getImmediateData(), 6);
case 0xC4: case 0xC4:
return this->MOV(this->_internalRegisters.a, this->_getDirectAddr(), 4); return this->MOV(this->_internalRegisters.a, this->_getDirectAddr(), 4);
case 0xC5: case 0xC5:
@@ -602,13 +602,13 @@ namespace ComSquare::APU
case 0xCF: case 0xCF:
return this->MUL(); return this->MUL();
case 0xD0: case 0xD0:
return this->BNE(); return this->BNE(this->_getImmediateData());
case 0xD1: case 0xD1:
return this->TCALL(13); return this->TCALL(13);
case 0xD2: case 0xD2:
return this->CLR1(this->_getDirectAddr(), 6); return this->CLR1(this->_getDirectAddr(), 6);
case 0xD3: case 0xD3:
return this->BBC(this->_getDirectAddr(), 6); return this->BBC(this->_getDirectAddr(), this->_getImmediateData(), 6);
case 0xD4: case 0xD4:
return this->MOV(this->_internalRegisters.a, this->_getDirectAddrByX(), 5); return this->MOV(this->_internalRegisters.a, this->_getDirectAddrByX(), 5);
case 0xD5: case 0xD5:
@@ -630,7 +630,7 @@ namespace ComSquare::APU
case 0xDD: case 0xDD:
return this->MOV(this->_internalRegisters.y, this->_internalRegisters.a); return this->MOV(this->_internalRegisters.y, this->_internalRegisters.a);
case 0xDE: case 0xDE:
return this->CBNE(this->_getDirectAddrByX(), true); return this->CBNE(this->_getDirectAddrByX(), this->_getImmediateData(), true);
case 0xDF: case 0xDF:
return this->DAA(); return this->DAA();
case 0xE0: case 0xE0:
@@ -640,7 +640,7 @@ namespace ComSquare::APU
case 0xE2: case 0xE2:
return this->SET1(this->_getDirectAddr(), 7); return this->SET1(this->_getDirectAddr(), 7);
case 0xE3: case 0xE3:
return this->BBS(this->_getDirectAddr(), 7); return this->BBS(this->_getDirectAddr(), this->_getImmediateData(), 7);
case 0xE4: case 0xE4:
return this->MOV(this->_getDirectAddr(), this->_internalRegisters.a, 3); return this->MOV(this->_getDirectAddr(), this->_internalRegisters.a, 3);
case 0xE5: case 0xE5:
@@ -666,13 +666,13 @@ namespace ComSquare::APU
case 0xEF: case 0xEF:
return this->SLEEP(); return this->SLEEP();
case 0xF0: case 0xF0:
return BEQ(); return BEQ(this->_getImmediateData());
case 0xF1: case 0xF1:
return this->TCALL(15); return this->TCALL(15);
case 0xF2: case 0xF2:
return this->CLR1(this->_getDirectAddr(), 7); return this->CLR1(this->_getDirectAddr(), 7);
case 0xF3: case 0xF3:
return this->BBC(this->_getDirectAddr(), 7); return this->BBC(this->_getDirectAddr(), this->_getImmediateData(), 7);
case 0xF4: case 0xF4:
return this->MOV(this->_getDirectAddrByX(), this->_internalRegisters.a, 4); return this->MOV(this->_getDirectAddrByX(), this->_internalRegisters.a, 4);
case 0xF5: case 0xF5:
@@ -694,7 +694,7 @@ namespace ComSquare::APU
case 0xFD: case 0xFD:
return this->MOV(this->_internalRegisters.a, this->_internalRegisters.y); return this->MOV(this->_internalRegisters.a, this->_internalRegisters.y);
case 0xFE: case 0xFE:
return this->DBNZ(); return this->DBNZ(this->_getImmediateData());
case 0xFF: case 0xFF:
return this->STOP(); return this->STOP();
default: default:

View File

@@ -264,31 +264,31 @@ namespace ComSquare::APU
int RETI(); int RETI();
//! @brief Branch Always, go to the specified location from the next instruction. //! @brief Branch Always, go to the specified location from the next instruction.
int BRA(); int BRA(int8_t offset);
//! @brief Branch if Zero Flag is set. //! @brief Branch if Zero Flag is set.
int BEQ(); int BEQ(int8_t offset);
//! @brief Branch if Zero Flag is clear. //! @brief Branch if Zero Flag is clear.
int BNE(); int BNE(int8_t offset);
//! @brief Branch if Carry Flag is set. //! @brief Branch if Carry Flag is set.
int BCS(); int BCS(int8_t offset);
//! @brief Branch if Carry Flag is clear. //! @brief Branch if Carry Flag is clear.
int BCC(); int BCC(int8_t offset);
//! @brief Branch if Overflow Flag is set. //! @brief Branch if Overflow Flag is set.
int BVS(); int BVS(int8_t offset);
//! @brief Branch if Overflow Flag is set. //! @brief Branch if Overflow Flag is set.
int BVC(); int BVC(int8_t offset);
//! @brief Branch if Negative Flag is set. //! @brief Branch if Negative Flag is set.
int BMI(); int BMI(int8_t offset);
//! @brief Branch if Negative Flag is clear. //! @brief Branch if Negative Flag is clear.
int BPL(); int BPL(int8_t offset);
//! @brief Branch if the specified is set in the address, go to the specified location from the next instruction. //! @brief Branch if the specified is set in the address, go to the specified location from the next instruction.
int BBS(uint24_t addr, uint8_t bit); int BBS(uint24_t addr, uint8_t bit, int8_t offset);
//! @brief Branch if the specified is clear in the address, go to the specified location from the next instruction. //! @brief Branch if the specified is clear in the address, go to the specified location from the next instruction.
int BBC(uint24_t addr, uint8_t bit); int BBC(uint24_t addr, uint8_t bit, int8_t offset);
//! @brief Branch if the value at the specified address is not equal to the Accumulator Flag. //! @brief Branch if the value at the specified address is not equal to the Accumulator Flag.
int CBNE(uint24_t addr, bool by_x = false); int CBNE(uint24_t addr, int8_t offset, bool by_x = false);
//! @brief Decrement a value then branch to the specified location if the value is not zero. //! @brief Decrement a value then branch to the specified location if the value is not zero.
int DBNZ(bool direct_addr = false); int DBNZ(int8_t offset, bool direct_addr = false);
//! @brief Jump to the specified location. //! @brief Jump to the specified location.
int JMP(uint24_t addr, bool by_x = false); int JMP(uint24_t addr, bool by_x = false);
@@ -363,9 +363,9 @@ namespace ComSquare::APU
int CMPreg(uint8_t &reg, uint24_t addr, int cycles); int CMPreg(uint8_t &reg, uint24_t addr, int cycles);
int MOV(uint8_t &regFrom, uint8_t &regTo, bool setFlags = true); int MOV(uint8_t &regFrom, uint8_t &regTo, bool setFlags = true);
int MOV(uint24_t memFrom, uint24_t memTo);
int MOV(uint8_t &regFrom, uint24_t memTo, int cycles, bool incrementX = false); int MOV(uint8_t &regFrom, uint24_t memTo, int cycles, bool incrementX = false);
int MOV(uint24_t memFrom, uint8_t &regTo, int cycles, bool incrementX = false); int MOV(uint24_t memFrom, uint8_t &regTo, int cycles, bool incrementX = false);
int MOV(uint24_t memTo, uint24_t memFrom);
public: public:
explicit APU(std::shared_ptr<MemoryMap> &map); explicit APU(std::shared_ptr<MemoryMap> &map);
APU(const APU &) = default; APU(const APU &) = default;

View File

@@ -32,9 +32,9 @@ namespace ComSquare::APU
return 2; return 2;
} }
int APU::MOV(uint24_t memFrom, uint24_t memTo) int APU::MOV(uint24_t memTo, uint24_t memFrom)
{ {
this->_internalWrite(memTo, this->_internalRead(memFrom)); this->_internalWrite(memTo, memFrom);
return 5; return 5;
} }
} }

View File

@@ -6,109 +6,107 @@
namespace ComSquare::APU namespace ComSquare::APU
{ {
int APU::BRA() int APU::BRA(int8_t offset)
{ {
int8_t offset = this->_getImmediateData();
this->_internalRegisters.pc += offset; this->_internalRegisters.pc += offset;
return 4; return 4;
} }
int APU::BEQ() int APU::BEQ(int8_t offset)
{ {
if (!this->_internalRegisters.z) if (!this->_internalRegisters.z)
return 2; return 2;
this->BRA(); this->BRA(offset);
return 4; return 4;
} }
int APU::BNE() int APU::BNE(int8_t offset)
{ {
if (this->_internalRegisters.z) if (this->_internalRegisters.z)
return 2; return 2;
this->BRA(); this->BRA(offset);
return 4; return 4;
} }
int APU::BCS() int APU::BCS(int8_t offset)
{ {
if (!this->_internalRegisters.c) if (!this->_internalRegisters.c)
return 2; return 2;
this->BRA(); this->BRA(offset);
return 4; return 4;
} }
int APU::BCC() int APU::BCC(int8_t offset)
{ {
if (this->_internalRegisters.c) if (this->_internalRegisters.c)
return 2; return 2;
this->BRA(); this->BRA(offset);
return 4; return 4;
} }
int APU::BVS() int APU::BVS(int8_t offset)
{ {
if (!this->_internalRegisters.v) if (!this->_internalRegisters.v)
return 2; return 2;
this->BRA(); this->BRA(offset);
return 4; return 4;
} }
int APU::BVC() int APU::BVC(int8_t offset)
{ {
if (this->_internalRegisters.v) if (this->_internalRegisters.v)
return 2; return 2;
this->BRA(); this->BRA(offset);
return 4; return 4;
} }
int APU::BMI() int APU::BMI(int8_t offset)
{ {
if (!this->_internalRegisters.n) if (!this->_internalRegisters.n)
return 2; return 2;
this->BRA(); this->BRA(offset);
return 4; return 4;
} }
int APU::BPL() int APU::BPL(int8_t offset)
{ {
if (this->_internalRegisters.n) if (this->_internalRegisters.n)
return 2; return 2;
this->BRA(); this->BRA(offset);
return 4; return 4;
} }
int APU::BBS(uint24_t addr, uint8_t bit) int APU::BBS(uint24_t addr, uint8_t bit, int8_t offset)
{ {
uint8_t data = this->_internalRead(addr); uint8_t data = this->_internalRead(addr);
if (!(data & (1u << bit))) if (!(data & (1u << bit)))
return 5; return 5;
this->BRA(); this->BRA(offset);
return 7; return 7;
} }
int APU::BBC(uint24_t addr, uint8_t bit) int APU::BBC(uint24_t addr, uint8_t bit, int8_t offset)
{ {
uint8_t data = this->_internalRead(addr); uint8_t data = this->_internalRead(addr);
if (data & (1u << bit)) if (data & (1u << bit))
return 5; return 5;
this->BRA(); this->BRA(offset);
return 7; return 7;
} }
int APU::CBNE(uint24_t addr, bool by_x) int APU::CBNE(uint24_t addr, int8_t offset, bool by_x)
{ {
uint8_t data = this->_internalRead(addr); uint8_t data = this->_internalRead(addr);
if (this->_internalRegisters.a == data) if (this->_internalRegisters.a == data)
return 5 + by_x; return 5 + by_x;
this->BRA(); this->BRA(offset);
return 7 + by_x; return 7 + by_x;
} }
int APU::DBNZ(bool direct_addr) int APU::DBNZ(int8_t offset, bool direct_addr)
{ {
uint8_t data; uint8_t data;
@@ -122,7 +120,7 @@ namespace ComSquare::APU
data = --this->_internalRegisters.y; data = --this->_internalRegisters.y;
if (!data) if (!data)
return 4 + direct_addr; return 4 + direct_addr;
this->BRA(); this->BRA(offset);
return 6 + direct_addr; return 6 + direct_addr;
} }

View File

@@ -35,11 +35,11 @@ namespace ComSquare::Debugger
this->_ui.port1hexaLineEdit->setText(Utility::to_hex(this->_registers.port1).c_str()); this->_ui.port1hexaLineEdit->setText(Utility::to_hex(this->_registers.port1).c_str());
this->_ui.port1LineEdit->setText(Utility::to_binary(this->_registers.port1).c_str()); this->_ui.port1LineEdit->setText(Utility::to_binary(this->_registers.port1).c_str());
this->_ui.port2hexaLineEdit->setText(Utility::to_hex(this->_registers.port1).c_str()); this->_ui.port2hexaLineEdit->setText(Utility::to_hex(this->_registers.port2).c_str());
this->_ui.port2LineEdit->setText(Utility::to_binary(this->_registers.port1).c_str()); this->_ui.port2LineEdit->setText(Utility::to_binary(this->_registers.port2).c_str());
this->_ui.port3hexaLineEdit->setText(Utility::to_hex(this->_registers.port1).c_str()); this->_ui.port3hexaLineEdit->setText(Utility::to_hex(this->_registers.port2).c_str());
this->_ui.port3LineEdit->setText(Utility::to_binary(this->_registers.port1).c_str()); this->_ui.port3LineEdit->setText(Utility::to_binary(this->_registers.port2).c_str());
this->_ui.controlhexaLineEdit->setText(Utility::to_hex(this->_registers.ctrlreg).c_str()); this->_ui.controlhexaLineEdit->setText(Utility::to_hex(this->_registers.ctrlreg).c_str());
this->_ui.controlLineEdit->setText(Utility::to_binary(this->_registers.ctrlreg).c_str()); this->_ui.controlLineEdit->setText(Utility::to_binary(this->_registers.ctrlreg).c_str());
@@ -475,6 +475,8 @@ namespace ComSquare::Debugger
int APUDebug::_executeInstruction() int APUDebug::_executeInstruction()
{ {
int cycles = 0;
if (this->_isPaused) if (this->_isPaused)
return 0xFF; return 0xFF;
if (this->_isStepping) { if (this->_isStepping) {
@@ -482,8 +484,9 @@ namespace ComSquare::Debugger
this->_isPaused = true; this->_isPaused = true;
} }
this->_ui.logger->append(APUDebug::_getInstructionString().c_str()); this->_ui.logger->append(APUDebug::_getInstructionString().c_str());
cycles = APU::_executeInstruction();
this->_updatePanel(); this->_updatePanel();
return APU::_executeInstruction(); return cycles;
} }
void APUDebug::update(unsigned cycles) void APUDebug::update(unsigned cycles)