Previous 15994 Revisions Next

r1057 Sunday 30th September, 2007 at 13:28:34 UTC by Wilbert Pol
[GAMEBOY] Small video timing changes and made video timing use enums for readability.
[src/mess/video]gb.c

src/mess/video/gb.c
r1056r1057
11841184   gb_lcd.lcd_int_state = lcd_int_state;
11851185}
11861186
1187enum {
1188   GB_LCD_STATE_LY00_M2=1,
1189   GB_LCD_STATE_LYXX_M3,
1190   GB_LCD_STATE_LYXX_M0,
1191   GB_LCD_STATE_LYXX_M2,
1192   GB_LCD_STATE_LY9X_M1,
1193   GB_LCD_STATE_LY00_M1,
1194   GB_LCD_STATE_LY00_M0
1195};
1196
11871197static TIMER_CALLBACK(gb_lcd_timer_proc)
11881198{
11891199   int mode = param;
11901200   if ( LCDCONT & 0x80 ) {
11911201      switch( mode ) {
1192      case 0:      /* Switch to mode 0 */
1202      case GB_LCD_STATE_LYXX_M0:      /* Switch to mode 0 */
11931203         /* update current scanline */
11941204         update_scanline();
11951205         /* Increment the number of window lines drawn if enabled */
r1056r1057
12051215         if( gbc_hdma_enabled )
12061216            gbc_hdma(0x10);
12071217         if ( CURLINE == 143 ) {
1208            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(204 - 10 * gb_lcd.sprCount,0), 1, time_never );
1218            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(204 - 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LY9X_M1, time_never );
12091219         } else {
1210            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(204 - 10 * gb_lcd.sprCount,0), 2, time_never );
1220            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(204 - 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M2, time_never );
12111221         }
12121222         break;
1213      case 2:      /* Switch to mode 2 */
1223      case GB_LCD_STATE_LYXX_M2:      /* Switch to mode 2 */
12141224         gb_increment_scanline();
1215      case 5:      /* on scanline 0, don't increment the current line counter */
12161225         /* Set Mode 2 lcdstate */
12171226         LCDSTAT = (LCDSTAT & 0xFC) | 0x02;
12181227         /* Generate lcd interrupt if requested */
12191228         gb_lcd_int_check();
12201229         /* Mode 2 last for approximately 80 clock cycles */
1221         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), 3, time_never );
1230         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), GB_LCD_STATE_LYXX_M3, time_never );
12221231         break;
1223      case 3:      /* Switch to mode 3 */
1232      case GB_LCD_STATE_LY00_M2:      /* on scanline 0, don't increment the current line counter */
1233         /* Set Mode 2 lcdstate */
1234         LCDSTAT = (LCDSTAT & 0xFC) | 0x02;
1235         /* Generate lcd interrupt if requested */
1236         gb_lcd_int_check();
1237         /* Mode 2 last for approximately 80 clock cycles */
1238         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(76,0), GB_LCD_STATE_LYXX_M3, time_never );
1239         break;
1240      case GB_LCD_STATE_LYXX_M3:      /* Switch to mode 3 */
12241241         gb_select_sprites();
12251242         /* Set Mode 3 lcdstate */
12261243         LCDSTAT = (LCDSTAT & 0xFC) | 0x03;
12271244         gb_lcd_int_check();
12281245         /* Mode 3 lasts for approximately 172+#sprites*10 clock cycles */
1229         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(172 + 10 * gb_lcd.sprCount,0), 0, time_never );
1246         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(172 + 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M0, time_never );
12301247         gb_lcd.start_x = 0;
12311248         break;
1232      case 1:      /* Switch to or stay in mode 1 */
1249      case GB_LCD_STATE_LY9X_M1:      /* Switch to or stay in mode 1 */
12331250         gb_increment_scanline();
12341251         if ( CURLINE == 144 ) {
12351252            /* Trigger VBlank interrupt generation */
r1056r1057
12391256            /* Trigger LCD interrupt if requested */
12401257            gb_lcd_int_check();
12411258         }
1242         if ( gb_lcd.current_line == 153 ) {
1243            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(24,0), 4, time_never );
1244         } else {
1245            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456,0), 1, time_never );
1259         switch( gb_lcd.current_line ) {
1260         case 153:
1261            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(6,0), GB_LCD_STATE_LY00_M1, time_never );
1262            break;
1263         case 152:
1264            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(452,0), GB_LCD_STATE_LY9X_M1, time_never );
1265            break;
1266         default:
1267            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456,0), GB_LCD_STATE_LY9X_M1, time_never );
12461268         }
12471269         break;
1248      case 4:      /* we stay in VBlank but current line counter should already be incremented */
1270      case GB_LCD_STATE_LY00_M1:      /* we stay in VBlank but current line counter should already be incremented */
12491271         gb_increment_scanline();
1250         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456-24,0), 5, time_never );
1272         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456-(2),0), GB_LCD_STATE_LY00_M0, time_never );
12511273         break;
1274      case GB_LCD_STATE_LY00_M0:      /* The STAT register seems to go to 0 for about 4 cycles */
1275         /* Set Mode 0 lcdstat */
1276         LCDSTAT = ( LCDSTAT & 0xFC );
1277         gb_lcd_int_check();
1278         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(4,0), GB_LCD_STATE_LY00_M2, time_never );
1279         break;
1280
12521281      }
12531282   } else {
12541283      gb_increment_scanline();
r1056r1057
12701299      /* Generate lcd interrupt if requested */
12711300      gb_lcd_int_check();
12721301   }
1273   mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), 3, time_never );
1302   mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), GB_LCD_STATE_LYXX_M3, time_never );
12741303}
12751304
12761305READ8_HANDLER( gb_video_r ) {
1277   /* When reading STAT make sure the timers are up to date */
1278   if ( offset == 0x01 ) {
1306if ( offset == 0x01 || offset == 0x04 ) {
1307   if ( 0 && activecpu_get_pc() > 0x100 ) {
1308      logerror("LCDSTAT/LY read, cycles left is %d\n", (int)MAME_TIME_TO_CYCLES(0,mame_timer_timeleft( gb_lcd.lcd_timer )) );
1309   }
1310   if ( offset == 0x01 || (int)MAME_TIME_TO_CYCLES(0,mame_timer_timeleft( gb_lcd.lcd_timer)) < 0 )
12791311      mame_timer_set_global_time(mame_timer_get_time());
1280   }
1312}
12811313   return gb_vid_regs[offset];
12821314}
12831315

Previous 15994 Revisions Next


© 1998-2018 The MESS Team