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:
parent
d86ebf1bb8
commit
d44474c24e
5 changed files with 54 additions and 5 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
28
src/main.c
28
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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue