From fe05d468d62e040b68ca3ef8cf3c060db6f1aa45 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 6 Oct 2018 23:52:39 +0100 Subject: [PATCH] Start adding MC6809 unit tests for each instruction. Just ABX, so far Signed-off-by: Adrian Conlon --- .gitmodules | 3 + EightBit.sln | 10 + MC6809/unittest/Board.cpp | 17 ++ MC6809/unittest/Board.h | 21 ++ MC6809/unittest/mc6809_tests.cpp | 54 +++++ MC6809/unittest/pch.cpp | Bin 0 -> 430 bytes MC6809/unittest/pch.h | Bin 0 -> 128 bytes MC6809/unittest/unittest_MC6809.cpp | Bin 0 -> 244 bytes MC6809/unittest/unittest_MC6809.vcxproj | 213 ++++++++++++++++++ .../unittest/unittest_MC6809.vcxproj.filters | 35 +++ modules/catch2 | 1 + 11 files changed, 354 insertions(+) create mode 100644 .gitmodules create mode 100644 MC6809/unittest/Board.cpp create mode 100644 MC6809/unittest/Board.h create mode 100644 MC6809/unittest/mc6809_tests.cpp create mode 100644 MC6809/unittest/pch.cpp create mode 100644 MC6809/unittest/pch.h create mode 100644 MC6809/unittest/unittest_MC6809.cpp create mode 100644 MC6809/unittest/unittest_MC6809.vcxproj create mode 100644 MC6809/unittest/unittest_MC6809.vcxproj.filters create mode 160000 modules/catch2 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..40f0bdd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "modules/catch2"] + path = modules/catch2 + url = https://github.com/catchorg/Catch2.git diff --git a/EightBit.sln b/EightBit.sln index 79643c4..03f8c06 100644 --- a/EightBit.sln +++ b/EightBit.sln @@ -31,6 +31,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_MC6809", "MC6809\test\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MC6850", "MC6850\src\MC6850.vcxproj", "{A4ADA650-55C3-4C00-8DAD-E4E4AFF86EFF}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unittest_MC6809", "MC6809\unittest\unittest_MC6809.vcxproj", "{9EFEA22E-E981-4342-BE17-7DD0F33F1F52}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -151,6 +153,14 @@ Global {A4ADA650-55C3-4C00-8DAD-E4E4AFF86EFF}.Release|x64.Build.0 = Release|x64 {A4ADA650-55C3-4C00-8DAD-E4E4AFF86EFF}.Release|x86.ActiveCfg = Release|Win32 {A4ADA650-55C3-4C00-8DAD-E4E4AFF86EFF}.Release|x86.Build.0 = Release|Win32 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52}.Debug|x64.ActiveCfg = Debug|x64 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52}.Debug|x64.Build.0 = Debug|x64 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52}.Debug|x86.ActiveCfg = Debug|Win32 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52}.Debug|x86.Build.0 = Debug|Win32 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52}.Release|x64.ActiveCfg = Release|x64 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52}.Release|x64.Build.0 = Release|x64 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52}.Release|x86.ActiveCfg = Release|Win32 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MC6809/unittest/Board.cpp b/MC6809/unittest/Board.cpp new file mode 100644 index 0000000..bd814cd --- /dev/null +++ b/MC6809/unittest/Board.cpp @@ -0,0 +1,17 @@ +#include "pch.h" +#include "Board.h" + +Board::Board() +: m_cpu(EightBit::mc6809(*this)) { +} + +void Board::initialise() { + CPU().powerOn(); + CPU().raise(CPU().NMI()); + CPU().raise(CPU().FIRQ()); + CPU().reset(); +} + +EightBit::MemoryMapping Board::mapping(uint16_t) { + return { m_ram, 0x0000, EightBit::MemoryMapping::ReadWrite }; +} diff --git a/MC6809/unittest/Board.h b/MC6809/unittest/Board.h new file mode 100644 index 0000000..3253bd1 --- /dev/null +++ b/MC6809/unittest/Board.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +class Board : public EightBit::Bus { +public: + Board(); + + EightBit::mc6809& CPU() { return m_cpu; } + + void initialise(); + +protected: + virtual EightBit::MemoryMapping mapping(uint16_t address) final; + +private: + EightBit::Ram m_ram = 0x10000; // 0000 - FFFF, 64K RAM + EightBit::mc6809 m_cpu; +}; diff --git a/MC6809/unittest/mc6809_tests.cpp b/MC6809/unittest/mc6809_tests.cpp new file mode 100644 index 0000000..3ec28d3 --- /dev/null +++ b/MC6809/unittest/mc6809_tests.cpp @@ -0,0 +1,54 @@ +#include "pch.h" +#include "Board.h" + +// Using examples from 6809 Assembly Language Programming, by Lance A. Leventhal + +TEST_CASE("Add Accumulator B to Index Register X Unsigned ", "[ABX]") { + + Board board; + board.initialise(); + auto& cpu = board.CPU(); + cpu.step(); // Jump over the reset + + SECTION("Inherent") { + board.poke(0, 0x3a); + cpu.B() = 0x84; + cpu.X() = 0x1097; + cpu.step(); + REQUIRE(cpu.X() == 0x111b); + } +} + + +//TEST_CASE( "vectors can be sized and resized", "[vector]" ) { +// +// std::vector v( 5 ); +// +// REQUIRE( v.size() == 5 ); +// REQUIRE( v.capacity() >= 5 ); +// +// SECTION( "resizing bigger changes size and capacity" ) { +// v.resize( 10 ); +// +// REQUIRE( v.size() == 10 ); +// REQUIRE( v.capacity() >= 10 ); +// } +// SECTION( "resizing smaller changes size but not capacity" ) { +// v.resize( 0 ); +// +// REQUIRE( v.size() == 0 ); +// REQUIRE( v.capacity() >= 5 ); +// } +// SECTION( "reserving bigger changes capacity but not size" ) { +// v.reserve( 10 ); +// +// REQUIRE( v.size() == 5 ); +// REQUIRE( v.capacity() >= 10 ); +// } +// SECTION( "reserving smaller does not change size or capacity" ) { +// v.reserve( 0 ); +// +// REQUIRE( v.size() == 5 ); +// REQUIRE( v.capacity() >= 5 ); +// } +//} diff --git a/MC6809/unittest/pch.cpp b/MC6809/unittest/pch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a38f8a37da858b0e7a4a577210e923c883ac97f3 GIT binary patch literal 430 zcma)(OAdlS5JYQj;vFWsRoUwaJO;ubLXfO} ziM!*RK?b#&)PqF4LX~Q_GVq=g$>^{f<-{7@$r|ykmqm|MwtC_%l{t|TJS9Jpalvn} ztpC7C!Dg_+`-h+El+KlNtsDc|GOvyF+iK(A-j!r1ot!0T2mdlziM{46Ghg8k=#H+V zM?tLvNCnoo3Y&aHb%nm~4lL&e!^riDc4jR@ + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {9EFEA22E-E981-4342-BE17-7DD0F33F1F52} + Win32Proj + unittestMC6809 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + ..\inc;..\..\inc;..\..\MC6850\inc;$(SolutionDir)modules\catch2\single_include\catch2;C:\Libraries\boost_1_65_1;$(IncludePath) + + + true + ..\inc;..\..\inc;..\..\MC6850\inc;$(SolutionDir)modules\catch2\single_include\catch2;C:\Libraries\boost_1_65_1;$(IncludePath) + + + true + ..\inc;..\..\inc;..\..\MC6850\inc;$(SolutionDir)modules\catch2\single_include\catch2;C:\Libraries\boost_1_65_1;$(IncludePath) + + + false + ..\inc;..\..\inc;..\..\MC6850\inc;$(SolutionDir)modules\catch2\single_include\catch2;C:\Libraries\boost_1_65_1;$(IncludePath) + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + true + true + + + $(TargetPath) + + + Running tests + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + + + + + + + Running tests + + + + + Use + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + + + + + + + Running tests + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + true + true + + + $(TargetPath) + + + Running tests + + + + + + + + + + + Create + Create + Create + Create + + + NotUsing + NotUsing + NotUsing + NotUsing + + + + + {a9c24bd9-0cb4-4c84-b09b-46b815f9da47} + + + {09c1b50e-408e-48b1-a616-8400904b5829} + + + + + + \ No newline at end of file diff --git a/MC6809/unittest/unittest_MC6809.vcxproj.filters b/MC6809/unittest/unittest_MC6809.vcxproj.filters new file mode 100644 index 0000000..6209978 --- /dev/null +++ b/MC6809/unittest/unittest_MC6809.vcxproj.filters @@ -0,0 +1,35 @@ + + + + + {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 + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/modules/catch2 b/modules/catch2 new file mode 160000 index 0000000..9e1bdca --- /dev/null +++ b/modules/catch2 @@ -0,0 +1 @@ +Subproject commit 9e1bdca4667295fcb16265eae00efa8423f07007