src/mess/machine/gb.c
| r1409 | r1410 | |
| 107 | 107 | UINT8 gbLastTama5Command; |
| 108 | 108 | /* Timer related globals */ |
| 109 | 109 | UINT16 gb_divcount; |
| 110 | | UINT8 gb_timer_count; |
| 111 | 110 | UINT8 gb_timer_shift; |
| 112 | 111 | /* Serial I/O related */ |
| 113 | 112 | static UINT32 SIOCount; /* Serial I/O counter */ |
| r1409 | r1410 | |
| 236 | 235 | gb_serial_timer = timer_alloc( gb_serial_timer_proc , NULL); |
| 237 | 236 | timer_enable( gb_serial_timer, 0 ); |
| 238 | 237 | |
| 238 | gb_divcount = 0; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | MACHINE_START( gb ) |
| r1409 | r1410 | |
| 705 | 705 | case 0x07: /* TAC - Timer control */ |
| 706 | 706 | data |= 0xF8; |
| 707 | 707 | gb_timer_shift = timer_shifts[data & 0x03]; |
| 708 | | gb_timer_count = 1 << gb_timer_shift; |
| 709 | 708 | /* Check if timer is just enabled */ |
| 710 | 709 | if ( ( data & 0x04 ) && ! ( TIMEFRQ & 0x04 ) ) { |
| 711 | 710 | TIMECNT = TIMEMOD; |
| r1409 | r1410 | |
| 1762 | 1761 | if ( TIMEFRQ & 0x04 ) { |
| 1763 | 1762 | UINT16 old_count = old_gb_divcount >> gb_timer_shift; |
| 1764 | 1763 | UINT16 new_count = gb_divcount >> gb_timer_shift; |
| 1765 | | if ( cycles > gb_timer_count ) { |
| 1764 | if ( cycles > ( 1 << gb_timer_shift ) ) { |
| 1766 | 1765 | gb_timer_increment(); |
| 1767 | | old_gb_divcount += gb_timer_count; |
| 1766 | old_gb_divcount += ( 1 << gb_timer_shift ); |
| 1768 | 1767 | old_count++; |
| 1769 | 1768 | } |
| 1770 | 1769 | if ( new_count != old_count ) { |