aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index dd4145a..17e0127 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,9 +37,10 @@ WITH REGARD TO THIS SOFTWARE.
37typedef enum { 37typedef enum {
38 CONTROL_CONTROLLER, 38 CONTROL_CONTROLLER,
39 CONTROL_MOUSE, 39 CONTROL_MOUSE,
40 CONTROL_KEYBOARD,
40} ControlMethod; 41} ControlMethod;
41 42
42static ControlMethod control_method = DEFAULT_CONTROL; 43static ControlMethod control_method = CONTROL_KEYBOARD;
43 44
44#define MOUSE_DELTA 1 45#define MOUSE_DELTA 1
45typedef struct Mouse { 46typedef struct Mouse {
@@ -173,12 +174,17 @@ handle_input(Uxn *u) {
173 devctrl->dat[3] = 0; 174 devctrl->dat[3] = 0;
174 control_method = CONTROL_MOUSE; 175 control_method = CONTROL_MOUSE;
175 } break; 176 } break;
176 default: { 177 case CONTROL_MOUSE: {
177 devmouse->dat[6] = 0; 178 devmouse->dat[6] = 0;
178 devmouse->dat[7] = 0; 179 devmouse->dat[7] = 0;
179 mempoke16(devmouse->dat, 0x2, -10); 180 mempoke16(devmouse->dat, 0x2, -10);
180 mempoke16(devmouse->dat, 0x4, -10); 181 mempoke16(devmouse->dat, 0x4, -10);
181 evaluxn(u, mempeek16(devmouse->dat, 0)); 182 evaluxn(u, mempeek16(devmouse->dat, 0));
183 toggle_keyboard();
184 control_method = CONTROL_KEYBOARD;
185 } break;
186 case CONTROL_KEYBOARD: {
187 toggle_keyboard();
182 control_method = CONTROL_CONTROLLER; 188 control_method = CONTROL_CONTROLLER;
183 } break; 189 } break;
184 } 190 }
@@ -270,6 +276,22 @@ handle_input(Uxn *u) {
270 mempoke16(devmouse->dat, 0x2, mouse.x); 276 mempoke16(devmouse->dat, 0x2, mouse.x);
271 mempoke16(devmouse->dat, 0x4, mouse.y); 277 mempoke16(devmouse->dat, 0x4, mouse.y);
272 evaluxn(u, mempeek16(devmouse->dat, 0)); 278 evaluxn(u, mempeek16(devmouse->dat, 0));
279 } else if (control_method == CONTROL_KEYBOARD) {
280 if (key_tap(KEY_LEFT)) {
281 update_cursor(cursor_position - 1);
282 } else if (key_tap(KEY_RIGHT)) {
283 update_cursor(cursor_position + 1);
284 }
285 if (key_tap(KEY_UP) && cursor_position >= KEYBOARD_ROW_SIZE) {
286 update_cursor(cursor_position - KEYBOARD_ROW_SIZE);
287 } else if (key_tap(KEY_DOWN) && cursor_position < LEN(keyboard) - KEYBOARD_ROW_SIZE) {
288 update_cursor(cursor_position + KEYBOARD_ROW_SIZE);
289 }
290 if (key_tap(KEY_B)) {
291 devctrl->dat[3] = keyboard[cursor_position].symbol;
292 evaluxn(u, mempeek16(devctrl->dat, 0));
293 devctrl->dat[3] = 0;
294 }
273 } 295 }
274} 296}
275 297