diff --git a/external/frag.spv b/external/frag.spv new file mode 100644 index 00000000..5a0382be Binary files /dev/null and b/external/frag.spv differ diff --git a/external/parallel-rdp/CMakeLists.txt b/external/parallel-rdp/CMakeLists.txt index fb3bd79d..1646390c 100644 --- a/external/parallel-rdp/CMakeLists.txt +++ b/external/parallel-rdp/CMakeLists.txt @@ -55,13 +55,18 @@ target_include_directories(parallel-rdp PUBLIC parallel-rdp-standalone/vulkan parallel-rdp-standalone/vulkan-headers/include parallel-rdp-standalone/util - ../../src/cores + ../../src/n64 + ../../src/n64/core/ + ../../src/n64/core/cpu/ + ../../src/n64/core/cpu/registers parallel-rdp-standalone .. ../../src/frontend + ../../src ../imgui ../imgui/imgui ../imgui/imgui/backends + . ) if(WIN32) diff --git a/external/parallel-rdp/ParallelRDPWrapper.cpp b/external/parallel-rdp/ParallelRDPWrapper.cpp index 24c4a14b..405ec523 100644 --- a/external/parallel-rdp/ParallelRDPWrapper.cpp +++ b/external/parallel-rdp/ParallelRDPWrapper.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include #include @@ -115,7 +115,7 @@ WSI* LoadWSIPlatform(Vulkan::WSIPlatform* wsi_platform, std::unique_ptrset_backbuffer_srgb(false); wsi->set_platform(wsi_platform); Context::SystemHandles handles; - if (!wsi->init_context_from_platform(1, handles)) { + if (!wsi->init_simple(1, handles)) { util::panic("Failed to initialize WSI!"); } @@ -139,11 +139,11 @@ void LoadParallelRDP(const u8* rdram) { fragLayout.sets[0].fp_mask = 1; fragLayout.sets[0].array_size[0] = 1; - u32* fullscreenQuadVert = nullptr, *fullscreenQuadFrag = nullptr; - util::ReadFileBinary("external/vert.spv", fullscreenQuadVert); - util::ReadFileBinary("external/frag.spv", fullscreenQuadFrag); + u32* fullscreenQuadVert, *fullscreenQuadFrag; + auto sizeVert = util::ReadFileBinary("external/vert.spv", fullscreenQuadVert); + auto sizeFrag = util::ReadFileBinary("external/frag.spv", fullscreenQuadFrag); - fullscreen_quad_program = wsi->get_device().request_program(fullscreenQuadVert, sizeof(fullscreenQuadVert), fullscreenQuadFrag, sizeof(fullscreenQuadFrag), &vertLayout, &fragLayout); + fullscreen_quad_program = wsi->get_device().request_program(fullscreenQuadVert, sizeVert, fullscreenQuadFrag, sizeFrag, &vertLayout, &fragLayout); auto aligned_rdram = reinterpret_cast(rdram); uintptr_t offset = 0; diff --git a/external/parallel-rdp/ParallelRDPWrapper.hpp b/external/parallel-rdp/ParallelRDPWrapper.hpp index ff617917..2422ad92 100644 --- a/external/parallel-rdp/ParallelRDPWrapper.hpp +++ b/external/parallel-rdp/ParallelRDPWrapper.hpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include struct Window; static SDL_Window* window; diff --git a/external/vert.spv b/external/vert.spv new file mode 100644 index 00000000..924cb24d Binary files /dev/null and b/external/vert.spv differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ba572693..2b784f86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED true) add_subdirectory(n64) add_subdirectory(frontend) +find_package(fmt REQUIRED) + add_executable(natsukashii main.cpp) -target_link_libraries(natsukashii PUBLIC frontend n64) +target_link_libraries(natsukashii PUBLIC frontend n64 fmt) target_include_directories(natsukashii PUBLIC . ../external) diff --git a/src/frontend/App.cpp b/src/frontend/App.cpp index 2a256042..cc45b6a9 100644 --- a/src/frontend/App.cpp +++ b/src/frontend/App.cpp @@ -14,11 +14,10 @@ void App::Run() { done = true; } - if(core->initialized) - core->Run(); - if(core->system == System::Nintendo64) { - if(core->initialized) UpdateScreenParallelRdp(window, dynamic_cast(core.get())->GetVI()); - else UpdateScreenParallelRdpNoGame(window); - } + if(core.initialized) + core.Run(); + + if(core.initialized) UpdateScreenParallelRdp(window, core.GetVI()); + else UpdateScreenParallelRdpNoGame(window); } } \ No newline at end of file diff --git a/src/frontend/App.hpp b/src/frontend/App.hpp index 82a08e90..15b24dfd 100644 --- a/src/frontend/App.hpp +++ b/src/frontend/App.hpp @@ -1,11 +1,11 @@ #pragma once -#include +#include #include struct App { App() : window(core) {}; void Run(); private: - std::shared_ptr core; + n64::Core core; Window window; }; diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index f76072f8..6a5e8fe9 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -9,11 +9,14 @@ add_library(frontend target_include_directories(frontend PUBLIC . + .. ../../external ../../external/parallel-rdp ../../external/parallel-rdp/parallel-rdp-standalone/vulkan ../../external/parallel-rdp/parallel-rdp-standalone/util ../../external/parallel-rdp/parallel-rdp-standalone/volk - ../cores - ../cores/n64) + ../n64 + ../n64/core + ../n64/core/cpu + ../n64/core/cpu/registers) target_link_libraries(frontend PUBLIC frontend-imgui) diff --git a/src/frontend/imgui/CMakeLists.txt b/src/frontend/imgui/CMakeLists.txt index 9dbfe1eb..5f106ad8 100644 --- a/src/frontend/imgui/CMakeLists.txt +++ b/src/frontend/imgui/CMakeLists.txt @@ -10,7 +10,11 @@ add_library(frontend-imgui target_include_directories(frontend-imgui PUBLIC . + ../.. ../../n64 + ../../n64/core + ../../n64/core/cpu + ../../n64/core/cpu/registers ../../../external ../../../external/parallel-rdp/parallel-rdp-standalone/vulkan ../../../external/parallel-rdp/parallel-rdp-standalone/util diff --git a/src/frontend/imgui/Window.cpp b/src/frontend/imgui/Window.cpp index eb9b9fd8..c92850e4 100644 --- a/src/frontend/imgui/Window.cpp +++ b/src/frontend/imgui/Window.cpp @@ -6,7 +6,7 @@ #include #include -Window::Window(n64::Core& core) { +Window::Window(const n64::Core& core) { InitSDL(); InitParallelRDP(core.GetRDRAM()); InitImgui(); @@ -191,9 +191,7 @@ void Window::Render() { const nfdu8filteritem_t filter {"Nintendo 64 roms", "n64,z64,v64,N64,Z64,V64"}; nfdresult_t result = NFD_OpenDialog(&outpath, &filter, 1, nullptr); if(result == NFD_OKAY) { - core = std::make_shared(outpath); - core->initialized = true; - core->system = System::Nintendo64; + core.LoadROM(outpath); NFD_FreePath(outpath); } } diff --git a/src/frontend/imgui/Window.hpp b/src/frontend/imgui/Window.hpp index 07ac6201..9e928358 100644 --- a/src/frontend/imgui/Window.hpp +++ b/src/frontend/imgui/Window.hpp @@ -10,7 +10,7 @@ #include struct Window { - explicit Window(n64::Core& core); + explicit Window(const n64::Core& core); ~Window(); ImDrawData* Present(); diff --git a/src/main.cpp b/src/main.cpp index 8e21934f..f02f66cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include int main() { - App app; - app.Run(); + App* app = new App; + app->Run(); return 0; } \ No newline at end of file diff --git a/src/n64/Core.cpp b/src/n64/Core.cpp index ecbe7ad4..c12d8ec3 100644 --- a/src/n64/Core.cpp +++ b/src/n64/Core.cpp @@ -2,8 +2,9 @@ #include namespace n64 { -Core::Core(const std::string& rom) { +void Core::LoadROM(const std::string& rom) { mem.LoadROM(rom); + initialized = true; } void Core::Run() { diff --git a/src/n64/Core.hpp b/src/n64/Core.hpp index f31fd79d..def143e7 100644 --- a/src/n64/Core.hpp +++ b/src/n64/Core.hpp @@ -6,11 +6,13 @@ namespace n64 { struct Core { ~Core() = default; - explicit Core(const std::string&); + Core() = default; + void LoadROM(const std::string&); void Run(); void PollInputs(u32); VI& GetVI() { return mem.mmio.vi; } - const u8* GetRDRAM() { return mem.rdram.data(); } + const u8* GetRDRAM() const { return mem.rdram.data(); } + bool initialized = false; private: Mem mem; Cpu cpu; diff --git a/src/n64/core/Cpu.hpp b/src/n64/core/Cpu.hpp index c4bdcf91..1b95abd8 100644 --- a/src/n64/core/Cpu.hpp +++ b/src/n64/core/Cpu.hpp @@ -1,6 +1,6 @@ #pragma once -#include -#include +#include +#include namespace n64 { struct Cpu { diff --git a/src/n64/core/cpu/CMakeLists.txt b/src/n64/core/cpu/CMakeLists.txt index 8df0f3bf..e8065672 100644 --- a/src/n64/core/cpu/CMakeLists.txt +++ b/src/n64/core/cpu/CMakeLists.txt @@ -13,5 +13,9 @@ add_library(cpu registers/cop1instructions.cpp instructions.cpp) -target_include_directories(cpu PUBLIC registers . .. ../../ - ../../../../../external ../../../) +target_include_directories(cpu PUBLIC registers + . .. + ../../../../external + ../../../../src + ../../ +) diff --git a/src/n64/core/cpu/Registers.hpp b/src/n64/core/cpu/Registers.hpp index b7c26e7e..dccb5b31 100644 --- a/src/n64/core/cpu/Registers.hpp +++ b/src/n64/core/cpu/Registers.hpp @@ -1,6 +1,6 @@ #pragma once -#include -#include +#include +#include namespace n64 { struct Registers { diff --git a/src/util.hpp b/src/util.hpp index 84b3dc73..3a2b20d5 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace util { enum MessageType : u8 { @@ -145,20 +146,20 @@ inline size_t NextPow2(size_t num) { return num + 1; } -inline void ReadFileBinary(const std::string& path, void* buf) { - std::ifstream file("external/vert.spv", std::ios::binary); +inline auto ReadFileBinary(const std::string& path, u32* buf) { + std::ifstream file(path, std::ios::binary); file.unsetf(std::ios::skipws); if(!file.is_open()) { util::panic("Could not load file!\n"); } - file.seekg(std::ios::end); - auto size = file.tellg(); - file.seekg(std::ios::beg); - if(buf) - free(buf); - buf = calloc(size, 1); - file.read((char*)buf, size); + file.seekg(0, std::ios::end); + size_t size = file.tellg(); + file.seekg(0, std::ios::beg); + + buf = (u32*)calloc(size, 1); + file.read(reinterpret_cast(buf), size); file.close(); + return size; } } \ No newline at end of file