Updated the INS 8154 RAM I/O device to no longer be legacy. [Harmony]

Non-whatsnew note: For MESS.
This commit is contained in:
Ryan Holtz 2010-08-27 05:37:56 +00:00
parent 04aa0a09eb
commit 4cc59054e0
3 changed files with 245 additions and 171 deletions

View File

@ -85,7 +85,9 @@ void pia6821_device_config::device_config_complete()
// inherit a copy of the static data // inherit a copy of the static data
const pia6821_interface *intf = reinterpret_cast<const pia6821_interface *>(static_config()); const pia6821_interface *intf = reinterpret_cast<const pia6821_interface *>(static_config());
if (intf != NULL) if (intf != NULL)
{
*static_cast<pia6821_interface *>(this) = *intf; *static_cast<pia6821_interface *>(this) = *intf;
}
// or initialize to defaults if none provided // or initialize to defaults if none provided
else else

View File

@ -11,6 +11,7 @@
#include "emu.h" #include "emu.h"
#include "ins8154.h" #include "ins8154.h"
#include "devhelpr.h"
/*************************************************************************** /***************************************************************************
@ -29,86 +30,136 @@ enum
}; };
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef struct _ins8154_state ins8154_state;
struct _ins8154_state
{
/* i/o lines */
devcb_resolved_read8 in_a_func;
devcb_resolved_write8 out_a_func;
devcb_resolved_read8 in_b_func;
devcb_resolved_write8 out_b_func;
devcb_resolved_write_line out_irq_func;
/* registers */
UINT8 in_a; /* Input Latch Port A */
UINT8 in_b; /* Input Latch Port B */
UINT8 out_a; /* Output Latch Port A */
UINT8 out_b; /* Output Latch Port B */
UINT8 mdr; /* Mode Definition Register */
UINT8 odra; /* Output Definition Register Port A */
UINT8 odrb; /* Output Definition Register Port B */
};
/*****************************************************************************
INLINE FUNCTIONS
*****************************************************************************/
INLINE ins8154_state *get_safe_token(running_device *device)
{
assert(device != NULL);
assert(device->type() == INS8154);
return (ins8154_state *)downcast<legacy_device_base *>(device)->token();
}
/*************************************************************************** /***************************************************************************
IMPLEMENTATION IMPLEMENTATION
***************************************************************************/ ***************************************************************************/
READ8_DEVICE_HANDLER( ins8154_r ) //**************************************************************************
// DEVICE CONFIGURATION
//**************************************************************************
GENERIC_DEVICE_CONFIG_SETUP(ins8154, "INS8154")
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void ins8154_device_config::device_config_complete()
{
// inherit a copy of the static data
const ins8154_interface *intf = reinterpret_cast<const ins8154_interface *>(static_config());
if (intf != NULL)
{
*static_cast<ins8154_interface *>(this) = *intf;
}
// or initialize to defaults if none provided
else
{
memset(&m_in_a_func, 0, sizeof(m_in_a_func));
memset(&m_in_b_func, 0, sizeof(m_in_b_func));
memset(&m_out_a_func, 0, sizeof(m_out_a_func));
memset(&m_out_b_func, 0, sizeof(m_out_b_func));
memset(&m_out_irq_func, 0, sizeof(m_out_irq_func));
}
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
const device_type INS8154 = ins8154_device_config::static_alloc_device_config;
//-------------------------------------------------
// ins8154_device - constructor
//-------------------------------------------------
ins8154_device::ins8154_device(running_machine &_machine, const ins8154_device_config &config)
: device_t(_machine, config),
m_config(config)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void ins8154_device::device_start()
{
/* resolve callbacks */
devcb_resolve_read8(&m_in_a_func, &m_config.m_in_a_func, this);
devcb_resolve_write8(&m_out_a_func, &m_config.m_out_a_func, this);
devcb_resolve_read8(&m_in_b_func, &m_config.m_in_b_func, this);
devcb_resolve_write8(&m_out_b_func, &m_config.m_out_b_func, this);
devcb_resolve_write_line(&m_out_irq_func, &m_config.m_out_irq_func, this);
/* register for state saving */
state_save_register_device_item(this, 0, m_in_a);
state_save_register_device_item(this, 0, m_in_b);
state_save_register_device_item(this, 0, m_out_a);
state_save_register_device_item(this, 0, m_out_b);
state_save_register_device_item(this, 0, m_mdr);
state_save_register_device_item(this, 0, m_odra);
state_save_register_device_item(this, 0, m_odrb);
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void ins8154_device::device_reset()
{
m_in_a = 0;
m_in_b = 0;
m_out_a = 0;
m_out_b = 0;
m_mdr = 0;
m_odra = 0;
m_odrb = 0;
}
READ8_DEVICE_HANDLER_TRAMPOLINE(ins8154, ins8154_r)
{ {
ins8154_state *ins8154 = get_safe_token(device);
UINT8 val = 0xff; UINT8 val = 0xff;
if (offset > 0x24) if (offset > 0x24)
{ {
if (VERBOSE) if (VERBOSE)
logerror("%s: INS8154 '%s' Read from invalid offset %02x!\n", cpuexec_describe_context(device->machine), device->tag(), offset); {
logerror("%s: INS8154 '%s' Read from invalid offset %02x!\n", cpuexec_describe_context(&m_machine), tag(), offset);
}
return 0xff; return 0xff;
} }
switch (offset) switch (offset)
{ {
case 0x20: case 0x20:
if (ins8154->in_a_func.read != NULL) val = devcb_call_read8(&m_in_a_func, 0);
val = devcb_call_read8(&ins8154->in_a_func, 0); m_in_a = val;
ins8154->in_a = val;
break; break;
case 0x21: case 0x21:
if (ins8154->in_b_func.read != NULL) val = devcb_call_read8(&m_in_b_func, 0);
val = devcb_call_read8(&ins8154->in_b_func, 0); m_in_b = val;
ins8154->in_b = val;
break; break;
default: default:
if (offset < 0x08) if (offset < 0x08)
{ {
if (ins8154->in_a_func.read != NULL) val = (devcb_call_read8(&m_in_a_func, 0) << (8 - offset)) & 0x80;
val = (devcb_call_read8(&ins8154->in_a_func, 0) << (8 - offset)) & 0x80; m_in_a = val;
ins8154->in_a = val;
} }
else else
{ {
if (ins8154->in_b_func.read != NULL) val = (devcb_call_read8(&m_in_b_func, 0) << (8 - (offset >> 4))) & 0x80;
val = (devcb_call_read8(&ins8154->in_b_func, 0) << (8 - (offset >> 4))) & 0x80; m_in_b = val;
ins8154->in_b = val;
} }
break; break;
} }
@ -116,68 +167,74 @@ READ8_DEVICE_HANDLER( ins8154_r )
return val; return val;
} }
WRITE8_DEVICE_HANDLER( ins8154_porta_w ) WRITE8_DEVICE_HANDLER_TRAMPOLINE(ins8154, ins8154_porta_w)
{ {
ins8154_state *ins8154 = get_safe_token(device); m_out_a = data;
ins8154->out_a = data;
/* Test if any pins are set as outputs */ /* Test if any pins are set as outputs */
if (ins8154->odra) if (m_odra)
devcb_call_write8(&ins8154->out_a_func, 0, (data & ins8154->odra) | (ins8154->odra ^ 0xff)); {
devcb_call_write8(&m_out_a_func, 0, (data & m_odra) | (m_odra ^ 0xff));
}
} }
WRITE8_DEVICE_HANDLER( ins8154_portb_w ) WRITE8_DEVICE_HANDLER_TRAMPOLINE(ins8154, ins8154_portb_w)
{ {
ins8154_state *ins8154 = get_safe_token(device); m_out_b = data;
ins8154->out_b = data;
/* Test if any pins are set as outputs */ /* Test if any pins are set as outputs */
if (ins8154->odrb) if (m_odrb)
devcb_call_write8(&ins8154->out_b_func, 0, (data & ins8154->odrb) | (ins8154->odrb ^ 0xff)); {
devcb_call_write8(&m_out_b_func, 0, (data & m_odrb) | (m_odrb ^ 0xff));
}
} }
WRITE8_DEVICE_HANDLER( ins8154_w ) WRITE8_DEVICE_HANDLER_TRAMPOLINE(ins8154, ins8154_w)
{ {
ins8154_state *ins8154 = get_safe_token(device);
if (offset > 0x24) if (offset > 0x24)
{ {
if (VERBOSE) if (VERBOSE)
logerror("%s: INS8154 '%s' Write %02x to invalid offset %02x!\n", cpuexec_describe_context(device->machine), device->tag(), data, offset); {
logerror("%s: INS8154 '%s' Write %02x to invalid offset %02x!\n", cpuexec_describe_context(&m_machine), tag(), data, offset);
}
return; return;
} }
switch (offset) switch (offset)
{ {
case 0x20: case 0x20:
ins8154_porta_w(device, 0, data); ins8154_porta_w(0, data);
break; break;
case 0x21: case 0x21:
ins8154_portb_w(device, 0, data); ins8154_portb_w(0, data);
break; break;
case 0x22: case 0x22:
if (VERBOSE) if (VERBOSE)
logerror("%s: INS8154 '%s' ODRA set to %02x\n", cpuexec_describe_context(device->machine), device->tag(), data); {
logerror("%s: INS8154 '%s' ODRA set to %02x\n", cpuexec_describe_context(&m_machine), tag(), data);
}
ins8154->odra = data; m_odra = data;
break; break;
case 0x23: case 0x23:
if (VERBOSE) if (VERBOSE)
logerror("%s: INS8154 '%s' ODRB set to %02x\n", cpuexec_describe_context(device->machine), device->tag(), data); {
logerror("%s: INS8154 '%s' ODRB set to %02x\n", cpuexec_describe_context(&m_machine), tag(), data);
}
ins8154->odrb = data; m_odrb = data;
break; break;
case 0x24: case 0x24:
if (VERBOSE) if (VERBOSE)
logerror("%s: INS8154 '%s' MDR set to %02x\n", cpuexec_describe_context(device->machine), device->tag(), data); {
logerror("%s: INS8154 '%s' MDR set to %02x\n", cpuexec_describe_context(&m_machine), tag(), data);
}
ins8154->mdr = data; m_mdr = data;
break; break;
default: default:
@ -186,11 +243,11 @@ WRITE8_DEVICE_HANDLER( ins8154_w )
/* Set bit */ /* Set bit */
if (offset < 0x08) if (offset < 0x08)
{ {
ins8154_porta_w(device, 0, ins8154->out_a |= offset & 0x07); ins8154_porta_w(0, m_out_a |= offset & 0x07);
} }
else else
{ {
ins8154_portb_w(device, 0, ins8154->out_b |= (offset >> 4) & 0x07); ins8154_portb_w(0, m_out_b |= (offset >> 4) & 0x07);
} }
} }
else else
@ -198,75 +255,14 @@ WRITE8_DEVICE_HANDLER( ins8154_w )
/* Clear bit */ /* Clear bit */
if (offset < 0x08) if (offset < 0x08)
{ {
ins8154_porta_w(device, 0, ins8154->out_a & ~(offset & 0x07)); ins8154_porta_w(0, m_out_a & ~(offset & 0x07));
} }
else else
{ {
ins8154_portb_w(device, 0, ins8154->out_b & ~((offset >> 4) & 0x07)); ins8154_portb_w(0, m_out_b & ~((offset >> 4) & 0x07));
} }
} }
break; break;
} }
} }
/*****************************************************************************
DEVICE INTERFACE
*****************************************************************************/
static DEVICE_START( ins8154 )
{
ins8154_state *ins8154 = get_safe_token(device);
const ins8154_interface *intf = (const ins8154_interface *)device->baseconfig().static_config();
/* validate some basic stuff */
assert(intf != NULL);
/* resolve callbacks */
devcb_resolve_read8(&ins8154->in_a_func, &intf->in_a_func, device);
devcb_resolve_write8(&ins8154->out_a_func, &intf->out_a_func, device);
devcb_resolve_read8(&ins8154->in_b_func, &intf->in_b_func, device);
devcb_resolve_write8(&ins8154->out_b_func, &intf->out_b_func, device);
devcb_resolve_write_line(&ins8154->out_irq_func, &intf->out_irq_func, device);
/* register for state saving */
state_save_register_device_item(device, 0, ins8154->in_a);
state_save_register_device_item(device, 0, ins8154->in_b);
state_save_register_device_item(device, 0, ins8154->out_a);
state_save_register_device_item(device, 0, ins8154->out_b);
state_save_register_device_item(device, 0, ins8154->mdr);
state_save_register_device_item(device, 0, ins8154->odra);
state_save_register_device_item(device, 0, ins8154->odrb);
}
static DEVICE_RESET( ins8154 )
{
ins8154_state *ins8154 = get_safe_token(device);
ins8154->in_a = 0;
ins8154->in_b = 0;
ins8154->out_a = 0;
ins8154->out_b = 0;
ins8154->mdr = 0;
ins8154->odra = 0;
ins8154->odrb = 0;
}
/***************************************************************************
DEVICE GETINFO
***************************************************************************/
static const char DEVTEMPLATE_SOURCE[] = __FILE__;
#define DEVTEMPLATE_ID(p,s) p##ins8154##s
#define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET
#define DEVTEMPLATE_NAME "INS8154"
#define DEVTEMPLATE_FAMILY "INS8154"
#define DEVTEMPLATE_VERSION "1.1"
#define DEVTEMPLATE_CREDITS "Copyright MESS Team"
#include "devtempl.h"
DEFINE_LEGACY_DEVICE(INS8154, ins8154);

