mirror of
https://github.com/libretro/libretro-fceumm.git
synced 2024-12-28 03:45:48 +00:00
Merge pull request #527 from DigiDwrf/master
Add sequential targets light gun support
This commit is contained in:
commit
fe05e00b52
@ -4,3 +4,5 @@
|
||||
# FCE Ultra mappers modified
|
||||
FCEU "mappers modified" is an unofficial build of FCEU Ultra by CaH4e3, which supports a lot of new mappers including some obscure mappers such as one for unlicensed NES ROM's.
|
||||
|
||||
# Sequential targets Light Guns support added
|
||||
Support for Sequential targets Light Guns has been added. "Gun Aux A" serves as light sensor logic input.
|
@ -47,17 +47,17 @@
|
||||
#define MAX_PORTS 2 /* max controller ports,
|
||||
* port 0 for player 1/3, port 1 for player 2/4 */
|
||||
|
||||
#define RETRO_DEVICE_AUTO RETRO_DEVICE_JOYPAD
|
||||
#define RETRO_DEVICE_GAMEPAD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1)
|
||||
#define RETRO_DEVICE_ZAPPER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 0)
|
||||
#define RETRO_DEVICE_ARKANOID RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 1)
|
||||
#define RETRO_DEVICE_AUTO RETRO_DEVICE_JOYPAD
|
||||
#define RETRO_DEVICE_GAMEPAD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1)
|
||||
#define RETRO_DEVICE_ZAPPER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 0)
|
||||
#define RETRO_DEVICE_ARKANOID RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 1)
|
||||
|
||||
#define RETRO_DEVICE_FC_ARKANOID RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 2)
|
||||
#define RETRO_DEVICE_FC_OEKAKIDS RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 3)
|
||||
#define RETRO_DEVICE_FC_SHADOW RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 4)
|
||||
#define RETRO_DEVICE_FC_4PLAYERS RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 2)
|
||||
#define RETRO_DEVICE_FC_ARKANOID RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 2)
|
||||
#define RETRO_DEVICE_FC_OEKAKIDS RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 3)
|
||||
#define RETRO_DEVICE_FC_SHADOW RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 4)
|
||||
#define RETRO_DEVICE_FC_4PLAYERS RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 2)
|
||||
#define RETRO_DEVICE_FC_HYPERSHOT RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 3)
|
||||
#define RETRO_DEVICE_FC_AUTO RETRO_DEVICE_JOYPAD
|
||||
#define RETRO_DEVICE_FC_AUTO RETRO_DEVICE_JOYPAD
|
||||
|
||||
#define NES_WIDTH 256
|
||||
#define NES_HEIGHT 240
|
||||
@ -141,14 +141,15 @@ typedef struct {
|
||||
uint32_t type[MAX_PLAYERS + 1]; /* 4-players + famicom expansion */
|
||||
|
||||
/* input data */
|
||||
uint32_t JSReturn; /* player input data, 1 byte per player (1-4) */
|
||||
uint32_t MouseData[MAX_PORTS][3]; /* nes mouse data */
|
||||
uint32_t FamicomData[3]; /* Famicom expansion port data */
|
||||
uint32_t JSReturn; /* player input data, 1 byte per player (1-4) */
|
||||
uint32_t MouseData[MAX_PORTS][4]; /* nes mouse data */
|
||||
uint32_t FamicomData[3]; /* Famicom expansion port data */
|
||||
} NES_INPUT_T;
|
||||
|
||||
static NES_INPUT_T nes_input = { 0 };
|
||||
enum RetroZapperInputModes{RetroLightgun, RetroMouse, RetroPointer};
|
||||
static enum RetroZapperInputModes zappermode = RetroLightgun;
|
||||
enum RetroZapperInputModes{RetroCLightgun, RetroSTLightgun, RetroMouse, RetroPointer};
|
||||
enum RetroZapperInputModes zappermode = RetroCLightgun;
|
||||
extern int switchZapper;
|
||||
|
||||
static bool libretro_supports_bitmasks = false;
|
||||
static bool libretro_supports_option_categories = false;
|
||||
@ -206,6 +207,8 @@ extern CartInfo iNESCart;
|
||||
extern CartInfo UNIFCart;
|
||||
extern int show_crosshair;
|
||||
extern int option_ramstate;
|
||||
extern int zapper_trigger_invert_option;
|
||||
extern int zapper_sensor_invert_option;
|
||||
|
||||
/* emulator-specific callback functions */
|
||||
|
||||
@ -1949,9 +1952,22 @@ static void check_variables(bool startup)
|
||||
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
||||
{
|
||||
if (!strcmp(var.value, "mouse")) zappermode = RetroMouse;
|
||||
else if (!strcmp(var.value, "touchscreen")) zappermode = RetroPointer;
|
||||
else zappermode = RetroLightgun; /*default setting*/
|
||||
if (!strcmp(var.value, "mouse")) {
|
||||
zappermode = RetroMouse;
|
||||
switchZapper = 0;
|
||||
}
|
||||
else if (!strcmp(var.value, "touchscreen")) {
|
||||
zappermode = RetroPointer;
|
||||
switchZapper = 0;
|
||||
}
|
||||
else if (!strcmp(var.value, "stlightgun")) {
|
||||
zappermode = RetroSTLightgun;
|
||||
switchZapper = 1;
|
||||
}
|
||||
else {
|
||||
zappermode = RetroCLightgun; /*default setting*/
|
||||
switchZapper = 0;
|
||||
}
|
||||
}
|
||||
|
||||
var.key = "fceumm_zapper_tolerance";
|
||||
@ -1969,6 +1985,22 @@ static void check_variables(bool startup)
|
||||
else if (!strcmp(var.value, "disabled")) show_crosshair = 0;
|
||||
}
|
||||
|
||||
var.key = "fceumm_zapper_trigger";
|
||||
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
||||
{
|
||||
if (!strcmp(var.value, "enabled")) zapper_trigger_invert_option = 1;
|
||||
else if (!strcmp(var.value, "disabled")) zapper_trigger_invert_option = 0;
|
||||
}
|
||||
|
||||
var.key = "fceumm_zapper_sensor";
|
||||
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
||||
{
|
||||
if (!strcmp(var.value, "enabled")) zapper_sensor_invert_option = 1;
|
||||
else if (!strcmp(var.value, "disabled")) zapper_sensor_invert_option = 0;
|
||||
}
|
||||
|
||||
#ifdef PSP
|
||||
var.key = "fceumm_overscan";
|
||||
|
||||
@ -2195,6 +2227,9 @@ void get_mouse_input(unsigned port, uint32_t *zapdata)
|
||||
|
||||
if (zappermode == RetroMouse) /* mouse device */
|
||||
{
|
||||
int mouse_Lbutton;
|
||||
int mouse_Rbutton;
|
||||
|
||||
min_width = (adjx ? 8 : 0) + 1;
|
||||
min_height = (adjy ? 8 : 0) + 1;
|
||||
max_width -= (adjx ? 8 : 0);
|
||||
@ -2213,10 +2248,13 @@ void get_mouse_input(unsigned port, uint32_t *zapdata)
|
||||
|
||||
zapdata[0] = mzx;
|
||||
zapdata[1] = mzy;
|
||||
|
||||
mouse_Lbutton = input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
|
||||
mouse_Rbutton = input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT);
|
||||
|
||||
if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT))
|
||||
if (mouse_Lbutton)
|
||||
zapdata[2] |= 0x1;
|
||||
if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT))
|
||||
if (mouse_Rbutton)
|
||||
zapdata[2] |= 0x2;
|
||||
}
|
||||
else if (zappermode == RetroPointer) {
|
||||
@ -2240,7 +2278,7 @@ void get_mouse_input(unsigned port, uint32_t *zapdata)
|
||||
if (input_cb(port, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED))
|
||||
zapdata[2] |= 0x1;
|
||||
}
|
||||
else /* lightgun device */
|
||||
else if (zappermode == RetroCLightgun) /* Crosshair lightgun device */
|
||||
{
|
||||
int offset_x = (adjx ? 0X8FF : 0);
|
||||
int offset_y = (adjy ? 0X999 : 0);
|
||||
@ -2259,8 +2297,8 @@ void get_mouse_input(unsigned port, uint32_t *zapdata)
|
||||
}
|
||||
else
|
||||
{
|
||||
int _x = input_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X);
|
||||
int _y = input_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y);
|
||||
int _x = input_cb( port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X );
|
||||
int _y = input_cb( port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y );
|
||||
|
||||
zapdata[0] = (_x + (0x7FFF + offset_x)) * max_width / ((0x7FFF + offset_x) * 2);
|
||||
zapdata[1] = (_y + (0x7FFF + offset_y)) * max_height / ((0x7FFF + offset_y) * 2);
|
||||
@ -2269,6 +2307,11 @@ void get_mouse_input(unsigned port, uint32_t *zapdata)
|
||||
if ( trigger || offscreen_shot )
|
||||
zapdata[2] |= 0x1;
|
||||
}
|
||||
else /* Sequential targets lightgun device integration */
|
||||
{
|
||||
zapdata[2] = input_cb( port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER );
|
||||
zapdata[3] = input_cb( port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_A );
|
||||
}
|
||||
}
|
||||
|
||||
static void FCEUD_UpdateInput(void)
|
||||
@ -2415,7 +2458,7 @@ static void FCEUD_UpdateInput(void)
|
||||
{
|
||||
case RETRO_DEVICE_ARKANOID:
|
||||
case RETRO_DEVICE_ZAPPER:
|
||||
get_mouse_input(port, nes_input.MouseData[port]);
|
||||
get_mouse_input(port, nes_input.MouseData[port]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -468,12 +468,13 @@ struct retro_core_option_v2_definition option_defs[] = {
|
||||
NULL,
|
||||
"input",
|
||||
{
|
||||
{ "lightgun", "Light gun" },
|
||||
{ "clightgun", "Crosshair light gun" },
|
||||
{ "stlightgun", "Sequential Targets light gun" },
|
||||
{ "touchscreen", "Touchscreen" },
|
||||
{ "mouse", "Mouse" },
|
||||
{ NULL, NULL },
|
||||
},
|
||||
"lightgun",
|
||||
"clightgun",
|
||||
},
|
||||
{
|
||||
"fceumm_show_crosshair",
|
||||
@ -522,6 +523,34 @@ struct retro_core_option_v2_definition option_defs[] = {
|
||||
},
|
||||
"6",
|
||||
},
|
||||
{
|
||||
"fceumm_zapper_trigger",
|
||||
"Invert Zapper Trigger Signal",
|
||||
NULL,
|
||||
"Inverts trigger logic when using a Zapper. Disabling it resembles original hardware behavior.",
|
||||
NULL,
|
||||
"input",
|
||||
{
|
||||
{ "enabled", NULL },
|
||||
{ "disabled", NULL },
|
||||
{ NULL, NULL },
|
||||
},
|
||||
"enabled",
|
||||
},
|
||||
{
|
||||
"fceumm_zapper_sensor",
|
||||
"Invert Zapper Sensor Signal",
|
||||
NULL,
|
||||
"Inverts sensor logic when using a Zapper (Sequential Targets Light gun mode only). Disabling it resembles original NES/FC hardware behavior.",
|
||||
NULL,
|
||||
"input",
|
||||
{
|
||||
{ "enabled", NULL },
|
||||
{ "disabled", NULL },
|
||||
{ NULL, NULL },
|
||||
},
|
||||
"enabled",
|
||||
},
|
||||
{
|
||||
"fceumm_up_down_allowed",
|
||||
"Allow Opposing Directions",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,10 +18,10 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "share.h"
|
||||
#include "share.h"
|
||||
|
||||
#define ROUNDED_TARGET
|
||||
#ifdef ROUNDED_TARGET
|
||||
@ -29,68 +29,79 @@
|
||||
static uint32 targetExpansion[MAX_TOLERANCE+1];
|
||||
#endif
|
||||
static uint32 tolerance;
|
||||
static uint32 ZapperStrobe[2];
|
||||
|
||||
int switchZapper = 0;
|
||||
int zapper_trigger_invert_option = 1;
|
||||
int zapper_sensor_invert_option = 1;
|
||||
|
||||
typedef struct {
|
||||
uint32 mzx, mzy, mzb;
|
||||
uint32 mzx, mzy, mzb, mzs; /* sequential targets lightgun sensor added */
|
||||
int zap_readbit;
|
||||
int bogo;
|
||||
int zappo;
|
||||
|
||||
uint64 zaphit;
|
||||
} ZAPPER;
|
||||
|
||||
static ZAPPER ZD[2];
|
||||
|
||||
static void FP_FASTAPASS(3) ZapperFrapper(int w, uint8 * bg, uint8 * spr, uint32 linets, int final) {
|
||||
int xs, xe;
|
||||
int zx, zy;
|
||||
if (!switchZapper) {
|
||||
int xs, xe;
|
||||
int zx, zy;
|
||||
|
||||
if (!bg) { /* New line, so reset stuff. */
|
||||
ZD[w].zappo = 0;
|
||||
return;
|
||||
}
|
||||
xs = ZD[w].zappo;
|
||||
xe = final;
|
||||
|
||||
zx = ZD[w].mzx;
|
||||
zy = ZD[w].mzy;
|
||||
|
||||
if (xe > 256) xe = 256;
|
||||
|
||||
if (scanline >= (zy - tolerance) && scanline <= (zy + tolerance)) {
|
||||
#ifdef ROUNDED_TARGET
|
||||
int spread;
|
||||
int dy = scanline - zy;
|
||||
if (dy < 0)
|
||||
dy = -dy;
|
||||
spread = targetExpansion[dy];
|
||||
#else
|
||||
int spread = tolerance;
|
||||
#endif
|
||||
while (xs < xe) {
|
||||
uint8 a1, a2;
|
||||
uint32 sum;
|
||||
if (xs <= (zx + spread) && xs >= (zx - spread)) {
|
||||
a1 = bg[xs];
|
||||
if (spr) {
|
||||
a2 = spr[xs];
|
||||
|
||||
if (!(a2 & 0x80))
|
||||
if (!(a2 & 0x40) || (a1 & 64))
|
||||
a1 = a2;
|
||||
}
|
||||
a1 &= 63;
|
||||
|
||||
sum = palo[a1].r + palo[a1].g + palo[a1].b;
|
||||
if (sum >= 100 * 3) {
|
||||
ZD[w].zaphit = ((uint64)linets + (uint64)(xs + 16) * (PAL ? 15 : 16)) / 48 + timestampbase;
|
||||
goto endo;
|
||||
}
|
||||
}
|
||||
xs++;
|
||||
if (!bg) { /* New line, so reset stuff. */
|
||||
ZD[w].zappo = 0;
|
||||
return;
|
||||
}
|
||||
xs = ZD[w].zappo;
|
||||
xe = final;
|
||||
|
||||
zx = ZD[w].mzx;
|
||||
zy = ZD[w].mzy;
|
||||
|
||||
if (xe > 256) xe = 256;
|
||||
|
||||
if (scanline >= (zy - tolerance) && scanline <= (zy + tolerance)) {
|
||||
#ifdef ROUNDED_TARGET
|
||||
int spread;
|
||||
int dy = scanline - zy;
|
||||
if (dy < 0)
|
||||
dy = -dy;
|
||||
spread = targetExpansion[dy];
|
||||
#else
|
||||
int spread = tolerance;
|
||||
#endif
|
||||
while (xs < xe) {
|
||||
uint8 a1, a2;
|
||||
uint32 sum;
|
||||
if (xs <= (zx + spread) && xs >= (zx - spread)) {
|
||||
a1 = bg[xs];
|
||||
if (spr) {
|
||||
a2 = spr[xs];
|
||||
|
||||
if (!(a2 & 0x80))
|
||||
if (!(a2 & 0x40) || (a1 & 64))
|
||||
a1 = a2;
|
||||
}
|
||||
a1 &= 63;
|
||||
|
||||
sum = palo[a1].r + palo[a1].g + palo[a1].b;
|
||||
if (sum >= 100 * 3) {
|
||||
ZD[w].zaphit = ((uint64)linets + (uint64)(xs + 16) * (PAL ? 15 : 16)) / 48 + timestampbase;
|
||||
goto endo;
|
||||
}
|
||||
}
|
||||
xs++;
|
||||
}
|
||||
}
|
||||
endo:
|
||||
ZD[w].zappo = final;
|
||||
}
|
||||
else {
|
||||
ZD[w].zappo = 0;
|
||||
}
|
||||
endo:
|
||||
ZD[w].zappo = final;
|
||||
}
|
||||
|
||||
static INLINE int CheckColor(int w) {
|
||||
@ -109,12 +120,18 @@ static uint8 FP_FASTAPASS(1) ReadZapperVS(int w) {
|
||||
|
||||
if (ZD[w].zap_readbit == 7) {
|
||||
if (ZD[w].bogo)
|
||||
ret |= 0x1;
|
||||
ret |= 0x1;
|
||||
}
|
||||
|
||||
if (ZD[w].zap_readbit == 6) {
|
||||
if (!CheckColor(w))
|
||||
if (!switchZapper) {
|
||||
if (!CheckColor(w))
|
||||
ret |= 0x1;
|
||||
}
|
||||
else if (!ZD[w].mzs)
|
||||
ret |= 0x1;
|
||||
}
|
||||
|
||||
#ifdef FCEUDEF_DEBUGGER
|
||||
if (!fceuindbg)
|
||||
#endif
|
||||
@ -128,15 +145,22 @@ static void FP_FASTAPASS(1) StrobeZapperVS(int w) {
|
||||
|
||||
static uint8 FP_FASTAPASS(1) ReadZapper(int w) {
|
||||
uint8 ret = 0;
|
||||
if (ZD[w].bogo)
|
||||
|
||||
if (ZD[w].bogo)
|
||||
ret |= 0x10;
|
||||
if (CheckColor(w))
|
||||
ret |= 0x8;
|
||||
|
||||
if (!switchZapper) {
|
||||
if (CheckColor(w))
|
||||
ret |= 0x8;
|
||||
}
|
||||
else if (ZD[w].mzs)
|
||||
ret |= 0x8;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void FASTAPASS(3) DrawZapper(int w, uint8 * buf, int arg) {
|
||||
if (arg)
|
||||
if (arg && !switchZapper)
|
||||
FCEU_DrawGunSight(buf, ZD[w].mzx, ZD[w].mzy);
|
||||
}
|
||||
|
||||
@ -150,7 +174,16 @@ static void FP_FASTAPASS(3) UpdateZapper(int w, void *data, int arg) {
|
||||
|
||||
ZD[w].mzx = ptr[0];
|
||||
ZD[w].mzy = ptr[1];
|
||||
ZD[w].mzb = ptr[2];
|
||||
|
||||
if (zapper_trigger_invert_option)
|
||||
ZD[w].mzb = ptr[2];
|
||||
else
|
||||
ZD[w].mzb = !ptr[2];
|
||||
|
||||
if (zapper_sensor_invert_option)
|
||||
ZD[w].mzs = !ptr[3];
|
||||
else
|
||||
ZD[w].mzs = ptr[3];
|
||||
}
|
||||
|
||||
static INPUTC ZAPC = { ReadZapper, 0, 0, UpdateZapper, ZapperFrapper, DrawZapper };
|
||||
|
Loading…
Reference in New Issue
Block a user