src/mess/video/gb.c
| r1645 | r1646 | |
| 81 | 81 | |
| 82 | 82 | /* Things used to render current line */ |
| 83 | 83 | int current_line; /* Current line */ |
| 84 | int cmp_line; /* Compare line */ |
| 84 | 85 | int sprCount; /* Number of sprites on current line */ |
| 85 | 86 | int sprite[10]; /* References to sprites to draw on current line */ |
| 86 | 87 | int previous_line; /* Previous line we've drawn in */ |
| 87 | 88 | int start_x; /* Pixel to start drawing from (inclusive) */ |
| 88 | 89 | int end_x; /* Pixel to end drawing (exclusive) */ |
| 89 | 90 | int mode; /* Keep track of internal STAT mode */ |
| 91 | int state; /* Current state of the video state machine */ |
| 90 | 92 | int lcd_irq_line; |
| 91 | 93 | int triggering_line_irq; |
| 92 | 94 | int line_irq; |
| r1645 | r1646 | |
| 1315 | 1317 | static TIMER_CALLBACK(gb_lcd_timer_proc) |
| 1316 | 1318 | { |
| 1317 | 1319 | static const int sprite_cycles[] = { 0, 8, 20, 32, 44, 52, 64, 76, 88, 96, 108 }; |
| 1318 | | int mode = param; |
| 1319 | 1320 | |
| 1321 | gb_lcd.state = param; |
| 1322 | |
| 1320 | 1323 | if ( LCDCONT & 0x80 ) { |
| 1321 | | switch( mode ) { |
| 1324 | switch( gb_lcd.state ) { |
| 1322 | 1325 | case GB_LCD_STATE_LYXX_PRE_M0: /* Just before switching to mode 0 */ |
| 1323 | 1326 | gb_lcd.mode = 0; |
| 1324 | 1327 | if ( LCDSTAT & 0x08 ) { |
| r1645 | r1646 | |
| 1545 | 1548 | static TIMER_CALLBACK(gbc_lcd_timer_proc) |
| 1546 | 1549 | { |
| 1547 | 1550 | static const int sprite_cycles[] = { 0, 8, 20, 32, 44, 52, 64, 76, 88, 96, 108 }; |
| 1548 | | int mode = param; |
| 1549 | 1551 | |
| 1552 | gb_lcd.state = param; |
| 1553 | |
| 1550 | 1554 | if ( LCDCONT & 0x80 ) { |
| 1551 | | switch( mode ) { |
| 1555 | switch( gb_lcd.state ) { |
| 1552 | 1556 | case GB_LCD_STATE_LYXX_PRE_M0: /* Just before switching to mode 0 */ |
| 1553 | 1557 | gb_lcd.mode = 0; |
| 1554 | 1558 | if ( LCDSTAT & 0x08 ) { |
| r1645 | r1646 | |
| 1612 | 1616 | 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 ); |
| 1613 | 1617 | break; |
| 1614 | 1618 | 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; |
| 1615 | 1620 | if ( CURLINE < 143 ) { |
| 1616 | 1621 | gb_lcd.mode = 2; |
| 1617 | 1622 | if ( LCDSTAT & 0x20 ) { |
| r1645 | r1646 | |
| 1630 | 1635 | case GB_LCD_STATE_LYXX_M0_INC: /* Increment LY, stay in M0 for 4 more cycles */ |
| 1631 | 1636 | gb_increment_scanline(); |
| 1632 | 1637 | 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; |
| 1634 | 1639 | gb_lcd.line_irq = 0; |
| 1635 | 1640 | if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) { |
| 1636 | 1641 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| r1645 | r1646 | |
| 1807 | 1812 | cpunum_set_input_line(Machine, 0, LCD_INT, HOLD_LINE ); |
| 1808 | 1813 | } |
| 1809 | 1814 | } |
| 1815 | gb_lcd.state = GB_LCD_STATE_LY00_M2; |
| 1810 | 1816 | timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(80,0), GB_LCD_STATE_LYXX_M3, attotime_never ); |
| 1811 | 1817 | } |
| 1812 | 1818 | |
| r1645 | r1646 | |
| 1901 | 1907 | case 0x05: /* LYC */ |
| 1902 | 1908 | if ( CMPLINE != data ) { |
| 1903 | 1909 | 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 | } |
| 1908 | 1916 | } |
| 1909 | 1917 | } else { |
| 1910 | 1918 | LCDSTAT &= 0xFB; |
| r1645 | r1646 | |
| 2007 | 2015 | } |
| 2008 | 2016 | } |
| 2009 | 2017 | 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; |
| 2010 | 2034 | case 0x07: /* BGP - GB background palette */ |
| 2011 | 2035 | /* Some GBC games are lazy and still call this */ |
| 2012 | 2036 | if( gbc_mode == GBC_MODE_MONO ) { |