commit 2199411

chld  ·  2026-10-29 22:34:04 +0000 UTC
parent e4cde80
maus
1 files changed,  +59, -2
M uxn.c
M uxn.c
+59, -2
  1@@ -303,6 +303,7 @@ static Uint16 breakpoint=0;
  2 static Uint16 break_pc=0x0100;
  3 static Uint32 last_tick = 0;
  4 static Uint8 debug_op=0;
  5+static const touchpad_info_t *tpinfo=NULL;
  6 
  7 static void debug(int i) {
  8   int j;
  9@@ -1132,6 +1133,57 @@ static inline int select_joystick(Uint8 n) {
 10   return 0;
 11 }
 12 
 13+static Sint16 last_x = -1, last_y = -1;
 14+
 15+#define SENSITIVITY 4
 16+void update_mouse_from_touchpad(void) {
 17+    if (!tpinfo) {
 18+        tpinfo = touchpad_getinfo();
 19+        if (!tpinfo) return;
 20+    }
 21+
 22+    touchpad_report_t report;
 23+    if (touchpad_scan(&report) != 0) return;
 24+
 25+    if (!report.contact) {
 26+        device[9].d[6] = 0;
 27+        last_x = -1; last_y = -1;
 28+        return;
 29+    }
 30+
 31+    if (last_x < 0) {
 32+        last_x = report.x; last_y = report.y;
 33+        return;
 34+    }
 35+
 36+    /* relative delta */
 37+    Sint16 dx = (Sint16)report.x - last_x;
 38+    Sint16 dy = last_y - (Sint16)report.y;
 39+    last_x = report.x;
 40+    last_y = report.y;
 41+    dx /= SENSITIVITY; /* higher divisor, higher sensitivity */
 42+    dy /= SENSITIVITY;
 43+
 44+    Uint16 mx = (device[9].d[2] << 8) | device[9].d[3];
 45+    Uint16 my = (device[9].d[4] << 8) | device[9].d[5];
 46+  
 47+    /* apply delta to actual mouse coords */
 48+    if (dx < 0 && mx < (Uint16)(-dx)) mx = 0;
 49+    else mx += dx;
 50+    if (dy < 0 && my < (Uint16)(-dy)) my = 0;
 51+    else my += dy;
 52+
 53+    if (mx >= scr_w) mx = scr_w - 1;
 54+    if (my >= scr_h) my = scr_h - 1;
 55+
 56+    device[9].d[2] = mx >> 8;
 57+    device[9].d[3] = mx & 0xff;
 58+    device[9].d[4] = my >> 8;
 59+    device[9].d[5] = my & 0xff;
 60+
 61+    run(GET16(device[9].d));
 62+}
 63+
 64 static int run_screen(void) {
 65   SDL_Event e;
 66   int i,j,k;
 67@@ -1162,6 +1214,9 @@ static int run_screen(void) {
 68           case SDLK_PAGEUP: i=-scroll_size; goto scroll;
 69           case SDLK_PAGEDOWN: i=scroll_size; goto scroll;
 70 	case SDLK_F1: run(GET16(device[2].d));  break;
 71+	case SDLK_1:  device[9].d[6] = 0x01; break;
 72+	case SDLK_PERIOD:  device[9].d[6] = 0x03; break;
 73+	case SDLK_3:  device[9].d[6] = 0x02; break;
 74           case SDLK_F3: use_mouse^=1; set_cursor(); picture_changed=debugger; break;
 75           case SDLK_F4: layers=(layers+1)%3; redraw(); break;
 76           case SDLK_F5: redraw(); if(SDL_GetModState()&KMOD_RSHIFT) debug(-1); break;
 77@@ -1200,6 +1255,7 @@ static int run_screen(void) {
 78 	case SDLK_2: case SDLK_DOWN: i=0x20; break;
 79 	case SDLK_4: case SDLK_LEFT: i=0x40; break;
 80 	case SDLK_6: case SDLK_RIGHT: i=0x80; break;
 81+	case SDLK_PERIOD: case SDLK_3: case SDLK_1:  device[9].d[6] = 0x00; break;
 82         }
 83         if(device[8].d[2]&i) {
 84           device[8].d[2]&=~i;
 85@@ -1212,6 +1268,7 @@ static int run_screen(void) {
 86     redraw();
 87     picture_changed=0;
 88   }
 89+  update_mouse_from_touchpad();
 90   SDL_Delay(1);
 91     }
 92     return 0;
 93@@ -1255,8 +1312,8 @@ int main(int argc, char **argv)
 94   zoom = 1;
 95   disallow_size_change = 1;
 96   timer_rate = 16;
 97-  scr_w = 320;
 98-  scr_h = 240;
 99+  scr_w = 320; scr_h = 240;
100+  tpinfo=touchpad_getinfo();
101 
102   if (argc > 1) rom_name = argv[1];
103