Implement & link libultra/contreaddata, libultra finished

This commit is contained in:
Cuyler36
2025-06-19 09:36:42 -04:00
parent f906a552f5
commit 3548520687
6 changed files with 241 additions and 3 deletions
+1 -1
View File
@@ -399,7 +399,7 @@ config.libs = [
"src_dir": "src/static",
"objects": [
Object(Matching, "libultra/contquery.c"),
Object(NonMatching, "libultra/contreaddata.c"),
Object(Matching, "libultra/contreaddata.c"),
Object(Matching, "libultra/controller.c"),
Object(Matching, "libultra/contsetch.c"),
Object(Matching, "libultra/gu/coss.c"),
+23
View File
@@ -117,6 +117,29 @@ enum resource_index {
RESOURCE_NUM
};
enum {
JUT_MAINSTICK_UP = 0x8000000,
JUT_MAINSTICK_DOWN = 0x4000000,
JUT_MAINSTICK_RIGHT = 0x2000000,
JUT_MAINSTICK_LEFT = 0x1000000,
JUT_CSTICK_UP = 0x80000,
JUT_CSTICK_DOWN = 0x40000,
JUT_CSTICK_RIGHT = 0x20000,
JUT_CSTICK_LEFT = 0x10000,
JUT_START = 0x1000,
JUT_Y = 0x800,
JUT_X = 0x400,
JUT_B = 0x200,
JUT_A = 0x100,
JUT_L = 0x40,
JUT_R = 0x20,
JUT_Z = 0x10,
JUT_DPAD_UP = 0x8,
JUT_DPAD_DOWN = 0x4,
JUT_DPAD_RIGHT = 0x2,
JUT_DPAD_LEFT = 0x1
};
extern void JW_UpdateVideoMode();
extern void JW_SetProgressiveMode(int enabled);
extern void JW_SetLowResoMode(int enabled);
+7
View File
@@ -2,6 +2,7 @@
#define INITIALIZE_H
#include "types.h"
#include "dolphin/os/OSTime.h"
#ifdef __cplusplus
extern "C" {
@@ -9,6 +10,12 @@ extern "C" {
extern void __osInitialize_common();
extern BOOL osIsEnableShutdown(void);
extern BOOL osIsDisableShutdown(void);
extern OSTime osGetDisableShutdownTime(void);
extern OSTime __osShutdownTime;
extern OSTime __osDisableShutdownTime;
extern int __osShutdownDisable;
#ifdef __cplusplus
}
+9
View File
@@ -63,12 +63,21 @@ typedef struct {
/* 0x04 */ u8 errno;
} OSContPad;
typedef struct {
OSContPad pad;
s8 substickX;
s8 substickY;
u8 triggerR;
u8 triggerL;
} OSContPadEx;
extern s32 osContInit(OSMessageQueue* mq, u8* pattern_p, OSContStatus* status);
extern s32 osContStartQuery(OSMessageQueue* mq);
extern s32 osContStartReadData(OSMessageQueue* mq);
extern void osContGetQuery(OSContStatus* status);
extern s32 osContSetCh(u8 num_controllers);
extern void osContGetReadData(OSContPad* pad);
extern void osContGetReadDataEx(OSContPadEx* pad);
#ifdef __cplusplus
}
+200
View File
@@ -1,3 +1,203 @@
#include "libultra/contreaddata.h"
#include "libultra/osContPad.h"
#include "libultra/controller.h"
#include "libultra/initialize.h"
#include "libultra/osMesg.h"
#include "libultra/libultra.h"
#include <dolphin/os.h>
#include "jsyswrap.h"
#include "m_nmibuf.h"
u8 __osResetKeyStep;
u8 __osResetSwitchPressed;
extern s32 osContStartReadData(OSMessageQueue* mq) {
JW_JUTGamePad_read();
osSendMesg(mq, (OSMessage)0, OS_MESG_NOBLOCK);
return 0;
}
extern void osContGetReadData(OSContPad* pad) {
OSContPadEx padEx[PAD_MAX_CONTROLLERS];
u32 i;
osContGetReadDataEx(padEx);
for (i = 0; i < PAD_MAX_CONTROLLERS; i++) {
bcopy(&padEx[i].pad, &pad[i], sizeof(OSContPad));
}
}
extern void osContGetReadDataEx(OSContPadEx* pad) {
static u16 last_button = 0;
static u32 reset_t0 = 0;
PADStatus padStatus[PAD_MAX_CONTROLLERS];
int resetSwitchState;
PADStatus* padStatus_p;
int i;
if (osShutdown) {
OSTime time = osGetTime();
if (
(osIsEnableShutdown() && OSMicrosecondsToTicks((u64)3000000) + __osShutdownTime < time) ||
(osIsDisableShutdown() && OSMicrosecondsToTicks((u64)30000000) + osGetDisableShutdownTime() < time)
) {
osShutdownStart(OS_RESET_RESTART);
}
}
JW_getPadStatus(padStatus);
resetSwitchState = OSGetResetSwitchState();
if ((__osResetSwitchPressed || resetSwitchState != OS_RESET_RESTART)) {
if (resetSwitchState != OS_RESET_RESTART) {
if (!__osResetSwitchPressed) {
__osResetSwitchPressed = TRUE;
}
} else {
JC_JUTGamePad_recalibrate(0xF0000000); // all controllers
osShutdown = TRUE;
__osShutdownTime = osGetTime();
}
}
if ((APPNMI_ZURUMODE3_GET() || APPNMI_HOTRESET_GET()) && (padStatus[0].err == 0) && (padStatus[0].button & (s16)0xE1EF) == 0 && (padStatus[0].button & (JUT_START | JUT_X | JUT_B)) == (JUT_START | JUT_X | JUT_B)) {
u32 count = osGetCount();
if (__osResetKeyStep == 0) {
__osResetKeyStep = 1;
reset_t0 = count;
last_button = padStatus[0].button;
} else if (__osResetKeyStep == 1) {
if (padStatus[0].button != last_button) {
__osResetKeyStep = 0;
} else if (count - reset_t0 > OSMicrosecondsToTicks((u64)500000)) {
u16 jut_input;
__osResetKeyStep = 2;
jut_input = padStatus[0].button & (JUT_Y | JUT_Z);
if (jut_input == (JUT_Y | JUT_Z)) {
osShutdown = 5;
} else if (jut_input == JUT_Z) {
osShutdown = 4;
} else if (jut_input == JUT_Y) {
osShutdown = 3;
} else {
osShutdown = 2;
}
if (osShutdown != 0) {
__osShutdownTime = osGetTime();
}
}
}
} else {
__osResetKeyStep = 0;
}
for (i = 0; i < __osMaxControllers; i++, pad++) {
PADStatus curPad = padStatus[i];
if (curPad.err == PAD_ERR_TRANSFER) {
pad->pad.errno = 0;
} else {
switch (curPad.err) {
case PAD_ERR_NO_CONTROLLER:
pad->pad.errno = 8;
break;
case PAD_ERR_NOT_READY:
pad->pad.errno = 8;
break;
case PAD_ERR_TRANSFER:
pad->pad.errno = 4;
break;
default:
pad->pad.errno = 0;
break;
}
}
if (pad->pad.errno == 0) {
u16 jut_button = curPad.button;
u16 mask = jut_button & (JUT_START | JUT_X | JUT_B);
u16 button = 0;
if ((APPNMI_ZURUMODE3_GET() || APPNMI_HOTRESET_GET()) && mask == (JUT_START | JUT_X | JUT_B)) {
bzero(pad, sizeof(OSContPadEx));
} else {
if (jut_button & JUT_DPAD_LEFT) {
button |= BUTTON_DLEFT;
}
if (jut_button & JUT_DPAD_RIGHT) {
button |= BUTTON_DRIGHT;
}
if (jut_button & JUT_DPAD_DOWN) {
button |= BUTTON_DDOWN;
}
if (jut_button & JUT_DPAD_UP) {
button |= BUTTON_DUP;
}
if (jut_button & JUT_Z) {
button |= BUTTON_Z;
}
if ((jut_button & JUT_R) != 0 || curPad.triggerRight) {
button |= BUTTON_R;
}
if ((jut_button & JUT_L) != 0 || curPad.triggerLeft) {
button |= BUTTON_L;
}
if (jut_button & JUT_A) {
button |= BUTTON_A;
}
if (jut_button & JUT_B) {
button |= BUTTON_B;
}
if (jut_button & JUT_X) {
button |= BUTTON_X;
}
if (jut_button & JUT_Y) {
button |= BUTTON_Y;
}
if (jut_button & JUT_START) {
button |= BUTTON_START;
}
if (curPad.substickX >= 29) {
button |= BUTTON_CRIGHT;
}
if (curPad.substickX <= -29) {
button |= BUTTON_CLEFT;
}
if (curPad.substickY >= 29) {
button |= BUTTON_CUP;
}
if (curPad.substickY <= -29) {
button |= BUTTON_CDOWN;
}
pad->pad.button = button;
pad->pad.stick_x = curPad.stickX;
pad->pad.stick_y = curPad.stickY;
pad->substickX = curPad.substickX;
pad->substickY = curPad.substickY;
pad->triggerL = curPad.triggerLeft;
pad->triggerR = curPad.triggerRight;
}
}
}
}
+1 -2
View File
@@ -1,4 +1,3 @@
#include "dolphin/os/OSTime.h"
#include "libultra/libultra.h"
#include "libultra/contreaddata.h"
#include "libultra/controller.h"
@@ -30,7 +29,7 @@ void __osInitialize_common(void){
}
}
BOOL osIsDisableShutdown(void){
BOOL osIsDisableShutdown(void) {
return __osDisableShutdownLevel != FALSE;
}