diff options
-rw-r--r-- | .gitattributes | 2 | ||||
-rw-r--r-- | src/emu/bus/sms_ctrl/graphic.c | 158 | ||||
-rw-r--r-- | src/emu/bus/sms_ctrl/graphic.h | 60 | ||||
-rw-r--r-- | src/emu/bus/sms_ctrl/smsctrl.c | 2 |
4 files changed, 222 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes index 593a8fc3297..46cb970467e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1517,6 +1517,8 @@ src/emu/bus/sega8/rom.c svneol=native#text/plain src/emu/bus/sega8/rom.h svneol=native#text/plain src/emu/bus/sega8/sega8_slot.c svneol=native#text/plain src/emu/bus/sega8/sega8_slot.h svneol=native#text/plain +src/emu/bus/sms_ctrl/graphic.c svneol=native#text/plain +src/emu/bus/sms_ctrl/graphic.h svneol=native#text/plain src/emu/bus/sms_ctrl/joypad.c svneol=native#text/plain src/emu/bus/sms_ctrl/joypad.h svneol=native#text/plain src/emu/bus/sms_ctrl/lphaser.c svneol=native#text/plain diff --git a/src/emu/bus/sms_ctrl/graphic.c b/src/emu/bus/sms_ctrl/graphic.c new file mode 100644 index 00000000000..6b0024d91af --- /dev/null +++ b/src/emu/bus/sms_ctrl/graphic.c @@ -0,0 +1,158 @@ +/********************************************************************** + + Sega Master System "Graphic Board" emulation + + Copyright MESS Team. + Visit http://mamedev.org for licensing and usage restrictions. + +I/O 3f write | this method + 0x20 | 0x7f + 0x00 | 0x3f + 0x30 | 0xff + +Typical sequence: +- 3f write 0x20 +- read dc +- 3f write 0x00 +- read dc +- 3f write 0x20 +- read dc +- 3f write 0x30 +Suspect from kind of counter that is reset by a 0x30 write to I/O port 0x3f. +Once reset reads from i/O port dc expect to see 0xE0. +And then any write with differing bits goes through several internal I/O ports +with the first port being the one with the buttons + +In the reset/start state the lower four/five bits are 0. +Then a nibble is read containing the buttons (active low) +Then 2 nibbles are read to form a byte (first high nibble, then low nibble) indicating +whether the pen is on the graphic board, a value of FD, FE, or FF used for this. For +any other value the following 2 bytes are not read. +Then 2 nibbles are read to form a byte containing the absolute X coordinate. +THen 2 nibbles are read to form a byte containing the absolute Y coordiante. + +**********************************************************************/ + +#include "graphic.h" + + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +const device_type SMS_GRAPHIC = &device_creator<sms_graphic_device>; + + +static INPUT_PORTS_START( sms_graphic ) + PORT_START("BUTTONS") + PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) // MENU + PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) // DO + PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) // PEN + PORT_BIT( 0xf8, IP_ACTIVE_LOW, IPT_UNUSED ) + + PORT_START("X") + PORT_BIT( 0xff, 0x00, IPT_LIGHTGUN_X) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(15) + + PORT_START("Y") + PORT_BIT( 0xff, 0x00, IPT_LIGHTGUN_Y) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(15) +INPUT_PORTS_END + + +//------------------------------------------------- +// input_ports - device-specific input ports +//------------------------------------------------- + +ioport_constructor sms_graphic_device::device_input_ports() const +{ + return INPUT_PORTS_NAME( sms_graphic ); +} + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// sms_graphic_device - constructor +//------------------------------------------------- + +sms_graphic_device::sms_graphic_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, SMS_GRAPHIC, "Graphic Board", tag, owner, clock, "sms_joypad", __FILE__) + , device_sms_control_port_interface(mconfig, *this) + , m_buttons(*this, "BUTTONS") + , m_x(*this, "X") + , m_y(*this, "Y") + , m_index(0) + , m_previous_write(0xff) + , m_pressure(0xfd) +{ +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void sms_graphic_device::device_start() +{ + save_item(NAME(m_index)); + save_item(NAME(m_previous_write)); +} + + +//------------------------------------------------- +// sms_peripheral_r - joypad read +//------------------------------------------------- + +UINT8 sms_graphic_device::peripheral_r() +{ + switch (m_index) + { + case 0: // Initial state / "I am a board" + // If any regular button is pressed raise/lower TL ? +// if ((m_buttons->read() & 0x07) != 0x07) +// return 0xf0; + return 0xd0; + + case 1: // Read buttons (active low) + return m_buttons->read(); + + case 2: // Some thing only FD, FE, and FF cause the other values to be read + return m_pressure >> 4; + + case 3: + return m_pressure & 0x0f; + + case 4: // High nibble X? + return m_x->read() >> 4; + + case 5: // Low nibble X? + return m_x->read() & 0x0f; + + case 6: // High nibble Y? + return m_y->read() >> 4; + + case 7: // Low Nibble Y? + return m_y->read() & 0x0f; + } + + return 0xff; +} + +void sms_graphic_device::peripheral_w(UINT8 data) +{ + // Check for toggle on TH/TL + if ((data ^ m_previous_write) & 0xc0) + { + m_index++; + } + + // If TR is high, restart + if (data & 0x80) + { + m_index = 0; + } + + m_previous_write = data; +} + diff --git a/src/emu/bus/sms_ctrl/graphic.h b/src/emu/bus/sms_ctrl/graphic.h new file mode 100644 index 00000000000..fab7234c6b3 --- /dev/null +++ b/src/emu/bus/sms_ctrl/graphic.h @@ -0,0 +1,60 @@ +/********************************************************************** + + Sega Master System "Graphic Board" emulation + + Copyright MESS Team. + Visit http://mamedev.org for licensing and usage restrictions. + +**********************************************************************/ + +#pragma once + +#ifndef __SMS_GRAPHIC__ +#define __SMS_GRAPHIC__ + + +#include "emu.h" +#include "smsctrl.h" + + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> sms_graphic_device + +class sms_graphic_device : public device_t, + public device_sms_control_port_interface +{ +public: + // construction/destruction + sms_graphic_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // optional information overrides + virtual ioport_constructor device_input_ports() const; + +protected: + // device-level overrides + virtual void device_start(); + + // device_sms_control_port_interface overrides + virtual UINT8 peripheral_r(); + virtual void peripheral_w(UINT8 data); + +private: + required_ioport m_buttons; + required_ioport m_x; + required_ioport m_y; + + int m_index; + UINT8 m_previous_write; + UINT8 m_pressure; +}; + + +// device type definition +extern const device_type SMS_GRAPHIC; + + +#endif diff --git a/src/emu/bus/sms_ctrl/smsctrl.c b/src/emu/bus/sms_ctrl/smsctrl.c index 67225bdbcf1..667d090da86 100644 --- a/src/emu/bus/sms_ctrl/smsctrl.c +++ b/src/emu/bus/sms_ctrl/smsctrl.c @@ -16,6 +16,7 @@ #include "sportsjp.h" #include "rfu.h" #include "multitap.h" +#include "graphic.h" @@ -129,4 +130,5 @@ SLOT_INTERFACE_START( sms_control_port_devices ) SLOT_INTERFACE("sportspadjp", SMS_SPORTS_PAD_JP) SLOT_INTERFACE("rapidfire", SMS_RAPID_FIRE) SLOT_INTERFACE("multitap", SMS_MULTITAP) + SLOT_INTERFACE("graphic", SMS_GRAPHIC) SLOT_INTERFACE_END |