diff --git a/src/mess/drivers/z88.c b/src/mess/drivers/z88.c index 6b1afe8640e..197f9768591 100644 --- a/src/mess/drivers/z88.c +++ b/src/mess/drivers/z88.c @@ -56,7 +56,7 @@ WRITE8_MEMBER(z88_state::bank2_cart_w) { m_carts[m_bank[2].slot]->write(space, ( WRITE8_MEMBER(z88_state::bank3_cart_w) { m_carts[m_bank[3].slot]->write(space, (m_bank[3].page<<14) + offset, data); } -void z88_state::bankswitch_update(int bank, UINT16 page, int rams) +UPD65031_MEMORY_UPDATE(z88_state::bankswitch_update) { char bank_tag[6]; sprintf(bank_tag, "bank%d", bank + 2); @@ -605,24 +605,6 @@ READ8_MEMBER(z88_state::kb_r) return data; } -static UPD65031_MEMORY_UPDATE(z88_bankswitch_update) -{ - z88_state *state = device.machine().driver_data(); - state->bankswitch_update(bank, page, rams); -} - -static UPD65031_SCREEN_UPDATE(z88_screen_update) -{ - z88_state *state = device.machine().driver_data(); - state->lcd_update(bitmap, sbf, hires0, hires1, lores0, lores1, flash); -} - -static UPD65031_INTERFACE( z88_blink_intf ) -{ - z88_screen_update, // callback for update the LCD - z88_bankswitch_update, // callback for update the bankswitch -}; - static const z88cart_interface z88_cart_interface = { DEVCB_DEVICE_LINE_MEMBER("blink", upd65031_device, flp_w) @@ -659,11 +641,13 @@ static MACHINE_CONFIG_START( z88, z88_state ) MCFG_DEFAULT_LAYOUT(layout_lcd) - MCFG_UPD65031_ADD("blink", XTAL_9_8304MHz, z88_blink_intf) + MCFG_DEVICE_ADD("blink", UPD65031, XTAL_9_8304MHz) MCFG_UPD65031_KB_CALLBACK(READ8(z88_state, kb_r)) MCFG_UPD65031_INT_CALLBACK(INPUTLINE("maincpu", INPUT_LINE_IRQ0)) MCFG_UPD65031_NMI_CALLBACK(INPUTLINE("maincpu", INPUT_LINE_NMI)) MCFG_UPD65031_SPKR_CALLBACK(DEVWRITELINE("speaker", speaker_sound_device, level_w)) + MCFG_UPD65031_SCR_UPDATE_CB(z88_state, lcd_update) + MCFG_UPD65031_MEM_UPDATE_CB(z88_state, bankswitch_update) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") diff --git a/src/mess/includes/z88.h b/src/mess/includes/z88.h index a4f266cbdc1..edc6f9a737d 100644 --- a/src/mess/includes/z88.h +++ b/src/mess/includes/z88.h @@ -58,8 +58,9 @@ public: virtual void machine_start(); virtual void machine_reset(); - void bankswitch_update(int bank, UINT16 page, int rams); DECLARE_READ8_MEMBER(kb_r); + UPD65031_MEMORY_UPDATE(bankswitch_update); + UPD65031_SCREEN_UPDATE(lcd_update); // cartridges read/write DECLARE_READ8_MEMBER(bank0_cart_r); @@ -77,7 +78,6 @@ public: void vh_render_8x8(bitmap_ind16 &bitmap, int x, int y, UINT16 pen0, UINT16 pen1, UINT8 *gfx); void vh_render_6x8(bitmap_ind16 &bitmap, int x, int y, UINT16 pen0, UINT16 pen1, UINT8 *gfx); void vh_render_line(bitmap_ind16 &bitmap, int x, int y, UINT16 pen); - void lcd_update(bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash); struct { diff --git a/src/mess/machine/upd65031.c b/src/mess/machine/upd65031.c index 983fd70aeaa..94b1430b178 100644 --- a/src/mess/machine/upd65031.c +++ b/src/mess/machine/upd65031.c @@ -203,29 +203,6 @@ upd65031_device::upd65031_device(const machine_config &mconfig, const char *tag, } -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void upd65031_device::device_config_complete() -{ - // inherit a copy of the static data - const upd65031_interface *intf = reinterpret_cast(static_config()); - if (intf != NULL) - { - *static_cast(this) = *intf; - } - // or initialize to defaults if none provided - else - { - m_screen_update_cb = NULL; - m_out_mem_cb = NULL; - } -} - - //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- @@ -238,6 +215,10 @@ void upd65031_device::device_start() m_write_nmi.resolve_safe(); m_write_spkr.resolve_safe(); + // bind delegates + m_screen_update_cb.bind_relative_to(*owner()); + m_out_mem_cb.bind_relative_to(*owner()); + // allocate timers m_rtc_timer = timer_alloc(TIMER_RTC); m_flash_timer = timer_alloc(TIMER_FLASH); @@ -282,13 +263,13 @@ void upd65031_device::device_reset() m_mode = 0; set_mode(STATE_AWAKE); - if (m_out_mem_cb) + if (!m_out_mem_cb.isnull()) { // reset bankswitch - (m_out_mem_cb)(*this, 0, 0, 0); - (m_out_mem_cb)(*this, 1, 0, 0); - (m_out_mem_cb)(*this, 2, 0, 0); - (m_out_mem_cb)(*this, 3, 0, 0); + m_out_mem_cb(0, 0, 0); + m_out_mem_cb(1, 0, 0); + m_out_mem_cb(2, 0, 0); + m_out_mem_cb(3, 0, 0); } } @@ -405,8 +386,8 @@ void upd65031_device::device_timer(emu_timer &timer, device_timer_id id, int par UINT32 upd65031_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { - if (m_screen_update_cb && (m_com & COM_LCDON)) - (m_screen_update_cb)(*this, bitmap, m_lcd_regs[4], m_lcd_regs[2], m_lcd_regs[3], m_lcd_regs[0], m_lcd_regs[1], m_flash); + if (!m_screen_update_cb.isnull() && (m_com & COM_LCDON)) + m_screen_update_cb(bitmap, m_lcd_regs[4], m_lcd_regs[2], m_lcd_regs[3], m_lcd_regs[0], m_lcd_regs[1], m_flash); else bitmap.fill(0, cliprect); @@ -528,8 +509,8 @@ WRITE8_MEMBER( upd65031_device::write ) } // bit 2 controls the lower 8kb of memory - if (BIT(m_com^data, 2) && m_out_mem_cb) - (m_out_mem_cb)(*this, 0, m_sr[0], BIT(data, 2)); + if (BIT(m_com^data, 2) && !m_out_mem_cb.isnull()) + m_out_mem_cb(0, m_sr[0], BIT(data, 2)); m_com = data; break; @@ -582,8 +563,8 @@ WRITE8_MEMBER( upd65031_device::write ) case REG_SR1: case REG_SR2: case REG_SR3: - if (m_out_mem_cb && m_sr[port & 3] != data) - (m_out_mem_cb)(*this, port & 3, data, BIT(m_com, 2)); + if (!m_out_mem_cb.isnull() && m_sr[port & 3] != data) + m_out_mem_cb(port & 3, data, BIT(m_com, 2)); m_sr[port & 3] = data; break; diff --git a/src/mess/machine/upd65031.h b/src/mess/machine/upd65031.h index 70401c06485..2f96a075c5f 100644 --- a/src/mess/machine/upd65031.h +++ b/src/mess/machine/upd65031.h @@ -17,13 +17,6 @@ // INTERFACE CONFIGURATION MACROS //************************************************************************** -#define MCFG_UPD65031_ADD(_tag, _clock, _config) \ - MCFG_DEVICE_ADD((_tag), UPD65031, _clock) \ - MCFG_DEVICE_CONFIG(_config) - -#define UPD65031_INTERFACE(name) \ - const upd65031_interface (name) = - #define MCFG_UPD65031_KB_CALLBACK(_read) \ devcb = &upd65031_device::set_kb_rd_callback(*device, DEVCB2_##_read); @@ -36,31 +29,27 @@ #define MCFG_UPD65031_SPKR_CALLBACK(_write) \ devcb = &upd65031_device::set_spkr_wr_callback(*device, DEVCB2_##_write); +#define MCFG_UPD65031_SCR_UPDATE_CB(_class, _method) \ + upd65031_device::set_screen_update_callback(*device, upd65031_screen_update_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner))); + +#define MCFG_UPD65031_MEM_UPDATE_CB(_class, _method) \ + upd65031_device::set_memory_update_callback(*device, upd65031_memory_update_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner))); + //************************************************************************** // TYPE DEFINITIONS //************************************************************************** -typedef void (*upd65031_screen_update_func)(device_t &device, bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash); -#define UPD65031_SCREEN_UPDATE(name) void name(device_t &device, bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash) +typedef device_delegate upd65031_screen_update_delegate; +typedef device_delegate upd65031_memory_update_delegate; -typedef void (*upd65031_memory_update_func)(device_t &device, int bank, UINT16 page, int rams); -#define UPD65031_MEMORY_UPDATE(name) void name(device_t &device, int bank, UINT16 page, int rams) - - -// ======================> upd65031_interface - -struct upd65031_interface -{ - upd65031_screen_update_func m_screen_update_cb; // callback for update the LCD - upd65031_memory_update_func m_out_mem_cb; // callback for update bankswitch -}; +#define UPD65031_SCREEN_UPDATE(_name) void _name(bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash) +#define UPD65031_MEMORY_UPDATE(_name) void _name(int bank, UINT16 page, int rams) // ======================> upd65031_device -class upd65031_device : public device_t, - public upd65031_interface +class upd65031_device : public device_t { public: // construction/destruction @@ -71,6 +60,9 @@ public: template static devcb2_base &set_nmi_wr_callback(device_t &device, _Object object) { return downcast(device).m_write_nmi.set_callback(object); } template static devcb2_base &set_spkr_wr_callback(device_t &device, _Object object) { return downcast(device).m_write_spkr.set_callback(object); } + static void set_screen_update_callback(device_t &device, upd65031_screen_update_delegate callback) { downcast(device).m_screen_update_cb = callback; } + static void set_memory_update_callback(device_t &device, upd65031_memory_update_delegate callback) { downcast(device).m_out_mem_cb = callback; } + DECLARE_READ8_MEMBER( read ); DECLARE_WRITE8_MEMBER( write ); DECLARE_WRITE_LINE_MEMBER( flp_w ); @@ -79,7 +71,6 @@ public: protected: // device-level overrides - virtual void device_config_complete(); virtual void device_start(); virtual void device_reset(); virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); @@ -97,6 +88,9 @@ private: devcb2_write_line m_write_nmi; devcb2_write_line m_write_spkr; + upd65031_screen_update_delegate m_screen_update_cb; // callback for update the LCD + upd65031_memory_update_delegate m_out_mem_cb; // callback for update bankswitch + int m_mode; UINT16 m_lcd_regs[5]; // LCD registers UINT8 m_tim[5]; // RTC registers diff --git a/src/mess/video/z88.c b/src/mess/video/z88.c index 70c75122596..cb5ddb455d8 100644 --- a/src/mess/video/z88.c +++ b/src/mess/video/z88.c @@ -72,7 +72,7 @@ void z88_state::vh_render_line(bitmap_ind16 &bitmap, int x, int y, UINT16 pen) plot_pixel(bitmap, x + i, y + 7, pen); } -void z88_state::lcd_update(bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash) +UPD65031_SCREEN_UPDATE(z88_state::lcd_update) { if (sbf == 0) {