1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************
jedparse.c
Parser for .JED files into raw fusemaps.
****************************************************************************
Binary file format:
Offset
0 = Total number of fuses (32 bits)
4 = Raw fuse data, packed 8 bits at a time, LSB to MSB
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "jedparse.h"
/***************************************************************************
DEBUGGING
***************************************************************************/
#define LOG_PARSE 0
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
struct jed_parse_info
{
uint16_t checksum; /* checksum value */
uint32_t explicit_numfuses; /* explicitly specified number of fuses */
};
/***************************************************************************
UTILITIES
***************************************************************************/
/*-------------------------------------------------
ishex - is a character a valid hex digit?
-------------------------------------------------*/
static int ishex(char c)
{
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F');
}
/*-------------------------------------------------
hexval - the hex value of a given character
-------------------------------------------------*/
static int hexval(char c)
{
return (c >= '0' && c <= '9') ? (c - '0') : (10 + c - 'A');
}
/*-------------------------------------------------
isdelim - is a character a JEDEC delimiter?
-------------------------------------------------*/
static int isdelim(char c)
{
return (c == ' ' || c == 13 || c == 10);
}
/*-------------------------------------------------
suck_number - read a decimal value from the
character stream
-------------------------------------------------*/
static uint32_t suck_number(const uint8_t **psrc)
{
const uint8_t *src = *psrc;
uint32_t value = 0;
/* skip delimiters */
while (isdelim(*src))
src++;
/* loop over and accumulate digits */
while (isdigit(*src))
{
value = value * 10 + *src - '0';
src++;
}
/* return a pointer to the string afterwards */
*psrc = src;
return value;
}
/***************************************************************************
CORE IMPLEMENTATION
***************************************************************************/
/*-------------------------------------------------
process_field - process a single JEDEC field
-------------------------------------------------*/
static void process_field(jed_data *data, const uint8_t *cursrc, const uint8_t *srcend, jed_parse_info *pinfo)
{
/* switch off of the field type */
switch (*cursrc)
{
case 'Q':
cursrc++;
switch (*cursrc)
{
/* number of fuses */
case 'F':
cursrc++;
pinfo->explicit_numfuses = data->numfuses = suck_number(&cursrc);
break;
}
break;
/* default fuse state (0 or 1) */
case 'F':
cursrc++;
if (LOG_PARSE) printf("F%c\n", *cursrc);
if (*cursrc == '0')
memset(data->fusemap, 0x00, sizeof(data->fusemap));
else
memset(data->fusemap, 0xff, sizeof(data->fusemap));
break;
/* fuse states */
case 'L':
{
uint32_t curfuse;
/* read the fuse number */
cursrc++;
curfuse = suck_number(&cursrc);
if (LOG_PARSE) printf("L%u\n", curfuse);
/* read digits, skipping delimiters */
for ( ; cursrc < srcend; cursrc++)
if (*cursrc == '0' || *cursrc == '1')
{
jed_set_fuse(data, curfuse, *cursrc - '0');
if (LOG_PARSE) printf(" fuse %u = %d\n", curfuse, 0);
if (curfuse >= data->numfuses)
data->numfuses = curfuse + 1;
curfuse++;
}
break;
}
/* fuse checksum */
case 'C':
cursrc++;
if (cursrc < srcend + 4 && ishex(cursrc[0]) && ishex(cursrc[1]) && ishex(cursrc[2]) && ishex(cursrc[3]))
{
pinfo->checksum = 0;
while (ishex(*cursrc) && cursrc < srcend)
pinfo->checksum = (pinfo->checksum << 4) | hexval(*cursrc++);
}
break;
}
}
/*-------------------------------------------------
jed_parse - parse a .JED file that has been
loaded raw into memory
-------------------------------------------------*/
int jed_parse(const void *data, size_t length, jed_data *result)
{
const uint8_t *cursrc = (const uint8_t *)data;
const uint8_t *srcend = cursrc + length;
const uint8_t *scan;
jed_parse_info pinfo;
uint16_t checksum;
int i;
/* initialize the output and the intermediate info struct */
memset(result, 0, sizeof(*result));
memset(&pinfo, 0, sizeof(pinfo));
/* first scan for the STX character; ignore anything prior */
while (cursrc < srcend && *cursrc != 0x02)
cursrc++;
if (cursrc >= srcend)
return pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */// license:GPL-2.0+
// copyright-holders:Joseph Zbiciak,Tim Lindner
/*
GI SP0256 Narrator Speech Processor
GI SPB640 Speech Buffer
By Joe Zbiciak. Ported to MESS by tim lindner.
Unimplemented:
- Microsequencer repeat count of zero
- Support for non bit-flipped ROMs
- SPB-640 perpherial/RAM bus
Copyright Joseph Zbiciak, all rights reserved.
Copyright tim lindner, all rights reserved.
- This source code is released as freeware for non-commercial purposes.
- You are free to use and redistribute this code in modified or
unmodified form, provided you list us in the credits.
- If you modify this source code, you must add a notice to each
modified source file that it has been changed. If you're a nice
person, you will clearly mark each change too. :)
- If you wish to use this for commercial purposes, please contact us at
intvnut@gmail.com (Joseph Zbiciak), tlindner@macmess.org (tim lindner)
- This entire notice must remain in the source code.
Note: Bit flipping.
This emulation flips the bits on every byte of the memory map during
the sp0256_start() call.
If the memory map contents is modified during execution (accross of ROM
bank switching) the bitrevbuff() call must be called after the section
of ROM is modified.
*/
#include "emu.h"
#include "sp0256.h"
#define CLOCK_DIVIDER (7*6*8)
#define HIGH_QUALITY
#define SCBUF_SIZE (4096) /* Must be power of 2 */
#define SCBUF_MASK (SCBUF_SIZE - 1)
#define PER_PAUSE (64) /* Equiv timing period for pauses. */
#define PER_NOISE (64) /* Equiv timing period for noise. */
#define FIFO_ADDR (0x1800 << 3) /* SP0256 address of SPB260 speech FIFO. */
#define VERBOSE 0
#define DEBUG_FIFO 0
#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
#define LOG_FIFO(x) do { if (DEBUG_FIFO) logerror x; } while (0)
#define SET_SBY(line_state) { \
if (m_sby_line != line_state) \
{ \
m_sby_line = line_state; \
m_sby_cb(m_sby_line); \
} \
}
/* ======================================================================== */
/* qtbl -- Coefficient Quantization Table. This comes from a */
/* SP0250 data sheet, and should be correct for SP0256. */
/* ======================================================================== */
static const INT16 qtbl[128] =
{
0, 9, 17, 25, 33, 41, 49, 57,
65, 73, 81, 89, 97, 105, 113, 121,
129, 137, 145, 153, 161, 169, 177, 185,
193, 201, 209, 217, 225, 233, 241, 249,
257, 265, 273, 281, 289, 297, 301, 305,
309, 313, 317, 321, 325, 329, 333, 337,
341, 345, 349, 353, 357, 361, 365, 369,
373, 377, 381, 385, 389, 393, 397, 401,
405, 409, 413, 417, 421, 425, 427, 429,
431, 433, 435, 437, 439, 441, 443, 445,
447, 449, 451, 453, 455, 457, 459, 461,
463, 465, 467, 469, 471, 473, 475, 477,
479, 481, 482, 483, 484, 485, 486, 487,
488, 489, 490, 491, 492, 493, 494, 495,
496, 497, 498, 499, 500, 501, 502, 503,
504, 505, 506, 507, 508, 509, 510, 511
};
// device type definition
const device_type SP0256 = &device_creator<sp0256_device>;
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
sp0256_device::sp0256_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, SP0256, "SP0256", tag, owner, clock, "sp0256", __FILE__),
device_sound_interface(mconfig, *this),
m_rom(*this, DEVICE_SELF),
m_drq_cb(*this),
m_sby_cb(*this)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void sp0256_device::device_start()
{
m_drq_cb.resolve_safe();
m_sby_cb.resolve_safe();
m_drq_cb(1);
m_sby_cb(1);
m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() / CLOCK_DIVIDER);
/* -------------------------------------------------------------------- */
/* Configure our internal variables. */
/* -------------------------------------------------------------------- */
m_filt.rng = 1;
/* -------------------------------------------------------------------- */
/* Allocate a scratch buffer for generating ~10kHz samples. */
/* -------------------------------------------------------------------- */
m_scratch = auto_alloc_array(machine(), INT16, SCBUF_SIZE);
save_pointer(NAME(m_scratch), SCBUF_SIZE);
m_sc_head = m_sc_tail = 0;
/* -------------------------------------------------------------------- */
/* Set up the microsequencer's initial state. */
/* -------------------------------------------------------------------- */
m_halted = 1;
m_filt.rpt = -1;
m_lrq = 0x8000;
m_page = 0x1000 << 3;
m_silent = 1;
/* -------------------------------------------------------------------- */
/* Setup the ROM. */
/* -------------------------------------------------------------------- */
// the rom is not supposed to be reversed first; according to Joe Zbiciak.
// see http://forums.bannister.org/ubbthreads.php?ubb=showflat&Number=72385#Post72385
// TODO: because of this, check if the bitrev functions are even used anywhere else
// bitrevbuff(m_rom, 0, 0xffff);
m_lrq_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sp0256_device::set_lrq_timer_proc),this));
// save device variables
save_item(NAME(m_sby_line));
save_item(NAME(m_cur_len));
save_item(NAME(m_silent));
save_item(NAME(m_sc_head));
save_item(NAME(m_sc_tail));
save_item(NAME(m_lrq));
save_item(NAME(m_ald));
save_item(NAME(m_pc));
save_item(NAME(m_stack));
save_item(NAME(m_fifo_sel));
save_item(NAME(m_halted));
save_item(NAME(m_mode));
save_item(NAME(m_page));
save_item(NAME(m_fifo_head));
save_item(NAME(m_fifo_tail));
save_item(NAME(m_fifo_bitp));
save_item(NAME(m_fifo));
// save filter variables
save_item(NAME(m_filt.rpt));
save_item(NAME(m_filt.cnt));
save_item(NAME(m_filt.per));
save_item(NAME(m_filt.rng));
save_item(NAME(m_filt.amp));
save_item(NAME(m_filt.f_coef));
save_item(NAME(m_filt.b_coef));
save_item(NAME(m_filt.z_data));
save_item(NAME(m_filt.r));
save_item(NAME(m_filt.interp));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void sp0256_device::device_reset()
{
// reset FIFO and SP0256
m_fifo_head = m_fifo_tail = m_fifo_bitp = 0;
memset(&m_filt, 0, sizeof(m_filt));
m_halted = 1;
m_filt.rpt = -1;
m_filt.rng = 1;
m_lrq = 0x8000;
m_ald = 0x0000;
m_pc = 0x0000;
m_stack = 0x0000;
m_fifo_sel = 0;
m_mode = 0;
m_page = 0x1000 << 3;
m_silent = 1;
m_sby_line = 0;
m_drq_cb(1);
SET_SBY(1)
m_lrq = 0;
m_lrq_timer->adjust(attotime::from_ticks(50, m_clock));
}
/* ======================================================================== */
/* LIMIT -- Limiter function for digital sample output. */
/* ======================================================================== */
INLINE INT16 limit(INT16 s)
{
#ifdef HIGH_QUALITY /* Higher quality than the original, but who cares? */
if (s > 8191) return 8191;
if (s < -8192) return -8192;
#else
if (s > 127) return 127;
if (s < -128) return -128;
#endif
return s;
}
/* ======================================================================== */
/* LPC12_UPDATE -- Update the 12-pole filter, outputting samples. */
/* ======================================================================== */
INLINE int lpc12_update(struct lpc12_t *f, int num_samp, INT16 *out, UINT32 *optr)
{
int i, j;
INT16 samp;
int do_int;
int oidx = *optr;
/* -------------------------------------------------------------------- */
/* Iterate up to the desired number of samples. We actually may */
/* break out early if our repeat count expires. */
/* -------------------------------------------------------------------- */
for (i = 0; i < num_samp; i++)
{
/* ---------------------------------------------------------------- */
/* Generate a series of periodic impulses, or random noise. */
/* ---------------------------------------------------------------- */
do_int = 0;
samp = 0;
if (f->per)
{
if (f->cnt <= 0)
{
f->cnt += f->per;
samp = f->amp;
f->rpt--;
do_int = f->interp;
for (j = 0; j < 6; j++)
f->z_data[j][1] = f->z_data[j][0] = 0;
} else
{
samp = 0;
f->cnt--;
}
} else
{
int bit;
if (--f->cnt <= 0)
{
do_int = f->interp;
f->cnt = PER_NOISE;
f->rpt--;
for (j = 0; j < 6; j++)
f->z_data[j][0] = f->z_data[j][1] = 0;
}
bit = f->rng & 1;
f->rng = (f->rng >> 1) ^ (bit ? 0x4001 : 0);
if (bit) { samp = f->amp; }
else { samp = -f->amp; }
}
/* ---------------------------------------------------------------- */
/* If we need to, process the interpolation registers. */
/* ---------------------------------------------------------------- */
if (do_int)
{
f->r[0] += f->r[14];
f->r[1] += f->r[15];
f->amp = (f->r[0] & 0x1F) << (((f->r[0] & 0xE0) >> 5) + 0);
f->per = f->r[1];
do_int = 0;
}
/* ---------------------------------------------------------------- */
/* Stop if we expire our repeat counter and return the actual */
/* number of samples we did. */
/* ---------------------------------------------------------------- */
if (f->
|