mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-04-06 12:37:33 +00:00
Tidy method casing a little.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
da3b966666
commit
13725b7a3c
@ -11,11 +11,11 @@ namespace EightBit {
|
||||
public:
|
||||
Disassembly(MOS6502& processor, const Symbols& symbols);
|
||||
|
||||
std::string Dump_Flags(uint8_t value) const;
|
||||
std::string Dump_ByteValue(uint8_t value) const;
|
||||
std::string Dump_WordValue(uint16_t value) const;
|
||||
std::string dump_Flags(uint8_t value) const;
|
||||
std::string dump_ByteValue(uint8_t value) const;
|
||||
std::string dump_WordValue(uint16_t value) const;
|
||||
|
||||
std::string Disassemble(uint16_t current) const;
|
||||
std::string disassemble(uint16_t current) const;
|
||||
|
||||
private:
|
||||
MOS6502& processor;
|
||||
@ -36,7 +36,7 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
std::string disassemble_Relative(const std::string& instruction, uint16_t address) const {
|
||||
return AM_Immediate_dump() + "\t" + instruction + " $" + Dump_WordValue(address);
|
||||
return AM_Immediate_dump() + "\t" + instruction + " $" + dump_WordValue(address);
|
||||
}
|
||||
|
||||
std::string disassemble_AM_00(int bbb, const std::string& instruction) const {
|
||||
@ -60,7 +60,7 @@ namespace EightBit {
|
||||
#pragma region References
|
||||
|
||||
std::string AM_Immediate_dump() const {
|
||||
return Dump_Byte(m_address + 1);
|
||||
return dump_Byte(m_address + 1);
|
||||
}
|
||||
|
||||
std::string AM_Immediate() const {
|
||||
@ -68,19 +68,19 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
std::string AM_Absolute_dump() const {
|
||||
return Dump_DByte(m_address + 1);
|
||||
return dump_DByte(m_address + 1);
|
||||
}
|
||||
|
||||
std::string AM_Absolute() const {
|
||||
return "$" + Dump_WordValue(processor.getMemory().peekWord(m_address + 1));
|
||||
return "$" + dump_WordValue(processor.getMemory().peekWord(m_address + 1));
|
||||
}
|
||||
|
||||
std::string AM_ZeroPage_dump() const {
|
||||
return Dump_Byte(m_address + 1);
|
||||
return dump_Byte(m_address + 1);
|
||||
}
|
||||
|
||||
std::string AM_ZeroPage() const {
|
||||
return "$" + Dump_Byte(m_address + 1);
|
||||
return "$" + dump_Byte(m_address + 1);
|
||||
}
|
||||
|
||||
std::string AM_ZeroPageX_dump() const {
|
||||
@ -120,7 +120,7 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
std::string AM_IndexedIndirectX() const {
|
||||
return "($" + Dump_Byte(m_address + 1) + ",X)";
|
||||
return "($" + dump_Byte(m_address + 1) + ",X)";
|
||||
}
|
||||
|
||||
std::string AM_IndirectIndexedY_dump() const {
|
||||
@ -128,7 +128,7 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
std::string AM_IndirectIndexedY() const {
|
||||
return "($" + Dump_Byte(m_address + 1) + "),Y";
|
||||
return "($" + dump_Byte(m_address + 1) + "),Y";
|
||||
}
|
||||
|
||||
#pragma endregion References
|
||||
@ -315,14 +315,14 @@ namespace EightBit {
|
||||
|
||||
#pragma endregion 6502 addressing modes
|
||||
|
||||
uint8_t GetByte(uint16_t address) const;
|
||||
uint8_t getByte(uint16_t address) const;
|
||||
|
||||
std::string Dump_Byte(uint16_t address) const;
|
||||
std::string Dump_DByte(uint16_t address) const;
|
||||
std::string dump_Byte(uint16_t address) const;
|
||||
std::string dump_DByte(uint16_t address) const;
|
||||
|
||||
std::string ConvertAddress(uint16_t address) const;
|
||||
std::string ConvertAddress(uint8_t address) const;
|
||||
std::string ConvertConstant(uint16_t constant) const;
|
||||
std::string ConvertConstant(uint8_t constant) const;
|
||||
std::string convertAddress(uint16_t address) const;
|
||||
std::string convertAddress(uint8_t address) const;
|
||||
std::string convertConstant(uint16_t constant) const;
|
||||
std::string convertConstant(uint8_t constant) const;
|
||||
};
|
||||
}
|
@ -56,24 +56,24 @@ namespace EightBit {
|
||||
|
||||
virtual int step();
|
||||
|
||||
virtual void Reset();
|
||||
virtual void reset();
|
||||
|
||||
virtual void TriggerIRQ();
|
||||
virtual void TriggerNMI();
|
||||
virtual void triggerIRQ();
|
||||
virtual void triggerNMI();
|
||||
|
||||
void GetWord(register16_t& output);
|
||||
void GetWord(uint16_t offset, register16_t& output);
|
||||
void getWord(register16_t& output);
|
||||
void getWord(uint16_t offset, register16_t& output);
|
||||
|
||||
uint8_t GetByte() { return m_memory.read(); }
|
||||
uint8_t GetByte(uint16_t offset) { return m_memory.read(offset); }
|
||||
uint8_t getByte() { return m_memory.read(); }
|
||||
uint8_t getByte(uint16_t offset) { return m_memory.read(offset); }
|
||||
|
||||
void SetByte(uint8_t value) { m_memory.write(value); }
|
||||
void SetByte(uint16_t offset, uint8_t value) { m_memory.write(offset, value); }
|
||||
void setByte(uint8_t value) { m_memory.write(value); }
|
||||
void setByte(uint16_t offset, uint8_t value) { m_memory.write(offset, value); }
|
||||
|
||||
protected:
|
||||
virtual void Interrupt(uint16_t vector);
|
||||
virtual void interrupt(uint16_t vector);
|
||||
|
||||
virtual int Execute(uint8_t cell);
|
||||
virtual int execute(uint8_t cell);
|
||||
|
||||
private:
|
||||
register16_t& MEMPTR() { return m_memptr; }
|
||||
@ -86,37 +86,37 @@ namespace EightBit {
|
||||
adjustNegative(datum);
|
||||
}
|
||||
|
||||
void PushByte(uint8_t value);
|
||||
uint8_t PopByte();
|
||||
void PushWord(register16_t value);
|
||||
void PopWord(register16_t& output);
|
||||
void pushByte(uint8_t value);
|
||||
uint8_t popByte();
|
||||
void pushWord(register16_t value);
|
||||
void popWord(register16_t& output);
|
||||
|
||||
uint8_t FetchByte();
|
||||
void FetchWord(register16_t& output);
|
||||
uint8_t fetchByte();
|
||||
void fetchWord(register16_t& output);
|
||||
|
||||
#pragma region 6502 addressing modes
|
||||
|
||||
#pragma region Addresses
|
||||
|
||||
void Address_Absolute() {
|
||||
FetchWord(MEMPTR());
|
||||
fetchWord(MEMPTR());
|
||||
}
|
||||
|
||||
void Address_ZeroPage() {
|
||||
MEMPTR().low = FetchByte();
|
||||
MEMPTR().low = fetchByte();
|
||||
MEMPTR().high = 0;
|
||||
}
|
||||
|
||||
void Address_ZeroPageIndirect() {
|
||||
Address_ZeroPage();
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
GetWord(MEMPTR());
|
||||
getWord(MEMPTR());
|
||||
}
|
||||
|
||||
void Address_Indirect() {
|
||||
Address_Absolute();
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
GetWord(MEMPTR());
|
||||
getWord(MEMPTR());
|
||||
}
|
||||
|
||||
void Address_ZeroPageX() {
|
||||
@ -142,7 +142,7 @@ namespace EightBit {
|
||||
void Address_IndexedIndirectX() {
|
||||
Address_ZeroPageX();
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
GetWord(MEMPTR());
|
||||
getWord(MEMPTR());
|
||||
}
|
||||
|
||||
void Address_IndirectIndexedY() {
|
||||
@ -161,7 +161,7 @@ namespace EightBit {
|
||||
|
||||
uint8_t& AM_Immediate() {
|
||||
m_busRW = false;
|
||||
FetchByte();
|
||||
fetchByte();
|
||||
return m_memory.reference();
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ EightBit::Disassembly::Disassembly(MOS6502& targetProcessor, const Symbols& targ
|
||||
symbols(targetSymbols) {
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembly::Dump_Flags(uint8_t value) const {
|
||||
std::string EightBit::Disassembly::dump_Flags(uint8_t value) const {
|
||||
std::string returned;
|
||||
returned += (value & MOS6502::NF) ? "N" : "-";
|
||||
returned += (value & MOS6502::VF) ? "O" : "-";
|
||||
@ -25,19 +25,19 @@ std::string EightBit::Disassembly::Dump_Flags(uint8_t value) const {
|
||||
return returned;
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembly::Dump_ByteValue(uint8_t value) const {
|
||||
std::string EightBit::Disassembly::dump_ByteValue(uint8_t value) const {
|
||||
std::ostringstream output;
|
||||
output << std::hex << std::setw(2) << std::setfill('0') << (int)value;
|
||||
return output.str();
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembly::Dump_WordValue(uint16_t value) const {
|
||||
std::string EightBit::Disassembly::dump_WordValue(uint16_t value) const {
|
||||
std::ostringstream output;
|
||||
output << std::hex << std::setw(4) << std::setfill('0') << (int)value;
|
||||
return output.str();
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembly::Disassemble(uint16_t current) const {
|
||||
std::string EightBit::Disassembly::disassemble(uint16_t current) const {
|
||||
|
||||
m_address = current;
|
||||
|
||||
@ -47,7 +47,7 @@ std::string EightBit::Disassembly::Disassemble(uint16_t current) const {
|
||||
|
||||
auto cell = memory.peek(current);
|
||||
|
||||
output << Dump_ByteValue(cell);
|
||||
output << dump_ByteValue(cell);
|
||||
|
||||
auto byte = memory.peek(current + 1);
|
||||
uint16_t relative = processor.PC().word + 2 + (int8_t)byte;
|
||||
@ -321,51 +321,51 @@ std::string EightBit::Disassembly::Disassemble(uint16_t current) const {
|
||||
|
||||
////
|
||||
|
||||
uint8_t EightBit::Disassembly::GetByte(uint16_t address) const {
|
||||
uint8_t EightBit::Disassembly::getByte(uint16_t address) const {
|
||||
return processor.getMemory().peek(address);
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
std::string EightBit::Disassembly::Dump_Byte(uint16_t address) const {
|
||||
return Dump_ByteValue(GetByte(address));
|
||||
std::string EightBit::Disassembly::dump_Byte(uint16_t address) const {
|
||||
return dump_ByteValue(getByte(address));
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembly::Dump_DByte(uint16_t address) const {
|
||||
return Dump_Byte(address) + Dump_Byte(address + 1);
|
||||
std::string EightBit::Disassembly::dump_DByte(uint16_t address) const {
|
||||
return dump_Byte(address) + dump_Byte(address + 1);
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
std::string EightBit::Disassembly::ConvertAddress(uint16_t address) const {
|
||||
std::string EightBit::Disassembly::convertAddress(uint16_t address) const {
|
||||
auto label = symbols.getLabels().find(address);
|
||||
if (label != symbols.getLabels().end())
|
||||
return label->second;
|
||||
std::ostringstream output;
|
||||
output << "$" << Dump_WordValue(address);
|
||||
output << "$" << dump_WordValue(address);
|
||||
return output.str();
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembly::ConvertAddress(uint8_t address) const {
|
||||
std::string EightBit::Disassembly::convertAddress(uint8_t address) const {
|
||||
auto label = symbols.getLabels().find(address);
|
||||
if (label != symbols.getLabels().end())
|
||||
return label->second;
|
||||
std::ostringstream output;
|
||||
output << "$" << Dump_ByteValue(address);
|
||||
output << "$" << dump_ByteValue(address);
|
||||
return output.str();
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembly::ConvertConstant(uint16_t constant) const {
|
||||
std::string EightBit::Disassembly::convertConstant(uint16_t constant) const {
|
||||
auto label = symbols.getConstants().find(constant);
|
||||
if (label != symbols.getConstants().end())
|
||||
return label->second;
|
||||
return Dump_DByte(constant);
|
||||
return dump_DByte(constant);
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembly::ConvertConstant(uint8_t constant) const {
|
||||
std::string EightBit::Disassembly::convertConstant(uint8_t constant) const {
|
||||
auto label = symbols.getConstants().find(constant);
|
||||
if (label != symbols.getConstants().end())
|
||||
return label->second;
|
||||
return Dump_ByteValue(constant);
|
||||
return dump_ByteValue(constant);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ void EightBit::Profiler::EmitProfileInformation() {
|
||||
auto cycles = addressProfiles[address];
|
||||
if (cycles > 0) {
|
||||
// Dump a profile/disassembly line
|
||||
auto source = disassembler.Disassemble(address);
|
||||
auto source = disassembler.disassemble(address);
|
||||
EmitLine.fire(ProfileLineEventArgs(source, cycles));
|
||||
}
|
||||
}
|
||||
|
@ -50,42 +50,42 @@ void EightBit::MOS6502::initialise() {
|
||||
|
||||
int EightBit::MOS6502::step() {
|
||||
ExecutingInstruction.fire(*this);
|
||||
auto returned = Execute(FetchByte());
|
||||
auto returned = execute(fetchByte());
|
||||
ExecutedInstruction.fire(*this);
|
||||
return returned;
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::Reset() {
|
||||
GetWord(RSTvector, PC());
|
||||
void EightBit::MOS6502::reset() {
|
||||
getWord(RSTvector, PC());
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::TriggerIRQ() {
|
||||
Interrupt(IRQvector);
|
||||
void EightBit::MOS6502::triggerIRQ() {
|
||||
interrupt(IRQvector);
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::TriggerNMI() {
|
||||
Interrupt(NMIvector);
|
||||
void EightBit::MOS6502::triggerNMI() {
|
||||
interrupt(NMIvector);
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::GetWord(register16_t& output) {
|
||||
output.low = GetByte();
|
||||
void EightBit::MOS6502::getWord(register16_t& output) {
|
||||
output.low = getByte();
|
||||
m_memory.ADDRESS().word++;
|
||||
output.high = GetByte();
|
||||
output.high = getByte();
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::GetWord(uint16_t offset, register16_t& output) {
|
||||
void EightBit::MOS6502::getWord(uint16_t offset, register16_t& output) {
|
||||
m_memory.ADDRESS().word = offset;
|
||||
GetWord(output);
|
||||
getWord(output);
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::Interrupt(uint16_t vector) {
|
||||
PushWord(PC());
|
||||
PushByte(P());
|
||||
void EightBit::MOS6502::interrupt(uint16_t vector) {
|
||||
pushWord(PC());
|
||||
pushByte(P());
|
||||
setFlag(P(), IF);
|
||||
GetWord(vector, PC());
|
||||
getWord(vector, PC());
|
||||
}
|
||||
|
||||
int EightBit::MOS6502::Execute(uint8_t cell) {
|
||||
int EightBit::MOS6502::execute(uint8_t cell) {
|
||||
|
||||
cycles = m_timings[cell];
|
||||
|
||||
@ -146,7 +146,7 @@ int EightBit::MOS6502::Execute(uint8_t cell) {
|
||||
RTI();
|
||||
break;
|
||||
case 0b010: // PHA
|
||||
PushByte(A());
|
||||
pushByte(A());
|
||||
break;
|
||||
case 0b011: // JMP
|
||||
JMP_abs();
|
||||
@ -167,7 +167,7 @@ int EightBit::MOS6502::Execute(uint8_t cell) {
|
||||
RTS();
|
||||
break;
|
||||
case 0b010: // PLA
|
||||
adjustNZ(A() = PopByte());
|
||||
adjustNZ(A() = popByte());
|
||||
break;
|
||||
case 0b011: // JMP (abs)
|
||||
JMP_ind();
|
||||
@ -389,32 +389,32 @@ int EightBit::MOS6502::Execute(uint8_t cell) {
|
||||
|
||||
////
|
||||
|
||||
void EightBit::MOS6502::PushByte(uint8_t value) {
|
||||
SetByte(PageOne + S()--, value);
|
||||
void EightBit::MOS6502::pushByte(uint8_t value) {
|
||||
setByte(PageOne + S()--, value);
|
||||
}
|
||||
|
||||
uint8_t EightBit::MOS6502::PopByte() {
|
||||
return GetByte(PageOne + ++S());
|
||||
uint8_t EightBit::MOS6502::popByte() {
|
||||
return getByte(PageOne + ++S());
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::PushWord(register16_t value) {
|
||||
PushByte(value.high);
|
||||
PushByte(value.low);
|
||||
void EightBit::MOS6502::pushWord(register16_t value) {
|
||||
pushByte(value.high);
|
||||
pushByte(value.low);
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::PopWord(register16_t& output) {
|
||||
output.low = PopByte();
|
||||
output.high = PopByte();
|
||||
void EightBit::MOS6502::popWord(register16_t& output) {
|
||||
output.low = popByte();
|
||||
output.high = popByte();
|
||||
}
|
||||
|
||||
uint8_t EightBit::MOS6502::FetchByte() {
|
||||
uint8_t EightBit::MOS6502::fetchByte() {
|
||||
m_memory.ADDRESS().word = PC().word++;
|
||||
return GetByte();
|
||||
return getByte();
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::FetchWord(register16_t& output) {
|
||||
void EightBit::MOS6502::fetchWord(register16_t& output) {
|
||||
m_memory.ADDRESS().word = PC().word++;
|
||||
GetWord(output);
|
||||
getWord(output);
|
||||
PC().word++;
|
||||
}
|
||||
|
||||
@ -561,11 +561,11 @@ void EightBit::MOS6502::Branch(bool flag) {
|
||||
|
||||
void EightBit::MOS6502::PHP() {
|
||||
setFlag(P(), BF);
|
||||
PushByte(P());
|
||||
pushByte(P());
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::PLP() {
|
||||
P() = PopByte();
|
||||
P() = popByte();
|
||||
setFlag(P(), RF);
|
||||
}
|
||||
|
||||
@ -574,17 +574,17 @@ void EightBit::MOS6502::PLP() {
|
||||
void EightBit::MOS6502::JSR_abs() {
|
||||
Address_Absolute();
|
||||
PC().word--;
|
||||
PushWord(PC());
|
||||
pushWord(PC());
|
||||
PC() = MEMPTR();
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::RTI() {
|
||||
PLP();
|
||||
PopWord(PC());
|
||||
popWord(PC());
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::RTS() {
|
||||
PopWord(PC());
|
||||
popWord(PC());
|
||||
PC().word++;
|
||||
}
|
||||
|
||||
@ -600,8 +600,8 @@ void EightBit::MOS6502::JMP_ind() {
|
||||
|
||||
void EightBit::MOS6502::BRK() {
|
||||
PC().word++;
|
||||
PushWord(PC());
|
||||
pushWord(PC());
|
||||
PHP();
|
||||
setFlag(P(), IF);
|
||||
GetWord(IRQvector, PC());
|
||||
getWord(IRQvector, PC());
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ void Board::Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu) {
|
||||
auto pc = m_cpu.PC().word;
|
||||
if (m_oldPC == pc) {
|
||||
m_cpu.halt();
|
||||
auto test = m_cpu.GetByte(0x0200);
|
||||
auto test = m_memory.peek(0x0200);
|
||||
std::cout << std::endl << "** Test=" << std::hex << (int)test;
|
||||
} else {
|
||||
m_oldPC = pc;
|
||||
@ -96,14 +96,14 @@ void Board::Cpu_ExecutingInstruction_Debug(const EightBit::MOS6502& cpu) {
|
||||
|
||||
std::cout << std::hex;
|
||||
std::cout << "PC=" << std::setw(4) << std::setfill('0') << address << ":";
|
||||
std::cout << "P=" << m_disassembler.Dump_Flags(m_cpu.P()) << ", ";
|
||||
std::cout << "P=" << m_disassembler.dump_Flags(m_cpu.P()) << ", ";
|
||||
std::cout << std::setw(2) << std::setfill('0');
|
||||
std::cout << "A=" << (int)m_cpu.A() << ", ";
|
||||
std::cout << "X=" << (int)m_cpu.X() << ", ";
|
||||
std::cout << "Y=" << (int)m_cpu.Y() << ", ";
|
||||
std::cout << "S=" << (int)m_cpu.S() << "\t";
|
||||
|
||||
std::cout << m_disassembler.Disassemble(address);
|
||||
std::cout << m_disassembler.disassemble(address);
|
||||
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user