Previous 199869 Revisions Next

r29629 Monday 14th April, 2014 at 07:13:04 UTC by Fabio Priuli
adc12138: updated to use delegates and slightly reduced tagmap lookups in
hornet and nwk-tr while at it. nw.
[src/emu/machine]adc1213x.c adc1213x.h
[src/mame/drivers]hornet.c nwk-tr.c

trunk/src/emu/machine/adc1213x.c
r29628r29629
5959{
6060}
6161
62
6362//-------------------------------------------------
64//  device_config_complete - perform any
65//  operations now that the configuration is
66//  complete
67//-------------------------------------------------
68
69void adc12138_device::device_config_complete()
70{
71   // inherit a copy of the static data
72   const adc12138_interface *intf = reinterpret_cast<const adc12138_interface *>(static_config());
73   if (intf != NULL)
74      *static_cast<adc12138_interface *>(this) = *intf;
75
76   // or initialize to defaults if none provided
77   else
78   {
79      input_callback_r = NULL;
80   }
81}
82
83//-------------------------------------------------
8463//  device_start - device-specific startup
8564//-------------------------------------------------
8665
r29628r29629
9675   m_end_conv = 0;
9776
9877   /* resolve callbacks */
99   m_input_callback_r_func = input_callback_r;
78   m_ipt_read_cb.bind_relative_to(*owner());
10079
10180   /* register for state saving */
10281   save_item(NAME(m_cycle));
r29628r29629
144123
145124void adc12138_device::convert(int channel, int bits16, int lsbfirst)
146125{
147   int i;
148126   int bits;
149127   int input_value;
150128   double input = 0;
r29628r29629
159137   {
160138      case 0x8:       // H L L L - CH0 (single-ended)
161139      {
162         input = m_input_callback_r_func(this, 0);
140         input = m_ipt_read_cb(0);
163141         break;
164142      }
165143      case 0xc:       // H H L L - CH1 (single-ended)
166144      {
167         input = m_input_callback_r_func(this, 1);
145         input = m_ipt_read_cb(1);
168146         break;
169147      }
170148      case 0x9:       // H L L H - CH2 (single-ended)
171149      {
172         input = m_input_callback_r_func(this, 2);
150         input = m_ipt_read_cb(2);
173151         break;
174152      }
175153      case 0xd:       // H H L H - CH3 (single-ended)
176154      {
177         input = m_input_callback_r_func(this, 3);
155         input = m_ipt_read_cb(3);
178156         break;
179157      }
180158      case 0xa:       // H L H L - CH4 (single-ended)
181159      {
182         input = m_input_callback_r_func(this, 4);
160         input = m_ipt_read_cb(4);
183161         break;
184162      }
185163      case 0xe:       // H H H L - CH5 (single-ended)
186164      {
187         input = m_input_callback_r_func(this, 5);
165         input = m_ipt_read_cb(5);
188166         break;
189167      }
190168      case 0xb:       // H L H H - CH6 (single-ended)
191169      {
192         input = m_input_callback_r_func(this, 6);
170         input = m_ipt_read_cb(6);
193171         break;
194172      }
195173      case 0xf:       // H H H H - CH7 (single-ended)
196174      {
197         input = m_input_callback_r_func(this, 7);
175         input = m_ipt_read_cb(7);
198176         break;
199177      }
200178      default:
r29628r29629
216194
217195   m_output_shift_reg = 0;
218196
219   for (i=0; i < bits; i++)
197   for (int i = 0; i < bits; i++)
220198   {
221      if (input_value & (1 << ((bits-1) - i)))
199      if (input_value & (1 << ((bits - 1) - i)))
222200      {
223201         m_output_shift_reg |= (1 << i);
224202      }
trunk/src/emu/machine/adc1213x.h
r29628r29629
1515    TYPE DEFINITIONS
1616***************************************************************************/
1717
18typedef double (*adc1213x_input_convert_func)(device_t *device, UINT8 input);
18typedef device_delegate<double (UINT8 input)> adc1213x_ipt_convert_delegate;
19#define ADC12138_IPT_CONVERT_CB(name)  double name(UINT8 input)
1920
20struct adc12138_interface
21{
22   adc1213x_input_convert_func input_callback_r;
23};
24
2521/***************************************************************************
2622    MACROS / CONSTANTS
2723***************************************************************************/
2824
29class adc12138_device : public device_t,
30                              public adc12138_interface
25class adc12138_device : public device_t
3126{
3227public:
3328   adc12138_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
3429   adc12138_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
3530   ~adc12138_device() {}
3631
32   static void set_ipt_convert_callback(device_t &device, adc1213x_ipt_convert_delegate callback) { downcast<adc12138_device &>(device).m_ipt_read_cb = callback; }
33
3734   DECLARE_WRITE8_MEMBER( di_w );
3835   DECLARE_WRITE8_MEMBER( cs_w );
3936   DECLARE_WRITE8_MEMBER( sclk_w );
r29628r29629
4340
4441protected:
4542   // device-level overrides
46   virtual void device_config_complete();
4743   virtual void device_start();
4844   virtual void device_reset();
4945
5046   void convert(int channel, int bits16, int lsbfirst);
5147
52   adc1213x_input_convert_func m_input_callback_r_func;
48   adc1213x_ipt_convert_delegate m_ipt_read_cb;
5349
54   private:
50private:
5551   // internal state
5652   int m_cycle;
5753   int m_data_out;
r29628r29629
8480
8581extern const device_type ADC12132;
8682
87#define MCFG_ADC12130_ADD(_tag, _config) \
88   MCFG_DEVICE_ADD(_tag, ADC12130, 0) \
89   MCFG_DEVICE_CONFIG(_config)
9083
91#define MCFG_ADC12132_ADD(_tag, _config) \
92   MCFG_DEVICE_ADD(_tag, ADC12132, 0) \
93   MCFG_DEVICE_CONFIG(_config)
84#define MCFG_ADC1213X_IPT_CONVERT_CB(_class, _method) \
85   adc12138_device::set_ipt_convert_callback(*device, adc1213x_ipt_convert_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
9486
95#define MCFG_ADC12138_ADD(_tag, _config) \
96   MCFG_DEVICE_ADD(_tag, ADC12138, 0) \
97   MCFG_DEVICE_CONFIG(_config)
98
99
10087#endif  /* __ADC1213X_H__ */
trunk/src/mame/drivers/nwk-tr.c
r29628r29629
238238      m_k056800(*this, "k056800"),
239239      m_k001604(*this, "k001604"),
240240      m_adc12138(*this, "adc12138"),
241      m_in0(*this, "IN0"),
242      m_in1(*this, "IN1"),
243      m_in2(*this, "IN2"),
244      m_dsw(*this, "DSW"),
245      m_analog1(*this, "ANALOG1"),
246      m_analog2(*this, "ANALOG2"),
247      m_analog3(*this, "ANALOG3"),
248      m_analog4(*this, "ANALOG4"),
249      m_analog5(*this, "ANALOG5"),
241250      m_palette(*this, "palette") { }
242251
243252   // TODO: Needs verification on real hardware
r29628r29629
252261   required_device<k056800_device> m_k056800;
253262   required_device<k001604_device> m_k001604;
254263   required_device<adc12138_device> m_adc12138;
264   required_ioport m_in0, m_in1, m_in2, m_dsw, m_analog1, m_analog2, m_analog3, m_analog4, m_analog5;
255265   required_device<palette_device> m_palette;
256266   emu_timer *m_sound_irq_timer;
257267   int m_fpga_uploaded;
r29628r29629
271281   DECLARE_WRITE16_MEMBER(soundtimer_en_w);
272282   DECLARE_WRITE16_MEMBER(soundtimer_count_w);
273283   DECLARE_WRITE_LINE_MEMBER(voodoo_vblank_0);
284   ADC12138_IPT_CONVERT_CB(adc12138_input_callback);
285
274286   TIMER_CALLBACK_MEMBER(sound_irq);
275287   DECLARE_DRIVER_INIT(nwktr);
276288   virtual void machine_start();
r29628r29629
282294
283295
284296
285
286
287297WRITE32_MEMBER(nwktr_state::paletteram32_w)
288298{
289299   COMBINE_DATA(&m_generic_paletteram_32[offset]);
r29628r29629
324334   {
325335      if (ACCESSING_BITS_24_31)
326336      {
327         r |= ioport("IN0")->read() << 24;
337         r |= m_in0->read() << 24;
328338      }
329339      if (ACCESSING_BITS_16_23)
330340      {
331         r |= ioport("IN1")->read() << 16;
341         r |= m_in1->read() << 16;
332342      }
333343      if (ACCESSING_BITS_8_15)
334344      {
335         r |= ioport("IN2")->read() << 8;
345         r |= m_in2->read() << 8;
336346      }
337347      if (ACCESSING_BITS_0_7)
338348      {
r29628r29629
343353   {
344354      if (ACCESSING_BITS_24_31)
345355      {
346         r |= ioport("DSW")->read() << 24;
356         r |= m_dsw->read() << 24;
347357      }
348358   }
349359   return r;
r29628r29629
689699INPUT_PORTS_END
690700
691701
692static double adc12138_input_callback( device_t *device, UINT8 input )
702ADC12138_IPT_CONVERT_CB(nwktr_state::adc12138_input_callback)
693703{
694704   int value = 0;
695705   switch (input)
696706   {
697      case 0:     value = device->machine().root_device().ioport("ANALOG1")->read(); break;
698      case 1:     value = device->machine().root_device().ioport("ANALOG2")->read(); break;
699      case 2:     value = device->machine().root_device().ioport("ANALOG3")->read(); break;
700      case 3:     value = device->machine().root_device().ioport("ANALOG4")->read(); break;
701      case 4:     value = device->machine().root_device().ioport("ANALOG5")->read(); break;
707      case 0: value = m_analog1->read(); break;
708      case 1: value = m_analog2->read(); break;
709      case 2: value = m_analog3->read(); break;
710      case 3: value = m_analog4->read(); break;
711      case 4: value = m_analog5->read(); break;
702712   }
703713
704714   return (double)(value) / 4095.0;
705715}
706716
707static const adc12138_interface nwktr_adc_interface = {
708   adc12138_input_callback
709};
710
711
712717void nwktr_state::machine_reset()
713718{
714719   m_dsp->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
r29628r29629
741746   MCFG_QUANTUM_TIME(attotime::from_hz(9000))
742747
743748   MCFG_M48T58_ADD( "m48t58" )
744   MCFG_ADC12138_ADD( "adc12138", nwktr_adc_interface )
745749
750   MCFG_DEVICE_ADD("adc12138", ADC12138, 0)
751   MCFG_ADC1213X_IPT_CONVERT_CB(nwktr_state, adc12138_input_callback)
752
746753   MCFG_DEVICE_ADD("k033906_1", K033906, 0)
747754   MCFG_K033906_VOODOO("voodoo")
748755
trunk/src/mame/drivers/hornet.c
r29628r29629
341341      m_eeprom(*this, "eeprom"),
342342      m_k037122_1(*this, "k037122_1"),
343343      m_k037122_2(*this, "k037122_2" ),
344      m_adc12138(*this, "adc12138") { }
344      m_adc12138(*this, "adc12138"),
345      m_in0(*this, "IN0"),
346      m_in1(*this, "IN1"),
347      m_in2(*this, "IN2"),
348      m_dsw(*this, "DSW"),
349      m_eepromout(*this, "EEPROMOUT"),
350      m_analog1(*this, "ANALOG1"),
351      m_analog2(*this, "ANALOG2"){ }
345352
346353   // TODO: Needs verification on real hardware
347354   static const int m_sound_timer_usec = 2800;
r29628r29629
359366   optional_device<k037122_device> m_k037122_1;
360367   optional_device<k037122_device> m_k037122_2;
361368   required_device<adc12138_device> m_adc12138;
369   required_ioport m_in0, m_in1, m_in2, m_dsw, m_eepromout;
370   optional_ioport m_analog1, m_analog2;
362371
363372   emu_timer *m_sound_irq_timer;
364373   UINT8 m_led_reg0;
r29628r29629
393402   DECLARE_WRITE_LINE_MEMBER(voodoo_vblank_1);
394403   DECLARE_WRITE16_MEMBER(soundtimer_en_w);
395404   DECLARE_WRITE16_MEMBER(soundtimer_count_w);
405   ADC12138_IPT_CONVERT_CB(adc12138_input_callback);
396406
397407   DECLARE_DRIVER_INIT(hornet);
398408   DECLARE_DRIVER_INIT(hornet_2board);
r29628r29629
498508READ8_MEMBER(hornet_state::sysreg_r)
499509{
500510   UINT8 r = 0;
501   static const char *const portnames[] = { "IN0", "IN1", "IN2" };
511
502512   switch (offset)
503513   {
504514      case 0: /* I/O port 0 */
515         r = m_in0->read();
516         break;
505517      case 1: /* I/O port 1 */
518         r = m_in1->read();
519         break;
506520      case 2: /* I/O port 2 */
507         r = ioport(portnames[offset])->read();
521         r = m_in2->read();
508522         break;
509523
510524      case 3: /* I/O port 3 */
r29628r29629
522536         break;
523537
524538      case 4: /* I/O port 4 - DIP switches */
525         r = ioport("DSW")->read();
539         r = m_dsw->read();
526540         break;
527541   }
528542   return r;
r29628r29629
555569             0x02 = LAMP1
556570             0x01 = LAMP0
557571         */
558         ioport("EEPROMOUT")->write(data, 0xff);
572         m_eepromout->write(data, 0xff);
559573         mame_printf_debug("System register 0 = %02X\n", data);
560574         break;
561575
r29628r29629
932946      membank("bank5")->set_base(usr5);
933947}
934948
935static double adc12138_input_callback( device_t *device, UINT8 input )
949ADC12138_IPT_CONVERT_CB(hornet_state::adc12138_input_callback)
936950{
937951   int value = 0;
938952   switch (input)
939953   {
940      case 0: value = device->machine().root_device().ioport("ANALOG1")->read(); break;
941      case 1: value = device->machine().root_device().ioport("ANALOG2")->read(); break;
954      case 0: value = (m_analog1) ? m_analog1->read() : 0; break;
955      case 1: value = (m_analog2) ? m_analog2->read() : 0; break;
942956   }
943957
944958   return (double)(value) / 2047.0;
945959}
946960
947static const adc12138_interface hornet_adc_interface = {
948   adc12138_input_callback
949};
950
951961static const voodoo_config hornet_voodoo_intf =
952962{
953963   2, //               fbmem;
r29628r29629
10091019
10101020   MCFG_M48T58_ADD( "m48t58" )
10111021
1012   MCFG_ADC12138_ADD( "adc12138", hornet_adc_interface )
1022   MCFG_DEVICE_ADD("adc12138", ADC12138, 0)
1023   MCFG_ADC1213X_IPT_CONVERT_CB(hornet_state, adc12138_input_callback)
10131024MACHINE_CONFIG_END
10141025
10151026

Previous 199869 Revisions Next


© 1997-2024 The MAME Team