mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-21 18:29:57 +00:00
Remove duplicated code (from const definitions) the performance benefit isn't worth the amount of duplicated code.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
feb5e7ad60
commit
cac871cf2b
@ -12,8 +12,8 @@ namespace EightBit {
|
||||
public:
|
||||
Disassembler();
|
||||
|
||||
static std::string state(const Intel8080& cpu);
|
||||
std::string disassemble(const Intel8080& cpu);
|
||||
static std::string state(Intel8080& cpu);
|
||||
std::string disassemble(Intel8080& cpu);
|
||||
|
||||
static std::string flag(uint8_t value, int flag, std::string represents, std::string off = "-");
|
||||
static std::string flags(uint8_t value);
|
||||
@ -26,7 +26,7 @@ namespace EightBit {
|
||||
private:
|
||||
mutable boost::format m_formatter;
|
||||
|
||||
void disassemble(std::ostringstream& output, const Intel8080& cpu, uint16_t pc);
|
||||
void disassemble(std::ostringstream& output, Intel8080& cpu, uint16_t pc);
|
||||
|
||||
void disassemble(
|
||||
std::ostringstream& output,
|
||||
|
@ -29,13 +29,9 @@ namespace EightBit {
|
||||
virtual int execute(uint8_t opcode) final;
|
||||
virtual int step() final;
|
||||
|
||||
virtual register16_t AF() const final;
|
||||
virtual register16_t& AF() final;
|
||||
virtual register16_t BC() const final;
|
||||
virtual register16_t& BC() final;
|
||||
virtual register16_t DE() const final;
|
||||
virtual register16_t& DE() final;
|
||||
virtual register16_t HL() const final;
|
||||
virtual register16_t& HL() final;
|
||||
|
||||
protected:
|
||||
@ -105,21 +101,6 @@ namespace EightBit {
|
||||
}
|
||||
}
|
||||
|
||||
register16_t RP(int rp) const {
|
||||
switch (rp) {
|
||||
case 0b00:
|
||||
return BC();
|
||||
case 0b01:
|
||||
return DE();
|
||||
case 0b10:
|
||||
return HL();
|
||||
case 0b11:
|
||||
return SP();
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
register16_t& RP(int rp) {
|
||||
switch (rp) {
|
||||
case 0b00:
|
||||
@ -135,21 +116,6 @@ namespace EightBit {
|
||||
}
|
||||
}
|
||||
|
||||
register16_t RP2(int rp) const {
|
||||
switch (rp) {
|
||||
case 0b00:
|
||||
return BC();
|
||||
case 0b01:
|
||||
return DE();
|
||||
case 0b10:
|
||||
return HL();
|
||||
case 0b11:
|
||||
return AF();
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
register16_t& RP2(int rp) {
|
||||
switch (rp) {
|
||||
case 0b00:
|
||||
|
@ -13,7 +13,7 @@ EightBit::Disassembler::Disassembler() {
|
||||
m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembler::state(const Intel8080& cpu) {
|
||||
std::string EightBit::Disassembler::state(Intel8080& cpu) {
|
||||
|
||||
auto pc = cpu.PC();
|
||||
auto sp = cpu.SP();
|
||||
@ -160,13 +160,13 @@ std::string EightBit::Disassembler::alu2(int which) {
|
||||
throw std::logic_error("Unhandled alu operation");
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembler::disassemble(const Intel8080& cpu) {
|
||||
std::string EightBit::Disassembler::disassemble(Intel8080& cpu) {
|
||||
std::ostringstream output;
|
||||
disassemble(output, cpu, cpu.PC().word);
|
||||
return output.str();
|
||||
}
|
||||
|
||||
void EightBit::Disassembler::disassemble(std::ostringstream& output, const Intel8080& cpu, uint16_t pc) {
|
||||
void EightBit::Disassembler::disassemble(std::ostringstream& output, Intel8080& cpu, uint16_t pc) {
|
||||
|
||||
auto& bus = cpu.BUS();
|
||||
auto opcode = bus.peek(pc);
|
||||
|
@ -49,7 +49,7 @@ void Board::Cpu_ExecutingInstruction_Cpm(const EightBit::Intel8080& cpu) {
|
||||
}
|
||||
}
|
||||
|
||||
void Board::bdos() const {
|
||||
void Board::bdos() {
|
||||
switch (CPU().C()) {
|
||||
case 0x2: {
|
||||
const auto character = CPU().E();
|
||||
|
@ -24,10 +24,6 @@ protected:
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
virtual uint8_t reference(uint16_t address) const {
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
private:
|
||||
const Configuration& m_configuration;
|
||||
EightBit::Ram m_ram = 0x10000;
|
||||
@ -41,5 +37,5 @@ private:
|
||||
void Cpu_ExecutingInstruction_Debug(const EightBit::Intel8080& cpu);
|
||||
void Cpu_ExecutingInstruction_Profile(const EightBit::Intel8080& cpu);
|
||||
|
||||
void bdos() const;
|
||||
void bdos();
|
||||
};
|
||||
|
@ -41,10 +41,6 @@ namespace Fuse {
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
virtual uint8_t reference(uint16_t address) const {
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
public:
|
||||
TestRunner(const Test& test, const ExpectedTestResult& expected);
|
||||
|
||||
|
@ -10,12 +10,12 @@ namespace EightBit {
|
||||
namespace GameBoy {
|
||||
class CharacterDefinition final {
|
||||
public:
|
||||
CharacterDefinition(const Ram& vram, uint16_t address);
|
||||
CharacterDefinition(Ram& vram, uint16_t address);
|
||||
|
||||
std::array<int, 8> get(int row) const;
|
||||
std::array<int, 8> get(int row);
|
||||
|
||||
private:
|
||||
const Ram& m_vram;
|
||||
Ram& m_vram;
|
||||
uint16_t m_address = ~0;
|
||||
};
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ namespace EightBit {
|
||||
int drawX, int drawY,
|
||||
bool flipX, bool flipY, bool allowTransparencies,
|
||||
const std::array<int, 4>& palette,
|
||||
const CharacterDefinition& definition);
|
||||
CharacterDefinition& definition);
|
||||
};
|
||||
}
|
||||
}
|
@ -36,13 +36,9 @@ namespace EightBit {
|
||||
Bus();
|
||||
|
||||
LR35902& CPU() { return m_cpu; }
|
||||
const LR35902& CPU() const { return m_cpu; }
|
||||
Ram& VRAM() { return m_videoRam; }
|
||||
const Ram& VRAM() const { return m_videoRam; }
|
||||
Ram& OAMRAM() { return m_oamRam; }
|
||||
const Ram& OAMRAM() const { return m_oamRam; }
|
||||
IoRegisters& IO() { return m_ioPorts; }
|
||||
const IoRegisters& IO() const { return m_ioPorts; }
|
||||
|
||||
void reset();
|
||||
|
||||
@ -59,8 +55,7 @@ namespace EightBit {
|
||||
int runVerticalBlankLines();
|
||||
|
||||
protected:
|
||||
virtual uint8_t& reference(uint16_t address, bool& rom);
|
||||
virtual uint8_t reference(uint16_t address, bool& rom) const;
|
||||
virtual uint8_t& reference(uint16_t address);
|
||||
|
||||
private:
|
||||
LR35902 m_cpu;
|
||||
|
@ -35,17 +35,8 @@ namespace EightBit {
|
||||
return af;
|
||||
}
|
||||
|
||||
register16_t AF() const final {
|
||||
const auto low = higherNibble(af.low);
|
||||
const auto high = af.high;
|
||||
return register16_t(low, high);
|
||||
}
|
||||
|
||||
virtual register16_t BC() const final { return bc; }
|
||||
virtual register16_t& BC() final { return bc; }
|
||||
virtual register16_t DE() const final { return de; }
|
||||
virtual register16_t& DE() final { return de; }
|
||||
virtual register16_t HL() const final { return hl; }
|
||||
virtual register16_t& HL() final { return hl; }
|
||||
|
||||
int singleStep();
|
||||
|
@ -3,12 +3,12 @@
|
||||
|
||||
#include <Ram.h>
|
||||
|
||||
EightBit::GameBoy::CharacterDefinition::CharacterDefinition(const Ram& vram, const uint16_t address)
|
||||
EightBit::GameBoy::CharacterDefinition::CharacterDefinition(Ram& vram, const uint16_t address)
|
||||
: m_vram(vram),
|
||||
m_address(address) {
|
||||
}
|
||||
|
||||
std::array<int, 8> EightBit::GameBoy::CharacterDefinition::get(int row) const {
|
||||
std::array<int, 8> EightBit::GameBoy::CharacterDefinition::get(int row) {
|
||||
|
||||
std::array<int, 8> returned;
|
||||
|
||||
|
@ -71,7 +71,7 @@ void EightBit::GameBoy::Display::renderObjects() {
|
||||
const auto drawX = spriteX - 8;
|
||||
|
||||
const auto sprite = current.pattern();
|
||||
const auto definition = CharacterDefinition(m_vram, characterAddressMultiplier * sprite);
|
||||
auto definition = CharacterDefinition(m_vram, characterAddressMultiplier * sprite);
|
||||
const auto& palette = palettes[current.palette()];
|
||||
const auto flipX = current.flipX();
|
||||
const auto flipY = current.flipY();
|
||||
@ -118,7 +118,7 @@ void EightBit::GameBoy::Display::renderBackground(
|
||||
|
||||
const auto character = m_vram.peek(address++);
|
||||
|
||||
const auto definition = CharacterDefinition(m_vram, bgCharacters + 16 * character);
|
||||
auto definition = CharacterDefinition(m_vram, bgCharacters + 16 * character);
|
||||
renderTile(
|
||||
8,
|
||||
column * 8 + offsetX, row * 8 + offsetY,
|
||||
@ -133,7 +133,7 @@ void EightBit::GameBoy::Display::renderTile(
|
||||
const int drawX, const int drawY,
|
||||
const bool flipX, const bool flipY, const bool allowTransparencies,
|
||||
const std::array<int, 4>& palette,
|
||||
const CharacterDefinition& definition) {
|
||||
CharacterDefinition& definition) {
|
||||
|
||||
const auto width = 8;
|
||||
|
||||
|
@ -149,21 +149,19 @@ void EightBit::GameBoy::Bus::validateCartridgeType() {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t EightBit::GameBoy::Bus::reference(uint16_t address, bool& rom) const {
|
||||
uint8_t& EightBit::GameBoy::Bus::reference(uint16_t address) {
|
||||
|
||||
rom = true;
|
||||
if ((address < 0x100) && IO().bootRomEnabled())
|
||||
return m_bootRom.reference(address);
|
||||
return DATA() = m_bootRom.peek(address);
|
||||
if ((address < 0x4000) && gameRomEnabled())
|
||||
return m_gameRomBanks[0].reference(address);
|
||||
return DATA() = m_gameRomBanks[0].peek(address);
|
||||
if ((address < 0x8000) && gameRomEnabled())
|
||||
return m_gameRomBanks[m_romBank].reference(address - 0x4000);
|
||||
return DATA() = m_gameRomBanks[m_romBank].peek(address - 0x4000);
|
||||
|
||||
rom = false;
|
||||
if (address < 0xa000)
|
||||
return VRAM().reference(address - 0x8000);
|
||||
if (address < 0xc000)
|
||||
return m_ramBanks.size() == 0 ? rom = true, 0xff : m_ramBanks[m_ramBank].reference(address - 0xa000);
|
||||
return m_ramBanks.size() == 0 ? DATA() = 0xff : m_ramBanks[m_ramBank].reference(address - 0xa000);
|
||||
if (address < 0xe000)
|
||||
return m_lowInternalRam.reference(address - 0xc000);
|
||||
if (address < 0xfe00)
|
||||
@ -171,35 +169,7 @@ uint8_t EightBit::GameBoy::Bus::reference(uint16_t address, bool& rom) const {
|
||||
if (address < 0xfea0)
|
||||
return OAMRAM().reference(address - 0xfe00);
|
||||
if (address < IoRegisters::BASE)
|
||||
return rom = true, 0xff;
|
||||
if (address < 0xff80)
|
||||
return IO().reference(address - IoRegisters::BASE);
|
||||
return m_highInternalRam.reference(address - 0xff80);
|
||||
}
|
||||
|
||||
uint8_t& EightBit::GameBoy::Bus::reference(uint16_t address, bool& rom) {
|
||||
|
||||
rom = true;
|
||||
if ((address < 0x100) && IO().bootRomEnabled())
|
||||
return DATA() = m_bootRom.reference(address);
|
||||
if ((address < 0x4000) && gameRomEnabled())
|
||||
return DATA() = m_gameRomBanks[0].reference(address);
|
||||
if ((address < 0x8000) && gameRomEnabled())
|
||||
return DATA() = m_gameRomBanks[m_romBank].reference(address - 0x4000);
|
||||
|
||||
rom = false;
|
||||
if (address < 0xa000)
|
||||
return VRAM().reference(address - 0x8000);
|
||||
if (address < 0xc000)
|
||||
return m_ramBanks.size() == 0 ? rom = true, DATA() = 0xff : m_ramBanks[m_ramBank].reference(address - 0xa000);
|
||||
if (address < 0xe000)
|
||||
return m_lowInternalRam.reference(address - 0xc000);
|
||||
if (address < 0xfe00)
|
||||
return m_lowInternalRam.reference(address - 0xe000); // Low internal RAM mirror
|
||||
if (address < 0xfea0)
|
||||
return OAMRAM().reference(address - 0xfe00);
|
||||
if (address < IoRegisters::BASE)
|
||||
return rom = true, DATA() = 0xff;
|
||||
return DATA() = 0xff;
|
||||
if (address < 0xff80)
|
||||
return IO().reference(address - IoRegisters::BASE);
|
||||
return m_highInternalRam.reference(address - 0xff80);
|
||||
|
@ -33,18 +33,12 @@ namespace EightBit {
|
||||
virtual int step() final;
|
||||
virtual void powerOn() override;
|
||||
|
||||
uint8_t X() const { return x; }
|
||||
uint8_t& X() { return x; }
|
||||
uint8_t Y() const { return y; }
|
||||
uint8_t& Y() { return y; }
|
||||
uint8_t A() const { return a; }
|
||||
uint8_t& A() { return a; }
|
||||
uint8_t S() const { return s; }
|
||||
uint8_t& S() { return s; }
|
||||
uint8_t P() const { return p; }
|
||||
uint8_t& P() { return p; }
|
||||
|
||||
PinLevel SO() const { return m_soLine; } // In
|
||||
PinLevel& SO() { return m_soLine; } // In
|
||||
|
||||
protected:
|
||||
|
@ -24,10 +24,6 @@ protected:
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
virtual uint8_t reference(uint16_t address) const {
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
private:
|
||||
const Configuration& m_configuration;
|
||||
EightBit::Ram m_ram = 0x10000;
|
||||
|
@ -40,10 +40,6 @@ namespace Fuse {
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
virtual uint8_t reference(uint16_t address) const {
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
public:
|
||||
TestRunner(const Test& test, const ExpectedTestResult& expected);
|
||||
|
||||
|
@ -11,8 +11,8 @@ namespace EightBit {
|
||||
public:
|
||||
Disassembler();
|
||||
|
||||
static std::string state(const Z80& cpu);
|
||||
std::string disassemble(const Z80& cpu);
|
||||
static std::string state(Z80& cpu);
|
||||
std::string disassemble(Z80& cpu);
|
||||
|
||||
static std::string flag(uint8_t value, int flag, const std::string& represents);
|
||||
static std::string flags(uint8_t value);
|
||||
@ -30,7 +30,7 @@ namespace EightBit {
|
||||
bool m_prefixED;
|
||||
bool m_prefixFD;
|
||||
|
||||
void disassemble(std::ostringstream& output, const Z80& cpu, uint16_t pc);
|
||||
void disassemble(std::ostringstream& output, Z80& cpu, uint16_t pc);
|
||||
|
||||
void disassembleCB(
|
||||
std::ostringstream& output,
|
||||
@ -52,7 +52,7 @@ namespace EightBit {
|
||||
|
||||
void disassembleOther(
|
||||
std::ostringstream& output,
|
||||
const Z80& cpu,
|
||||
Z80& cpu,
|
||||
uint16_t pc,
|
||||
std::string& specification,
|
||||
int& dumpCount,
|
||||
|
@ -51,44 +51,28 @@ namespace EightBit {
|
||||
Signal<Z80> ExecutingInstruction;
|
||||
|
||||
PinLevel& M1() { return m_m1Line; } // Out
|
||||
PinLevel M1() const { return m_m1Line; }
|
||||
|
||||
virtual int execute(uint8_t opcode) final;
|
||||
virtual int step() final;
|
||||
|
||||
virtual register16_t& AF() final;
|
||||
virtual register16_t AF() const final;
|
||||
virtual register16_t& BC() final;
|
||||
virtual register16_t BC() const final;
|
||||
virtual register16_t& DE() final;
|
||||
virtual register16_t DE() const final;
|
||||
virtual register16_t& HL() final;
|
||||
virtual register16_t HL() const final;
|
||||
|
||||
register16_t& IX() { return m_ix; }
|
||||
register16_t IX() const { return m_ix; }
|
||||
uint8_t& IXH() { return IX().high; }
|
||||
uint8_t IXH() const { return IX().high; }
|
||||
uint8_t& IXL() { return IX().low; }
|
||||
uint8_t IXL() const { return IX().low; }
|
||||
|
||||
register16_t& IY() { return m_iy; }
|
||||
register16_t IY() const { return m_iy; }
|
||||
uint8_t& IYH() { return IY().high; }
|
||||
uint8_t IYH() const { return IY().high; }
|
||||
uint8_t& IYL() { return IY().low; }
|
||||
uint8_t IYL() const { return IY().low; }
|
||||
|
||||
refresh_t& REFRESH() { return m_refresh; }
|
||||
refresh_t REFRESH() const { return m_refresh; }
|
||||
uint8_t& IV() { return iv; }
|
||||
uint8_t IV() const { return iv; }
|
||||
int& IM() { return m_interruptMode; }
|
||||
int IM() const { return m_interruptMode; }
|
||||
bool& IFF1() { return m_iff1; }
|
||||
bool IFF1() const { return m_iff1; }
|
||||
bool& IFF2() { return m_iff2; }
|
||||
bool IFF2() const { return m_iff2; }
|
||||
|
||||
void exx() {
|
||||
m_registerSet ^= 1;
|
||||
@ -274,23 +258,6 @@ namespace EightBit {
|
||||
}
|
||||
}
|
||||
|
||||
register16_t RP(const int rp) const {
|
||||
ASSUME(rp >= 0);
|
||||
ASSUME(rp <= 3);
|
||||
switch (rp) {
|
||||
case 0:
|
||||
return BC();
|
||||
case 1:
|
||||
return DE();
|
||||
case 2:
|
||||
return HL2();
|
||||
case 3:
|
||||
return SP();
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
register16_t& HL2() {
|
||||
if (LIKELY(!m_displaced))
|
||||
return HL();
|
||||
@ -300,15 +267,6 @@ namespace EightBit {
|
||||
return IY();
|
||||
}
|
||||
|
||||
register16_t HL2() const {
|
||||
if (LIKELY(!m_displaced))
|
||||
return HL();
|
||||
if (m_prefixDD)
|
||||
return IX();
|
||||
// Must be FD prefix
|
||||
return IY();
|
||||
}
|
||||
|
||||
register16_t& RP2(const int rp) {
|
||||
ASSUME(rp >= 0);
|
||||
ASSUME(rp <= 3);
|
||||
@ -326,23 +284,6 @@ namespace EightBit {
|
||||
}
|
||||
}
|
||||
|
||||
register16_t RP2(const int rp) const {
|
||||
ASSUME(rp >= 0);
|
||||
ASSUME(rp <= 3);
|
||||
switch (rp) {
|
||||
case 0:
|
||||
return BC();
|
||||
case 1:
|
||||
return DE();
|
||||
case 2:
|
||||
return HL2();
|
||||
case 3:
|
||||
return AF();
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
static void adjustHalfCarryAdd(uint8_t& f, const uint8_t before, const uint8_t value, const int calculation) {
|
||||
setFlag(f, HC, calculateHalfCarryAdd(before, value, calculation));
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ EightBit::Disassembler::Disassembler() {
|
||||
m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembler::state(const Z80& cpu) {
|
||||
std::string EightBit::Disassembler::state(Z80& cpu) {
|
||||
|
||||
auto pc = cpu.PC();
|
||||
auto sp = cpu.SP();
|
||||
@ -171,14 +171,14 @@ std::string EightBit::Disassembler::alu(int which) {
|
||||
throw std::logic_error("Unhandled alu operation");
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembler::disassemble(const Z80& cpu) {
|
||||
std::string EightBit::Disassembler::disassemble(Z80& cpu) {
|
||||
m_prefixCB = m_prefixDD = m_prefixED = m_prefixFD = false;
|
||||
std::ostringstream output;
|
||||
disassemble(output, cpu, cpu.PC().word);
|
||||
return output.str();
|
||||
}
|
||||
|
||||
void EightBit::Disassembler::disassemble(std::ostringstream& output, const Z80& cpu, uint16_t pc) {
|
||||
void EightBit::Disassembler::disassemble(std::ostringstream& output, Z80& cpu, uint16_t pc) {
|
||||
|
||||
auto& bus = cpu.BUS();
|
||||
auto opcode = bus.peek(pc);
|
||||
@ -423,7 +423,7 @@ void EightBit::Disassembler::disassembleED(
|
||||
|
||||
void EightBit::Disassembler::disassembleOther(
|
||||
std::ostringstream& output,
|
||||
const Z80& cpu,
|
||||
Z80& cpu,
|
||||
uint16_t pc,
|
||||
std::string& specification,
|
||||
int& dumpCount,
|
||||
|
@ -8,34 +8,18 @@ EightBit::Z80::Z80(Bus& bus, InputOutput& ports)
|
||||
m_ports(ports) {
|
||||
}
|
||||
|
||||
EightBit::register16_t EightBit::Z80::AF() const {
|
||||
return m_accumulatorFlags[m_accumulatorFlagsSet];
|
||||
}
|
||||
|
||||
EightBit::register16_t& EightBit::Z80::AF() {
|
||||
return m_accumulatorFlags[m_accumulatorFlagsSet];
|
||||
}
|
||||
|
||||
EightBit::register16_t EightBit::Z80::BC() const {
|
||||
return m_registers[m_registerSet][BC_IDX];
|
||||
}
|
||||
|
||||
EightBit::register16_t& EightBit::Z80::BC() {
|
||||
return m_registers[m_registerSet][BC_IDX];
|
||||
}
|
||||
|
||||
EightBit::register16_t EightBit::Z80::DE() const {
|
||||
return m_registers[m_registerSet][DE_IDX];
|
||||
}
|
||||
|
||||
EightBit::register16_t& EightBit::Z80::DE() {
|
||||
return m_registers[m_registerSet][DE_IDX];
|
||||
}
|
||||
|
||||
EightBit::register16_t EightBit::Z80::HL() const {
|
||||
return m_registers[m_registerSet][HL_IDX];
|
||||
}
|
||||
|
||||
EightBit::register16_t& EightBit::Z80::HL() {
|
||||
return m_registers[m_registerSet][HL_IDX];
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ void Board::Cpu_ExecutingInstruction_Cpm(const EightBit::Z80& cpu) {
|
||||
}
|
||||
}
|
||||
|
||||
void Board::bdos() const {
|
||||
void Board::bdos() {
|
||||
switch (CPU().C()) {
|
||||
case 0x2:
|
||||
std::cout << CPU().E();
|
||||
@ -73,7 +73,7 @@ void Board::Cpu_ExecutingInstruction_Profile(const EightBit::Z80& cpu) {
|
||||
m_profiler.addInstruction(peek(pc.word));
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutingInstruction_Debug(const EightBit::Z80& cpu) {
|
||||
void Board::Cpu_ExecutingInstruction_Debug(EightBit::Z80& cpu) {
|
||||
|
||||
std::cerr
|
||||
<< EightBit::Disassembler::state(cpu)
|
||||
|
@ -22,11 +22,7 @@ public:
|
||||
void initialise();
|
||||
|
||||
protected:
|
||||
virtual uint8_t& reference(uint16_t address) {
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
virtual uint8_t reference(uint16_t address) const {
|
||||
virtual uint8_t& reference(uint16_t address) final {
|
||||
return m_ram.reference(address);
|
||||
}
|
||||
|
||||
@ -40,8 +36,8 @@ private:
|
||||
|
||||
void Cpu_ExecutingInstruction_Cpm(const EightBit::Z80& cpu);
|
||||
|
||||
void Cpu_ExecutingInstruction_Debug(const EightBit::Z80& cpu);
|
||||
void Cpu_ExecutingInstruction_Debug(EightBit::Z80& cpu);
|
||||
void Cpu_ExecutingInstruction_Profile(const EightBit::Z80& cpu);
|
||||
|
||||
void bdos() const;
|
||||
void bdos();
|
||||
};
|
||||
|
@ -22,12 +22,12 @@ namespace EightBit {
|
||||
uint8_t& DATA() { return m_data; }
|
||||
uint8_t DATA() const { return m_data; }
|
||||
|
||||
uint8_t peek() const;
|
||||
uint8_t peek(uint16_t address) const;
|
||||
uint8_t peek();
|
||||
uint8_t peek(uint16_t address);
|
||||
void poke(uint8_t value);
|
||||
void poke(uint16_t address, uint8_t value);
|
||||
|
||||
uint16_t peekWord(uint16_t address) const;
|
||||
uint16_t peekWord(uint16_t address);
|
||||
|
||||
uint8_t read();
|
||||
template<class T> uint8_t read(const T address) {
|
||||
@ -44,10 +44,7 @@ namespace EightBit {
|
||||
|
||||
protected:
|
||||
virtual uint8_t& reference(uint16_t address) = 0;
|
||||
virtual uint8_t reference(uint16_t address) const = 0;
|
||||
|
||||
uint8_t& reference();
|
||||
uint8_t reference() const;
|
||||
|
||||
private:
|
||||
uint8_t m_data = 0xff;
|
||||
|
@ -37,38 +37,24 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
register16_t& MEMPTR() { return m_memptr; }
|
||||
register16_t MEMPTR() const { return m_memptr; }
|
||||
|
||||
register16_t& SP() { return m_sp; }
|
||||
register16_t SP() const { return m_sp; }
|
||||
|
||||
virtual register16_t& AF() = 0;
|
||||
virtual register16_t AF() const = 0;
|
||||
uint8_t& A() { return AF().high; }
|
||||
uint8_t A() const { return AF().high; }
|
||||
uint8_t& F() { return AF().low; }
|
||||
uint8_t F() const { return AF().low; }
|
||||
|
||||
virtual register16_t& BC() = 0;
|
||||
virtual register16_t BC() const = 0;
|
||||
uint8_t& B() { return BC().high; }
|
||||
uint8_t B() const { return BC().high; }
|
||||
uint8_t& C() { return BC().low; }
|
||||
uint8_t C() const { return BC().low; }
|
||||
|
||||
virtual register16_t& DE() = 0;
|
||||
virtual register16_t DE() const = 0;
|
||||
uint8_t& D() { return DE().high; }
|
||||
uint8_t D() const { return DE().high; }
|
||||
uint8_t& E() { return DE().low; }
|
||||
uint8_t E() const { return DE().low; }
|
||||
|
||||
virtual register16_t& HL() = 0;
|
||||
virtual register16_t HL() const = 0;
|
||||
uint8_t& H() { return HL().high; }
|
||||
uint8_t H() const { return HL().high; }
|
||||
uint8_t& L() { return HL().low; }
|
||||
uint8_t L() const { return HL().low; }
|
||||
|
||||
protected:
|
||||
IntelProcessor(Bus& bus);
|
||||
|
@ -34,13 +34,12 @@ namespace EightBit {
|
||||
return limit;
|
||||
}
|
||||
|
||||
uint8_t peek(const uint16_t address) const {
|
||||
uint8_t peek(const uint16_t address) {
|
||||
return BYTES()[address];
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<uint8_t>& BYTES() { return m_bytes; }
|
||||
const std::vector<uint8_t>& BYTES() const { return m_bytes; }
|
||||
|
||||
void poke(const uint16_t address, const uint8_t value) {
|
||||
BYTES()[address] = value;
|
||||
|
@ -14,10 +14,6 @@ namespace EightBit {
|
||||
return BYTES()[address];
|
||||
}
|
||||
|
||||
uint8_t reference(uint16_t address) const {
|
||||
return peek(address);
|
||||
}
|
||||
|
||||
void poke(uint16_t address, uint8_t value) {
|
||||
Memory::poke(address, value);
|
||||
}
|
||||
|
@ -9,9 +9,5 @@ namespace EightBit {
|
||||
Rom(const size_t size = 0)
|
||||
: Memory(size) {
|
||||
}
|
||||
|
||||
uint8_t reference(uint16_t address) const {
|
||||
return peek(address);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
namespace EightBit {
|
||||
template<class T> class Signal final {
|
||||
private:
|
||||
typedef std::function<void(const T&)> delegate_t;
|
||||
typedef std::function<void(T&)> delegate_t;
|
||||
typedef std::vector<delegate_t> delegates_t;
|
||||
|
||||
delegates_t m_delegates;
|
||||
@ -16,7 +16,7 @@ namespace EightBit {
|
||||
m_delegates.push_back(functor);
|
||||
}
|
||||
|
||||
void fire(const T& e) const {
|
||||
void fire(T& e) const {
|
||||
for (auto& delegate : m_delegates)
|
||||
delegate(e);
|
||||
}
|
||||
|
10
src/Bus.cpp
10
src/Bus.cpp
@ -1,11 +1,11 @@
|
||||
#include "stdafx.h"
|
||||
#include "Bus.h"
|
||||
|
||||
uint8_t EightBit::Bus::peek() const {
|
||||
uint8_t EightBit::Bus::peek() {
|
||||
return reference();
|
||||
}
|
||||
|
||||
uint8_t EightBit::Bus::peek(const uint16_t address) const {
|
||||
uint8_t EightBit::Bus::peek(const uint16_t address) {
|
||||
return reference(address);
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ void EightBit::Bus::poke(const uint16_t address, const uint8_t value) {
|
||||
reference(address) = value;
|
||||
}
|
||||
|
||||
uint16_t EightBit::Bus::peekWord(const uint16_t address) const {
|
||||
uint16_t EightBit::Bus::peekWord(const uint16_t address) {
|
||||
const auto low = peek(address);
|
||||
const auto high = peek(address + 1);
|
||||
return register16_t(low, high).word;
|
||||
@ -41,10 +41,6 @@ void EightBit::Bus::write(const uint8_t value) {
|
||||
write();
|
||||
}
|
||||
|
||||
uint8_t EightBit::Bus::reference() const {
|
||||
return reference(ADDRESS().word);
|
||||
}
|
||||
|
||||
uint8_t& EightBit::Bus::reference() {
|
||||
return reference(ADDRESS().word);
|
||||
}
|
||||
|
@ -14,18 +14,18 @@ void EightBit::InputOutput::writeOutputPort(const uint8_t port, const uint8_t va
|
||||
OnWrittenPort(port);
|
||||
}
|
||||
|
||||
void EightBit::InputOutput::OnReadingPort(const uint8_t port) {
|
||||
void EightBit::InputOutput::OnReadingPort(uint8_t port) {
|
||||
ReadingPort.fire(port);
|
||||
}
|
||||
|
||||
void EightBit::InputOutput::OnReadPort(const uint8_t port) {
|
||||
void EightBit::InputOutput::OnReadPort(uint8_t port) {
|
||||
ReadPort.fire(port);
|
||||
}
|
||||
|
||||
void EightBit::InputOutput::OnWritingPort(const uint8_t port) {
|
||||
void EightBit::InputOutput::OnWritingPort(uint8_t port) {
|
||||
WritingPort.fire(port);
|
||||
}
|
||||
|
||||
void EightBit::InputOutput::OnWrittenPort(const uint8_t port) {
|
||||
void EightBit::InputOutput::OnWrittenPort(uint8_t port) {
|
||||
WrittenPort.fire(port);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user