Previous 15994 Revisions Next

r1407 Thursday 13th December, 2007 at 22:00:56 UTC by Wilbert Pol
[GAMEBOY] Several fixes to the video timing.
[docs]messnew.txt
[src/mess/video]gb.c

src/mess/video/gb.c
r1406r1407
8585   int   end_x;            /* Pixel to end drawing (exclusive) */
8686   int mode;            /* Keep track of internal STAT mode */
8787   int lcd_irq_line;
88   int triggering_line_irq;
8889   int line_irq;
8990   int mode_irq;
9091   int delayed_line_irq;
92   int scrollx_adjust;
9193   struct layer_struct   layer[2];
9294   emu_timer   *lcd_timer;
9395} gb_lcd;
r1406r1407
11401142
11411143enum {
11421144   GB_LCD_STATE_LYXX_M3=1,
1145   GB_LCD_STATE_LYXX_PRE_M0,
11431146   GB_LCD_STATE_LYXX_M0,
1144   GB_LCD_STATE_LYXX_M0_2,
11451147   GB_LCD_STATE_LYXX_M0_PRE_INC,
11461148   GB_LCD_STATE_LYXX_M0_INC,
11471149   GB_LCD_STATE_LY00_M2,
r1406r1407
11591161   int mode = param;
11601162   if ( LCDCONT & 0x80 ) {
11611163      switch( mode ) {
1164      case GB_LCD_STATE_LYXX_PRE_M0:   /* Just before switching to mode 0 */
1165         gb_lcd.mode = 0;
1166         if ( LCDSTAT & 0x08 ) {
1167            if ( ! gb_lcd.mode_irq ) {
1168               if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
1169                  gb_lcd.mode_irq = 1;
1170                  cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
1171               }
1172            } else {
1173               gb_lcd.mode_irq = 0;
1174            }
1175         }
1176         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LYXX_M0, attotime_never );
1177         break;
11621178      case GB_LCD_STATE_LYXX_M0:      /* Switch to mode 0 */
11631179         /* update current scanline */
11641180         update_scanline();
r1406r1407
11781194         /* Check for HBLANK DMA */
11791195         if( gbc_hdma_enabled )
11801196            gbc_hdma(0x10);
1181         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(196 - 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M0_PRE_INC, attotime_never );
1197         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(196 - gb_lcd.scrollx_adjust - 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M0_PRE_INC, attotime_never );
11821198         break;
11831199      case GB_LCD_STATE_LYXX_M0_PRE_INC:   /* Just before incrementing the line counter go to mode 2 internally */
11841200         if ( CURLINE < 143 ) {
11851201            gb_lcd.mode = 2;
1186            if ( ! gb_lcd.mode_irq ) {
1187               if ( ( LCDSTAT & 0x20 ) && ( LCDSTAT & 0x40 ) && ( CMPLINE == CURLINE + 1 ) ) {
1188                  gb_lcd.mode_irq = 1;
1189                  cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
1202            if ( LCDSTAT & 0x20 ) {
1203               if ( ! gb_lcd.mode_irq ) {
1204                  if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
1205                     gb_lcd.mode_irq = 1;
1206                     cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
1207                  }
1208               } else {
1209                  gb_lcd.mode_irq = 0;
11901210               }
11911211            }
11921212         }
r1406r1407
11951215      case GB_LCD_STATE_LYXX_M0_INC:   /* Increment LY, stay in M0 for 4 more cycles */
11961216         gb_increment_scanline();
11971217         gb_lcd.delayed_line_irq = gb_lcd.line_irq;
1198         gb_lcd.line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
1199         if ( ! gb_lcd.delayed_line_irq && gb_lcd.line_irq && ! ( LCDSTAT & 0x20 ) ) {
1218         gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
1219         gb_lcd.line_irq = 0;
1220         if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) {
1221            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
12001222            cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
12011223         }
12021224         /* Reset LY==LYC STAT bit */
r1406r1407
12091231            gb_lcd.mode = 2;
12101232            /* Generate lcd interrupt if requested */
12111233            if ( ! gb_lcd.mode_irq && ( LCDSTAT & 0x20 ) &&
1212                ( ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
1234                ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
12131235               gb_lcd.mode_irq = 1;
12141236               cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
1215            } else {
1216               gb_lcd.mode_irq = 0;
12171237            }
12181238            timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LYXX_M2, attotime_never );
12191239         }
r1406r1407
12231243         gb_lcd.mode = 2;
12241244         LCDSTAT = ( LCDSTAT & 0xFC ) | 0x02;
12251245         /* Generate lcd interrupt if requested */
1226         if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq ) {
1246         if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) {
12271247            cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
12281248         }
12291249         /* Mode 2 lasts approximately 80 clock cycles */
r1406r1407
12331253         /* Update STAT register to the correct state */
12341254         LCDSTAT = (LCDSTAT & 0xFC) | 0x02;
12351255         /* Generate lcd interrupt if requested */
1236         if ( ( gb_lcd.delayed_line_irq && gb_lcd.line_irq && ! ( LCDSTAT & 0x20 ) ) ||
1256         if ( ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) ||
12371257             ( !gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && ( LCDSTAT & 0x20 ) ) ) {
12381258            cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
12391259         }
1260         gb_lcd.line_irq = gb_lcd.triggering_line_irq;
12401261         /* Check if LY==LYC STAT bit should be set */
12411262         if ( CURLINE == CMPLINE ) {
12421263            LCDSTAT |= 0x04;
r1406r1407
12491270         /* Set Mode 3 lcdstate */
12501271         gb_lcd.mode = 3;
12511272         LCDSTAT = (LCDSTAT & 0xFC) | 0x03;
1273         /* Check for compensations of x-scroll register */
1274         if ( ( SCROLLX & 0x07 ) > 2 ) {
1275            gb_lcd.scrollx_adjust = 4;
1276         } else {
1277            gb_lcd.scrollx_adjust = 0;
1278         }
12521279         /* Mode 3 lasts for approximately 172+#sprites*10 clock cycles */
1253         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(172 + 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M0, attotime_never );
1280         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(168 + gb_lcd.scrollx_adjust + 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_PRE_M0, attotime_never );
12541281         gb_lcd.start_x = 0;
12551282         break;
12561283      case GB_LCD_STATE_LY9X_M1:      /* Switch to or stay in mode 1 */
r1406r1407
12921319            if ( gb_lcd.line_irq ) {
12931320               cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
12941321            }
1295         } else {
1296            gb_lcd.delayed_line_irq = gb_lcd.line_irq;
12971322         }
1323         gb_lcd.delayed_line_irq = gb_lcd.delayed_line_irq | gb_lcd.line_irq;
12981324         if ( CURLINE == CMPLINE ) {
12991325            LCDSTAT |= 0x04;
13001326         }
13011327         gb_increment_scanline();
1302         gb_lcd.line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
1303//         if ( ! gb_lcd.delayed_line_irq && gb_lcd.line_irq ) {
1304//            cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
1305//         }
1328         gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
1329         gb_lcd.line_irq = 0;
13061330         LCDSTAT &= 0xFB;
13071331         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4/*8*/,0), GB_LCD_STATE_LY00_M1_1, attotime_never );
13081332         break;
13091333      case GB_LCD_STATE_LY00_M1_1:
1310         if ( ! gb_lcd.delayed_line_irq && gb_lcd.line_irq ) {
1334         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1335            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
13111336            cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
13121337         }
13131338         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LY00_M1_2, attotime_never );
13141339         break;
13151340      case GB_LCD_STATE_LY00_M1_2:   /* Rest of line #0 during VBlank */
1316         if ( gb_lcd.delayed_line_irq && gb_lcd.line_irq ) {
1341         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1342            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
13171343            cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
13181344         }
13191345         if ( CURLINE == CMPLINE ) {
r1406r1407
13871413}
13881414
13891415WRITE8_HANDLER ( gb_video_w ) {
1416   gb_video_up_to_date();
13901417   switch (offset) {
13911418   case 0x00:                  /* LCDC - LCD Control */
13921419      gb_chrgen = gb_vram + ((data & 0x10) ? 0x0000 : 0x0800);
r1406r1407
14111438         interrupt to be triggered.
14121439       */
14131440      if ( LCDCONT & 0x80 ) {
1414         /* Are these triggers correct? */
1415         if ( ( gb_lcd.mode != 2 ) || ( ! ( data & 0x40 ) && ! ( LCDSTAT & 0x40 ) ) ) {
1441         /* Triggers seen so far:
1442            - 0x40 -> 0x00 - trigger
1443            - 0x00 -> 0x08 - trigger
1444            - 0x08 -> 0x00 - don't trigger
1445            - 0x00 -> 0x20 (mode 3) - trigger
1446            - 0x00 -> 0x60 (mode 2) - don't trigger
1447            - 0x20 -> 0x60 (mode 3) - trigger
1448            - 0x20 -> 0x40 (mode 3) - trigger
1449            - 0x40 -> 0x20 (mode 2) - don't trigger
1450            - 0x00 -> 0x40 - trigger only if LY==LYC
1451         */
1452         if ( ! gb_lcd.mode_irq && ( ( gb_lcd.mode == 1 ) ||
1453            ( ( LCDSTAT & 0x40 ) && ! ( data & 0x60 ) ) ||
1454            ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) && ( LCDSTAT & 0x04 ) ) ||
1455            ( ! ( LCDSTAT & 0x08 ) && ( data & 0x08 ) ) ||
1456            ( ( LCDSTAT & 0x60 ) == 0x00 && ( data & 0x60 ) == 0x20 ) ||
1457            ( ( LCDSTAT & 0x60 ) == 0x20 && ( data & 0x40 ) )
1458            ) ) {
14161459            cpunum_set_input_line(0, LCD_INT, HOLD_LINE);
14171460         }
1418         if ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) ) {
1419            if ( LCDSTAT & 0x04 ) {
1420               cpunum_set_input_line( 0, LCD_INT, HOLD_LINE );
1421            }
1422         }
14231461      }
14241462      break;
14251463   case 0x04:                  /* LY - LCD Y-coordinate */
r1406r1407
14341472            }
14351473         } else {
14361474            LCDSTAT &= 0xFB;
1475            gb_lcd.triggering_line_irq = 0;
14371476         }
14381477      }
14391478      break;
r1406r1407
14821521   static const UINT16 gbc_to_gb_pal[4] = {32767, 21140, 10570, 0};
14831522   static UINT16 BP = 0, OP = 0;
14841523
1524   gb_video_up_to_date();
14851525   switch( offset ) {
14861526   case 0x00:      /* LCDC - LCD Control */
14871527      gb_chrgen = GBC_VRAMMap[0] + ((data & 0x10) ? 0x0000 : 0x0800);
r1406r1407
14961536         LCDSTAT &= ~0x03;
14971537         CURLINE = 0;
14981538      }
1499                /* If LCD is being switched on */
1500                if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) {
1539      /* If LCD is being switched on */
1540      if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) {
15011541         gb_lcd_switch_on();
1502                }
1542      }
15031543      break;
15041544   case 0x01:      /* STAT - LCD Status */
15051545      data = 0x80 | (data & 0x78) | (LCDSTAT & 0x07);
docs/messnew.txt
r1406r1407
1212
1313- [FAMICOM] Fixed reads to $4031-2 when a disk is not mounted.  [MAMEPlus Team]
1414
15- [GAMEBOY] Several fixes to the video timing.  [Wilbert Pol]
16
1517- [QL] Added sound. [Curt Coder]
1618
1719- [SG1000] Fixed keyboard/joystick detection. (bug #1444) [Curt Coder]

Previous 15994 Revisions Next


© 1998-2018 The MESS Team