diff options
Diffstat (limited to 'src/devices/bus/nes_ctrl/zapper.cpp')
-rw-r--r-- | src/devices/bus/nes_ctrl/zapper.cpp | 95 |
1 files changed, 42 insertions, 53 deletions
diff --git a/src/devices/bus/nes_ctrl/zapper.cpp b/src/devices/bus/nes_ctrl/zapper.cpp index da3df413a40..4a2b42d136a 100644 --- a/src/devices/bus/nes_ctrl/zapper.cpp +++ b/src/devices/bus/nes_ctrl/zapper.cpp @@ -7,7 +7,6 @@ **********************************************************************/ #include "emu.h" -#include "screen.h" #include "zapper.h" //************************************************************************** @@ -17,60 +16,69 @@ DEFINE_DEVICE_TYPE(NES_ZAPPER, nes_zapper_device, "nes_zapper", "Nintendo Zapper Lightgun") -static INPUT_PORTS_START( nes_zapper ) - PORT_START("ZAPPER_X") - PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(70) PORT_KEYDELTA(30) PORT_MINMAX(0,255) - PORT_START("ZAPPER_Y") - PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(30) PORT_MINMAX(0,255) - PORT_START("ZAPPER_T") - PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Lightgun Trigger") -INPUT_PORTS_END - - //------------------------------------------------- // input_ports - device-specific input ports //------------------------------------------------- +static INPUT_PORTS_START( nes_zapper ) + PORT_START("GUN_X") + PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(70) PORT_KEYDELTA(30) PORT_MINMAX(0, 255) + PORT_START("GUN_Y") + PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(30) PORT_MINMAX(0, 239) + PORT_START("GUN_T") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Lightgun Trigger") PORT_CHANGED_MEMBER(DEVICE_SELF, FUNC(nes_zapper_device::trigger), 0) +INPUT_PORTS_END + ioport_constructor nes_zapper_device::device_input_ports() const { return INPUT_PORTS_NAME( nes_zapper ); } +INPUT_CHANGED_MEMBER(nes_zapper_device::trigger) +{ + // a trigger pull is active for around 3-4 frames + if (newval) + m_trigger->adjust(attotime::from_msec(50)); +} -//************************************************************************** -// LIVE DEVICE -//************************************************************************** - //------------------------------------------------- -// nes_zapper_device - constructor +// device_add_mconfig - add device configuration //------------------------------------------------- -nes_zapper_device::nes_zapper_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : - device_t(mconfig, NES_ZAPPER, tag, owner, clock), - device_nes_control_port_interface(mconfig, *this), - m_lightx(*this, "ZAPPER_X"), - m_lighty(*this, "ZAPPER_Y"), - m_trigger(*this, "ZAPPER_T") +void nes_zapper_device::device_add_mconfig(machine_config &config) { + NES_ZAPPER_SENSOR(config, m_sensor, 0); + if (m_port != nullptr) + m_sensor->set_screen_tag(m_port->m_screen); } +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + //------------------------------------------------- -// device_start +// constructor //------------------------------------------------- -void nes_zapper_device::device_start() +nes_zapper_device::nes_zapper_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) + : device_t(mconfig, NES_ZAPPER, tag, owner, clock) + , device_nes_control_port_interface(mconfig, *this) + , m_sensor(*this, "sensor") + , m_lightx(*this, "GUN_X") + , m_lighty(*this, "GUN_Y") { } //------------------------------------------------- -// device_reset +// device_start //------------------------------------------------- -void nes_zapper_device::device_reset() +void nes_zapper_device::device_start() { + m_trigger = timer_alloc(timer_expired_delegate()); } @@ -78,39 +86,20 @@ void nes_zapper_device::device_reset() // read //------------------------------------------------- -uint8_t nes_zapper_device::read_bit34() +u8 nes_zapper_device::read_bit34() { - uint8_t ret = m_trigger->read(); - int x = m_lightx->read(); - int y = m_lighty->read(); - - // update the screen if necessary - if (!m_port->m_screen->vblank()) - { - int vpos = m_port->m_screen->vpos(); - int hpos = m_port->m_screen->hpos(); - - if (vpos > y || (vpos == y && hpos >= x)) - m_port->m_screen->update_now(); - } - - // get the pixel at the gun position - rgb_t pix = m_port->m_screen->pixel(x, y); - - // check if the cursor is over a bright pixel - // FIXME: still a gross hack - if (pix.r() == 0xff && pix.b() == 0xff && pix.g() > 0x90) - ret &= ~0x08; // sprite hit - else - ret |= 0x08; // no sprite hit + u8 ret = m_trigger->enabled() ? 0x10 : 0; + + if (!m_sensor->detect_light(m_lightx->read(), m_lighty->read())) + ret |= 0x08; return ret; } -uint8_t nes_zapper_device::read_exp(offs_t offset) +u8 nes_zapper_device::read_exp(offs_t offset) { - uint8_t ret = 0; + u8 ret = 0; if (offset == 1) // $4017 - ret |= nes_zapper_device::read_bit34(); + ret = nes_zapper_device::read_bit34(); return ret; } |