Skip to content

Commit

Permalink
Mostly merge new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDoom committed Dec 11, 2024
2 parents a0edb78 + 6800a11 commit 69de193
Show file tree
Hide file tree
Showing 28 changed files with 955 additions and 194 deletions.
180 changes: 96 additions & 84 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,31 @@ name: Build

on:
push:
paths:
- 'src/**'
- 'CMakeLists.txt'
- 'assets/**'
- 'dependencies/**'
- '.github/workflows/**'
branches:
- master
- sdl
workflow_dispatch:

jobs:
build-ubuntu:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
build_type: [ Release ]
c_compiler: [ gcc ]
cpp_compiler: [ g++ ]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand All @@ -28,106 +42,104 @@ jobs:
ssh-keyscan github.com >> ~/.ssh/known_hosts
git submodule update --init --recursive
- name: Configure and build
- name: Configure CMake
run: |
mkdir build && cd build
cmake ..
cmake --build .
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
- name: Build CMake
run: |
cd build
cmake --build . --config Release
- name: Collect executable and assets
run: |
mkdir -p output
ls build
ls build/bin
# cp build/bin/8ChocChip output/
# cp -r build/bin/assets output/

- name: Upload executable
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ubuntu-executable
path: build/src/8ChocChip

name: build-artifacts-linux
path: build/bin/

build-windows:
runs-on: windows-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
strategy:
fail-fast: false
matrix:
build_type: [Release]
c_compiler: [gcc]
cpp_compiler: [g++]

- name: Install CMake
run: choco install cmake --installargs '"ADD_CMAKE_TO_PATH=System"'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Install vcpkg
- name: Set up SSH
run: |
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
working-directory: ${{ github.workspace }}

- name: Set VCPKG_ROOT environment variable
run: echo "VCPKG_ROOT=$(vcpkg integrate install)" >> $GITHUB_ENV

- name: Install SFML with vcpkg
run: vcpkg install sfml

- name: Setup SSH key and Install submodules
mkdir -p ~/.ssh
echo "$env:SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Set reusable strings
id: strings
shell: bash
run: |
mkdir -p $HOME/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > $HOME/.ssh/id_rsa
echo "StrictHostKeyChecking no" > $HOME/.ssh/config
chmod 600 $HOME/.ssh/id_rsa
ssh-keyscan github.com >> $HOME/.ssh/known_hosts
git submodule update --init --recursive
- name: Configure and build
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: |
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=OFF ..
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
- name: Build CMake
run: |
cd build
cmake --build . --config Release
- name: Upload executable
uses: actions/upload-artifact@v2
with:
name: windows-executable
path: |
build/src/Release/*.exe
build/src/Release/*.dll
- name: Search for .dll and .lib files
run: |
echo "Searching for .dll and .lib files..."
Get-ChildItem -Path . -Recurse -Include *.dll,*.lib | ForEach-Object { $_.FullName } | Out-File -FilePath found_files.txt
# - name: Configure build environment for target architecture
# run: |
# export TARGET_ARCH=${{ matrix.arch }}
# case $TARGET_ARCH in
# x64)
# # Set compiler and linker for 64-bit Windows target
# export TOOLCHAIN=$(command -v x86_64-w64-mingw32-g++-posix)
# ;;
# x86)
# # Set compiler and linker for 32-bit Windows target
# export TOOLCHAIN=$(command -v i686-w64-mingw32-g++-posix)
# ;;
# *)
# echo "Unsupported architecture: $TARGET_ARCH"
# exit 1
# ;;
# esac
# echo "Using compiler: $TOOLCHAIN"

# - name: Create build directory
# run: mkdir build

# - name: Configure CMake (cross-compiling)
# env:
# CMAKE_C_COMPILER: $TOOLCHAIN
# CMAKE_CXX_COMPILER: $TOOLCHAIN
# working-directory: build
# run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=Release -DSFML_DIR=/usr/lib/x86_64-linux-gnu/pkgconfig/SFML.pc # (or adjust for your SFML installation path)

# - name: Build
# working-directory: build
# run: cmake --build . --config Release
- name: Output Results
if: success()
run: |
echo "Found the following .dll and .lib files:"
cat found_files.txt
# - name: Archive Windows EXEs (recursive)
# if: success() # Only run if previous steps succeed
# uses: actions/upload-artifact@v3
# with:
# name: windows-exe # Generic name (you can customize)
# path: build/**/*.exe # Capture all .exe files recursively

