diff --git a/include/scc.h b/include/scc.h index 1817d4f..c78fe08 100644 --- a/include/scc.h +++ b/include/scc.h @@ -35,6 +35,8 @@ void scc_write(unsigned int address, uint8_t data); uint8_t scc_read(unsigned int address); /* Set a new state for the DCD pins: */ void scc_set_dcd(int a, int b); +/* check if scc master interrupt is enabled */ +int scc_get_mie(); #endif diff --git a/include/umac.h b/include/umac.h index 024a174..c5b6f2b 100644 --- a/include/umac.h +++ b/include/umac.h @@ -34,6 +34,7 @@ int umac_loop(void); void umac_reset(void); void umac_opt_disassemble(int enable); void umac_mouse(int deltax, int deltay, int button); +void umac_absmouse(int x, int y, int button); void umac_kbd_event(uint8_t scancode, int down); static inline void umac_vsync_event(void) diff --git a/src/main.c b/src/main.c index f9074fa..14e6b44 100644 --- a/src/main.c +++ b/src/main.c @@ -619,13 +619,39 @@ void umac_opt_disassemble(int enable) * * X is positive going right; Y is positive going upwards. */ -void umac_mouse(int deltax, int deltay, int button) +void umac_absmouse(int x, int y, int button) { + if (!scc_get_mie()) return; #define MTemp_h 0x82a #define MTemp_v 0x828 #define CrsrNew 0x8ce #define CrsrCouple 0x8cf + int oldx = RAM_RD16(MTemp_h); + int oldy = RAM_RD16(MTemp_v); + + if(x != oldx) { + RAM_WR16(MTemp_h, x); + } + + if (y != oldy) { + RAM_WR16(MTemp_v, y); + } + + if(x != oldx || y != oldy) { + RAM_WR8(CrsrNew, RAM_RD8(CrsrCouple)); + } + + via_mouse_pressed = button; +} + +/* Provide mouse input (movement, button) data. + * + * X is positive going right; Y is positive going upwards. + */ +void umac_mouse(int deltax, int deltay, int button) +{ + if (!scc_get_mie()) return; if(deltax) { int16_t temp_h = RAM_RD16(MTemp_h) + deltax; RAM_WR16(MTemp_h, temp_h); diff --git a/src/scc.c b/src/scc.c index a3ec367..6680b3e 100644 --- a/src/scc.c +++ b/src/scc.c @@ -126,6 +126,8 @@ static void scc_wr3(int AnB, uint8_t data) } } +int scc_get_mie() { return scc_mie; } + // WR9: Master Interrupt control and reset commands static void scc_wr9(uint8_t data) { diff --git a/src/unix_main.c b/src/unix_main.c index e4d82fc..d536bd4 100644 --- a/src/unix_main.c +++ b/src/unix_main.c @@ -383,8 +383,14 @@ int main(int argc, char *argv[]) perror("SDL window"); return 1; } - SDL_SetWindowGrab(window, SDL_FALSE); - SDL_SetRelativeMouseMode(SDL_TRUE); + + static const int absmouse = 1; + if (!absmouse) { + SDL_SetWindowGrab(window, SDL_TRUE); + SDL_SetRelativeMouseMode(SDL_TRUE); + } else { + SDL_ShowCursor(SDL_DISABLE); + } renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); @@ -423,7 +429,8 @@ int main(int argc, char *argv[]) SDL_Event event; int mousex = 0; int mousey = 0; - + int send_mouse = 0; + static int absmousex, absmousey; if (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: @@ -439,21 +446,32 @@ int main(int argc, char *argv[]) } break; case SDL_MOUSEMOTION: + send_mouse = 1; + absmousex = event.motion.x / DISP_SCALE; + absmousey = event.motion.y / DISP_SCALE; mousex = event.motion.xrel; mousey = -event.motion.yrel; break; case SDL_MOUSEBUTTONDOWN: + send_mouse = 1; mouse_button = 1; break; case SDL_MOUSEBUTTONUP: + send_mouse = 1; mouse_button = 0; break; } } - umac_mouse(mousex, mousey, mouse_button); + if (send_mouse) { + if(absmouse) { + umac_absmouse(absmousex, absmousey, mouse_button); + } else { + umac_mouse(mousex, mousey, mouse_button); + } + } done |= umac_loop();