Wii: Add libwiidrc support

This commit is contained in:
Vicki Pfau 2020-11-26 22:09:01 -08:00
parent 2e2ad70550
commit 0d96ba4f8f
3 changed files with 113 additions and 6 deletions

View File

@ -14,6 +14,7 @@ Features:
- ARM disassembler now resolves addresses to symbol names
- Add Game Boy Player feature support to ports
- Individual window types can now be toggled in debugging views
- Support for the Wii U GamePad when running as an injected VC title
Emulation fixes:
- ARM: Fix ALU reading PC after shifting
- ARM: Fix STR storing PC after address calculation

View File

@ -3,6 +3,11 @@ find_program(GXTEXCONV gxtexconv)
find_program(RAW2C raw2c)
find_program(WIILOAD wiiload)
find_library(WIIDRC_LIBRARY wiidrc)
if(WIIDRC_LIBRARY)
add_definitions(-DWIIDRC)
endif()
set(OS_DEFINES _GNU_SOURCE COLOR_16_BIT COLOR_5_6_5 USE_VFS_FILE IOAPI_NO_64 FIXED_ROM_BUFFER)
list(APPEND CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-file.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-devlist.c)
@ -20,6 +25,9 @@ set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/font.c PROPERTIES GENERA
add_executable(${BINARY_NAME}.elf ${GUI_SRC} main.c)
set_target_properties(${BINARY_NAME}.elf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
target_link_libraries(${BINARY_NAME}.elf ${BINARY_NAME} ${OS_LIB})
if(WIIDRC_LIBRARY)
target_link_libraries(${BINARY_NAME}.elf ${WIIDRC_LIBRARY})
endif()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/font.tpl
COMMAND ${GXTEXCONV} -i ${CMAKE_SOURCE_DIR}/res/font2x.png -o font.tpl colfmt=5 mipmap=no

View File

@ -28,10 +28,15 @@
#include <mgba-util/memory.h>
#include <mgba-util/vfs.h>
#ifdef WIIDRC
#include <wiidrc/wiidrc.h>
#endif
#define GCN1_INPUT 0x47434E31
#define GCN2_INPUT 0x47434E32
#define WIIMOTE_INPUT 0x5749494D
#define CLASSIC_INPUT 0x57494943
#define DRC_INPUT 0x44524355
#define TEX_W 256
#define TEX_H 224
@ -254,6 +259,9 @@ int main(int argc, char* argv[]) {
PAD_Init();
WPAD_Init();
WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
#ifdef WIIDRC
WiiDRC_Init();
#endif
AUDIO_Init(0);
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
AUDIO_RegisterDMACallback(_audioDMA);
@ -452,6 +460,31 @@ int main(int argc, char* argv[]) {
},
.nKeys = 32
},
#ifdef WIIDRC
{
.name = "Wii U GamePad Input",
.id = DRC_INPUT,
.keyNames = (const char*[]) {
0, // Sync
"\1\xE",
"-",
"+",
"R",
"L",
"ZR",
"ZL",
"Down",
"Up",
"Right",
"Left",
"Y",
"X",
"B",
"A",
},
.nKeys = 16
},
#endif
{ .id = 0 }
},
.configExtra = (struct GUIMenuItem[]) {
@ -576,6 +609,15 @@ int main(int argc, char* argv[]) {
_mapKey(&runner.params.keyMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_LEFT, GUI_INPUT_LEFT);
_mapKey(&runner.params.keyMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_RIGHT, GUI_INPUT_RIGHT);
#ifdef WIIDRC
_mapKey(&runner.params.keyMap, DRC_INPUT, WIIDRC_BUTTON_A, GUI_INPUT_SELECT);
_mapKey(&runner.params.keyMap, DRC_INPUT, WIIDRC_BUTTON_B, GUI_INPUT_BACK);
_mapKey(&runner.params.keyMap, DRC_INPUT, WIIDRC_BUTTON_X, GUI_INPUT_CANCEL);
_mapKey(&runner.params.keyMap, DRC_INPUT, WIIDRC_BUTTON_UP, GUI_INPUT_UP);
_mapKey(&runner.params.keyMap, DRC_INPUT, WIIDRC_BUTTON_DOWN, GUI_INPUT_DOWN);
_mapKey(&runner.params.keyMap, DRC_INPUT, WIIDRC_BUTTON_LEFT, GUI_INPUT_LEFT);
_mapKey(&runner.params.keyMap, DRC_INPUT, WIIDRC_BUTTON_RIGHT, GUI_INPUT_RIGHT);
#endif
float stretch = 0;
if (mCoreConfigGetFloatValue(&runner.config, "stretchWidth", &stretch)) {
@ -701,29 +743,48 @@ static uint32_t _pollInput(const struct mInputMap* map) {
u32 ext = 0;
WPAD_Probe(0, &ext);
#ifdef WIIDRC
u32 drckeys = 0;
if (WiiDRC_ScanPads()) {
drckeys = WiiDRC_ButtonsHeld();
}
#endif
int keys = 0;
keys |= mInputMapKeyBits(map, GCN1_INPUT, padkeys, 0);
keys |= mInputMapKeyBits(map, GCN2_INPUT, padkeys, 0);
keys |= mInputMapKeyBits(map, WIIMOTE_INPUT, wiiPad, 0);
#ifdef WIIDRC
keys |= mInputMapKeyBits(map, DRC_INPUT, drckeys, 0);
#endif
if (ext == WPAD_EXP_CLASSIC) {
keys |= mInputMapKeyBits(map, CLASSIC_INPUT, wiiPad, 0);
}
int x = PAD_StickX(0);
int y = PAD_StickY(0);
int w_x = WPAD_StickX(0, 0);
int w_y = WPAD_StickY(0, 0);
if (x < -ANALOG_DEADZONE || w_x < -ANALOG_DEADZONE) {
int wX = WPAD_StickX(0, 0);
int wY = WPAD_StickY(0, 0);
ATTRIBUTE_UNUSED int drcX = 0;
ATTRIBUTE_UNUSED int drcY = 0;
#ifdef WIIDRC
if (WiiDRC_Connected()) {
drcX = WiiDRC_lStickX();
drcY = WiiDRC_lStickY();
}
#endif
if (x < -ANALOG_DEADZONE || wX < -ANALOG_DEADZONE || drcX < -ANALOG_DEADZONE) {
keys |= 1 << GUI_INPUT_LEFT;
}
if (x > ANALOG_DEADZONE || w_x > ANALOG_DEADZONE) {
if (x > ANALOG_DEADZONE || wX > ANALOG_DEADZONE || drcX > ANALOG_DEADZONE) {
keys |= 1 << GUI_INPUT_RIGHT;
}
if (y < -ANALOG_DEADZONE || w_y < -ANALOG_DEADZONE) {
if (y < -ANALOG_DEADZONE || wY < -ANALOG_DEADZONE || drcY < -ANALOG_DEADZONE) {
keys |= 1 << GUI_INPUT_DOWN;
}
if (y > ANALOG_DEADZONE || w_y > ANALOG_DEADZONE) {
if (y > ANALOG_DEADZONE || wY > ANALOG_DEADZONE || drcY > ANALOG_DEADZONE) {
keys |= 1 << GUI_INPUT_UP;
}
return keys;
}
@ -803,12 +864,27 @@ void _setup(struct mGUIRunner* runner) {
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_FULL_L, GBA_KEY_L);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_FULL_R, GBA_KEY_R);
#ifdef WIIDRC
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_A, GBA_KEY_A);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_B, GBA_KEY_B);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_PLUS, GBA_KEY_START);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_MINUS, GBA_KEY_SELECT);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_UP, GBA_KEY_UP);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_DOWN, GBA_KEY_DOWN);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_LEFT, GBA_KEY_LEFT);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_RIGHT, GBA_KEY_RIGHT);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_L, GBA_KEY_L);
_mapKey(&runner->core->inputMap, DRC_INPUT, WIIDRC_BUTTON_R, GBA_KEY_R);
#endif
struct mInputAxis desc = { GBA_KEY_RIGHT, GBA_KEY_LEFT, ANALOG_DEADZONE, -ANALOG_DEADZONE };
mInputBindAxis(&runner->core->inputMap, GCN1_INPUT, 0, &desc);
mInputBindAxis(&runner->core->inputMap, CLASSIC_INPUT, 0, &desc);
mInputBindAxis(&runner->core->inputMap, DRC_INPUT, 0, &desc);
desc = (struct mInputAxis) { GBA_KEY_UP, GBA_KEY_DOWN, ANALOG_DEADZONE, -ANALOG_DEADZONE };
mInputBindAxis(&runner->core->inputMap, GCN1_INPUT, 1, &desc);
mInputBindAxis(&runner->core->inputMap, CLASSIC_INPUT, 1, &desc);
mInputBindAxis(&runner->core->inputMap, DRC_INPUT, 1, &desc);
outputBuffer = memalign(32, TEX_W * TEX_H * BYTES_PER_PIXEL);
runner->core->setVideoBuffer(runner->core, outputBuffer, TEX_W);
@ -1033,9 +1109,18 @@ uint16_t _pollGameInput(struct mGUIRunner* runner) {
u32 wiiPad = WPAD_ButtonsHeld(0);
u32 ext = 0;
WPAD_Probe(0, &ext);
#ifdef WIIDRC
u32 drckeys = 0;
if (WiiDRC_ScanPads()) {
drckeys = WiiDRC_ButtonsHeld();
}
#endif
uint16_t keys = mInputMapKeyBits(&runner->core->inputMap, GCN1_INPUT, padkeys, 0);
keys |= mInputMapKeyBits(&runner->core->inputMap, GCN2_INPUT, padkeys, 0);
keys |= mInputMapKeyBits(&runner->core->inputMap, WIIMOTE_INPUT, wiiPad, 0);
#ifdef WIIDRC
keys |= mInputMapKeyBits(&runner->core->inputMap, DRC_INPUT, drckeys, 0);
#endif
enum GBAKey angles = mInputMapAxis(&runner->core->inputMap, GCN1_INPUT, 0, PAD_StickX(0));
if (angles != GBA_KEY_NONE) {
@ -1056,6 +1141,19 @@ uint16_t _pollGameInput(struct mGUIRunner* runner) {
keys |= 1 << angles;
}
}
#ifdef WIIDRC
if (WiiDRC_Connected()) {
keys |= mInputMapKeyBits(&runner->core->inputMap, DRC_INPUT, drckeys, 0);
angles = mInputMapAxis(&runner->core->inputMap, DRC_INPUT, 0, WiiDRC_lStickX());
if (angles != GBA_KEY_NONE) {
keys |= 1 << angles;
}
angles = mInputMapAxis(&runner->core->inputMap, DRC_INPUT, 1, WiiDRC_lStickY());
if (angles != GBA_KEY_NONE) {
keys |= 1 << angles;
}
}
#endif
return keys;
}