- name: Collect executable and assets
run: |
mkdir -p output
dir build
dir build/bin
dir build/bin/Release
cp build/dependencies/nativefiledialog/src/Release/* build/bin/Release
cp build/out/Release/libconfig++.* build/bin/Release
# cp build/src/Release/* build/bin/
# cp build/src/Release/assets/* build/bin/assets
# cp -r assets output/

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts-windows
path: build/bin/Release

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}


# build-macos:
Expand Down
10 changes: 5 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "dependencies/sdl"]
path = dependencies/sdl
url = git@github.com:libsdl-org/SDL.git
[submodule "dependencies/nativefiledialog"]
path = dependencies/nativefiledialog
url = git@github.com:AlvaroBarua/nativefiledialog.git
url = git@github.com:btzy/nativefiledialog-extended.git
[submodule "dependencies/libconfig"]
path = dependencies/libconfig
url = git@github.com:hyperrealm/libconfig.git
[submodule "dependencies/sdl"]
path = dependencies/sdl
url = git@github.com:libsdl-org/SDL.git
url = https://github.com/hyperrealm/libconfig.git
70 changes: 68 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,75 @@ project(8ChocChip
LANGUAGES CXX
VERSION 0.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_executable(8ChocChip)

#option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

#file(GLOB ASSETS "${CMAKE_SOURCE_DIR}/assets/*")
#
#foreach(ASSET ${ASSETS})
# configure_file(${ASSET} ${CMAKE_BINARY_DIR}/assets COPYONLY)
#endforeach()

add_subdirectory(dependencies)
add_subdirectory(src)

file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})
if(CMAKE_HOST_WIN32)
set(libname "libconfig")
else()
set(libname "config")
endif()

target_link_libraries(8ChocChip PRIVATE sfml-graphics sfml-audio sfml-window sfml-system nfd ${libname}++)

# Set the RPATH of the executable to include the directory where SFML libraries are located
set_target_properties(8ChocChip PROPERTIES
INSTALL_RPATH "$ORIGIN"
BUILD_RPATH "$ORIGIN"
)

# Copy DLLs needed for runtime on Windows
if(WIN32)
add_custom_command(
TARGET 8ChocChip
COMMENT "Copy OpenAL DLL"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:${PROJECT_NAME}>
VERBATIM)

if (BUILD_SHARED_LIBS)
add_custom_command(TARGET 8ChocChip POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:sfml-graphics>
$<TARGET_FILE:sfml-window>
$<TARGET_FILE:sfml-system>
$<TARGET_FILE:sfml-audio>
$<TARGET_FILE_DIR:8ChocChip>)
endif()
endif()

# Copy nfd and config++ libraries to the executable directory
if (UNIX AND NOT APPLE)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:nfd>"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:config++>"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ln -sf "libnfd.so.1.2.1" "$<TARGET_FILE_DIR:${PROJECT_NAME}>/libnfd.so.1"
COMMAND ln -sf "libconfig++.so.1.7.4" "$<TARGET_FILE_DIR:${PROJECT_NAME}>/libconfig++.so.1"
)
endif()


install(DIRECTORY assets DESTINATION ${CMAKE_INSTALL_PREFIX})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/assets"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/assets")
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

**This is a basic SDL port of the emulator. The menu and sound is not yet implementated. Gameplay frame rate increased from SFML 650 or so to about 5000 with SDL so may finish this once it is more stable**

8ChocChip is an emulator for the Chip8 software that I am working on to learn the basics around emulation.
I decided to program this in C++ because I wanted to do more in it and improve my skills.
8ChocChip is an emulator for the Chip8 software that I am working on to learn the basics around emulation.

The graphics and only library used in this is SFML which handles the window, inputs and sounds.
libconfig is used to manage config and save data files, and NativeFileDialog is used for basic popup windows like the file/directory selector.
libconfig is used to manage config and save data files, and NativeFileDialog-extended is used for basic popup windows like the file/directory selector.

## TODO

There are a couple of things left to do until I would say it works well enough
- [ ] Fix some of the instructions that result in most programs failing except for `BLINKY`
- [x] ~~Fix some of the instructions that result in most programs failing except for `BLINKY`~~ Should be done but the test suite has issues I can not figure out how to fix. But is better than before and should work with most stuff
- [ ] Cleaner/more optimised code
- [x] ~~Windows Support~~ Needs fixing again, GitHub actions just don't like it at the moment, compilable on a local machine though.
- [ ] MacOS Support
- [ ] Easily support multiple graphics frameworks for different platform support if the primary one doesn't support them (Desktop, Mobile, Game Consoles etc)
- [x] Windows Support
- [ ] MacOS Support (Builds, but unable to test)
- [ ] Switch to SDL from SFML

## Usage

Expand All @@ -24,6 +23,10 @@ Or you can normally launch the executable to open the UI and manage it from ther

Some basic ROMS can be found [here](https://github.com/ericgrandt/chip8-emulator/tree/master/roms).

More games are [here](https://github.com/dmatlack/chip8/tree/master/roms/games)

For a proper test suite you can check out https://github.com/Timendus/chip8-test-suite

## Building

Until a proper building section is created, just follow the commands that are used in the GitHub actions workflow for your platform.
Expand All @@ -47,5 +50,5 @@ Thanks to these two blogs that helped me through creating this emulator

Currently, three libraries are being used
- [SFML](https://github.com/SFML/SFML) - UI, graphics, input and sounds
- [NativeFileDialog](https://github.com/mlabbe/nativefiledialog) - A fork of this is used for the CMakeLists files (https://github.com/AlvaroBarua/nativefiledialog/tree/CMakeLists)
- [NativeFileDialog-extended](https://github.com/btzy/nativefiledialog-extended) - Handles file dialogs for selecting files/directories. Fork of [nativefiledialog](https://github.com/mlabbe/nativefiledialog) which I used a fork of that added only CMake support, this new one adds that plus new fixes/features
- [libconfig](https://github.com/hyperrealm/libconfig) - Library to manage save data (like directories that hold ROMs) and possible future config files
2 changes: 1 addition & 1 deletion dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_subdirectory(nativefiledialog)
add_subdirectory(libconfig)
add_subdirectory(sdl)
add_subdirectory(sdl)
2 changes: 1 addition & 1 deletion dependencies/nativefiledialog
4 changes: 1 addition & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
add_executable(8ChocChip)

add_subdirectory(sdl)
add_subdirectory(util)
add_subdirectory(emulator)
Expand All @@ -12,4 +10,4 @@ else()
set(libname "config")
endif()

target_link_libraries(8ChocChip PRIVATE nativefiledialog ${libname}++ SDL2)
target_link_libraries(8ChocChip PRIVATE nfd ${libname}++ SDL2)
Loading

0 comments on commit 69de193

Please sign in to comment.