Previous 15994 Revisions Next

r6410 Wednesday 18th November, 2009 at 07:38:35 UTC by Jonathan Gevaryahu
Got rid of R->OldNoise since it causes problems for gamegear/sms. Changed noise taps accordingly. Redid change to gamegear/sms for XOR vs XNOR, now verified by Justin Kerk. Verified gamegear noise taps thanks to sample provided by Justin Kerk.
Add stereo sound support to sn76496.c for gamegear.
Hooked up gamegear as stereo.
[src/emu/sound]sn76496.c sn76496.h
[src/mess/drivers]sms.c
[src/mess/includes]sms.h
[src/mess/machine]sms.c

src/emu/sound/sn76496.c
r6409r6410
3030  The register, connected to a z80 port, means:
3131  for bits 7  6  5  4  3  2  1  0
3232           L3 L2 L1 L0 R3 R2 R1 R0
33  Noise is an XOR function, and audio output is negated before being output.
3334  ** NCR7496 (as used on the Tandy 1000) is similar to the SN76489 but with a
3435  different noise LFSR patttern: taps on bits A and E, output on E
3536  It uses a 15-bit ring buffer for periodic noise/arbitrary duty cycle.
r6409r6410
6263  Fix screeching in regulus: When summing together four equal channels, the
6364  size of the max amplitude per channel should be 1/4 of the max range, not
6465  1/3. Added NCR7496.
66 
67  18/11/2009 : Lord Nightmare
68  Modify Init functions to support negating the audio output. The gamegear
69  psg does this. Change gamegear and sega psgs to use XOR rather than XNOR
70  based on testing. Got rid of R->OldNoise and fixed taps accordingly.
71  Added stereo support for game gear.
6572
66  TODO: * Implement a function for setting stereo regs for the game gear.
67          Requires making the core support both mono and stereo, and have
68          a select register which determines which channels go where.
69        * Implement the TMS9919 which is an earlier version, possibly
73  TODO: * Implement the TMS9919 which is an earlier version, possibly
7074          lacking the /8 clock divider, of the SN76489, and hence would
7175          have a max clock of 500Khz and 4 clocks per sample, as opposed to
7276          max of 4Mhz and 32 clocks per sample on the SN76489A.
r6409r6410
7478          to be 'sanitized' first. Also is stereo, similar to game gear.
7579        * Test the NCR7496; Smspower says the whitenoise taps are A and E,
7680          but this needs verification on real hardware.
77        * Test the SMS PSG/Gamegear PSG to see whether it uses XOR or XNOR
78          taps. (17/11/2009: this seems to be XNOR? Need a better sample.)
7981        * Factor out common code so that the SAA1099 can share some code.
8082***************************************************************************/
8183
r6409r6410
101103   INT32 FeedbackMask;   /* mask for feedback */
102104   INT32 WhitenoiseTaps;   /* mask for white noise taps */
103105   INT32 FeedbackInvert;   /* feedback invert flag (xor vs xnor) */
106   INT32 Negate;      /* output negate flag */
107   INT32 Stereo;      /* whether we're dealing with stereo or not */
108   INT32 StereoMask;   /* the stereo output mask */
104109   INT32 Period[4];   /* Length of 1/2 of waveform */
105110   INT32 Count[4];      /* Position within the waveform */
106   INT32 OldNoise;      /* 1 bit output of the PREVIOUS noise output */
107111   INT32 Output[4];   /* 1-bit output of each channel, pre-volume */
108112   INT32 CyclestoREADY;/* number of cycles until the READY line goes active */
109113};
r6409r6410
132136   return (R->CyclestoREADY? 0 : 1);
133137}
134138
139WRITE8_DEVICE_HANDLER( sn76496_stereo_w )
140{
141   sn76496_state *R = get_safe_token(device);
142   stream_update(R->Channel);
143   if (R->Stereo) R->StereoMask = data;
144   else fatalerror("Call to stereo write with mono chip!\n");
145}
146
135147WRITE8_DEVICE_HANDLER( sn76496_w )
136148{
137149   sn76496_state *R = get_safe_token(device);
r6409r6410
192204            R->Period[3] = ((n&3) == 3) ? 2 * R->Period[2] : (1 << (5+(n&3)));
193205                 /* Reset noise shifter */
194206            R->RNG = R->FeedbackMask;
195            R->OldNoise = 0;
196            R->Output[3] = R->OldNoise;
197            R->OldNoise = R->RNG & 1;
207            R->Output[3] = R->RNG & 1;
198208         }
199209         break;
200210   }
r6409r6410
204214{
205215   int i;
206216   sn76496_state *R = (sn76496_state *)param;
207   stream_sample_t *buffer = outputs[0];
217   stream_sample_t *lbuffer = outputs[0];
218   stream_sample_t *rbuffer = outputs[1];
208219
209
210220   while (samples > 0)
211221   {
212222   // clock chip once
213      INT16 out;
223      INT16 out = 0;
224      INT16 out2 = 0;
214225
215226      /* decrement Cycles to READY by one */
216227      if (R->CyclestoREADY >0) R->CyclestoREADY--;
r6409r6410
254265               R->RNG >>= 1;
255266            }
256267         }
257         R->Output[3] = R->OldNoise;
258         R->OldNoise = R->RNG & 1;
268         R->Output[3] = R->RNG & 1;
259269         R->Count[3] = R->Period[3];
260270      }
261271/* //bipolar output, doesn't seem to work right with sonic 2 on gamegear at least
r6409r6410
264274         +(R->Output[2]?R->Volume[2]:(0-R->Volume[2]))
265275         +(R->Output[3]?R->Volume[3]:(0-R->Volume[3]));
266276*/
267      out = (R->Output[0]?R->Volume[0]:0)
268         +(R->Output[1]?R->Volume[1]:0)
269         +(R->Output[2]?R->Volume[2]:0)
270         +(R->Output[3]?R->Volume[3]:0);
277      if (R->Stereo)
278      {
279         out = (((R->StereoMask&0x10)&&R->Output[0])?R->Volume[0]:0)
280            + (((R->StereoMask&0x20)&&R->Output[1])?R->Volume[1]:0)
281            + (((R->StereoMask&0x40)&&R->Output[2])?R->Volume[2]:0)
282            + (((R->StereoMask&0x80)&&R->Output[3])?R->Volume[3]:0);
283           
284         out2 = (((R->StereoMask&0x1)&&R->Output[0])?R->Volume[0]:0)
285            + (((R->StereoMask&0x2)&&R->Output[1])?R->Volume[1]:0)
286            + (((R->StereoMask&0x4)&&R->Output[2])?R->Volume[2]:0)
287            + (((R->StereoMask&0x8)&&R->Output[3])?R->Volume[3]:0);
288      }
289      else
290      {
291         out = (R->Output[0]?R->Volume[0]:0)
292            +(R->Output[1]?R->Volume[1]:0)
293            +(R->Output[2]?R->Volume[2]:0)
294            +(R->Output[3]?R->Volume[3]:0);
295      }
271296
272      *(buffer++) = out;
297      if(R->Negate) { out = -out; out2 = -out2; }
273298
299      *(lbuffer++) = out;
300      if (R->Stereo) *(rbuffer++) = out2;
274301      samples--;
275302   }
276303}
r6409r6410
294321   for (i = 0;i < 15;i++)
295322   {
296323      /* limit volume to avoid clipping */
297      if (out > MAX_OUTPUT / 3) R->VolTable[i] = MAX_OUTPUT / 3;
324      if (out > MAX_OUTPUT / 4) R->VolTable[i] = MAX_OUTPUT / 4;
298325      else R->VolTable[i] = out;
299326
300327      out /= 1.258925412;   /* = 10 ^ (2/20) = 2dB */
r6409r6410
304331
305332
306333
307static int SN76496_init(const device_config *device, sn76496_state *R)
334static int SN76496_init(const device_config *device, sn76496_state *R, int stereo)
308335{
309336   int sample_rate = device->clock/16;
310337   int i;
311338
312   R->Channel = stream_create(device,0,1,sample_rate,R,SN76496Update);
339   R->Channel = stream_create(device,0,(stereo?2:1),sample_rate,R,SN76496Update);
313340
314341   for (i = 0;i < 4;i++) R->Volume[i] = 0;
315342
r6409r6410
330357   R->WhitenoiseTaps = 0x03;   /* mask for white noise taps */
331358   R->FeedbackInvert = 0; /* feedback invert flag */
332359   R->CyclestoREADY = 1; /* assume ready is not active immediately on init. is this correct?*/
360   R->Negate = 0; /* channels are not negated */
361   R->Stereo = stereo; /* depends on init */
362   R->StereoMask = 0xFF; /* all channels enabled */
333363
334364   R->RNG = R->FeedbackMask;
335   R->OldNoise = 0;
336   R->Output[3] = R->OldNoise;
337   R->OldNoise = R->RNG & 1;
365   R->Output[3] = R->RNG & 1;
338366
339367   return 0;
340368}
341369
342370
343static void generic_start(const device_config *device, int feedbackmask, int noisetaps, int feedbackinvert)
371static void generic_start(const device_config *device, int feedbackmask, int noisetaps, int feedbackinvert, int negate, int stereo)
344372{
345373   sn76496_state *chip = get_safe_token(device);
346374
347   if (SN76496_init(device,chip) != 0)
375   if (SN76496_init(device,chip,stereo) != 0)
348376      fatalerror("Error creating SN76496 chip");
349377   SN76496_set_gain(chip, 0);
350378
351379   chip->FeedbackMask = feedbackmask;
352380   chip->WhitenoiseTaps = noisetaps;
353381   chip->FeedbackInvert = feedbackinvert;
382   chip->Negate = negate;
383   chip->Stereo = stereo;
354384
355385   state_save_register_device_item_array(device, 0, chip->VolTable);
356386   state_save_register_device_item_array(device, 0, chip->Register);
r6409r6410
360390   state_save_register_device_item(device, 0, chip->FeedbackMask);
361391   state_save_register_device_item(device, 0, chip->WhitenoiseTaps);
362392   state_save_register_device_item(device, 0, chip->FeedbackInvert);
393   state_save_register_device_item(device, 0, chip->Negate);
394   state_save_register_device_item(device, 0, chip->Stereo);
395   state_save_register_device_item(device, 0, chip->StereoMask);
363396   state_save_register_device_item_array(device, 0, chip->Period);
364397   state_save_register_device_item_array(device, 0, chip->Count);
365   state_save_register_device_item(device, 0, chip->OldNoise);
366398   state_save_register_device_item_array(device, 0, chip->Output);
367399   state_save_register_device_item(device, 0, chip->CyclestoREADY);
368400}
369401
402// function parameters: device, feedback destination tap, feedback source taps, xor(false)/xnor(true), normal(false)/invert(true), mono(false)/stereo(true)
370403
371404static DEVICE_START( sn76489 )
372405{
373   generic_start(device, 0x4000, 0x03, FALSE); // todo: verify; assumed to be the same as sn94624
406   generic_start(device, 0x8000, 0x06, FALSE, FALSE, FALSE); // todo: verify; assumed to be the same as sn94624
374407}
375408
376409static DEVICE_START( sn76489a )
377410{
378   generic_start(device, 0x8000, 0x06, TRUE); // verified by plgdavid
411   generic_start(device, 0x10000, 0x0C, TRUE, FALSE, FALSE); // verified by plgdavid
379412}
380413
381414static DEVICE_START( sn76494 )
382415{
383   generic_start(device, 0x8000, 0x06, TRUE); // todo: verify; assumed to be the same as sn76489a
416   generic_start(device, 0x10000, 0x0C, TRUE, FALSE, FALSE); // todo: verify; assumed to be the same as sn76489a
384417}
385418
386419static DEVICE_START( sn76496 )
387420{
388   generic_start(device, 0x8000, 0x06, TRUE); // todo: verify; assumed to be the same as sn76489a
421   generic_start(device, 0x10000, 0x0C, TRUE, FALSE, FALSE); // todo: verify; assumed to be the same as sn76489a
389422}
390423
391424static DEVICE_START( sn94624 )
392425{
393   generic_start(device, 0x4000, 0x03, FALSE); // verified by plgdavid
426   generic_start(device, 0x10000, 0x0C, FALSE, FALSE, FALSE); // verified by plgdavid
394427}
395428
396429static DEVICE_START( ncr7496 )
397430{
398   generic_start(device, 0x4000, 0x11, FALSE); // todo: verify; from smspower wiki
431   generic_start(device, 0x8000, 0x22, FALSE, FALSE, FALSE); // todo: verify; from smspower wiki
399432}
400433
401434static DEVICE_START( gamegear )
402435{
403   generic_start(device, 0x8000, 0x09, TRUE); // semi-verified by Lord Nightmare, need better sample
436   generic_start(device, 0x8000, 0x09, FALSE, TRUE, TRUE); // Verified by Justin Kerk
404437}
405438
406439static DEVICE_START( smsiii )
407440{
408   generic_start(device, 0x8000, 0x09, TRUE); // todo: verify; from smspower wiki, assumed to have same invert as gamegear
441   generic_start(device, 0x8000, 0x09, FALSE, TRUE, FALSE); // todo: verify; from smspower wiki, assumed to have same invert as gamegear
409442}
410443
411444
src/emu/sound/sn76496.h
r6409r6410
55
66READ8_DEVICE_HANDLER( sn76496_ready_r );
77WRITE8_DEVICE_HANDLER( sn76496_w );
8WRITE8_DEVICE_HANDLER( sn76496_stereo_w );
89
910DEVICE_GET_INFO( sn76496 );
1011DEVICE_GET_INFO( sn76489 );
src/mess/includes/sms.h
r6409r6410
3434WRITE8_HANDLER( sms_bios_w );
3535WRITE8_HANDLER( gg_sio_w );
3636READ8_HANDLER( gg_sio_r );
37READ8_HANDLER( gg_psg_r );
38WRITE8_HANDLER( gg_psg_w );
3937READ8_HANDLER( gg_input_port_2_r );
4038
4139void sms_pause_callback( running_machine *machine );
src/mess/machine/sms.c
r6409r6410
953953   return sms_state.gg_sio[offset];
954954}
955955
956
957READ8_HANDLER( gg_psg_r )
958{
959   return 0xff;
960}
961
962
963WRITE8_HANDLER( gg_psg_w )
964{
965   logerror("write %02X to psg at offset #%d.\n",data , offset);
966
967   /* D7 = Noise Left */
968   /* D6 = Tone3 Left */
969   /* D5 = Tone2 Left */
970   /* D4 = Tone1 Left */
971
972   /* D3 = Noise Right */
973   /* D2 = Tone3 Right */
974   /* D1 = Tone2 Right */
975   /* D0 = Tone1 Right */
976}
977
978
979956static void sms_machine_stop( running_machine *machine )
980957{
981958   /* Does the cartridge have SRAM that should be saved? */
src/mess/drivers/sms.c
r6409r6410
134134   ADDRESS_MAP_UNMAP_HIGH
135135   AM_RANGE(0x00, 0x00)                 AM_READ(gg_input_port_2_r)
136136   AM_RANGE(0x01, 0x05)                 AM_READWRITE(gg_sio_r, gg_sio_w)
137   AM_RANGE(0x06, 0x06)                 AM_READWRITE(gg_psg_r, gg_psg_w)
137   AM_RANGE(0x06, 0x06)                 AM_DEVWRITE("gamegear", sn76496_stereo_w)
138138   AM_RANGE(0x07, 0x07)                 AM_WRITE(sms_io_control_w)
139139   AM_RANGE(0x08, 0x08) AM_MIRROR(0x06) AM_WRITE(sms_bios_w)
140140   AM_RANGE(0x09, 0x09) AM_MIRROR(0x06) AM_WRITE(sms_io_control_w)
r6409r6410
659659   MDRV_SMSVDP_ADD("sms_vdp", _315_5378_intf)
660660
661661   /* sound hardware */
662   MDRV_SPEAKER_STANDARD_MONO("mono")
662   MDRV_SPEAKER_STANDARD_STEREO("lspeaker","rspeaker")
663663   MDRV_SOUND_ADD("gamegear", GAMEGEAR, XTAL_53_693175MHz/15)
664   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
664   MDRV_SOUND_ROUTE(0, "lspeaker", 1.00)
665   MDRV_SOUND_ROUTE(1, "rspeaker", 1.00)
665666
666667   /* cartridge */
667668   MDRV_CARTSLOT_ADD("cart1")

Previous 15994 Revisions Next


© 1998-2018 The MESS Team