| 1 |
// license:BSD-3-Clause |
| 2 |
// copyright-holders:Acho A. Tang,R. Belmont, Valley Bell |
| 3 |
/********************************************************* |
| 4 |
|
| 5 |
Irem GA20 PCM Sound Chip |
| 6 |
80 pin QFP, label NANAO GA20 (Nanao Corporation was Irem's parent company) |
| 7 |
|
| 8 |
TODO: |
| 9 |
- It's not currently known whether this chip is stereo. |
| 10 |
- Is sample position base(regs 0,1) used while sample is playing, or |
| 11 |
latched at key on? We've always emulated it the latter way. |
| 12 |
gunforc2 seems to be the only game updating the address regs sometimes |
| 13 |
while a sample is playing, but it doesn't seem intentional. |
| 14 |
- What is the 2nd sample address for? Is it end(cut-off) address, or |
| 15 |
loop start address? Every game writes a value that's past sample end. |
| 16 |
- All games write either 0 or 2 to reg #6, do other bits have any function? |
| 17 |
|
| 18 |
|
| 19 |
Revisions: |
| 20 |
|
| 21 |
04-15-2002 Acho A. Tang |
| 22 |
- rewrote channel mixing |
| 23 |
- added prelimenary volume and sample rate emulation |
| 24 |
|
| 25 |
05-30-2002 Acho A. Tang |
| 26 |
- applied hyperbolic gain control to volume and used |
| 27 |
a musical-note style progression in sample rate |
| 28 |
calculation(still very inaccurate) |
| 29 |
|
| 30 |
02-18-2004 R. Belmont |
| 31 |
- sample rate calculation reverse-engineered. |
| 32 |
Thanks to Fujix, Yasuhiro Ogawa, the Guru, and Tormod |
| 33 |
for real PCB samples that made this possible. |
| 34 |
|
| 35 |
02-03-2007 R. Belmont |
| 36 |
- Cleaned up faux x86 assembly. |
| 37 |
|
| 38 |
09-25-2018 Valley Bell & co |
| 39 |
- rewrote channel update to make data 0 act as sample terminator |
| 40 |
|
| 41 |
|
| 42 |
DISCLAIMER |
| 43 |
- This file is modified for suitable in furnace. |
| 44 |
- modified by cam900 |
| 45 |
|
| 46 |
*********************************************************/ |
| 47 |
|
| 48 |
#include "iremga20.h" |
| 49 |
|
| 50 |
#include <string.h> |
| 51 |
|
| 52 |
|
| 53 |
//************************************************************************** |
| 54 |
// LIVE DEVICE |
| 55 |
//************************************************************************** |
| 56 |
|
| 57 |
//------------------------------------------------- |
| 58 |
// iremga20_device - constructor |
| 59 |
//------------------------------------------------- |
| 60 |
|
| 61 |
iremga20_device::iremga20_device(iremga20_intf &intf) : |
| 62 |
m_regs{0}, |
| 63 |
m_channel{channel_def(), channel_def(), channel_def(), channel_def()}, |
| 64 |
m_intf(intf) |
| 65 |
{ |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
//------------------------------------------------- |
| 70 |
// device_reset - device-specific reset |
| 71 |
//------------------------------------------------- |
| 72 |
|
| 73 |
void iremga20_device::device_reset() |
| 74 |
{ |
| 75 |
memset(m_regs, 0, 0x20 * sizeof(u8)); |
| 76 |
for (int i = 0; i < 4; i++) |
| 77 |
{ |
| 78 |
m_channel[i].rate = 0; |
| 79 |
m_channel[i].pos = 0; |
| 80 |
m_channel[i].sample = 0; |
| 81 |
m_channel[i].counter = 0; |
| 82 |
m_channel[i].end = 0; |
| 83 |
m_channel[i].volume = 0; |
| 84 |
m_channel[i].play = false; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
//------------------------------------------------- |
| 89 |
// sound_stream_update - handle a stream update |
| 90 |
//------------------------------------------------- |
| 91 |
|
| 92 |
void iremga20_device::sound_stream_update(short* outputs, int len) |
| 93 |
{ |
| 94 |
for (int j = 0; j < 4; j++) |
| 95 |
{ |
| 96 |
channel_def &ch = m_channel[j]; |
| 97 |
if (ch.play) |
| 98 |
{ |
| 99 |
if (ch.sample == 0x00) // check for sample end marker |
| 100 |
ch.play = false; |
| 101 |
else |
| 102 |
{ |
| 103 |
if (ch.hot) { |
| 104 |
ch.hot=false; |
| 105 |
ch.output = ch.mute ? 0 : (ch.sample - 0x80) * (s32)ch.volume; |
| 106 |
} |
| 107 |
ch.counter-=len; |
| 108 |
if (ch.counter <= ch.rate) |
| 109 |
{ |
| 110 |
ch.pos++; |
| 111 |
ch.counter = 0x100; |
| 112 |
ch.sample = m_intf.read_byte(ch.pos); |
| 113 |
ch.hot=true; |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
outputs[j] = ch.output; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
void iremga20_device::write(u32 offset, u8 data) |
| 122 |
{ |
| 123 |
offset &= 0x1f; |
| 124 |
m_regs[offset] = data; |
| 125 |
int ch = offset >> 3; |
| 126 |
|
| 127 |
// channel regs: |
| 128 |
// 0,1: start address |
| 129 |
// 2,3: end? address |
| 130 |
// 4: rate |
| 131 |
// 5: volume |
| 132 |
// 6: control |
| 133 |
// 7: voice status (read-only) |
| 134 |
|
| 135 |
switch (offset & 0x7) |
| 136 |
{ |
| 137 |
case 4: |
| 138 |
m_channel[ch].rate = data; |
| 139 |
break; |
| 140 |
|
| 141 |
case 5: |
| 142 |
m_channel[ch].volume = (data * 256) / (data + 10); |
| 143 |
m_channel[ch].hot=true; |
| 144 |
break; |
| 145 |
|
| 146 |
case 6: |
| 147 |
// d1: key on/off |
| 148 |
if (data & 2) |
| 149 |
{ |
| 150 |
m_channel[ch].play = true; |
| 151 |
m_channel[ch].pos = (m_regs[ch << 3 | 0] | m_regs[ch << 3 | 1] << 8) << 4; |
| 152 |
m_channel[ch].end = (m_regs[ch << 3 | 2] | m_regs[ch << 3 | 3] << 8) << 4; |
| 153 |
m_channel[ch].counter = 0x100; |
| 154 |
m_channel[ch].sample = m_intf.read_byte(m_channel[ch].pos); |
| 155 |
m_channel[ch].hot=true; |
| 156 |
} |
| 157 |
else |
| 158 |
m_channel[ch].play = false; |
| 159 |
|
| 160 |
// other: unknown/unused |
| 161 |
// possibilities are: loop flag, left/right speaker(stereo) |
| 162 |
break; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
u8 iremga20_device::read(u32 offset) |
| 167 |
{ |
| 168 |
offset &= 0x1f; |
| 169 |
int ch = offset >> 3; |
| 170 |
|
| 171 |
switch (offset & 0x7) |
| 172 |
{ |
| 173 |
case 7: // voice status. bit 0 is 1 if active. (routine around 0xccc in rtypeleo) |
| 174 |
return m_channel[ch].play ? 1 : 0; |
| 175 |
} |
| 176 |
|
| 177 |
return 0; |
| 178 |
} |