trunk/src/mess/video/gba.c
r23313 | r23314 | |
45 | 45 | #define GBA_SUBMODE1 1 |
46 | 46 | #define GBA_SUBMODE2 2 |
47 | 47 | |
| 48 | inline void gba_state::update_mask(UINT8* mask, int mode, int submode, UINT32* obj_win, UINT8 inwin0, UINT8 inwin1, UINT8 in0_mask, UINT8 in1_mask, UINT8 out_mask) |
| 49 | { |
| 50 | UINT8 mode_mask = 0; |
| 51 | if (submode == GBA_SUBMODE2) |
| 52 | { |
| 53 | for (int x = 0; x < 240; x++) |
| 54 | { |
| 55 | mask[x] = out_mask; |
| 56 | |
| 57 | if ((obj_win[x] & 0x80000000) == 0) |
| 58 | mask[x] = m_WINOUT >> 8; |
| 59 | |
| 60 | if (inwin1) |
| 61 | { |
| 62 | if (is_in_window(x, 1)) |
| 63 | mask[x] = in1_mask; |
| 64 | } |
| 65 | |
| 66 | if (inwin0) |
| 67 | { |
| 68 | if (is_in_window(x, 0)) |
| 69 | mask[x] = in0_mask; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if (mode == GBA_MODE1) |
| 75 | { |
| 76 | // disable line3 |
| 77 | mode_mask = ~0x08; |
| 78 | } |
| 79 | else if (mode == GBA_MODE2) |
| 80 | { |
| 81 | // disable line0 & line1 |
| 82 | mode_mask = ~0x03; |
| 83 | } |
| 84 | else if (mode == GBA_MODE345) |
| 85 | { |
| 86 | // disable line0, line1 & line3 |
| 87 | mode_mask = ~0x0b; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | if (mode_mask) |
| 92 | { |
| 93 | for (int x = 0; x < 240; x++) |
| 94 | mask[x] &= mode_mask; |
| 95 | } |
| 96 | } |
| 97 | |
48 | 98 | void gba_state::draw_modes(int mode, int submode, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
49 | 99 | { |
50 | 100 | UINT32 backdrop = ((UINT16*)m_gba_pram.target())[0] | 0x30000000; |
r23313 | r23314 | |
53 | 103 | UINT8 inWin0Mask = m_WININ & 0x00ff; |
54 | 104 | UINT8 inWin1Mask = m_WININ >> 8; |
55 | 105 | UINT8 outMask = m_WINOUT & 0x00ff; |
| 106 | UINT8 masks[240]; // this puts together WinMasks with the fact that some modes/submodes skip specific layers! |
56 | 107 | |
57 | 108 | if (submode == GBA_SUBMODE2) |
58 | 109 | { |
r23313 | r23314 | |
108 | 159 | draw_gba_oam(lineOBJ, y); |
109 | 160 | if (submode == GBA_SUBMODE2) |
110 | 161 | draw_gba_oam_window(lineOBJWin, y); |
| 162 | |
| 163 | memset(masks, 0xff, sizeof(masks)); |
| 164 | update_mask(&masks[0], mode, submode, lineOBJWin, inWindow0, inWindow1, inWin0Mask, inWin1Mask, outMask); |
111 | 165 | |
112 | 166 | for (int x = 0; x < 240; x++) |
113 | 167 | { |
114 | 168 | UINT32 color = backdrop; |
115 | 169 | UINT8 top = 0x20; |
116 | | UINT8 mask = outMask; |
117 | 170 | |
118 | | if (submode == GBA_SUBMODE2) |
| 171 | if ((UINT8)(line0[x] >> 24) < (UINT8)(color >> 24) && masks[x] & 0x01) |
119 | 172 | { |
120 | | if ((lineOBJWin[x] & 0x80000000) == 0) |
121 | | mask = m_WINOUT >> 8; |
122 | | |
123 | | if (inWindow1) |
124 | | { |
125 | | if (is_in_window(x, 1)) |
126 | | mask = inWin1Mask; |
127 | | } |
128 | | |
129 | | if (inWindow0) |
130 | | { |
131 | | if (is_in_window(x, 0)) |
132 | | mask = inWin0Mask; |
133 | | } |
134 | | |
| 173 | color = line0[x]; |
| 174 | top = 0x01; |
135 | 175 | } |
136 | 176 | |
137 | | if (mode == GBA_MODE0 || mode == GBA_MODE1) |
138 | | if ((UINT8)(line0[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x01))) |
139 | | { |
140 | | color = line0[x]; |
141 | | top = 0x01; |
142 | | } |
| 177 | if ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24) && masks[x] & 0x02) |
| 178 | { |
| 179 | color = line1[x]; |
| 180 | top = 0x02; |
| 181 | } |
143 | 182 | |
144 | | if (mode == GBA_MODE0 || mode == GBA_MODE1) |
145 | | if ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x02))) |
146 | | { |
147 | | color = line1[x]; |
148 | | top = 0x02; |
149 | | } |
| 183 | if ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24) && masks[x] & 0x04) |
| 184 | { |
| 185 | color = line2[x]; |
| 186 | top = 0x04; |
| 187 | } |
150 | 188 | |
151 | | if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345) |
152 | | if ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x04))) |
153 | | { |
154 | | color = line2[x]; |
155 | | top = 0x04; |
156 | | } |
| 189 | if ((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24) && masks[x] & 0x08) |
| 190 | { |
| 191 | color = line3[x]; |
| 192 | top = 0x08; |
| 193 | } |
157 | 194 | |
158 | | if (mode == GBA_MODE0 || mode == GBA_MODE2) |
159 | | if ((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x08))) |
160 | | { |
161 | | color = line3[x]; |
162 | | top = 0x08; |
163 | | } |
| 195 | if ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24) && masks[x] & 0x10) |
| 196 | { |
| 197 | color = lineOBJ[x]; |
| 198 | top = 0x10; |
| 199 | } |
164 | 200 | |
165 | | if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345) |
166 | | if ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x10))) |
167 | | { |
168 | | color = lineOBJ[x]; |
169 | | top = 0x10; |
170 | | } |
171 | | |
172 | 201 | if (color & 0x00010000) |
173 | 202 | { |
174 | | if ((submode == GBA_SUBMODE0 && top == 0x10) || submode == GBA_SUBMODE1 || submode == GBA_SUBMODE2) |
| 203 | if (submode != GBA_SUBMODE0 || top == 0x10) |
175 | 204 | { |
176 | 205 | UINT32 back = backdrop; |
177 | 206 | UINT8 top2 = 0x20; |
178 | 207 | |
179 | | if (mode == GBA_MODE0 || mode == GBA_MODE1) |
180 | | if ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x01))) |
181 | | { |
182 | | back = line0[x]; |
183 | | top2 = 0x01; |
184 | | } |
| 208 | if ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x01) |
| 209 | { |
| 210 | back = line0[x]; |
| 211 | top2 = 0x01; |
| 212 | } |
185 | 213 | |
186 | | if (mode == GBA_MODE0 || mode == GBA_MODE1) |
187 | | if ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x02))) |
188 | | { |
189 | | back = line1[x]; |
190 | | top2 = 0x02; |
191 | | } |
| 214 | if ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x02) |
| 215 | { |
| 216 | back = line1[x]; |
| 217 | top2 = 0x02; |
| 218 | } |
192 | 219 | |
193 | | if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345) |
194 | | if ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x04))) |
195 | | { |
196 | | back = line2[x]; |
197 | | top2 = 0x04; |
198 | | } |
| 220 | if ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x04) |
| 221 | { |
| 222 | back = line2[x]; |
| 223 | top2 = 0x04; |
| 224 | } |
199 | 225 | |
200 | | if (mode == GBA_MODE0 || mode == GBA_MODE2) |
201 | | if ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE0 || submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x08))) |
202 | | { |
203 | | back = line3[x]; |
204 | | top2 = 0x08; |
205 | | } |
| 226 | if ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x08) |
| 227 | { |
| 228 | back = line3[x]; |
| 229 | top2 = 0x08; |
| 230 | } |
206 | 231 | |
207 | 232 | if (top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT)) |
208 | 233 | color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]); |
r23313 | r23314 | |
223 | 248 | } |
224 | 249 | } |
225 | 250 | } |
226 | | else if (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x20)) |
| 251 | else if (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && masks[x] & 0x20)) |
227 | 252 | { |
228 | 253 | if (top & m_BLDCNT) |
229 | 254 | { |
r23313 | r23314 | |
236 | 261 | UINT32 back = backdrop; |
237 | 262 | UINT8 top2 = 0x20; |
238 | 263 | |
239 | | if (mode == GBA_MODE0 || mode == GBA_MODE1) |
240 | | if ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x01))) |
| 264 | if ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x01) |
| 265 | { |
| 266 | if (top != 0x01) |
241 | 267 | { |
242 | | if (top != 0x01) |
243 | | { |
244 | | back = line0[x]; |
245 | | top2 = 0x01; |
246 | | } |
| 268 | back = line0[x]; |
| 269 | top2 = 0x01; |
247 | 270 | } |
| 271 | } |
248 | 272 | |
249 | | if (mode == GBA_MODE0 || mode == GBA_MODE1) |
250 | | if ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x02))) |
| 273 | if ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x02) |
| 274 | { |
| 275 | if (top != 0x02) |
251 | 276 | { |
252 | | if (top != 0x02) |
253 | | { |
254 | | back = line1[x]; |
255 | | top2 = 0x02; |
256 | | } |
| 277 | back = line1[x]; |
| 278 | top2 = 0x02; |
257 | 279 | } |
| 280 | } |
258 | 281 | |
259 | | if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345) |
260 | | if ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x04))) |
| 282 | if ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x04) |
| 283 | { |
| 284 | if (top != 0x04) |
261 | 285 | { |
262 | | if (top != 0x04) |
263 | | { |
264 | | back = line2[x]; |
265 | | top2 = 0x04; |
266 | | } |
| 286 | back = line2[x]; |
| 287 | top2 = 0x04; |
267 | 288 | } |
| 289 | } |
268 | 290 | |
269 | | if (mode == GBA_MODE0 || mode == GBA_MODE2) |
270 | | if ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x08))) |
| 291 | if ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x08) |
| 292 | { |
| 293 | if (top != 0x08) |
271 | 294 | { |
272 | | if (top != 0x08) |
273 | | { |
274 | | back = line3[x]; |
275 | | top2 = 0x08; |
276 | | } |
| 295 | back = line3[x]; |
| 296 | top2 = 0x08; |
277 | 297 | } |
| 298 | } |
278 | 299 | |
279 | | if (mode == GBA_MODE0 || mode == GBA_MODE1 || mode == GBA_MODE2 || mode == GBA_MODE345) |
280 | | if ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24) && (submode == GBA_SUBMODE1 || (submode == GBA_SUBMODE2 && mask & 0x10))) |
| 300 | if ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24) && masks[x] & 0x10) |
| 301 | { |
| 302 | if (top != 0x10) |
281 | 303 | { |
282 | | if (top != 0x10) |
283 | | { |
284 | | back = lineOBJ[x]; |
285 | | top2 = 0x10; |
286 | | } |
| 304 | back = lineOBJ[x]; |
| 305 | top2 = 0x10; |
287 | 306 | } |
| 307 | } |
288 | 308 | |
289 | 309 | if (top2 & (m_BLDCNT >> BLDCNT_TP2_SHIFT)) |
290 | 310 | color = alpha_blend_pixel(color, back, coeff[m_BLDALPHA & 0x1f], coeff[(m_BLDALPHA >> 8) & 0x1f]); |
r23313 | r23314 | |
1852 | 1872 | case 3: |
1853 | 1873 | case 4: |
1854 | 1874 | case 5: |
1855 | | draw_modes( m_DISPCNT & 7, submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], depth); |
| 1875 | draw_modes(m_DISPCNT & 7, submode, y, &m_xferscan[0][1024], &m_xferscan[1][1024], &m_xferscan[2][1024], &m_xferscan[3][1024], &m_xferscan[4][1024], &m_xferscan[5][1024], &m_xferscan[6][1024], depth); |
1856 | 1876 | break; |
1857 | 1877 | default: |
1858 | | fatalerror( "Invalid screen mode (6 or 7)!\n" ); |
| 1878 | fatalerror("Invalid screen mode (6 or 7)!\n"); |
1859 | 1879 | break; |
1860 | 1880 | } |
1861 | | |
| 1881 | |
1862 | 1882 | for (int x = 0; x < 240; x++) |
1863 | 1883 | { |
1864 | 1884 | scanline[x] = m_xferscan[6][1024 + x] & 0x7fff; |