diff --git a/misc/ps2/Makefile b/misc/ps2/Makefile index ee5fc509c..70fc744bf 100644 --- a/misc/ps2/Makefile +++ b/misc/ps2/Makefile @@ -5,11 +5,11 @@ BUILD_DIR = build-ps2 CFILES := $(wildcard src/*.c) OBJS :=$(patsubst %.c, %.o, $(CFILES)) -IOP_MODS:= DEV9_irx.o NETMAN_irx.o SMAP_irx.o USBD_irx.o BDM_irx.o BDMFS_FATFS_irx.o USBMASS_BD_irx.o USBHDFSD_irx.o +IOP_MODS:= DEV9_irx.o NETMAN_irx.o SMAP_irx.o USBD_irx.o BDM_irx.o BDMFS_FATFS_irx.o USBMASS_BD_irx.o USBHDFSD_irx.o USBMOUSE_irx.o EE_BIN = ClassiCube-ps2.elf EE_OBJS = $(OBJS) $(patsubst %.o, $(BUILD_DIR)/%.o, $(IOP_MODS)) -EE_LIBS = -lpatches -lpad -lpacket -ldma -lgraph -ldraw -lc -lps2ip -lnetman -lmc +EE_LIBS = -lpatches -lpad -lpacket -ldma -lgraph -ldraw -lc -lps2ip -lnetman -lmc -lmouse EE_CFLAGS = -DPLAT_PS2 all: $(BUILD_DIR) $(EE_BIN) @@ -46,6 +46,10 @@ $(BUILD_DIR)/USBMASS_BD_irx.c: $(PS2SDK)/iop/irx/usbmass_bd.irx $(BUILD_DIR)/USBHDFSD_irx.c: $(PS2SDK)/iop/irx/usbhdfsd.irx bin2c $< $@ USBHDFSD_irx +# USB input IRX modules +$(BUILD_DIR)/USBMOUSE_irx.c: $(PS2SDK)/iop/irx/ps2mouse.irx + bin2c $< $@ USBMOUSE_irx + include $(PS2SDK)/samples/Makefile.pref include $(PS2SDK)/samples/Makefile.eeglobal diff --git a/src/Platform_PS2.c b/src/Platform_PS2.c index a5807fa04..10fd07de4 100644 --- a/src/Platform_PS2.c +++ b/src/Platform_PS2.c @@ -50,12 +50,24 @@ const char* Platform_AppNameSuffix = " PS2"; /*########################################################################################################################* *------------------------------------------------------Logging/Time-------------------------------------------------------* *#########################################################################################################################*/ +static cc_bool hookedDebug; + void Platform_Log(const char* msg, int len) { char tmp[2048 + 1]; len = min(len, 2048); Mem_Copy(tmp, msg, len); tmp[len] = '\0'; - _print("%s", tmp); + +#ifdef PS2_DEBUG + volatile char* dst = (char*)0x1000F180; + + for (int i = 0; i < len; i++) + { + *dst = msg[i]; + } + *dst = '\n'; + *dst = '\r'; +#endif } TimeMS DateTime_CurrentUTC(void) { @@ -609,6 +621,12 @@ extern unsigned int size_USBMASS_BD_irx; extern unsigned char USBHDFSD_irx[]; extern unsigned int size_USBHDFSD_irx; +extern unsigned char USBMASS_BD_irx[]; +extern unsigned int size_USBMASS_BD_irx; + +extern unsigned char USBMOUSE_irx[]; +extern unsigned int size_USBMOUSE_irx; + static void USBStorage_LoadIOPModules(void) { int ret; // TODO: Seems that @@ -629,6 +647,9 @@ static void USBStorage_LoadIOPModules(void) { ret = SifExecModuleBuffer(USBMASS_BD_irx, size_USBMASS_BD_irx, 0, NULL, NULL); if (ret < 0) Platform_Log1("SifExecModuleBuffer USBMASS_BD_irx failed: %i", &ret); + + ret = SifExecModuleBuffer(USBMOUSE_irx, size_USBMOUSE_irx, 0, NULL, NULL); + if (ret < 0) Platform_Log1("SifExecModuleBuffer USBMOUSE_irx failed: %i", &ret); } // TODO Maybe needed ??? diff --git a/src/Window_PS2.c b/src/Window_PS2.c index eeb2f7e9e..6105d8397 100644 --- a/src/Window_PS2.c +++ b/src/Window_PS2.c @@ -21,8 +21,9 @@ #include #include #include +#include -static cc_bool launcherMode; +static cc_bool launcherMode, mouseSupported; static char padBuf0[256] __attribute__((aligned(64))); static char padBuf1[256] __attribute__((aligned(64))); @@ -54,6 +55,11 @@ void Window_Init(void) { padInit(0); padPortOpen(0, 0, padBuf0); padPortOpen(1, 0, padBuf1); + + if (PS2MouseInit() >= 0) { + PS2MouseSetReadMode(PS2MOUSE_READMODE_DIFF); + mouseSupported = true; + } } void Window_Free(void) { } @@ -107,7 +113,26 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +static void ProcessMouseInput(float delta) { + if (!mouseSupported) return; + if (PS2MouseEnum() == 0) return; + + mouse_data mData = { 0 }; + if (PS2MouseRead(&mData) < 0) return; + + //Platform_Log3("MOUSE: %i, %i, %i", &mData.x, &mData.y, &mData.buttons); + Input_SetNonRepeatable(CCMOUSE_L, mData.buttons & PS2MOUSE_BTN1); + Input_SetNonRepeatable(CCMOUSE_R, mData.buttons & PS2MOUSE_BTN2); + Input_SetNonRepeatable(CCMOUSE_M, mData.buttons & PS2MOUSE_BTN3); + + if (!Input.RawMode) return; + float scale = (delta * 60.0) / 2.0f; + Event_RaiseRawMove(&PointerEvents.RawMoved, + mData.x * scale, mData.y * scale); +} + void Window_ProcessEvents(float delta) { + ProcessMouseInput(delta); } void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita @@ -149,8 +174,8 @@ static void HandleButtons(int port, int buttons) { #define AXIS_SCALE 16.0f static void HandleJoystick(int port, int axis, int x, int y, float delta) { - if (Math_AbsI(x) <= 8) x = 0; - if (Math_AbsI(y) <= 8) y = 0; + if (Math_AbsI(x) <= 32) x = 0; + if (Math_AbsI(y) <= 32) y = 0; Gamepad_SetAxis(port, axis, x / AXIS_SCALE, y / AXIS_SCALE, delta); }