Previous 199869 Revisions Next

r29602 Sunday 13th April, 2014 at 13:14:08 UTC by Fabio Priuli
updated upd7002 to use delegates. nw.
[src/emu/machine]upd7002.c upd7002.h
[src/mess/drivers]bbc.c
[src/mess/includes]bbc.h
[src/mess/machine]bbc.c

trunk/src/mess/drivers/bbc.c
r29601r29602
764764   MCFG_VIA6522_IRQ_HANDLER(WRITELINE(bbc_state, bbcb_via_user_irq_w))
765765
766766   /* adc */
767   MCFG_UPD7002_ADD("upd7002", bbc_uPD7002)
767   MCFG_DEVICE_ADD("upd7002", UPD7002, 0)
768   MCFG_UPD7002_GET_ANALOGUE_CB(bbc_state, BBC_get_analogue_input)
769   MCFG_UPD7002_EOC_CB(bbc_state, BBC_uPD7002_EOC)
768770
769771   /* printer */
770772   MCFG_CENTRONICS_ADD("centronics", centronics_printers, "image")
r29601r29602
821823   MCFG_VIA6522_IRQ_HANDLER(WRITELINE(bbc_state, bbcb_via_user_irq_w))
822824
823825   /* adc */
824   MCFG_UPD7002_ADD("upd7002", bbc_uPD7002)
826   MCFG_DEVICE_ADD("upd7002", UPD7002, 0)
827   MCFG_UPD7002_GET_ANALOGUE_CB(bbc_state, BBC_get_analogue_input)
828   MCFG_UPD7002_EOC_CB(bbc_state, BBC_uPD7002_EOC)
825829
826830   /* printer */
827831   MCFG_CENTRONICS_ADD("centronics", centronics_printers, "image")
r29601r29602
965969   MCFG_CLOCK_SIGNAL_HANDLER(WRITELINE(bbc_state, write_acia_clock))
966970
967971   /* adc */
968   MCFG_UPD7002_ADD("upd7002", bbc_uPD7002)
972   MCFG_DEVICE_ADD("upd7002", UPD7002, 0)
973   MCFG_UPD7002_GET_ANALOGUE_CB(bbc_state, BBC_get_analogue_input)
974   MCFG_UPD7002_EOC_CB(bbc_state, BBC_uPD7002_EOC)
969975
970976   /* system via */
971977   MCFG_DEVICE_ADD("via6522_0", VIA6522, 1000000)
trunk/src/mess/machine/bbc.c
r29601r29602
11531153BBC Joystick Support
11541154**************************************/
11551155
1156static UPD7002_GET_ANALOGUE(BBC_get_analogue_input)
1156UPD7002_GET_ANALOGUE(bbc_state::BBC_get_analogue_input)
11571157{
1158   switch(channel_number)
1158   switch (channel_number)
11591159   {
11601160      case 0:
1161         return ((0xff-device->machine().root_device().ioport("JOY0")->read())<<8);
1161         return ((0xff - m_joy0->read()) << 8);
11621162      case 1:
1163         return ((0xff-device->machine().root_device().ioport("JOY1")->read())<<8);
1163         return ((0xff - m_joy1->read()) << 8);
11641164      case 2:
1165         return ((0xff-device->machine().root_device().ioport("JOY2")->read())<<8);
1165         return ((0xff - m_joy2->read()) << 8);
11661166      case 3:
1167         return ((0xff-device->machine().root_device().ioport("JOY3")->read())<<8);
1167         return ((0xff - m_joy3->read()) << 8);
11681168   }
11691169
11701170   return 0;
11711171}
11721172
1173static UPD7002_EOC(BBC_uPD7002_EOC)
1173UPD7002_EOC(bbc_state::BBC_uPD7002_EOC)
11741174{
1175   via6522_device *via_0 = device->machine().device<via6522_device>("via6522_0");
1176   via_0->write_cb1(data);
1175   m_via6522_0->write_cb1(data);
11771176}
11781177
1179const upd7002_interface bbc_uPD7002 =
1180{
1181   BBC_get_analogue_input,
1182   BBC_uPD7002_EOC
1183};
1184
1185
11861178/***************************************
11871179  BBC 2C199 Serial Interface Cassette
11881180****************************************/
trunk/src/mess/includes/bbc.h
r29601r29602
4848      m_via6522_1(*this, "via6522_1"),
4949      m_upd7002(*this, "upd7002"),
5050      m_i8271(*this, "i8271"),
51      m_joy0(*this, "JOY0"),
52      m_joy1(*this, "JOY1"),
53      m_joy2(*this, "JOY2"),
54      m_joy3(*this, "JOY3"),
5155      m_region_maincpu(*this, "maincpu"),
5256      m_region_user1(*this, "user1"),
5357      m_region_user2(*this, "user2"),
r29601r29602
152156   DECLARE_WRITE_LINE_MEMBER(write_dcd_serial);
153157   DECLARE_WRITE_LINE_MEMBER(write_cts_serial);
154158   DECLARE_INPUT_CHANGED_MEMBER( trigger_reset );
155
156159   DECLARE_WRITE_LINE_MEMBER(bbc_i8271_interrupt);
157160
161   UPD7002_GET_ANALOGUE(BBC_get_analogue_input);
162   UPD7002_EOC(BBC_uPD7002_EOC);
163
158164   int exp_rom_load(device_image_interface &image, int index);
159165   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( bbc_exp_rom );
160166   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( bbcm_cart );
r29601r29602
176182   optional_device<via6522_device> m_via6522_1;
177183   optional_device<upd7002_device> m_upd7002;
178184   optional_device<i8271_device> m_i8271;
185   required_ioport m_joy0, m_joy1, m_joy2, m_joy3;
179186
180187   required_memory_region m_region_maincpu;
181188   required_memory_region m_region_user1;
r29601r29602
417424extern const i8271_interface bbc_i8271_interface;
418425extern const wd17xx_interface bbc_wd17xx_interface;
419426
420/* tape support */
421
422extern const upd7002_interface bbc_uPD7002;
423
424427#endif /* BBC_H_ */
trunk/src/emu/machine/upd7002.c
r29601r29602
2222}
2323
2424//-------------------------------------------------
25//  device_config_complete - perform any
26//  operations now that the configuration is
27//  complete
28//-------------------------------------------------
29
30void upd7002_device::device_config_complete()
31{
32   // inherit a copy of the static data
33   const upd7002_interface *intf = reinterpret_cast<const upd7002_interface *>(static_config());
34   if (intf != NULL)
35      *static_cast<upd7002_interface *>(this) = *intf;
36
37   // or initialize to defaults if none provided
38   else
39   {
40      get_analogue_func = NULL;
41      eoc_func = NULL;
42   }
43}
44
45//-------------------------------------------------
4625//  device_start - device-specific startup
4726//-------------------------------------------------
4827
4928void upd7002_device::device_start()
5029{
30   m_get_analogue_cb.bind_relative_to(*owner());
31   m_eoc_cb.bind_relative_to(*owner());
32
5133   // register for state saving
5234   save_item(NAME(m_status));
5335   save_item(NAME(m_data1));
r29601r29602
9981
10082         // call the EOC function with EOC from status
10183         // eoc_r(0) this has just been set to 0
102         if (eoc_func) (eoc_func)(this,0);
84         if (!m_eoc_cb.isnull()) m_eoc_cb(0);
10385         m_conversion_counter=0;
10486      }
10587      break;
r29601r29602
153135
154136      // call the EOC function with EOC from status
155137      // eoc_r(0) this has just been set to 1
156      if (eoc_func) eoc_func(this, 1);
138      if (!m_eoc_cb.isnull()) m_eoc_cb(1);
157139
158140      /* the uPD7002 works by sampling the analogue value at the start of the conversion
159141         so it is read hear and stored until the end of the A to D conversion */
160142
161143      // this function should return a 16 bit value.
162      m_digitalvalue = get_analogue_func(this, m_status & 0x03);
144      m_digitalvalue = m_get_analogue_cb(m_status & 0x03);
163145
164146      m_conversion_counter++;
165147
trunk/src/emu/machine/upd7002.h
r29601r29602
1515    TYPE DEFINITIONS
1616***************************************************************************/
1717
18typedef int (*upd7002_get_analogue_func)(device_t *device, int channel_number);
19#define UPD7002_GET_ANALOGUE(name)  int name(device_t *device, int channel_number )
18typedef device_delegate<int (int channel_number)> upd7002_get_analogue_delegate;
19#define UPD7002_GET_ANALOGUE(name)  int name(int channel_number)
2020
21typedef void (*upd7002_eoc_func)(device_t *device, int data);
22#define UPD7002_EOC(name)   void name(device_t *device, int data )
21typedef device_delegate<void (int data)> upd7002_eoc_delegate;
22#define UPD7002_EOC(name)   void name(int data)
2323
2424
25struct upd7002_interface
26{
27   upd7002_get_analogue_func get_analogue_func;
28   upd7002_eoc_func          eoc_func;
29};
30
3125/***************************************************************************
3226    MACROS
3327***************************************************************************/
3428
35class upd7002_device : public device_t,
36                        public upd7002_interface
29class upd7002_device : public device_t
3730{
3831public:
3932   upd7002_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
4033   ~upd7002_device() {}
4134
42   DECLARE_READ8_MEMBER ( eoc_r );
43   DECLARE_READ8_MEMBER ( read );
44   DECLARE_WRITE8_MEMBER ( write );
35   static void set_get_analogue_callback(device_t &device, upd7002_get_analogue_delegate callback) { downcast<upd7002_device &>(device).m_get_analogue_cb = callback; }
36   static void set_eoc_callback(device_t &device, upd7002_eoc_delegate callback) { downcast<upd7002_device &>(device).m_eoc_cb = callback; }
4537
38   DECLARE_READ8_MEMBER(eoc_r);
39   DECLARE_READ8_MEMBER(read);
40   DECLARE_WRITE8_MEMBER(write);
41
4642protected:
4743   // device-level overrides
48   virtual void device_config_complete();
4944   virtual void device_start();
5045   virtual void device_reset();
5146   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
r29601r29602
8479   only then at the end of the second conversion will the conversion complete function run */
8580   int m_conversion_counter;
8681
82   upd7002_get_analogue_delegate m_get_analogue_cb;
83   upd7002_eoc_delegate          m_eoc_cb;
84
8785   enum
8886   {
8987      TIMER_CONVERSION_COMPLETE
r29601r29602
9795    DEVICE CONFIGURATION MACROS
9896***************************************************************************/
9997
100#define MCFG_UPD7002_ADD(_tag, _intrf) \
101   MCFG_DEVICE_ADD(_tag, UPD7002, 0) \
102   MCFG_DEVICE_CONFIG(_intrf)
98#define MCFG_UPD7002_GET_ANALOGUE_CB(_class, _method) \
99   upd7002_device::set_get_analogue_callback(*device, upd7002_get_analogue_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
103100
101#define MCFG_UPD7002_EOC_CB(_class, _method) \
102   upd7002_device::set_eoc_callback(*device, upd7002_eoc_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
104103
105104#endif /* UPD7002_H_ */

Previous 199869 Revisions Next


© 1997-2024 The MAME Team