diff --git a/EightBit.sln b/EightBit.sln index d9fc117..d9a756c 100644 --- a/EightBit.sln +++ b/EightBit.sln @@ -27,7 +27,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_M6502", "M6502\test\te EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MC6809", "MC6809\src\MC6809.vcxproj", "{09C1B50E-408E-48B1-A616-8400904B5829}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_MC6809", "MC6809\test\test_MC6809.vcxproj", "{80412055-64FB-417B-B017-EBF92770C922}" +EndProject Global + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 @@ -131,6 +136,14 @@ Global {09C1B50E-408E-48B1-A616-8400904B5829}.Release|x64.Build.0 = Release|x64 {09C1B50E-408E-48B1-A616-8400904B5829}.Release|x86.ActiveCfg = Release|Win32 {09C1B50E-408E-48B1-A616-8400904B5829}.Release|x86.Build.0 = Release|Win32 + {80412055-64FB-417B-B017-EBF92770C922}.Debug|x64.ActiveCfg = Debug|x64 + {80412055-64FB-417B-B017-EBF92770C922}.Debug|x64.Build.0 = Debug|x64 + {80412055-64FB-417B-B017-EBF92770C922}.Debug|x86.ActiveCfg = Debug|Win32 + {80412055-64FB-417B-B017-EBF92770C922}.Debug|x86.Build.0 = Debug|Win32 + {80412055-64FB-417B-B017-EBF92770C922}.Release|x64.ActiveCfg = Release|x64 + {80412055-64FB-417B-B017-EBF92770C922}.Release|x64.Build.0 = Release|x64 + {80412055-64FB-417B-B017-EBF92770C922}.Release|x86.ActiveCfg = Release|Win32 + {80412055-64FB-417B-B017-EBF92770C922}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MC6809/test/Board.cpp b/MC6809/test/Board.cpp new file mode 100644 index 0000000..04fca25 --- /dev/null +++ b/MC6809/test/Board.cpp @@ -0,0 +1,80 @@ +#include "stdafx.h" +#include "Board.h" + +#include +#include +#include +#include + +Board::Board(const Configuration& configuration) +: m_configuration(configuration), + m_cpu(EightBit::mc6809(*this)), + m_disassembler(m_cpu) {} + +void Board::initialise() { + + const auto directory = m_configuration.getRomDirectory() + "\\"; + + m_extendedBasic.load(directory + "extbas11.rom"); + m_colorBasic.load(directory + "bas12.rom"); + m_diskBasic.load(directory + "disk11.rom"); + + if (m_configuration.isDebugMode()) { + CPU().ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1)); + } + + CPU().powerOn(); + CPU().reset(); +} + +void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809& cpu) { + + auto address = cpu.PC().word; + auto cell = peek(address); + + std::cout << std::hex; + std::cout << "PC=" << std::setw(4) << std::setfill('0') << address << ":"; + std::cout << "CC=" << m_disassembler.dump_Flags(CPU().CC()) << ", "; + std::cout << "D=" << (int)CPU().D().word << ", "; + std::cout << "X=" << (int)CPU().X().word << ", "; + std::cout << "Y=" << (int)CPU().Y().word << ", "; + std::cout << "U=" << (int)CPU().U().word << ","; + std::cout << "S=" << (int)CPU().S().word << ", "; + std::cout << std::setw(2) << std::setfill('0'); + std::cout << "DP=" << (int)CPU().DP() << "\t"; + + std::cout << m_disassembler.disassemble(address); + + std::cout << "\n"; +} + +uint8_t& Board::reference(uint16_t address) { + + // 0x0000 - 0x7fff + if (address < 0x8000) + return m_ram.reference(address); + + // 0x8000 - 0x9fff + if (address < 0xa000) + return DATA() = m_extendedBasic.peek(address - 0x8000); + + // 0xa000 - 0xbfff + if (address < 0xc000) + return DATA() = m_colorBasic.peek(address - 0xa000); + + // 0xc000 - 0xdfff + if (address < 0xe000) + return DATA() = m_diskBasic.peek(address - 0xc000); + + // 0xe000 - 0xfeff + if (address < 0xff00) + return DATA() = 0xff; + + // 0xe000 - 0xfeff + if (address < 0xfff0) + return m_io.reference(address - 0xff00); + + // 0xfff0 - 0xffff + const auto offset = address - 0xfff0; + return DATA() = m_colorBasic.peek(0x1ff0 + offset); +} diff --git a/MC6809/test/Board.h b/MC6809/test/Board.h new file mode 100644 index 0000000..3d0bb9d --- /dev/null +++ b/MC6809/test/Board.h @@ -0,0 +1,39 @@ +#pragma once + +#include "Configuration.h" + +#include + +#include +#include +#include +#include + +class Board : public EightBit::Bus { +public: + Board(const Configuration& configuration); + + EightBit::mc6809& CPU() { return m_cpu; } + + void initialise(); + +protected: + virtual uint8_t& reference(uint16_t address) final; + +private: + const Configuration& m_configuration; + EightBit::Ram m_ram = 0x8000; // 0000 - 7FFF, 32K RAM + EightBit::Rom m_extendedBasic = 0x2000; // 8000 - 9FFF, 8K Extended BASIC ROM + EightBit::Rom m_colorBasic = 0x2000; // A000 - BFFF, 8K Color BASIC ROM + EightBit::Rom m_cartridge = 0x2000; // C000 - DFFF, 8K Cartridge ROM + EightBit::Rom m_diskBasic = 0x2000; // C000 - DFFF, 8K Disk BASIC ROM + // E000 - FEFF, Unused + EightBit::Ram m_io = 0xf0; // FF00 - FFEF, I/O Registers + // FFF0 - FFFF, Interrupt vectors (mapped from BFF0-BFFF) + EightBit::mc6809 m_cpu; + EightBit::Disassembly m_disassembler; + + void pollKeyboard(); + + void Cpu_ExecutingInstruction_Debug(EightBit::mc6809& cpu); +}; diff --git a/MC6809/test/Configuration.h b/MC6809/test/Configuration.h new file mode 100644 index 0000000..23f76c3 --- /dev/null +++ b/MC6809/test/Configuration.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include + +class Configuration { +public: + Configuration() = default; + + bool isDebugMode() const { return m_debugMode; } + void setDebugMode(bool value) { m_debugMode = value; } + + std::string getRomDirectory() const { return m_romDirectory; } + +private: + bool m_debugMode = false; + std::string m_romDirectory = "roms\\coco2h"; +}; diff --git a/MC6809/test/stdafx.cpp b/MC6809/test/stdafx.cpp new file mode 100644 index 0000000..fd4f341 --- /dev/null +++ b/MC6809/test/stdafx.cpp @@ -0,0 +1 @@ +#include "stdafx.h" diff --git a/MC6809/test/stdafx.h b/MC6809/test/stdafx.h new file mode 100644 index 0000000..6024a75 --- /dev/null +++ b/MC6809/test/stdafx.h @@ -0,0 +1,22 @@ +#ifdef _MSC_VER +#pragma once +#endif + +#include + +#include + +#include +#include +#include + +#include + +#ifdef _MSC_VER +#include +#endif + +#include +#include +#include +#include diff --git a/MC6809/test/test.cpp b/MC6809/test/test.cpp new file mode 100644 index 0000000..e9b074c --- /dev/null +++ b/MC6809/test/test.cpp @@ -0,0 +1,22 @@ +#include "stdafx.h" +#include "Configuration.h" +#include "Board.h" + +#include + +#include + +int main(int argc, char* argv[]) { + + Configuration configuration; + +#ifdef _DEBUG + configuration.setDebugMode(true); +#endif + + EightBit::TestHarness harness(configuration); + harness.initialise(); + harness.runLoop(); + + return 0; +} \ No newline at end of file diff --git a/MC6809/test/test_MC6809.vcxproj b/MC6809/test/test_MC6809.vcxproj new file mode 100644 index 0000000..a8b5f4b --- /dev/null +++ b/MC6809/test/test_MC6809.vcxproj @@ -0,0 +1,178 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {80412055-64FB-417B-B017-EBF92770C922} + Win32Proj + testMC6809 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + ..\inc;..\..\inc;C:\Libraries\boost_1_65_1;$(IncludePath) + + + true + ..\inc;..\..\inc;C:\Libraries\boost_1_65_1;$(IncludePath) + + + true + ..\inc;..\..\inc;C:\Libraries\boost_1_65_1;$(IncludePath) + + + false + ..\inc;..\..\inc;C:\Libraries\boost_1_65_1;$(IncludePath) + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + Create + Create + Create + Create + + + + + + {a9c24bd9-0cb4-4c84-b09b-46b815f9da47} + + + {09c1b50e-408e-48b1-a616-8400904b5829} + + + + + + \ No newline at end of file diff --git a/MC6809/test/test_MC6809.vcxproj.filters b/MC6809/test/test_MC6809.vcxproj.filters new file mode 100644 index 0000000..135c7b1 --- /dev/null +++ b/MC6809/test/test_MC6809.vcxproj.filters @@ -0,0 +1,39 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file