*/}}
Browse Source

Win fixes

YimingWu 1 month ago
parent
commit
887d126de2
4 changed files with 31 additions and 1 deletions
  1. 13 1
      la_controllers.c
  2. 1 0
      la_kernel.c
  3. 14 0
      la_util.c
  4. 3 0
      la_util.h

+ 13 - 1
la_controllers.c

@@ -109,6 +109,7 @@ void la_ReadControllerAxisLimit(laController* c, int i, int Min, int Max){
 }
 
 int la_ControllerButtonToMap(int btn){
+#ifdef __linux__
     if(btn<BTN_MISC) return -1;
     if(btn<=BTN_GEAR_UP) return btn-BTN_MISC;
     if(btn<BTN_DPAD_UP) return -1;
@@ -116,13 +117,22 @@ int la_ControllerButtonToMap(int btn){
     if(btn<BTN_TRIGGER_HAPPY) return -1;
     if(btn<=BTN_TRIGGER_HAPPY40) return BTN_GEAR_UP-BTN_MISC+1+BTN_DPAD_RIGHT-BTN_DPAD_UP+1+btn-BTN_TRIGGER_HAPPY;
     return -1;
+#endif
+#ifdef _WIN32
+    return -1;
+#endif
 }
 int la_ControllerButtonToIndex(laController* c,int btn){
     int map=la_ControllerButtonToMap(btn); if(map<0) return -1; return c->ButtonsMap[map];
 }
 int la_ControllerAxisToMap(int abs){
+#ifdef __linux__
     if(abs<ABS_X) return -1; if(abs>ABS_MAX) return -1;
     return abs;
+#endif
+#ifdef _WIN32
+    return abs;
+#endif
 }
 int la_ControllerAxisToIndex(laController* c,int abs){
     int map=la_ControllerAxisToMap(abs); if(map<0) return -1; return c->AxisMap[map];
@@ -278,12 +288,14 @@ int OPMOD_RemoveController(laOperator* a, laEvent* e){
 
 void lapost_Controller(laController* c){
     c->InternalType = la_IdentifyControllerInternalType(SSTR(c->Name));
+#ifdef __linux__
     c->fd=open(SSTR(c->Path),O_RDWR | O_NONBLOCK); if(c->fd<0){ c->Error=1; }
+#endif
 }
 
 void* lagetraw_ControllerButtonMap(laController* c, int* r_size, int* ret_is_copy){
     int use_size=/*sizeof(int16_t)*LA_JS_MAX_AXES*4 +*/ sizeof(u8bit)*LA_JS_MAX_BUTTONS + sizeof(u8bit)*LA_JS_MAX_AXES;
-    char* data=malloc(use_size); char* p=data;
+    char* data = malloc(use_size); char* p = data; if (!data) return 0;
     //memcpy(p,c->AxisCenterMaxes,sizeof(int16_t)*LA_JS_MAX_AXES); p+= sizeof(int16_t)*LA_JS_MAX_AXES;
     //memcpy(p,c->AxisCenterMins,sizeof(int16_t)*LA_JS_MAX_AXES); p+= sizeof(int16_t)*LA_JS_MAX_AXES;
     //memcpy(p,c->AxisLimitMaxes,sizeof(int16_t)*LA_JS_MAX_AXES); p+= sizeof(int16_t)*LA_JS_MAX_AXES;

+ 1 - 0
la_kernel.c

@@ -1469,6 +1469,7 @@ void laRemoveCustomSignal(laCustomSignal* cs){
     strSafeDestroy(&cs->Name); lstRemoveItem(&MAIN.CustomSignals,cs); memFree(cs);
 }
 
+void la_SendSignalEvent(SYSWINDOW* hwnd, int signal);
 void la_SendSignalsFromEvent(laEvent* e){
     laInputMapping* im = MAIN.InputMapping->CurrentInputMapping;
     if(!im){return;}

+ 14 - 0
la_util.c

@@ -151,6 +151,20 @@ int nutSameAddress(void *l, void *r){
     return (l == r);
 }
 
+#ifdef _MSC_VER
+#  include <intrin.h>
+#  define __builtin_popcountll __popcnt64
+static inline int __builtin_ctzl(u64bit x)
+{
+#ifdef _WIN64
+    return (int)_tzcnt_u64(x);
+#else
+    return !!unsigned(x) ? __builtin_ctz((unsigned)x) : 32 + __builtin_ctz((unsigned)(x >> 32));
+#endif
+}
+
+#endif
+
 barray_t *barray_init(size_t num_bits)
 {
     size_t num_longs = BITS_TO_LONGS(num_bits);

+ 3 - 0
la_util.h

@@ -68,6 +68,9 @@
 #define SYSTEMDISPLAY int
 #define PATH_MAX 4096
 #define SYSLOCK CRITICAL_SECTION
+#ifndef off_t
+typedef long off_t;
+#endif
 #endif
 
 #ifdef LA_WITH_LUAJIT