This commit is contained in:
red-prig 2023-06-21 15:38:33 +03:00
parent 74dc091e83
commit 441da1d040
4 changed files with 34 additions and 15 deletions

View File

@ -39,6 +39,7 @@ var
function FindPadByParam(userID,_type,index:Integer):TScePadHandle;
Procedure SavePadHandle(handle:TScePadHandle);
Procedure ClearPadHandle(handle:TScePadHandle);
implementation
@ -56,8 +57,7 @@ begin
begin
Result:=pad_opened[i];
Result.Acqure;
spin_unlock(pad_lock);
Exit;
Break;
end;
spin_unlock(pad_lock);
end;
@ -71,12 +71,24 @@ begin
if (pad_opened[i]=nil) then
begin
pad_opened[i]:=handle;
spin_unlock(pad_lock);
Exit;
Break;
end;
spin_unlock(pad_lock);
end;
Procedure ClearPadHandle(handle:TScePadHandle);
var
i:Integer;
begin
spin_lock(pad_lock);
For i:=Low(pad_opened) to High(pad_opened) do
if (pad_opened[i]=handle) then
begin
pad_opened[i]:=nil;
Break;
end;
spin_unlock(pad_lock);
end;
function TScePadHandle.ReadState(data:PScePadData):Integer;
begin
@ -94,15 +106,8 @@ begin
end;
destructor TScePadHandle.Destroy;
var
i:Integer;
begin
For i:=Low(pad_opened) to High(pad_opened) do
if (pad_opened[i]=Self) then
begin
pad_opened[i]:=nil;
Break;
end;
ClearPadHandle(Self);
//
inherited;
end;

View File

@ -159,7 +159,7 @@ type
end;
ScePadStickInformation=packed record
deadZoneLeft:Byte;
deadZoneLeft :Byte;
deadZoneRight:Byte;
end;

View File

@ -115,6 +115,7 @@ begin
compared:=-1;
cs:=Default(TXInputState);
For i:=0 to XUSER_MAX_COUNT-1 do
begin
if (XInputGetState(i, cs)=0) then
if not FindOpened(i,prev) then
begin
@ -130,6 +131,7 @@ begin
Break;
end;
end;
end;
//
if (compared=-1) then compared:=first;
if (compared<>-1) then
@ -151,6 +153,8 @@ begin
end;
function TXInputPadHandle.ReadState(data:PScePadData):Integer;
label
_retry;
var
cs:TXInputState;
new:Integer;
@ -185,6 +189,7 @@ begin
end;
end;
_retry:
cs:=Default(TXInputState);
stateResult:=XInputGetState(UserIndex, cs);
@ -198,6 +203,7 @@ begin
begin
//connect
DoConnect(new);
goto _retry;
end else
begin
//not connected

View File

@ -90,22 +90,27 @@ begin
SCE_PAD_PORT_TYPE_SPECIAL :;
SCE_PAD_PORT_TYPE_REMOTE_CONTROL:;
else
Exit(SCE_PAD_ERROR_INVALID_ARG);
begin
//Writeln('scePadOpen:SCE_PAD_ERROR_INVALID_ARG:1');
Exit(SCE_PAD_ERROR_INVALID_ARG);
end;
end;
if (_type=SCE_PAD_PORT_TYPE_REMOTE_CONTROL) and
(userID<>$FF) then {SCE_USER_SERVICE_USER_ID_SYSTEM}
begin
//Writeln('scePadOpen:SCE_PAD_ERROR_INVALID_ARG:2');
Exit(SCE_PAD_ERROR_INVALID_ARG);
end;
Writeln('scePadOpen:[userID=',userID,' type=',_type,' index=',index,']');
//Writeln('scePadOpen:[userID=',userID,' type=',_type,' index=',index,']');
_sig_lock;
sce_handle:=FindPadByParam(userID,_type,index);
if (sce_handle<>nil) then
begin
//Writeln('scePadOpen:SCE_PAD_ERROR_ALREADY_OPENED');
sce_handle.Release;
_sig_unlock;
Exit(SCE_PAD_ERROR_ALREADY_OPENED);
@ -115,6 +120,7 @@ begin
Result:=ScePadInterface.Open(sce_handle);
if (Result<>0) then
begin
//Writeln('scePadOpen:',HexStr(Result,8));
_sig_unlock;
Exit;
end;
@ -139,6 +145,8 @@ begin
Result:=SCE_PAD_ERROR_FATAL;
end;
//Writeln('scePadOpen:',Result);
_sig_unlock;
end;