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);
|
uint8_t scc_read(unsigned int address);
|
||||||
/* Set a new state for the DCD pins: */
|
/* Set a new state for the DCD pins: */
|
||||||
void scc_set_dcd(int a, int b);
|
void scc_set_dcd(int a, int b);
|
||||||
|
/* check if scc master interrupt is enabled */
|
||||||
|
int scc_get_mie();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ int umac_loop(void);
|
||||||
void umac_reset(void);
|
void umac_reset(void);
|
||||||
void umac_opt_disassemble(int enable);
|
void umac_opt_disassemble(int enable);
|
||||||
void umac_mouse(int deltax, int deltay, int button);
|
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);
|
void umac_kbd_event(uint8_t scancode, int down);
|
||||||
|
|
||||||
static inline void umac_vsync_event(void)
|
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.
|
* 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_h 0x82a
|
||||||
#define MTemp_v 0x828
|
#define MTemp_v 0x828
|
||||||
#define CrsrNew 0x8ce
|
#define CrsrNew 0x8ce
|
||||||
#define CrsrCouple 0x8cf
|
#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) {
|
if(deltax) {
|
||||||
int16_t temp_h = RAM_RD16(MTemp_h) + deltax;
|
int16_t temp_h = RAM_RD16(MTemp_h) + deltax;
|
||||||
RAM_WR16(MTemp_h, temp_h);
|
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
|
// WR9: Master Interrupt control and reset commands
|
||||||
static void scc_wr9(uint8_t data)
|
static void scc_wr9(uint8_t data)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -383,8 +383,14 @@ int main(int argc, char *argv[])
|
||||||
perror("SDL window");
|
perror("SDL window");
|
||||||
return 1;
|
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);
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
|
@ -423,7 +429,8 @@ int main(int argc, char *argv[])
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int mousex = 0;
|
int mousex = 0;
|
||||||
int mousey = 0;
|
int mousey = 0;
|
||||||
|
int send_mouse = 0;
|
||||||
|
static int absmousex, absmousey;
|
||||||
if (SDL_PollEvent(&event)) {
|
if (SDL_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
|
|
@ -439,21 +446,32 @@ int main(int argc, char *argv[])
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
|
send_mouse = 1;
|
||||||
|
absmousex = event.motion.x / DISP_SCALE;
|
||||||
|
absmousey = event.motion.y / DISP_SCALE;
|
||||||
mousex = event.motion.xrel;
|
mousex = event.motion.xrel;
|
||||||
mousey = -event.motion.yrel;
|
mousey = -event.motion.yrel;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
send_mouse = 1;
|
||||||
mouse_button = 1;
|
mouse_button = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
send_mouse = 1;
|
||||||
mouse_button = 0;
|
mouse_button = 0;
|
||||||
break;
|
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();
|
done |= umac_loop();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue