trunk/src/mess/video/gb.c
| r23879 | r23880 | |
| 18 | 18 | #include "cpu/lr35902/lr35902.h" |
| 19 | 19 | #include "includes/gb.h" |
| 20 | 20 | |
| 21 | | #define LCDCONT m_lcd.gb_vid_regs[0x00] /* LCD control register */ |
| 22 | | #define LCDSTAT m_lcd.gb_vid_regs[0x01] /* LCD status register */ |
| 23 | | #define SCROLLY m_lcd.gb_vid_regs[0x02] /* Starting Y position of the background */ |
| 24 | | #define SCROLLX m_lcd.gb_vid_regs[0x03] /* Starting X position of the background */ |
| 25 | | #define CURLINE m_lcd.gb_vid_regs[0x04] /* Current screen line being scanned */ |
| 26 | | #define CMPLINE m_lcd.gb_vid_regs[0x05] /* Gen. int. when scan reaches this line */ |
| 27 | | #define BGRDPAL m_lcd.gb_vid_regs[0x07] /* Background palette */ |
| 28 | | #define SPR0PAL m_lcd.gb_vid_regs[0x08] /* Sprite palette #0 */ |
| 29 | | #define SPR1PAL m_lcd.gb_vid_regs[0x09] /* Sprite palette #1 */ |
| 30 | | #define WNDPOSY m_lcd.gb_vid_regs[0x0A] /* Window Y position */ |
| 31 | | #define WNDPOSX m_lcd.gb_vid_regs[0x0B] /* Window X position */ |
| 32 | | #define KEY1 m_lcd.gb_vid_regs[0x0D] /* Prepare speed switch */ |
| 33 | | #define HDMA1 m_lcd.gb_vid_regs[0x11] /* HDMA source high byte */ |
| 34 | | #define HDMA2 m_lcd.gb_vid_regs[0x12] /* HDMA source low byte */ |
| 35 | | #define HDMA3 m_lcd.gb_vid_regs[0x13] /* HDMA destination high byte */ |
| 36 | | #define HDMA4 m_lcd.gb_vid_regs[0x14] /* HDMA destination low byte */ |
| 37 | | #define HDMA5 m_lcd.gb_vid_regs[0x15] /* HDMA length/mode/start */ |
| 38 | | #define GBCBCPS m_lcd.gb_vid_regs[0x28] /* Backgound palette spec */ |
| 39 | | #define GBCBCPD m_lcd.gb_vid_regs[0x29] /* Backgound palette data */ |
| 40 | | #define GBCOCPS m_lcd.gb_vid_regs[0x2A] /* Object palette spec */ |
| 41 | | #define GBCOCPD m_lcd.gb_vid_regs[0x2B] /* Object palette data */ |
| 21 | #define LCDCONT m_vid_regs[0x00] /* LCD control register */ |
| 22 | #define LCDSTAT m_vid_regs[0x01] /* LCD status register */ |
| 23 | #define SCROLLY m_vid_regs[0x02] /* Starting Y position of the background */ |
| 24 | #define SCROLLX m_vid_regs[0x03] /* Starting X position of the background */ |
| 25 | #define CURLINE m_vid_regs[0x04] /* Current screen line being scanned */ |
| 26 | #define CMPLINE m_vid_regs[0x05] /* Gen. int. when scan reaches this line */ |
| 27 | #define BGRDPAL m_vid_regs[0x07] /* Background palette */ |
| 28 | #define SPR0PAL m_vid_regs[0x08] /* Sprite palette #0 */ |
| 29 | #define SPR1PAL m_vid_regs[0x09] /* Sprite palette #1 */ |
| 30 | #define WNDPOSY m_vid_regs[0x0A] /* Window Y position */ |
| 31 | #define WNDPOSX m_vid_regs[0x0B] /* Window X position */ |
| 32 | #define KEY1 m_vid_regs[0x0D] /* Prepare speed switch */ |
| 33 | #define HDMA1 m_vid_regs[0x11] /* HDMA source high byte */ |
| 34 | #define HDMA2 m_vid_regs[0x12] /* HDMA source low byte */ |
| 35 | #define HDMA3 m_vid_regs[0x13] /* HDMA destination high byte */ |
| 36 | #define HDMA4 m_vid_regs[0x14] /* HDMA destination low byte */ |
| 37 | #define HDMA5 m_vid_regs[0x15] /* HDMA length/mode/start */ |
| 38 | #define GBCBCPS m_vid_regs[0x28] /* Backgound palette spec */ |
| 39 | #define GBCBCPD m_vid_regs[0x29] /* Backgound palette data */ |
| 40 | #define GBCOCPS m_vid_regs[0x2A] /* Object palette spec */ |
| 41 | #define GBCOCPD m_vid_regs[0x2B] /* Object palette data */ |
| 42 | 42 | |
| 43 | 43 | enum { |
| 44 | 44 | UNLOCKED=0, |
| r23879 | r23880 | |
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | 48 | |
| 49 | enum { |
| 50 | GB_LCD_STATE_LYXX_M3=1, |
| 51 | GB_LCD_STATE_LYXX_PRE_M0, |
| 52 | GB_LCD_STATE_LYXX_M0, |
| 53 | GB_LCD_STATE_LYXX_M0_SCX3, |
| 54 | GB_LCD_STATE_LYXX_M0_GBC_PAL, |
| 55 | GB_LCD_STATE_LYXX_M0_PRE_INC, |
| 56 | GB_LCD_STATE_LYXX_M0_INC, |
| 57 | GB_LCD_STATE_LY00_M2, |
| 58 | GB_LCD_STATE_LYXX_M2, |
| 59 | GB_LCD_STATE_LY9X_M1, |
| 60 | GB_LCD_STATE_LY9X_M1_INC, |
| 61 | GB_LCD_STATE_LY00_M1, |
| 62 | GB_LCD_STATE_LY00_M1_1, |
| 63 | GB_LCD_STATE_LY00_M1_2, |
| 64 | GB_LCD_STATE_LY00_M0 |
| 65 | }; |
| 66 | |
| 67 | |
| 49 | 68 | static const unsigned char palette[] = |
| 50 | 69 | { |
| 51 | 70 | /* Simple black and white palette */ |
| r23879 | r23880 | |
| 72 | 91 | }; |
| 73 | 92 | |
| 74 | 93 | /* Initialise the palettes */ |
| 75 | | PALETTE_INIT_MEMBER(gb_state,gb) |
| 94 | PALETTE_INIT_MEMBER(gb_state, gb) |
| 76 | 95 | { |
| 77 | | int ii; |
| 78 | | for( ii = 0; ii < 4; ii++) |
| 96 | for (int i = 0; i < 4; i++) |
| 97 | palette_set_color_rgb(machine(), i, palette[i * 3 + 0], palette[i * 3 + 1], palette[i * 3 + 2]); |
| 98 | } |
| 99 | |
| 100 | PALETTE_INIT_MEMBER(gb_state, gbp) |
| 101 | { |
| 102 | for (int i = 0; i < 4; i++) |
| 103 | palette_set_color_rgb(machine(), i, palette[(i + 4) * 3 + 0], palette[(i + 4) * 3 + 1], palette[(i + 4) * 3 + 2]); |
| 104 | } |
| 105 | |
| 106 | PALETTE_INIT_MEMBER(gb_state, sgb) |
| 107 | { |
| 108 | int r, g, b; |
| 109 | |
| 110 | for (int i = 0; i < 32768; i++) |
| 79 | 111 | { |
| 80 | | palette_set_color_rgb(machine(), ii, palette[ii*3+0], palette[ii*3+1], palette[ii*3+2]); |
| 112 | r = (i & 0x1F) << 3; |
| 113 | g = ((i >> 5) & 0x1F) << 3; |
| 114 | b = ((i >> 10) & 0x1F) << 3; |
| 115 | palette_set_color_rgb(machine(), i, r, g, b); |
| 81 | 116 | } |
| 82 | 117 | } |
| 83 | 118 | |
| 84 | | PALETTE_INIT_MEMBER(gb_state,gbp) |
| 119 | PALETTE_INIT_MEMBER(gb_state, gbc) |
| 85 | 120 | { |
| 86 | | int ii; |
| 87 | | for( ii = 0; ii < 4; ii++) |
| 121 | int r, g, b; |
| 122 | |
| 123 | for (int i = 0; i < 32768; i++) |
| 88 | 124 | { |
| 89 | | palette_set_color_rgb(machine(), ii, palette[(ii + 4)*3+0], palette[(ii + 4)*3+1], palette[(ii + 4)*3+2]); |
| 125 | r = (i & 0x1F) << 3; |
| 126 | g = ((i >> 5) & 0x1F) << 3; |
| 127 | b = ((i >> 10) & 0x1F) << 3; |
| 128 | palette_set_color_rgb(machine(), i, r, g, b); |
| 90 | 129 | } |
| 91 | 130 | } |
| 92 | 131 | |
| 93 | | PALETTE_INIT_MEMBER(gb_state,sgb) |
| 132 | PALETTE_INIT_MEMBER(megaduck_state, megaduck) |
| 94 | 133 | { |
| 95 | | int ii, r, g, b; |
| 134 | for (int i = 0; i < 4; i++) |
| 135 | palette_set_color_rgb(machine(), i, palette_megaduck[i * 3 + 0], palette_megaduck[i * 3 + 1], palette_megaduck[i * 3 + 2]); |
| 136 | } |
| 96 | 137 | |
| 97 | | for( ii = 0; ii < 32768; ii++ ) |
| 138 | |
| 139 | /* OAM contents on power up. |
| 140 | |
| 141 | The OAM area seems contain some kind of unit fingerprint. On each boot |
| 142 | the data is almost always the same. Some random bits are flipped between |
| 143 | different boots. It is currently unknown how much these fingerprints |
| 144 | differ between different units. |
| 145 | |
| 146 | OAM fingerprints taken from Wilbert Pol's own unit. |
| 147 | */ |
| 148 | |
| 149 | static const UINT8 dmg_oam_fingerprint[0x100] = { |
| 150 | 0xD8, 0xE6, 0xB3, 0x89, 0xEC, 0xDE, 0x11, 0x62, 0x0B, 0x7E, 0x48, 0x9E, 0xB9, 0x6E, 0x26, 0xC9, |
| 151 | 0x36, 0xF4, 0x7D, 0xE4, 0xD9, 0xCE, 0xFA, 0x5E, 0xA3, 0x77, 0x60, 0xFC, 0x1C, 0x64, 0x8B, 0xAC, |
| 152 | 0xB6, 0x74, 0x3F, 0x9A, 0x0E, 0xFE, 0xEA, 0xA9, 0x40, 0x3A, 0x7A, 0xB6, 0xF2, 0xED, 0xA8, 0x3E, |
| 153 | 0xAF, 0x2C, 0xD2, 0xF2, 0x01, 0xE0, 0x5B, 0x3A, 0x53, 0x6A, 0x1C, 0x6C, 0x20, 0xD9, 0x22, 0xB4, |
| 154 | 0x8C, 0x38, 0x71, 0x69, 0x3E, 0x93, 0xA3, 0x22, 0xCE, 0x76, 0x24, 0xE7, 0x1A, 0x14, 0x6B, 0xB1, |
| 155 | 0xF9, 0x3D, 0xBF, 0x3D, 0x74, 0x64, 0xCB, 0xF5, 0xDC, 0x9A, 0x53, 0xC6, 0x0E, 0x78, 0x34, 0xCB, |
| 156 | 0x42, 0xB3, 0xFF, 0x07, 0x73, 0xAE, 0x6C, 0xA2, 0x6F, 0x6A, 0xA4, 0x66, 0x0A, 0x8C, 0x40, 0xB3, |
| 157 | 0x9A, 0x3D, 0x39, 0x78, 0xAB, 0x29, 0xE7, 0xC5, 0x7A, 0xDD, 0x51, 0x95, 0x2B, 0xE4, 0x1B, 0xF6, |
| 158 | 0x31, 0x16, 0x34, 0xFE, 0x11, 0xF2, 0x5E, 0x11, 0xF3, 0x95, 0x66, 0xB9, 0x37, 0xC2, 0xAD, 0x6D, |
| 159 | 0x1D, 0xA7, 0x79, 0x06, 0xD7, 0xE5, 0x8F, 0xFA, 0x9C, 0x02, 0x0C, 0x31, 0x8B, 0x17, 0x2E, 0x31, |
| 160 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 161 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 162 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 163 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 164 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 165 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 166 | }; |
| 167 | |
| 168 | static const UINT8 mgb_oam_fingerprint[0x100] = { |
| 169 | 0xB9, 0xE9, 0x0D, 0x69, 0xBB, 0x7F, 0x00, 0x80, 0xE9, 0x7B, 0x79, 0xA2, 0xFD, 0xCF, 0xD8, 0x0A, |
| 170 | 0x87, 0xEF, 0x44, 0x11, 0xFE, 0x37, 0x10, 0x21, 0xFA, 0xFF, 0x00, 0x17, 0xF6, 0x4F, 0x83, 0x03, |
| 171 | 0x3A, 0xF4, 0x00, 0x24, 0xBB, 0xAE, 0x05, 0x01, 0xFF, 0xF7, 0x12, 0x48, 0xA7, 0x5E, 0xF6, 0x28, |
| 172 | 0x5B, 0xFF, 0x2E, 0x10, 0xFF, 0xB9, 0x50, 0xC8, 0xAF, 0x77, 0x2C, 0x1A, 0x62, 0xD7, 0x81, 0xC2, |
| 173 | 0xFD, 0x5F, 0xA0, 0x94, 0xAF, 0xFF, 0x51, 0x20, 0x36, 0x76, 0x50, 0x0A, 0xFD, 0xF6, 0x20, 0x00, |
| 174 | 0xFE, 0xF7, 0xA0, 0x68, 0xFF, 0xFC, 0x29, 0x51, 0xA3, 0xFA, 0x06, 0xC4, 0x94, 0xFF, 0x39, 0x0A, |
| 175 | 0xFF, 0x6C, 0x20, 0x20, 0xF1, 0xAD, 0x0C, 0x81, 0x56, 0xFB, 0x03, 0x82, 0xFF, 0xFF, 0x08, 0x58, |
| 176 | 0x96, 0x7E, 0x01, 0x4D, 0xFF, 0xE4, 0x82, 0xE3, 0x3D, 0xBB, 0x54, 0x00, 0x3D, 0xF3, 0x04, 0x21, |
| 177 | 0xB7, 0x39, 0xCC, 0x10, 0xF9, 0x5B, 0x80, 0x50, 0x3F, 0x6A, 0x1C, 0x21, 0x1F, 0xFA, 0xA8, 0x52, |
| 178 | 0x5F, 0xB3, 0x44, 0xA1, 0x96, 0x1E, 0x00, 0x27, 0x63, 0x77, 0x30, 0x54, 0x37, 0x6F, 0x60, 0x22, |
| 179 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 180 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 181 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 182 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 183 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 184 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 185 | }; |
| 186 | |
| 187 | static const UINT8 cgb_oam_fingerprint[0x100] = { |
| 188 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 189 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 191 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 192 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 193 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 194 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 195 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 196 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 197 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 198 | 0x74, 0xFF, 0x09, 0x00, 0x9D, 0x61, 0xA8, 0x28, 0x36, 0x1E, 0x58, 0xAA, 0x75, 0x74, 0xA1, 0x42, |
| 199 | 0x05, 0x96, 0x40, 0x09, 0x41, 0x02, 0x60, 0x00, 0x1F, 0x11, 0x22, 0xBC, 0x31, 0x52, 0x22, 0x54, |
| 200 | 0x22, 0xA9, 0xC4, 0x00, 0x1D, 0xAD, 0x80, 0x0C, 0x5D, 0xFA, 0x51, 0x92, 0x93, 0x98, 0xA4, 0x04, |
| 201 | 0x22, 0xA9, 0xC4, 0x00, 0x1D, 0xAD, 0x80, 0x0C, 0x5D, 0xFA, 0x51, 0x92, 0x93, 0x98, 0xA4, 0x04, |
| 202 | 0x22, 0xA9, 0xC4, 0x00, 0x1D, 0xAD, 0x80, 0x0C, 0x5D, 0xFA, 0x51, 0x92, 0x93, 0x98, 0xA4, 0x04, |
| 203 | 0x22, 0xA9, 0xC4, 0x00, 0x1D, 0xAD, 0x80, 0x0C, 0x5D, 0xFA, 0x51, 0x92, 0x93, 0x98, 0xA4, 0x04 |
| 204 | }; |
| 205 | |
| 206 | /* |
| 207 | For an AGS in CGB mode this data is: */ |
| 208 | #if 0 |
| 209 | static const UINT8 abs_oam_fingerprint[0x100] = { |
| 210 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 211 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 212 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 213 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 214 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 215 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 216 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 217 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 218 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 219 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 220 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
| 221 | 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, |
| 222 | 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, |
| 223 | 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, |
| 224 | 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, |
| 225 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF |
| 226 | }; |
| 227 | #endif |
| 228 | |
| 229 | |
| 230 | const device_type GB_LCD_DMG = &device_creator<gb_lcd_device>; |
| 231 | const device_type GB_LCD_MGB = &device_creator<mgb_lcd_device>; |
| 232 | const device_type GB_LCD_SGB = &device_creator<sgb_lcd_device>; |
| 233 | const device_type GB_LCD_CGB = &device_creator<cgb_lcd_device>; |
| 234 | |
| 235 | |
| 236 | |
| 237 | gb_lcd_device::gb_lcd_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) |
| 238 | : device_t(mconfig, type, name, tag, owner, clock, shortname, source), |
| 239 | m_sgb_border_hack(0) |
| 240 | { |
| 241 | } |
| 242 | |
| 243 | gb_lcd_device::gb_lcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 244 | : device_t(mconfig, GB_LCD_DMG, "DMG LCD", tag, owner, clock, "dmg_lcd", __FILE__), |
| 245 | m_sgb_border_hack(0) |
| 246 | { |
| 247 | } |
| 248 | |
| 249 | mgb_lcd_device::mgb_lcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 250 | : gb_lcd_device(mconfig, GB_LCD_MGB, "MGB LCD", tag, owner, clock, "mgb_lcd", __FILE__) |
| 251 | { |
| 252 | } |
| 253 | |
| 254 | sgb_lcd_device::sgb_lcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 255 | : gb_lcd_device(mconfig, GB_LCD_SGB, "SGB LCD", tag, owner, clock, "sgb_lcd", __FILE__) |
| 256 | { |
| 257 | } |
| 258 | |
| 259 | cgb_lcd_device::cgb_lcd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 260 | : gb_lcd_device(mconfig, GB_LCD_CGB, "CGB LCD", tag, owner, clock, "cgb_lcd", __FILE__) |
| 261 | { |
| 262 | } |
| 263 | |
| 264 | |
| 265 | //------------------------------------------------- |
| 266 | // device_start - device-specific startup |
| 267 | //------------------------------------------------- |
| 268 | |
| 269 | void gb_lcd_device::common_start() |
| 270 | { |
| 271 | machine().primary_screen->register_screen_bitmap(m_bitmap); |
| 272 | m_oam = auto_alloc_array_clear(machine(), UINT8, 0x100); |
| 273 | |
| 274 | m_lcd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gb_lcd_device::lcd_timer_proc),this)); |
| 275 | machine().save().register_postload(save_prepost_delegate(FUNC(gb_lcd_device::videoptr_restore), this)); |
| 276 | |
| 277 | m_maincpu = machine().device<cpu_device>("maincpu"); |
| 278 | m_screen = machine().device<screen_device>("screen"); |
| 279 | |
| 280 | save_pointer(NAME(m_oam), 0x100); |
| 281 | save_item(NAME(m_window_lines_drawn)); |
| 282 | save_item(NAME(m_vid_regs)); |
| 283 | save_item(NAME(m_bg_zbuf)); |
| 284 | |
| 285 | save_item(NAME(m_cgb_bpal)); |
| 286 | save_item(NAME(m_cgb_spal)); |
| 287 | |
| 288 | save_item(NAME(m_gb_bpal)); |
| 289 | save_item(NAME(m_gb_spal0)); |
| 290 | save_item(NAME(m_gb_spal1)); |
| 291 | |
| 292 | save_item(NAME(m_current_line)); |
| 293 | save_item(NAME(m_cmp_line)); |
| 294 | save_item(NAME(m_sprCount)); |
| 295 | save_item(NAME(m_sprite)); |
| 296 | save_item(NAME(m_previous_line)); |
| 297 | save_item(NAME(m_start_x)); |
| 298 | save_item(NAME(m_end_x)); |
| 299 | save_item(NAME(m_mode)); |
| 300 | save_item(NAME(m_state)); |
| 301 | save_item(NAME(m_lcd_irq_line)); |
| 302 | save_item(NAME(m_triggering_line_irq)); |
| 303 | save_item(NAME(m_line_irq)); |
| 304 | save_item(NAME(m_triggering_mode_irq)); |
| 305 | save_item(NAME(m_mode_irq)); |
| 306 | save_item(NAME(m_delayed_line_irq)); |
| 307 | save_item(NAME(m_sprite_cycles)); |
| 308 | save_item(NAME(m_scrollx_adjust)); |
| 309 | save_item(NAME(m_oam_locked)); |
| 310 | save_item(NAME(m_vram_locked)); |
| 311 | save_item(NAME(m_pal_locked)); |
| 312 | save_item(NAME(m_hdma_enabled)); |
| 313 | save_item(NAME(m_hdma_possible)); |
| 314 | save_item(NAME(m_gbc_mode)); |
| 315 | save_item(NAME(m_gb_tile_no_mod)); |
| 316 | save_item(NAME(m_vram_bank)); |
| 317 | |
| 318 | save_item(NAME(m_gb_chrgen_offs)); |
| 319 | save_item(NAME(m_gb_bgdtab_offs)); |
| 320 | save_item(NAME(m_gb_wndtab_offs)); |
| 321 | save_item(NAME(m_gbc_chrgen_offs)); |
| 322 | save_item(NAME(m_gbc_bgdtab_offs)); |
| 323 | save_item(NAME(m_gbc_wndtab_offs)); |
| 324 | |
| 325 | save_item(NAME(m_layer[0].enabled)); |
| 326 | save_item(NAME(m_layer[0].xindex)); |
| 327 | save_item(NAME(m_layer[0].xshift)); |
| 328 | save_item(NAME(m_layer[0].xstart)); |
| 329 | save_item(NAME(m_layer[0].xend)); |
| 330 | save_item(NAME(m_layer[0].bgline)); |
| 331 | save_item(NAME(m_layer[1].enabled)); |
| 332 | save_item(NAME(m_layer[1].xindex)); |
| 333 | save_item(NAME(m_layer[1].xshift)); |
| 334 | save_item(NAME(m_layer[1].xstart)); |
| 335 | save_item(NAME(m_layer[1].xend)); |
| 336 | save_item(NAME(m_layer[1].bgline)); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | void gb_lcd_device::videoptr_restore() |
| 341 | { |
| 342 | m_layer[0].bg_map = m_vram + m_gb_bgdtab_offs; |
| 343 | m_layer[0].bg_tiles = m_vram + m_gb_chrgen_offs; |
| 344 | m_layer[1].bg_map = m_vram + m_gb_wndtab_offs; |
| 345 | m_layer[1].bg_tiles = m_vram + m_gb_chrgen_offs; |
| 346 | } |
| 347 | |
| 348 | void cgb_lcd_device::videoptr_restore() |
| 349 | { |
| 350 | m_layer[0].bg_map = m_vram + m_gb_bgdtab_offs; |
| 351 | m_layer[0].gbc_map = m_vram + m_gbc_bgdtab_offs; |
| 352 | m_layer[1].bg_map = m_vram + m_gb_wndtab_offs; |
| 353 | m_layer[1].gbc_map = m_vram + m_gbc_wndtab_offs; |
| 354 | } |
| 355 | |
| 356 | |
| 357 | void gb_lcd_device::device_start() |
| 358 | { |
| 359 | common_start(); |
| 360 | |
| 361 | m_vram = auto_alloc_array_clear(machine(), UINT8, 0x2000); |
| 362 | save_pointer(NAME(m_vram), 0x2000); |
| 363 | |
| 364 | memcpy(m_oam, dmg_oam_fingerprint, 0x100); |
| 365 | } |
| 366 | |
| 367 | void mgb_lcd_device::device_start() |
| 368 | { |
| 369 | common_start(); |
| 370 | |
| 371 | m_vram = auto_alloc_array_clear(machine(), UINT8, 0x2000); |
| 372 | save_pointer(NAME(m_vram), 0x2000); |
| 373 | |
| 374 | memcpy(m_oam, mgb_oam_fingerprint, 0x100); |
| 375 | |
| 376 | /* Initialize part of VRAM. This code must be deleted when we have added the bios dump */ |
| 377 | for (int i = 1; i < 0x0d; i++) |
| 98 | 378 | { |
| 99 | | r = (ii & 0x1F) << 3; |
| 100 | | g = ((ii >> 5) & 0x1F) << 3; |
| 101 | | b = ((ii >> 10) & 0x1F) << 3; |
| 102 | | palette_set_color_rgb(machine(), ii, r, g, b ); |
| 379 | m_vram[0x1903 + i] = i; |
| 380 | m_vram[0x1923 + i] = i + 0x0C; |
| 103 | 381 | } |
| 382 | m_vram[0x1910] = 0x19; |
| 383 | } |
| 104 | 384 | |
| 385 | void sgb_lcd_device::device_start() |
| 386 | { |
| 387 | common_start(); |
| 388 | |
| 389 | m_vram = auto_alloc_array_clear(machine(), UINT8, 0x2000); |
| 390 | save_pointer(NAME(m_vram), 0x2000); |
| 391 | |
| 392 | m_sgb_tile_data = auto_alloc_array_clear(machine(), UINT8, 0x2000); |
| 393 | save_pointer(NAME(m_sgb_tile_data), 0x2000); |
| 394 | |
| 105 | 395 | /* Some default colours for non-SGB games */ |
| 106 | 396 | m_sgb_pal[0] = 32767; |
| 107 | 397 | m_sgb_pal[1] = 21140; |
| 108 | 398 | m_sgb_pal[2] = 10570; |
| 109 | 399 | m_sgb_pal[3] = 0; |
| 110 | 400 | /* The rest of the colortable can be black */ |
| 111 | | for( ii = 4; ii < 8*16; ii++ ) |
| 112 | | m_sgb_pal[ii] = 0; |
| 401 | for (int i = 4; i < 8 * 16; i++) |
| 402 | m_sgb_pal[i] = 0; |
| 403 | |
| 404 | save_item(NAME(m_sgb_atf_data)); |
| 405 | save_item(NAME(m_sgb_atf)); |
| 406 | save_item(NAME(m_sgb_pal_data)); |
| 407 | save_item(NAME(m_sgb_pal_map)); |
| 408 | save_item(NAME(m_sgb_pal)); |
| 409 | save_item(NAME(m_sgb_tile_map)); |
| 410 | save_item(NAME(m_sgb_window_mask)); |
| 113 | 411 | } |
| 114 | 412 | |
| 115 | | PALETTE_INIT_MEMBER(gb_state,gbc) |
| 413 | void cgb_lcd_device::device_start() |
| 116 | 414 | { |
| 117 | | int ii, r, g, b; |
| 415 | common_start(); |
| 416 | |
| 417 | m_vram = auto_alloc_array_clear(machine(), UINT8, 0x4000); |
| 418 | save_pointer(NAME(m_vram), 0x4000); |
| 118 | 419 | |
| 119 | | for( ii = 0; ii < 32768; ii++ ) |
| 120 | | { |
| 121 | | r = (ii & 0x1F) << 3; |
| 122 | | g = ((ii >> 5) & 0x1F) << 3; |
| 123 | | b = ((ii >> 10) & 0x1F) << 3; |
| 124 | | palette_set_color_rgb( machine(), ii, r, g, b ); |
| 125 | | } |
| 420 | memcpy(m_oam, cgb_oam_fingerprint, 0x100); |
| 126 | 421 | |
| 422 | |
| 127 | 423 | /* Background is initialised as white */ |
| 128 | | for( ii = 0; ii < 32; ii++ ) |
| 129 | | m_lcd.cgb_bpal[ii] = 32767; |
| 424 | for (int i = 0; i < 32; i++) |
| 425 | m_cgb_bpal[i] = 32767; |
| 130 | 426 | /* Sprites are supposed to be uninitialized, but we'll make them black */ |
| 131 | | for( ii = 0; ii < 32; ii++ ) |
| 132 | | m_lcd.cgb_spal[ii] = 0; |
| 427 | for (int i = 0; i < 32; i++) |
| 428 | m_cgb_spal[i] = 0; |
| 133 | 429 | } |
| 134 | 430 | |
| 135 | | PALETTE_INIT_MEMBER(megaduck_state,megaduck) |
| 431 | |
| 432 | //------------------------------------------------- |
| 433 | // device_reset - device-specific reset |
| 434 | //------------------------------------------------- |
| 435 | |
| 436 | void gb_lcd_device::common_reset() |
| 437 | { |
| 438 | m_window_lines_drawn = 0; |
| 439 | |
| 440 | m_current_line = 0; |
| 441 | m_cmp_line = 0; |
| 442 | m_sprCount = 0; |
| 443 | m_previous_line = 0; |
| 444 | m_start_x = 0; |
| 445 | m_end_x = 0; |
| 446 | m_mode = 0; |
| 447 | m_state = 0; |
| 448 | m_lcd_irq_line = 0; |
| 449 | m_triggering_line_irq = 0; |
| 450 | m_line_irq = 0; |
| 451 | m_triggering_mode_irq = 0; |
| 452 | m_mode_irq = 0; |
| 453 | m_delayed_line_irq = 0; |
| 454 | m_sprite_cycles = 0; |
| 455 | m_scrollx_adjust = 0; |
| 456 | m_oam_locked = 0; |
| 457 | m_vram_locked = 0; |
| 458 | m_pal_locked = 0; |
| 459 | m_gbc_mode = 0; |
| 460 | m_gb_tile_no_mod = 0; |
| 461 | m_vram_bank = 0; |
| 462 | |
| 463 | m_gb_chrgen_offs = 0; |
| 464 | m_gb_bgdtab_offs = 0x1c00; |
| 465 | m_gb_wndtab_offs = 0x1c00; |
| 466 | |
| 467 | memset(&m_vid_regs, 0, sizeof(m_vid_regs)); |
| 468 | memset(&m_bg_zbuf, 0, sizeof(m_bg_zbuf)); |
| 469 | memset(&m_cgb_bpal, 0, sizeof(m_cgb_bpal)); |
| 470 | memset(&m_cgb_spal, 0, sizeof(m_cgb_spal)); |
| 471 | memset(&m_sprite, 0, sizeof(m_sprite)); |
| 472 | memset(&m_layer[0], 0, sizeof(m_layer[0])); |
| 473 | memset(&m_layer[1], 0, sizeof(m_layer[1])); |
| 474 | |
| 475 | // specific reg initialization |
| 476 | m_vid_regs[0x06] = 0xff; |
| 477 | |
| 478 | for (int i = 0x0c; i < _NR_GB_VID_REGS; i++) |
| 479 | m_vid_regs[i] = 0xff; |
| 480 | |
| 481 | LCDSTAT = 0x80; |
| 482 | LCDCONT = 0x00; /* Video hardware is turned off at boot time */ |
| 483 | m_current_line = CURLINE = CMPLINE = 0x00; |
| 484 | SCROLLX = SCROLLY = 0x00; |
| 485 | SPR0PAL = SPR1PAL = 0xFF; |
| 486 | WNDPOSX = WNDPOSY = 0x00; |
| 487 | |
| 488 | // Initialize palette arrays |
| 489 | for (int i = 0; i < 4; i++) |
| 490 | m_gb_bpal[i] = m_gb_spal0[i] = m_gb_spal1[i] = i; |
| 491 | |
| 492 | } |
| 493 | |
| 494 | |
| 495 | void gb_lcd_device::device_reset() |
| 136 | 496 | { |
| 137 | | int ii; |
| 138 | | for( ii = 0; ii < 4; ii++) |
| 139 | | { |
| 140 | | palette_set_color_rgb(machine(), ii, palette_megaduck[ii*3+0], palette_megaduck[ii*3+1], palette_megaduck[ii*3+2]); |
| 141 | | } |
| 497 | common_reset(); |
| 498 | |
| 499 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(456)); |
| 142 | 500 | } |
| 143 | 501 | |
| 502 | void mgb_lcd_device::device_reset() |
| 503 | { |
| 504 | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 505 | common_reset(); |
| 144 | 506 | |
| 145 | | inline void gb_state::gb_plot_pixel(bitmap_ind16 &bitmap, int x, int y, UINT32 color) |
| 507 | /* Make sure the VBlank interrupt is set when the first instruction gets executed */ |
| 508 | machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(1), timer_expired_delegate(FUNC(mgb_lcd_device::video_init_vbl),this)); |
| 509 | |
| 510 | /* Initialize some video registers */ |
| 511 | video_w(space, 0x0, 0x91); /* LCDCONT */ |
| 512 | video_w(space, 0x7, 0xFC); /* BGRDPAL */ |
| 513 | video_w(space, 0x8, 0xFC); /* SPR0PAL */ |
| 514 | video_w(space, 0x9, 0xFC); /* SPR1PAL */ |
| 515 | |
| 516 | CURLINE = m_current_line = 0; |
| 517 | LCDSTAT = (LCDSTAT & 0xF8) | 0x05; |
| 518 | m_mode = 1; |
| 519 | |
| 520 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(60), GB_LCD_STATE_LY00_M0); |
| 521 | } |
| 522 | |
| 523 | void sgb_lcd_device::device_reset() |
| 146 | 524 | { |
| 525 | common_reset(); |
| 526 | |
| 527 | memset(m_sgb_tile_data, 0, 0x2000); |
| 528 | |
| 529 | m_sgb_window_mask = 0; |
| 530 | |
| 531 | memset(m_sgb_pal_map, 0, sizeof(m_sgb_pal_map)); |
| 532 | memset(m_sgb_atf_data, 0, sizeof(m_sgb_atf_data)); |
| 533 | } |
| 534 | |
| 535 | void cgb_lcd_device::device_reset() |
| 536 | { |
| 537 | common_reset(); |
| 538 | |
| 539 | m_gbc_chrgen_offs = 0x2000; |
| 540 | m_gbc_bgdtab_offs = 0x3c00; |
| 541 | m_gbc_wndtab_offs = 0x3c00; |
| 542 | |
| 543 | /* HDMA disabled */ |
| 544 | m_hdma_enabled = 0; |
| 545 | m_hdma_possible = 0; |
| 546 | |
| 547 | m_gbc_mode = 1; |
| 548 | |
| 549 | } |
| 550 | |
| 551 | |
| 552 | |
| 553 | inline void gb_lcd_device::plot_pixel(bitmap_ind16 &bitmap, int x, int y, UINT32 color) |
| 554 | { |
| 147 | 555 | bitmap.pix16(y, x) = (UINT16)color; |
| 148 | 556 | } |
| 149 | 557 | |
| r23879 | r23880 | |
| 151 | 559 | Select which sprites should be drawn for the current scanline and return the |
| 152 | 560 | number of sprites selected. |
| 153 | 561 | */ |
| 154 | | void gb_state::gb_select_sprites() |
| 562 | void gb_lcd_device::select_sprites() |
| 155 | 563 | { |
| 156 | | int i, /*yindex,*/ line, height; |
| 157 | | UINT8 *oam = m_lcd.gb_oam + 39 * 4; |
| 564 | int /*yindex,*/ line, height; |
| 565 | UINT8 *oam = m_oam + 39 * 4; |
| 158 | 566 | |
| 159 | | m_lcd.sprCount = 0; |
| 567 | m_sprCount = 0; |
| 160 | 568 | |
| 161 | 569 | /* If video hardware is enabled and sprites are enabled */ |
| 162 | | if ( ( LCDCONT & 0x80 ) && ( LCDCONT & 0x02 ) ) |
| 570 | if ((LCDCONT & 0x80) && (LCDCONT & 0x02)) |
| 163 | 571 | { |
| 164 | 572 | /* Check for stretched sprites */ |
| 165 | | if ( LCDCONT & 0x04 ) |
| 166 | | { |
| 573 | if (LCDCONT & 0x04) |
| 167 | 574 | height = 16; |
| 168 | | } |
| 169 | 575 | else |
| 170 | | { |
| 171 | 576 | height = 8; |
| 172 | | } |
| 173 | 577 | |
| 174 | | //yindex = m_lcd.current_line; |
| 175 | | line = m_lcd.current_line + 16; |
| 578 | //yindex = m_current_line; |
| 579 | line = m_current_line + 16; |
| 176 | 580 | |
| 177 | | for( i = 39; i >= 0; i-- ) |
| 581 | for (int i = 39; i >= 0; i--) |
| 178 | 582 | { |
| 179 | | if ( line >= oam[0] && line < ( oam[0] + height ) && oam[1] && oam[1] < 168 ) |
| 583 | if (line >= oam[0] && line < (oam[0] + height) && oam[1] && oam[1] < 168) |
| 180 | 584 | { |
| 181 | 585 | /* We limit the sprite count to max 10 here; |
| 182 | 586 | proper games should not exceed this... */ |
| 183 | | if ( m_lcd.sprCount < 10 ) |
| 587 | if (m_sprCount < 10) |
| 184 | 588 | { |
| 185 | | m_lcd.sprite[m_lcd.sprCount] = i; |
| 186 | | m_lcd.sprCount++; |
| 589 | m_sprite[m_sprCount] = i; |
| 590 | m_sprCount++; |
| 187 | 591 | } |
| 188 | 592 | } |
| 189 | 593 | oam -= 4; |
| r23879 | r23880 | |
| 191 | 595 | } |
| 192 | 596 | } |
| 193 | 597 | |
| 194 | | void gb_state::gb_update_sprites() |
| 598 | void gb_lcd_device::update_sprites() |
| 195 | 599 | { |
| 196 | 600 | bitmap_ind16 &bitmap = m_bitmap; |
| 197 | 601 | UINT8 height, tilemask, line, *oam, *vram; |
| 198 | | int i, yindex; |
| 602 | int yindex; |
| 199 | 603 | |
| 200 | 604 | if (LCDCONT & 0x04) |
| 201 | 605 | { |
| r23879 | r23880 | |
| 208 | 612 | tilemask = 0xFF; |
| 209 | 613 | } |
| 210 | 614 | |
| 211 | | yindex = m_lcd.current_line; |
| 212 | | line = m_lcd.current_line + 16; |
| 615 | yindex = m_current_line; |
| 616 | line = m_current_line + 16; |
| 213 | 617 | |
| 214 | | oam = m_lcd.gb_oam + 39 * 4; |
| 215 | | vram = m_lcd.gb_vram; |
| 216 | | for (i = 39; i >= 0; i--) |
| 618 | oam = m_oam + 39 * 4; |
| 619 | vram = m_vram; |
| 620 | for (int i = 39; i >= 0; i--) |
| 217 | 621 | { |
| 218 | 622 | /* if sprite is on current line && x-coordinate && x-coordinate is < 168 */ |
| 219 | 623 | if (line >= oam[0] && line < (oam[0] + height) && oam[1] && oam[1] < 168) |
| r23879 | r23880 | |
| 222 | 626 | UINT8 bit, *spal; |
| 223 | 627 | int xindex, adr; |
| 224 | 628 | |
| 225 | | spal = (oam[3] & 0x10) ? m_lcd.gb_spal1 : m_lcd.gb_spal0; |
| 629 | spal = (oam[3] & 0x10) ? m_gb_spal1 : m_gb_spal0; |
| 226 | 630 | xindex = oam[1] - 8; |
| 227 | 631 | if (oam[3] & 0x40) /* flip y ? */ |
| 228 | 632 | { |
| r23879 | r23880 | |
| 240 | 644 | for (bit = 0; bit < 8; bit++, xindex++) |
| 241 | 645 | { |
| 242 | 646 | register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0); |
| 243 | | if (colour && !m_lcd.bg_zbuf[xindex] && xindex >= 0 && xindex < 160) |
| 244 | | gb_plot_pixel(bitmap, xindex, yindex, spal[colour]); |
| 647 | if (colour && !m_bg_zbuf[xindex] && xindex >= 0 && xindex < 160) |
| 648 | plot_pixel(bitmap, xindex, yindex, spal[colour]); |
| 245 | 649 | data >>= 1; |
| 246 | 650 | } |
| 247 | 651 | break; |
| r23879 | r23880 | |
| 250 | 654 | { |
| 251 | 655 | register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0); |
| 252 | 656 | if (colour && xindex >= 0 && xindex < 160) |
| 253 | | gb_plot_pixel(bitmap, xindex, yindex, spal[colour]); |
| 657 | plot_pixel(bitmap, xindex, yindex, spal[colour]); |
| 254 | 658 | data >>= 1; |
| 255 | 659 | } |
| 256 | 660 | break; |
| r23879 | r23880 | |
| 258 | 662 | for (bit = 0; bit < 8 && xindex < 160; bit++, xindex++) |
| 259 | 663 | { |
| 260 | 664 | register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 261 | | if (colour && !m_lcd.bg_zbuf[xindex] && xindex >= 0 && xindex < 160) |
| 262 | | gb_plot_pixel(bitmap, xindex, yindex, spal[colour]); |
| 665 | if (colour && !m_bg_zbuf[xindex] && xindex >= 0 && xindex < 160) |
| 666 | plot_pixel(bitmap, xindex, yindex, spal[colour]); |
| 263 | 667 | data <<= 1; |
| 264 | 668 | } |
| 265 | 669 | break; |
| r23879 | r23880 | |
| 268 | 672 | { |
| 269 | 673 | register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 270 | 674 | if (colour && xindex >= 0 && xindex < 160) |
| 271 | | gb_plot_pixel(bitmap, xindex, yindex, spal[colour]); |
| 675 | plot_pixel(bitmap, xindex, yindex, spal[colour]); |
| 272 | 676 | data <<= 1; |
| 273 | 677 | } |
| 274 | 678 | break; |
| r23879 | r23880 | |
| 278 | 682 | } |
| 279 | 683 | } |
| 280 | 684 | |
| 281 | | void gb_state::gb_update_scanline() |
| 685 | void gb_lcd_device::update_scanline() |
| 282 | 686 | { |
| 283 | 687 | bitmap_ind16 &bitmap = m_bitmap; |
| 284 | 688 | |
| 285 | 689 | g_profiler.start(PROFILER_VIDEO); |
| 286 | 690 | |
| 287 | 691 | /* Make sure we're in mode 3 */ |
| 288 | | if ( ( LCDSTAT & 0x03 ) == 0x03 ) |
| 692 | if ((LCDSTAT & 0x03) == 0x03) |
| 289 | 693 | { |
| 290 | 694 | /* Calculate number of pixels to render based on time still left on the timer */ |
| 291 | | UINT32 cycles_to_go = m_maincpu->attotime_to_cycles(m_lcd.lcd_timer->remaining( ) ); |
| 695 | UINT32 cycles_to_go = m_maincpu->attotime_to_cycles(m_lcd_timer->remaining()); |
| 292 | 696 | int l = 0; |
| 293 | 697 | |
| 294 | | if ( m_lcd.start_x < 0 ) |
| 698 | if (m_start_x < 0) |
| 295 | 699 | { |
| 296 | 700 | /* Window is enabled if the hardware says so AND the current scanline is |
| 297 | 701 | * within the window AND the window X coordinate is <=166 */ |
| 298 | | m_lcd.layer[1].enabled = ( ( LCDCONT & 0x20 ) && ( m_lcd.current_line >= WNDPOSY ) && ( WNDPOSX <= 166 ) ) ? 1 : 0; |
| 702 | m_layer[1].enabled = ((LCDCONT & 0x20) && (m_current_line >= WNDPOSY) && (WNDPOSX <= 166)) ? 1 : 0; |
| 299 | 703 | |
| 300 | 704 | /* BG is enabled if the hardware says so AND (window_off OR (window_on |
| 301 | | * AND window's X position is >=7 ) ) */ |
| 302 | | m_lcd.layer[0].enabled = ( ( LCDCONT & 0x01 ) && ( ( ! m_lcd.layer[1].enabled ) || ( m_lcd.layer[1].enabled && ( WNDPOSX >= 7 ) ) ) ) ? 1 : 0; |
| 705 | * AND window's X position is >=7)) */ |
| 706 | m_layer[0].enabled = ((LCDCONT & 0x01) && ((!m_layer[1].enabled) || (m_layer[1].enabled && (WNDPOSX >= 7)))) ? 1 : 0; |
| 303 | 707 | |
| 304 | | if ( m_lcd.layer[0].enabled ) |
| 708 | if (m_layer[0].enabled) |
| 305 | 709 | { |
| 306 | | m_lcd.layer[0].bgline = ( SCROLLY + m_lcd.current_line ) & 0xFF; |
| 307 | | m_lcd.layer[0].bg_map = m_lcd.gb_vram + m_lcd.gb_bgdtab_offs; |
| 308 | | m_lcd.layer[0].bg_tiles = m_lcd.gb_vram + m_lcd.gb_chrgen_offs; |
| 309 | | m_lcd.layer[0].xindex = SCROLLX >> 3; |
| 310 | | m_lcd.layer[0].xshift = SCROLLX & 7; |
| 311 | | m_lcd.layer[0].xstart = 0; |
| 312 | | m_lcd.layer[0].xend = 160; |
| 710 | m_layer[0].bgline = (SCROLLY + m_current_line) & 0xFF; |
| 711 | m_layer[0].bg_map = m_vram + m_gb_bgdtab_offs; |
| 712 | m_layer[0].bg_tiles = m_vram + m_gb_chrgen_offs; |
| 713 | m_layer[0].xindex = SCROLLX >> 3; |
| 714 | m_layer[0].xshift = SCROLLX & 7; |
| 715 | m_layer[0].xstart = 0; |
| 716 | m_layer[0].xend = 160; |
| 313 | 717 | } |
| 314 | 718 | |
| 315 | | if ( m_lcd.layer[1].enabled ) |
| 719 | if (m_layer[1].enabled) |
| 316 | 720 | { |
| 317 | | int xpos; |
| 318 | | |
| 319 | | xpos = WNDPOSX - 7; /* Window is offset by 7 pixels */ |
| 320 | | if ( xpos < 0 ) |
| 721 | int xpos = WNDPOSX - 7; /* Window is offset by 7 pixels */ |
| 722 | if (xpos < 0) |
| 321 | 723 | xpos = 0; |
| 322 | 724 | |
| 323 | | m_lcd.layer[1].bgline = m_lcd.window_lines_drawn; |
| 324 | | m_lcd.layer[1].bg_map = m_lcd.gb_vram + m_lcd.gb_wndtab_offs; |
| 325 | | m_lcd.layer[1].bg_tiles = m_lcd.gb_vram + m_lcd.gb_chrgen_offs; |
| 326 | | m_lcd.layer[1].xindex = 0; |
| 327 | | m_lcd.layer[1].xshift = 0; |
| 328 | | m_lcd.layer[1].xstart = xpos; |
| 329 | | m_lcd.layer[1].xend = 160; |
| 330 | | m_lcd.layer[0].xend = xpos; |
| 725 | m_layer[1].bgline = m_window_lines_drawn; |
| 726 | m_layer[1].bg_map = m_vram + m_gb_wndtab_offs; |
| 727 | m_layer[1].bg_tiles = m_vram + m_gb_chrgen_offs; |
| 728 | m_layer[1].xindex = 0; |
| 729 | m_layer[1].xshift = 0; |
| 730 | m_layer[1].xstart = xpos; |
| 731 | m_layer[1].xend = 160; |
| 732 | m_layer[0].xend = xpos; |
| 331 | 733 | } |
| 332 | | m_lcd.start_x = 0; |
| 734 | m_start_x = 0; |
| 333 | 735 | } |
| 334 | 736 | |
| 335 | | if ( cycles_to_go < 160 ) |
| 737 | if (cycles_to_go < 160) |
| 336 | 738 | { |
| 337 | | m_lcd.end_x = MIN(160 - cycles_to_go,160); |
| 739 | m_end_x = MIN(160 - cycles_to_go, 160); |
| 338 | 740 | /* Draw empty pixels when the background is disabled */ |
| 339 | | if ( ! ( LCDCONT & 0x01 ) ) |
| 741 | if (!(LCDCONT & 0x01)) |
| 340 | 742 | { |
| 341 | | rectangle r(m_lcd.start_x, m_lcd.end_x - 1, m_lcd.current_line, m_lcd.current_line); |
| 342 | | bitmap.fill(m_lcd.gb_bpal[0], r ); |
| 743 | rectangle r(m_start_x, m_end_x - 1, m_current_line, m_current_line); |
| 744 | bitmap.fill(m_gb_bpal[0], r); |
| 343 | 745 | } |
| 344 | | while ( l < 2 ) |
| 746 | while (l < 2) |
| 345 | 747 | { |
| 346 | | UINT8 xindex, *map, *tiles; |
| 347 | | UINT16 data; |
| 748 | UINT8 xindex, *map, *tiles; |
| 749 | UINT16 data; |
| 348 | 750 | int i, tile_index; |
| 349 | 751 | |
| 350 | | if ( ! m_lcd.layer[l].enabled ) |
| 752 | if (!m_layer[l].enabled) |
| 351 | 753 | { |
| 352 | 754 | l++; |
| 353 | 755 | continue; |
| 354 | 756 | } |
| 355 | | map = m_lcd.layer[l].bg_map + ( ( m_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 356 | | tiles = m_lcd.layer[l].bg_tiles + ( ( m_lcd.layer[l].bgline & 7 ) << 1 ); |
| 357 | | xindex = m_lcd.start_x; |
| 358 | | if ( xindex < m_lcd.layer[l].xstart ) |
| 359 | | xindex = m_lcd.layer[l].xstart; |
| 360 | | i = m_lcd.end_x; |
| 361 | | if ( i > m_lcd.layer[l].xend ) |
| 362 | | i = m_lcd.layer[l].xend; |
| 757 | map = m_layer[l].bg_map + ((m_layer[l].bgline << 2) & 0x3E0); |
| 758 | tiles = m_layer[l].bg_tiles + ((m_layer[l].bgline & 7) << 1); |
| 759 | xindex = m_start_x; |
| 760 | if (xindex < m_layer[l].xstart) |
| 761 | xindex = m_layer[l].xstart; |
| 762 | i = m_end_x; |
| 763 | if (i > m_layer[l].xend) |
| 764 | i = m_layer[l].xend; |
| 363 | 765 | i = i - xindex; |
| 364 | 766 | |
| 365 | | tile_index = ( map[ m_lcd.layer[l].xindex ] ^ m_lcd.gb_tile_no_mod ) * 16; |
| 366 | | data = tiles[ tile_index ] | ( tiles[ tile_index+1 ] << 8 ); |
| 367 | | data <<= m_lcd.layer[l].xshift; |
| 767 | tile_index = (map[m_layer[l].xindex] ^ m_gb_tile_no_mod) * 16; |
| 768 | data = tiles[tile_index] | (tiles[tile_index+1] << 8); |
| 769 | data <<= m_layer[l].xshift; |
| 368 | 770 | |
| 369 | | while ( i > 0 ) |
| 771 | while (i > 0) |
| 370 | 772 | { |
| 371 | | while ( ( m_lcd.layer[l].xshift < 8 ) && i ) |
| 773 | while ((m_layer[l].xshift < 8) && i) |
| 372 | 774 | { |
| 373 | | register int colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 ); |
| 374 | | gb_plot_pixel( bitmap, xindex, m_lcd.current_line, m_lcd.gb_bpal[ colour ] ); |
| 375 | | m_lcd.bg_zbuf[ xindex ] = colour; |
| 775 | register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 776 | plot_pixel(bitmap, xindex, m_current_line, m_gb_bpal[colour]); |
| 777 | m_bg_zbuf[xindex] = colour; |
| 376 | 778 | xindex++; |
| 377 | 779 | data <<= 1; |
| 378 | | m_lcd.layer[l].xshift++; |
| 780 | m_layer[l].xshift++; |
| 379 | 781 | i--; |
| 380 | 782 | } |
| 381 | | if ( m_lcd.layer[l].xshift == 8 ) |
| 783 | if (m_layer[l].xshift == 8) |
| 382 | 784 | { |
| 383 | 785 | /* Take possible changes to SCROLLY into account */ |
| 384 | | if ( l == 0 ) |
| 786 | if (l == 0) |
| 385 | 787 | { |
| 386 | | m_lcd.layer[0].bgline = ( SCROLLY + m_lcd.current_line ) & 0xFF; |
| 387 | | map = m_lcd.layer[l].bg_map + ( ( m_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 388 | | tiles = m_lcd.layer[l].bg_tiles + ( ( m_lcd.layer[l].bgline & 7 ) << 1 ); |
| 788 | m_layer[0].bgline = (SCROLLY + m_current_line) & 0xFF; |
| 789 | map = m_layer[l].bg_map + ((m_layer[l].bgline << 2) & 0x3E0); |
| 790 | tiles = m_layer[l].bg_tiles + ((m_layer[l].bgline & 7) << 1); |
| 389 | 791 | } |
| 390 | 792 | |
| 391 | | m_lcd.layer[l].xindex = ( m_lcd.layer[l].xindex + 1 ) & 31; |
| 392 | | m_lcd.layer[l].xshift = 0; |
| 393 | | tile_index = ( map[ m_lcd.layer[l].xindex ] ^ m_lcd.gb_tile_no_mod ) * 16; |
| 394 | | data = tiles[ tile_index ] | ( tiles[ tile_index+1 ] << 8 ); |
| 793 | m_layer[l].xindex = (m_layer[l].xindex + 1) & 31; |
| 794 | m_layer[l].xshift = 0; |
| 795 | tile_index = (map[m_layer[l].xindex] ^ m_gb_tile_no_mod) * 16; |
| 796 | data = tiles[tile_index] | (tiles[tile_index + 1] << 8); |
| 395 | 797 | } |
| 396 | 798 | } |
| 397 | 799 | l++; |
| 398 | 800 | } |
| 399 | | if ( m_lcd.end_x == 160 && LCDCONT & 0x02 ) |
| 801 | if (m_end_x == 160 && LCDCONT & 0x02) |
| 400 | 802 | { |
| 401 | | gb_update_sprites(); |
| 803 | update_sprites(); |
| 402 | 804 | } |
| 403 | | m_lcd.start_x = m_lcd.end_x; |
| 805 | m_start_x = m_end_x; |
| 404 | 806 | } |
| 405 | 807 | } |
| 406 | 808 | else |
| 407 | 809 | { |
| 408 | | if ( ! ( LCDCONT & 0x80 ) ) |
| 810 | if (!(LCDCONT & 0x80)) |
| 409 | 811 | { |
| 410 | 812 | /* Draw an empty line when LCD is disabled */ |
| 411 | | if ( m_lcd.previous_line != m_lcd.current_line ) |
| 813 | if (m_previous_line != m_current_line) |
| 412 | 814 | { |
| 413 | | if ( m_lcd.current_line < 144 ) |
| 815 | if (m_current_line < 144) |
| 414 | 816 | { |
| 415 | 817 | screen_device *screen = machine().first_screen(); |
| 416 | 818 | const rectangle &r = screen->visible_area(); |
| 417 | | rectangle r1(r.min_x, r.max_x, m_lcd.current_line, m_lcd.current_line); |
| 418 | | bitmap.fill(0, r1 ); |
| 819 | rectangle r1(r.min_x, r.max_x, m_current_line, m_current_line); |
| 820 | bitmap.fill(0, r1); |
| 419 | 821 | } |
| 420 | | m_lcd.previous_line = m_lcd.current_line; |
| 822 | m_previous_line = m_current_line; |
| 421 | 823 | } |
| 422 | 824 | } |
| 423 | 825 | } |
| r23879 | r23880 | |
| 427 | 829 | |
| 428 | 830 | /* --- Super Game Boy Specific --- */ |
| 429 | 831 | |
| 430 | | void gb_state::sgb_update_sprites() |
| 832 | void sgb_lcd_device::update_sprites() |
| 431 | 833 | { |
| 432 | 834 | bitmap_ind16 &bitmap = m_bitmap; |
| 433 | 835 | UINT8 height, tilemask, line, *oam, *vram, pal; |
| 434 | | INT16 i, yindex; |
| 836 | INT16 yindex; |
| 435 | 837 | |
| 436 | 838 | if (LCDCONT & 0x04) |
| 437 | 839 | { |
| r23879 | r23880 | |
| 445 | 847 | } |
| 446 | 848 | |
| 447 | 849 | /* Offset to center of screen */ |
| 448 | | yindex = m_lcd.current_line + SGB_YOFFSET; |
| 449 | | line = m_lcd.current_line + 16; |
| 850 | yindex = m_current_line + SGB_YOFFSET; |
| 851 | line = m_current_line + 16; |
| 450 | 852 | |
| 451 | | oam = m_lcd.gb_oam + 39 * 4; |
| 452 | | vram = m_lcd.gb_vram; |
| 453 | | for (i = 39; i >= 0; i--) |
| 853 | oam = m_oam + 39 * 4; |
| 854 | vram = m_vram; |
| 855 | for (int i = 39; i >= 0; i--) |
| 454 | 856 | { |
| 455 | 857 | /* if sprite is on current line && x-coordinate && x-coordinate is < 168 */ |
| 456 | 858 | if (line >= oam[0] && line < (oam[0] + height) && oam[1] && oam[1] < 168) |
| r23879 | r23880 | |
| 460 | 862 | INT16 xindex; |
| 461 | 863 | int adr; |
| 462 | 864 | |
| 463 | | spal = (oam[3] & 0x10) ? m_lcd.gb_spal1 : m_lcd.gb_spal0; |
| 865 | spal = (oam[3] & 0x10) ? m_gb_spal1 : m_gb_spal0; |
| 464 | 866 | xindex = oam[1] - 8; |
| 465 | 867 | if (oam[3] & 0x40) /* flip y ? */ |
| 466 | 868 | { |
| 467 | | adr = (oam[2] & tilemask) * 16 + (height -1 - line + oam[0]) * 2; |
| 869 | adr = (oam[2] & tilemask) * 16 + (height - 1 - line + oam[0]) * 2; |
| 468 | 870 | } |
| 469 | 871 | else |
| 470 | 872 | { |
| r23879 | r23880 | |
| 484 | 886 | for (bit = 0; bit < 8; bit++, xindex++) |
| 485 | 887 | { |
| 486 | 888 | register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0); |
| 487 | | if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour && !m_lcd.bg_zbuf[xindex - SGB_XOFFSET]) |
| 488 | | gb_plot_pixel(bitmap, xindex, yindex, m_sgb_pal[pal + spal[colour]]); |
| 889 | if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour && !m_bg_zbuf[xindex - SGB_XOFFSET]) |
| 890 | plot_pixel(bitmap, xindex, yindex, m_sgb_pal[pal + spal[colour]]); |
| 489 | 891 | data >>= 1; |
| 490 | 892 | } |
| 491 | 893 | break; |
| r23879 | r23880 | |
| 494 | 896 | { |
| 495 | 897 | register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0); |
| 496 | 898 | if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour) |
| 497 | | gb_plot_pixel(bitmap, xindex, yindex, m_sgb_pal[pal + spal[colour]]); |
| 899 | plot_pixel(bitmap, xindex, yindex, m_sgb_pal[pal + spal[colour]]); |
| 498 | 900 | data >>= 1; |
| 499 | 901 | } |
| 500 | 902 | break; |
| r23879 | r23880 | |
| 502 | 904 | for (bit = 0; bit < 8; bit++, xindex++) |
| 503 | 905 | { |
| 504 | 906 | register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 505 | | if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour && !m_lcd.bg_zbuf[xindex - SGB_XOFFSET]) |
| 506 | | gb_plot_pixel(bitmap, xindex, yindex, m_sgb_pal[pal + spal[colour]]); |
| 907 | if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour && !m_bg_zbuf[xindex - SGB_XOFFSET]) |
| 908 | plot_pixel(bitmap, xindex, yindex, m_sgb_pal[pal + spal[colour]]); |
| 507 | 909 | data <<= 1; |
| 508 | 910 | } |
| 509 | 911 | break; |
| r23879 | r23880 | |
| 512 | 914 | { |
| 513 | 915 | register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 514 | 916 | if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour) |
| 515 | | gb_plot_pixel(bitmap, xindex, yindex, m_sgb_pal[pal + spal[colour]]); |
| 917 | plot_pixel(bitmap, xindex, yindex, m_sgb_pal[pal + spal[colour]]); |
| 516 | 918 | data <<= 1; |
| 517 | 919 | } |
| 518 | 920 | break; |
| r23879 | r23880 | |
| 523 | 925 | } |
| 524 | 926 | |
| 525 | 927 | |
| 526 | | void gb_state::sgb_refresh_border() |
| 928 | void sgb_lcd_device::refresh_border() |
| 527 | 929 | { |
| 528 | 930 | UINT16 data, data2; |
| 529 | 931 | UINT8 *tiles, *tiles2; |
| 530 | 932 | |
| 531 | | for( UINT16 yidx = 0; yidx < 224; yidx++ ) |
| 933 | for (UINT16 yidx = 0; yidx < 224; yidx++) |
| 532 | 934 | { |
| 533 | | UINT8 *map = m_sgb_tile_map + ( ( yidx >> 3 ) * 64 ); |
| 935 | UINT8 *map = m_sgb_tile_map + ((yidx >> 3) * 64); |
| 534 | 936 | UINT16 xindex = 0; |
| 535 | 937 | |
| 536 | | for( UINT16 xidx = 0; xidx < 64; xidx+=2 ) |
| 938 | for (UINT16 xidx = 0; xidx < 64; xidx += 2) |
| 537 | 939 | { |
| 538 | | if( map[xidx+1] & 0x80 ) /* Vertical flip */ |
| 539 | | tiles = m_sgb_tile_data + ( ( 7 - ( yidx % 8 ) ) << 1 ); |
| 940 | if (map[xidx + 1] & 0x80) /* Vertical flip */ |
| 941 | tiles = m_sgb_tile_data + ((7 - (yidx % 8)) << 1); |
| 540 | 942 | else /* No vertical flip */ |
| 541 | | tiles = m_sgb_tile_data + ( ( yidx % 8 ) << 1 ); |
| 943 | tiles = m_sgb_tile_data + ((yidx % 8) << 1); |
| 542 | 944 | tiles2 = tiles + 16; |
| 543 | 945 | |
| 544 | | UINT8 pal = (map[xidx+1] & 0x1C) >> 2; |
| 545 | | if( pal == 0 ) |
| 946 | UINT8 pal = (map[xidx + 1] & 0x1C) >> 2; |
| 947 | if (pal == 0) |
| 546 | 948 | pal = 1; |
| 547 | 949 | pal <<= 4; |
| 548 | 950 | |
| 549 | | if (m_cartslot && m_cartslot->get_sgb_hack()) |
| 951 | if (m_sgb_border_hack) |
| 550 | 952 | { /* A few games do weird stuff */ |
| 551 | 953 | UINT8 tileno = map[xidx]; |
| 552 | | if( tileno >= 128 ) tileno = ((64 + tileno) % 128) + 128; |
| 954 | if (tileno >= 128) tileno = ((64 + tileno) % 128) + 128; |
| 553 | 955 | else tileno = (64 + tileno) % 128; |
| 554 | | data = tiles[ tileno * 32 ] | ( tiles[ ( tileno * 32 ) + 1 ] << 8 ); |
| 555 | | data2 = tiles2[ tileno * 32 ] | ( tiles2[ ( tileno * 32 ) + 1 ] << 8 ); |
| 956 | data = tiles[tileno * 32] | (tiles[(tileno * 32) + 1] << 8); |
| 957 | data2 = tiles2[tileno * 32] | (tiles2[(tileno * 32) + 1] << 8); |
| 556 | 958 | } |
| 557 | 959 | else |
| 558 | 960 | { |
| 559 | | data = tiles[ map[xidx] * 32 ] | ( tiles[ (map[xidx] * 32 ) + 1 ] << 8 ); |
| 560 | | data2 = tiles2[ map[xidx] * 32 ] | ( tiles2[ (map[xidx] * 32 ) + 1 ] << 8 ); |
| 961 | data = tiles[map[xidx] * 32] | (tiles[(map[xidx] * 32) + 1] << 8); |
| 962 | data2 = tiles2[map[xidx] * 32] | (tiles2[(map[xidx] * 32) + 1] << 8); |
| 561 | 963 | } |
| 562 | 964 | |
| 563 | | for( UINT8 i = 0; i < 8; i++ ) |
| 965 | for (int i = 0; i < 8; i++) |
| 564 | 966 | { |
| 565 | 967 | register UINT8 colour; |
| 566 | | if( (map[xidx+1] & 0x40) ) /* Horizontal flip */ |
| 968 | if ((map[xidx + 1] & 0x40)) /* Horizontal flip */ |
| 567 | 969 | { |
| 568 | 970 | colour = ((data & 0x0001) ? 1 : 0) | ((data & 0x0100) ? 2 : 0) | |
| 569 | 971 | ((data2 & 0x0001) ? 4 : 0) | ((data2 & 0x0100) ? 8 : 0); |
| r23879 | r23880 | |
| 581 | 983 | * Drawing there is allowed, but due to the way we draw the |
| 582 | 984 | * scanline, it can obscure the screen even when it shouldn't. |
| 583 | 985 | */ |
| 584 | | if( !((yidx >= SGB_YOFFSET && yidx < SGB_YOFFSET + 144) && |
| 585 | | (xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160)) ) |
| 986 | if (!((yidx >= SGB_YOFFSET && yidx < SGB_YOFFSET + 144) && |
| 987 | (xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160))) |
| 586 | 988 | { |
| 587 | | gb_plot_pixel(m_bitmap, xindex, yidx, m_sgb_pal[pal + colour]); |
| 989 | plot_pixel(m_bitmap, xindex, yidx, m_sgb_pal[pal + colour]); |
| 588 | 990 | } |
| 589 | 991 | xindex++; |
| 590 | 992 | } |
| r23879 | r23880 | |
| 592 | 994 | } |
| 593 | 995 | } |
| 594 | 996 | |
| 595 | | void gb_state::sgb_update_scanline() |
| 997 | void sgb_lcd_device::update_scanline() |
| 596 | 998 | { |
| 597 | 999 | bitmap_ind16 &bitmap = m_bitmap; |
| 598 | 1000 | |
| 599 | 1001 | g_profiler.start(PROFILER_VIDEO); |
| 600 | 1002 | |
| 601 | | if ( ( LCDSTAT & 0x03 ) == 0x03 ) |
| 1003 | if ((LCDSTAT & 0x03) == 0x03) |
| 602 | 1004 | { |
| 603 | 1005 | /* Calcuate number of pixels to render based on time still left on the timer */ |
| 604 | | UINT32 cycles_to_go = m_maincpu->attotime_to_cycles(m_lcd.lcd_timer->remaining( ) ); |
| 1006 | UINT32 cycles_to_go = m_maincpu->attotime_to_cycles(m_lcd_timer->remaining()); |
| 605 | 1007 | int l = 0; |
| 606 | 1008 | |
| 607 | | if ( m_lcd.start_x < 0 ) |
| 1009 | if (m_start_x < 0) |
| 608 | 1010 | { |
| 609 | 1011 | /* Window is enabled if the hardware says so AND the current scanline is |
| 610 | 1012 | * within the window AND the window X coordinate is <=166 */ |
| 611 | | m_lcd.layer[1].enabled = ((LCDCONT & 0x20) && m_lcd.current_line >= WNDPOSY && WNDPOSX <= 166) ? 1 : 0; |
| 1013 | m_layer[1].enabled = ((LCDCONT & 0x20) && m_current_line >= WNDPOSY && WNDPOSX <= 166) ? 1 : 0; |
| 612 | 1014 | |
| 613 | 1015 | /* BG is enabled if the hardware says so AND (window_off OR (window_on |
| 614 | | * AND window's X position is >=7 ) ) */ |
| 615 | | m_lcd.layer[0].enabled = ((LCDCONT & 0x01) && ((!m_lcd.layer[1].enabled) || (m_lcd.layer[1].enabled && WNDPOSX >= 7))) ? 1 : 0; |
| 1016 | * AND window's X position is >=7 )) */ |
| 1017 | m_layer[0].enabled = ((LCDCONT & 0x01) && ((!m_layer[1].enabled) || (m_layer[1].enabled && WNDPOSX >= 7))) ? 1 : 0; |
| 616 | 1018 | |
| 617 | | if ( m_lcd.layer[0].enabled ) |
| 1019 | if (m_layer[0].enabled) |
| 618 | 1020 | { |
| 619 | | m_lcd.layer[0].bgline = ( SCROLLY + m_lcd.current_line ) & 0xFF; |
| 620 | | m_lcd.layer[0].bg_map = m_lcd.gb_vram + m_lcd.gb_bgdtab_offs; |
| 621 | | m_lcd.layer[0].bg_tiles = m_lcd.gb_vram + m_lcd.gb_chrgen_offs; |
| 622 | | m_lcd.layer[0].xindex = SCROLLX >> 3; |
| 623 | | m_lcd.layer[0].xshift = SCROLLX & 7; |
| 624 | | m_lcd.layer[0].xstart = 0; |
| 625 | | m_lcd.layer[0].xend = 160; |
| 1021 | m_layer[0].bgline = (SCROLLY + m_current_line) & 0xFF; |
| 1022 | m_layer[0].bg_map = m_vram + m_gb_bgdtab_offs; |
| 1023 | m_layer[0].bg_tiles = m_vram + m_gb_chrgen_offs; |
| 1024 | m_layer[0].xindex = SCROLLX >> 3; |
| 1025 | m_layer[0].xshift = SCROLLX & 7; |
| 1026 | m_layer[0].xstart = 0; |
| 1027 | m_layer[0].xend = 160; |
| 626 | 1028 | } |
| 627 | 1029 | |
| 628 | | if ( m_lcd.layer[1].enabled ) |
| 1030 | if (m_layer[1].enabled) |
| 629 | 1031 | { |
| 630 | 1032 | int xpos; |
| 631 | 1033 | |
| r23879 | r23880 | |
| 634 | 1036 | if (xpos < 0) |
| 635 | 1037 | xpos = 0; |
| 636 | 1038 | |
| 637 | | m_lcd.layer[1].bgline = m_lcd.window_lines_drawn; |
| 638 | | m_lcd.layer[1].bg_map = m_lcd.gb_vram + m_lcd.gb_wndtab_offs; |
| 639 | | m_lcd.layer[1].bg_tiles = m_lcd.gb_vram + m_lcd.gb_chrgen_offs; |
| 640 | | m_lcd.layer[1].xindex = 0; |
| 641 | | m_lcd.layer[1].xshift = 0; |
| 642 | | m_lcd.layer[1].xstart = xpos; |
| 643 | | m_lcd.layer[1].xend = 160; |
| 644 | | m_lcd.layer[0].xend = xpos; |
| 1039 | m_layer[1].bgline = m_window_lines_drawn; |
| 1040 | m_layer[1].bg_map = m_vram + m_gb_wndtab_offs; |
| 1041 | m_layer[1].bg_tiles = m_vram + m_gb_chrgen_offs; |
| 1042 | m_layer[1].xindex = 0; |
| 1043 | m_layer[1].xshift = 0; |
| 1044 | m_layer[1].xstart = xpos; |
| 1045 | m_layer[1].xend = 160; |
| 1046 | m_layer[0].xend = xpos; |
| 645 | 1047 | } |
| 646 | | m_lcd.start_x = 0; |
| 1048 | m_start_x = 0; |
| 647 | 1049 | } |
| 648 | 1050 | |
| 649 | | if ( cycles_to_go == 0 ) |
| 1051 | if (cycles_to_go == 0) |
| 650 | 1052 | { |
| 651 | 1053 | /* Does this belong here? or should it be moved to the else block */ |
| 652 | 1054 | /* Handle SGB mask */ |
| 653 | | switch( m_sgb_window_mask ) |
| 1055 | switch (m_sgb_window_mask) |
| 654 | 1056 | { |
| 655 | 1057 | case 1: /* Freeze screen */ |
| 656 | 1058 | return; |
| 657 | 1059 | case 2: /* Blank screen (black) */ |
| 658 | 1060 | { |
| 659 | 1061 | rectangle r(SGB_XOFFSET, SGB_XOFFSET + 160-1, SGB_YOFFSET, SGB_YOFFSET + 144 - 1); |
| 660 | | bitmap.fill(0, r ); |
| 661 | | } return; |
| 1062 | bitmap.fill(0, r); |
| 1063 | } |
| 1064 | return; |
| 662 | 1065 | case 3: /* Blank screen (white - or should it be color 0?) */ |
| 663 | 1066 | { |
| 664 | 1067 | rectangle r(SGB_XOFFSET, SGB_XOFFSET + 160 - 1, SGB_YOFFSET, SGB_YOFFSET + 144 - 1); |
| 665 | | bitmap.fill(32767, r ); |
| 666 | | } return; |
| 1068 | bitmap.fill(32767, r); |
| 1069 | } |
| 1070 | return; |
| 667 | 1071 | } |
| 668 | 1072 | |
| 669 | 1073 | /* Draw the "border" if we're on the first line */ |
| 670 | | if ( m_lcd.current_line == 0 ) |
| 1074 | if (m_current_line == 0) |
| 671 | 1075 | { |
| 672 | | sgb_refresh_border(); |
| 1076 | refresh_border(); |
| 673 | 1077 | } |
| 674 | 1078 | } |
| 675 | | if ( cycles_to_go < 160 ) |
| 1079 | if (cycles_to_go < 160) |
| 676 | 1080 | { |
| 677 | | m_lcd.end_x = MIN(160 - cycles_to_go,160); |
| 1081 | m_end_x = MIN(160 - cycles_to_go,160); |
| 678 | 1082 | |
| 679 | 1083 | /* if background or screen disabled clear line */ |
| 680 | | if ( ! ( LCDCONT & 0x01 ) ) |
| 1084 | if (!(LCDCONT & 0x01)) |
| 681 | 1085 | { |
| 682 | | rectangle r(SGB_XOFFSET, SGB_XOFFSET + 160 - 1, m_lcd.current_line + SGB_YOFFSET, m_lcd.current_line + SGB_YOFFSET); |
| 683 | | bitmap.fill(0, r ); |
| 1086 | rectangle r(SGB_XOFFSET, SGB_XOFFSET + 160 - 1, m_current_line + SGB_YOFFSET, m_current_line + SGB_YOFFSET); |
| 1087 | bitmap.fill(0, r); |
| 684 | 1088 | } |
| 685 | | while( l < 2 ) |
| 1089 | while (l < 2) |
| 686 | 1090 | { |
| 687 | 1091 | UINT8 xindex, sgb_palette, *map, *tiles; |
| 688 | 1092 | UINT16 data; |
| 689 | 1093 | int i, tile_index; |
| 690 | 1094 | |
| 691 | | if ( ! m_lcd.layer[l].enabled ) |
| 1095 | if (!m_layer[l].enabled) |
| 692 | 1096 | { |
| 693 | 1097 | l++; |
| 694 | 1098 | continue; |
| 695 | 1099 | } |
| 696 | | map = m_lcd.layer[l].bg_map + ( ( m_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 697 | | tiles = m_lcd.layer[l].bg_tiles + ( ( m_lcd.layer[l].bgline & 7 ) << 1 ); |
| 698 | | xindex = m_lcd.start_x; |
| 699 | | if ( xindex < m_lcd.layer[l].xstart ) |
| 700 | | xindex = m_lcd.layer[l].xstart; |
| 701 | | i = m_lcd.end_x; |
| 702 | | if ( i > m_lcd.layer[l].xend ) |
| 703 | | i = m_lcd.layer[l].xend; |
| 1100 | map = m_layer[l].bg_map + ((m_layer[l].bgline << 2) & 0x3E0); |
| 1101 | tiles = m_layer[l].bg_tiles + ((m_layer[l].bgline & 7) << 1); |
| 1102 | xindex = m_start_x; |
| 1103 | if (xindex < m_layer[l].xstart) |
| 1104 | xindex = m_layer[l].xstart; |
| 1105 | i = m_end_x; |
| 1106 | if (i > m_layer[l].xend) |
| 1107 | i = m_layer[l].xend; |
| 704 | 1108 | i = i - xindex; |
| 705 | 1109 | |
| 706 | | tile_index = (map[m_lcd.layer[l].xindex] ^ m_lcd.gb_tile_no_mod) * 16; |
| 707 | | data = tiles[tile_index] | ( tiles[tile_index + 1] << 8 ); |
| 708 | | data <<= m_lcd.layer[l].xshift; |
| 1110 | tile_index = (map[m_layer[l].xindex] ^ m_gb_tile_no_mod) * 16; |
| 1111 | data = tiles[tile_index] | (tiles[tile_index + 1] << 8); |
| 1112 | data <<= m_layer[l].xshift; |
| 709 | 1113 | |
| 710 | 1114 | /* Figure out which palette we're using */ |
| 711 | | sgb_palette = m_sgb_pal_map[ ( m_lcd.end_x - i ) >> 3 ][ m_lcd.current_line >> 3 ] << 2; |
| 1115 | sgb_palette = m_sgb_pal_map[(m_end_x - i) >> 3][m_current_line >> 3] << 2; |
| 712 | 1116 | |
| 713 | | while( i > 0 ) |
| 1117 | while (i > 0) |
| 714 | 1118 | { |
| 715 | | while( ( m_lcd.layer[l].xshift < 8 ) && i ) |
| 1119 | while ((m_layer[l].xshift < 8) && i) |
| 716 | 1120 | { |
| 717 | | register int colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 ); |
| 718 | | gb_plot_pixel( bitmap, xindex + SGB_XOFFSET, m_lcd.current_line + SGB_YOFFSET, m_sgb_pal[ sgb_palette + m_lcd.gb_bpal[colour]] ); |
| 719 | | m_lcd.bg_zbuf[xindex] = colour; |
| 1121 | register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 1122 | plot_pixel(bitmap, xindex + SGB_XOFFSET, m_current_line + SGB_YOFFSET, m_sgb_pal[sgb_palette + m_gb_bpal[colour]]); |
| 1123 | m_bg_zbuf[xindex] = colour; |
| 720 | 1124 | xindex++; |
| 721 | 1125 | data <<= 1; |
| 722 | | m_lcd.layer[l].xshift++; |
| 1126 | m_layer[l].xshift++; |
| 723 | 1127 | i--; |
| 724 | 1128 | } |
| 725 | | if ( m_lcd.layer[l].xshift == 8 ) |
| 1129 | if (m_layer[l].xshift == 8) |
| 726 | 1130 | { |
| 727 | 1131 | /* Take possible changes to SCROLLY into account */ |
| 728 | | if ( l == 0 ) |
| 1132 | if (l == 0) |
| 729 | 1133 | { |
| 730 | | m_lcd.layer[0].bgline = ( SCROLLY + m_lcd.current_line ) & 0xFF; |
| 731 | | map = m_lcd.layer[l].bg_map + ( ( m_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 732 | | tiles = m_lcd.layer[l].bg_tiles + ( ( m_lcd.layer[l].bgline & 7 ) << 1 ); |
| 1134 | m_layer[0].bgline = (SCROLLY + m_current_line) & 0xFF; |
| 1135 | map = m_layer[l].bg_map + ((m_layer[l].bgline << 2) & 0x3E0); |
| 1136 | tiles = m_layer[l].bg_tiles + ((m_layer[l].bgline & 7) << 1); |
| 733 | 1137 | } |
| 734 | 1138 | |
| 735 | | m_lcd.layer[l].xindex = ( m_lcd.layer[l].xindex + 1 ) & 31; |
| 736 | | m_lcd.layer[l].xshift = 0; |
| 737 | | tile_index = ( map[ m_lcd.layer[l].xindex ] ^ m_lcd.gb_tile_no_mod ) * 16; |
| 738 | | data = tiles[ tile_index ] | ( tiles[ tile_index + 1 ] << 8 ); |
| 739 | | sgb_palette = m_sgb_pal_map[ ( m_lcd.end_x - i ) >> 3 ][ m_lcd.current_line >> 3 ] << 2; |
| 1139 | m_layer[l].xindex = (m_layer[l].xindex + 1) & 31; |
| 1140 | m_layer[l].xshift = 0; |
| 1141 | tile_index = (map[m_layer[l].xindex] ^ m_gb_tile_no_mod) * 16; |
| 1142 | data = tiles[tile_index] | (tiles[tile_index + 1] << 8); |
| 1143 | sgb_palette = m_sgb_pal_map[(m_end_x - i) >> 3][m_current_line >> 3] << 2; |
| 740 | 1144 | } |
| 741 | 1145 | } |
| 742 | 1146 | l++; |
| 743 | 1147 | } |
| 744 | | if ( ( m_lcd.end_x == 160 ) && ( LCDCONT & 0x02 ) ) |
| 1148 | if ((m_end_x == 160) && (LCDCONT & 0x02)) |
| 745 | 1149 | { |
| 746 | | sgb_update_sprites(); |
| 1150 | update_sprites(); |
| 747 | 1151 | } |
| 748 | | m_lcd.start_x = m_lcd.end_x; |
| 1152 | m_start_x = m_end_x; |
| 749 | 1153 | } |
| 750 | 1154 | } |
| 751 | 1155 | else |
| 752 | 1156 | { |
| 753 | | if ( ! ( LCDCONT * 0x80 ) ) |
| 1157 | if (!(LCDCONT * 0x80)) |
| 754 | 1158 | { |
| 755 | 1159 | /* if screen disabled clear line */ |
| 756 | | if ( m_lcd.previous_line != m_lcd.current_line ) |
| 1160 | if (m_previous_line != m_current_line) |
| 757 | 1161 | { |
| 758 | 1162 | /* Also refresh border here??? */ |
| 759 | | if ( m_lcd.current_line < 144 ) |
| 1163 | if (m_current_line < 144) |
| 760 | 1164 | { |
| 761 | | rectangle r(SGB_XOFFSET, SGB_XOFFSET + 160 - 1, m_lcd.current_line + SGB_YOFFSET, m_lcd.current_line + SGB_YOFFSET); |
| 1165 | rectangle r(SGB_XOFFSET, SGB_XOFFSET + 160 - 1, m_current_line + SGB_YOFFSET, m_current_line + SGB_YOFFSET); |
| 762 | 1166 | bitmap.fill(0, r); |
| 763 | 1167 | } |
| 764 | | m_lcd.previous_line = m_lcd.current_line; |
| 1168 | m_previous_line = m_current_line; |
| 765 | 1169 | } |
| 766 | 1170 | } |
| 767 | 1171 | } |
| r23879 | r23880 | |
| 771 | 1175 | |
| 772 | 1176 | /* --- Game Boy Color Specific --- */ |
| 773 | 1177 | |
| 774 | | void gb_state::cgb_update_sprites() |
| 1178 | void cgb_lcd_device::update_sprites() |
| 775 | 1179 | { |
| 776 | 1180 | bitmap_ind16 &bitmap = m_bitmap; |
| 777 | 1181 | UINT8 height, tilemask, line, *oam; |
| 778 | | int i, xindex, yindex; |
| 1182 | int xindex, yindex; |
| 779 | 1183 | |
| 780 | 1184 | if (LCDCONT & 0x04) |
| 781 | 1185 | { |
| r23879 | r23880 | |
| 788 | 1192 | tilemask = 0xFF; |
| 789 | 1193 | } |
| 790 | 1194 | |
| 791 | | yindex = m_lcd.current_line; |
| 792 | | line = m_lcd.current_line + 16; |
| 1195 | yindex = m_current_line; |
| 1196 | line = m_current_line + 16; |
| 793 | 1197 | |
| 794 | | oam = m_lcd.gb_oam + 39 * 4; |
| 795 | | for (i = 39; i >= 0; i--) |
| 1198 | oam = m_oam + 39 * 4; |
| 1199 | for (int i = 39; i >= 0; i--) |
| 796 | 1200 | { |
| 797 | 1201 | /* if sprite is on current line && x-coordinate && x-coordinate is < 168 */ |
| 798 | 1202 | if (line >= oam[0] && line < (oam[0] + height) && oam[1] && oam[1] < 168) |
| r23879 | r23880 | |
| 801 | 1205 | UINT8 bit, pal; |
| 802 | 1206 | |
| 803 | 1207 | /* Handle mono mode for GB games */ |
| 804 | | if( ! m_lcd.gbc_mode ) |
| 1208 | if (!m_gbc_mode) |
| 805 | 1209 | pal = (oam[3] & 0x10) ? 4 : 0; |
| 806 | 1210 | else |
| 807 | 1211 | pal = ((oam[3] & 0x7) * 4); |
| r23879 | r23880 | |
| 809 | 1213 | xindex = oam[1] - 8; |
| 810 | 1214 | if (oam[3] & 0x40) /* flip y ? */ |
| 811 | 1215 | { |
| 812 | | data = *((UINT16 *) &m_lcd.gb_vram[((oam[3] & 0x8)<<10) + (oam[2] & tilemask) * 16 + (height - 1 - line + oam[0]) * 2]); |
| 1216 | data = *((UINT16 *) &m_vram[((oam[3] & 0x8)<<10) + (oam[2] & tilemask) * 16 + (height - 1 - line + oam[0]) * 2]); |
| 813 | 1217 | } |
| 814 | 1218 | else |
| 815 | 1219 | { |
| 816 | | data = *((UINT16 *) &m_lcd.gb_vram[((oam[3] & 0x8)<<10) + (oam[2] & tilemask) * 16 + (line - oam[0]) * 2]); |
| 1220 | data = *((UINT16 *) &m_vram[((oam[3] & 0x8)<<10) + (oam[2] & tilemask) * 16 + (line - oam[0]) * 2]); |
| 817 | 1221 | } |
| 818 | 1222 | #ifndef LSB_FIRST |
| 819 | 1223 | data = (data << 8) | (data >> 8); |
| r23879 | r23880 | |
| 825 | 1229 | for (bit = 0; bit < 8; bit++, xindex++) |
| 826 | 1230 | { |
| 827 | 1231 | register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0); |
| 828 | | if (colour && !m_lcd.bg_zbuf[xindex] && xindex >= 0 && xindex < 160) |
| 1232 | if (colour && !m_bg_zbuf[xindex] && xindex >= 0 && xindex < 160) |
| 829 | 1233 | { |
| 830 | | if ( ! m_lcd.gbc_mode ) |
| 831 | | colour = pal ? m_lcd.gb_spal1[colour] : m_lcd.gb_spal0[colour]; |
| 832 | | gb_plot_pixel(bitmap, xindex, yindex, m_lcd.cgb_spal[pal + colour]); |
| 1234 | if (! m_gbc_mode) |
| 1235 | colour = pal ? m_gb_spal1[colour] : m_gb_spal0[colour]; |
| 1236 | plot_pixel(bitmap, xindex, yindex, m_cgb_spal[pal + colour]); |
| 833 | 1237 | } |
| 834 | 1238 | data >>= 1; |
| 835 | 1239 | } |
| r23879 | r23880 | |
| 838 | 1242 | for (bit = 0; bit < 8; bit++, xindex++) |
| 839 | 1243 | { |
| 840 | 1244 | register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0); |
| 841 | | if((m_lcd.bg_zbuf[xindex] & 0x80) && (m_lcd.bg_zbuf[xindex] & 0x7f) && (LCDCONT & 0x1)) |
| 1245 | if ((m_bg_zbuf[xindex] & 0x80) && (m_bg_zbuf[xindex] & 0x7f) && (LCDCONT & 0x1)) |
| 842 | 1246 | colour = 0; |
| 843 | 1247 | if (colour && xindex >= 0 && xindex < 160) |
| 844 | 1248 | { |
| 845 | | if ( ! m_lcd.gbc_mode ) |
| 846 | | colour = pal ? m_lcd.gb_spal1[colour] : m_lcd.gb_spal0[colour]; |
| 847 | | gb_plot_pixel(bitmap, xindex, yindex, m_lcd.cgb_spal[pal + colour]); |
| 1249 | if (! m_gbc_mode) |
| 1250 | colour = pal ? m_gb_spal1[colour] : m_gb_spal0[colour]; |
| 1251 | plot_pixel(bitmap, xindex, yindex, m_cgb_spal[pal + colour]); |
| 848 | 1252 | } |
| 849 | 1253 | data >>= 1; |
| 850 | 1254 | } |
| r23879 | r23880 | |
| 853 | 1257 | for (bit = 0; bit < 8; bit++, xindex++) |
| 854 | 1258 | { |
| 855 | 1259 | register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 856 | | if (colour && !m_lcd.bg_zbuf[xindex] && xindex >= 0 && xindex < 160) |
| 1260 | if (colour && !m_bg_zbuf[xindex] && xindex >= 0 && xindex < 160) |
| 857 | 1261 | { |
| 858 | | if ( ! m_lcd.gbc_mode ) |
| 859 | | colour = pal ? m_lcd.gb_spal1[colour] : m_lcd.gb_spal0[colour]; |
| 860 | | gb_plot_pixel(bitmap, xindex, yindex, m_lcd.cgb_spal[pal + colour]); |
| 1262 | if (! m_gbc_mode) |
| 1263 | colour = pal ? m_gb_spal1[colour] : m_gb_spal0[colour]; |
| 1264 | plot_pixel(bitmap, xindex, yindex, m_cgb_spal[pal + colour]); |
| 861 | 1265 | } |
| 862 | 1266 | data <<= 1; |
| 863 | 1267 | } |
| r23879 | r23880 | |
| 866 | 1270 | for (bit = 0; bit < 8; bit++, xindex++) |
| 867 | 1271 | { |
| 868 | 1272 | register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 869 | | if((m_lcd.bg_zbuf[xindex] & 0x80) && (m_lcd.bg_zbuf[xindex] & 0x7f) && (LCDCONT & 0x1)) |
| 1273 | if ((m_bg_zbuf[xindex] & 0x80) && (m_bg_zbuf[xindex] & 0x7f) && (LCDCONT & 0x1)) |
| 870 | 1274 | colour = 0; |
| 871 | 1275 | if (colour && xindex >= 0 && xindex < 160) |
| 872 | 1276 | { |
| 873 | | if ( ! m_lcd.gbc_mode ) |
| 874 | | colour = pal ? m_lcd.gb_spal1[colour] : m_lcd.gb_spal0[colour]; |
| 875 | | gb_plot_pixel(bitmap, xindex, yindex, m_lcd.cgb_spal[pal + colour]); |
| 1277 | if (! m_gbc_mode) |
| 1278 | colour = pal ? m_gb_spal1[colour] : m_gb_spal0[colour]; |
| 1279 | plot_pixel(bitmap, xindex, yindex, m_cgb_spal[pal + colour]); |
| 876 | 1280 | } |
| 877 | 1281 | data <<= 1; |
| 878 | 1282 | } |
| r23879 | r23880 | |
| 883 | 1287 | } |
| 884 | 1288 | } |
| 885 | 1289 | |
| 886 | | void gb_state::cgb_update_scanline() |
| 1290 | void cgb_lcd_device::update_scanline() |
| 887 | 1291 | { |
| 888 | 1292 | bitmap_ind16 &bitmap = m_bitmap; |
| 889 | 1293 | |
| 890 | 1294 | g_profiler.start(PROFILER_VIDEO); |
| 891 | 1295 | |
| 892 | | if ( ( LCDSTAT & 0x03 ) == 0x03 ) |
| 1296 | if ((LCDSTAT & 0x03) == 0x03) |
| 893 | 1297 | { |
| 894 | 1298 | /* Calcuate number of pixels to render based on time still left on the timer */ |
| 895 | | UINT32 cycles_to_go = m_maincpu->attotime_to_cycles(m_lcd.lcd_timer->remaining( ) ); |
| 1299 | UINT32 cycles_to_go = m_maincpu->attotime_to_cycles(m_lcd_timer->remaining()); |
| 896 | 1300 | int l = 0; |
| 897 | 1301 | |
| 898 | | if ( m_lcd.start_x < 0 ) |
| 1302 | if (m_start_x < 0) |
| 899 | 1303 | { |
| 900 | 1304 | /* Window is enabled if the hardware says so AND the current scanline is |
| 901 | 1305 | * within the window AND the window X coordinate is <=166 */ |
| 902 | | m_lcd.layer[1].enabled = ( ( LCDCONT & 0x20 ) && ( m_lcd.current_line >= WNDPOSY ) && ( WNDPOSX <= 166 ) ) ? 1 : 0; |
| 1306 | m_layer[1].enabled = ((LCDCONT & 0x20) && (m_current_line >= WNDPOSY) && (WNDPOSX <= 166)) ? 1 : 0; |
| 903 | 1307 | |
| 904 | 1308 | /* BG is enabled if the hardware says so AND (window_off OR (window_on |
| 905 | | * AND window's X position is >=7 ) ) */ |
| 906 | | m_lcd.layer[0].enabled = ( ( LCDCONT & 0x01 ) && ( ( ! m_lcd.layer[1].enabled ) || ( m_lcd.layer[1].enabled && ( WNDPOSX >= 7 ) ) ) ) ? 1 : 0; |
| 1309 | * AND window's X position is >=7 )) */ |
| 1310 | m_layer[0].enabled = ((LCDCONT & 0x01) && ((!m_layer[1].enabled) || (m_layer[1].enabled && (WNDPOSX >= 7)))) ? 1 : 0; |
| 907 | 1311 | |
| 908 | | if ( m_lcd.layer[0].enabled ) |
| 1312 | if (m_layer[0].enabled) |
| 909 | 1313 | { |
| 910 | | m_lcd.layer[0].bgline = ( SCROLLY + m_lcd.current_line ) & 0xFF; |
| 911 | | m_lcd.layer[0].bg_map = m_lcd.gb_vram + m_lcd.gb_bgdtab_offs; |
| 912 | | m_lcd.layer[0].gbc_map = m_lcd.gb_vram + m_lcd.gbc_bgdtab_offs; |
| 913 | | m_lcd.layer[0].xindex = SCROLLX >> 3; |
| 914 | | m_lcd.layer[0].xshift = SCROLLX & 7; |
| 915 | | m_lcd.layer[0].xstart = 0; |
| 916 | | m_lcd.layer[0].xend = 160; |
| 1314 | m_layer[0].bgline = (SCROLLY + m_current_line) & 0xFF; |
| 1315 | m_layer[0].bg_map = m_vram + m_gb_bgdtab_offs; |
| 1316 | m_layer[0].gbc_map = m_vram + m_gbc_bgdtab_offs; |
| 1317 | m_layer[0].xindex = SCROLLX >> 3; |
| 1318 | m_layer[0].xshift = SCROLLX & 7; |
| 1319 | m_layer[0].xstart = 0; |
| 1320 | m_layer[0].xend = 160; |
| 917 | 1321 | } |
| 918 | 1322 | |
| 919 | | if ( m_lcd.layer[1].enabled ) |
| 1323 | if (m_layer[1].enabled) |
| 920 | 1324 | { |
| 921 | 1325 | int xpos; |
| 922 | 1326 | |
| r23879 | r23880 | |
| 925 | 1329 | if (xpos < 0) |
| 926 | 1330 | xpos = 0; |
| 927 | 1331 | |
| 928 | | m_lcd.layer[1].bgline = m_lcd.window_lines_drawn; |
| 929 | | m_lcd.layer[1].bg_map = m_lcd.gb_vram + m_lcd.gb_wndtab_offs; |
| 930 | | m_lcd.layer[1].gbc_map = m_lcd.gb_vram + m_lcd.gbc_wndtab_offs; |
| 931 | | m_lcd.layer[1].xindex = 0; |
| 932 | | m_lcd.layer[1].xshift = 0; |
| 933 | | m_lcd.layer[1].xstart = xpos; |
| 934 | | m_lcd.layer[1].xend = 160; |
| 935 | | m_lcd.layer[0].xend = xpos; |
| 1332 | m_layer[1].bgline = m_window_lines_drawn; |
| 1333 | m_layer[1].bg_map = m_vram + m_gb_wndtab_offs; |
| 1334 | m_layer[1].gbc_map = m_vram + m_gbc_wndtab_offs; |
| 1335 | m_layer[1].xindex = 0; |
| 1336 | m_layer[1].xshift = 0; |
| 1337 | m_layer[1].xstart = xpos; |
| 1338 | m_layer[1].xend = 160; |
| 1339 | m_layer[0].xend = xpos; |
| 936 | 1340 | } |
| 937 | | m_lcd.start_x = 0; |
| 1341 | m_start_x = 0; |
| 938 | 1342 | } |
| 939 | 1343 | |
| 940 | | if ( cycles_to_go < 160 ) |
| 1344 | if (cycles_to_go < 160) |
| 941 | 1345 | { |
| 942 | | m_lcd.end_x = MIN(160 - cycles_to_go,160); |
| 1346 | m_end_x = MIN(160 - cycles_to_go, 160); |
| 943 | 1347 | /* Draw empty line when the background is disabled */ |
| 944 | | if ( ! ( LCDCONT & 0x01 ) ) |
| 1348 | if (!(LCDCONT & 0x01)) |
| 945 | 1349 | { |
| 946 | | rectangle r(m_lcd.start_x, m_lcd.end_x - 1, m_lcd.current_line, m_lcd.current_line); |
| 947 | | bitmap.fill(( ! m_lcd.gbc_mode ) ? 0 : 32767 , r); |
| 1350 | rectangle r(m_start_x, m_end_x - 1, m_current_line, m_current_line); |
| 1351 | bitmap.fill((!m_gbc_mode) ? 0 : 32767, r); |
| 948 | 1352 | } |
| 949 | | while ( l < 2 ) |
| 1353 | while (l < 2) |
| 950 | 1354 | { |
| 951 | 1355 | UINT8 xindex, *map, *tiles, *gbcmap; |
| 952 | 1356 | UINT16 data; |
| 953 | 1357 | int i, tile_index; |
| 954 | 1358 | |
| 955 | | if ( ! m_lcd.layer[l].enabled ) |
| 1359 | if (!m_layer[l].enabled) |
| 956 | 1360 | { |
| 957 | 1361 | l++; |
| 958 | 1362 | continue; |
| 959 | 1363 | } |
| 960 | | map = m_lcd.layer[l].bg_map + ( ( m_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 961 | | gbcmap = m_lcd.layer[l].gbc_map + ( ( m_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 962 | | tiles = (gbcmap[m_lcd.layer[l].xindex] & 0x08) ? (m_lcd.gb_vram + m_lcd.gbc_chrgen_offs) : (m_lcd.gb_vram + m_lcd.gb_chrgen_offs); |
| 1364 | map = m_layer[l].bg_map + ((m_layer[l].bgline << 2) & 0x3E0); |
| 1365 | gbcmap = m_layer[l].gbc_map + ((m_layer[l].bgline << 2) & 0x3E0); |
| 1366 | tiles = (gbcmap[m_layer[l].xindex] & 0x08) ? (m_vram + m_gbc_chrgen_offs) : (m_vram + m_gb_chrgen_offs); |
| 963 | 1367 | |
| 964 | 1368 | /* Check for vertical flip */ |
| 965 | | if ( gbcmap[ m_lcd.layer[l].xindex ] & 0x40 ) |
| 1369 | if (gbcmap[m_layer[l].xindex] & 0x40) |
| 966 | 1370 | { |
| 967 | | tiles += ( ( 7 - ( m_lcd.layer[l].bgline & 0x07 ) ) << 1 ); |
| 1371 | tiles += ((7 - (m_layer[l].bgline & 0x07)) << 1); |
| 968 | 1372 | } |
| 969 | 1373 | else |
| 970 | 1374 | { |
| 971 | | tiles += ( ( m_lcd.layer[l].bgline & 0x07 ) << 1 ); |
| 1375 | tiles += ((m_layer[l].bgline & 0x07) << 1); |
| 972 | 1376 | } |
| 973 | | xindex = m_lcd.start_x; |
| 974 | | if ( xindex < m_lcd.layer[l].xstart ) |
| 975 | | xindex = m_lcd.layer[l].xstart; |
| 976 | | i = m_lcd.end_x; |
| 977 | | if ( i > m_lcd.layer[l].xend ) |
| 978 | | i = m_lcd.layer[l].xend; |
| 1377 | xindex = m_start_x; |
| 1378 | if (xindex < m_layer[l].xstart) |
| 1379 | xindex = m_layer[l].xstart; |
| 1380 | i = m_end_x; |
| 1381 | if (i > m_layer[l].xend) |
| 1382 | i = m_layer[l].xend; |
| 979 | 1383 | i = i - xindex; |
| 980 | 1384 | |
| 981 | | tile_index = ( map[ m_lcd.layer[l].xindex ] ^ m_lcd.gb_tile_no_mod ) * 16; |
| 982 | | data = tiles[ tile_index ] | ( tiles[ tile_index + 1 ] << 8 ); |
| 1385 | tile_index = (map[m_layer[l].xindex] ^ m_gb_tile_no_mod) * 16; |
| 1386 | data = tiles[tile_index] | (tiles[tile_index + 1] << 8); |
| 983 | 1387 | /* Check for horinzontal flip */ |
| 984 | | if ( gbcmap[ m_lcd.layer[l].xindex ] & 0x20 ) |
| 1388 | if (gbcmap[m_layer[l].xindex] & 0x20) |
| 985 | 1389 | { |
| 986 | | data >>= m_lcd.layer[l].xshift; |
| 1390 | data >>= m_layer[l].xshift; |
| 987 | 1391 | } |
| 988 | 1392 | else |
| 989 | 1393 | { |
| 990 | | data <<= m_lcd.layer[l].xshift; |
| 1394 | data <<= m_layer[l].xshift; |
| 991 | 1395 | } |
| 992 | 1396 | |
| 993 | | while ( i > 0 ) |
| 1397 | while (i > 0) |
| 994 | 1398 | { |
| 995 | | while ( ( m_lcd.layer[l].xshift < 8 ) && i ) |
| 1399 | while ((m_layer[l].xshift < 8) && i) |
| 996 | 1400 | { |
| 997 | 1401 | int colour; |
| 998 | 1402 | /* Check for horinzontal flip */ |
| 999 | | if ( gbcmap[ m_lcd.layer[l].xindex ] & 0x20 ) |
| 1403 | if (gbcmap[m_layer[l].xindex] & 0x20) |
| 1000 | 1404 | { |
| 1001 | | colour = ( ( data & 0x0100 ) ? 2 : 0 ) | ( ( data & 0x0001 ) ? 1 : 0 ); |
| 1405 | colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0); |
| 1002 | 1406 | data >>= 1; |
| 1003 | 1407 | } |
| 1004 | 1408 | else |
| 1005 | 1409 | { |
| 1006 | | colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 ); |
| 1410 | colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0); |
| 1007 | 1411 | data <<= 1; |
| 1008 | 1412 | } |
| 1009 | | gb_plot_pixel( bitmap, xindex, m_lcd.current_line, m_lcd.cgb_bpal[ ( ! m_lcd.gbc_mode ) ? m_lcd.gb_bpal[colour] : ( ( ( gbcmap[ m_lcd.layer[l].xindex ] & 0x07 ) * 4 ) + colour ) ] ); |
| 1010 | | m_lcd.bg_zbuf[ xindex ] = colour + ( gbcmap[ m_lcd.layer[l].xindex ] & 0x80 ); |
| 1413 | plot_pixel(bitmap, xindex, m_current_line, m_cgb_bpal[(!m_gbc_mode) ? m_gb_bpal[colour] : (((gbcmap[m_layer[l].xindex] & 0x07) * 4) + colour)]); |
| 1414 | m_bg_zbuf[xindex] = colour + (gbcmap[m_layer[l].xindex] & 0x80); |
| 1011 | 1415 | xindex++; |
| 1012 | | m_lcd.layer[l].xshift++; |
| 1416 | m_layer[l].xshift++; |
| 1013 | 1417 | i--; |
| 1014 | 1418 | } |
| 1015 | | if ( m_lcd.layer[l].xshift == 8 ) |
| 1419 | if (m_layer[l].xshift == 8) |
| 1016 | 1420 | { |
| 1017 | 1421 | /* Take possible changes to SCROLLY into account */ |
| 1018 | | if ( l == 0 ) |
| 1422 | if (l == 0) |
| 1019 | 1423 | { |
| 1020 | | m_lcd.layer[0].bgline = ( SCROLLY + m_lcd.current_line ) & 0xFF; |
| 1021 | | map = m_lcd.layer[l].bg_map + ( ( m_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 1022 | | gbcmap = m_lcd.layer[l].gbc_map + ( ( m_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 1424 | m_layer[0].bgline = (SCROLLY + m_current_line) & 0xFF; |
| 1425 | map = m_layer[l].bg_map + ((m_layer[l].bgline << 2) & 0x3E0); |
| 1426 | gbcmap = m_layer[l].gbc_map + ((m_layer[l].bgline << 2) & 0x3E0); |
| 1023 | 1427 | } |
| 1024 | 1428 | |
| 1025 | | m_lcd.layer[l].xindex = ( m_lcd.layer[l].xindex + 1 ) & 31; |
| 1026 | | m_lcd.layer[l].xshift = 0; |
| 1027 | | tiles = (gbcmap[m_lcd.layer[l].xindex] & 0x08) ? (m_lcd.gb_vram + m_lcd.gbc_chrgen_offs) : (m_lcd.gb_vram + m_lcd.gb_chrgen_offs); |
| 1429 | m_layer[l].xindex = (m_layer[l].xindex + 1) & 31; |
| 1430 | m_layer[l].xshift = 0; |
| 1431 | tiles = (gbcmap[m_layer[l].xindex] & 0x08) ? (m_vram + m_gbc_chrgen_offs) : (m_vram + m_gb_chrgen_offs); |
| 1028 | 1432 | |
| 1029 | 1433 | /* Check for vertical flip */ |
| 1030 | | if ( gbcmap[ m_lcd.layer[l].xindex ] & 0x40 ) |
| 1434 | if (gbcmap[m_layer[l].xindex] & 0x40) |
| 1031 | 1435 | { |
| 1032 | | tiles += ( ( 7 - ( m_lcd.layer[l].bgline & 0x07 ) ) << 1 ); |
| 1436 | tiles += ((7 - (m_layer[l].bgline & 0x07)) << 1); |
| 1033 | 1437 | } |
| 1034 | 1438 | else |
| 1035 | 1439 | { |
| 1036 | | tiles += ( ( m_lcd.layer[l].bgline & 0x07 ) << 1 ); |
| 1440 | tiles += ((m_layer[l].bgline & 0x07) << 1); |
| 1037 | 1441 | } |
| 1038 | | tile_index = ( map[ m_lcd.layer[l].xindex ] ^ m_lcd.gb_tile_no_mod ) * 16; |
| 1039 | | data = tiles[ tile_index ] | ( tiles[ tile_index + 1 ] << 8 ); |
| 1442 | tile_index = (map[m_layer[l].xindex] ^ m_gb_tile_no_mod) * 16; |
| 1443 | data = tiles[tile_index] | (tiles[tile_index + 1] << 8); |
| 1040 | 1444 | } |
| 1041 | 1445 | } |
| 1042 | 1446 | l++; |
| 1043 | 1447 | } |
| 1044 | | if ( m_lcd.end_x == 160 && ( LCDCONT & 0x02 ) ) |
| 1448 | if (m_end_x == 160 && (LCDCONT & 0x02)) |
| 1045 | 1449 | { |
| 1046 | | cgb_update_sprites(); |
| 1450 | update_sprites(); |
| 1047 | 1451 | } |
| 1048 | | m_lcd.start_x = m_lcd.end_x; |
| 1452 | m_start_x = m_end_x; |
| 1049 | 1453 | } |
| 1050 | 1454 | } |
| 1051 | 1455 | else |
| 1052 | 1456 | { |
| 1053 | | if ( ! ( LCDCONT & 0x80 ) ) |
| 1457 | if (!(LCDCONT & 0x80)) |
| 1054 | 1458 | { |
| 1055 | 1459 | /* Draw an empty line when LCD is disabled */ |
| 1056 | | if ( m_lcd.previous_line != m_lcd.current_line ) |
| 1460 | if (m_previous_line != m_current_line) |
| 1057 | 1461 | { |
| 1058 | | if ( m_lcd.current_line < 144 ) |
| 1462 | if (m_current_line < 144) |
| 1059 | 1463 | { |
| 1060 | 1464 | screen_device *screen = machine().first_screen(); |
| 1061 | 1465 | const rectangle &r1 = screen->visible_area(); |
| 1062 | | rectangle r(r1.min_x, r1.max_x, m_lcd.current_line, m_lcd.current_line); |
| 1063 | | bitmap.fill(( ! m_lcd.gbc_mode ) ? 0 : 32767 , r); |
| 1466 | rectangle r(r1.min_x, r1.max_x, m_current_line, m_current_line); |
| 1467 | bitmap.fill((!m_gbc_mode) ? 0 : 32767 , r); |
| 1064 | 1468 | } |
| 1065 | | m_lcd.previous_line = m_lcd.current_line; |
| 1469 | m_previous_line = m_current_line; |
| 1066 | 1470 | } |
| 1067 | 1471 | } |
| 1068 | 1472 | } |
| r23879 | r23880 | |
| 1070 | 1474 | g_profiler.stop(); |
| 1071 | 1475 | } |
| 1072 | 1476 | |
| 1073 | | /* OAM contents on power up. |
| 1074 | 1477 | |
| 1075 | | The OAM area seems contain some kind of unit fingerprint. On each boot |
| 1076 | | the data is almost always the same. Some random bits are flipped between |
| 1077 | | different boots. It is currently unknown how much these fingerprints |
| 1078 | | differ between different units. |
| 1079 | | |
| 1080 | | OAM fingerprints taken from Wilbert Pol's own unit. |
| 1081 | | */ |
| 1082 | | |
| 1083 | | static const UINT8 dmg_oam_fingerprint[0x100] = { |
| 1084 | | 0xD8, 0xE6, 0xB3, 0x89, 0xEC, 0xDE, 0x11, 0x62, 0x0B, 0x7E, 0x48, 0x9E, 0xB9, 0x6E, 0x26, 0xC9, |
| 1085 | | 0x36, 0xF4, 0x7D, 0xE4, 0xD9, 0xCE, 0xFA, 0x5E, 0xA3, 0x77, 0x60, 0xFC, 0x1C, 0x64, 0x8B, 0xAC, |
| 1086 | | 0xB6, 0x74, 0x3F, 0x9A, 0x0E, 0xFE, 0xEA, 0xA9, 0x40, 0x3A, 0x7A, 0xB6, 0xF2, 0xED, 0xA8, 0x3E, |
| 1087 | | 0xAF, 0x2C, 0xD2, 0xF2, 0x01, 0xE0, 0x5B, 0x3A, 0x53, 0x6A, 0x1C, 0x6C, 0x20, 0xD9, 0x22, 0xB4, |
| 1088 | | 0x8C, 0x38, 0x71, 0x69, 0x3E, 0x93, 0xA3, 0x22, 0xCE, 0x76, 0x24, 0xE7, 0x1A, 0x14, 0x6B, 0xB1, |
| 1089 | | 0xF9, 0x3D, 0xBF, 0x3D, 0x74, 0x64, 0xCB, 0xF5, 0xDC, 0x9A, 0x53, 0xC6, 0x0E, 0x78, 0x34, 0xCB, |
| 1090 | | 0x42, 0xB3, 0xFF, 0x07, 0x73, 0xAE, 0x6C, 0xA2, 0x6F, 0x6A, 0xA4, 0x66, 0x0A, 0x8C, 0x40, 0xB3, |
| 1091 | | 0x9A, 0x3D, 0x39, 0x78, 0xAB, 0x29, 0xE7, 0xC5, 0x7A, 0xDD, 0x51, 0x95, 0x2B, 0xE4, 0x1B, 0xF6, |
| 1092 | | 0x31, 0x16, 0x34, 0xFE, 0x11, 0xF2, 0x5E, 0x11, 0xF3, 0x95, 0x66, 0xB9, 0x37, 0xC2, 0xAD, 0x6D, |
| 1093 | | 0x1D, 0xA7, 0x79, 0x06, 0xD7, 0xE5, 0x8F, 0xFA, 0x9C, 0x02, 0x0C, 0x31, 0x8B, 0x17, 0x2E, 0x31, |
| 1094 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1095 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1096 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1097 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1098 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1099 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 1100 | | }; |
| 1101 | | |
| 1102 | | static const UINT8 mgb_oam_fingerprint[0x100] = { |
| 1103 | | 0xB9, 0xE9, 0x0D, 0x69, 0xBB, 0x7F, 0x00, 0x80, 0xE9, 0x7B, 0x79, 0xA2, 0xFD, 0xCF, 0xD8, 0x0A, |
| 1104 | | 0x87, 0xEF, 0x44, 0x11, 0xFE, 0x37, 0x10, 0x21, 0xFA, 0xFF, 0x00, 0x17, 0xF6, 0x4F, 0x83, 0x03, |
| 1105 | | 0x3A, 0xF4, 0x00, 0x24, 0xBB, 0xAE, 0x05, 0x01, 0xFF, 0xF7, 0x12, 0x48, 0xA7, 0x5E, 0xF6, 0x28, |
| 1106 | | 0x5B, 0xFF, 0x2E, 0x10, 0xFF, 0xB9, 0x50, 0xC8, 0xAF, 0x77, 0x2C, 0x1A, 0x62, 0xD7, 0x81, 0xC2, |
| 1107 | | 0xFD, 0x5F, 0xA0, 0x94, 0xAF, 0xFF, 0x51, 0x20, 0x36, 0x76, 0x50, 0x0A, 0xFD, 0xF6, 0x20, 0x00, |
| 1108 | | 0xFE, 0xF7, 0xA0, 0x68, 0xFF, 0xFC, 0x29, 0x51, 0xA3, 0xFA, 0x06, 0xC4, 0x94, 0xFF, 0x39, 0x0A, |
| 1109 | | 0xFF, 0x6C, 0x20, 0x20, 0xF1, 0xAD, 0x0C, 0x81, 0x56, 0xFB, 0x03, 0x82, 0xFF, 0xFF, 0x08, 0x58, |
| 1110 | | 0x96, 0x7E, 0x01, 0x4D, 0xFF, 0xE4, 0x82, 0xE3, 0x3D, 0xBB, 0x54, 0x00, 0x3D, 0xF3, 0x04, 0x21, |
| 1111 | | 0xB7, 0x39, 0xCC, 0x10, 0xF9, 0x5B, 0x80, 0x50, 0x3F, 0x6A, 0x1C, 0x21, 0x1F, 0xFA, 0xA8, 0x52, |
| 1112 | | 0x5F, 0xB3, 0x44, 0xA1, 0x96, 0x1E, 0x00, 0x27, 0x63, 0x77, 0x30, 0x54, 0x37, 0x6F, 0x60, 0x22, |
| 1113 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1114 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1115 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1116 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1117 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1118 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 1119 | | }; |
| 1120 | | |
| 1121 | | static const UINT8 cgb_oam_fingerprint[0x100] = { |
| 1122 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1123 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1124 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1125 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1126 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1127 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1128 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1129 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1130 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1131 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1132 | | 0x74, 0xFF, 0x09, 0x00, 0x9D, 0x61, 0xA8, 0x28, 0x36, 0x1E, 0x58, 0xAA, 0x75, 0x74, 0xA1, 0x42, |
| 1133 | | 0x05, 0x96, 0x40, 0x09, 0x41, 0x02, 0x60, 0x00, 0x1F, 0x11, 0x22, 0xBC, 0x31, 0x52, 0x22, 0x54, |
| 1134 | | 0x22, 0xA9, 0xC4, 0x00, 0x1D, 0xAD, 0x80, 0x0C, 0x5D, 0xFA, 0x51, 0x92, 0x93, 0x98, 0xA4, 0x04, |
| 1135 | | 0x22, 0xA9, 0xC4, 0x00, 0x1D, 0xAD, 0x80, 0x0C, 0x5D, 0xFA, 0x51, 0x92, 0x93, 0x98, 0xA4, 0x04, |
| 1136 | | 0x22, 0xA9, 0xC4, 0x00, 0x1D, 0xAD, 0x80, 0x0C, 0x5D, 0xFA, 0x51, 0x92, 0x93, 0x98, 0xA4, 0x04, |
| 1137 | | 0x22, 0xA9, 0xC4, 0x00, 0x1D, 0xAD, 0x80, 0x0C, 0x5D, 0xFA, 0x51, 0x92, 0x93, 0x98, 0xA4, 0x04 |
| 1138 | | }; |
| 1139 | | |
| 1140 | | /* |
| 1141 | | For an AGS in CGB mode this data is: */ |
| 1142 | | #if 0 |
| 1143 | | static const UINT8 abs_oam_fingerprint[0x100] = { |
| 1144 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1145 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1146 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1147 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1148 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1149 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1150 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1151 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1152 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1153 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1154 | | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
| 1155 | | 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, |
| 1156 | | 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, |
| 1157 | | 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, |
| 1158 | | 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, |
| 1159 | | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF |
| 1160 | | }; |
| 1161 | | #endif |
| 1162 | | |
| 1163 | | enum { |
| 1164 | | GB_LCD_STATE_LYXX_M3=1, |
| 1165 | | GB_LCD_STATE_LYXX_PRE_M0, |
| 1166 | | GB_LCD_STATE_LYXX_M0, |
| 1167 | | GB_LCD_STATE_LYXX_M0_SCX3, |
| 1168 | | GB_LCD_STATE_LYXX_M0_GBC_PAL, |
| 1169 | | GB_LCD_STATE_LYXX_M0_PRE_INC, |
| 1170 | | GB_LCD_STATE_LYXX_M0_INC, |
| 1171 | | GB_LCD_STATE_LY00_M2, |
| 1172 | | GB_LCD_STATE_LYXX_M2, |
| 1173 | | GB_LCD_STATE_LY9X_M1, |
| 1174 | | GB_LCD_STATE_LY9X_M1_INC, |
| 1175 | | GB_LCD_STATE_LY00_M1, |
| 1176 | | GB_LCD_STATE_LY00_M1_1, |
| 1177 | | GB_LCD_STATE_LY00_M1_2, |
| 1178 | | GB_LCD_STATE_LY00_M0 |
| 1179 | | }; |
| 1180 | | |
| 1181 | | TIMER_CALLBACK_MEMBER(gb_state::gb_video_init_vbl) |
| 1478 | TIMER_CALLBACK_MEMBER(gb_lcd_device::video_init_vbl) |
| 1182 | 1479 | { |
| 1183 | | m_maincpu->set_input_line(VBL_INT, ASSERT_LINE ); |
| 1480 | m_maincpu->set_input_line(VBL_INT, ASSERT_LINE); |
| 1184 | 1481 | } |
| 1185 | 1482 | |
| 1186 | | void gb_state::gb_videoptr_restore() |
| 1483 | UINT32 gb_lcd_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 1187 | 1484 | { |
| 1188 | | m_lcd.layer[0].bg_map = m_lcd.gb_vram + m_lcd.gb_bgdtab_offs; |
| 1189 | | m_lcd.layer[0].bg_tiles = m_lcd.gb_vram + m_lcd.gb_chrgen_offs; |
| 1190 | | m_lcd.layer[1].bg_map = m_lcd.gb_vram + m_lcd.gb_wndtab_offs; |
| 1191 | | m_lcd.layer[1].bg_tiles = m_lcd.gb_vram + m_lcd.gb_chrgen_offs; |
| 1192 | | } |
| 1193 | | |
| 1194 | | void gb_state::gbc_videoptr_restore() |
| 1195 | | { |
| 1196 | | m_lcd.layer[0].bg_map = m_lcd.gb_vram + m_lcd.gb_bgdtab_offs; |
| 1197 | | m_lcd.layer[0].gbc_map = m_lcd.gb_vram + m_lcd.gbc_bgdtab_offs; |
| 1198 | | m_lcd.layer[1].bg_map = m_lcd.gb_vram + m_lcd.gb_wndtab_offs; |
| 1199 | | m_lcd.layer[1].gbc_map = m_lcd.gb_vram + m_lcd.gbc_wndtab_offs; |
| 1200 | | } |
| 1201 | | |
| 1202 | | void gb_state::save_gb_video() |
| 1203 | | { |
| 1204 | | save_item(NAME(m_lcd.window_lines_drawn)); |
| 1205 | | save_item(NAME(m_lcd.gb_vid_regs)); |
| 1206 | | save_item(NAME(m_lcd.bg_zbuf)); |
| 1207 | | |
| 1208 | | save_item(NAME(m_lcd.cgb_bpal)); |
| 1209 | | save_item(NAME(m_lcd.cgb_spal)); |
| 1210 | | |
| 1211 | | save_item(NAME(m_lcd.gb_bpal)); |
| 1212 | | save_item(NAME(m_lcd.gb_spal0)); |
| 1213 | | save_item(NAME(m_lcd.gb_spal1)); |
| 1214 | | |
| 1215 | | save_item(NAME(m_lcd.current_line)); |
| 1216 | | save_item(NAME(m_lcd.cmp_line)); |
| 1217 | | save_item(NAME(m_lcd.sprCount)); |
| 1218 | | save_item(NAME(m_lcd.sprite)); |
| 1219 | | save_item(NAME(m_lcd.previous_line)); |
| 1220 | | save_item(NAME(m_lcd.start_x)); |
| 1221 | | save_item(NAME(m_lcd.end_x)); |
| 1222 | | save_item(NAME(m_lcd.mode)); |
| 1223 | | save_item(NAME(m_lcd.state)); |
| 1224 | | save_item(NAME(m_lcd.lcd_irq_line)); |
| 1225 | | save_item(NAME(m_lcd.triggering_line_irq)); |
| 1226 | | save_item(NAME(m_lcd.line_irq)); |
| 1227 | | save_item(NAME(m_lcd.triggering_mode_irq)); |
| 1228 | | save_item(NAME(m_lcd.mode_irq)); |
| 1229 | | save_item(NAME(m_lcd.delayed_line_irq)); |
| 1230 | | save_item(NAME(m_lcd.sprite_cycles)); |
| 1231 | | save_item(NAME(m_lcd.scrollx_adjust)); |
| 1232 | | save_item(NAME(m_lcd.oam_locked)); |
| 1233 | | save_item(NAME(m_lcd.vram_locked)); |
| 1234 | | save_item(NAME(m_lcd.pal_locked)); |
| 1235 | | save_item(NAME(m_lcd.hdma_enabled)); |
| 1236 | | save_item(NAME(m_lcd.hdma_possible)); |
| 1237 | | save_item(NAME(m_lcd.gbc_mode)); |
| 1238 | | save_item(NAME(m_lcd.gb_tile_no_mod)); |
| 1239 | | save_item(NAME(m_lcd.gb_vram_bank)); |
| 1240 | | |
| 1241 | | save_item(NAME(m_lcd.gb_chrgen_offs)); |
| 1242 | | save_item(NAME(m_lcd.gb_bgdtab_offs)); |
| 1243 | | save_item(NAME(m_lcd.gb_wndtab_offs)); |
| 1244 | | save_item(NAME(m_lcd.gbc_chrgen_offs)); |
| 1245 | | save_item(NAME(m_lcd.gbc_bgdtab_offs)); |
| 1246 | | save_item(NAME(m_lcd.gbc_wndtab_offs)); |
| 1247 | | |
| 1248 | | save_item(NAME(m_lcd.layer[0].enabled)); |
| 1249 | | save_item(NAME(m_lcd.layer[0].xindex)); |
| 1250 | | save_item(NAME(m_lcd.layer[0].xshift)); |
| 1251 | | save_item(NAME(m_lcd.layer[0].xstart)); |
| 1252 | | save_item(NAME(m_lcd.layer[0].xend)); |
| 1253 | | save_item(NAME(m_lcd.layer[0].bgline)); |
| 1254 | | save_item(NAME(m_lcd.layer[1].enabled)); |
| 1255 | | save_item(NAME(m_lcd.layer[1].xindex)); |
| 1256 | | save_item(NAME(m_lcd.layer[1].xshift)); |
| 1257 | | save_item(NAME(m_lcd.layer[1].xstart)); |
| 1258 | | save_item(NAME(m_lcd.layer[1].xend)); |
| 1259 | | save_item(NAME(m_lcd.layer[1].bgline)); |
| 1260 | | } |
| 1261 | | |
| 1262 | | void gb_state::gb_video_start( int mode ) |
| 1263 | | { |
| 1264 | | int vram_size = (mode == GB_VIDEO_CGB) ? 0x4000 : 0x2000; |
| 1265 | | |
| 1266 | | machine().primary_screen->register_screen_bitmap(m_bitmap); |
| 1267 | | m_lcd.gb_vram = auto_alloc_array_clear(machine(), UINT8, vram_size); |
| 1268 | | m_lcd.gb_oam = auto_alloc_array_clear(machine(), UINT8, 0x100); |
| 1269 | | |
| 1270 | | save_pointer(NAME(m_lcd.gb_vram), vram_size); |
| 1271 | | save_pointer(NAME(m_lcd.gb_oam), 0x100); |
| 1272 | | save_gb_video(); |
| 1273 | | |
| 1274 | | if (mode == GB_VIDEO_CGB) |
| 1275 | | { |
| 1276 | | m_lcd.lcd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gb_state::gbc_lcd_timer_proc),this)); |
| 1277 | | machine().save().register_postload(save_prepost_delegate(FUNC(gb_state::gbc_videoptr_restore), this)); |
| 1278 | | } |
| 1279 | | else |
| 1280 | | { |
| 1281 | | m_lcd.lcd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gb_state::gb_lcd_timer_proc),this)); |
| 1282 | | machine().save().register_postload(save_prepost_delegate(FUNC(gb_state::gb_videoptr_restore), this)); |
| 1283 | | } |
| 1284 | | |
| 1285 | | switch (mode) |
| 1286 | | { |
| 1287 | | case GB_VIDEO_DMG: |
| 1288 | | memcpy(m_lcd.gb_oam, dmg_oam_fingerprint, 0x100); |
| 1289 | | break; |
| 1290 | | case GB_VIDEO_MGB: |
| 1291 | | /* Initialize part of VRAM. This code must be deleted when we have added the bios dump */ |
| 1292 | | for (int i = 1; i < 0x0d; i++) |
| 1293 | | { |
| 1294 | | m_lcd.gb_vram[0x1903 + i] = i; |
| 1295 | | m_lcd.gb_vram[0x1923 + i] = i + 0x0C; |
| 1296 | | } |
| 1297 | | m_lcd.gb_vram[0x1910] = 0x19; |
| 1298 | | memcpy(m_lcd.gb_oam, mgb_oam_fingerprint, 0x100); |
| 1299 | | break; |
| 1300 | | case GB_VIDEO_SGB: |
| 1301 | | break; |
| 1302 | | case GB_VIDEO_CGB: |
| 1303 | | memcpy(m_lcd.gb_oam, cgb_oam_fingerprint, 0x100); |
| 1304 | | break; |
| 1305 | | } |
| 1306 | | } |
| 1307 | | |
| 1308 | | |
| 1309 | | UINT32 gb_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 1310 | | { |
| 1311 | 1485 | copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect); |
| 1312 | 1486 | return 0; |
| 1313 | 1487 | } |
| 1314 | 1488 | |
| 1315 | | void gb_state::gb_video_reset( int mode ) |
| 1316 | | { |
| 1317 | | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 1318 | 1489 | |
| 1319 | | m_lcd.window_lines_drawn = 0; |
| 1320 | | |
| 1321 | | m_lcd.current_line = 0; |
| 1322 | | m_lcd.cmp_line = 0; |
| 1323 | | m_lcd.sprCount = 0; |
| 1324 | | m_lcd.previous_line = 0; |
| 1325 | | m_lcd.start_x = 0; |
| 1326 | | m_lcd.end_x = 0; |
| 1327 | | m_lcd.mode = 0; |
| 1328 | | m_lcd.state = 0; |
| 1329 | | m_lcd.lcd_irq_line = 0; |
| 1330 | | m_lcd.triggering_line_irq = 0; |
| 1331 | | m_lcd.line_irq = 0; |
| 1332 | | m_lcd.triggering_mode_irq = 0; |
| 1333 | | m_lcd.mode_irq = 0; |
| 1334 | | m_lcd.delayed_line_irq = 0; |
| 1335 | | m_lcd.sprite_cycles = 0; |
| 1336 | | m_lcd.scrollx_adjust = 0; |
| 1337 | | m_lcd.oam_locked = 0; |
| 1338 | | m_lcd.vram_locked = 0; |
| 1339 | | m_lcd.pal_locked = 0; |
| 1340 | | m_lcd.gbc_mode = 0; |
| 1341 | | m_lcd.gb_tile_no_mod = 0; |
| 1342 | | m_lcd.gb_vram_bank = 0; |
| 1343 | | |
| 1344 | | m_lcd.gb_chrgen_offs = 0; |
| 1345 | | m_lcd.gb_bgdtab_offs = 0x1c00; |
| 1346 | | m_lcd.gb_wndtab_offs = 0x1c00; |
| 1347 | | |
| 1348 | | memset(&m_lcd.gb_vid_regs, 0, sizeof(m_lcd.gb_vid_regs)); |
| 1349 | | memset(&m_lcd.bg_zbuf, 0, sizeof(m_lcd.bg_zbuf)); |
| 1350 | | memset(&m_lcd.cgb_bpal, 0, sizeof(m_lcd.cgb_bpal)); |
| 1351 | | memset(&m_lcd.cgb_spal, 0, sizeof(m_lcd.cgb_spal)); |
| 1352 | | memset(&m_lcd.sprite, 0, sizeof(m_lcd.sprite)); |
| 1353 | | memset(&m_lcd.layer[0], 0, sizeof(m_lcd.layer[0])); |
| 1354 | | memset(&m_lcd.layer[1], 0, sizeof(m_lcd.layer[1])); |
| 1355 | | |
| 1356 | | // specific reg initialization |
| 1357 | | m_lcd.gb_vid_regs[0x06] = 0xff; |
| 1358 | | |
| 1359 | | for (int i = 0x0c; i < _NR_GB_VID_REGS; i++) |
| 1360 | | m_lcd.gb_vid_regs[i] = 0xff; |
| 1361 | | |
| 1362 | | LCDSTAT = 0x80; |
| 1363 | | LCDCONT = 0x00; /* Video hardware is turned off at boot time */ |
| 1364 | | m_lcd.current_line = CURLINE = CMPLINE = 0x00; |
| 1365 | | SCROLLX = SCROLLY = 0x00; |
| 1366 | | SPR0PAL = SPR1PAL = 0xFF; |
| 1367 | | WNDPOSX = WNDPOSY = 0x00; |
| 1368 | | |
| 1369 | | // Initialize palette arrays |
| 1370 | | for (int i = 0; i < 4; i++) |
| 1371 | | m_lcd.gb_bpal[i] = m_lcd.gb_spal0[i] = m_lcd.gb_spal1[i] = i; |
| 1372 | | |
| 1373 | | switch( mode ) |
| 1374 | | { |
| 1375 | | case GB_VIDEO_DMG: |
| 1376 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(456)); |
| 1377 | | |
| 1378 | | /* set the scanline update function */ |
| 1379 | | update_scanline = &gb_state::gb_update_scanline; |
| 1380 | | break; |
| 1381 | | |
| 1382 | | case GB_VIDEO_MGB: |
| 1383 | | /* set the scanline update function */ |
| 1384 | | update_scanline = &gb_state::gb_update_scanline; |
| 1385 | | /* Make sure the VBlank interrupt is set when the first instruction gets executed */ |
| 1386 | | machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(1), timer_expired_delegate(FUNC(gb_state::gb_video_init_vbl),this)); |
| 1387 | | |
| 1388 | | /* Initialize some video registers */ |
| 1389 | | gb_video_w(space, 0x0, 0x91); /* LCDCONT */ |
| 1390 | | gb_video_w(space, 0x7, 0xFC); /* BGRDPAL */ |
| 1391 | | gb_video_w(space, 0x8, 0xFC); /* SPR0PAL */ |
| 1392 | | gb_video_w(space, 0x9, 0xFC); /* SPR1PAL */ |
| 1393 | | |
| 1394 | | CURLINE = m_lcd.current_line = 0; |
| 1395 | | LCDSTAT = ( LCDSTAT & 0xF8 ) | 0x05; |
| 1396 | | m_lcd.mode = 1; |
| 1397 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(60), GB_LCD_STATE_LY00_M0); |
| 1398 | | break; |
| 1399 | | |
| 1400 | | case GB_VIDEO_SGB: |
| 1401 | | /* set the scanline update function */ |
| 1402 | | update_scanline = &gb_state::sgb_update_scanline; |
| 1403 | | break; |
| 1404 | | |
| 1405 | | case GB_VIDEO_CGB: |
| 1406 | | /* set the scanline update function */ |
| 1407 | | update_scanline = &gb_state::cgb_update_scanline; |
| 1408 | | |
| 1409 | | m_lcd.gbc_chrgen_offs = 0x2000; |
| 1410 | | m_lcd.gbc_bgdtab_offs = 0x3c00; |
| 1411 | | m_lcd.gbc_wndtab_offs = 0x3c00; |
| 1412 | | |
| 1413 | | /* HDMA disabled */ |
| 1414 | | m_lcd.hdma_enabled = 0; |
| 1415 | | m_lcd.hdma_possible = 0; |
| 1416 | | |
| 1417 | | m_lcd.gbc_mode = 1; |
| 1418 | | break; |
| 1419 | | } |
| 1420 | | } |
| 1421 | | |
| 1422 | | |
| 1423 | | void gb_state::gbc_hdma(UINT16 length) |
| 1490 | void gb_lcd_device::increment_scanline() |
| 1424 | 1491 | { |
| 1425 | | UINT16 src, dst; |
| 1426 | | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 1427 | | |
| 1428 | | src = ((UINT16)HDMA1 << 8) | (HDMA2 & 0xF0); |
| 1429 | | dst = ((UINT16)(HDMA3 & 0x1F) << 8) | (HDMA4 & 0xF0); |
| 1430 | | dst |= 0x8000; |
| 1431 | | while( length > 0 ) |
| 1492 | m_current_line = (m_current_line + 1) % 154; |
| 1493 | if (LCDCONT & 0x80) |
| 1432 | 1494 | { |
| 1433 | | space.write_byte( dst++, space.read_byte( src++ ) ); |
| 1434 | | length--; |
| 1495 | CURLINE = m_current_line; |
| 1435 | 1496 | } |
| 1436 | | HDMA1 = src >> 8; |
| 1437 | | HDMA2 = src & 0xF0; |
| 1438 | | HDMA3 = 0x1f & (dst >> 8); |
| 1439 | | HDMA4 = dst & 0xF0; |
| 1440 | | HDMA5--; |
| 1441 | | if( (HDMA5 & 0x7f) == 0x7f ) |
| 1497 | if (m_current_line == 0) |
| 1442 | 1498 | { |
| 1443 | | HDMA5 = 0xff; |
| 1444 | | m_lcd.hdma_enabled = 0; |
| 1499 | m_window_lines_drawn = 0; |
| 1445 | 1500 | } |
| 1446 | 1501 | } |
| 1447 | 1502 | |
| 1448 | | |
| 1449 | | void gb_state::gb_increment_scanline() |
| 1503 | TIMER_CALLBACK_MEMBER(gb_lcd_device::lcd_timer_proc) |
| 1450 | 1504 | { |
| 1451 | | m_lcd.current_line = ( m_lcd.current_line + 1 ) % 154; |
| 1452 | | if ( LCDCONT & 0x80 ) |
| 1453 | | { |
| 1454 | | CURLINE = m_lcd.current_line; |
| 1455 | | } |
| 1456 | | if ( m_lcd.current_line == 0 ) |
| 1457 | | { |
| 1458 | | m_lcd.window_lines_drawn = 0; |
| 1459 | | } |
| 1460 | | } |
| 1461 | | |
| 1462 | | TIMER_CALLBACK_MEMBER(gb_state::gb_lcd_timer_proc) |
| 1463 | | { |
| 1464 | 1505 | static const int sprite_cycles[] = { 0, 8, 20, 32, 44, 52, 64, 76, 88, 96, 108 }; |
| 1465 | 1506 | |
| 1466 | | m_lcd.state = param; |
| 1507 | m_state = param; |
| 1467 | 1508 | |
| 1468 | | if ( LCDCONT & 0x80 ) |
| 1509 | if (LCDCONT & 0x80) |
| 1469 | 1510 | { |
| 1470 | | switch( m_lcd.state ) |
| 1511 | switch (m_state) |
| 1471 | 1512 | { |
| 1472 | 1513 | case GB_LCD_STATE_LYXX_PRE_M0: /* Just before switching to mode 0 */ |
| 1473 | | m_lcd.mode = 0; |
| 1474 | | if ( LCDSTAT & 0x08 ) |
| 1514 | m_mode = 0; |
| 1515 | if (LCDSTAT & 0x08) |
| 1475 | 1516 | { |
| 1476 | | if ( ! m_lcd.mode_irq ) |
| 1517 | if (!m_mode_irq) |
| 1477 | 1518 | { |
| 1478 | | if ( ! m_lcd.line_irq && ! m_lcd.delayed_line_irq ) |
| 1519 | if (!m_line_irq && !m_delayed_line_irq) |
| 1479 | 1520 | { |
| 1480 | | m_lcd.mode_irq = 1; |
| 1481 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1521 | m_mode_irq = 1; |
| 1522 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1482 | 1523 | } |
| 1483 | 1524 | } |
| 1484 | 1525 | else |
| 1485 | 1526 | { |
| 1486 | | m_lcd.mode_irq = 0; |
| 1527 | m_mode_irq = 0; |
| 1487 | 1528 | } |
| 1488 | 1529 | } |
| 1489 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0); |
| 1530 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0); |
| 1490 | 1531 | break; |
| 1491 | 1532 | case GB_LCD_STATE_LYXX_M0: /* Switch to mode 0 */ |
| 1492 | 1533 | /* update current scanline */ |
| 1493 | | (this->*update_scanline)(); |
| 1534 | update_scanline(); |
| 1494 | 1535 | /* Increment the number of window lines drawn if enabled */ |
| 1495 | | if ( m_lcd.layer[1].enabled ) |
| 1536 | if (m_layer[1].enabled) |
| 1496 | 1537 | { |
| 1497 | | m_lcd.window_lines_drawn++; |
| 1538 | m_window_lines_drawn++; |
| 1498 | 1539 | } |
| 1499 | | m_lcd.previous_line = m_lcd.current_line; |
| 1540 | m_previous_line = m_current_line; |
| 1500 | 1541 | /* Set Mode 0 lcdstate */ |
| 1501 | | m_lcd.mode = 0; |
| 1542 | m_mode = 0; |
| 1502 | 1543 | LCDSTAT &= 0xFC; |
| 1503 | | m_lcd.oam_locked = UNLOCKED; |
| 1504 | | m_lcd.vram_locked = UNLOCKED; |
| 1544 | m_oam_locked = UNLOCKED; |
| 1545 | m_vram_locked = UNLOCKED; |
| 1505 | 1546 | /* |
| 1506 | 1547 | There seems to a kind of feature in the Game Boy hardware when the lowest bits of the |
| 1507 | 1548 | SCROLLX register equals 3 or 7, then the delayed M0 irq is triggered 4 cycles later |
| 1508 | 1549 | than usual. |
| 1509 | 1550 | The SGB probably has the same bug. |
| 1510 | 1551 | */ |
| 1511 | | if ( ( SCROLLX & 0x03 ) == 0x03 ) |
| 1552 | if ((SCROLLX & 0x03) == 0x03) |
| 1512 | 1553 | { |
| 1513 | | m_lcd.scrollx_adjust += 4; |
| 1514 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_SCX3); |
| 1554 | m_scrollx_adjust += 4; |
| 1555 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_SCX3); |
| 1515 | 1556 | break; |
| 1516 | 1557 | } |
| 1517 | 1558 | case GB_LCD_STATE_LYXX_M0_SCX3: |
| 1518 | 1559 | /* Generate lcd interrupt if requested */ |
| 1519 | | if ( ! m_lcd.mode_irq && ( LCDSTAT & 0x08 ) && |
| 1520 | | ( ( ! m_lcd.line_irq && m_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) |
| 1560 | if (!m_mode_irq && (LCDSTAT & 0x08) && |
| 1561 | ((!m_line_irq && m_delayed_line_irq) || !(LCDSTAT & 0x40))) |
| 1521 | 1562 | { |
| 1522 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1563 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1523 | 1564 | } |
| 1524 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(196 - m_lcd.scrollx_adjust - m_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC); |
| 1565 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(196 - m_scrollx_adjust - m_sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC); |
| 1525 | 1566 | break; |
| 1526 | 1567 | case GB_LCD_STATE_LYXX_M0_PRE_INC: /* Just before incrementing the line counter go to mode 2 internally */ |
| 1527 | | if ( CURLINE < 143 ) |
| 1568 | if (CURLINE < 143) |
| 1528 | 1569 | { |
| 1529 | | m_lcd.mode = 2; |
| 1530 | | m_lcd.triggering_mode_irq = ( LCDSTAT & 0x20 ) ? 1 : 0; |
| 1531 | | if ( m_lcd.triggering_mode_irq ) |
| 1570 | m_mode = 2; |
| 1571 | m_triggering_mode_irq = (LCDSTAT & 0x20) ? 1 : 0; |
| 1572 | if (m_triggering_mode_irq) |
| 1532 | 1573 | { |
| 1533 | | if ( ! m_lcd.mode_irq ) |
| 1574 | if (!m_mode_irq) |
| 1534 | 1575 | { |
| 1535 | | if ( ! m_lcd.line_irq && ! m_lcd.delayed_line_irq ) |
| 1576 | if (!m_line_irq && !m_delayed_line_irq) |
| 1536 | 1577 | { |
| 1537 | | m_lcd.mode_irq = 1; |
| 1538 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1578 | m_mode_irq = 1; |
| 1579 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1539 | 1580 | } |
| 1540 | 1581 | } |
| 1541 | 1582 | else |
| 1542 | 1583 | { |
| 1543 | | m_lcd.mode_irq = 0; |
| 1584 | m_mode_irq = 0; |
| 1544 | 1585 | } |
| 1545 | 1586 | } |
| 1546 | 1587 | } |
| 1547 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_INC); |
| 1588 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_INC); |
| 1548 | 1589 | break; |
| 1549 | 1590 | case GB_LCD_STATE_LYXX_M0_INC: /* Increment LY, stay in M0 for 4 more cycles */ |
| 1550 | | gb_increment_scanline(); |
| 1551 | | m_lcd.delayed_line_irq = m_lcd.line_irq; |
| 1552 | | m_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1553 | | m_lcd.line_irq = 0; |
| 1554 | | if ( ! m_lcd.mode_irq && ! m_lcd.delayed_line_irq && m_lcd.triggering_line_irq && ! m_lcd.triggering_mode_irq ) |
| 1591 | increment_scanline(); |
| 1592 | m_delayed_line_irq = m_line_irq; |
| 1593 | m_triggering_line_irq = ((CMPLINE == CURLINE) && (LCDSTAT & 0x40)) ? 1 : 0; |
| 1594 | m_line_irq = 0; |
| 1595 | if (!m_mode_irq && !m_delayed_line_irq && m_triggering_line_irq && !m_triggering_mode_irq) |
| 1555 | 1596 | { |
| 1556 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 1557 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1597 | m_line_irq = m_triggering_line_irq; |
| 1598 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1558 | 1599 | } |
| 1559 | 1600 | /* Reset LY==LYC STAT bit */ |
| 1560 | 1601 | LCDSTAT &= 0xFB; |
| 1561 | 1602 | /* Check if we're going into VBlank next */ |
| 1562 | | if ( CURLINE == 144 ) |
| 1603 | if (CURLINE == 144) |
| 1563 | 1604 | { |
| 1564 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY9X_M1); |
| 1605 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY9X_M1); |
| 1565 | 1606 | } |
| 1566 | 1607 | else |
| 1567 | 1608 | { |
| 1568 | 1609 | /* Internally switch to mode 2 */ |
| 1569 | | m_lcd.mode = 2; |
| 1610 | m_mode = 2; |
| 1570 | 1611 | /* Generate lcd interrupt if requested */ |
| 1571 | | if ( ! m_lcd.mode_irq && m_lcd.triggering_mode_irq && |
| 1572 | | ( ( ! m_lcd.triggering_line_irq && ! m_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) |
| 1612 | if (!m_mode_irq && m_triggering_mode_irq && |
| 1613 | ((!m_triggering_line_irq && !m_delayed_line_irq) || !(LCDSTAT & 0x40))) |
| 1573 | 1614 | { |
| 1574 | | m_lcd.mode_irq = 1; |
| 1575 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1615 | m_mode_irq = 1; |
| 1616 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1576 | 1617 | } |
| 1577 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M2); |
| 1618 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M2); |
| 1578 | 1619 | } |
| 1579 | 1620 | break; |
| 1580 | 1621 | case GB_LCD_STATE_LY00_M2: /* Switch to mode 2 on line #0 */ |
| 1581 | 1622 | /* Set Mode 2 lcdstate */ |
| 1582 | | m_lcd.mode = 2; |
| 1583 | | LCDSTAT = ( LCDSTAT & 0xFC ) | 0x02; |
| 1584 | | m_lcd.oam_locked = LOCKED; |
| 1623 | m_mode = 2; |
| 1624 | LCDSTAT = (LCDSTAT & 0xFC) | 0x02; |
| 1625 | m_oam_locked = LOCKED; |
| 1585 | 1626 | /* Generate lcd interrupt if requested */ |
| 1586 | | if ( ( LCDSTAT & 0x20 ) && ! m_lcd.line_irq ) |
| 1627 | if ((LCDSTAT & 0x20) && !m_line_irq) |
| 1587 | 1628 | { |
| 1588 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1629 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1589 | 1630 | } |
| 1590 | 1631 | /* Check for regular compensation of x-scroll register */ |
| 1591 | | m_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0; |
| 1632 | m_scrollx_adjust = (SCROLLX & 0x04) ? 4 : 0; |
| 1592 | 1633 | /* Mode 2 lasts approximately 80 clock cycles */ |
| 1593 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 1634 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 1594 | 1635 | break; |
| 1595 | 1636 | case GB_LCD_STATE_LYXX_M2: /* Switch to mode 2 */ |
| 1596 | 1637 | /* Update STAT register to the correct state */ |
| 1597 | 1638 | LCDSTAT = (LCDSTAT & 0xFC) | 0x02; |
| 1598 | | m_lcd.oam_locked = LOCKED; |
| 1639 | m_oam_locked = LOCKED; |
| 1599 | 1640 | /* Generate lcd interrupt if requested */ |
| 1600 | | if ( ( m_lcd.delayed_line_irq && m_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) || |
| 1601 | | ( ! m_lcd.mode_irq && ! m_lcd.line_irq && ! m_lcd.delayed_line_irq && m_lcd.triggering_mode_irq ) ) |
| 1641 | if ((m_delayed_line_irq && m_triggering_line_irq && !(LCDSTAT & 0x20)) || |
| 1642 | (!m_mode_irq && !m_line_irq && !m_delayed_line_irq && m_triggering_mode_irq)) |
| 1602 | 1643 | { |
| 1603 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1644 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1604 | 1645 | } |
| 1605 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 1606 | | m_lcd.triggering_mode_irq = 0; |
| 1646 | m_line_irq = m_triggering_line_irq; |
| 1647 | m_triggering_mode_irq = 0; |
| 1607 | 1648 | /* Check if LY==LYC STAT bit should be set */ |
| 1608 | | if ( CURLINE == CMPLINE ) |
| 1649 | if (CURLINE == CMPLINE) |
| 1609 | 1650 | { |
| 1610 | 1651 | LCDSTAT |= 0x04; |
| 1611 | 1652 | } |
| 1612 | 1653 | /* Check for regular compensation of x-scroll register */ |
| 1613 | | m_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0; |
| 1654 | m_scrollx_adjust = (SCROLLX & 0x04) ? 4 : 0; |
| 1614 | 1655 | /* Mode 2 last for approximately 80 clock cycles */ |
| 1615 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 1656 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 1616 | 1657 | break; |
| 1617 | 1658 | case GB_LCD_STATE_LYXX_M3: /* Switch to mode 3 */ |
| 1618 | | gb_select_sprites(); |
| 1619 | | m_lcd.sprite_cycles = sprite_cycles[ m_lcd.sprCount ]; |
| 1659 | select_sprites(); |
| 1660 | m_sprite_cycles = sprite_cycles[m_sprCount]; |
| 1620 | 1661 | /* Set Mode 3 lcdstate */ |
| 1621 | | m_lcd.mode = 3; |
| 1662 | m_mode = 3; |
| 1622 | 1663 | LCDSTAT = (LCDSTAT & 0xFC) | 0x03; |
| 1623 | | m_lcd.vram_locked = LOCKED; |
| 1664 | m_vram_locked = LOCKED; |
| 1624 | 1665 | /* Check for compensations of x-scroll register */ |
| 1625 | 1666 | /* Mode 3 lasts for approximately 172+cycles needed to handle sprites clock cycles */ |
| 1626 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(168 + m_lcd.scrollx_adjust + m_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0); |
| 1627 | | m_lcd.start_x = -1; |
| 1667 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(168 + m_scrollx_adjust + m_sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0); |
| 1668 | m_start_x = -1; |
| 1628 | 1669 | break; |
| 1629 | 1670 | case GB_LCD_STATE_LY9X_M1: /* Switch to or stay in mode 1 */ |
| 1630 | | if ( CURLINE == 144 ) |
| 1671 | if (CURLINE == 144) |
| 1631 | 1672 | { |
| 1632 | 1673 | /* Trigger VBlank interrupt */ |
| 1633 | | m_maincpu->set_input_line(VBL_INT, ASSERT_LINE ); |
| 1674 | m_maincpu->set_input_line(VBL_INT, ASSERT_LINE); |
| 1634 | 1675 | /* Set VBlank lcdstate */ |
| 1635 | | m_lcd.mode = 1; |
| 1676 | m_mode = 1; |
| 1636 | 1677 | LCDSTAT = (LCDSTAT & 0xFC) | 0x01; |
| 1637 | 1678 | /* Trigger LCD interrupt if requested */ |
| 1638 | | if ( LCDSTAT & 0x10 ) |
| 1679 | if (LCDSTAT & 0x10) |
| 1639 | 1680 | { |
| 1640 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1681 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1641 | 1682 | } |
| 1642 | 1683 | } |
| 1643 | 1684 | /* Check if LY==LYC STAT bit should be set */ |
| 1644 | | if ( CURLINE == CMPLINE ) |
| 1685 | if (CURLINE == CMPLINE) |
| 1645 | 1686 | { |
| 1646 | 1687 | LCDSTAT |= 0x04; |
| 1647 | 1688 | } |
| 1648 | | if ( m_lcd.delayed_line_irq && m_lcd.triggering_line_irq ) |
| 1689 | if (m_delayed_line_irq && m_triggering_line_irq) |
| 1649 | 1690 | { |
| 1650 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1691 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1651 | 1692 | } |
| 1652 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(452), GB_LCD_STATE_LY9X_M1_INC); |
| 1693 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(452), GB_LCD_STATE_LY9X_M1_INC); |
| 1653 | 1694 | break; |
| 1654 | 1695 | case GB_LCD_STATE_LY9X_M1_INC: /* Increment scanline counter */ |
| 1655 | | gb_increment_scanline(); |
| 1656 | | m_lcd.delayed_line_irq = m_lcd.line_irq; |
| 1657 | | m_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1658 | | m_lcd.line_irq = 0; |
| 1659 | | if ( ! m_lcd.delayed_line_irq && m_lcd.triggering_line_irq ) |
| 1696 | increment_scanline(); |
| 1697 | m_delayed_line_irq = m_line_irq; |
| 1698 | m_triggering_line_irq = ((CMPLINE == CURLINE) && (LCDSTAT & 0x40)) ? 1 : 0; |
| 1699 | m_line_irq = 0; |
| 1700 | if (!m_delayed_line_irq && m_triggering_line_irq) |
| 1660 | 1701 | { |
| 1661 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 1662 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1702 | m_line_irq = m_triggering_line_irq; |
| 1703 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1663 | 1704 | } |
| 1664 | 1705 | /* Reset LY==LYC STAT bit */ |
| 1665 | 1706 | LCDSTAT &= 0xFB; |
| 1666 | | if ( m_lcd.current_line == 153 ) |
| 1707 | if (m_current_line == 153) |
| 1667 | 1708 | { |
| 1668 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1); |
| 1709 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1); |
| 1669 | 1710 | } |
| 1670 | 1711 | else |
| 1671 | 1712 | { |
| 1672 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY9X_M1); |
| 1713 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY9X_M1); |
| 1673 | 1714 | } |
| 1674 | 1715 | break; |
| 1675 | 1716 | case GB_LCD_STATE_LY00_M1: /* we stay in VBlank but current line counter should already be incremented */ |
| 1676 | 1717 | /* Check LY=LYC for line #153 */ |
| 1677 | | if ( m_lcd.delayed_line_irq ) |
| 1718 | if (m_delayed_line_irq) |
| 1678 | 1719 | { |
| 1679 | | if ( m_lcd.triggering_line_irq ) |
| 1720 | if (m_triggering_line_irq) |
| 1680 | 1721 | { |
| 1681 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1722 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1682 | 1723 | } |
| 1683 | 1724 | } |
| 1684 | | m_lcd.delayed_line_irq = m_lcd.delayed_line_irq | m_lcd.line_irq; |
| 1685 | | if ( CURLINE == CMPLINE ) |
| 1725 | m_delayed_line_irq = m_delayed_line_irq | m_line_irq; |
| 1726 | if (CURLINE == CMPLINE) |
| 1686 | 1727 | { |
| 1687 | 1728 | LCDSTAT |= 0x04; |
| 1688 | 1729 | } |
| 1689 | | gb_increment_scanline(); |
| 1690 | | m_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1691 | | m_lcd.line_irq = 0; |
| 1730 | increment_scanline(); |
| 1731 | m_triggering_line_irq = ((CMPLINE == CURLINE) && (LCDSTAT & 0x40)) ? 1 : 0; |
| 1732 | m_line_irq = 0; |
| 1692 | 1733 | LCDSTAT &= 0xFB; |
| 1693 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4/*8*/), GB_LCD_STATE_LY00_M1_1); |
| 1734 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4/*8*/), GB_LCD_STATE_LY00_M1_1); |
| 1694 | 1735 | break; |
| 1695 | 1736 | case GB_LCD_STATE_LY00_M1_1: |
| 1696 | | if ( ! m_lcd.delayed_line_irq && m_lcd.triggering_line_irq ) |
| 1737 | if (!m_delayed_line_irq && m_triggering_line_irq) |
| 1697 | 1738 | { |
| 1698 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 1699 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1739 | m_line_irq = m_triggering_line_irq; |
| 1740 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1700 | 1741 | } |
| 1701 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1_2); |
| 1742 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1_2); |
| 1702 | 1743 | break; |
| 1703 | 1744 | case GB_LCD_STATE_LY00_M1_2: /* Rest of line #0 during VBlank */ |
| 1704 | | if ( m_lcd.delayed_line_irq && m_lcd.triggering_line_irq ) |
| 1745 | if (m_delayed_line_irq && m_triggering_line_irq) |
| 1705 | 1746 | { |
| 1706 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 1707 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1747 | m_line_irq = m_triggering_line_irq; |
| 1748 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1708 | 1749 | } |
| 1709 | | if ( CURLINE == CMPLINE ) |
| 1750 | if (CURLINE == CMPLINE) |
| 1710 | 1751 | { |
| 1711 | 1752 | LCDSTAT |= 0x04; |
| 1712 | 1753 | } |
| 1713 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(444), GB_LCD_STATE_LY00_M0); |
| 1754 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(444), GB_LCD_STATE_LY00_M0); |
| 1714 | 1755 | break; |
| 1715 | 1756 | case GB_LCD_STATE_LY00_M0: /* The STAT register seems to go to 0 for about 4 cycles */ |
| 1716 | 1757 | /* Set Mode 0 lcdstat */ |
| 1717 | | m_lcd.mode = 0; |
| 1718 | | LCDSTAT = ( LCDSTAT & 0xFC ); |
| 1719 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M2); |
| 1758 | m_mode = 0; |
| 1759 | LCDSTAT = (LCDSTAT & 0xFC); |
| 1760 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M2); |
| 1720 | 1761 | break; |
| 1721 | 1762 | } |
| 1722 | 1763 | } |
| 1723 | 1764 | else |
| 1724 | 1765 | { |
| 1725 | | gb_increment_scanline(); |
| 1726 | | if ( m_lcd.current_line < 144 ) |
| 1766 | increment_scanline(); |
| 1767 | if (m_current_line < 144) |
| 1727 | 1768 | { |
| 1728 | | (this->*update_scanline)(); |
| 1769 | update_scanline(); |
| 1729 | 1770 | } |
| 1730 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(456)); |
| 1771 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(456)); |
| 1731 | 1772 | } |
| 1732 | 1773 | } |
| 1733 | 1774 | |
| 1734 | | TIMER_CALLBACK_MEMBER(gb_state::gbc_lcd_timer_proc) |
| 1775 | |
| 1776 | // CGB specific code |
| 1777 | |
| 1778 | void cgb_lcd_device::hdma_trans(UINT16 length) |
| 1735 | 1779 | { |
| 1780 | UINT16 src, dst; |
| 1781 | address_space &space = m_maincpu->space(AS_PROGRAM); |
| 1782 | |
| 1783 | src = ((UINT16)HDMA1 << 8) | (HDMA2 & 0xF0); |
| 1784 | dst = ((UINT16)(HDMA3 & 0x1F) << 8) | (HDMA4 & 0xF0); |
| 1785 | dst |= 0x8000; |
| 1786 | while (length > 0) |
| 1787 | { |
| 1788 | space.write_byte(dst++, space.read_byte(src++)); |
| 1789 | length--; |
| 1790 | } |
| 1791 | HDMA1 = src >> 8; |
| 1792 | HDMA2 = src & 0xF0; |
| 1793 | HDMA3 = 0x1f & (dst >> 8); |
| 1794 | HDMA4 = dst & 0xF0; |
| 1795 | HDMA5--; |
| 1796 | if ((HDMA5 & 0x7f) == 0x7f) |
| 1797 | { |
| 1798 | HDMA5 = 0xff; |
| 1799 | m_hdma_enabled = 0; |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | |
| 1804 | TIMER_CALLBACK_MEMBER(cgb_lcd_device::lcd_timer_proc) |
| 1805 | { |
| 1736 | 1806 | static const int sprite_cycles[] = { 0, 8, 20, 32, 44, 52, 64, 76, 88, 96, 108 }; |
| 1737 | 1807 | |
| 1738 | | m_lcd.state = param; |
| 1808 | m_state = param; |
| 1739 | 1809 | |
| 1740 | | if ( LCDCONT & 0x80 ) |
| 1810 | if (LCDCONT & 0x80) |
| 1741 | 1811 | { |
| 1742 | | switch( m_lcd.state ) |
| 1812 | switch (m_state) |
| 1743 | 1813 | { |
| 1744 | 1814 | case GB_LCD_STATE_LYXX_PRE_M0: /* Just before switching to mode 0 */ |
| 1745 | | m_lcd.mode = 0; |
| 1746 | | if ( LCDSTAT & 0x08 ) |
| 1815 | m_mode = 0; |
| 1816 | if (LCDSTAT & 0x08) |
| 1747 | 1817 | { |
| 1748 | | if ( ! m_lcd.mode_irq ) |
| 1818 | if (!m_mode_irq) |
| 1749 | 1819 | { |
| 1750 | | if ( ! m_lcd.line_irq && ! m_lcd.delayed_line_irq ) |
| 1820 | if (!m_line_irq && !m_delayed_line_irq) |
| 1751 | 1821 | { |
| 1752 | | m_lcd.mode_irq = 1; |
| 1753 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1822 | m_mode_irq = 1; |
| 1823 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1754 | 1824 | } |
| 1755 | 1825 | } |
| 1756 | 1826 | else |
| 1757 | 1827 | { |
| 1758 | | m_lcd.mode_irq = 0; |
| 1828 | m_mode_irq = 0; |
| 1759 | 1829 | } |
| 1760 | 1830 | } |
| 1761 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0); |
| 1831 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0); |
| 1762 | 1832 | break; |
| 1763 | 1833 | case GB_LCD_STATE_LYXX_M0: /* Switch to mode 0 */ |
| 1764 | 1834 | /* update current scanline */ |
| 1765 | | (this->*update_scanline)(); |
| 1835 | update_scanline(); |
| 1766 | 1836 | /* Increment the number of window lines drawn if enabled */ |
| 1767 | | if ( m_lcd.layer[1].enabled ) |
| 1837 | if (m_layer[1].enabled) |
| 1768 | 1838 | { |
| 1769 | | m_lcd.window_lines_drawn++; |
| 1839 | m_window_lines_drawn++; |
| 1770 | 1840 | } |
| 1771 | | m_lcd.previous_line = m_lcd.current_line; |
| 1841 | m_previous_line = m_current_line; |
| 1772 | 1842 | /* Set Mode 0 lcdstate */ |
| 1773 | | m_lcd.mode = 0; |
| 1843 | m_mode = 0; |
| 1774 | 1844 | LCDSTAT &= 0xFC; |
| 1775 | | m_lcd.oam_locked = UNLOCKED; |
| 1776 | | m_lcd.vram_locked = UNLOCKED; |
| 1845 | m_oam_locked = UNLOCKED; |
| 1846 | m_vram_locked = UNLOCKED; |
| 1777 | 1847 | /* |
| 1778 | 1848 | There seems to a kind of feature in the Game Boy hardware when the lowest bits of the |
| 1779 | 1849 | SCROLLX register equals 3 or 7, then the delayed M0 irq is triggered 4 cycles later |
| 1780 | 1850 | than usual. |
| 1781 | 1851 | The SGB probably has the same bug. |
| 1782 | 1852 | */ |
| 1783 | | m_lcd.triggering_mode_irq = ( LCDSTAT & 0x08 ) ? 1 : 0; |
| 1784 | | if ( ( SCROLLX & 0x03 ) == 0x03 ) |
| 1853 | m_triggering_mode_irq = (LCDSTAT & 0x08) ? 1 : 0; |
| 1854 | if ((SCROLLX & 0x03) == 0x03) |
| 1785 | 1855 | { |
| 1786 | | m_lcd.scrollx_adjust += 4; |
| 1787 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_SCX3); |
| 1856 | m_scrollx_adjust += 4; |
| 1857 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_SCX3); |
| 1788 | 1858 | break; |
| 1789 | 1859 | } |
| 1790 | 1860 | case GB_LCD_STATE_LYXX_M0_SCX3: |
| 1791 | 1861 | /* Generate lcd interrupt if requested */ |
| 1792 | | if ( ! m_lcd.mode_irq && m_lcd.triggering_mode_irq && |
| 1793 | | ( ( ! m_lcd.line_irq && m_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) |
| 1862 | if (!m_mode_irq && m_triggering_mode_irq && |
| 1863 | ((!m_line_irq && m_delayed_line_irq) || !(LCDSTAT & 0x40))) |
| 1794 | 1864 | { |
| 1795 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1796 | | m_lcd.triggering_mode_irq = 0; |
| 1865 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1866 | m_triggering_mode_irq = 0; |
| 1797 | 1867 | } |
| 1798 | | if ( ( SCROLLX & 0x03 ) == 0x03 ) |
| 1868 | if ((SCROLLX & 0x03) == 0x03) |
| 1799 | 1869 | { |
| 1800 | | m_lcd.pal_locked = UNLOCKED; |
| 1870 | m_pal_locked = UNLOCKED; |
| 1801 | 1871 | } |
| 1802 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_GBC_PAL); |
| 1872 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_GBC_PAL); |
| 1803 | 1873 | break; |
| 1804 | 1874 | case GB_LCD_STATE_LYXX_M0_GBC_PAL: |
| 1805 | | m_lcd.pal_locked = UNLOCKED; |
| 1875 | m_pal_locked = UNLOCKED; |
| 1806 | 1876 | /* Check for HBLANK DMA */ |
| 1807 | | if( m_lcd.hdma_enabled ) |
| 1877 | if (m_hdma_enabled) |
| 1808 | 1878 | { |
| 1809 | | gbc_hdma(0x10); |
| 1810 | | // cpunum_set_reg( 0, LR35902_DMA_CYCLES, 36 ); |
| 1879 | hdma_trans(0x10); |
| 1880 | // cpunum_set_reg(0, LR35902_DMA_CYCLES, 36); |
| 1811 | 1881 | } |
| 1812 | 1882 | else |
| 1813 | 1883 | { |
| 1814 | | m_lcd.hdma_possible = 1; |
| 1884 | m_hdma_possible = 1; |
| 1815 | 1885 | } |
| 1816 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(192 - m_lcd.scrollx_adjust - m_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC); |
| 1886 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(192 - m_scrollx_adjust - m_sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC); |
| 1817 | 1887 | break; |
| 1818 | 1888 | case GB_LCD_STATE_LYXX_M0_PRE_INC: /* Just before incrementing the line counter go to mode 2 internally */ |
| 1819 | | m_lcd.cmp_line = CMPLINE; |
| 1820 | | if ( CURLINE < 143 ) |
| 1889 | m_cmp_line = CMPLINE; |
| 1890 | if (CURLINE < 143) |
| 1821 | 1891 | { |
| 1822 | | m_lcd.mode = 2; |
| 1823 | | if ( LCDSTAT & 0x20 ) |
| 1892 | m_mode = 2; |
| 1893 | if (LCDSTAT & 0x20) |
| 1824 | 1894 | { |
| 1825 | | if ( ! m_lcd.mode_irq ) |
| 1895 | if (!m_mode_irq) |
| 1826 | 1896 | { |
| 1827 | | if ( ! m_lcd.line_irq && ! m_lcd.delayed_line_irq ) |
| 1897 | if (!m_line_irq && !m_delayed_line_irq) |
| 1828 | 1898 | { |
| 1829 | | m_lcd.mode_irq = 1; |
| 1830 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1899 | m_mode_irq = 1; |
| 1900 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1831 | 1901 | } |
| 1832 | 1902 | } |
| 1833 | 1903 | else |
| 1834 | 1904 | { |
| 1835 | | m_lcd.mode_irq = 0; |
| 1905 | m_mode_irq = 0; |
| 1836 | 1906 | } |
| 1837 | 1907 | } |
| 1838 | 1908 | } |
| 1839 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_INC); |
| 1909 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M0_INC); |
| 1840 | 1910 | break; |
| 1841 | 1911 | case GB_LCD_STATE_LYXX_M0_INC: /* Increment LY, stay in M0 for 4 more cycles */ |
| 1842 | | gb_increment_scanline(); |
| 1843 | | m_lcd.delayed_line_irq = m_lcd.line_irq; |
| 1844 | | m_lcd.triggering_line_irq = ( ( m_lcd.cmp_line == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1845 | | m_lcd.line_irq = 0; |
| 1846 | | if ( ! m_lcd.mode_irq && ! m_lcd.delayed_line_irq && m_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) |
| 1912 | increment_scanline(); |
| 1913 | m_delayed_line_irq = m_line_irq; |
| 1914 | m_triggering_line_irq = ((m_cmp_line == CURLINE) && (LCDSTAT & 0x40)) ? 1 : 0; |
| 1915 | m_line_irq = 0; |
| 1916 | if (!m_mode_irq && !m_delayed_line_irq && m_triggering_line_irq && !(LCDSTAT & 0x20)) |
| 1847 | 1917 | { |
| 1848 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 1849 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1918 | m_line_irq = m_triggering_line_irq; |
| 1919 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1850 | 1920 | } |
| 1851 | | m_lcd.hdma_possible = 0; |
| 1921 | m_hdma_possible = 0; |
| 1852 | 1922 | /* Check if we're going into VBlank next */ |
| 1853 | | if ( CURLINE == 144 ) |
| 1923 | if (CURLINE == 144) |
| 1854 | 1924 | { |
| 1855 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY9X_M1); |
| 1925 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY9X_M1); |
| 1856 | 1926 | } |
| 1857 | 1927 | else |
| 1858 | 1928 | { |
| 1859 | 1929 | /* Internally switch to mode 2 */ |
| 1860 | | m_lcd.mode = 2; |
| 1930 | m_mode = 2; |
| 1861 | 1931 | /* Generate lcd interrupt if requested */ |
| 1862 | | if ( ! m_lcd.mode_irq && ( LCDSTAT & 0x20 ) && |
| 1863 | | ( ( ! m_lcd.triggering_line_irq && ! m_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) |
| 1932 | if (!m_mode_irq && (LCDSTAT & 0x20) && |
| 1933 | ((!m_triggering_line_irq && !m_delayed_line_irq) || !(LCDSTAT & 0x40))) |
| 1864 | 1934 | { |
| 1865 | | m_lcd.mode_irq = 1; |
| 1866 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1935 | m_mode_irq = 1; |
| 1936 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1867 | 1937 | } |
| 1868 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M2); |
| 1938 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LYXX_M2); |
| 1869 | 1939 | } |
| 1870 | 1940 | break; |
| 1871 | 1941 | case GB_LCD_STATE_LY00_M2: /* Switch to mode 2 on line #0 */ |
| 1872 | 1942 | /* Set Mode 2 lcdstate */ |
| 1873 | | m_lcd.mode = 2; |
| 1874 | | LCDSTAT = ( LCDSTAT & 0xFC ) | 0x02; |
| 1875 | | m_lcd.oam_locked = LOCKED; |
| 1943 | m_mode = 2; |
| 1944 | LCDSTAT = (LCDSTAT & 0xFC) | 0x02; |
| 1945 | m_oam_locked = LOCKED; |
| 1876 | 1946 | /* Generate lcd interrupt if requested */ |
| 1877 | | if ( ( LCDSTAT & 0x20 ) && ! m_lcd.line_irq ) |
| 1947 | if ((LCDSTAT & 0x20) && ! m_line_irq) |
| 1878 | 1948 | { |
| 1879 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1949 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1880 | 1950 | } |
| 1881 | 1951 | /* Check for regular compensation of x-scroll register */ |
| 1882 | | m_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0; |
| 1952 | m_scrollx_adjust = (SCROLLX & 0x04) ? 4 : 0; |
| 1883 | 1953 | /* Mode 2 lasts approximately 80 clock cycles */ |
| 1884 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 1954 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 1885 | 1955 | break; |
| 1886 | 1956 | case GB_LCD_STATE_LYXX_M2: /* Switch to mode 2 */ |
| 1887 | 1957 | /* Update STAT register to the correct state */ |
| 1888 | 1958 | LCDSTAT = (LCDSTAT & 0xFC) | 0x02; |
| 1889 | | m_lcd.oam_locked = LOCKED; |
| 1959 | m_oam_locked = LOCKED; |
| 1890 | 1960 | /* Generate lcd interrupt if requested */ |
| 1891 | | if ( ( m_lcd.delayed_line_irq && m_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) || |
| 1892 | | ( !m_lcd.mode_irq && ! m_lcd.line_irq && ! m_lcd.delayed_line_irq && ( LCDSTAT & 0x20 ) ) ) |
| 1961 | if ((m_delayed_line_irq && m_triggering_line_irq && !(LCDSTAT & 0x20)) || |
| 1962 | (!m_mode_irq && !m_line_irq && !m_delayed_line_irq && (LCDSTAT & 0x20))) |
| 1893 | 1963 | { |
| 1894 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 1964 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1895 | 1965 | } |
| 1896 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 1966 | m_line_irq = m_triggering_line_irq; |
| 1897 | 1967 | /* Check if LY==LYC STAT bit should be set */ |
| 1898 | | if ( CURLINE == CMPLINE ) |
| 1968 | if (CURLINE == CMPLINE) |
| 1899 | 1969 | { |
| 1900 | 1970 | LCDSTAT |= 0x04; |
| 1901 | 1971 | } |
| r23879 | r23880 | |
| 1904 | 1974 | LCDSTAT &= ~0x04; |
| 1905 | 1975 | } |
| 1906 | 1976 | /* Check for regular compensation of x-scroll register */ |
| 1907 | | m_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0; |
| 1977 | m_scrollx_adjust = (SCROLLX & 0x04) ? 4 : 0; |
| 1908 | 1978 | /* Mode 2 last for approximately 80 clock cycles */ |
| 1909 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 1979 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 1910 | 1980 | break; |
| 1911 | 1981 | case GB_LCD_STATE_LYXX_M3: /* Switch to mode 3 */ |
| 1912 | | gb_select_sprites(); |
| 1913 | | m_lcd.sprite_cycles = sprite_cycles[ m_lcd.sprCount ]; |
| 1982 | select_sprites(); |
| 1983 | m_sprite_cycles = sprite_cycles[m_sprCount]; |
| 1914 | 1984 | /* Set Mode 3 lcdstate */ |
| 1915 | | m_lcd.mode = 3; |
| 1985 | m_mode = 3; |
| 1916 | 1986 | LCDSTAT = (LCDSTAT & 0xFC) | 0x03; |
| 1917 | | m_lcd.vram_locked = LOCKED; |
| 1918 | | m_lcd.pal_locked = LOCKED; |
| 1987 | m_vram_locked = LOCKED; |
| 1988 | m_pal_locked = LOCKED; |
| 1919 | 1989 | /* Check for compensations of x-scroll register */ |
| 1920 | 1990 | /* Mode 3 lasts for approximately 172+cycles needed to handle sprites clock cycles */ |
| 1921 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(168 + m_lcd.scrollx_adjust + m_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0); |
| 1922 | | m_lcd.start_x = -1; |
| 1991 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(168 + m_scrollx_adjust + m_sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0); |
| 1992 | m_start_x = -1; |
| 1923 | 1993 | break; |
| 1924 | 1994 | case GB_LCD_STATE_LY9X_M1: /* Switch to or stay in mode 1 */ |
| 1925 | | if ( CURLINE == 144 ) |
| 1995 | if (CURLINE == 144) |
| 1926 | 1996 | { |
| 1927 | 1997 | /* Trigger VBlank interrupt */ |
| 1928 | | m_maincpu->set_input_line(VBL_INT, ASSERT_LINE ); |
| 1998 | m_maincpu->set_input_line(VBL_INT, ASSERT_LINE); |
| 1929 | 1999 | /* Set VBlank lcdstate */ |
| 1930 | | m_lcd.mode = 1; |
| 2000 | m_mode = 1; |
| 1931 | 2001 | LCDSTAT = (LCDSTAT & 0xFC) | 0x01; |
| 1932 | 2002 | /* Trigger LCD interrupt if requested */ |
| 1933 | | if ( LCDSTAT & 0x10 ) |
| 2003 | if (LCDSTAT & 0x10) |
| 1934 | 2004 | { |
| 1935 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2005 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1936 | 2006 | } |
| 1937 | 2007 | } |
| 1938 | 2008 | /* Check if LY==LYC STAT bit should be set */ |
| 1939 | | if ( CURLINE == CMPLINE ) |
| 2009 | if (CURLINE == CMPLINE) |
| 1940 | 2010 | { |
| 1941 | 2011 | LCDSTAT |= 0x04; |
| 1942 | 2012 | } |
| r23879 | r23880 | |
| 1944 | 2014 | { |
| 1945 | 2015 | LCDSTAT &= ~0x04; |
| 1946 | 2016 | } |
| 1947 | | if ( m_lcd.delayed_line_irq && m_lcd.triggering_line_irq ) |
| 2017 | if (m_delayed_line_irq && m_triggering_line_irq) |
| 1948 | 2018 | { |
| 1949 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2019 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1950 | 2020 | } |
| 1951 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(452), GB_LCD_STATE_LY9X_M1_INC); |
| 2021 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(452), GB_LCD_STATE_LY9X_M1_INC); |
| 1952 | 2022 | break; |
| 1953 | 2023 | case GB_LCD_STATE_LY9X_M1_INC: /* Increment scanline counter */ |
| 1954 | | gb_increment_scanline(); |
| 1955 | | m_lcd.delayed_line_irq = m_lcd.line_irq; |
| 1956 | | m_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1957 | | m_lcd.line_irq = 0; |
| 1958 | | if ( ! m_lcd.delayed_line_irq && m_lcd.triggering_line_irq ) |
| 2024 | increment_scanline(); |
| 2025 | m_delayed_line_irq = m_line_irq; |
| 2026 | m_triggering_line_irq = ((CMPLINE == CURLINE) && (LCDSTAT & 0x40)) ? 1 : 0; |
| 2027 | m_line_irq = 0; |
| 2028 | if (!m_delayed_line_irq && m_triggering_line_irq) |
| 1959 | 2029 | { |
| 1960 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 1961 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2030 | m_line_irq = m_triggering_line_irq; |
| 2031 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1962 | 2032 | } |
| 1963 | | if ( m_lcd.current_line == 153 ) |
| 2033 | if (m_current_line == 153) |
| 1964 | 2034 | { |
| 1965 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1); |
| 2035 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1); |
| 1966 | 2036 | } |
| 1967 | 2037 | else |
| 1968 | 2038 | { |
| 1969 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY9X_M1); |
| 2039 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY9X_M1); |
| 1970 | 2040 | } |
| 1971 | 2041 | break; |
| 1972 | 2042 | case GB_LCD_STATE_LY00_M1: /* we stay in VBlank but current line counter should already be incremented */ |
| 1973 | 2043 | /* Check LY=LYC for line #153 */ |
| 1974 | | if ( m_lcd.delayed_line_irq ) |
| 2044 | if (m_delayed_line_irq) |
| 1975 | 2045 | { |
| 1976 | | if ( m_lcd.triggering_line_irq ) |
| 2046 | if (m_triggering_line_irq) |
| 1977 | 2047 | { |
| 1978 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2048 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 1979 | 2049 | } |
| 1980 | 2050 | } |
| 1981 | | m_lcd.delayed_line_irq = m_lcd.delayed_line_irq | m_lcd.line_irq; |
| 1982 | | if ( CURLINE == CMPLINE ) |
| 2051 | m_delayed_line_irq = m_delayed_line_irq | m_line_irq; |
| 2052 | if (CURLINE == CMPLINE) |
| 1983 | 2053 | { |
| 1984 | 2054 | LCDSTAT |= 0x04; |
| 1985 | 2055 | } |
| r23879 | r23880 | |
| 1987 | 2057 | { |
| 1988 | 2058 | LCDSTAT &= ~0x04; |
| 1989 | 2059 | } |
| 1990 | | gb_increment_scanline(); |
| 1991 | | m_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1992 | | m_lcd.line_irq = 0; |
| 2060 | increment_scanline(); |
| 2061 | m_triggering_line_irq = ((CMPLINE == CURLINE) && (LCDSTAT & 0x40)) ? 1 : 0; |
| 2062 | m_line_irq = 0; |
| 1993 | 2063 | LCDSTAT &= 0xFB; |
| 1994 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1_1); |
| 2064 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1_1); |
| 1995 | 2065 | break; |
| 1996 | 2066 | case GB_LCD_STATE_LY00_M1_1: |
| 1997 | | if ( ! m_lcd.delayed_line_irq && m_lcd.triggering_line_irq ) |
| 2067 | if (!m_delayed_line_irq && m_triggering_line_irq) |
| 1998 | 2068 | { |
| 1999 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 2000 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2069 | m_line_irq = m_triggering_line_irq; |
| 2070 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2001 | 2071 | } |
| 2002 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1_2); |
| 2072 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M1_2); |
| 2003 | 2073 | break; |
| 2004 | 2074 | case GB_LCD_STATE_LY00_M1_2: /* Rest of line #0 during VBlank */ |
| 2005 | | if ( m_lcd.delayed_line_irq && m_lcd.triggering_line_irq ) |
| 2075 | if (m_delayed_line_irq && m_triggering_line_irq) |
| 2006 | 2076 | { |
| 2007 | | m_lcd.line_irq = m_lcd.triggering_line_irq; |
| 2008 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2077 | m_line_irq = m_triggering_line_irq; |
| 2078 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2009 | 2079 | } |
| 2010 | | if ( CURLINE == CMPLINE ) |
| 2080 | if (CURLINE == CMPLINE) |
| 2011 | 2081 | { |
| 2012 | 2082 | LCDSTAT |= 0x04; |
| 2013 | 2083 | } |
| r23879 | r23880 | |
| 2015 | 2085 | { |
| 2016 | 2086 | LCDSTAT &= ~0x04; |
| 2017 | 2087 | } |
| 2018 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(444), GB_LCD_STATE_LY00_M0); |
| 2088 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(444), GB_LCD_STATE_LY00_M0); |
| 2019 | 2089 | break; |
| 2020 | 2090 | case GB_LCD_STATE_LY00_M0: /* The STAT register seems to go to 0 for about 4 cycles */ |
| 2021 | 2091 | /* Set Mode 0 lcdstat */ |
| 2022 | | m_lcd.mode = 0; |
| 2023 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M2); |
| 2092 | m_mode = 0; |
| 2093 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(4), GB_LCD_STATE_LY00_M2); |
| 2024 | 2094 | break; |
| 2025 | 2095 | } |
| 2026 | 2096 | } |
| 2027 | 2097 | else |
| 2028 | 2098 | { |
| 2029 | | gb_increment_scanline(); |
| 2030 | | if ( m_lcd.current_line < 144 ) |
| 2099 | increment_scanline(); |
| 2100 | if (m_current_line < 144) |
| 2031 | 2101 | { |
| 2032 | | (this->*update_scanline)(); |
| 2102 | update_scanline(); |
| 2033 | 2103 | } |
| 2034 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(456)); |
| 2104 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(456)); |
| 2035 | 2105 | } |
| 2036 | 2106 | } |
| 2037 | 2107 | |
| 2038 | 2108 | |
| 2039 | | void gb_state::gb_lcd_switch_on() |
| 2109 | void gb_lcd_device::lcd_switch_on() |
| 2040 | 2110 | { |
| 2041 | | m_lcd.current_line = 0; |
| 2042 | | m_lcd.previous_line = 153; |
| 2043 | | m_lcd.window_lines_drawn = 0; |
| 2044 | | m_lcd.line_irq = 0; |
| 2045 | | m_lcd.delayed_line_irq = 0; |
| 2046 | | m_lcd.mode = 0; |
| 2047 | | m_lcd.oam_locked = LOCKED; /* TODO: Investigate whether this OAM locking is correct. */ |
| 2111 | m_current_line = 0; |
| 2112 | m_previous_line = 153; |
| 2113 | m_window_lines_drawn = 0; |
| 2114 | m_line_irq = 0; |
| 2115 | m_delayed_line_irq = 0; |
| 2116 | m_mode = 0; |
| 2117 | m_oam_locked = LOCKED; /* TODO: Investigate whether this OAM locking is correct. */ |
| 2048 | 2118 | /* Check for LY=LYC coincidence */ |
| 2049 | | if ( CURLINE == CMPLINE ) |
| 2119 | if (CURLINE == CMPLINE) |
| 2050 | 2120 | { |
| 2051 | 2121 | LCDSTAT |= 0x04; |
| 2052 | 2122 | /* Generate lcd interrupt if requested */ |
| 2053 | | if ( LCDSTAT & 0x40 ) |
| 2123 | if (LCDSTAT & 0x40) |
| 2054 | 2124 | { |
| 2055 | | m_maincpu->set_input_line( LCD_INT, ASSERT_LINE ); |
| 2125 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2056 | 2126 | } |
| 2057 | 2127 | } |
| 2058 | | m_lcd.state = GB_LCD_STATE_LY00_M2; |
| 2059 | | m_lcd.lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 2128 | m_state = GB_LCD_STATE_LY00_M2; |
| 2129 | m_lcd_timer->adjust(m_maincpu->cycles_to_attotime(80), GB_LCD_STATE_LYXX_M3); |
| 2060 | 2130 | } |
| 2061 | 2131 | |
| 2062 | | READ8_MEMBER(gb_state::gb_video_r) |
| 2063 | | { |
| 2064 | | return m_lcd.gb_vid_regs[offset]; |
| 2065 | | } |
| 2066 | 2132 | |
| 2067 | | READ8_MEMBER(gb_state::gb_vram_r) |
| 2133 | |
| 2134 | |
| 2135 | READ8_MEMBER(gb_lcd_device::vram_r) |
| 2068 | 2136 | { |
| 2069 | | return (m_lcd.vram_locked == LOCKED) ? 0xff : m_lcd.gb_vram[offset + (m_lcd.gb_vram_bank * 0x2000)]; |
| 2137 | return (m_vram_locked == LOCKED) ? 0xff : m_vram[offset + (m_vram_bank * 0x2000)]; |
| 2070 | 2138 | } |
| 2071 | 2139 | |
| 2072 | | WRITE8_MEMBER(gb_state::gb_vram_w) |
| 2140 | WRITE8_MEMBER(gb_lcd_device::vram_w) |
| 2073 | 2141 | { |
| 2074 | | if (m_lcd.vram_locked == LOCKED) |
| 2142 | if (m_vram_locked == LOCKED) |
| 2075 | 2143 | return; |
| 2076 | | |
| 2077 | | m_lcd.gb_vram[offset + (m_lcd.gb_vram_bank * 0x2000)] = data; |
| 2144 | |
| 2145 | m_vram[offset + (m_vram_bank * 0x2000)] = data; |
| 2078 | 2146 | } |
| 2079 | 2147 | |
| 2080 | | READ8_MEMBER(gb_state::gb_oam_r) |
| 2148 | READ8_MEMBER(gb_lcd_device::oam_r) |
| 2081 | 2149 | { |
| 2082 | | return (m_lcd.oam_locked == LOCKED) ? 0xff : m_lcd.gb_oam[offset]; |
| 2150 | return (m_oam_locked == LOCKED) ? 0xff : m_oam[offset]; |
| 2083 | 2151 | } |
| 2084 | 2152 | |
| 2085 | | WRITE8_MEMBER(gb_state::gb_oam_w) |
| 2153 | WRITE8_MEMBER(gb_lcd_device::oam_w) |
| 2086 | 2154 | { |
| 2087 | | if (m_lcd.oam_locked == LOCKED || offset >= 0xa0) |
| 2155 | if (m_oam_locked == LOCKED || offset >= 0xa0) |
| 2088 | 2156 | return; |
| 2157 | |
| 2158 | m_oam[offset] = data; |
| 2159 | } |
| 2089 | 2160 | |
| 2090 | | m_lcd.gb_oam[offset] = data; |
| 2161 | |
| 2162 | |
| 2163 | READ8_MEMBER(gb_lcd_device::video_r) |
| 2164 | { |
| 2165 | return m_vid_regs[offset]; |
| 2091 | 2166 | } |
| 2092 | 2167 | |
| 2093 | | WRITE8_MEMBER(gb_state::gb_video_w) |
| 2168 | WRITE8_MEMBER(gb_lcd_device::video_w) |
| 2094 | 2169 | { |
| 2095 | 2170 | switch (offset) |
| 2096 | 2171 | { |
| 2097 | 2172 | case 0x00: /* LCDC - LCD Control */ |
| 2098 | | m_lcd.gb_chrgen_offs = (data & 0x10) ? 0x0000 : 0x0800; |
| 2099 | | m_lcd.gb_tile_no_mod = (data & 0x10) ? 0x00 : 0x80; |
| 2100 | | m_lcd.gb_bgdtab_offs = (data & 0x08) ? 0x1c00 : 0x1800; |
| 2101 | | m_lcd.gb_wndtab_offs = (data & 0x40) ? 0x1c00 : 0x1800; |
| 2173 | m_gb_chrgen_offs = (data & 0x10) ? 0x0000 : 0x0800; |
| 2174 | m_gb_tile_no_mod = (data & 0x10) ? 0x00 : 0x80; |
| 2175 | m_gb_bgdtab_offs = (data & 0x08) ? 0x1c00 : 0x1800; |
| 2176 | m_gb_wndtab_offs = (data & 0x40) ? 0x1c00 : 0x1800; |
| 2102 | 2177 | /* if LCD controller is switched off, set STAT and LY to 00 */ |
| 2103 | 2178 | if (!(data & 0x80)) |
| 2104 | 2179 | { |
| 2105 | 2180 | LCDSTAT &= ~0x03; |
| 2106 | 2181 | CURLINE = 0; |
| 2107 | | m_lcd.oam_locked = UNLOCKED; |
| 2108 | | m_lcd.vram_locked = UNLOCKED; |
| 2182 | m_oam_locked = UNLOCKED; |
| 2183 | m_vram_locked = UNLOCKED; |
| 2109 | 2184 | } |
| 2110 | 2185 | /* If LCD is being switched on */ |
| 2111 | 2186 | if (!(LCDCONT & 0x80) && (data & 0x80)) |
| 2112 | 2187 | { |
| 2113 | | gb_lcd_switch_on(); |
| 2188 | lcd_switch_on(); |
| 2114 | 2189 | } |
| 2115 | 2190 | break; |
| 2116 | 2191 | case 0x01: /* STAT - LCD Status */ |
| r23879 | r23880 | |
| 2120 | 2195 | Writing to STAT when the LCD controller is active causes a STAT |
| 2121 | 2196 | interrupt to be triggered. |
| 2122 | 2197 | */ |
| 2123 | | if ( LCDCONT & 0x80 ) |
| 2198 | if (LCDCONT & 0x80) |
| 2124 | 2199 | { |
| 2125 | 2200 | /* Triggers seen so far: |
| 2126 | 2201 | - 0x40 -> 0x00 - trigger |
| r23879 | r23880 | |
| 2136 | 2211 | - 0x20 -> 0x00/0x08/0x10/0x20/0x40 (mode 2, after m2int) - don't trigger |
| 2137 | 2212 | - 0x20 -> 0x00/0x08/0x10/0x20/0x40 (mode 3, after m2int) - don't trigger |
| 2138 | 2213 | */ |
| 2139 | | if ( ! m_lcd.mode_irq && ( ( m_lcd.mode == 1 ) || |
| 2140 | | ( ( LCDSTAT & 0x40 ) && ! ( data & 0x68 ) ) || |
| 2141 | | ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) && ( LCDSTAT & 0x04 ) ) || |
| 2142 | | ( ! ( LCDSTAT & 0x48 ) && ( data & 0x08 ) ) || |
| 2143 | | ( ( LCDSTAT & 0x60 ) == 0x00 && ( data & 0x60 ) == 0x20 ) || |
| 2144 | | ( ( LCDSTAT & 0x60 ) == 0x20 && ( data & 0x40 ) ) |
| 2145 | | ) ) |
| 2214 | if (!m_mode_irq && ((m_mode == 1) || |
| 2215 | ((LCDSTAT & 0x40) && !(data & 0x68)) || |
| 2216 | (!(LCDSTAT & 0x40) && (data & 0x40) && (LCDSTAT & 0x04)) || |
| 2217 | (!(LCDSTAT & 0x48) && (data & 0x08)) || |
| 2218 | ((LCDSTAT & 0x60) == 0x00 && (data & 0x60) == 0x20) || |
| 2219 | ((LCDSTAT & 0x60) == 0x20 && (data & 0x40)) |
| 2220 | )) |
| 2146 | 2221 | { |
| 2147 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2222 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2148 | 2223 | } |
| 2149 | 2224 | /* |
| 2150 | 2225 | - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger |
| 2151 | 2226 | - 0x20 -> 0x00/0x10/0x20/0x40 (mode 0, after m2int) - trigger (stat bug) |
| 2152 | 2227 | - 0x00 -> 0xXX (mode 0) - trigger stat bug |
| 2153 | 2228 | */ |
| 2154 | | if ( m_lcd.mode_irq && m_lcd.mode == 0 ) |
| 2229 | if (m_mode_irq && m_mode == 0) |
| 2155 | 2230 | { |
| 2156 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2231 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2157 | 2232 | } |
| 2158 | 2233 | } |
| 2159 | 2234 | break; |
| 2160 | 2235 | case 0x04: /* LY - LCD Y-coordinate */ |
| 2161 | 2236 | return; |
| 2162 | 2237 | case 0x05: /* LYC */ |
| 2163 | | if ( CMPLINE != data ) |
| 2238 | if (CMPLINE != data) |
| 2164 | 2239 | { |
| 2165 | | if ( CURLINE == data ) |
| 2240 | if (CURLINE == data) |
| 2166 | 2241 | { |
| 2167 | | if ( m_lcd.state != GB_LCD_STATE_LYXX_M0_INC && m_lcd.state != GB_LCD_STATE_LY9X_M1_INC ) |
| 2242 | if (m_state != GB_LCD_STATE_LYXX_M0_INC && m_state != GB_LCD_STATE_LY9X_M1_INC) |
| 2168 | 2243 | { |
| 2169 | 2244 | LCDSTAT |= 0x04; |
| 2170 | 2245 | /* Generate lcd interrupt if requested */ |
| 2171 | | if ( LCDSTAT & 0x40 ) |
| 2246 | if (LCDSTAT & 0x40) |
| 2172 | 2247 | { |
| 2173 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2248 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2174 | 2249 | } |
| 2175 | 2250 | } |
| 2176 | 2251 | } |
| 2177 | 2252 | else |
| 2178 | 2253 | { |
| 2179 | 2254 | LCDSTAT &= 0xFB; |
| 2180 | | m_lcd.triggering_line_irq = 0; |
| 2255 | m_triggering_line_irq = 0; |
| 2181 | 2256 | } |
| 2182 | 2257 | } |
| 2183 | 2258 | break; |
| 2184 | 2259 | case 0x06: /* DMA - DMA Transfer and Start Address */ |
| 2185 | 2260 | { |
| 2186 | | UINT8 *P = m_lcd.gb_oam; |
| 2261 | UINT8 *P = m_oam; |
| 2187 | 2262 | offset = (UINT16) data << 8; |
| 2188 | 2263 | for (data = 0; data < 0xA0; data++) |
| 2189 | 2264 | *P++ = space.read_byte(offset++); |
| 2190 | 2265 | } |
| 2191 | 2266 | return; |
| 2192 | 2267 | case 0x07: /* BGP - Background Palette */ |
| 2193 | | (this->*update_scanline)(); |
| 2194 | | m_lcd.gb_bpal[0] = data & 0x3; |
| 2195 | | m_lcd.gb_bpal[1] = (data & 0xC) >> 2; |
| 2196 | | m_lcd.gb_bpal[2] = (data & 0x30) >> 4; |
| 2197 | | m_lcd.gb_bpal[3] = (data & 0xC0) >> 6; |
| 2268 | update_scanline(); |
| 2269 | m_gb_bpal[0] = data & 0x3; |
| 2270 | m_gb_bpal[1] = (data & 0xC) >> 2; |
| 2271 | m_gb_bpal[2] = (data & 0x30) >> 4; |
| 2272 | m_gb_bpal[3] = (data & 0xC0) >> 6; |
| 2198 | 2273 | break; |
| 2199 | 2274 | case 0x08: /* OBP0 - Object Palette 0 */ |
| 2200 | | // (this->*update_scanline)(); |
| 2201 | | m_lcd.gb_spal0[0] = data & 0x3; |
| 2202 | | m_lcd.gb_spal0[1] = (data & 0xC) >> 2; |
| 2203 | | m_lcd.gb_spal0[2] = (data & 0x30) >> 4; |
| 2204 | | m_lcd.gb_spal0[3] = (data & 0xC0) >> 6; |
| 2275 | // update_scanline(); |
| 2276 | m_gb_spal0[0] = data & 0x3; |
| 2277 | m_gb_spal0[1] = (data & 0xC) >> 2; |
| 2278 | m_gb_spal0[2] = (data & 0x30) >> 4; |
| 2279 | m_gb_spal0[3] = (data & 0xC0) >> 6; |
| 2205 | 2280 | break; |
| 2206 | 2281 | case 0x09: /* OBP1 - Object Palette 1 */ |
| 2207 | | // (this->*update_scanline)(); |
| 2208 | | m_lcd.gb_spal1[0] = data & 0x3; |
| 2209 | | m_lcd.gb_spal1[1] = (data & 0xC) >> 2; |
| 2210 | | m_lcd.gb_spal1[2] = (data & 0x30) >> 4; |
| 2211 | | m_lcd.gb_spal1[3] = (data & 0xC0) >> 6; |
| 2282 | // update_scanline(); |
| 2283 | m_gb_spal1[0] = data & 0x3; |
| 2284 | m_gb_spal1[1] = (data & 0xC) >> 2; |
| 2285 | m_gb_spal1[2] = (data & 0x30) >> 4; |
| 2286 | m_gb_spal1[3] = (data & 0xC0) >> 6; |
| 2212 | 2287 | break; |
| 2213 | 2288 | case 0x02: /* SCY - Scroll Y */ |
| 2214 | 2289 | case 0x03: /* SCX - Scroll X */ |
| 2215 | | (this->*update_scanline)(); |
| 2290 | update_scanline(); |
| 2291 | break; |
| 2216 | 2292 | case 0x0A: /* WY - Window Y position */ |
| 2217 | 2293 | case 0x0B: /* WX - Window X position */ |
| 2218 | 2294 | break; |
| 2219 | 2295 | default: /* Unknown register, no change */ |
| 2220 | 2296 | return; |
| 2221 | 2297 | } |
| 2222 | | m_lcd.gb_vid_regs[offset] = data; |
| 2298 | m_vid_regs[offset] = data; |
| 2223 | 2299 | } |
| 2224 | 2300 | |
| 2225 | | READ8_MEMBER(gb_state::gbc_video_r) |
| 2301 | READ8_MEMBER(cgb_lcd_device::video_r) |
| 2226 | 2302 | { |
| 2227 | | switch( offset ) |
| 2303 | switch (offset) |
| 2228 | 2304 | { |
| 2229 | 2305 | case 0x11: /* FF51 */ |
| 2230 | 2306 | case 0x12: /* FF52 */ |
| r23879 | r23880 | |
| 2233 | 2309 | return 0xFF; |
| 2234 | 2310 | case 0x29: /* FF69 */ |
| 2235 | 2311 | case 0x2B: /* FF6B */ |
| 2236 | | if ( m_lcd.pal_locked == LOCKED ) |
| 2312 | if (m_pal_locked == LOCKED) |
| 2237 | 2313 | { |
| 2238 | 2314 | return 0xFF; |
| 2239 | 2315 | } |
| 2240 | 2316 | break; |
| 2241 | 2317 | } |
| 2242 | | return m_lcd.gb_vid_regs[offset]; |
| 2318 | return m_vid_regs[offset]; |
| 2243 | 2319 | } |
| 2244 | 2320 | |
| 2245 | | WRITE8_MEMBER(gb_state::gbc_video_w) |
| 2321 | WRITE8_MEMBER(cgb_lcd_device::video_w) |
| 2246 | 2322 | { |
| 2247 | | switch( offset ) |
| 2323 | switch (offset) |
| 2248 | 2324 | { |
| 2249 | 2325 | case 0x00: /* LCDC - LCD Control */ |
| 2250 | | m_lcd.gb_chrgen_offs = (data & 0x10) ? 0x0000 : 0x0800; |
| 2251 | | m_lcd.gbc_chrgen_offs = (data & 0x10) ? 0x2000 : 0x2800; |
| 2252 | | m_lcd.gb_tile_no_mod = (data & 0x10) ? 0x00 : 0x80; |
| 2253 | | m_lcd.gb_bgdtab_offs = (data & 0x08) ? 0x1c00 : 0x1800; |
| 2254 | | m_lcd.gbc_bgdtab_offs = (data & 0x08) ? 0x3c00 : 0x3800; |
| 2255 | | m_lcd.gb_wndtab_offs = (data & 0x40) ? 0x1c00 : 0x1800; |
| 2256 | | m_lcd.gbc_wndtab_offs = (data & 0x40) ? 0x3c00 : 0x3800; |
| 2326 | m_gb_chrgen_offs = (data & 0x10) ? 0x0000 : 0x0800; |
| 2327 | m_gbc_chrgen_offs = (data & 0x10) ? 0x2000 : 0x2800; |
| 2328 | m_gb_tile_no_mod = (data & 0x10) ? 0x00 : 0x80; |
| 2329 | m_gb_bgdtab_offs = (data & 0x08) ? 0x1c00 : 0x1800; |
| 2330 | m_gbc_bgdtab_offs = (data & 0x08) ? 0x3c00 : 0x3800; |
| 2331 | m_gb_wndtab_offs = (data & 0x40) ? 0x1c00 : 0x1800; |
| 2332 | m_gbc_wndtab_offs = (data & 0x40) ? 0x3c00 : 0x3800; |
| 2257 | 2333 | /* if LCD controller is switched off, set STAT to 00 */ |
| 2258 | | if ( ! ( data & 0x80 ) ) |
| 2334 | if (!(data & 0x80)) |
| 2259 | 2335 | { |
| 2260 | 2336 | LCDSTAT &= ~0x03; |
| 2261 | 2337 | CURLINE = 0; |
| 2262 | | m_lcd.oam_locked = UNLOCKED; |
| 2263 | | m_lcd.vram_locked = UNLOCKED; |
| 2264 | | m_lcd.pal_locked = UNLOCKED; |
| 2338 | m_oam_locked = UNLOCKED; |
| 2339 | m_vram_locked = UNLOCKED; |
| 2340 | m_pal_locked = UNLOCKED; |
| 2265 | 2341 | } |
| 2266 | 2342 | /* If LCD is being switched on */ |
| 2267 | | if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) |
| 2343 | if (!(LCDCONT & 0x80) && (data & 0x80)) |
| 2268 | 2344 | { |
| 2269 | | gb_lcd_switch_on(); |
| 2345 | lcd_switch_on(); |
| 2270 | 2346 | } |
| 2271 | 2347 | break; |
| 2272 | 2348 | case 0x01: /* STAT - LCD Status */ |
| 2273 | 2349 | data = 0x80 | (data & 0x78) | (LCDSTAT & 0x07); |
| 2274 | | if ( LCDCONT & 0x80 ) |
| 2350 | if (LCDCONT & 0x80) |
| 2275 | 2351 | { |
| 2276 | 2352 | /* |
| 2277 | 2353 | - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger |
| 2278 | 2354 | */ |
| 2279 | | if ( m_lcd.mode_irq && m_lcd.mode == 0 && ( LCDSTAT & 0x28 ) == 0x20 && ( data & 0x08 ) ) |
| 2355 | if (m_mode_irq && m_mode == 0 && (LCDSTAT & 0x28) == 0x20 && (data & 0x08)) |
| 2280 | 2356 | { |
| 2281 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2357 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2282 | 2358 | } |
| 2283 | 2359 | /* Check if line irqs are being disabled */ |
| 2284 | | if ( ! ( data & 0x40 ) ) |
| 2360 | if (!(data & 0x40)) |
| 2285 | 2361 | { |
| 2286 | | m_lcd.delayed_line_irq = 0; |
| 2362 | m_delayed_line_irq = 0; |
| 2287 | 2363 | } |
| 2288 | 2364 | /* Check if line irqs are being enabled */ |
| 2289 | | if ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) ) |
| 2365 | if (!(LCDSTAT & 0x40) && (data & 0x40)) |
| 2290 | 2366 | { |
| 2291 | | if ( CMPLINE == CURLINE ) |
| 2367 | if (CMPLINE == CURLINE) |
| 2292 | 2368 | { |
| 2293 | | m_lcd.line_irq = 1; |
| 2294 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2369 | m_line_irq = 1; |
| 2370 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2295 | 2371 | } |
| 2296 | 2372 | } |
| 2297 | 2373 | } |
| 2298 | 2374 | break; |
| 2299 | 2375 | case 0x05: /* LYC */ |
| 2300 | | if ( CMPLINE != data ) |
| 2376 | if (CMPLINE != data) |
| 2301 | 2377 | { |
| 2302 | | if ( ( m_lcd.state != GB_LCD_STATE_LYXX_M0_PRE_INC && CURLINE == data ) || |
| 2303 | | ( m_lcd.state == GB_LCD_STATE_LYXX_M0_INC && m_lcd.triggering_line_irq ) ) |
| 2378 | if ((m_state != GB_LCD_STATE_LYXX_M0_PRE_INC && CURLINE == data) || |
| 2379 | (m_state == GB_LCD_STATE_LYXX_M0_INC && m_triggering_line_irq)) |
| 2304 | 2380 | { |
| 2305 | 2381 | LCDSTAT |= 0x04; |
| 2306 | 2382 | /* Generate lcd interrupt if requested */ |
| 2307 | | if ( LCDSTAT & 0x40 ) |
| 2383 | if (LCDSTAT & 0x40) |
| 2308 | 2384 | { |
| 2309 | | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE ); |
| 2385 | m_maincpu->set_input_line(LCD_INT, ASSERT_LINE); |
| 2310 | 2386 | } |
| 2311 | 2387 | } |
| 2312 | 2388 | else |
| 2313 | 2389 | { |
| 2314 | 2390 | LCDSTAT &= 0xFB; |
| 2315 | | m_lcd.triggering_line_irq = 0; |
| 2316 | | m_lcd.cmp_line = data; |
| 2391 | m_triggering_line_irq = 0; |
| 2392 | m_cmp_line = data; |
| 2317 | 2393 | } |
| 2318 | 2394 | } |
| 2319 | 2395 | break; |
| 2320 | 2396 | case 0x07: /* BGP - GB background palette */ |
| 2321 | | (this->*update_scanline)(); |
| 2322 | | m_lcd.gb_bpal[0] = data & 0x3; |
| 2323 | | m_lcd.gb_bpal[1] = (data & 0xC) >> 2; |
| 2324 | | m_lcd.gb_bpal[2] = (data & 0x30) >> 4; |
| 2325 | | m_lcd.gb_bpal[3] = (data & 0xC0) >> 6; |
| 2397 | update_scanline(); |
| 2398 | m_gb_bpal[0] = data & 0x3; |
| 2399 | m_gb_bpal[1] = (data & 0xC) >> 2; |
| 2400 | m_gb_bpal[2] = (data & 0x30) >> 4; |
| 2401 | m_gb_bpal[3] = (data & 0xC0) >> 6; |
| 2326 | 2402 | break; |
| 2327 | 2403 | case 0x08: /* OBP0 - GB Object 0 palette */ |
| 2328 | | m_lcd.gb_spal0[0] = data & 0x3; |
| 2329 | | m_lcd.gb_spal0[1] = (data & 0xC) >> 2; |
| 2330 | | m_lcd.gb_spal0[2] = (data & 0x30) >> 4; |
| 2331 | | m_lcd.gb_spal0[3] = (data & 0xC0) >> 6; |
| 2404 | m_gb_spal0[0] = data & 0x3; |
| 2405 | m_gb_spal0[1] = (data & 0xC) >> 2; |
| 2406 | m_gb_spal0[2] = (data & 0x30) >> 4; |
| 2407 | m_gb_spal0[3] = (data & 0xC0) >> 6; |
| 2332 | 2408 | break; |
| 2333 | 2409 | case 0x09: /* OBP1 - GB Object 1 palette */ |
| 2334 | | m_lcd.gb_spal1[0] = data & 0x3; |
| 2335 | | m_lcd.gb_spal1[1] = (data & 0xC) >> 2; |
| 2336 | | m_lcd.gb_spal1[2] = (data & 0x30) >> 4; |
| 2337 | | m_lcd.gb_spal1[3] = (data & 0xC0) >> 6; |
| 2410 | m_gb_spal1[0] = data & 0x3; |
| 2411 | m_gb_spal1[1] = (data & 0xC) >> 2; |
| 2412 | m_gb_spal1[2] = (data & 0x30) >> 4; |
| 2413 | m_gb_spal1[3] = (data & 0xC0) >> 6; |
| 2338 | 2414 | break; |
| 2339 | 2415 | case 0x0c: /* Undocumented register involved in selecting gb/gbc mode */ |
| 2340 | | logerror( "Write to undocumented register: %X = %X\n", offset, data ); |
| 2416 | logerror("Write to undocumented register: %X = %X\n", offset, data); |
| 2341 | 2417 | break; |
| 2342 | 2418 | case 0x0F: /* VBK - VRAM bank select */ |
| 2343 | | m_lcd.gb_vram_bank = data & 0x01; |
| 2419 | m_vram_bank = data & 0x01; |
| 2344 | 2420 | data |= 0xFE; |
| 2345 | 2421 | break; |
| 2346 | 2422 | case 0x11: /* HDMA1 - HBL General DMA - Source High */ |
| r23879 | r23880 | |
| 2355 | 2431 | data &= 0xF0; |
| 2356 | 2432 | break; |
| 2357 | 2433 | case 0x15: /* HDMA5 - HBL General DMA - Mode, Length */ |
| 2358 | | if( !(data & 0x80) ) |
| 2434 | if (!(data & 0x80)) |
| 2359 | 2435 | { |
| 2360 | | if( m_lcd.hdma_enabled ) |
| 2436 | if (m_hdma_enabled) |
| 2361 | 2437 | { |
| 2362 | | m_lcd.hdma_enabled = 0; |
| 2438 | m_hdma_enabled = 0; |
| 2363 | 2439 | data = HDMA5 & 0x80; |
| 2364 | 2440 | } |
| 2365 | 2441 | else |
| 2366 | 2442 | { |
| 2367 | 2443 | /* General DMA */ |
| 2368 | | gbc_hdma( ((data & 0x7F) + 1) * 0x10 ); |
| 2369 | | // cpunum_set_reg( 0, LR35902_DMA_CYCLES, 4 + ( ( ( data & 0x7F ) + 1 ) * 32 ) ); |
| 2444 | hdma_trans(((data & 0x7F) + 1) * 0x10); |
| 2445 | // cpunum_set_reg(0, LR35902_DMA_CYCLES, 4 + (((data & 0x7F) + 1) * 32)); |
| 2370 | 2446 | data = 0xff; |
| 2371 | 2447 | } |
| 2372 | 2448 | } |
| 2373 | 2449 | else |
| 2374 | 2450 | { |
| 2375 | 2451 | /* H-Blank DMA */ |
| 2376 | | m_lcd.hdma_enabled = 1; |
| 2452 | m_hdma_enabled = 1; |
| 2377 | 2453 | data &= 0x7f; |
| 2378 | | m_lcd.gb_vid_regs[offset] = data; |
| 2454 | m_vid_regs[offset] = data; |
| 2379 | 2455 | /* Check if HDMA should be immediately performed */ |
| 2380 | | if ( m_lcd.hdma_possible ) |
| 2456 | if (m_hdma_possible) |
| 2381 | 2457 | { |
| 2382 | | gbc_hdma( 0x10 ); |
| 2383 | | // cpunum_set_reg( 0, LR35902_DMA_CYCLES, 36 ); |
| 2384 | | m_lcd.hdma_possible = 0; |
| 2458 | hdma_trans(0x10); |
| 2459 | // cpunum_set_reg(0, LR35902_DMA_CYCLES, 36); |
| 2460 | m_hdma_possible = 0; |
| 2385 | 2461 | } |
| 2386 | 2462 | } |
| 2387 | 2463 | break; |
| 2388 | 2464 | case 0x28: /* BCPS - Background palette specification */ |
| 2389 | 2465 | GBCBCPS = data; |
| 2390 | 2466 | if (data & 0x01) |
| 2391 | | GBCBCPD = m_lcd.cgb_bpal[( data >> 1 ) & 0x1F] >> 8; |
| 2467 | GBCBCPD = m_cgb_bpal[(data >> 1) & 0x1F] >> 8; |
| 2392 | 2468 | else |
| 2393 | | GBCBCPD = m_lcd.cgb_bpal[( data >> 1 ) & 0x1F] & 0xFF; |
| 2469 | GBCBCPD = m_cgb_bpal[(data >> 1) & 0x1F] & 0xFF; |
| 2394 | 2470 | break; |
| 2395 | 2471 | case 0x29: /* BCPD - background palette data */ |
| 2396 | | if ( m_lcd.pal_locked == LOCKED ) |
| 2472 | if (m_pal_locked == LOCKED) |
| 2397 | 2473 | { |
| 2398 | 2474 | return; |
| 2399 | 2475 | } |
| 2400 | 2476 | GBCBCPD = data; |
| 2401 | 2477 | if (GBCBCPS & 0x01) |
| 2402 | | m_lcd.cgb_bpal[( GBCBCPS >> 1 ) & 0x1F] = ((data << 8) | (m_lcd.cgb_bpal[( GBCBCPS >> 1 ) & 0x1F] & 0xFF)) & 0x7FFF; |
| 2478 | m_cgb_bpal[(GBCBCPS >> 1) & 0x1F] = ((data << 8) | (m_cgb_bpal[(GBCBCPS >> 1) & 0x1F] & 0xFF)) & 0x7FFF; |
| 2403 | 2479 | else |
| 2404 | | m_lcd.cgb_bpal[( GBCBCPS >> 1 ) & 0x1F] = ((m_lcd.cgb_bpal[( GBCBCPS >> 1 ) & 0x1F] & 0xFF00) | data) & 0x7FFF; |
| 2405 | | if( GBCBCPS & 0x80 ) |
| 2480 | m_cgb_bpal[(GBCBCPS >> 1) & 0x1F] = ((m_cgb_bpal[(GBCBCPS >> 1) & 0x1F] & 0xFF00) | data) & 0x7FFF; |
| 2481 | if (GBCBCPS & 0x80) |
| 2406 | 2482 | { |
| 2407 | 2483 | GBCBCPS++; |
| 2408 | 2484 | GBCBCPS &= 0xBF; |
| r23879 | r23880 | |
| 2411 | 2487 | case 0x2A: /* OCPS - Object palette specification */ |
| 2412 | 2488 | GBCOCPS = data; |
| 2413 | 2489 | if (data & 0x01) |
| 2414 | | GBCOCPD = m_lcd.cgb_spal[( data >> 1 ) & 0x1F] >> 8; |
| 2490 | GBCOCPD = m_cgb_spal[(data >> 1) & 0x1F] >> 8; |
| 2415 | 2491 | else |
| 2416 | | GBCOCPD = m_lcd.cgb_spal[( data >> 1 ) & 0x1F] & 0xFF; |
| 2492 | GBCOCPD = m_cgb_spal[(data >> 1) & 0x1F] & 0xFF; |
| 2417 | 2493 | break; |
| 2418 | 2494 | case 0x2B: /* OCPD - Object palette data */ |
| 2419 | | if ( m_lcd.pal_locked == LOCKED ) |
| 2495 | if (m_pal_locked == LOCKED) |
| 2420 | 2496 | { |
| 2421 | 2497 | return; |
| 2422 | 2498 | } |
| 2423 | 2499 | GBCOCPD = data; |
| 2424 | 2500 | if (GBCOCPS & 0x01) |
| 2425 | | m_lcd.cgb_spal[( GBCOCPS >> 1 ) & 0x1F] = ((data << 8) | (m_lcd.cgb_spal[( GBCOCPS >> 1 ) & 0x1F] & 0xFF)) & 0x7FFF; |
| 2501 | m_cgb_spal[(GBCOCPS >> 1) & 0x1F] = ((data << 8) | (m_cgb_spal[(GBCOCPS >> 1) & 0x1F] & 0xFF)) & 0x7FFF; |
| 2426 | 2502 | else |
| 2427 | | m_lcd.cgb_spal[( GBCOCPS >> 1 ) & 0x1F] = ((m_lcd.cgb_spal[( GBCOCPS >> 1 ) & 0x1F] & 0xFF00) | data) & 0x7FFF; |
| 2428 | | if( GBCOCPS & 0x80 ) |
| 2503 | m_cgb_spal[(GBCOCPS >> 1) & 0x1F] = ((m_cgb_spal[(GBCOCPS >> 1) & 0x1F] & 0xFF00) | data) & 0x7FFF; |
| 2504 | if (GBCOCPS & 0x80) |
| 2429 | 2505 | { |
| 2430 | 2506 | GBCOCPS++; |
| 2431 | 2507 | GBCOCPS &= 0xBF; |
| r23879 | r23880 | |
| 2434 | 2510 | /* Undocumented registers */ |
| 2435 | 2511 | case 0x2C: |
| 2436 | 2512 | /* bit 0 can be read/written */ |
| 2437 | | logerror( "Write to undocumented register: %X = %X\n", offset, data ); |
| 2438 | | data = 0xFE | ( data & 0x01 ); |
| 2439 | | if ( data & 0x01 ) |
| 2513 | logerror("Write to undocumented register: %X = %X\n", offset, data); |
| 2514 | data = 0xFE | (data & 0x01); |
| 2515 | if (data & 0x01) |
| 2440 | 2516 | { |
| 2441 | | m_lcd.gbc_mode = 0; |
| 2517 | m_gbc_mode = 0; |
| 2442 | 2518 | } |
| 2443 | 2519 | break; |
| 2444 | 2520 | case 0x32: |
| 2445 | 2521 | case 0x33: |
| 2446 | 2522 | case 0x34: |
| 2447 | 2523 | /* whole byte can be read/written */ |
| 2448 | | logerror( "Write to undocumented register: %X = %X\n", offset, data ); |
| 2524 | logerror("Write to undocumented register: %X = %X\n", offset, data); |
| 2449 | 2525 | break; |
| 2450 | 2526 | case 0x35: |
| 2451 | 2527 | /* bit 4-6 can be read/written */ |
| 2452 | | logerror( "Write to undocumented register: %X = %X\n", offset, data ); |
| 2453 | | data = 0x8F | ( data & 0x70 ); |
| 2528 | logerror("Write to undocumented register: %X = %X\n", offset, data); |
| 2529 | data = 0x8F | (data & 0x70); |
| 2454 | 2530 | break; |
| 2455 | 2531 | case 0x36: |
| 2456 | 2532 | case 0x37: |
| 2457 | | logerror( "Write to undocumented register: %X = %X\n", offset, data ); |
| 2533 | logerror("Write to undocumented register: %X = %X\n", offset, data); |
| 2458 | 2534 | return; |
| 2459 | 2535 | default: |
| 2460 | 2536 | /* we didn't handle the write, so pass it to the GB handler */ |
| 2461 | | gb_video_w( space, offset, data ); |
| 2537 | gb_lcd_device::video_w(space, offset, data); |
| 2462 | 2538 | return; |
| 2463 | 2539 | } |
| 2464 | 2540 | |
| 2465 | | m_lcd.gb_vid_regs[offset] = data; |
| 2541 | m_vid_regs[offset] = data; |
| 2466 | 2542 | } |
| 2543 | |
| 2544 | // Super Game Boy |
| 2545 | |
| 2546 | void sgb_lcd_device::sgb_io_write_pal(int offs, UINT8 *data) |
| 2547 | { |
| 2548 | switch (offs) |
| 2549 | { |
| 2550 | case 0x00: /* PAL01 */ |
| 2551 | m_sgb_pal[0 * 4 + 0] = data[1] | (data[2] << 8); |
| 2552 | m_sgb_pal[0 * 4 + 1] = data[3] | (data[4] << 8); |
| 2553 | m_sgb_pal[0 * 4 + 2] = data[5] | (data[6] << 8); |
| 2554 | m_sgb_pal[0 * 4 + 3] = data[7] | (data[8] << 8); |
| 2555 | m_sgb_pal[1 * 4 + 0] = data[1] | (data[2] << 8); |
| 2556 | m_sgb_pal[1 * 4 + 1] = data[9] | (data[10] << 8); |
| 2557 | m_sgb_pal[1 * 4 + 2] = data[11] | (data[12] << 8); |
| 2558 | m_sgb_pal[1 * 4 + 3] = data[13] | (data[14] << 8); |
| 2559 | break; |
| 2560 | case 0x01: /* PAL23 */ |
| 2561 | m_sgb_pal[2 * 4 + 0] = data[1] | (data[2] << 8); |
| 2562 | m_sgb_pal[2 * 4 + 1] = data[3] | (data[4] << 8); |
| 2563 | m_sgb_pal[2 * 4 + 2] = data[5] | (data[6] << 8); |
| 2564 | m_sgb_pal[2 * 4 + 3] = data[7] | (data[8] << 8); |
| 2565 | m_sgb_pal[3 * 4 + 0] = data[1] | (data[2] << 8); |
| 2566 | m_sgb_pal[3 * 4 + 1] = data[9] | (data[10] << 8); |
| 2567 | m_sgb_pal[3 * 4 + 2] = data[11] | (data[12] << 8); |
| 2568 | m_sgb_pal[3 * 4 + 3] = data[13] | (data[14] << 8); |
| 2569 | break; |
| 2570 | case 0x02: /* PAL03 */ |
| 2571 | m_sgb_pal[0 * 4 + 0] = data[1] | (data[2] << 8); |
| 2572 | m_sgb_pal[0 * 4 + 1] = data[3] | (data[4] << 8); |
| 2573 | m_sgb_pal[0 * 4 + 2] = data[5] | (data[6] << 8); |
| 2574 | m_sgb_pal[0 * 4 + 3] = data[7] | (data[8] << 8); |
| 2575 | m_sgb_pal[3 * 4 + 0] = data[1] | (data[2] << 8); |
| 2576 | m_sgb_pal[3 * 4 + 1] = data[9] | (data[10] << 8); |
| 2577 | m_sgb_pal[3 * 4 + 2] = data[11] | (data[12] << 8); |
| 2578 | m_sgb_pal[3 * 4 + 3] = data[13] | (data[14] << 8); |
| 2579 | break; |
| 2580 | case 0x03: /* PAL12 */ |
| 2581 | m_sgb_pal[1 * 4 + 0] = data[1] | (data[2] << 8); |
| 2582 | m_sgb_pal[1 * 4 + 1] = data[3] | (data[4] << 8); |
| 2583 | m_sgb_pal[1 * 4 + 2] = data[5] | (data[6] << 8); |
| 2584 | m_sgb_pal[1 * 4 + 3] = data[7] | (data[8] << 8); |
| 2585 | m_sgb_pal[2 * 4 + 0] = data[1] | (data[2] << 8); |
| 2586 | m_sgb_pal[2 * 4 + 1] = data[9] | (data[10] << 8); |
| 2587 | m_sgb_pal[2 * 4 + 2] = data[11] | (data[12] << 8); |
| 2588 | m_sgb_pal[2 * 4 + 3] = data[13] | (data[14] << 8); |
| 2589 | break; |
| 2590 | case 0x04: /* ATTR_BLK */ |
| 2591 | { |
| 2592 | UINT8 I, J, K, o; |
| 2593 | for( K = 0; K < data[1]; K++ ) |
| 2594 | { |
| 2595 | o = K * 6; |
| 2596 | if( data[o + 2] & 0x1 ) |
| 2597 | { |
| 2598 | for( I = data[ o + 4]; I <= data[o + 6]; I++ ) |
| 2599 | { |
| 2600 | for( J = data[o + 5]; J <= data[o + 7]; J++ ) |
| 2601 | { |
| 2602 | m_sgb_pal_map[I][J] = data[o + 3] & 0x3; |
| 2603 | } |
| 2604 | } |
| 2605 | } |
| 2606 | } |
| 2607 | } |
| 2608 | break; |
| 2609 | case 0x05: /* ATTR_LIN */ |
| 2610 | { |
| 2611 | UINT8 J, K; |
| 2612 | if( data[1] > 15 ) |
| 2613 | data[1] = 15; |
| 2614 | for( K = 0; K < data[1]; K++ ) |
| 2615 | { |
| 2616 | if( data[K + 1] & 0x80 ) |
| 2617 | { |
| 2618 | for( J = 0; J < 20; J++ ) |
| 2619 | { |
| 2620 | m_sgb_pal_map[J][data[K + 1] & 0x1f] = (data[K + 1] & 0x60) >> 5; |
| 2621 | } |
| 2622 | } |
| 2623 | else |
| 2624 | { |
| 2625 | for( J = 0; J < 18; J++ ) |
| 2626 | { |
| 2627 | m_sgb_pal_map[data[K + 1] & 0x1f][J] = (data[K + 1] & 0x60) >> 5; |
| 2628 | } |
| 2629 | } |
| 2630 | } |
| 2631 | } |
| 2632 | break; |
| 2633 | case 0x06: /* ATTR_DIV */ |
| 2634 | { |
| 2635 | UINT8 I, J; |
| 2636 | if( data[1] & 0x40 ) /* Vertical */ |
| 2637 | { |
| 2638 | for( I = 0; I < data[2]; I++ ) |
| 2639 | { |
| 2640 | for( J = 0; J < 20; J++ ) |
| 2641 | { |
| 2642 | m_sgb_pal_map[J][I] = (data[1] & 0xC) >> 2; |
| 2643 | } |
| 2644 | } |
| 2645 | for( J = 0; J < 20; J++ ) |
| 2646 | { |
| 2647 | m_sgb_pal_map[J][data[2]] = (data[1] & 0x30) >> 4; |
| 2648 | } |
| 2649 | for( I = data[2] + 1; I < 18; I++ ) |
| 2650 | { |
| 2651 | for( J = 0; J < 20; J++ ) |
| 2652 | { |
| 2653 | m_sgb_pal_map[J][I] = data[1] & 0x3; |
| 2654 | } |
| 2655 | } |
| 2656 | } |
| 2657 | else /* Horizontal */ |
| 2658 | { |
| 2659 | for( I = 0; I < data[2]; I++ ) |
| 2660 | { |
| 2661 | for( J = 0; J < 18; J++ ) |
| 2662 | { |
| 2663 | m_sgb_pal_map[I][J] = (data[1] & 0xC) >> 2; |
| 2664 | } |
| 2665 | } |
| 2666 | for( J = 0; J < 18; J++ ) |
| 2667 | { |
| 2668 | m_sgb_pal_map[data[2]][J] = (data[1] & 0x30) >> 4; |
| 2669 | } |
| 2670 | for( I = data[2] + 1; I < 20; I++ ) |
| 2671 | { |
| 2672 | for( J = 0; J < 18; J++ ) |
| 2673 | { |
| 2674 | m_sgb_pal_map[I][J] = data[1] & 0x3; |
| 2675 | } |
| 2676 | } |
| 2677 | } |
| 2678 | } |
| 2679 | break; |
| 2680 | case 0x07: /* ATTR_CHR */ |
| 2681 | { |
| 2682 | UINT16 I, sets; |
| 2683 | UINT8 x, y; |
| 2684 | sets = (data[3] | (data[4] << 8) ); |
| 2685 | if( sets > 360 ) |
| 2686 | sets = 360; |
| 2687 | sets >>= 2; |
| 2688 | sets += 6; |
| 2689 | x = data[1]; |
| 2690 | y = data[2]; |
| 2691 | if( data[5] ) /* Vertical */ |
| 2692 | { |
| 2693 | for( I = 6; I < sets; I++ ) |
| 2694 | { |
| 2695 | m_sgb_pal_map[x][y++] = (data[I] & 0xC0) >> 6; |
| 2696 | if( y > 17 ) |
| 2697 | { |
| 2698 | y = 0; |
| 2699 | x++; |
| 2700 | if( x > 19 ) |
| 2701 | x = 0; |
| 2702 | } |
| 2703 | |
| 2704 | m_sgb_pal_map[x][y++] = (data[I] & 0x30) >> 4; |
| 2705 | if( y > 17 ) |
| 2706 | { |
| 2707 | y = 0; |
| 2708 | x++; |
| 2709 | if( x > 19 ) |
| 2710 | x = 0; |
| 2711 | } |
| 2712 | |
| 2713 | m_sgb_pal_map[x][y++] = (data[I] & 0xC) >> 2; |
| 2714 | if( y > 17 ) |
| 2715 | { |
| 2716 | y = 0; |
| 2717 | x++; |
| 2718 | if( x > 19 ) |
| 2719 | x = 0; |
| 2720 | } |
| 2721 | |
| 2722 | m_sgb_pal_map[x][y++] = data[I] & 0x3; |
| 2723 | if( y > 17 ) |
| 2724 | { |
| 2725 | y = 0; |
| 2726 | x++; |
| 2727 | if( x > 19 ) |
| 2728 | x = 0; |
| 2729 | } |
| 2730 | } |
| 2731 | } |
| 2732 | else /* horizontal */ |
| 2733 | { |
| 2734 | for( I = 6; I < sets; I++ ) |
| 2735 | { |
| 2736 | m_sgb_pal_map[x++][y] = (data[I] & 0xC0) >> 6; |
| 2737 | if( x > 19 ) |
| 2738 | { |
| 2739 | x = 0; |
| 2740 | y++; |
| 2741 | if( y > 17 ) |
| 2742 | y = 0; |
| 2743 | } |
| 2744 | |
| 2745 | m_sgb_pal_map[x++][y] = (data[I] & 0x30) >> 4; |
| 2746 | if( x > 19 ) |
| 2747 | { |
| 2748 | x = 0; |
| 2749 | y++; |
| 2750 | if( y > 17 ) |
| 2751 | y = 0; |
| 2752 | } |
| 2753 | |
| 2754 | m_sgb_pal_map[x++][y] = (data[I] & 0xC) >> 2; |
| 2755 | if( x > 19 ) |
| 2756 | { |
| 2757 | x = 0; |
| 2758 | y++; |
| 2759 | if( y > 17 ) |
| 2760 | y = 0; |
| 2761 | } |
| 2762 | |
| 2763 | m_sgb_pal_map[x++][y] = data[I] & 0x3; |
| 2764 | if( x > 19 ) |
| 2765 | { |
| 2766 | x = 0; |
| 2767 | y++; |
| 2768 | if( y > 17 ) |
| 2769 | y = 0; |
| 2770 | } |
| 2771 | } |
| 2772 | } |
| 2773 | } |
| 2774 | break; |
| 2775 | case 0x08: /* SOUND */ |
| 2776 | /* This command enables internal sound effects */ |
| 2777 | /* Not Implemented */ |
| 2778 | break; |
| 2779 | case 0x09: /* SOU_TRN */ |
| 2780 | /* This command sends data to the SNES sound processor. |
| 2781 | We'll need to emulate that for this to be used */ |
| 2782 | /* Not Implemented */ |
| 2783 | break; |
| 2784 | case 0x0A: /* PAL_SET */ |
| 2785 | { |
| 2786 | UINT16 index_; |
| 2787 | |
| 2788 | /* Palette 0 */ |
| 2789 | index_ = (UINT16)(data[1] | (data[2] << 8)) * 4; |
| 2790 | m_sgb_pal[0] = m_sgb_pal_data[index_]; |
| 2791 | m_sgb_pal[1] = m_sgb_pal_data[index_ + 1]; |
| 2792 | m_sgb_pal[2] = m_sgb_pal_data[index_ + 2]; |
| 2793 | m_sgb_pal[3] = m_sgb_pal_data[index_ + 3]; |
| 2794 | /* Palette 1 */ |
| 2795 | index_ = (UINT16)(data[3] | (data[4] << 8)) * 4; |
| 2796 | m_sgb_pal[4] = m_sgb_pal_data[index_]; |
| 2797 | m_sgb_pal[5] = m_sgb_pal_data[index_ + 1]; |
| 2798 | m_sgb_pal[6] = m_sgb_pal_data[index_ + 2]; |
| 2799 | m_sgb_pal[7] = m_sgb_pal_data[index_ + 3]; |
| 2800 | /* Palette 2 */ |
| 2801 | index_ = (UINT16)(data[5] | (data[6] << 8)) * 4; |
| 2802 | m_sgb_pal[8] = m_sgb_pal_data[index_]; |
| 2803 | m_sgb_pal[9] = m_sgb_pal_data[index_ + 1]; |
| 2804 | m_sgb_pal[10] = m_sgb_pal_data[index_ + 2]; |
| 2805 | m_sgb_pal[11] = m_sgb_pal_data[index_ + 3]; |
| 2806 | /* Palette 3 */ |
| 2807 | index_ = (UINT16)(data[7] | (data[8] << 8)) * 4; |
| 2808 | m_sgb_pal[12] = m_sgb_pal_data[index_]; |
| 2809 | m_sgb_pal[13] = m_sgb_pal_data[index_ + 1]; |
| 2810 | m_sgb_pal[14] = m_sgb_pal_data[index_ + 2]; |
| 2811 | m_sgb_pal[15] = m_sgb_pal_data[index_ + 3]; |
| 2812 | /* Attribute File */ |
| 2813 | if (data[9] & 0x40) |
| 2814 | m_sgb_window_mask = 0; |
| 2815 | m_sgb_atf = (data[9] & 0x3f) * (18 * 5); |
| 2816 | if (data[9] & 0x80) |
| 2817 | { |
| 2818 | for (int j = 0; j < 18; j++ ) |
| 2819 | { |
| 2820 | for (int i = 0; i < 5; i++ ) |
| 2821 | { |
| 2822 | m_sgb_pal_map[i * 4][j] = (m_sgb_atf_data[(j * 5) + m_sgb_atf + i] & 0xC0) >> 6; |
| 2823 | m_sgb_pal_map[(i * 4) + 1][j] = (m_sgb_atf_data[(j * 5) + m_sgb_atf + i] & 0x30) >> 4; |
| 2824 | m_sgb_pal_map[(i * 4) + 2][j] = (m_sgb_atf_data[(j * 5) + m_sgb_atf + i] & 0xC) >> 2; |
| 2825 | m_sgb_pal_map[(i * 4) + 3][j] = m_sgb_atf_data[(j * 5) + m_sgb_atf + i] & 0x3; |
| 2826 | } |
| 2827 | } |
| 2828 | } |
| 2829 | } |
| 2830 | break; |
| 2831 | case 0x0B: /* PAL_TRN */ |
| 2832 | { |
| 2833 | UINT16 col; |
| 2834 | |
| 2835 | for (int i = 0; i < 2048; i++ ) |
| 2836 | { |
| 2837 | col = (m_vram[0x0800 + (i * 2) + 1] << 8) | m_vram[0x0800 + (i * 2)]; |
| 2838 | m_sgb_pal_data[i] = col; |
| 2839 | } |
| 2840 | } |
| 2841 | break; |
| 2842 | case 0x0C: /* ATRC_EN */ |
| 2843 | /* Not Implemented */ |
| 2844 | break; |
| 2845 | case 0x0D: /* TEST_EN */ |
| 2846 | /* Not Implemented */ |
| 2847 | break; |
| 2848 | case 0x0E: /* ICON_EN */ |
| 2849 | /* Not Implemented */ |
| 2850 | break; |
| 2851 | case 0x0F: /* DATA_SND */ |
| 2852 | /* Not Implemented */ |
| 2853 | break; |
| 2854 | case 0x10: /* DATA_TRN */ |
| 2855 | /* Not Implemented */ |
| 2856 | break; |
| 2857 | case 0x12: /* JUMP */ |
| 2858 | /* Not Implemented */ |
| 2859 | break; |
| 2860 | case 0x13: /* CHR_TRN */ |
| 2861 | if (data[1] & 0x1) |
| 2862 | memcpy(m_sgb_tile_data + 4096, m_vram + 0x0800, 4096); |
| 2863 | else |
| 2864 | memcpy(m_sgb_tile_data, m_vram + 0x0800, 4096); |
| 2865 | break; |
| 2866 | case 0x14: /* PCT_TRN */ |
| 2867 | { |
| 2868 | UINT16 col; |
| 2869 | if (m_sgb_border_hack) |
| 2870 | { |
| 2871 | memcpy(m_sgb_tile_map, m_vram + 0x1000, 2048); |
| 2872 | for (int i = 0; i < 64; i++) |
| 2873 | { |
| 2874 | col = (m_vram[0x0800 + (i * 2) + 1 ] << 8) | m_vram[0x0800 + (i * 2)]; |
| 2875 | m_sgb_pal[SGB_BORDER_PAL_OFFSET + i] = col; |
| 2876 | } |
| 2877 | } |
| 2878 | else /* Do things normally */ |
| 2879 | { |
| 2880 | memcpy(m_sgb_tile_map, m_vram + 0x0800, 2048); |
| 2881 | for (int i = 0; i < 64; i++) |
| 2882 | { |
| 2883 | col = (m_vram[0x1000 + (i * 2) + 1] << 8) | m_vram[0x1000 + (i * 2)]; |
| 2884 | m_sgb_pal[SGB_BORDER_PAL_OFFSET + i] = col; |
| 2885 | } |
| 2886 | } |
| 2887 | } |
| 2888 | break; |
| 2889 | case 0x15: /* ATTR_TRN */ |
| 2890 | memcpy(m_sgb_atf_data, m_vram + 0x0800, 4050); |
| 2891 | break; |
| 2892 | case 0x16: /* ATTR_SET */ |
| 2893 | { |
| 2894 | /* Attribute File */ |
| 2895 | if (data[1] & 0x40) |
| 2896 | m_sgb_window_mask = 0; |
| 2897 | m_sgb_atf = (data[1] & 0x3f) * (18 * 5); |
| 2898 | for (int j = 0; j < 18; j++) |
| 2899 | { |
| 2900 | for (int i = 0; i < 5; i++) |
| 2901 | { |
| 2902 | m_sgb_pal_map[i * 4][j] = (m_sgb_atf_data[(j * 5) + m_sgb_atf + i] & 0xC0) >> 6; |
| 2903 | m_sgb_pal_map[(i * 4) + 1][j] = (m_sgb_atf_data[(j * 5) + m_sgb_atf + i] & 0x30) >> 4; |
| 2904 | m_sgb_pal_map[(i * 4) + 2][j] = (m_sgb_atf_data[(j * 5) + m_sgb_atf + i] & 0xC) >> 2; |
| 2905 | m_sgb_pal_map[(i * 4) + 3][j] = m_sgb_atf_data[(j * 5) + m_sgb_atf + i] & 0x3; |
| 2906 | } |
| 2907 | } |
| 2908 | } |
| 2909 | break; |
| 2910 | case 0x17: /* MASK_EN */ |
| 2911 | m_sgb_window_mask = data[1]; |
| 2912 | break; |
| 2913 | case 0x18: /* OBJ_TRN */ |
| 2914 | /* Not Implemnted */ |
| 2915 | break; |
| 2916 | case 0x19: /* ? */ |
| 2917 | /* Called by: dkl,dkl2,dkl3,zeldadx |
| 2918 | But I don't know what it is for. */ |
| 2919 | /* Not Implemented */ |
| 2920 | break; |
| 2921 | case 0x1E: /* Used by bootrom to transfer the gb cart header */ |
| 2922 | break; |
| 2923 | case 0x1F: /* Used by bootrom to transfer the gb cart header */ |
| 2924 | break; |
| 2925 | default: |
| 2926 | logerror( "SGB: Unknown Command 0x%02x!\n", data[0] >> 3 ); |
| 2927 | } |
| 2928 | |
| 2929 | } |
| 2930 | |
| 2931 | |