Previous 199869 Revisions Next

r22799 Sunday 12th May, 2013 at 20:32:48 UTC by smf
modernised the YMF262 [smf]
[src/emu/sound]262intf.c 262intf.h
[src/mame/audio]t5182.h
[src/mame/drivers]fuukifg3.c tecmosys.c
[src/mess/machine]isa_sblaster.c

trunk/src/emu/sound/262intf.c
r22798r22799
1010#include "ymf262.h"
1111
1212
13struct ymf262_state
13/* IRQ Handler */
14static void IRQHandler(void *param,int irq)
1415{
15   sound_stream *  stream;
16   emu_timer *     timer[2];
17   void *          chip;
18   const ymf262_interface *intf;
19   device_t *device;
20   devcb_resolved_write_line irqhandler;
21};
22
23
24INLINE ymf262_state *get_safe_token(device_t *device)
25{
26   assert(device != NULL);
27   assert(device->type() == YMF262);
28   return (ymf262_state *)downcast<ymf262_device *>(device)->token();
16   ymf262_device *ymf262 = (ymf262_device *) param;
17   ymf262->_IRQHandler(irq);
2918}
3019
31
32
33
34static void IRQHandler_262(void *param,int irq)
20void ymf262_device::_IRQHandler(int irq)
3521{
36   ymf262_state *info = (ymf262_state *)param;
37   if (!info->irqhandler.isnull())
38      info->irqhandler(irq);
22   if (!m_irq_handler.isnull())
23      m_irq_handler(irq);
3924}
4025
41static TIMER_CALLBACK( timer_callback_262_0 )
26/* Timer overflow callback from timer.c */
27void ymf262_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
4228{
43   ymf262_state *info = (ymf262_state *)ptr;
44   ymf262_timer_over(info->chip, 0);
29   switch(id)
30   {
31   case 0:
32      ymf262_timer_over(m_chip,0);
33      break;
34
35   case 1:
36      ymf262_timer_over(m_chip,1);
37      break;
38   }
4539}
4640
47static TIMER_CALLBACK( timer_callback_262_1 )
41
42static void timer_handler(void *param, int c, attotime period)
4843{
49   ymf262_state *info = (ymf262_state *)ptr;
50   ymf262_timer_over(info->chip, 1);
44   ymf262_device *ymf262 = (ymf262_device *) param;
45   ymf262->_timer_handler(c, period);
5146}
5247
53static void timer_handler_262(void *param,int timer, attotime period)
48void ymf262_device::_timer_handler(int c, attotime period)
5449{
55   ymf262_state *info = (ymf262_state *)param;
5650   if( period == attotime::zero )
5751   {   /* Reset FM Timer */
58      info->timer[timer]->enable(false);
52      m_timer[c]->enable(false);
5953   }
6054   else
6155   {   /* Start FM Timer */
62      info->timer[timer]->adjust(period);
56      m_timer[c]->adjust(period);
6357   }
6458}
6559
66static STREAM_UPDATE( ymf262_stream_update )
60void ymf262_update_request(void *param, int interval)
6761{
68   ymf262_state *info = (ymf262_state *)param;
69   ymf262_update_one(info->chip, outputs, samples);
62   ymf262_device *ymf262 = (ymf262_device *) param;
63   ymf262->_ymf262_update_request();
7064}
7165
72static void _stream_update(void *param, int interval)
66void ymf262_device::_ymf262_update_request()
7367{
74   ymf262_state *info = (ymf262_state *)param;
75   info->stream->update();
68   m_stream->update();
7669}
7770
7871
79static DEVICE_START( ymf262 )
72
73//-------------------------------------------------
74//  sound_stream_update - handle a stream update
75//-------------------------------------------------
76
77void ymf262_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
8078{
81   static const ymf262_interface dummy = { DEVCB_NULL };
82   ymf262_state *info = get_safe_token(device);
83   int rate = device->clock()/288;
79   ymf262_update_one(m_chip, outputs, samples);
80}
8481
85   info->intf = device->static_config() ? (const ymf262_interface *)device->static_config() : &dummy;
86   info->device = device;
87   info->irqhandler.resolve(info->intf->irqhandler, *device);
82//-------------------------------------------------
83//  device_start - device-specific startup
84//-------------------------------------------------
8885
86void ymf262_device::device_start()
87{
88   int rate = clock()/288;
89
90   m_irq_handler.resolve();
91
8992   /* stream system initialize */
90   info->chip = ymf262_init(device,device->clock(),rate);
91   assert_always(info->chip != NULL, "Error creating YMF262 chip");
93   m_chip = ymf262_init(this,clock(),rate);
94   assert_always(m_chip != NULL, "Error creating YMF262 chip");
9295
93   info->stream = device->machine().sound().stream_alloc(*device,0,4,rate,info,ymf262_stream_update);
96   m_stream = machine().sound().stream_alloc(*this,0,4,rate);
9497
9598   /* YMF262 setup */
96   ymf262_set_timer_handler (info->chip, timer_handler_262, info);
97   ymf262_set_irq_handler   (info->chip, IRQHandler_262, info);
98   ymf262_set_update_handler(info->chip, _stream_update, info);
99   ymf262_set_timer_handler (m_chip, timer_handler, this);
100   ymf262_set_irq_handler   (m_chip, IRQHandler, this);
101   ymf262_set_update_handler(m_chip, ymf262_update_request, this);
99102
100   info->timer[0] = device->machine().scheduler().timer_alloc(FUNC(timer_callback_262_0), info);
101   info->timer[1] = device->machine().scheduler().timer_alloc(FUNC(timer_callback_262_1), info);
103   m_timer[0] = timer_alloc(0);
104   m_timer[1] = timer_alloc(1);
102105}
103106
104static DEVICE_STOP( ymf262 )
107//-------------------------------------------------
108//  device_stop - device-specific stop
109//-------------------------------------------------
110
111void ymf262_device::device_stop()
105112{
106   ymf262_state *info = get_safe_token(device);
107   ymf262_shutdown(info->chip);
113   ymf262_shutdown(m_chip);
108114}
109115
110/* reset */
111static DEVICE_RESET( ymf262 )
116//-------------------------------------------------
117//  device_reset - device-specific reset
118//-------------------------------------------------
119
120void ymf262_device::device_reset()
112121{
113   ymf262_state *info = get_safe_token(device);
114   ymf262_reset_chip(info->chip);
122   ymf262_reset_chip(m_chip);
115123}
116124
117125
118READ8_DEVICE_HANDLER( ymf262_r )
126READ8_MEMBER( ymf262_device::read )
119127{
120   ymf262_state *info = get_safe_token(device);
121   return ymf262_read(info->chip, offset & 3);
128   return ymf262_read(m_chip, offset & 3);
122129}
123130
124WRITE8_DEVICE_HANDLER( ymf262_w )
131WRITE8_MEMBER( ymf262_device::write )
125132{
126   ymf262_state *info = get_safe_token(device);
127   ymf262_write(info->chip, offset & 3, data);
133   ymf262_write(m_chip, offset & 3, data);
128134}
129135
130READ8_DEVICE_HANDLER ( ymf262_status_r ) { return ymf262_r(device, space, 0); }
131WRITE8_DEVICE_HANDLER( ymf262_register_a_w ) { ymf262_w(device, space, 0, data); }
132WRITE8_DEVICE_HANDLER( ymf262_register_b_w ) { ymf262_w(device, space, 2, data); }
133WRITE8_DEVICE_HANDLER( ymf262_data_a_w ) { ymf262_w(device, space, 1, data); }
134WRITE8_DEVICE_HANDLER( ymf262_data_b_w ) { ymf262_w(device, space, 3, data); }
135
136136const device_type YMF262 = &device_creator<ymf262_device>;
137137
138138ymf262_device::ymf262_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
139139   : device_t(mconfig, YMF262, "YMF262", tag, owner, clock),
140      device_sound_interface(mconfig, *this)
140      device_sound_interface(mconfig, *this),
141      m_irq_handler(*this)
141142{
142   m_token = global_alloc_clear(ymf262_state);
143143}
144144
145145//-------------------------------------------------
r22798r22799
151151void ymf262_device::device_config_complete()
152152{
153153}
154
155//-------------------------------------------------
156//  device_start - device-specific startup
157//-------------------------------------------------
158
159void ymf262_device::device_start()
160{
161   DEVICE_START_NAME( ymf262 )(this);
162}
163
164//-------------------------------------------------
165//  device_reset - device-specific reset
166//-------------------------------------------------
167
168void ymf262_device::device_reset()
169{
170   DEVICE_RESET_NAME( ymf262 )(this);
171}
172
173//-------------------------------------------------
174//  device_stop - device-specific stop
175//-------------------------------------------------
176
177void ymf262_device::device_stop()
178{
179   DEVICE_STOP_NAME( ymf262 )(this);
180}
181
182//-------------------------------------------------
183//  sound_stream_update - handle a stream update
184//-------------------------------------------------
185
186void ymf262_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
187{
188   // should never get here
189   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
190}
trunk/src/emu/sound/262intf.h
r22798r22799
33#ifndef __262INTF_H__
44#define __262INTF_H__
55
6#include "devlegcy.h"
6#include "emu.h"
77
8#define MCFG_YMF262_IRQ_HANDLER(_devcb) \
9   devcb = &ymf262_device::set_irq_handler(*device, DEVCB2_##_devcb);
810
9struct ymf262_interface
10{
11   devcb_write_line irqhandler;
12};
13
14
15DECLARE_READ8_DEVICE_HANDLER( ymf262_r );
16DECLARE_WRITE8_DEVICE_HANDLER( ymf262_w );
17
18DECLARE_READ8_DEVICE_HANDLER ( ymf262_status_r );
19DECLARE_WRITE8_DEVICE_HANDLER( ymf262_register_a_w );
20DECLARE_WRITE8_DEVICE_HANDLER( ymf262_register_b_w );
21DECLARE_WRITE8_DEVICE_HANDLER( ymf262_data_a_w );
22DECLARE_WRITE8_DEVICE_HANDLER( ymf262_data_b_w );
23
24
2511class ymf262_device : public device_t,
2612                           public device_sound_interface
2713{
2814public:
2915   ymf262_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
30   ~ymf262_device() { global_free(m_token); }
3116
32   // access to legacy token
33   void *token() const { assert(m_token != NULL); return m_token; }
17   // static configuration helpers
18   template<class _Object> static devcb2_base &set_irq_handler(device_t &device, _Object object) { return downcast<ymf262_device &>(device).m_irq_handler.set_callback(object); }
19
20   DECLARE_READ8_MEMBER( read );
21   DECLARE_WRITE8_MEMBER( write );
22
23   void _IRQHandler(int irq);
24   void _timer_handler(int c, attotime period);
25   void _ymf262_update_request();
26
27   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
28
3429protected:
3530   // device-level overrides
3631   virtual void device_config_complete();
r22798r22799
4237   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
4338private:
4439   // internal state
45   void *m_token;
40   sound_stream *  m_stream;
41   emu_timer *     m_timer[2];
42   void *          m_chip;
43   devcb2_write_line m_irq_handler;
4644};
4745
4846extern const device_type YMF262;
trunk/src/mess/machine/isa_sblaster.c
r22798r22799
6666   DEVCB_NULL
6767};
6868
69static const ymf262_interface pc_ymf262_interface =
70{
71   DEVCB_NULL
72};
73
7469static SLOT_INTERFACE_START(midiin_slot)
7570   SLOT_INTERFACE("midiin", MIDIIN_PORT)
7671SLOT_INTERFACE_END
r22798r22799
133128static MACHINE_CONFIG_FRAGMENT( sblaster_16_config )
134129   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
135130   MCFG_SOUND_ADD("ymf262", YMF262, ymf262_StdClock)
136   MCFG_SOUND_CONFIG(pc_ymf262_interface)
137131   MCFG_SOUND_ROUTE(0, "lspeaker", 1.00)
138132   MCFG_SOUND_ROUTE(1, "rspeaker", 1.00)
139133   MCFG_SOUND_ROUTE(2, "lspeaker", 1.00)
r22798r22799
11641158
11651159void sb8_device::device_start()
11661160{
1167   m_isa->install_device(                   0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("pc_joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("pc_joy")));
1168   m_isa->install_device(                   0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
1169   m_isa->install_device(                   0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
1170   m_isa->install_device(                   0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
1171   m_isa->install_device(                   0x022e, 0x022f, 0, 0, read8_delegate(FUNC(sb_device::dsp_rbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_rbuf_status_w), this) );
1161   m_isa->install_device(0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("pc_joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("pc_joy")));
1162   m_isa->install_device(0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
1163   m_isa->install_device(0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
1164   m_isa->install_device(0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
1165   m_isa->install_device(0x022e, 0x022f, 0, 0, read8_delegate(FUNC(sb_device::dsp_rbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_rbuf_status_w), this) );
11721166   if(m_dsp.version >= 0x0301)
11731167   {
1174      //m_isa->install_device(0x0224, 0x0225, 0, 0, read8_delegate(FUNC(sb8_device::mixer_r), this), write8_delegate(FUNC(sb8_device::mixer_w), this));
1175      m_isa->install_device(subdevice("ymf262"),    0x0388, 0x038b, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
1176      m_isa->install_device(subdevice("ymf262"),    0x0220, 0x0223, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
1177      m_isa->install_device(subdevice("ymf262"),    0x0228, 0x0229, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
1168      ymf262_device *ymf262 = subdevice<ymf262_device>("ymf262");
1169
1170      m_isa->install_device(0x0388, 0x038b, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
1171      m_isa->install_device(0x0220, 0x0223, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
1172      m_isa->install_device(0x0228, 0x0229, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
11781173   }
11791174   else
11801175   {
r22798r22799
12221217
12231218void sb16_device::device_start()
12241219{
1225   m_isa->install_device(                   0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("pc_joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("pc_joy")));
1226   m_isa->install_device(                   0x0224, 0x0225, 0, 0, read8_delegate(FUNC(sb16_device::mixer_r), this), write8_delegate(FUNC(sb16_device::mixer_w), this));
1227   m_isa->install_device(                   0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
1228   m_isa->install_device(                   0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
1229   m_isa->install_device(                   0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
1230   m_isa->install_device(                   0x022e, 0x022f, 0, 0, read8_delegate(FUNC(sb_device::dsp_rbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_rbuf_status_w), this) );
1231   m_isa->install_device(                   0x0330, 0x0331, 0, 0, read8_delegate(FUNC(sb16_device::mpu401_r), this), write8_delegate(FUNC(sb16_device::mpu401_w), this));
1232   m_isa->install_device(subdevice("ymf262"),    0x0388, 0x038b, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
1233   m_isa->install_device(subdevice("ymf262"),    0x0220, 0x0223, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
1234   m_isa->install_device(subdevice("ymf262"),    0x0228, 0x0229, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
1220   ymf262_device *ymf262 = subdevice<ymf262_device>("ymf262");
12351221
1222   m_isa->install_device(0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("pc_joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("pc_joy")));
1223   m_isa->install_device(0x0224, 0x0225, 0, 0, read8_delegate(FUNC(sb16_device::mixer_r), this), write8_delegate(FUNC(sb16_device::mixer_w), this));
1224   m_isa->install_device(0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
1225   m_isa->install_device(0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
1226   m_isa->install_device(0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
1227   m_isa->install_device(0x022e, 0x022f, 0, 0, read8_delegate(FUNC(sb_device::dsp_rbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_rbuf_status_w), this) );
1228   m_isa->install_device(0x0330, 0x0331, 0, 0, read8_delegate(FUNC(sb16_device::mpu401_r), this), write8_delegate(FUNC(sb16_device::mpu401_w), this));
1229   m_isa->install_device(0x0388, 0x038b, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
1230   m_isa->install_device(0x0220, 0x0223, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
1231   m_isa->install_device(0x0228, 0x0229, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
1232
12361233   m_timer = timer_alloc(0, NULL);
12371234
12381235   save_item(NAME(m_mixer.data));
trunk/src/mame/audio/t5182.h
r22798r22799
1#include "sound/262intf.h"
21#include "sound/2151intf.h"
32
43
trunk/src/mame/drivers/fuukifg3.c
r22798r22799
286286
287287   // also write to ymf262
288288   if (offset < 4)
289      ymf262_w(machine().device("ymf2"), space, offset, data);
289      machine().device<ymf262_device>("ymf2")->write(space, offset, data);
290290}
291291
292292static ADDRESS_MAP_START( fuuki32_sound_map, AS_PROGRAM, 8, fuuki32_state )
r22798r22799
576576   DEVCB_DRIVER_LINE_MEMBER(fuuki32_state,irqhandler)      /* irq */
577577};
578578
579static const ymf262_interface fuuki32_ymf262_interface =
580{
581   DEVCB_NULL            /* irq, already hooked up via ymf278b */
582};
583
584579static MACHINE_CONFIG_START( fuuki32, fuuki32_state )
585580
586581   /* basic machine hardware */
r22798r22799
613608   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
614609
615610   MCFG_SOUND_ADD("ymf2", YMF262, YMF278B_STD_CLOCK / (19/8.0))
616   MCFG_SOUND_CONFIG(fuuki32_ymf262_interface)
617611   MCFG_SOUND_ROUTE(0, "lspeaker", 0.40)
618612   MCFG_SOUND_ROUTE(1, "rspeaker", 0.40)
619613   MCFG_SOUND_ROUTE(2, "lspeaker", 0.40)
trunk/src/mame/drivers/tecmosys.c
r22798r22799
345345
346346static ADDRESS_MAP_START( io_map, AS_IO, 8, tecmosys_state )
347347   ADDRESS_MAP_GLOBAL_MASK(0xff)
348   AM_RANGE(0x00, 0x03) AM_DEVREADWRITE_LEGACY("ymf", ymf262_r, ymf262_w)
348   AM_RANGE(0x00, 0x03) AM_DEVREADWRITE("ymf", ymf262_device, read, write)
349349   AM_RANGE(0x10, 0x10) AM_DEVREADWRITE("oki", okim6295_device, read, write)
350350   AM_RANGE(0x20, 0x20) AM_WRITE(tecmosys_oki_bank_w)
351351   AM_RANGE(0x30, 0x30) AM_WRITE(tecmosys_z80_bank_w)
r22798r22799
438438   m_audiocpu->set_input_line(0, state ? ASSERT_LINE : CLEAR_LINE);
439439}
440440
441static const ymf262_interface tecmosys_ymf262_interface =
442{
443   DEVCB_DRIVER_LINE_MEMBER(tecmosys_state,sound_irq)       /* irq */
444};
445
446441void tecmosys_state::machine_start()
447442{
448443   membank("bank1")->configure_entries(0, 16, memregion("audiocpu")->base(), 0x4000);
r22798r22799
479474   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
480475
481476   MCFG_SOUND_ADD("ymf", YMF262, XTAL_14_31818MHz)
482   MCFG_SOUND_CONFIG(tecmosys_ymf262_interface)
477   MCFG_YMF262_IRQ_HANDLER(WRITELINE(tecmosys_state, sound_irq))
483478   MCFG_SOUND_ROUTE(0, "lspeaker", 1.00)
484479   MCFG_SOUND_ROUTE(1, "rspeaker", 1.00)
485480   MCFG_SOUND_ROUTE(2, "lspeaker", 1.00)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team