Add sequential targets light gun support
Support for Sequential targets Light Guns has been added. "Gun Aux A" serves as light sensor logic input.
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user