From c472d70c5cd40a5e723c31b7c05f71d078be58bf Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Thu, 7 Sep 2017 00:58:56 +0100 Subject: [PATCH] Ensure the MOS6502 unit tests run successfully to completion. Signed-off-by: Adrian.Conlon --- M6502/inc/Disassembly.h | 2 +- M6502/inc/mos6502.h | 20 ++++++++++---------- M6502/src/Disassembly.cpp | 8 ++++---- M6502/src/mos6502.cpp | 10 +++++----- M6502/test_M6502/Board.cpp | 24 +++++++++++------------- M6502/test_M6502/Board.h | 27 +++++++++++++++++---------- 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/M6502/inc/Disassembly.h b/M6502/inc/Disassembly.h index 02b4722..5180be7 100644 --- a/M6502/inc/Disassembly.h +++ b/M6502/inc/Disassembly.h @@ -72,7 +72,7 @@ namespace EightBit { } std::string AM_Absolute() const { - return "$" + dump_WordValue(processor.getMemory().peekWord(m_address + 1)); + return "$" + dump_WordValue(processor.BUS().peekWord(m_address + 1)); } std::string AM_ZeroPage_dump() const { diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index c962863..b1980b5 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -6,9 +6,9 @@ #include #include -#include "Memory.h" -#include "Processor.h" -#include "Signal.h" +#include +#include +#include namespace EightBit { class MOS6502 : public Processor { @@ -41,7 +41,7 @@ namespace EightBit { CF = Bit0, // Carry }; - MOS6502(Memory& memory); + MOS6502(Bus& bus); Signal ExecutingInstruction; Signal ExecutedInstruction; @@ -156,16 +156,16 @@ namespace EightBit { uint8_t AM_AbsoluteX() { Address_AbsoluteX(); - m_memory.ADDRESS() = MEMPTR(); - if (m_memory.ADDRESS().low == Mask8) + BUS().ADDRESS() = MEMPTR(); + if (BUS().ADDRESS().low == Mask8) ++cycles; return getByte(); } uint8_t AM_AbsoluteY() { Address_AbsoluteY(); - m_memory.ADDRESS() = MEMPTR(); - if (m_memory.ADDRESS().low == Mask8) + BUS().ADDRESS() = MEMPTR(); + if (BUS().ADDRESS().low == Mask8) ++cycles; return getByte(); } @@ -187,8 +187,8 @@ namespace EightBit { uint8_t AM_IndirectIndexedY() { Address_IndirectIndexedY(); - m_memory.ADDRESS() = MEMPTR(); - if (m_memory.ADDRESS().low == Mask8) + BUS().ADDRESS() = MEMPTR(); + if (BUS().ADDRESS().low == Mask8) ++cycles; return getByte(); } diff --git a/M6502/src/Disassembly.cpp b/M6502/src/Disassembly.cpp index edb1654..6eb8a4f 100644 --- a/M6502/src/Disassembly.cpp +++ b/M6502/src/Disassembly.cpp @@ -43,13 +43,13 @@ std::string EightBit::Disassembly::disassemble(uint16_t current) const { std::ostringstream output; - auto memory = processor.getMemory(); + auto& bus = processor.BUS(); - auto cell = memory.peek(current); + auto cell = bus.peek(current); output << dump_ByteValue(cell); - auto byte = memory.peek(current + 1); + auto byte = bus.peek(current + 1); uint16_t relative = processor.PC().word + 2 + (int8_t)byte; auto aaa = (cell & 0b11100000) >> 5; @@ -322,7 +322,7 @@ std::string EightBit::Disassembly::disassemble(uint16_t current) const { //// uint8_t EightBit::Disassembly::getByte(uint16_t address) const { - return processor.getMemory().peek(address); + return processor.BUS().peek(address); } //// diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 7bbdc41..6fb8529 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" #include "mos6502.h" -EightBit::MOS6502::MOS6502(Memory& memory) -: Processor(memory) { +EightBit::MOS6502::MOS6502(Bus& bus) +: Processor(bus) { m_timings = { //// 0 1 2 3 4 5 6 7 8 9 A B C D E F /* 0 */ 7, 6, 0, 0, 0, 4, 5, 0, 3, 2, 2, 0, 0, 4, 6, 0, @@ -60,17 +60,17 @@ void EightBit::MOS6502::triggerNMI() { void EightBit::MOS6502::getWord(register16_t& output) { output.low = getByte(); - m_memory.ADDRESS().word++; + BUS().ADDRESS().word++; output.high = getByte(); } void EightBit::MOS6502::getWord(uint16_t offset, register16_t& output) { - m_memory.ADDRESS().word = offset; + BUS().ADDRESS().word = offset; getWord(output); } void EightBit::MOS6502::getWord(const register16_t& offset, register16_t& output) { - m_memory.ADDRESS() = offset; + BUS().ADDRESS() = offset; getWord(output); } diff --git a/M6502/test_M6502/Board.cpp b/M6502/test_M6502/Board.cpp index e1edb0a..cf1e880 100644 --- a/M6502/test_M6502/Board.cpp +++ b/M6502/test_M6502/Board.cpp @@ -9,8 +9,8 @@ Board::Board(const Configuration& configuration) : m_configuration(configuration), - m_memory(0xffff), - m_cpu(EightBit::MOS6502(m_memory)), + m_ram(0x10000), + m_cpu(EightBit::MOS6502(*this)), m_symbols(""), m_disassembler(m_cpu, m_symbols), m_profiler(m_cpu, m_disassembler, m_symbols), @@ -20,18 +20,16 @@ Board::Board(const Configuration& configuration) void Board::initialise() { - m_memory.clear(); - auto programFilename = m_configuration.getProgram(); auto programPath = m_configuration.getRomDirectory() + "\\" + m_configuration.getProgram(); auto loadAddress = m_configuration.getLoadAddress(); switch (m_configuration.getLoadMethod()) { case Configuration::LoadMethod::Ram: - m_memory.loadRam(programPath, loadAddress); + m_ram.load(programPath, loadAddress); break; case Configuration::LoadMethod::Rom: - m_memory.loadRom(programPath, loadAddress); + // m_rom.load(programPath, loadAddress); break; } @@ -54,12 +52,12 @@ void Board::initialise() { } if (m_configuration.allowInput()) { - m_memory.ReadByte.connect(std::bind(&Board::Memory_ReadByte_Input, this, std::placeholders::_1)); + ReadByte.connect(std::bind(&Board::Memory_ReadByte_Input, this, std::placeholders::_1)); m_cpu.ExecutedInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Poll, this, std::placeholders::_1)); } if (m_configuration.allowOutput()) - m_memory.WrittenByte.connect(std::bind(&Board::Memory_WrittenByte_Output, this, std::placeholders::_1)); + WrittenByte.connect(std::bind(&Board::Memory_WrittenByte_Output, this, std::placeholders::_1)); m_pollCounter = 0; m_pollInterval = m_configuration.getPollInterval(); @@ -81,7 +79,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_memory.peek(0x0200); + auto test = peek(0x0200); std::cout << std::endl << "** Test=" << std::hex << (int)test; } else { m_oldPC = pc; @@ -91,7 +89,7 @@ void Board::Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu) { void Board::Cpu_ExecutingInstruction_Debug(const EightBit::MOS6502& cpu) { auto address = m_cpu.PC().word; - auto cell = m_memory.peek(address); + auto cell = peek(address); std::cout << std::hex; std::cout << "PC=" << std::setw(4) << std::setfill('0') << address << ":"; @@ -112,8 +110,8 @@ void Board::Memory_ReadByte_Input(const EightBit::AddressEventArgs& e) { if (address == m_configuration.getInputAddress()) { auto cell = e.getCell(); if (cell != 0) { - assert(address == m_memory.ADDRESS().word); - m_memory.write(0); + assert(address == ADDRESS().word); + write(0); } } } @@ -133,5 +131,5 @@ void Board::Cpu_ExecutedInstruction_Poll(const EightBit::MOS6502& cpu) { void Board::pollKeyboard() { if (_kbhit()) - m_memory.poke(m_configuration.getInputAddress(), _getch()); + poke(m_configuration.getInputAddress(), _getch()); } \ No newline at end of file diff --git a/M6502/test_M6502/Board.h b/M6502/test_M6502/Board.h index ab8510e..aa31876 100644 --- a/M6502/test_M6502/Board.h +++ b/M6502/test_M6502/Board.h @@ -1,27 +1,34 @@ #pragma once +#include "Configuration.h" + #include -#include "Memory.h" -#include "Configuration.h" -#include "Profiler.h" -#include "EventArgs.h" -#include "Disassembly.h" -#include "mos6502.h" -#include "Symbols.h" +#include +#include +#include +#include +#include +#include +#include -class Board { +class Board : public EightBit::Bus { public: Board(const Configuration& configuration); - EightBit::Memory& Memory() { return m_memory; } EightBit::MOS6502& CPU() { return m_cpu; } void initialise(); +protected: + virtual uint8_t& reference(uint16_t address, bool& rom) { + rom = false; + return m_ram.reference(address); + } + private: const Configuration& m_configuration; - EightBit::Memory m_memory; + EightBit::Ram m_ram; EightBit::MOS6502 m_cpu; EightBit::Symbols m_symbols; EightBit::Disassembly m_disassembler;