diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml new file mode 100644 index 0000000..36abd29 --- /dev/null +++ b/.github/workflows/cmake-single-platform.yml @@ -0,0 +1,34 @@ +# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml +name: CMake on a single platform + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + container: + image: mattgomes28/jammy-cpp:0.0.0 + + steps: + - uses: actions/checkout@v4 + + - name: Run clang format + run: ./cpp-lint.sh + + - name: Configure CMake + run: cmake . --preset "unix-deb-ninja" + + - name: Build + run: cmake --build --preset "unix-deb-ninja" + + - name: Test + run: ctest --preset "unix-deb-ninja" + diff --git a/CMakePresets.json b/CMakePresets.json index 95ed6ac..a9544ef 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -228,5 +228,13 @@ "configurePreset": "unix-rel-shared", "configuration": "Release" } + ], + "testPresets": [ + { + "name": "unix-deb-ninja", + "configurePreset": "unix-deb-ninja", + "output": {"outputOnFailure": true}, + "execution": {"noTestsAction": "error", "stopOnFailure": true} + } ] } diff --git a/cpp-lint.sh b/cpp-lint.sh new file mode 100755 index 0000000..39a56a9 --- /dev/null +++ b/cpp-lint.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -euo pipefail + +: ' This script will find all the cpp files + and lint them using clang-format +' + +THIS_DIR=$(cd "$(dirname "$0")" && pwd) +PROJECT_DIR="$(cd "${THIS_DIR}/" && pwd)" + +# Create the exclude regex by replacing spaces +# with the | (for or), and wrap the text in regex +# brackets +FILES_TO_EXCLUDE="base64pp_export.h" +FILE_EXCLUDE_REGEX="(${FILES_TO_EXCLUDE/ /|})" + +# Find all cpp files and exclide the files +ALL_CPP_FILES="$(find "${PROJECT_DIR}" -iname "*.cpp" -o -iname "*.h")" +CPP_FILES_TO_LINT="$(echo "${ALL_CPP_FILES}" | grep -Ev "${FILE_EXCLUDE_REGEX}")" +echo "${CPP_FILES_TO_LINT}" | xargs clang-format -i diff --git a/emulator_app/CMakeLists.txt b/emulator_app/CMakeLists.txt index aef9478..31506d0 100644 --- a/emulator_app/CMakeLists.txt +++ b/emulator_app/CMakeLists.txt @@ -3,4 +3,5 @@ add_executable(emulator_app main.cpp) target_link_libraries(emulator_app PRIVATE emulator + fmt::fmt raylib) diff --git a/emulator_app/main.cpp b/emulator_app/main.cpp index 60c05be..5bd1abf 100644 --- a/emulator_app/main.cpp +++ b/emulator_app/main.cpp @@ -2,13 +2,13 @@ import emulator; #include #include -#include #include #include #include #include #include +#include #include namespace @@ -74,7 +74,7 @@ int main(int argc, char** argv) emulator::Cpu easy65k; - std::cout << std::format("The clock speed was set to {}\n", easy65k.clock_speed); + std::cout << fmt::format("The clock speed was set to {}\n", easy65k.clock_speed); auto const filename = argv[1]; auto file = std::ifstream{filename}; @@ -85,7 +85,7 @@ int main(int argc, char** argv) for (auto const& [function, profile] : easy65k.current_profile()) { - std::cout << std::format("{}: {:.6f}\n", function, profile); + std::cout << fmt::format("{}: {:.6f}\n", function, profile); } draw(easy65k); diff --git a/profiler/profiler.cpp b/profiler/profiler.cpp index d3b08b6..653be59 100644 --- a/profiler/profiler.cpp +++ b/profiler/profiler.cpp @@ -3,9 +3,9 @@ module; #include #include #include +#include #include #include -#include export module profiler; diff --git a/tests/and_indexed_indirect_tests.cpp b/tests/and_indexed_indirect_tests.cpp index 5103b1a..0c6ddbc 100644 --- a/tests/and_indexed_indirect_tests.cpp +++ b/tests/and_indexed_indirect_tests.cpp @@ -27,11 +27,11 @@ TEST(ANDIndexedIndirectTests, ZeroAddressToLastAddress) // which will store the two last accessible bytes emulator::Cpu cpu; - cpu.reg.a = 0b0111'1111; - cpu.reg.x = 0x00; + cpu.reg.a = 0b0111'1111; + cpu.reg.x = 0x00; cpu.mem[0xffff] = 0b0111'1111; - cpu.mem[0x00] = 0xff; - cpu.mem[0x01] = 0xff; + cpu.mem[0x00] = 0xff; + cpu.mem[0x01] = 0xff; std::array const program{0x21, 0x00}; @@ -57,11 +57,11 @@ TEST(ANDIndexedIndirectTests, ZeropageWrapsAround) // on the indirect address emulator::Cpu cpu; - cpu.reg.a = 0b0111'1111; - cpu.reg.x = 0x01; + cpu.reg.a = 0b0111'1111; + cpu.reg.x = 0x01; cpu.mem[0xffff] = 0b0111'1111; - cpu.mem[0xff] = 0xff; - cpu.mem[0x00] = 0xff; + cpu.mem[0xff] = 0xff; + cpu.mem[0x00] = 0xff; std::array const program{0x21, 0xfe}; diff --git a/tests/and_zeropage_indexed_tests.cpp b/tests/and_zeropage_indexed_tests.cpp index df1151c..011f0b5 100644 --- a/tests/and_zeropage_indexed_tests.cpp +++ b/tests/and_zeropage_indexed_tests.cpp @@ -36,8 +36,8 @@ TEST(ANDZeropageIndexTests, WrapAroundTests) for (auto const& [init_acc, value, address, init_x, exp_mem] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; - cpu.reg.x = init_x; + cpu.reg.a = init_acc; + cpu.reg.x = init_x; cpu.mem[exp_mem] = value; std::array program{ diff --git a/tests/and_zeropage_tests.cpp b/tests/and_zeropage_tests.cpp index b74c996..f1a7392 100644 --- a/tests/and_zeropage_tests.cpp +++ b/tests/and_zeropage_tests.cpp @@ -36,7 +36,7 @@ TEST(ANDZeropageTests, NoFlagOperations) for (auto const& [init_acc, value, address] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; + cpu.reg.a = init_acc; cpu.mem[static_cast(address)] = value; std::array program{ @@ -73,7 +73,7 @@ TEST(ANDZeropageTests, NegativeFlagOperation) for (auto const& [acc, value, address] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = acc; + cpu.reg.a = acc; cpu.mem[static_cast(address)] = value; std::array program{ @@ -106,7 +106,7 @@ TEST(ANDZeropageTests, ZeroFlagOperation) for (auto const& [init_acc, value, zp_addr] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; + cpu.reg.a = init_acc; cpu.mem[0x88] = value; std::array program{ diff --git a/tests/common.h b/tests/common.h index be637ae..364ab4d 100644 --- a/tests/common.h +++ b/tests/common.h @@ -8,7 +8,8 @@ /// format `0bNVB1DIZC` /// @param flags an 8-bit bitset representing the flag /// @return the equivalent `Flags` object -constexpr emulator::Flags make_flags(std::bitset<8> flags) +// constexpr emulator::Flags make_flags(std::bitset<8> flags) +inline emulator::Flags make_flags(std::bitset<8> flags) { // CZID B1VN return emulator::Flags{ diff --git a/tests/eor_zeropage_indexed_tests.cpp b/tests/eor_zeropage_indexed_tests.cpp index 477d11c..9d532a2 100644 --- a/tests/eor_zeropage_indexed_tests.cpp +++ b/tests/eor_zeropage_indexed_tests.cpp @@ -31,8 +31,8 @@ TEST(EORZeropageIndexTests, WrapAroundTests) for (auto const& [init_acc, value, address, init_x, exp_mem] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; - cpu.reg.x = init_x; + cpu.reg.a = init_acc; + cpu.reg.x = init_x; cpu.mem[exp_mem] = value; std::array program{ diff --git a/tests/eor_zeropage_tests.cpp b/tests/eor_zeropage_tests.cpp index dc2efac..2f8e451 100644 --- a/tests/eor_zeropage_tests.cpp +++ b/tests/eor_zeropage_tests.cpp @@ -37,10 +37,10 @@ TEST(EORZeropageTests, NoFlagOperations) for (auto const& [init_acc, value, address] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; + cpu.reg.a = init_acc; cpu.mem[static_cast(address)] = value; - // TODO : The other zero page tests are probably taking + // TODO : The other zero page tests are probably taking // TODO : 3 instructions instead of two std::array program{ 0x45, @@ -74,7 +74,7 @@ TEST(EORZeropageTests, NegativeFlagOperation) for (auto const& [acc, value, address] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = acc; + cpu.reg.a = acc; cpu.mem[static_cast(address)] = value; std::array program{ @@ -111,7 +111,7 @@ TEST(EORZeropageTests, ZeroFlagOperation) for (auto const& [init_acc, value, zp_addr] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; + cpu.reg.a = init_acc; cpu.mem[0x88] = value; std::array program{ diff --git a/tests/flags_tests.cpp b/tests/flags_tests.cpp index d3da787..9af420b 100644 --- a/tests/flags_tests.cpp +++ b/tests/flags_tests.cpp @@ -22,7 +22,7 @@ TEST(FlagsTests, SEC) ASSERT_FALSE(cpu.flags.c); emulator::execute(cpu, {program.data(), program.size()}); - ASSERT_TRUE (cpu.flags.c); + ASSERT_TRUE(cpu.flags.c); ASSERT_EQ(0b0000'0001, cpu.sr()); } @@ -35,7 +35,7 @@ TEST(FlagsTests, SED) ASSERT_FALSE(cpu.flags.d); emulator::execute(cpu, {program.data(), program.size()}); - ASSERT_TRUE (cpu.flags.d); + ASSERT_TRUE(cpu.flags.d); ASSERT_EQ(0b0000'1000, cpu.sr()); } @@ -48,7 +48,7 @@ TEST(FlagsTests, SEI) ASSERT_FALSE(cpu.flags.i); emulator::execute(cpu, {program.data(), program.size()}); - ASSERT_TRUE (cpu.flags.i); + ASSERT_TRUE(cpu.flags.i); ASSERT_EQ(0b0000'0100, cpu.sr()); } @@ -61,7 +61,7 @@ TEST(FlagsTests, SRGetsNegative) ASSERT_FALSE(cpu.flags.n); emulator::execute(cpu, {program.data(), program.size()}); - ASSERT_TRUE (cpu.flags.n); + ASSERT_TRUE(cpu.flags.n); ASSERT_EQ(0b1000'0000, cpu.sr()); } diff --git a/tests/ora_absolute_indexed_tests.cpp b/tests/ora_absolute_indexed_tests.cpp index bfa4245..859e985 100644 --- a/tests/ora_absolute_indexed_tests.cpp +++ b/tests/ora_absolute_indexed_tests.cpp @@ -34,8 +34,8 @@ TEST(ORAAbsoluteTests, PlusXTests) for (auto const& [init_acc, value, init_x, address, exp_mem] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; - cpu.reg.x = init_x; + cpu.reg.a = init_acc; + cpu.reg.x = init_x; cpu.mem[exp_mem] = value; auto const hsb = static_cast((address >> 8) & 0b1111'11111); @@ -70,8 +70,8 @@ TEST(ORAAbsoluteTests, PlusYTests) for (auto const& [init_acc, value, init_y, address, exp_mem] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; - cpu.reg.y = init_y; + cpu.reg.a = init_acc; + cpu.reg.y = init_y; cpu.mem[exp_mem] = value; auto const hsb = static_cast((address >> 8) & 0b1111'1111); diff --git a/tests/ora_absolute_tests.cpp b/tests/ora_absolute_tests.cpp index 874d13d..8f23c14 100644 --- a/tests/ora_absolute_tests.cpp +++ b/tests/ora_absolute_tests.cpp @@ -32,7 +32,7 @@ TEST(ORAAbsoluteTests, GeneralTests) for (auto const& [init_acc, value, address] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; + cpu.reg.a = init_acc; cpu.mem[address] = value; auto const hsb = static_cast((address >> 8) & 0b1111'11111); diff --git a/tests/ora_indexed_indirect_tests.cpp b/tests/ora_indexed_indirect_tests.cpp index 44509da..07ab972 100644 --- a/tests/ora_indexed_indirect_tests.cpp +++ b/tests/ora_indexed_indirect_tests.cpp @@ -27,11 +27,11 @@ TEST(ORAIndexedIndirectTests, ZeroAddressToLastAddress) // which will store the two last accessible bytes emulator::Cpu cpu; - cpu.reg.a = 0b0101'0101; - cpu.reg.x = 0x00; + cpu.reg.a = 0b0101'0101; + cpu.reg.x = 0x00; cpu.mem[0xffff] = 0b0010'1010; - cpu.mem[0x00] = 0xff; - cpu.mem[0x01] = 0xff; + cpu.mem[0x00] = 0xff; + cpu.mem[0x01] = 0xff; std::array const program{0x01, 0x00}; @@ -57,11 +57,11 @@ TEST(ORAIndexedIndirectTests, ZeropageWrapsAround) // on the indirect address emulator::Cpu cpu; - cpu.reg.a = 0b0101'0101; - cpu.reg.x = 0x01; + cpu.reg.a = 0b0101'0101; + cpu.reg.x = 0x01; cpu.mem[0xffff] = 0b0010'1010; - cpu.mem[0xff] = 0xff; - cpu.mem[0x00] = 0xff; + cpu.mem[0xff] = 0xff; + cpu.mem[0x00] = 0xff; std::array const program{0x01, 0xfe}; diff --git a/tests/ora_indirect_indexed_tests.cpp b/tests/ora_indirect_indexed_tests.cpp index 2ffe272..58ab6de 100644 --- a/tests/ora_indirect_indexed_tests.cpp +++ b/tests/ora_indirect_indexed_tests.cpp @@ -27,11 +27,11 @@ TEST(ORAIndirectIndexedTests, ZeroAddressToLastAddress) // complement of the or operation emulator::Cpu cpu; - cpu.reg.a = 0b0101'0101; - cpu.reg.y = 0x01; + cpu.reg.a = 0b0101'0101; + cpu.reg.y = 0x01; cpu.mem[0xffff] = 0b0010'1010; - cpu.mem[0x00] = 0xfe; - cpu.mem[0x01] = 0xff; + cpu.mem[0x00] = 0xfe; + cpu.mem[0x01] = 0xff; std::array const program{0x11, 0x00}; @@ -59,11 +59,11 @@ TEST(ORAIndirectIndexedTests, ZeropageWrapsAround) // the or operation emulator::Cpu cpu; - cpu.reg.a = 0b0101'0101; - cpu.reg.y = 0x01; + cpu.reg.a = 0b0101'0101; + cpu.reg.y = 0x01; cpu.mem[0xffff] = 0b0010'1010; - cpu.mem[0xff] = 0xfe; - cpu.mem[0x00] = 0xff; + cpu.mem[0xff] = 0xfe; + cpu.mem[0x00] = 0xff; std::array const program{0x11, 0xff}; diff --git a/tests/ora_zeropage_index_tests.cpp b/tests/ora_zeropage_index_tests.cpp index 26c28ec..ab745f7 100644 --- a/tests/ora_zeropage_index_tests.cpp +++ b/tests/ora_zeropage_index_tests.cpp @@ -36,8 +36,8 @@ TEST(ORAZeropageIndexTests, WrapAroundTests) for (auto const& [init_acc, value, address, init_x, exp_mem] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; - cpu.reg.x = init_x; + cpu.reg.a = init_acc; + cpu.reg.x = init_x; cpu.mem[exp_mem] = value; std::array program{ diff --git a/tests/ora_zeropage_tests.cpp b/tests/ora_zeropage_tests.cpp index 932d5bb..e2f97c2 100644 --- a/tests/ora_zeropage_tests.cpp +++ b/tests/ora_zeropage_tests.cpp @@ -36,7 +36,7 @@ TEST(ORAZeropageTests, NoFlagOperations) for (auto const& [init_acc, value, address] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = init_acc; + cpu.reg.a = init_acc; cpu.mem[static_cast(address)] = value; std::array program{ @@ -73,7 +73,7 @@ TEST(ORAZeropageTests, NegativeFlagOperation) for (auto const& [acc, value, address] : test_cases) { emulator::Cpu cpu; - cpu.reg.a = acc; + cpu.reg.a = acc; cpu.mem[static_cast(address)] = value; std::array program{ @@ -98,7 +98,7 @@ TEST(ORAZeropageTests, NegativeFlagOperation) TEST(ORAZeropageTests, ZeroFlagOperation) { emulator::Cpu cpu; - cpu.reg.a = 0x00; + cpu.reg.a = 0x00; cpu.mem[0x88] = 0x00; std::array program{ @@ -129,7 +129,7 @@ TEST(ORAZeropageTests, MakeSureFlagsAreSound) for (std::int16_t val = 0; val < 256; ++val) { emulator::Cpu cpu; - cpu.reg.a = static_cast(acc); + cpu.reg.a = static_cast(acc); cpu.mem[0x88] = static_cast(val); std::array program{ diff --git a/tests/pla_tests.cpp b/tests/pla_tests.cpp index bd92014..f31ade2 100644 --- a/tests/pla_tests.cpp +++ b/tests/pla_tests.cpp @@ -14,10 +14,10 @@ TEST(PLATests, PopsNoFlagsNoOverflow) emulator::Cpu cpu; ASSERT_EQ(cpu.reg.a, 0x00); - cpu.reg.sp = 0xfe; + cpu.reg.sp = 0xfe; cpu.mem[0x01ff] = 0b0111'1111; - constexpr std::array program{ 0x68 }; + constexpr std::array program{0x68}; emulator::execute(cpu, {program.data(), program.size()}); ASSERT_EQ(cpu.reg.sp, 0xff); @@ -39,10 +39,10 @@ TEST(PLATests, PopsNegativeFlag) emulator::Cpu cpu; ASSERT_EQ(cpu.reg.a, 0x00); - cpu.reg.sp = 0xfe; + cpu.reg.sp = 0xfe; cpu.mem[0x01ff] = 0b1111'1111; - constexpr std::array program{ 0x68 }; + constexpr std::array program{0x68}; emulator::execute(cpu, {program.data(), program.size()}); ASSERT_EQ(cpu.reg.sp, 0xff); @@ -64,10 +64,10 @@ TEST(PLATests, PopsZeroFlag) emulator::Cpu cpu; cpu.reg.a = 0xff; - cpu.reg.sp = 0xfe; + cpu.reg.sp = 0xfe; cpu.mem[0x01ff] = 0x00; - constexpr std::array program{ 0x68 }; + constexpr std::array program{0x68}; emulator::execute(cpu, {program.data(), program.size()}); ASSERT_EQ(cpu.reg.sp, 0xff); @@ -89,10 +89,10 @@ TEST(PLATests, PopsOverflow) emulator::Cpu cpu; ASSERT_EQ(cpu.reg.a, 0x00); - cpu.reg.sp = 0xff; + cpu.reg.sp = 0xff; cpu.mem[0x0100] = 0b0111'1111; - constexpr std::array program{ 0x68 }; + constexpr std::array program{0x68}; emulator::execute(cpu, {program.data(), program.size()}); ASSERT_EQ(cpu.reg.sp, 0x00);