mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2026-04-26 21:18:36 +00:00
Tidy up some C++ issues in GameBoy emulator
Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
1 parent
4d2d1d214a
commit
4dd3106af0
2 files changed
+144
-135
No files matched your search
+17
-135
@@ -43,54 +43,22 @@ namespace EightBit {
|
|||||||
void tickMachine() { tick(4); MachineTicked.fire(EventArgs::empty()); }
|
void tickMachine() { tick(4); MachineTicked.fire(EventArgs::empty()); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int execute() final;
|
int execute() final;
|
||||||
virtual int step() final;
|
int step() final;
|
||||||
|
|
||||||
void handleRESET() final;
|
void handleRESET() final;
|
||||||
void handleINT() final;
|
void handleINT() final;
|
||||||
|
|
||||||
void memoryWrite() final {
|
void memoryWrite() final;
|
||||||
tickMachine();
|
uint8_t memoryRead() final;
|
||||||
IntelProcessor::memoryWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t memoryRead() final {
|
void pushWord(register16_t value) final;
|
||||||
tickMachine();
|
|
||||||
return IntelProcessor::memoryRead();
|
|
||||||
}
|
|
||||||
|
|
||||||
void pushWord(register16_t value) final {
|
void jr(int8_t offset) final;
|
||||||
tickMachine();
|
int jumpConditional(int condition) final;
|
||||||
IntelProcessor::pushWord(value);
|
int returnConditional(int condition) final;
|
||||||
}
|
int jrConditional(int condition) final;
|
||||||
|
void ret() final;
|
||||||
void jr(int8_t offset) final {
|
|
||||||
IntelProcessor::jr(offset);
|
|
||||||
tickMachine();
|
|
||||||
}
|
|
||||||
|
|
||||||
int jumpConditional(const int condition) final {
|
|
||||||
if (IntelProcessor::jumpConditional(condition))
|
|
||||||
tickMachine();
|
|
||||||
return condition;
|
|
||||||
}
|
|
||||||
|
|
||||||
int returnConditional(const int condition) final {
|
|
||||||
IntelProcessor::returnConditional(condition);
|
|
||||||
tickMachine();
|
|
||||||
return condition;
|
|
||||||
}
|
|
||||||
|
|
||||||
int jrConditional(const int condition) final {
|
|
||||||
if (!IntelProcessor::jrConditional(condition))
|
|
||||||
tickMachine();
|
|
||||||
return condition;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ret() final {
|
|
||||||
IntelProcessor::ret();
|
|
||||||
tickMachine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Bus& m_bus;
|
Bus& m_bus;
|
||||||
@@ -105,97 +73,11 @@ namespace EightBit {
|
|||||||
|
|
||||||
bool m_prefixCB = false;
|
bool m_prefixCB = false;
|
||||||
|
|
||||||
[[nodiscard]] auto R(const int r) {
|
[[nodiscard]] uint8_t R(int r);
|
||||||
ASSUME(r >= 0);
|
void R(int r, uint8_t value);
|
||||||
ASSUME(r <= 7);
|
|
||||||
switch (r) {
|
|
||||||
case 0:
|
|
||||||
return B();
|
|
||||||
case 1:
|
|
||||||
return C();
|
|
||||||
case 2:
|
|
||||||
return D();
|
|
||||||
case 3:
|
|
||||||
return E();
|
|
||||||
case 4:
|
|
||||||
return H();
|
|
||||||
case 5:
|
|
||||||
return L();
|
|
||||||
case 6:
|
|
||||||
return IntelProcessor::memoryRead(HL());
|
|
||||||
case 7:
|
|
||||||
return A();
|
|
||||||
default:
|
|
||||||
UNREACHABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void R(const int r, const uint8_t value) {
|
[[nodiscard]] register16_t& RP(int rp);
|
||||||
ASSUME(r >= 0);
|
[[nodiscard]] register16_t& RP2(int rp);
|
||||||
ASSUME(r <= 7);
|
|
||||||
switch (r) {
|
|
||||||
case 0:
|
|
||||||
B() = value;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
C() = value;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
D() = value;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
E() = value;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
H() = value;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
L() = value;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
IntelProcessor::memoryWrite(HL(), value);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
A() = value;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
UNREACHABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto& RP(const int rp) {
|
|
||||||
ASSUME(rp >= 0);
|
|
||||||
ASSUME(rp <= 3);
|
|
||||||
switch (rp) {
|
|
||||||
case 0b00:
|
|
||||||
return BC();
|
|
||||||
case 0b01:
|
|
||||||
return DE();
|
|
||||||
case 0b10:
|
|
||||||
return HL();
|
|
||||||
case 0b11:
|
|
||||||
return SP();
|
|
||||||
default:
|
|
||||||
UNREACHABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto& RP2(const int rp) {
|
|
||||||
ASSUME(rp >= 0);
|
|
||||||
ASSUME(rp <= 3);
|
|
||||||
switch (rp) {
|
|
||||||
case 0b00:
|
|
||||||
return BC();
|
|
||||||
case 0b01:
|
|
||||||
return DE();
|
|
||||||
case 0b10:
|
|
||||||
return HL();
|
|
||||||
case 0b11:
|
|
||||||
return AF();
|
|
||||||
default:
|
|
||||||
UNREACHABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static auto adjustHalfCarryAdd(uint8_t f, const uint8_t before, const uint8_t value, const int calculation) {
|
[[nodiscard]] static auto adjustHalfCarryAdd(uint8_t f, const uint8_t before, const uint8_t value, const int calculation) {
|
||||||
return setBit(f, HC, calculateHalfCarryAdd(before, value, calculation));
|
return setBit(f, HC, calculateHalfCarryAdd(before, value, calculation));
|
||||||
@@ -217,7 +99,7 @@ namespace EightBit {
|
|||||||
|
|
||||||
void stop(bool value = true) noexcept { m_stopped = value; }
|
void stop(bool value = true) noexcept { m_stopped = value; }
|
||||||
void start() noexcept { stop(false); }
|
void start() noexcept { stop(false); }
|
||||||
bool stopped() const noexcept { return m_stopped; }
|
[[nodiscard]] bool stopped() const noexcept { return m_stopped; }
|
||||||
|
|
||||||
void di();
|
void di();
|
||||||
void ei();
|
void ei();
|
||||||
@@ -255,9 +137,9 @@ namespace EightBit {
|
|||||||
|
|
||||||
static void scf(uint8_t& f, uint8_t operand);
|
static void scf(uint8_t& f, uint8_t operand);
|
||||||
static void ccf(uint8_t& f, uint8_t operand);
|
static void ccf(uint8_t& f, uint8_t operand);
|
||||||
static uint8_t cpl(uint8_t& f, uint8_t operand);
|
[[nodiscard]] static uint8_t cpl(uint8_t& f, uint8_t operand);
|
||||||
|
|
||||||
static uint8_t swap(uint8_t& f, uint8_t operand);
|
[[nodiscard]] static uint8_t swap(uint8_t& f, uint8_t operand);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,49 @@ void EightBit::GameBoy::LR35902::handleINT() {
|
|||||||
restart(BUS().DATA());
|
restart(BUS().DATA());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EightBit::GameBoy::LR35902::memoryWrite() {
|
||||||
|
tickMachine();
|
||||||
|
IntelProcessor::memoryWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t EightBit::GameBoy::LR35902::memoryRead() {
|
||||||
|
tickMachine();
|
||||||
|
return IntelProcessor::memoryRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EightBit::GameBoy::LR35902::pushWord(register16_t value) {
|
||||||
|
tickMachine();
|
||||||
|
IntelProcessor::pushWord(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EightBit::GameBoy::LR35902::jr(int8_t offset) {
|
||||||
|
IntelProcessor::jr(offset);
|
||||||
|
tickMachine();
|
||||||
|
}
|
||||||
|
|
||||||
|
int EightBit::GameBoy::LR35902::jumpConditional(const int condition) {
|
||||||
|
if (IntelProcessor::jumpConditional(condition))
|
||||||
|
tickMachine();
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EightBit::GameBoy::LR35902::returnConditional(const int condition) {
|
||||||
|
IntelProcessor::returnConditional(condition);
|
||||||
|
tickMachine();
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EightBit::GameBoy::LR35902::jrConditional(const int condition) {
|
||||||
|
if (!IntelProcessor::jrConditional(condition))
|
||||||
|
tickMachine();
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EightBit::GameBoy::LR35902::ret() {
|
||||||
|
IntelProcessor::ret();
|
||||||
|
tickMachine();
|
||||||
|
}
|
||||||
|
|
||||||
void EightBit::GameBoy::LR35902::di() {
|
void EightBit::GameBoy::LR35902::di() {
|
||||||
IME() = false;
|
IME() = false;
|
||||||
}
|
}
|
||||||
@@ -68,6 +111,90 @@ uint8_t EightBit::GameBoy::LR35902::decrement(uint8_t& f, const uint8_t operand)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t EightBit::GameBoy::LR35902::R(const int r) {
|
||||||
|
switch (r) {
|
||||||
|
case 0:
|
||||||
|
return B();
|
||||||
|
case 1:
|
||||||
|
return C();
|
||||||
|
case 2:
|
||||||
|
return D();
|
||||||
|
case 3:
|
||||||
|
return E();
|
||||||
|
case 4:
|
||||||
|
return H();
|
||||||
|
case 5:
|
||||||
|
return L();
|
||||||
|
case 6:
|
||||||
|
return IntelProcessor::memoryRead(HL());
|
||||||
|
case 7:
|
||||||
|
return A();
|
||||||
|
default:
|
||||||
|
UNREACHABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EightBit::GameBoy::LR35902::R(const int r, const uint8_t value) {
|
||||||
|
switch (r) {
|
||||||
|
case 0:
|
||||||
|
B() = value;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
C() = value;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
D() = value;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
E() = value;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
H() = value;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
L() = value;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
IntelProcessor::memoryWrite(HL(), value);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
A() = value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EightBit::register16_t& EightBit::GameBoy::LR35902::RP(const int rp) {
|
||||||
|
switch (rp) {
|
||||||
|
case 0b00:
|
||||||
|
return BC();
|
||||||
|
case 0b01:
|
||||||
|
return DE();
|
||||||
|
case 0b10:
|
||||||
|
return HL();
|
||||||
|
case 0b11:
|
||||||
|
return SP();
|
||||||
|
default:
|
||||||
|
UNREACHABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EightBit::register16_t& EightBit::GameBoy::LR35902::RP2(const int rp) {
|
||||||
|
switch (rp) {
|
||||||
|
case 0b00:
|
||||||
|
return BC();
|
||||||
|
case 0b01:
|
||||||
|
return DE();
|
||||||
|
case 0b10:
|
||||||
|
return HL();
|
||||||
|
case 0b11:
|
||||||
|
return AF();
|
||||||
|
default:
|
||||||
|
UNREACHABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool EightBit::GameBoy::LR35902::convertCondition(const uint8_t f, int flag) {
|
bool EightBit::GameBoy::LR35902::convertCondition(const uint8_t f, int flag) {
|
||||||
ASSUME(flag >= 0);
|
ASSUME(flag >= 0);
|
||||||
ASSUME(flag <= 7);
|
ASSUME(flag <= 7);
|
||||||
|
|||||||
Reference in new issue
Block a user