mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-03-06 06:30:14 +00:00
Start incorporating CPP core guidelines (as an experiment!)
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
b3114ed520
commit
d010e3ca2f
@ -98,30 +98,30 @@ namespace EightBit {
|
||||
enum { BC_IDX, DE_IDX, HL_IDX };
|
||||
|
||||
std::array<std::array<register16_t, 3>, 2> m_registers;
|
||||
int m_registerSet;
|
||||
int m_registerSet = 0;
|
||||
|
||||
std::array<register16_t, 2> m_accumulatorFlags;
|
||||
int m_accumulatorFlagsSet;
|
||||
int m_accumulatorFlagsSet = 0;
|
||||
|
||||
register16_t m_ix;
|
||||
register16_t m_iy;
|
||||
register16_t m_ix = { 0xff, 0xff };
|
||||
register16_t m_iy = { 0xff, 0xff };
|
||||
|
||||
refresh_t m_refresh;
|
||||
refresh_t m_refresh = 0x7f;
|
||||
|
||||
uint8_t iv;
|
||||
int m_interruptMode;
|
||||
bool m_iff1;
|
||||
bool m_iff2;
|
||||
uint8_t iv = 0xff;
|
||||
int m_interruptMode = 0;
|
||||
bool m_iff1 = false;
|
||||
bool m_iff2 = false;
|
||||
|
||||
bool m1;
|
||||
bool m1 = false;
|
||||
|
||||
bool m_prefixCB;
|
||||
bool m_prefixDD;
|
||||
bool m_prefixED;
|
||||
bool m_prefixFD;
|
||||
bool m_prefixCB = false;
|
||||
bool m_prefixDD = false;
|
||||
bool m_prefixED = false;
|
||||
bool m_prefixFD = false;
|
||||
|
||||
int8_t m_displacement;
|
||||
bool m_displaced;
|
||||
int8_t m_displacement = 0;
|
||||
bool m_displaced = false;
|
||||
|
||||
uint16_t displacedAddress() {
|
||||
assert(m_displaced);
|
||||
|
@ -5,23 +5,7 @@
|
||||
|
||||
EightBit::Z80::Z80(Bus& bus, InputOutput& ports)
|
||||
: IntelProcessor(bus),
|
||||
m_ports(ports),
|
||||
m_registerSet(0),
|
||||
m_accumulatorFlagsSet(0),
|
||||
m_refresh(0x7f),
|
||||
iv(0xff),
|
||||
m_interruptMode(0),
|
||||
m_iff1(false),
|
||||
m_iff2(false),
|
||||
m1(false),
|
||||
m_prefixCB(false),
|
||||
m_prefixDD(false),
|
||||
m_prefixED(false),
|
||||
m_prefixFD(false),
|
||||
m_displacement(0),
|
||||
m_displaced(false) {
|
||||
IX().word = 0xffff;
|
||||
IY().word = 0xffff;
|
||||
m_ports(ports) {
|
||||
}
|
||||
|
||||
EightBit::register16_t& EightBit::Z80::AF() {
|
||||
|
86
inc/Bus.h
86
inc/Bus.h
@ -8,87 +8,37 @@
|
||||
namespace EightBit {
|
||||
class Bus {
|
||||
public:
|
||||
Bus()
|
||||
: m_temporary(0xff), m_data(nullptr) {
|
||||
m_address.word = 0xffff;
|
||||
}
|
||||
virtual ~Bus() = default;
|
||||
|
||||
Signal<uint16_t> WrittenByte;
|
||||
Signal<uint16_t> ReadingByte;
|
||||
|
||||
register16_t& ADDRESS() { return m_address; }
|
||||
uint8_t& DATA() { return *m_data; }
|
||||
register16_t& ADDRESS();
|
||||
uint8_t& DATA();
|
||||
|
||||
uint8_t& placeDATA(uint8_t value) {
|
||||
m_temporary = value;
|
||||
m_data = &m_temporary;
|
||||
return DATA();
|
||||
}
|
||||
uint8_t& placeDATA(uint8_t value);
|
||||
uint8_t& referenceDATA(uint8_t& value);
|
||||
|
||||
uint8_t& referenceDATA(uint8_t& value) {
|
||||
m_data = &value;
|
||||
return DATA();
|
||||
}
|
||||
uint8_t peek(uint16_t address);
|
||||
void poke(uint16_t address, uint8_t value);
|
||||
|
||||
uint8_t peek(uint16_t address) {
|
||||
bool rom;
|
||||
return reference(address, rom);
|
||||
}
|
||||
uint16_t peekWord(uint16_t address);
|
||||
|
||||
void poke(uint16_t address, uint8_t value) {
|
||||
bool rom;
|
||||
reference(address, rom) = value;
|
||||
}
|
||||
uint8_t read();
|
||||
uint8_t read(uint16_t offset);
|
||||
uint8_t read(register16_t address);
|
||||
|
||||
uint16_t peekWord(uint16_t address) {
|
||||
register16_t returned;
|
||||
returned.low = peek(address);
|
||||
returned.high = peek(address + 1);
|
||||
return returned.word;
|
||||
}
|
||||
|
||||
uint8_t read() {
|
||||
ReadingByte.fire(ADDRESS().word);
|
||||
return reference();
|
||||
}
|
||||
|
||||
uint8_t read(uint16_t offset) {
|
||||
ADDRESS().word = offset;
|
||||
return read();
|
||||
}
|
||||
|
||||
uint8_t read(register16_t address) {
|
||||
ADDRESS() = address;
|
||||
return read();
|
||||
}
|
||||
|
||||
void write(uint8_t value) {
|
||||
reference() = value;
|
||||
WrittenByte.fire(ADDRESS().word);
|
||||
}
|
||||
|
||||
void write(uint16_t offset, uint8_t value) {
|
||||
ADDRESS().word = offset;
|
||||
write(value);
|
||||
}
|
||||
|
||||
void write(register16_t address, uint8_t value) {
|
||||
ADDRESS() = address;
|
||||
write(value);
|
||||
}
|
||||
void write(uint8_t value);
|
||||
void write(uint16_t offset, uint8_t value);
|
||||
void write(register16_t address, uint8_t value);
|
||||
|
||||
protected:
|
||||
virtual uint8_t& reference(uint16_t address, bool& rom) = 0;
|
||||
|
||||
uint8_t& reference() {
|
||||
bool rom;
|
||||
auto& value = reference(ADDRESS().word, rom);
|
||||
return rom ? placeDATA(value) : referenceDATA(value);
|
||||
}
|
||||
uint8_t& reference();
|
||||
|
||||
private:
|
||||
uint8_t m_temporary; // Used to simulate ROM
|
||||
register16_t m_address;
|
||||
uint8_t* m_data;
|
||||
uint8_t* m_data = nullptr;
|
||||
register16_t m_address { 0xff, 0xff };
|
||||
uint8_t m_temporary = 0xff; // Used to simulate ROM
|
||||
};
|
||||
}
|
@ -179,6 +179,6 @@ namespace EightBit {
|
||||
|
||||
private:
|
||||
std::array<opcode_decoded_t, 0x100> m_decodedOpcodes;
|
||||
register16_t m_sp;
|
||||
register16_t m_sp = { 0xff, 0xff };
|
||||
};
|
||||
}
|
@ -115,7 +115,7 @@ namespace EightBit {
|
||||
virtual void push(uint8_t value) = 0;
|
||||
virtual uint8_t pop() = 0;
|
||||
|
||||
void pushWord(const register16_t& value) {
|
||||
void pushWord(register16_t value) {
|
||||
push(value.high);
|
||||
push(value.low);
|
||||
}
|
||||
@ -146,10 +146,10 @@ namespace EightBit {
|
||||
|
||||
private:
|
||||
Bus& m_bus;
|
||||
int m_cycles;
|
||||
register16_t m_pc;
|
||||
register16_t m_memptr;
|
||||
bool m_halted;
|
||||
bool m_power;
|
||||
int m_cycles = 0;
|
||||
register16_t m_pc = { 0, 0 };
|
||||
register16_t m_memptr = { 0, 0 };
|
||||
bool m_halted = false;
|
||||
bool m_power = false;
|
||||
};
|
||||
}
|
74
src/Bus.cpp
Normal file
74
src/Bus.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include "stdafx.h"
|
||||
#include "Bus.h"
|
||||
|
||||
EightBit::register16_t& EightBit::Bus::ADDRESS() {
|
||||
return m_address;
|
||||
}
|
||||
|
||||
uint8_t& EightBit::Bus::DATA() {
|
||||
return *m_data;
|
||||
}
|
||||
|
||||
uint8_t& EightBit::Bus::placeDATA(uint8_t value) {
|
||||
m_temporary = value;
|
||||
m_data = &m_temporary;
|
||||
return DATA();
|
||||
}
|
||||
|
||||
uint8_t& EightBit::Bus::referenceDATA(uint8_t& value) {
|
||||
m_data = &value;
|
||||
return DATA();
|
||||
}
|
||||
|
||||
uint8_t EightBit::Bus::peek(uint16_t address) {
|
||||
bool rom;
|
||||
return reference(address, rom);
|
||||
}
|
||||
|
||||
void EightBit::Bus::poke(uint16_t address, uint8_t value) {
|
||||
bool rom;
|
||||
reference(address, rom) = value;
|
||||
}
|
||||
|
||||
uint16_t EightBit::Bus::peekWord(uint16_t address) {
|
||||
register16_t returned;
|
||||
returned.low = peek(address);
|
||||
returned.high = peek(address + 1);
|
||||
return returned.word;
|
||||
}
|
||||
|
||||
uint8_t EightBit::Bus::read() {
|
||||
ReadingByte.fire(ADDRESS().word);
|
||||
return reference();
|
||||
}
|
||||
|
||||
uint8_t EightBit::Bus::read(uint16_t offset) {
|
||||
ADDRESS().word = offset;
|
||||
return read();
|
||||
}
|
||||
|
||||
uint8_t EightBit::Bus::read(register16_t address) {
|
||||
ADDRESS() = address;
|
||||
return read();
|
||||
}
|
||||
|
||||
void EightBit::Bus::write(uint8_t value) {
|
||||
reference() = value;
|
||||
WrittenByte.fire(ADDRESS().word);
|
||||
}
|
||||
|
||||
void EightBit::Bus::write(uint16_t offset, uint8_t value) {
|
||||
ADDRESS().word = offset;
|
||||
write(value);
|
||||
}
|
||||
|
||||
void EightBit::Bus::write(register16_t address, uint8_t value) {
|
||||
ADDRESS() = address;
|
||||
write(value);
|
||||
}
|
||||
|
||||
uint8_t& EightBit::Bus::reference() {
|
||||
bool rom;
|
||||
auto& value = reference(ADDRESS().word, rom);
|
||||
return rom ? placeDATA(value) : referenceDATA(value);
|
||||
}
|
@ -152,6 +152,7 @@
|
||||
<ClInclude Include="stdafx.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Bus.cpp" />
|
||||
<ClCompile Include="EventArgs.cpp" />
|
||||
<ClCompile Include="InputOutput.cpp" />
|
||||
<ClCompile Include="IntelProcessor.cpp" />
|
||||
|
@ -67,5 +67,8 @@
|
||||
<ClCompile Include="InputOutput.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Bus.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -3,7 +3,6 @@
|
||||
|
||||
EightBit::IntelProcessor::IntelProcessor(Bus& bus)
|
||||
: Processor(bus) {
|
||||
SP().word = Mask16;
|
||||
}
|
||||
|
||||
void EightBit::IntelProcessor::initialise() {
|
||||
|
@ -2,11 +2,7 @@
|
||||
#include "Processor.h"
|
||||
|
||||
EightBit::Processor::Processor(Bus& bus)
|
||||
: m_bus(bus),
|
||||
m_cycles(0),
|
||||
m_halted(false),
|
||||
m_power(false) {
|
||||
PC().word = MEMPTR().word = 0;
|
||||
: m_bus(bus) {
|
||||
}
|
||||
|
||||
void EightBit::Processor::reset() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user