mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-21 18:29:57 +00:00
Simplify LR35902 machine timing.
This commit is contained in:
parent
eb761bc62f
commit
d785b1eae7
@ -37,6 +37,11 @@ namespace EightBit {
|
||||
[[nodiscard]] uint8_t flaggedInterrupts();
|
||||
[[nodiscard]] uint8_t maskedInterrupts();
|
||||
|
||||
Signal<EventArgs> MachineTicked;
|
||||
|
||||
void tickMachine(const int extra) { for (int i = 0; i < extra; ++i) tickMachine(); }
|
||||
void tickMachine() { tick(4); MachineTicked.fire(EventArgs::empty()); }
|
||||
|
||||
protected:
|
||||
virtual int execute() final;
|
||||
virtual int step() final;
|
||||
@ -45,46 +50,46 @@ namespace EightBit {
|
||||
void handleINT() final;
|
||||
|
||||
void memoryWrite() final {
|
||||
tick(4);
|
||||
tickMachine();
|
||||
IntelProcessor::memoryWrite();
|
||||
}
|
||||
|
||||
uint8_t memoryRead() final {
|
||||
tick(4);
|
||||
tickMachine();
|
||||
return IntelProcessor::memoryRead();
|
||||
}
|
||||
|
||||
void pushWord(register16_t value) final {
|
||||
tick(4);
|
||||
tickMachine();
|
||||
IntelProcessor::pushWord(value);
|
||||
}
|
||||
|
||||
void jr(int8_t offset) final {
|
||||
IntelProcessor::jr(offset);
|
||||
tick(4);
|
||||
tickMachine();
|
||||
}
|
||||
|
||||
int jumpConditional(const int condition) final {
|
||||
if (IntelProcessor::jumpConditional(condition))
|
||||
tick(4);
|
||||
tickMachine();
|
||||
return condition;
|
||||
}
|
||||
|
||||
int returnConditional(const int condition) final {
|
||||
IntelProcessor::returnConditional(condition);
|
||||
tick(4);
|
||||
tickMachine();
|
||||
return condition;
|
||||
}
|
||||
|
||||
int jrConditional(const int condition) final {
|
||||
if (!IntelProcessor::jrConditional(condition))
|
||||
tick(4);
|
||||
tickMachine();
|
||||
return condition;
|
||||
}
|
||||
|
||||
void ret() final {
|
||||
IntelProcessor::ret();
|
||||
tick(4);
|
||||
tickMachine();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -7,11 +7,9 @@
|
||||
EightBit::GameBoy::LR35902::LR35902(Bus& memory)
|
||||
: IntelProcessor(memory),
|
||||
m_bus(memory) {
|
||||
Ticked.connect([this](EventArgs) {
|
||||
if ((cycles() % 4) == 0) {
|
||||
m_bus.IO().incrementTimers();
|
||||
m_bus.IO().transferDma();
|
||||
}
|
||||
MachineTicked.connect([this](EventArgs) {
|
||||
m_bus.IO().incrementTimers();
|
||||
m_bus.IO().transferDma();
|
||||
});
|
||||
}
|
||||
|
||||
@ -36,7 +34,7 @@ void EightBit::GameBoy::LR35902::handleRESET() {
|
||||
IntelProcessor::handleRESET();
|
||||
di();
|
||||
SP() = Mask16 - 1;
|
||||
tick(4 * 4);
|
||||
tickMachine(4);
|
||||
}
|
||||
|
||||
void EightBit::GameBoy::LR35902::handleINT() {
|
||||
@ -110,7 +108,7 @@ void EightBit::GameBoy::LR35902::reti() {
|
||||
|
||||
EightBit::register16_t EightBit::GameBoy::LR35902::add(uint8_t& f, const register16_t operand, const register16_t value) {
|
||||
|
||||
tick(4);
|
||||
tickMachine();
|
||||
|
||||
const int addition = operand.word + value.word;
|
||||
const register16_t result = addition;
|
||||
@ -508,7 +506,7 @@ void EightBit::GameBoy::LR35902::executeOther(const int x, const int y, const in
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
tick(4);
|
||||
tickMachine();
|
||||
break;
|
||||
case 4: { // 8-bit INC
|
||||
auto operand = R(y);
|
||||
@ -608,7 +606,7 @@ void EightBit::GameBoy::LR35902::executeOther(const int x, const int y, const in
|
||||
case 5: { // GB: ADD SP,dd
|
||||
const auto before = SP().word;
|
||||
const int8_t value = fetchByte();
|
||||
tick(2 * 4);
|
||||
tickMachine(2);
|
||||
const auto result = before + value;
|
||||
SP() = result;
|
||||
const auto carried = before ^ value ^ (result & Mask16);
|
||||
@ -623,7 +621,7 @@ void EightBit::GameBoy::LR35902::executeOther(const int x, const int y, const in
|
||||
case 7: { // GB: LD HL,SP + dd
|
||||
const auto before = SP().word;
|
||||
const int8_t value = fetchByte();
|
||||
tick(4);
|
||||
tickMachine();
|
||||
const auto result = before + value;
|
||||
HL() = result;
|
||||
const auto carried = before ^ value ^ (result & Mask16);
|
||||
@ -654,7 +652,7 @@ void EightBit::GameBoy::LR35902::executeOther(const int x, const int y, const in
|
||||
break;
|
||||
case 3: // LD SP,HL
|
||||
SP() = HL();
|
||||
tick(4);
|
||||
tickMachine();
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE;
|
||||
@ -694,7 +692,7 @@ void EightBit::GameBoy::LR35902::executeOther(const int x, const int y, const in
|
||||
switch (y) {
|
||||
case 0: // JP nn
|
||||
jump(MEMPTR() = fetchWord());
|
||||
tick(4);
|
||||
tickMachine();
|
||||
break;
|
||||
case 1: // CB prefix
|
||||
m_prefixCB = true;
|
||||
|
Loading…
Reference in New Issue
Block a user