ditch multi-system idea

This commit is contained in:
CocoSimone
2022-08-06 11:19:45 +02:00
parent ef29e4797c
commit c5303ede59
58 changed files with 74 additions and 82 deletions

View File

@@ -4,4 +4,4 @@
[![CodeFactor](https://www.codefactor.io/repository/github/cocosimone/natsukashii/badge/master)](https://www.codefactor.io/repository/github/cocosimone/natsukashii/overview/master)
[![build](https://github.com/CocoSimone/natsukashii/actions/workflows/build.yml/badge.svg)](https://github.com/CocoSimone/natsukashii/actions/workflows/build.yml)
Multi-system emulator in its infancy
Rewrite of my Nintendo 64 emulator "[shibumi](https://github.com/CocoSimone/shibumi)".

View File

@@ -12,6 +12,7 @@ using namespace RDP;
static CommandProcessor* command_processor;
static WSI* wsi;
static std::unique_ptr<ParallelRdpWindowInfo> windowInfo;
std::vector<Semaphore> acquire_semaphore;
@@ -109,14 +110,17 @@ public:
Program* fullscreen_quad_program;
void LoadWSIPlatform() {
WSI* LoadWSIPlatform(Vulkan::WSIPlatform* wsi_platform, std::unique_ptr<ParallelRdpWindowInfo>&& newWindowInfo) {
wsi = new WSI();
wsi->set_backbuffer_srgb(false);
wsi->set_platform(new SDLWSIPlatform());
wsi->set_platform(wsi_platform);
Context::SystemHandles handles;
if (!wsi->init_context_from_platform(1, handles)) {
util::panic("Failed to initialize WSI!");
}
windowInfo = std::move(newWindowInfo);
return wsi;
}
void LoadParallelRDP(const u8* rdram) {
@@ -161,6 +165,11 @@ void LoadParallelRDP(const u8* rdram) {
}
}
void InitParallelRDP(const u8* rdram) {
LoadWSIPlatform(new SDLWSIPlatform(), std::make_unique<SDLParallelRdpWindowInfo>());
LoadParallelRDP(rdram);
}
void DrawFullscreenTexturedQuad(Util::IntrusivePtr<Image> image, Util::IntrusivePtr<CommandBuffer> cmd) {
cmd->set_texture(0, 0, image->get_view(), Vulkan::StockSampler::LinearClamp);
cmd->set_program(fullscreen_quad_program);

View File

@@ -1,12 +1,30 @@
#pragma once
#include <n64/Core.hpp>
#include <Core.hpp>
#include <wsi.hpp>
#include <SDL2/SDL.h>
#include <n64/core/mmio/VI.hpp>
struct Window;
static SDL_Window* window;
class ParallelRdpWindowInfo {
public:
struct CoordinatePair {
int x;
int y;
};
virtual CoordinatePair get_window_size() = 0;
virtual ~ParallelRdpWindowInfo() = default;
};
class SDLParallelRdpWindowInfo : public ParallelRdpWindowInfo {
CoordinatePair get_window_size() {
int width, height;
SDL_GetWindowSize(window, &width, &height);
return CoordinatePair{ width, height };
}
};
static u32 windowID;
VkQueue GetGraphicsQueue();
VkInstance GetVkInstance();
@@ -16,11 +34,10 @@ uint32_t GetVkGraphicsQueueFamily();
VkFormat GetVkFormat();
VkCommandBuffer GetVkCommandBuffer();
void SubmitRequestedVkCommandBuffer();
void LoadWSIPlatform();
void LoadParallelRDP(const u8* rdram);
void InitParallelRDP(const u8* rdram);
void UpdateScreenParallelRdp(Window& imguiWindow, const n64::VI& vi);
void ParallelRdpEnqueueCommand(int command_length, u32* buffer);
void ParallelRdpOnFullSync();
void UpdateScreenParallelRdpNoGame(Window& imguiWindow);
bool IsFramerateUnlocked();
void SetFramerateUnlocked(bool unlocked);
void SetFramerateUnlocked(bool unlocked);

View File

@@ -3,10 +3,10 @@ project(natsukashii)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED true)
add_subdirectory(cores)
add_subdirectory(n64)
add_subdirectory(frontend)
add_executable(natsukashii main.cpp)
target_link_libraries(natsukashii PUBLIC frontend cores)
target_link_libraries(natsukashii PUBLIC frontend n64)
target_include_directories(natsukashii PUBLIC . ../external)

View File

@@ -1,17 +0,0 @@
#pragma once
#include <common.hpp>
enum class System {
GameBoy, Nintendo64
};
struct BaseCore {
virtual ~BaseCore() = default;
virtual void Run() {};
virtual void PollInputs(u32) {};
[[nodiscard]] bool& ShouldQuit() { return quit; }
bool initialized = false;
System system;
private:
bool quit = false;
};

View File

@@ -1,14 +0,0 @@
cmake_minimum_required(VERSION 3.20)
project(cores CXX)
add_subdirectory(n64)
find_package(fmt REQUIRED)
add_library(cores
common.hpp
util.hpp
BaseCore.hpp)
target_link_libraries(cores PUBLIC fmt::fmt n64)
target_include_directories(cores PUBLIC . ../../external)

View File

@@ -1,18 +0,0 @@
#pragma once
#include <BaseCore.hpp>
#include <n64/core/Cpu.hpp>
#include <n64/core/Mem.hpp>
#include <string>
namespace n64 {
struct Core : BaseCore {
~Core() override = default;
explicit Core(const std::string&);
void Run() override;
void PollInputs(u32) override;
VI& GetVI() { return mem.mmio.vi; }
private:
Mem mem;
Cpu cpu;
};
}

View File

@@ -10,7 +10,7 @@ add_library(frontend-imgui
target_include_directories(frontend-imgui PUBLIC
.
../../cores
../../n64
../../../external
../../../external/parallel-rdp/parallel-rdp-standalone/vulkan
../../../external/parallel-rdp/parallel-rdp-standalone/util

View File

@@ -1,14 +1,14 @@
#include <Window.hpp>
#include <util.hpp>
#include <nfd.hpp>
#include <n64/Core.hpp>
#include <Core.hpp>
#include <parallel-rdp/parallel-rdp-standalone/volk/volk.h>
#include <parallel-rdp/ParallelRDPWrapper.hpp>
#include <utility>
Window::Window(std::shared_ptr<BaseCore> core) : core(std::move(core)) {
Window::Window(n64::Core& core) {
InitSDL();
LoadWSIPlatform();
InitParallelRDP(core.GetRDRAM());
InitImgui();
}

View File

@@ -6,11 +6,11 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_vulkan.h>
#include <vulkan/vulkan.h>
#include <BaseCore.hpp>
#include <Core.hpp>
#include <vector>
struct Window {
explicit Window(std::shared_ptr<BaseCore> core);
explicit Window(n64::Core& core);
~Window();
ImDrawData* Present();
@@ -20,7 +20,7 @@ struct Window {
&& event.window.windowID == SDL_GetWindowID(window);
}
private:
std::shared_ptr<BaseCore> core;
n64::Core core;
void InitSDL();
void InitImgui();
void Render();

View File

@@ -8,10 +8,10 @@ add_library(n64
Core.hpp
memory_regions.hpp)
target_link_libraries(n64 PUBLIC n64-core)
target_link_libraries(n64 PUBLIC core)
target_include_directories(n64 PUBLIC
.
..
../../../external
../../../external/imgui/imgui
../../../external/imgui/imgui/backends)
../../external
../../external/imgui/imgui
../../external/imgui/imgui/backends)

View File

@@ -1,11 +1,9 @@
#include <Core.hpp>
#include <SDL2/SDL_events.h>
#include "parallel-rdp/ParallelRDPWrapper.hpp"
namespace n64 {
Core::Core(const std::string& rom) {
mem.LoadROM(rom);
LoadParallelRDP(mem.GetRDRAM());
}
void Core::Run() {
@@ -28,6 +26,5 @@ void Core::Run() {
void Core::PollInputs(u32 windowID) {
SDL_Event event;
SDL_PollEvent(&event);
ShouldQuit() = event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == windowID;
}
}

18
src/n64/Core.hpp Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include <Cpu.hpp>
#include <Mem.hpp>
#include <string>
namespace n64 {
struct Core {
~Core() = default;
explicit Core(const std::string&);
void Run();
void PollInputs(u32);
VI& GetVI() { return mem.mmio.vi; }
const u8* GetRDRAM() { return mem.rdram.data(); }
private:
Mem mem;
Cpu cpu;
};
}

View File

@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.20)
project(n64-core)
project(core)
add_subdirectory(cpu)
add_subdirectory(../../../../external/parallel-rdp temp)
add_subdirectory(../../../external/parallel-rdp temp)
add_library(n64-core
add_library(core
Cpu.hpp
Cpu.cpp
Mem.cpp
@@ -37,13 +37,13 @@ add_library(n64-core
rsp/decode.cpp
rsp/instructions.cpp)
target_include_directories(n64-core PUBLIC
target_include_directories(core PUBLIC
.
..
../..
../../../../external
../../../external
../../../external/imgui/imgui
../../../external/imgui/imgui/backends
mmio)
target_link_libraries(n64-core PUBLIC n64-cpu parallel-rdp)
target_link_libraries(core PUBLIC cpu parallel-rdp)

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20)
project(n64-cpu)
project(cpu)
add_library(n64-cpu
add_library(cpu
Registers.cpp
Registers.hpp
registers/Cop0.cpp
@@ -13,5 +13,5 @@ add_library(n64-cpu
registers/cop1instructions.cpp
instructions.cpp)
target_include_directories(n64-cpu PUBLIC registers . .. ../../
target_include_directories(cpu PUBLIC registers . .. ../../
../../../../../external ../../../)