From 23478340d231d96df18463548982863810abe397 Mon Sep 17 00:00:00 2001 From: Ry Date: Wed, 26 Oct 2022 16:55:11 -0700 Subject: [PATCH] Use absolute mouse position instead of grabbing the cursor --- src/main.c | 2 ++ src/mmu.c | 2 +- src/mouse.c | 6 +++--- src/screen.c | 37 ++++++------------------------------- 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/main.c b/src/main.c index a96998f..37d36ef 100644 --- a/src/main.c +++ b/src/main.c @@ -42,6 +42,8 @@ int main(int argc, char *argv[]) { return 1; } + SDL_ShowCursor(SDL_DISABLE); + fox32_init(&vm); vm.io_read = bus_io_read; vm.io_write = bus_io_write; diff --git a/src/mmu.c b/src/mmu.c index 4cf3ec3..ddcdcd2 100644 --- a/src/mmu.c +++ b/src/mmu.c @@ -24,7 +24,7 @@ static size_t find_free_tlb_entry_index() { } } - return (replacement_index++)&63; + return (replacement_index++) & 63; } void set_and_flush_tlb(uint32_t virtual_address) { diff --git a/src/mouse.c b/src/mouse.c index 7f22c79..26a7916 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -13,9 +13,9 @@ mouse_t mouse; -void mouse_moved(int dx, int dy) { - mouse.x += dx; - mouse.y += dy; +void mouse_moved(int x, int y) { + mouse.x = x; + mouse.y = y; if (mouse.x > 0x8000) mouse.x = 0; if (mouse.x > 640) mouse.x = 640; diff --git a/src/screen.c b/src/screen.c index 3a300e1..f42e0aa 100644 --- a/src/screen.c +++ b/src/screen.c @@ -9,20 +9,15 @@ #include "screen.h" -#define WINDOW_TITLE_UNGRABBED "fox32 emulator" -#define WINDOW_TITLE_GRABBED "fox32 emulator - strike F1 to uncapture mouse" +#define SCREEN_ZOOM 1 struct Screen MainScreen; int WindowWidth = 0; int WindowHeight = 0; -int ScreenZoom = 1; - bool ScreenFirstDraw = true; -bool ScreenMouseGrabbed = false; - SDL_Window *ScreenWindow; SDL_Renderer *ScreenRenderer; @@ -30,10 +25,10 @@ SDL_Rect WindowRect; void ScreenInit() { ScreenWindow = SDL_CreateWindow( - WINDOW_TITLE_UNGRABBED, + "fox32 emulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - (int)(WindowWidth * ScreenZoom), - (int)(WindowHeight * ScreenZoom), + (int)(WindowWidth * SCREEN_ZOOM), + (int)(WindowHeight * SCREEN_ZOOM), SDL_WINDOW_HIDDEN ); @@ -109,23 +104,12 @@ int ScreenProcessEvents() { } case SDL_MOUSEMOTION: { - if (ScreenMouseGrabbed) { - if (MainScreen.MouseMoved) - MainScreen.MouseMoved(event.motion.xrel, event.motion.yrel); - } + if (MainScreen.MouseMoved) + MainScreen.MouseMoved(event.motion.x, event.motion.y); break; } case SDL_MOUSEBUTTONDOWN: { - if (!ScreenMouseGrabbed) { - SDL_SetWindowGrab(ScreenWindow, true); - SDL_ShowCursor(false); - SDL_SetWindowTitle(ScreenWindow, WINDOW_TITLE_GRABBED); - SDL_SetRelativeMouseMode(true); - ScreenMouseGrabbed = true; - break; - } - if (MainScreen.MousePressed) MainScreen.MousePressed(event.button.button); break; @@ -139,15 +123,6 @@ int ScreenProcessEvents() { } case SDL_KEYDOWN: - if ((event.key.keysym.scancode == SDL_SCANCODE_F1) && ScreenMouseGrabbed) { - SDL_SetWindowGrab(ScreenWindow, false); - SDL_ShowCursor(true); - SDL_SetWindowTitle(ScreenWindow, WINDOW_TITLE_UNGRABBED); - SDL_SetRelativeMouseMode(false); - ScreenMouseGrabbed = false; - break; - } - if (MainScreen.KeyPressed) MainScreen.KeyPressed(event.key.keysym.scancode); break;