From 693216fb46778f642992e7e526aa2f7cefe46001 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 2 Jul 2026 15:32:34 -0400 Subject: [PATCH] Init --- .gitignore | 45 +++++++++++++++++++++++ CMakeLists.txt | 40 ++++++++++++++++++++ CMakePresets.json | 37 +++++++++++++++++++ README.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++ src/emulator.cpp | 13 +++++++ src/emulator.hpp | 16 ++++++++ src/main.cpp | 13 +++++++ vcpkg.json | 9 +++++ 8 files changed, 266 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 CMakePresets.json create mode 100644 README.md create mode 100644 src/emulator.cpp create mode 100644 src/emulator.hpp create mode 100644 src/main.cpp create mode 100644 vcpkg.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..77486e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# --- Build directories --- +build/ +out/ + +# --- vcpkg installed artifacts (restored from vcpkg.json on configure) --- +vcpkg_installed/ +build/vcpkg_installed/ + +# --- CMake generated / cache files --- +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +compile_commands.json +*.cmake +!CMakeLists.txt +!CMakePresets.json +!CMakeUserPresets.json + +# --- Ninja --- +build.ninja +.ninja_deps +.ninja_log + +# --- vcpkg logs --- +vcpkg-manifest-install.log + +# --- Compiled objects & executables --- +*.obj +*.o +*.a +*.lib +*.exe +*.pdb +*.ilk +*.exp + +# --- IDE / editor --- +.vs/ +.vscode/ +*.user + +# --- OS junk --- +Thumbs.db +desktop.ini +.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a3e7523 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.16) +project(emulator LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) +endif() + +option(EMULATOR_BUILD_TESTS "Build unit tests" OFF) + +find_package(SDL2 REQUIRED) +find_package(SDL2_image REQUIRED) + +add_executable(emulator + src/main.cpp + src/emulator.cpp +) + +target_include_directories(emulator PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +target_link_libraries(emulator PRIVATE + SDL2::SDL2 + SDL2_image::SDL2_image +) + +if(MSVC) + target_compile_options(emulator PRIVATE /W4 /permissive-) +else() + target_compile_options(emulator PRIVATE -Wall -Wextra -Wpedantic) +endif() + +if(EMULATOR_BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..e850599 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,37 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default (vcpkg + MSVC)", + "description": "Configure with vcpkg manifest mode and generate compile_commands.json for IntelliSense", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": { + "type": "BOOL", + "value": "ON" + }, + "CMAKE_TOOLCHAIN_FILE": { + "type": "FILEPATH", + "value": "C:/Program Files (x86)/Microsoft Visual Studio/18/BuildTools/VC/vcpkg/scripts/buildsystems/vcpkg.cmake" + }, + "VCPKG_TARGET_TRIPLET": { + "type": "STRING", + "value": "x64-windows" + } + }, + "generator": "Ninja" + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" + } + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..6967919 --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +# emulator + +A simple emulator built in C++17 using SDL2 for video/audio. It loads a ROM +file from disk, maps it into memory, and runs a fetch/decode/execute loop +rendered to an SDL window. + +## Prerequisites + +- **C++17 compiler** — MSVC (Visual Studio 2019 or 2022 Build Tools) on + Windows. The project is currently configured for the MSVC toolchain. +- **CMake** 3.21 or newer (required for the CMake Presets feature). +- **Ninja** — used as the build generator. +- **vcpkg** — dependencies are declared in `vcpkg.json` (manifest mode), so + vcpkg fetches them automatically on first configure. A working vcpkg + installation must be available on the system. +- **Git** — for cloning and for vcpkg to fetch package sources. + +## Project layout + +``` +. +├── CMakeLists.txt # build definition +├── CMakePresets.json # configure/build presets (vcpkg + MSVC + Ninja) +├── vcpkg.json # dependency manifest (sdl2, sdl2-image) +├── .vscode/ # editor / IntelliSense config +├── src/ +│ ├── main.cpp # entry point: parses argv, runs the emulator +│ ├── emulator.hpp # Emulator class declaration +│ └── emulator.cpp # Emulator class implementation +└── build/ # generated after configure (gitignored) +``` + +## Installation + +1. **Clone the repository** + + ```sh + git clone emulator + cd emulator + ``` + +2. **Ensure vcpkg is installed** + + If you do not already have vcpkg, clone and bootstrap it: + + ```sh + git clone https://github.com/microsoft/vcpkg.git + cd vcpkg + .\bootstrap-vcpkg.bat + ``` + + Note its root path — you will reference it in the next step. + +3. **Point CMake at the vcpkg toolchain** + + `CMakePresets.json` sets `CMAKE_TOOLCHAIN_FILE` to: + + ``` + C:/Program Files (x86)/Microsoft Visual Studio/18/BuildTools/VC/vcpkg/scripts/buildsystems/vcpkg.cmake + ``` + + If your vcpkg lives elsewhere, edit the `default` configure preset + (or create a `CMakeUserPresets.json` next to `CMakePresets.json`) so the + `CMAKE_TOOLCHAIN_FILE` value matches your vcpkg install. + +## Setup & build + +Configure and build with the bundled preset (uses vcpkg manifest mode, so +`sdl2` and `sdl2-image` are installed automatically on first configure): + +```sh +cmake --preset default +cmake --build --preset default +``` + +The resulting executable is placed in `build/` (e.g. `build/emulator.exe`). + +## Running + +Pass a ROM file as the only argument: + +```sh +.\build\emulator.exe +``` + +Press **Esc** or close the window to quit. + +## Editor / IntelliSense + +VS Code IntelliSense is configured in `.vscode/c_cpp_properties.json` to read +`build/compile_commands.json` (generated by the `default` preset). Configure +the project once with `cmake --preset default` so the compile database exists; +IntelliSense will then resolve `SDL.h` and the project headers correctly. diff --git a/src/emulator.cpp b/src/emulator.cpp new file mode 100644 index 0000000..a43b6d2 --- /dev/null +++ b/src/emulator.cpp @@ -0,0 +1,13 @@ +#include "emulator.hpp" + +namespace emu { + +Emulator::Emulator(std::string rom_path) + : rom_path_(std::move(rom_path)) {} + +int Emulator::run() { + // TODO: load ROM from rom_path_ and run the emulator loop + return 0; +} + +} // namespace emu diff --git a/src/emulator.hpp b/src/emulator.hpp new file mode 100644 index 0000000..b768a33 --- /dev/null +++ b/src/emulator.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace emu { + +class Emulator { +public: + explicit Emulator(std::string rom_path); + int run(); + +private: + std::string rom_path_; +}; + +} // namespace emu diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..0f48c25 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,13 @@ +#include + +#include "emulator.hpp" + +int main(int argc, char** argv) { + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } + + emu::Emulator emulator(argv[1]); + return emulator.run(); +} diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..9a95d42 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,9 @@ +{ + "name": "emulator", + "version-string": "0.1.0", + "dependencies": [ + "sdl2", + "sdl2-image" + ], + "builtin-baseline": "544a4c5c297e60e4ac4a5a1810df66748d908869" +}