KPAD mostly matching for Wii (#3084)

This commit is contained in:
Max Roncace 2026-02-07 07:32:31 -05:00 committed by GitHub
parent 61422182e8
commit 6ad0254bbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 1902 additions and 32 deletions

View File

@ -23234,7 +23234,7 @@ checkInvalidData = .data:0x80402360; // type:object size:0x15 scope:global align
@3599 = .data:0x8040272C; // type:object size:0xE scope:local align:4 data:string
base = .data:0x80402740; // type:object size:0x2A scope:global align:4
tb = .data:0x80402770; // type:object size:0x900 scope:global align:4
lbl_80403070 = .data:0x80403070; // type:object size:0x49 data:string
@1375 = .data:0x80403070; // type:object size:0x49 data:string
...data.0 = .data:0x804030C0; // type:label scope:local align:4
@1642 = .data:0x804030C0; // type:object size:0xA scope:local align:4 data:string
@1658 = .data:0x804030CC; // type:object size:0x2E scope:local align:4 data:string

View File

@ -24356,7 +24356,7 @@ checkInvalidData = .data:0x80440A08; // type:object size:0x15 scope:global align
@3599 = .data:0x80440DD4; // type:object size:0xE scope:local align:4 data:string
base = .data:0x80440DE8; // type:object size:0x2A scope:global align:4
tb = .data:0x80440E18; // type:object size:0x900 scope:global align:4
lbl_80441718 = .data:0x80441718; // type:object size:0x49 data:string
@1375 = .data:0x80441718; // type:object size:0x49 data:string
...data.0 = .data:0x80441768; // type:label scope:local align:4
@1642 = .data:0x80441768; // type:object size:0xA scope:local align:4 data:string
@1658 = .data:0x80441774; // type:object size:0x2E scope:local align:4 data:string

View File

@ -23901,7 +23901,7 @@ checkInvalidData = .data:0x80427EE8; // type:object size:0x15 scope:global align
@3599 = .data:0x804282B4; // type:object size:0xE scope:local align:4 data:string
base = .data:0x804282C8; // type:object size:0x2A scope:global align:4
tb = .data:0x804282F8; // type:object size:0x900 scope:global align:4
lbl_80428BF8 = .data:0x80428BF8; // type:object size:0x49 data:string
@1375 = .data:0x80428BF8; // type:object size:0x49 data:string
...data.0 = .data:0x80428C48; // type:label scope:local align:4
@1642 = .data:0x80428C48; // type:object size:0xA scope:local align:4 data:string
@1658 = .data:0x80428C54; // type:object size:0x2E scope:local align:4 data:string

View File

@ -23903,7 +23903,7 @@ checkInvalidData = .data:0x80425D68; // type:object size:0x15 scope:global align
@3599 = .data:0x80426134; // type:object size:0xE scope:local align:4 data:string
base = .data:0x80426148; // type:object size:0x2A scope:global align:4
tb = .data:0x80426178; // type:object size:0x900 scope:global align:4
lbl_80426A78 = .data:0x80426A78; // type:object size:0x49 data:string
@1375 = .data:0x80426A78; // type:object size:0x49 data:string
...data.0 = .data:0x80426AC8; // type:label scope:local align:4
@1642 = .data:0x80426AC8; // type:object size:0xA scope:local align:4 data:string
@1658 = .data:0x80426AD4; // type:object size:0x2E scope:local align:4 data:string

View File

@ -23897,7 +23897,7 @@ checkInvalidData = .data:0x804287E8; // type:object size:0x15 scope:global align
@3599 = .data:0x80428BB4; // type:object size:0xE scope:local align:4 data:string
base = .data:0x80428BC8; // type:object size:0x2A scope:global align:4
tb = .data:0x80428BF8; // type:object size:0x900 scope:global align:4
lbl_804294F8 = .data:0x804294F8; // type:object size:0x49 data:string
@1375 = .data:0x804294F8; // type:object size:0x49 data:string
...data.0 = .data:0x80429548; // type:label scope:local align:4
@1642 = .data:0x80429548; // type:object size:0xA scope:local align:4 data:string
@1658 = .data:0x80429554; // type:object size:0x2E scope:local align:4 data:string

View File

@ -472,12 +472,12 @@ def DolphinLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
"objects": objects,
}
def RevolutionLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
def RevolutionLib(lib_name: str, objects: List[Object], extra_cflags=[]) -> Dict[str, Any]:
if config.version == "ShieldD":
return {
"lib": lib_name,
"mw_version": "Wii/1.0",
"cflags": [*cflags_revolution_debug, "-DSDK_AUG2010"],
"cflags": [*cflags_revolution_debug, "-DSDK_AUG2010", *extra_cflags],
"progress_category": "sdk",
"objects": objects,
}
@ -485,7 +485,7 @@ def RevolutionLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
return {
"lib": lib_name,
"mw_version": "Wii/1.0",
"cflags": [*cflags_revolution_retail, "-DSDK_AUG2010"],
"cflags": [*cflags_revolution_retail, "-DSDK_AUG2010", *extra_cflags],
"progress_category": "sdk",
"objects": objects,
}
@ -493,7 +493,7 @@ def RevolutionLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
return {
"lib": lib_name,
"mw_version": "GC/3.0a3",
"cflags": [*cflags_revolution_retail, "-DSDK_SEP2006", "-DNW4HBM_DEBUG"],
"cflags": [*cflags_revolution_retail, "-DSDK_SEP2006", "-DNW4HBM_DEBUG", *extra_cflags],
"progress_category": "sdk",
"objects": objects,
}
@ -501,7 +501,7 @@ def RevolutionLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
return {
"lib": lib_name,
"mw_version": "GC/3.0a3",
"cflags": [*cflags_revolution_retail, "-DSDK_SEP2006"],
"cflags": [*cflags_revolution_retail, "-DSDK_SEP2006", *extra_cflags],
"progress_category": "sdk",
"objects": objects,
}
@ -1867,6 +1867,13 @@ config.libs = [
Object(MatchingFor(ALL_WII), "revolution/wud/debug_msg.c"),
],
),
RevolutionLib(
"kpad",
[
Object(NonMatching, "revolution/kpad/KPAD.c"),
],
extra_cflags=["-O4,s"]
),
RevolutionLib(
"euart",
[

View File

@ -3,15 +3,36 @@
#include <revolution/mtx.h>
#include <revolution/wpad.h>
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define KPAD_BUTTON_MASK 0x0000ffff
#define KPAD_BUTTON_RPT 0x80000000
#define KPAD_BTN_RPT_TIME_MAX 20000
#define KPAD_BTN_NO_RPT_DELAY 40000
#define KPAD_CMOS_RESO_WX 128
#define KPAD_CMOS_RESO_WY 96
#define KPAD_CMOS_RESO_CX (KPAD_CMOS_RESO_WX / 2)
#define KPAD_CMOS_RESO_CY (KPAD_CMOS_RESO_WY / 2)
#define KPAD_DPD_RESO_WX WPAD_DPD_IMG_RESO_WX
#define KPAD_DPD_RESO_WY WPAD_DPD_IMG_RESO_WY
#define KPAD_DPD_RESO_CX (KPAD_DPD_RESO_WX / 2)
#define KPAD_DPD_RESO_CY (KPAD_DPD_RESO_WY / 2)
#define KPAD_USE_OBJECTS 2
typedef struct Vec2 {
f32 x, y;
} Vec2;
typedef enum KPADPlayMode { KPAD_PLAY_MODE_LOOSE = 0, KPAD_PLAY_MODE_TIGHT } KPADPlayMode;
typedef s32 KPADResult;
typedef union KPADEXStatus {
@ -50,16 +71,103 @@ typedef struct KPADStatus {
/* 0x4C */ f32 dist_vec;
/* 0x50 */ f32 dist_speed;
/* 0x54 */ Vec2 acc_vertical;
/* 0x5C */ u8 dev_type;
/* 0x5D */ s8 wpad_err;
/* 0x5E */ s8 dpd_valid_fg;
/* 0x5F */ u8 data_format;
/* 0x5C */ u32 dev_type;
/* 0x60 */ KPADEXStatus ex_status;
/* 0x84 */ u8 __paddings__[4]; // ??? is this the compiler?
} KPADStatus; // size 0x88
/* 0x84 */ s8 dpd_valid_fg;
/* 0x85 */ s8 wpad_err;
} KPADStatus; // size 0x88
void KPADEnableDPD(s32);
void KPADDisableDPD(s32);
typedef struct KPADUnifiedWpadStatus {
union {
WPADStatus core;
WPADFSStatus fs;
WPADCLStatus cl;
} u;
} KPADUnifiedWpadStatus;
typedef struct {
Vec2 center;
s8 error_fg;
s8 state_fg;
s8 _fg_1;
s8 _fg_2;
} KPADObject;
typedef union {
KPADStatus k;
KPADUnifiedWpadStatus w;
} KPADTmpStatus;
typedef void (*KPADControlDpdCallback)(s32 chan, s32 reason);
typedef WPADCallback KPADCallback;
typedef WPADChannel KPADChannel;
typedef struct {
/* 0x000 */ KPADStatus status;
/* 0x088 */ f32 pos_play_radius;
/* 0x08C */ f32 pos_sensitivity;
/* 0x090 */ f32 hori_play_radius;
/* 0x094 */ f32 hori_sensitivity;
/* 0x098 */ f32 dist_play_radius;
/* 0x09C */ f32 dist_sensitivity;
/* 0x0A0 */ f32 acc_play_radius;
/* 0x0A4 */ f32 acc_sensitivity;
/* 0x0A8 */ f32 dist_org;
/* 0x0AC */ Vec2 accXY_nrm_hori;
/* 0x0B4 */ Vec2 sec_nrm_hori;
/* 0x0BC */ Vec2 center_org;
/* 0x0C4 */ f32 dpd2pos_scale;
/* 0x0C8 */ KPADObject kobj_sample[4];
/* 0x0F8 */ KPADObject kobj_regular[2];
/* 0x110 */ s16 valid_objs;
/* 0x112 */ u16 repeat_count;
/* 0x114 */ s16 active_chan;
/* 0x116 */ s16 unk_0x116;
/* 0x118 */ KPADUnifiedWpadStatus uniRingBuf[12];
/* 0x3A0 */ f32 sec_length;
/* 0x3A4 */ Vec2 sec_nrm;
/* 0x3AC */ f32 sec_dist;
/* 0x3B0 */ f32 trust_sec_length;
/* 0x3B4 */ Vec hard_acc;
/* 0x3C0 */ Vec2 obj_horizon;
/* 0x3C8 */ Vec2 acc_horizon;
/* 0x3D0 */ Vec2 ah_circle_pos;
/* 0x3D8 */ u16 ah_circle_ct;
/* 0x3DA */ u8 dpd_valid2_ct;
/* 0x3DC */ u16 btn_repeat_time;
/* 0x3DE */ u16 btn_repeat_next;
/* 0x3E0 */ u16 btn_repeat_delay;
/* 0x3E2 */ u16 btn_repeat_pulse;
/* 0x3E4 */ u16 btn_cl_repeat_time;
/* 0x3E6 */ u16 btn_cl_repeat_next;
/* 0x3E8 */ u16 btn_cl_repeat_delay;
/* 0x3EA */ u16 btn_cl_repeat_pulse;
/* 0x3EC */ BOOL is_dpd_enabled;
/* 0x3F0 */ BOOL unk_0x3f0;
/* 0x3F4 */ BOOL unk_0x3f4;
/* 0x3F8 */ KPADControlDpdCallback dpd_ctrl_callback;
/* 0x3FC */ BOOL unk_0x3fc;
} KPADInsideStatus;
void KPADInit();
void KPADSetFSStickClamp(s8 min, s8 max);
void KPADSetBtnRepeat(s32 chan, f32 delay_sec, f32 pulse_sec);
void KPADSetObjInterval(f32 interval);
void KPADSetPosParam(s32 chan, f32 play_radius, f32 sensitivity);
void KPADSetHoriParam(s32 chan, f32 play_radius, f32 sensitivity);
void KPADSetDistParam(s32 chan, f32 play_radius, f32 sensitivity);
void KPADSetAccParam(s32 chan, f32 play_radius, f32 sensitivity);
void KPADSetSensorHeight(s32 chan, f32 level);
void KPADReset(void);
s32 KPADRead(s32 chan, KPADStatus* sampling_bufs, s32 length);
void KPADEnableDPD(s32 chan);
void KPADDisableDPD(s32 chan);
extern KPADInsideStatus inside_kpads[];
#ifdef __cplusplus
}

View File

@ -7,6 +7,8 @@
extern "C" {
#endif
#define MTXRowCol(m, r, c) ((m)[(r)][(c)])
typedef struct Vec {
f32 x, y, z;
} Vec, *VecPtr, Point3d, *Point3dPtr;

View File

@ -71,6 +71,9 @@ extern "C" {
#define WPAD_DEV_NONE 253 // sort of like WPAD_ENODEV (see __wpadAbortInitExtension in WPADHIDParser.c)
#define WPAD_DEV_INITIALIZING 255 // see __a1_20_status_report
#define WPAD_SENSOR_BAR_POS_BOTTOM 0
#define WPAD_SENSOR_BAR_POS_TOP 1
enum WPADResult_et {
WPAD_ERR_OK = 0,
@ -103,6 +106,14 @@ enum WPADResult_et {
#define WPAD_CEBADE (WPAD_EBADE + 0)
#define WPAD_DPD_MAX_OBJECTS 4
#define WPAD_DPD_IMG_RESO_WX 1024
#define WPAD_DPD_IMG_RESO_WY 768
#define WPAD_STATE_DISABLED 0
#define WPAD_STATE_ENABLING 1
#define WPAD_STATE_ENABLED 2
#define WPAD_STATE_SETUP 3
#define WPAD_STATE_DISABLING 4
#define WPAD_CHAN0 0
#define WPAD_CHAN1 1
@ -382,6 +393,7 @@ void WPADGetAccGravityUnit(s32 chan, u32 type, WPADAcc* acc);
BOOL WPADIsDpdEnabled(s32 chan);
s32 WPADControlDpd(s32 chan, u32 command, WPADCallback callback);
u32 WPADGetLatestIndexInBuf(s32 chan);
u32 WPADGetDataFormat(s32 chan);
s32 WPADSetDataFormat(s32 chan, u32 fmt);
void WPADSetAutoSleepTime(u8 minute);

1708
src/revolution/kpad/KPAD.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
#ifndef _REVOLUTION_KPAD_PRIVATE_H_
#define _REVOLUTION_KPAD_PRIVATE_H_
#include <revolution/kpad.h>
#include "types.h"
static void calc_dpd2pos_scale(KPADInsideStatus* kp);
void reset_kpad(KPADInsideStatus* kp);
void calc_button_repeat(KPADInsideStatus* kp, KPADStatus* status, u32 dev_type);
void read_kpad_button(KPADInsideStatus* kp, KPADUnifiedWpadStatus* status, u32 dev_type);
void calc_acc(KPADInsideStatus* kp, f32* acc, f32 acc2);
static void calc_acc_horizon(KPADInsideStatus* kp);
static void calc_acc_vertical(KPADInsideStatus* kp);
static f32 clamp_acc(f32 acc, f32 clamp);
void read_kpad_acc(KPADInsideStatus* kp, KPADUnifiedWpadStatus* uwp, u32 dev_type, s32 chan);
void get_kobj(KPADInsideStatus* kp, KPADUnifiedWpadStatus* status, u32 param_2);
s8 select_2obj_first(KPADInsideStatus* kp);
static s8 select_2obj_continue(KPADInsideStatus* kp);
static s8 select_1obj_first(KPADInsideStatus* kp);
s8 select_1obj_continue(KPADInsideStatus* kp);
static void calc_dpd_variable(KPADInsideStatus* kp, s8 valid_fg_next);
static void calc_obj_horizon(KPADInsideStatus* kp);
static void check_kobj_outside_frame(KPADObject* kobj_t);
static void check_kobj_same_position(KPADObject* kobj_t);
void read_kpad_dpd(KPADInsideStatus* kp, KPADUnifiedWpadStatus* uwp, u32 dev_type);
static void clamp_stick_circle(Vec2* stick, s32 sx, s32 sy, s32 min, s32 max);
static void clamp_trigger(f32* trigger, s32 tr, s32 min, s32 max);
static void clamp_stick(Vec2* stick, s32 x, s32 y, s32 min, s32 max);
static f32 calc_horizon(KPADInsideStatus* kp, Vec2* p1, Vec2* p2, Vec2* hori);
static void clamp_stick_cross(Vec2* stick, s32 sx, s32 sy, s32 min, s32 max);
void read_kpad_stick(KPADInsideStatus* kp, KPADUnifiedWpadStatus* uwp);
s32 check_device(s32 chan, KPADInsideStatus* kp);
static BOOL is_valid_device(s32 dev_type);
static void set_dpd_disable(s32 chan, s32 dev_type);
static void set_dpd_enable(s32 chan, s32 dev_type);
static void control_dpd_start_(s32 chan);
static void control_dpd_end_(s32 chan);
static f32 calc_horizon(KPADInsideStatus* kp, Vec2* p1, Vec2* p2, Vec2* hori);
static s32 KPADiRestoreDPD(s32 chan, BOOL enable);
static void KPADiSamplingCallback(s32 chan);
#if SDK_AUG2010
s32 KPADiRead(s32 chan, KPADStatus* sampling_bufs, s32 length, s32 param_3, s32 param_4);
#endif
void KPADiControlDpdCallback(s32 chan, s32 result);
#endif /* _REVOLUTION_KPAD_PRIVATE_H_ */

View File

@ -1445,7 +1445,7 @@ void WPADSetAutoSamplingBuf(s32 chan, void* buf, u32 cnt) {
OSRestoreInterrupts(enabled);
}
u32 WPADGetLatestIndexInBuf(s32 chan, void* buf) {
u32 WPADGetLatestIndexInBuf(s32 chan) {
BOOL enable;
u32 idx;

View File

@ -268,15 +268,6 @@ extern "C" {
#define WPAD_NZFILTER_MPLS 3
#define WPAD_MAX_NZFILTERS 4
#define WPAD_DPD_IMG_RESO_WX 1024
#define WPAD_DPD_IMG_RESO_WY 768
#define WPAD_STATE_DISABLED 0
#define WPAD_STATE_ENABLING 1
#define WPAD_STATE_ENABLED 2
#define WPAD_STATE_SETUP 3
#define WPAD_STATE_DISABLING 4
#define WPAD_BATTERY_LEVEL_CRITICAL 0
#define WPAD_BATTERY_LEVEL_LOW 1
#define WPAD_BATTERY_LEVEL_MEDIUM 2
@ -286,9 +277,6 @@ extern "C" {
#define WPAD_RADIO_QUALITY_GOOD 0 // 80+
#define WPAD_RADIO_QUALITY_BAD 1 // 80-
#define WPAD_SENSOR_BAR_POS_BOTTOM 0
#define WPAD_SENSOR_BAR_POS_TOP 1
#define WPAD_RX_DATASIZE 96
#define WPAD_COMMAND_CMD_MAX_LEN 24
#if PLATFORM_SHIELD
@ -615,7 +603,6 @@ BOOL WPADiSendReadData(WPADCmdQueue* queue, void* p_buf, u16 len, u32 addr, WPAD
BOOL WPADiSendWriteData(WPADCmdQueue* queue, void* p_buf, u16 len, u32 addr, WPADCallback callback);
void WPADiCopyOut(s32 chan);
u32 WPADGetLatestIndexInBuf(s32 chan, void* buf);
void WPADiExcludeButton(s32 chan);
s32 WPADiGetStatus(s32 chan);