Enable absolute mouse (todo: add flag to turn it off)

&& fix(?) a crash if mouse events were delivered too early
This commit is contained in:
Jeff Epler 2025-08-01 16:11:05 -05:00
parent 431e905354
commit f868c8669f
5 changed files with 54 additions and 5 deletions

View file

@ -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

View file

@ -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)

View file

@ -618,13 +618,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);

View file

@ -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)
{

View file

@ -287,8 +287,14 @@ int main(int argc, char *argv[])
perror("SDL window");
return 1;
}
SDL_SetWindowGrab(window, SDL_TRUE);
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);
}
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
@ -355,7 +361,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:
@ -372,21 +379,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();