Skip to content

Commit

Permalink
Merge pull request #52 from matheusgomes28/simple-build-pipeline
Browse files Browse the repository at this point in the history
Create cmake-single-platform.yml
  • Loading branch information
matheusgomes28 authored Oct 1, 2024
2 parents 235dbf3 + a1e1b7b commit 0015fb0
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 63 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
@@ -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"

8 changes: 8 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
]
}
21 changes: 21 additions & 0 deletions cpp-lint.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions emulator_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ add_executable(emulator_app main.cpp)
target_link_libraries(emulator_app
PRIVATE
emulator
fmt::fmt
raylib)
6 changes: 3 additions & 3 deletions emulator_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import emulator;

#include <chrono>
#include <cstdint>
#include <format>
#include <fstream>
#include <future>
#include <iostream>
#include <thread>
#include <vector>

#include <fmt/format.h>
#include <raylib.h>

namespace
Expand Down Expand Up @@ -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};
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion profiler/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module;
#include <chrono>
#include <concepts>
#include <iostream>
#include <memory>
#include <source_location>
#include <string>
#include <unordered_map>

export module profiler;

Expand Down
16 changes: 8 additions & 8 deletions tests/and_indexed_indirect_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t, 2> const program{0x21, 0x00};

Expand All @@ -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<std::uint8_t, 2> const program{0x21, 0xfe};

Expand Down
4 changes: 2 additions & 2 deletions tests/and_zeropage_indexed_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t, 2> program{
Expand Down
6 changes: 3 additions & 3 deletions tests/and_zeropage_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t>(address)] = value;

std::array<std::uint8_t, 3> program{
Expand Down Expand Up @@ -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<std::uint8_t>(address)] = value;

std::array<std::uint8_t, 2> program{
Expand Down Expand Up @@ -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<std::uint8_t, 2> program{
Expand Down
3 changes: 2 additions & 1 deletion tests/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions tests/eor_zeropage_indexed_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t, 2> program{
Expand Down
8 changes: 4 additions & 4 deletions tests/eor_zeropage_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t>(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<std::uint8_t, 2> program{
0x45,
Expand Down Expand Up @@ -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<std::uint8_t>(address)] = value;

std::array<std::uint8_t, 2> program{
Expand Down Expand Up @@ -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<std::uint8_t, 2> program{
Expand Down
8 changes: 4 additions & 4 deletions tests/flags_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ora_absolute_indexed_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t>((address >> 8) & 0b1111'11111);
Expand Down Expand Up @@ -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<std::uint8_t>((address >> 8) & 0b1111'1111);
Expand Down
2 changes: 1 addition & 1 deletion tests/ora_absolute_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t>((address >> 8) & 0b1111'11111);
Expand Down
16 changes: 8 additions & 8 deletions tests/ora_indexed_indirect_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t, 2> const program{0x01, 0x00};

Expand All @@ -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<std::uint8_t, 2> const program{0x01, 0xfe};

Expand Down
16 changes: 8 additions & 8 deletions tests/ora_indirect_indexed_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t, 2> const program{0x11, 0x00};

Expand Down Expand Up @@ -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<std::uint8_t, 2> const program{0x11, 0xff};

Expand Down
4 changes: 2 additions & 2 deletions tests/ora_zeropage_index_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t, 2> program{
Expand Down
Loading

0 comments on commit 0015fb0

Please sign in to comment.