fix controller vibration (#1685)

* fix vibration being wrong and untoggleable

* fix a battle hud crash
This commit is contained in:
ManDude
2022-07-20 00:06:05 +01:00
committed by GitHub
parent a8653f7595
commit 5d4ba62bdb
5 changed files with 18 additions and 10 deletions
+6 -1
View File
@@ -1,6 +1,9 @@
#pragma once
#include "common/common_types.h"
//! Mirror of cpad-info
#pragma pack(push, 4)
struct CPadInfo {
u8 valid;
u8 status;
@@ -23,12 +26,14 @@ struct CPadInfo {
u8 align[6];
u8 direct[6];
u8 buzz_val[2];
u8 __pad[2];
u64 buzz_time[2];
u32 buzz;
s32 buzz_act;
s32 change_time; // actually u64 in goal!
};
// static_assert(offsetof(CPadInfo, number) == 32, "CPadInfo number field is wrong");
static_assert(sizeof(CPadInfo) == 128, "CPadInfo size is wrong");
#pragma pack(pop)
struct FileStream {
u32 flags;
+5 -5
View File
@@ -113,8 +113,8 @@ u64 CPadGetData(u64 cpad_info) {
// ps2 controllers would send an enabled bit if the button was NOT pressed, but we don't do
// that here. removed code that flipped the bits.
if (cpad->buzz_act) {
scePadSetActDirect(cpad->number, 0, cpad);
if (cpad->change_time) {
scePadSetActDirect(cpad->number, 0, cpad->direct);
}
cpad->valid = pad_state;
}
@@ -143,7 +143,7 @@ u64 CPadGetData(u64 cpad_info) {
break;
case 40: // controller mode - check for extra modes
// cpad->change_time = 0;
cpad->buzz_act = 0;
cpad->change_time = 0;
if (scePadInfoMode(cpad->number, 0, InfoModeIdTable, -1) == 0) {
// no controller modes
cpad->state = 90;
@@ -171,12 +171,12 @@ u64 CPadGetData(u64 cpad_info) {
if (scePadInfoAct(cpad->number, 0, -1, 0) < 1) {
// no actuators means no vibration. skip to end!
// cpad->change_time = 0;
cpad->buzz_act = 0;
cpad->change_time = 0;
cpad->state = 99;
} else {
// we have actuators to use.
// cpad->change_time = 1; // remember to update pad times.
cpad->buzz_act = 1;
cpad->change_time = 1;
cpad->state = 75;
}
break;
+5 -2
View File
@@ -91,8 +91,11 @@ int scePadRead(int port, int /*slot*/, u8* rdata) {
return 32;
}
int scePadSetActDirect(int port, int /*slot*/, CPadInfo* cpad) {
return Pad::rumble(port, ((float)cpad->buzz_val[0]) / 255, ((float)cpad->buzz_val[1]) / 255);
int scePadSetActDirect(int port, int /*slot*/, const u8* data) {
// offsets are set by scePadSetActAlign, but we already know the game uses 0 for big motor and 1
// for small motor
// also, the "slow" motor corresponds to the "large" motor on the PS2
return Pad::rumble(port, ((float)data[1]) / 255, ((float)data[0]));
}
int scePadSetActAlign(int /*port*/, int /*slot*/, const u8* /*data*/) {
+1 -1
View File
@@ -54,7 +54,7 @@ int scePadPortOpen(int port, int slot, void* data);
int scePadGetState(int port, int slot);
int scePadInfoMode(int port, int slot, int term, int offs);
int scePadRead(int port, int slot, u8* rdata);
int scePadSetActDirect(int port, int slot, CPadInfo* cpad);
int scePadSetActDirect(int port, int slot, const u8* data);
int scePadSetActAlign(int port, int slot, const u8* data);
int scePadSetMainMode(int port, int slot, int offs, int lock);
int scePadGetReqState(int port, int slot);
+1 -1
View File
@@ -507,7 +507,7 @@
)
(else
;; we have nothing. kill everything.
(unless (hidden? obj)
(unless (and (= (-> obj last-battle) INVALID_HANDLE) (hidden? obj))
(set! (-> obj last-battle) INVALID_HANDLE)
(set! (-> obj last-task) #f)
(false! (-> obj ready?))