Previous 15994 Revisions Next

r1647 Saturday 2nd February, 2008 at 14:41:14 UTC by Wilbert Pol
[GBCOLOR] Improved handling of writes to the STAT register.
[src/mess/video]gb.c

src/mess/video/gb.c
r1646r1647
11401140};
11411141
11421142static TIMER_CALLBACK( gb_video_init_vbl ) {
1143   cpunum_set_input_line(machine, 0, VBL_INT, ASSERT_LINE );
1143   cpunum_set_input_line( machine, 0, VBL_INT, ASSERT_LINE );
11441144}
11451145
11461146void gb_video_init( int mode ) {
r1646r1647
13281328            if ( ! gb_lcd.mode_irq ) {
13291329               if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
13301330                  gb_lcd.mode_irq = 1;
1331                  cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1331                  cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
13321332               }
13331333            } else {
13341334               gb_lcd.mode_irq = 0;
r1646r1647
13641364         /* Generate lcd interrupt if requested */
13651365         if ( ! gb_lcd.mode_irq && ( LCDSTAT & 0x08 ) &&
13661366              ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
1367            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1367            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
13681368         }
13691369         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(196 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles,0), GB_LCD_STATE_LYXX_M0_PRE_INC, attotime_never );
13701370         break;
r1646r1647
13761376               if ( ! gb_lcd.mode_irq ) {
13771377                  if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
13781378                     gb_lcd.mode_irq = 1;
1379                     cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1379                     cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
13801380                  }
13811381               } else {
13821382                  gb_lcd.mode_irq = 0;
r1646r1647
13921392         gb_lcd.line_irq = 0;
13931393         if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! gb_lcd.triggering_mode_irq ) {
13941394            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1395            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1395            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
13961396         }
13971397         /* Reset LY==LYC STAT bit */
13981398         LCDSTAT &= 0xFB;
r1646r1647
14061406            if ( ! gb_lcd.mode_irq && gb_lcd.triggering_mode_irq &&
14071407                ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
14081408               gb_lcd.mode_irq = 1;
1409               cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1409               cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
14101410            }
14111411            timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LYXX_M2, attotime_never );
14121412         }
r1646r1647
14181418         gb_lcd.oam_locked = LOCKED;
14191419         /* Generate lcd interrupt if requested */
14201420         if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) {
1421            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1421            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
14221422         }
14231423         /* Check for regular compensation of x-scroll register */
14241424         gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0;
r1646r1647
14321432         /* Generate lcd interrupt if requested */
14331433         if ( ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) ||
14341434             ( ! gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_mode_irq ) ) {
1435            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1435            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
14361436         }
14371437         gb_lcd.line_irq = gb_lcd.triggering_line_irq;
14381438         gb_lcd.triggering_mode_irq = 0;
r1646r1647
14601460      case GB_LCD_STATE_LY9X_M1:      /* Switch to or stay in mode 1 */
14611461         if ( CURLINE == 144 ) {
14621462            /* Trigger VBlank interrupt */
1463            cpunum_set_input_line(machine, 0, VBL_INT, HOLD_LINE );
1463            cpunum_set_input_line( machine, 0, VBL_INT, HOLD_LINE );
14641464            /* Set VBlank lcdstate */
14651465            gb_lcd.mode = 1;
14661466            LCDSTAT = (LCDSTAT & 0xFC) | 0x01;
14671467            /* Trigger LCD interrupt if requested */
14681468            if ( LCDSTAT & 0x10 ) {
1469               cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1469               cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
14701470            }
14711471         }
14721472         /* Check if LY==LYC STAT bit should be set */
r1646r1647
14741474            LCDSTAT |= 0x04;
14751475         }
14761476         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1477            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1477            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
14781478         }
14791479         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(452,0), GB_LCD_STATE_LY9X_M1_INC, attotime_never );
14801480         break;
r1646r1647
14851485         gb_lcd.line_irq = 0;
14861486         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
14871487            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1488            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1488            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
14891489         }
14901490         /* Reset LY==LYC STAT bit */
14911491         LCDSTAT &= 0xFB;
r1646r1647
14991499         /* Check LY=LYC for line #153 */
15001500         if ( gb_lcd.delayed_line_irq ) {
15011501            if ( gb_lcd.triggering_line_irq ) {
1502               cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1502               cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
15031503            }
15041504         }
15051505         gb_lcd.delayed_line_irq = gb_lcd.delayed_line_irq | gb_lcd.line_irq;
r1646r1647
15151515      case GB_LCD_STATE_LY00_M1_1:
15161516         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
15171517            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1518            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1518            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
15191519         }
15201520         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LY00_M1_2, attotime_never );
15211521         break;
15221522      case GB_LCD_STATE_LY00_M1_2:   /* Rest of line #0 during VBlank */
15231523         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
15241524            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1525            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1525            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
15261526         }
15271527         if ( CURLINE == CMPLINE ) {
15281528            LCDSTAT |= 0x04;
r1646r1647
15591559            if ( ! gb_lcd.mode_irq ) {
15601560               if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
15611561                  gb_lcd.mode_irq = 1;
1562                  cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1562                  cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
15631563               }
15641564            } else {
15651565               gb_lcd.mode_irq = 0;
r1646r1647
15961596         /* Generate lcd interrupt if requested */
15971597         if ( ! gb_lcd.mode_irq && gb_lcd.triggering_mode_irq &&
15981598              ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
1599            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1599            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
16001600            gb_lcd.triggering_mode_irq = 0;
16011601         }
16021602         if ( ( SCROLLX & 0x03 ) == 0x03 ) {
r1646r1647
16231623               if ( ! gb_lcd.mode_irq ) {
16241624                  if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) {
16251625                     gb_lcd.mode_irq = 1;
1626                     cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1626                     cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
16271627                  }
16281628               } else {
16291629                  gb_lcd.mode_irq = 0;
r1646r1647
16391639         gb_lcd.line_irq = 0;
16401640         if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) {
16411641            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1642            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1642            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
16431643         }
16441644         gb_lcd.hdma_possible = 0;
16451645         /* Check if we're going into VBlank next */
r1646r1647
16521652            if ( ! gb_lcd.mode_irq && ( LCDSTAT & 0x20 ) &&
16531653                ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) {
16541654               gb_lcd.mode_irq = 1;
1655               cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1655               cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
16561656            }
16571657            timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LYXX_M2, attotime_never );
16581658         }
r1646r1647
16641664         gb_lcd.oam_locked = LOCKED;
16651665         /* Generate lcd interrupt if requested */
16661666         if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) {
1667            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1667            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
16681668         }
16691669         /* Check for regular compensation of x-scroll register */
16701670         gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0;
r1646r1647
16781678         /* Generate lcd interrupt if requested */
16791679         if ( ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) ||
16801680             ( !gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && ( LCDSTAT & 0x20 ) ) ) {
1681            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1681            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
16821682         }
16831683         gb_lcd.line_irq = gb_lcd.triggering_line_irq;
16841684         /* Check if LY==LYC STAT bit should be set */
r1646r1647
17081708      case GB_LCD_STATE_LY9X_M1:      /* Switch to or stay in mode 1 */
17091709         if ( CURLINE == 144 ) {
17101710            /* Trigger VBlank interrupt */
1711            cpunum_set_input_line(machine, 0, VBL_INT, HOLD_LINE );
1711            cpunum_set_input_line( machine, 0, VBL_INT, HOLD_LINE );
17121712            /* Set VBlank lcdstate */
17131713            gb_lcd.mode = 1;
17141714            LCDSTAT = (LCDSTAT & 0xFC) | 0x01;
17151715            /* Trigger LCD interrupt if requested */
17161716            if ( LCDSTAT & 0x10 ) {
1717               cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1717               cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
17181718            }
17191719         }
17201720         /* Check if LY==LYC STAT bit should be set */
r1646r1647
17241724            LCDSTAT &= ~0x04;
17251725         }
17261726         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
1727            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1727            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
17281728         }
17291729         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(452,0), GB_LCD_STATE_LY9X_M1_INC, attotime_never );
17301730         break;
r1646r1647
17351735         gb_lcd.line_irq = 0;
17361736         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
17371737            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1738            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1738            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
17391739         }
17401740         if ( gb_lcd.current_line == 153 ) {
17411741            timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LY00_M1, attotime_never );
r1646r1647
17471747         /* Check LY=LYC for line #153 */
17481748         if ( gb_lcd.delayed_line_irq ) {
17491749            if ( gb_lcd.triggering_line_irq ) {
1750               cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1750               cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
17511751            }
17521752         }
17531753         gb_lcd.delayed_line_irq = gb_lcd.delayed_line_irq | gb_lcd.line_irq;
r1646r1647
17651765      case GB_LCD_STATE_LY00_M1_1:
17661766         if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
17671767            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1768            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1768            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
17691769         }
17701770         timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LY00_M1_2, attotime_never );
17711771         break;
17721772      case GB_LCD_STATE_LY00_M1_2:   /* Rest of line #0 during VBlank */
17731773         if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) {
17741774            gb_lcd.line_irq = gb_lcd.triggering_line_irq;
1775            cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE );
1775            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
17761776         }
17771777         if ( CURLINE == CMPLINE ) {
17781778            LCDSTAT |= 0x04;
r1646r1647
18091809      LCDSTAT |= 0x04;
18101810      /* Generate lcd interrupt if requested */
18111811      if ( LCDSTAT & 0x40 ) {
1812         cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE );
1812         cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
18131813      }
18141814   }
18151815   gb_lcd.state = GB_LCD_STATE_LY00_M2;
r1646r1647
18901890            ( ( LCDSTAT & 0x60 ) == 0x00 && ( data & 0x60 ) == 0x20 ) ||
18911891            ( ( LCDSTAT & 0x60 ) == 0x20 && ( data & 0x40 ) )
18921892            ) ) {
1893            cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE);
1893            cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
18941894         }
18951895         /*
18961896            - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger
r1646r1647
18981898            - 0x00 -> 0xXX (mode 0) - trigger stat bug
18991899         */
19001900         if ( gb_lcd.mode_irq && gb_lcd.mode == 0 ) {
1901            cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE);
1901            cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
19021902         }
19031903      }
19041904      break;
r1646r1647
19111911               LCDSTAT |= 0x04;
19121912               /* Generate lcd interrupt if requested */
19131913               if ( LCDSTAT & 0x40 ) {
1914                  cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE );
1914                  cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
19151915               }
19161916            }
19171917         } else {
r1646r1647
20112011            - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger
20122012         */
20132013         if ( gb_lcd.mode_irq && gb_lcd.mode == 0 && ( LCDSTAT & 0x28 ) == 0x20 && ( data & 0x08 ) ) {
2014            cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE);
2014            cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
20152015         }
2016         /* Check if line irqs are being disabled */
2017         if ( ! ( data & 0x40 ) ) {
2018            gb_lcd.delayed_line_irq = 0;
2019         }
2020         /* Check if line irqs are being enabled */
2021         if ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) ) {
2022            if ( CMPLINE == CURLINE ) {
2023               gb_lcd.line_irq = 1;
2024               cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
2025            }
2026         }
20162027      }
20172028      break;
20182029   case 0x05:                      /* LYC */
r1646r1647
20222033            LCDSTAT |= 0x04;
20232034            /* Generate lcd interrupt if requested */
20242035            if ( LCDSTAT & 0x40 ) {
2025               cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE );
2036               cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
20262037            }
20272038         } else {
20282039            LCDSTAT &= 0xFB;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team