Previous 199869 Revisions Next

r32563 Monday 6th October, 2014 at 13:12:49 UTC by Alex Jackson
Rewrite k053260 sound device [Alex Jackson]
[src/emu/sound]k053260.c k053260.h
[src/mame/drivers]asterix.c overdriv.c parodius.c rollerg.c simpsons.c tmnt.c vendetta.c
[src/mame/includes]asterix.h overdriv.h parodius.h rollerg.h simpsons.h tmnt.h vendetta.h
[src/mame/machine]simpsons.c

trunk/src/mame/drivers/rollerg.c
r32562r32563
4242      return m_k051316->read(space, offset);
4343}
4444
45READ8_MEMBER(rollerg_state::rollerg_sound_r)
46{
47   /* If the sound CPU is running, read the status, otherwise
48      just make it pass the test */
49   return m_k053260->k053260_r(space, 2 + offset);
50}
51
5245WRITE8_MEMBER(rollerg_state::soundirq_w)
5346{
5447   m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff);
r32562r32563
8073static ADDRESS_MAP_START( rollerg_map, AS_PROGRAM, 8, rollerg_state )
8174   AM_RANGE(0x0010, 0x0010) AM_WRITE(rollerg_0010_w)
8275   AM_RANGE(0x0020, 0x0020) AM_READWRITE(watchdog_reset_r,watchdog_reset_w)
83   AM_RANGE(0x0030, 0x0031) AM_READ(rollerg_sound_r) AM_DEVWRITE("k053260", k053260_device, k053260_w)  /* K053260 */
76   AM_RANGE(0x0030, 0x0031) AM_DEVREADWRITE("k053260", k053260_device, main_read, main_write)
8477   AM_RANGE(0x0040, 0x0040) AM_WRITE(soundirq_w)
8578   AM_RANGE(0x0050, 0x0050) AM_READ_PORT("P1")
8679   AM_RANGE(0x0051, 0x0051) AM_READ_PORT("P2")
r32562r32563
10295static ADDRESS_MAP_START( rollerg_sound_map, AS_PROGRAM, 8, rollerg_state )
10396   AM_RANGE(0x0000, 0x7fff) AM_ROM
10497   AM_RANGE(0x8000, 0x87ff) AM_RAM
105   AM_RANGE(0xa000, 0xa02f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
98   AM_RANGE(0xa000, 0xa02f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
10699   AM_RANGE(0xc000, 0xc001) AM_DEVREADWRITE("ymsnd", ym3812_device, read, write)
107100   AM_RANGE(0xfc00, 0xfc00) AM_WRITE(sound_arm_nmi_w)
108101ADDRESS_MAP_END
trunk/src/mame/drivers/tmnt.c
r32562r32563
5959#include "sound/2151intf.h"
6060#include "sound/okim6295.h"
6161#include "sound/samples.h"
62#include "sound/k053260.h"
6362#include "sound/k054539.h"
6463#include "machine/nvram.h"
6564#include "includes/tmnt.h"
r32562r32563
163162      device.execute().set_input_line(M68K_IRQ_5, HOLD_LINE);
164163}
165164
166READ8_MEMBER(tmnt_state::punkshot_sound_r)
167{
168   /* If the sound CPU is running, read the status, otherwise
169      just make it pass the test */
170   return m_k053260->k053260_r(space, 2 + offset);
171}
172
173165WRITE8_MEMBER(tmnt_state::glfgreat_sound_w)
174166{
175   m_k053260->k053260_w(space, offset, data);
167   m_k053260->main_write(space, offset, data);
176168
177169   if (offset)
178170      m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff);
r32562r32563
543535   AM_RANGE(0x0a0004, 0x0a0005) AM_READ_PORT("P3/P4")
544536   AM_RANGE(0x0a0006, 0x0a0007) AM_READ_PORT("P1/P2")
545537   AM_RANGE(0x0a0020, 0x0a0021) AM_WRITE(punkshot_0a0020_w)
546   AM_RANGE(0x0a0040, 0x0a0043) AM_READ8(punkshot_sound_r, 0x00ff) /* K053260 */
547   AM_RANGE(0x0a0040, 0x0a0041) AM_DEVWRITE8("k053260", k053260_device, k053260_w, 0x00ff)
538   AM_RANGE(0x0a0040, 0x0a0043) AM_DEVREADWRITE8("k053260", k053260_device, main_read, main_write, 0x00ff)
548539   AM_RANGE(0x0a0060, 0x0a007f) AM_DEVWRITE("k053251", k053251_device, lsb_w)
549540   AM_RANGE(0x0a0080, 0x0a0081) AM_WRITE(watchdog_reset16_w)
550541   AM_RANGE(0x100000, 0x107fff) AM_READWRITE(k052109_word_noA12_r, punkshot_k052109_word_noA12_w)
r32562r32563
565556   AM_RANGE(0x0a0008, 0x0a0009) AM_READ_PORT("DSW2")
566557   AM_RANGE(0x0a0010, 0x0a0011) AM_READ_PORT("DSW3")
567558   AM_RANGE(0x0a0018, 0x0a0019) AM_WRITE(lgtnfght_0a0018_w)
568   AM_RANGE(0x0a0020, 0x0a0023) AM_READ8(punkshot_sound_r, 0x00ff) /* K053260 */
569   AM_RANGE(0x0a0020, 0x0a0021) AM_DEVWRITE8("k053260", k053260_device, k053260_w, 0x00ff)
559   AM_RANGE(0x0a0020, 0x0a0023) AM_DEVREADWRITE8("k053260", k053260_device, main_read, main_write, 0x00ff)
570560   AM_RANGE(0x0a0028, 0x0a0029) AM_WRITE(watchdog_reset16_w)
571561   AM_RANGE(0x0b0000, 0x0b3fff) AM_READWRITE(k053245_scattered_word_r, k053245_scattered_word_w) AM_SHARE("spriteram")
572562   AM_RANGE(0x0c0000, 0x0c001f) AM_READWRITE(k053244_word_noA1_r, k053244_word_noA1_w)
r32562r32563
595585   AM_RANGE(0x700006, 0x700007) AM_READ_PORT("EEPROM")
596586   AM_RANGE(0x700200, 0x700201) AM_WRITE(blswhstl_eeprom_w)
597587   AM_RANGE(0x700300, 0x700301) AM_WRITE(blswhstl_700300_w)
598   AM_RANGE(0x700400, 0x700401) AM_WRITE(watchdog_reset16_w)
599   AM_RANGE(0x780600, 0x780603) AM_READ8(punkshot_sound_r, 0x00ff) /* K053260 */
600   AM_RANGE(0x780600, 0x780601) AM_DEVWRITE8("k053260", k053260_device, k053260_w, 0x00ff)
588   AM_RANGE(0x700400, 0x700401) AM_READWRITE(watchdog_reset16_r, watchdog_reset16_w)
589   AM_RANGE(0x780600, 0x780603) AM_DEVREADWRITE8("k053260", k053260_device, main_read, main_write, 0x00ff)
601590   AM_RANGE(0x780604, 0x780605) AM_WRITE(ssriders_soundkludge_w)
602591   AM_RANGE(0x780700, 0x78071f) AM_DEVWRITE("k053251", k053251_device, lsb_w)
603592ADDRESS_MAP_END
r32562r32563
642631   AM_RANGE(0x121000, 0x121001) AM_READ(glfgreat_ball_r)   /* returns the color of the center pixel of the roz layer */
643632   AM_RANGE(0x122000, 0x122001) AM_WRITE(glfgreat_122000_w)
644633   AM_RANGE(0x124000, 0x124001) AM_WRITE(watchdog_reset16_w)
645   AM_RANGE(0x125000, 0x125003) AM_READWRITE8(punkshot_sound_r, glfgreat_sound_w, 0xff00)  /* K053260 */
634   AM_RANGE(0x125000, 0x125003) AM_DEVREAD8("k053260", k053260_device, main_read, 0xff00) AM_WRITE8(glfgreat_sound_w, 0xff00)
646635   AM_RANGE(0x200000, 0x207fff) AM_READWRITE(k052109_word_noA12_r, k052109_word_noA12_w)
647636   AM_RANGE(0x300000, 0x3fffff) AM_READ(glfgreat_rom_r)
648637ADDRESS_MAP_END
r32562r32563
926915//  AM_RANGE(0x1c0800, 0x1c0801) AM_READ(ssriders_protection_r) /* protection device */
927916   AM_RANGE(0x1c0800, 0x1c081f) AM_WRITE(tmnt2_1c0800_w) AM_SHARE("tmnt2_1c0800")  /* protection device */
928917   AM_RANGE(0x5a0000, 0x5a001f) AM_READWRITE(k053244_word_noA1_r, k053244_word_noA1_w)
929   AM_RANGE(0x5c0600, 0x5c0603) AM_READ8(punkshot_sound_r, 0x00ff) /* K053260 */
930   AM_RANGE(0x5c0600, 0x5c0601) AM_DEVWRITE8("k053260", k053260_device, k053260_w, 0x00ff)
918   AM_RANGE(0x5c0600, 0x5c0603) AM_DEVREADWRITE8("k053260", k053260_device, main_read, main_write, 0x00ff)
931919   AM_RANGE(0x5c0604, 0x5c0605) AM_WRITE(ssriders_soundkludge_w)
932920   AM_RANGE(0x5c0700, 0x5c071f) AM_DEVWRITE("k053251", k053251_device, lsb_w)
933921   AM_RANGE(0x600000, 0x603fff) AM_DEVREADWRITE("k052109", k052109_device, word_r, word_w)
r32562r32563
952940   AM_RANGE(0x1c0800, 0x1c0801) AM_READ(ssriders_protection_r)
953941   AM_RANGE(0x1c0800, 0x1c0803) AM_WRITE(ssriders_protection_w)
954942   AM_RANGE(0x5a0000, 0x5a001f) AM_READWRITE(k053244_word_noA1_r, k053244_word_noA1_w)
955   AM_RANGE(0x5c0600, 0x5c0603) AM_READ8(punkshot_sound_r, 0x00ff) /* K053260 */
956   AM_RANGE(0x5c0600, 0x5c0601) AM_DEVWRITE8("k053260", k053260_device, k053260_w, 0x00ff)
943   AM_RANGE(0x5c0600, 0x5c0603) AM_DEVREADWRITE8("k053260", k053260_device, main_read, main_write, 0x00ff)
957944   AM_RANGE(0x5c0604, 0x5c0605) AM_WRITE(ssriders_soundkludge_w)
958945   AM_RANGE(0x5c0700, 0x5c071f) AM_DEVWRITE("k053251", k053251_device, lsb_w)
959946   AM_RANGE(0x600000, 0x603fff) AM_DEVREADWRITE("k052109", k052109_device, word_r, word_w)
r32562r32563
991978   AM_RANGE(0x100000, 0x103fff) AM_RAM /* main RAM */
992979   AM_RANGE(0x200000, 0x200fff) AM_RAM_DEVWRITE("palette", palette_device, write) AM_SHARE("palette")
993980   AM_RANGE(0x300000, 0x30001f) AM_DEVWRITE("k053251", k053251_device, lsb_w)
994   AM_RANGE(0x400000, 0x400003) AM_READ8(punkshot_sound_r, 0x00ff) /* K053260 */
995   AM_RANGE(0x400000, 0x400001) AM_DEVWRITE8("k053260", k053260_device, k053260_w, 0x00ff)
981   AM_RANGE(0x400000, 0x400003) AM_DEVREADWRITE8("k053260", k053260_device, main_read, main_write, 0x00ff)
996982   AM_RANGE(0x500000, 0x50003f) AM_DEVREADWRITE("k054000", k054000_device, lsb_r, lsb_w)
997983   AM_RANGE(0x500100, 0x500101) AM_WRITE(thndrx2_eeprom_w)
998984   AM_RANGE(0x500200, 0x500201) AM_READ_PORT("P1/COINS")
r32562r32563
10321018   AM_RANGE(0xf000, 0xf7ff) AM_RAM
10331019   AM_RANGE(0xf800, 0xf801) AM_DEVREADWRITE("ymsnd", ym2151_device, read, write)
10341020   AM_RANGE(0xfa00, 0xfa00) AM_WRITE(sound_arm_nmi_w)
1035   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
1021   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
10361022ADDRESS_MAP_END
10371023
10381024
r32562r32563
10401026   AM_RANGE(0x0000, 0x7fff) AM_ROM
10411027   AM_RANGE(0x8000, 0x87ff) AM_RAM
10421028   AM_RANGE(0xa000, 0xa001) AM_DEVREADWRITE("ymsnd", ym2151_device, read, write)
1043   AM_RANGE(0xc000, 0xc02f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
1029   AM_RANGE(0xc000, 0xc02f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
10441030ADDRESS_MAP_END
10451031
10461032
10471033static ADDRESS_MAP_START( glfgreat_audio_map, AS_PROGRAM, 8, tmnt_state )
10481034   AM_RANGE(0x0000, 0x7fff) AM_ROM
10491035   AM_RANGE(0xf000, 0xf7ff) AM_RAM
1050   AM_RANGE(0xf800, 0xf82f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
1036   AM_RANGE(0xf800, 0xf82f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
10511037   AM_RANGE(0xfa00, 0xfa00) AM_WRITE(sound_arm_nmi_w)
10521038ADDRESS_MAP_END
10531039
r32562r32563
10561042   AM_RANGE(0x0000, 0xefff) AM_ROM
10571043   AM_RANGE(0xf000, 0xf7ff) AM_RAM
10581044   AM_RANGE(0xf800, 0xf801) AM_DEVREADWRITE("ymsnd", ym2151_device, read, write)
1059   AM_RANGE(0xfa00, 0xfa2f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
1045   AM_RANGE(0xfa00, 0xfa2f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
10601046   AM_RANGE(0xfc00, 0xfc00) AM_WRITE(sound_arm_nmi_w)
10611047ADDRESS_MAP_END
10621048
r32562r32563
10661052   AM_RANGE(0xf000, 0xf7ff) AM_RAM
10671053   AM_RANGE(0xf800, 0xf801) AM_MIRROR(0x0010) AM_DEVREADWRITE("ymsnd", ym2151_device, read, write)
10681054   AM_RANGE(0xfa00, 0xfa00) AM_WRITE(sound_arm_nmi_w)
1069   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
1055   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
10701056ADDRESS_MAP_END
10711057
10721058
trunk/src/mame/drivers/simpsons.c
r32562r32563
124124   AM_RANGE(0x1fc0, 0x1fc0) AM_WRITE(simpsons_coin_counter_w)
125125   AM_RANGE(0x1fc2, 0x1fc2) AM_WRITE(simpsons_eeprom_w)
126126   AM_RANGE(0x1fc4, 0x1fc4) AM_READ(simpsons_sound_interrupt_r)
127   AM_RANGE(0x1fc6, 0x1fc7) AM_READ(simpsons_sound_r) AM_DEVWRITE("k053260", k053260_device, k053260_w)
127   AM_RANGE(0x1fc6, 0x1fc7) AM_DEVREADWRITE("k053260", k053260_device, main_read, main_write)
128128   AM_RANGE(0x1fc8, 0x1fc9) AM_DEVREAD("k053246", k053247_device, k053246_r)
129129   AM_RANGE(0x1fca, 0x1fca) AM_READ(watchdog_reset_r)
130130   AM_RANGE(0x0000, 0x1fff) AM_DEVREADWRITE("k052109", k052109_device, read, write)
r32562r32563
188188   AM_RANGE(0xf000, 0xf7ff) AM_RAM
189189   AM_RANGE(0xf800, 0xf801) AM_DEVREADWRITE("ymsnd", ym2151_device, read, write)
190190   AM_RANGE(0xfa00, 0xfa00) AM_WRITE(z80_arm_nmi_w)
191   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
191   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
192192   AM_RANGE(0xfe00, 0xfe00) AM_WRITE(z80_bankswitch_w)
193193ADDRESS_MAP_END
194194
trunk/src/mame/drivers/asterix.c
r32562r32563
5050   device.execute().set_input_line(5, HOLD_LINE); /* ??? All irqs have the same vector, and the mask used is 0 or 7 */
5151}
5252
53READ8_MEMBER(asterix_state::asterix_sound_r)
54{
55   return m_k053260->k053260_r(space, 2 + offset);
56}
57
5853void asterix_state::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
5954{
6055   switch (id)
r32562r32563
170165   AM_RANGE(0x380000, 0x380001) AM_READ_PORT("IN0")
171166   AM_RANGE(0x380002, 0x380003) AM_READ_PORT("IN1")
172167   AM_RANGE(0x380100, 0x380101) AM_WRITE(control2_w)
173   AM_RANGE(0x380200, 0x380203) AM_READ8(asterix_sound_r, 0x00ff) AM_DEVWRITE8("k053260", k053260_device, k053260_w, 0x00ff)
168   AM_RANGE(0x380200, 0x380203) AM_DEVREADWRITE8("k053260", k053260_device, main_read, main_write, 0x00ff)
174169   AM_RANGE(0x380300, 0x380301) AM_WRITE(sound_irq_w)
175170   AM_RANGE(0x380400, 0x380401) AM_WRITE(asterix_spritebank_w)
176171   AM_RANGE(0x380500, 0x38051f) AM_DEVWRITE("k053251", k053251_device, lsb_w)
r32562r32563
186181   AM_RANGE(0x0000, 0xefff) AM_ROM
187182   AM_RANGE(0xf000, 0xf7ff) AM_RAM
188183   AM_RANGE(0xf801, 0xf801) AM_DEVREADWRITE("ymsnd", ym2151_device, status_r, data_w)
189   AM_RANGE(0xfa00, 0xfa2f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
184   AM_RANGE(0xfa00, 0xfa2f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
190185   AM_RANGE(0xfc00, 0xfc00) AM_WRITE(sound_arm_nmi_w)
191186   AM_RANGE(0xfe00, 0xfe00) AM_DEVWRITE("ymsnd", ym2151_device, register_w)
192187ADDRESS_MAP_END
trunk/src/mame/drivers/overdriv.c
r32562r32563
123123   }
124124}
125125
126
127READ8_MEMBER(overdriv_state::overdriv_1_sound_r)
128{
129   return m_k053260_1->k053260_r(space, 2 + offset);
130}
131
132READ8_MEMBER(overdriv_state::overdriv_2_sound_r)
133{
134   return m_k053260_2->k053260_r(space, 2 + offset);
135}
136
137126WRITE16_MEMBER(overdriv_state::overdriv_soundirq_w)
138127{
139128   m_audiocpu->set_input_line(M6809_IRQ_LINE, HOLD_LINE);
r32562r32563
162151   AM_RANGE(0x1c0000, 0x1c001f) AM_DEVWRITE8("k051316_1", k051316_device, ctrl_w, 0xff00)
163152   AM_RANGE(0x1c8000, 0x1c801f) AM_DEVWRITE8("k051316_2", k051316_device, ctrl_w, 0xff00)
164153   AM_RANGE(0x1d0000, 0x1d001f) AM_DEVWRITE("k053251", k053251_device, msb_w)
165   AM_RANGE(0x1d8000, 0x1d8003) AM_READ8(overdriv_1_sound_r, 0x00ff) AM_DEVWRITE8("k053260_1", k053260_device, k053260_w, 0x00ff)   /* K053260 */
166   AM_RANGE(0x1e0000, 0x1e0003) AM_READ8(overdriv_2_sound_r, 0x00ff) AM_DEVWRITE8("k053260_2", k053260_device, k053260_w, 0x00ff)   /* K053260 */
154   AM_RANGE(0x1d8000, 0x1d8003) AM_DEVREADWRITE8("k053260_1", k053260_device, main_read, main_write, 0x00ff)
155   AM_RANGE(0x1e0000, 0x1e0003) AM_DEVREADWRITE8("k053260_2", k053260_device, main_read, main_write, 0x00ff)
167156   AM_RANGE(0x1e8000, 0x1e8001) AM_WRITE(overdriv_soundirq_w)
168157   AM_RANGE(0x1f0000, 0x1f0001) AM_WRITE(cpuA_ctrl_w)  /* halt cpu B, coin counter, start lamp, other? */
169158   AM_RANGE(0x1f8000, 0x1f8001) AM_WRITE(eeprom_w)
r32562r32563
218207
219208static ADDRESS_MAP_START( overdriv_sound_map, AS_PROGRAM, 8, overdriv_state )
220209   AM_RANGE(0x0200, 0x0201) AM_DEVREADWRITE("ymsnd", ym2151_device,read,write)
221   AM_RANGE(0x0400, 0x042f) AM_DEVREADWRITE("k053260_1", k053260_device, k053260_r, k053260_w)
222   AM_RANGE(0x0600, 0x062f) AM_DEVREADWRITE("k053260_2", k053260_device, k053260_r, k053260_w)
210   AM_RANGE(0x0400, 0x042f) AM_DEVREADWRITE("k053260_1", k053260_device, read, write)
211   AM_RANGE(0x0600, 0x062f) AM_DEVREADWRITE("k053260_2", k053260_device, read, write)
223212   AM_RANGE(0x0800, 0x0fff) AM_RAM
224213   AM_RANGE(0x1000, 0xffff) AM_ROM
225214ADDRESS_MAP_END
trunk/src/mame/drivers/parodius.c
r32562r32563
5353   /* other bits unknown */
5454}
5555
56READ8_MEMBER(parodius_state::parodius_sound_r)
57{
58   return m_k053260->k053260_r(space, 2 + offset);
59}
60
6156WRITE8_MEMBER(parodius_state::parodius_sh_irqtrigger_w)
6257{
6358   m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff);
r32562r32563
105100   AM_RANGE(0x3fc0, 0x3fc0) AM_READ(watchdog_reset_r) AM_WRITE(parodius_3fc0_w)
106101   AM_RANGE(0x3fc4, 0x3fc4) AM_WRITE(parodius_videobank_w)
107102   AM_RANGE(0x3fc8, 0x3fc8) AM_WRITE(parodius_sh_irqtrigger_w)
108   AM_RANGE(0x3fcc, 0x3fcd) AM_READ(parodius_sound_r) AM_DEVWRITE("k053260", k053260_device, k053260_w) /* K053260 */
103   AM_RANGE(0x3fcc, 0x3fcd) AM_DEVREADWRITE("k053260", k053260_device, main_read, main_write)
109104   AM_RANGE(0x2000, 0x27ff) AM_DEVICE("bank2000", address_map_bank_device, amap8)
110105   AM_RANGE(0x2000, 0x5fff) AM_DEVREADWRITE("k052109", k052109_device, read, write)
111106   AM_RANGE(0x6000, 0x9fff) AM_ROMBANK("bank1")            /* banked ROM */
r32562r32563
127122   AM_RANGE(0xf000, 0xf7ff) AM_RAM
128123   AM_RANGE(0xf800, 0xf801) AM_DEVREADWRITE("ymsnd", ym2151_device,read,write)
129124   AM_RANGE(0xfa00, 0xfa00) AM_WRITE(sound_arm_nmi_w)
130   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
125   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
131126ADDRESS_MAP_END
132127
133128
trunk/src/mame/drivers/vendetta.c
r32562r32563
203203   m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff);
204204}
205205
206READ8_MEMBER(vendetta_state::vendetta_sound_interrupt_r)
206READ8_MEMBER(vendetta_state::z80_irq_r)
207207{
208208   m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff);
209209   return 0x00;
210210}
211211
212READ8_MEMBER(vendetta_state::vendetta_sound_r)
213{
214   return m_k053260->k053260_r(space, 2 + offset);
215}
216
217212/********************************************/
218213
219214static ADDRESS_MAP_START( main_map, AS_PROGRAM, 8, vendetta_state )
r32562r32563
230225   AM_RANGE(0x5fd1, 0x5fd1) AM_READ_PORT("SERVICE")
231226   AM_RANGE(0x5fe0, 0x5fe0) AM_WRITE(vendetta_5fe0_w)
232227   AM_RANGE(0x5fe2, 0x5fe2) AM_WRITE(vendetta_eeprom_w)
233   AM_RANGE(0x5fe4, 0x5fe4) AM_READWRITE(vendetta_sound_interrupt_r, z80_irq_w)
234   AM_RANGE(0x5fe6, 0x5fe7) AM_READ(vendetta_sound_r) AM_DEVWRITE("k053260", k053260_device, k053260_w)
228   AM_RANGE(0x5fe4, 0x5fe4) AM_READWRITE(z80_irq_r, z80_irq_w)
229   AM_RANGE(0x5fe6, 0x5fe7) AM_DEVREADWRITE("k053260", k053260_device, main_read, main_write)
235230   AM_RANGE(0x5fe8, 0x5fe9) AM_DEVREAD("k053246", k053247_device, k053246_r)
236231   AM_RANGE(0x5fea, 0x5fea) AM_READ(watchdog_reset_r)
237232   /* what is the desired effect of overlapping these memory regions anyway? */
r32562r32563
254249   AM_RANGE(0x3fc0, 0x3fcf) AM_DEVREADWRITE("k053252", k053252_device, read, write)              // Not Emulated (053252 ???)
255250   AM_RANGE(0x3fd0, 0x3fd0) AM_WRITE(vendetta_5fe0_w)      // Coin Counter, 052109 RMRD, 053246 OBJCHA
256251   AM_RANGE(0x3fd2, 0x3fd2) AM_WRITE(vendetta_eeprom_w)    // EEPROM, Video banking
257   AM_RANGE(0x3fd4, 0x3fd4) AM_READWRITE(vendetta_sound_interrupt_r, z80_irq_w)            // Sound
258   AM_RANGE(0x3fd6, 0x3fd7) AM_READ(vendetta_sound_r) AM_DEVWRITE("k053260", k053260_device, k053260_w)     // Sound
252   AM_RANGE(0x3fd4, 0x3fd4) AM_READWRITE(z80_irq_r, z80_irq_w)            // Sound
253   AM_RANGE(0x3fd6, 0x3fd7) AM_DEVREADWRITE("k053260", k053260_device, main_read, main_write) // Sound
259254   AM_RANGE(0x3fd8, 0x3fd9) AM_DEVREAD("k053246", k053247_device, k053246_r)                // 053246 (Sprite)
260255   AM_RANGE(0x3fda, 0x3fda) AM_WRITENOP                // Not Emulated (Watchdog ???)
261256   /* what is the desired effect of overlapping these memory regions anyway? */
r32562r32563
272267   AM_RANGE(0xf000, 0xf7ff) AM_RAM
273268   AM_RANGE(0xf800, 0xf801) AM_DEVREADWRITE("ymsnd", ym2151_device, read, write)
274269   AM_RANGE(0xfa00, 0xfa00) AM_WRITE(z80_arm_nmi_w)
275   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, k053260_r, k053260_w)
270   AM_RANGE(0xfc00, 0xfc2f) AM_DEVREADWRITE("k053260", k053260_device, read, write)
276271ADDRESS_MAP_END
277272
278273
trunk/src/mame/machine/simpsons.c
r32562r32563
22
33#include "cpu/m6809/konami.h"
44#include "machine/eepromser.h"
5#include "sound/k053260.h"
65#include "includes/simpsons.h"
76
87/***************************************************************************
r32562r32563
4847   return 0x00;
4948}
5049
51READ8_MEMBER(simpsons_state::simpsons_sound_r)
52{
53   return m_k053260->k053260_r(space, 2 + offset);
54}
5550
56
5751/***************************************************************************
5852
5953  Banking, initialization
trunk/src/mame/includes/asterix.h
r32562r32563
33    Asterix
44
55*************************************************************************/
6#include "sound/k053260.h"
76#include "video/k053251.h"
87#include "video/k054156_k054157_k056832.h"
98#include "video/k053244_k053245.h"
r32562r32563
2120      : driver_device(mconfig, type, tag),
2221      m_maincpu(*this, "maincpu"),
2322      m_audiocpu(*this, "audiocpu"),
24      m_k053260(*this, "k053260"),
2523      m_k056832(*this, "k056832"),
2624      m_k053244(*this, "k053244"),
2725      m_k053251(*this, "k053251") { }
r32562r32563
4442   /* devices */
4543   required_device<cpu_device> m_maincpu;
4644   required_device<cpu_device> m_audiocpu;
47   required_device<k053260_device> m_k053260;
4845   required_device<k056832_device> m_k056832;
4946   required_device<k05324x_device> m_k053244;
5047   required_device<k053251_device> m_k053251;
r32562r32563
5451   DECLARE_WRITE16_MEMBER(sound_irq_w);
5552   DECLARE_WRITE16_MEMBER(protection_w);
5653   DECLARE_WRITE16_MEMBER(asterix_spritebank_w);
57   DECLARE_READ8_MEMBER(asterix_sound_r);
5854   DECLARE_DRIVER_INIT(asterix);
5955   virtual void machine_start();
6056   virtual void machine_reset();
trunk/src/mame/includes/rollerg.h
r32562r32563
33    Rollergames
44
55*************************************************************************/
6#include "sound/k053260.h"
76#include "machine/k053252.h"
87#include "video/k051316.h"
98#include "video/konami_helper.h"
r32562r32563
2120      : driver_device(mconfig, type, tag),
2221      m_maincpu(*this, "maincpu"),
2322      m_audiocpu(*this, "audiocpu"),
24      m_k053260(*this, "k053260"),
2523      m_k053244(*this, "k053244"),
2624      m_k051316(*this, "k051316"),
2725      m_k053252(*this, "k053252")
2826      { }
2927
30   /* memory pointers */
31//  UINT8 *    m_paletteram;    // currently this uses generic palette handling
32
3328   /* video-related */
3429   int        m_sprite_colorbase;
3530   int        m_zoom_colorbase;
r32562r32563
4035   /* devices */
4136   required_device<cpu_device> m_maincpu;
4237   required_device<cpu_device> m_audiocpu;
43   required_device<k053260_device> m_k053260;
4438   required_device<k05324x_device> m_k053244;
4539   required_device<k051316_device> m_k051316;
4640   required_device<k053252_device> m_k053252;
r32562r32563
4943   DECLARE_WRITE8_MEMBER(soundirq_w);
5044   DECLARE_WRITE8_MEMBER(sound_arm_nmi_w);
5145   DECLARE_READ8_MEMBER(pip_r);
52   DECLARE_READ8_MEMBER(rollerg_sound_r);
5346   DECLARE_WRITE_LINE_MEMBER(rollerg_irq_ack_w);
5447   virtual void machine_start();
5548   virtual void machine_reset();
trunk/src/mame/includes/simpsons.h
r32562r32563
11#include "machine/bankdev.h"
2#include "sound/k053260.h"
32#include "video/k053246_k053247_k055673.h"
43#include "video/k052109.h"
54#include "video/k053251.h"
r32562r32563
2019      m_audiocpu(*this, "audiocpu"),
2120      m_bank0000(*this, "bank0000"),
2221      m_bank2000(*this, "bank2000"),
23      m_k053260(*this, "k053260"),
2422      m_k052109(*this, "k052109"),
2523      m_k053246(*this, "k053246"),
2624      m_k053251(*this, "k053251") { }
r32562r32563
4240   required_device<cpu_device> m_audiocpu;
4341   required_device<address_map_bank_device> m_bank0000;
4442   required_device<address_map_bank_device> m_bank2000;
45   required_device<k053260_device> m_k053260;
4643   required_device<k052109_device> m_k052109;
4744   required_device<k053247_device> m_k053246;
4845   required_device<k053251_device> m_k053251;
r32562r32563
6158   INTERRUPT_GEN_MEMBER(simpsons_irq);
6259   TIMER_CALLBACK_MEMBER(nmi_callback);
6360   TIMER_CALLBACK_MEMBER(dmaend_callback);
64   DECLARE_READ8_MEMBER(simpsons_sound_r);
6561   void simpsons_video_banking(int bank);
6662   void sound_nmi_callback(int param);
6763   void simpsons_objdma();
trunk/src/mame/includes/tmnt.h
r32562r32563
134134   DECLARE_READ16_MEMBER(prmrsocr_rom_r);
135135   DECLARE_WRITE16_MEMBER(tmnt_priority_w);
136136   DECLARE_READ16_MEMBER(glfgreat_ball_r);
137   DECLARE_READ8_MEMBER(punkshot_sound_r);
138137   DECLARE_WRITE8_MEMBER(glfgreat_sound_w);
139138   DECLARE_WRITE8_MEMBER(tmnt_upd_start_w);
140139   DECLARE_READ8_MEMBER(tmnt_upd_busy_r);
trunk/src/mame/includes/overdriv.h
r32562r32563
33    Over Drive
44
55*************************************************************************/
6#include "sound/k053260.h"
76#include "machine/k053252.h"
87#include "video/k051316.h"
98#include "video/k053246_k053247_k055673.h"
r32562r32563
1817      m_maincpu(*this, "maincpu"),
1918      m_subcpu(*this, "sub"),
2019      m_audiocpu(*this, "audiocpu"),
21      m_k053260_1(*this, "k053260_1"),
22      m_k053260_2(*this, "k053260_2"),
2320      m_k051316_1(*this, "k051316_1"),
2421      m_k051316_2(*this, "k051316_2"),
2522      m_k053246(*this, "k053246"),
r32562r32563
4441   required_device<cpu_device> m_maincpu;
4542   required_device<cpu_device> m_subcpu;
4643   required_device<cpu_device> m_audiocpu;
47   required_device<k053260_device> m_k053260_1;
48   required_device<k053260_device> m_k053260_2;
4944   required_device<k051316_device> m_k051316_1;
5045   required_device<k051316_device> m_k051316_2;
5146   required_device<k053247_device> m_k053246;
trunk/src/mame/includes/parodius.h
r32562r32563
55*************************************************************************/
66
77#include "machine/bankdev.h"
8#include "sound/k053260.h"
98#include "video/k053244_k053245.h"
109#include "video/k052109.h"
1110#include "video/k053251.h"
r32562r32563
2524      m_audiocpu(*this, "audiocpu"),
2625      m_bank0000(*this, "bank0000"),
2726      m_bank2000(*this, "bank2000"),
28      m_k053260(*this, "k053260"),
2927      m_k052109(*this, "k052109"),
3028      m_k053245(*this, "k053245"),
3129      m_k053251(*this, "k053251") { }
r32562r32563
4341   required_device<cpu_device> m_audiocpu;
4442   required_device<address_map_bank_device> m_bank0000;
4543   required_device<address_map_bank_device> m_bank2000;
46   required_device<k053260_device> m_k053260;
4744   required_device<k052109_device> m_k052109;
4845   required_device<k05324x_device> m_k053245;
4946   required_device<k053251_device> m_k053251;
r32562r32563
5148   DECLARE_WRITE8_MEMBER(parodius_3fc0_w);
5249   DECLARE_WRITE8_MEMBER(parodius_sh_irqtrigger_w);
5350   DECLARE_WRITE8_MEMBER(sound_arm_nmi_w);
54   DECLARE_READ8_MEMBER(parodius_sound_r);
5551   virtual void machine_start();
5652   virtual void machine_reset();
5753   UINT32 screen_update_parodius(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
trunk/src/mame/includes/vendetta.h
r32562r32563
33    Vendetta
44
55*************************************************************************/
6#include "sound/k053260.h"
76#include "machine/k053252.h"
87#include "video/k053246_k053247_k055673.h"
98#include "video/k054000.h"
r32562r32563
2322      : driver_device(mconfig, type, tag),
2423      m_maincpu(*this, "maincpu"),
2524      m_audiocpu(*this, "audiocpu"),
26      m_k053260(*this, "k053260"),
2725      m_k052109(*this, "k052109"),
2826      m_k053246(*this, "k053246"),
2927      m_k053251(*this, "k053251"),
r32562r32563
4644   /* devices */
4745   required_device<cpu_device> m_maincpu;
4846   required_device<cpu_device> m_audiocpu;
49   required_device<k053260_device> m_k053260;
5047   required_device<k052109_device> m_k052109;
5148   required_device<k053247_device> m_k053246;
5249   required_device<k053251_device> m_k053251;
r32562r32563
5956   DECLARE_WRITE8_MEMBER(vendetta_5fe0_w);
6057   DECLARE_WRITE8_MEMBER(z80_arm_nmi_w);
6158   DECLARE_WRITE8_MEMBER(z80_irq_w);
62   DECLARE_READ8_MEMBER(vendetta_sound_interrupt_r);
63   DECLARE_READ8_MEMBER(vendetta_sound_r);
59   DECLARE_READ8_MEMBER(z80_irq_r);
6460   DECLARE_DRIVER_INIT(vendetta);
6561   DECLARE_DRIVER_INIT(esckids);
6662   virtual void machine_start();
trunk/src/emu/sound/k053260.c
r32562r32563
11/*********************************************************
22
3    Konami 053260 PCM Sound Chip
3    Konami 053260 KDSC
44
5    The 053260 is a four voice PCM/ADPCM sound chip that
6    also incorporates four 8-bit ports for communication
7    between a main CPU and audio CPU. The chip's output
8    is compatible with a YM3012 DAC, and it has a digital
9    auxiliary input compatible with the output of a YM2151.
10    Some games (e.g. Simpsons) only connect one channel of
11    the YM2151, but others (e.g. Thunder Cross II) connect
12    both channels for stereo mixing.
13
14    The 053260 has a 21-bit address bus and 8-bit data bus
15    to ROM, allowing it to access up to 2 megabytes of
16    sample data. Sample data can be either signed 8-bit
17    PCM or a custom 4-bit ADPCM format. It is possible for
18    two 053260 chips to share access to the same ROMs
19    (used by Over Drive)
20
21    The 053260 has separate address and data buses to the
22    audio CPU controlling it and to the main CPU. Both data
23    buses are 8 bit. The audio CPU address bus has 6 lines
24    (64 addressable registers, but fewer than 48 are
25    actually used) while the main CPU "bus" has only 1 line
26    (2 addressable registers). All registers on the audio
27    CPU side seem to be either read-only or write-only,
28    although some games write 0 to all the registers in a
29    loop at startup (including otherwise read-only or
30    entirely unused registers).
31    On the main CPU side, reads and writes to the same
32    address access different communication ports.
33
34    The sound data ROMs of Simpsons and Vendetta have
35    "headers" listing all the samples in the ROM, their
36    formats ("PCM" or "KADPCM"), start and end addresses.
37    The header data doesn't seem to be used by the hardware
38    (none of the other games have headers) but provides
39    useful information about the chip.
40
41    2004-02-28 (Oliver Achten)
42    Fixed ADPCM decoding. Games sound much better now.
43
44    2014-10-06 (Alex W. Jackson)
45    Rewrote from scratch in C++; implemented communication
46    ports properly; used the actual up counters instead of
47    converting to fractional sample position; fixed ADPCM
48    decoding bugs; added documentation.
49
50
551*********************************************************/
652
753#include "emu.h"
854#include "k053260.h"
955
10/* 2004-02-28: Fixed PPCM decoding. Games sound much better now.*/
11
1256#define LOG 0
1357
14#define BASE_SHIFT 16
58#define CLOCKS_PER_SAMPLE 32
1559
1660
61
1762// device type definition
1863const device_type K053260 = &device_creator<k053260_device>;
1964
r32562r32563
2772//-------------------------------------------------
2873
2974k053260_device::k053260_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
30   : device_t(mconfig, K053260, "K053260 PCM", tag, owner, clock, "k053260", __FILE__),
75   : device_t(mconfig, K053260, "K053260 KDSC", tag, owner, clock, "k053260", __FILE__),
3176      device_sound_interface(mconfig, *this),
32      m_channel(NULL),
33      m_mode(0),
77      m_rgnoverride(NULL),
78      m_stream(NULL),
3479      m_rom(NULL),
3580      m_rom_size(0),
36      m_delta_table(NULL),
37      m_rgnoverride(NULL)
81      m_keyon(0),
82      m_mode(0)
3883{
39   memset(m_regs, 0, sizeof(int)*0x30);
84   memset(m_portdata, 0, sizeof(m_portdata));
4085}
4186
4287
r32562r32563
4691
4792void k053260_device::device_start()
4893{
49   int rate = clock() / 32;
94   memory_region *ROM = (m_rgnoverride) ? owner()->memregion(m_rgnoverride) : region();
95   m_rom = *ROM;
96   m_rom_size = ROM->bytes();
5097
51   m_mode = 0;
98   m_stream = stream_alloc( 0, 2, clock() / CLOCKS_PER_SAMPLE );
5299
53   memory_region *region = (m_rgnoverride) ? memregion(m_rgnoverride) : this->region();
54   m_rom = *region;
55   m_rom_size = region->bytes();
56
57   device_reset();
58
59   for (int i = 0; i < 0x30; i++)
60      m_regs[i] = 0;
61
62   m_delta_table = auto_alloc_array( machine(), UINT32, 0x1000 );
63
64   m_channel = stream_alloc( 0, 2, rate );
65
66   InitDeltaTable( rate, clock() );
67
68100   /* register with the save state system */
101   save_item(NAME(m_portdata));
102   save_item(NAME(m_keyon));
69103   save_item(NAME(m_mode));
70   save_item(NAME(m_regs));
71104
72105   for (int i = 0; i < 4; i++)
73   {
74      save_item(NAME(m_channels[i].rate), i);
75      save_item(NAME(m_channels[i].size), i);
76      save_item(NAME(m_channels[i].start), i);
77      save_item(NAME(m_channels[i].bank), i);
78      save_item(NAME(m_channels[i].volume), i);
79      save_item(NAME(m_channels[i].play), i);
80      save_item(NAME(m_channels[i].pan), i);
81      save_item(NAME(m_channels[i].pos), i);
82      save_item(NAME(m_channels[i].loop), i);
83      save_item(NAME(m_channels[i].ppcm), i);
84      save_item(NAME(m_channels[i].ppcm_data), i);
85   }
106      m_voice[i].voice_start(*this, i);
86107}
87108
88109
r32562r32563
93114void k053260_device::device_reset()
94115{
95116   for (int i = 0; i < 4; i++)
96   {
97      m_channels[i].rate = 0;
98      m_channels[i].size = 0;
99      m_channels[i].start = 0;
100      m_channels[i].bank = 0;
101      m_channels[i].volume = 0;
102      m_channels[i].play = 0;
103      m_channels[i].pan = 0;
104      m_channels[i].pos = 0;
105      m_channels[i].loop = 0;
106      m_channels[i].ppcm = 0;
107      m_channels[i].ppcm_data = 0;
108   }
117      m_voice[i].voice_reset();
109118}
110119
111120
112INLINE int limit( int val, int max, int min )
121READ8_MEMBER( k053260_device::main_read )
113122{
114   if ( val > max )
115      val = max;
116   else if ( val < min )
117      val = min;
123   // sub-to-main ports
124   return m_portdata[2 + (offset & 1)];
125}
118126
119   return val;
127
128WRITE8_MEMBER( k053260_device::main_write )
129{
130   // main-to-sub ports
131   m_portdata[offset & 1] = data;
120132}
121133
122#define MAXOUT 0x7fff
123#define MINOUT -0x8000
124134
125//-------------------------------------------------
126//  sound_stream_update - handle a stream update
127//-------------------------------------------------
128
129void k053260_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
135READ8_MEMBER( k053260_device::read )
130136{
131   static const INT8 dpcmcnv[] = { 0,1,2,4,8,16,32,64, -128, -64, -32, -16, -8, -4, -2, -1};
137   offset &= 0x3f;
138   UINT8 ret = 0;
132139
133   int lvol[4], rvol[4], play[4], loop[4], ppcm[4];
134   UINT8 *rom[4];
135   UINT32 delta[4], end[4], pos[4];
136   INT8 ppcm_data[4];
137   int dataL, dataR;
138   INT8 d;
140   switch (offset)
141   {
142      case 0x00: // main-to-sub ports
143      case 0x01:
144         ret = m_portdata[offset];
145         break;
139146
140   /* precache some values */
141   for ( int i = 0; i < 4; i++ ) {
142      rom[i]= &m_rom[m_channels[i].start + ( m_channels[i].bank << 16 )];
143      delta[i] = m_delta_table[m_channels[i].rate];
144      lvol[i] = m_channels[i].volume * m_channels[i].pan;
145      rvol[i] = m_channels[i].volume * ( 8 - m_channels[i].pan );
146      end[i] = m_channels[i].size;
147      pos[i] = m_channels[i].pos;
148      play[i] = m_channels[i].play;
149      loop[i] = m_channels[i].loop;
150      ppcm[i] = m_channels[i].ppcm;
151      ppcm_data[i] = m_channels[i].ppcm_data;
152      if ( ppcm[i] )
153         delta[i] /= 2;
147      case 0x29: // voice status
148         m_stream->update();
149         for (int i = 0; i < 4; i++)
150            ret |= m_voice[i].playing() << i;
151         break;
152
153      case 0x2e: // read ROM
154         if (m_mode & 1)
155            ret = m_voice[0].read_rom();
156         else
157            logerror("%s: Attempting to read K053260 ROM without mode bit set\n", machine().describe_context());
158         break;
159
160      default:
161         logerror("%s: Read from unknown K053260 register %02x\n", machine().describe_context(), offset);
154162   }
163   return ret;
164}
155165
156      for ( int j = 0; j < samples; j++ ) {
157         dataL = dataR = 0;
158166
159         for ( int i = 0; i < 4; i++ ) {
160            /* see if the voice is on */
161            if ( play[i] ) {
162               /* see if we're done */
163               if ( ( pos[i] >> BASE_SHIFT ) >= end[i] ) {
164                  ppcm_data[i] = 0;
165                  if ( loop[i] )
166                     pos[i] = 0;
167                  else {
168                     play[i] = 0;
169                     continue;
170                  }
171               }
167WRITE8_MEMBER( k053260_device::write )
168{
169   offset &= 0x3f;
172170
173               if ( ppcm[i] ) { /* Packed PCM */
174                  /* we only update the signal if we're starting or a real sound sample has gone by */
175                  /* this is all due to the dynamic sample rate convertion */
176                  if ( pos[i] == 0 || ( ( pos[i] ^ ( pos[i] - delta[i] ) ) & 0x8000 ) == 0x8000 )
171   m_stream->update();
177172
178                  {
179                     int newdata;
180                     if ( pos[i] & 0x8000 ){
181                        newdata = ((rom[i][pos[i] >> BASE_SHIFT]) >> 4) & 0x0f; /*high nybble*/
182                     }
183                     else{
184                        newdata = ( ( rom[i][pos[i] >> BASE_SHIFT] ) ) & 0x0f; /*low nybble*/
185                     }
173   // per voice registers
174   if ((offset >= 0x08) && (offset <= 0x27))
175   {
176      m_voice[(offset - 8) / 8].set_register(offset, data);
177      return;
178   }
186179
187                     ppcm_data[i] += dpcmcnv[newdata];
188                  }
180   switch (offset)
181   {
182      // 0x00 and 0x01 are read registers
189183
184      case 0x02: // sub-to-main ports
185      case 0x03:
186         m_portdata[offset] = data;
187         break;
190188
189      // 0x04 through 0x07 seem to be unused
191190
192                  d = ppcm_data[i];
191      case 0x28: // key on/off
192      {
193         UINT8 rising_edge = data & ~m_keyon;
193194
194                  pos[i] += delta[i];
195               } else { /* PCM */
196                  d = rom[i][pos[i] >> BASE_SHIFT];
195         for (int i = 0; i < 4; i++)
196         {
197            if (rising_edge & (1 << i))
198               m_voice[i].key_on();
199            else if (!(data & (1 << i)))
200               m_voice[i].key_off();
201         }
202         m_keyon = data;
203         break;
204      }
197205
198                  pos[i] += delta[i];
199               }
206      // 0x29 is a read register
200207
201               if ( m_mode & 2 ) {
202                  dataL += ( d * lvol[i] ) >> 2;
203                  dataR += ( d * rvol[i] ) >> 2;
204               }
205            }
208      case 0x2a: // loop and pcm/adpcm select
209         for (int i = 0; i < 4; i++)
210         {
211            m_voice[i].set_loop_kadpcm(data);
212            data >>= 1;
206213         }
214         break;
207215
208         outputs[1][j] = limit( dataL, MAXOUT, MINOUT );
209         outputs[0][j] = limit( dataR, MAXOUT, MINOUT );
210      }
216      // 0x2b seems to be unused
211217
212   /* update the regs now */
213   for ( int i = 0; i < 4; i++ ) {
214      m_channels[i].pos = pos[i];
215      m_channels[i].play = play[i];
216      m_channels[i].ppcm_data = ppcm_data[i];
217   }
218}
218      case 0x2c: // pan, voices 0 and 1
219         m_voice[0].set_pan(data);
220         m_voice[1].set_pan(data >> 3);
221         break;
219222
223      case 0x2d: // pan, voices 2 and 3
224         m_voice[2].set_pan(data);
225         m_voice[3].set_pan(data >> 3);
226         break;
220227
221void k053260_device::InitDeltaTable( int rate, int clock )
222{
223   int     i;
224   double  base = ( double )rate;
225   double  max = (double)(clock); /* Hz */
226   UINT32 val;
228      // 0x2e is a read register
227229
228   for( i = 0; i < 0x1000; i++ ) {
229      double v = ( double )( 0x1000 - i );
230      double target = (max) / v;
231      double fixed = ( double )( 1 << BASE_SHIFT );
230      case 0x2f: // control
231         m_mode = data;
232         // bit 0 = enable ROM read from register 0x2e
233         // bit 1 = enable sound output
234         // bit 2 = enable aux input?
235         //   (set by all games except Golfing Greats and Rollergames, both of which
236         //    don't have a YM2151. Over Drive only sets it on one of the two chips)
237         // bit 3 = aux input or ROM sharing related?
238         //   (only set by Over Drive, and only on the same chip that bit 2 is set on)
239         break;
232240
233      if ( target && base ) {
234         target = fixed / ( base / target );
235         val = ( UINT32 )target;
236         if ( val == 0 )
237            val = 1;
238      } else
239         val = 1;
240
241      m_delta_table[i] = val;
241      default:
242         logerror("%s: Write to unknown K053260 register %02x (data = %02x)\n",
243               machine().describe_context(), offset, data);
242244   }
243245}
244246
245247
246void k053260_device::check_bounds( int channel )
248INLINE int limit( int val, int max, int min )
247249{
248   int channel_start = ( m_channels[channel].bank << 16 ) + m_channels[channel].start;
249   int channel_end = channel_start + m_channels[channel].size - 1;
250   if ( val > max )
251      val = max;
252   else if ( val < min )
253      val = min;
250254
251   if ( channel_start > m_rom_size ) {
252      logerror("K053260: Attempting to start playing past the end of the ROM ( start = %06x, end = %06x ).\n", channel_start, channel_end );
255   return val;
256}
253257
254      m_channels[channel].play = 0;
258#define MAXOUT 0x7fff
259#define MINOUT -0x8000
255260
256      return;
257   }
261//-------------------------------------------------
262//  sound_stream_update - handle a stream update
263//-------------------------------------------------
258264
259   if ( channel_end > m_rom_size ) {
260      logerror("K53260: Attempting to play past the end of the ROM ( start = %06x, end = %06x ).\n", channel_start, channel_end );
265void k053260_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
266{
267   if (m_mode & 2)
268   {
269      for ( int j = 0; j < samples; j++ )
270      {
271         stream_sample_t buffer[2] = {0, 0};
261272
262      m_channels[channel].size = m_rom_size - channel_start;
273         for (int i = 0; i < 4; i++)
274         {
275            KDSC_Voice &voice = m_voice[i];
276            if (voice.playing())
277               voice.play(buffer);
278         }
279
280         outputs[0][j] = limit( buffer[0] >> 1, MAXOUT, MINOUT );
281         outputs[1][j] = limit( buffer[1] >> 1, MAXOUT, MINOUT );
282      }
263283   }
264   if (LOG) logerror("K053260: Sample Start = %06x, Sample End = %06x, Sample rate = %04x, PPCM = %s\n", channel_start, channel_end, m_channels[channel].rate, m_channels[channel].ppcm ? "yes" : "no" );
284   else
285   {
286      memset( outputs[0], 0, samples * sizeof(*outputs[0]));
287      memset( outputs[1], 0, samples * sizeof(*outputs[1]));
288   }
265289}
266290
267291
268WRITE8_MEMBER( k053260_device::k053260_w )
292//**************************************************************************
293//  KDSC_Voice - one of the four voices
294//**************************************************************************
295
296void k053260_device::KDSC_Voice::voice_start(k053260_device &device, int index)
269297{
270   int i, t;
271   int r = offset;
272   int v = data;
298   m_device = &device;
273299
274   if ( r > 0x2f ) {
275      logerror("K053260: Writing past registers\n" );
276      return;
277   }
300   voice_reset();
278301
279      m_channel->update();
302   device.save_item(NAME(m_position), index);
303   device.save_item(NAME(m_pan_volume), index);
304   device.save_item(NAME(m_counter), index);
305   device.save_item(NAME(m_output), index);
306   device.save_item(NAME(m_playing), index);
307   device.save_item(NAME(m_start), index);
308   device.save_item(NAME(m_length), index);
309   device.save_item(NAME(m_pitch), index);
310   device.save_item(NAME(m_volume), index);
311   device.save_item(NAME(m_pan), index);
312   device.save_item(NAME(m_loop), index);
313   device.save_item(NAME(m_kadpcm), index);
314}
280315
281   /* before we update the regs, we need to check for a latched reg */
282   if ( r == 0x28 ) {
283      t = m_regs[r] ^ v;
316void k053260_device::KDSC_Voice::voice_reset()
317{
318   m_position = 0;
319   m_counter = 0;
320   m_output = 0;
321   m_playing = false;
322   m_start = 0;
323   m_length = 0;
324   m_pitch = 0;
325   m_volume = 0;
326   m_pan = 0;
327   m_loop = false;
328   m_kadpcm = false;
329   update_pan_volume();
330}
284331
285      for ( i = 0; i < 4; i++ ) {
286         if ( t & ( 1 << i ) ) {
287            if ( v & ( 1 << i ) ) {
288               m_channels[i].play = 1;
289               m_channels[i].pos = 0;
290               m_channels[i].ppcm_data = 0;
291               check_bounds( i );
292            } else
293               m_channels[i].play = 0;
294         }
295      }
296
297      m_regs[r] = v;
298      return;
299   }
300
301   /* update regs */
302   m_regs[r] = v;
303
304   /* communication registers */
305   if ( r < 8 )
306      return;
307
308   /* channel setup */
309   if ( r < 0x28 ) {
310      int channel = ( r - 8 ) / 8;
311
312      switch ( ( r - 8 ) & 0x07 ) {
313         case 0: /* sample rate low */
314            m_channels[channel].rate &= 0x0f00;
315            m_channels[channel].rate |= v;
332void k053260_device::KDSC_Voice::set_register(offs_t offset, UINT8 data)
333{
334   switch (offset & 0x7)
335   {
336      case 0: // pitch, lower 8 bits
337         m_pitch = (m_pitch & 0x0f00) | data;
316338         break;
317
318         case 1: /* sample rate high */
319            m_channels[channel].rate &= 0x00ff;
320            m_channels[channel].rate |= ( v & 0x0f ) << 8;
339      case 1: // pitch, upper 4 bits
340         m_pitch = (m_pitch & 0x00ff) | ((data << 8) & 0x0f00);
321341         break;
322
323         case 2: /* size low */
324            m_channels[channel].size &= 0xff00;
325            m_channels[channel].size |= v;
342      case 2: // length, lower 8 bits
343         m_length = (m_length & 0xff00) | data;
326344         break;
327
328         case 3: /* size high */
329            m_channels[channel].size &= 0x00ff;
330            m_channels[channel].size |= v << 8;
345      case 3: // length, upper 8 bits
346         m_length = (m_length & 0x00ff) | (data << 8);
331347         break;
332
333         case 4: /* start low */
334            m_channels[channel].start &= 0xff00;
335            m_channels[channel].start |= v;
348      case 4: // start, lower 8 bits
349         m_start = (m_start & 0x1fff00) | data;
336350         break;
337
338         case 5: /* start high */
339            m_channels[channel].start &= 0x00ff;
340            m_channels[channel].start |= v << 8;
351      case 5: // start, middle 8 bits
352         m_start = (m_start & 0x1f00ff) | (data << 8);
341353         break;
342
343         case 6: /* bank */
344            m_channels[channel].bank = v & 0xff;
354      case 6: // start, upper 5 bits
355         m_start = (m_start & 0x00ffff) | ((data << 16) & 0x1f0000);
345356         break;
357      case 7: // volume, 7 bits
358         m_volume = data & 0x7f;
359         update_pan_volume();
360   }
361}
346362
347         case 7: /* volume is 7 bits. Convert to 8 bits now. */
348            m_channels[channel].volume = ( ( v & 0x7f ) << 1 ) | ( v & 1 );
349         break;
350      }
363void k053260_device::KDSC_Voice::set_loop_kadpcm(UINT8 data)
364{
365   m_loop = BIT(data, 0);
366   m_kadpcm = BIT(data, 4);
367}
351368
352      return;
353   }
369void k053260_device::KDSC_Voice::set_pan(UINT8 data)
370{
371   m_pan = data & 0x7;
372   update_pan_volume();
373}
354374
355   switch( r ) {
356      case 0x2a: /* loop, ppcm */
357         for ( i = 0; i < 4; i++ )
358            m_channels[i].loop = ( v & ( 1 << i ) ) != 0;
375void k053260_device::KDSC_Voice::update_pan_volume()
376{
377   m_pan_volume[0] = m_volume * (8 - m_pan);
378   m_pan_volume[1] = m_volume * m_pan;
379}
359380
360         for ( i = 4; i < 8; i++ )
361            m_channels[i-4].ppcm = ( v & ( 1 << i ) ) != 0;
362      break;
381void k053260_device::KDSC_Voice::key_on()
382{
383   if (m_start >= m_device->m_rom_size)
384      logerror("K053260: Attempting to start playing past the end of the ROM ( start = %06x, length = %06x )\n", m_start, m_length);
363385
364      case 0x2c: /* pan */
365         m_channels[0].pan = v & 7;
366         m_channels[1].pan = ( v >> 3 ) & 7;
367      break;
386   else if (m_start + m_length >= m_device->m_rom_size)
387      logerror("K053260: Attempting to play past the end of the ROM ( start = %06x, length = %06x )\n",
388             m_start, m_length);
368389
369      case 0x2d: /* more pan */
370         m_channels[2].pan = v & 7;
371         m_channels[3].pan = ( v >> 3 ) & 7;
372      break;
373
374      case 0x2f: /* control */
375         m_mode = v & 7;
376         /* bit 0 = read ROM */
377         /* bit 1 = enable sound output */
378         /* bit 2 = unknown */
379      break;
390   else
391   {
392      m_position = m_kadpcm; // for kadpcm low bit is nybble offset, so must start at 1 due to preincrement
393      m_counter = 0x1000 - CLOCKS_PER_SAMPLE; // force update on next sound_stream_update
394      m_output = 0;
395      m_playing = true;
396      if (LOG) logerror("K053260: start = %06x, length = %06x, pitch = %04x, vol = %02x, loop = %s, %s\n",
397                  m_start, m_length, m_pitch, m_volume, m_loop ? "yes" : "no", m_kadpcm ? "KADPCM" : "PCM" );
380398   }
381399}
382400
383READ8_MEMBER( k053260_device::k053260_r )
401void k053260_device::KDSC_Voice::key_off()
384402{
385   switch ( offset ) {
386      case 0x29: /* channel status */
387         {
388            int i, status = 0;
403   m_position = 0;
404   m_output = 0;
405   m_playing = false;
406}
389407
390            for ( i = 0; i < 4; i++ )
391               status |= m_channels[i].play << i;
408void k053260_device::KDSC_Voice::play(stream_sample_t *outputs)
409{
410   m_counter += CLOCKS_PER_SAMPLE;
392411
393            return status;
394         }
412   while (m_counter >= 0x1000)
413   {
414      m_counter = m_counter - 0x1000 + m_pitch;
395415
396      case 0x2e: /* read ROM */
397         if ( m_mode & 1 )
416      UINT32 bytepos = ++m_position >> m_kadpcm;
417      /*
418      Yes, _pre_increment. Playback must start 1 byte position after the
419      start address written to the register, or else ADPCM sounds will
420      have DC offsets (e.g. TMNT2 theme song) or will overflow and be
421      distorted (e.g. various Vendetta sound effects)
422      The "headers" in the Simpsons and Vendetta sound ROMs provide
423      further evidence of this quirk (the start addresses listed in the
424      ROM header are all 1 greater than the addresses the CPU writes
425      into the register)
426      */
427      if (bytepos > m_length)
428      {
429         if (m_loop)
398430         {
399            UINT32 offs = m_channels[0].start + ( m_channels[0].pos >> BASE_SHIFT ) + ( m_channels[0].bank << 16 );
431            m_position = m_output = bytepos = 0;
432         }
433         else
434         {
435            m_playing = false;
436            return;
437         }
438      }
400439
401            m_channels[0].pos += ( 1 << 16 );
440      UINT8 romdata = m_device->m_rom[m_start + bytepos];
402441
403            if ( offs > m_rom_size ) {
404               logerror("%s: K53260: Attempting to read past ROM size in ROM Read Mode (offs = %06x, size = %06x).\n", machine().describe_context(),offs,m_rom_size );
442      if (m_kadpcm)
443      {
444         if (m_position & 1) romdata >>= 4; // decode low nybble, then high nybble
445         static const INT8 kadpcm_table[] = {0,1,2,4,8,16,32,64,-128,-64,-32,-16,-8,-4,-2,-1};
446         m_output += kadpcm_table[romdata & 0xf];
447      }
448      else
449      {
450         m_output = romdata;
451      }
452   }
405453
406               return 0;
407            }
454   outputs[0] += m_output * m_pan_volume[0];
455   outputs[1] += m_output * m_pan_volume[1];
456}
408457
409            return m_rom[offs];
410         }
411      break;
458UINT8 k053260_device::KDSC_Voice::read_rom()
459{
460   UINT32 offs = m_start + m_position;
461
462   m_position = (m_position + 1) & 0xffff;
463
464   if (offs >= m_device->m_rom_size)
465   {
466      logerror("%s: K053260: Attempting to read past the end of the ROM (offs = %06x, size = %06x)\n",
467             m_device->machine().describe_context(), offs, m_device->m_rom_size);
468      return 0;
412469   }
413470
414   return m_regs[offset];
471   return m_device->m_rom[offs];
415472}
trunk/src/emu/sound/k053260.h
r32562r32563
11/*********************************************************
22
3    Konami 053260 PCM/ADPCM Sound Chip
3    Konami 053260 KDSC
44
55*********************************************************/
66
r32562r32563
2727//  TYPE DEFINITIONS
2828//**************************************************************************
2929
30struct k053260_channel
31{
32   k053260_channel() :
33      rate(0),
34      size(0),
35      start(0),
36      bank(0),
37      volume(0),
38      play(0),
39      pan(0),
40      pos(0),
41      loop(0),
42      ppcm(0),
43      ppcm_data(0) {}
44
45   UINT32      rate;
46   UINT32      size;
47   UINT32      start;
48   UINT32      bank;
49   UINT32      volume;
50   int         play;
51   UINT32      pan;
52   UINT32      pos;
53   int         loop;
54   int         ppcm; /* packed PCM ( 4 bit signed ) */
55   int         ppcm_data;
56};
57
58
5930// ======================> k053260_device
6031
6132class k053260_device : public device_t,
r32562r32563
6738
6839   static void set_region_tag(device_t &device, const char *tag) { downcast<k053260_device &>(device).m_rgnoverride = tag; }
6940
41   DECLARE_READ8_MEMBER( main_read );
42   DECLARE_WRITE8_MEMBER( main_write );
43   DECLARE_READ8_MEMBER( read );
44   DECLARE_WRITE8_MEMBER( write );
45
7046protected:
7147   // device-level overrides
7248   virtual void device_start();
r32562r32563
7551   // sound stream update overrides
7652   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
7753
78public:
79   DECLARE_WRITE8_MEMBER( k053260_w );
80   DECLARE_READ8_MEMBER( k053260_r );
81
8254private:
83   void InitDeltaTable( int rate, int clock );
84   void check_bounds( int channel );
55   // configuration
56   const char *    m_rgnoverride;
8557
86   sound_stream *              m_channel;
87   int                         m_mode;
88   int                         m_regs[0x30];
89   UINT8                       *m_rom;
90   int                         m_rom_size;
91   UINT32                      *m_delta_table;
92   k053260_channel             m_channels[4];
93   const char                  *m_rgnoverride;
58   sound_stream *  m_stream;
59   UINT8 *         m_rom;
60   UINT32          m_rom_size;
61
62   // live state
63    UINT8           m_portdata[4];
64   UINT8           m_keyon;
65   UINT8           m_mode;
66
67   // per voice state
68   class KDSC_Voice
69   {
70   public:
71      inline void voice_start(k053260_device &device, int index);
72      inline void voice_reset();
73      inline void set_register(offs_t offset, UINT8 data);
74      inline void set_loop_kadpcm(UINT8 data);
75      inline void set_pan(UINT8 data);
76      inline void update_pan_volume();
77      inline void key_on();
78      inline void key_off();
79      inline void play(stream_sample_t *outputs);
80      inline bool playing() { return m_playing; }
81      inline UINT8 read_rom();
82
83   private:
84      // pointer to owning device
85      k053260_device *m_device;
86
87      // live state
88      UINT32 m_position;
89      UINT16 m_pan_volume[2];
90      UINT16 m_counter;
91      INT8   m_output;
92      bool   m_playing;
93
94      // per voice registers
95      UINT32 m_start;
96      UINT16 m_length;
97      UINT16 m_pitch;
98      UINT8  m_volume;
99
100      // bit packed registers
101      UINT8  m_pan;
102      bool   m_loop;
103      bool   m_kadpcm;
104   } m_voice[4];
105
106   friend class k053260_device::KDSC_Voice;
94107};
95108
96109extern const device_type K053260;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team