src/mess/machine/gamecom.c
| r8746 | r8747 | |
| 40 | 40 | int enabled; |
| 41 | 41 | int state_count; |
| 42 | 42 | int state_limit; |
| 43 | | int counter; |
| 44 | 43 | int check_value; |
| 45 | 44 | } GAMECOM_TIMER; |
| 46 | 45 | |
| r8746 | r8747 | |
| 206 | 205 | break; |
| 207 | 206 | case SM8521_TM0D: |
| 208 | 207 | gamecom_timer[0].check_value = data; |
| 209 | | break; |
| 208 | return; |
| 210 | 209 | case SM8521_TM0C: |
| 211 | 210 | gamecom_timer[0].enabled = data & 0x80; |
| 212 | 211 | gamecom_timer[0].state_limit = gamecom_timer_limit[data & 0x07]; |
| 213 | 212 | gamecom_timer[0].state_count = 0; |
| 214 | | gamecom_timer[0].counter = 0; |
| 213 | RAM[SM8521_TM0D] = 0; |
| 215 | 214 | break; |
| 216 | 215 | case SM8521_TM1D: |
| 217 | 216 | gamecom_timer[1].check_value = data; |
| 218 | | break; |
| 217 | return; |
| 219 | 218 | case SM8521_TM1C: |
| 220 | 219 | gamecom_timer[1].enabled = data & 0x80; |
| 221 | 220 | gamecom_timer[1].state_limit = gamecom_timer_limit[data & 0x07]; |
| 222 | 221 | gamecom_timer[1].state_count = 0; |
| 223 | | gamecom_timer[1].counter = 0; |
| 222 | RAM[SM8521_TM1D] = 0; |
| 224 | 223 | break; |
| 225 | 224 | case SM8521_CLKT: /* bit 6-7 */ |
| 226 | 225 | if ( data & 0x80 ) |
| r8746 | r8747 | |
| 334 | 333 | |
| 335 | 334 | READ8_HANDLER( gamecom_internal_r ) |
| 336 | 335 | { |
| 337 | | /* NPW 22-Dec-2008 - Shouldn't this entire function be moved to an internal memory map of the CPU core? */ |
| 338 | 336 | UINT8 * RAM = memory_region(space->machine, "maincpu"); |
| 339 | | offset += 0x20; |
| 340 | | UINT8 data = RAM[offset]; |
| 341 | | switch( offset ) |
| 342 | | { |
| 343 | | case SM8521_TM0D: return gamecom_timer[0].counter; |
| 344 | | case SM8521_TM1D: return gamecom_timer[1].counter; |
| 345 | | // case SM8521_CLKT: /* bit 0-5 read only, 6-7 read/write */ |
| 346 | | // return ( RAM[offset] & 0xC0 ) | ( clock_timer_val & 0x3F ); |
| 347 | | } |
| 348 | | return data; |
| 337 | return RAM[offset + 0x20]; |
| 349 | 338 | } |
| 350 | 339 | |
| 351 | 340 | WRITE8_HANDLER( gamecom_pio_w ) |
| r8746 | r8747 | |
| 629 | 618 | |
| 630 | 619 | void gamecom_update_timers( running_device *device, int cycles ) |
| 631 | 620 | { |
| 621 | UINT8 * RAM = memory_region(device->machine, "maincpu"); |
| 632 | 622 | if ( gamecom_timer[0].enabled ) |
| 633 | 623 | { |
| 634 | 624 | gamecom_timer[0].state_count += cycles; |
| 635 | 625 | while ( gamecom_timer[0].state_count >= gamecom_timer[0].state_limit ) |
| 636 | 626 | { |
| 637 | 627 | gamecom_timer[0].state_count -= gamecom_timer[0].state_limit; |
| 638 | | gamecom_timer[0].counter++; |
| 639 | | if ( gamecom_timer[0].counter == gamecom_timer[0].check_value ) |
| 628 | RAM[SM8521_TM0D]++; |
| 629 | if ( RAM[SM8521_TM0D] >= gamecom_timer[0].check_value ) |
| 640 | 630 | { |
| 641 | | gamecom_timer[0].counter = 0; |
| 631 | RAM[SM8521_TM0D] = 0; |
| 642 | 632 | cputag_set_input_line(device->machine, "maincpu", TIM0_INT, ASSERT_LINE ); |
| 643 | 633 | } |
| 644 | 634 | } |
| r8746 | r8747 | |
| 649 | 639 | while ( gamecom_timer[1].state_count >= gamecom_timer[1].state_limit ) |
| 650 | 640 | { |
| 651 | 641 | gamecom_timer[1].state_count -= gamecom_timer[1].state_limit; |
| 652 | | gamecom_timer[1].counter++; |
| 653 | | if ( gamecom_timer[1].counter == gamecom_timer[1].check_value ) |
| 642 | RAM[SM8521_TM1D]++; |
| 643 | if ( RAM[SM8521_TM1D] >= gamecom_timer[1].check_value ) |
| 654 | 644 | { |
| 655 | | gamecom_timer[1].counter = 0; |
| 645 | RAM[SM8521_TM1D] = 0; |
| 656 | 646 | cputag_set_input_line(device->machine, "maincpu", TIM1_INT, ASSERT_LINE ); |
| 657 | 647 | } |
| 658 | 648 | } |