From 8c97be36194a9621fd9a2456100e12ad1378f65e Mon Sep 17 00:00:00 2001 From: CocoSimone Date: Tue, 20 Sep 2022 23:02:05 +0200 Subject: [PATCH] PIF fixes + implement drag and drop --- src/frontend/App.cpp | 10 +++++++++- src/n64/Core.cpp | 26 ++++++++++++++------------ src/n64/core/mmio/PIF.cpp | 7 ++----- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/frontend/App.cpp b/src/frontend/App.cpp index a7829746..e8752078 100644 --- a/src/frontend/App.cpp +++ b/src/frontend/App.cpp @@ -5,9 +5,10 @@ void App::Run() { // Main loop const u8* state = SDL_GetKeyboardState(nullptr); + SDL_EventState(SDL_DROPFILE, SDL_ENABLE); while (!core.done) { - core.Run(window, window.volumeL, window.volumeR); core.UpdateController(state); + core.Run(window, window.volumeL, window.volumeR); SDL_Event event; while (SDL_PollEvent(&event)) { @@ -38,6 +39,13 @@ void App::Run() { } } break; } break; + case SDL_DROPFILE: { + char* droppedDir = event.drop.file; + if(droppedDir) { + LoadROM(droppedDir); + } + free(droppedDir); + } break; } } } diff --git a/src/n64/Core.cpp b/src/n64/Core.cpp index 9e0be83d..9bef20bd 100644 --- a/src/n64/Core.cpp +++ b/src/n64/Core.cpp @@ -70,12 +70,8 @@ void Core::Run(Window& window, float volumeL, float volumeR) { void Core::UpdateController(const u8* state) { Controller& controller = mem.mmio.si.controller; + controller.raw = 0; if(gamepadConnected) { - controller.b1 = 0; - controller.b2 = 0; - controller.b3 = 0; - controller.b4 = 0; - bool A = GET_BUTTON(gamepad, SDL_CONTROLLER_BUTTON_A); bool B = GET_BUTTON(gamepad, SDL_CONTROLLER_BUTTON_X); bool Z = GET_AXIS(gamepad, SDL_CONTROLLER_AXIS_TRIGGERLEFT) == 32767; @@ -109,11 +105,6 @@ void Core::UpdateController(const u8* state) { controller.b4 = 0; } } else { - controller.b1 = 0; - controller.b2 = 0; - controller.b3 = 0; - controller.b4 = 0; - controller.b1 = (state[SDL_SCANCODE_X] << 7) | (state[SDL_SCANCODE_C] << 6) | @@ -133,8 +124,19 @@ void Core::UpdateController(const u8* state) { (state[SDL_SCANCODE_K] << 1) | (state[SDL_SCANCODE_L]); - s8 xaxis = state[SDL_SCANCODE_LEFT] ? -128 : (state[SDL_SCANCODE_RIGHT] ? 127 : 0); - s8 yaxis = state[SDL_SCANCODE_DOWN] ? -128 : (state[SDL_SCANCODE_UP] ? 127 : 0); + s8 xaxis = 0; + if(state[SDL_SCANCODE_LEFT]) { + xaxis = -128; + } else if(state[SDL_SCANCODE_RIGHT]) { + xaxis = 127; + } + + s8 yaxis = 0; + if(state[SDL_SCANCODE_DOWN]) { + yaxis = -128; + } else if(state[SDL_SCANCODE_UP]) { + yaxis = 127; + } controller.b3 = xaxis; controller.b4 = yaxis; diff --git a/src/n64/core/mmio/PIF.cpp b/src/n64/core/mmio/PIF.cpp index 370dfe9b..8e8ed849 100644 --- a/src/n64/core/mmio/PIF.cpp +++ b/src/n64/core/mmio/PIF.cpp @@ -52,7 +52,6 @@ void ProcessPIFCommands(u8* pifRam, Controller& controller, Mem& mem) { } i += t + rlen; - channel++; } } } @@ -61,11 +60,9 @@ void ProcessPIFCommands(u8* pifRam, Controller& controller, Mem& mem) { pifRam[63] &= ~8; } - if(control & 48) { - pifRam[63] = 128; + if (control & 0x30) { + pifRam[63] = 0x80; } - - //pifRam[63] &= ~1; } } \ No newline at end of file