From 9dbf099b651c8c48140db01059614e23d5bbdcb9 Mon Sep 17 00:00:00 2001 From: hap Date: Thu, 16 Feb 2023 21:54:04 +0100 Subject: nes zapper: improve trigger, put bandai lightgun in its own file --- scripts/src/bus.lua | 2 + src/devices/bus/nes_ctrl/bandaihs.cpp | 132 ++++++++++++++++++++++++++++++++++ src/devices/bus/nes_ctrl/bandaihs.h | 53 ++++++++++++++ src/devices/bus/nes_ctrl/ctrl.cpp | 2 + src/devices/bus/nes_ctrl/rob.cpp | 25 ++++--- src/devices/bus/nes_ctrl/zapper.cpp | 101 +++++--------------------- src/devices/bus/nes_ctrl/zapper.h | 31 +------- 7 files changed, 223 insertions(+), 123 deletions(-) create mode 100644 src/devices/bus/nes_ctrl/bandaihs.cpp create mode 100644 src/devices/bus/nes_ctrl/bandaihs.h diff --git a/scripts/src/bus.lua b/scripts/src/bus.lua index 577e20237ba..4252146dc10 100644 --- a/scripts/src/bus.lua +++ b/scripts/src/bus.lua @@ -3188,6 +3188,8 @@ if (BUSES["NES_CTRL"]~=null) then MAME_DIR .. "src/devices/bus/nes_ctrl/4score.h", MAME_DIR .. "src/devices/bus/nes_ctrl/arkpaddle.cpp", MAME_DIR .. "src/devices/bus/nes_ctrl/arkpaddle.h", + MAME_DIR .. "src/devices/bus/nes_ctrl/bandaihs.cpp", + MAME_DIR .. "src/devices/bus/nes_ctrl/bandaihs.h", MAME_DIR .. "src/devices/bus/nes_ctrl/bcbattle.cpp", MAME_DIR .. "src/devices/bus/nes_ctrl/bcbattle.h", MAME_DIR .. "src/devices/bus/nes_ctrl/dorepiano.cpp", diff --git a/src/devices/bus/nes_ctrl/bandaihs.cpp b/src/devices/bus/nes_ctrl/bandaihs.cpp new file mode 100644 index 00000000000..e77cf7002ab --- /dev/null +++ b/src/devices/bus/nes_ctrl/bandaihs.cpp @@ -0,0 +1,132 @@ +// license:BSD-3-Clause +// copyright-holders:Fabio Priuli +/********************************************************************** + + Nintendo Family Computer Bandai Hyper Shot Lightgun + +**********************************************************************/ + +#include "emu.h" +#include "bandaihs.h" + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +DEFINE_DEVICE_TYPE(NES_BANDAIHS, nes_bandaihs_device, "nes_bandaihs", "Bandai Hyper Shot Lightgun") + + +//------------------------------------------------- +// input_ports - device-specific input ports +//------------------------------------------------- + +static INPUT_PORTS_START( nes_bandaihs ) + PORT_START("JOYPAD") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) // has complete joypad inputs except button A + PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("%p B") + PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) + PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) + PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY + PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY + PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY + PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY + + 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( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Lightgun Trigger") +INPUT_PORTS_END + +ioport_constructor nes_bandaihs_device::device_input_ports() const +{ + return INPUT_PORTS_NAME( nes_bandaihs ); +} + + +//------------------------------------------------- +// device_add_mconfig - add device configuration +//------------------------------------------------- + +void nes_bandaihs_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 +//************************************************************************** + +//------------------------------------------------- +// constructor +//------------------------------------------------- + +nes_bandaihs_device::nes_bandaihs_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) + : device_t(mconfig, NES_BANDAIHS, tag, owner, clock) + , device_nes_control_port_interface(mconfig, *this) + , m_sensor(*this, "sensor") + , m_lightx(*this, "GUN_X") + , m_lighty(*this, "GUN_Y") + , m_trigger(*this, "GUN_T") + , m_joypad(*this, "JOYPAD") + , m_latch(0) +{ +} + + +//------------------------------------------------- +// device_start +//------------------------------------------------- + +void nes_bandaihs_device::device_start() +{ + save_item(NAME(m_latch)); + save_item(NAME(m_strobe)); +} + + +//------------------------------------------------- +// read +//------------------------------------------------- + +u8 nes_bandaihs_device::read_exp(offs_t offset) +{ + u8 ret = 0; + + if (offset == 0) // $4016 + { + if (m_strobe) + m_latch = m_joypad->read(); + ret = (m_latch & 1) << 1; + m_latch = (m_latch >> 1) | 0x80; + } + else // $4017 + { + ret = m_trigger->read(); + if (!m_sensor->detect_light(m_lightx->read(), m_lighty->read())) + ret |= 0x08; + } + + return ret; +} + + +//------------------------------------------------- +// write +//------------------------------------------------- + +// In addition to bit 0 used here the real Bandai Hyper Shot also responds to +// bits 1 and 2, neither emulated here. Bit 1 turns on and off a motor, which +// causes the machine gun to shake as if to simulate recoil. Bit 2 turns on and +// off an internal speaker in the gun. Videos demostrate that the speaker plays +// the same audio as the Famicom itself. The analog audio signal of the FC is +// carried on expansion port pin 2, so there's likely nothing more going on. +void nes_bandaihs_device::write(u8 data) +{ + if (write_strobe(data)) + m_latch = m_joypad->read(); +} diff --git a/src/devices/bus/nes_ctrl/bandaihs.h b/src/devices/bus/nes_ctrl/bandaihs.h new file mode 100644 index 00000000000..3ab57b5a053 --- /dev/null +++ b/src/devices/bus/nes_ctrl/bandaihs.h @@ -0,0 +1,53 @@ +// license:BSD-3-Clause +// copyright-holders:Fabio Priuli +/********************************************************************** + + Nintendo Family Computer Bandai Hyper Shot Lightgun + +**********************************************************************/ + +#ifndef MAME_BUS_NES_CTRL_BANDAIHS +#define MAME_BUS_NES_CTRL_BANDAIHS + +#pragma once + +#include "ctrl.h" +#include "zapper_sensor.h" + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> nes_bandaihs_device + +class nes_bandaihs_device : public device_t, + public device_nes_control_port_interface +{ +public: + // construction/destruction + nes_bandaihs_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); + + virtual u8 read_exp(offs_t offset) override; + virtual void write(u8 data) override; + +protected: + // device-level overrides + virtual void device_start() override; + virtual void device_add_mconfig(machine_config &config) override; + virtual ioport_constructor device_input_ports() const override; + +private: + required_device m_sensor; + required_ioport m_lightx; + required_ioport m_lighty; + required_ioport m_trigger; + required_ioport m_joypad; + u8 m_latch; +}; + + +// device type definition +DECLARE_DEVICE_TYPE(NES_BANDAIHS, nes_bandaihs_device) + +#endif // MAME_BUS_NES_CTRL_BANDAIHS diff --git a/src/devices/bus/nes_ctrl/ctrl.cpp b/src/devices/bus/nes_ctrl/ctrl.cpp index aaeec552b4e..4f508cac556 100644 --- a/src/devices/bus/nes_ctrl/ctrl.cpp +++ b/src/devices/bus/nes_ctrl/ctrl.cpp @@ -42,9 +42,11 @@ #include "emu.h" #include "ctrl.h" + // slot devices #include "4score.h" #include "arkpaddle.h" +#include "bandaihs.h" #include "bcbattle.h" #include "dorepiano.h" #include "fckeybrd.h" diff --git a/src/devices/bus/nes_ctrl/rob.cpp b/src/devices/bus/nes_ctrl/rob.cpp index 24747e6a088..5e101d55042 100644 --- a/src/devices/bus/nes_ctrl/rob.cpp +++ b/src/devices/bus/nes_ctrl/rob.cpp @@ -2,14 +2,14 @@ // copyright-holders:hap /********************************************************************** - Nintendo HVC-012 Family Computer Robot / Nintendo NES-012 R.O.B. +Nintendo HVC-012 Family Computer Robot / Nintendo NES-012 R.O.B. - TODO: - - does nes_rob have motor sensors? (eg. limit switches, or optical - sensor to determine position) - - can't really play anything with nes_rob, because of interaction - with physical objects (gyromite especially, since it has a gadget - to make the robot press joypad buttons) +TODO: +- does nes_rob have motor sensors? (eg. limit switches, or optical + sensor to determine position) +- can't really play anything with nes_rob, because of interaction + with physical objects (gyromite especially, since it has a gadget + to make the robot press joypad buttons) **********************************************************************/ @@ -25,6 +25,10 @@ DEFINE_DEVICE_TYPE(NES_ROB, nes_rob_device, "nes_rob", "Nintendo R.O.B. / Family Computer Robot") +//------------------------------------------------- +// input_ports - device-specific input ports +//------------------------------------------------- + static INPUT_PORTS_START( nes_rob ) PORT_START("EYE_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) @@ -32,11 +36,6 @@ static INPUT_PORTS_START( nes_rob ) 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) INPUT_PORTS_END - -//------------------------------------------------- -// input_ports - device-specific input ports -//------------------------------------------------- - ioport_constructor nes_rob_device::device_input_ports() const { return INPUT_PORTS_NAME( nes_rob ); @@ -83,7 +82,7 @@ void nes_rob_device::device_start() u8 nes_rob_device::input_r() { // R00: lightsensor - return !m_sensor->detect_light(m_eye_x->read(), m_eye_y->read()); + return m_sensor->detect_light(m_eye_x->read(), m_eye_y->read()) ? 0 : 1; } void nes_rob_device::output_w(offs_t offset, u8 data) diff --git a/src/devices/bus/nes_ctrl/zapper.cpp b/src/devices/bus/nes_ctrl/zapper.cpp index 5d55b1f2d3f..8562db41bec 100644 --- a/src/devices/bus/nes_ctrl/zapper.cpp +++ b/src/devices/bus/nes_ctrl/zapper.cpp @@ -3,7 +3,6 @@ /********************************************************************** Nintendo Family Computer & Entertainment System Zapper Lightgun - Nintendo Family Computer Bandai Hyper Shot Lightgun **********************************************************************/ @@ -15,48 +14,34 @@ //************************************************************************** DEFINE_DEVICE_TYPE(NES_ZAPPER, nes_zapper_device, "nes_zapper", "Nintendo Zapper Lightgun") -DEFINE_DEVICE_TYPE(NES_BANDAIHS, nes_bandaihs_device, "nes_bandaihs", "Bandai Hyper Shot Lightgun") +//------------------------------------------------- +// input_ports - device-specific input ports +//------------------------------------------------- + static INPUT_PORTS_START( nes_zapper ) - PORT_START("ZAPPER_X") + 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("ZAPPER_Y") + 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("ZAPPER_T") - PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Lightgun Trigger") + PORT_START("GUN_T") + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Lightgun Trigger") PORT_CHANGED_MEMBER(DEVICE_SELF, nes_zapper_device, trigger, 0) INPUT_PORTS_END - -static INPUT_PORTS_START( nes_bandaihs ) - PORT_INCLUDE( nes_zapper ) - - PORT_START("JOYPAD") - PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) // has complete joypad inputs except button A - PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("%p B") - PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SELECT ) - PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START ) - PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_8WAY - PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_8WAY - PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_8WAY - PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_8WAY -INPUT_PORTS_END - - -//------------------------------------------------- -// input_ports - device-specific input ports -//------------------------------------------------- - ioport_constructor nes_zapper_device::device_input_ports() const { return INPUT_PORTS_NAME( nes_zapper ); } -ioport_constructor nes_bandaihs_device::device_input_ports() const +INPUT_CHANGED_MEMBER(nes_zapper_device::trigger) { - return INPUT_PORTS_NAME( nes_bandaihs ); + // a trigger pull is active for around 3-4 frames + if (newval) + m_trigger->adjust(attotime::from_msec(50)); } + //------------------------------------------------- // device_add_mconfig - add device configuration //------------------------------------------------- @@ -77,25 +62,12 @@ void nes_zapper_device::device_add_mconfig(machine_config &config) // constructor //------------------------------------------------- -nes_zapper_device::nes_zapper_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) - : device_t(mconfig, type, tag, owner, clock) +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, "ZAPPER_X") - , m_lighty(*this, "ZAPPER_Y") - , m_trigger(*this, "ZAPPER_T") -{ -} - -nes_zapper_device::nes_zapper_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : nes_zapper_device(mconfig, NES_ZAPPER, tag, owner, clock) -{ -} - -nes_bandaihs_device::nes_bandaihs_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : nes_zapper_device(mconfig, NES_BANDAIHS, tag, owner, clock) - , m_joypad(*this, "JOYPAD") - , m_latch(0) + , m_lightx(*this, "GUN_X") + , m_lighty(*this, "GUN_Y") { } @@ -106,13 +78,7 @@ nes_bandaihs_device::nes_bandaihs_device(const machine_config &mconfig, const ch void nes_zapper_device::device_start() { -} - -void nes_bandaihs_device::device_start() -{ - nes_zapper_device::device_start(); - save_item(NAME(m_latch)); - save_item(NAME(m_strobe)); + m_trigger = timer_alloc(timer_expired_delegate()); } @@ -122,7 +88,7 @@ void nes_bandaihs_device::device_start() u8 nes_zapper_device::read_bit34() { - u8 ret = m_trigger->read(); + u8 ret = m_trigger->enabled() ? 0x10 : 0; if (!m_sensor->detect_light(m_lightx->read(), m_lighty->read())) ret |= 0x08; @@ -137,32 +103,3 @@ u8 nes_zapper_device::read_exp(offs_t offset) ret = nes_zapper_device::read_bit34(); return ret; } - -u8 nes_bandaihs_device::read_exp(offs_t offset) -{ - u8 ret = 0; - - if (offset == 0) // $4016 - { - if (m_strobe) - m_latch = m_joypad->read(); - ret = (m_latch & 1) << 1; - m_latch = (m_latch >> 1) | 0x80; - } - else // $4017 - ret = nes_zapper_device::read_exp(offset); - - return ret; -} - -// In addition to bit 0 used here the real Bandai Hyper Shot also responds to -// bits 1 and 2, neither emulated here. Bit 1 turns on and off a motor, which -// causes the machine gun to shake as if to simulate recoil. Bit 2 turns on and -// off an internal speaker in the gun. Videos demostrate that the speaker plays -// the same audio as the Famicom itself. The analog audio signal of the FC is -// carried on expansion port pin 2, so there's likely nothing more going on. -void nes_bandaihs_device::write(u8 data) -{ - if (write_strobe(data)) - m_latch = m_joypad->read(); -} diff --git a/src/devices/bus/nes_ctrl/zapper.h b/src/devices/bus/nes_ctrl/zapper.h index d3ca9a298bf..232a38cce5b 100644 --- a/src/devices/bus/nes_ctrl/zapper.h +++ b/src/devices/bus/nes_ctrl/zapper.h @@ -3,7 +3,6 @@ /********************************************************************** Nintendo Family Computer & Entertainment System Zapper Lightgun - Nintendo Family Computer Bandai Hyper Shot Lightgun **********************************************************************/ @@ -32,10 +31,9 @@ public: virtual u8 read_bit34() override; virtual u8 read_exp(offs_t offset) override; -protected: - // construction/destruction - nes_zapper_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); + DECLARE_INPUT_CHANGED_MEMBER(trigger); +protected: // device-level overrides virtual void device_start() override; virtual void device_add_mconfig(machine_config &config) override; @@ -45,34 +43,11 @@ private: required_device m_sensor; required_ioport m_lightx; required_ioport m_lighty; - required_ioport m_trigger; -}; - - -// ======================> nes_bandaihs_device - -class nes_bandaihs_device : public nes_zapper_device -{ -public: - // construction/destruction - nes_bandaihs_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); - - virtual u8 read_exp(offs_t offset) override; - virtual void write(u8 data) override; - -protected: - // device-level overrides - virtual void device_start() override; - virtual ioport_constructor device_input_ports() const override; - -private: - required_ioport m_joypad; - u8 m_latch; + emu_timer *m_trigger; }; // device type definition DECLARE_DEVICE_TYPE(NES_ZAPPER, nes_zapper_device) -DECLARE_DEVICE_TYPE(NES_BANDAIHS, nes_bandaihs_device) #endif // MAME_BUS_NES_CTRL_ZAPPER -- cgit v1.2.3