src/emu/sound/sn76496.c
| r6294 | r6295 | |
| 12 | 12 | duty cycle channel. |
| 13 | 13 | |
| 14 | 14 | Noise emulation for all chips should be accurate: |
| 15 | | SN76489 uses a 15-bit shift register with taps on bits D and E, output on /E |
| 15 | SN76489 uses a 15-bit shift register with taps on bits D and E, output on E, |
| 16 | XOR function; SN94624 is identical to SN76489. |
| 16 | 17 | * It uses a 15-bit ring buffer for periodic noise/arbitrary duty cycle. |
| 17 | | SN76489A uses a 16-bit shift register with taps on bits D and F, output on F |
| 18 | SN76489A uses a 16-bit shift register with taps on bits D and E, output on F, |
| 19 | XNOR function |
| 18 | 20 | * It uses a 16-bit ring buffer for periodic noise/arbitrary duty cycle. |
| 19 | 21 | SN76494 and SN76496 are PROBABLY identical in operation to the SN76489A |
| 20 | 22 | * They have an audio input line which is mixed with the 4 channels of output. |
| r6294 | r6295 | |
| 36 | 38 | 28/04/2009 : Lord Nightmare |
| 37 | 39 | Add READY line readback; cleaned up struct a bit. Cleaned up comments. |
| 38 | 40 | Add more TODOs. Fixed some unsaved savestate related stuff. |
| 41 | |
| 42 | 04/11/2009 : Lord Nightmare |
| 43 | Changed the way that the invert works (it now selects between XOR and XNOR |
| 44 | for the taps), and added R->OldNoise to simulate the extra 0 that is always |
| 45 | output before the noise LFSR contents are after an LFSR reset. |
| 46 | This fixes SN76489/A to match chips. Added SN94624. |
| 39 | 47 | |
| 40 | 48 | TODO: * Implement a function for setting stereo regs for the game gear. |
| 41 | 49 | Requires making the core support both mono and stereo, and have |
| 42 | 50 | a select register which determines which channels go where. |
| 43 | | * Implement the TMS9919 and SN94624, which are earlier versions, |
| 44 | | possibly lacking the /8 clock divider, of the SN76489, and hence |
| 45 | | would have a max clock of 500Khz and 4 clocks per sample, as |
| 46 | | opposed to max of 4Mhz and 32 clocks per sample on the SN76489A |
| 51 | * Implement the TMS9919 which is an earlier version, possibly |
| 52 | lacking the /8 clock divider, of the SN76489, and hence would |
| 53 | have a max clock of 500Khz and 4 clocks per sample, as opposed to |
| 54 | max of 4Mhz and 32 clocks per sample on the SN76489A. |
| 47 | 55 | * Implement the T6W28; has registers in a weird order, needs writes |
| 48 | 56 | to be 'sanitized' first. Also is stereo, similar to game gear. |
| 49 | 57 | * Implement the NCR 7496; Is probably 100% compatible with SN76496, |
| r6294 | r6295 | |
| 73 | 81 | UINT32 RNG; /* noise generator LFSR*/ |
| 74 | 82 | INT32 FeedbackMask; /* mask for feedback */ |
| 75 | 83 | INT32 WhitenoiseTaps; /* mask for white noise taps */ |
| 76 | | INT32 WhitenoiseInvert; /* white noise invert flag */ |
| 84 | INT32 FeedbackInvert; /* feedback invert flag (xor vs xnor) */ |
| 77 | 85 | INT32 Period[4]; /* Length of 1/2 of waveform */ |
| 78 | 86 | INT32 Count[4]; /* Position within the waveform */ |
| 87 | INT32 OldNoise; /* 1 bit output of the PREVIOUS noise output, buffered by the volume amp */ |
| 79 | 88 | INT32 Output[4]; /* 1-bit output of each channel, pre-volume */ |
| 80 | 89 | INT32 CyclestoREADY;/* number of cycles until the READY line goes active */ |
| 81 | 90 | }; |
| r6294 | r6295 | |
| 247 | 256 | { |
| 248 | 257 | if (NOISEMODE == 1) /* White Noise Mode */ |
| 249 | 258 | { |
| 250 | | if (((R->RNG & R->WhitenoiseTaps) != R->WhitenoiseTaps) && ((R->RNG & R->WhitenoiseTaps) != 0)) /* crappy xor! */ |
| 259 | if ((((R->RNG & R->WhitenoiseTaps) != R->WhitenoiseTaps) && ((R->RNG & R->WhitenoiseTaps) != 0)) ^ R->FeedbackInvert ) /* XOR or XNOR */ |
| 251 | 260 | { |
| 252 | 261 | R->RNG >>= 1; |
| 253 | 262 | R->RNG |= R->FeedbackMask; |
| r6294 | r6295 | |
| 256 | 265 | { |
| 257 | 266 | R->RNG >>= 1; |
| 258 | 267 | } |
| 259 | | R->Output[3] = R->WhitenoiseInvert ? !(R->RNG & 1) : R->RNG & 1; |
| 260 | 268 | } |
| 261 | 269 | else /* Periodic noise mode */ |
| 262 | 270 | { |
| r6294 | r6295 | |
| 269 | 277 | { |
| 270 | 278 | R->RNG >>= 1; |
| 271 | 279 | } |
| 272 | | R->Output[3] = R->RNG & 1; |
| 273 | 280 | } |
| 281 | R->Output[3] = R->OldNoise; |
| 282 | R->OldNoise = R->RNG & 1; |
| 274 | 283 | R->Count[3] += R->Period[3]; |
| 275 | 284 | if (R->Output[3]) vol[3] += R->Period[3]; |
| 276 | 285 | } |
| r6294 | r6295 | |
| 344 | 353 | /* Default is SN76489 non-A */ |
| 345 | 354 | R->FeedbackMask = 0x4000; /* mask for feedback */ |
| 346 | 355 | R->WhitenoiseTaps = 0x03; /* mask for white noise taps */ |
| 347 | | R->WhitenoiseInvert = 1; /* white noise invert flag */ |
| 356 | R->FeedbackInvert = 0; /* feedback invert flag */ |
| 348 | 357 | R->CyclestoREADY = 1; /* assume ready is not active immediately on init. is this correct?*/ |
| 349 | 358 | |
| 350 | 359 | R->RNG = R->FeedbackMask; |
| 351 | | R->Output[3] = R->RNG & 1; |
| 360 | R->OldNoise = 0; |
| 361 | R->Output[3] = R->OldNoise; |
| 362 | R->OldNoise = R->RNG & 1; |
| 352 | 363 | |
| 353 | 364 | return 0; |
| 354 | 365 | } |
| 355 | 366 | |
| 356 | 367 | |
| 357 | | static void generic_start(const device_config *device, int feedbackmask, int noisetaps, int noiseinvert) |
| 368 | static void generic_start(const device_config *device, int feedbackmask, int noisetaps, int feedbackinvert) |
| 358 | 369 | { |
| 359 | 370 | sn76496_state *chip = get_safe_token(device); |
| 360 | 371 | |
| r6294 | r6295 | |
| 364 | 375 | |
| 365 | 376 | chip->FeedbackMask = feedbackmask; |
| 366 | 377 | chip->WhitenoiseTaps = noisetaps; |
| 367 | | chip->WhitenoiseInvert = noiseinvert; |
| 378 | chip->FeedbackInvert = feedbackinvert; |
| 368 | 379 | |
| 369 | 380 | state_save_register_device_item_array(device, 0, chip->VolTable); |
| 370 | 381 | state_save_register_device_item_array(device, 0, chip->Register); |
| r6294 | r6295 | |
| 373 | 384 | state_save_register_device_item(device, 0, chip->RNG); |
| 374 | 385 | state_save_register_device_item(device, 0, chip->FeedbackMask); |
| 375 | 386 | state_save_register_device_item(device, 0, chip->WhitenoiseTaps); |
| 376 | | state_save_register_device_item(device, 0, chip->WhitenoiseInvert); |
| 387 | state_save_register_device_item(device, 0, chip->FeedbackInvert); |
| 377 | 388 | state_save_register_device_item_array(device, 0, chip->Period); |
| 378 | 389 | state_save_register_device_item_array(device, 0, chip->Count); |
| 390 | state_save_register_device_item(device, 0, chip->OldNoise); |
| 379 | 391 | state_save_register_device_item_array(device, 0, chip->Output); |
| 380 | 392 | state_save_register_device_item(device, 0, chip->CyclestoREADY); |
| 381 | 393 | } |
| r6294 | r6295 | |
| 383 | 395 | |
| 384 | 396 | static DEVICE_START( sn76489 ) |
| 385 | 397 | { |
| 386 | | generic_start(device, 0x4000, 0x03, TRUE); |
| 398 | generic_start(device, 0x4000, 0x03, FALSE); |
| 387 | 399 | } |
| 388 | 400 | |
| 389 | 401 | static DEVICE_START( sn76489a ) |
| 390 | 402 | { |
| 391 | | generic_start(device, 0x8000, 0x06, FALSE); |
| 403 | generic_start(device, 0x8000, 0x06, TRUE); |
| 392 | 404 | } |
| 393 | 405 | |
| 394 | 406 | static DEVICE_START( sn76494 ) |
| 395 | 407 | { |
| 396 | | generic_start(device, 0x8000, 0x06, FALSE); |
| 408 | generic_start(device, 0x8000, 0x06, TRUE); |
| 397 | 409 | } |
| 398 | 410 | |
| 399 | 411 | static DEVICE_START( sn76496 ) |
| 400 | 412 | { |
| 401 | | generic_start(device, 0x8000, 0x06, FALSE); |
| 413 | generic_start(device, 0x8000, 0x06, TRUE); |
| 402 | 414 | } |
| 403 | 415 | |
| 416 | static DEVICE_START( sn94624 ) |
| 417 | { |
| 418 | generic_start(device, 0x4000, 0x03, FALSE); |
| 419 | } |
| 420 | |
| 404 | 421 | static DEVICE_START( gamegear ) |
| 405 | 422 | { |
| 406 | | generic_start(device, 0x8000, 0x09, FALSE); |
| 423 | generic_start(device, 0x8000, 0x09, TRUE); |
| 407 | 424 | } |
| 408 | 425 | |
| 409 | 426 | static DEVICE_START( smsiii ) |
| 410 | 427 | { |
| 411 | | generic_start(device, 0x8000, 0x09, FALSE); |
| 428 | generic_start(device, 0x8000, 0x09, TRUE); |
| 412 | 429 | } |
| 413 | 430 | |
| 414 | 431 | |
| r6294 | r6295 | |
| 447 | 464 | } |
| 448 | 465 | } |
| 449 | 466 | |
| 467 | DEVICE_GET_INFO( sn94624 ) |
| 468 | { |
| 469 | switch (state) |
| 470 | { |
| 471 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( sn94624 ); break; |
| 472 | case DEVINFO_STR_NAME: strcpy(info->s, "SN94624"); break; |
| 473 | default: DEVICE_GET_INFO_CALL(sn76496); break; |
| 474 | } |
| 475 | } |
| 476 | |
| 450 | 477 | DEVICE_GET_INFO( sn76489a ) |
| 451 | 478 | { |
| 452 | 479 | switch (state) |