src/mess/video/gb.c
| r1613 | r1614 | |
| 54 | 54 | static UINT8 gb_spal1[4]; /* Sprite 1 palette */ |
| 55 | 55 | static UINT8 *gb_oam; |
| 56 | 56 | UINT8 *gb_vram; |
| 57 | | static double lcd_time; |
| 58 | 57 | static UINT8 *gb_vram_ptr; |
| 59 | | static int gbc_hdma_enabled; |
| 60 | 58 | static UINT8 *gb_chrgen; /* Character generator */ |
| 61 | 59 | static UINT8 *gb_bgdtab; /* Background character table */ |
| 62 | 60 | static UINT8 *gb_wndtab; /* Window character table */ |
| r1613 | r1614 | |
| 100 | 98 | int oam_locked; |
| 101 | 99 | int vram_locked; |
| 102 | 100 | int pal_locked; |
| 101 | int hdma_enabled; |
| 102 | int hdma_possible; |
| 103 | 103 | struct layer_struct layer[2]; |
| 104 | 104 | emu_timer *lcd_timer; |
| 105 | 105 | } gb_lcd; |
| r1613 | r1614 | |
| 1124 | 1124 | GB_LCD_STATE_LYXX_PRE_M0, |
| 1125 | 1125 | GB_LCD_STATE_LYXX_M0, |
| 1126 | 1126 | GB_LCD_STATE_LYXX_M0_SCX3, |
| 1127 | | GB_LCD_STATE_LYXX_M0_HDMA, |
| 1128 | 1127 | GB_LCD_STATE_LYXX_M0_GBC_PAL, |
| 1129 | 1128 | GB_LCD_STATE_LYXX_M0_PRE_INC, |
| 1130 | 1129 | GB_LCD_STATE_LYXX_M0_INC, |
| r1613 | r1614 | |
| 1259 | 1258 | gbc_bgdtab = gbc_wndtab = gb_vram + 0x3C00; |
| 1260 | 1259 | |
| 1261 | 1260 | /* HDMA disabled */ |
| 1262 | | gbc_hdma_enabled = 0; |
| 1261 | gb_lcd.hdma_enabled = 0; |
| 1262 | gb_lcd.hdma_possible = 0; |
| 1263 | 1263 | |
| 1264 | 1264 | /* Make sure the VBlank interrupt is set when the first instruction gets executed */ |
| 1265 | 1265 | timer_set( ATTOTIME_IN_CYCLES(1,0), NULL, 0, gb_video_init_vbl ); |
| r1613 | r1614 | |
| 1296 | 1296 | HDMA3 = 0x1f & (dst >> 8); |
| 1297 | 1297 | HDMA4 = dst & 0xF0; |
| 1298 | 1298 | HDMA5--; |
| 1299 | | if( (HDMA5 & 0x7f) == 0 ) { |
| 1299 | if( (HDMA5 & 0x7f) == 0x7f ) { |
| 1300 | 1300 | HDMA5 = 0xff; |
| 1301 | | gbc_hdma_enabled = 0; |
| 1301 | gb_lcd.hdma_enabled = 0; |
| 1302 | 1302 | } |
| 1303 | 1303 | } |
| 1304 | 1304 | |
| r1613 | r1614 | |
| 1600 | 1600 | break; |
| 1601 | 1601 | case GB_LCD_STATE_LYXX_M0_GBC_PAL: |
| 1602 | 1602 | gb_lcd.pal_locked = UNLOCKED; |
| 1603 | | case GB_LCD_STATE_LYXX_M0_HDMA: |
| 1604 | | /* Check for HBLANK DMA */ |
| 1605 | | if( gbc_hdma_enabled ) |
| 1603 | /* Check for HBLANK DMA */ |
| 1604 | if( gb_lcd.hdma_enabled ) { |
| 1606 | 1605 | gbc_hdma(0x10); |
| 1606 | // cpunum_set_reg( 0, Z80GB_DMA_CYCLES, 36 ); |
| 1607 | } else { |
| 1608 | gb_lcd.hdma_possible = 1; |
| 1609 | } |
| 1607 | 1610 | 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 ); |
| 1608 | 1611 | break; |
| 1609 | 1612 | case GB_LCD_STATE_LYXX_M0_PRE_INC: /* Just before incrementing the line counter go to mode 2 internally */ |
| r1613 | r1614 | |
| 1631 | 1634 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1632 | 1635 | cpunum_set_input_line(machine, 0, LCD_INT, HOLD_LINE ); |
| 1633 | 1636 | } |
| 1637 | gb_lcd.hdma_possible = 0; |
| 1634 | 1638 | /* Check if we're going into VBlank next */ |
| 1635 | 1639 | if ( CURLINE == 144 ) { |
| 1636 | 1640 | timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(4,0), GB_LCD_STATE_LY9X_M1, attotime_never ); |
| r1613 | r1614 | |
| 2047 | 2051 | case 0x15: /* HDMA5 - HBL General DMA - Mode, Length */ |
| 2048 | 2052 | if( !(data & 0x80) ) |
| 2049 | 2053 | { |
| 2050 | | if( gbc_hdma_enabled ) |
| 2054 | if( gb_lcd.hdma_enabled ) |
| 2051 | 2055 | { |
| 2052 | | gbc_hdma_enabled = 0; |
| 2056 | gb_lcd.hdma_enabled = 0; |
| 2053 | 2057 | data = HDMA5 & 0x80; |
| 2054 | 2058 | } |
| 2055 | 2059 | else |
| 2056 | 2060 | { |
| 2057 | 2061 | /* General DMA */ |
| 2058 | 2062 | gbc_hdma( ((data & 0x7F) + 1) * 0x10 ); |
| 2059 | | lcd_time -= ((KEY1 & 0x80)?110:220) + (((data & 0x7F) + 1) * 7.68); |
| 2063 | // cpunum_set_reg( 0, Z80GB_DMA_CYCLES, 4 + ( ( ( data & 0x7F ) + 1 ) * 32 ) ); |
| 2060 | 2064 | data = 0xff; |
| 2061 | 2065 | } |
| 2062 | 2066 | } |
| 2063 | 2067 | else |
| 2064 | 2068 | { |
| 2065 | 2069 | /* H-Blank DMA */ |
| 2066 | | gbc_hdma_enabled = 1; |
| 2070 | gb_lcd.hdma_enabled = 1; |
| 2067 | 2071 | data &= 0x7f; |
| 2072 | gb_vid_regs[offset] = data; |
| 2073 | /* Check if HDMA should be immediately performed */ |
| 2074 | if ( gb_lcd.hdma_possible ) { |
| 2075 | gbc_hdma( 0x10 ); |
| 2076 | // cpunum_set_reg( 0, Z80GB_DMA_CYCLES, 36 ); |
| 2077 | gb_lcd.hdma_possible = 0; |
| 2078 | } |
| 2068 | 2079 | } |
| 2069 | 2080 | break; |
| 2070 | 2081 | case 0x28: /* BCPS - Background palette specification */ |