Previous 15994 Revisions Next

r7673 Thursday 1st April, 2010 at 15:53:56 UTC by Jonathan Gevaryahu
Added hardware comments and added preliminary noise support [PlgDavid]
[src/mess/audio]upd1771.c

src/mess/audio/upd1771.c
r7672r7673
11/**********************************************************************
22
3    NEC uPD1771
3    NEC uPD1771 as used in the Epoch Super Cassette Vision (SCV)
44
55    Made using recording/analysis on a Yeno (PAL Super Cassete Vision)
66    by plgDavid
77
8    Full markings on my 2 specimens are "NEC JAPAN 8431K9 D1771C 017"
9    31th week of 1984, mask rom #017
10
11    Ive seen mentions of a 006, 011 and 015 on part miner sites.
12    Since the chip generates tones using embeded wavetables,
13    it is probable other sounds are possible and were made for other embeded systems.
14    Its anyone's guess at this point in which products.
15   
16    upd17XXX devices are typically 4bit NEC MCUs, so it wouldnt be a stretch to
17    say that this chip is part of that lot.
18    Maybe mask roms 006,011 and 015 dont generate audio at all.
19
20     Used pinout in the SCV:
21
22     NC           1        28        NC
23     NC           2        27        NC
24     NC           3        26        ACK
25    !WR           4        25        D7
26    !CS           5        24        D6
27     PCM          6        23        D5
28     NC           7        22        D4
29     VCC          8        21        D3
30     6Mhz XIN     9        20        D2
31     6Mhz XOUT   10        19        D1
32     AUDOUT      11        18        D0
33     NC          12        17        GND
34     AUDOUT(inv) 13        16        VCC
35     GND         14        15        ? tied to pin 16 (VCC) thru a resistor (pullup?)
36
37    In the SCV:
38    pin  5 is tied to the !SCPU pin on the Epoch TV chip pin 29 (0x3600 writes)
39    pin  6 is tied to the   PC3 pin of the upD7801 CPU
40    and according to the Enri is used for 1 bit PCM injection.
41    pin 26 is tied to the  INT1 pin of the upD7801 (CPU pin 12),
42
43    1,2,3,28,27 dont generate any digital signals
44    6 seems to be lowered 2.5 ms before an audio write
45    7  is always low.
46    12 is always high
47
48    It is unknown which is the "real" VCC input betwwen pin 8 and 16,
49    same goes for GNDs on pin 14 and 17.
50
51    Pins 11 and 13 go to a special circuit, which according to kevtris's analysis
52    of my schematics, consist of a balanced output (not unlike XLR cables),
53    which are then combined togheter then sent to the RF box.
54
55    All NC pins are unknown, maybe some are  "test" pins.
56
57    All non PCM writes are made through adress 0x3600 on the upD7801
58    Instead of useing register=value, this chip require sending multiple
59    bytes for each command, one after the other.
60
861**********************************************************************/
962
1063#include "emu.h"
r7672r7673
1265#include "upd1771.h"
1366
1467
15#define LOG 1
68#define LOG
1669
1770#define MAX_PACKET_SIZE 16 //protection/padding max is really 10
1871
1972
2073
2174/*
22  Each of the 32 waveform has been sampled at 192Khz, filtered, and each level has been
23  calculated with averages on around 10 samples (removing the transition samples)
24  then quantized to 8bit signed. (not clear on the exact DAC details yet)
75  Each of the 8 waveforms have been sampled at 192Khz using period 0xFF,
76  filtered, and each of the 32 levels have been calculated with averages on around 10 samples
77  (removing the transition samples) then quantized to 8bit signed.
78  We are not clear on the exact DAC details yet, especially with regards to volume changes
79
80  External AC coupling is assumed in the use of this DAC, so we will center the 8bit data using a signed container
2581*/
2682const char WAVEFORMS[8][32]={
27
28{-5,-5,-5,-117,-116,-53,-10,127,120,108,97,-121,-121,-121,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-119,-119,-118,-2,-2,-2,-2,-2},
29{6,-21,-1,-41,-1,25,-35,-35,-1,-16,34,29,-37,-30,-33,-20,38,-15,50,-20,-20,-15,7,-20,77,-15,-37,69,93,-21,-38,-37},
30{-11,-4,-11,51,-9,-11,-11,84,87,-112,44,102,-86,-112,35,103,-12,51,-10,-12,-12,-9,-12,13,-11,-44,25,103,-12,-5,-90,-101},
31{40,98,31,98,-1,13,58,3,-18,45,-5,-13,-5,-13,-5,-13,-5,-13,-5,-13,-10,-15,-121,5,-17,45,-128,8,-16,-12,-16,-9},
32{-53,-101,-121,-128,-113,-77,-34,5,26,63,97,117,119,119,115,99,54,13,-13,-11,-2,3,31,52,62,74,60,51,38,22,8,-14},
33{-86,-128,-60,3,65,101,119,44,37,41,51,53,55,58,58,29,-12,74,82,77,59,113,52,21,24,34,39,45,48,48,48,-13},
34{-15,-18,-46,-67,-95,-111,-117,-124,-128,-123,-116,-105,-89,-72,-50,-21,2,16,46,76,95,111,118,119,119,119,117,110,97,75,47,18},
35{-84,-121,-128,-105,-51,7,38,66,93,97,93,88,89,96,102,111,116,118,118,119,118,118,117,117,118,118,117,117,117,115,85,-14}
36
83{ -5,   -5,  -5,-117,-116, -53, -10, 127, 120, 108,  97, -121,-121,-121,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,-119,-119,-118,  -2,  -2,  -2,  -2,  -2},
84{  6,  -21,  -1, -41,  -1,  25, -35, -35,  -1, -16,  34,   29, -37, -30, -33, -20,  38, -15,  50, -20, -20, -15,   7, -20,  77, -15, -37,  69,  93, -21, -38, -37},
85{ -11,  -4, -11,  51,  -9, -11, -11,  84,  87,-112,  44,  102, -86,-112,  35, 103, -12,  51, -10, -12, -12,  -9, -12,  13, -11, -44,  25, 103, -12,  -5, -90,-101},
86{  40,  98,  31,  98,  -1,  13,  58,   3, -18,  45,  -5,  -13,  -5, -13,  -5, -13,  -5, -13,  -5, -13, -10, -15,-121,   5, -17,  45,-128,   8, -16, -12, -16,  -9},
87{ -53,-101,-121,-128,-113, -77, -34,   5,  26,  63,  97,  117, 119, 119, 115,  99,  54,  13, -13, -11,  -2,   3,  31,  52,  62,  74,  60,  51,  38,  22,   8, -14},
88{ -86,-128, -60,   3,  65, 101, 119,  44,  37,  41,  51,   53,  55,  58,  58,  29, -12,  74,  82,  77,  59, 113,  52,  21,  24,  34,  39,  45,  48,  48,  48, -13},
89{ -15, -18, -46, -67, -95,-111,-117,-124,-128,-123,-116, -105, -89, -72, -50, -21,   2,  16,  46,  76,  95, 111, 118, 119, 119, 119, 117, 110,  97,  75,  47,  18},
90{ -84,-121,-128,-105, -51,   7,  38,  66,  93,  97,  93,   88,  89,  96, 102, 111, 116, 118, 118, 119, 118, 118, 117, 117, 118, 118, 117, 117, 117, 115,  85, -14}
3791};
3892
3993#define STATE_SILENCE 0
r7672r7673
4397typedef struct _upd1771_state upd1771_state;
4498struct _upd1771_state
4599{
46   sound_stream *channel;
47   devcb_resolved_write_line ack_out_func;
48   emu_timer *timer;
100    sound_stream *channel;
101    devcb_resolved_write_line ack_out_func;
102    emu_timer *timer;
49103
50   UINT8   packet[MAX_PACKET_SIZE];
51   UINT8   index;
52   UINT8   expected_bytes;
104    UINT8    packet[MAX_PACKET_SIZE];
105    UINT8    index;
106    UINT8    expected_bytes;
53107
54   UINT8   state;//0:silence, 1 noise, 2 tone
108    UINT8   state;//0:silence, 1 noise, 2 tone
55109
56   //tone
57   UINT8    t_timbre; //[0;  7]
58   UINT8    t_offset; //[0; 32]
59   UINT16   t_period; //[0;255]
60   UINT8    t_volume; //[0; 31]
110    //tone
111    UINT8    t_timbre; //[0;  7]
112    UINT8    t_offset; //[0; 32]
113    UINT16   t_period; //[0;255]
114    UINT8    t_volume; //[0; 31]
115    UINT8    t_tpos;//timber pos
116    UINT16   t_ppos;//period pos
61117
62   UINT8    t_tpos;//timber pos
63   UINT16   t_ppos;//period pos
118    //TODO noise wavetable LFSR
119
120    UINT8    n_value[3];  //[0;1]
121    UINT16   n_volume[3]; //[0; 31]
122    UINT32   n_period[3];
123    UINT32   n_ppos[3];   //period pos
124
64125};
65126
66127
67128INLINE upd1771_state *get_safe_token(running_device *device)
68129{
69   assert(device != NULL);
70   assert(device->token != NULL);
71   assert(device->type == SOUND);
72   assert(sound_get_type(device) == SOUND_UPD1771C);
73   return (upd1771_state *)device->token;
130    assert(device != NULL);
131    assert(device->token != NULL);
132    assert(device->type == SOUND);
133    assert(sound_get_type(device) == SOUND_UPD1771C);
134    return (upd1771_state *)device->token;
74135}
75136
76137
r7672r7673
106167
107168WRITE8_DEVICE_HANDLER( upd1771_w )
108169{
109   upd1771_state *state = get_safe_token( device );
170    upd1771_state *state = get_safe_token( device );
110171
111   //if (LOG)
112   //  logerror( "upd1771_w: received byte 0x%02x\n", data );
172    //if (LOG)
173    //  logerror( "upd1771_w: received byte 0x%02x\n", data );
113174
114   devcb_call_write_line( &state->ack_out_func, 0 );
175    devcb_call_write_line( &state->ack_out_func, 0 );
115176
116   state->packet[state->index++]=data;
177    state->packet[state->index++]=data;
117178
118   switch(state->packet[0]){
179    switch(state->packet[0]){
119180
120      case 0:
121      {
122         state->state = STATE_SILENCE;
123         state->index = 0;
124         //logerror( "upd1771_w: ----------------silence  state reset\n");
125      }break;
181        case 0:
182        {
183            state->state = STATE_SILENCE;
184            state->index = 0;
185            //logerror( "upd1771_w: ----------------silence  state reset\n");
186        }break;
126187
127      case 1:
128         if (state->index == 10){
129            state->state = STATE_NOISE; //TODO
130            state->index = 0;
131            //logerror( "upd1771_w: ----------------noise state reset\n");
132         }
133         else
134            timer_adjust_oneshot( state->timer, ticks_to_attotime( 512, device->clock ), 0 );
135      break;
188        case 1:
189            if (state->index == 10){
190                state->state = STATE_NOISE;
191                state->index = 0;
136192
137      case 2:
138         if (state->index == 4){
139            //logerror( "upd1771_w: ----------------tone  state reset\n");
140            state->t_timbre = (state->packet[1] & 0xE0) >> 5;
141            state->t_offset = (state->packet[1] & 0x1F);
142            state->t_period =  state->packet[2];
143            //smaller periods dont all equal to 0x20
193                //very long clocked periods.. used for engine drones
194                state->n_period[0] = (((UINT32)state->packet[4])+1)*128;
195                state->n_period[1] = (((UINT32)state->packet[5])+1)*128;
196                state->n_period[2] = (((UINT32)state->packet[6])+1)*128;
197
198                state->n_volume[0] = state->packet[7]& 0x1f;
199                state->n_volume[1] = state->packet[8]& 0x1f;
200                state->n_volume[2] = state->packet[9]& 0x1f;
201
202                //logerror( "upd1771_w: ----------------noise state reset\n");
203            }
204            else
205                timer_adjust_oneshot( state->timer, ticks_to_attotime( 512, device->clock ), 0 );
206        break;
207
208        case 2:
209            if (state->index == 4){
210                //logerror( "upd1771_w: ----------------tone  state reset\n");
211                state->t_timbre = (state->packet[1] & 0xE0) >> 5;
212                state->t_offset = (state->packet[1] & 0x1F);
213                state->t_period =  state->packet[2];
214                //smaller periods dont all equal to 0x20
144215                if (state->t_period < 0x20)
145216                    state->t_period = 0x20;
146217
147            state->t_volume =  state->packet[3] & 0x1f;
148            state->state = STATE_TONE;
149            state->index = 0;
150         }
151         else
152            timer_adjust_oneshot( state->timer, ticks_to_attotime( 512, device->clock ), 0 );
218                state->t_volume =  state->packet[3] & 0x1f;
219                state->state = STATE_TONE;
220                state->index = 0;
221            }
222            else
223                timer_adjust_oneshot( state->timer, ticks_to_attotime( 512, device->clock ), 0 );
153224
154      break;
225        break;
155226
156      //garbage: wipe stack
157      default:
158         state->index = 0;
159      break;
160   }
227        //garbage: wipe stack
228        default:
229            state->index = 0;
230        break;
231    }
161232}
162233
163234
164235static STREAM_UPDATE( upd1771c_update )
165236{
166   upd1771_state *state = get_safe_token( device );
167   stream_sample_t *buffer = outputs[0];
237    upd1771_state *state = get_safe_token( device );
238    stream_sample_t *buffer = outputs[0];
168239
169   switch(state->state){
170      case STATE_TONE:
171      {
172         //logerror( "upd1771_STATE_TONE samps:%d %d %d %d %d %d\n",(int)samples,
173         //    (int)state->t_timbre,(int)state->t_offset,(int)state->t_volume,(int)state->t_period,(int)state->t_tpos);
240    switch(state->state){
241        case STATE_TONE:
242        {
243            //logerror( "upd1771_STATE_TONE samps:%d %d %d %d %d %d\n",(int)samples,
244            //    (int)state->t_timbre,(int)state->t_offset,(int)state->t_volume,(int)state->t_period,(int)state->t_tpos);
174245
175         while ( samples > 0 ){
246            while ( --samples >= 0 ){
176247
177            *buffer = (WAVEFORMS[state->t_timbre][state->t_tpos])*state->t_volume * 2;
248                *buffer++ = (WAVEFORMS[state->t_timbre][state->t_tpos])*state->t_volume * 2;
178249
179             state->t_ppos++;
180            if (state->t_ppos >= state->t_period){
250                state->t_ppos++;
251                if (state->t_ppos >= state->t_period){
181252
182               state->t_tpos++;
183               if (state->t_tpos == 32)
184                  state->t_tpos = state->t_offset;
253                    state->t_tpos++;
254                    if (state->t_tpos == 32)
255                       state->t_tpos = state->t_offset;
185256
186               state->t_ppos = 0;
187            }
257                   state->t_ppos = 0;
258                }
259            }
260        }break;
188261
189            buffer++;
190            samples--;
191         }
192      }break;
262        case STATE_NOISE:
263        {
264            while (--samples >= 0 ){
193265
194      default:
195      {
196          //fill buffer with silence
197         while ( samples > 0 )
198         {
199            *buffer = 0;
200            buffer++;
201            samples--;
202         }
203      }
266                *buffer = 0;
267                //TODO implement "wavetable-LFSR" component
268                //mix in each of the noise's 3 pulse components
269                char res[3];
270                for (size_t i=0;i<3;++i){
204271
205      break;
206   }
272                      res[i] = state->n_value[i];
273                    state->n_ppos[i]++;
274                    if (state->n_ppos[i] >= state->n_period[i]){
275                        state->n_ppos[i] = 0;
276                        state->n_value[i] = !state->n_value[i];
277                    }
278                }
279                //not quite, but close.
280                *buffer+= ((res[0]*state->n_volume[0]) | (res[1]*state->n_volume[1]) | (res[2]*state->n_volume[2])) * 127;
207281
282                buffer++;
283            }
284        }break;
285
286        default:
287        {
288            //fill buffer with silence
289            while (--samples >= 0 ){
290                *buffer++ = 0;
291            }
292        }
293
294        break;
295    }
296
208297}
209298
210299
211300static TIMER_CALLBACK( upd1771c_callback )
212301{
213   running_device *device = (running_device *)ptr;
214   upd1771_state *state = get_safe_token( device );
302    running_device *device = (running_device *)ptr;
303    upd1771_state *state = get_safe_token( device );
215304
216   devcb_call_write_line( &state->ack_out_func, 1 );
305    devcb_call_write_line( &state->ack_out_func, 1 );
217306}
218307
219308
220309static DEVICE_START( upd1771c )
221310{
222   const upd1771_interface *intf = (const upd1771_interface *)device->baseconfig().static_config;
223   upd1771_state *state = get_safe_token( device );
224   int sample_rate = device->clock / 4;
311    const upd1771_interface *intf = (const upd1771_interface *)device->baseconfig().static_config;
312    upd1771_state *state = get_safe_token( device );
313    int sample_rate = device->clock / 4;
225314
315    /* resolve callbacks */
316    devcb_resolve_write_line( &state->ack_out_func, &intf->ack_callback, device );
226317
227   /* resolve callbacks */
228   devcb_resolve_write_line( &state->ack_out_func, &intf->ack_callback, device );
318    state->timer = timer_alloc( device->machine, upd1771c_callback, (void *)device );
229319
230   state->timer = timer_alloc( device->machine, upd1771c_callback, (void *)device );
320    state->channel = stream_create( device, 0, 1, sample_rate, state, upd1771c_update );
231321
232   state->channel = stream_create( device, 0, 1, sample_rate, state, upd1771c_update );
233
234   state_save_register_device_item_array( device, 0, state->packet );
235   state_save_register_device_item(device, 0, state->index );
236   state_save_register_device_item(device, 0, state->expected_bytes );
322    state_save_register_device_item_array( device, 0, state->packet );
323    state_save_register_device_item(device, 0, state->index );
324    state_save_register_device_item(device, 0, state->expected_bytes );
237325}
238326
239327
240328static DEVICE_RESET( upd1771c )
241329{
242   upd1771_state *state = get_safe_token( device );
330    upd1771_state *state = get_safe_token( device );
243331
244   state->index = 0;
245   state->expected_bytes = 0;
332    state->index = 0;
333    state->expected_bytes = 0;
246334}
247335
248336
r7672r7673
253341
254342DEVICE_GET_INFO( upd1771c )
255343{
256   switch (state)
257   {
258      /* --- the following bits of info are returned as 64-bit signed integers --- */
259      case DEVINFO_INT_TOKEN_BYTES:            info->i = sizeof(upd1771_state);            break;
344    switch (state)
345    {
346        /* --- the following bits of info are returned as 64-bit signed integers --- */
347        case DEVINFO_INT_TOKEN_BYTES:                info->i = sizeof(upd1771_state);                break;
260348
261      /* --- the following bits of info are returned as pointers to functions --- */
262      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME( upd1771c );   break;
263      case DEVINFO_FCT_RESET:                  info->reset = DEVICE_RESET_NAME( upd1771c );   break;
264      case DEVINFO_FCT_STOP:                  info->stop  = DEVICE_STOP_NAME( upd1771c );      break;
349        /* --- the following bits of info are returned as pointers to functions --- */
350        case DEVINFO_FCT_START:                      info->start = DEVICE_START_NAME( upd1771c );    break;
351        case DEVINFO_FCT_RESET:                      info->reset = DEVICE_RESET_NAME( upd1771c );    break;
352        case DEVINFO_FCT_STOP:                       info->stop  = DEVICE_STOP_NAME( upd1771c );        break;
265353
266
267      /* --- the following bits of info are returned as NULL-terminated strings --- */
268      case DEVINFO_STR_NAME:                  strcpy(info->s, "NEC uPD1771C 017");         break;
269      case DEVINFO_STR_FAMILY:               strcpy(info->s, "NEC uPD1771");               break;
270      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.0");                     break;
271      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);                  break;
272      case DEVINFO_STR_CREDITS:               strcpy(info->s, "Copyright the MAME & MESS Teams"); break;
273   }
354        /* --- the following bits of info are returned as NULL-terminated strings --- */
355        case DEVINFO_STR_NAME:                       strcpy(info->s, "NEC uPD1771C 017");            break;
356        case DEVINFO_STR_FAMILY:                     strcpy(info->s, "NEC uPD1771");                    break;
357        case DEVINFO_STR_VERSION:                    strcpy(info->s, "1.0");                            break;
358        case DEVINFO_STR_SOURCE_FILE:                strcpy(info->s, __FILE__);                        break;
359        case DEVINFO_STR_CREDITS:                    strcpy(info->s, "Copyright the MAME & MESS Teams"); break;
360    }
274361}
275362

Previous 15994 Revisions Next


© 1998-2018 The MESS Team