From 66b341e179164da4924b700d8a57823ad1c5285a Mon Sep 17 00:00:00 2001 From: 0kmg <9137159+0kmg@users.noreply.github.com> Date: Sat, 1 Oct 2022 06:34:32 -0800 Subject: bus/vcs_ctrl: Corrected header access modifiers. Simplified keypad code. (#10371) --- src/devices/bus/vcs_ctrl/joybooster.h | 14 ++++---- src/devices/bus/vcs_ctrl/joystick.h | 8 ++--- src/devices/bus/vcs_ctrl/keypad.cpp | 63 +++++++---------------------------- src/devices/bus/vcs_ctrl/keypad.h | 24 +++++++------ src/devices/bus/vcs_ctrl/lightpen.h | 8 ++--- src/devices/bus/vcs_ctrl/mouse.h | 14 ++++---- src/devices/bus/vcs_ctrl/paddles.h | 14 ++++---- src/devices/bus/vcs_ctrl/wheel.cpp | 2 +- src/devices/bus/vcs_ctrl/wheel.h | 8 ++--- 9 files changed, 59 insertions(+), 96 deletions(-) diff --git a/src/devices/bus/vcs_ctrl/joybooster.h b/src/devices/bus/vcs_ctrl/joybooster.h index 8b3cf922a1b..23f97fdb7a7 100644 --- a/src/devices/bus/vcs_ctrl/joybooster.h +++ b/src/devices/bus/vcs_ctrl/joybooster.h @@ -29,13 +29,6 @@ public: // construction/destruction vcs_joystick_booster_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - // optional information overrides - virtual ioport_constructor device_input_ports() const override; - -protected: - // device-level overrides - virtual void device_start() override; - // device_vcs_control_port_interface overrides virtual uint8_t vcs_joy_r() override; virtual uint8_t vcs_pot_x_r() override; @@ -44,6 +37,13 @@ protected: virtual bool has_pot_x() override { return true; } virtual bool has_pot_y() override { return true; } +protected: + // device-level overrides + virtual void device_start() override; + + // optional information overrides + virtual ioport_constructor device_input_ports() const override; + private: required_ioport m_joy; required_ioport m_potx; diff --git a/src/devices/bus/vcs_ctrl/joystick.h b/src/devices/bus/vcs_ctrl/joystick.h index dcae27d2965..1c8f941a633 100644 --- a/src/devices/bus/vcs_ctrl/joystick.h +++ b/src/devices/bus/vcs_ctrl/joystick.h @@ -28,15 +28,15 @@ public: // construction/destruction vcs_joystick_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - // optional information overrides - virtual ioport_constructor device_input_ports() const override; + // device_vcs_control_port_interface overrides + virtual uint8_t vcs_joy_r() override; protected: // device-level overrides virtual void device_start() override; - // device_vcs_control_port_interface overrides - virtual uint8_t vcs_joy_r() override; + // optional information overrides + virtual ioport_constructor device_input_ports() const override; private: required_ioport m_joy; diff --git a/src/devices/bus/vcs_ctrl/keypad.cpp b/src/devices/bus/vcs_ctrl/keypad.cpp index 97a43253c08..888cae738f5 100644 --- a/src/devices/bus/vcs_ctrl/keypad.cpp +++ b/src/devices/bus/vcs_ctrl/keypad.cpp @@ -58,7 +58,7 @@ vcs_keypad_device::vcs_keypad_device(const machine_config &mconfig, const char * device_t(mconfig, VCS_KEYPAD, tag, owner, clock), device_vcs_control_port_interface(mconfig, *this), m_keypad(*this, "KEYPAD"), - m_column(0) + m_row(0) { } @@ -69,8 +69,7 @@ vcs_keypad_device::vcs_keypad_device(const machine_config &mconfig, const char * void vcs_keypad_device::device_start() { - m_column = 0; - save_item(NAME(m_column)); + save_item(NAME(m_row)); } @@ -78,64 +77,26 @@ void vcs_keypad_device::device_start() // vcs_joy_w - joystick write //------------------------------------------------- -uint8_t vcs_keypad_device::vcs_joy_r() +void vcs_keypad_device::vcs_joy_w(uint8_t data) { - for ( int i = 0; i < 4; i++ ) - { - if ( ! ( ( m_column >> i ) & 0x01 ) ) - { - if ( ( m_keypad->read() >> 3*i ) & 0x04 ) - { - return 0xff; - } - else - { - return 0; - } - } - } - return 0xff; + m_row = data & 0x0f; } -void vcs_keypad_device::vcs_joy_w( uint8_t data ) +uint8_t vcs_keypad_device::read_keys(uint8_t col) { - m_column = data & 0x0F; -} + uint8_t val = 0; -uint8_t vcs_keypad_device::vcs_pot_x_r() -{ - for ( int i = 0; i < 4; i++ ) + for (int row = 0; row < 4; row++) { - if ( ! ( ( m_column >> i ) & 0x01 ) ) + if (!BIT(m_row, row)) { - if ( ( m_keypad->read() >> 3*i ) & 0x01 ) - { - return 0; - } - else + if (!BIT(m_keypad->read(), 3*row + col)) { - return 0xff; + val = 0xff; } + break; } } - return 0; -} -uint8_t vcs_keypad_device::vcs_pot_y_r() -{ - for ( int i = 0; i < 4; i++ ) - { - if ( ! ( ( m_column >> i ) & 0x01 ) ) - { - if ( ( m_keypad->read() >> 3*i ) & 0x02 ) - { - return 0; - } - else - { - return 0xff; - } - } - } - return 0; + return val; } diff --git a/src/devices/bus/vcs_ctrl/keypad.h b/src/devices/bus/vcs_ctrl/keypad.h index 37733cc135c..13218b0bf0c 100644 --- a/src/devices/bus/vcs_ctrl/keypad.h +++ b/src/devices/bus/vcs_ctrl/keypad.h @@ -28,26 +28,28 @@ public: // construction/destruction vcs_keypad_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - // optional information overrides - virtual ioport_constructor device_input_ports() const override; + // device_vcs_control_port_interface overrides + virtual uint8_t vcs_joy_r() override { return ~read_keys(2); } + virtual uint8_t vcs_pot_x_r() override { return read_keys(0); } + virtual uint8_t vcs_pot_y_r() override { return read_keys(1); } + virtual void vcs_joy_w(uint8_t data) override; + + virtual bool has_pot_x() override { return true; } + virtual bool has_pot_y() override { return true; } protected: // device-level overrides virtual void device_start() override; - // device_vcs_control_port_interface overrides - virtual uint8_t vcs_joy_r() override; - virtual void vcs_joy_w( uint8_t data ) override; - virtual uint8_t vcs_pot_x_r() override; - virtual uint8_t vcs_pot_y_r() override; - - virtual bool has_pot_x() override { return true; } - virtual bool has_pot_y() override { return true; } + // optional information overrides + virtual ioport_constructor device_input_ports() const override; private: + uint8_t read_keys(uint8_t column); + required_ioport m_keypad; - uint8_t m_column; + uint8_t m_row; }; diff --git a/src/devices/bus/vcs_ctrl/lightpen.h b/src/devices/bus/vcs_ctrl/lightpen.h index f0b2805bdd6..82c4f06c5aa 100644 --- a/src/devices/bus/vcs_ctrl/lightpen.h +++ b/src/devices/bus/vcs_ctrl/lightpen.h @@ -28,8 +28,8 @@ public: // construction/destruction vcs_lightpen_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - // optional information overrides - virtual ioport_constructor device_input_ports() const override; + // device_vcs_control_port_interface overrides + virtual uint8_t vcs_joy_r() override; DECLARE_INPUT_CHANGED_MEMBER( trigger ); @@ -37,8 +37,8 @@ protected: // device-level overrides virtual void device_start() override; - // device_vcs_control_port_interface overrides - virtual uint8_t vcs_joy_r() override; + // optional information overrides + virtual ioport_constructor device_input_ports() const override; private: required_ioport m_joy; diff --git a/src/devices/bus/vcs_ctrl/mouse.h b/src/devices/bus/vcs_ctrl/mouse.h index eab33d64aab..e90f413f8b3 100644 --- a/src/devices/bus/vcs_ctrl/mouse.h +++ b/src/devices/bus/vcs_ctrl/mouse.h @@ -28,13 +28,6 @@ public: // construction/destruction vcs_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - // optional information overrides - virtual ioport_constructor device_input_ports() const override; - -protected: - // device-level overrides - virtual void device_start() override; - // device_vcs_control_port_interface overrides virtual uint8_t vcs_joy_r() override; virtual uint8_t vcs_pot_x_r() override; @@ -43,6 +36,13 @@ protected: virtual bool has_pot_x() override { return true; } virtual bool has_pot_y() override { return true; } +protected: + // device-level overrides + virtual void device_start() override; + + // optional information overrides + virtual ioport_constructor device_input_ports() const override; + private: required_ioport m_joy; required_ioport m_potx; diff --git a/src/devices/bus/vcs_ctrl/paddles.h b/src/devices/bus/vcs_ctrl/paddles.h index e88084066ee..70414f1da4b 100644 --- a/src/devices/bus/vcs_ctrl/paddles.h +++ b/src/devices/bus/vcs_ctrl/paddles.h @@ -28,13 +28,6 @@ public: // construction/destruction vcs_paddles_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - // optional information overrides - virtual ioport_constructor device_input_ports() const override; - -protected: - // device-level overrides - virtual void device_start() override; - // device_vcs_control_port_interface overrides virtual uint8_t vcs_joy_r() override; virtual uint8_t vcs_pot_x_r() override; @@ -43,6 +36,13 @@ protected: virtual bool has_pot_x() override { return true; } virtual bool has_pot_y() override { return true; } +protected: + // device-level overrides + virtual void device_start() override; + + // optional information overrides + virtual ioport_constructor device_input_ports() const override; + private: required_ioport m_joy; required_ioport m_potx; diff --git a/src/devices/bus/vcs_ctrl/wheel.cpp b/src/devices/bus/vcs_ctrl/wheel.cpp index 76e86530cf8..871835d89dd 100644 --- a/src/devices/bus/vcs_ctrl/wheel.cpp +++ b/src/devices/bus/vcs_ctrl/wheel.cpp @@ -73,5 +73,5 @@ uint8_t vcs_wheel_device::vcs_joy_r() { static const uint8_t driving_lookup[4] = { 0x00, 0x02, 0x03, 0x01 }; - return m_joy->read() | driving_lookup[ ( m_wheel->read() & 0x18 ) >> 3 ]; + return m_joy->read() | driving_lookup[BIT(m_wheel->read(), 3, 2)]; } diff --git a/src/devices/bus/vcs_ctrl/wheel.h b/src/devices/bus/vcs_ctrl/wheel.h index 369afe7c614..8919e2d2888 100644 --- a/src/devices/bus/vcs_ctrl/wheel.h +++ b/src/devices/bus/vcs_ctrl/wheel.h @@ -28,15 +28,15 @@ public: // construction/destruction vcs_wheel_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - // optional information overrides - virtual ioport_constructor device_input_ports() const override; + // device_vcs_control_port_interface overrides + virtual uint8_t vcs_joy_r() override; protected: // device-level overrides virtual void device_start() override; - // device_vcs_control_port_interface overrides - virtual uint8_t vcs_joy_r() override; + // optional information overrides + virtual ioport_constructor device_input_ports() const override; private: required_ioport m_joy; -- cgit v1.2.3