Skip to content

Commit

Permalink
testkit: Allow menus to be controlled via a mouse in either port
Browse files Browse the repository at this point in the history
Previously only port 1 (default "mouse port") was supported.

Based on a patch by Andrew Hutchings <[email protected]>

Refs #71
  • Loading branch information
keirf committed Aug 24, 2024
1 parent e58293a commit f774a98
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions testkit/testkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,24 +1065,28 @@ static void c_CIAB_IRQ(struct c_exception_frame *frame)
IRQ_RESET(INT_CIAB);
}

static uint16_t vblank_joydat, mouse_x, mouse_y;
static uint16_t vblank_joydat[2], mouse_x, mouse_y;
static void c_VBLANK_IRQ(struct c_exception_frame *frame)
{
uint16_t joydat, hstart, vstart, vstop;
uint16_t joydat[2], hstart, vstart, vstop;
uint16_t cur16 = get_ciaatb();
int i;

vblank_count++;

stamp32 -= (uint16_t)(stamp16 - cur16);
stamp16 = cur16;

/* Update mouse pointer coordinates based on mouse input. */
joydat = cust->joy0dat;
mouse_x += (int8_t)(joydat - vblank_joydat);
mouse_y += (int8_t)((joydat >> 8) - (vblank_joydat >> 8));
joydat[0] = cust->joy0dat;
joydat[1] = cust->joy1dat;
for (i = 0; i < 2; i++) {
mouse_x += (int8_t)(joydat[i] - vblank_joydat[i]);
mouse_y += (int8_t)((joydat[i] >> 8) - (vblank_joydat[i] >> 8));
vblank_joydat[i] = joydat[i];
}
mouse_x = min_t(int16_t, max_t(int16_t, mouse_x, 0), xres-1);
mouse_y = min_t(int16_t, max_t(int16_t, mouse_y, 0), 2*yres-1);
vblank_joydat = joydat;

/* Move the mouse pointer sprite. */
hstart = (mouse_x>>1) + diwstrt_h-1;
Expand All @@ -1099,8 +1103,8 @@ static void c_VBLANK_IRQ(struct c_exception_frame *frame)

static void c_SOFT_IRQ(struct c_exception_frame *frame)
{
static uint16_t prev_lmb;
uint16_t lmb, i, x, y;
static uint16_t prev_ciaapra;
uint16_t ciaapra, i, x, y;
struct menu_option *am, *m;

/* Clear the spurious autovector counts. This allows a certain maximum
Expand Down Expand Up @@ -1148,17 +1152,19 @@ static void c_SOFT_IRQ(struct c_exception_frame *frame)
active_menu_option = m;
}

/* When LMB is first pressed emit a keycode if we are within a menu box. */
lmb = !(ciaa->pra & CIAAPRA_FIR0);
if (lmb && !prev_lmb && (m != NULL)) {
/* When a left mouse button or fire button is first pressed emit a keycode
* if we are within a menu box. */
ciaapra = ciaa->pra;
if ((~ciaapra & prev_ciaapra & (CIAAPRA_FIR0 | CIAAPRA_FIR1))
&& (m != NULL)) {
keycode_buffer = m->c;
if (m->c == K_CTRL)
do_exit = 1; /* Ctrl (+ L.Alt) sets the exit flag */
/* Cancel any long-running check if instructed to exit. */
if (do_exit || (m->c == K_ESC))
do_cancel = 1;
}
prev_lmb = lmb;
prev_ciaapra = ciaapra;

/* Perform an asynchronous function cancellation if so instructed. */
if (do_cancel)
Expand Down Expand Up @@ -1252,7 +1258,8 @@ void cstart(void)
cust->cop1lc.p = copper;
cust->cop2lc.p = copper_2;

vblank_joydat = cust->joy0dat;
vblank_joydat[0] = cust->joy0dat;
vblank_joydat[1] = cust->joy1dat;

wait_bos();
cust->dmacon = DMA_SETCLR | DMA_COPEN | DMA_DSKEN;
Expand Down

0 comments on commit f774a98

Please sign in to comment.