commit 9aefeebf25f70489f159c0c97741ccb5108a6bf6
parent 062bbac37df33f55924489fb72a212200ac57eca
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sun, 1 Jan 2023 11:37:34 -0800
Removed Device struct from controller device
Diffstat:
3 files changed, 23 insertions(+), 36 deletions(-)
diff --git a/src/devices/controller.c b/src/devices/controller.c
@@ -2,8 +2,7 @@
#include "controller.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,39 +13,29 @@ WITH REGARD TO THIS SOFTWARE.
*/
void
-controller_down(Device *d, Uint8 mask)
+controller_down(Uxn *u, Uint8 *d, Uint8 mask)
{
if(mask) {
- d->dat[2] |= mask;
- uxn_eval(d->u, GETVECTOR(d));
+ d[2] |= mask;
+ uxn_eval(u, GETVEC(d));
}
}
void
-controller_up(Device *d, Uint8 mask)
+controller_up(Uxn *u, Uint8 *d, Uint8 mask)
{
if(mask) {
- d->dat[2] &= (~mask);
- uxn_eval(d->u, GETVECTOR(d));
+ d[2] &= (~mask);
+ uxn_eval(u, GETVEC(d));
}
}
void
-controller_key(Device *d, Uint8 key)
+controller_key(Uxn *u, Uint8 *d, Uint8 key)
{
if(key) {
- d->dat[3] = key;
- uxn_eval(d->u, GETVECTOR(d));
- d->dat[3] = 0x00;
- }
-}
-
-void
-controller_special(Device *d, Uint8 key)
-{
- if(key) {
- d->dat[4] = key;
- uxn_eval(d->u, GETVECTOR(d));
- d->dat[4] = 0x00;
+ d[3] = key;
+ uxn_eval(u, GETVEC(d));
+ d[3] = 0x00;
}
}
diff --git a/src/devices/controller.h b/src/devices/controller.h
@@ -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,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
-void controller_down(Device *d, Uint8 mask);
-void controller_up(Device *d, Uint8 mask);
-void controller_key(Device *d, Uint8 key);
-void controller_special(Device *d, Uint8 key);
+void controller_down(Uxn *u, Uint8 *d, Uint8 mask);
+void controller_up(Uxn *u, Uint8 *d, Uint8 mask);
+void controller_key(Uxn *u, Uint8 *d, Uint8 key);
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -411,13 +411,13 @@ handle_events(Uxn *u)
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]);
+ controller_key(u, devctrl->dat, event.text.text[0]);
else if(event.type == SDL_KEYDOWN) {
int ksym;
if(get_key(&event))
- controller_key(devctrl, get_key(&event));
+ controller_key(u, devctrl->dat, get_key(&event));
else if(get_button(&event))
- controller_down(devctrl, get_button(&event));
+ controller_down(u, devctrl->dat, get_button(&event));
else
do_shortcut(u, &event);
ksym = event.key.keysym.sym;
@@ -425,17 +425,17 @@ handle_events(Uxn *u)
return 1;
}
} else if(event.type == SDL_KEYUP)
- controller_up(devctrl, get_button(&event));
+ controller_up(u, devctrl->dat, get_button(&event));
else if(event.type == SDL_JOYAXISMOTION) {
Uint8 vec = get_vector_joystick(&event);
if(!vec)
- controller_up(devctrl, (0x03 << (!event.jaxis.axis * 2)) << 4);
+ controller_up(u, devctrl->dat, (0x03 << (!event.jaxis.axis * 2)) << 4);
else
- controller_down(devctrl, (0x01 << ((vec + !event.jaxis.axis * 2) - 1)) << 4);
+ controller_down(u, devctrl->dat, (0x01 << ((vec + !event.jaxis.axis * 2) - 1)) << 4);
} else if(event.type == SDL_JOYBUTTONDOWN)
- controller_down(devctrl, get_button_joystick(&event));
+ controller_down(u, devctrl->dat, get_button_joystick(&event));
else if(event.type == SDL_JOYBUTTONUP)
- controller_up(devctrl, get_button_joystick(&event));
+ controller_up(u, devctrl->dat, get_button_joystick(&event));
/* Console */
else if(event.type == stdin_event)
console_input(u, event.cbutton.button);