| 1 |
// license:BSD-3-Clause |
| 2 |
// copyright-holders:David Viens |
| 3 |
/********************************************************************** |
| 4 |
|
| 5 |
NEC uPD1771-017 as used in the Epoch Super Cassette Vision (SCV) |
| 6 |
|
| 7 |
Made using recording/analysis on a Yeno (PAL Super Cassette Vision) |
| 8 |
by plgDavid |
| 9 |
|
| 10 |
Full markings on my 2 specimens are |
| 11 |
"NEC JAPAN 8431K9 D1771C 017" (31st week of 1984, mask rom #017) |
| 12 |
|
| 13 |
I've since (October 2012) got a Grandstand Firefox F-7 Handheld game |
| 14 |
(AKA Epoch GalagaX6/Epoch Astro Thunder 7/Tandy Astro Thunder), |
| 15 |
(http://www.handheldmuseum.com/Grandstand/Firefox.htm) |
| 16 |
which includes a |
| 17 |
"NEC JAPAN 8319K9 D1771C 011" (19th week of 1983, mask rom #011) |
| 18 |
Thanks to user 'Blanka' from Dragonslairfans for the nice catch! |
| 19 |
(http://www.dragonslairfans.com/smfor/index.php?topic=3061.0) |
| 20 |
|
| 21 |
Since the chip generates tones using ROM wavetables, |
| 22 |
it is perfectly possible to generate other sounds with different rom code and data. |
| 23 |
|
| 24 |
Most upd17XXX devices are typically 4bit NEC MCUs, however based on information |
| 25 |
in "Electronic Speech Synthesis" by Geoff Bristow (ISBN 0-07-007912-9, pages 148-152) |
| 26 |
the upd1770/1771 is not one of these 4-bit ones. |
| 27 |
|
| 28 |
The uPD1770/uPD1771 SSM is a 16-bit-wide rom/ram mcu with 8kb (4kw) of rom code, |
| 29 |
64 bytes of ram (16x16bit words addressable as 16 or 2x8 bits each, the |
| 30 |
remaining 32 bytes acting as an 8-level stack), 182 instructions, a complex |
| 31 |
noise and tone internal interrupt system, external interrupts, |
| 32 |
and two 8-bit ports with multiple modes allowing for chips to operate as master |
| 33 |
or slave devices. |
| 34 |
SSM stands for "Sound Synthesis Microcomputer". |
| 35 |
|
| 36 |
People who I *THINK* worked on the uPD1771 and what part I think they worked on: |
| 37 |
Toshio Oura - Project Lead(?), VSRSSS/TSRSSS speech synthesis engine (on upd1776C), master/slave i/o controls, author of bristow article and primary author of the IEEE article |
| 38 |
Hatsuhide Igarashi - Clock oscillator and pad layout, coauthor on the IEEE article, other IEEE stuff |
| 39 |
Tomoaki Isozaki - ? (senior NEC engineer?), coauthor on the IEEE article |
| 40 |
Sachiyuki Toufuku - ?, coauthor on the IEEE article |
| 41 |
Tojiro Mukawa - IGFETs and the DAC |
| 42 |
M. Sakai ? - digital filtering for VSRSSS? (IEEE 4131979, 1169295) |
| 43 |
M. Endo ? - digital design system or speech synthesis? (IEEE 4069656, another? person: IEEE 150330, 225838) |
| 44 |
H. Aoyama ? - logic design system used to assemble/lay out the chip? (IEEE 1585393) |
| 45 |
I. Fujitaka ? (no IEEE) |
| 46 |
Eiji Sugimoto - cpu design? 1156033 1155824 |
| 47 |
F. Tsukuda ? (no IEEE) |
| 48 |
N. Miyake ? switched capacitor stuff? (IEEE nnnnnn) |
| 49 |
|
| 50 |
|
| 51 |
The uPD1771 internal workings are described to some extent by the Bristow book |
| 52 |
and the IEEE article "A Single-Chip Sound Synthesis Microcomputer" which complements the book |
| 53 |
and are covered by at least four US patents: |
| 54 |
4184152 - on IGFET-based DAC stuff |
| 55 |
4488061 - on the IGFET-based drive circuit part of the DAC. |
| 56 |
4408094 - covers the 3 pin DAC with the volume control/vref pin. Not all that interesting, |
| 57 |
except it might describe to some extent how the (9->5bit?) PWM works in the text. |
| 58 |
4470113 - covers the multiplexed PB0/1/2/3 pins and their use as /CS /WR /RD and ALE |
| 59 |
note as I have marked the pins below I assume the final pins connected |
| 60 |
to /CS /WR /RD and /ALE are PB7,6,5,4 but this is just a guess of mine: |
| 61 |
The actual order may well match the patent. |
| 62 |
4577343 - covers the VSRSSS implementation as discussed in the Bristow book. |
| 63 |
This patent has an internal diagram of the workings of the chips and |
| 64 |
a limited description of how many registers etc it has. |
| 65 |
4805508 - on the operation of the tone divider register and correction for accurate period when |
| 66 |
the tone interrupt frequency is not perfectly divisible from the clock. |
| 67 |
These next two may not be specific to the 1771 or even related at all! |
| 68 |
4321562 - on a self-adjusting circuit for internal coupling to the clock crystal inputs. |
| 69 |
This may be a generic NEC invention and probably isn't limited to the upd1771. |
| 70 |
4656491 - on a new method of distributing resistors and transistors on anti-ESD pin buffers |
| 71 |
This may be a generic NEC invention and probably isn't limited to the upd1771. |
| 72 |
|
| 73 |
|
| 74 |
Based on the 4577343 patent mostly, plus the bristow and IEEE article: |
| 75 |
* these are the registers: |
| 76 |
8bits: |
| 77 |
AH, AL (forming the 16-bit A' accumulator), |
| 78 |
B, C (a pair of general purpose registers), |
| 79 |
4bits (may be technically part of ALU): |
| 80 |
H -> points to one of the 16 words of ram |
| 81 |
1bit: |
| 82 |
L -> selector of left or right half of the ram word |
| 83 |
?bits: |
| 84 |
D (having to do with the DAC) |
| 85 |
N (3 bits? having to do with the pseudorandom noise interrupt, namely setting the clock divider ratio for the PRNG clock vs cpu clock) |
| 86 |
MODE (5 or more bits? enabling/disabling/acking the noise interrupt, and the tone interrupts (there are four!)) |
| 87 |
SP (the stack pointer, probably 5 bits, points to the stack ram; may encompass H and L as above!) |
| 88 |
FLO: unsure. quite possibly 'flag overflow' used for branching. there likely exists other flags as well... |
| 89 |
ODF: 'output data flag?', selects which half of a selected ram word is output to the dac not really sure of this? |
| 90 |
|
| 91 |
|
| 92 |
Mask roms known: |
| 93 |
uPD1776C: mentioned in the bristow book, implements VSRSSS speech concatenation |
| 94 |
(see US Patent 4577343 which is a patent on this VSRSSS implementation) |
| 95 |
uPD1771C-006: used in NEC APC for sound as the "MPU" |
| 96 |
-011: used on Firefox F-4/Astro Thunder handheld |
| 97 |
-015: unknown, known to exist from part scalper sites only. |
| 98 |
-017: used on Epoch Super Cassette Vision for sound; This audio driver HLEs that part only. |
| 99 |
|
| 100 |
Used pinout in the SCV: |
| 101 |
|
| 102 |
NC 1 28 NC |
| 103 |
NC 2 27 NC |
| 104 |
NC 3 26 ACK |
| 105 |
!WR 4 25 D7 |
| 106 |
!CS 5 24 D6 |
| 107 |
RESET 6 23 D5 |
| 108 |
NC 7 22 D4 |
| 109 |
VCC 8 21 D3 |
| 110 |
6Mhz XIN 9 20 D2 |
| 111 |
6Mhz XOUT 10 19 D1 |
| 112 |
AUDOUT 11 18 D0 |
| 113 |
NC(recheck!)12 17 GND |
| 114 |
AUDOUT(inv) 13 16 VCC |
| 115 |
GND 14 15 ? tied to pin 16 (VCC) through a resistor (pullup?) |
| 116 |
|
| 117 |
Pinout based on guesses and information in "Electronic Speech Synthesis" by Geoff Bristow |
| 118 |
(ISBN 0-07-007912-9, pages 148-152), and the data on page 233 of the Nec APC technical manual at |
| 119 |
http://bitsavers.trailing-edge.com/pdf/nec/APC/819-000100-1003_APC_System_Reference_Guide_Apr83.pdf |
| 120 |
I/O pin purpose based on testing by kevtris. |
| 121 |
[x] is unsure: |
| 122 |
PB3 <> 1 28 <> PB2 |
| 123 |
PB4(/ALE) <> 2 27 <> PB1 |
| 124 |
PB5(/RD) <> 3 26 <> PB0 |
| 125 |
PB6(/WR) <> 4 25 <> D7(PA7) |
| 126 |
PB7(/CS) <> 5 24 <> D6(PA6) |
| 127 |
/RESET -> 6 23 <> D5(PA5) |
| 128 |
[/TSTOUT?] <- 7 22 <> D4(PA4) |
| 129 |
VCC -- 8 21 <> D3(PA3) |
| 130 |
XI(CLK) -> 9 20 <> D2(PA2) |
| 131 |
XO <- 10 19 <> D1(PA1) |
| 132 |
D/A OUT + <- 11 18 <> D0(PA0) |
| 133 |
D/A POWER -- 12 17 <- CH2 |
| 134 |
D/A OUT - <- 13 16 <> /EXTINT and [/TSTOUT2?] (test out is related to pin 15 state) |
| 135 |
GND -- 14 15 <- CH1 tied to pin 16 (VCC) through a resistor, on APC to VCC thru a 12k resistor and thru a 10uf cap to gnd |
| 136 |
|
| 137 |
CH1 and CH2 are mode selects, purpose based on testing by kevtris: |
| 138 |
CH1 CH2 |
| 139 |
H L - 'master' mode, pb4-pb7 are i/o? /EXTINT is an input |
| 140 |
L L - 'slave' mode where pb4-pb7 are /ale /rd /wr /cs? /EXTINT may be an output in this mode? |
| 141 |
X H - test mode: the 512 byte 16-bit wide ROM is output sequentially on pins pa7-pa0 and pb7-pb0 for the high and low bytes of each word respectively |
| 142 |
D/A POWER is the FET source for the D/A OUT+ and D/A OUT- push-pull dac drains; it should be tied to VCC or thereabouts |
| 143 |
|
| 144 |
In the SCV (info from plgDavid): |
| 145 |
pin 5 is tied to the !SCPU pin on the Epoch TV chip pin 29 (0x3600 writes) |
| 146 |
pin 6 is tied to the PC3 pin of the upD7801 CPU |
| 147 |
pin 26 is tied to the INT1 pin of the upD7801 (CPU pin 12), |
| 148 |
|
| 149 |
1,2,3,28,27 don't generate any digital signals |
| 150 |
6 seems to be lowered 2.5 ms before an audio write |
| 151 |
7 is always low. |
| 152 |
12 is always high |
| 153 |
|
| 154 |
(NOTE: the photomicrograph in the bristow book makes it fairly clear due to |
| 155 |
pad thicknessess that the real VCC is pin 8 and the real GND is pin 14. |
| 156 |
The function of pin 7 is unknown. |
| 157 |
|
| 158 |
Pins 11 and 13 go to a special circuit, which according to kevtris's analysis |
| 159 |
of my schematics, consist of a balanced output (not unlike XLR cables), |
| 160 |
which are then combined together then sent to the RF box. |
| 161 |
(The bristow book explains that there are two DAC pins and one DAC |
| 162 |
VREF/volume pin. The dac+ and dac- are pins 11 and 13, and based on the |
| 163 |
photomicrograph it looks like dac vref is probably pin 12) |
| 164 |
|
| 165 |
HLE: |
| 166 |
All writes are made through address 0x3600 on the upD7801 |
| 167 |
Instead of using register=value, this chip require sending multiple |
| 168 |
bytes for each command, one after the other. |
| 169 |
|
| 170 |
**********************************************************************/ |
| 171 |
|
| 172 |
#include "upd1771.h" |
| 173 |
#include <string.h> |
| 174 |
|
| 175 |
//#define VERBOSE 1 |
| 176 |
|
| 177 |
namespace { |
| 178 |
|
| 179 |
/* |
| 180 |
Each of the 8 waveforms have been extracted from the uPD1771c-017 internal |
| 181 |
ROM, from offset 0x1fd (start of first waveform) to offset 0x2fc (end of |
| 182 |
last waveform). |
| 183 |
(note: given test mode dumping offset non-clarity it may be 0x200-0x2ff) |
| 184 |
The waveforms are stored in an 8-bit sign-magnitude format, so if in ROM the |
| 185 |
upper bit is 0x80, invert the lower 7 bits to get the 2's complement result |
| 186 |
seen here. |
| 187 |
Note that only the last 4 waveforms appear to have been intended for use as |
| 188 |
waveforms; the first four look as if they're playing back a piece of code as |
| 189 |
wave data. |
| 190 |
*/ |
| 191 |
static const signed char WAVEFORMS[8][32]={ |
| 192 |
{ 0, 0,-123,-123, -61, -23, 125, 107, 94, 83,-128,-128,-128, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0,-128,-128,-128, 0, 0, 0, 0, 0, 0}, |
| 193 |
{ 37, 16, 32, -21, 32, 52, 4, 4, 33, 18, 60, 56, 0, 8, 5, 16, 65, 19, 69, 16, -2, 19, 37, 16, 97, 19, 0, 87, 127, -3, 1, 2}, |
| 194 |
{ 0, 8, 1, 52, 4, 0, 0, 77, 81,-109, 47, 97, -83,-109, 38, 97, 0, 52, 4, 0, 1, 4, 1, 22, 2, -46, 33, 97, 0, 8, -85, -99}, |
| 195 |
{ 47, 97, 40, 97, -3, 25, 64, 17, 0, 52, 12, 5, 12, 5, 12, 5, 12, 5, 12, 5, 8, 4,-114, 19, 0, 52,-122, 21, 2, 5, 0, 8}, |
| 196 |
{ -52, -96,-118,-128,-111, -74, -37, -5, 31, 62, 89, 112, 127, 125, 115, 93, 57, 23, 0, -16, -8, 15, 37, 54, 65, 70, 62, 54, 43, 31, 19, 0}, |
| 197 |
{ -81,-128, -61, 13, 65, 93, 127, 47, 41, 44, 52, 55, 56, 58, 58, 34, 0, 68, 76, 72, 61, 108, 55, 29, 32, 39, 43, 49, 50, 51, 51, 0}, |
| 198 |
{ -21, -45, -67, -88,-105,-114,-122,-128,-123,-116,-103, -87, -70, -53, -28, -9, 22, 46, 67, 86, 102, 114, 123, 125, 127, 117, 104, 91, 72, 51, 28, 0}, |
| 199 |
{ -78,-118,-128,-102, -54, -3, 40, 65, 84, 88, 84, 80, 82, 88, 94, 103, 110, 119, 122, 125, 122, 122, 121, 123, 125, 126, 127, 127, 125, 118, 82, 0} |
| 200 |
}; |
| 201 |
|
| 202 |
|
| 203 |
#define NOISE_SIZE 255 |
| 204 |
|
| 205 |
|
| 206 |
static const unsigned char noise_tbl[8][256] = { |
| 207 |
{ |
| 208 |
0x84, 0x87, 0x8c, 0x93, 0x9a, 0xa4, 0xb2, 0xc8, 0x8a, 0x6c, 0x58, 0x4e, 0x43, 0x3d, 0x37, 0x33, |
| 209 |
0x86, 0x8d, 0x95, 0x9d, 0xa8, 0xb5, 0xc9, 0xe7, 0x6d, 0x58, 0x4b, 0x43, 0x3e, 0x38, 0x37, 0x34, |
| 210 |
0x87, 0x8b, 0x8f, 0x96, 0x9d, 0xa7, 0xb5, 0xcb, 0x4d, 0x45, 0x40, 0x3a, 0x39, 0x35, 0x89, 0x8d, |
| 211 |
0x91, 0x98, 0x9f, 0xa9, 0xb7, 0xcd, 0x37, 0x34, 0x87, 0x8c, 0x90, 0x97, 0x9e, 0xa8, 0xb5, 0xcb, |
| 212 |
0xca, 0x93, 0x9b, 0xa6, 0xb3, 0xc7, 0xe5, 0x6b, 0x56, 0x49, 0x41, 0x3c, 0x36, 0x35, 0x32, 0x86, |
| 213 |
0x89, 0x8e, 0x95, 0x9c, 0xa6, 0xb4, 0xc9, 0xb2, 0xc8, 0x8a, 0x6c, 0x58, 0x4d, 0x43, 0x3d, 0x37, |
| 214 |
0x33, 0x86, 0x8d, 0x95, 0x9d, 0xa8, 0xb5, 0xc9, 0xe7, 0x6d, 0x58, 0x4b, 0x43, 0x3e, 0x38, 0x37, |
| 215 |
0x34, 0x87, 0x8b, 0x8f, 0x97, 0x9e, 0xa8, 0xb5, 0xcb, 0xb5, 0xc9, 0xe6, 0x6d, 0x58, 0x4b, 0x43, |
| 216 |
0x3d, 0x38, 0x37, 0x33, 0x87, 0x8b, 0x8f, 0x96, 0x9e, 0xa7, 0xb5, 0xcb, 0x9c, 0xa7, 0xb3, 0xc8, |
| 217 |
0xe6, 0x6c, 0x56, 0x4a, 0x42, 0x3d, 0x37, 0x36, 0x33, 0x86, 0x8a, 0x8e, 0x95, 0x9c, 0xa6, 0xb4, |
| 218 |
0xca, 0xa4, 0xb2, 0xc8, 0x35, 0x33, 0x30, 0x84, 0x88, 0x8c, 0x93, 0x9a, 0xa5, 0xb2, 0xc8, 0x34, |
| 219 |
0x30, 0x84, 0x8a, 0x93, 0x9a, 0xa5, 0xb2, 0xc6, 0xe4, 0x6a, 0x55, 0x49, 0x41, 0x3b, 0x36, 0x34, |
| 220 |
0x31, 0x85, 0x89, 0x8d, 0x94, 0x9b, 0xa5, 0xb3, 0xc9, 0x43, 0x3d, 0x37, 0x33, 0x86, 0x8d, 0x95, |
| 221 |
0x9d, 0xa8, 0xb4, 0xc9, 0xe7, 0x6d, 0x57, 0x4b, 0x43, 0x3e, 0x38, 0x37, 0x33, 0x87, 0x8b, 0x8f, |
| 222 |
0x96, 0x9d, 0xa7, 0xb5, 0xcb, 0x85, 0x8b, 0x93, 0x9b, 0xa6, 0xb3, 0xc7, 0xe5, 0x6b, 0x56, 0x4a, |
| 223 |
0x41, 0x3c, 0x36, 0x35, 0x32, 0x86, 0x89, 0x8e, 0x95, 0x9c, 0xa6, 0xb4, 0xca, 0x30 |
| 224 |
}, |
| 225 |
{ |
| 226 |
0x95, 0x95, 0x98, 0x9c, 0x9e, 0xa3, 0xaa, 0xb4, 0xb3, 0x98, 0x9c, 0xa1, 0xa7, 0xb1, 0xc0, 0x57, |
| 227 |
0x4f, 0x49, 0x48, 0x44, 0x42, 0x40, 0x40, 0x94, 0x95, 0x96, 0x9a, 0x9d, 0xa2, 0xa9, 0xb3, 0xa8, |
| 228 |
0xb1, 0x66, 0x59, 0x50, 0x4c, 0x4a, 0x46, 0x44, 0x41, 0x94, 0x97, 0x9b, 0x9e, 0xa4, 0xaa, 0xb3, |
| 229 |
0xc2, 0x59, 0x52, 0x4c, 0x4a, 0x46, 0x45, 0x43, 0x43, 0x96, 0x97, 0x99, 0x9d, 0x9f, 0xa5, 0xab, |
| 230 |
0xb5, 0xaa, 0xb4, 0xc2, 0x5a, 0x52, 0x4c, 0x4b, 0x47, 0x45, 0x43, 0x43, 0x96, 0x97, 0x99, 0x9d, |
| 231 |
0xa0, 0xa5, 0xab, 0xb5, 0x9d, 0xa3, 0xa9, 0xb3, 0xc2, 0x59, 0x51, 0x4b, 0x4a, 0x46, 0x44, 0x42, |
| 232 |
0x42, 0x96, 0x97, 0x98, 0x9c, 0x9f, 0xa4, 0xab, 0xb4, 0xa2, 0xa9, 0xb3, 0x41, 0x40, 0x40, 0x93, |
| 233 |
0x94, 0x96, 0x9a, 0x9d, 0xa2, 0xa8, 0xb2, 0x41, 0x3e, 0x92, 0x94, 0x99, 0x9b, 0xa2, 0xa7, 0xb1, |
| 234 |
0xc0, 0x57, 0x4f, 0x4a, 0x48, 0x44, 0x42, 0x40, 0x40, 0x94, 0x95, 0x97, 0x9a, 0x9d, 0xa2, 0xa9, |
| 235 |
0xb3, 0x48, 0x45, 0x43, 0x41, 0x94, 0x97, 0x9b, 0x9d, 0xa3, 0xa9, 0xb3, 0xc1, 0x59, 0x51, 0x4b, |
| 236 |
0x4a, 0x45, 0x44, 0x42, 0x42, 0x95, 0x97, 0x98, 0x9c, 0x9f, 0xa4, 0xab, 0xb4, 0x92, 0x95, 0x99, |
| 237 |
0x9c, 0xa2, 0xa8, 0xb1, 0xc0, 0x57, 0x4f, 0x4a, 0x48, 0x44, 0x42, 0x41, 0x41, 0x94, 0x95, 0x97, |
| 238 |
0x9b, 0x9e, 0xa3, 0xa9, 0xb3, 0x3e, 0x92, 0x93, 0x95, 0x98, 0x9b, 0xa0, 0xa7, 0xb1, 0x65, 0x58, |
| 239 |
0x50, 0x4b, 0x49, 0x45, 0x43, 0x41, 0x94, 0x97, 0x9b, 0x9e, 0xa4, 0xa9, 0xb3, 0xc2, 0x59, 0x51, |
| 240 |
0x4b, 0x4a, 0x46, 0x45, 0x42, 0x42, 0x96, 0x96, 0x99, 0x9c, 0x9f, 0xa4, 0xab, 0xb5, 0x4d, 0x4b, |
| 241 |
0x47, 0x45, 0x43, 0x43, 0x97, 0x97, 0x9a, 0x9d, 0xa0, 0xa5, 0xac, 0xb6, 0x41, 0x42 |
| 242 |
}, |
| 243 |
{ |
| 244 |
0x93, 0x93, 0x93, 0x94, 0x95, 0x99, 0x9c, 0xa1, 0xa8, 0x4e, 0x48, 0x45, 0x43, 0x44, 0x42, 0x42, |
| 245 |
0x95, 0x95, 0x95, 0x96, 0x97, 0x98, 0x9b, 0x9e, 0xa6, 0x43, 0x41, 0x41, 0x95, 0x94, 0x94, 0x95, |
| 246 |
0x97, 0x9b, 0x9d, 0xa3, 0xa9, 0x4f, 0x4a, 0x46, 0x45, 0x45, 0x43, 0x43, 0x97, 0x96, 0x96, 0x97, |
| 247 |
0x99, 0x9a, 0x9c, 0x9f, 0xa7, 0x94, 0x93, 0x94, 0x96, 0x9a, 0x9d, 0xa2, 0xa9, 0x4f, 0x49, 0x45, |
| 248 |
0x44, 0x45, 0x43, 0x43, 0x96, 0x96, 0x96, 0x96, 0x98, 0x99, 0x9c, 0x9f, 0xa7, 0x93, 0x93, 0x93, |
| 249 |
0x93, 0x95, 0x96, 0x99, 0x9c, 0xa4, 0x50, 0x4b, 0x49, 0x45, 0x44, 0x42, 0x42, 0x95, 0x95, 0x95, |
| 250 |
0x96, 0x97, 0x9b, 0x9e, 0xa3, 0xaa, 0x50, 0x4b, 0x46, 0x46, 0x46, 0x44, 0x44, 0x97, 0x97, 0x97, |
| 251 |
0x97, 0x99, 0x9a, 0x9d, 0x9f, 0xa8, 0x47, 0x46, 0x46, 0x44, 0x44, 0x98, 0x98, 0x97, 0x98, 0x9a, |
| 252 |
0x9b, 0x9d, 0xa0, 0xa8, 0x42, 0x96, 0x95, 0x95, 0x96, 0x98, 0x98, 0x9b, 0x9e, 0xa6, 0xa6, 0x93, |
| 253 |
0x95, 0x99, 0x9c, 0xa1, 0xa7, 0x4e, 0x48, 0x44, 0x43, 0x44, 0x41, 0x42, 0x95, 0x95, 0x95, 0x95, |
| 254 |
0x97, 0x98, 0x9b, 0x9e, 0xa6, 0x9d, 0xa5, 0x52, 0x4c, 0x4b, 0x46, 0x45, 0x42, 0x43, 0x97, 0x96, |
| 255 |
0x96, 0x97, 0x98, 0x9c, 0x9f, 0xa4, 0xab, 0x51, 0x4b, 0x48, 0x46, 0x47, 0x44, 0x45, 0x98, 0x98, |
| 256 |
0x98, 0x98, 0x9a, 0x9b, 0x9e, 0xa0, 0xa8, 0x9f, 0xa4, 0xab, 0x51, 0x4c, 0x48, 0x47, 0x47, 0x45, |
| 257 |
0x45, 0x99, 0x98, 0x98, 0x99, 0x9a, 0x9b, 0x9e, 0xa1, 0xa9, 0x98, 0x9d, 0x9f, 0xa4, 0xab, 0x51, |
| 258 |
0x4b, 0x47, 0x47, 0x47, 0x45, 0x45, 0x98, 0x98, 0x98, 0x98, 0x9a, 0x9b, 0x9e, 0xa1, 0xa8, 0x9c, |
| 259 |
0x9f, 0xa7, 0x42, 0x42, 0x95, 0x95, 0x95, 0x96, 0x97, 0x98, 0x9b, 0x9e, 0xa6, 0x3f |
| 260 |
}, |
| 261 |
{ |
| 262 |
0x94, 0x93, 0x92, 0x92, 0x93, 0x95, 0x96, 0x99, 0x9c, 0x43, 0x43, 0x43, 0x41, 0x41, 0x42, 0x95, |
| 263 |
0x95, 0x95, 0x94, 0x94, 0x94, 0x95, 0x97, 0x97, 0x9a, 0x40, 0x40, 0x41, 0x95, 0x95, 0x94, 0x95, |
| 264 |
0x95, 0x97, 0x97, 0x9a, 0x9e, 0x45, 0x44, 0x44, 0x42, 0x42, 0x43, 0x97, 0x96, 0x96, 0x96, 0x96, |
| 265 |
0x95, 0x96, 0x98, 0x99, 0x9c, 0x94, 0x94, 0x94, 0x94, 0x96, 0x97, 0x9a, 0x9d, 0x44, 0x43, 0x44, |
| 266 |
0x42, 0x42, 0x43, 0x96, 0x96, 0x96, 0x95, 0x95, 0x95, 0x96, 0x98, 0x98, 0x9b, 0x93, 0x93, 0x93, |
| 267 |
0x92, 0x92, 0x93, 0x95, 0x95, 0x98, 0x49, 0x44, 0x43, 0x44, 0x42, 0x42, 0x43, 0x96, 0x96, 0x96, |
| 268 |
0x95, 0x96, 0x98, 0x99, 0x9b, 0x9f, 0x46, 0x45, 0x45, 0x43, 0x44, 0x44, 0x98, 0x98, 0x97, 0x97, |
| 269 |
0x97, 0x97, 0x97, 0x99, 0x9a, 0x9d, 0x45, 0x43, 0x43, 0x44, 0x98, 0x98, 0x98, 0x97, 0x97, 0x97, |
| 270 |
0x97, 0x99, 0x9a, 0x9d, 0x95, 0x95, 0x94, 0x94, 0x94, 0x94, 0x94, 0x96, 0x97, 0x9a, 0x9a, 0x92, |
| 271 |
0x93, 0x94, 0x95, 0x98, 0x9c, 0x43, 0x42, 0x43, 0x40, 0x40, 0x41, 0x95, 0x95, 0x94, 0x94, 0x94, |
| 272 |
0x93, 0x94, 0x96, 0x97, 0x9a, 0x96, 0x99, 0x4a, 0x45, 0x44, 0x44, 0x42, 0x42, 0x43, 0x97, 0x96, |
| 273 |
0x96, 0x96, 0x97, 0x98, 0x99, 0x9c, 0xa0, 0x47, 0x46, 0x46, 0x44, 0x44, 0x45, 0x98, 0x98, 0x98, |
| 274 |
0x98, 0x97, 0x97, 0x98, 0x99, 0x9a, 0x9d, 0x9a, 0x9c, 0xa0, 0x47, 0x46, 0x46, 0x44, 0x44, 0x45, |
| 275 |
0x99, 0x98, 0x98, 0x98, 0x97, 0x97, 0x98, 0x9a, 0x9a, 0x9e, 0x97, 0x98, 0x99, 0x9c, 0xa0, 0x47, |
| 276 |
0x46, 0x46, 0x44, 0x44, 0x45, 0x98, 0x98, 0x98, 0x98, 0x98, 0x97, 0x98, 0x9a, 0x9a, 0x9d, 0x98, |
| 277 |
0x99, 0x9c, 0x42, 0x95, 0x95, 0x95, 0x94, 0x94, 0x94, 0x95, 0x96, 0x97, 0x9a, 0x40 |
| 278 |
}, |
| 279 |
{ |
| 280 |
0xe6, 0x1c, 0x87, 0xcb, 0x42, 0x9b, 0x87, 0x35, 0xd8, 0x1c, 0xa3, 0x58, 0x84, 0xa4, 0x28, 0x71, |
| 281 |
0xd9, 0x3e, 0x82, 0xbb, 0x28, 0xd2, 0x80, 0x63, 0xe0, 0x38, 0x71, 0xcb, 0x22, 0x81, 0x9b, 0x83, |
| 282 |
0xa4, 0x28, 0x71, 0xd8, 0x3e, 0x81, 0xbb, 0x28, 0xd2, 0x80, 0x63, 0xe0, 0x37, 0x71, 0xcb, 0x22, |
| 283 |
0x81, 0x9b, 0xa3, 0x57, 0x83, 0xa3, 0x28, 0x70, 0xd8, 0x3e, 0x81, 0xba, 0x28, 0xd1, 0x80, 0x63, |
| 284 |
0xe0, 0x37, 0x70, 0xcb, 0x22, 0x81, 0x9b, 0x23, 0x82, 0x9b, 0x28, 0xd2, 0x80, 0x63, 0xe1, 0x38, |
| 285 |
0x71, 0xcc, 0x23, 0x81, 0x9b, 0x9c, 0x88, 0x36, 0xd9, 0x1d, 0xa4, 0x58, 0x84, 0xa5, 0x28, 0x72, |
| 286 |
0xd9, 0x3f, 0x82, 0xbb, 0x29, 0xd2, 0x81, 0x64, 0xe1, 0x38, 0x72, 0xcc, 0x23, 0x82, 0x9b, 0xcc, |
| 287 |
0x43, 0x9c, 0x88, 0x36, 0xd8, 0x1d, 0xa4, 0x58, 0x84, 0xa5, 0x29, 0x71, 0xd9, 0x3f, 0x82, 0xbc, |
| 288 |
0x29, 0xd2, 0x81, 0x64, 0xe1, 0x39, 0x72, 0xcc, 0x23, 0x82, 0x9c, 0x37, 0xd9, 0x1d, 0xa4, 0x59, |
| 289 |
0x85, 0xa6, 0x29, 0x72, 0xda, 0x40, 0x83, 0xbc, 0x2a, 0xd3, 0x82, 0x64, 0xe2, 0x39, 0x72, 0xcc, |
| 290 |
0x24, 0x82, 0x9c, 0x82, 0x64, 0xe1, 0x3a, 0x72, 0xcc, 0x24, 0x82, 0x9c, 0x40, 0xe8, 0x1e, 0x89, |
| 291 |
0xcd, 0x44, 0x9d, 0x89, 0x37, 0xd9, 0x1e, 0xa5, 0x59, 0x85, 0xa6, 0x2a, 0x73, 0xda, 0x40, 0x84, |
| 292 |
0xbd, 0x2a, 0xd3, 0x82, 0x65, 0xe2, 0x39, 0x73, 0xcd, 0x24, 0x83, 0x9c, 0x40, 0x83, 0xbd, 0x2a, |
| 293 |
0xd3, 0x82, 0x65, 0xe2, 0x39, 0x73, 0xcd, 0x24, 0x83, 0x9c, 0xd2, 0x81, 0x63, 0xe0, 0x39, 0x71, |
| 294 |
0xcc, 0x23, 0x82, 0x9b, 0x9b, 0x1d, 0xa4, 0x59, 0x84, 0xa5, 0x29, 0x72, 0xd9, 0x3f, 0x83, 0xbc, |
| 295 |
0x29, 0xd3, 0x81, 0x64, 0xe1, 0x39, 0x72, 0xcc, 0x24, 0x82, 0x9c, 0x82, 0x9c, 0x3f |
| 296 |
}, |
| 297 |
{ |
| 298 |
0xe7, 0x89, 0x1b, 0x8b, 0xe6, 0x89, 0x1b, 0x8b, 0xe6, 0x89, 0x1b, 0x8a, 0xe6, 0x88, 0x1b, 0x8a, |
| 299 |
0xe6, 0x88, 0x1a, 0x8a, 0x1c, 0x8b, 0xe7, 0x89, 0x1b, 0x8b, 0xe6, 0x89, 0x1b, 0x8a, 0xe6, 0x89, |
| 300 |
0x1b, 0x8a, 0xe6, 0x89, 0x1b, 0x8a, 0xe6, 0x89, 0x1a, 0x8a, 0xe6, 0x88, 0x1a, 0x89, 0xe5, 0x88, |
| 301 |
0x1a, 0x89, 0xe5, 0x88, 0x1a, 0xe5, 0x88, 0x1a, 0x89, 0xe5, 0x88, 0x1a, 0x89, 0xe4, 0x87, 0x19, |
| 302 |
0x89, 0xe4, 0x87, 0x19, 0x88, 0xe4, 0x87, 0x19, 0x1a, 0x8a, 0xe5, 0x88, 0x1a, 0x89, 0xe5, 0x88, |
| 303 |
0x1a, 0x89, 0xe5, 0x88, 0x1a, 0x89, 0xe4, 0x87, 0x19, 0x89, 0xe4, 0x87, 0x19, 0xe4, 0x87, 0x19, |
| 304 |
0xe4, 0x87, 0x1a, 0x88, 0xe4, 0x87, 0x19, 0x88, 0xe4, 0x87, 0x19, 0x88, 0x1a, 0x89, 0xe5, 0x88, |
| 305 |
0x1a, 0x89, 0xe5, 0x88, 0x1a, 0x89, 0xe5, 0x87, 0x1a, 0x89, 0xe4, 0x88, 0x19, 0x89, 0xe4, 0x87, |
| 306 |
0x19, 0x88, 0xe4, 0x87, 0x19, 0x88, 0xe4, 0x87, 0x19, 0x88, 0xe4, 0x87, 0x19, 0x88, 0xe4, 0x87, |
| 307 |
0x19, 0x88, 0xe3, 0x86, 0x19, 0x88, 0xe3, 0x86, 0x18, 0x87, 0xe3, 0x86, 0x18, 0x88, 0xe3, 0x86, |
| 308 |
0x18, 0x87, 0xe3, 0x86, 0x18, 0x87, 0xe3, 0x86, 0x18, 0x87, 0xe3, 0x86, 0x18, 0x87, 0xe3, 0x86, |
| 309 |
0x18, 0x87, 0xe2, 0x85, 0x18, 0x87, 0xe3, 0x85, 0x17, 0x19, 0x88, 0xe3, 0x86, 0x19, 0x88, 0xe4, |
| 310 |
0x86, 0x19, 0x88, 0xe3, 0x86, 0x18, 0x88, 0xe3, 0x86, 0x18, 0x87, 0xe3, 0x86, 0x18, 0x87, 0xe3, |
| 311 |
0x86, 0x18, 0x87, 0xe3, 0x85, 0x18, 0x87, 0xe3, 0x86, 0x18, 0x87, 0xe3, 0x86, 0x18, 0x87, 0xe3, |
| 312 |
0x85, 0x18, 0x87, 0x19, 0x88, 0xe3, 0x86, 0x19, 0x88, 0xe3, 0x86, 0x18, 0x87, 0xe3, 0x86, 0x18, |
| 313 |
0x87, 0x1a, 0x89, 0xe4, 0x87, 0x19, 0x88, 0xe4, 0x87, 0x19, 0x1b, 0x89, 0x1c, 0x8b |
| 314 |
}, |
| 315 |
{ |
| 316 |
0xa1, 0xe6, 0xcf, 0x79, 0x58, 0x4a, 0x78, 0x7a, 0x53, 0x7b, 0xc2, 0xc3, 0x82, 0x36, 0x48, 0x84, |
| 317 |
0xcb, 0xa6, 0x67, 0x2e, 0x49, 0x7c, 0xaa, 0x93, 0x87, 0x73, 0x62, 0x6c, 0xa4, 0xaa, 0x71, 0xa7, |
| 318 |
0x67, 0x2f, 0x4a, 0x7c, 0xab, 0x94, 0x87, 0x74, 0x62, 0x6d, 0xa4, 0xab, 0x72, 0x7b, 0xaa, 0x93, |
| 319 |
0x87, 0x72, 0x61, 0x6c, 0xa4, 0xaa, 0x71, 0x72, 0x7b, 0xc2, 0xc3, 0x81, 0x36, 0x48, 0x84, 0xcb, |
| 320 |
0xa6, 0x67, 0x2e, 0x49, 0x7b, 0xaa, 0x93, 0x87, 0x72, 0x61, 0x6c, 0xa4, 0xaa, 0x71, 0xaa, 0x71, |
| 321 |
0x59, 0xa0, 0xe5, 0xce, 0x78, 0x57, 0x49, 0x77, 0x79, 0x52, 0x7a, 0xc1, 0xc2, 0x81, 0x35, 0x47, |
| 322 |
0x83, 0xca, 0xa6, 0x66, 0x2d, 0x48, 0x7b, 0xa9, 0x92, 0x86, 0x72, 0x61, 0x6b, 0xa3, 0xa9, 0x70, |
| 323 |
0x82, 0x36, 0x49, 0x84, 0xcc, 0xa7, 0x67, 0x2e, 0x4a, 0x7c, 0xab, 0x94, 0x87, 0x73, 0x62, 0x6c, |
| 324 |
0xa4, 0xab, 0x72, 0xc2, 0xc3, 0x82, 0x36, 0x48, 0x84, 0xcb, 0xa6, 0x67, 0x2e, 0x4a, 0x7c, 0xaa, |
| 325 |
0x93, 0x87, 0x73, 0x62, 0x6c, 0xa4, 0xaa, 0x71, 0xa3, 0xaa, 0x70, 0x49, 0x7b, 0xa9, 0x92, 0x86, |
| 326 |
0x72, 0x61, 0x6b, 0xa3, 0xaa, 0x70, 0x4b, 0x78, 0x7a, 0x53, 0x7c, 0xc2, 0xc3, 0x82, 0x36, 0x49, |
| 327 |
0x84, 0xcc, 0xa6, 0x67, 0x2f, 0x4a, 0x7c, 0xaa, 0x93, 0x87, 0x73, 0x62, 0x6c, 0xa4, 0xab, 0x72, |
| 328 |
0x7b, 0x5a, 0x4c, 0x7a, 0x7c, 0x55, 0x7e, 0xc4, 0xc5, 0x83, 0x38, 0x4a, 0x85, 0xcd, 0xa8, 0x69, |
| 329 |
0x30, 0x4b, 0x7d, 0xac, 0x95, 0x88, 0x74, 0x63, 0x6e, 0xa5, 0xac, 0x73, 0x7c, 0x55, 0x7d, 0xc4, |
| 330 |
0xc5, 0x83, 0x37, 0x4a, 0x85, 0xcd, 0xa8, 0x68, 0x30, 0x4b, 0x7d, 0xac, 0x95, 0x88, 0x74, 0x63, |
| 331 |
0x6e, 0xa6, 0xac, 0x73, 0xab, 0x94, 0x87, 0x73, 0x62, 0x6d, 0xa5, 0xab, 0x72, 0x5a |
| 332 |
}, |
| 333 |
{ |
| 334 |
0xbf, 0xdc, 0xd4, 0xaa, 0x82, 0x81, 0x35, 0x34, 0x4d, 0x75, 0x95, 0xcb, 0xde, 0xc9, 0x91, 0x72, |
| 335 |
0x4a, 0x30, 0x6b, 0x57, 0x69, 0x7d, 0x65, 0x3f, 0x33, 0x4f, 0x69, 0x81, 0xc1, 0xde, 0xd6, 0xac, |
| 336 |
0x83, 0x82, 0x37, 0x36, 0x4f, 0x77, 0x96, 0xcd, 0xe0, 0xca, 0x93, 0x73, 0x4c, 0x31, 0x6d, 0x58, |
| 337 |
0x6a, 0x4f, 0x68, 0x80, 0xc0, 0xdd, 0xd5, 0xab, 0x82, 0x82, 0x36, 0x35, 0x4e, 0x76, 0x95, 0xcc, |
| 338 |
0xdf, 0xca, 0x92, 0x73, 0x4b, 0x31, 0x6c, 0x57, 0x6a, 0xe0, 0xca, 0x92, 0x73, 0x4c, 0x31, 0x6c, |
| 339 |
0x58, 0x6a, 0xad, 0xd5, 0xdb, 0xbc, 0x7b, 0x63, 0x3c, 0x31, 0x4e, 0x66, 0x7e, 0xbe, 0xdb, 0xd3, |
| 340 |
0xaa, 0x81, 0x80, 0x34, 0x33, 0x4c, 0x75, 0x94, 0xcb, 0xde, 0xc8, 0x91, 0x71, 0x4a, 0x2f, 0x6b, |
| 341 |
0x56, 0x68, 0x35, 0x4e, 0x76, 0x95, 0xcc, 0xdf, 0xca, 0x92, 0x72, 0x4b, 0x30, 0x6c, 0x57, 0x6a, |
| 342 |
0xcc, 0xdf, 0xca, 0x91, 0x72, 0x4b, 0x30, 0x6c, 0x57, 0x69, 0x69, 0x7e, 0xbe, 0xdb, 0xd3, 0xa9, |
| 343 |
0x81, 0x80, 0x34, 0x33, 0x4c, 0x74, 0x94, 0xcb, 0xdd, 0xc8, 0x90, 0x71, 0x4a, 0x2f, 0x6b, 0x55, |
| 344 |
0x68, 0x56, 0x69, 0xac, 0xd4, 0xd9, 0xbb, 0x7a, 0x62, 0x3c, 0x30, 0x4c, 0x65, 0x7d, 0xbd, 0xda, |
| 345 |
0xd2, 0xa8, 0x80, 0x7f, 0x34, 0x33, 0x4c, 0x74, 0x94, 0xca, 0xdd, 0xc8, 0x90, 0x71, 0x49, 0x2e, |
| 346 |
0x6a, 0x55, 0x67, 0xd3, 0xa9, 0x81, 0x80, 0x34, 0x33, 0x4c, 0x74, 0x94, 0xca, 0xde, 0xc8, 0x91, |
| 347 |
0x71, 0x4a, 0x2f, 0x6a, 0x56, 0x68, 0xbd, 0xda, 0xd2, 0xa8, 0x7f, 0x7e, 0x33, 0x32, 0x4b, 0x73, |
| 348 |
0x92, 0xc9, 0xdc, 0xc7, 0x8f, 0x70, 0x49, 0x2e, 0x69, 0x54, 0x67, 0x6a, 0x56, 0x68, 0x93, 0xca, |
| 349 |
0xdd, 0xc8, 0x90, 0x70, 0x49, 0x2e, 0x6a, 0x55, 0x68, 0x3d, 0x31, 0x4e, 0x67, 0x7f |
| 350 |
}, |
| 351 |
}; |
| 352 |
|
| 353 |
|
| 354 |
#define STATE_SILENCE 0 |
| 355 |
#define STATE_NOISE 1 |
| 356 |
#define STATE_TONE 2 |
| 357 |
#define STATE_ADPCM 3 |
| 358 |
|
| 359 |
} // anonymous namespace |
| 360 |
|
| 361 |
//------------------------------------------------- |
| 362 |
// device_reset - device-specific reset |
| 363 |
//------------------------------------------------- |
| 364 |
|
| 365 |
void upd1771c_device::device_reset() |
| 366 |
{ |
| 367 |
m_index = 0; |
| 368 |
m_expected_bytes = 0; |
| 369 |
m_pc3 = 0; |
| 370 |
m_t_tpos = 0; |
| 371 |
m_t_ppos = 0; |
| 372 |
m_state = STATE_SILENCE; |
| 373 |
m_nw_tpos = 0; |
| 374 |
memset(m_n_value, 0x00, sizeof(m_n_value)); |
| 375 |
memset(m_n_ppos, 0x00, sizeof(m_n_ppos)); |
| 376 |
memset(chout,0,4*sizeof(short)); |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
uint8_t upd1771c_device::read() |
| 382 |
{ |
| 383 |
return 0x80; // TODO |
| 384 |
} |
| 385 |
|
| 386 |
/* |
| 387 |
*************TONE***************** |
| 388 |
Tone consists of a wavetable playback mechanism. |
| 389 |
Each wavetable is a looping period of 32 samples but can be played with an offset from any point in the table |
| 390 |
effectively shrinking the sample loop, thus allowing different pitch "macros ranges" to be played. |
| 391 |
This method is rather crude because the spectrum of the sound get heavily altered... |
| 392 |
unless that was the intent. |
| 393 |
|
| 394 |
Tone Write (4 bytes): |
| 395 |
|
| 396 |
Byte0: 0x02 |
| 397 |
|
| 398 |
Byte1: 0bTTTOOOOO |
| 399 |
MSB 3 bits of Timbre (8 wavetables) |
| 400 |
LSB 5 bits offset in the table. |
| 401 |
|
| 402 |
Byte2: 0bPPPPPPPP |
| 403 |
8bits of clock divider/period |
| 404 |
Anything under <= 0x20 give the same value |
| 405 |
|
| 406 |
Byte3: 0b???VVVVV |
| 407 |
MSB 3 bits unknown |
| 408 |
LSB 5 bits of "Volume" |
| 409 |
|
| 410 |
Note: volume is not a volume in a normal sense but some kind |
| 411 |
of bit cropping/rounding. |
| 412 |
*/ |
| 413 |
|
| 414 |
|
| 415 |
/* |
| 416 |
*************NOISE***************** |
| 417 |
Noise consists on 4 different components |
| 418 |
A weird Wavetable LFSR (for lack of a better term), |
| 419 |
and three independent (but equal) low frequency |
| 420 |
50/50 pulse wavs. |
| 421 |
|
| 422 |
The 4 components are mixed in a mysterious way, |
| 423 |
a weird ORing with volume having a huge effect. |
| 424 |
|
| 425 |
Byte0: 0x01 |
| 426 |
|
| 427 |
Byte1: 0bTTTOOOOO |
| 428 |
MSB 3 bits of LFSR Timbre (8 wavetables) |
| 429 |
LSB 5 bits ????????? |
| 430 |
|
| 431 |
Byte2: 0bPPPPPPPP |
| 432 |
8bits of clock divider/period |
| 433 |
|
| 434 |
Byte3: 0b???VVVVV |
| 435 |
MSB 3 bits unknown |
| 436 |
LSB 5 bits of "Volume" |
| 437 |
|
| 438 |
|
| 439 |
Byte4: 0bPPPPPPPP Low Freq0 period(if not 0 this periodically resets the Wavetable LFSR) |
| 440 |
Byte5: 0bPPPPPPPP Low Freq1 period(if not 0 this periodically resets the Wavetable LFSR) |
| 441 |
Byte6: 0bPPPPPPPP Low Freq2 period(if not 0 this periodically resets the Wavetable LFSR) |
| 442 |
|
| 443 |
Byte7: 0b???VVVVV Low Freq0 volume |
| 444 |
Byte8: 0b???VVVVV Low Freq1 volume |
| 445 |
Byte9: 0b???VVVVV Low Freq2 volume |
| 446 |
*/ |
| 447 |
|
| 448 |
void upd1771c_device::write(uint8_t data) |
| 449 |
{ |
| 450 |
//LOG("upd1771_w: received byte 0x%02x\n", data); |
| 451 |
|
| 452 |
if (m_index < MAX_PACKET_SIZE) |
| 453 |
m_packet[m_index++] = data; |
| 454 |
else |
| 455 |
{ |
| 456 |
//logerror("upd1771_w: received byte 0x%02x overload!\n", data); |
| 457 |
return; |
| 458 |
} |
| 459 |
|
| 460 |
switch (m_packet[0]) |
| 461 |
{ |
| 462 |
case 0: |
| 463 |
m_state = STATE_SILENCE; |
| 464 |
m_index = 0; |
| 465 |
//logerror( "upd1771_w: ----------------silence state reset\n"); |
| 466 |
break; |
| 467 |
|
| 468 |
case 1: |
| 469 |
if (m_index == 10) |
| 470 |
{ |
| 471 |
m_state = STATE_NOISE; |
| 472 |
m_index = 0; |
| 473 |
|
| 474 |
m_nw_timbre = (m_packet[1] & 0xe0) >> 5; |
| 475 |
m_nw_period = ((uint32_t)m_packet[2] + 1) << 7; |
| 476 |
m_nw_volume = m_packet[3] & 0x1f; |
| 477 |
|
| 478 |
//very long clocked periods.. used for engine drones |
| 479 |
m_n_period[0] = (((uint32_t)m_packet[4]) + 1) << 7; |
| 480 |
m_n_period[1] = (((uint32_t)m_packet[5]) + 1) << 7; |
| 481 |
m_n_period[2] = (((uint32_t)m_packet[6]) + 1) << 7; |
| 482 |
|
| 483 |
m_n_volume[0] = m_packet[7] & 0x1f; |
| 484 |
m_n_volume[1] = m_packet[8] & 0x1f; |
| 485 |
m_n_volume[2] = m_packet[9] & 0x1f; |
| 486 |
|
| 487 |
//logerror( "upd1771_w: ----------------noise state reset\n"); |
| 488 |
} else { |
| 489 |
// supposedly timer adjusts here, to 512 cycles |
| 490 |
} |
| 491 |
|
| 492 |
break; |
| 493 |
|
| 494 |
case 2: |
| 495 |
if (m_index == 4) |
| 496 |
{ |
| 497 |
//logerror( "upd1771_w: ----------------tone state reset\n"); |
| 498 |
m_t_timbre = (m_packet[1] & 0xe0) >> 5; |
| 499 |
m_t_offset = (m_packet[1] & 0x1f); |
| 500 |
m_t_period = m_packet[2]; |
| 501 |
//smaller periods don't all equal to 0x20 |
| 502 |
if (m_t_period < 0x20) |
| 503 |
m_t_period = 0x20; |
| 504 |
|
| 505 |
m_t_volume = m_packet[3] & 0x1f; |
| 506 |
m_state = STATE_TONE; |
| 507 |
m_index = 0; |
| 508 |
} else { |
| 509 |
// supposedly timer adjusts here, to 512 cycles |
| 510 |
} |
| 511 |
break; |
| 512 |
|
| 513 |
case 0x1f: |
| 514 |
//6Khz(ish) DIGI playback |
| 515 |
|
| 516 |
//end capture |
| 517 |
{ |
| 518 |
bool have_all_data = false; |
| 519 |
if (m_index >= 2 && m_packet[m_index - 2] == 0xfe && m_packet[m_index - 1] == 0x00) |
| 520 |
{ |
| 521 |
//TODO play capture! |
| 522 |
if (m_index >= 6) |
| 523 |
{ |
| 524 |
// offsets 2 and 3 in the transferred pcm data seem to contain the number of samples |
| 525 |
uint16_t count = (m_packet[4] << 8) | m_packet[3]; |
| 526 |
count--; |
| 527 |
m_packet[3] = count & 0xff; |
| 528 |
m_packet[4] = (count >> 8); |
| 529 |
if (count == 0) |
| 530 |
{ |
| 531 |
m_index = 0; |
| 532 |
m_packet[0] = 0; |
| 533 |
m_state = STATE_ADPCM; |
| 534 |
have_all_data = true; |
| 535 |
} |
| 536 |
} |
| 537 |
} |
| 538 |
if (!have_all_data) { |
| 539 |
// supposedly timer adjusts here, to 512 cycles |
| 540 |
} |
| 541 |
} |
| 542 |
break; |
| 543 |
|
| 544 |
//garbage: wipe stack |
| 545 |
default: |
| 546 |
m_state = STATE_SILENCE; |
| 547 |
m_index = 0; |
| 548 |
break; |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
void upd1771c_device::pcm_write(int state) |
| 554 |
{ |
| 555 |
//RESET upon HIGH |
| 556 |
if (state != m_pc3) |
| 557 |
{ |
| 558 |
//logerror("upd1771_pc3 change!: state = %d\n", state); |
| 559 |
m_index = 0; |
| 560 |
m_packet[0] = 0; |
| 561 |
m_state = STATE_SILENCE; |
| 562 |
} |
| 563 |
|
| 564 |
m_pc3 = state; |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
//------------------------------------------------- |
| 569 |
// sound_stream_update - handle a stream update |
| 570 |
//------------------------------------------------- |
| 571 |
|
| 572 |
void upd1771c_device::sound_stream_update(short* output, int len) |
| 573 |
{ |
| 574 |
switch (m_state) |
| 575 |
{ |
| 576 |
case STATE_TONE: |
| 577 |
//logerror( "upd1771_STATE_TONE samps:%d %d %d %d %d %d\n",(int)samples, |
| 578 |
// (int)m_t_timbre,(int)m_t_offset,(int)m_t_volume,(int)m_t_period,(int)m_t_tpos); |
| 579 |
|
| 580 |
for (int sampindex = 0; sampindex < len; sampindex++) |
| 581 |
{ |
| 582 |
output[sampindex]=(WAVEFORMS[m_t_timbre][m_t_tpos]) * m_t_volume * 8; |
| 583 |
|
| 584 |
m_t_ppos++; |
| 585 |
if (m_t_ppos >= m_t_period) |
| 586 |
{ |
| 587 |
m_t_tpos++; |
| 588 |
if (m_t_tpos == 32) |
| 589 |
m_t_tpos = m_t_offset; |
| 590 |
|
| 591 |
m_t_ppos = 0; |
| 592 |
} |
| 593 |
} |
| 594 |
break; |
| 595 |
|
| 596 |
case STATE_NOISE: |
| 597 |
// TODO: improve this |
| 598 |
for (int sampindex = 0; sampindex < len; sampindex++) |
| 599 |
{ |
| 600 |
// "wavetable-LFSR" component |
| 601 |
int wlfsr_val = ((int)noise_tbl[m_nw_timbre][m_nw_tpos]) - 127; // data too wide |
| 602 |
|
| 603 |
m_nw_ppos++; |
| 604 |
if (m_nw_ppos >= m_nw_period) |
| 605 |
{ |
| 606 |
m_nw_tpos++; |
| 607 |
if (m_nw_tpos == NOISE_SIZE) |
| 608 |
m_nw_tpos = 0; |
| 609 |
m_nw_ppos = 0; |
| 610 |
} |
| 611 |
|
| 612 |
// mix in each of the noise's 3 pulse components |
| 613 |
signed char res[3]; |
| 614 |
for (int i = 0; i < 3; ++i) |
| 615 |
{ |
| 616 |
res[i] = m_n_value[i]; |
| 617 |
m_n_ppos[i]++; |
| 618 |
if (m_n_ppos[i] >= m_n_period[i]) |
| 619 |
{ |
| 620 |
m_n_ppos[i] = 0; |
| 621 |
m_n_value[i] = !m_n_value[i]; |
| 622 |
} |
| 623 |
} |
| 624 |
// not quite! |
| 625 |
chout[0]=res[0] * m_n_volume[0] * 4; |
| 626 |
chout[1]=res[1] * m_n_volume[1] * 4; |
| 627 |
chout[2]=res[2] * m_n_volume[2] * 4; |
| 628 |
chout[3]=wlfsr_val * m_nw_volume * 2; |
| 629 |
output[sampindex]= |
| 630 |
( |
| 631 |
((chout[0] + chout[1] + chout[2]) * 32) + |
| 632 |
chout[3] |
| 633 |
) * 2; |
| 634 |
|
| 635 |
|
| 636 |
} |
| 637 |
break; |
| 638 |
|
| 639 |
default: |
| 640 |
//fill buffer with silence |
| 641 |
memset(output,0,sizeof(short)*len); |
| 642 |
break; |
| 643 |
} |
| 644 |
} |