trunk/src/emu/sound/tms5110.c
| r249030 | r249031 | |
| 235 | 235 | save_item(NAME(m_old_frame_pitch_idx)); |
| 236 | 236 | save_item(NAME(m_old_frame_k_idx)); |
| 237 | 237 | save_item(NAME(m_old_zpar)); |
| 238 | | save_item(NAME(m_old_uv_zpar)); |
| 239 | 238 | #endif |
| 240 | 239 | save_item(NAME(m_current_energy)); |
| 241 | 240 | save_item(NAME(m_current_pitch)); |
| r249030 | r249031 | |
| 350 | 349 | int i, bitout; |
| 351 | 350 | INT32 this_sample; |
| 352 | 351 | |
| 352 | /* if we're not speaking, fill with nothingness */ |
| 353 | if (!m_TALKD) |
| 354 | goto empty; |
| 355 | |
| 353 | 356 | /* loop until the buffer is full or we've stopped speaking */ |
| 354 | | while (size > 0) |
| 357 | while ((size > 0) && m_TALKD) |
| 355 | 358 | { |
| 356 | | if(m_TALKD) // speaking |
| 359 | /* if it is the appropriate time to update the old energy/pitch indices, |
| 360 | * i.e. when IP=7, PC=12, T=17, subcycle=2, do so. Since IP=7 PC=12 T=17 |
| 361 | * is JUST BEFORE the transition to IP=0 PC=0 T=0 sybcycle=(0 or 1), |
| 362 | * which happens 4 T-cycles later), we change on the latter. |
| 363 | * The indices are updated here ~12 PCs before the new frame is applied. |
| 364 | */ |
| 365 | /** TODO: the patents 4331836, 4335277, and 4419540 disagree about the timing of this **/ |
| 366 | if ((m_IP == 0) && (m_PC == 0) && (m_subcycle < 2)) |
| 357 | 367 | { |
| 358 | | /* if we're ready for a new frame to be applied, i.e. when IP=0, PC=12, Sub=1 |
| 359 | | * (In reality, the frame was really loaded incrementally during the entire IP=0 |
| 360 | | * PC=x time period, but it doesn't affect anything until IP=0 PC=12 happens) |
| 361 | | */ |
| 362 | | if ((m_IP == 0) && (m_PC == 12) && (m_subcycle == 1)) |
| 363 | | { |
| 364 | | // HACK for regression testing, be sure to comment out before release! |
| 365 | | //m_RNG = 0x1234; |
| 366 | | // end HACK |
| 368 | m_OLDE = (m_new_frame_energy_idx == 0); |
| 369 | m_OLDP = (m_new_frame_pitch_idx == 0); |
| 370 | } |
| 367 | 371 | |
| 372 | /* if we're ready for a new frame to be applied, i.e. when IP=0, PC=12, Sub=1 |
| 373 | * (In reality, the frame was really loaded incrementally during the entire IP=0 |
| 374 | * PC=x time period, but it doesn't affect anything until IP=0 PC=12 happens) |
| 375 | */ |
| 376 | if ((m_IP == 0) && (m_PC == 12) && (m_subcycle == 1)) |
| 377 | { |
| 378 | // HACK for regression testing, be sure to comment out before release! |
| 379 | //m_RNG = 0x1234; |
| 380 | // end HACK |
| 381 | |
| 368 | 382 | #ifdef PERFECT_INTERPOLATION_HACK |
| 369 | | /* remember previous frame energy, pitch, and coefficients */ |
| 370 | | m_old_frame_energy_idx = m_new_frame_energy_idx; |
| 371 | | m_old_frame_pitch_idx = m_new_frame_pitch_idx; |
| 372 | | for (i = 0; i < m_coeff->num_k; i++) |
| 373 | | m_old_frame_k_idx[i] = m_new_frame_k_idx[i]; |
| 383 | /* remember previous frame energy, pitch, and coefficients */ |
| 384 | m_old_frame_energy_idx = m_new_frame_energy_idx; |
| 385 | m_old_frame_pitch_idx = m_new_frame_pitch_idx; |
| 386 | for (i = 0; i < m_coeff->num_k; i++) |
| 387 | m_old_frame_k_idx[i] = m_new_frame_k_idx[i]; |
| 374 | 388 | #endif |
| 375 | 389 | |
| 376 | | /* Parse a new frame into the new_target_energy, new_target_pitch and new_target_k[] */ |
| 377 | | parse_frame(); |
| 378 | | |
| 379 | | // if the new frame is unvoiced (or silenced via ZPAR), be sure to zero out the k5-k10 parameters |
| 380 | | // NOTE: this is probably the bug the tms5100/tmc0280 has, pre-rev D, I think. |
| 381 | | // GUESS: Pre-rev D versions start zeroing k5-k10 immediately upon new frame load regardless of interpolation inhibit |
| 382 | | // I.e. ZPAR = /TALKD || (PC>5&&P=0) |
| 383 | | // GUESS: D and later versions only start or stop zeroing k5-k10 at the IP7->IP0 transition AFTER the frame |
| 384 | | // I.e. ZPAR = /TALKD || (PC>5&&OLDP) |
| 385 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 386 | | m_old_uv_zpar = m_uv_zpar; |
| 387 | | m_old_zpar = m_zpar; // unset old zpar on new frame |
| 390 | /* Parse a new frame into the new_target_energy, new_target_pitch and new_target_k[] */ |
| 391 | parse_frame(); |
| 392 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 393 | fprintf(stderr,"\n"); |
| 388 | 394 | #endif |
| 389 | | m_zpar = 0; |
| 390 | | //m_uv_zpar = (OLD_FRAME_UNVOICED_FLAG||m_zpar); // GUESS: fixed version in tmc0280d/tms5100a/cd280x/tms5110 |
| 391 | | m_uv_zpar = (NEW_FRAME_UNVOICED_FLAG||m_zpar); // GUESS: buggy version in tmc0280/tms5100 |
| 395 | /* if the new frame is unvoiced (or silenced via ZPAR), be sure to zero out the k5-k10 parameters */ |
| 396 | m_uv_zpar = NEW_FRAME_UNVOICED_FLAG | m_zpar; |
| 392 | 397 | |
| 393 | | /* if the new frame is a stop frame, unset both TALK and SPEN (via TCON). TALKD remains active while the energy is ramping to 0. */ |
| 394 | | if (NEW_FRAME_STOP_FLAG == 1) |
| 395 | | { |
| 396 | | m_TALK = m_SPEN = 0; |
| 397 | | } |
| 398 | /* if the new frame is a stop frame, unset both TALK and SPEN. TALKD remains active while the energy is ramping to 0. */ |
| 399 | if (NEW_FRAME_STOP_FLAG == 1) |
| 400 | { |
| 401 | m_TALK = m_SPEN = 0; |
| 402 | } |
| 398 | 403 | |
| 399 | | /* in all cases where interpolation would be inhibited, set the inhibit flag; otherwise clear it. |
| 400 | | Interpolation inhibit cases: |
| 401 | | * Old frame was voiced, new is unvoiced |
| 402 | | * Old frame was silence/zero energy, new has nonzero energy |
| 403 | | * Old frame was unvoiced, new is voiced (note this is the case on the patent but may not be correct on the real final chip) |
| 404 | | */ |
| 405 | | if ( ((OLD_FRAME_UNVOICED_FLAG == 0) && (NEW_FRAME_UNVOICED_FLAG == 1)) |
| 406 | | || ((OLD_FRAME_UNVOICED_FLAG == 1) && (NEW_FRAME_UNVOICED_FLAG == 0)) /* this line needs further investigation, starwars tie fighters may sound better without it */ |
| 407 | | || ((OLD_FRAME_SILENCE_FLAG == 1) && (NEW_FRAME_SILENCE_FLAG == 0)) ) |
| 408 | | m_inhibit = 1; |
| 409 | | else // normal frame, normal interpolation |
| 410 | | m_inhibit = 0; |
| 404 | /* in all cases where interpolation would be inhibited, set the inhibit flag; otherwise clear it. |
| 405 | Interpolation inhibit cases: |
| 406 | * Old frame was voiced, new is unvoiced |
| 407 | * Old frame was silence/zero energy, new has nonzero energy |
| 408 | * Old frame was unvoiced, new is voiced (note this is the case on the patent but may not be correct on the real final chip) |
| 409 | */ |
| 410 | if ( ((OLD_FRAME_UNVOICED_FLAG == 0) && (NEW_FRAME_UNVOICED_FLAG == 1)) |
| 411 | || ((OLD_FRAME_UNVOICED_FLAG == 1) && (NEW_FRAME_UNVOICED_FLAG == 0)) /* this line needs further investigation, starwars tie fighters may sound better without it */ |
| 412 | || ((OLD_FRAME_SILENCE_FLAG == 1) && (NEW_FRAME_SILENCE_FLAG == 0)) ) |
| 413 | m_inhibit = 1; |
| 414 | else // normal frame, normal interpolation |
| 415 | m_inhibit = 0; |
| 411 | 416 | |
| 412 | 417 | #ifdef DEBUG_GENERATION |
| 413 | | /* Debug info for current parsed frame */ |
| 414 | | fprintf(stderr, "OLDE: %d; OLDP: %d; ", m_OLDE, m_OLDP); |
| 415 | | fprintf(stderr,"Processing new frame: "); |
| 416 | | if (m_inhibit == 0) |
| 417 | | fprintf(stderr, "Normal Frame\n"); |
| 418 | | else |
| 419 | | fprintf(stderr,"Interpolation Inhibited\n"); |
| 420 | | fprintf(stderr,"*** current Energy, Pitch and Ks = %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n",m_current_energy, m_current_pitch, m_current_k[0], m_current_k[1], m_current_k[2], m_current_k[3], m_current_k[4], m_current_k[5], m_current_k[6], m_current_k[7], m_current_k[8], m_current_k[9]); |
| 421 | | fprintf(stderr,"*** target Energy(idx), Pitch, and Ks = %04d(%x),%04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n", |
| 422 | | (m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)), |
| 423 | | m_new_frame_energy_idx, |
| 424 | | (m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)), |
| 425 | | (m_coeff->ktable[0][m_new_frame_k_idx[0]] * (1-m_zpar)), |
| 426 | | (m_coeff->ktable[1][m_new_frame_k_idx[1]] * (1-m_zpar)), |
| 427 | | (m_coeff->ktable[2][m_new_frame_k_idx[2]] * (1-m_zpar)), |
| 428 | | (m_coeff->ktable[3][m_new_frame_k_idx[3]] * (1-m_zpar)), |
| 429 | | (m_coeff->ktable[4][m_new_frame_k_idx[4]] * (1-m_uv_zpar)), |
| 430 | | (m_coeff->ktable[5][m_new_frame_k_idx[5]] * (1-m_uv_zpar)), |
| 431 | | (m_coeff->ktable[6][m_new_frame_k_idx[6]] * (1-m_uv_zpar)), |
| 432 | | (m_coeff->ktable[7][m_new_frame_k_idx[7]] * (1-m_uv_zpar)), |
| 433 | | (m_coeff->ktable[8][m_new_frame_k_idx[8]] * (1-m_uv_zpar)), |
| 434 | | (m_coeff->ktable[9][m_new_frame_k_idx[9]] * (1-m_uv_zpar)) ); |
| 418 | /* Debug info for current parsed frame */ |
| 419 | fprintf(stderr, "OLDE: %d; OLDP: %d; ", m_OLDE, m_OLDP); |
| 420 | fprintf(stderr,"Processing frame: "); |
| 421 | if (m_inhibit == 0) |
| 422 | fprintf(stderr, "Normal Frame\n"); |
| 423 | else |
| 424 | fprintf(stderr,"Interpolation Inhibited\n"); |
| 425 | fprintf(stderr,"*** current Energy, Pitch and Ks = %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n",m_current_energy, m_current_pitch, m_current_k[0], m_current_k[1], m_current_k[2], m_current_k[3], m_current_k[4], m_current_k[5], m_current_k[6], m_current_k[7], m_current_k[8], m_current_k[9]); |
| 426 | fprintf(stderr,"*** target Energy(idx), Pitch, and Ks = %04d(%x),%04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n", |
| 427 | (m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)), |
| 428 | m_new_frame_energy_idx, |
| 429 | (m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)), |
| 430 | (m_coeff->ktable[0][m_new_frame_k_idx[0]] * (1-m_zpar)), |
| 431 | (m_coeff->ktable[1][m_new_frame_k_idx[1]] * (1-m_zpar)), |
| 432 | (m_coeff->ktable[2][m_new_frame_k_idx[2]] * (1-m_zpar)), |
| 433 | (m_coeff->ktable[3][m_new_frame_k_idx[3]] * (1-m_zpar)), |
| 434 | (m_coeff->ktable[4][m_new_frame_k_idx[4]] * (1-m_uv_zpar)), |
| 435 | (m_coeff->ktable[5][m_new_frame_k_idx[5]] * (1-m_uv_zpar)), |
| 436 | (m_coeff->ktable[6][m_new_frame_k_idx[6]] * (1-m_uv_zpar)), |
| 437 | (m_coeff->ktable[7][m_new_frame_k_idx[7]] * (1-m_uv_zpar)), |
| 438 | (m_coeff->ktable[8][m_new_frame_k_idx[8]] * (1-m_uv_zpar)), |
| 439 | (m_coeff->ktable[9][m_new_frame_k_idx[9]] * (1-m_uv_zpar)) ); |
| 435 | 440 | #endif |
| 436 | 441 | |
| 442 | } |
| 443 | else // Not a new frame, just interpolate the existing frame. |
| 444 | { |
| 445 | int inhibit_state = ((m_inhibit==1)&&(m_IP != 0)); // disable inhibit when reaching the last interp period, but don't overwrite the m_inhibit value |
| 446 | #ifdef PERFECT_INTERPOLATION_HACK |
| 447 | int samples_per_frame = m_subc_reload?175:266; // either (13 A cycles + 12 B cycles) * 7 interps for normal SPEAK/SPKEXT, or (13*2 A cycles + 12 B cycles) * 7 interps for SPKSLOW |
| 448 | //int samples_per_frame = m_subc_reload?200:304; // either (13 A cycles + 12 B cycles) * 8 interps for normal SPEAK/SPKEXT, or (13*2 A cycles + 12 B cycles) * 8 interps for SPKSLOW |
| 449 | int current_sample = (m_subcycle - m_subc_reload)+(m_PC*(3-m_subc_reload))+((m_subc_reload?25:38)*((m_IP-1)&7)); |
| 450 | //fprintf(stderr, "CS: %03d", current_sample); |
| 451 | // reset the current energy, pitch, etc to what it was at frame start |
| 452 | m_current_energy = (m_coeff->energytable[m_old_frame_energy_idx] * (1-m_zpar)); |
| 453 | m_current_pitch = (m_coeff->pitchtable[m_old_frame_pitch_idx] * (1-m_old_zpar)); |
| 454 | for (i = 0; i < 4; i++) |
| 455 | m_current_k[i] = (m_coeff->ktable[i][m_old_frame_k_idx[i]] * (1-m_old_zpar)); |
| 456 | for (i = 4; i < m_coeff->num_k; i++) |
| 457 | m_current_k[i] = (m_coeff->ktable[i][m_old_frame_k_idx[i]] * (1-m_uv_zpar)); |
| 458 | // now adjust each value to be exactly correct for each of the samples per frame |
| 459 | if (m_IP != 0) // if we're still interpolating... |
| 460 | { |
| 461 | m_current_energy += ((((m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)) - m_current_energy)*(1-inhibit_state))*current_sample)/samples_per_frame; |
| 462 | m_current_pitch += ((((m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)) - m_current_pitch)*(1-inhibit_state))*current_sample)/samples_per_frame; |
| 463 | for (i = 0; i < m_coeff->num_k; i++) |
| 464 | m_current_k[i] += ((((m_coeff->ktable[i][m_new_frame_k_idx[i]] * (1-((i<4)?m_zpar:m_uv_zpar))) - m_current_k[i])*(1-inhibit_state))*current_sample)/samples_per_frame; |
| 437 | 465 | } |
| 438 | | else // Not a new frame, just interpolate the existing frame. |
| 466 | else // we're done, play this frame for 1/8 frame. |
| 439 | 467 | { |
| 440 | | int inhibit_state = ((m_inhibit==1)&&(m_IP != 0)); // disable inhibit when reaching the last interp period, but don't overwrite the m_inhibit value |
| 441 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 442 | | int samples_per_frame = m_subc_reload?175:266; // either (13 A cycles + 12 B cycles) * 7 interps for normal SPEAK/SPKEXT, or (13*2 A cycles + 12 B cycles) * 7 interps for SPKSLOW |
| 443 | | //int samples_per_frame = m_subc_reload?200:304; // either (13 A cycles + 12 B cycles) * 8 interps for normal SPEAK/SPKEXT, or (13*2 A cycles + 12 B cycles) * 8 interps for SPKSLOW |
| 444 | | int current_sample = (m_subcycle - m_subc_reload)+(m_PC*(3-m_subc_reload))+((m_subc_reload?25:38)*((m_IP-1)&7)); |
| 445 | | //fprintf(stderr, "CS: %03d", current_sample); |
| 446 | | // reset the current energy, pitch, etc to what it was at frame start |
| 447 | | m_current_energy = (m_coeff->energytable[m_old_frame_energy_idx] * (1-m_old_zpar)); |
| 448 | | m_current_pitch = (m_coeff->pitchtable[m_old_frame_pitch_idx] * (1-m_old_zpar)); |
| 468 | m_current_energy = (m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)); |
| 469 | m_current_pitch = (m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)); |
| 449 | 470 | for (i = 0; i < m_coeff->num_k; i++) |
| 450 | | m_current_k[i] = (m_coeff->ktable[i][m_old_frame_k_idx[i]] * (1-((i<4)?m_old_zpar:m_old_uv_zpar))); |
| 451 | | // now adjust each value to be exactly correct for each of the samples per frame |
| 452 | | if (m_IP != 0) // if we're still interpolating... |
| 453 | | { |
| 454 | | m_current_energy = (m_current_energy + (((m_coeff->energytable[m_new_frame_energy_idx] - m_current_energy)*(1-inhibit_state))*current_sample)/samples_per_frame)*(1-m_zpar); |
| 455 | | m_current_pitch = (m_current_pitch + (((m_coeff->pitchtable[m_new_frame_pitch_idx] - m_current_pitch)*(1-inhibit_state))*current_sample)/samples_per_frame)*(1-m_zpar); |
| 456 | | for (i = 0; i < m_coeff->num_k; i++) |
| 457 | | m_current_k[i] = (m_current_k[i] + (((m_coeff->ktable[i][m_new_frame_k_idx[i]] - m_current_k[i])*(1-inhibit_state))*current_sample)/samples_per_frame)*(1-((i<4)?m_zpar:m_uv_zpar)); |
| 458 | | } |
| 459 | | else // we're done, play this frame for 1/8 frame. |
| 460 | | { |
| 461 | | m_current_energy = (m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)); |
| 462 | | m_current_pitch = (m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)); |
| 463 | | for (i = 0; i < m_coeff->num_k; i++) |
| 464 | | m_current_k[i] = (m_coeff->ktable[i][m_new_frame_k_idx[i]] * (1-((i<4)?m_zpar:m_uv_zpar))); |
| 465 | | } |
| 471 | m_current_k[i] = (m_coeff->ktable[i][m_new_frame_k_idx[i]] * (1-((i<4)?m_zpar:m_uv_zpar))); |
| 472 | } |
| 466 | 473 | #else |
| 467 | | //Updates to parameters only happen on subcycle '2' (B cycle) of PCs. |
| 468 | | if (m_subcycle == 2) |
| 474 | //Updates to parameters only happen on subcycle '2' (B cycle) of PCs. |
| 475 | if (m_subcycle == 2) |
| 476 | { |
| 477 | switch(m_PC) |
| 469 | 478 | { |
| 470 | | switch(m_PC) |
| 471 | | { |
| 472 | | case 0: /* PC = 0, B cycle, write updated energy */ |
| 473 | | m_current_energy = (m_current_energy + (((m_coeff->energytable[m_new_frame_energy_idx] - m_current_energy)*(1-inhibit_state)) INTERP_SHIFT))*(1-m_zpar); |
| 474 | | break; |
| 475 | | case 1: /* PC = 1, B cycle, write updated pitch */ |
| 476 | | m_current_pitch = (m_current_pitch + (((m_coeff->pitchtable[m_new_frame_pitch_idx] - m_current_pitch)*(1-inhibit_state)) INTERP_SHIFT))*(1-m_zpar); |
| 477 | | break; |
| 478 | | case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: |
| 479 | | /* PC = 2 through 11, B cycle, write updated K1 through K10 */ |
| 480 | | m_current_k[m_PC-2] = (m_current_k[m_PC-2] + (((m_coeff->ktable[m_PC-2][m_new_frame_k_idx[m_PC-2]] - m_current_k[m_PC-2])*(1-inhibit_state)) INTERP_SHIFT))*(((m_PC-2)>4)?(1-m_uv_zpar):(1-m_zpar)); |
| 481 | | break; |
| 482 | | case 12: /* PC = 12 */ |
| 483 | | /* we should NEVER reach this point, PC=12 doesn't have a subcycle 2 */ |
| 484 | | break; |
| 485 | | } |
| 479 | case 0: /* PC = 0, B cycle, write updated energy */ |
| 480 | m_current_energy += ((((m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)) - m_current_energy)*(1-inhibit_state)) INTERP_SHIFT); |
| 481 | break; |
| 482 | case 1: /* PC = 1, B cycle, write updated pitch */ |
| 483 | m_current_pitch += ((((m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)) - m_current_pitch)*(1-inhibit_state)) INTERP_SHIFT); |
| 484 | break; |
| 485 | case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: |
| 486 | /* PC = 2 through 11, B cycle, write updated K1 through K10 */ |
| 487 | m_current_k[m_PC-2] += ((((m_coeff->ktable[m_PC-2][m_new_frame_k_idx[m_PC-2]] * (1-(((m_PC-2)<4)?m_zpar:m_uv_zpar))) - m_current_k[m_PC-2])*(1-inhibit_state)) INTERP_SHIFT); |
| 488 | break; |
| 489 | case 12: /* PC = 12, do nothing */ |
| 490 | break; |
| 486 | 491 | } |
| 487 | | #endif |
| 488 | 492 | } |
| 493 | #endif |
| 494 | } |
| 489 | 495 | |
| 490 | | // calculate the output |
| 491 | | if (OLD_FRAME_UNVOICED_FLAG == 1) |
| 492 | | { |
| 493 | | // generate unvoiced samples here |
| 494 | | if (m_RNG & 1) |
| 495 | | m_excitation_data = ~0x3F; /* according to the patent it is (either + or -) half of the maximum value in the chirp table, so either 01000000(0x40) or 11000000(0xC0)*/ |
| 496 | | else |
| 497 | | m_excitation_data = 0x40; |
| 498 | | } |
| 499 | | else /* (OLD_FRAME_UNVOICED_FLAG == 0) */ |
| 500 | | { |
| 501 | | // generate voiced samples here |
| 502 | | /* US patent 4331836 Figure 14B shows, and logic would hold, that a pitch based chirp |
| 503 | | * function has a chirp/peak and then a long chain of zeroes. |
| 504 | | * The last entry of the chirp rom is at address 0b110011 (51d), the 52nd sample, |
| 505 | | * and if the address reaches that point the ADDRESS incrementer is |
| 506 | | * disabled, forcing all samples beyond 51d to be == 51d |
| 507 | | */ |
| 508 | | if (m_pitch_count >= 51) |
| 509 | | m_excitation_data = (INT8)m_coeff->chirptable[51]; |
| 510 | | else /*m_pitch_count < 51*/ |
| 511 | | m_excitation_data = (INT8)m_coeff->chirptable[m_pitch_count]; |
| 512 | | } |
| 496 | // calculate the output |
| 497 | if (OLD_FRAME_UNVOICED_FLAG == 1) |
| 498 | { |
| 499 | // generate unvoiced samples here |
| 500 | if (m_RNG & 1) |
| 501 | m_excitation_data = ~0x3F; /* according to the patent it is (either + or -) half of the maximum value in the chirp table, so either 01000000(0x40) or 11000000(0xC0)*/ |
| 502 | else |
| 503 | m_excitation_data = 0x40; |
| 504 | } |
| 505 | else /* (OLD_FRAME_UNVOICED_FLAG == 0) */ |
| 506 | { |
| 507 | // generate voiced samples here |
| 508 | /* US patent 4331836 Figure 14B shows, and logic would hold, that a pitch based chirp |
| 509 | * function has a chirp/peak and then a long chain of zeroes. |
| 510 | * The last entry of the chirp rom is at address 0b110011 (51d), the 52nd sample, |
| 511 | * and if the address reaches that point the ADDRESS incrementer is |
| 512 | * disabled, forcing all samples beyond 51d to be == 51d |
| 513 | */ |
| 514 | if (m_pitch_count >= 51) |
| 515 | m_excitation_data = (INT8)m_coeff->chirptable[51]; |
| 516 | else /*m_pitch_count < 51*/ |
| 517 | m_excitation_data = (INT8)m_coeff->chirptable[m_pitch_count]; |
| 518 | } |
| 513 | 519 | |
| 514 | | // Update LFSR *20* times every sample (once per T cycle), like patent shows |
| 515 | | for (i=0; i<20; i++) |
| 516 | | { |
| 517 | | bitout = ((m_RNG >> 12) & 1) ^ |
| 518 | | ((m_RNG >> 3) & 1) ^ |
| 519 | | ((m_RNG >> 2) & 1) ^ |
| 520 | | ((m_RNG >> 0) & 1); |
| 521 | | m_RNG <<= 1; |
| 522 | | m_RNG |= bitout; |
| 523 | | } |
| 524 | | this_sample = lattice_filter(); /* execute lattice filter */ |
| 520 | // Update LFSR *20* times every sample (once per T cycle), like patent shows |
| 521 | for (i=0; i<20; i++) |
| 522 | { |
| 523 | bitout = ((m_RNG >> 12) & 1) ^ |
| 524 | ((m_RNG >> 3) & 1) ^ |
| 525 | ((m_RNG >> 2) & 1) ^ |
| 526 | ((m_RNG >> 0) & 1); |
| 527 | m_RNG <<= 1; |
| 528 | m_RNG |= bitout; |
| 529 | } |
| 530 | this_sample = lattice_filter(); /* execute lattice filter */ |
| 525 | 531 | #ifdef DEBUG_GENERATION_VERBOSE |
| 526 | | //fprintf(stderr,"C:%01d; ",m_subcycle); |
| 527 | | fprintf(stderr,"IP:%01d PC:%02d X:%04d E:%03d P:%03d Pc:%03d ",m_IP, m_PC, m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 528 | | //fprintf(stderr,"X:%04d E:%03d P:%03d Pc:%03d ", m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 529 | | for (i=0; i<10; i++) |
| 530 | | fprintf(stderr,"K%d:%04d ", i+1, m_current_k[i]); |
| 531 | | fprintf(stderr,"Out:%06d ", this_sample); |
| 532 | | //#ifdef PERFECT_INTERPOLATION_HACK |
| 533 | | // fprintf(stderr,"%d%d%d%d",m_old_zpar,m_zpar,m_old_uv_zpar,m_uv_zpar); |
| 534 | | //#else |
| 535 | | // fprintf(stderr,"x%dx%d",m_zpar,m_uv_zpar); |
| 536 | | //#endif |
| 537 | | fprintf(stderr,"\n"); |
| 532 | //fprintf(stderr,"C:%01d; ",m_subcycle); |
| 533 | fprintf(stderr,"IP:%01d PC:%02d X:%04d E:%03d P:%03d Pc:%03d ",m_IP, m_PC, m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 534 | //fprintf(stderr,"X:%04d E:%03d P:%03d Pc:%03d ", m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 535 | for (i=0; i<10; i++) |
| 536 | fprintf(stderr,"K%d:%04d ", i+1, m_current_k[i]); |
| 537 | fprintf(stderr,"Out:%06d", this_sample); |
| 538 | fprintf(stderr,"\n"); |
| 538 | 539 | #endif |
| 539 | | /* next, force result to 14 bits (since its possible that the addition at the final (k1) stage of the lattice overflowed) */ |
| 540 | | while (this_sample > 16383) this_sample -= 32768; |
| 541 | | while (this_sample < -16384) this_sample += 32768; |
| 542 | | if (m_digital_select == 0) // analog SPK pin output is only 8 bits, with clipping |
| 543 | | buffer[buf_count] = clip_analog(this_sample); |
| 544 | | else // digital I/O pin output is 12 bits |
| 545 | | { |
| 540 | /* next, force result to 14 bits (since its possible that the addition at the final (k1) stage of the lattice overflowed) */ |
| 541 | while (this_sample > 16383) this_sample -= 32768; |
| 542 | while (this_sample < -16384) this_sample += 32768; |
| 543 | if (m_digital_select == 0) // analog SPK pin output is only 8 bits, with clipping |
| 544 | buffer[buf_count] = clip_analog(this_sample); |
| 545 | else // digital I/O pin output is 12 bits |
| 546 | { |
| 546 | 547 | #ifdef ALLOW_4_LSB |
| 547 | | // input: ssss ssss ssss ssss ssnn nnnn nnnn nnnn |
| 548 | | // N taps: ^ = 0x2000; |
| 549 | | // output: ssss ssss ssss ssss snnn nnnn nnnn nnnN |
| 550 | | buffer[buf_count] = (this_sample<<1)|((this_sample&0x2000)>>13); |
| 548 | // input: ssss ssss ssss ssss ssnn nnnn nnnn nnnn |
| 549 | // N taps: ^ = 0x2000; |
| 550 | // output: ssss ssss ssss ssss snnn nnnn nnnn nnnN |
| 551 | buffer[buf_count] = (this_sample<<1)|((this_sample&0x2000)>>13); |
| 551 | 552 | #else |
| 552 | | this_sample &= ~0xF; |
| 553 | | // input: ssss ssss ssss ssss ssnn nnnn nnnn 0000 |
| 554 | | // N taps: ^^ ^^^ = 0x3E00; |
| 555 | | // output: ssss ssss ssss ssss snnn nnnn nnnN NNNN |
| 556 | | buffer[buf_count] = (this_sample<<1)|((this_sample&0x3E00)>>9); |
| 553 | this_sample &= ~0xF; |
| 554 | // input: ssss ssss ssss ssss ssnn nnnn nnnn 0000 |
| 555 | // N taps: ^^ ^^^ = 0x3E00; |
| 556 | // output: ssss ssss ssss ssss snnn nnnn nnnN NNNN |
| 557 | buffer[buf_count] = (this_sample<<1)|((this_sample&0x3E00)>>9); |
| 557 | 558 | #endif |
| 558 | | } |
| 559 | | // Update all counts |
| 559 | } |
| 560 | // Update all counts |
| 560 | 561 | |
| 561 | | m_subcycle++; |
| 562 | | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 562 | m_subcycle++; |
| 563 | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 564 | { |
| 565 | /* Circuit 412 in the patent acts a reset, resetting the pitch counter to 0 |
| 566 | * if INHIBIT was true during the most recent frame transition. |
| 567 | * The exact time this occurs is betwen IP=7, PC=12 sub=0, T=t12 |
| 568 | * and m_IP = 0, PC=0 sub=0, T=t12, a period of exactly 20 cycles, |
| 569 | * which overlaps the time OLDE and OLDP are updated at IP=7 PC=12 T17 |
| 570 | * (and hence INHIBIT itself 2 t-cycles later). We do it here because it is |
| 571 | * convenient and should make no difference in output. |
| 572 | */ |
| 573 | if ((m_IP == 7)&&(m_inhibit==1)) m_pitch_zero = 1; |
| 574 | if ((m_IP == 0)&&(m_pitch_zero==1)) m_pitch_zero = 0; |
| 575 | if (m_IP == 7) // RESETL4 |
| 563 | 576 | { |
| 564 | | /* Circuit 412 in the patent acts a reset, resetting the pitch counter to 0 |
| 565 | | * if INHIBIT was true during the most recent frame transition. |
| 566 | | * The exact time this occurs is betwen IP=7, PC=12 sub=0, T=t12 |
| 567 | | * and m_IP = 0, PC=0 sub=0, T=t12, a period of exactly 20 cycles, |
| 568 | | * which overlaps the time OLDE and OLDP are updated at IP=7 PC=12 T17 |
| 569 | | * (and hence INHIBIT itself 2 t-cycles later). We do it here because it is |
| 570 | | * convenient and should make no difference in output. |
| 571 | | */ |
| 572 | | if ((m_IP == 7)&&(m_inhibit==1)) m_pitch_zero = 1; |
| 573 | | if ((m_IP == 0)&&(m_pitch_zero==1)) m_pitch_zero = 0; |
| 574 | | if (m_IP == 7) // RESETL4 |
| 575 | | { |
| 576 | | // Latch OLDE and OLDP |
| 577 | | OLD_FRAME_SILENCE_FLAG = NEW_FRAME_SILENCE_FLAG; // m_OLDE |
| 578 | | OLD_FRAME_UNVOICED_FLAG = NEW_FRAME_UNVOICED_FLAG; // m_OLDP |
| 579 | | /* if TALK was clear last frame, halt speech now, since TALKD (latched from TALK on new frame) just went inactive. */ |
| 577 | /* if TALK was clear last frame, halt speech now, since TALKD (latched from TALK on new frame) just went inactive. */ |
| 580 | 578 | #ifdef DEBUG_GENERATION |
| 581 | | if (m_TALK == 0) |
| 582 | | fprintf(stderr,"tms5110_process: processing frame: TALKD = 0 caused by stop frame or buffer empty, halting speech.\n"); |
| 579 | if (m_TALK == 0) |
| 580 | fprintf(stderr,"tms5110_process: processing frame: TALKD = 0 caused by stop frame or buffer empty, halting speech.\n"); |
| 583 | 581 | #endif |
| 584 | | m_TALKD = m_TALK; // TALKD is latched from TALK |
| 585 | | m_TALK = m_SPEN; // TALK is latched from SPEN |
| 586 | | } |
| 587 | | m_subcycle = m_subc_reload; |
| 588 | | m_PC = 0; |
| 589 | | m_IP++; |
| 590 | | m_IP&=0x7; |
| 582 | m_TALKD = m_TALK; // TALKD is latched from TALK |
| 583 | m_TALK = m_SPEN; // TALK is latched from SPEN |
| 584 | #ifdef PERFECT_INTERPOLATION_HACK |
| 585 | m_old_zpar = m_zpar; |
| 586 | #endif |
| 587 | m_zpar = 1 - m_TALKD; // ZPAR is inverse of m_TALKD |
| 591 | 588 | } |
| 592 | | else if (m_subcycle == 3) |
| 593 | | { |
| 594 | | m_subcycle = m_subc_reload; |
| 595 | | m_PC++; |
| 596 | | } |
| 597 | | m_pitch_count++; |
| 598 | | if ((m_pitch_count >= m_current_pitch)||(m_pitch_zero == 1)) m_pitch_count = 0; |
| 599 | | m_pitch_count &= 0x1FF; |
| 589 | m_subcycle = m_subc_reload; |
| 590 | m_PC = 0; |
| 591 | m_IP++; |
| 592 | m_IP&=0x7; |
| 600 | 593 | } |
| 601 | | else // m_TALKD == 0 |
| 594 | else if (m_subcycle == 3) |
| 602 | 595 | { |
| 603 | | m_subcycle++; |
| 604 | | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 596 | m_subcycle = m_subc_reload; |
| 597 | m_PC++; |
| 598 | } |
| 599 | m_pitch_count++; |
| 600 | if ((m_pitch_count >= m_current_pitch)||(m_pitch_zero == 1)) m_pitch_count = 0; |
| 601 | m_pitch_count &= 0x1FF; |
| 602 | buf_count++; |
| 603 | size--; |
| 604 | } |
| 605 | |
| 606 | empty: |
| 607 | |
| 608 | while (size > 0) |
| 609 | { |
| 610 | m_subcycle++; |
| 611 | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 612 | { |
| 613 | if (m_IP == 7) // RESETL4 |
| 605 | 614 | { |
| 606 | | if (m_IP == 7) // RESETL4 |
| 607 | | { |
| 608 | | m_TALKD = m_TALK; // TALKD is latched from TALK |
| 609 | | m_TALK = m_SPEN; // TALK is latched from SPEN |
| 610 | | } |
| 611 | | m_subcycle = m_subc_reload; |
| 612 | | m_PC = 0; |
| 613 | | m_IP++; |
| 614 | | m_IP&=0x7; |
| 615 | m_TALKD = m_TALK; // TALKD is latched from TALK |
| 616 | m_TALK = m_SPEN; // TALK is latched from SPEN |
| 617 | #ifdef PERFECT_INTERPOLATION_HACK |
| 618 | m_old_zpar = m_zpar; |
| 619 | #endif |
| 620 | m_zpar = 1 - m_TALKD; // ZPAR is inverse of m_TALKD |
| 615 | 621 | } |
| 616 | | else if (m_subcycle == 3) |
| 617 | | { |
| 618 | | m_subcycle = m_subc_reload; |
| 619 | | m_PC++; |
| 620 | | } |
| 621 | | buffer[buf_count] = -1; /* should be just -1; actual chip outputs -1 every idle sample; (cf note in data sheet, p 10, table 4) */ |
| 622 | m_subcycle = m_subc_reload; |
| 623 | m_PC = 0; |
| 624 | m_IP++; |
| 625 | m_IP&=0x7; |
| 622 | 626 | } |
| 623 | | buf_count++; |
| 624 | | size--; |
| 627 | else if (m_subcycle == 3) |
| 628 | { |
| 629 | m_subcycle = m_subc_reload; |
| 630 | m_PC++; |
| 631 | } |
| 632 | buffer[buf_count] = -1; /* should be just -1; actual chip outputs -1 every idle sample; (cf note in data sheet, p 10, table 4) */ |
| 633 | buf_count++; |
| 634 | size--; |
| 625 | 635 | } |
| 626 | 636 | } |
| 627 | 637 | |
| r249030 | r249031 | |
| 853 | 863 | m_SPEN = 1; /* start immediately */ |
| 854 | 864 | /* clear out variables before speaking */ |
| 855 | 865 | m_zpar = 1; // zero all the parameters |
| 856 | | m_uv_zpar = 1; // zero k4-k10 as well |
| 857 | | m_OLDE = 1; // 'silence/zpar' frames are zero energy |
| 858 | | m_OLDP = 1; // 'silence/zpar' frames are zero pitch |
| 859 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 860 | | m_old_zpar = 1; // zero all the old parameters |
| 861 | | m_old_uv_zpar = 1; // zero old k4-k10 as well |
| 862 | | #endif |
| 863 | 866 | m_subc_reload = 0; // SPKSLOW means this is 0 |
| 867 | m_subcycle = m_subc_reload; |
| 868 | m_PC = 0; |
| 869 | m_IP = 0; |
| 864 | 870 | break; |
| 865 | 871 | |
| 866 | 872 | case TMS5110_CMD_READ_BIT: |
| r249030 | r249031 | |
| 888 | 894 | m_SPEN = 1; /* start immediately */ |
| 889 | 895 | /* clear out variables before speaking */ |
| 890 | 896 | m_zpar = 1; // zero all the parameters |
| 891 | | m_uv_zpar = 1; // zero k4-k10 as well |
| 892 | | m_OLDE = 1; // 'silence/zpar' frames are zero energy |
| 893 | | m_OLDP = 1; // 'silence/zpar' frames are zero pitch |
| 894 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 895 | | m_old_zpar = 1; // zero all the old parameters |
| 896 | | m_old_uv_zpar = 1; // zero old k4-k10 as well |
| 897 | | #endif |
| 898 | 897 | m_subc_reload = 1; // SPEAK means this is 1 |
| 898 | m_subcycle = m_subc_reload; |
| 899 | m_PC = 0; |
| 900 | m_IP = 0; |
| 899 | 901 | break; |
| 900 | 902 | |
| 901 | 903 | case TMS5110_CMD_READ_BRANCH: |
| r249030 | r249031 | |
| 994 | 996 | fprintf(stderr," "); |
| 995 | 997 | #endif |
| 996 | 998 | } |
| 997 | | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 998 | | fprintf(stderr,"\n"); |
| 999 | | #endif |
| 1000 | 999 | #ifdef VERBOSE |
| 1001 | 1000 | logerror("Parsed a frame successfully in ROM\n"); |
| 1002 | 1001 | #endif |
| r249030 | r249031 | |
| 1153 | 1152 | #ifdef PERFECT_INTERPOLATION_HACK |
| 1154 | 1153 | m_old_frame_energy_idx = m_old_frame_pitch_idx = 0; |
| 1155 | 1154 | memset(m_old_frame_k_idx, 0, sizeof(m_old_frame_k_idx)); |
| 1156 | | m_old_zpar = m_old_uv_zpar = 0; |
| 1155 | m_old_zpar = 0; |
| 1157 | 1156 | #endif |
| 1158 | 1157 | m_new_frame_energy_idx = m_current_energy = m_previous_energy = 0; |
| 1159 | 1158 | m_new_frame_pitch_idx = m_current_pitch = 0; |
trunk/src/emu/sound/tms5220.c
| r249030 | r249031 | |
| 271 | 271 | * or clip logic, even though the real hardware doesn't do this, partially verified by decap */ |
| 272 | 272 | #undef ALLOW_4_LSB |
| 273 | 273 | |
| 274 | | /* forces m_TALK active instantly whenever m_SPEN would be activated, causing speech delay to be reduced by up to one frame time */ |
| 275 | | /* for some reason, this hack makes victory behave better, though it does not match the patent */ |
| 276 | | #define FAST_START_HACK 1 |
| 277 | 274 | |
| 278 | | |
| 279 | 275 | /* *****configuration of chip connection stuff***** */ |
| 280 | 276 | /* must be defined; if 0, output the waveform as if it was tapped on the speaker pin as usual, if 1, output the waveform as if it was tapped on the i/o pin (volume is much lower in the latter case) */ |
| 281 | 277 | #define FORCE_DIGITAL 0 |
| r249030 | r249031 | |
| 365 | 361 | save_item(NAME(m_fifo_count)); |
| 366 | 362 | save_item(NAME(m_fifo_bits_taken)); |
| 367 | 363 | |
| 368 | | save_item(NAME(m_previous_TALK_STATUS)); |
| 369 | | save_item(NAME(m_SPEN)); |
| 370 | | save_item(NAME(m_DDIS)); |
| 371 | | save_item(NAME(m_TALK)); |
| 372 | | save_item(NAME(m_TALKD)); |
| 364 | save_item(NAME(m_speaking_now)); |
| 365 | save_item(NAME(m_speak_external)); |
| 366 | save_item(NAME(m_talk_status)); |
| 373 | 367 | save_item(NAME(m_buffer_low)); |
| 374 | 368 | save_item(NAME(m_buffer_empty)); |
| 375 | 369 | save_item(NAME(m_irq_pin)); |
| r249030 | r249031 | |
| 390 | 384 | save_item(NAME(m_current_pitch)); |
| 391 | 385 | save_item(NAME(m_current_k)); |
| 392 | 386 | |
| 387 | save_item(NAME(m_target_energy)); |
| 388 | save_item(NAME(m_target_pitch)); |
| 389 | save_item(NAME(m_target_k)); |
| 390 | |
| 393 | 391 | save_item(NAME(m_previous_energy)); |
| 394 | 392 | |
| 395 | 393 | save_item(NAME(m_subcycle)); |
| r249030 | r249031 | |
| 397 | 395 | save_item(NAME(m_PC)); |
| 398 | 396 | save_item(NAME(m_IP)); |
| 399 | 397 | save_item(NAME(m_inhibit)); |
| 400 | | save_item(NAME(m_uv_zpar)); |
| 401 | | save_item(NAME(m_zpar)); |
| 402 | | save_item(NAME(m_pitch_zero)); |
| 403 | 398 | save_item(NAME(m_c_variant_rate)); |
| 404 | 399 | save_item(NAME(m_pitch_count)); |
| 405 | 400 | |
| r249030 | r249031 | |
| 470 | 465 | |
| 471 | 466 | void tms5220_device::data_write(int data) |
| 472 | 467 | { |
| 473 | | int old_buffer_low = m_buffer_low; |
| 474 | 468 | #ifdef DEBUG_DUMP_INPUT_DATA |
| 475 | 469 | fprintf(stdout, "%c",data); |
| 476 | 470 | #endif |
| 477 | | if (m_DDIS) // If we're in speak external mode |
| 471 | if (m_speak_external) // If we're in speak external mode |
| 478 | 472 | { |
| 479 | 473 | // add this byte to the FIFO |
| 480 | 474 | if (m_fifo_count < FIFO_SIZE) |
| r249030 | r249031 | |
| 483 | 477 | m_fifo_tail = (m_fifo_tail + 1) % FIFO_SIZE; |
| 484 | 478 | m_fifo_count++; |
| 485 | 479 | #ifdef DEBUG_FIFO |
| 486 | | fprintf(stderr,"data_write: Added byte to FIFO (current count=%2d)\n", m_fifo_count); |
| 480 | logerror("data_write: Added byte to FIFO (current count=%2d)\n", m_fifo_count); |
| 487 | 481 | #endif |
| 488 | 482 | update_fifo_status_and_ints(); |
| 489 | | // if we just unset buffer low with that last write, and SPEN *was* zero (see circuit 251, sheet 12) |
| 490 | | if ((m_SPEN == 0) && ((old_buffer_low == 1) && (m_buffer_low == 0))) // MUST HAVE EDGE DETECT |
| 483 | if ((m_talk_status == 0) && (m_buffer_low == 0)) // we just unset buffer low with that last write, and talk status *was* zero... |
| 491 | 484 | { |
| 492 | | int i; |
| 485 | int i; |
| 493 | 486 | #ifdef DEBUG_FIFO |
| 494 | | fprintf(stderr,"data_write triggered SPEN to go active!\n"); |
| 487 | logerror("data_write triggered talk status to go active!\n"); |
| 495 | 488 | #endif |
| 496 | | // ...then we now have enough bytes to start talking; set zpar and clear out the new frame parameters (it will become old frame just before the first call to parse_frame() ) |
| 497 | | m_zpar = 1; |
| 498 | | m_uv_zpar = 1; // zero k4-k10 as well |
| 499 | | m_OLDE = 1; // 'silence/zpar' frames are zero energy |
| 500 | | m_OLDP = 1; // 'silence/zpar' frames are zero pitch |
| 501 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 502 | | m_old_zpar = 1; // zero all the old parameters |
| 503 | | m_old_uv_zpar = 1; // zero old k4-k10 as well |
| 504 | | #endif |
| 505 | | m_SPEN = 1; |
| 506 | | #ifdef FAST_START_HACK |
| 507 | | m_TALK = 1; |
| 508 | | #endif |
| 489 | // ...then we now have enough bytes to start talking; clear out the new frame parameters (it will become old frame just before the first call to parse_frame() ) |
| 490 | // TODO: the 3 lines below (and others) are needed for victory to not fail its selftest due to a sample ending too late, may require additional investigation |
| 491 | m_subcycle = m_subc_reload; |
| 492 | m_PC = 0; |
| 493 | m_IP = reload_table[m_c_variant_rate&0x3]; // is this correct? should this be always 7 instead, so that the new frame is loaded quickly? |
| 509 | 494 | m_new_frame_energy_idx = 0; |
| 510 | 495 | m_new_frame_pitch_idx = 0; |
| 511 | 496 | for (i = 0; i < 4; i++) |
| r249030 | r249031 | |
| 514 | 499 | m_new_frame_k_idx[i] = 0xF; |
| 515 | 500 | for (i = 7; i < m_coeff->num_k; i++) |
| 516 | 501 | m_new_frame_k_idx[i] = 0x7; |
| 517 | | |
| 502 | m_talk_status = m_speaking_now = 1; |
| 518 | 503 | } |
| 519 | 504 | } |
| 520 | 505 | else |
| 521 | 506 | { |
| 522 | 507 | #ifdef DEBUG_FIFO |
| 523 | | fprintf(stderr,"data_write: Ran out of room in the tms52xx FIFO! this should never happen!\n"); |
| 508 | logerror("data_write: Ran out of room in the tms52xx FIFO! this should never happen!\n"); |
| 524 | 509 | // at this point, /READY should remain HIGH/inactive until the fifo has at least one byte open in it. |
| 525 | 510 | #endif |
| 526 | 511 | } |
| 527 | 512 | |
| 528 | 513 | |
| 529 | 514 | } |
| 530 | | else //(! m_DDIS) |
| 515 | else //(! m_speak_external) |
| 531 | 516 | // R Nabet : we parse commands at once. It is necessary for such commands as read. |
| 532 | 517 | process_command(data); |
| 533 | 518 | } |
| r249030 | r249031 | |
| 575 | 560 | m_buffer_low = 0; |
| 576 | 561 | |
| 577 | 562 | /* BE is set if neither byte 15 nor 14 of the fifo are in use; this |
| 578 | | translates to having fifo_count equal to exactly 0 |
| 579 | | */ |
| 563 | translates to having fifo_count equal to exactly 0 */ |
| 580 | 564 | if (m_fifo_count == 0) |
| 581 | 565 | { |
| 582 | 566 | // generate an interrupt if necessary; if /BE was inactive and is now active, set int. |
| 583 | 567 | if (!m_buffer_empty) |
| 584 | 568 | set_interrupt_state(1); |
| 585 | 569 | m_buffer_empty = 1; |
| 586 | | m_TALK = m_SPEN = 0; // /BE being active clears the TALK(TCON) status which in turn clears SPEN |
| 587 | 570 | } |
| 588 | 571 | else |
| 589 | 572 | m_buffer_empty = 0; |
| 590 | 573 | |
| 591 | | // generate an interrupt if /TS was active, and is now inactive. |
| 592 | | // also, in this case, regardless if DDIS was set, unset it. |
| 593 | | if (m_previous_TALK_STATUS == 1 && (TALK_STATUS == 0)) |
| 574 | /* TS is talk status and is set elsewhere in the fifo parser and in |
| 575 | the SPEAK command handler; however, if /BE is true during speak external |
| 576 | mode, it is immediately unset here. */ |
| 577 | if ((m_speak_external == 1) && (m_buffer_empty == 1)) |
| 594 | 578 | { |
| 595 | | #ifdef VERBOSE |
| 596 | | fprintf(stderr,"Talk status WAS 1, is now 0, unsetting DDIS and firing an interrupt!\n"); |
| 597 | | #endif |
| 598 | | set_interrupt_state(1); |
| 599 | | m_DDIS = 0; |
| 579 | // generate an interrupt: /TS was active, and is now inactive. |
| 580 | if (m_talk_status == 1) |
| 581 | { |
| 582 | m_talk_status = m_speak_external = 0; |
| 583 | set_interrupt_state(1); |
| 584 | } |
| 600 | 585 | } |
| 601 | | m_previous_TALK_STATUS = TALK_STATUS; |
| 602 | | |
| 586 | /* Note that TS being unset will also generate an interrupt when a STOP |
| 587 | frame is encountered; this is handled in the sample generator code and not here */ |
| 603 | 588 | } |
| 604 | 589 | |
| 605 | 590 | /********************************************************************************************** |
| r249030 | r249031 | |
| 612 | 597 | { |
| 613 | 598 | int val = 0; |
| 614 | 599 | |
| 615 | | if (m_DDIS) |
| 600 | if (m_speak_external) |
| 616 | 601 | { |
| 617 | 602 | // extract from FIFO |
| 618 | 603 | while (count--) |
| r249030 | r249031 | |
| 658 | 643 | /* clear the interrupt pin on status read */ |
| 659 | 644 | set_interrupt_state(0); |
| 660 | 645 | #ifdef DEBUG_PIN_READS |
| 661 | | fprintf(stderr,"Status read: TS=%d BL=%d BE=%d\n", TALK_STATUS, m_buffer_low, m_buffer_empty); |
| 646 | logerror("Status read: TS=%d BL=%d BE=%d\n", m_talk_status, m_buffer_low, m_buffer_empty); |
| 662 | 647 | #endif |
| 663 | 648 | |
| 664 | | return (TALK_STATUS << 7) | (m_buffer_low << 6) | (m_buffer_empty << 5); |
| 649 | return (m_talk_status << 7) | (m_buffer_low << 6) | (m_buffer_empty << 5); |
| 665 | 650 | } |
| 666 | 651 | } |
| 667 | 652 | |
| r249030 | r249031 | |
| 675 | 660 | int tms5220_device::ready_read() |
| 676 | 661 | { |
| 677 | 662 | #ifdef DEBUG_PIN_READS |
| 678 | | fprintf(stderr,"ready_read: ready pin read, io_ready is %d, fifo count is %d, DDIS(speak external) is %d\n", m_io_ready, m_fifo_count, m_DDIS); |
| 663 | logerror("ready_read: ready pin read, io_ready is %d, fifo count is %d\n", m_io_ready, m_fifo_count); |
| 679 | 664 | #endif |
| 680 | | return ((m_fifo_count < FIFO_SIZE)||(!m_DDIS)) && m_io_ready; |
| 665 | return ((m_fifo_count < FIFO_SIZE)||(!m_speak_external)) && m_io_ready; |
| 681 | 666 | } |
| 682 | 667 | |
| 683 | 668 | |
| r249030 | r249031 | |
| 733 | 718 | int tms5220_device::int_read() |
| 734 | 719 | { |
| 735 | 720 | #ifdef DEBUG_PIN_READS |
| 736 | | fprintf(stderr,"int_read: irq pin read, state is %d\n", m_irq_pin); |
| 721 | logerror("int_read: irq pin read, state is %d\n", m_irq_pin); |
| 737 | 722 | #endif |
| 738 | 723 | return m_irq_pin; |
| 739 | 724 | } |
| r249030 | r249031 | |
| 748 | 733 | void tms5220_device::process(INT16 *buffer, unsigned int size) |
| 749 | 734 | { |
| 750 | 735 | int buf_count=0; |
| 751 | | int i, bitout; |
| 736 | int i, bitout, zpar; |
| 752 | 737 | INT32 this_sample; |
| 753 | 738 | |
| 754 | | #ifdef VERBOSE |
| 755 | | fprintf(stderr,"process called with size of %d; IP=%d, PC=%d, subcycle=%d, m_SPEN=%d, m_TALK=%d, m_TALKD=%d\n", size, m_IP, m_PC, m_subcycle, m_SPEN, m_TALK, m_TALKD); |
| 756 | | #endif |
| 739 | /* the following gotos are probably safe to remove */ |
| 740 | /* if we're empty and still not speaking, fill with nothingness */ |
| 741 | if (!m_speaking_now) |
| 742 | goto empty; |
| 757 | 743 | |
| 744 | /* if speak external is set, but talk status is not (yet) set, |
| 745 | wait for buffer low to clear */ |
| 746 | if (!m_talk_status && m_speak_external && m_buffer_low) |
| 747 | goto empty; |
| 748 | |
| 758 | 749 | /* loop until the buffer is full or we've stopped speaking */ |
| 759 | | while (size > 0) |
| 750 | while ((size > 0) && m_speaking_now) |
| 760 | 751 | { |
| 761 | | if(m_TALKD) // speaking |
| 752 | /* if it is the appropriate time to update the old energy/pitch indices, |
| 753 | * i.e. when IP=7, PC=12, T=17, subcycle=2, do so. Since IP=7 PC=12 T=17 |
| 754 | * is JUST BEFORE the transition to IP=0 PC=0 T=0 sybcycle=(0 or 1), |
| 755 | * which happens 4 T-cycles later), we change on the latter. |
| 756 | * The indices are updated here ~12 PCs before the new frame is applied. |
| 757 | */ |
| 758 | /** TODO: the patents 4331836, 4335277, and 4419540 disagree about the timing of this **/ |
| 759 | if ((m_IP == 0) && (m_PC == 0) && (m_subcycle < 2)) |
| 762 | 760 | { |
| 763 | | /* if we're ready for a new frame to be applied, i.e. when IP=0, PC=12, Sub=1 |
| 764 | | * (In reality, the frame was really loaded incrementally during the entire IP=0 |
| 765 | | * PC=x time period, but it doesn't affect anything until IP=0 PC=12 happens) |
| 766 | | */ |
| 767 | | if ((m_IP == 0) && (m_PC == 12) && (m_subcycle == 1)) |
| 768 | | { |
| 769 | | // HACK for regression testing, be sure to comment out before release! |
| 770 | | //m_RNG = 0x1234; |
| 771 | | // end HACK |
| 761 | m_OLDE = (m_new_frame_energy_idx == 0); |
| 762 | m_OLDP = (m_new_frame_pitch_idx == 0); |
| 763 | } |
| 772 | 764 | |
| 773 | | /* appropriately override the interp count if needed; this will be incremented after the frame parse! */ |
| 774 | | m_IP = reload_table[m_c_variant_rate&0x3]; |
| 765 | /* if we're ready for a new frame to be applied, i.e. when IP=0, PC=12, Sub=1 |
| 766 | * (In reality, the frame was really loaded incrementally during the entire IP=0 |
| 767 | * PC=x time period, but it doesn't affect anything until IP=0 PC=12 happens) |
| 768 | */ |
| 769 | if ((m_IP == 0) && (m_PC == 12) && (m_subcycle == 1)) |
| 770 | { |
| 771 | // HACK for regression testing, be sure to comment out before release! |
| 772 | //m_RNG = 0x1234; |
| 773 | // end HACK |
| 775 | 774 | |
| 775 | /* appropriately override the interp count if needed; this will be incremented after the frame parse! */ |
| 776 | m_IP = reload_table[m_c_variant_rate&0x3]; |
| 777 | |
| 776 | 778 | #ifdef PERFECT_INTERPOLATION_HACK |
| 777 | | /* remember previous frame energy, pitch, and coefficients */ |
| 778 | | m_old_frame_energy_idx = m_new_frame_energy_idx; |
| 779 | | m_old_frame_pitch_idx = m_new_frame_pitch_idx; |
| 780 | | for (i = 0; i < m_coeff->num_k; i++) |
| 781 | | m_old_frame_k_idx[i] = m_new_frame_k_idx[i]; |
| 779 | /* remember previous frame energy, pitch, and coefficients */ |
| 780 | m_old_frame_energy_idx = m_new_frame_energy_idx; |
| 781 | m_old_frame_pitch_idx = m_new_frame_pitch_idx; |
| 782 | for (i = 0; i < m_coeff->num_k; i++) |
| 783 | m_old_frame_k_idx[i] = m_new_frame_k_idx[i]; |
| 782 | 784 | #endif |
| 783 | 785 | |
| 784 | | /* Parse a new frame into the new_target_energy, new_target_pitch and new_target_k[] */ |
| 785 | | parse_frame(); |
| 786 | /* if the talk status was clear last frame, halt speech now. */ |
| 787 | if (m_talk_status == 0) |
| 788 | { |
| 789 | #ifdef DEBUG_GENERATION |
| 790 | fprintf(stderr,"tms5220_process: processing frame: talk status = 0 caused by stop frame or buffer empty, halting speech.\n"); |
| 791 | #endif |
| 792 | if (m_speaking_now == 1) // we're done, set all coeffs to idle state but keep going for a bit... |
| 793 | { |
| 794 | /**TODO: should index clearing be done here, or elsewhere? **/ |
| 795 | m_new_frame_energy_idx = 0; |
| 796 | m_new_frame_pitch_idx = 0; |
| 797 | for (i = 0; i < 4; i++) |
| 798 | m_new_frame_k_idx[i] = 0; |
| 799 | for (i = 4; i < 7; i++) |
| 800 | m_new_frame_k_idx[i] = 0xF; |
| 801 | for (i = 7; i < m_coeff->num_k; i++) |
| 802 | m_new_frame_k_idx[i] = 0x7; |
| 803 | m_speaking_now = 2; // wait 8 extra interp periods before shutting down so we can interpolate everything to zero state |
| 804 | } |
| 805 | else // m_speaking_now == 2 // now we're really done. |
| 806 | { |
| 807 | m_speaking_now = 0; // finally halt speech |
| 808 | goto empty; |
| 809 | } |
| 810 | } |
| 786 | 811 | |
| 787 | | // if the new frame is unvoiced (or silenced via ZPAR), be sure to zero out the k5-k10 parameters |
| 788 | | // NOTE: this is probably the bug the tms5100/tmc0280 has, pre-rev D, I think. |
| 789 | | // GUESS: Pre-rev D versions start zeroing k5-k10 immediately upon new frame load regardless of interpolation inhibit |
| 790 | | // I.e. ZPAR = /TALKD || (PC>5&&P=0) |
| 791 | | // GUESS: D and later versions only start or stop zeroing k5-k10 at the IP7->IP0 transition AFTER the frame |
| 792 | | // I.e. ZPAR = /TALKD || (PC>5&&OLDP) |
| 793 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 794 | | m_old_uv_zpar = m_uv_zpar; |
| 795 | | m_old_zpar = m_zpar; // unset old zpar on new frame |
| 812 | |
| 813 | /* Parse a new frame into the new_target_energy, new_target_pitch and new_target_k[], |
| 814 | * but only if we're not just about to end speech */ |
| 815 | if (m_speaking_now == 1) parse_frame(); |
| 816 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 817 | fprintf(stderr,"\n"); |
| 796 | 818 | #endif |
| 797 | | m_zpar = 0; |
| 798 | | //m_uv_zpar = (OLD_FRAME_UNVOICED_FLAG||m_zpar); // GUESS: fixed version in tmc0280d/tms5100a/cd280x/tms5110 |
| 799 | | m_uv_zpar = (NEW_FRAME_UNVOICED_FLAG||m_zpar); // GUESS: buggy version in tmc0280/tms5100 |
| 800 | 819 | |
| 801 | | /* if the new frame is a stop frame, unset both TALK and SPEN (via TCON). TALKD remains active while the energy is ramping to 0. */ |
| 802 | | if (NEW_FRAME_STOP_FLAG == 1) |
| 820 | /* if the new frame is a stop frame, set an interrupt and set talk status to 0 */ |
| 821 | /** TODO: investigate this later! **/ |
| 822 | if (NEW_FRAME_STOP_FLAG == 1) |
| 803 | 823 | { |
| 804 | | m_TALK = m_SPEN = 0; |
| 824 | m_talk_status = m_speak_external = 0; |
| 825 | set_interrupt_state(1); |
| 826 | update_fifo_status_and_ints(); |
| 805 | 827 | } |
| 806 | 828 | |
| 807 | | /* in all cases where interpolation would be inhibited, set the inhibit flag; otherwise clear it. |
| 808 | | Interpolation inhibit cases: |
| 809 | | * Old frame was voiced, new is unvoiced |
| 810 | | * Old frame was silence/zero energy, new has nonzero energy |
| 811 | | * Old frame was unvoiced, new is voiced |
| 812 | | * Old frame was unvoiced, new frame is silence/zero energy (unique to tms52xx) |
| 813 | | */ |
| 814 | | if ( ((OLD_FRAME_UNVOICED_FLAG == 0) && (NEW_FRAME_UNVOICED_FLAG == 1)) |
| 815 | | || ((OLD_FRAME_UNVOICED_FLAG == 1) && (NEW_FRAME_UNVOICED_FLAG == 0)) |
| 816 | | || ((OLD_FRAME_SILENCE_FLAG == 1) && (NEW_FRAME_SILENCE_FLAG == 0)) |
| 817 | | || ((OLD_FRAME_UNVOICED_FLAG == 1) && (NEW_FRAME_SILENCE_FLAG == 1)) ) |
| 818 | | m_inhibit = 1; |
| 819 | | else // normal frame, normal interpolation |
| 820 | | m_inhibit = 0; |
| 829 | /* in all cases where interpolation would be inhibited, set the inhibit flag; otherwise clear it. |
| 830 | Interpolation inhibit cases: |
| 831 | * Old frame was voiced, new is unvoiced |
| 832 | * Old frame was silence/zero energy, new has nonzero energy |
| 833 | * Old frame was unvoiced, new is voiced |
| 834 | * Old frame was unvoiced, new frame is silence/zero energy (unique to tms52xx) |
| 835 | */ |
| 836 | if ( ((OLD_FRAME_UNVOICED_FLAG == 0) && (NEW_FRAME_UNVOICED_FLAG == 1)) |
| 837 | || ((OLD_FRAME_UNVOICED_FLAG == 1) && (NEW_FRAME_UNVOICED_FLAG == 0)) |
| 838 | || ((OLD_FRAME_SILENCE_FLAG == 1) && (NEW_FRAME_SILENCE_FLAG == 0)) |
| 839 | || ((OLD_FRAME_UNVOICED_FLAG == 1) && (NEW_FRAME_SILENCE_FLAG == 1)) ) |
| 840 | m_inhibit = 1; |
| 841 | else // normal frame, normal interpolation |
| 842 | m_inhibit = 0; |
| 821 | 843 | |
| 844 | /* load new frame targets from tables, using parsed indices */ |
| 845 | m_target_energy = m_coeff->energytable[m_new_frame_energy_idx]; |
| 846 | m_target_pitch = m_coeff->pitchtable[m_new_frame_pitch_idx]; |
| 847 | zpar = NEW_FRAME_UNVOICED_FLAG; // find out if parameters k5-k10 should be zeroed |
| 848 | for (i = 0; i < 4; i++) |
| 849 | m_target_k[i] = m_coeff->ktable[i][m_new_frame_k_idx[i]]; |
| 850 | for (i = 4; i < m_coeff->num_k; i++) |
| 851 | m_target_k[i] = (m_coeff->ktable[i][m_new_frame_k_idx[i]] * (1-zpar)); |
| 852 | |
| 822 | 853 | #ifdef DEBUG_GENERATION |
| 823 | | /* Debug info for current parsed frame */ |
| 824 | | fprintf(stderr, "OLDE: %d; OLDP: %d; ", m_OLDE, m_OLDP); |
| 825 | | fprintf(stderr,"Processing new frame: "); |
| 826 | | if (m_inhibit == 0) |
| 827 | | fprintf(stderr, "Normal Frame\n"); |
| 828 | | else |
| 829 | | fprintf(stderr,"Interpolation Inhibited\n"); |
| 830 | | fprintf(stderr,"*** current Energy, Pitch and Ks = %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n",m_current_energy, m_current_pitch, m_current_k[0], m_current_k[1], m_current_k[2], m_current_k[3], m_current_k[4], m_current_k[5], m_current_k[6], m_current_k[7], m_current_k[8], m_current_k[9]); |
| 831 | | fprintf(stderr,"*** target Energy(idx), Pitch, and Ks = %04d(%x),%04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n", |
| 832 | | (m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)), |
| 833 | | m_new_frame_energy_idx, |
| 834 | | (m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)), |
| 835 | | (m_coeff->ktable[0][m_new_frame_k_idx[0]] * (1-m_zpar)), |
| 836 | | (m_coeff->ktable[1][m_new_frame_k_idx[1]] * (1-m_zpar)), |
| 837 | | (m_coeff->ktable[2][m_new_frame_k_idx[2]] * (1-m_zpar)), |
| 838 | | (m_coeff->ktable[3][m_new_frame_k_idx[3]] * (1-m_zpar)), |
| 839 | | (m_coeff->ktable[4][m_new_frame_k_idx[4]] * (1-m_uv_zpar)), |
| 840 | | (m_coeff->ktable[5][m_new_frame_k_idx[5]] * (1-m_uv_zpar)), |
| 841 | | (m_coeff->ktable[6][m_new_frame_k_idx[6]] * (1-m_uv_zpar)), |
| 842 | | (m_coeff->ktable[7][m_new_frame_k_idx[7]] * (1-m_uv_zpar)), |
| 843 | | (m_coeff->ktable[8][m_new_frame_k_idx[8]] * (1-m_uv_zpar)), |
| 844 | | (m_coeff->ktable[9][m_new_frame_k_idx[9]] * (1-m_uv_zpar)) ); |
| 854 | /* Debug info for current parsed frame */ |
| 855 | fprintf(stderr, "OLDE: %d; OLDP: %d; ", m_OLDE, m_OLDP); |
| 856 | fprintf(stderr,"Processing frame: "); |
| 857 | if (m_inhibit == 0) |
| 858 | fprintf(stderr, "Normal Frame\n"); |
| 859 | else |
| 860 | fprintf(stderr,"Interpolation Inhibited\n"); |
| 861 | fprintf(stderr,"*** current Energy, Pitch and Ks = %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n",m_current_energy, m_current_pitch, m_current_k[0], m_current_k[1], m_current_k[2], m_current_k[3], m_current_k[4], m_current_k[5], m_current_k[6], m_current_k[7], m_current_k[8], m_current_k[9]); |
| 862 | fprintf(stderr,"*** target Energy(idx), Pitch, and Ks = %04d(%x),%04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n",m_target_energy, m_new_frame_energy_idx, m_target_pitch, m_target_k[0], m_target_k[1], m_target_k[2], m_target_k[3], m_target_k[4], m_target_k[5], m_target_k[6], m_target_k[7], m_target_k[8], m_target_k[9]); |
| 845 | 863 | #endif |
| 846 | 864 | |
| 847 | | } |
| 848 | | else // Not a new frame, just interpolate the existing frame. |
| 865 | /* if TS is now 0, ramp the energy down to 0. Is this really correct to hardware? */ |
| 866 | if (m_talk_status == 0) |
| 849 | 867 | { |
| 850 | | int inhibit_state = ((m_inhibit==1)&&(m_IP != 0)); // disable inhibit when reaching the last interp period, but don't overwrite the m_inhibit value |
| 851 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 852 | | int samples_per_frame = m_subc_reload?175:266; // either (13 A cycles + 12 B cycles) * 7 interps for normal SPEAK/SPKEXT, or (13*2 A cycles + 12 B cycles) * 7 interps for SPKSLOW |
| 853 | | //int samples_per_frame = m_subc_reload?200:304; // either (13 A cycles + 12 B cycles) * 8 interps for normal SPEAK/SPKEXT, or (13*2 A cycles + 12 B cycles) * 8 interps for SPKSLOW |
| 854 | | int current_sample = (m_subcycle - m_subc_reload)+(m_PC*(3-m_subc_reload))+((m_subc_reload?25:38)*((m_IP-1)&7)); |
| 855 | | //fprintf(stderr, "CS: %03d", current_sample); |
| 856 | | // reset the current energy, pitch, etc to what it was at frame start |
| 857 | | m_current_energy = (m_coeff->energytable[m_old_frame_energy_idx] * (1-m_old_zpar)); |
| 858 | | m_current_pitch = (m_coeff->pitchtable[m_old_frame_pitch_idx] * (1-m_old_zpar)); |
| 859 | | for (i = 0; i < m_coeff->num_k; i++) |
| 860 | | m_current_k[i] = (m_coeff->ktable[i][m_old_frame_k_idx[i]] * (1-((i<4)?m_old_zpar:m_old_uv_zpar))); |
| 861 | | // now adjust each value to be exactly correct for each of the samples per frame |
| 862 | | if (m_IP != 0) // if we're still interpolating... |
| 863 | | { |
| 864 | | m_current_energy = (m_current_energy + (((m_coeff->energytable[m_new_frame_energy_idx] - m_current_energy)*(1-inhibit_state))*current_sample)/samples_per_frame)*(1-m_zpar); |
| 865 | | m_current_pitch = (m_current_pitch + (((m_coeff->pitchtable[m_new_frame_pitch_idx] - m_current_pitch)*(1-inhibit_state))*current_sample)/samples_per_frame)*(1-m_zpar); |
| 866 | | for (i = 0; i < m_coeff->num_k; i++) |
| 867 | | m_current_k[i] = (m_current_k[i] + (((m_coeff->ktable[i][m_new_frame_k_idx[i]] - m_current_k[i])*(1-inhibit_state))*current_sample)/samples_per_frame)*(1-((i<4)?m_zpar:m_uv_zpar)); |
| 868 | | } |
| 869 | | else // we're done, play this frame for 1/8 frame. |
| 870 | | { |
| 871 | | m_current_energy = (m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)); |
| 872 | | m_current_pitch = (m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)); |
| 873 | | for (i = 0; i < m_coeff->num_k; i++) |
| 874 | | m_current_k[i] = (m_coeff->ktable[i][m_new_frame_k_idx[i]] * (1-((i<4)?m_zpar:m_uv_zpar))); |
| 875 | | } |
| 876 | | #else |
| 877 | | //Updates to parameters only happen on subcycle '2' (B cycle) of PCs. |
| 878 | | if (m_subcycle == 2) |
| 879 | | { |
| 880 | | switch(m_PC) |
| 881 | | { |
| 882 | | case 0: /* PC = 0, B cycle, write updated energy */ |
| 883 | | m_current_energy = (m_current_energy + (((m_coeff->energytable[m_new_frame_energy_idx] - m_current_energy)*(1-inhibit_state)) INTERP_SHIFT))*(1-m_zpar); |
| 884 | | break; |
| 885 | | case 1: /* PC = 1, B cycle, write updated pitch */ |
| 886 | | m_current_pitch = (m_current_pitch + (((m_coeff->pitchtable[m_new_frame_pitch_idx] - m_current_pitch)*(1-inhibit_state)) INTERP_SHIFT))*(1-m_zpar); |
| 887 | | break; |
| 888 | | case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: |
| 889 | | /* PC = 2 through 11, B cycle, write updated K1 through K10 */ |
| 890 | | m_current_k[m_PC-2] = (m_current_k[m_PC-2] + (((m_coeff->ktable[m_PC-2][m_new_frame_k_idx[m_PC-2]] - m_current_k[m_PC-2])*(1-inhibit_state)) INTERP_SHIFT))*(((m_PC-2)>4)?(1-m_uv_zpar):(1-m_zpar)); |
| 891 | | break; |
| 892 | | case 12: /* PC = 12 */ |
| 893 | | /* we should NEVER reach this point, PC=12 doesn't have a subcycle 2 */ |
| 894 | | break; |
| 895 | | } |
| 896 | | } |
| 868 | #ifdef DEBUG_GENERATION |
| 869 | fprintf(stderr,"Talk status is 0, forcing target energy to 0\n"); |
| 897 | 870 | #endif |
| 871 | m_target_energy = 0; |
| 898 | 872 | } |
| 873 | } |
| 874 | else // Not a new frame, just interpolate the existing frame. |
| 875 | { |
| 876 | int inhibit_state = ((m_inhibit==1)&&(m_IP != 0)); // disable inhibit when reaching the last interp period, but don't overwrite the m_inhibit value |
| 877 | #ifdef PERFECT_INTERPOLATION_HACK |
| 878 | int samples_per_frame = m_subc_reload?175:266; // either (13 A cycles + 12 B cycles) * 7 interps for normal SPEAK/SPKEXT, or (13*2 A cycles + 12 B cycles) * 7 interps for SPKSLOW |
| 879 | //int samples_per_frame = m_subc_reload?200:304; // either (13 A cycles + 12 B cycles) * 8 interps for normal SPEAK/SPKEXT, or (13*2 A cycles + 12 B cycles) * 8 interps for SPKSLOW |
| 880 | int current_sample = (m_subcycle - m_subc_reload)+(m_PC*(3-m_subc_reload))+((m_subc_reload?25:38)*((m_IP-1)&7)); |
| 899 | 881 | |
| 900 | | // calculate the output |
| 901 | | if (OLD_FRAME_UNVOICED_FLAG == 1) |
| 882 | zpar = OLD_FRAME_UNVOICED_FLAG; |
| 883 | //fprintf(stderr, "CS: %03d", current_sample); |
| 884 | // reset the current energy, pitch, etc to what it was at frame start |
| 885 | m_current_energy = m_coeff->energytable[m_old_frame_energy_idx]; |
| 886 | m_current_pitch = m_coeff->pitchtable[m_old_frame_pitch_idx]; |
| 887 | for (i = 0; i < 4; i++) |
| 888 | m_current_k[i] = m_coeff->ktable[i][m_old_frame_k_idx[i]]; |
| 889 | for (i = 4; i < m_coeff->num_k; i++) |
| 890 | m_current_k[i] = (m_coeff->ktable[i][m_old_frame_k_idx[i]] * (1-zpar)); |
| 891 | // now adjust each value to be exactly correct for each of the samples per frame |
| 892 | if (m_IP != 0) // if we're still interpolating... |
| 902 | 893 | { |
| 903 | | // generate unvoiced samples here |
| 904 | | if (m_RNG & 1) |
| 905 | | m_excitation_data = ~0x3F; /* according to the patent it is (either + or -) half of the maximum value in the chirp table, so either 01000000(0x40) or 11000000(0xC0)*/ |
| 906 | | else |
| 907 | | m_excitation_data = 0x40; |
| 894 | m_current_energy += (((m_target_energy - m_current_energy)*(1-inhibit_state))*current_sample)/samples_per_frame; |
| 895 | m_current_pitch += (((m_target_pitch - m_current_pitch)*(1-inhibit_state))*current_sample)/samples_per_frame; |
| 896 | for (i = 0; i < m_coeff->num_k; i++) |
| 897 | m_current_k[i] += (((m_target_k[i] - m_current_k[i])*(1-inhibit_state))*current_sample)/samples_per_frame; |
| 908 | 898 | } |
| 909 | | else /* (OLD_FRAME_UNVOICED_FLAG == 0) */ |
| 899 | else // we're done, play this frame for 1/8 frame. |
| 910 | 900 | { |
| 911 | | // generate voiced samples here |
| 912 | | /* US patent 4331836 Figure 14B shows, and logic would hold, that a pitch based chirp |
| 913 | | * function has a chirp/peak and then a long chain of zeroes. |
| 914 | | * The last entry of the chirp rom is at address 0b110011 (51d), the 52nd sample, |
| 915 | | * and if the address reaches that point the ADDRESS incrementer is |
| 916 | | * disabled, forcing all samples beyond 51d to be == 51d |
| 917 | | */ |
| 918 | | if (m_pitch_count >= 51) |
| 919 | | m_excitation_data = (INT8)m_coeff->chirptable[51]; |
| 920 | | else /*m_pitch_count < 51*/ |
| 921 | | m_excitation_data = (INT8)m_coeff->chirptable[m_pitch_count]; |
| 901 | m_current_energy = m_target_energy; |
| 902 | m_current_pitch = m_target_pitch; |
| 903 | for (i = 0; i < m_coeff->num_k; i++) |
| 904 | m_current_k[i] = m_target_k[i]; |
| 922 | 905 | } |
| 923 | | |
| 924 | | // Update LFSR *20* times every sample (once per T cycle), like patent shows |
| 925 | | for (i=0; i<20; i++) |
| 906 | #else |
| 907 | //Updates to parameters only happen on subcycle '2' (B cycle) of PCs. |
| 908 | if (m_subcycle == 2) |
| 926 | 909 | { |
| 927 | | bitout = ((m_RNG >> 12) & 1) ^ |
| 928 | | ((m_RNG >> 3) & 1) ^ |
| 929 | | ((m_RNG >> 2) & 1) ^ |
| 930 | | ((m_RNG >> 0) & 1); |
| 931 | | m_RNG <<= 1; |
| 932 | | m_RNG |= bitout; |
| 910 | switch(m_PC) |
| 911 | { |
| 912 | case 0: /* PC = 0, B cycle, write updated energy */ |
| 913 | m_current_energy += (((m_target_energy - m_current_energy)*(1-inhibit_state)) INTERP_SHIFT); |
| 914 | break; |
| 915 | case 1: /* PC = 1, B cycle, write updated pitch */ |
| 916 | m_current_pitch += (((m_target_pitch - m_current_pitch)*(1-inhibit_state)) INTERP_SHIFT); |
| 917 | break; |
| 918 | case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: |
| 919 | /* PC = 2 through 11, B cycle, write updated K1 through K10 */ |
| 920 | m_current_k[m_PC-2] += (((m_target_k[m_PC-2] - m_current_k[m_PC-2])*(1-inhibit_state)) INTERP_SHIFT); |
| 921 | break; |
| 922 | case 12: /* PC = 12, do nothing */ |
| 923 | break; |
| 924 | } |
| 933 | 925 | } |
| 934 | | this_sample = lattice_filter(); /* execute lattice filter */ |
| 926 | #endif |
| 927 | } |
| 928 | |
| 929 | // calculate the output |
| 930 | if (OLD_FRAME_UNVOICED_FLAG == 1) |
| 931 | { |
| 932 | // generate unvoiced samples here |
| 933 | if (m_RNG & 1) |
| 934 | m_excitation_data = ~0x3F; /* according to the patent it is (either + or -) half of the maximum value in the chirp table, so either 01000000(0x40) or 11000000(0xC0)*/ |
| 935 | else |
| 936 | m_excitation_data = 0x40; |
| 937 | } |
| 938 | else /* (OLD_FRAME_UNVOICED_FLAG == 0) */ |
| 939 | { |
| 940 | // generate voiced samples here |
| 941 | /* US patent 4331836 Figure 14B shows, and logic would hold, that a pitch based chirp |
| 942 | * function has a chirp/peak and then a long chain of zeroes. |
| 943 | * The last entry of the chirp rom is at address 0b110011 (51d), the 52nd sample, |
| 944 | * and if the address reaches that point the ADDRESS incrementer is |
| 945 | * disabled, forcing all samples beyond 51d to be == 51d |
| 946 | */ |
| 947 | if (m_pitch_count >= 51) |
| 948 | m_excitation_data = (INT8)m_coeff->chirptable[51]; |
| 949 | else /*m_pitch_count < 51*/ |
| 950 | m_excitation_data = (INT8)m_coeff->chirptable[m_pitch_count]; |
| 951 | } |
| 952 | |
| 953 | // Update LFSR *20* times every sample (once per T cycle), like patent shows |
| 954 | for (i=0; i<20; i++) |
| 955 | { |
| 956 | bitout = ((m_RNG >> 12) & 1) ^ |
| 957 | ((m_RNG >> 3) & 1) ^ |
| 958 | ((m_RNG >> 2) & 1) ^ |
| 959 | ((m_RNG >> 0) & 1); |
| 960 | m_RNG <<= 1; |
| 961 | m_RNG |= bitout; |
| 962 | } |
| 963 | this_sample = lattice_filter(); /* execute lattice filter */ |
| 935 | 964 | #ifdef DEBUG_GENERATION_VERBOSE |
| 936 | | //fprintf(stderr,"C:%01d; ",m_subcycle); |
| 937 | | fprintf(stderr,"IP:%01d PC:%02d X:%04d E:%03d P:%03d Pc:%03d ",m_IP, m_PC, m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 938 | | //fprintf(stderr,"X:%04d E:%03d P:%03d Pc:%03d ", m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 939 | | for (i=0; i<10; i++) |
| 940 | | fprintf(stderr,"K%d:%04d ", i+1, m_current_k[i]); |
| 941 | | fprintf(stderr,"Out:%06d ", this_sample); |
| 942 | | //#ifdef PERFECT_INTERPOLATION_HACK |
| 943 | | // fprintf(stderr,"%d%d%d%d",m_old_zpar,m_zpar,m_old_uv_zpar,m_uv_zpar); |
| 944 | | //#else |
| 945 | | // fprintf(stderr,"x%dx%d",m_zpar,m_uv_zpar); |
| 946 | | //#endif |
| 947 | | fprintf(stderr,"\n"); |
| 965 | //fprintf(stderr,"C:%01d; ",m_subcycle); |
| 966 | fprintf(stderr,"IP:%01d PC:%02d X:%04d E:%03d P:%03d Pc:%03d ",m_IP, m_PC, m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 967 | //fprintf(stderr,"X:%04d E:%03d P:%03d Pc:%03d ", m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 968 | for (i=0; i<10; i++) |
| 969 | fprintf(stderr,"K%d:%04d ", i+1, m_current_k[i]); |
| 970 | fprintf(stderr,"Out:%06d", this_sample); |
| 971 | fprintf(stderr,"\n"); |
| 948 | 972 | #endif |
| 949 | | /* next, force result to 14 bits (since its possible that the addition at the final (k1) stage of the lattice overflowed) */ |
| 950 | | while (this_sample > 16383) this_sample -= 32768; |
| 951 | | while (this_sample < -16384) this_sample += 32768; |
| 952 | | if (m_digital_select == 0) // analog SPK pin output is only 8 bits, with clipping |
| 953 | | buffer[buf_count] = clip_analog(this_sample); |
| 954 | | else // digital I/O pin output is 12 bits |
| 955 | | { |
| 973 | /* next, force result to 14 bits (since its possible that the addition at the final (k1) stage of the lattice overflowed) */ |
| 974 | while (this_sample > 16383) this_sample -= 32768; |
| 975 | while (this_sample < -16384) this_sample += 32768; |
| 976 | if (m_digital_select == 0) // analog SPK pin output is only 8 bits, with clipping |
| 977 | buffer[buf_count] = clip_analog(this_sample); |
| 978 | else // digital I/O pin output is 12 bits |
| 979 | { |
| 956 | 980 | #ifdef ALLOW_4_LSB |
| 957 | | // input: ssss ssss ssss ssss ssnn nnnn nnnn nnnn |
| 958 | | // N taps: ^ = 0x2000; |
| 959 | | // output: ssss ssss ssss ssss snnn nnnn nnnn nnnN |
| 960 | | buffer[buf_count] = (this_sample<<1)|((this_sample&0x2000)>>13); |
| 981 | // input: ssss ssss ssss ssss ssnn nnnn nnnn nnnn |
| 982 | // N taps: ^ = 0x2000; |
| 983 | // output: ssss ssss ssss ssss snnn nnnn nnnn nnnN |
| 984 | buffer[buf_count] = (this_sample<<1)|((this_sample&0x2000)>>13); |
| 961 | 985 | #else |
| 962 | | this_sample &= ~0xF; |
| 963 | | // input: ssss ssss ssss ssss ssnn nnnn nnnn 0000 |
| 964 | | // N taps: ^^ ^^^ = 0x3E00; |
| 965 | | // output: ssss ssss ssss ssss snnn nnnn nnnN NNNN |
| 966 | | buffer[buf_count] = (this_sample<<1)|((this_sample&0x3E00)>>9); |
| 986 | this_sample &= ~0xF; |
| 987 | // input: ssss ssss ssss ssss ssnn nnnn nnnn 0000 |
| 988 | // N taps: ^^ ^^^ = 0x3E00; |
| 989 | // output: ssss ssss ssss ssss snnn nnnn nnnN NNNN |
| 990 | buffer[buf_count] = (this_sample<<1)|((this_sample&0x3E00)>>9); |
| 967 | 991 | #endif |
| 968 | | } |
| 969 | | // Update all counts |
| 992 | } |
| 993 | // Update all counts |
| 970 | 994 | |
| 971 | | m_subcycle++; |
| 972 | | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 973 | | { |
| 974 | | /* Circuit 412 in the patent acts a reset, resetting the pitch counter to 0 |
| 975 | | * if INHIBIT was true during the most recent frame transition. |
| 976 | | * The exact time this occurs is betwen IP=7, PC=12 sub=0, T=t12 |
| 977 | | * and m_IP = 0, PC=0 sub=0, T=t12, a period of exactly 20 cycles, |
| 978 | | * which overlaps the time OLDE and OLDP are updated at IP=7 PC=12 T17 |
| 979 | | * (and hence INHIBIT itself 2 t-cycles later). We do it here because it is |
| 980 | | * convenient and should make no difference in output. |
| 981 | | */ |
| 982 | | if ((m_IP == 7)&&(m_inhibit==1)) m_pitch_zero = 1; |
| 983 | | if ((m_IP == 0)&&(m_pitch_zero==1)) m_pitch_zero = 0; |
| 984 | | if (m_IP == 7) // RESETL4 |
| 985 | | { |
| 986 | | // Latch OLDE and OLDP |
| 987 | | OLD_FRAME_SILENCE_FLAG = NEW_FRAME_SILENCE_FLAG; // m_OLDE |
| 988 | | OLD_FRAME_UNVOICED_FLAG = NEW_FRAME_UNVOICED_FLAG; // m_OLDP |
| 989 | | /* if TALK was clear last frame, halt speech now, since TALKD (latched from TALK on new frame) just went inactive. */ |
| 990 | | #ifdef DEBUG_GENERATION |
| 991 | | fprintf(stderr,"RESETL4, about to update status: IP=%d, PC=%d, subcycle=%d, m_SPEN=%d, m_TALK=%d, m_TALKD=%d\n", m_IP, m_PC, m_subcycle, m_SPEN, m_TALK, m_TALKD); |
| 992 | | #endif |
| 993 | | #ifdef DEBUG_GENERATION |
| 994 | | if (m_TALK == 0) |
| 995 | | fprintf(stderr,"tms5220_process: processing frame: TALKD = 0 caused by stop frame or buffer empty, halting speech.\n"); |
| 996 | | #endif |
| 997 | | m_TALKD = m_TALK; // TALKD is latched from TALK |
| 998 | | update_fifo_status_and_ints(); // to trigger an interrupt if TALK_STATUS is now inactive |
| 999 | | m_TALK = m_SPEN; // TALK is latched from SPEN |
| 1000 | | #ifdef DEBUG_GENERATION |
| 1001 | | fprintf(stderr,"RESETL4, status updated: IP=%d, PC=%d, subcycle=%d, m_SPEN=%d, m_TALK=%d, m_TALKD=%d\n", m_IP, m_PC, m_subcycle, m_SPEN, m_TALK, m_TALKD); |
| 1002 | | #endif |
| 1003 | | } |
| 1004 | | m_subcycle = m_subc_reload; |
| 1005 | | m_PC = 0; |
| 1006 | | m_IP++; |
| 1007 | | m_IP&=0x7; |
| 1008 | | } |
| 1009 | | else if (m_subcycle == 3) |
| 1010 | | { |
| 1011 | | m_subcycle = m_subc_reload; |
| 1012 | | m_PC++; |
| 1013 | | } |
| 1014 | | m_pitch_count++; |
| 1015 | | if ((m_pitch_count >= m_current_pitch)||(m_pitch_zero == 1)) m_pitch_count = 0; |
| 1016 | | m_pitch_count &= 0x1FF; |
| 995 | m_subcycle++; |
| 996 | if ((m_subcycle == 2) && (m_PC == 12)) |
| 997 | { |
| 998 | /* Circuit 412 in the patent acts a reset, resetting the pitch counter to 0 |
| 999 | * if INHIBIT was true during the most recent frame transition. |
| 1000 | * The exact time this occurs is betwen IP=7, PC=12 sub=0, T=t12 |
| 1001 | * and m_IP = 0, PC=0 sub=0, T=t12, a period of exactly 20 cycles, |
| 1002 | * which overlaps the time OLDE and OLDP are updated at IP=7 PC=12 T17 |
| 1003 | * (and hence INHIBIT itself 2 t-cycles later). We do it here because it is |
| 1004 | * convenient and should make no difference in output. |
| 1005 | */ |
| 1006 | if ((m_IP == 7)&&(m_inhibit==1)) m_pitch_count = 0; |
| 1007 | m_subcycle = m_subc_reload; |
| 1008 | m_PC = 0; |
| 1009 | m_IP++; |
| 1010 | m_IP&=0x7; |
| 1017 | 1011 | } |
| 1018 | | else // m_TALKD == 0 |
| 1012 | else if (m_subcycle == 3) |
| 1019 | 1013 | { |
| 1020 | | m_subcycle++; |
| 1021 | | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 1022 | | { |
| 1023 | | if (m_IP == 7) // RESETL4 |
| 1024 | | { |
| 1025 | | m_TALKD = m_TALK; // TALKD is latched from TALK |
| 1026 | | m_TALK = m_SPEN; // TALK is latched from SPEN |
| 1027 | | } |
| 1028 | | m_subcycle = m_subc_reload; |
| 1029 | | m_PC = 0; |
| 1030 | | m_IP++; |
| 1031 | | m_IP&=0x7; |
| 1032 | | } |
| 1033 | | else if (m_subcycle == 3) |
| 1034 | | { |
| 1035 | | m_subcycle = m_subc_reload; |
| 1036 | | m_PC++; |
| 1037 | | } |
| 1038 | | buffer[buf_count] = -1; /* should be just -1; actual chip outputs -1 every idle sample; (cf note in data sheet, p 10, table 4) */ |
| 1014 | m_subcycle = m_subc_reload; |
| 1015 | m_PC++; |
| 1039 | 1016 | } |
| 1040 | | buf_count++; |
| 1041 | | size--; |
| 1017 | m_pitch_count++; |
| 1018 | if (m_pitch_count >= m_current_pitch) m_pitch_count = 0; |
| 1019 | m_pitch_count &= 0x1FF; |
| 1020 | buf_count++; |
| 1021 | size--; |
| 1042 | 1022 | } |
| 1023 | |
| 1024 | empty: |
| 1025 | |
| 1026 | while (size > 0) |
| 1027 | { |
| 1028 | m_subcycle++; |
| 1029 | if ((m_subcycle == 2) && (m_PC == 12)) |
| 1030 | { |
| 1031 | m_subcycle = m_subc_reload; |
| 1032 | m_PC = 0; |
| 1033 | m_IP++; |
| 1034 | m_IP&=0x7; |
| 1035 | } |
| 1036 | else if (m_subcycle == 3) |
| 1037 | { |
| 1038 | m_subcycle = m_subc_reload; |
| 1039 | m_PC++; |
| 1040 | } |
| 1041 | buffer[buf_count] = -1; /* should be just -1; actual chip outputs -1 every idle sample; (cf note in data sheet, p 10, table 4) */ |
| 1042 | buf_count++; |
| 1043 | size--; |
| 1044 | } |
| 1043 | 1045 | } |
| 1044 | 1046 | |
| 1045 | 1047 | /********************************************************************************************** |
| r249030 | r249031 | |
| 1180 | 1182 | |
| 1181 | 1183 | void tms5220_device::process_command(unsigned char cmd) |
| 1182 | 1184 | { |
| 1183 | | int i; |
| 1184 | 1185 | #ifdef DEBUG_COMMAND_DUMP |
| 1185 | 1186 | fprintf(stderr,"process_command called with parameter %02X\n",cmd); |
| 1186 | 1187 | #endif |
| r249030 | r249031 | |
| 1188 | 1189 | switch (cmd & 0x70) |
| 1189 | 1190 | { |
| 1190 | 1191 | case 0x10 : /* read byte */ |
| 1191 | | if (TALK_STATUS == 0) /* TALKST must be clear for RDBY */ |
| 1192 | if (m_talk_status == 0) /* TALKST must be clear for RDBY */ |
| 1192 | 1193 | { |
| 1193 | 1194 | if (m_schedule_dummy_read) |
| 1194 | 1195 | { |
| r249030 | r249031 | |
| 1210 | 1211 | break; |
| 1211 | 1212 | |
| 1212 | 1213 | case 0x30 : /* read and branch */ |
| 1213 | | if (TALK_STATUS == 0) /* TALKST must be clear for RB */ |
| 1214 | if (m_talk_status == 0) /* TALKST must be clear for RB */ |
| 1214 | 1215 | { |
| 1215 | 1216 | #ifdef VERBOSE |
| 1216 | | fprintf(stderr,"read and branch command received\n"); |
| 1217 | logerror("read and branch command received\n"); |
| 1217 | 1218 | #endif |
| 1218 | 1219 | m_RDB_flag = FALSE; |
| 1219 | 1220 | if (m_speechrom) |
| r249030 | r249031 | |
| 1222 | 1223 | break; |
| 1223 | 1224 | |
| 1224 | 1225 | case 0x40 : /* load address */ |
| 1225 | | if (TALK_STATUS == 0) /* TALKST must be clear for LA */ |
| 1226 | if (m_talk_status == 0) /* TALKST must be clear for LA */ |
| 1226 | 1227 | { |
| 1227 | 1228 | /* tms5220 data sheet says that if we load only one 4-bit nibble, it won't work. |
| 1228 | 1229 | This code does not care about this. */ |
| r249030 | r249031 | |
| 1239 | 1240 | if (m_speechrom) |
| 1240 | 1241 | m_speechrom->read(1); |
| 1241 | 1242 | } |
| 1242 | | m_SPEN = 1; |
| 1243 | | #ifdef FAST_START_HACK |
| 1244 | | m_TALK = 1; |
| 1245 | | #endif |
| 1246 | | m_DDIS = 0; |
| 1247 | | m_zpar = 1; // zero all the parameters |
| 1248 | | m_uv_zpar = 1; // zero k4-k10 as well |
| 1249 | | m_OLDE = 1; // 'silence/zpar' frames are zero energy |
| 1250 | | m_OLDP = 1; // 'silence/zpar' frames are zero pitch |
| 1251 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 1252 | | m_old_zpar = 1; // zero all the old parameters |
| 1253 | | m_old_uv_zpar = 1; // zero old k4-k10 as well |
| 1254 | | #endif |
| 1255 | | // following is semi-hack but matches idle state observed on chip |
| 1243 | m_speaking_now = 1; |
| 1244 | m_speak_external = 0; |
| 1245 | m_talk_status = 1; /* start immediately */ |
| 1246 | /* clear out variables before speaking */ |
| 1247 | // TODO: similar to the victory case described above, but for VSM speech |
| 1248 | m_subcycle = m_subc_reload; |
| 1249 | m_PC = 0; |
| 1250 | m_IP = reload_table[m_c_variant_rate&0x3]; |
| 1256 | 1251 | m_new_frame_energy_idx = 0; |
| 1257 | 1252 | m_new_frame_pitch_idx = 0; |
| 1253 | int i; |
| 1258 | 1254 | for (i = 0; i < 4; i++) |
| 1259 | 1255 | m_new_frame_k_idx[i] = 0; |
| 1260 | 1256 | for (i = 4; i < 7; i++) |
| r249030 | r249031 | |
| 1264 | 1260 | break; |
| 1265 | 1261 | |
| 1266 | 1262 | case 0x60 : /* speak external */ |
| 1267 | | // SPKEXT going active activates SPKEE which clears the fifo |
| 1263 | //SPKEXT going active activates SPKEE which clears the fifo |
| 1268 | 1264 | m_fifo_head = m_fifo_tail = m_fifo_count = m_fifo_bits_taken = 0; |
| 1269 | | // SPEN is enabled when the fifo passes half full (falling edge of BL signal) |
| 1270 | | m_DDIS = 1; |
| 1271 | | m_zpar = 1; // zero all the parameters |
| 1272 | | m_uv_zpar = 1; // zero k4-k10 as well |
| 1273 | | m_OLDE = 1; // 'silence/zpar' frames are zero energy |
| 1274 | | m_OLDP = 1; // 'silence/zpar' frames are zero pitch |
| 1275 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 1276 | | m_old_zpar = 1; // zero all the old parameters |
| 1277 | | m_old_uv_zpar = 1; // zero old k4-k10 as well |
| 1278 | | #endif |
| 1279 | | // following is semi-hack but matches idle state observed on chip |
| 1280 | | m_new_frame_energy_idx = 0; |
| 1281 | | m_new_frame_pitch_idx = 0; |
| 1282 | | for (i = 0; i < 4; i++) |
| 1283 | | m_new_frame_k_idx[i] = 0; |
| 1284 | | for (i = 4; i < 7; i++) |
| 1285 | | m_new_frame_k_idx[i] = 0xF; |
| 1286 | | for (i = 7; i < m_coeff->num_k; i++) |
| 1287 | | m_new_frame_k_idx[i] = 0x7; |
| 1265 | m_speak_external = 1; |
| 1288 | 1266 | m_RDB_flag = FALSE; |
| 1289 | 1267 | break; |
| 1290 | 1268 | |
| r249030 | r249031 | |
| 1330 | 1308 | m_IP = reload_table[m_c_variant_rate&0x3]; |
| 1331 | 1309 | |
| 1332 | 1310 | update_fifo_status_and_ints(); |
| 1333 | | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1311 | if (!m_talk_status) goto ranout; |
| 1334 | 1312 | |
| 1335 | 1313 | // attempt to extract the energy index |
| 1336 | 1314 | m_new_frame_energy_idx = extract_bits(m_coeff->energy_bits); |
| r249030 | r249031 | |
| 1339 | 1317 | fprintf(stderr," "); |
| 1340 | 1318 | #endif |
| 1341 | 1319 | update_fifo_status_and_ints(); |
| 1342 | | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1320 | if (!m_talk_status) goto ranout; |
| 1343 | 1321 | // if the energy index is 0 or 15, we're done |
| 1344 | 1322 | if ((m_new_frame_energy_idx == 0) || (m_new_frame_energy_idx == 15)) |
| 1345 | 1323 | return; |
| r249030 | r249031 | |
| 1359 | 1337 | fprintf(stderr," "); |
| 1360 | 1338 | #endif |
| 1361 | 1339 | update_fifo_status_and_ints(); |
| 1362 | | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1340 | if (!m_talk_status) goto ranout; |
| 1363 | 1341 | // if this is a repeat frame, just do nothing, it will reuse the old coefficients |
| 1364 | 1342 | if (rep_flag) |
| 1365 | 1343 | return; |
| r249030 | r249031 | |
| 1373 | 1351 | fprintf(stderr," "); |
| 1374 | 1352 | #endif |
| 1375 | 1353 | update_fifo_status_and_ints(); |
| 1376 | | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1354 | if (!m_talk_status) goto ranout; |
| 1377 | 1355 | } |
| 1378 | 1356 | |
| 1379 | 1357 | // if the pitch index was zero, we only need 4 K's... |
| r249030 | r249031 | |
| 1392 | 1370 | fprintf(stderr," "); |
| 1393 | 1371 | #endif |
| 1394 | 1372 | update_fifo_status_and_ints(); |
| 1395 | | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1373 | if (!m_talk_status) goto ranout; |
| 1396 | 1374 | } |
| 1397 | | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 1398 | | fprintf(stderr,"\n"); |
| 1399 | | #endif |
| 1400 | 1375 | #ifdef VERBOSE |
| 1401 | | if (m_DDIS) |
| 1402 | | fprintf(stderr,"Parsed a frame successfully in FIFO - %d bits remaining\n", (m_fifo_count*8)-(m_fifo_bits_taken)); |
| 1376 | if (m_speak_external) |
| 1377 | logerror("Parsed a frame successfully in FIFO - %d bits remaining\n", (m_fifo_count*8)-(m_fifo_bits_taken)); |
| 1403 | 1378 | else |
| 1404 | | fprintf(stderr,"Parsed a frame successfully in ROM\n"); |
| 1379 | logerror("Parsed a frame successfully in ROM\n"); |
| 1405 | 1380 | #endif |
| 1406 | 1381 | return; |
| 1407 | 1382 | |
| 1408 | 1383 | ranout: |
| 1409 | 1384 | #ifdef DEBUG_FRAME_ERRORS |
| 1410 | | fprintf(stderr,"Ran out of bits on a parse!\n"); |
| 1385 | logerror("Ran out of bits on a parse!\n"); |
| 1411 | 1386 | #endif |
| 1412 | 1387 | return; |
| 1413 | 1388 | } |
| r249030 | r249031 | |
| 1422 | 1397 | { |
| 1423 | 1398 | if (!TMS5220_IS_52xx) return; // bail out if not a 52xx chip, since there's no int pin |
| 1424 | 1399 | #ifdef DEBUG_PIN_READS |
| 1425 | | fprintf(stderr,"irq pin set to state %d\n", state); |
| 1400 | logerror("irq pin set to state %d\n", state); |
| 1426 | 1401 | #endif |
| 1427 | 1402 | if (!m_irq_handler.isnull() && state != m_irq_pin) |
| 1428 | 1403 | m_irq_handler(!state); |
| r249030 | r249031 | |
| 1439 | 1414 | { |
| 1440 | 1415 | int state = ready_read(); |
| 1441 | 1416 | #ifdef DEBUG_PIN_READS |
| 1442 | | fprintf(stderr,"ready pin set to state %d\n", state); |
| 1417 | logerror("ready pin set to state %d\n", state); |
| 1443 | 1418 | #endif |
| 1444 | 1419 | if (!m_readyq_handler.isnull() && state != m_ready_pin) |
| 1445 | 1420 | m_readyq_handler(!state); |
| r249030 | r249031 | |
| 1539 | 1514 | |
| 1540 | 1515 | /* initialize the chip state */ |
| 1541 | 1516 | /* Note that we do not actually clear IRQ on start-up : IRQ is even raised if m_buffer_empty or m_buffer_low are 0 */ |
| 1542 | | m_SPEN = m_DDIS = m_TALK = m_TALKD = m_previous_TALK_STATUS = m_irq_pin = m_ready_pin = 0; |
| 1517 | m_speaking_now = m_speak_external = m_talk_status = m_irq_pin = m_ready_pin = 0; |
| 1543 | 1518 | set_interrupt_state(0); |
| 1544 | 1519 | update_ready_state(); |
| 1545 | 1520 | m_buffer_empty = m_buffer_low = 1; |
| r249030 | r249031 | |
| 1550 | 1525 | #ifdef PERFECT_INTERPOLATION_HACK |
| 1551 | 1526 | m_old_frame_energy_idx = m_old_frame_pitch_idx = 0; |
| 1552 | 1527 | memset(m_old_frame_k_idx, 0, sizeof(m_old_frame_k_idx)); |
| 1553 | | m_old_zpar = 0; |
| 1554 | 1528 | #endif |
| 1555 | | m_new_frame_energy_idx = m_current_energy = m_previous_energy = 0; |
| 1556 | | m_new_frame_pitch_idx = m_current_pitch = 0; |
| 1557 | | m_zpar = m_uv_zpar = 0; |
| 1529 | m_new_frame_energy_idx = m_current_energy = m_target_energy = m_previous_energy = 0; |
| 1530 | m_new_frame_pitch_idx = m_current_pitch = m_target_pitch = 0; |
| 1558 | 1531 | memset(m_new_frame_k_idx, 0, sizeof(m_new_frame_k_idx)); |
| 1559 | 1532 | memset(m_current_k, 0, sizeof(m_current_k)); |
| 1533 | memset(m_target_k, 0, sizeof(m_target_k)); |
| 1560 | 1534 | |
| 1561 | 1535 | /* initialize the sample generators */ |
| 1562 | 1536 | m_inhibit = 1; |
| r249030 | r249031 | |
| 1600 | 1574 | /* Write */ |
| 1601 | 1575 | /* bring up to date first */ |
| 1602 | 1576 | #ifdef DEBUG_IO_READY |
| 1603 | | fprintf(stderr,"Serviced write: %02x\n", m_write_latch); |
| 1577 | logerror("Serviced write: %02x\n", m_write_latch); |
| 1604 | 1578 | //fprintf(stderr, "Processed write data: %02X\n", m_write_latch); |
| 1605 | 1579 | #endif |
| 1606 | 1580 | m_stream->update(); |
| r249030 | r249031 | |
| 1636 | 1610 | m_true_timing = 1; |
| 1637 | 1611 | state &= 0x01; |
| 1638 | 1612 | #ifdef DEBUG_RS_WS |
| 1639 | | fprintf(stderr,"/RS written with data: %d\n", state); |
| 1613 | logerror("/RS written with data: %d\n", state); |
| 1640 | 1614 | #endif |
| 1641 | 1615 | new_val = (m_rs_ws & 0x01) | (state<<1); |
| 1642 | 1616 | if (new_val != m_rs_ws) |
| r249030 | r249031 | |
| 1649 | 1623 | #ifdef DEBUG_RS_WS |
| 1650 | 1624 | else |
| 1651 | 1625 | /* illegal */ |
| 1652 | | fprintf(stderr,"tms5220_rs_w: illegal\n"); |
| 1626 | logerror("tms5220_rs_w: illegal\n"); |
| 1653 | 1627 | #endif |
| 1654 | 1628 | return; |
| 1655 | 1629 | } |
| r249030 | r249031 | |
| 1667 | 1641 | { |
| 1668 | 1642 | /* high to low - schedule ready cycle */ |
| 1669 | 1643 | #ifdef DEBUG_RS_WS |
| 1670 | | fprintf(stderr,"Scheduling ready cycle for /RS...\n"); |
| 1644 | logerror("Scheduling ready cycle for /RS...\n"); |
| 1671 | 1645 | #endif |
| 1672 | 1646 | /* upon /RS being activated, /READY goes inactive after 100 nsec from data sheet, through 3 asynchronous gates on patent. This is effectively within one clock, so we immediately set io_ready to 0 and activate the callback. */ |
| 1673 | 1647 | m_io_ready = 0; |
| r249030 | r249031 | |
| 1688 | 1662 | m_true_timing = 1; |
| 1689 | 1663 | state &= 0x01; |
| 1690 | 1664 | #ifdef DEBUG_RS_WS |
| 1691 | | fprintf(stderr,"/WS written with data: %d\n", state); |
| 1665 | logerror("/WS written with data: %d\n", state); |
| 1692 | 1666 | #endif |
| 1693 | 1667 | new_val = (m_rs_ws & 0x02) | (state<<0); |
| 1694 | 1668 | if (new_val != m_rs_ws) |
| r249030 | r249031 | |
| 1701 | 1675 | #ifdef DEBUG_RS_WS |
| 1702 | 1676 | else |
| 1703 | 1677 | /* illegal */ |
| 1704 | | fprintf(stderr,"tms5220_ws_w: illegal\n"); |
| 1678 | logerror("tms5220_ws_w: illegal\n"); |
| 1705 | 1679 | #endif |
| 1706 | 1680 | return; |
| 1707 | 1681 | } |
| r249030 | r249031 | |
| 1719 | 1693 | { |
| 1720 | 1694 | /* high to low - schedule ready cycle */ |
| 1721 | 1695 | #ifdef DEBUG_RS_WS |
| 1722 | | fprintf(stderr,"Scheduling ready cycle for /WS...\n"); |
| 1696 | logerror("Scheduling ready cycle for /WS...\n"); |
| 1723 | 1697 | #endif |
| 1724 | 1698 | /* upon /WS being activated, /READY goes inactive after 100 nsec from data sheet, through 3 asynchronous gates on patent. This is effectively within one clock, so we immediately set io_ready to 0 and activate the callback. */ |
| 1725 | 1699 | m_io_ready = 0; |
| r249030 | r249031 | |
| 1752 | 1726 | if (space.debugger_access()) return; |
| 1753 | 1727 | |
| 1754 | 1728 | #ifdef DEBUG_RS_WS |
| 1755 | | fprintf(stderr,"tms5220_data_w: data %02x\n", data); |
| 1729 | logerror("tms5220_data_w: data %02x\n", data); |
| 1756 | 1730 | #endif |
| 1757 | 1731 | if (!m_true_timing) |
| 1758 | 1732 | { |
| r249030 | r249031 | |
| 1765 | 1739 | /* actually in a write ? */ |
| 1766 | 1740 | #ifdef DEBUG_RS_WS |
| 1767 | 1741 | if (!(m_rs_ws == 0x02)) |
| 1768 | | fprintf(stderr,"tms5220_data_w: data written outside ws, status: %02x!\n", m_rs_ws); |
| 1742 | logerror("tms5220_data_w: data written outside ws, status: %02x!\n", m_rs_ws); |
| 1769 | 1743 | #endif |
| 1770 | 1744 | m_write_latch = data; |
| 1771 | 1745 | } |
| r249030 | r249031 | |
| 1797 | 1771 | return m_read_latch; |
| 1798 | 1772 | #ifdef DEBUG_RS_WS |
| 1799 | 1773 | else |
| 1800 | | fprintf(stderr,"tms5220_status_r: data read outside rs!\n"); |
| 1774 | logerror("tms5220_status_r: data read outside rs!\n"); |
| 1801 | 1775 | #endif |
| 1802 | 1776 | return 0xff; |
| 1803 | 1777 | } |
trunk/src/mame/video/chihiro.c
| r249030 | r249031 | |
| 3 | 3 | #include "emu.h" |
| 4 | 4 | #include "video/poly.h" |
| 5 | 5 | #include "bitmap.h" |
| 6 | | #include "machine/pic8259.h" |
| 7 | 6 | #include "includes/chihiro.h" |
| 8 | 7 | |
| 9 | 8 | //#define LOG_NV2A |
| r249030 | r249031 | |
| 946 | 945 | UINT32 nv2a_renderer::geforce_object_offset(UINT32 handle) |
| 947 | 946 | { |
| 948 | 947 | UINT32 h = ((((handle >> 11) ^ handle) >> 11) ^ handle) & 0x7ff; |
| 949 | | UINT32 o = (pfifo[0x210 / 4] & 0x1ff) << 8; // 0x1ff is not certain |
| 948 | UINT32 o = (pfifo[0x210 / 4] & 0x1f) << 8; // or 12 ? |
| 950 | 949 | UINT32 e = o + h * 8; // at 0xfd000000+0x00700000 |
| 951 | 950 | UINT32 w; |
| 952 | 951 | |
| 953 | | if (ramin[e / 4] != handle) { |
| 954 | | // this should never happen |
| 955 | | for (UINT32 aa = o / 4; aa < (sizeof(ramin) / 4); aa = aa + 2) { |
| 956 | | if (ramin[aa] == handle) { |
| 957 | | e = aa * 4; |
| 958 | | } |
| 959 | | } |
| 960 | | } |
| 952 | if (ramin[e / 4] != handle) |
| 953 | e = 0; |
| 961 | 954 | w = ramin[e / 4 + 1]; |
| 962 | | return (w & 0xffff) * 0x10; // 0xffff is not certain |
| 955 | return (w & 0xffff) * 0x10; |
| 963 | 956 | } |
| 964 | 957 | |
| 965 | 958 | void nv2a_renderer::geforce_read_dma_object(UINT32 handle, UINT32 &offset, UINT32 &size) |
| r249030 | r249031 | |
| 1253 | 1246 | addr = rendertarget + (dilated0[dilate_rendertarget][x] + dilated1[dilate_rendertarget][y]); |
| 1254 | 1247 | else // type_rendertarget == LINEAR*/ |
| 1255 | 1248 | addr = rendertarget + (pitch_rendertarget / 4)*y + x; |
| 1256 | | fbcolor = 0; |
| 1257 | | if (color_mask != 0) |
| 1258 | | fbcolor = *addr; |
| 1249 | fbcolor = *addr; |
| 1259 | 1250 | daddr=depthbuffer + (pitch_depthbuffer / 4)*y + x; |
| 1260 | 1251 | deptsten = *daddr; |
| 1261 | 1252 | c[3] = color >> 24; |
| r249030 | r249031 | |
| 1781 | 1772 | break; |
| 1782 | 1773 | } |
| 1783 | 1774 | } |
| 1784 | | if (color_mask != 0) { |
| 1785 | | UINT32 fbcolor_tmp; |
| 1786 | | |
| 1787 | | fbcolor_tmp = (c[3] << 24) | (c[2] << 16) | (c[1] << 8) | c[0]; |
| 1788 | | *addr = (fbcolor & ~color_mask) | (fbcolor_tmp & color_mask); |
| 1789 | | } |
| 1775 | fbcolor = (c[3] << 24) | (c[2] << 16) | (c[1] << 8) | c[0]; |
| 1776 | *addr = fbcolor; |
| 1790 | 1777 | if (depth_write_enabled) |
| 1791 | 1778 | dep = depth; |
| 1792 | 1779 | deptsten = (dep << 8) | sten; |
| r249030 | r249031 | |
| 2246 | 2233 | maddress = method * 4; |
| 2247 | 2234 | data = space.read_dword(address); |
| 2248 | 2235 | channel[chanel][subchannel].object.method[method] = data; |
| 2249 | | #ifdef LOG_NV2A |
| 2250 | | printf("A:%08X MTHD:%08X D:%08X\n\r",address,maddress,data); |
| 2251 | | #endif |
| 2252 | 2236 | if (maddress == 0x17fc) { |
| 2253 | 2237 | indexesleft_count = 0; |
| 2254 | 2238 | indexesleft_first = 0; |
| r249030 | r249031 | |
| 2286 | 2270 | } |
| 2287 | 2271 | wait(); |
| 2288 | 2272 | } |
| 2289 | | else if (type == nv2a_renderer::TRIANGLE_FAN) { |
| 2290 | | vertex_nv vert[3]; |
| 2291 | | vertex_t xy[3]; |
| 2292 | | |
| 2293 | | read_vertices_0x1810(space, vert, offset, 2); |
| 2294 | | convert_vertices_poly(vert, xy, 2); |
| 2295 | | count = count - 2; |
| 2296 | | offset = offset + 2; |
| 2297 | | for (n = 0; n <= count; n++) { |
| 2298 | | read_vertices_0x1810(space, vert + (((n + 1) & 1) + 1), offset + n, 1); |
| 2299 | | convert_vertices_poly(vert + (((n + 1) & 1) + 1), xy + (((n + 1) & 1) + 1), 1); |
| 2300 | | render_triangle(limits_rendertarget, renderspans, 4 + 4 * 2, xy[0], xy[(~(n + 1) & 1) + 1], xy[((n + 1) & 1) + 1]); |
| 2301 | | } |
| 2302 | | wait(); |
| 2303 | | } |
| 2304 | 2273 | else if (type == nv2a_renderer::TRIANGLE_STRIP) { |
| 2305 | 2274 | vertex_nv vert[4]; |
| 2306 | 2275 | vertex_t xy[4]; |
| r249030 | r249031 | |
| 2342 | 2311 | // each dword after 1800 contains two 16 bit index values to select the vartices |
| 2343 | 2312 | // each dword after 1808 contains a 32 bit index value to select the vartices |
| 2344 | 2313 | type = channel[chanel][subchannel].object.method[0x17fc / 4]; |
| 2314 | #ifdef LOG_NV2A |
| 2315 | printf("vertex %d %d %d\n\r", type, offset, count); |
| 2316 | #endif |
| 2345 | 2317 | if (type == nv2a_renderer::QUADS) { |
| 2346 | 2318 | while (1) { |
| 2347 | 2319 | vertex_nv vert[4]; |
| r249030 | r249031 | |
| 2360 | 2332 | render_polygon<4>(limits_rendertarget, renderspans, 4 + 4 * 2, xy); // 4 rgba, 4 texture units 2 uv |
| 2361 | 2333 | } |
| 2362 | 2334 | } |
| 2363 | | else if (type == nv2a_renderer::TRIANGLE_FAN) { |
| 2364 | | if ((countlen * mult + indexesleft_count) >= 3) { |
| 2365 | | vertex_nv vert[3]; |
| 2366 | | vertex_t xy[3]; |
| 2367 | | int c, count; |
| 2368 | | |
| 2369 | | if (mult == 1) |
| 2370 | | c = read_vertices_0x1808(space, vert, address, 2); |
| 2371 | | else |
| 2372 | | c = read_vertices_0x1800(space, vert, address, 2); |
| 2373 | | convert_vertices_poly(vert, xy, 2); |
| 2374 | | address = address + c * 4; |
| 2375 | | countlen = countlen - c; |
| 2376 | | count = countlen * mult + indexesleft_count; |
| 2377 | | for (n = 1; n <= count; n++) { |
| 2378 | | if (mult == 1) |
| 2379 | | c = read_vertices_0x1808(space, vert + ((n & 1) + 1), address, 1); |
| 2380 | | else |
| 2381 | | c = read_vertices_0x1800(space, vert + ((n & 1) + 1), address, 1); |
| 2382 | | |
| 2383 | | convert_vertices_poly(vert + ((n & 1) + 1), xy + ((n & 1) + 1), 1); |
| 2384 | | address = address + c * 4; |
| 2385 | | countlen = countlen - c; |
| 2386 | | render_triangle(limits_rendertarget, renderspans, 4 + 4 * 2, xy[0], xy[(~n & 1) + 1], xy[(n & 1) + 1]); |
| 2387 | | } |
| 2388 | | wait(); |
| 2389 | | } |
| 2390 | | } |
| 2391 | 2335 | else if (type == nv2a_renderer::TRIANGLES) { |
| 2392 | 2336 | while (1) { |
| 2393 | 2337 | vertex_nv vert[3]; |
| r249030 | r249031 | |
| 2502 | 2446 | } |
| 2503 | 2447 | wait(); |
| 2504 | 2448 | } |
| 2505 | | else if (type == nv2a_renderer::TRIANGLES) { |
| 2506 | | while (countlen > 0) { |
| 2507 | | vertex_nv vert[3]; |
| 2508 | | vertex_t xy[3]; |
| 2509 | | int c; |
| 2510 | | |
| 2511 | | c = read_vertices_0x1818(space, vert, address, 3); |
| 2512 | | convert_vertices_poly(vert, xy, 3); |
| 2513 | | countlen = countlen - c; |
| 2514 | | if (countlen < 0) { |
| 2515 | | logerror("Method 0x1818 missing %d words to draw a complete primitive\n", -countlen); |
| 2516 | | countlen = 0; |
| 2517 | | break; |
| 2518 | | } |
| 2519 | | address = address + c * 3; |
| 2520 | | render_triangle(limits_rendertarget, renderspans, 4 + 4 * 2, xy[0], xy[1], xy[2]); // 4 rgba, 4 texture units 2 uv |
| 2521 | | } |
| 2522 | | } |
| 2523 | 2449 | else if (type == nv2a_renderer::TRIANGLE_STRIP) { |
| 2524 | 2450 | vertex_nv vert[4]; |
| 2525 | 2451 | vertex_t xy[4]; |
| r249030 | r249031 | |
| 2687 | 2613 | // clear colors |
| 2688 | 2614 | UINT32 color = channel[chanel][subchannel].object.method[0x1d90 / 4]; |
| 2689 | 2615 | bm.fill(color); |
| 2690 | | #ifdef LOG_NV2A |
| 2691 | | printf("clearscreen\n\r"); |
| 2692 | | #endif |
| 2616 | //printf("clearscreen\n\r"); |
| 2693 | 2617 | } |
| 2694 | 2618 | if ((data & 0x03) == 3) { |
| 2695 | 2619 | bitmap_rgb32 bm(depthbuffer, (limits_rendertarget.right() + 1) * m, (limits_rendertarget.bottom() + 1) * m, pitch_rendertarget / 4); // why *2 ? |
| r249030 | r249031 | |
| 2725 | 2649 | dilate_rendertarget = dilatechose[(log2width_rendertarget << 4) + log2height_rendertarget]; |
| 2726 | 2650 | } |
| 2727 | 2651 | if (maddress == 0x020c) { |
| 2652 | // line size ? |
| 2728 | 2653 | pitch_rendertarget=data & 0xffff; |
| 2729 | 2654 | pitch_depthbuffer=(data >> 16) & 0xffff; |
| 2730 | | #ifdef LOG_NV2A |
| 2731 | | printf("Pitch color %04X zbuffer %04X\n\r",pitch_rendertarget,pitch_depthbuffer); |
| 2732 | | #endif |
| 2655 | //printf("Pitch color %04X zbuffer %04X\n\r",pitch_rendertarget,pitch_depthbuffer); |
| 2733 | 2656 | countlen--; |
| 2734 | 2657 | } |
| 2735 | 2658 | if (maddress == 0x0100) { |
| 2736 | | countlen--; |
| 2737 | | if (data != 0) { |
| 2738 | | pgraph[0x704 / 4] = 0x100; |
| 2739 | | pgraph[0x708 / 4] = data; |
| 2740 | | pgraph[0x100 / 4] |= 1; |
| 2741 | | pgraph[0x108 / 4] |= 1; |
| 2742 | | if (update_interrupts() == true) |
| 2743 | | interruptdevice->ir3_w(1); // IRQ 3 |
| 2744 | | else |
| 2745 | | interruptdevice->ir3_w(0); // IRQ 3 |
| 2746 | | return 2; |
| 2659 | // just temporarily |
| 2660 | if ((data & 0x1f) == 1) { |
| 2661 | data = data >> 5; |
| 2662 | data = data & 0x0ffffff0; |
| 2663 | displayedtarget = (UINT32 *)direct_access_ptr(data); |
| 2747 | 2664 | } |
| 2748 | | else |
| 2749 | | return 0; |
| 2750 | 2665 | } |
| 2751 | 2666 | if (maddress == 0x0130) { |
| 2752 | 2667 | countlen--; |
| r249030 | r249031 | |
| 2755 | 2670 | else |
| 2756 | 2671 | return 0; |
| 2757 | 2672 | } |
| 2758 | | if (maddress == 0x1d8c) { |
| 2759 | | countlen--; |
| 2760 | | // it is used to specify the clear value for the depth buffer (zbuffer) |
| 2761 | | // but also as a parameter for interrupt routines |
| 2762 | | pgraph[0x1a88 / 4] = data; |
| 2763 | | } |
| 2764 | | if (maddress == 0x1d90) { |
| 2765 | | countlen--; |
| 2766 | | // it is used to specify the clear value for the color buffer |
| 2767 | | // but also as a parameter for interrupt routines |
| 2768 | | pgraph[0x186c / 4] = data; |
| 2769 | | } |
| 2770 | 2673 | if (maddress == 0x0210) { |
| 2771 | 2674 | // framebuffer offset ? |
| 2772 | 2675 | rendertarget = (UINT32 *)direct_access_ptr(data); |
| 2773 | | #ifdef LOG_NV2A |
| 2774 | | printf("Render target at %08X\n\r", data); |
| 2775 | | #endif |
| 2676 | //printf("Render target at %08X\n\r",data); |
| 2776 | 2677 | countlen--; |
| 2777 | 2678 | } |
| 2778 | 2679 | if (maddress == 0x0214) { |
| 2779 | 2680 | // zbuffer offset ? |
| 2780 | 2681 | depthbuffer = (UINT32 *)direct_access_ptr(data); |
| 2781 | | #ifdef LOG_NV2A |
| 2782 | | printf("Depth buffer at %08X\n\r",data); |
| 2783 | | #endif |
| 2682 | //printf("Depth buffer at %08X\n\r",data); |
| 2784 | 2683 | if ((data == 0) || (data > 0x7ffffffc)) |
| 2785 | 2684 | depth_write_enabled = false; |
| 2786 | 2685 | else if (channel[chanel][subchannel].object.method[0x035c / 4] != 0) |
| r249030 | r249031 | |
| 2810 | 2709 | if (maddress == 0x0354) { |
| 2811 | 2710 | depth_function = data; |
| 2812 | 2711 | } |
| 2813 | | if (maddress == 0x0358) { |
| 2814 | | //color_mask = data; |
| 2815 | | if (data & 0x000000ff) |
| 2816 | | data |= 0x000000ff; |
| 2817 | | if (data & 0x0000ff00) |
| 2818 | | data |= 0x0000ff00; |
| 2819 | | if (data & 0x00ff0000) |
| 2820 | | data |= 0x00ff0000; |
| 2821 | | if (data & 0xff000000) |
| 2822 | | data |= 0xff000000; |
| 2823 | | color_mask = data; |
| 2824 | | } |
| 2825 | 2712 | if (maddress == 0x035c) { |
| 2826 | 2713 | UINT32 g = channel[chanel][subchannel].object.method[0x0214 / 4]; |
| 2827 | 2714 | depth_write_enabled = data != 0; |
| r249030 | r249031 | |
| 3761 | 3648 | combiner.function_Aop3 = MAX(MIN((combiner.function_Aop3 + biasa) * scalea, 1.0f), -1.0f); |
| 3762 | 3649 | } |
| 3763 | 3650 | |
| 3764 | | void nv2a_renderer::vblank_callback(screen_device &screen, bool state) |
| 3651 | bool nv2a_renderer::vblank_callback(screen_device &screen, bool state) |
| 3765 | 3652 | { |
| 3766 | | #ifdef LOG_NV2A |
| 3767 | | printf("vblank_callback\n\r"); |
| 3768 | | #endif |
| 3769 | | if ((state == true) && (puller_waiting == 1)) { |
| 3770 | | puller_waiting = 0; |
| 3771 | | puller_timer_work(NULL, 0); |
| 3772 | | } |
| 3773 | | if (state == true) { |
| 3653 | //printf("vblank_callback\n\r"); |
| 3654 | if (state == true) |
| 3774 | 3655 | pcrtc[0x100 / 4] |= 1; |
| 3775 | | pcrtc[0x808 / 4] |= 0x10000; |
| 3776 | | } |
| 3777 | | else { |
| 3778 | | pcrtc[0x100 / 4] &= ~1; |
| 3779 | | pcrtc[0x808 / 4] &= ~0x10000; |
| 3780 | | } |
| 3781 | | if (update_interrupts() == true) |
| 3782 | | interruptdevice->ir3_w(1); // IRQ 3 |
| 3783 | 3656 | else |
| 3784 | | interruptdevice->ir3_w(0); // IRQ 3 |
| 3785 | | } |
| 3786 | | |
| 3787 | | bool nv2a_renderer::update_interrupts() |
| 3788 | | { |
| 3657 | pcrtc[0x100 / 4] &= ~1; |
| 3789 | 3658 | if (pcrtc[0x100 / 4] & pcrtc[0x140 / 4]) |
| 3790 | 3659 | pmc[0x100 / 4] |= 0x1000000; |
| 3791 | 3660 | else |
| 3792 | 3661 | pmc[0x100 / 4] &= ~0x1000000; |
| 3793 | | if (pgraph[0x100 / 4] & pgraph[0x140 / 4]) |
| 3794 | | pmc[0x100 / 4] |= 0x1000; |
| 3795 | | else |
| 3796 | | pmc[0x100 / 4] &= ~0x1000; |
| 3797 | | if (((pmc[0x100 / 4] & 0x7fffffff) && (pmc[0x140 / 4] & 1)) || ((pmc[0x100 / 4] & 0x80000000) && (pmc[0x140 / 4] & 2))) { |
| 3662 | if ((state == true) && (puller_waiting == 1)) { |
| 3663 | puller_waiting = 0; |
| 3664 | puller_timer_work(NULL, 0); |
| 3665 | } |
| 3666 | if ((pmc[0x100 / 4] != 0) && (pmc[0x140 / 4] != 0)) { |
| 3798 | 3667 | // send interrupt |
| 3799 | 3668 | return true; |
| 3800 | 3669 | } |
| r249030 | r249031 | |
| 3823 | 3692 | int countlen; |
| 3824 | 3693 | int ret; |
| 3825 | 3694 | address_space *space = puller_space; |
| 3826 | | #ifdef LOG_NV2A |
| 3827 | | UINT32 subch; |
| 3828 | | #endif |
| 3829 | 3695 | |
| 3830 | 3696 | chanel = puller_channel; |
| 3831 | 3697 | subchannel = puller_subchannel; |
| r249030 | r249031 | |
| 3882 | 3748 | } |
| 3883 | 3749 | if (ret != 0) { |
| 3884 | 3750 | puller_timer->enable(false); |
| 3885 | | puller_waiting = ret; |
| 3751 | puller_waiting = 1; |
| 3886 | 3752 | return; |
| 3887 | 3753 | } |
| 3888 | 3754 | } |
| r249030 | r249031 | |
| 3981 | 3847 | //logerror("NV_2A: read PRAMIN[%06X] value %08X\n",offset*4-0x00700000,ret); |
| 3982 | 3848 | } |
| 3983 | 3849 | else if ((offset >= 0x00400000 / 4) && (offset < 0x00402000 / 4)) { |
| 3984 | | ret = pgraph[offset - 0x00400000 / 4]; |
| 3985 | 3850 | //logerror("NV_2A: read PGRAPH[%06X] value %08X\n",offset*4-0x00400000,ret); |
| 3986 | 3851 | } |
| 3987 | 3852 | else if ((offset >= 0x00600000 / 4) && (offset < 0x00601000 / 4)) { |
| r249030 | r249031 | |
| 4005 | 3870 | //logerror("NV_2A: read channel[%02X,%d,%04X]=%08X\n",chanel,subchannel,suboffset*4,ret); |
| 4006 | 3871 | return ret; |
| 4007 | 3872 | } |
| 3873 | else |
| 3874 | { |
| 3875 | /* nothing */ |
| 3876 | } |
| 4008 | 3877 | //logerror("NV_2A: read at %08X mask %08X value %08X\n",0xfd000000+offset*4,mem_mask,ret); |
| 4009 | 3878 | return ret; |
| 4010 | 3879 | } |
| 4011 | 3880 | |
| 4012 | 3881 | WRITE32_MEMBER(nv2a_renderer::geforce_w) |
| 4013 | 3882 | { |
| 4014 | | UINT32 old; |
| 4015 | | bool update_int; |
| 4016 | | |
| 4017 | | update_int = false; |
| 4018 | 3883 | if ((offset >= 0x00101000 / 4) && (offset < 0x00102000 / 4)) { |
| 4019 | 3884 | //logerror("NV_2A: write STRAPS[%06X] mask %08X value %08X\n",offset*4-0x00101000,mem_mask,data); |
| 4020 | 3885 | } |
| r249030 | r249031 | |
| 4033 | 3898 | //logerror("NV_2A: write PRAMIN[%06X]=%08X\n",offset*4-0x00700000,data & mem_mask); |
| 4034 | 3899 | } |
| 4035 | 3900 | else if ((offset >= 0x00400000 / 4) && (offset < 0x00402000 / 4)) { |
| 4036 | | int e = offset - 0x00400000 / 4; |
| 4037 | | if (e >= (sizeof(pgraph) / sizeof(UINT32))) |
| 4038 | | return; |
| 4039 | | old = pgraph[e]; |
| 4040 | | COMBINE_DATA(pgraph + e); |
| 4041 | | if (e == 0x100 / 4) { |
| 4042 | | pgraph[e] = old & ~data; |
| 4043 | | if (data & 1) |
| 4044 | | pgraph[0x108 / 4] = 0; |
| 4045 | | update_int = true; |
| 4046 | | } |
| 4047 | | if (e == 0x140 / 4) |
| 4048 | | update_int = true; |
| 4049 | | if (e == 0x720 / 4) { |
| 4050 | | if ((data & 1) && (puller_waiting == 2)) { |
| 4051 | | puller_waiting = 0; |
| 4052 | | puller_timer->enable(); |
| 4053 | | puller_timer->adjust(attotime::zero); |
| 4054 | | } |
| 4055 | | } |
| 4056 | | if ((e >= 0x900 / 4) && (e < 0xa00 / 4)) |
| 4057 | | pgraph[e] = 0; |
| 4058 | 3901 | //logerror("NV_2A: write PGRAPH[%06X]=%08X\n",offset*4-0x00400000,data & mem_mask); |
| 4059 | 3902 | } |
| 4060 | 3903 | else if ((offset >= 0x00600000 / 4) && (offset < 0x00601000 / 4)) { |
| 4061 | 3904 | int e = offset - 0x00600000 / 4; |
| 4062 | 3905 | if (e >= (sizeof(pcrtc) / sizeof(UINT32))) |
| 4063 | 3906 | return; |
| 4064 | | old = pcrtc[e]; |
| 4065 | 3907 | COMBINE_DATA(pcrtc + e); |
| 4066 | | if (e == 0x100 / 4) { |
| 4067 | | pcrtc[e] = old & ~data; |
| 4068 | | update_int = true; |
| 4069 | | } |
| 4070 | | if (e == 0x140 / 4) |
| 4071 | | update_int = true; |
| 4072 | 3908 | if (e == 0x800 / 4) { |
| 4073 | | displayedtarget = (UINT32 *)direct_access_ptr(pcrtc[e]); |
| 4074 | | #ifdef LOG_NV2A |
| 4075 | | printf("crtc buffer %08X\n\r", data); |
| 4076 | | #endif |
| 3909 | displayedtarget = (UINT32 *)direct_access_ptr(data); |
| 3910 | //printf("crtc buffer %08X\n\r", data); |
| 4077 | 3911 | } |
| 4078 | 3912 | //logerror("NV_2A: write PCRTC[%06X]=%08X\n",offset*4-0x00600000,data & mem_mask); |
| 4079 | 3913 | } |
| r249030 | r249031 | |
| 4088 | 3922 | // 32 channels size 0x10000 each, 8 subchannels per channel size 0x2000 each |
| 4089 | 3923 | int chanel, subchannel, suboffset; |
| 4090 | 3924 | //int method, count, handle, objclass; |
| 3925 | #ifdef LOG_NV2A |
| 3926 | int subch; |
| 3927 | #endif |
| 4091 | 3928 | |
| 4092 | 3929 | suboffset = offset - 0x00800000 / 4; |
| 4093 | 3930 | chanel = (suboffset >> (16 - 2)) & 31; |
| r249030 | r249031 | |
| 4122 | 3959 | } |
| 4123 | 3960 | //else |
| 4124 | 3961 | // logerror("NV_2A: write at %08X mask %08X value %08X\n",0xfd000000+offset*4,mem_mask,data); |
| 4125 | | if (update_int == true) { |
| 4126 | | if (update_interrupts() == true) |
| 4127 | | interruptdevice->ir3_w(1); // IRQ 3 |
| 4128 | | else |
| 4129 | | interruptdevice->ir3_w(0); // IRQ 3 |
| 4130 | | } |
| 4131 | 3962 | } |
| 4132 | 3963 | |
| 4133 | 3964 | void nv2a_renderer::savestate_items() |
| r249030 | r249031 | |
| 4140 | 3971 | puller_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(nv2a_renderer::puller_timer_work), this), (void *)"NV2A Puller Timer"); |
| 4141 | 3972 | puller_timer->enable(false); |
| 4142 | 3973 | } |
| 4143 | | |
| 4144 | | void nv2a_renderer::set_interrupt_device(pic8259_device *device) |
| 4145 | | { |
| 4146 | | interruptdevice = device; |
| 4147 | | } |