summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Ivan Vangelista <mesgnet@yahoo.it>2014-01-07 17:37:19 +0000
committer Ivan Vangelista <mesgnet@yahoo.it>2014-01-07 17:37:19 +0000
commit8bcb41f366d436d6d8316308f35aac1af7df43b2 (patch)
tree2a021aa1eb96f263920ba2fba7d511a0244be1b3 /src
parent60c5be899ab0b09d96bbb28d192e6bfdcf51fb35 (diff)
Modernized kr2376 device. (nw)
Diffstat (limited to 'src')
-rw-r--r--src/mess/drivers/z80ne.c1
-rw-r--r--src/mess/includes/z80ne.h4
-rw-r--r--src/mess/machine/kr2376.c242
-rw-r--r--src/mess/machine/kr2376.h101
-rw-r--r--src/mess/machine/z80ne.c10
5 files changed, 170 insertions, 188 deletions
diff --git a/src/mess/drivers/z80ne.c b/src/mess/drivers/z80ne.c
index 5b58d0649de..2bcbc37a3ab 100644
--- a/src/mess/drivers/z80ne.c
+++ b/src/mess/drivers/z80ne.c
@@ -99,7 +99,6 @@
#include "machine/ram.h"
/* peripheral chips */
-#include "machine/kr2376.h"
#include "machine/wd17xx.h"
/* Layout */
diff --git a/src/mess/includes/z80ne.h b/src/mess/includes/z80ne.h
index 3d51d89452d..155c0116ef7 100644
--- a/src/mess/includes/z80ne.h
+++ b/src/mess/includes/z80ne.h
@@ -14,7 +14,7 @@
#include "video/mc6847.h"
#include "imagedev/cassette.h"
#include "machine/ay31015.h"
-
+#include "machine/kr2376.h"
/***************************************************************************
CONSTANTS
@@ -99,7 +99,7 @@ public:
optional_device<mc6847_base_device> m_vdg;
optional_shared_ptr<UINT8> m_videoram;
required_device<ay31015_device> m_ay31015;
- optional_device<device_t> m_lx388_kr2376;
+ optional_device<kr2376_device> m_lx388_kr2376;
UINT8 m_lx383_scan_counter;
UINT8 m_lx383_key[LX383_KEYS];
int m_lx383_downsampler;
diff --git a/src/mess/machine/kr2376.c b/src/mess/machine/kr2376.c
index ecd991cb796..e9db28e7eff 100644
--- a/src/mess/machine/kr2376.c
+++ b/src/mess/machine/kr2376.c
@@ -9,7 +9,6 @@
#include "emu.h"
#include "kr2376.h"
-#include "devlegcy.h"
static const UINT8 KR2376_KEY_CODES[3][8][11] =
{
@@ -65,118 +64,142 @@ static const UINT8 KR2376_KEY_CODES[3][8][11] =
}
};
-struct kr2376_t
+
+const device_type KR2376 = &device_creator<kr2376_device>;
+
+kr2376_device::kr2376_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : device_t(mconfig, KR2376, "SMC KR2376", tag, owner, clock, "kr2376", __FILE__)
{
- const kr2376_interface *intf;
- int pins[41];
+}
- int ring11; /* sense input scan counter */
- int ring8; /* drive output scan counter */
- int modifiers; /* modifier inputs */
+//-------------------------------------------------
+// device_config_complete - perform any
+// operations now that the configuration is
+// complete
+//-------------------------------------------------
- int strobe; /* strobe output */
- int strobe_old;
- int parity;
- int data;
+void kr2376_device::device_config_complete()
+{
+ // inherit a copy of the static data
+ const kr2376_interface *intf = reinterpret_cast<const kr2376_interface *>(static_config());
+ if (intf != NULL)
+ *static_cast<kr2376_interface *>(this) = *intf;
- /* timers */
- emu_timer *scan_timer; /* keyboard scan timer */
- devcb_resolved_write_line on_strobe_changed;
-};
+ // or initialize to defaults if none provided
+ else
+ {
+ m_our_clock = 0;
+ memset(&m_on_strobe_changed_cb, 0, sizeof(m_on_strobe_changed_cb));
+ }
+}
-INLINE kr2376_t *get_safe_token(device_t *device)
+//-------------------------------------------------
+// device_start - device-specific startup
+//-------------------------------------------------
+
+void kr2376_device::device_start()
{
- assert(device != NULL);
- assert(device->type() == KR2376);
+ m_on_strobe_changed.resolve(m_on_strobe_changed_cb, *this);
+
+ /* set initial values */
+ m_ring11 = 0;
+ m_ring8 = 0;
+ m_modifiers = 0;
+ m_strobe = 0;
+ m_strobe_old = 0;
+ m_parity = 0;
+ m_data = 0;
+ change_output_lines();
+
+ /* create the timers */
+ m_scan_timer = timer_alloc(TIMER_SCAN_TICK);
+ m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(m_our_clock));
- return (kr2376_t *)downcast<kr2376_device *>(device)->token();
+ /* register for state saving */
+ save_item(NAME(m_ring11));
+ save_item(NAME(m_ring8));
+ save_item(NAME(m_modifiers));
+ save_item(NAME(m_strobe));
+ save_item(NAME(m_strobe_old));
+ save_item(NAME(m_parity));
+ save_item(NAME(m_data));
}
/*-------------------------------------------------
- kr2376_set_input_pin - set an input pin
+ set_input_pin - set an input pin
-------------------------------------------------*/
-void kr2376_set_input_pin( device_t *device, kr2376_input_pin_t pin, int data )
+void kr2376_device::set_input_pin( kr2376_input_pin_t pin, int data )
{
- kr2376_t *kr2376 = get_safe_token(device);
-
data = data ? 1 : 0;
switch ( pin )
{
case KR2376_PII:
case KR2376_DSII:
- kr2376->pins[pin] = data;
+ m_pins[pin] = data;
break;
}
}
/*-------------------------------------------------
- kr2376_get_output_pin - get the status of an output pin
+ get_output_pin - get the status of an output pin
-------------------------------------------------*/
-int kr2376_get_output_pin( device_t *device, kr2376_output_pin_t pin )
+int kr2376_device::get_output_pin( kr2376_output_pin_t pin )
{
- kr2376_t *kr2376 = get_safe_token(device);
-
- return kr2376->pins[pin];
+ return m_pins[pin];
}
-static void change_output_lines(device_t *device)
+void kr2376_device::change_output_lines()
{
- kr2376_t *kr2376 = get_safe_token(device);
-
- if (kr2376->strobe != kr2376->strobe_old)
+ if (m_strobe != m_strobe_old)
{
- kr2376->strobe_old = kr2376->strobe;
+ m_strobe_old = m_strobe;
- if (kr2376->strobe) // strobe 0 --> 1 transition
+ if (m_strobe) // strobe 0 --> 1 transition
{
/* update parity */
- kr2376->pins[KR2376_PO] = kr2376->parity ^ kr2376->pins[KR2376_PII];
+ m_pins[KR2376_PO] = m_parity ^ m_pins[KR2376_PII];
}
- kr2376->pins[KR2376_SO] = kr2376->strobe ^ kr2376->pins[KR2376_DSII];
- if (!kr2376->on_strobe_changed.isnull())
- kr2376->on_strobe_changed(kr2376->strobe ^ kr2376->pins[KR2376_DSII]);
+ m_pins[KR2376_SO] = m_strobe ^ m_pins[KR2376_DSII];
+ if (!m_on_strobe_changed.isnull())
+ m_on_strobe_changed(m_strobe ^ m_pins[KR2376_DSII]);
}
}
-static void clock_scan_counters(device_t *device)
+void kr2376_device::clock_scan_counters()
{
- kr2376_t *kr2376 = get_safe_token(device);
-
/* ring counters inhibited while strobe active */
- if (!kr2376->strobe)
+ if (!m_strobe)
{
- kr2376->ring11++;
- if (kr2376->ring11 == 11)
+ m_ring11++;
+ if (m_ring11 == 11)
{
- kr2376->ring11 = 0;
- kr2376->ring8++;
- if (kr2376->ring8 == 8)
- kr2376->ring8 = 0;
+ m_ring11 = 0;
+ m_ring8++;
+ if (m_ring8 == 8)
+ m_ring8 = 0;
}
}
}
-static void detect_keypress(device_t *device)
+void kr2376_device::detect_keypress()
{
- kr2376_t *kr2376= get_safe_token(device);
-
static const char *const keynames[] = { "X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7" };
- if (device->machine().root_device().ioport(keynames[kr2376->ring8])->read() == (1 << kr2376->ring11))
+ if (ioport(keynames[m_ring8])->read() == (1 << m_ring11))
{
- kr2376->modifiers = device->machine().root_device().ioport("MODIFIERS")->read();
+ m_modifiers = ioport("MODIFIERS")->read();
- kr2376->strobe = 1;
+ m_strobe = 1;
/* strobe 0->1 transition, encode char and update parity */
- if (!kr2376->strobe_old)
+ if (!m_strobe_old)
{
int i;
int parbit;
- int shift = BIT(kr2376->modifiers, 0);
- int control = BIT(kr2376->modifiers, 1);
- int alpha = BIT(kr2376->modifiers, 2);
+ int shift = BIT(m_modifiers, 0);
+ int control = BIT(m_modifiers, 1);
+ int alpha = BIT(m_modifiers, 2);
int table = 0;
if (shift || alpha)
@@ -184,41 +207,42 @@ static void detect_keypress(device_t *device)
else if (control)
table = 2;
- kr2376->data = KR2376_KEY_CODES[table][kr2376->ring8][kr2376->ring11];
+ m_data = KR2376_KEY_CODES[table][m_ring8][m_ring11];
/* Compute ODD parity */
- kr2376->parity = kr2376->data;
+ m_parity = m_data;
parbit = 0;
for (i=0; i<8; i++)
- parbit ^= (kr2376->parity >> i) & 1;
- kr2376->parity = parbit;
+ parbit ^= (m_parity >> i) & 1;
+ m_parity = parbit;
}
}
else
{
- kr2376->strobe = 0;
+ m_strobe = 0;
}
}
-static TIMER_CALLBACK( kr2376_scan_tick )
+void kr2376_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
- device_t *device = (device_t *)ptr;
-
- change_output_lines(device);
- clock_scan_counters(device);
- detect_keypress(device);
+ switch (id)
+ {
+ case TIMER_SCAN_TICK:
+ change_output_lines();
+ clock_scan_counters();
+ detect_keypress();
+ break;
+ }
}
/* Keyboard Data */
-READ8_DEVICE_HANDLER( kr2376_data_r )
+READ8_MEMBER( kr2376_device::data_r )
{
- kr2376_t *kr2376 = get_safe_token(device);
-
- if (kr2376->pins[KR2376_DSII])
- return kr2376->data ^ 0xff;
+ if (m_pins[KR2376_DSII])
+ return m_data ^ 0xff;
else
- return kr2376->data;
+ return m_data;
}
/* Input Ports */
@@ -335,69 +359,11 @@ INPUT_PORTS_START( kr2376 )
PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_CAPSLOCK) PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
INPUT_PORTS_END
-
-static DEVICE_START( kr2376 )
-{
- kr2376_t *kr2376 = get_safe_token(device);
-
- /* validate arguments */
- assert(device != NULL);
- assert(device->tag() != NULL);
-
- kr2376->intf = (const kr2376_interface*)device->static_config();
-
- assert(kr2376->intf != NULL);
- assert(kr2376->intf->clock > 0);
-
- kr2376->on_strobe_changed.resolve(kr2376->intf->on_strobe_changed_cb, *device);
-
- /* set initial values */
- kr2376->ring11 = 0;
- kr2376->ring8 = 0;
- kr2376->modifiers = 0;
- kr2376->strobe = 0;
- kr2376->strobe_old = 0;
- kr2376->parity = 0;
- kr2376->data = 0;
- change_output_lines(device);
-
- /* create the timers */
- kr2376->scan_timer = device->machine().scheduler().timer_alloc(FUNC(kr2376_scan_tick), (void *)device);
- kr2376->scan_timer->adjust(attotime::zero, 0, attotime::from_hz(kr2376->intf->clock));
-
- /* register for state saving */
- device->save_item(NAME(kr2376->ring11));
- device->save_item(NAME(kr2376->ring8));
- device->save_item(NAME(kr2376->modifiers));
- device->save_item(NAME(kr2376->strobe));
- device->save_item(NAME(kr2376->strobe_old));
- device->save_item(NAME(kr2376->parity));
- device->save_item(NAME(kr2376->data));
-}
-
-const device_type KR2376 = &device_creator<kr2376_device>;
-
-kr2376_device::kr2376_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
- : device_t(mconfig, KR2376, "SMC KR2376", tag, owner, clock, "kr2376", __FILE__)
-{
- m_token = global_alloc_clear(kr2376_t);
-}
-
//-------------------------------------------------
-// device_config_complete - perform any
-// operations now that the configuration is
-// complete
+// input_ports - device-specific input ports
//-------------------------------------------------
-void kr2376_device::device_config_complete()
+ioport_constructor kr2376_device::device_input_ports() const
{
-}
-
-//-------------------------------------------------
-// device_start - device-specific startup
-//-------------------------------------------------
-
-void kr2376_device::device_start()
-{
- DEVICE_START_NAME( kr2376 )(this);
-}
+ return INPUT_PORTS_NAME( kr2376 );
+} \ No newline at end of file
diff --git a/src/mess/machine/kr2376.h b/src/mess/machine/kr2376.h
index 2b69bf7e522..ad3bf02b4f7 100644
--- a/src/mess/machine/kr2376.h
+++ b/src/mess/machine/kr2376.h
@@ -33,36 +33,6 @@
#ifndef __KR2376__
#define __KR2376__
-typedef void (*kr2376_on_strobe_changed_func) (device_t *device, int level);
-#define KR2376_ON_STROBE_CHANGED(name) void name(device_t *device, int level)
-
-class kr2376_device : public device_t
-{
-public:
- kr2376_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
- ~kr2376_device() { global_free(m_token); }
-
- // access to legacy token
- void *token() const { assert(m_token != NULL); return m_token; }
-protected:
- // device-level overrides
- virtual void device_config_complete();
- virtual void device_start();
-private:
- // internal state
- void *m_token;
-};
-
-extern const device_type KR2376;
-
-
-#define MCFG_KR2376_ADD(_tag, _intrf) \
- MCFG_DEVICE_ADD(_tag, KR2376, 0) \
- MCFG_DEVICE_CONFIG(_intrf)
-
-#define MCFG_KR2376_REMOVE(_tag) \
- MCFG_DEVICE_REMOVE(_tag, KR2376)
-
/*
* Input pins
*/
@@ -78,27 +48,76 @@ enum kr2376_output_pin_t
KR2376_PO=7 /* PO - Pin 7 - Parity Output */
};
+typedef void (*kr2376_on_strobe_changed_func) (device_t *device, int level);
+#define KR2376_ON_STROBE_CHANGED(name) void name(device_t *device, int level)
+
/* interface */
struct kr2376_interface
{
/* The clock of the chip (Typical 50 kHz) */
- int clock;
+ int m_our_clock;
/* This will be called for every change of the strobe pin (pin 16). Optional */
- devcb_write_line on_strobe_changed_cb;
+ devcb_write_line m_on_strobe_changed_cb;
};
-#define KR2376_INTERFACE(name) const kr2376_interface (name)=
-/* keyboard matrix */
-INPUT_PORTS_EXTERN( kr2376 );
-/* keyboard data */
-DECLARE_READ8_DEVICE_HANDLER( kr2376_data_r );
+class kr2376_device : public device_t,
+ public kr2376_interface
+{
+public:
+ kr2376_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
+ ~kr2376_device() {}
+
+ /* keyboard data */
+ DECLARE_READ8_MEMBER( data_r );
-/* Set an input pin */
-void kr2376_set_input_pin( device_t *device, kr2376_input_pin_t pin, int data );
+ /* Set an input pin */
+ void set_input_pin( kr2376_input_pin_t pin, int data );
+ /* Get an output pin */
+ int get_output_pin( kr2376_output_pin_t pin );
-/* Get an output pin */
-int kr2376_get_output_pin( device_t *device, kr2376_output_pin_t pin );
+protected:
+ // device-level overrides
+ virtual void device_config_complete();
+ virtual void device_start();
+ virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
+ virtual ioport_constructor device_input_ports() const;
+
+private:
+ // internal state
+ int m_pins[41];
+
+ int m_ring11; /* sense input scan counter */
+ int m_ring8; /* drive output scan counter */
+ int m_modifiers; /* modifier inputs */
+
+ int m_strobe; /* strobe output */
+ int m_strobe_old;
+ int m_parity;
+ int m_data;
+
+ /* timers */
+ emu_timer *m_scan_timer; /* keyboard scan timer */
+ devcb_resolved_write_line m_on_strobe_changed;
+
+ enum
+ {
+ TIMER_SCAN_TICK
+ };
+
+ void change_output_lines();
+ void clock_scan_counters();
+ void detect_keypress();
+};
+
+extern const device_type KR2376;
+
+
+#define MCFG_KR2376_ADD(_tag, _intrf) \
+ MCFG_DEVICE_ADD(_tag, KR2376, 0) \
+ MCFG_DEVICE_CONFIG(_intrf)
+
+#define KR2376_INTERFACE(name) const kr2376_interface (name)=
#endif
diff --git a/src/mess/machine/z80ne.c b/src/mess/machine/z80ne.c
index 9bf6bbe3f84..cb935dce0e2 100644
--- a/src/mess/machine/z80ne.c
+++ b/src/mess/machine/z80ne.c
@@ -13,8 +13,6 @@
/* Components */
#include "machine/ay31015.h"
-#include "machine/kr2376.h"
-#include "video/mc6847.h"
#include "machine/wd17xx.h"
/* Devices */
@@ -200,8 +198,8 @@ DIRECT_UPDATE_MEMBER(z80ne_state::z80ne_reset_delay_count)
void z80ne_state::reset_lx388()
{
- kr2376_set_input_pin( m_lx388_kr2376, KR2376_DSII, 0);
- kr2376_set_input_pin( m_lx388_kr2376, KR2376_PII, 0);
+ m_lx388_kr2376->set_input_pin( KR2376_DSII, 0);
+ m_lx388_kr2376->set_input_pin( KR2376_PII, 0);
}
void z80ne_state::reset_lx382_banking()
@@ -619,8 +617,8 @@ READ8_MEMBER(z80ne_state::lx388_data_r)
{
UINT8 data;
- data = kr2376_data_r(m_lx388_kr2376, space, 0) & 0x7f;
- data |= kr2376_get_output_pin(m_lx388_kr2376, KR2376_SO) << 7;
+ data = m_lx388_kr2376->data_r(space, 0) & 0x7f;
+ data |= m_lx388_kr2376->get_output_pin(KR2376_SO) << 7;
return data;
}