~rabbits/uxn

062bbac37df33f55924489fb72a212200ac57eca — Devine Lu Linvega 2 months ago 6317b5c
Removed Device struct from mouse device
4 files changed, 32 insertions(+), 30 deletions(-)

M src/devices/mouse.c
M src/devices/mouse.h
M src/uxn.h
M src/uxnemu.c
M src/devices/mouse.c => src/devices/mouse.c +17 -18
@@ 2,8 2,7 @@
#include "mouse.h"

/*
Copyright (c) 2021 Devine Lu Linvega
Copyright (c) 2021 Andrew Alderwick
Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above


@@ 14,33 13,33 @@ WITH REGARD TO THIS SOFTWARE.
*/

void
mouse_down(Device *d, Uint8 mask)
mouse_down(Uxn *u, Uint8 *d, Uint8 mask)
{
	d->dat[6] |= mask;
	uxn_eval(d->u, GETVECTOR(d));
	d[6] |= mask;
	uxn_eval(u, GETVEC(d));
}

void
mouse_up(Device *d, Uint8 mask)
mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
{
	d->dat[6] &= (~mask);
	uxn_eval(d->u, GETVECTOR(d));
	d[6] &= (~mask);
	uxn_eval(u, GETVEC(d));
}

void
mouse_pos(Device *d, Uint16 x, Uint16 y)
mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{
	DEVPOKE16(0x2, x);
	DEVPOKE16(0x4, y);
	uxn_eval(d->u, GETVECTOR(d));
	POKDEV(0x2, x);
	POKDEV(0x4, y);
	uxn_eval(u, GETVEC(d));
}

void
mouse_scroll(Device *d, Uint16 x, Uint16 y)
mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{
	DEVPOKE16(0xa, x);
	DEVPOKE16(0xc, -y);
	uxn_eval(d->u, GETVECTOR(d));
	DEVPOKE16(0xa, 0);
	DEVPOKE16(0xc, 0);
	POKDEV(0xa, x);
	POKDEV(0xc, -y);
	uxn_eval(u, GETVEC(d));
	POKDEV(0xa, 0);
	POKDEV(0xc, 0);
}

M src/devices/mouse.h => src/devices/mouse.h +5 -6
@@ 1,6 1,5 @@
/*
Copyright (c) 2021 Devine Lu Linvega
Copyright (c) 2021 Andrew Alderwick
Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above


@@ 10,7 9,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/

void mouse_down(Device *d, Uint8 mask);
void mouse_up(Device *d, Uint8 mask);
void mouse_pos(Device *d, Uint16 x, Uint16 y);
void mouse_scroll(Device *d, Uint16 x, Uint16 y);
void mouse_down(Uxn *u, Uint8 *d, Uint8 mask);
void mouse_up(Uxn *u, Uint8 *d, Uint8 mask);
void mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y);
void mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y);

M src/uxn.h => src/uxn.h +6 -0
@@ 26,6 26,12 @@ typedef unsigned int Uint32;
#define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])

/* new macros */

#define GETVEC(d) ((d)[0] << 8 | (d)[1])
#define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }

/* clang-format on */

typedef struct {

M src/uxnemu.c => src/uxnemu.c +4 -6
@@ 402,15 402,13 @@ handle_events(Uxn *u)
		}
		/* Mouse */
		else if(event.type == SDL_MOUSEMOTION)
			mouse_pos(devmouse,
				clamp(event.motion.x - PAD, 0, uxn_screen.width - 1),
				clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
			mouse_pos(u, devmouse->dat, clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
		else if(event.type == SDL_MOUSEBUTTONUP)
			mouse_up(devmouse, SDL_BUTTON(event.button.button));
			mouse_up(u, devmouse->dat, SDL_BUTTON(event.button.button));
		else if(event.type == SDL_MOUSEBUTTONDOWN)
			mouse_down(devmouse, SDL_BUTTON(event.button.button));
			mouse_down(u, devmouse->dat, SDL_BUTTON(event.button.button));
		else if(event.type == SDL_MOUSEWHEEL)
			mouse_scroll(devmouse, event.wheel.x, event.wheel.y);
			mouse_scroll(u, devmouse->dat, event.wheel.x, event.wheel.y);
		/* Controller */
		else if(event.type == SDL_TEXTINPUT)
			controller_key(devctrl, event.text.text[0]);