Previous 15994 Revisions Next

r1646 Friday 1st February, 2008 at 18:44:26 UTC by Wilbert Pol
[GAMEBOY] Fix some small irq details when incrementing the line counter.
[src/mess/video]gb.c

src/mess/video/gb.c
r1645r1646
8181
8282   /* Things used to render current line */
8383   int   current_line;      /* Current line */
84   int cmp_line;         /* Compare line */
8485   int   sprCount;         /* Number of sprites on current line */
8586   int   sprite[10];         /* References to sprites to draw on current line */
8687   int   previous_line;      /* Previous line we've drawn in */
8788   int   start_x;         /* Pixel to start drawing from (inclusive) */
8889   int   end_x;            /* Pixel to end drawing (exclusive) */
8990   int mode;            /* Keep track of internal STAT mode */
91   int state;            /* Current state of the video state machine */
9092   int lcd_irq_line;
9193   int triggering_line_irq;
9294   int line_irq;
r1645r1646
13151317static TIMER_CALLBACK(gb_lcd_timer_proc)
13161318{
13171319   static const int sprite_cycles[] = { 0, 8, 20, 32, 44, 52, 64, 76, 88, 96, 108 };
1318   int mode = param;
13191320
1321   gb_lcd.state = param;
1322
13201323   if ( LCDCONT & 0x80 ) {
1321      switch( mode ) {
1324      switch( gb_lcd.state ) {
13221325      case GB_LCD_STATE_LYXX_PRE_M0:   /* Just before switching to mode 0 */
13231326         gb_lcd.mode = 0;
13241327         if ( LCDSTAT & 0x08 ) {
r1645r1646
15451548static TIMER_CALLBACK(gbc_lcd_timer_proc)
15461549{
15471550   static const int sprite_cycles[] = { 0, 8, 20, 32, 44, 52, 64, 76, 88, 96, 108 };
1548   int mode = param;
15491551
1552   gb_lcd.state = param;
1553
15501554   if ( LCDCONT & 0x80 ) {
1551      switch( mode ) {
1555      switch( gb_lcd.state ) {
15521556      case GB_LCD_STATE_LYXX_PRE_M0:   /* Just before switching to mode 0 */
15531557         gb_lcd.mode = 0;
15541558         if ( LCDSTAT & 0x08 ) {
r1645r1646
16121616         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(192 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles,0), GB_LCD_STATE_LYXX_M0_PRE_INC, attotime_never );
16131617         break;
16141618      case GB_LCD_STATE_LYXX_M0_PRE_INC:   /* Just before incrementing the line counter go to mode 2 internally */
1619         gb_lcd.cmp_line = CMPLINE;
16151620         if ( CURLINE < 143 ) {
16161621            gb_lcd.mode = 2;
16171622            if ( LCDSTAT & 0x20 ) {
r1645r1646
16301635      case GB_LCD_STATE_LYXX_M0_INC:   /* Increment LY, stay in M0 for 4 more cycles */
16311636         gb_increment_scanline();
16321637         gb_lcd.delayed_line_irq = gb_lcd.line_irq;
1633         gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
1638         gb_lcd.triggering_line_irq = ( ( gb_lcd.cmp_line == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0;
16341639         gb_lcd.line_irq = 0;
16351640         if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) {
16361641            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
r1645r1646
18071812         cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE );
18081813      }
18091814   }
1815   gb_lcd.state = GB_LCD_STATE_LY00_M2;
18101816   timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(80,0), GB_LCD_STATE_LYXX_M3, attotime_never );
18111817}
18121818
r1645r1646
19011907   case 0x05:                  /* LYC */
19021908      if ( CMPLINE != data ) {
19031909         if ( CURLINE == data ) {
1904            LCDSTAT |= 0x04;
1905            /* Generate lcd interrupt if requested */
1906            if ( LCDSTAT & 0x40 ) {
1907               cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE );
1910            if ( gb_lcd.state != GB_LCD_STATE_LYXX_M0_INC && gb_lcd.state != GB_LCD_STATE_LY9X_M1_INC ) {
1911               LCDSTAT |= 0x04;
1912               /* Generate lcd interrupt if requested */
1913               if ( LCDSTAT & 0x40 ) {
1914                  cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE );
1915               }
19081916            }
19091917         } else {
19101918            LCDSTAT &= 0xFB;
r1645r1646
20072015         }
20082016      }
20092017      break;
2018   case 0x05:                      /* LYC */
2019      if ( CMPLINE != data ) {
2020         if ( ( gb_lcd.state != GB_LCD_STATE_LYXX_M0_PRE_INC && CURLINE == data ) ||
2021              ( gb_lcd.state == GB_LCD_STATE_LYXX_M0_INC && gb_lcd.triggering_line_irq ) ) {
2022            LCDSTAT |= 0x04;
2023            /* Generate lcd interrupt if requested */
2024            if ( LCDSTAT & 0x40 ) {
2025               cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE );
2026            }
2027         } else {
2028            LCDSTAT &= 0xFB;
2029            gb_lcd.triggering_line_irq = 0;
2030            gb_lcd.cmp_line = data;
2031         }
2032      }
2033      break;
20102034   case 0x07:      /* BGP - GB background palette */
20112035      /* Some GBC games are lazy and still call this */
20122036      if( gbc_mode == GBC_MODE_MONO ) {

Previous 15994 Revisions Next


© 1998-2018 The MESS Team