View File

@ -28,40 +28,14 @@
***************************************************************************/ ***************************************************************************/
#pragma once
#ifndef __INS8154_H__ #ifndef __INS8154_H__
#define __INS8154_H__ #define __INS8154_H__
#include "devlegcy.h" #include "emu.h"
#include "devcb.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef struct _ins8154_interface ins8154_interface;
struct _ins8154_interface
{
devcb_read8 in_a_func;
devcb_write8 out_a_func;
devcb_read8 in_b_func;
devcb_write8 out_b_func;
devcb_write_line out_irq_func;
};
DECLARE_LEGACY_DEVICE(INS8154, ins8154);
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
READ8_DEVICE_HANDLER( ins8154_r );
WRITE8_DEVICE_HANDLER( ins8154_w );
WRITE8_DEVICE_HANDLER( ins8154_porta_w );
WRITE8_DEVICE_HANDLER( ins8154_portb_w );
/*************************************************************************** /***************************************************************************
DEVICE CONFIGURATION MACROS DEVICE CONFIGURATION MACROS
@ -72,4 +46,106 @@ WRITE8_DEVICE_HANDLER( ins8154_portb_w );
MDRV_DEVICE_CONFIG(_intrf) MDRV_DEVICE_CONFIG(_intrf)
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
// ======================> ins8154_interface
struct ins8154_interface
{
devcb_read8 m_in_a_func;
devcb_write8 m_out_a_func;
devcb_read8 m_in_b_func;
devcb_write8 m_out_b_func;
devcb_write_line m_out_irq_func;
};
// ======================> ins8154_device_config
class ins8154_device_config : public device_config,
public ins8154_interface
{
friend class ins8154_device;
// construction/destruction
ins8154_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
public:
// allocators
static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
virtual device_t *alloc_device(running_machine &machine) const;
protected:
// device_config overrides
virtual void device_config_complete();
};
// ======================> ins8154_device
class ins8154_device : public device_t
{
friend class ins8154_device_config;
// construction/destruction
ins8154_device(running_machine &_machine, const ins8154_device_config &_config);
public:
UINT8 ins8154_r(UINT32 offset);
void ins8154_w(UINT32 offset, UINT8 data);
void ins8154_porta_w(UINT32 offset, UINT8 data);
void ins8154_portb_w(UINT32 offset, UINT8 data);
protected:
// device-level overrides
virtual void device_start();
virtual void device_reset();
virtual void device_post_load() { }
virtual void device_clock_changed() { }
private:
/* i/o lines */
devcb_resolved_read8 m_in_a_func;
devcb_resolved_write8 m_out_a_func;
devcb_resolved_read8 m_in_b_func;
devcb_resolved_write8 m_out_b_func;
devcb_resolved_write_line m_out_irq_func;
/* registers */
UINT8 m_in_a; /* Input Latch Port A */
UINT8 m_in_b; /* Input Latch Port B */
UINT8 m_out_a; /* Output Latch Port A */
UINT8 m_out_b; /* Output Latch Port B */
UINT8 m_mdr; /* Mode Definition Register */
UINT8 m_odra; /* Output Definition Register Port A */
UINT8 m_odrb; /* Output Definition Register Port B */
const ins8154_device_config &m_config;
};
// device type definition
extern const device_type INS8154;
/***************************************************************************
PROTOTYPES
***************************************************************************/
READ8_DEVICE_HANDLER( ins8154_r );
WRITE8_DEVICE_HANDLER( ins8154_w );
WRITE8_DEVICE_HANDLER( ins8154_porta_w );
WRITE8_DEVICE_HANDLER( ins8154_portb_w );
#endif /* __INS8154_H__ */ #endif /* __INS8154_H__ */