Skip to content

Commit b57201b

Browse files
committed
QVSS/VIDEO: Fix for mouse tracking on Ultrix from Mike Burke for issue simh#88
1 parent 30cd103 commit b57201b

File tree

3 files changed

+93
-47
lines changed

3 files changed

+93
-47
lines changed

VAX/vax_vc.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
2626
vc Qbus video subsystem
2727
28+
08-Nov-2013 MB Implemented mouse position register
2829
06-Nov-2013 MB Increased the speed of v-sync interrupts, which
2930
was too slow for some O/S drivers.
3031
11-Jun-2013 MB First version
@@ -169,11 +170,12 @@ BITFIELD vc_ic_mode_bits[] = {
169170
#define IRQ_MBC 6 /* Mouse button C */
170171
#define IRQ_SPARE 7 /* (spare) */
171172

172-
#define VC_XSIZE 1024
173+
#define VC_XSIZE 1024 /* screen size */
173174
#define VC_YSIZE 864
174-
175175
#define VC_MEMSIZE (1u << 16) /* video memory size */
176176

177+
#define VC_MOVE_MAX 49 /* mouse movement max (per update) */
178+
177179
#define VCMAP_VLD 0x80000000 /* valid */
178180
#define VCMAP_LN 0x00000FFF /* buffer line */
179181

@@ -735,6 +737,7 @@ t_stat vc_svc (UNIT *uptr)
735737
t_bool updated = FALSE; /* flag for refresh */
736738
uint32 line[1024];
737739
uint32 ln, col, off;
740+
int32 xpos, ypos, dx, dy;
738741
uint8 *cur;
739742

740743
vc_crtc_p = vc_crtc_p ^ CRTCP_VB; /* Toggle VBI */
@@ -759,6 +762,32 @@ vc_cur_y = CUR_Y;
759762
vc_cur_v = CUR_V;
760763
vc_cur_f = CUR_F;
761764

765+
xpos = vc_mpos & 0xFF; /* get current mouse position */
766+
ypos = (vc_mpos >> 8) & 0xFF;
767+
dx = vid_mouse_xrel; /* get relative movement */
768+
dy = vid_mouse_yrel;
769+
if (dx > VC_MOVE_MAX) /* limit movement */
770+
dx = VC_MOVE_MAX;
771+
else if (dx < -VC_MOVE_MAX)
772+
dx = -VC_MOVE_MAX;
773+
if (dy > VC_MOVE_MAX)
774+
dy = VC_MOVE_MAX;
775+
else if (dy < -VC_MOVE_MAX)
776+
dy = -VC_MOVE_MAX;
777+
xpos += dx; /* add to counters */
778+
ypos += dy;
779+
vc_mpos = ((ypos & 0xFF) << 8) | (xpos & 0xFF); /* update register */
780+
vid_mouse_xrel = 0; /* reset counters for next poll */
781+
vid_mouse_yrel = 0;
782+
783+
vc_csr |= (CSR_MSA | CSR_MSB | CSR_MSC); /* reset button states */
784+
if (vid_mouse_b3) /* set new button states */
785+
vc_csr &= ~CSR_MSA;
786+
if (vid_mouse_b2)
787+
vc_csr &= ~CSR_MSB;
788+
if (vid_mouse_b1)
789+
vc_csr &= ~CSR_MSC;
790+
762791
for (ln = 0; ln < VC_YSIZE; ln++) {
763792
if ((vc_map[ln] & VCMAP_VLD) == 0) { /* line invalid? */
764793
off = vc_map[ln] * 32; /* get video buf offet */

sim_video.c

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@
2323
used in advertising or otherwise to promote the sale, use or other dealings
2424
in this Software without prior written authorization from the author.
2525
26+
08-Nov-2013 MB Added globals for current mouse status
2627
11-Jun-2013 MB First version
2728
*/
2829

2930
#include "sim_video.h"
3031

3132
t_bool vid_active = FALSE;
33+
int32 vid_mouse_xrel = 0;
34+
int32 vid_mouse_yrel = 0;
35+
t_bool vid_mouse_b1 = FALSE;
36+
t_bool vid_mouse_b2 = FALSE;
37+
t_bool vid_mouse_b3 = FALSE;
3238

3339
#if HAVE_LIBSDL
3440
#include <SDL.h>
@@ -54,9 +60,6 @@ typedef struct {
5460
int32 head;
5561
int32 tail;
5662
int32 count;
57-
t_bool b1_state;
58-
t_bool b2_state;
59-
t_bool b3_state;
6063
} MOUSE_EVENT_QUEUE;
6164

6265
int vid_thread (void* arg);
@@ -93,6 +96,8 @@ if (!vid_active) {
9396
vid_width = width;
9497
vid_height = height;
9598
vid_mouse_captured = FALSE;
99+
vid_mouse_xrel = 0;
100+
vid_mouse_yrel = 0;
96101

97102
vid_key_events.head = 0;
98103
vid_key_events.tail = 0;
@@ -605,17 +610,19 @@ if ((event->x == 0) ||
605610
}
606611
if (!sim_is_running)
607612
return;
613+
vid_mouse_xrel += event->xrel; /* update cumulative x rel */
614+
vid_mouse_yrel -= event->yrel; /* update cumulative y rel */
615+
vid_mouse_b1 = (event->state & SDL_BUTTON(SDL_BUTTON_LEFT)) ? TRUE : FALSE;
616+
vid_mouse_b2 = (event->state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) ? TRUE : FALSE;
617+
vid_mouse_b3 = (event->state & SDL_BUTTON(SDL_BUTTON_RIGHT)) ? TRUE : FALSE;
608618
if (SDL_SemWait (vid_mouse_events.sem) == 0) {
609619
sim_debug (SIM_VID_DBG_MOUSE, vid_dev, "Mouse Move Event: (%d,%d)\n", event->xrel, event->yrel);
610620
if (vid_mouse_events.count < MAX_EVENTS) {
611621
ev.x_rel = event->xrel;
612622
ev.y_rel = (-event->yrel);
613-
ev.b1_state = (event->state & SDL_BUTTON(SDL_BUTTON_LEFT)) ? TRUE : FALSE;
614-
ev.b2_state = (event->state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) ? TRUE : FALSE;
615-
ev.b3_state = (event->state & SDL_BUTTON(SDL_BUTTON_RIGHT)) ? TRUE : FALSE;
616-
vid_mouse_events.b1_state = ev.b1_state;
617-
vid_mouse_events.b2_state = ev.b2_state;
618-
vid_mouse_events.b3_state = ev.b3_state;
623+
ev.b1_state = vid_mouse_b1;
624+
ev.b2_state = vid_mouse_b2;
625+
ev.b3_state = vid_mouse_b3;
619626
vid_mouse_events.events[vid_mouse_events.tail++] = ev;
620627
vid_mouse_events.count++;
621628
if (vid_mouse_events.tail == MAX_EVENTS)
@@ -650,26 +657,26 @@ if (!vid_mouse_captured) {
650657
}
651658
if (!sim_is_running)
652659
return;
660+
state = (event->state == SDL_PRESSED) ? TRUE : FALSE;
661+
switch (event->button) {
662+
case SDL_BUTTON_LEFT:
663+
vid_mouse_b1 = state;
664+
break;
665+
case SDL_BUTTON_MIDDLE:
666+
vid_mouse_b2 = state;
667+
break;
668+
case SDL_BUTTON_RIGHT:
669+
vid_mouse_b3 = state;
670+
break;
671+
}
653672
if (SDL_SemWait (vid_mouse_events.sem) == 0) {
654673
sim_debug (SIM_VID_DBG_MOUSE, vid_dev, "Mouse Button Event: State: %d, Button: %d, (%d,%d)\n", event->state, event->button, event->x, event->y);
655674
if (vid_mouse_events.count < MAX_EVENTS) {
656-
state = (event->state == SDL_PRESSED) ? TRUE : FALSE;
657675
ev.x_rel = 0;
658676
ev.y_rel = 0;
659-
switch (event->button) {
660-
case SDL_BUTTON_LEFT:
661-
vid_mouse_events.b1_state = state;
662-
break;
663-
case SDL_BUTTON_MIDDLE:
664-
vid_mouse_events.b2_state = state;
665-
break;
666-
case SDL_BUTTON_RIGHT:
667-
vid_mouse_events.b3_state = state;
668-
break;
669-
}
670-
ev.b1_state = vid_mouse_events.b1_state;
671-
ev.b2_state = vid_mouse_events.b2_state;
672-
ev.b3_state = vid_mouse_events.b3_state;
677+
ev.b1_state = vid_mouse_b1;
678+
ev.b2_state = vid_mouse_b2;
679+
ev.b3_state = vid_mouse_b3;
673680
vid_mouse_events.events[vid_mouse_events.tail++] = ev;
674681
vid_mouse_events.count++;
675682
if (vid_mouse_events.tail == MAX_EVENTS)
@@ -811,6 +818,8 @@ if (!vid_active) {
811818
vid_width = width;
812819
vid_height = height;
813820
vid_mouse_captured = FALSE;
821+
vid_mouse_xrel = 0;
822+
vid_mouse_yrel = 0;
814823

815824
vid_key_events.head = 0;
816825
vid_key_events.tail = 0;
@@ -1318,17 +1327,19 @@ if ((event->x == 0) ||
13181327
}
13191328
if (!sim_is_running)
13201329
return;
1330+
vid_mouse_xrel += event->xrel; /* update cumulative x rel */
1331+
vid_mouse_yrel -= event->yrel; /* update cumulative y rel */
1332+
vid_mouse_b1 = (event->state & SDL_BUTTON(SDL_BUTTON_LEFT)) ? TRUE : FALSE;
1333+
vid_mouse_b2 = (event->state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) ? TRUE : FALSE;
1334+
vid_mouse_b3 = (event->state & SDL_BUTTON(SDL_BUTTON_RIGHT)) ? TRUE : FALSE;
13211335
if (SDL_SemWait (vid_mouse_events.sem) == 0) {
13221336
sim_debug (SIM_VID_DBG_MOUSE, vid_dev, "Mouse Move Event: (%d,%d)\n", event->xrel, event->yrel);
13231337
if (vid_mouse_events.count < MAX_EVENTS) {
13241338
ev.x_rel = event->xrel;
13251339
ev.y_rel = (-event->yrel);
1326-
ev.b1_state = (event->state & SDL_BUTTON(SDL_BUTTON_LEFT)) ? TRUE : FALSE;
1327-
ev.b2_state = (event->state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) ? TRUE : FALSE;
1328-
ev.b3_state = (event->state & SDL_BUTTON(SDL_BUTTON_RIGHT)) ? TRUE : FALSE;
1329-
vid_mouse_events.b1_state = ev.b1_state;
1330-
vid_mouse_events.b2_state = ev.b2_state;
1331-
vid_mouse_events.b3_state = ev.b3_state;
1340+
ev.b1_state = vid_mouse_b1;
1341+
ev.b2_state = vid_mouse_b2;
1342+
ev.b3_state = vid_mouse_b3;
13321343
vid_mouse_events.events[vid_mouse_events.tail++] = ev;
13331344
vid_mouse_events.count++;
13341345
if (vid_mouse_events.tail == MAX_EVENTS)
@@ -1362,26 +1373,26 @@ if (!vid_mouse_captured) {
13621373
}
13631374
if (!sim_is_running)
13641375
return;
1376+
state = (event->state == SDL_PRESSED) ? TRUE : FALSE;
1377+
switch (event->button) {
1378+
case SDL_BUTTON_LEFT:
1379+
vid_mouse_b1 = state;
1380+
break;
1381+
case SDL_BUTTON_MIDDLE:
1382+
vid_mouse_b2 = state;
1383+
break;
1384+
case SDL_BUTTON_RIGHT:
1385+
vid_mouse_b3 = state;
1386+
break;
1387+
}
13651388
if (SDL_SemWait (vid_mouse_events.sem) == 0) {
13661389
sim_debug (SIM_VID_DBG_MOUSE, vid_dev, "Mouse Button Event: State: %d, Button: %d, (%d,%d)\n", event->state, event->button, event->x, event->y);
13671390
if (vid_mouse_events.count < MAX_EVENTS) {
1368-
state = (event->state == SDL_PRESSED) ? TRUE : FALSE;
13691391
ev.x_rel = 0;
13701392
ev.y_rel = 0;
1371-
switch (event->button) {
1372-
case SDL_BUTTON_LEFT:
1373-
vid_mouse_events.b1_state = state;
1374-
break;
1375-
case SDL_BUTTON_MIDDLE:
1376-
vid_mouse_events.b2_state = state;
1377-
break;
1378-
case SDL_BUTTON_RIGHT:
1379-
vid_mouse_events.b3_state = state;
1380-
break;
1381-
}
1382-
ev.b1_state = vid_mouse_events.b1_state;
1383-
ev.b2_state = vid_mouse_events.b2_state;
1384-
ev.b3_state = vid_mouse_events.b3_state;
1393+
ev.b1_state = vid_mouse_b1;
1394+
ev.b2_state = vid_mouse_b2;
1395+
ev.b3_state = vid_mouse_b3;
13851396
vid_mouse_events.events[vid_mouse_events.tail++] = ev;
13861397
vid_mouse_events.count++;
13871398
if (vid_mouse_events.tail == MAX_EVENTS)

sim_video.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
used in advertising or otherwise to promote the sale, use or other dealings
2424
in this Software without prior written authorization from the author.
2525
26+
08-Nov-2013 MB Added globals for current mouse status
2627
11-Jun-2013 MB First version
2728
*/
2829

@@ -180,6 +181,11 @@ t_stat vid_show_release_key (FILE* st, UNIT* uptr, int32 val, void* desc);
180181

181182
extern t_bool vid_active;
182183
extern uint32 vid_mono_palette[2];
184+
extern int32 vid_mouse_xrel; /* mouse cumulative x rel */
185+
extern int32 vid_mouse_yrel; /* mouse cumulative y rel */
186+
extern t_bool vid_mouse_b1; /* mouse button 1 state */
187+
extern t_bool vid_mouse_b2; /* mouse button 2 state */
188+
extern t_bool vid_mouse_b3; /* mouse button 3 state */
183189

184190
#define SIM_VID_DBG_MOUSE 0x01000000
185191
#define SIM_VID_DBG_KEY 0x02000000

0 commit comments

Comments
 (0)