trunk/src/emu/sound/tms5110.c
| r249043 | r249044 | |
| 14 | 14 | |
| 15 | 15 | Todo: |
| 16 | 16 | - implement CS |
| 17 | | - implement missing commands |
| 18 | 17 | - TMS5110_CMD_TEST_TALK is only partially implemented |
| 19 | 18 | |
| 20 | 19 | TMS5100: |
| r249043 | r249044 | |
| 212 | 211 | { |
| 213 | 212 | save_item(NAME(m_variant)); |
| 214 | 213 | |
| 215 | | save_item(NAME(m_fifo)); |
| 216 | | save_item(NAME(m_fifo_head)); |
| 217 | | save_item(NAME(m_fifo_tail)); |
| 218 | | save_item(NAME(m_fifo_count)); |
| 219 | | |
| 220 | 214 | save_item(NAME(m_PDC)); |
| 221 | 215 | save_item(NAME(m_CTL_pins)); |
| 222 | 216 | save_item(NAME(m_SPEN)); |
| r249043 | r249044 | |
| 241 | 235 | save_item(NAME(m_old_frame_pitch_idx)); |
| 242 | 236 | save_item(NAME(m_old_frame_k_idx)); |
| 243 | 237 | save_item(NAME(m_old_zpar)); |
| 238 | save_item(NAME(m_old_uv_zpar)); |
| 244 | 239 | #endif |
| 245 | 240 | save_item(NAME(m_current_energy)); |
| 246 | 241 | save_item(NAME(m_current_pitch)); |
| r249043 | r249044 | |
| 310 | 305 | } |
| 311 | 306 | #endif |
| 312 | 307 | |
| 313 | | |
| 314 | 308 | /****************************************************************************************** |
| 315 | 309 | |
| 316 | | FIFO_data_write -- handle bit data write to the TMS5110 (as a result of toggling M0 pin) |
| 310 | extract_bits -- extract a specific number of bits from the VSM |
| 317 | 311 | |
| 318 | 312 | ******************************************************************************************/ |
| 319 | | void tms5110_device::FIFO_data_write(int data) |
| 320 | | { |
| 321 | | /* add this bit to the FIFO */ |
| 322 | | if (m_fifo_count < FIFO_SIZE) |
| 323 | | { |
| 324 | | m_fifo[m_fifo_tail] = (data&1); /* set bit to 1 or 0 */ |
| 325 | 313 | |
| 326 | | m_fifo_tail = (m_fifo_tail + 1) % FIFO_SIZE; |
| 327 | | m_fifo_count++; |
| 328 | | |
| 329 | | if (DEBUG_5110) logerror("Added bit to FIFO (size=%2d)\n", m_fifo_count); |
| 330 | | } |
| 331 | | else |
| 332 | | { |
| 333 | | if (DEBUG_5110) logerror("Ran out of room in the FIFO!\n"); |
| 334 | | } |
| 335 | | } |
| 336 | | |
| 337 | | /****************************************************************************************** |
| 338 | | |
| 339 | | extract_bits -- extract a specific number of bits from the FIFO |
| 340 | | |
| 341 | | ******************************************************************************************/ |
| 342 | | |
| 343 | 314 | int tms5110_device::extract_bits(int count) |
| 344 | 315 | { |
| 345 | 316 | int val = 0; |
| 346 | | if (DEBUG_5110) logerror("requesting %d bits from fifo: ", count); |
| 347 | | while (count--) |
| 317 | if (DEBUG_5110) logerror("requesting %d bits", count); |
| 318 | for (int i = 0; i < count; i++) |
| 348 | 319 | { |
| 349 | | val = (val << 1) | (m_fifo[m_fifo_head] & 1); |
| 350 | | m_fifo_count--; |
| 351 | | m_fifo_head = (m_fifo_head + 1) % FIFO_SIZE; |
| 320 | val = (val<<1) | new_int_read(); |
| 321 | if (DEBUG_5110) logerror("bit read: %d\n", val&1); |
| 352 | 322 | } |
| 353 | 323 | if (DEBUG_5110) logerror("returning: %02x\n", val); |
| 354 | 324 | return val; |
| 355 | 325 | } |
| 356 | 326 | |
| 357 | | void tms5110_device::request_bits(int no) |
| 358 | | { |
| 359 | | for (int i = 0; i < no; i++) |
| 360 | | { |
| 361 | | UINT8 data = new_int_read(); |
| 362 | | if (DEBUG_5110) logerror("bit added to fifo: %d\n", data); |
| 363 | | FIFO_data_write(data); |
| 364 | | } |
| 365 | | } |
| 366 | 327 | |
| 367 | 328 | void tms5110_device::perform_dummy_read() |
| 368 | 329 | { |
| r249043 | r249044 | |
| 389 | 350 | int i, bitout; |
| 390 | 351 | INT32 this_sample; |
| 391 | 352 | |
| 392 | | /* if we're not speaking, fill with nothingness */ |
| 393 | | if (!m_TALKD) |
| 394 | | goto empty; |
| 395 | | |
| 396 | 353 | /* loop until the buffer is full or we've stopped speaking */ |
| 397 | | while ((size > 0) && m_TALKD) |
| 354 | while (size > 0) |
| 398 | 355 | { |
| 399 | | /* if it is the appropriate time to update the old energy/pitch indices, |
| 400 | | * i.e. when IP=7, PC=12, T=17, subcycle=2, do so. Since IP=7 PC=12 T=17 |
| 401 | | * is JUST BEFORE the transition to IP=0 PC=0 T=0 sybcycle=(0 or 1), |
| 402 | | * which happens 4 T-cycles later), we change on the latter. |
| 403 | | * The indices are updated here ~12 PCs before the new frame is applied. |
| 404 | | */ |
| 405 | | /** TODO: the patents 4331836, 4335277, and 4419540 disagree about the timing of this **/ |
| 406 | | if ((m_IP == 0) && (m_PC == 0) && (m_subcycle < 2)) |
| 356 | if(m_TALKD) // speaking |
| 407 | 357 | { |
| 408 | | m_OLDE = (m_new_frame_energy_idx == 0); |
| 409 | | m_OLDP = (m_new_frame_pitch_idx == 0); |
| 410 | | } |
| 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 |
| 411 | 367 | |
| 412 | | /* if we're ready for a new frame to be applied, i.e. when IP=0, PC=12, Sub=1 |
| 413 | | * (In reality, the frame was really loaded incrementally during the entire IP=0 |
| 414 | | * PC=x time period, but it doesn't affect anything until IP=0 PC=12 happens) |
| 415 | | */ |
| 416 | | if ((m_IP == 0) && (m_PC == 12) && (m_subcycle == 1)) |
| 417 | | { |
| 418 | | // HACK for regression testing, be sure to comment out before release! |
| 419 | | //m_RNG = 0x1234; |
| 420 | | // end HACK |
| 421 | | |
| 422 | 368 | #ifdef PERFECT_INTERPOLATION_HACK |
| 423 | | /* remember previous frame energy, pitch, and coefficients */ |
| 424 | | m_old_frame_energy_idx = m_new_frame_energy_idx; |
| 425 | | m_old_frame_pitch_idx = m_new_frame_pitch_idx; |
| 426 | | for (i = 0; i < m_coeff->num_k; i++) |
| 427 | | m_old_frame_k_idx[i] = m_new_frame_k_idx[i]; |
| 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]; |
| 428 | 374 | #endif |
| 429 | 375 | |
| 430 | | /* Parse a new frame into the new_target_energy, new_target_pitch and new_target_k[] */ |
| 431 | | parse_frame(); |
| 432 | | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 433 | | fprintf(stderr,"\n"); |
| 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 |
| 434 | 388 | #endif |
| 435 | | /* if the new frame is unvoiced (or silenced via ZPAR), be sure to zero out the k5-k10 parameters */ |
| 436 | | m_uv_zpar = NEW_FRAME_UNVOICED_FLAG | m_zpar; |
| 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 |
| 437 | 392 | |
| 438 | | /* if the new frame is a stop frame, unset both TALK and SPEN. TALKD remains active while the energy is ramping to 0. */ |
| 439 | | if (NEW_FRAME_STOP_FLAG == 1) |
| 440 | | { |
| 441 | | m_TALK = m_SPEN = 0; |
| 442 | | } |
| 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 | } |
| 443 | 398 | |
| 444 | | /* in all cases where interpolation would be inhibited, set the inhibit flag; otherwise clear it. |
| 445 | | Interpolation inhibit cases: |
| 446 | | * Old frame was voiced, new is unvoiced |
| 447 | | * Old frame was silence/zero energy, new has nonzero energy |
| 448 | | * 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) |
| 449 | | */ |
| 450 | | if ( ((OLD_FRAME_UNVOICED_FLAG == 0) && (NEW_FRAME_UNVOICED_FLAG == 1)) |
| 451 | | || ((OLD_FRAME_UNVOICED_FLAG == 1) && (NEW_FRAME_UNVOICED_FLAG == 0)) /* this line needs further investigation, starwars tie fighters may sound better without it */ |
| 452 | | || ((OLD_FRAME_SILENCE_FLAG == 1) && (NEW_FRAME_SILENCE_FLAG == 0)) ) |
| 453 | | m_inhibit = 1; |
| 454 | | else // normal frame, normal interpolation |
| 455 | | m_inhibit = 0; |
| 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; |
| 456 | 411 | |
| 457 | 412 | #ifdef DEBUG_GENERATION |
| 458 | | /* Debug info for current parsed frame */ |
| 459 | | fprintf(stderr, "OLDE: %d; OLDP: %d; ", m_OLDE, m_OLDP); |
| 460 | | fprintf(stderr,"Processing frame: "); |
| 461 | | if (m_inhibit == 0) |
| 462 | | fprintf(stderr, "Normal Frame\n"); |
| 463 | | else |
| 464 | | fprintf(stderr,"Interpolation Inhibited\n"); |
| 465 | | 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]); |
| 466 | | fprintf(stderr,"*** target Energy(idx), Pitch, and Ks = %04d(%x),%04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d, %04d\n", |
| 467 | | (m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)), |
| 468 | | m_new_frame_energy_idx, |
| 469 | | (m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)), |
| 470 | | (m_coeff->ktable[0][m_new_frame_k_idx[0]] * (1-m_zpar)), |
| 471 | | (m_coeff->ktable[1][m_new_frame_k_idx[1]] * (1-m_zpar)), |
| 472 | | (m_coeff->ktable[2][m_new_frame_k_idx[2]] * (1-m_zpar)), |
| 473 | | (m_coeff->ktable[3][m_new_frame_k_idx[3]] * (1-m_zpar)), |
| 474 | | (m_coeff->ktable[4][m_new_frame_k_idx[4]] * (1-m_uv_zpar)), |
| 475 | | (m_coeff->ktable[5][m_new_frame_k_idx[5]] * (1-m_uv_zpar)), |
| 476 | | (m_coeff->ktable[6][m_new_frame_k_idx[6]] * (1-m_uv_zpar)), |
| 477 | | (m_coeff->ktable[7][m_new_frame_k_idx[7]] * (1-m_uv_zpar)), |
| 478 | | (m_coeff->ktable[8][m_new_frame_k_idx[8]] * (1-m_uv_zpar)), |
| 479 | | (m_coeff->ktable[9][m_new_frame_k_idx[9]] * (1-m_uv_zpar)) ); |
| 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)) ); |
| 480 | 435 | #endif |
| 481 | 436 | |
| 482 | | } |
| 483 | | else // Not a new frame, just interpolate the existing frame. |
| 484 | | { |
| 485 | | 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 |
| 486 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 487 | | 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 |
| 488 | | //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 |
| 489 | | int current_sample = (m_subcycle - m_subc_reload)+(m_PC*(3-m_subc_reload))+((m_subc_reload?25:38)*((m_IP-1)&7)); |
| 490 | | //fprintf(stderr, "CS: %03d", current_sample); |
| 491 | | // reset the current energy, pitch, etc to what it was at frame start |
| 492 | | m_current_energy = (m_coeff->energytable[m_old_frame_energy_idx] * (1-m_zpar)); |
| 493 | | m_current_pitch = (m_coeff->pitchtable[m_old_frame_pitch_idx] * (1-m_old_zpar)); |
| 494 | | for (i = 0; i < 4; i++) |
| 495 | | m_current_k[i] = (m_coeff->ktable[i][m_old_frame_k_idx[i]] * (1-m_old_zpar)); |
| 496 | | for (i = 4; i < m_coeff->num_k; i++) |
| 497 | | m_current_k[i] = (m_coeff->ktable[i][m_old_frame_k_idx[i]] * (1-m_uv_zpar)); |
| 498 | | // now adjust each value to be exactly correct for each of the samples per frame |
| 499 | | if (m_IP != 0) // if we're still interpolating... |
| 500 | | { |
| 501 | | 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; |
| 502 | | 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; |
| 503 | | for (i = 0; i < m_coeff->num_k; i++) |
| 504 | | 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; |
| 505 | 437 | } |
| 506 | | else // we're done, play this frame for 1/8 frame. |
| 438 | else // Not a new frame, just interpolate the existing frame. |
| 507 | 439 | { |
| 508 | | m_current_energy = (m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)); |
| 509 | | m_current_pitch = (m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)); |
| 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)); |
| 510 | 449 | for (i = 0; i < m_coeff->num_k; i++) |
| 511 | | m_current_k[i] = (m_coeff->ktable[i][m_new_frame_k_idx[i]] * (1-((i<4)?m_zpar:m_uv_zpar))); |
| 512 | | } |
| 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 | } |
| 513 | 466 | #else |
| 514 | | //Updates to parameters only happen on subcycle '2' (B cycle) of PCs. |
| 515 | | if (m_subcycle == 2) |
| 516 | | { |
| 517 | | switch(m_PC) |
| 467 | //Updates to parameters only happen on subcycle '2' (B cycle) of PCs. |
| 468 | if (m_subcycle == 2) |
| 518 | 469 | { |
| 519 | | case 0: /* PC = 0, B cycle, write updated energy */ |
| 520 | | m_current_energy += ((((m_coeff->energytable[m_new_frame_energy_idx] * (1-m_zpar)) - m_current_energy)*(1-inhibit_state)) INTERP_SHIFT); |
| 521 | | break; |
| 522 | | case 1: /* PC = 1, B cycle, write updated pitch */ |
| 523 | | m_current_pitch += ((((m_coeff->pitchtable[m_new_frame_pitch_idx] * (1-m_zpar)) - m_current_pitch)*(1-inhibit_state)) INTERP_SHIFT); |
| 524 | | break; |
| 525 | | case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: |
| 526 | | /* PC = 2 through 11, B cycle, write updated K1 through K10 */ |
| 527 | | 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); |
| 528 | | break; |
| 529 | | case 12: /* PC = 12, do nothing */ |
| 530 | | break; |
| 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 | } |
| 531 | 486 | } |
| 532 | | } |
| 533 | 487 | #endif |
| 534 | | } |
| 488 | } |
| 535 | 489 | |
| 536 | | // calculate the output |
| 537 | | if (OLD_FRAME_UNVOICED_FLAG == 1) |
| 538 | | { |
| 539 | | // generate unvoiced samples here |
| 540 | | if (m_RNG & 1) |
| 541 | | 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)*/ |
| 542 | | else |
| 543 | | m_excitation_data = 0x40; |
| 544 | | } |
| 545 | | else /* (OLD_FRAME_UNVOICED_FLAG == 0) */ |
| 546 | | { |
| 547 | | // generate voiced samples here |
| 548 | | /* US patent 4331836 Figure 14B shows, and logic would hold, that a pitch based chirp |
| 549 | | * function has a chirp/peak and then a long chain of zeroes. |
| 550 | | * The last entry of the chirp rom is at address 0b110011 (51d), the 52nd sample, |
| 551 | | * and if the address reaches that point the ADDRESS incrementer is |
| 552 | | * disabled, forcing all samples beyond 51d to be == 51d |
| 553 | | */ |
| 554 | | if (m_pitch_count >= 51) |
| 555 | | m_excitation_data = (INT8)m_coeff->chirptable[51]; |
| 556 | | else /*m_pitch_count < 51*/ |
| 557 | | m_excitation_data = (INT8)m_coeff->chirptable[m_pitch_count]; |
| 558 | | } |
| 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 | } |
| 559 | 513 | |
| 560 | | // Update LFSR *20* times every sample (once per T cycle), like patent shows |
| 561 | | for (i=0; i<20; i++) |
| 562 | | { |
| 563 | | bitout = ((m_RNG >> 12) & 1) ^ |
| 564 | | ((m_RNG >> 3) & 1) ^ |
| 565 | | ((m_RNG >> 2) & 1) ^ |
| 566 | | ((m_RNG >> 0) & 1); |
| 567 | | m_RNG <<= 1; |
| 568 | | m_RNG |= bitout; |
| 569 | | } |
| 570 | | this_sample = lattice_filter(); /* execute lattice filter */ |
| 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 */ |
| 571 | 525 | #ifdef DEBUG_GENERATION_VERBOSE |
| 572 | | //fprintf(stderr,"C:%01d; ",m_subcycle); |
| 573 | | 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); |
| 574 | | //fprintf(stderr,"X:%04d E:%03d P:%03d Pc:%03d ", m_excitation_data, m_current_energy, m_current_pitch, m_pitch_count); |
| 575 | | for (i=0; i<10; i++) |
| 576 | | fprintf(stderr,"K%d:%04d ", i+1, m_current_k[i]); |
| 577 | | fprintf(stderr,"Out:%06d", this_sample); |
| 578 | | fprintf(stderr,"\n"); |
| 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"); |
| 579 | 538 | #endif |
| 580 | | /* next, force result to 14 bits (since its possible that the addition at the final (k1) stage of the lattice overflowed) */ |
| 581 | | while (this_sample > 16383) this_sample -= 32768; |
| 582 | | while (this_sample < -16384) this_sample += 32768; |
| 583 | | if (m_digital_select == 0) // analog SPK pin output is only 8 bits, with clipping |
| 584 | | buffer[buf_count] = clip_analog(this_sample); |
| 585 | | else // digital I/O pin output is 12 bits |
| 586 | | { |
| 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 | { |
| 587 | 546 | #ifdef ALLOW_4_LSB |
| 588 | | // input: ssss ssss ssss ssss ssnn nnnn nnnn nnnn |
| 589 | | // N taps: ^ = 0x2000; |
| 590 | | // output: ssss ssss ssss ssss snnn nnnn nnnn nnnN |
| 591 | | buffer[buf_count] = (this_sample<<1)|((this_sample&0x2000)>>13); |
| 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); |
| 592 | 551 | #else |
| 593 | | this_sample &= ~0xF; |
| 594 | | // input: ssss ssss ssss ssss ssnn nnnn nnnn 0000 |
| 595 | | // N taps: ^^ ^^^ = 0x3E00; |
| 596 | | // output: ssss ssss ssss ssss snnn nnnn nnnN NNNN |
| 597 | | buffer[buf_count] = (this_sample<<1)|((this_sample&0x3E00)>>9); |
| 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); |
| 598 | 557 | #endif |
| 599 | | } |
| 600 | | // Update all counts |
| 558 | } |
| 559 | // Update all counts |
| 601 | 560 | |
| 602 | | m_subcycle++; |
| 603 | | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 604 | | { |
| 605 | | /* Circuit 412 in the patent acts a reset, resetting the pitch counter to 0 |
| 606 | | * if INHIBIT was true during the most recent frame transition. |
| 607 | | * The exact time this occurs is betwen IP=7, PC=12 sub=0, T=t12 |
| 608 | | * and m_IP = 0, PC=0 sub=0, T=t12, a period of exactly 20 cycles, |
| 609 | | * which overlaps the time OLDE and OLDP are updated at IP=7 PC=12 T17 |
| 610 | | * (and hence INHIBIT itself 2 t-cycles later). We do it here because it is |
| 611 | | * convenient and should make no difference in output. |
| 612 | | */ |
| 613 | | if ((m_IP == 7)&&(m_inhibit==1)) m_pitch_zero = 1; |
| 614 | | if ((m_IP == 0)&&(m_pitch_zero==1)) m_pitch_zero = 0; |
| 615 | | #ifdef PERFECT_INTERPOLATION_HACK |
| 616 | | m_old_zpar = m_zpar; |
| 617 | | #endif |
| 618 | | m_zpar = 0; /* this gets effectively reset by resetf3, same signal which resets m_PC to 0 */ |
| 619 | | if (m_IP == 7) // RESETL4 |
| 561 | m_subcycle++; |
| 562 | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 620 | 563 | { |
| 621 | | /* if TALK was clear last frame, halt speech now, since TALKD (latched from TALK on new frame) just went inactive. */ |
| 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. */ |
| 622 | 580 | #ifdef DEBUG_GENERATION |
| 623 | | if (m_TALK == 0) |
| 624 | | fprintf(stderr,"tms5110_process: processing frame: TALKD = 0 caused by stop frame or buffer empty, halting speech.\n"); |
| 581 | if (m_TALK == 0) |
| 582 | fprintf(stderr,"tms5110_process: processing frame: TALKD = 0 caused by stop frame or buffer empty, halting speech.\n"); |
| 625 | 583 | #endif |
| 626 | | m_TALKD = m_TALK; // TALKD is latched from TALK |
| 627 | | m_TALK = m_SPEN; // TALK is latched from SPEN |
| 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; |
| 628 | 591 | } |
| 629 | | m_subcycle = m_subc_reload; |
| 630 | | m_PC = 0; |
| 631 | | m_IP++; |
| 632 | | m_IP&=0x7; |
| 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; |
| 633 | 600 | } |
| 634 | | else if (m_subcycle == 3) |
| 601 | else // m_TALKD == 0 |
| 635 | 602 | { |
| 636 | | m_subcycle = m_subc_reload; |
| 637 | | m_PC++; |
| 638 | | } |
| 639 | | m_pitch_count++; |
| 640 | | if ((m_pitch_count >= m_current_pitch)||(m_pitch_zero == 1)) m_pitch_count = 0; |
| 641 | | m_pitch_count &= 0x1FF; |
| 642 | | buf_count++; |
| 643 | | size--; |
| 644 | | } |
| 645 | | |
| 646 | | empty: |
| 647 | | |
| 648 | | while (size > 0) |
| 649 | | { |
| 650 | | m_subcycle++; |
| 651 | | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 652 | | { |
| 653 | | if (m_IP == 7) // RESETL4 |
| 603 | m_subcycle++; |
| 604 | if ((m_subcycle == 2) && (m_PC == 12)) // RESETF3 |
| 654 | 605 | { |
| 655 | | m_TALKD = m_TALK; // TALKD is latched from TALK |
| 656 | | m_TALK = m_SPEN; // TALK is latched from SPEN |
| 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; |
| 657 | 615 | } |
| 658 | | m_subcycle = m_subc_reload; |
| 659 | | m_PC = 0; |
| 660 | | m_IP++; |
| 661 | | m_IP&=0x7; |
| 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) */ |
| 662 | 622 | } |
| 663 | | else if (m_subcycle == 3) |
| 664 | | { |
| 665 | | m_subcycle = m_subc_reload; |
| 666 | | m_PC++; |
| 667 | | } |
| 668 | | buffer[buf_count] = -1; /* should be just -1; actual chip outputs -1 every idle sample; (cf note in data sheet, p 10, table 4) */ |
| 669 | | buf_count++; |
| 670 | | size--; |
| 623 | buf_count++; |
| 624 | size--; |
| 671 | 625 | } |
| 672 | 626 | } |
| 673 | 627 | |
| r249043 | r249044 | |
| 899 | 853 | m_SPEN = 1; /* start immediately */ |
| 900 | 854 | /* clear out variables before speaking */ |
| 901 | 855 | 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 |
| 902 | 863 | m_subc_reload = 0; // SPKSLOW means this is 0 |
| 903 | | m_subcycle = m_subc_reload; |
| 904 | | m_PC = 0; |
| 905 | | m_IP = 0; |
| 906 | 864 | break; |
| 907 | 865 | |
| 908 | 866 | case TMS5110_CMD_READ_BIT: |
| r249043 | r249044 | |
| 916 | 874 | #ifdef DEBUG_COMMAND_DUMP |
| 917 | 875 | fprintf(stderr,"actually reading a bit now\n"); |
| 918 | 876 | #endif |
| 919 | | request_bits(1); |
| 920 | 877 | m_CTL_buffer >>= 1; |
| 921 | 878 | m_CTL_buffer |= (extract_bits(1)<<3); |
| 922 | 879 | m_CTL_buffer &= 0xF; |
| r249043 | r249044 | |
| 931 | 888 | m_SPEN = 1; /* start immediately */ |
| 932 | 889 | /* clear out variables before speaking */ |
| 933 | 890 | 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 |
| 934 | 898 | m_subc_reload = 1; // SPEAK means this is 1 |
| 935 | | m_subcycle = m_subc_reload; |
| 936 | | m_PC = 0; |
| 937 | | m_IP = 0; |
| 938 | 899 | break; |
| 939 | 900 | |
| 940 | 901 | case TMS5110_CMD_READ_BRANCH: |
| r249043 | r249044 | |
| 979 | 940 | |
| 980 | 941 | void tms5110_device::parse_frame() |
| 981 | 942 | { |
| 982 | | int bits, i, rep_flag; |
| 983 | | /** TODO: get rid of bits handling here and move into extract_bits (as in tms5220.c) **/ |
| 984 | | /* count the total number of bits available */ |
| 985 | | bits = m_fifo_count; |
| 943 | int i, rep_flag; |
| 986 | 944 | |
| 987 | | /* attempt to extract the energy index */ |
| 988 | | bits -= m_coeff->energy_bits; |
| 989 | | if (bits < 0) |
| 990 | | { |
| 991 | | request_bits( -bits ); /* toggle M0 to receive needed bits */ |
| 992 | | bits = 0; |
| 993 | | } |
| 994 | 945 | // attempt to extract the energy index |
| 995 | 946 | m_new_frame_energy_idx = extract_bits(m_coeff->energy_bits); |
| 996 | 947 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| r249043 | r249044 | |
| 998 | 949 | fprintf(stderr," "); |
| 999 | 950 | #endif |
| 1000 | 951 | |
| 1001 | | /* if the energy index is 0 or 15, we're done |
| 1002 | | |
| 1003 | | if ((indx == 0) || (indx == 15)) |
| 1004 | | { |
| 1005 | | if (DEBUG_5110) logerror(" (4-bit energy=%d frame)\n",m_new_energy); |
| 1006 | | |
| 1007 | | // clear the k's |
| 1008 | | if (indx == 0) |
| 1009 | | { |
| 1010 | | for (i = 0; i < m_coeff->num_k; i++) |
| 1011 | | m_new_k[i] = 0; |
| 1012 | | } |
| 1013 | | |
| 1014 | | // clear fifo if stop frame encountered |
| 1015 | | if (indx == 15) |
| 1016 | | { |
| 1017 | | if (DEBUG_5110) logerror(" (4-bit energy=%d STOP frame)\n",m_new_energy); |
| 1018 | | m_fifo_head = m_fifo_tail = m_fifo_count = 0; |
| 1019 | | } |
| 1020 | | return; |
| 1021 | | }*/ |
| 1022 | 952 | // if the energy index is 0 or 15, we're done |
| 1023 | 953 | if ((m_new_frame_energy_idx == 0) || (m_new_frame_energy_idx == 15)) |
| 1024 | 954 | return; |
| 1025 | 955 | |
| 1026 | | |
| 1027 | | /* attempt to extract the repeat flag */ |
| 1028 | | bits -= 1; |
| 1029 | | if (bits < 0) |
| 1030 | | { |
| 1031 | | request_bits( -bits ); /* toggle M0 to receive needed bits */ |
| 1032 | | bits = 0; |
| 1033 | | } |
| 1034 | 956 | rep_flag = extract_bits(1); |
| 1035 | 957 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 1036 | 958 | printbits(rep_flag, 1); |
| 1037 | 959 | fprintf(stderr," "); |
| 1038 | 960 | #endif |
| 1039 | 961 | |
| 1040 | | /* attempt to extract the pitch */ |
| 1041 | | bits -= m_coeff->pitch_bits; |
| 1042 | | if (bits < 0) |
| 1043 | | { |
| 1044 | | request_bits( -bits ); /* toggle M0 to receive needed bits */ |
| 1045 | | bits = 0; |
| 1046 | | } |
| 1047 | 962 | m_new_frame_pitch_idx = extract_bits(m_coeff->pitch_bits); |
| 1048 | 963 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 1049 | 964 | printbits(m_new_frame_pitch_idx,m_coeff->pitch_bits); |
| r249043 | r249044 | |
| 1056 | 971 | // extract first 4 K coefficients |
| 1057 | 972 | for (i = 0; i < 4; i++) |
| 1058 | 973 | { |
| 1059 | | /* attempt to extract 4 K's */ |
| 1060 | | bits -= m_coeff->kbits[i]; |
| 1061 | | if (bits < 0) |
| 1062 | | { |
| 1063 | | request_bits( -bits ); /* toggle M0 to receive needed bits */ |
| 1064 | | bits = 0; |
| 1065 | | } |
| 1066 | 974 | m_new_frame_k_idx[i] = extract_bits(m_coeff->kbits[i]); |
| 1067 | 975 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 1068 | 976 | printbits(m_new_frame_k_idx[i],m_coeff->kbits[i]); |
| r249043 | r249044 | |
| 1080 | 988 | // If we got here, we need the remaining 6 K's |
| 1081 | 989 | for (i = 4; i < m_coeff->num_k; i++) |
| 1082 | 990 | { |
| 1083 | | bits -= m_coeff->kbits[i]; |
| 1084 | | if (bits < 0) |
| 1085 | | { |
| 1086 | | request_bits( -bits ); /* toggle M0 to receive needed bits */ |
| 1087 | | bits = 0; |
| 1088 | | } |
| 1089 | 991 | m_new_frame_k_idx[i] = extract_bits(m_coeff->kbits[i]); |
| 1090 | 992 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 1091 | 993 | printbits(m_new_frame_k_idx[i],m_coeff->kbits[i]); |
| 1092 | 994 | fprintf(stderr," "); |
| 1093 | 995 | #endif |
| 1094 | 996 | } |
| 997 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 998 | fprintf(stderr,"\n"); |
| 999 | #endif |
| 1095 | 1000 | #ifdef VERBOSE |
| 1096 | | if (m_speak_external) |
| 1097 | | logerror("Parsed a frame successfully in FIFO - %d bits remaining\n", (m_fifo_count*8)-(m_fifo_bits_taken)); |
| 1098 | | else |
| 1099 | 1001 | logerror("Parsed a frame successfully in ROM\n"); |
| 1100 | 1002 | #endif |
| 1101 | 1003 | return; |
| r249043 | r249044 | |
| 1239 | 1141 | void tms5110_device::device_reset() |
| 1240 | 1142 | { |
| 1241 | 1143 | m_digital_select = FORCE_DIGITAL; // assume analog output |
| 1242 | | /* initialize the FIFO */ |
| 1243 | | memset(m_fifo, 0, sizeof(m_fifo)); |
| 1244 | | m_fifo_head = m_fifo_tail = m_fifo_count = 0; |
| 1245 | 1144 | |
| 1246 | 1145 | /* initialize the chip state */ |
| 1247 | 1146 | m_SPEN = m_TALK = m_TALKD = 0; |
| r249043 | r249044 | |
| 1254 | 1153 | #ifdef PERFECT_INTERPOLATION_HACK |
| 1255 | 1154 | m_old_frame_energy_idx = m_old_frame_pitch_idx = 0; |
| 1256 | 1155 | memset(m_old_frame_k_idx, 0, sizeof(m_old_frame_k_idx)); |
| 1257 | | m_old_zpar = 0; |
| 1156 | m_old_zpar = m_old_uv_zpar = 0; |
| 1258 | 1157 | #endif |
| 1259 | 1158 | m_new_frame_energy_idx = m_current_energy = m_previous_energy = 0; |
| 1260 | 1159 | m_new_frame_pitch_idx = m_current_pitch = 0; |
| r249043 | r249044 | |
| 1391 | 1290 | } |
| 1392 | 1291 | |
| 1393 | 1292 | |
| 1394 | | |
| 1395 | 1293 | /****************************************************************************** |
| 1396 | 1294 | |
| 1397 | | tms5110_ready_r -- return the not ready status from the sound chip |
| 1398 | | |
| 1399 | | ******************************************************************************/ |
| 1400 | | |
| 1401 | | int tms5110_device::ready_r() |
| 1402 | | { |
| 1403 | | /* bring up to date first */ |
| 1404 | | m_stream->update(); |
| 1405 | | return (m_fifo_count < FIFO_SIZE-1); |
| 1406 | | } |
| 1407 | | |
| 1408 | | |
| 1409 | | |
| 1410 | | /****************************************************************************** |
| 1411 | | |
| 1412 | 1295 | tms5110_update -- update the sound chip so that it is in sync with CPU execution |
| 1413 | 1296 | |
| 1414 | 1297 | ******************************************************************************/ |
trunk/src/emu/sound/tms5220.c
| r249043 | r249044 | |
| 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 |
| 274 | 277 | |
| 278 | |
| 275 | 279 | /* *****configuration of chip connection stuff***** */ |
| 276 | 280 | /* 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) */ |
| 277 | 281 | #define FORCE_DIGITAL 0 |
| r249043 | r249044 | |
| 361 | 365 | save_item(NAME(m_fifo_count)); |
| 362 | 366 | save_item(NAME(m_fifo_bits_taken)); |
| 363 | 367 | |
| 364 | | save_item(NAME(m_speaking_now)); |
| 365 | | save_item(NAME(m_speak_external)); |
| 366 | | save_item(NAME(m_talk_status)); |
| 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)); |
| 367 | 373 | save_item(NAME(m_buffer_low)); |
| 368 | 374 | save_item(NAME(m_buffer_empty)); |
| 369 | 375 | save_item(NAME(m_irq_pin)); |
| r249043 | r249044 | |
| 384 | 390 | save_item(NAME(m_current_pitch)); |
| 385 | 391 | save_item(NAME(m_current_k)); |
| 386 | 392 | |
| 387 | | save_item(NAME(m_target_energy)); |
| 388 | | save_item(NAME(m_target_pitch)); |
| 389 | | save_item(NAME(m_target_k)); |
| 390 | | |
| 391 | 393 | save_item(NAME(m_previous_energy)); |
| 392 | 394 | |
| 393 | 395 | save_item(NAME(m_subcycle)); |
| r249043 | r249044 | |
| 395 | 397 | save_item(NAME(m_PC)); |
| 396 | 398 | save_item(NAME(m_IP)); |
| 397 | 399 | 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)); |
| 398 | 403 | save_item(NAME(m_c_variant_rate)); |
| 399 | 404 | save_item(NAME(m_pitch_count)); |
| 400 | 405 | |
| r249043 | r249044 | |
| 465 | 470 | |
| 466 | 471 | void tms5220_device::data_write(int data) |
| 467 | 472 | { |
| 473 | int old_buffer_low = m_buffer_low; |
| 468 | 474 | #ifdef DEBUG_DUMP_INPUT_DATA |
| 469 | 475 | fprintf(stdout, "%c",data); |
| 470 | 476 | #endif |
| 471 | | if (m_speak_external) // If we're in speak external mode |
| 477 | if (m_DDIS) // If we're in speak external mode |
| 472 | 478 | { |
| 473 | 479 | // add this byte to the FIFO |
| 474 | 480 | if (m_fifo_count < FIFO_SIZE) |
| r249043 | r249044 | |
| 477 | 483 | m_fifo_tail = (m_fifo_tail + 1) % FIFO_SIZE; |
| 478 | 484 | m_fifo_count++; |
| 479 | 485 | #ifdef DEBUG_FIFO |
| 480 | | logerror("data_write: Added byte to FIFO (current count=%2d)\n", m_fifo_count); |
| 486 | fprintf(stderr,"data_write: Added byte to FIFO (current count=%2d)\n", m_fifo_count); |
| 481 | 487 | #endif |
| 482 | 488 | update_fifo_status_and_ints(); |
| 483 | | if ((m_talk_status == 0) && (m_buffer_low == 0)) // we just unset buffer low with that last write, and talk status *was* zero... |
| 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 |
| 484 | 491 | { |
| 485 | | int i; |
| 492 | int i; |
| 486 | 493 | #ifdef DEBUG_FIFO |
| 487 | | logerror("data_write triggered talk status to go active!\n"); |
| 494 | fprintf(stderr,"data_write triggered SPEN to go active!\n"); |
| 488 | 495 | #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? |
| 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 |
| 494 | 509 | m_new_frame_energy_idx = 0; |
| 495 | 510 | m_new_frame_pitch_idx = 0; |
| 496 | 511 | for (i = 0; i < 4; i++) |
| r249043 | r249044 | |
| 499 | 514 | m_new_frame_k_idx[i] = 0xF; |
| 500 | 515 | for (i = 7; i < m_coeff->num_k; i++) |
| 501 | 516 | m_new_frame_k_idx[i] = 0x7; |
| 502 | | m_talk_status = m_speaking_now = 1; |
| 517 | |
| 503 | 518 | } |
| 504 | 519 | } |
| 505 | 520 | else |
| 506 | 521 | { |
| 507 | 522 | #ifdef DEBUG_FIFO |
| 508 | | logerror("data_write: Ran out of room in the tms52xx FIFO! this should never happen!\n"); |
| 523 | fprintf(stderr,"data_write: Ran out of room in the tms52xx FIFO! this should never happen!\n"); |
| 509 | 524 | // at this point, /READY should remain HIGH/inactive until the fifo has at least one byte open in it. |
| 510 | 525 | #endif |
| 511 | 526 | } |
| 512 | 527 | |
| 513 | 528 | |
| 514 | 529 | } |
| 515 | | else //(! m_speak_external) |
| 530 | else //(! m_DDIS) |
| 516 | 531 | // R Nabet : we parse commands at once. It is necessary for such commands as read. |
| 517 | 532 | process_command(data); |
| 518 | 533 | } |
| r249043 | r249044 | |
| 560 | 575 | m_buffer_low = 0; |
| 561 | 576 | |
| 562 | 577 | /* BE is set if neither byte 15 nor 14 of the fifo are in use; this |
| 563 | | translates to having fifo_count equal to exactly 0 */ |
| 578 | translates to having fifo_count equal to exactly 0 |
| 579 | */ |
| 564 | 580 | if (m_fifo_count == 0) |
| 565 | 581 | { |
| 566 | 582 | // generate an interrupt if necessary; if /BE was inactive and is now active, set int. |
| 567 | 583 | if (!m_buffer_empty) |
| 568 | 584 | set_interrupt_state(1); |
| 569 | 585 | m_buffer_empty = 1; |
| 586 | m_TALK = m_SPEN = 0; // /BE being active clears the TALK(TCON) status which in turn clears SPEN |
| 570 | 587 | } |
| 571 | 588 | else |
| 572 | 589 | m_buffer_empty = 0; |
| 573 | 590 | |
| 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)) |
| 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)) |
| 578 | 594 | { |
| 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 | | } |
| 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; |
| 585 | 600 | } |
| 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 */ |
| 601 | m_previous_TALK_STATUS = TALK_STATUS; |
| 602 | |
| 588 | 603 | } |
| 589 | 604 | |
| 590 | 605 | /********************************************************************************************** |
| r249043 | r249044 | |
| 597 | 612 | { |
| 598 | 613 | int val = 0; |
| 599 | 614 | |
| 600 | | if (m_speak_external) |
| 615 | if (m_DDIS) |
| 601 | 616 | { |
| 602 | 617 | // extract from FIFO |
| 603 | 618 | while (count--) |
| r249043 | r249044 | |
| 643 | 658 | /* clear the interrupt pin on status read */ |
| 644 | 659 | set_interrupt_state(0); |
| 645 | 660 | #ifdef DEBUG_PIN_READS |
| 646 | | logerror("Status read: TS=%d BL=%d BE=%d\n", m_talk_status, m_buffer_low, m_buffer_empty); |
| 661 | fprintf(stderr,"Status read: TS=%d BL=%d BE=%d\n", TALK_STATUS, m_buffer_low, m_buffer_empty); |
| 647 | 662 | #endif |
| 648 | 663 | |
| 649 | | return (m_talk_status << 7) | (m_buffer_low << 6) | (m_buffer_empty << 5); |
| 664 | return (TALK_STATUS << 7) | (m_buffer_low << 6) | (m_buffer_empty << 5); |
| 650 | 665 | } |
| 651 | 666 | } |
| 652 | 667 | |
| r249043 | r249044 | |
| 660 | 675 | int tms5220_device::ready_read() |
| 661 | 676 | { |
| 662 | 677 | #ifdef DEBUG_PIN_READS |
| 663 | | logerror("ready_read: ready pin read, io_ready is %d, fifo count is %d\n", m_io_ready, m_fifo_count); |
| 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); |
| 664 | 679 | #endif |
| 665 | | return ((m_fifo_count < FIFO_SIZE)||(!m_speak_external)) && m_io_ready; |
| 680 | return ((m_fifo_count < FIFO_SIZE)||(!m_DDIS)) && m_io_ready; |
| 666 | 681 | } |
| 667 | 682 | |
| 668 | 683 | |
| r249043 | r249044 | |
| 718 | 733 | int tms5220_device::int_read() |
| 719 | 734 | { |
| 720 | 735 | #ifdef DEBUG_PIN_READS |
| 721 | | logerror("int_read: irq pin read, state is %d\n", m_irq_pin); |
| 736 | fprintf(stderr,"int_read: irq pin read, state is %d\n", m_irq_pin); |
| 722 | 737 | #endif |
| 723 | 738 | return m_irq_pin; |
| 724 | 739 | } |
| r249043 | r249044 | |
| 733 | 748 | void tms5220_device::process(INT16 *buffer, unsigned int size) |
| 734 | 749 | { |
| 735 | 750 | int buf_count=0; |
| 736 | | int i, bitout, zpar; |
| 751 | int i, bitout; |
| 737 | 752 | INT32 this_sample; |
| 738 | 753 | |
| 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; |
| 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 |
| 743 | 757 | |
| 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 | | |
| 749 | 758 | /* loop until the buffer is full or we've stopped speaking */ |
| 750 | | while ((size > 0) && m_speaking_now) |
| 759 | while (size > 0) |
| 751 | 760 | { |
| 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)) |
| 761 | if(m_TALKD) // speaking |
| 760 | 762 | { |
| 761 | | m_OLDE = (m_new_frame_energy_idx == 0); |
| 762 | | m_OLDP = (m_new_frame_pitch_idx == 0); |
| 763 | | } |
| 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 |
| 764 | 772 | |
| 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 |
| 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]; |
| 774 | 775 | |
| 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 | | |
| 778 | 776 | #ifdef PERFECT_INTERPOLATION_HACK |
| 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]; |
| 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]; |
| 784 | 782 | #endif |
| 785 | 783 | |
| 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 | | } |
| 784 | /* Parse a new frame into the new_target_energy, new_target_pitch and new_target_k[] */ |
| 785 | parse_frame(); |
| 811 | 786 | |
| 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"); |
| 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 |
| 818 | 796 | #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 |
| 819 | 800 | |
| 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) |
| 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) |
| 823 | 803 | { |
| 824 | | m_talk_status = m_speak_external = 0; |
| 825 | | set_interrupt_state(1); |
| 826 | | update_fifo_status_and_ints(); |
| 804 | m_TALK = m_SPEN = 0; |
| 827 | 805 | } |
| 828 | 806 | |
| 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; |
| 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; |
| 843 | 821 | |
| 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 | | |
| 853 | 822 | #ifdef DEBUG_GENERATION |
| 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]); |
| 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)) ); |
| 863 | 845 | #endif |
| 864 | 846 | |
| 865 | | /* if TS is now 0, ramp the energy down to 0. Is this really correct to hardware? */ |
| 866 | | if (m_talk_status == 0) |
| 847 | } |
| 848 | else // Not a new frame, just interpolate the existing frame. |
| 867 | 849 | { |
| 868 | | #ifdef DEBUG_GENERATION |
| 869 | | fprintf(stderr,"Talk status is 0, forcing target energy to 0\n"); |
| 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 | } |
| 870 | 897 | #endif |
| 871 | | m_target_energy = 0; |
| 872 | 898 | } |
| 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)); |
| 881 | 899 | |
| 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... |
| 900 | // calculate the output |
| 901 | if (OLD_FRAME_UNVOICED_FLAG == 1) |
| 893 | 902 | { |
| 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; |
| 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; |
| 898 | 908 | } |
| 899 | | else // we're done, play this frame for 1/8 frame. |
| 909 | else /* (OLD_FRAME_UNVOICED_FLAG == 0) */ |
| 900 | 910 | { |
| 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]; |
| 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]; |
| 905 | 922 | } |
| 906 | | #else |
| 907 | | //Updates to parameters only happen on subcycle '2' (B cycle) of PCs. |
| 908 | | if (m_subcycle == 2) |
| 923 | |
| 924 | // Update LFSR *20* times every sample (once per T cycle), like patent shows |
| 925 | for (i=0; i<20; i++) |
| 909 | 926 | { |
| 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 | | } |
| 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; |
| 925 | 933 | } |
| 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 */ |
| 934 | this_sample = lattice_filter(); /* execute lattice filter */ |
| 964 | 935 | #ifdef DEBUG_GENERATION_VERBOSE |
| 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"); |
| 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"); |
| 972 | 948 | #endif |
| 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 | | { |
| 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 | { |
| 980 | 956 | #ifdef ALLOW_4_LSB |
| 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); |
| 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); |
| 985 | 961 | #else |
| 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); |
| 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); |
| 991 | 967 | #endif |
| 992 | | } |
| 993 | | // Update all counts |
| 968 | } |
| 969 | // Update all counts |
| 994 | 970 | |
| 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; |
| 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; |
| 1011 | 1017 | } |
| 1012 | | else if (m_subcycle == 3) |
| 1018 | else // m_TALKD == 0 |
| 1013 | 1019 | { |
| 1014 | | m_subcycle = m_subc_reload; |
| 1015 | | m_PC++; |
| 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) */ |
| 1016 | 1039 | } |
| 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--; |
| 1040 | buf_count++; |
| 1041 | size--; |
| 1022 | 1042 | } |
| 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 | | } |
| 1045 | 1043 | } |
| 1046 | 1044 | |
| 1047 | 1045 | /********************************************************************************************** |
| r249043 | r249044 | |
| 1182 | 1180 | |
| 1183 | 1181 | void tms5220_device::process_command(unsigned char cmd) |
| 1184 | 1182 | { |
| 1183 | int i; |
| 1185 | 1184 | #ifdef DEBUG_COMMAND_DUMP |
| 1186 | 1185 | fprintf(stderr,"process_command called with parameter %02X\n",cmd); |
| 1187 | 1186 | #endif |
| r249043 | r249044 | |
| 1189 | 1188 | switch (cmd & 0x70) |
| 1190 | 1189 | { |
| 1191 | 1190 | case 0x10 : /* read byte */ |
| 1192 | | if (m_talk_status == 0) /* TALKST must be clear for RDBY */ |
| 1191 | if (TALK_STATUS == 0) /* TALKST must be clear for RDBY */ |
| 1193 | 1192 | { |
| 1194 | 1193 | if (m_schedule_dummy_read) |
| 1195 | 1194 | { |
| r249043 | r249044 | |
| 1211 | 1210 | break; |
| 1212 | 1211 | |
| 1213 | 1212 | case 0x30 : /* read and branch */ |
| 1214 | | if (m_talk_status == 0) /* TALKST must be clear for RB */ |
| 1213 | if (TALK_STATUS == 0) /* TALKST must be clear for RB */ |
| 1215 | 1214 | { |
| 1216 | 1215 | #ifdef VERBOSE |
| 1217 | | logerror("read and branch command received\n"); |
| 1216 | fprintf(stderr,"read and branch command received\n"); |
| 1218 | 1217 | #endif |
| 1219 | 1218 | m_RDB_flag = FALSE; |
| 1220 | 1219 | if (m_speechrom) |
| r249043 | r249044 | |
| 1223 | 1222 | break; |
| 1224 | 1223 | |
| 1225 | 1224 | case 0x40 : /* load address */ |
| 1226 | | if (m_talk_status == 0) /* TALKST must be clear for LA */ |
| 1225 | if (TALK_STATUS == 0) /* TALKST must be clear for LA */ |
| 1227 | 1226 | { |
| 1228 | 1227 | /* tms5220 data sheet says that if we load only one 4-bit nibble, it won't work. |
| 1229 | 1228 | This code does not care about this. */ |
| r249043 | r249044 | |
| 1240 | 1239 | if (m_speechrom) |
| 1241 | 1240 | m_speechrom->read(1); |
| 1242 | 1241 | } |
| 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]; |
| 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 |
| 1251 | 1256 | m_new_frame_energy_idx = 0; |
| 1252 | 1257 | m_new_frame_pitch_idx = 0; |
| 1253 | | int i; |
| 1254 | 1258 | for (i = 0; i < 4; i++) |
| 1255 | 1259 | m_new_frame_k_idx[i] = 0; |
| 1256 | 1260 | for (i = 4; i < 7; i++) |
| r249043 | r249044 | |
| 1260 | 1264 | break; |
| 1261 | 1265 | |
| 1262 | 1266 | case 0x60 : /* speak external */ |
| 1263 | | //SPKEXT going active activates SPKEE which clears the fifo |
| 1267 | // SPKEXT going active activates SPKEE which clears the fifo |
| 1264 | 1268 | m_fifo_head = m_fifo_tail = m_fifo_count = m_fifo_bits_taken = 0; |
| 1265 | | m_speak_external = 1; |
| 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; |
| 1266 | 1288 | m_RDB_flag = FALSE; |
| 1267 | 1289 | break; |
| 1268 | 1290 | |
| r249043 | r249044 | |
| 1308 | 1330 | m_IP = reload_table[m_c_variant_rate&0x3]; |
| 1309 | 1331 | |
| 1310 | 1332 | update_fifo_status_and_ints(); |
| 1311 | | if (!m_talk_status) goto ranout; |
| 1333 | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1312 | 1334 | |
| 1313 | 1335 | // attempt to extract the energy index |
| 1314 | 1336 | m_new_frame_energy_idx = extract_bits(m_coeff->energy_bits); |
| r249043 | r249044 | |
| 1317 | 1339 | fprintf(stderr," "); |
| 1318 | 1340 | #endif |
| 1319 | 1341 | update_fifo_status_and_ints(); |
| 1320 | | if (!m_talk_status) goto ranout; |
| 1342 | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1321 | 1343 | // if the energy index is 0 or 15, we're done |
| 1322 | 1344 | if ((m_new_frame_energy_idx == 0) || (m_new_frame_energy_idx == 15)) |
| 1323 | 1345 | return; |
| r249043 | r249044 | |
| 1337 | 1359 | fprintf(stderr," "); |
| 1338 | 1360 | #endif |
| 1339 | 1361 | update_fifo_status_and_ints(); |
| 1340 | | if (!m_talk_status) goto ranout; |
| 1362 | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1341 | 1363 | // if this is a repeat frame, just do nothing, it will reuse the old coefficients |
| 1342 | 1364 | if (rep_flag) |
| 1343 | 1365 | return; |
| r249043 | r249044 | |
| 1351 | 1373 | fprintf(stderr," "); |
| 1352 | 1374 | #endif |
| 1353 | 1375 | update_fifo_status_and_ints(); |
| 1354 | | if (!m_talk_status) goto ranout; |
| 1376 | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1355 | 1377 | } |
| 1356 | 1378 | |
| 1357 | 1379 | // if the pitch index was zero, we only need 4 K's... |
| r249043 | r249044 | |
| 1370 | 1392 | fprintf(stderr," "); |
| 1371 | 1393 | #endif |
| 1372 | 1394 | update_fifo_status_and_ints(); |
| 1373 | | if (!m_talk_status) goto ranout; |
| 1395 | if (m_DDIS && m_buffer_empty) goto ranout; |
| 1374 | 1396 | } |
| 1397 | #ifdef DEBUG_PARSE_FRAME_DUMP |
| 1398 | fprintf(stderr,"\n"); |
| 1399 | #endif |
| 1375 | 1400 | #ifdef VERBOSE |
| 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)); |
| 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)); |
| 1378 | 1403 | else |
| 1379 | | logerror("Parsed a frame successfully in ROM\n"); |
| 1404 | fprintf(stderr,"Parsed a frame successfully in ROM\n"); |
| 1380 | 1405 | #endif |
| 1381 | 1406 | return; |
| 1382 | 1407 | |
| 1383 | 1408 | ranout: |
| 1384 | 1409 | #ifdef DEBUG_FRAME_ERRORS |
| 1385 | | logerror("Ran out of bits on a parse!\n"); |
| 1410 | fprintf(stderr,"Ran out of bits on a parse!\n"); |
| 1386 | 1411 | #endif |
| 1387 | 1412 | return; |
| 1388 | 1413 | } |
| r249043 | r249044 | |
| 1397 | 1422 | { |
| 1398 | 1423 | if (!TMS5220_IS_52xx) return; // bail out if not a 52xx chip, since there's no int pin |
| 1399 | 1424 | #ifdef DEBUG_PIN_READS |
| 1400 | | logerror("irq pin set to state %d\n", state); |
| 1425 | fprintf(stderr,"irq pin set to state %d\n", state); |
| 1401 | 1426 | #endif |
| 1402 | 1427 | if (!m_irq_handler.isnull() && state != m_irq_pin) |
| 1403 | 1428 | m_irq_handler(!state); |
| r249043 | r249044 | |
| 1414 | 1439 | { |
| 1415 | 1440 | int state = ready_read(); |
| 1416 | 1441 | #ifdef DEBUG_PIN_READS |
| 1417 | | logerror("ready pin set to state %d\n", state); |
| 1442 | fprintf(stderr,"ready pin set to state %d\n", state); |
| 1418 | 1443 | #endif |
| 1419 | 1444 | if (!m_readyq_handler.isnull() && state != m_ready_pin) |
| 1420 | 1445 | m_readyq_handler(!state); |
| r249043 | r249044 | |
| 1514 | 1539 | |
| 1515 | 1540 | /* initialize the chip state */ |
| 1516 | 1541 | /* 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 */ |
| 1517 | | m_speaking_now = m_speak_external = m_talk_status = m_irq_pin = m_ready_pin = 0; |
| 1542 | m_SPEN = m_DDIS = m_TALK = m_TALKD = m_previous_TALK_STATUS = m_irq_pin = m_ready_pin = 0; |
| 1518 | 1543 | set_interrupt_state(0); |
| 1519 | 1544 | update_ready_state(); |
| 1520 | 1545 | m_buffer_empty = m_buffer_low = 1; |
| r249043 | r249044 | |
| 1525 | 1550 | #ifdef PERFECT_INTERPOLATION_HACK |
| 1526 | 1551 | m_old_frame_energy_idx = m_old_frame_pitch_idx = 0; |
| 1527 | 1552 | memset(m_old_frame_k_idx, 0, sizeof(m_old_frame_k_idx)); |
| 1553 | m_old_zpar = 0; |
| 1528 | 1554 | #endif |
| 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; |
| 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; |
| 1531 | 1558 | memset(m_new_frame_k_idx, 0, sizeof(m_new_frame_k_idx)); |
| 1532 | 1559 | memset(m_current_k, 0, sizeof(m_current_k)); |
| 1533 | | memset(m_target_k, 0, sizeof(m_target_k)); |
| 1534 | 1560 | |
| 1535 | 1561 | /* initialize the sample generators */ |
| 1536 | 1562 | m_inhibit = 1; |
| r249043 | r249044 | |
| 1574 | 1600 | /* Write */ |
| 1575 | 1601 | /* bring up to date first */ |
| 1576 | 1602 | #ifdef DEBUG_IO_READY |
| 1577 | | logerror("Serviced write: %02x\n", m_write_latch); |
| 1603 | fprintf(stderr,"Serviced write: %02x\n", m_write_latch); |
| 1578 | 1604 | //fprintf(stderr, "Processed write data: %02X\n", m_write_latch); |
| 1579 | 1605 | #endif |
| 1580 | 1606 | m_stream->update(); |
| r249043 | r249044 | |
| 1610 | 1636 | m_true_timing = 1; |
| 1611 | 1637 | state &= 0x01; |
| 1612 | 1638 | #ifdef DEBUG_RS_WS |
| 1613 | | logerror("/RS written with data: %d\n", state); |
| 1639 | fprintf(stderr,"/RS written with data: %d\n", state); |
| 1614 | 1640 | #endif |
| 1615 | 1641 | new_val = (m_rs_ws & 0x01) | (state<<1); |
| 1616 | 1642 | if (new_val != m_rs_ws) |
| r249043 | r249044 | |
| 1623 | 1649 | #ifdef DEBUG_RS_WS |
| 1624 | 1650 | else |
| 1625 | 1651 | /* illegal */ |
| 1626 | | logerror("tms5220_rs_w: illegal\n"); |
| 1652 | fprintf(stderr,"tms5220_rs_w: illegal\n"); |
| 1627 | 1653 | #endif |
| 1628 | 1654 | return; |
| 1629 | 1655 | } |
| r249043 | r249044 | |
| 1641 | 1667 | { |
| 1642 | 1668 | /* high to low - schedule ready cycle */ |
| 1643 | 1669 | #ifdef DEBUG_RS_WS |
| 1644 | | logerror("Scheduling ready cycle for /RS...\n"); |
| 1670 | fprintf(stderr,"Scheduling ready cycle for /RS...\n"); |
| 1645 | 1671 | #endif |
| 1646 | 1672 | /* 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. */ |
| 1647 | 1673 | m_io_ready = 0; |
| r249043 | r249044 | |
| 1662 | 1688 | m_true_timing = 1; |
| 1663 | 1689 | state &= 0x01; |
| 1664 | 1690 | #ifdef DEBUG_RS_WS |
| 1665 | | logerror("/WS written with data: %d\n", state); |
| 1691 | fprintf(stderr,"/WS written with data: %d\n", state); |
| 1666 | 1692 | #endif |
| 1667 | 1693 | new_val = (m_rs_ws & 0x02) | (state<<0); |
| 1668 | 1694 | if (new_val != m_rs_ws) |
| r249043 | r249044 | |
| 1675 | 1701 | #ifdef DEBUG_RS_WS |
| 1676 | 1702 | else |
| 1677 | 1703 | /* illegal */ |
| 1678 | | logerror("tms5220_ws_w: illegal\n"); |
| 1704 | fprintf(stderr,"tms5220_ws_w: illegal\n"); |
| 1679 | 1705 | #endif |
| 1680 | 1706 | return; |
| 1681 | 1707 | } |
| r249043 | r249044 | |
| 1693 | 1719 | { |
| 1694 | 1720 | /* high to low - schedule ready cycle */ |
| 1695 | 1721 | #ifdef DEBUG_RS_WS |
| 1696 | | logerror("Scheduling ready cycle for /WS...\n"); |
| 1722 | fprintf(stderr,"Scheduling ready cycle for /WS...\n"); |
| 1697 | 1723 | #endif |
| 1698 | 1724 | /* 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. */ |
| 1699 | 1725 | m_io_ready = 0; |
| r249043 | r249044 | |
| 1726 | 1752 | if (space.debugger_access()) return; |
| 1727 | 1753 | |
| 1728 | 1754 | #ifdef DEBUG_RS_WS |
| 1729 | | logerror("tms5220_data_w: data %02x\n", data); |
| 1755 | fprintf(stderr,"tms5220_data_w: data %02x\n", data); |
| 1730 | 1756 | #endif |
| 1731 | 1757 | if (!m_true_timing) |
| 1732 | 1758 | { |
| r249043 | r249044 | |
| 1739 | 1765 | /* actually in a write ? */ |
| 1740 | 1766 | #ifdef DEBUG_RS_WS |
| 1741 | 1767 | if (!(m_rs_ws == 0x02)) |
| 1742 | | logerror("tms5220_data_w: data written outside ws, status: %02x!\n", m_rs_ws); |
| 1768 | fprintf(stderr,"tms5220_data_w: data written outside ws, status: %02x!\n", m_rs_ws); |
| 1743 | 1769 | #endif |
| 1744 | 1770 | m_write_latch = data; |
| 1745 | 1771 | } |
| r249043 | r249044 | |
| 1771 | 1797 | return m_read_latch; |
| 1772 | 1798 | #ifdef DEBUG_RS_WS |
| 1773 | 1799 | else |
| 1774 | | logerror("tms5220_status_r: data read outside rs!\n"); |
| 1800 | fprintf(stderr,"tms5220_status_r: data read outside rs!\n"); |
| 1775 | 1801 | #endif |
| 1776 | 1802 | return 0xff; |
| 1777 | 1803 | } |
trunk/src/mame/video/chihiro.c
| r249043 | r249044 | |
| 3 | 3 | #include "emu.h" |
| 4 | 4 | #include "video/poly.h" |
| 5 | 5 | #include "bitmap.h" |
| 6 | #include "machine/pic8259.h" |
| 6 | 7 | #include "includes/chihiro.h" |
| 7 | 8 | |
| 8 | 9 | //#define LOG_NV2A |
| r249043 | r249044 | |
| 945 | 946 | UINT32 nv2a_renderer::geforce_object_offset(UINT32 handle) |
| 946 | 947 | { |
| 947 | 948 | UINT32 h = ((((handle >> 11) ^ handle) >> 11) ^ handle) & 0x7ff; |
| 948 | | UINT32 o = (pfifo[0x210 / 4] & 0x1f) << 8; // or 12 ? |
| 949 | UINT32 o = (pfifo[0x210 / 4] & 0x1ff) << 8; // 0x1ff is not certain |
| 949 | 950 | UINT32 e = o + h * 8; // at 0xfd000000+0x00700000 |
| 950 | 951 | UINT32 w; |
| 951 | 952 | |
| 952 | | if (ramin[e / 4] != handle) |
| 953 | | e = 0; |
| 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 | } |
| 954 | 961 | w = ramin[e / 4 + 1]; |
| 955 | | return (w & 0xffff) * 0x10; |
| 962 | return (w & 0xffff) * 0x10; // 0xffff is not certain |
| 956 | 963 | } |
| 957 | 964 | |
| 958 | 965 | void nv2a_renderer::geforce_read_dma_object(UINT32 handle, UINT32 &offset, UINT32 &size) |
| r249043 | r249044 | |
| 1246 | 1253 | addr = rendertarget + (dilated0[dilate_rendertarget][x] + dilated1[dilate_rendertarget][y]); |
| 1247 | 1254 | else // type_rendertarget == LINEAR*/ |
| 1248 | 1255 | addr = rendertarget + (pitch_rendertarget / 4)*y + x; |
| 1249 | | fbcolor = *addr; |
| 1256 | fbcolor = 0; |
| 1257 | if (color_mask != 0) |
| 1258 | fbcolor = *addr; |
| 1250 | 1259 | daddr=depthbuffer + (pitch_depthbuffer / 4)*y + x; |
| 1251 | 1260 | deptsten = *daddr; |
| 1252 | 1261 | c[3] = color >> 24; |
| r249043 | r249044 | |
| 1772 | 1781 | break; |
| 1773 | 1782 | } |
| 1774 | 1783 | } |
| 1775 | | fbcolor = (c[3] << 24) | (c[2] << 16) | (c[1] << 8) | c[0]; |
| 1776 | | *addr = fbcolor; |
| 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 | } |
| 1777 | 1790 | if (depth_write_enabled) |
| 1778 | 1791 | dep = depth; |
| 1779 | 1792 | deptsten = (dep << 8) | sten; |
| r249043 | r249044 | |
| 2233 | 2246 | maddress = method * 4; |
| 2234 | 2247 | data = space.read_dword(address); |
| 2235 | 2248 | 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 |
| 2236 | 2252 | if (maddress == 0x17fc) { |
| 2237 | 2253 | indexesleft_count = 0; |
| 2238 | 2254 | indexesleft_first = 0; |
| r249043 | r249044 | |
| 2270 | 2286 | } |
| 2271 | 2287 | wait(); |
| 2272 | 2288 | } |
| 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 | } |
| 2273 | 2304 | else if (type == nv2a_renderer::TRIANGLE_STRIP) { |
| 2274 | 2305 | vertex_nv vert[4]; |
| 2275 | 2306 | vertex_t xy[4]; |
| r249043 | r249044 | |
| 2311 | 2342 | // each dword after 1800 contains two 16 bit index values to select the vartices |
| 2312 | 2343 | // each dword after 1808 contains a 32 bit index value to select the vartices |
| 2313 | 2344 | 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 |
| 2317 | 2345 | if (type == nv2a_renderer::QUADS) { |
| 2318 | 2346 | while (1) { |
| 2319 | 2347 | vertex_nv vert[4]; |
| r249043 | r249044 | |
| 2332 | 2360 | render_polygon<4>(limits_rendertarget, renderspans, 4 + 4 * 2, xy); // 4 rgba, 4 texture units 2 uv |
| 2333 | 2361 | } |
| 2334 | 2362 | } |
| 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 | } |
| 2335 | 2391 | else if (type == nv2a_renderer::TRIANGLES) { |
| 2336 | 2392 | while (1) { |
| 2337 | 2393 | vertex_nv vert[3]; |
| r249043 | r249044 | |
| 2446 | 2502 | } |
| 2447 | 2503 | wait(); |
| 2448 | 2504 | } |
| 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 | } |
| 2449 | 2523 | else if (type == nv2a_renderer::TRIANGLE_STRIP) { |
| 2450 | 2524 | vertex_nv vert[4]; |
| 2451 | 2525 | vertex_t xy[4]; |
| r249043 | r249044 | |
| 2613 | 2687 | // clear colors |
| 2614 | 2688 | UINT32 color = channel[chanel][subchannel].object.method[0x1d90 / 4]; |
| 2615 | 2689 | bm.fill(color); |
| 2616 | | //printf("clearscreen\n\r"); |
| 2690 | #ifdef LOG_NV2A |
| 2691 | printf("clearscreen\n\r"); |
| 2692 | #endif |
| 2617 | 2693 | } |
| 2618 | 2694 | if ((data & 0x03) == 3) { |
| 2619 | 2695 | bitmap_rgb32 bm(depthbuffer, (limits_rendertarget.right() + 1) * m, (limits_rendertarget.bottom() + 1) * m, pitch_rendertarget / 4); // why *2 ? |
| r249043 | r249044 | |
| 2649 | 2725 | dilate_rendertarget = dilatechose[(log2width_rendertarget << 4) + log2height_rendertarget]; |
| 2650 | 2726 | } |
| 2651 | 2727 | if (maddress == 0x020c) { |
| 2652 | | // line size ? |
| 2653 | 2728 | pitch_rendertarget=data & 0xffff; |
| 2654 | 2729 | pitch_depthbuffer=(data >> 16) & 0xffff; |
| 2655 | | //printf("Pitch color %04X zbuffer %04X\n\r",pitch_rendertarget,pitch_depthbuffer); |
| 2730 | #ifdef LOG_NV2A |
| 2731 | printf("Pitch color %04X zbuffer %04X\n\r",pitch_rendertarget,pitch_depthbuffer); |
| 2732 | #endif |
| 2656 | 2733 | countlen--; |
| 2657 | 2734 | } |
| 2658 | 2735 | if (maddress == 0x0100) { |
| 2659 | | // just temporarily |
| 2660 | | if ((data & 0x1f) == 1) { |
| 2661 | | data = data >> 5; |
| 2662 | | data = data & 0x0ffffff0; |
| 2663 | | displayedtarget = (UINT32 *)direct_access_ptr(data); |
| 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; |
| 2664 | 2747 | } |
| 2748 | else |
| 2749 | return 0; |
| 2665 | 2750 | } |
| 2666 | 2751 | if (maddress == 0x0130) { |
| 2667 | 2752 | countlen--; |
| r249043 | r249044 | |
| 2670 | 2755 | else |
| 2671 | 2756 | return 0; |
| 2672 | 2757 | } |
| 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 | } |
| 2673 | 2770 | if (maddress == 0x0210) { |
| 2674 | 2771 | // framebuffer offset ? |
| 2675 | 2772 | rendertarget = (UINT32 *)direct_access_ptr(data); |
| 2676 | | //printf("Render target at %08X\n\r",data); |
| 2773 | #ifdef LOG_NV2A |
| 2774 | printf("Render target at %08X\n\r", data); |
| 2775 | #endif |
| 2677 | 2776 | countlen--; |
| 2678 | 2777 | } |
| 2679 | 2778 | if (maddress == 0x0214) { |
| 2680 | 2779 | // zbuffer offset ? |
| 2681 | 2780 | depthbuffer = (UINT32 *)direct_access_ptr(data); |
| 2682 | | //printf("Depth buffer at %08X\n\r",data); |
| 2781 | #ifdef LOG_NV2A |
| 2782 | printf("Depth buffer at %08X\n\r",data); |
| 2783 | #endif |
| 2683 | 2784 | if ((data == 0) || (data > 0x7ffffffc)) |
| 2684 | 2785 | depth_write_enabled = false; |
| 2685 | 2786 | else if (channel[chanel][subchannel].object.method[0x035c / 4] != 0) |
| r249043 | r249044 | |
| 2709 | 2810 | if (maddress == 0x0354) { |
| 2710 | 2811 | depth_function = data; |
| 2711 | 2812 | } |
| 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 | } |
| 2712 | 2825 | if (maddress == 0x035c) { |
| 2713 | 2826 | UINT32 g = channel[chanel][subchannel].object.method[0x0214 / 4]; |
| 2714 | 2827 | depth_write_enabled = data != 0; |
| r249043 | r249044 | |
| 3648 | 3761 | combiner.function_Aop3 = MAX(MIN((combiner.function_Aop3 + biasa) * scalea, 1.0f), -1.0f); |
| 3649 | 3762 | } |
| 3650 | 3763 | |
| 3651 | | bool nv2a_renderer::vblank_callback(screen_device &screen, bool state) |
| 3764 | void nv2a_renderer::vblank_callback(screen_device &screen, bool state) |
| 3652 | 3765 | { |
| 3653 | | //printf("vblank_callback\n\r"); |
| 3654 | | if (state == true) |
| 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) { |
| 3655 | 3774 | 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 |
| 3656 | 3783 | else |
| 3657 | | pcrtc[0x100 / 4] &= ~1; |
| 3784 | interruptdevice->ir3_w(0); // IRQ 3 |
| 3785 | } |
| 3786 | |
| 3787 | bool nv2a_renderer::update_interrupts() |
| 3788 | { |
| 3658 | 3789 | if (pcrtc[0x100 / 4] & pcrtc[0x140 / 4]) |
| 3659 | 3790 | pmc[0x100 / 4] |= 0x1000000; |
| 3660 | 3791 | else |
| 3661 | 3792 | pmc[0x100 / 4] &= ~0x1000000; |
| 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)) { |
| 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))) { |
| 3667 | 3798 | // send interrupt |
| 3668 | 3799 | return true; |
| 3669 | 3800 | } |
| r249043 | r249044 | |
| 3692 | 3823 | int countlen; |
| 3693 | 3824 | int ret; |
| 3694 | 3825 | address_space *space = puller_space; |
| 3826 | #ifdef LOG_NV2A |
| 3827 | UINT32 subch; |
| 3828 | #endif |
| 3695 | 3829 | |
| 3696 | 3830 | chanel = puller_channel; |
| 3697 | 3831 | subchannel = puller_subchannel; |
| r249043 | r249044 | |
| 3748 | 3882 | } |
| 3749 | 3883 | if (ret != 0) { |
| 3750 | 3884 | puller_timer->enable(false); |
| 3751 | | puller_waiting = 1; |
| 3885 | puller_waiting = ret; |
| 3752 | 3886 | return; |
| 3753 | 3887 | } |
| 3754 | 3888 | } |
| r249043 | r249044 | |
| 3847 | 3981 | //logerror("NV_2A: read PRAMIN[%06X] value %08X\n",offset*4-0x00700000,ret); |
| 3848 | 3982 | } |
| 3849 | 3983 | else if ((offset >= 0x00400000 / 4) && (offset < 0x00402000 / 4)) { |
| 3984 | ret = pgraph[offset - 0x00400000 / 4]; |
| 3850 | 3985 | //logerror("NV_2A: read PGRAPH[%06X] value %08X\n",offset*4-0x00400000,ret); |
| 3851 | 3986 | } |
| 3852 | 3987 | else if ((offset >= 0x00600000 / 4) && (offset < 0x00601000 / 4)) { |
| r249043 | r249044 | |
| 3870 | 4005 | //logerror("NV_2A: read channel[%02X,%d,%04X]=%08X\n",chanel,subchannel,suboffset*4,ret); |
| 3871 | 4006 | return ret; |
| 3872 | 4007 | } |
| 3873 | | else |
| 3874 | | { |
| 3875 | | /* nothing */ |
| 3876 | | } |
| 3877 | 4008 | //logerror("NV_2A: read at %08X mask %08X value %08X\n",0xfd000000+offset*4,mem_mask,ret); |
| 3878 | 4009 | return ret; |
| 3879 | 4010 | } |
| 3880 | 4011 | |
| 3881 | 4012 | WRITE32_MEMBER(nv2a_renderer::geforce_w) |
| 3882 | 4013 | { |
| 4014 | UINT32 old; |
| 4015 | bool update_int; |
| 4016 | |
| 4017 | update_int = false; |
| 3883 | 4018 | if ((offset >= 0x00101000 / 4) && (offset < 0x00102000 / 4)) { |
| 3884 | 4019 | //logerror("NV_2A: write STRAPS[%06X] mask %08X value %08X\n",offset*4-0x00101000,mem_mask,data); |
| 3885 | 4020 | } |
| r249043 | r249044 | |
| 3898 | 4033 | //logerror("NV_2A: write PRAMIN[%06X]=%08X\n",offset*4-0x00700000,data & mem_mask); |
| 3899 | 4034 | } |
| 3900 | 4035 | 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; |
| 3901 | 4058 | //logerror("NV_2A: write PGRAPH[%06X]=%08X\n",offset*4-0x00400000,data & mem_mask); |
| 3902 | 4059 | } |
| 3903 | 4060 | else if ((offset >= 0x00600000 / 4) && (offset < 0x00601000 / 4)) { |
| 3904 | 4061 | int e = offset - 0x00600000 / 4; |
| 3905 | 4062 | if (e >= (sizeof(pcrtc) / sizeof(UINT32))) |
| 3906 | 4063 | return; |
| 4064 | old = pcrtc[e]; |
| 3907 | 4065 | 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; |
| 3908 | 4072 | if (e == 0x800 / 4) { |
| 3909 | | displayedtarget = (UINT32 *)direct_access_ptr(data); |
| 3910 | | //printf("crtc buffer %08X\n\r", data); |
| 4073 | displayedtarget = (UINT32 *)direct_access_ptr(pcrtc[e]); |
| 4074 | #ifdef LOG_NV2A |
| 4075 | printf("crtc buffer %08X\n\r", data); |
| 4076 | #endif |
| 3911 | 4077 | } |
| 3912 | 4078 | //logerror("NV_2A: write PCRTC[%06X]=%08X\n",offset*4-0x00600000,data & mem_mask); |
| 3913 | 4079 | } |
| r249043 | r249044 | |
| 3922 | 4088 | // 32 channels size 0x10000 each, 8 subchannels per channel size 0x2000 each |
| 3923 | 4089 | int chanel, subchannel, suboffset; |
| 3924 | 4090 | //int method, count, handle, objclass; |
| 3925 | | #ifdef LOG_NV2A |
| 3926 | | int subch; |
| 3927 | | #endif |
| 3928 | 4091 | |
| 3929 | 4092 | suboffset = offset - 0x00800000 / 4; |
| 3930 | 4093 | chanel = (suboffset >> (16 - 2)) & 31; |
| r249043 | r249044 | |
| 3959 | 4122 | } |
| 3960 | 4123 | //else |
| 3961 | 4124 | // 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 | } |
| 3962 | 4131 | } |
| 3963 | 4132 | |
| 3964 | 4133 | void nv2a_renderer::savestate_items() |
| r249043 | r249044 | |
| 3971 | 4140 | puller_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(nv2a_renderer::puller_timer_work), this), (void *)"NV2A Puller Timer"); |
| 3972 | 4141 | puller_timer->enable(false); |
| 3973 | 4142 | } |
| 4143 | |
| 4144 | void nv2a_renderer::set_interrupt_device(pic8259_device *device) |
| 4145 | { |
| 4146 | interruptdevice = device; |
| 4147 | } |