Previous 15994 Revisions Next

r1063 Tuesday 2nd October, 2007 at 20:25:09 UTC by Wilbert Pol
[GAMEBOY] Finetuned the video driver state machine a bit more.
[src/mess/video]gb.c

src/mess/video/gb.c
r1062r1063
11341134   gb_lcd.current_line = ( gb_lcd.current_line + 1 ) % 154;
11351135   if ( LCDCONT & 0x80 ) {
11361136      CURLINE = gb_lcd.current_line;
1137      if ( CURLINE == CMPLINE ) {
1138         LCDSTAT |= 0x04;
1139      } else {
1140         LCDSTAT &= 0xFB;
1141      }
1142      /* Generate lcd interrupt if requested */
1143      gb_lcd_int_check();
11441137   }
11451138   if ( gb_lcd.current_line == 0 ) {
11461139      gb_lcd.window_lines_drawn = 0;
r1062r1063
11851178}
11861179
11871180enum {
1188   GB_LCD_STATE_LY00_M2=1,
1189   GB_LCD_STATE_LYXX_M3,
1181   GB_LCD_STATE_LYXX_M3=1,
11901182   GB_LCD_STATE_LYXX_M0,
1183   GB_LCD_STATE_LYXX_M0_INC,
11911184   GB_LCD_STATE_LYXX_M2,
11921185   GB_LCD_STATE_LY9X_M1,
1186   GB_LCD_STATE_LY9X_M1_INC,
11931187   GB_LCD_STATE_LY00_M1,
1188   GB_LCD_STATE_LY00_M1_2,
11941189   GB_LCD_STATE_LY00_M0
11951190};
11961191
r1062r1063
12141209         /* Check for HBLANK DMA */
12151210         if( gbc_hdma_enabled )
12161211            gbc_hdma(0x10);
1217         if ( CURLINE == 143 ) {
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 );
1212         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(200 - 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M0_INC, time_never );
1213         break;
1214      case GB_LCD_STATE_LYXX_M0_INC:   /* Increment LY, stay in M0 for 4 more cycles */
1215         gb_increment_scanline();
1216         /* Reset LY==LYC STAT bit */
1217         LCDSTAT &= 0xFB;
1218         /* Check if we're going into VBlank next */
1219         if ( CURLINE == 144 ) {
1220            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(4,0), GB_LCD_STATE_LY9X_M1, time_never );
12191221         } else {
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 );
1222            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(4,0), GB_LCD_STATE_LYXX_M2, time_never );
12211223         }
12221224         break;
12231225      case GB_LCD_STATE_LYXX_M2:      /* Switch to mode 2 */
1224         gb_increment_scanline();
12251226         /* Set Mode 2 lcdstate */
12261227         LCDSTAT = (LCDSTAT & 0xFC) | 0x02;
1228         /* Check if LY==LYC STAT bit should be set */
1229         if ( CURLINE == CMPLINE )
1230            LCDSTAT |= 0x04;
12271231         /* Generate lcd interrupt if requested */
12281232         gb_lcd_int_check();
12291233         /* Mode 2 last for approximately 80 clock cycles */
12301234         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), GB_LCD_STATE_LYXX_M3, time_never );
12311235         break;
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;
12401236      case GB_LCD_STATE_LYXX_M3:      /* Switch to mode 3 */
12411237         gb_select_sprites();
12421238         /* Set Mode 3 lcdstate */
r1062r1063
12471243         gb_lcd.start_x = 0;
12481244         break;
12491245      case GB_LCD_STATE_LY9X_M1:      /* Switch to or stay in mode 1 */
1250         gb_increment_scanline();
12511246         if ( CURLINE == 144 ) {
12521247            /* Trigger VBlank interrupt generation */
12531248            mame_timer_adjust( gb_lcd.vblank_delay_timer, MAME_TIME_IN_CYCLES(1,0), 0, time_never );
r1062r1063
12561251            /* Trigger LCD interrupt if requested */
12571252            gb_lcd_int_check();
12581253         }
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 );
1254         /* Check if LY==LYC STAT bit should be set */
1255         if ( CURLINE == CMPLINE )
1256            LCDSTAT |= 0x04;
1257         /* Trigger LCD interrupt if requested */
1258         gb_lcd_int_check();
1259         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(452,0), GB_LCD_STATE_LY9X_M1_INC, time_never );
1260         break;
1261      case GB_LCD_STATE_LY9X_M1_INC:      /* Increment scanline counter */
1262         gb_increment_scanline();
1263         /* Reset LY==LYC STAT bit */
1264         LCDSTAT &= 0xFB;
1265         if ( gb_lcd.current_line == 153 ) {
1266            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(4,0), GB_LCD_STATE_LY00_M1, time_never );
1267         } else {
1268            mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(4,0), GB_LCD_STATE_LY9X_M1, time_never );
12681269         }
12691270         break;
12701271      case GB_LCD_STATE_LY00_M1:      /* we stay in VBlank but current line counter should already be incremented */
1272         /* Check LY=LYC for line #153 */
1273         if ( CURLINE == CMPLINE ) {
1274            LCDSTAT |= 0x04;
1275            gb_lcd_int_check();
1276         }
12711277         gb_increment_scanline();
1272         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456-(2),0), GB_LCD_STATE_LY00_M0, time_never );
1278         LCDSTAT &= 0xFB;
1279         /* This 8 cycle period still needs to be verified on hardware */
1280         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(8,0), GB_LCD_STATE_LY00_M1_2, time_never );
12731281         break;
1282      case GB_LCD_STATE_LY00_M1_2:   /* Rest of line #0 during VBlank */
1283         if ( CURLINE == CMPLINE ) {
1284            LCDSTAT |= 0x04;
1285            gb_lcd_int_check();
1286         }
1287         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(444,0), GB_LCD_STATE_LY00_M0, time_never );
1288         break;
12741289      case GB_LCD_STATE_LY00_M0:      /* The STAT register seems to go to 0 for about 4 cycles */
12751290         /* Set Mode 0 lcdstat */
12761291         LCDSTAT = ( LCDSTAT & 0xFC );
12771292         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 );
1293         mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(4,0), GB_LCD_STATE_LYXX_M2, time_never );
12791294         break;
1280
12811295      }
12821296   } else {
12831297      gb_increment_scanline();
r1062r1063
13031317}
13041318
13051319READ8_HANDLER( gb_video_r ) {
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 )
1320//   if ( 0 && activecpu_get_pc() > 0x100 ) {
1321//      logerror("LCDSTAT/LY read, cycles left is %d\n", (int)MAME_TIME_TO_CYCLES(0,mame_timer_timeleft( gb_lcd.lcd_timer )) );
1322//   }
1323   if ( (int)MAME_TIME_TO_CYCLES(0,mame_timer_timeleft( gb_lcd.lcd_timer)) <= 0 )
13111324      mame_timer_set_global_time(mame_timer_get_time());
1312}
13131325   return gb_vid_regs[offset];
13141326}
13151327
13161328/* Ignore write when LCD is on and STAT is 02 or 03 */
13171329int gb_video_oam_locked( void ) {
1330   if ( (int)MAME_TIME_TO_CYCLES(0,mame_timer_timeleft( gb_lcd.lcd_timer)) <= 0 )
1331      mame_timer_set_global_time(mame_timer_get_time());
13181332   if ( ( LCDCONT & 0x80 ) && ( LCDSTAT & 0x02 ) ) {
13191333      return 1;
13201334   }
r1062r1063
13231337
13241338/* Ignore write when LCD is on and STAT is not 03 */
13251339int gb_video_vram_locked( void ) {
1340   if ( (int)MAME_TIME_TO_CYCLES(0,mame_timer_timeleft( gb_lcd.lcd_timer)) <= 0 )
1341      mame_timer_set_global_time(mame_timer_get_time());
13261342   if ( ( LCDCONT & 0x80 ) && ( ( LCDSTAT & 0x03 ) == 0x03 ) ) {
13271343      return 1;
13281344   }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team