bus/nes_ctrl: Added NES support for Virtual Boy controllers. (#9124)

- Generalized the read/write pattern for joypads a bit more and placed it in the base NES joypad class.
- Using that, added Virtual Boy controller and simplified Pachinko controller some more.

New working software list additions (nes.xml)
-----------------------------------
Candelabra - Estoscerro [SlyDogStudios]
This commit is contained in:
0kmg 2022-02-07 15:12:42 -09:00 committed by GitHub
parent 9da06744f1
commit e450cc7953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 41 deletions

View File

@ -79368,6 +79368,22 @@ be better to redump them properly. -->
</part>
</software>
<software name="candesto" supported="partial"> <!-- Restore/Options not yet supported -->
<description>Candelabra - Estoscerro</description>
<year>2020</year> <!-- cartridge release year -->
<publisher>&lt;homebrew&gt;</publisher>
<part name="cart" interface="nes_cart">
<feature name="slot" value="unrom512" />
<feature name="mirroring" value="vertical" />
<dataarea name="prg" size="524288">
<rom name="candelabra - estoscerro.prg" size="524288" crc="acc3e3df" sha1="6b929e2aaaf31b6bcddf530f608612aa5826632f" status="baddump" /> <!-- this is from the .nes file distributed by the author, Sly Dog Studios -->
</dataarea>
<!-- 8k VRAM on cartridge? -->
<dataarea name="vram" size="8192">
</dataarea>
</part>
</software>
<!-- Author self-published through mail order, carts made by RetroZone -->
<software name="et">
<description>E.T.</description>

View File

@ -185,6 +185,7 @@ void nes_control_port1_devices(device_slot_interface &device)
device.option_add("4score_p1p3", NES_4SCORE_P1P3);
device.option_add("miracle_piano", NES_MIRACLE);
device.option_add("snes_adapter", NES_SNESADAPTER);
device.option_add("vboy", NES_VBOYCTRL);
}
void nes_control_port2_devices(device_slot_interface &device)
@ -195,6 +196,7 @@ void nes_control_port2_devices(device_slot_interface &device)
device.option_add("powerpad", NES_POWERPAD);
device.option_add("4score_p2p4", NES_4SCORE_P2P4);
device.option_add("snes_adapter", NES_SNESADAPTER);
device.option_add("vboy", NES_VBOYCTRL);
}
void fc_control_port1_devices(device_slot_interface &device)

View File

