Previous 199869 Revisions Next

r29446 Tuesday 8th April, 2014 at 14:51:44 UTC by Fabio Priuli
(MESS) upd65031_device: updated to use delegates
+ small cleanup of the delegates themselves. nw.
[src/mess/drivers]z88.c
[src/mess/includes]z88.h
[src/mess/machine]upd65031.c upd65031.h
[src/mess/video]z88.c

trunk/src/mess/machine/upd65031.c
r29445r29446
204204
205205
206206//-------------------------------------------------
207//  device_config_complete - perform any
208//  operations now that the configuration is
209//  complete
210//-------------------------------------------------
211
212void upd65031_device::device_config_complete()
213{
214   // inherit a copy of the static data
215   const upd65031_interface *intf = reinterpret_cast<const upd65031_interface *>(static_config());
216   if (intf != NULL)
217   {
218      *static_cast<upd65031_interface *>(this) = *intf;
219   }
220   // or initialize to defaults if none provided
221   else
222   {
223      m_screen_update_cb = NULL;
224      m_out_mem_cb = NULL;
225   }
226}
227
228
229//-------------------------------------------------
230207//  device_start - device-specific startup
231208//-------------------------------------------------
232209
r29445r29446
238215   m_write_nmi.resolve_safe();
239216   m_write_spkr.resolve_safe();
240217
218   // bind delegates
219   m_screen_update_cb.bind_relative_to(*owner());
220   m_out_mem_cb.bind_relative_to(*owner());
221
241222   // allocate timers
242223   m_rtc_timer = timer_alloc(TIMER_RTC);
243224   m_flash_timer = timer_alloc(TIMER_FLASH);
r29445r29446
282263   m_mode = 0;
283264   set_mode(STATE_AWAKE);
284265
285   if (m_out_mem_cb)
266   if (!m_out_mem_cb.isnull())
286267   {
287268      // reset bankswitch
288      (m_out_mem_cb)(*this, 0, 0, 0);
289      (m_out_mem_cb)(*this, 1, 0, 0);
290      (m_out_mem_cb)(*this, 2, 0, 0);
291      (m_out_mem_cb)(*this, 3, 0, 0);
269      m_out_mem_cb(0, 0, 0);
270      m_out_mem_cb(1, 0, 0);
271      m_out_mem_cb(2, 0, 0);
272      m_out_mem_cb(3, 0, 0);
292273   }
293274}
294275
r29445r29446
405386
406387UINT32 upd65031_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
407388{
408   if (m_screen_update_cb && (m_com & COM_LCDON))
409      (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);
389   if (!m_screen_update_cb.isnull() && (m_com & COM_LCDON))
390      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);
410391   else
411392      bitmap.fill(0, cliprect);
412393
r29445r29446
528509         }
529510
530511         // bit 2 controls the lower 8kb of memory
531         if (BIT(m_com^data, 2) && m_out_mem_cb)
532            (m_out_mem_cb)(*this, 0, m_sr[0], BIT(data, 2));
512         if (BIT(m_com^data, 2) && !m_out_mem_cb.isnull())
513            m_out_mem_cb(0, m_sr[0], BIT(data, 2));
533514
534515         m_com = data;
535516         break;
r29445r29446
582563      case REG_SR1:
583564      case REG_SR2:
584565      case REG_SR3:
585         if (m_out_mem_cb && m_sr[port & 3] != data)
586            (m_out_mem_cb)(*this, port & 3, data, BIT(m_com, 2));
566         if (!m_out_mem_cb.isnull() && m_sr[port & 3] != data)
567            m_out_mem_cb(port & 3, data, BIT(m_com, 2));
587568
588569         m_sr[port & 3] = data;
589570         break;
trunk/src/mess/machine/upd65031.h
r29445r29446
1717//  INTERFACE CONFIGURATION MACROS
1818//**************************************************************************
1919
20#define MCFG_UPD65031_ADD(_tag, _clock, _config) \
21   MCFG_DEVICE_ADD((_tag), UPD65031, _clock)   \
22   MCFG_DEVICE_CONFIG(_config)
23
24#define UPD65031_INTERFACE(name) \
25   const upd65031_interface (name) =
26
2720#define MCFG_UPD65031_KB_CALLBACK(_read) \
2821   devcb = &upd65031_device::set_kb_rd_callback(*device, DEVCB2_##_read);
2922
r29445r29446
3629#define MCFG_UPD65031_SPKR_CALLBACK(_write) \
3730   devcb = &upd65031_device::set_spkr_wr_callback(*device, DEVCB2_##_write);
3831
32#define MCFG_UPD65031_SCR_UPDATE_CB(_class, _method) \
33   upd65031_device::set_screen_update_callback(*device, upd65031_screen_update_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
3934
35#define MCFG_UPD65031_MEM_UPDATE_CB(_class, _method) \
36   upd65031_device::set_memory_update_callback(*device, upd65031_memory_update_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
37
38
4039//**************************************************************************
4140//  TYPE DEFINITIONS
4241//**************************************************************************
4342
44typedef void (*upd65031_screen_update_func)(device_t &device, bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash);
45#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)
43typedef device_delegate<void (bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash)> upd65031_screen_update_delegate;
44typedef device_delegate<void (int bank, UINT16 page, int rams)> upd65031_memory_update_delegate;
4645
47typedef void (*upd65031_memory_update_func)(device_t &device, int bank, UINT16 page, int rams);
48#define UPD65031_MEMORY_UPDATE(name) void name(device_t &device, int bank, UINT16 page, int rams)
46#define UPD65031_SCREEN_UPDATE(_name) void _name(bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash)
47#define UPD65031_MEMORY_UPDATE(_name) void _name(int bank, UINT16 page, int rams)
4948
5049
51// ======================> upd65031_interface
52
53struct upd65031_interface
54{
55   upd65031_screen_update_func m_screen_update_cb;  // callback for update the LCD
56   upd65031_memory_update_func m_out_mem_cb;        // callback for update bankswitch
57};
58
59
6050// ======================> upd65031_device
6151
62class upd65031_device : public device_t,
63                  public upd65031_interface
52class upd65031_device : public device_t
6453{
6554public:
6655   // construction/destruction
r29445r29446
7160   template<class _Object> static devcb2_base &set_nmi_wr_callback(device_t &device, _Object object) { return downcast<upd65031_device &>(device).m_write_nmi.set_callback(object); }
7261   template<class _Object> static devcb2_base &set_spkr_wr_callback(device_t &device, _Object object) { return downcast<upd65031_device &>(device).m_write_spkr.set_callback(object); }
7362
63   static void set_screen_update_callback(device_t &device, upd65031_screen_update_delegate callback) { downcast<upd65031_device &>(device).m_screen_update_cb = callback; }
64   static void set_memory_update_callback(device_t &device, upd65031_memory_update_delegate callback) { downcast<upd65031_device &>(device).m_out_mem_cb = callback; }
65
7466   DECLARE_READ8_MEMBER( read );
7567   DECLARE_WRITE8_MEMBER( write );
7668   DECLARE_WRITE_LINE_MEMBER( flp_w );
r29445r29446
7971
8072protected:
8173   // device-level overrides
82   virtual void device_config_complete();
8374   virtual void device_start();
8475   virtual void device_reset();
8576   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
r29445r29446
9788   devcb2_write_line   m_write_nmi;
9889   devcb2_write_line   m_write_spkr;
9990
91   upd65031_screen_update_delegate m_screen_update_cb;  // callback for update the LCD
92   upd65031_memory_update_delegate m_out_mem_cb;        // callback for update bankswitch
93
10094   int     m_mode;
10195   UINT16  m_lcd_regs[5];      // LCD registers
10296   UINT8   m_tim[5];           // RTC registers
trunk/src/mess/includes/z88.h
r29445r29446
5858
5959   virtual void machine_start();
6060   virtual void machine_reset();
61   void bankswitch_update(int bank, UINT16 page, int rams);
6261   DECLARE_READ8_MEMBER(kb_r);
62   UPD65031_MEMORY_UPDATE(bankswitch_update);
63   UPD65031_SCREEN_UPDATE(lcd_update);
6364
6465   // cartridges read/write
6566   DECLARE_READ8_MEMBER(bank0_cart_r);
r29445r29446
7778   void vh_render_8x8(bitmap_ind16 &bitmap, int x, int y, UINT16 pen0, UINT16 pen1, UINT8 *gfx);
7879   void vh_render_6x8(bitmap_ind16 &bitmap, int x, int y, UINT16 pen0, UINT16 pen1, UINT8 *gfx);
7980   void vh_render_line(bitmap_ind16 &bitmap, int x, int y, UINT16 pen);
80   void lcd_update(bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash);
8181
8282   struct
8383   {
trunk/src/mess/video/z88.c
r29445r29446
7272      plot_pixel(bitmap, x + i, y + 7, pen);
7373}
7474
75void z88_state::lcd_update(bitmap_ind16 &bitmap, UINT16 sbf, UINT16 hires0, UINT16 hires1, UINT16 lores0, UINT16 lores1, int flash)
75UPD65031_SCREEN_UPDATE(z88_state::lcd_update)
7676{
7777   if (sbf == 0)
7878   {
trunk/src/mess/drivers/z88.c
r29445r29446
5656WRITE8_MEMBER(z88_state::bank3_cart_w) { m_carts[m_bank[3].slot]->write(space, (m_bank[3].page<<14) + offset, data); }
5757
5858
59void z88_state::bankswitch_update(int bank, UINT16 page, int rams)
59UPD65031_MEMORY_UPDATE(z88_state::bankswitch_update)
6060{
6161   char bank_tag[6];
6262   sprintf(bank_tag, "bank%d", bank + 2);
r29445r29446
605605   return data;
606606}
607607
608static UPD65031_MEMORY_UPDATE(z88_bankswitch_update)
609{
610   z88_state *state = device.machine().driver_data<z88_state>();
611   state->bankswitch_update(bank, page, rams);
612}
613
614static UPD65031_SCREEN_UPDATE(z88_screen_update)
615{
616   z88_state *state = device.machine().driver_data<z88_state>();
617   state->lcd_update(bitmap, sbf, hires0, hires1, lores0, lores1, flash);
618}
619
620static UPD65031_INTERFACE( z88_blink_intf )
621{
622   z88_screen_update,                                      // callback for update the LCD
623   z88_bankswitch_update,                                  // callback for update the bankswitch
624};
625
626608static const z88cart_interface z88_cart_interface =
627609{
628610   DEVCB_DEVICE_LINE_MEMBER("blink", upd65031_device, flp_w)
r29445r29446
659641
660642   MCFG_DEFAULT_LAYOUT(layout_lcd)
661643
662   MCFG_UPD65031_ADD("blink", XTAL_9_8304MHz, z88_blink_intf)
644   MCFG_DEVICE_ADD("blink", UPD65031, XTAL_9_8304MHz)
663645   MCFG_UPD65031_KB_CALLBACK(READ8(z88_state, kb_r))
664646   MCFG_UPD65031_INT_CALLBACK(INPUTLINE("maincpu", INPUT_LINE_IRQ0))
665647   MCFG_UPD65031_NMI_CALLBACK(INPUTLINE("maincpu", INPUT_LINE_NMI))
666648   MCFG_UPD65031_SPKR_CALLBACK(DEVWRITELINE("speaker", speaker_sound_device, level_w))
649   MCFG_UPD65031_SCR_UPDATE_CB(z88_state, lcd_update)
650   MCFG_UPD65031_MEM_UPDATE_CB(z88_state, bankswitch_update)
667651
668652   /* sound hardware */
669653   MCFG_SPEAKER_STANDARD_MONO("mono")

Previous 199869 Revisions Next


© 1997-2024 The MAME Team