src/mess/drivers/gba.c
| r5700 | r5701 | |
| 834 | 834 | case 0x0104/4: |
| 835 | 835 | case 0x0108/4: |
| 836 | 836 | case 0x010c/4: |
| 837 | | return gba_state->timer_regs[offset-(0x100/4)]; |
| 837 | { |
| 838 | UINT32 elapsed; |
| 839 | double time, ticks; |
| 840 | int timer = offset-(0x100/4); |
| 841 | |
| 842 | // printf("Read timer reg %x (PC=%x)\n", timer, cpu_get_pc(space->cpu)); |
| 843 | |
| 844 | // update times for |
| 845 | if (gba_state->timer_regs[timer] & 0x800000) |
| 846 | { |
| 847 | time = attotime_to_double(timer_timeelapsed(gba_state->tmr_timer[timer])); |
| 848 | |
| 849 | ticks = (double)(0x10000 - (gba_state->timer_regs[timer] & 0xffff)); |
| 850 | |
| 851 | // printf("time %f ticks %f 1/hz %f\n", time, ticks, 1.0 / gba_state->timer_hz[timer]); |
| 852 | |
| 853 | time *= ticks; |
| 854 | time /= (1.0 / gba_state->timer_hz[timer]); |
| 855 | |
| 856 | elapsed = (UINT32)time; |
| 857 | |
| 858 | // printf("elapsed = %x\n", elapsed); |
| 859 | } |
| 860 | else |
| 861 | { |
| 862 | printf("Reading inactive timer!\n"); |
| 863 | elapsed = 0; |
| 864 | } |
| 865 | |
| 866 | return (gba_state->timer_regs[timer] & 0xffff0000) | (elapsed & 0xffff); |
| 867 | } |
| 838 | 868 | break; |
| 839 | 869 | case 0x0120/4: |
| 840 | 870 | if( (mem_mask) & 0x0000ffff ) |
| r5700 | r5701 | |
| 1616 | 1646 | |
| 1617 | 1647 | final = clocksel / rate; |
| 1618 | 1648 | |
| 1649 | gba_state->timer_hz[offset] = final; |
| 1650 | |
| 1619 | 1651 | // printf("Enabling timer %d @ %f Hz\n", offset, final); |
| 1620 | 1652 | |
| 1621 | 1653 | // enable the timer |