@ -48,6 +48,7 @@ DEFINE_DEVICE_TYPE(NES_FCPAD_P2, nes_fcpad2_device, "nes_fcpad2", "Ninten
DEFINE_DEVICE_TYPE(NES_CCPAD_LEFT, nes_ccpadl_device, "nes_ccpadl", "FC Crazy Climber Left Pad")
DEFINE_DEVICE_TYPE(NES_CCPAD_RIGHT, nes_ccpadr_device, "nes_ccpadr", "FC Crazy Climber Right Pad")
DEFINE_DEVICE_TYPE(NES_ARCSTICK, nes_arcstick_device, "nes_arcstick", "Nintendo Family Computer Arcade Stick")
DEFINE_DEVICE_TYPE(NES_VBOYCTRL, nes_vboyctrl_device, "nes_vboyctrl", "Nintendo Virtual Boy Controller")
INPUT_PORTS_START( nes_joypad )
PORT_START("JOYPAD")
@ -121,6 +122,26 @@ static INPUT_PORTS_START( nes_arcstick )
PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_CONDITION("CONFIG", 0x01, EQUALS, 0x00)
INPUT_PORTS_END
static INPUT_PORTS_START( nes_vboyctrl )
PORT_START("JOYPAD")
PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_DOWN ) PORT_8WAY
PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_LEFT ) PORT_8WAY
PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_SELECT )
PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_START )
PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_UP ) PORT_8WAY
PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_DOWN ) PORT_8WAY
PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_LEFT ) PORT_8WAY
PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_JOYSTICKLEFT_RIGHT ) PORT_8WAY
PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_RIGHT ) PORT_8WAY
PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_JOYSTICKRIGHT_UP ) PORT_8WAY
PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("%p L") // Left button on back
PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("%p R") // Right button on back
PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("%p B")
PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("%p A")
PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNUSED ) // Always 1
PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_UNUSED ) // Battery low
INPUT_PORTS_END
//-------------------------------------------------
// input_ports - device-specific input ports
//-------------------------------------------------
@ -150,6 +171,11 @@ ioport_constructor nes_arcstick_device::device_input_ports() const
return INPUT_PORTS_NAME( nes_arcstick );
}
ioport_constructor nes_vboyctrl_device::device_input_ports() const
{
return INPUT_PORTS_NAME( nes_vboyctrl );
}
static void arcstick_daisy(device_slot_interface &device)
{
device.option_add("arcstick", NES_ARCSTICK);
@ -177,11 +203,12 @@ void nes_arcstick_device::device_add_mconfig(machine_config &config)
// nes_joypad_device - constructor
//-------------------------------------------------
nes_joypad_device::nes_joypad_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
nes_joypad_device::nes_joypad_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, u32 latch_fill)
: device_t(mconfig, type, tag, owner, clock)
, device_nes_control_port_interface(mconfig, *this)
, m_joypad(*this, "JOYPAD")
, m_latch(0)
, m_latch_fill(latch_fill)
{
}
@ -190,8 +217,8 @@ nes_joypad_device::nes_joypad_device(const machine_config &mconfig, const char *
{
}
nes_fcpadexp_device::nes_fcpadexp_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
: nes_joypad_device(mconfig, type, tag, owner, clock)
nes_fcpadexp_device::nes_fcpadexp_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, u32 latch_fill)
: nes_joypad_device(mconfig, type, tag, owner, clock, latch_fill)
{
}
@ -223,6 +250,11 @@ nes_arcstick_device::nes_arcstick_device(const machine_config &mconfig, const ch
{
}
nes_vboyctrl_device::nes_vboyctrl_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
: nes_joypad_device(mconfig, NES_VBOYCTRL, tag, owner, clock, 0x8000)
{
}
//-------------------------------------------------
// device_start
@ -242,10 +274,11 @@ void nes_joypad_device::device_start()
u8 nes_joypad_device::read_bit0()
{
if (m_strobe)
m_latch = m_joypad->read();
set_latch();
u8 ret = m_latch & 1;
m_latch = (m_latch >> 1) | 0x80; // fill shift reg with 1s, since excess reads on official pads return 1
m_latch >>= 1;
m_latch |= m_latch_fill;
return ret;
}
@ -285,7 +318,7 @@ u8 nes_arcstick_device::read_exp(offs_t offset)
void nes_joypad_device::write(u8 data)
{
if (write_strobe(data))
m_latch = m_joypad->read();
set_latch();
}
void nes_arcstick_device::write(u8 data)

View File

@ -31,16 +31,18 @@ public:
virtual ioport_constructor device_input_ports() const override;
protected:
nes_joypad_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);
nes_joypad_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, u32 latch_fill = 0x80);
// device-level overrides
virtual void device_start() override;
virtual u8 read_bit0() override;
virtual void write(u8 data) override;
virtual void set_latch() { m_latch = m_joypad->read(); }
required_ioport m_joypad;
u32 m_latch; // wider than standard joypad's 8-bit latch to accomodate subclass devices
u32 m_latch_fill; // the new MSB as a joypad's shift register shifts
};
@ -53,7 +55,7 @@ public:
nes_fcpadexp_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
protected:
nes_fcpadexp_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);
nes_fcpadexp_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, u32 latch_fill = 0x80);
virtual u8 read_bit0() override { return 0; }
virtual u8 read_exp(offs_t offset) override;
@ -122,6 +124,19 @@ protected:
};
// ======================> nes_vboyctrl_device
class nes_vboyctrl_device : public nes_joypad_device
{
public:
// construction/destruction
nes_vboyctrl_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
protected:
virtual ioport_constructor device_input_ports() const override;
};
// device type definition
DECLARE_DEVICE_TYPE(NES_JOYPAD, nes_joypad_device)
DECLARE_DEVICE_TYPE(NES_FCPAD_EXP, nes_fcpadexp_device)
@ -129,5 +144,6 @@ DECLARE_DEVICE_TYPE(NES_FCPAD_P2, nes_fcpad2_device)
DECLARE_DEVICE_TYPE(NES_CCPAD_LEFT, nes_ccpadl_device)
DECLARE_DEVICE_TYPE(NES_CCPAD_RIGHT, nes_ccpadr_device)
DECLARE_DEVICE_TYPE(NES_ARCSTICK, nes_arcstick_device)
DECLARE_DEVICE_TYPE(NES_VBOYCTRL, nes_vboyctrl_device)
#endif // MAME_BUS_NES_CTRL_JOYPAD_H

View File

@ -41,40 +41,12 @@ ioport_constructor nes_pachinko_device::device_input_ports() const
//-------------------------------------------------
nes_pachinko_device::nes_pachinko_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
: nes_fcpadexp_device(mconfig, NES_PACHINKO, tag, owner, clock)
: nes_fcpadexp_device(mconfig, NES_PACHINKO, tag, owner, clock, 0)
, m_trigger(*this, "TRIGGER")
{
}
//-------------------------------------------------
// read
//-------------------------------------------------
u8 nes_pachinko_device::read_exp(offs_t offset)
{
u8 ret = 0;
// this controller behaves like a standard P3 joypad, with longer stream of inputs
if (offset == 0) //$4016
{
if (m_strobe)
set_latch();
ret = (m_latch & 1) << 1;
m_latch >>= 1;
}
return ret;
}
//-------------------------------------------------
// write
//-------------------------------------------------
void nes_pachinko_device::write(u8 data)
{
if (write_strobe(data))
set_latch();
}
void nes_pachinko_device::set_latch()
{
m_latch = m_joypad->read();

View File

@ -29,12 +29,9 @@ public:
virtual ioport_constructor device_input_ports() const override;
protected:
virtual u8 read_exp(offs_t offset) override;
virtual void write(u8 data) override;
virtual void set_latch() override;
private:
void set_latch();
required_ioport m_trigger;
};