Previous 15994 Revisions Next

r7109 Thursday 21st January, 2010 at 18:34:02 UTC by Wilbert Pol
[SCV] Implemented upd177c audio. [plgDavid]
[docs]messnew.txt
[src/mess/audio]upd1771.c

src/mess/audio/upd1771.c
r7108r7109
22
33    NEC uPD1771
44
5    Made using recording/analysis on a Yeno (PAL Super Cassete Vision)
6    by plgDavid
7
58**********************************************************************/
69
710#include "emu.h"
r7108r7109
1114
1215#define LOG 1
1316
14#define MAX_PACKET_SIZE 1
17#define MAX_PACKET_SIZE 16 //protection/padding max is really 1
1518
1619
20
21/*
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)
25*/
26const 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
37};
38
39#define STATE_SILENCE 0
40#define STATE_NOISE   1
41#define STATE_TONE    2
42
1743typedef struct _upd1771_state upd1771_state;
1844struct _upd1771_state
1945{
r7108r7109
2450   UINT8   packet[MAX_PACKET_SIZE];
2551   UINT8   index;
2652   UINT8   expected_bytes;
53
54   UINT8   state;//0:silence, 1 noise, 2 tone
55
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]
61
62   UINT8    t_tpos;//timber pos
63   UINT16   t_ppos;//period pos
2764};
2865
2966
r7108r7109
3774}
3875
3976
77/*
78*************TONE*****************
79Tone consist of a wavetable playback mechanism.
80Each wavetable is a looping period of 32 samples but can be played with an offset from any point in the table
81effectively shrinking the sample loop, thus allowing different pitch "macros ranges" to be played.
82This method is rather crude because the spectrum of the sound get heavily altered...
83unless that was the intent.
84
85Tone Write (4 bytes):
86
87Byte0: 0x02
88
89Byte1: 0bTTTOOOOO
90  MSB 3 bits of Timbre (8 wavetables)
91  LSB 5 bits offset in the table.
92
93Byte2: 0bPPPPPPPP
94  8bits of clock divider/period
95  Anything under <= 0x20 give the same value
96
97Byte3: 0b???VVVVV
98   MSB 3 bits unknown
99   LSB 5 bits of "Volume"
100
101   Note: volume is not a volume in a normal sense but some kind
102   of bit cropping/rounding.
103*/
104
105
106
40107WRITE8_DEVICE_HANDLER( upd1771_w )
41108{
42109   upd1771_state *state = get_safe_token( device );
43110
44   if (LOG)
45      logerror( "upd1771_w: received byte 0x%02x\n", data );
111   //if (LOG)
112   //   logerror( "upd1771_w: received byte 0x%02x\n", data );
46113
47   state->packet[ state->index ] = data;
48   state->index = state->index + 1;
49
50114   devcb_call_write_line( &state->ack_out_func, 0 );
51115
52   /* Start of a new command */
53   if ( state->expected_bytes == 0 )
54   {
55      switch ( data )
116   state->packet[state->index++]=data;
117
118   switch(state->packet[0]){
119
120      case 0:
56121      {
57      case 0x00:      /* 00 - 1 byte command */
58         state->expected_bytes = 1;
59         break;
60      case 0x01:      /* 01 - 10 byte command */
61         state->expected_bytes = 10;
62      case 0x02:      /* 02 - 4 byte command */
63         state->expected_bytes = 4;
64         break;
122         state->state = STATE_SILENCE;
123         state->index = 0;
124         //logerror( "upd1771_w: ----------------silence  state reset\n");
125      }break;
126
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;
136
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
144                if (state->t_period < 0x20)
145                    state->t_period = 0x20;
146
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 );
153
154      break;
155
156      //garbage: wipe stack
65157      default:
66         if (LOG)
67            logerror("upd1771: unknown command %02x received\n", data );
68         state->expected_bytes = 99;
69         break;
70      }
158         state->index = 0;
159      break;
71160   }
72
73   if ( state->index == state->expected_bytes )
74   {
75      /* The command packet has been transferred, handle the command */
76      if (LOG)
77         logerror("upd1771_w: handle command %02x\n", state->packet[0] );
78      state->expected_bytes = 0;
79   }
80   else
81   {
82      /* We need more data to complete the command packet */
83      /* Trigger ACK after 512??? cycles */
84      timer_adjust_oneshot( state->timer, ticks_to_attotime( 512, device->clock ), 0 );
85   }
86
87   state->index = state->index % MAX_PACKET_SIZE;
88161}
89162
90163
91164static STREAM_UPDATE( upd1771c_update )
92165{
93//   upd1771_state *state = (upd1771_state *)param;
166   upd1771_state *state = get_safe_token( device );
94167   stream_sample_t *buffer = outputs[0];
95168
96   while ( samples > 0 )
97   {
98      *buffer = 0;
99      buffer++;
100      samples--;
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);
174
175         while ( samples > 0 ){
176
177            *buffer = (WAVEFORMS[state->t_timbre][state->t_tpos])*state->t_volume * 2;
178
179             state->t_ppos++;
180            if (state->t_ppos >= state->t_period){
181
182               state->t_tpos++;
183               if (state->t_tpos == 32)
184                  state->t_tpos = state->t_offset;
185
186               state->t_ppos = 0;
187            }
188
189            buffer++;
190            samples--;
191         }
192      }break;
193
194      default:
195      {
196          //fill buffer with silence
197         while ( samples > 0 )
198         {
199            *buffer = 0;
200            buffer++;
201            samples--;
202         }
203      }
204
205      break;
101206   }
207
102208}
103209
104210
r7108r7109
117223   upd1771_state *state = get_safe_token( device );
118224   int sample_rate = device->clock / 4;
119225
226
120227   /* resolve callbacks */
121228   devcb_resolve_write_line( &state->ack_out_func, &intf->ack_callback, device );
122229
r7108r7109
139246}
140247
141248
249static DEVICE_STOP( upd1771c )
250{
251}
252
253
142254DEVICE_GET_INFO( upd1771c )
143255{
144256   switch (state)
r7108r7109
149261      /* --- the following bits of info are returned as pointers to functions --- */
150262      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME( upd1771c );   break;
151263      case DEVINFO_FCT_RESET:                  info->reset = DEVICE_RESET_NAME( upd1771c );   break;
264      case DEVINFO_FCT_STOP:                  info->stop  = DEVICE_STOP_NAME( upd1771c );      break;
152265
266
153267      /* --- the following bits of info are returned as NULL-terminated strings --- */
154      case DEVINFO_STR_NAME:                  strcpy(info->s, "NEC uPD1771C");            break;
268      case DEVINFO_STR_NAME:                  strcpy(info->s, "NEC uPD1771C 017");         break;
155269      case DEVINFO_STR_FAMILY:               strcpy(info->s, "NEC uPD1771");               break;
156270      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.0");                     break;
157271      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);                  break;
docs/messnew.txt
r7108r7109
2828
2929- [MIKROMIK] Fixed memory banking regression. [Curt Coder]
3030
31- [SCV] Implemented upd177c audio. [plgDavid]
3132
3233
34
3335Imgtool Changes:
3436----------------
3537(none)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team