(MESS) hd61700: converted to use devcb callbacks instead of

static config, and removed a few trampolines in pb1000.c as a
consequence. nw.
This commit is contained in:
Fabio Priuli 2014-10-12 07:40:44 +00:00
parent 5654fcee2b
commit 542969fb95
3 changed files with 112 additions and 179 deletions

View File

@ -107,23 +107,19 @@ hd61700_cpu_device::hd61700_cpu_device(const machine_config &mconfig, const char
m_ppc(0x0000),
m_curpc(0x0000),
m_pc(0),
m_flags(0)
m_flags(0),
m_lcd_ctrl_cb(*this),
m_lcd_read_cb(*this),
m_lcd_write_cb(*this),
m_kb_read_cb(*this),
m_kb_write_cb(*this),
m_port_read_cb(*this),
m_port_write_cb(*this)
{
// ...
}
//-------------------------------------------------
// static_set_config - set the configuration
// structure
//-------------------------------------------------
void hd61700_cpu_device::static_set_config(device_t &device, const hd61700_config &config)
{
hd61700_cpu_device &conf = downcast<hd61700_cpu_device &>(device);
static_cast<hd61700_config &>(conf) = config;
}
//-------------------------------------------------
// device_start - start up the device
//-------------------------------------------------
@ -135,6 +131,14 @@ void hd61700_cpu_device::device_start()
m_sec_timer = timer_alloc(SEC_TIMER);
m_sec_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1));
m_lcd_ctrl_cb.resolve_safe();
m_lcd_read_cb.resolve_safe(0xff);
m_lcd_write_cb.resolve_safe();
m_kb_read_cb.resolve_safe(0xff);
m_kb_write_cb.resolve_safe();
m_port_read_cb.resolve_safe(0xff);
m_port_write_cb.resolve_safe();
// save state
save_item(NAME(m_ppc));
save_item(NAME(m_curpc));
@ -464,9 +468,7 @@ void hd61700_cpu_device::execute_run()
case 0x12: //stl
{
UINT8 arg = read_op();
if (m_lcd_data_w)
(*m_lcd_data_w)(*this, READ_REG(arg));
m_lcd_write_cb((offs_t)0, READ_REG(arg));
check_optional_jr(arg);
m_icount -= 11;
@ -476,10 +478,7 @@ void hd61700_cpu_device::execute_run()
case 0x13: //ldl
{
UINT8 arg = read_op();
UINT8 res = 0xff;
if (m_lcd_data_r)
res = (*m_lcd_data_r)(*this);
UINT8 res = m_lcd_read_cb(0);
WRITE_REG(arg, res);
@ -498,8 +497,7 @@ void hd61700_cpu_device::execute_run()
}
else
{
if (m_lcd_control)
(*m_lcd_control)(*this, READ_REG(arg));
m_lcd_ctrl_cb((offs_t)0, READ_REG(arg));
}
check_optional_jr(arg);
@ -529,8 +527,7 @@ void hd61700_cpu_device::execute_run()
case 0: //PE
case 1: //PD
WRITE_REG8(idx, src);
if (m_port_w)
(*m_port_w)(*this, REG_PD & REG_PE);
m_port_write_cb((offs_t)0, REG_PD & REG_PE);
break;
case 2: //IB
REG_IB = (REG_IB & 0x1f) | (src & 0xe0);
@ -539,8 +536,7 @@ void hd61700_cpu_device::execute_run()
WRITE_REG8(idx, src);
break;
case 4: //IA
if (m_kb_w)
(*m_kb_w)(*this, src);
m_kb_write_cb((offs_t)0, src);
WRITE_REG8(idx, src);
break;
case 5: //IE
@ -673,9 +669,7 @@ void hd61700_cpu_device::execute_run()
}
else
{
if (m_port_r)
src = (*m_port_r)(*this);
src = m_port_read_cb(0);
src&=(~REG_PE);
}
@ -1017,9 +1011,7 @@ void hd61700_cpu_device::execute_run()
case 0x52: //stl
{
UINT8 arg = read_op();
if (m_lcd_data_w)
(*m_lcd_data_w)(*this, arg);
m_lcd_write_cb((offs_t)0, arg);
m_icount -= 12;
}
@ -1036,8 +1028,7 @@ void hd61700_cpu_device::execute_run()
}
else
{
if (m_lcd_control)
(*m_lcd_control)(*this, src);
m_lcd_ctrl_cb((offs_t)0, src);
}
m_icount -= 3;
@ -1065,8 +1056,7 @@ void hd61700_cpu_device::execute_run()
case 0: //PE
case 1: //PD
WRITE_REG8(idx, src);
if (m_port_w)
(*m_port_w)(*this, REG_PD & REG_PE);
m_port_write_cb((offs_t)0, REG_PD & REG_PE);
break;
case 2: //IB
REG_IB = (REG_IB & 0x1f) | (src & 0xe0);
@ -1075,8 +1065,7 @@ void hd61700_cpu_device::execute_run()
WRITE_REG8(idx, src);
break;
case 4: //IA
if (m_kb_w)
(*m_kb_w)(*this, src);
m_kb_write_cb((offs_t)0, src);
WRITE_REG8(idx, src);
break;
case 5: //IE
@ -1449,11 +1438,8 @@ void hd61700_cpu_device::execute_run()
{
UINT8 arg = read_op();
if (m_lcd_data_w)
{
(*m_lcd_data_w)(*this, READ_REG(arg));
(*m_lcd_data_w)(*this, READ_REG(arg+1));
}
m_lcd_write_cb((offs_t)0, READ_REG(arg));
m_lcd_write_cb((offs_t)0, READ_REG(arg+1));
check_optional_jr(arg);
m_icount -= 19;
@ -1465,13 +1451,8 @@ void hd61700_cpu_device::execute_run()
UINT8 arg = read_op();
UINT8 reg0, reg1;
if (m_lcd_data_r)
{
reg0 = (*m_lcd_data_r)(*this);
reg1 = (*m_lcd_data_r)(*this);
}
else
reg0 = reg1 = 0xff;
reg0 = m_lcd_read_cb(0);
reg1 = m_lcd_read_cb(0);
WRITE_REG(arg+0, reg0);
WRITE_REG(arg+1, reg1);
@ -1633,13 +1614,8 @@ void hd61700_cpu_device::execute_run()
}
else
{
if (m_port_r)
{
reg0 = (*m_port_r)(*this);
reg1 = (*m_port_r)(*this);
}
else
reg0 = reg1 = 0xff;
reg0 = m_port_read_cb(0);
reg1 = m_port_read_cb(0);
reg0&=(~REG_PE);
reg1&=(~REG_PE);
@ -1663,11 +1639,7 @@ void hd61700_cpu_device::execute_run()
if (idx >= 5)
{
UINT16 port = 0xff;
if (m_kb_r)
port = (*m_kb_r)(*this);
UINT16 port = m_kb_read_cb(0);
src = (REG_KY & 0x0f00) | (port & 0xf0ff);
}
else
@ -2125,8 +2097,7 @@ void hd61700_cpu_device::execute_run()
for (int n=GET_IM3(arg1); n>0; n--)
{
if (m_lcd_data_w)
(*m_lcd_data_w)(*this, READ_REG(arg));
m_lcd_write_cb((offs_t)0, READ_REG(arg));
arg++;
m_icount -= 8;
@ -2144,10 +2115,7 @@ void hd61700_cpu_device::execute_run()
for (int n=GET_IM3(arg1); n>0; n--)
{
if (m_lcd_data_r)
src = (*m_lcd_data_r)(*this);
else
src = 0xff;
src = m_lcd_read_cb(0);
WRITE_REG(arg, src++);
@ -2641,11 +2609,8 @@ void hd61700_cpu_device::execute_run()
m_state |= CPU_SLP;
m_irq_status = 0;
if (m_lcd_control)
(*m_lcd_control)(*this, 0);
if (m_kb_w)
(*m_kb_w)(*this, 0);
m_lcd_ctrl_cb((offs_t)0, 0);
m_kb_write_cb((offs_t)0, 0);
m_icount -= 3;
}
break;

View File

@ -15,37 +15,32 @@
// INTERFACE CONFIGURATION MACROS
//**************************************************************************
#define MCFG_HD61700_CONFIG(_config) \
hd61700_cpu_device::static_set_config(*device, _config);
#define MCFG_HD61700_LCD_CTRL_CB(_devcb) \
devcb = &hd61700_cpu_device::set_lcd_ctrl_callback(*device, DEVCB_##_devcb);
#define MCFG_HD61700_LCD_WRITE_CB(_devcb) \
devcb = &hd61700_cpu_device::set_lcd_write_callback(*device, DEVCB_##_devcb);
#define MCFG_HD61700_LCD_READ_CB(_devcb) \
devcb = &hd61700_cpu_device::set_lcd_read_callback(*device, DEVCB_##_devcb);
#define MCFG_HD61700_KB_WRITE_CB(_devcb) \
devcb = &hd61700_cpu_device::set_kb_write_callback(*device, DEVCB_##_devcb);
#define MCFG_HD61700_KB_READ_CB(_devcb) \
devcb = &hd61700_cpu_device::set_kb_read_callback(*device, DEVCB_##_devcb);
#define MCFG_HD61700_PORT_WRITE_CB(_devcb) \
devcb = &hd61700_cpu_device::set_port_write_callback(*device, DEVCB_##_devcb);
#define MCFG_HD61700_PORT_READ_CB(_devcb) \
devcb = &hd61700_cpu_device::set_port_read_callback(*device, DEVCB_##_devcb);
//**************************************************************************
// DEFINITIONS
//**************************************************************************
// class definition
class hd61700_cpu_device;
// cpu port callbacks types
typedef void (*hd61700_lcd_control_func)(hd61700_cpu_device &device, UINT8 data);
typedef UINT8 (*hd61700_lcd_data_r_func)(hd61700_cpu_device &device);
typedef void (*hd61700_lcd_data_w_func)(hd61700_cpu_device &device, UINT8 data);
typedef UINT16 (*hd61700_kb_r_func)(hd61700_cpu_device &device);
typedef void (*hd61700_kb_w_func)(hd61700_cpu_device &device, UINT8 matrix);
typedef UINT8 (*hd61700_port_r_func)(hd61700_cpu_device &device);
typedef void (*hd61700_port_w_func)(hd61700_cpu_device &device, UINT8 data);
// device config
struct hd61700_config
{
hd61700_lcd_control_func m_lcd_control; //lcd control
hd61700_lcd_data_r_func m_lcd_data_r; //lcd data read
hd61700_lcd_data_w_func m_lcd_data_w; //lcd data write
hd61700_kb_r_func m_kb_r; //keyboard matrix read
hd61700_kb_w_func m_kb_w; //keyboard matrix write
hd61700_port_r_func m_port_r; //8 bit port read
hd61700_port_w_func m_port_w; //8 bit port write
};
// registers
enum
{
@ -68,15 +63,20 @@ enum
// ======================> hd61700_cpu_device
class hd61700_cpu_device : public cpu_device,
public hd61700_config
class hd61700_cpu_device : public cpu_device
{
public:
// construction/destruction
hd61700_cpu_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock);
static void static_set_config(device_t &device, const hd61700_config &config);
template<class _Object> static devcb_base &set_lcd_ctrl_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_lcd_ctrl_cb.set_callback(object); }
template<class _Object> static devcb_base &set_lcd_write_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_lcd_write_cb.set_callback(object); }
template<class _Object> static devcb_base &set_lcd_read_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_lcd_read_cb.set_callback(object); }
template<class _Object> static devcb_base &set_kb_write_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_kb_write_cb.set_callback(object); }
template<class _Object> static devcb_base &set_kb_read_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_kb_read_cb.set_callback(object); }
template<class _Object> static devcb_base &set_port_write_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_port_write_cb.set_callback(object); }
template<class _Object> static devcb_base &set_port_read_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_port_read_cb.set_callback(object); }
protected:
// device-level overrides
virtual void device_start();
@ -148,6 +148,14 @@ protected:
address_space *m_program;
devcb_write8 m_lcd_ctrl_cb; //lcd control
devcb_read8 m_lcd_read_cb; //lcd data read
devcb_write8 m_lcd_write_cb; //lcd data write
devcb_read16 m_kb_read_cb; //keyboard matrix read
devcb_write8 m_kb_write_cb; //keyboard matrix write
devcb_read8 m_port_read_cb; //8 bit port read
devcb_write8 m_port_write_cb; //8 bit port write
// flag definitions
static const int FLAG_Z = 0x80;
static const int FLAG_C = 0x40;

View File

@ -59,9 +59,15 @@ public:
virtual void machine_start();
UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
DECLARE_WRITE16_MEMBER( gatearray_w );
UINT16 pb2000c_kb_r();
UINT16 pb1000_kb_r();
void kb_matrix_w(UINT8 matrix);
DECLARE_WRITE8_MEMBER( lcd_control );
DECLARE_READ8_MEMBER( lcd_data_r );
DECLARE_WRITE8_MEMBER( lcd_data_w );
DECLARE_READ16_MEMBER( pb1000_kb_r );
DECLARE_READ16_MEMBER( pb2000c_kb_r );
DECLARE_WRITE8_MEMBER( kb_matrix_w );
DECLARE_READ8_MEMBER( pb1000_port_r );
DECLARE_READ8_MEMBER( pb2000c_port_r );
DECLARE_WRITE8_MEMBER( port_w );
UINT16 read_touchscreen(UINT8 line);
DECLARE_PALETTE_INIT(pb1000);
TIMER_CALLBACK_MEMBER(keyboard_timer);
@ -325,27 +331,21 @@ WRITE16_MEMBER( pb1000_state::gatearray_w )
membank("bank1")->set_base(m_rom_reg->base());
}
static void lcd_control(hd61700_cpu_device &device, UINT8 data)
WRITE8_MEMBER( pb1000_state::lcd_control )
{
pb1000_state *state = device.machine().driver_data<pb1000_state>();
state->m_hd44352->control_write(data);
m_hd44352->control_write(data);
}
static UINT8 lcd_data_r(hd61700_cpu_device &device)
READ8_MEMBER( pb1000_state::lcd_data_r )
{
pb1000_state *state = device.machine().driver_data<pb1000_state>();
return state->m_hd44352->data_read();
return m_hd44352->data_read();
}
static void lcd_data_w(hd61700_cpu_device &device, UINT8 data)
WRITE8_MEMBER( pb1000_state::lcd_data_w )
{
pb1000_state *state = device.machine().driver_data<pb1000_state>();
state->m_hd44352->data_write(data);
m_hd44352->data_write(data);
}
@ -364,7 +364,7 @@ UINT16 pb1000_state::read_touchscreen(UINT8 line)
}
UINT16 pb1000_state::pb1000_kb_r()
READ16_MEMBER( pb1000_state::pb1000_kb_r )
{
static const char *const bitnames[] = {"NULL", "KO1", "KO2", "KO3", "KO4", "KO5", "KO6", "KO7", "KO8", "KO9", "KO10", "KO11", "KO12", "NULL", "NULL", "NULL"};
UINT16 data = 0;
@ -388,7 +388,7 @@ UINT16 pb1000_state::pb1000_kb_r()
return data;
}
UINT16 pb1000_state::pb2000c_kb_r()
READ16_MEMBER( pb1000_state::pb2000c_kb_r )
{
static const char *const bitnames[] = {"NULL", "KO1", "KO2", "KO3", "KO4", "KO5", "KO6", "KO7", "KO8", "KO9", "KO10", "KO11", "KO12", "NULL", "NULL", "NULL"};
UINT16 data = 0;
@ -410,92 +410,45 @@ UINT16 pb1000_state::pb2000c_kb_r()
return data;
}
void pb1000_state::kb_matrix_w(UINT8 matrix)
WRITE8_MEMBER( pb1000_state::kb_matrix_w )
{
if (matrix & 0x80)
if (data & 0x80)
{
if ((m_kb_matrix & 0x80) != (matrix & 0x80))
if ((m_kb_matrix & 0x80) != (data & 0x80))
m_kb_timer->adjust(attotime::never, 0, attotime::never);
}
else
{
if ((m_kb_matrix & 0x40) != (matrix & 0x40))
if ((m_kb_matrix & 0x40) != (data & 0x40))
{
if (matrix & 0x40)
if (data & 0x40)
m_kb_timer->adjust(attotime::from_hz(32), 0, attotime::from_hz(32));
else
m_kb_timer->adjust(attotime::from_hz(256), 0, attotime::from_hz(256));
}
}
m_kb_matrix = matrix;
m_kb_matrix = data;
}
//-------------------------------------------------
// HD61700 interface
//-------------------------------------------------
static void kb_matrix_w_call(hd61700_cpu_device &device, UINT8 matrix)
{
pb1000_state *state = device.machine().driver_data<pb1000_state>();
state->kb_matrix_w(matrix);
}
static UINT8 pb1000_port_r(hd61700_cpu_device &device)
READ8_MEMBER( pb1000_state::pb1000_port_r )
{
//TODO
return 0x00;
}
static UINT8 pb2000c_port_r(hd61700_cpu_device &device)
READ8_MEMBER( pb1000_state::pb2000c_port_r )
{
//TODO
return 0xfc;
}
static void port_w(hd61700_cpu_device &device, UINT8 data)
WRITE8_MEMBER( pb1000_state::port_w )
{
pb1000_state *state = device.machine().driver_data<pb1000_state>();
state->m_beeper->set_state((BIT(data,7) ^ BIT(data,6)));
m_beeper->set_state((BIT(data,7) ^ BIT(data,6)));
//printf("%x\n", data);
}
static UINT16 pb1000_kb_r_call(hd61700_cpu_device &device)
{
pb1000_state *state = device.machine().driver_data<pb1000_state>();
return state->pb1000_kb_r();
}
static UINT16 pb2000c_kb_r_call(hd61700_cpu_device &device)
{
pb1000_state *state = device.machine().driver_data<pb1000_state>();
return state->pb2000c_kb_r();
}
static const hd61700_config pb1000_config =
{
lcd_control, //lcd control
lcd_data_r, //lcd data read
lcd_data_w, //lcd data write
pb1000_kb_r_call, //keyboard matrix read
kb_matrix_w_call, //keyboard matrix write
pb1000_port_r, //8 bit port read
port_w //8 bit port write
};
static const hd61700_config pb2000c_config =
{
lcd_control, //lcd control
lcd_data_r, //lcd data read
lcd_data_w, //lcd data write
pb2000c_kb_r_call, //keyboard matrix read
kb_matrix_w_call, //keyboard matrix write
pb2000c_port_r, //8 bit port read
port_w //8 bit port write
};
TIMER_CALLBACK_MEMBER(pb1000_state::keyboard_timer)
{
@ -522,7 +475,13 @@ static MACHINE_CONFIG_START( pb1000, pb1000_state )
/* basic machine hardware */
MCFG_CPU_ADD("maincpu", HD61700, 910000)
MCFG_CPU_PROGRAM_MAP(pb1000_mem)
MCFG_HD61700_CONFIG(pb1000_config)
MCFG_HD61700_LCD_CTRL_CB(WRITE8(pb1000_state, lcd_control))
MCFG_HD61700_LCD_READ_CB(READ8(pb1000_state, lcd_data_r))
MCFG_HD61700_LCD_WRITE_CB(WRITE8(pb1000_state, lcd_data_w))
MCFG_HD61700_KB_READ_CB(READ16(pb1000_state, pb1000_kb_r))
MCFG_HD61700_KB_WRITE_CB(WRITE8(pb1000_state, kb_matrix_w))
MCFG_HD61700_PORT_READ_CB(READ8(pb1000_state, pb1000_port_r))
MCFG_HD61700_PORT_WRITE_CB(WRITE8(pb1000_state, port_w))
/* video hardware */
MCFG_SCREEN_ADD("screen", LCD)
@ -554,7 +513,8 @@ static MACHINE_CONFIG_DERIVED( pb2000c, pb1000 )
/* basic machine hardware */
MCFG_CPU_MODIFY("maincpu")
MCFG_CPU_PROGRAM_MAP(pb2000c_mem)
MCFG_HD61700_CONFIG(pb2000c_config)
MCFG_HD61700_KB_READ_CB(READ16(pb1000_state, pb2000c_kb_r))
MCFG_HD61700_PORT_READ_CB(READ8(pb1000_state, pb2000c_port_r))
MCFG_GENERIC_CARTSLOT_ADD("cardslot1", generic_plain_slot, "pb2000c_card")
MCFG_GENERIC_CARTSLOT_ADD("cardslot2", generic_plain_slot, "pb2000c_card")