From cbd6cab28b6b3d03e9625e9d429f8acaa34aa8a5 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 3 Jan 2021 00:50:25 +0100 Subject: [PATCH] Provide experimental (non-working) mouse support --- libpsx/include/psx.h | 2 ++ libpsx/src/psxsdk.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/libpsx/include/psx.h b/libpsx/include/psx.h index e972e0c..f1316d0 100644 --- a/libpsx/include/psx.h +++ b/libpsx/include/psx.h @@ -224,6 +224,8 @@ void PSX_InitEx(unsigned int flags); */ void PSX_ReadPad(unsigned short *padbuf, unsigned short *padbuf2); +void PSX_ReadMouse(unsigned short* dig_pad1, unsigned short* adc_pad1); + void PSX_PollPad_Fast(int pad_num, psx_pad_state *pad_state); void PSX_PollPad_Fast_Ex(const unsigned char* const arr, psx_pad_state* const pad_state); diff --git a/libpsx/src/psxsdk.c b/libpsx/src/psxsdk.c index 6fd97af..df623e2 100644 --- a/libpsx/src/psxsdk.c +++ b/libpsx/src/psxsdk.c @@ -141,6 +141,27 @@ void PSX_ReadPad(unsigned short *padbuf, unsigned short *padbuf2) unsigned char psxsdkPadArr[PAD_READ_RAW_SIZE][2]; +void PSX_ReadMouse(unsigned short* dig_pad1, unsigned short* adc_pad1) +{ + unsigned char* arr = psxsdkPadArr[0]; + + const unsigned char pad_cmd[PAD_READ_RAW_SIZE] = {1,0x42,0,0,0,0,0}; // 2 extra bytes than digital pad + + QueryPAD(0, pad_cmd, arr, sizeof(pad_cmd)); + + if(arr[2] == 0x5A) + { + *dig_pad1 = (arr[3]<<8)|arr[4]; + *dig_pad1 = ~*dig_pad1; + *adc_pad1 = (arr[5]<<8)|arr[6]; + } + else + { + *dig_pad1 = 0; + *adc_pad1 = 0; + } +} + void PSX_PollPad_Fast_Ex(const unsigned char* const arr, psx_pad_state* const pad_state) { //Rely on pad_read_raw being called AFTER PSX_ReadPad(),