From ae3034065d36006c30762e9e7e618b7640e988b5 Mon Sep 17 00:00:00 2001 From: Braiden Gent Date: Mon, 15 Apr 2024 01:22:45 -0700 Subject: [PATCH] load files from command line --- CMakeLists.txt | 6 +++--- src/addressSpace.cpp | 11 +++++++++-- src/main.cpp | 7 ++++++- src/ppu.cpp | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6c873c..bd46da3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 3.25) -project(GBpp) +project(GameBoy++) set(CMAKE_CXX_STANDARD 23) find_package(SDL2 REQUIRED) include_directories(${SDL2_INCLUDE_DIRS}) -add_executable(GBpp src/main.cpp +add_executable(GameBoy++ src/main.cpp src/gameboy.cpp src/opcodeResolver.cpp src/interupts.cpp @@ -18,4 +18,4 @@ add_executable(GBpp src/main.cpp src/testing.hpp src/joypad.cpp ) -target_link_libraries(GBpp ${SDL2_LIBRARIES}) \ No newline at end of file +target_link_libraries(GameBoy++ ${SDL2_LIBRARIES}) \ No newline at end of file diff --git a/src/addressSpace.cpp b/src/addressSpace.cpp index f2c60aa..6f2e4f7 100644 --- a/src/addressSpace.cpp +++ b/src/addressSpace.cpp @@ -16,11 +16,18 @@ void AddressSpace::mapBootrom() { void AddressSpace::loadBootrom(const std::string& filename) { std::ifstream file; - if (const uintmax_t size = std::filesystem::file_size(filename); size != 256) { + file.open(filename, std::ios::binary); + + if (!file.is_open()) { + std::cerr << "Bootrom was not found!\nQuitting!\n" << std::endl; + exit(1); + } + + const uintmax_t size = std::filesystem::file_size(filename); + if (size != 256) { std::cerr << "Bootrom was an unexpected size!\nQuitting!\n" << std::endl; exit(1); } - file.open(filename, std::ios::binary); file.read(reinterpret_cast(bootrom), BOOTROM_SIZE); } diff --git a/src/main.cpp b/src/main.cpp index ab9e09d..aeed7eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,10 +10,15 @@ using json = nlohmann::json; void runJSONTests(GameBoy* gb); int main(int argc, char** argv) { + if (argc != 3) { + std::cout << "Usage: " << argv[0] << " " << std::endl; + return -1; + } + auto* gb = new GameBoy(); gb->SDL2setup(); //runJSONTests(gb); - gb->start("../dmg_boot.bin", "../roms/DrMario.gb"); + gb->start(argv[1], argv[2]); gb->SDL2destroy(); delete gb; diff --git a/src/ppu.cpp b/src/ppu.cpp index 5c128f6..73b9c3f 100644 --- a/src/ppu.cpp +++ b/src/ppu.cpp @@ -352,7 +352,7 @@ void GameBoy::drawLine() { void GameBoy::SDL2setup() { SDL_Init(SDL_INIT_EVERYTHING); - screen = SDL_CreateWindow("GBpp", + screen = SDL_CreateWindow("GameBoy++", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESOLUTION_X, RESOLUTION_Y, 0);