diff --git a/Makefile.wii b/Makefile.wii index 10db880..53c46b9 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -30,7 +30,7 @@ INCLUDES := core core/m68k core/z80 core/sound core/tremor core/ntsc core/input_ CFLAGS = -O3 -fomit-frame-pointer --param large-function-growth=800 --param inline-unit-growth=200 -Wall -Winline -Wno-strict-aliasing $(MACHDEP) $(INCLUDE) -DUSE_LIBTREMOR -DUSE_16BPP_RENDERING -DALT_RENDERER -DHW_RVL CXXFLAGS = $(CFLAGS) -LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map +LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map,-wrap,wiiuse_set_ir,-wrap,wiiuse_handshake,-wrap,classic_ctrl_handshake,-wrap,classic_ctrl_event #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project diff --git a/builds/genplus_cube.dol b/builds/genplus_cube.dol index 61e0826..903562d 100644 Binary files a/builds/genplus_cube.dol and b/builds/genplus_cube.dol differ diff --git a/builds/genplus_wii.dol b/builds/genplus_wii.dol index f4c81cc..8dede53 100644 Binary files a/builds/genplus_wii.dol and b/builds/genplus_wii.dol differ diff --git a/core/cd_hw/scd.c b/core/cd_hw/scd.c index 651ff9c..9287ed5 100644 --- a/core/cd_hw/scd.c +++ b/core/cd_hw/scd.c @@ -2,7 +2,7 @@ * Genesis Plus * Mega CD / Sega CD hardware * - * Copyright (C) 2012-2014 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2012-2015 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -1094,7 +1094,7 @@ void scd_init(void) m68k.memory_map[i].write8 = NULL; m68k.memory_map[i].write16 = NULL; zbank_memory_map[i].read = NULL; - zbank_memory_map[i].write = NULL; + zbank_memory_map[i].write = zbank_unused_w; /* Z80 cannot write to PRG-RAM (Dungeon Explorer USA version) */ } else diff --git a/core/cd_hw/scd.h b/core/cd_hw/scd.h index a9c5320..aad230e 100644 --- a/core/cd_hw/scd.h +++ b/core/cd_hw/scd.h @@ -2,7 +2,7 @@ * Genesis Plus * Mega CD / Sega CD hardware * - * Copyright (C) 2012-2014 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2012-2015 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: diff --git a/core/loadrom.c b/core/loadrom.c index 30b43a2..e21f91b 100644 --- a/core/loadrom.c +++ b/core/loadrom.c @@ -3,7 +3,7 @@ * ROM Loading Support * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) - * Copyright (C) 2007-2014 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2015 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -735,12 +735,20 @@ int load_rom(char *filename) /* try to load CD BOOTROM */ if (load_bios()) { + char *ptr; + char fname[256]; + /* boot from cartridge */ scd.cartridge.boot = 0x40; /* automatically load associated .iso image */ - strncpy(&filename[strlen(filename) - 4], ".iso", 4); - cdd_load(filename, (char *)cdc.ram); + strncpy(fname, filename, 256); + ptr = strchr(fname,'.'); + if (ptr && (ptr < &fname[252])) + { + strcpy(ptr+1,"iso"); + } + cdd_load(fname, (char *)cdc.ram); } else { diff --git a/core/loadrom.h b/core/loadrom.h index 5f13ffa..4eb5bf3 100644 --- a/core/loadrom.h +++ b/core/loadrom.h @@ -3,7 +3,7 @@ * ROM Loading Support * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) - * Copyright (C) 2007-2014 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2015 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: diff --git a/gx/gui/menu.c b/gx/gui/menu.c index e56c31c..9f510ea 100644 --- a/gx/gui/menu.c +++ b/gx/gui/menu.c @@ -3,7 +3,7 @@ * * Genesis Plus GX menu * - * Copyright Eke-Eke (2009-2014) + * Copyright Eke-Eke (2009-2015) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -395,11 +395,11 @@ static gui_item items_video[] = {NULL,NULL,"Display: PROGRESSIVE", "Select video mode", 56,132,276,48}, {NULL,NULL,"TV mode: 50/60HZ", "Select video refresh rate", 56,132,276,48}, {NULL,NULL,"VSYNC: AUTO", "Enable/disable sync with video hardware", 56,132,276,48}, - {NULL,NULL,"GX Bilinear Filter: OFF", "Enable/disable hardware texture filtering", 56,132,276,48}, - {NULL,NULL,"GX Deflickering Filter: OFF", "Enable/disable hardware GX filtering", 56,132,276,48}, + {NULL,NULL,"Bilinear Filter: OFF", "Enable/disable GX hardware texture filtering", 56,132,276,48}, + {NULL,NULL,"Deflickering Filter: AUTO", "Enable/disable GX hardware framebuffer filtering", 56,132,276,48}, #ifdef HW_RVL - {NULL,NULL,"VI Trap Filter: ON", "Enable/disable hardware composite video filtering", 56,132,276,48}, - {NULL,NULL,"VI Gamma Correction: 1.0", "Adjust video hardware gamma correction", 56,132,276,48}, + {NULL,NULL,"Trap Filter: ON", "Enable/disable VI hardware composite out filtering",56,132,276,48}, + {NULL,NULL,"Gamma Correction: 1.0", "Adjust VI hardware gamma correction", 56,132,276,48}, #endif {NULL,NULL,"LCD Ghosting Filter: OFF", "Enable/disable software LCD image persistence", 56,132,276,48}, {NULL,NULL,"NTSC Filter: COMPOSITE", "Enable/disable software NTSC filtering", 56,132,276,48}, @@ -1679,12 +1679,12 @@ static void videomenu () else sprintf (items[2].text, "VSYNC: OFF"); - sprintf (items[3].text, "GX Bilinear Filter: %s", config.bilinear ? " ON" : "OFF"); - sprintf (items[4].text, "GX Deflickering Filter: %s", config.vfilter ? " ON" : "OFF"); + sprintf (items[3].text, "Bilinear Filter: %s", config.bilinear ? " ON" : "OFF"); + sprintf (items[4].text, "Deflickering Filter: %s", config.vfilter ? "AUTO" : "OFF"); #ifdef HW_RVL - sprintf (items[5].text, "VI Trap Filter: %s", config.trap ? " ON" : "OFF"); - sprintf (items[6].text, "VI Gamma Correction: %1.1f", config.gamma); + sprintf (items[5].text, "Trap Filter: %s", config.trap ? " ON" : "OFF"); + sprintf (items[6].text, "Gamma Correction: %1.1f", config.gamma); #endif if (config.lcd > 0) @@ -1820,14 +1820,14 @@ static void videomenu () case 3: /*** GX Texture filtering ***/ { config.bilinear ^= 1; - sprintf (items[3].text, "GX Bilinear Filter: %s", config.bilinear ? " ON" : "OFF"); + sprintf (items[3].text, "Bilinear Filter: %s", config.bilinear ? " ON" : "OFF"); break; } case 4: /*** GX Copy filtering (deflickering filter) ***/ { config.vfilter ^= 1; - sprintf (items[4].text, "GX Deflicker Filter: %s", config.vfilter ? " ON" : "OFF"); + sprintf (items[4].text, "Deflickering Filter: %s", config.vfilter ? "AUTO" : "OFF"); break; } @@ -1835,7 +1835,7 @@ static void videomenu () case 5: /*** VIDEO Trap filtering ***/ { config.trap ^= 1; - sprintf (items[5].text, "VI Trap Filter: %s", config.trap ? " ON" : "OFF"); + sprintf (items[5].text, "Trap Filter: %s", config.trap ? " ON" : "OFF"); break; } @@ -1852,14 +1852,14 @@ static void videomenu () m->arrows[1]->state = 0; m->screenshot = 255; strcpy(m->title,""); - GUI_OptionBox(m,update_gamma,"VI Gamma Correction",(void *)&config.gamma,0.1,0.1,3.0,0); + GUI_OptionBox(m,update_gamma,"Gamma Correction",(void *)&config.gamma,0.1,0.1,3.0,0); m->max_buttons = 4; m->max_images = 6; m->arrows[0]->state = state[0]; m->arrows[1]->state = state[1]; m->screenshot = 0; strcpy(m->title,"Video Settings"); - sprintf (items[6].text, "VI Gamma Correction: %1.1f", config.gamma); + sprintf (items[6].text, "Gamma Correction: %1.1f", config.gamma); VIDEO_SetGamma(VI_GM_1_0); VIDEO_Flush(); } @@ -2825,23 +2825,22 @@ static void ctrlmenu(void) /* autodetect connected wiimotes (without nunchuk) */ if (config.input[player].device == 1) { - /* test current port */ - exp = 255; - if (config.input[player].port < 4) - { - WPAD_Probe(config.input[player].port,&exp); - } - /* find first connected controller */ + exp = 255; while ((config.input[player].port < 4) && (exp == 255)) { - /* try next port */ - config.input[player].port ++; - if (config.input[player].port < 4) + WPAD_Probe(config.input[player].port,&exp); + + /* check if this is a Wii U Pro Controller */ + if (exp == WPAD_EXP_CLASSIC) { - exp = 255; - WPAD_Probe(config.input[player].port,&exp); + WPADData *data = WPAD_Data(config.input[player].port); + exp = data->exp.classic.rjs.max.x; } + + /* try next port if no wimote available */ + if (exp == 255) + config.input[player].port ++; } /* no more wiimote */ diff --git a/gx/gui/menu.h b/gx/gui/menu.h index b8608bd..6398d4b 100644 --- a/gx/gui/menu.h +++ b/gx/gui/menu.h @@ -3,7 +3,7 @@ * * Genesis Plus GX menus * - * Copyright Eke-Eke (2009-2014) + * Copyright Eke-Eke (2009-2015) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: diff --git a/gx/gx_input.c b/gx/gx_input.c index 3682c45..d51aab0 100644 --- a/gx/gx_input.c +++ b/gx/gx_input.c @@ -3,7 +3,7 @@ * * Genesis Plus GX input support * - * Copyright Eke-Eke (2007-2014) + * Copyright Eke-Eke (2007-2015) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -1168,7 +1168,17 @@ int gx_input_FindDevices(void) { wpad = 255; WPAD_Probe(config.input[player].port, &wpad); - if (wpad != 255) + + /* make sure this is not a Wii U Pro Controller */ + if (wpad == WPAD_EXP_CLASSIC) + { + WPADData *data = WPAD_Data(config.input[player].port); + if (data->exp.classic.rjs.max.x != 255) + { + found++; + } + } + else if (wpad != 255) { found++; } @@ -1183,39 +1193,6 @@ int gx_input_FindDevices(void) if (wpad == (config.input[player].device - 1)) { found++; - - /* some 3rd party classic controllers return invalid factory calibration data */ - if (wpad == EXP_CLASSIC) - { - /* WPAD data */ - WPADData *data = WPAD_Data(config.input[player].port); - - /* Left analog stick */ - struct joystick_t* js = &data->exp.classic.ljs; - - /* Check acquired calibration data */ - if ((js->max.x <= js->center.x) || (js->min.x >= js->center.x) || - (js->max.y <= js->center.y) || (js->min.y >= js->center.y)) - { - /* Reset to default values */ - js->min.x = js->min.y = 0; - js->max.x = js->max.y = 64; - js->center.x = js->center.y = 32; - } - - /* Right analog stick */ - js = &data->exp.classic.rjs; - - /* Check acquired calibration data */ - if ((js->max.x <= js->center.x) || (js->min.x >= js->center.x) || - (js->max.y <= js->center.y) || (js->min.y >= js->center.y)) - { - /* Reset to default values */ - js->min.x = js->min.y = 0; - js->max.x = js->max.y = 32; - js->center.x = js->center.y = 16; - } - } } break; } @@ -1329,12 +1306,17 @@ void gx_input_SetDefault(void) /* look for unused Wiimotes */ for (j=0; jexp.classic.rjs.max.x != 255) + { + /* Wiimote is available */ + config.input[i].device = 1; + config.input[i].port = j; + } } } } @@ -1608,36 +1590,6 @@ void gx_input_UpdateMenu(void) /* WPAD held keys (direction/selection) */ u32 hw = data->btns_h & WPAD_BUTTONS_HELD; - /* Some 3rd party classic controllers return invalid factory calibration data */ - if (data->exp.type == EXP_CLASSIC) - { - /* Left analog stick */ - struct joystick_t* js = &data->exp.classic.ljs; - - /* Check acquired calibration data */ - if ((js->max.x <= js->center.x) || (js->min.x >= js->center.x) || - (js->max.y <= js->center.y) || (js->min.y >= js->center.y)) - { - /* Reset to default values */ - js->min.x = js->min.y = 0; - js->max.x = js->max.y = 64; - js->center.x = js->center.y = 32; - } - - /* Right analog stick */ - js = &data->exp.classic.rjs; - - /* Check acquired calibration data */ - if ((js->max.x <= js->center.x) || (js->min.x >= js->center.x) || - (js->max.y <= js->center.y) || (js->min.y >= js->center.y)) - { - /* Reset to default values */ - js->min.x = js->min.y = 0; - js->max.x = js->max.y = 32; - js->center.x = js->center.y = 16; - } - } - /* WPAD analog sticks (handled as PAD held direction keys) */ x = wpad_StickX(data, 0); y = wpad_StickY(data, 0); diff --git a/gx/gx_input.h b/gx/gx_input.h index 070cbf6..6d50c0c 100644 --- a/gx/gx_input.h +++ b/gx/gx_input.h @@ -3,7 +3,7 @@ * * Genesis Plus GX input support * - * Copyright Eke-Eke (2007-2014) + * Copyright Eke-Eke (2007-2015) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: diff --git a/gx/utils/wrap_wiiuse.c b/gx/utils/wrap_wiiuse.c new file mode 100644 index 0000000..3b1ab25 --- /dev/null +++ b/gx/utils/wrap_wiiuse.c @@ -0,0 +1,189 @@ +/**************************************************************************** + * wrap_wiiuse.c + * + * libwiiuse wrapper for 3rd-party Classic Controller & Wii U Pro Controller support + * + * Copyright (C) 2015 Eke-Eke, based on technical info & code from Tueidj + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************************/ + +#ifdef HW_RVL + +#include +#include + +#define WM_EXP_MEM_BASE 0x04A40000 + +#define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02 + +#define WIIMOTE_STATE_WIIU_PRO_FOUND 0x00002 +#define WIIMOTE_STATE_HANDSHAKE 0x00004 +#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x00008 + +extern void __real_wiiuse_handshake(struct wiimote_t *wm,ubyte *data,uword len); +extern void __real_wiiuse_set_ir(struct wiimote_t *wm,int status); +extern int __real_classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, ubyte* data, uword len); + +static ubyte id[2]; + +void __wrap_wiiuse_handshake(struct wiimote_t *wm,ubyte *data,uword len) +{ + if (!wm->handshake_state) + { + if (len==0) + { + /* 1st step : read wiimote status (this will also starts expansion handshake if one is connected) */ + wiiuse_set_leds(wm,WIIMOTE_LED_NONE,NULL); + wiiuse_status(wm,__wrap_wiiuse_handshake); + return; + } + + if (len > 2) + { + /* 2nd step: read expansion controller ID (if connected) */ + if (data[2]&WM_CTRL_STATUS_BYTE1_ATTACHMENT) + { + wiiuse_read_data(wm,id,WM_EXP_MEM_BASE+0xFE,2,__wrap_wiiuse_handshake); + return; + } + } + else + { + /* 3rd step: finish handshake without trying to read internal memory if Wii U pro controller is detected */ + if ((data[0]==0x01) && (data[1]==0x20)) + { + int *state = (int *)&wm->state; + WIIUSE_EVENT_TYPE *event = (WIIUSE_EVENT_TYPE *)&wm->event; + *state &= ~WIIMOTE_STATE_HANDSHAKE; + *state |= (WIIMOTE_STATE_HANDSHAKE_COMPLETE | WIIMOTE_STATE_WIIU_PRO_FOUND); + *event = WIIUSE_CONNECT; + wiiuse_status(wm,NULL); + return; + } + } + } + + /* proceed with default handshake sequence */ + __real_wiiuse_handshake(wm,data,len); +} + +void __wrap_wiiuse_set_ir(struct wiimote_t *wm,int status) +{ + /* do not enable IR on Wii U Pro Controller */ + if (wm->state & WIIMOTE_STATE_WIIU_PRO_FOUND) + { + /* this will force data report modes 0x34 or 0x35 */ + wiiuse_status(wm,NULL); + return; + } + + __real_wiiuse_set_ir(wm,status); +} + +int __wrap_classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, ubyte* data, uword len) +{ + /* detect Wii U Pro Controller */ + if ((len > 223) && (data[222] == 0x01) && (data[223] == 0x20)) + { + /* set default calibration values */ + cc->btns = 0; + cc->btns_held = 0; + cc->btns_released = 0; + cc->ljs.max.x = cc->ljs.max.y = cc->rjs.max.x = cc->rjs.max.y = 255; + cc->ljs.min.x = cc->ljs.min.y = cc->rjs.min.x = cc->rjs.min.y = 0; + cc->ljs.center.x = cc->ljs.center.y = cc->rjs.center.x = cc->rjs.center.y = 128; + + /* finish expansion handshake */ + int *type = (int *)&wm->exp.type; + *type = EXP_CLASSIC; + return 1; + } + + /* sometimes the first 16 bytes are invalid but the next 16 bytes are ok (?) */ + if (data[0] == 0xFF) + { + if (data[16] != 0xFF) + data += 16; + } + + /* some 3rd-party classic controllers return invalid factory calibration data */ + if ((data[0] <= data[2]) || (data[1] >= data[2]) || (data[3] <= data[5]) || (data[4] >= data[5]) || + (data[6] <= data[8]) || (data[7] >= data[8]) || (data[9] <= data[11]) || (data[10] >= data[11])) + { + /* this will reset to default values */ + memset(data, 0, 16); + } + + return __real_classic_ctrl_handshake(wm, cc, data, len); +} + +void __wrap_classic_ctrl_event(struct classic_ctrl_t* cc, ubyte* msg) +{ + /* save previously pressed buttons */ + cc->btns_last = cc->btns; + + /* detect Wii U pro controller */ + if (cc->rjs.max.x == 0xFF) + { + /* pressed buttons (0 is active, 1 is inactive) */ + cc->btns = ~((msg[8] << 8) | msg[9]) & CLASSIC_CTRL_BUTTON_ALL; + + /* convert 12-bit little endian analog joysticks position to 8-bit values */ + cc->ljs.pos.x = (msg[0] >> 4) | (msg[1] << 4); + cc->rjs.pos.x = (msg[2] >> 4) | (msg[3] << 4); + cc->ljs.pos.y = (msg[4] >> 4) | (msg[5] << 4); + cc->rjs.pos.y = (msg[6] >> 4) | (msg[7] << 4); + + /* left/right triggers (not analog) */ + cc->ls_raw = cc->btns & CLASSIC_CTRL_BUTTON_FULL_L ? 0x1F : 0; + cc->rs_raw = cc->btns & CLASSIC_CTRL_BUTTON_FULL_R ? 0x1F : 0; + } + else + { + /* pressed buttons (0 is active, 1 is inactive) */ + cc->btns = ~((msg[4] << 8) | msg[5]) & CLASSIC_CTRL_BUTTON_ALL; + + /* analog joysticks position */ + cc->ljs.pos.x = (msg[0] & 0x3F); + cc->ljs.pos.y = (msg[1] & 0x3F); + cc->rjs.pos.x = ((msg[0] & 0xC0) >> 3) | ((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7); + cc->rjs.pos.y = (msg[2] & 0x1F); + + /* left/right triggers (analog) */ + cc->ls_raw = (((msg[2] & 0x60) >> 2) | ((msg[3] & 0xE0) >> 5)); + cc->rs_raw = (msg[3] & 0x1F); + } + + /* held buttons */ + cc->btns_held = (cc->btns & cc->btns_last); + + /* released buttons */ + cc->btns_released = (~cc->btns & cc->btns_last); +} + +#endif