src/emu/cpu/tlcs900/tlcs900.c
| r4555 | r4556 | |
| 352 | 352 | #include "900tbl.c" |
| 353 | 353 | |
| 354 | 354 | |
| 355 | | INLINE void tlcs900_process_hdma( tlcs900_state *cpustate, int channel, int vector ) |
| 355 | #define NUM_MASKABLE_IRQS 22 |
| 356 | static const struct { |
| 357 | UINT8 reg; |
| 358 | UINT8 iff; |
| 359 | UINT8 vector; |
| 360 | } irq_vector_map[NUM_MASKABLE_IRQS] = |
| 356 | 361 | { |
| 357 | | if ( vector == ( cpustate->reg[0x7c + channel] & 0x1f ) ) |
| 362 | { INTETC32, 0x80, 0x80 }, /* INTTC3 */ |
| 363 | { INTETC32, 0x08, 0x7c }, /* INTTC2 */ |
| 364 | { INTETC10, 0x80, 0x78 }, /* INTTC1 */ |
| 365 | { INTETC10, 0x08, 0x74 }, /* INTTC0 */ |
| 366 | { INTE0AD, 0x80, 0x70 }, /* INTAD */ |
| 367 | { INTES1, 0x80, 0x6c }, /* INTTX1 */ |
| 368 | { INTES1, 0x08, 0x68 }, /* INTRX1 */ |
| 369 | { INTES0, 0x80, 0x64 }, /* INTTX0 */ |
| 370 | { INTES0, 0x08, 0x60 }, /* INTRX0 */ |
| 371 | { INTET76, 0x80, 0x5c }, /* INTTR7 */ |
| 372 | { INTET76, 0x08, 0x58 }, /* INTTR6 */ |
| 373 | { INTET54, 0x80, 0x54 }, /* INTTR5 */ |
| 374 | { INTET54, 0x08, 0x50 }, /* INTTR4 */ |
| 375 | { INTET32, 0x80, 0x4c }, /* INTT3 */ |
| 376 | { INTET32, 0x08, 0x48 }, /* INTT2 */ |
| 377 | { INTET10, 0x80, 0x44 }, /* INTT1 */ |
| 378 | { INTET10, 0x08, 0x40 }, /* INTT0 */ |
| 379 | /* 0x3c - reserved */ |
| 380 | { INTE67, 0x80, 0x38 }, /* INT7 */ |
| 381 | { INTE67, 0x08, 0x34 }, /* INT6 */ |
| 382 | { INTE45, 0x80, 0x30 }, /* INT5 */ |
| 383 | { INTE45, 0x08, 0x2c }, /* INT4 */ |
| 384 | { INTE0AD, 0x08, 0x28 } /* INT0 */ |
| 385 | }; |
| 386 | |
| 387 | |
| 388 | INLINE int tlcs900_process_hdma( tlcs900_state *cpustate, int channel ) |
| 389 | { |
| 390 | UINT8 vector = ( cpustate->reg[0x7c + channel] & 0x1f ) << 2; |
| 391 | |
| 392 | /* Check if any HDMA actions should be performed */ |
| 393 | if ( vector >= 0x28 && vector != 0x3C && vector < 0x74 ) |
| 358 | 394 | { |
| 359 | | switch( cpustate->dmam[channel].b.l & 0x1f ) |
| 360 | | { |
| 361 | | case 0x00: |
| 362 | | WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) ); |
| 363 | | cpustate->dmad[channel].d += 1; |
| 364 | | cpustate->cycles += 8; |
| 365 | | break; |
| 366 | | case 0x01: |
| 367 | | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 368 | | cpustate->dmad[channel].d += 2; |
| 369 | | cpustate->cycles += 8; |
| 370 | | break; |
| 371 | | case 0x02: |
| 372 | | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 373 | | cpustate->dmad[channel].d += 4; |
| 374 | | cpustate->cycles += 12; |
| 375 | | break; |
| 376 | | case 0x04: |
| 377 | | WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) ); |
| 378 | | cpustate->dmad[channel].d -= 1; |
| 379 | | cpustate->cycles += 8; |
| 380 | | break; |
| 381 | | case 0x05: |
| 382 | | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 383 | | cpustate->dmad[channel].d -= 2; |
| 384 | | cpustate->cycles += 8; |
| 385 | | break; |
| 386 | | case 0x06: |
| 387 | | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 388 | | cpustate->dmad[channel].d -= 4; |
| 389 | | cpustate->cycles += 12; |
| 390 | | break; |
| 391 | | case 0x08: |
| 392 | | WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) ); |
| 393 | | cpustate->dmas[channel].d += 1; |
| 394 | | cpustate->cycles += 8; |
| 395 | | break; |
| 396 | | case 0x09: |
| 397 | | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 398 | | cpustate->dmas[channel].d += 2; |
| 399 | | cpustate->cycles += 8; |
| 400 | | break; |
| 401 | | case 0x0a: |
| 402 | | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 403 | | cpustate->dmas[channel].d += 4; |
| 404 | | cpustate->cycles += 12; |
| 405 | | break; |
| 406 | | case 0x0c: |
| 407 | | WRMEM( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 408 | | cpustate->dmas[channel].d -= 1; |
| 409 | | cpustate->cycles += 8; |
| 410 | | break; |
| 411 | | case 0x0d: |
| 412 | | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 413 | | cpustate->dmas[channel].d -= 2; |
| 414 | | cpustate->cycles += 8; |
| 415 | | break; |
| 416 | | case 0x0e: |
| 417 | | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 418 | | cpustate->dmas[channel].d -= 4; |
| 419 | | cpustate->cycles += 12; |
| 420 | | break; |
| 421 | | case 0x10: |
| 422 | | WRMEM( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 423 | | cpustate->cycles += 8; |
| 424 | | break; |
| 425 | | case 0x11: |
| 426 | | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 427 | | cpustate->cycles += 8; |
| 428 | | break; |
| 429 | | case 0x12: |
| 430 | | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 431 | | cpustate->cycles += 12; |
| 432 | | break; |
| 433 | | case 0x14: |
| 434 | | cpustate->dmas[channel].d += 1; |
| 435 | | cpustate->cycles += 5; |
| 436 | | break; |
| 437 | | } |
| 395 | int irq = 0; |
| 438 | 396 | |
| 439 | | cpustate->dmac[channel].w.l -= 1; |
| 397 | while( irq < NUM_MASKABLE_IRQS && irq_vector_map[irq].vector != vector ) |
| 398 | irq++; |
| 440 | 399 | |
| 441 | | if ( cpustate->dmac[channel].w.l == 0 ) |
| 400 | /* Check if our interrupt flip-flop is set */ |
| 401 | if ( irq < NUM_MASKABLE_IRQS && cpustate->reg[irq_vector_map[irq].reg] & irq_vector_map[irq].iff ) |
| 442 | 402 | { |
| 443 | | cpustate->reg[0x7c + channel] = 0; |
| 444 | | switch( channel ) |
| 403 | switch( cpustate->dmam[channel].b.l & 0x1f ) |
| 445 | 404 | { |
| 446 | | case 0: |
| 447 | | cpustate->reg[INTETC10] |= 0x08; |
| 405 | case 0x00: |
| 406 | WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) ); |
| 407 | cpustate->dmad[channel].d += 1; |
| 408 | cpustate->cycles += 8; |
| 448 | 409 | break; |
| 449 | | case 1: |
| 450 | | cpustate->reg[INTETC10] |= 0x80; |
| 410 | case 0x01: |
| 411 | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 412 | cpustate->dmad[channel].d += 2; |
| 413 | cpustate->cycles += 8; |
| 451 | 414 | break; |
| 452 | | case 2: |
| 453 | | cpustate->reg[INTETC32] |= 0x08; |
| 415 | case 0x02: |
| 416 | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 417 | cpustate->dmad[channel].d += 4; |
| 418 | cpustate->cycles += 12; |
| 454 | 419 | break; |
| 455 | | case 3: |
| 456 | | cpustate->reg[INTETC32] |= 0x80; |
| 420 | case 0x04: |
| 421 | WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) ); |
| 422 | cpustate->dmad[channel].d -= 1; |
| 423 | cpustate->cycles += 8; |
| 457 | 424 | break; |
| 425 | case 0x05: |
| 426 | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 427 | cpustate->dmad[channel].d -= 2; |
| 428 | cpustate->cycles += 8; |
| 429 | break; |
| 430 | case 0x06: |
| 431 | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 432 | cpustate->dmad[channel].d -= 4; |
| 433 | cpustate->cycles += 12; |
| 434 | break; |
| 435 | case 0x08: |
| 436 | WRMEM( cpustate->dmad[channel].d, RDMEM( cpustate->dmas[channel].d ) ); |
| 437 | cpustate->dmas[channel].d += 1; |
| 438 | cpustate->cycles += 8; |
| 439 | break; |
| 440 | case 0x09: |
| 441 | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 442 | cpustate->dmas[channel].d += 2; |
| 443 | cpustate->cycles += 8; |
| 444 | break; |
| 445 | case 0x0a: |
| 446 | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 447 | cpustate->dmas[channel].d += 4; |
| 448 | cpustate->cycles += 12; |
| 449 | break; |
| 450 | case 0x0c: |
| 451 | WRMEM( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 452 | cpustate->dmas[channel].d -= 1; |
| 453 | cpustate->cycles += 8; |
| 454 | break; |
| 455 | case 0x0d: |
| 456 | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 457 | cpustate->dmas[channel].d -= 2; |
| 458 | cpustate->cycles += 8; |
| 459 | break; |
| 460 | case 0x0e: |
| 461 | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 462 | cpustate->dmas[channel].d -= 4; |
| 463 | cpustate->cycles += 12; |
| 464 | break; |
| 465 | case 0x10: |
| 466 | WRMEM( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 467 | cpustate->cycles += 8; |
| 468 | break; |
| 469 | case 0x11: |
| 470 | WRMEMW( cpustate->dmad[channel].d, RDMEMW( cpustate->dmas[channel].d ) ); |
| 471 | cpustate->cycles += 8; |
| 472 | break; |
| 473 | case 0x12: |
| 474 | WRMEML( cpustate->dmad[channel].d, RDMEML( cpustate->dmas[channel].d ) ); |
| 475 | cpustate->cycles += 12; |
| 476 | break; |
| 477 | case 0x14: |
| 478 | cpustate->dmas[channel].d += 1; |
| 479 | cpustate->cycles += 5; |
| 480 | break; |
| 458 | 481 | } |
| 482 | |
| 483 | cpustate->dmac[channel].w.l -= 1; |
| 484 | |
| 485 | if ( cpustate->dmac[channel].w.l == 0 ) |
| 486 | { |
| 487 | cpustate->reg[0x7c + channel] = 0; |
| 488 | switch( channel ) |
| 489 | { |
| 490 | case 0: |
| 491 | cpustate->reg[INTETC10] |= 0x08; |
| 492 | break; |
| 493 | case 1: |
| 494 | cpustate->reg[INTETC10] |= 0x80; |
| 495 | break; |
| 496 | case 2: |
| 497 | cpustate->reg[INTETC32] |= 0x08; |
| 498 | break; |
| 499 | case 3: |
| 500 | cpustate->reg[INTETC32] |= 0x80; |
| 501 | break; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | /* Clear the interrupt flip-flop */ |
| 506 | cpustate->reg[irq_vector_map[irq].reg] &= ~irq_vector_map[irq].iff; |
| 507 | |
| 508 | return 1; |
| 459 | 509 | } |
| 460 | 510 | } |
| 511 | return 0; |
| 461 | 512 | } |
| 462 | 513 | |
| 463 | 514 | |
| 515 | INLINE void tlcs900_check_hdma( tlcs900_state *cpustate ) |
| 516 | { |
| 517 | /* HDMA can only be performed if interrupts are allowed */ |
| 518 | if ( ( cpustate->sr.b.h & 0x70 ) != 0x70 ) |
| 519 | { |
| 520 | if ( ! tlcs900_process_hdma( cpustate, 0 ) ) |
| 521 | { |
| 522 | if ( ! tlcs900_process_hdma( cpustate, 1 ) ) |
| 523 | { |
| 524 | if ( ! tlcs900_process_hdma( cpustate, 2 ) ) |
| 525 | { |
| 526 | tlcs900_process_hdma( cpustate, 3 ); |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | |
| 464 | 534 | INLINE void tlcs900_check_irqs( tlcs900_state *cpustate ) |
| 465 | 535 | { |
| 466 | | #define NUM_MASKABLE_IRQS 22 |
| 467 | | static const struct { |
| 468 | | UINT8 reg; |
| 469 | | UINT8 iff; |
| 470 | | UINT8 vector; |
| 471 | | } irq_vector_map[NUM_MASKABLE_IRQS] = |
| 472 | | { |
| 473 | | { INTETC32, 0x80, 0x80 }, /* INTTC3 */ |
| 474 | | { INTETC32, 0x08, 0x7c }, /* INTTC2 */ |
| 475 | | { INTETC10, 0x80, 0x78 }, /* INTTC1 */ |
| 476 | | { INTETC10, 0x08, 0x74 }, /* INTTC0 */ |
| 477 | | { INTE0AD, 0x80, 0x70 }, /* INTAD */ |
| 478 | | { INTES1, 0x80, 0x6c }, /* INTTX1 */ |
| 479 | | { INTES1, 0x08, 0x68 }, /* INTRX1 */ |
| 480 | | { INTES0, 0x80, 0x64 }, /* INTTX0 */ |
| 481 | | { INTES0, 0x08, 0x60 }, /* INTRX0 */ |
| 482 | | { INTET76, 0x80, 0x5c }, /* INTTR7 */ |
| 483 | | { INTET76, 0x08, 0x58 }, /* INTTR6 */ |
| 484 | | { INTET54, 0x80, 0x54 }, /* INTTR5 */ |
| 485 | | { INTET54, 0x08, 0x50 }, /* INTTR4 */ |
| 486 | | { INTET32, 0x80, 0x4c }, /* INTT3 */ |
| 487 | | { INTET32, 0x08, 0x48 }, /* INTT2 */ |
| 488 | | { INTET10, 0x80, 0x44 }, /* INTT1 */ |
| 489 | | { INTET10, 0x08, 0x40 }, /* INTT0 */ |
| 490 | | /* 0x3c - reserved */ |
| 491 | | { INTE67, 0x80, 0x38 }, /* INT7 */ |
| 492 | | { INTE67, 0x08, 0x34 }, /* INT6 */ |
| 493 | | { INTE45, 0x80, 0x30 }, /* INT5 */ |
| 494 | | { INTE45, 0x08, 0x2c }, /* INT4 */ |
| 495 | | { INTE0AD, 0x08, 0x28 } /* INT0 */ |
| 496 | | }; |
| 497 | 536 | int irq_vectors[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 }; |
| 537 | int level = 0; |
| 498 | 538 | int irq = -1; |
| 499 | 539 | int i; |
| 500 | 540 | |
| r4555 | r4556 | |
| 538 | 578 | if ( irq_vectors[i] >= 0 ) |
| 539 | 579 | { |
| 540 | 580 | irq = irq_vectors[i]; |
| 581 | level = i + 1; |
| 541 | 582 | } |
| 542 | 583 | } |
| 543 | 584 | |
| r4555 | r4556 | |
| 550 | 591 | WRMEML( cpustate->xssp.d, cpustate->pc.d ); |
| 551 | 592 | cpustate->xssp.d -= 2; |
| 552 | 593 | WRMEMW( cpustate->xssp.d, cpustate->sr.w.l ); |
| 594 | |
| 595 | /* Mask off any lower priority interrupts */ |
| 596 | cpustate->sr.b.h = ( cpustate->sr.b.h & 0x8f ) | ( level << 4 ); |
| 597 | |
| 553 | 598 | cpustate->pc.d = RDMEML( 0xffff00 + vector ); |
| 554 | 599 | cpustate->cycles += 18; |
| 555 | 600 | |
| r4555 | r4556 | |
| 557 | 602 | |
| 558 | 603 | /* Clear taken IRQ */ |
| 559 | 604 | cpustate->reg[ irq_vector_map[irq].reg ] &= ~ irq_vector_map[irq].iff; |
| 560 | | |
| 561 | | /* Check if any HDMA actions should be performed */ |
| 562 | | if ( vector >= 0x28 && vector != 0x3C && vector < 0x74 ) |
| 563 | | { |
| 564 | | tlcs900_process_hdma( cpustate, 0, vector >> 2 ); |
| 565 | | tlcs900_process_hdma( cpustate, 1, vector >> 2 ); |
| 566 | | tlcs900_process_hdma( cpustate, 2, vector >> 2 ); |
| 567 | | tlcs900_process_hdma( cpustate, 3, vector >> 2 ); |
| 568 | | } |
| 569 | 605 | } |
| 570 | 606 | } |
| 571 | 607 | |
| r4555 | r4556 | |
| 678 | 714 | |
| 679 | 715 | for( ; cpustate->timer_change[0] > 0; cpustate->timer_change[0]-- ) |
| 680 | 716 | { |
| 717 | //printf("timer0 = %02x, TREG0 = %02x\n", cpustate->timer[0], cpustate->reg[TREG0] ); |
| 681 | 718 | cpustate->timer[0] += 1; |
| 682 | 719 | if ( cpustate->timer[0] == cpustate->reg[TREG0] ) |
| 683 | 720 | { |
| r4555 | r4556 | |
| 856 | 893 | |
| 857 | 894 | tlcs900_handle_timers( cpustate ); |
| 858 | 895 | |
| 896 | tlcs900_check_hdma( cpustate ); |
| 897 | |
| 859 | 898 | cpustate->icount -= cpustate->cycles; |
| 860 | 899 | } while ( cpustate->icount > 0 ); |
| 861 | 900 | |