Previous 199869 Revisions Next

r22786 Sunday 12th May, 2013 at 12:43:58 UTC by smf
modernised YM2612/YM3438 [smf]
[src/emu/sound]2612intf.c 2612intf.h
[src/mame/drivers]model1.c model2.c segac2.c segas18.c segas32.c seta.c shangha3.c system16.c
[src/mame/includes]megadriv.h
[src/mame/machine]megadriv.c

trunk/src/mame/machine/megadriv.c
r22785r22786
6666   //mame_printf_debug("megadriv_68k_YM2612_read %02x %04x\n",offset,mem_mask);
6767   if ((m_genz80.z80_has_bus == 0) && (m_genz80.z80_is_reset == 0))
6868   {
69      return ym2612_r(m_ymsnd, space, offset);
69      return m_ymsnd->read(space, offset);
7070   }
7171   else
7272   {
r22785r22786
8383   //mame_printf_debug("megadriv_68k_YM2612_write %02x %04x %04x\n",offset,data,mem_mask);
8484   if ((m_genz80.z80_has_bus == 0) && (m_genz80.z80_is_reset == 0))
8585   {
86      ym2612_w(m_ymsnd, space, offset, data);
86      m_ymsnd->write(space, offset, data);
8787   }
8888   else
8989   {
r22785r22786
774774
775775static ADDRESS_MAP_START( megadriv_z80_map, AS_PROGRAM, 8, md_base_state )
776776   AM_RANGE(0x0000, 0x1fff) AM_RAMBANK("bank1") AM_MIRROR(0x2000) // RAM can be accessed by the 68k
777   AM_RANGE(0x4000, 0x4003) AM_DEVREADWRITE_LEGACY("ymsnd", ym2612_r,ym2612_w)
777   AM_RANGE(0x4000, 0x4003) AM_DEVREADWRITE("ymsnd", ym2612_device, read, write)
778778
779779   AM_RANGE(0x6000, 0x6000) AM_WRITE(megadriv_z80_z80_bank_w)
780780   AM_RANGE(0x6001, 0x6001) AM_WRITE(megadriv_z80_z80_bank_w) // wacky races uses this address
r22785r22786
12881288/* sets the megadrive z80 to it's normal ports / map */
12891289void mtech_state::megatech_set_megadrive_z80_as_megadrive_z80(const char* tag)
12901290{
1291   device_t *ym = machine().device("ymsnd");
1291   ym2612_device *ym2612 = machine().device<ym2612_device>("ymsnd");
12921292
12931293   /* INIT THE PORTS *********************************************************************************************/
12941294   machine().device(tag)->memory().space(AS_IO).install_readwrite_handler(0x0000, 0xffff, read8_delegate(FUNC(mtech_state::z80_unmapped_port_r),this), write8_delegate(FUNC(mtech_state::z80_unmapped_port_w),this));
r22785r22786
13031303   machine().device(tag)->memory().space(AS_PROGRAM).install_ram(0x0000, 0x1fff, m_genz80.z80_prgram);
13041304
13051305
1306   machine().device(tag)->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(*ym, 0x4000, 0x4003, FUNC(ym2612_r), FUNC(ym2612_w));
1306   machine().device(tag)->memory().space(AS_PROGRAM).install_readwrite_handler(0x4000, 0x4003, read8_delegate(FUNC(ym2612_device::read),ym2612), write8_delegate(FUNC(ym2612_device::write),ym2612));
13071307   machine().device(tag)->memory().space(AS_PROGRAM).install_write_handler    (0x6000, 0x6000, write8_delegate(FUNC(mtech_state::megadriv_z80_z80_bank_w),this));
13081308   machine().device(tag)->memory().space(AS_PROGRAM).install_write_handler    (0x6001, 0x6001, write8_delegate(FUNC(mtech_state::megadriv_z80_z80_bank_w),this));
13091309   machine().device(tag)->memory().space(AS_PROGRAM).install_read_handler     (0x6100, 0x7eff, read8_delegate(FUNC(mtech_state::megadriv_z80_unmapped_read),this));
trunk/src/mame/includes/megadriv.h
r22785r22786
7070   { }
7171   required_device<cpu_device> m_maincpu;
7272   optional_device<cpu_device> m_z80snd;
73   optional_device<device_t> m_ymsnd;
73   optional_device<ym2612_device> m_ymsnd;
7474   required_device<sega_genesis_vdp_device> m_vdp;
7575   optional_device<sega_32x_device> m_32x;
7676   optional_device<sega_segacd_device> m_segacd;
trunk/src/mame/drivers/segac2.c
r22785r22786
599599   AM_RANGE(0x800000, 0x800001) AM_MIRROR(0x13fdfe) AM_READWRITE(prot_r, prot_w)
600600   AM_RANGE(0x800200, 0x800201) AM_MIRROR(0x13fdfe) AM_WRITE(control_w)
601601   AM_RANGE(0x840000, 0x84001f) AM_MIRROR(0x13fee0) AM_READWRITE(io_chip_r, io_chip_w)
602   AM_RANGE(0x840100, 0x840107) AM_MIRROR(0x13fef8) AM_DEVREADWRITE8_LEGACY("ymsnd", ym3438_r, ym3438_w, 0x00ff)
602   AM_RANGE(0x840100, 0x840107) AM_MIRROR(0x13fef8) AM_DEVREADWRITE8("ymsnd", ym3438_device, read, write, 0x00ff)
603603   AM_RANGE(0x880100, 0x880101) AM_MIRROR(0x13fefe) AM_WRITE(counter_timer_w)
604604   AM_RANGE(0x8c0000, 0x8c0fff) AM_MIRROR(0x13f000) AM_READWRITE(palette_r, palette_w) AM_SHARE("paletteram")
605605   AM_RANGE(0xc00000, 0xc0001f) AM_MIRROR(0x18ff00) AM_DEVREADWRITE("gen_vdp", sega_genesis_vdp_device, megadriv_vdp_r,megadriv_vdp_w)
r22785r22786
12251225   //printf("sound irq %d\n", state);
12261226   m_maincpu->set_input_line(2, state ? ASSERT_LINE : CLEAR_LINE);
12271227}
1228static const ym3438_interface ym3438_intf =
1229{
1230   DEVCB_DRIVER_LINE_MEMBER(segac2_state,segac2_irq2_interrupt)      /* IRQ handler */
1231};
12321228
12331229
12341230/******************************************************************************
r22785r22786
13871383   MCFG_SPEAKER_STANDARD_MONO("mono")
13881384
13891385   MCFG_SOUND_ADD("ymsnd", YM3438, XL2_CLOCK/7)
1390   MCFG_SOUND_CONFIG(ym3438_intf)
1386   MCFG_YM2612_IRQ_HANDLER(WRITELINE(segac2_state, segac2_irq2_interrupt))
13911387   MCFG_SOUND_ROUTE(0, "mono", 0.50)
13921388   /* right channel not connected */
13931389
trunk/src/mame/drivers/model2.c
r22785r22786
18361836   AM_RANGE(0xc50000, 0xc50001) AM_WRITE(m1_snd_mpcm_bnk1_w )
18371837   AM_RANGE(0xc60000, 0xc60007) AM_DEVREADWRITE8_LEGACY("sega2", multipcm_r, multipcm_w, 0x00ff )
18381838   AM_RANGE(0xc70000, 0xc70001) AM_WRITE(m1_snd_mpcm_bnk2_w )
1839   AM_RANGE(0xd00000, 0xd00007) AM_DEVREADWRITE8_LEGACY("ymsnd", ym3438_r, ym3438_w, 0x00ff )
1839   AM_RANGE(0xd00000, 0xd00007) AM_DEVREADWRITE8("ymsnd", ym3438_device, read, write, 0x00ff )
18401840   AM_RANGE(0xf00000, 0xf0ffff) AM_RAM
18411841ADDRESS_MAP_END
18421842
trunk/src/mame/drivers/seta.c
r22785r22786
14921492   m_audiocpu->set_input_line(INPUT_LINE_NMI, state);
14931493}
14941494
1495static const ym3438_interface utoukond_ym3438_intf =
1496{
1497   DEVCB_DRIVER_LINE_MEMBER(seta_state,utoukond_ym3438_interrupt)   // IRQ handler
1498};
1499
15001495/***************************************************************************
15011496
15021497
r22785r22786
32173212
32183213static ADDRESS_MAP_START( utoukond_sound_io_map, AS_IO, 8, seta_state )
32193214   ADDRESS_MAP_GLOBAL_MASK(0xff)
3220   AM_RANGE(0x00, 0x03) AM_DEVREADWRITE_LEGACY("ymsnd", ym3438_r, ym3438_w)
3215   AM_RANGE(0x00, 0x03) AM_DEVREADWRITE("ymsnd", ym3438_device, read, write)
32213216   AM_RANGE(0x80, 0x80) AM_WRITENOP //?
32223217   AM_RANGE(0xc0, 0xc0) AM_READ(soundlatch_byte_r)
32233218ADDRESS_MAP_END
r22785r22786
89098904   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
89108905
89118906   MCFG_SOUND_ADD("ymsnd", YM3438, 16000000/4) /* 4 MHz */
8912   MCFG_SOUND_CONFIG(utoukond_ym3438_intf)
8907   MCFG_YM2612_IRQ_HANDLER(WRITELINE(seta_state, utoukond_ym3438_interrupt))
89138908   MCFG_SOUND_ROUTE(0, "lspeaker", 0.30)
89148909   MCFG_SOUND_ROUTE(1, "rspeaker", 0.30)
89158910MACHINE_CONFIG_END
trunk/src/mame/drivers/segas32.c
r22785r22786
12301230static ADDRESS_MAP_START( system32_sound_portmap, AS_IO, 8, segas32_state )
12311231   ADDRESS_MAP_UNMAP_HIGH
12321232   ADDRESS_MAP_GLOBAL_MASK(0xff)
1233   AM_RANGE(0x80, 0x83) AM_MIRROR(0x0c) AM_DEVREADWRITE_LEGACY("ym1", ym3438_r, ym3438_w)
1234   AM_RANGE(0x90, 0x93) AM_MIRROR(0x0c) AM_DEVREADWRITE_LEGACY("ym2", ym3438_r, ym3438_w)
1233   AM_RANGE(0x80, 0x83) AM_MIRROR(0x0c) AM_DEVREADWRITE("ym1", ym3438_device, read, write)
1234   AM_RANGE(0x90, 0x93) AM_MIRROR(0x0c) AM_DEVREADWRITE("ym2", ym3438_device, read, write)
12351235   AM_RANGE(0xa0, 0xaf) AM_WRITE(sound_bank_lo_w)
12361236   AM_RANGE(0xb0, 0xbf) AM_WRITE(sound_bank_hi_w)
12371237   AM_RANGE(0xc0, 0xcf) AM_WRITE(sound_int_control_lo_w)
r22785r22786
12501250static ADDRESS_MAP_START( multi32_sound_portmap, AS_IO, 8, segas32_state )
12511251   ADDRESS_MAP_UNMAP_HIGH
12521252   ADDRESS_MAP_GLOBAL_MASK(0xff)
1253   AM_RANGE(0x80, 0x83) AM_MIRROR(0x0c) AM_DEVREADWRITE_LEGACY("ymsnd", ym3438_r, ym3438_w)
1253   AM_RANGE(0x80, 0x83) AM_MIRROR(0x0c) AM_DEVREADWRITE("ymsnd", ym3438_device, read, write)
12541254   AM_RANGE(0xa0, 0xaf) AM_WRITE(sound_bank_lo_w)
12551255   AM_RANGE(0xb0, 0xbf) AM_WRITE(multipcm_bank_w)
12561256   AM_RANGE(0xc0, 0xcf) AM_WRITE(sound_int_control_lo_w)
r22785r22786
21302130
21312131/*************************************
21322132 *
2133 *  Sound interfaces
2134 *
2135 *************************************/
2136
2137static const ym3438_interface ym3438_config =
2138{
2139   DEVCB_DRIVER_LINE_MEMBER(segas32_state,ym3438_irq_handler)
2140};
2141
2142
2143
2144/*************************************
2145 *
21462133 *  Dual PCB shared memory comms
21472134 *
21482135 *************************************/
r22785r22786
22122199   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
22132200
22142201   MCFG_SOUND_ADD("ym1", YM3438, MASTER_CLOCK/4)
2215   MCFG_SOUND_CONFIG(ym3438_config)
2202   MCFG_YM2612_IRQ_HANDLER(WRITELINE(segas32_state, ym3438_irq_handler))
22162203   MCFG_SOUND_ROUTE(0, "lspeaker", 0.40)
22172204   MCFG_SOUND_ROUTE(1, "rspeaker", 0.40)
22182205
r22785r22786
22782265   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
22792266
22802267   MCFG_SOUND_ADD("ymsnd", YM3438, MASTER_CLOCK/4)
2281   MCFG_SOUND_CONFIG(ym3438_config)
2268   MCFG_YM2612_IRQ_HANDLER(WRITELINE(segas32_state, ym3438_irq_handler))
22822269   MCFG_SOUND_ROUTE(1, "lspeaker", 0.40)
22832270   MCFG_SOUND_ROUTE(0, "rspeaker", 0.40)
22842271
trunk/src/mame/drivers/shangha3.c
r22785r22786
184184
185185static ADDRESS_MAP_START( heberpop_sound_io_map, AS_IO, 8, shangha3_state )
186186   ADDRESS_MAP_GLOBAL_MASK(0xff)
187   AM_RANGE(0x00, 0x03) AM_DEVREADWRITE_LEGACY("ymsnd", ym3438_r, ym3438_w)
187   AM_RANGE(0x00, 0x03) AM_DEVREADWRITE("ymsnd", ym3438_device, read, write)
188188   AM_RANGE(0x80, 0x80) AM_DEVREADWRITE("oki", okim6295_device, read, write)
189189   AM_RANGE(0xc0, 0xc0) AM_READ(soundlatch_byte_r)
190190ADDRESS_MAP_END
r22785r22786
470470   m_audiocpu->set_input_line(INPUT_LINE_NMI, state);
471471}
472472
473static const ym3438_interface ym3438_config =
474{
475   DEVCB_DRIVER_LINE_MEMBER(shangha3_state,irqhandler)
476};
477473
478
479474static MACHINE_CONFIG_START( shangha3, shangha3_state )
480475
481476   /* basic machine hardware */
r22785r22786
542537   MCFG_SPEAKER_STANDARD_MONO("mono")
543538
544539   MCFG_SOUND_ADD("ymsnd", YM3438, MASTER_CLOCK/6) /* 8 MHz? */
545   MCFG_SOUND_CONFIG(ym3438_config)
540   MCFG_YM2612_IRQ_HANDLER(WRITELINE(shangha3_state,irqhandler))
546541   MCFG_SOUND_ROUTE(0, "mono", 0.40)
547542   MCFG_SOUND_ROUTE(1, "mono", 0.40)
548543
r22785r22786
582577   MCFG_SPEAKER_STANDARD_MONO("mono")
583578
584579   MCFG_SOUND_ADD("ymsnd", YM3438, MASTER_CLOCK/6) /* 8 MHz? */
585   MCFG_SOUND_CONFIG(ym3438_config)
580   MCFG_YM2612_IRQ_HANDLER(WRITELINE(shangha3_state,irqhandler))
586581   MCFG_SOUND_ROUTE(0, "mono", 0.40)
587582   MCFG_SOUND_ROUTE(1, "mono", 0.40)
588583
trunk/src/mame/drivers/segas18.c
r22785r22786
628628static ADDRESS_MAP_START( sound_portmap, AS_IO, 8, segas18_state )
629629   ADDRESS_MAP_UNMAP_HIGH
630630   ADDRESS_MAP_GLOBAL_MASK(0xff)
631   AM_RANGE(0x80, 0x83) AM_MIRROR(0x0c) AM_DEVREADWRITE_LEGACY("ym1", ym3438_r, ym3438_w)
632   AM_RANGE(0x90, 0x93) AM_MIRROR(0x0c) AM_DEVREADWRITE_LEGACY("ym2", ym3438_r, ym3438_w)
631   AM_RANGE(0x80, 0x83) AM_MIRROR(0x0c) AM_DEVREADWRITE("ym1", ym3438_device, read, write)
632   AM_RANGE(0x90, 0x93) AM_MIRROR(0x0c) AM_DEVREADWRITE("ym2", ym3438_device, read, write)
633633   AM_RANGE(0xa0, 0xa0) AM_MIRROR(0x1f) AM_WRITE(soundbank_w)
634634   AM_RANGE(0xc0, 0xc0) AM_MIRROR(0x1f) AM_READ(soundlatch_byte_r) AM_WRITE(mcu_data_w)
635635ADDRESS_MAP_END
trunk/src/mame/drivers/system16.c
r22785r22786
10351035
10361036static ADDRESS_MAP_START( sound_18_io_map, AS_IO, 8, segas1x_bootleg_state )
10371037   ADDRESS_MAP_GLOBAL_MASK(0xff)
1038   AM_RANGE(0x80, 0x83) AM_DEVREADWRITE_LEGACY("3438.0", ym3438_r, ym3438_w)
1039   AM_RANGE(0x90, 0x93) AM_DEVREADWRITE_LEGACY("3438.1", ym3438_r, ym3438_w)
1038   AM_RANGE(0x80, 0x83) AM_DEVREADWRITE("3438.0", ym3438_device, read, write)
1039   AM_RANGE(0x90, 0x93) AM_DEVREADWRITE("3438.1", ym3438_device, read, write)
10401040   AM_RANGE(0xa0, 0xa0) AM_WRITE(sys18_soundbank_w)
10411041   AM_RANGE(0xc0, 0xc0) AM_READ(soundlatch_byte_r)
10421042ADDRESS_MAP_END
r22785r22786
12111211   AM_RANGE(0xc000, 0xc00f) AM_WRITENOP
12121212   AM_RANGE(0xc400, 0xc400) AM_READ(soundlatch_byte_r)
12131213   AM_RANGE(0xc800, 0xc800) AM_WRITE(shdancbl_msm5205_data_w)
1214   AM_RANGE(0xcc00, 0xcc03) AM_DEVREADWRITE_LEGACY("3438.0", ym3438_r, ym3438_w)
1215   AM_RANGE(0xd000, 0xd003) AM_DEVREADWRITE_LEGACY("3438.1", ym3438_r, ym3438_w)
1214   AM_RANGE(0xcc00, 0xcc03) AM_DEVREADWRITE("3438.0", ym3438_device, read, write)
1215   AM_RANGE(0xd000, 0xd003) AM_DEVREADWRITE("3438.1", ym3438_device, read, write)
12161216   AM_RANGE(0xd400, 0xd400) AM_WRITE(shdancbl_bankctrl_w)
12171217   AM_RANGE(0xdf00, 0xdfff) AM_NOP
12181218   AM_RANGE(0xe000, 0xffff) AM_RAM
trunk/src/mame/drivers/model1.c
r22785r22786
10381038   AM_RANGE(0xc50000, 0xc50001) AM_WRITE(m1_snd_mpcm_bnk1_w )
10391039   AM_RANGE(0xc60000, 0xc60007) AM_DEVREADWRITE8_LEGACY("sega2", multipcm_r, multipcm_w, 0x00ff )
10401040   AM_RANGE(0xc70000, 0xc70001) AM_WRITE(m1_snd_mpcm_bnk2_w )
1041   AM_RANGE(0xd00000, 0xd00007) AM_DEVREADWRITE8_LEGACY("ymsnd", ym3438_r, ym3438_w, 0x00ff )
1041   AM_RANGE(0xd00000, 0xd00007) AM_DEVREADWRITE8("ymsnd", ym3438_device, read, write, 0x00ff )
10421042   AM_RANGE(0xf00000, 0xf0ffff) AM_RAM
10431043ADDRESS_MAP_END
10441044
trunk/src/emu/sound/2612intf.c
r22785r22786
1212***************************************************************************/
1313
1414#include "emu.h"
15#include "sound/fm.h"
16#include "sound/2612intf.h"
15#include "fm.h"
16#include "2612intf.h"
1717
18
19struct ym2612_state
20{
21   sound_stream *  stream;
22   emu_timer *     timer[2];
23   void *          chip;
24   const ym2612_interface *intf;
25   device_t *device;
26   devcb_resolved_write_line irqhandler;
27};
28
29
30INLINE ym2612_state *get_safe_token(device_t *device)
31{
32   assert(device != NULL);
33   assert(device->type() == YM2612 || device->type() == YM3438);
34   return (ym2612_state *)downcast<ym2612_device *>(device)->token();
35}
36
37
38
3918/*------------------------- TM2612 -------------------------------*/
4019/* IRQ Handler */
4120static void IRQHandler(void *param,int irq)
4221{
43   ym2612_state *info = (ym2612_state *)param;
44   if (!info->irqhandler.isnull())
45      info->irqhandler(irq);
22   ym2612_device *ym2612 = (ym2612_device *) param;
23   ym2612->_IRQHandler(irq);
4624}
4725
48/* Timer overflow callback from timer.c */
49static TIMER_CALLBACK( timer_callback_2612_0 )
26void ym2612_device::_IRQHandler(int irq)
5027{
51   ym2612_state *info = (ym2612_state *)ptr;
52   ym2612_timer_over(info->chip,0);
28   if (!m_irq_handler.isnull())
29      m_irq_handler(irq);
5330}
5431
55static TIMER_CALLBACK( timer_callback_2612_1 )
32/* Timer overflow callback from timer.c */
33void ym2612_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
5634{
57   ym2612_state *info = (ym2612_state *)ptr;
58   ym2612_timer_over(info->chip,1);
35   switch(id)
36   {
37   case 0:
38      ym2612_timer_over(m_chip,0);
39      break;
40
41   case 1:
42      ym2612_timer_over(m_chip,1);
43      break;
44   }
5945}
6046
6147static void timer_handler(void *param,int c,int count,int clock)
6248{
63   ym2612_state *info = (ym2612_state *)param;
49   ym2612_device *ym2612 = (ym2612_device *) param;
50   ym2612->_timer_handler(c, count, clock);
51}
52
53void ym2612_device::_timer_handler(int c,int count,int clock)
54{
6455   if( count == 0 )
6556   {   /* Reset FM Timer */
66      info->timer[c]->enable(false);
57      m_timer[c]->enable(false);
6758   }
6859   else
6960   {   /* Start FM Timer */
7061      attotime period = attotime::from_hz(clock) * count;
71      if (!info->timer[c]->enable(1))
72         info->timer[c]->adjust(period);
62
63      if (!m_timer[c]->enable(true))
64         m_timer[c]->adjust(period);
7365   }
7466}
7567
7668/* update request from fm.c */
7769void ym2612_update_request(void *param)
7870{
79   ym2612_state *info = (ym2612_state *)param;
80   info->stream->update();
71   ym2612_device *ym2612 = (ym2612_device *) param;
72   ym2612->_ym2612_update_request();
8173}
8274
83/***********************************************************/
84/*    YM2612                                               */
85/***********************************************************/
75void ym2612_device::_ym2612_update_request()
76{
77   m_stream->update();
78}
8679
87static STREAM_UPDATE( ym2612_stream_update )
80//-------------------------------------------------
81//  sound_stream_update - handle a stream update
82//-------------------------------------------------
83
84void ym2612_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
8885{
89   ym2612_state *info = (ym2612_state *)param;
90   ym2612_update_one(info->chip, outputs, samples);
86   ym2612_update_one(m_chip, outputs, samples);
9187}
9288
9389
94static void ym2612_intf_postload(ym2612_state *info)
90void ym2612_device::device_post_load()
9591{
96   ym2612_postload(info->chip);
92   ym2612_postload(m_chip);
9793}
9894
9995
100static DEVICE_START( ym2612 )
96//-------------------------------------------------
97//  device_start - device-specific startup
98//-------------------------------------------------
99
100void ym2612_device::device_start()
101101{
102   static const ym2612_interface dummy = { DEVCB_NULL };
103   ym2612_state *info = get_safe_token(device);
104   int rate = device->clock()/72;
102   int rate = clock()/72;
105103
106   info->intf = device->static_config() ? (const ym2612_interface *)device->static_config() : &dummy;
107   info->device = device;
108   info->irqhandler.resolve(info->intf->irqhandler, *device);
104   m_irq_handler.resolve();
109105
110106   /* FM init */
111107   /* Timer Handler set */
112   info->timer[0] = device->machine().scheduler().timer_alloc(FUNC(timer_callback_2612_0), info);
113   info->timer[1] = device->machine().scheduler().timer_alloc(FUNC(timer_callback_2612_1), info);
108   m_timer[0] = timer_alloc(0);
109   m_timer[1] = timer_alloc(1);
114110
115111   /* stream system initialize */
116   info->stream = device->machine().sound().stream_alloc(*device,0,2,rate,info,ym2612_stream_update);
112   m_stream = machine().sound().stream_alloc(*this,0,2,rate);
117113
118114   /**** initialize YM2612 ****/
119   info->chip = ym2612_init(info,device,device->clock(),rate,timer_handler,IRQHandler);
120   assert_always(info->chip != NULL, "Error creating YM2612 chip");
121
122   device->machine().save().register_postload(save_prepost_delegate(FUNC(ym2612_intf_postload), info));
115   m_chip = ym2612_init(this,this,clock(),rate,timer_handler,IRQHandler);
116   assert_always(m_chip != NULL, "Error creating YM2612 chip");
123117}
124118
125119
126static DEVICE_STOP( ym2612 )
120//-------------------------------------------------
121//  device_stop - device-specific stop
122//-------------------------------------------------
123
124void ym2612_device::device_stop()
127125{
128   ym2612_state *info = get_safe_token(device);
129   ym2612_shutdown(info->chip);
126   ym2612_shutdown(m_chip);
130127}
131128
132static DEVICE_RESET( ym2612 )
129//-------------------------------------------------
130//  device_reset - device-specific reset
131//-------------------------------------------------
132
133void ym2612_device::device_reset()
133134{
134   ym2612_state *info = get_safe_token(device);
135   ym2612_reset_chip(info->chip);
135   ym2612_reset_chip(m_chip);
136136}
137137
138138
139READ8_DEVICE_HANDLER( ym2612_r )
139READ8_MEMBER( ym2612_device::read )
140140{
141   ym2612_state *info = get_safe_token(device);
142   return ym2612_read(info->chip, offset & 3);
141   return ym2612_read(m_chip, offset & 3);
143142}
144143
145WRITE8_DEVICE_HANDLER( ym2612_w )
144WRITE8_MEMBER( ym2612_device::write )
146145{
147   ym2612_state *info = get_safe_token(device);
148   ym2612_write(info->chip, offset & 3, data);
146   ym2612_write(m_chip, offset & 3, data);
149147}
150148
151149
152READ8_DEVICE_HANDLER( ym2612_status_port_a_r ) { return ym2612_r(device, space, 0); }
153READ8_DEVICE_HANDLER( ym2612_status_port_b_r ) { return ym2612_r(device, space, 2); }
154READ8_DEVICE_HANDLER( ym2612_data_port_a_r ) { return ym2612_r(device, space, 1); }
155READ8_DEVICE_HANDLER( ym2612_data_port_b_r ) { return ym2612_r(device, space, 3); }
156
157WRITE8_DEVICE_HANDLER( ym2612_control_port_a_w ) { ym2612_w(device, space, 0, data); }
158WRITE8_DEVICE_HANDLER( ym2612_control_port_b_w ) { ym2612_w(device, space, 2, data); }
159WRITE8_DEVICE_HANDLER( ym2612_data_port_a_w ) { ym2612_w(device, space, 1, data); }
160WRITE8_DEVICE_HANDLER( ym2612_data_port_b_w ) { ym2612_w(device, space, 3, data); }
161
162150const device_type YM2612 = &device_creator<ym2612_device>;
163151
164152ym2612_device::ym2612_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
165153   : device_t(mconfig, YM2612, "YM2612", tag, owner, clock),
166      device_sound_interface(mconfig, *this)
154      device_sound_interface(mconfig, *this),
155      m_irq_handler(*this)
167156{
168   m_token = global_alloc_clear(ym2612_state);
169157}
158
170159ym2612_device::ym2612_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
171160   : device_t(mconfig, type, name, tag, owner, clock),
172      device_sound_interface(mconfig, *this)
161      device_sound_interface(mconfig, *this),
162      m_irq_handler(*this)
173163{
174   m_token = global_alloc_clear(ym2612_state);
175164}
176165
177166//-------------------------------------------------
r22785r22786
184173{
185174}
186175
187//-------------------------------------------------
188//  device_start - device-specific startup
189//-------------------------------------------------
190176
191void ym2612_device::device_start()
192{
193   DEVICE_START_NAME( ym2612 )(this);
194}
195
196//-------------------------------------------------
197//  device_reset - device-specific reset
198//-------------------------------------------------
199
200void ym2612_device::device_reset()
201{
202   DEVICE_RESET_NAME( ym2612 )(this);
203}
204
205//-------------------------------------------------
206//  device_stop - device-specific stop
207//-------------------------------------------------
208
209void ym2612_device::device_stop()
210{
211   DEVICE_STOP_NAME( ym2612 )(this);
212}
213
214//-------------------------------------------------
215//  sound_stream_update - handle a stream update
216//-------------------------------------------------
217
218void ym2612_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
219{
220   // should never get here
221   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
222}
223
224
225177const device_type YM3438 = &device_creator<ym3438_device>;
226178
227179ym3438_device::ym3438_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
228180   : ym2612_device(mconfig, YM3438, "YM3438", tag, owner, clock)
229181{
230182}
231
232//-------------------------------------------------
233//  sound_stream_update - handle a stream update
234//-------------------------------------------------
235
236void ym3438_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
237{
238   // should never get here
239   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
240}
trunk/src/emu/sound/2612intf.h
r22785r22786
33#ifndef __2612INTF_H__
44#define __2612INTF_H__
55
6#include "devlegcy.h"
6#include "emu.h"
77
88void ym2612_update_request(void *param);
99
10struct ym2612_interface
11{
12   devcb_write_line irqhandler;
13};
10#define MCFG_YM2612_IRQ_HANDLER(_devcb) \
11   devcb = &ym2612_device::set_irq_handler(*device, DEVCB2_##_devcb);
1412
15DECLARE_READ8_DEVICE_HANDLER( ym2612_r );
16DECLARE_WRITE8_DEVICE_HANDLER( ym2612_w );
17
18DECLARE_READ8_DEVICE_HANDLER( ym2612_status_port_a_r );
19DECLARE_READ8_DEVICE_HANDLER( ym2612_status_port_b_r );
20DECLARE_READ8_DEVICE_HANDLER( ym2612_data_port_a_r );
21DECLARE_READ8_DEVICE_HANDLER( ym2612_data_port_b_r );
22
23DECLARE_WRITE8_DEVICE_HANDLER( ym2612_control_port_a_w );
24DECLARE_WRITE8_DEVICE_HANDLER( ym2612_control_port_b_w );
25DECLARE_WRITE8_DEVICE_HANDLER( ym2612_data_port_a_w );
26DECLARE_WRITE8_DEVICE_HANDLER( ym2612_data_port_b_w );
27
28
2913class ym2612_device : public device_t,
3014                           public device_sound_interface
3115{
3216public:
3317   ym2612_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
3418   ym2612_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
35   ~ym2612_device() { global_free(m_token); }
3619
37   // access to legacy token
38   void *token() const { assert(m_token != NULL); return m_token; }
20   // static configuration helpers
21   template<class _Object> static devcb2_base &set_irq_handler(device_t &device, _Object object) { return downcast<ym2612_device &>(device).m_irq_handler.set_callback(object); }
22
23   DECLARE_READ8_MEMBER( read );
24   DECLARE_WRITE8_MEMBER( write );
25
26   void _IRQHandler(int irq);
27   void _timer_handler(int c,int count,int clock);
28   void _ym2612_update_request();
29
3930protected:
4031   // device-level overrides
4132   virtual void device_config_complete();
4233   virtual void device_start();
34   virtual void device_post_load();
4335   virtual void device_stop();
4436   virtual void device_reset();
4537
38   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
39
4640   // sound stream update overrides
4741   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
42
4843private:
49   // internal state
50   void *m_token;
44   sound_stream *  m_stream;
45   emu_timer *     m_timer[2];
46   void *          m_chip;
47   devcb2_write_line m_irq_handler;
5148};
5249
5350extern const device_type YM2612;
5451
5552
56
57struct ym3438_interface
58{
59   devcb_write_line irqhandler;
60};
61
62
63#define ym3438_r                ym2612_r
64#define ym3438_w                ym2612_w
65
66#define ym3438_status_port_a_r  ym2612_status_port_a_r
67#define ym3438_status_port_b_r  ym2612_status_port_b_r
68#define ym3438_data_port_a_r    ym2612_data_port_a_r
69#define ym3438_data_port_b_r    ym2612_data_port_b_r
70
71#define ym3438_control_port_a_w ym2612_control_port_a_w
72#define ym3438_control_port_b_w ym2612_control_port_b_w
73#define ym3438_data_port_a_w    ym2612_data_port_a_w
74#define ym3438_data_port_b_w    ym2612_data_port_b_w
75
76
7753class ym3438_device : public ym2612_device
7854{
7955public:
8056   ym3438_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
81
82   // sound stream update overrides
83   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
8457};
8558
8659extern const device_type YM3438;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team