mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
Bonk frontend changes
This commit is contained in:
parent
6ce861624d
commit
de2751fb5c
5 changed files with 149 additions and 140 deletions
|
@ -47,7 +47,7 @@ class Emulator {
|
|||
static constexpr u32 width = 400;
|
||||
static constexpr u32 height = 240 * 2; // * 2 because 2 screens
|
||||
ROMType romType = ROMType::None;
|
||||
bool running = true, romLoaded = false;
|
||||
bool running = true;
|
||||
|
||||
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
||||
HttpServer httpServer;
|
||||
|
@ -64,7 +64,6 @@ class Emulator {
|
|||
Emulator();
|
||||
~Emulator();
|
||||
|
||||
void stop();
|
||||
void step();
|
||||
void render();
|
||||
void reset();
|
||||
|
|
|
@ -22,7 +22,6 @@ enum class GPUInterrupt : u8 {
|
|||
class Kernel;
|
||||
|
||||
class GPUService {
|
||||
bool registerInterruptRelayQueueBeenHere = false;
|
||||
Handle handle = KernelHandles::GPU;
|
||||
Memory& mem;
|
||||
GPU& gpu;
|
||||
|
@ -35,6 +34,9 @@ class GPUService {
|
|||
u32 privilegedProcess;
|
||||
std::optional<Handle> interruptEvent;
|
||||
|
||||
// Number of threads registers via RegisterInterruptRelayQueue
|
||||
u32 gspThreadCount = 0;
|
||||
|
||||
MAKE_LOG_FUNCTION(log, gspGPULogger)
|
||||
void processCommandBuffer();
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ namespace GXCommands {
|
|||
void GPUService::reset() {
|
||||
privilegedProcess = 0xFFFFFFFF; // Set the privileged process to an invalid handle
|
||||
interruptEvent = std::nullopt;
|
||||
gspThreadCount = 0;
|
||||
sharedMem = nullptr;
|
||||
registerInterruptRelayQueueBeenHere = false;
|
||||
}
|
||||
|
||||
void GPUService::handleSyncRequest(u32 messagePointer) {
|
||||
|
@ -78,8 +78,10 @@ void GPUService::acquireRight(u32 messagePointer) {
|
|||
// How does the shared memory handle thing work?
|
||||
void GPUService::registerInterruptRelayQueue(u32 messagePointer) {
|
||||
// Detect if this function is called a 2nd time because we'll likely need to impl threads properly for the GSP
|
||||
if (registerInterruptRelayQueueBeenHere) Helpers::panic("RegisterInterruptRelayQueue called a second time. Need to implement GSP threads properly");
|
||||
registerInterruptRelayQueueBeenHere = true;
|
||||
if (gspThreadCount >= 1) {
|
||||
Helpers::panic("RegisterInterruptRelayQueue called a second time. Need to implement GSP threads properly");
|
||||
}
|
||||
gspThreadCount += 1;
|
||||
|
||||
const u32 flags = mem.read32(messagePointer + 4);
|
||||
const u32 eventHandle = mem.read32(messagePointer + 12);
|
||||
|
|
|
@ -53,13 +53,12 @@ Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory
|
|||
}
|
||||
|
||||
config.load(std::filesystem::current_path() / "config.toml");
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
Emulator::~Emulator() { config.save(std::filesystem::current_path() / "config.toml"); }
|
||||
|
||||
void Emulator::stop() {
|
||||
void Emulator::reset() {
|
||||
cpu.reset();
|
||||
gpu.reset();
|
||||
memory.reset();
|
||||
|
@ -69,9 +68,7 @@ void Emulator::stop() {
|
|||
// Reloading r13 and r15 needs to happen after everything has been reset
|
||||
// Otherwise resetting the kernel or cpu might nuke them
|
||||
cpu.setReg(13, VirtualAddrs::StackTop); // Set initial SP
|
||||
}
|
||||
|
||||
void Emulator::reset() {
|
||||
// If a ROM is active and we reset, reload it. This is necessary to set up stack, executable memory, .data/.rodata/.bss all over again
|
||||
if (romType != ROMType::None && romPath.has_value()) {
|
||||
bool success = loadROM(romPath.value());
|
||||
|
@ -91,9 +88,11 @@ void Emulator::run() {
|
|||
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
||||
httpServer.startHttpServer();
|
||||
#endif
|
||||
|
||||
while (running) {
|
||||
ServiceManager& srv = kernel.getServiceManager();
|
||||
if(romLoaded) {
|
||||
|
||||
if (romType != ROMType::None) {
|
||||
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
||||
pollHttpServer();
|
||||
#endif
|
||||
|
@ -104,6 +103,7 @@ void Emulator::run() {
|
|||
srv.sendGPUInterrupt(GPUInterrupt::VBlank0);
|
||||
srv.sendGPUInterrupt(GPUInterrupt::VBlank1);
|
||||
}
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
namespace Keys = HID::Keys;
|
||||
|
@ -115,7 +115,8 @@ void Emulator::run() {
|
|||
return;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
if(romLoaded) {
|
||||
if (romType == ROMType::None) break;
|
||||
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_l: srv.pressKey(Keys::A); break;
|
||||
case SDLK_k: srv.pressKey(Keys::B); break;
|
||||
|
@ -153,11 +154,11 @@ void Emulator::run() {
|
|||
case SDLK_RETURN: srv.pressKey(Keys::Start); break;
|
||||
case SDLK_BACKSPACE: srv.pressKey(Keys::Select); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
if(romLoaded) {
|
||||
if (romType == ROMType::None) break;
|
||||
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_l: srv.releaseKey(Keys::A); break;
|
||||
case SDLK_k: srv.releaseKey(Keys::B); break;
|
||||
|
@ -188,11 +189,11 @@ void Emulator::run() {
|
|||
case SDLK_RETURN: srv.releaseKey(Keys::Start); break;
|
||||
case SDLK_BACKSPACE: srv.releaseKey(Keys::Select); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if(romLoaded) {
|
||||
if (romType == ROMType::None) break;
|
||||
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
const s32 x = event.button.x;
|
||||
const s32 y = event.button.y;
|
||||
|
@ -210,17 +211,17 @@ void Emulator::run() {
|
|||
} else if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||
holdingRightClick = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if(romLoaded) {
|
||||
if (romType == ROMType::None) break;
|
||||
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
srv.releaseTouchScreen();
|
||||
} else if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||
holdingRightClick = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
|
@ -239,8 +240,8 @@ void Emulator::run() {
|
|||
break;
|
||||
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
if(romLoaded) {
|
||||
case SDL_CONTROLLERBUTTONDOWN: {
|
||||
if (romType == ROMType::None) break;
|
||||
u32 key = 0;
|
||||
|
||||
switch (event.cbutton.button) {
|
||||
|
@ -265,14 +266,13 @@ void Emulator::run() {
|
|||
srv.releaseKey(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Detect mouse motion events for gyroscope emulation
|
||||
case SDL_MOUSEMOTION:
|
||||
if(romLoaded) {
|
||||
case SDL_MOUSEMOTION: {
|
||||
// We use right click to indicate we want to rotate the console. If right click is not held, then this is not a gyroscope rotation
|
||||
if (!holdingRightClick) break;
|
||||
if (romType == ROMType::None || !holdingRightClick) break;
|
||||
|
||||
// Relative motion since last mouse motion event
|
||||
const s32 motionX = event.motion.xrel;
|
||||
|
@ -284,21 +284,23 @@ void Emulator::run() {
|
|||
const s32 pitch = motionY > 0 ? 0x7f : -0x7f;
|
||||
srv.setRoll(roll);
|
||||
srv.setPitch(pitch);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_DROPFILE: {
|
||||
char* droppedDir = event.drop.file;
|
||||
|
||||
if (droppedDir) {
|
||||
loadROM(droppedDir);
|
||||
SDL_free(droppedDir);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(romLoaded) {
|
||||
// Update controller analog sticks and HID service
|
||||
if (romType != ROMType::None) {
|
||||
if (gameController != nullptr) {
|
||||
const s16 stickX = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTX);
|
||||
const s16 stickY = SDL_GameControllerGetAxis(gameController, SDL_CONTROLLER_AXIS_LEFTY);
|
||||
|
@ -319,6 +321,7 @@ void Emulator::run() {
|
|||
srv.setCirclepadY(-(stickY / div));
|
||||
}
|
||||
}
|
||||
|
||||
srv.updateInputs(cpu.getTicks());
|
||||
}
|
||||
|
||||
|
@ -330,7 +333,11 @@ void Emulator::run() {
|
|||
void Emulator::runFrame() { cpu.runFrame(); }
|
||||
|
||||
bool Emulator::loadROM(const std::filesystem::path& path) {
|
||||
stop();
|
||||
// Reset the emulator if we've already loaded a ROM
|
||||
if (romType != ROMType::None) {
|
||||
reset();
|
||||
}
|
||||
|
||||
// Get path for saving files (AppData on Windows, /home/user/.local/share/ApplcationName on Linux, etc)
|
||||
// Inside that path, we be use a game-specific folder as well. Eg if we were loading a ROM called PenguinDemo.3ds, the savedata would be in
|
||||
// %APPDATA%/Alber/PenguinDemo/SaveData on Windows, and so on. We do this because games save data in their own filesystem on the cart
|
||||
|
@ -370,7 +377,6 @@ bool Emulator::loadROM(const std::filesystem::path& path) {
|
|||
romType = ROMType::None;
|
||||
}
|
||||
|
||||
romLoaded = success;
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -433,9 +439,7 @@ void Emulator::pollHttpServer() {
|
|||
|
||||
if (httpServer.pendingAction) {
|
||||
switch (httpServer.action) {
|
||||
case HttpAction::Screenshot:
|
||||
gpu.screenshot(HttpServer::httpServerScreenshotPath);
|
||||
break;
|
||||
case HttpAction::Screenshot: gpu.screenshot(HttpServer::httpServerScreenshotPath); break;
|
||||
|
||||
case HttpAction::PressKey:
|
||||
if (httpServer.pendingKey != 0) {
|
||||
|
|
|
@ -11,6 +11,8 @@ int main (int argc, char *argv[]) {
|
|||
// For some reason just .c_str() doesn't show the proper path
|
||||
Helpers::panic("Failed to load ROM file: %s", romPath.string().c_str());
|
||||
}
|
||||
} else {
|
||||
printf("No ROM inserted! Load a ROM by dragging and dropping it into the emulator window!\n");
|
||||
}
|
||||
|
||||
emu.run();
|
||||
|
|
Loading…
Add table
Reference in a new issue