Previous 15994 Revisions Next

r1090 Monday 8th October, 2007 at 15:01:48 UTC by Wilbert Pol
[GAMEBOY] Fixed the 16 cycle period counter missing timer increments on longer operations.
[src/mess/machine]gb.c

src/mess/machine/gb.c
r1089r1090
136136WRITE8_HANDLER( gb_rom_bank_mmm01_2000_w );
137137WRITE8_HANDLER( gb_rom_bank_mmm01_4000_w );
138138WRITE8_HANDLER( gb_rom_bank_mmm01_6000_w );
139static void gb_timer_increment( void );
139140
140141#ifdef MAME_DEBUG
141142/* #define V_GENERAL*/      /* Display general debug information */
r1089r1090
646647
647648WRITE8_HANDLER ( gb_io_w )
648649{
649   static UINT8 timer_shifts[4] = {10, 4, 6, 8};
650   static const UINT8 timer_shifts[4] = {10, 4, 6, 8};
650651
651652   switch (offset)
652653   {
r1089r1090
677678   case 0x04:                  /* DIV - Divider register */
678679      /* Force increment of TIMECNT register */
679680      if ( gb_divcount >= 16 )
680         gb_timer_callback( 1024 );
681         gb_timer_increment();
681682      gb_divcount = 0;
682683      return;
683684   case 0x05:                  /* TIMA - Timer counter */
r1089r1090
687688   case 0x07:                  /* TAC - Timer control */
688689      data |= 0xF8;
689690      gb_timer_shift = timer_shifts[data & 0x03];
691      gb_timer_count = 1 << gb_timer_shift;
690692      /* Check if timer is just enabled */
691693      if ( ( data & 0x04 ) && ! ( TIMEFRQ & 0x04 ) ) {
692694         TIMECNT = TIMEMOD;
r1089r1090
17291731   }
17301732}
17311733
1734static void gb_timer_increment( void ) {
1735   TIMECNT += 1;
1736   if ( TIMECNT == 0 ) {
1737      TIMECNT = TIMEMOD;
1738      cpunum_set_input_line( 0, TIM_INT, HOLD_LINE );
1739   }
1740}
1741
17321742void gb_timer_callback(int cycles) {
17331743   UINT16 old_gb_divcount = gb_divcount;
17341744   gb_divcount += cycles;
17351745   if ( TIMEFRQ & 0x04 ) {
17361746      UINT16 old_count = old_gb_divcount >> gb_timer_shift;
17371747      UINT16 new_count = gb_divcount >> gb_timer_shift;
1748      if ( cycles > gb_timer_count ) {
1749         gb_timer_increment();
1750         old_gb_divcount += gb_timer_count;
1751         old_count++;
1752      }
17381753      if ( new_count != old_count ) {
1739         /* this increment is probably not correct when cycles > 1 timer cycle */
1740         TIMECNT += 1;
1741         if ( TIMECNT == 0x00 ) {
1742            TIMECNT = TIMEMOD;
1743            cpunum_set_input_line( 0, TIM_INT, HOLD_LINE );
1744         }
1754         gb_timer_increment();
17451755      }
17461756   }
17471757}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team