From df3877c47b03f205990590c5f2cdf34e42d2ab16 Mon Sep 17 00:00:00 2001 From: wilbertpol Date: Tue, 9 May 2023 04:48:44 +0100 Subject: bus/msx/ctrl: Added Arkanoid Vaus controller. (#11201) --- scripts/src/bus.lua | 2 + src/devices/bus/msx/ctrl/ctrl.cpp | 2 + src/devices/bus/msx/ctrl/vaus.cpp | 115 ++++++++++++++++++++++++++++++++++++++ src/devices/bus/msx/ctrl/vaus.h | 19 +++++++ 4 files changed, 138 insertions(+) create mode 100644 src/devices/bus/msx/ctrl/vaus.cpp create mode 100644 src/devices/bus/msx/ctrl/vaus.h diff --git a/scripts/src/bus.lua b/scripts/src/bus.lua index cd316c3a193..4f254b218ee 100644 --- a/scripts/src/bus.lua +++ b/scripts/src/bus.lua @@ -1842,6 +1842,8 @@ if (BUSES["MSX_CTRL"]~=null) then MAME_DIR .. "src/devices/bus/msx/ctrl/towns6b.h", MAME_DIR .. "src/devices/bus/msx/ctrl/townspad.cpp", MAME_DIR .. "src/devices/bus/msx/ctrl/townspad.h", + MAME_DIR .. "src/devices/bus/msx/ctrl/vaus.cpp", + MAME_DIR .. "src/devices/bus/msx/ctrl/vaus.h", MAME_DIR .. "src/devices/bus/msx/ctrl/xe1ap.cpp", MAME_DIR .. "src/devices/bus/msx/ctrl/xe1ap.h", } diff --git a/src/devices/bus/msx/ctrl/ctrl.cpp b/src/devices/bus/msx/ctrl/ctrl.cpp index 68139c0f625..efa8716edc1 100644 --- a/src/devices/bus/msx/ctrl/ctrl.cpp +++ b/src/devices/bus/msx/ctrl/ctrl.cpp @@ -16,6 +16,7 @@ #include "sgadapt.h" #include "towns6b.h" #include "townspad.h" +#include "vaus.h" #include "xe1ap.h" @@ -53,5 +54,6 @@ void msx_general_purpose_port_devices(device_slot_interface &device) device.option_add("sega", MSX_SEGACTRL); device.option_add("towns6b", MSX_TOWNS6B); device.option_add("townspad", MSX_TOWNSPAD); + device.option_add("vaus", MSX_VAUS); device.option_add("xe1ap", MSX_XE1AP); } diff --git a/src/devices/bus/msx/ctrl/vaus.cpp b/src/devices/bus/msx/ctrl/vaus.cpp new file mode 100644 index 00000000000..4ae62b8f89b --- /dev/null +++ b/src/devices/bus/msx/ctrl/vaus.cpp @@ -0,0 +1,115 @@ +// license:BSD-3-Clause +// copyright-holders:Wilbert Pol +/********************************************************************** + + MSX Arkanoid Vaus controller emulation + +**********************************************************************/ + +#include "emu.h" +#include "vaus.h" + + +namespace { + +INPUT_PORTS_START(msx_vaus) + PORT_START("BUTTON") + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON1) + + PORT_START("POT") + PORT_BIT(0x1ff, 0x100, IPT_PADDLE) PORT_MINMAX(110, 380) PORT_SENSITIVITY(30) PORT_KEYDELTA(20) +INPUT_PORTS_END + + +class msx_vaus_device : public device_t, public device_msx_general_purpose_port_interface +{ +public: + msx_vaus_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); + + virtual u8 read() override; + virtual void pin_6_w(int state) override; + virtual void pin_8_w(int state) override; + +protected: + virtual void device_start() override; + virtual void device_reset() override; + + virtual ioport_constructor device_input_ports() const override { return INPUT_PORTS_NAME(msx_vaus); } + TIMER_CALLBACK_MEMBER(copy_counter); + +private: + required_ioport m_button; + required_ioport m_pot; + emu_timer *m_timer; + u8 m_old_pin6; + u8 m_old_pin8; + u16 m_counter; + u16 m_shift_reg; +}; + +msx_vaus_device::msx_vaus_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) + : device_t(mconfig, MSX_VAUS, tag, owner, clock) + , device_msx_general_purpose_port_interface(mconfig, *this) + , m_button(*this, "BUTTON") + , m_pot(*this, "POT") + , m_timer(nullptr) +{ +} + +void msx_vaus_device::device_start() +{ + m_timer = timer_alloc(FUNC(msx_vaus_device::copy_counter), this); + save_item(NAME(m_old_pin6)); + save_item(NAME(m_old_pin8)); + save_item(NAME(m_counter)); + save_item(NAME(m_shift_reg)); +} + +void msx_vaus_device::device_reset() +{ + m_old_pin8 = 0; + m_counter = 0; + m_shift_reg = 0; +} + +u8 msx_vaus_device::read() +{ + // bit 0/pin 1 - shift register output + // bit 1/pin 2 - button + return (m_button->read() & 0x02) | (BIT(m_shift_reg, 8) ? 0x01 : 0x00) | 0xfc; +} + +void msx_vaus_device::pin_6_w(int state) +{ + if (!m_old_pin6 && state) + { + m_shift_reg <<= 1; + } + m_old_pin6 = state; +} + +void msx_vaus_device::pin_8_w(int state) +{ + if (!state) + { + m_counter = 0; + m_timer->adjust(attotime::never); + } + else if (!m_old_pin8) + { + // start counting; the counter is incremented on a ~96k2 clock + m_counter = m_pot->read(); + m_timer->adjust(attotime::from_ticks(m_counter, 96200)); + } + m_old_pin8 = state; +} + +TIMER_CALLBACK_MEMBER(msx_vaus_device::copy_counter) +{ + m_shift_reg = m_counter; +} + +} // anonymous namespace + + +DEFINE_DEVICE_TYPE_PRIVATE(MSX_VAUS, device_msx_general_purpose_port_interface, msx_vaus_device, "msx_vaus", "MSX Arkanoid Vaus") diff --git a/src/devices/bus/msx/ctrl/vaus.h b/src/devices/bus/msx/ctrl/vaus.h new file mode 100644 index 00000000000..1b6d713a9a3 --- /dev/null +++ b/src/devices/bus/msx/ctrl/vaus.h @@ -0,0 +1,19 @@ +// license:BSD-3-Clause +// copyright-holders:Wilbert Pol +/********************************************************************** + + MSX Arkanoid Vaus controller emulation + +**********************************************************************/ + +#ifndef MAME_BUS_MSX_CTRL_VAUS_H +#define MAME_BUS_MSX_CTRL_VAUS_H + +#pragma once + +#include "ctrl.h" + + +DECLARE_DEVICE_TYPE(MSX_VAUS, device_msx_general_purpose_port_interface) + +#endif // MAME_BUS_MSX_CTRL_VAUS_H -- cgit v1.2.3