diff --git a/.github/workflows/cmake.yaml b/.github/workflows/cmake.yaml deleted file mode 100644 index 4223b0e..0000000 --- a/.github/workflows/cmake.yaml +++ /dev/null @@ -1,51 +0,0 @@ -name: CMake - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -env: - BUILD_TYPE: Release - -jobs: - build: - runs-on: ${{matrix.os}} - strategy: - matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] - - steps: - - uses: actions/checkout@v3 - - - name: Setup ccache - uses: Chocobo1/setup-ccache-action@v1 - with: - windows_compile_environment: msvc - - - name: Cache CMake build directory - uses: actions/cache@v3 - env: - cache-name: cache-cmake-build - with: - path: ${{github.workspace}}/build - key: ${{matrix.os}}-${{env.BUILD_TYPE}}-build2 - - - name: Configure CMake (Windows) - # Builind with shared libs fails on Windows ATM - if: runner.os == 'Windows' - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_SHARED_LIBS=OFF - - - name: Configure CMake - if: runner.os != 'Windows' - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - - name: Build - # According to this link, github runners should have at least two CPUs - # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel 2 - - - name: Test - working-directory: ${{github.workspace}}/build - run: ctest -C ${{env.BUILD_TYPE}} diff --git a/.github/workflows/conan.yaml b/.github/workflows/conan.yaml new file mode 100644 index 0000000..55c682b --- /dev/null +++ b/.github/workflows/conan.yaml @@ -0,0 +1,56 @@ +name: conan + +on: + push: + pull_request: + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release, Debug] + + steps: + - uses: actions/checkout@v4 + + - name: Get conan + uses: turtlebrowser/get-conan@v1.2 + + - name: Set conan packages path + run: echo "CONAN_PACKAGES=$(conan config home)/p" >> $GITHUB_ENV + if: ${{ matrix.os == 'ubuntu-latest' }} + + - name: Set conan packages path + run: | + "CONAN_PACKAGES=$(conan config home)\p" | Out-File -FilePath $env:GITHUB_ENV -Append + if: ${{ matrix.os == 'windows-latest' }} + + - name: Cache conan home + uses: actions/cache@v4 + with: + path: ${{ env.CONAN_PACKAGES }} + key: ${{ matrix.os }}-${{ matrix.build_type }}-conan + + - name: Create default profile + run: conan profile detect --force + + - name: Install dependencies + run: | + conan install . \ + --settings build_type=${{ matrix.build_type }} \ + --build=missing \ + --conf tools.system.package_manager:mode=install \ + --conf tools.system.package_manager:sudo=True + if: ${{ matrix.os == 'ubuntu-latest' }} + + - name: Install dependencies + run: | + conan install . ` + --settings build_type=${{ matrix.build_type }} ` + --build=missing + if: ${{ matrix.os == 'windows-latest' }} + + - name: Build + run: conan build . diff --git a/CMakeLists.txt b/CMakeLists.txt index e1c1adc..6a70213 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,21 @@ cmake_minimum_required(VERSION 3.20) -project("Chip-8" VERSION 0.1 LANGUAGES CXX C) +project("Chip-8" VERSION 0.1 LANGUAGES CXX) option(BUILD_SHARED_LIBS "Build shared libs" ON) option(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "Export Windows symbols" ON) -if (MSVC) - message(WARNING "BUILD_SHARED_LIBS can't be used with MSVC") - set(BUILD_SHARED_LIBS OFF) -endif() +find_package(SDL2 REQUIRED) +find_package(SDL2_ttf REQUIRED) +find_package(fmt REQUIRED) +find_package(doctest REQUIRED) +find_package(cxxopts REQUIRED) +find_package(yaml-cpp REQUIRED) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -include(cmake/dependencies.cmake) -include(cmake/copy_dll.cmake) include(cmake/compiler_flags.cmake) enable_testing() # needed to create the target lib/test add_subdirectory(lib) diff --git a/README.MD b/README.MD index abe6b3b..796fd68 100644 --- a/README.MD +++ b/README.MD @@ -10,10 +10,13 @@ It contains: ## Build Requirements: -- C and C++ compiler -- Cmake v3.20 or later +- C++ 20 compiler +- conan 2.x ```console -cmake -B build -cmake --build build -``` \ No newline at end of file +# on Linux, you might need to add these options: +# -c tools.system.package_manager:mode=install +# -c tools.system.package_manager:sudo=True +conan install . --build=missing +conan build . +``` diff --git a/chip-8-disassembler/CMakeLists.txt b/chip-8-disassembler/CMakeLists.txt index 0b809a9..c2a93dc 100644 --- a/chip-8-disassembler/CMakeLists.txt +++ b/chip-8-disassembler/CMakeLists.txt @@ -4,4 +4,3 @@ add_executable(chip-8-disassembler disas.cpp) target_include_directories(chip-8-disassembler PRIVATE ${CHIP8_INCLUDE_DIRS}) target_link_libraries(chip-8-disassembler PRIVATE chip-8 fmt::fmt) enable_warnings(chip-8-disassembler) -copy_dll(chip-8-disassembler "chip-8;fmt") diff --git a/chip-8-disassembler/disas.cpp b/chip-8-disassembler/disas.cpp index 2405f24..38fcd88 100644 --- a/chip-8-disassembler/disas.cpp +++ b/chip-8-disassembler/disas.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) for (std::size_t i = 0; i < program.size() && i + 1 < program.size(); i += 2) { uint16_t raw_opcode = program[i] << 8 | program[i + 1]; - opcode decoded_opcode = opcode::decode(raw_opcode); + Opcode decoded_opcode = Opcode::decode(raw_opcode); std::cout << fmt::format("{:#06x} {}\n", addr, decoded_opcode.string_repr()); addr += 2; } diff --git a/chip-8-sdl/CMakeLists.txt b/chip-8-sdl/CMakeLists.txt index 95a5369..ed07049 100644 --- a/chip-8-sdl/CMakeLists.txt +++ b/chip-8-sdl/CMakeLists.txt @@ -11,16 +11,18 @@ add_executable(chip-8-sdl widget/widget.cpp ) -if (WIN32) - set_target_properties(chip-8-sdl PROPERTIES WIN32_EXECUTABLE TRUE) - target_link_libraries(chip-8-sdl PRIVATE SDL2main) -endif() target_include_directories(chip-8-sdl PRIVATE ${CHIP8_INCLUDE_DIRS} ".") target_include_directories(chip-8-sdl SYSTEM PRIVATE "${cxxopts_SOURCE_DIR}/include") -target_link_libraries(chip-8-sdl PRIVATE chip-8 "$,SDL2,SDL2-static>" SDL2_ttf yaml-cpp fmt::fmt) +target_link_libraries(chip-8-sdl PRIVATE + chip-8 + SDL2::SDL2main + SDL2::SDL2-static + SDL2_ttf::SDL2_ttf-static + yaml-cpp + fmt::fmt + cxxopts::cxxopts +) enable_warnings(chip-8-sdl) -copy_dll(chip-8-sdl "SDL2;SDL2_ttf;chip-8;fmt;yaml-cpp") - get_filename_component(SOUND_FILE_PATH "res/audio/beep-02.wav" ABSOLUTE) get_filename_component(FONT_FILE_PATH "res/fonts/PressStart2P-Regular.ttf" ABSOLUTE) configure_file(configuration.yaml.in configuration.yaml) diff --git a/chip-8-sdl/app.cpp b/chip-8-sdl/app.cpp index 61b4c30..840db2d 100644 --- a/chip-8-sdl/app.cpp +++ b/chip-8-sdl/app.cpp @@ -1,9 +1,12 @@ #include #include #include +#include #include "app.h" #include "icons/folder.h" +#include "icons/play.h" +#include "icons/warning.h" #include "widget/button.h" #include "widget/chip8_screen.h" #include "widget/label.h" @@ -11,37 +14,37 @@ static constexpr int font_point_size = 12; -static constexpr int scale_factor = 10; -static constexpr int panel_width = chip8::screen_width * scale_factor; -static constexpr int panel_height = (chip8::screen_height / 8) * scale_factor; -static constexpr int renderer_width = chip8::screen_width * scale_factor; -static constexpr int renderer_height = chip8::screen_height * scale_factor + panel_height; -static constexpr int chip8screen_y = panel_height; - -app::app(config& conf, std::string const& rom_path, const uint8_t* program, size_t program_size) - : m_emulator(program, program_size), m_rom_path(rom_path) +static constexpr int SCALE_FACTOR = 10; +static constexpr int PANEL_WIDTH = Chip8::SCREEN_WIDTH * SCALE_FACTOR; +static constexpr int PANEL_HEIGHT = (Chip8::SCREEN_HEIGHT / 8) * SCALE_FACTOR; +static constexpr int RENDERER_WIDTH = Chip8::SCREEN_WIDTH * SCALE_FACTOR; +static constexpr int RENDERER_HEIGHT = Chip8::SCREEN_HEIGHT * SCALE_FACTOR + PANEL_HEIGHT; +static constexpr int CHIP8SCREEN_Y = PANEL_HEIGHT; + +App::App(Config& conf, std::string const& rom_path, std::vector const& program) + : m_emulator(program), + m_rom_path(rom_path), + m_conf(conf), + m_window(SDLUniqueWindow(SDL_CreateWindow("Chip-8 Emulator", + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + conf.window_width, conf.window_height, 0) , SDLCleaner())), + m_quit(false), + m_audio_enabled(false), + m_wav_buffer(nullptr), + m_audio_device(0) { sdl_checksuccess(SDL_Init(init_flags), "Failed to initialize the SDL: %s\n"); sdl_checksuccess(TTF_Init(), "Failed to initialize SDL_ttf: %s\n"); - m_conf = conf; - m_window = SDLUniqueWindow(SDL_CreateWindow("Chip-8 Emulator", - SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - conf.window_width, conf.window_height, 0) - , SDLCleaner()); sdl_nullcheck(m_window.get(), "Failed to create the window: %s\n"); SDL_SetWindowResizable(m_window.get(), SDL_TRUE); m_renderer = SDLSharedRenderer(SDL_CreateRenderer(m_window.get(), -1, SDL_RENDERER_ACCELERATED), SDLCleaner()); sdl_nullcheck(m_renderer.get(), "Failed to create the renderer: %s\n"); set_renderer_color(m_renderer, m_conf.bg_color); sdl_checksuccess(SDL_RenderClear(m_renderer.get()), "Failed to clear the renderer: %s\n"); - sdl_checksuccess(SDL_RenderSetLogicalSize(m_renderer.get(), renderer_width, renderer_height), - "Failed to set the renderer's logical scale: %s"); + // sdl_checksuccess(SDL_RenderSetLogicalSize(m_renderer.get(), RENDERER_WIDTH, RENDERER_HEIGHT), + // "Failed to set the renderer's logical scale: %s"); sdl_checksuccess(SDL_RenderSetIntegerScale(m_renderer.get(), SDL_TRUE), "Failed to set integer scaling on the renderer: %s"); - m_quit = false; - m_audio_enabled = false; - m_audio_device = 0; - m_wav_buffer = nullptr; if (conf.sound_file) { std::string sound_strpath = conf.sound_file.value().string(); @@ -68,17 +71,17 @@ app::app(config& conf, std::string const& rom_path, const uint8_t* program, size sdl_nullcheck(m_font.get(), fmt::format("Failed to open font file: {}", font_strpath).c_str()); } - panel_ptr p1 = std::make_shared(m_renderer, 0, 0, panel_width, panel_height, m_conf.fg_color, m_conf.bg_color); - button_ptr b1 = std::make_shared