Revert "Implemented native Gamecube controller support and corresponding emulator hint in ROM header (#408)" (#494)

This reverts commit 4dfb8d9a64.
This commit is contained in:
Gregory Heskett
2022-09-22 07:30:02 -04:00
committed by GitHub
parent 4dfb8d9a64
commit 8864e5f3a2
15 changed files with 25 additions and 633 deletions

View File

@@ -15,14 +15,9 @@
.word 0x00000000 /* Unknown */
.word 0x00000000 /* Unknown */
.ascii INTERNAL_ROM_NAME /* Internal ROM name */
#if defined(USE_GAMECUBE_CONTROLLER)
/* Advanced homebrew ROM header bytes: https://n64brew.dev/wiki/ROM_Header#Advanced_Homebrew_ROM_Header */
.word 0x82000000
#else
.word 0x00000000 /* Unknown */
#endif
.word 0x0000004E /* Cartridge */
#if defined(EEP4K) && !defined(USE_GAMECUBE_CONTROLLER)
#if defined(EEP4K)
.ascii "SM" /* Cartridge ID */
#else
.ascii "ED" /* Cartridge ID */

View File

@@ -28,6 +28,3 @@
*/
#define BORDER_HEIGHT_CONSOLE 0
#define BORDER_HEIGHT_EMULATOR 0
// Informs supported emulators to default to gamecube controller inputs
// #define USE_GAMECUBE_CONTROLLER

View File

@@ -63,18 +63,6 @@ typedef struct {
u8 error;
} OSContPad;
// Custom extended controller pad struct that contains fields for gamecube controllers
typedef struct {
u16 button;
s8 stick_x; /* -80 <= stick_x <= 80 */
s8 stick_y; /* -80 <= stick_y <= 80 */
s8 c_stick_x;
s8 c_stick_y;
u8 l_trig;
u8 r_trig;
u8 errno;
} OSContPadEx;
typedef struct {
void *address; /* Ram pad Address: 11 bits */
u8 databuffer[32]; /* address of the data buffer */
@@ -115,7 +103,6 @@ typedef struct {
#define CONT_ABSOLUTE 0x0001
#define CONT_RELATIVE 0x0002
#define CONT_JOYPORT 0x0004
#define CONT_GCN 0x0008
#define CONT_EEPROM 0x8000
#define CONT_EEP16K 0x4000
#define CONT_TYPE_MASK 0x1f07
@@ -163,25 +150,6 @@ typedef struct {
#define L_CBUTTONS CONT_C
#define R_CBUTTONS CONT_F
#define D_CBUTTONS CONT_D
#define GCN_X_BUTTON 0x0040
#define GCN_Y_BUTTON 0x0080
/* Gamecube controller buttons */
#define CONT_GCN_GET_ORIGIN 0x2000
#define CONT_GCN_START 0x1000
#define CONT_GCN_Y 0x0800
#define CONT_GCN_X 0x0400
#define CONT_GCN_B 0x0200
#define CONT_GCN_A 0x0100
#define CONT_GCN_USE_ORIGIN 0x0080
#define CONT_GCN_L 0x0040
#define CONT_GCN_R 0x0020
#define CONT_GCN_Z 0x0010
#define CONT_GCN_UP 0x0008
#define CONT_GCN_DOWN 0x0004
#define CONT_GCN_RIGHT 0x0002
#define CONT_GCN_LEFT 0x0001
/* Controller error number */
@@ -194,9 +162,6 @@ typedef struct {
#define CONT_ERR_VOICE_WORD 14
#define CONT_ERR_VOICE_NO_RESPONSE 15
#define CONT_TYPE_N64 0
#define CONT_TYPE_GCN 1
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
@@ -213,7 +178,6 @@ typedef struct {
*
*/
extern u8 __osControllerTypes[MAXCONTROLLERS];
/**************************************************************************
*
@@ -227,13 +191,11 @@ extern s32 osContInit( OSMesgQueue *mq, u8 *bitpattern, OSContStatus *s
extern s32 osContReset( OSMesgQueue *mq, OSContStatus *status);
extern s32 osContStartQuery( OSMesgQueue *mq);
extern s32 osContStartReadData(OSMesgQueue *mq);
extern s32 osContStartReadDataEx(OSMesgQueue *mq);
#ifndef _HW_VERSION_1
extern s32 osContSetCh(u8 ch);
#endif
extern void osContGetQuery(OSContStatus *status);
extern void osContGetReadData(OSContPad *pad);
extern void osContGetReadDataEx(OSContPadEx *pad);
#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */

View File

@@ -62,14 +62,12 @@ extern "C" {
/* Rumble PAK interface */
extern s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int controller_no);
extern s32 osMotorInitEx(OSMesgQueue *mq, OSPfs *pfs, int controller_no);
#if 1
#define MOTOR_START 1
#define MOTOR_STOP 0
#define osMotorStart(x) __osMotorAccessEx((x), MOTOR_START)
#define osMotorStop(x) __osMotorAccessEx((x), MOTOR_STOP)
#define osMotorStart(x) __osMotorAccess((x), MOTOR_START)
#define osMotorStop(x) __osMotorAccess((x), MOTOR_STOP)
extern s32 __osMotorAccess(OSPfs *pfs, s32 flag);
extern s32 __osMotorAccessEx(OSPfs *pfs, s32 flag);
#else
extern s32 osMotorStop( OSPfs *pfs);
extern s32 osMotorStart(OSPfs *pfs);

View File

@@ -717,8 +717,7 @@ enum MarioActionFlags {
#define VALID_BUTTONS (A_BUTTON | B_BUTTON | Z_TRIG | START_BUTTON | \
U_JPAD | D_JPAD | L_JPAD | R_JPAD | \
L_TRIG | R_TRIG | \
U_CBUTTONS | D_CBUTTONS | L_CBUTTONS | R_CBUTTONS | \
GCN_X_BUTTON | GCN_Y_BUTTON)
U_CBUTTONS | D_CBUTTONS | L_CBUTTONS | R_CBUTTONS )
#define C_BUTTONS (U_CBUTTONS | D_CBUTTONS | L_CBUTTONS | R_CBUTTONS )

View File

@@ -42,7 +42,7 @@ struct Controller {
/*0x12*/ u16 buttonPressed;
/*0x14*/ u16 buttonReleased;
/*0x18*/ OSContStatus *statusData;
/*0x1C*/ OSContPadEx *controllerData;
/*0x1C*/ OSContPad *controllerData;
#if ENABLE_RUMBLE
/*0x20*/ s32 port;
#endif

View File

@@ -184,8 +184,6 @@ SECTIONS
lib/PR/audio/n_aspMain.o(.text*);
lib/PR/hvqm/hvqm2sp1.o(.text*);
_mainSegmentTextEnd = .;
/* Overwrite a libultra function with its modified counterpart for GCN controller support */
__osContGetInitData = __osContGetInitDataEx;
/* data */
BUILD_DIR/asm/n64_assert.o(.*data*);

View File

@@ -425,7 +425,7 @@ void thread2_crash_screen(UNUSED void *arg) {
#if ENABLE_RUMBLE
block_until_rumble_pak_free();
#endif
osContStartReadDataEx(&gSIEventMesgQueue);
osContStartReadData(&gSIEventMesgQueue);
}
read_controller_inputs(THREAD_2_CRASH_SCREEN);
draw_crash_screen(thread);

View File

@@ -43,9 +43,8 @@ struct GfxPool *gGfxPool;
// OS Controllers
OSContStatus gControllerStatuses[4];
OSContPadEx gControllerPads[4];
OSContPad gControllerPads[4];
u8 gControllerBits;
s8 gGamecubeControllerPort = -1; // HackerSM64: This is set to -1 if there's no GC controller, 0 if there's one in the first port and 1 if there's one in the second port.
u8 gIsConsole = TRUE; // Needs to be initialized before audio_reset_session is called
u8 gCacheEmulated = TRUE;
u8 gBorderHeight;
@@ -603,7 +602,7 @@ void read_controller_inputs(s32 threadID) {
if (threadID == THREAD_5_GAME_LOOP) {
osRecvMesg(&gSIEventMesgQueue, &gMainReceivedMesg, OS_MESG_BLOCK);
}
osContGetReadDataEx(&gControllerPads[0]);
osContGetReadData(&gControllerPads[0]);
#if ENABLE_RUMBLE
release_rumble_pak_control();
#endif
@@ -614,18 +613,7 @@ void read_controller_inputs(s32 threadID) {
for (i = 0; i < 2; i++) {
struct Controller *controller = &gControllers[i];
// HackerSM64: Swaps Z and L, only on console, and only when playing with a GameCube controller.
u32 oldButton = controller->controllerData->button;
if (gIsConsole && (gGamecubeControllerPort >= 0)) {
u32 newButton = oldButton & ~(Z_TRIG | L_TRIG);
if (oldButton & Z_TRIG) {
newButton |= L_TRIG;
}
if (controller->controllerData->l_trig > 85) { // How far the player has to press the L trigger for it to be considered a Z press. 64 is about 25%. 127 would be about 50%.
newButton |= Z_TRIG;
}
controller->controllerData->button = newButton;
}
// if we're receiving inputs, update the controller struct with the new button info.
if (controller->controllerData != NULL) {
controller->rawStickX = controller->controllerData->stick_x;
@@ -702,15 +690,6 @@ void init_controllers(void) {
gControllers[cont++].controllerData = &gControllerPads[port];
}
}
if (__osControllerTypes[1] == CONT_TYPE_GCN) {
gGamecubeControllerPort = 1;
gPlayer1Controller = &gControllers[1];
} else {
if (__osControllerTypes[0] == CONT_TYPE_GCN) {
gGamecubeControllerPort = 0;
}
gPlayer1Controller = &gControllers[0];
}
}
// Game thread core
@@ -790,7 +769,7 @@ void thread5_game_loop(UNUSED void *arg) {
#if ENABLE_RUMBLE
block_until_rumble_pak_free();
#endif
osContStartReadDataEx(&gSIEventMesgQueue);
osContStartReadData(&gSIEventMesgQueue);
}
audio_game_loop_tick();

View File

@@ -32,7 +32,7 @@ enum ZBmodes {
extern struct Controller gControllers[3];
extern OSContStatus gControllerStatuses[4];
extern OSContPadEx gControllerPads[4];
extern OSContPad gControllerPads[4];
extern OSMesgQueue gGameVblankQueue;
extern OSMesgQueue gGfxVblankQueue;
extern OSMesg gGameMesgBuf[1];
@@ -47,7 +47,6 @@ extern Gfx *gDisplayListHead;
extern u8 *gGfxPoolEnd;
extern struct GfxPool *gGfxPool;
extern u8 gControllerBits;
extern s8 gGamecubeControllerPort;
extern u8 gIsConsole;
extern u8 gCacheEmulated;
extern u8 gBorderHeight;

File diff suppressed because it is too large Load Diff

View File

@@ -1865,11 +1865,7 @@ void init_mario_from_save_file(void) {
gMarioState->spawnInfo = &gPlayerSpawnInfos[0];
gMarioState->statusForCamera = &gPlayerCameraState[0];
gMarioState->marioBodyState = &gBodyStates[0];
if (__osControllerTypes[1] == CONT_TYPE_GCN) {
gMarioState->controller = &gControllers[1];
} else {
gMarioState->controller = &gControllers[0];
}
gMarioState->controller = &gControllers[0];
gMarioState->animList = &gMarioAnimsBuf;
gMarioState->numCoins = 0;

View File

@@ -232,7 +232,7 @@ static void thread6_rumble_loop(UNUSED void *arg) {
sRumblePakActive = FALSE;
}
} else if (gNumVblanks % 60 == 0) {
sRumblePakActive = osMotorInitEx(&gSIEventMesgQueue, &gRumblePakPfs, gPlayer1Controller->port) < 1;
sRumblePakActive = osMotorInit(&gSIEventMesgQueue, &gRumblePakPfs, gPlayer1Controller->port) < 1;
sRumblePakErrorCount = 0;
}
@@ -243,7 +243,7 @@ static void thread6_rumble_loop(UNUSED void *arg) {
}
void cancel_rumble(void) {
sRumblePakActive = osMotorInitEx(&gSIEventMesgQueue, &gRumblePakPfs, gPlayer1Controller->port) < 1;
sRumblePakActive = osMotorInit(&gSIEventMesgQueue, &gRumblePakPfs, gPlayer1Controller->port) < 1;
if (sRumblePakActive) {
osMotorStop(&gRumblePakPfs);

View File

@@ -103,8 +103,8 @@ static struct ObjView *D_801BE994; // store if View flag 0x40 set
u8 EUpad4[0x88];
#endif
static OSContStatus D_801BAE60[4];
static OSContPadEx sGdContPads[4]; // @ 801BAE70
static OSContPadEx sPrevFrameCont[4]; // @ 801BAE88
static OSContPad sGdContPads[4]; // @ 801BAE70
static OSContPad sPrevFrameCont[4]; // @ 801BAE88
static u8 D_801BAEA0;
static struct ObjGadget *sTimerGadgets[GD_NUM_TIMERS]; // @ 801BAEA8
static u32 D_801BAF28; // RAM addr offset?
@@ -1287,12 +1287,12 @@ void gd_vblank(void) {
/**
* Copies the player1 controller data from p1cont to sGdContPads[0].
*/
void gd_copy_p1_contpad(OSContPadEx *p1cont) {
void gd_copy_p1_contpad(OSContPad *p1cont) {
u32 i; // 24
u8 *src = (u8 *) p1cont; // 20
u8 *dest = (u8 *) &sGdContPads[0]; // 1c
for (i = 0; i < sizeof(OSContPadEx); i++) {
for (i = 0; i < sizeof(OSContPad); i++) {
dest[i] = src[i];
}
@@ -2397,8 +2397,8 @@ void start_view_dl(struct ObjView *view) {
void parse_p1_controller(void) {
u32 i;
struct GdControl *gdctrl = &gGdCtrl;
OSContPadEx *currInputs;
OSContPadEx *prevInputs;
OSContPad *currInputs;
OSContPad *prevInputs;
// Copy current inputs to previous
u8 *src = (u8 *) gdctrl;
@@ -2509,7 +2509,7 @@ void parse_p1_controller(void) {
gdctrl->csrY = sScreenView->parent->upperLeft.y + sScreenView->parent->lowerRight.y - 32.0f;
}
for (i = 0; i < sizeof(OSContPadEx); i++) {
for (i = 0; i < sizeof(OSContPad); i++) {
((u8 *) prevInputs)[i] = ((u8 *) currInputs)[i];
}
}
@@ -2800,15 +2800,15 @@ s32 setup_view_buffers(const char *name, struct ObjView *view, UNUSED s32 ulx, U
/* 252AF8 -> 252BAC; orig name: _InitControllers */
void gd_init_controllers(void) {
OSContPadEx *p1cont = &sPrevFrameCont[0]; // 1c
OSContPad *p1cont = &sPrevFrameCont[0]; // 1c
u32 i; // 18
osCreateMesgQueue(&D_801BE830, D_801BE848, ARRAY_COUNT(D_801BE848));
osSetEventMesg(OS_EVENT_SI, &D_801BE830, (OSMesg) OS_MESG_SI_COMPLETE);
osContInit(&D_801BE830, &D_801BAEA0, D_801BAE60);
osContStartReadDataEx(&D_801BE830);
osContStartReadData(&D_801BE830);
for (i = 0; i < sizeof(OSContPadEx); i++) {
for (i = 0; i < sizeof(OSContPad); i++) {
((u8 *) p1cont)[i] = 0;
}
}

View File

@@ -61,7 +61,7 @@ void gdm_init(void *blockpool, u32 size);
void gdm_setup(void);
void gdm_maketestdl(s32 id);
void gd_vblank(void);
void gd_copy_p1_contpad(OSContPadEx *p1cont);
void gd_copy_p1_contpad(OSContPad *p1cont);
s32 gd_sfx_to_play(void);
Gfx *gdm_gettestdl(s32 id);
void gd_draw_rect(f32 ulx, f32 uly, f32 lrx, f32 lry);