src/mess/video/gbamode0.c
| r0 | r5698 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | gbamode0.c |
| 4 | |
| 5 | Handles GBA mode 0 screen rendering |
| 6 | |
| 7 | By R. Belmont & Harmony |
| 8 | |
| 9 | ***************************************************************************/ |
| 10 | |
| 11 | void draw_mode0_scanline(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 12 | { |
| 13 | int x = 0; |
| 14 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 15 | |
| 16 | draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS); |
| 17 | draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS); |
| 18 | draw_bg_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS); |
| 19 | draw_bg_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS); |
| 20 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 21 | |
| 22 | for(x = 0; x < 240; x++) |
| 23 | { |
| 24 | UINT32 color = backdrop; |
| 25 | UINT8 top = 0x20; |
| 26 | |
| 27 | if(line0[x] < color) |
| 28 | { |
| 29 | color = line0[x]; |
| 30 | top = 0x01; |
| 31 | } |
| 32 | |
| 33 | if((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24)) |
| 34 | { |
| 35 | color = line1[x]; |
| 36 | top = 0x02; |
| 37 | } |
| 38 | |
| 39 | if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24)) |
| 40 | { |
| 41 | color = line2[x]; |
| 42 | top = 0x04; |
| 43 | } |
| 44 | |
| 45 | if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24)) |
| 46 | { |
| 47 | color = line3[x]; |
| 48 | top = 0x08; |
| 49 | } |
| 50 | |
| 51 | if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)) |
| 52 | { |
| 53 | color = lineOBJ[x]; |
| 54 | top = 0x10; |
| 55 | } |
| 56 | |
| 57 | if(top == 0x10 && (color & 0x00010000) != 0) |
| 58 | { |
| 59 | UINT32 back = backdrop; |
| 60 | UINT8 top2 = 0x20; |
| 61 | |
| 62 | if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)) |
| 63 | { |
| 64 | back = line0[x]; |
| 65 | top2 = 0x01; |
| 66 | } |
| 67 | |
| 68 | if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)) |
| 69 | { |
| 70 | back = line1[x]; |
| 71 | top2 = 0x02; |
| 72 | } |
| 73 | |
| 74 | if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)) |
| 75 | { |
| 76 | back = line2[x]; |
| 77 | top2 = 0x04; |
| 78 | } |
| 79 | |
| 80 | if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)) |
| 81 | { |
| 82 | back = line3[x]; |
| 83 | top2 = 0x08; |
| 84 | } |
| 85 | |
| 86 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 87 | { |
| 88 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 93 | { |
| 94 | case BLDCNT_SFX_LIGHTEN: |
| 95 | if(top & gba_state->BLDCNT) |
| 96 | { |
| 97 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 98 | } |
| 99 | break; |
| 100 | case BLDCNT_SFX_DARKEN: |
| 101 | if(top & gba_state->BLDCNT) |
| 102 | { |
| 103 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 104 | } |
| 105 | break; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | lineMix[x] = color; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void draw_mode0_scanline_nowindow(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 115 | { |
| 116 | int x = 0; |
| 117 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 118 | int effect = gba_state->BLDCNT & BLDCNT_SFX; |
| 119 | |
| 120 | draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS); |
| 121 | draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS); |
| 122 | draw_bg_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS); |
| 123 | draw_bg_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS); |
| 124 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 125 | |
| 126 | for(x = 0; x < 240; x++) |
| 127 | { |
| 128 | UINT32 color = backdrop; |
| 129 | UINT8 top = 0x20; |
| 130 | |
| 131 | if(line0[x] < color) |
| 132 | { |
| 133 | color = line0[x]; |
| 134 | top = 0x01; |
| 135 | } |
| 136 | |
| 137 | if(line1[x] < (color & 0xff000000)) |
| 138 | { |
| 139 | color = line1[x]; |
| 140 | top = 0x02; |
| 141 | } |
| 142 | |
| 143 | if(line2[x] < (color & 0xff000000)) |
| 144 | { |
| 145 | color = line2[x]; |
| 146 | top = 0x04; |
| 147 | } |
| 148 | |
| 149 | if(line3[x] < (color & 0xff000000)) |
| 150 | { |
| 151 | color = line3[x]; |
| 152 | top = 0x08; |
| 153 | } |
| 154 | |
| 155 | if(lineOBJ[x] < (color & 0xff000000)) |
| 156 | { |
| 157 | color = lineOBJ[x]; |
| 158 | top = 0x10; |
| 159 | } |
| 160 | |
| 161 | if((color & 0x00010000) == 0) |
| 162 | { |
| 163 | switch(effect) |
| 164 | { |
| 165 | case BLDCNT_SFX_NONE: |
| 166 | break; |
| 167 | case BLDCNT_SFX_ALPHA: |
| 168 | if(gba_state->BLDCNT & top) |
| 169 | { |
| 170 | UINT32 back = backdrop; |
| 171 | UINT8 top2 = 0x20; |
| 172 | |
| 173 | if(line0[x] < back) |
| 174 | { |
| 175 | if(top != 0x01) |
| 176 | { |
| 177 | back = line0[x]; |
| 178 | top2 = 0x01; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if(line1[x] < (back & 0xff000000)) |
| 183 | { |
| 184 | if(top != 0x02) |
| 185 | { |
| 186 | back = line1[x]; |
| 187 | top2 = 0x02; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | if(line2[x] < (back & 0xff000000)) |
| 192 | { |
| 193 | if(top != 0x04) |
| 194 | { |
| 195 | back = line2[x]; |
| 196 | top2 = 0x04; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | if(line3[x] < (back & 0xff000000)) |
| 201 | { |
| 202 | if(top != 0x08) |
| 203 | { |
| 204 | back = line3[x]; |
| 205 | top2 = 0x08; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | if(lineOBJ[x] < (back & 0xff000000)) |
| 210 | { |
| 211 | if(top != 0x10) |
| 212 | { |
| 213 | back = lineOBJ[x]; |
| 214 | top2 = 0x10; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 219 | { |
| 220 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 221 | } |
| 222 | } |
| 223 | break; |
| 224 | case BLDCNT_SFX_LIGHTEN: |
| 225 | if(top & gba_state->BLDCNT) |
| 226 | { |
| 227 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 228 | } |
| 229 | break; |
| 230 | case BLDCNT_SFX_DARKEN: |
| 231 | if(top & gba_state->BLDCNT) |
| 232 | { |
| 233 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 234 | } |
| 235 | break; |
| 236 | } |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | UINT32 back = backdrop; |
| 241 | UINT8 top2 = 0x20; |
| 242 | |
| 243 | if(line0[x] < back) |
| 244 | { |
| 245 | back = line0[x]; |
| 246 | top2 = 0x01; |
| 247 | } |
| 248 | |
| 249 | if(line1[x] < (back & 0xff000000)) |
| 250 | { |
| 251 | back = line1[x]; |
| 252 | top2 = 0x02; |
| 253 | } |
| 254 | |
| 255 | if(line2[x] < (back & 0xff000000)) |
| 256 | { |
| 257 | back = line2[x]; |
| 258 | top2 = 0x04; |
| 259 | } |
| 260 | |
| 261 | if(line3[x] < (back & 0xff000000)) |
| 262 | { |
| 263 | back = line3[x]; |
| 264 | top2 = 0x08; |
| 265 | } |
| 266 | |
| 267 | if(lineOBJ[x] < (back & 0xff000000)) |
| 268 | { |
| 269 | back = lineOBJ[x]; |
| 270 | top2 = 0x10; |
| 271 | } |
| 272 | |
| 273 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 274 | { |
| 275 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 276 | } |
| 277 | else |
| 278 | { |
| 279 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 280 | { |
| 281 | case BLDCNT_SFX_LIGHTEN: |
| 282 | if(top & gba_state->BLDCNT) |
| 283 | { |
| 284 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 285 | } |
| 286 | break; |
| 287 | case BLDCNT_SFX_DARKEN: |
| 288 | if(top & gba_state->BLDCNT) |
| 289 | { |
| 290 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 291 | } |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | lineMix[x] = color; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void draw_mode0_scanline_all(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 301 | { |
| 302 | int x = 0; |
| 303 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 304 | int inWindow0 = 0; |
| 305 | int inWindow1 = 0; |
| 306 | UINT8 inWin0Mask = gba_state->WININ & 0x00ff; |
| 307 | UINT8 inWin1Mask = gba_state->WININ >> 8; |
| 308 | UINT8 outMask = gba_state->WINOUT & 0x00ff; |
| 309 | |
| 310 | if(gba_state->DISPCNT & DISPCNT_WIN0_EN) |
| 311 | { |
| 312 | UINT8 v0 = gba_state->WIN0V >> 8; |
| 313 | UINT8 v1 = gba_state->WIN0V & 0x00ff; |
| 314 | inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0; |
| 315 | if(v1 >= v0) |
| 316 | { |
| 317 | inWindow0 |= (y >= v0 && y < v1) ? 1 : 0; |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | inWindow0 |= (y >= v0 || y < v1) ? 1 : 0; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | if(gba_state->DISPCNT & DISPCNT_WIN1_EN) |
| 326 | { |
| 327 | UINT8 v0 = gba_state->WIN1V >> 8; |
| 328 | UINT8 v1 = gba_state->WIN1V & 0x00ff; |
| 329 | inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0; |
| 330 | if(v1 >= v0) |
| 331 | { |
| 332 | inWindow1 |= (y >= v0 && y < v1) ? 1 : 0; |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | inWindow1 |= (y >= v0 || y < v1) ? 1 : 0; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS); |
| 341 | draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS); |
| 342 | draw_bg_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS); |
| 343 | draw_bg_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS); |
| 344 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 345 | draw_gba_oam_window(gba_state, machine, lineOBJWin, y); |
| 346 | |
| 347 | for(x = 0; x < 240; x++) |
| 348 | { |
| 349 | UINT32 color = backdrop; |
| 350 | UINT8 top = 0x20; |
| 351 | UINT8 mask = outMask; |
| 352 | |
| 353 | if((lineOBJWin[x] & 0x80000000) == 0) |
| 354 | { |
| 355 | mask = gba_state->WINOUT >> 8; |
| 356 | } |
| 357 | |
| 358 | if(inWindow1) |
| 359 | { |
| 360 | if(is_in_window(gba_state, x, 1)) |
| 361 | { |
| 362 | mask = inWin1Mask; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | if(inWindow0) |
| 367 | { |
| 368 | if(is_in_window(gba_state, x, 0)) |
| 369 | { |
| 370 | mask = inWin0Mask; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | if((mask & 0x01) != 0 && (line0[x] < color)) |
| 375 | { |
| 376 | color = line0[x]; |
| 377 | top = 0x01; |
| 378 | } |
| 379 | |
| 380 | if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24))) |
| 381 | { |
| 382 | color = line1[x]; |
| 383 | top = 0x02; |
| 384 | } |
| 385 | |
| 386 | if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))) |
| 387 | { |
| 388 | color = line2[x]; |
| 389 | top = 0x04; |
| 390 | } |
| 391 | |
| 392 | if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24))) |
| 393 | { |
| 394 | color = line3[x]; |
| 395 | top = 0x08; |
| 396 | } |
| 397 | |
| 398 | if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))) |
| 399 | { |
| 400 | color = lineOBJ[x]; |
| 401 | top = 0x10; |
| 402 | } |
| 403 | |
| 404 | if((mask & 0x20) != 0) |
| 405 | { |
| 406 | if((color & 0x00010000) == 0) |
| 407 | { |
| 408 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 409 | { |
| 410 | case BLDCNT_SFX_NONE: |
| 411 | break; |
| 412 | case BLDCNT_SFX_ALPHA: |
| 413 | { |
| 414 | if(top & gba_state->BLDCNT) |
| 415 | { |
| 416 | UINT32 back = backdrop; |
| 417 | UINT8 top2 = 0x20; |
| 418 | if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))) |
| 419 | { |
| 420 | if(top != 0x01) |
| 421 | { |
| 422 | back = line0[x]; |
| 423 | top2 = 0x01; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))) |
| 428 | { |
| 429 | if(top != 0x02) |
| 430 | { |
| 431 | back = line1[x]; |
| 432 | top2 = 0x02; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))) |
| 437 | { |
| 438 | if(top != 0x04) |
| 439 | { |
| 440 | back = line2[x]; |
| 441 | top2 = 0x04; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))) |
| 446 | { |
| 447 | if(top != 0x08) |
| 448 | { |
| 449 | back = line3[x]; |
| 450 | top2 = 0x08; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))) |
| 455 | { |
| 456 | if(top != 0x10) |
| 457 | { |
| 458 | back = lineOBJ[x]; |
| 459 | top2 = 0x10; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 464 | { |
| 465 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 466 | } |
| 467 | } |
| 468 | break; |
| 469 | } |
| 470 | case BLDCNT_SFX_LIGHTEN: |
| 471 | if(top & gba_state->BLDCNT) |
| 472 | { |
| 473 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 474 | } |
| 475 | break; |
| 476 | case BLDCNT_SFX_DARKEN: |
| 477 | if(top & gba_state->BLDCNT) |
| 478 | { |
| 479 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 480 | } |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | else |
| 485 | { |
| 486 | UINT32 back = backdrop; |
| 487 | UINT8 top2 = 0x20; |
| 488 | |
| 489 | if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))) |
| 490 | { |
| 491 | back = line0[x]; |
| 492 | top2 = 0x01; |
| 493 | } |
| 494 | |
| 495 | if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))) |
| 496 | { |
| 497 | back = line1[x]; |
| 498 | top2 = 0x02; |
| 499 | } |
| 500 | |
| 501 | if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))) |
| 502 | { |
| 503 | back = line2[x]; |
| 504 | top2 = 0x04; |
| 505 | } |
| 506 | |
| 507 | if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))) |
| 508 | { |
| 509 | back = line3[x]; |
| 510 | top2 = 0x08; |
| 511 | } |
| 512 | |
| 513 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 514 | { |
| 515 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 516 | } |
| 517 | else |
| 518 | { |
| 519 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 520 | { |
| 521 | case BLDCNT_SFX_LIGHTEN: |
| 522 | if(top & gba_state->BLDCNT) |
| 523 | { |
| 524 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 525 | } |
| 526 | break; |
| 527 | case BLDCNT_SFX_DARKEN: |
| 528 | if(top & gba_state->BLDCNT) |
| 529 | { |
| 530 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 531 | } |
| 532 | break; |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | else if(color & 0x00010000) |
| 538 | { |
| 539 | UINT32 back = backdrop; |
| 540 | UINT8 top2 = 0x20; |
| 541 | |
| 542 | if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))) |
| 543 | { |
| 544 | back = line0[x]; |
| 545 | top2 = 0x01; |
| 546 | } |
| 547 | |
| 548 | if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))) |
| 549 | { |
| 550 | back = line1[x]; |
| 551 | top2 = 0x02; |
| 552 | } |
| 553 | |
| 554 | if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))) |
| 555 | { |
| 556 | back = line2[x]; |
| 557 | top2 = 0x04; |
| 558 | } |
| 559 | |
| 560 | if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))) |
| 561 | { |
| 562 | back = line3[x]; |
| 563 | top2 = 0x08; |
| 564 | } |
| 565 | |
| 566 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 567 | { |
| 568 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 573 | { |
| 574 | case BLDCNT_SFX_LIGHTEN: |
| 575 | if(top & gba_state->BLDCNT) |
| 576 | { |
| 577 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 578 | } |
| 579 | break; |
| 580 | case BLDCNT_SFX_DARKEN: |
| 581 | if(top & gba_state->BLDCNT) |
| 582 | { |
| 583 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 584 | } |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | lineMix[x] = color; |
| 590 | } |
| 591 | } |
src/mess/video/gbamode1.c
| r0 | r5698 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | gbamode1.c |
| 4 | |
| 5 | Handles GBA mode 1 screen rendering |
| 6 | |
| 7 | By R. Belmont & Harmony |
| 8 | |
| 9 | ***************************************************************************/ |
| 10 | |
| 11 | void draw_mode1_scanline(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 12 | { |
| 13 | int x = 0; |
| 14 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 15 | |
| 16 | draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS); |
| 17 | draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS); |
| 18 | draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed); |
| 19 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 20 | |
| 21 | for(x = 0; x < 240; x++) |
| 22 | { |
| 23 | UINT32 color = backdrop; |
| 24 | UINT8 top = 0x20; |
| 25 | |
| 26 | if(line0[x] < color) |
| 27 | { |
| 28 | color = line0[x]; |
| 29 | top = 0x01; |
| 30 | } |
| 31 | |
| 32 | if((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24)) |
| 33 | { |
| 34 | color = line1[x]; |
| 35 | top = 0x02; |
| 36 | } |
| 37 | |
| 38 | if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24)) |
| 39 | { |
| 40 | color = line2[x]; |
| 41 | top = 0x04; |
| 42 | } |
| 43 | |
| 44 | if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)) |
| 45 | { |
| 46 | color = lineOBJ[x]; |
| 47 | top = 0x10; |
| 48 | } |
| 49 | |
| 50 | if(top == 0x10 && (color & 0x00010000) != 0) |
| 51 | { |
| 52 | UINT32 back = backdrop; |
| 53 | UINT8 top2 = 0x20; |
| 54 | |
| 55 | if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)) |
| 56 | { |
| 57 | back = line0[x]; |
| 58 | top2 = 0x01; |
| 59 | } |
| 60 | |
| 61 | if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)) |
| 62 | { |
| 63 | back = line1[x]; |
| 64 | top2 = 0x02; |
| 65 | } |
| 66 | |
| 67 | if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)) |
| 68 | { |
| 69 | back = line2[x]; |
| 70 | top2 = 0x04; |
| 71 | } |
| 72 | |
| 73 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 74 | { |
| 75 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 80 | { |
| 81 | case BLDCNT_SFX_LIGHTEN: |
| 82 | if(top & gba_state->BLDCNT) |
| 83 | { |
| 84 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 85 | } |
| 86 | break; |
| 87 | case BLDCNT_SFX_DARKEN: |
| 88 | if(top & gba_state->BLDCNT) |
| 89 | { |
| 90 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 91 | } |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | lineMix[x] = color; |
| 98 | } |
| 99 | gba_state->gfxBG2Changed = 0; |
| 100 | } |
| 101 | |
| 102 | void draw_mode1_scanline_nowindow(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 103 | { |
| 104 | int x = 0; |
| 105 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 106 | int effect = gba_state->BLDCNT & BLDCNT_SFX; |
| 107 | |
| 108 | draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS); |
| 109 | draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS); |
| 110 | draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed); |
| 111 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 112 | |
| 113 | for(x = 0; x < 240; x++) |
| 114 | { |
| 115 | UINT32 color = backdrop; |
| 116 | UINT8 top = 0x20; |
| 117 | |
| 118 | if(line0[x] < color) |
| 119 | { |
| 120 | color = line0[x]; |
| 121 | top = 0x01; |
| 122 | } |
| 123 | |
| 124 | if(line1[x] < (color & 0xff000000)) |
| 125 | { |
| 126 | color = line1[x]; |
| 127 | top = 0x02; |
| 128 | } |
| 129 | |
| 130 | if(line2[x] < (color & 0xff000000)) |
| 131 | { |
| 132 | color = line2[x]; |
| 133 | top = 0x04; |
| 134 | } |
| 135 | |
| 136 | if(lineOBJ[x] < (color & 0xff000000)) |
| 137 | { |
| 138 | color = lineOBJ[x]; |
| 139 | top = 0x10; |
| 140 | } |
| 141 | |
| 142 | if((color & 0x00010000) == 0) |
| 143 | { |
| 144 | switch(effect) |
| 145 | { |
| 146 | case BLDCNT_SFX_NONE: |
| 147 | break; |
| 148 | case BLDCNT_SFX_ALPHA: |
| 149 | if(gba_state->BLDCNT & top) |
| 150 | { |
| 151 | UINT32 back = backdrop; |
| 152 | UINT8 top2 = 0x20; |
| 153 | |
| 154 | if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)) |
| 155 | { |
| 156 | if(top != 0x01) |
| 157 | { |
| 158 | back = line0[x]; |
| 159 | top2 = 0x01; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)) |
| 164 | { |
| 165 | if(top != 0x02) |
| 166 | { |
| 167 | back = line1[x]; |
| 168 | top2 = 0x02; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)) |
| 173 | { |
| 174 | if(top != 0x04) |
| 175 | { |
| 176 | back = line2[x]; |
| 177 | top2 = 0x04; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)) |
| 182 | { |
| 183 | if(top != 0x10) |
| 184 | { |
| 185 | back = lineOBJ[x]; |
| 186 | top2 = 0x10; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 191 | { |
| 192 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 193 | } |
| 194 | } |
| 195 | break; |
| 196 | case BLDCNT_SFX_LIGHTEN: |
| 197 | if(top & gba_state->BLDCNT) |
| 198 | { |
| 199 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 200 | } |
| 201 | break; |
| 202 | case BLDCNT_SFX_DARKEN: |
| 203 | if(top & gba_state->BLDCNT) |
| 204 | { |
| 205 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 206 | } |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | UINT32 back = backdrop; |
| 213 | UINT8 top2 = 0x20; |
| 214 | |
| 215 | if((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24)) |
| 216 | { |
| 217 | back = line0[x]; |
| 218 | top2 = 0x01; |
| 219 | } |
| 220 | |
| 221 | if((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24)) |
| 222 | { |
| 223 | back = line1[x]; |
| 224 | top2 = 0x02; |
| 225 | } |
| 226 | |
| 227 | if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)) |
| 228 | { |
| 229 | back = line2[x]; |
| 230 | top2 = 0x04; |
| 231 | } |
| 232 | |
| 233 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 234 | { |
| 235 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 240 | { |
| 241 | case BLDCNT_SFX_LIGHTEN: |
| 242 | if(top & gba_state->BLDCNT) |
| 243 | { |
| 244 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 245 | } |
| 246 | break; |
| 247 | case BLDCNT_SFX_DARKEN: |
| 248 | if(top & gba_state->BLDCNT) |
| 249 | { |
| 250 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 251 | } |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | lineMix[x] = color; |
| 257 | } |
| 258 | gba_state->gfxBG2Changed = 0; |
| 259 | } |
| 260 | |
| 261 | void draw_mode1_scanline_all(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 262 | { |
| 263 | int x = 0; |
| 264 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 265 | int inWindow0 = 0; |
| 266 | int inWindow1 = 0; |
| 267 | UINT8 inWin0Mask = gba_state->WININ & 0x00ff; |
| 268 | UINT8 inWin1Mask = gba_state->WININ >> 8; |
| 269 | UINT8 outMask = gba_state->WINOUT & 0x00ff; |
| 270 | |
| 271 | if(gba_state->DISPCNT & DISPCNT_WIN0_EN) |
| 272 | { |
| 273 | UINT8 v0 = gba_state->WIN0V >> 8; |
| 274 | UINT8 v1 = gba_state->WIN0V & 0x00ff; |
| 275 | inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0; |
| 276 | if(v1 >= v0) |
| 277 | { |
| 278 | inWindow0 |= (y >= v0 && y < v1) ? 1 : 0; |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | inWindow0 |= (y >= v0 || y < v1) ? 1 : 0; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if(gba_state->DISPCNT & DISPCNT_WIN1_EN) |
| 287 | { |
| 288 | UINT8 v0 = gba_state->WIN1V >> 8; |
| 289 | UINT8 v1 = gba_state->WIN1V & 0x00ff; |
| 290 | inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0; |
| 291 | if(v1 >= v0) |
| 292 | { |
| 293 | inWindow1 |= (y >= v0 && y < v1) ? 1 : 0; |
| 294 | } |
| 295 | else |
| 296 | { |
| 297 | inWindow1 |= (y >= v0 || y < v1) ? 1 : 0; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | draw_bg_scanline(gba_state, line0, y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS); |
| 302 | draw_bg_scanline(gba_state, line1, y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS); |
| 303 | draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed); |
| 304 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 305 | draw_gba_oam_window(gba_state, machine, lineOBJWin, y); |
| 306 | |
| 307 | for(x = 0; x < 240; x++) |
| 308 | { |
| 309 | UINT32 color = backdrop; |
| 310 | UINT8 top = 0x20; |
| 311 | UINT8 mask = outMask; |
| 312 | |
| 313 | if((lineOBJWin[x] & 0x80000000) == 0) |
| 314 | { |
| 315 | mask = gba_state->WINOUT >> 8; |
| 316 | } |
| 317 | |
| 318 | if(inWindow1) |
| 319 | { |
| 320 | if(is_in_window(gba_state, x, 1)) |
| 321 | { |
| 322 | mask = inWin1Mask; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if(inWindow0) |
| 327 | { |
| 328 | if(is_in_window(gba_state, x, 0)) |
| 329 | { |
| 330 | mask = inWin0Mask; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | if((mask & 0x01) != 0 && (line0[x] < color)) |
| 335 | { |
| 336 | color = line0[x]; |
| 337 | top = 0x01; |
| 338 | } |
| 339 | |
| 340 | if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(color >> 24))) |
| 341 | { |
| 342 | color = line1[x]; |
| 343 | top = 0x02; |
| 344 | } |
| 345 | |
| 346 | if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24))) |
| 347 | { |
| 348 | color = line2[x]; |
| 349 | top = 0x04; |
| 350 | } |
| 351 | |
| 352 | if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24))) |
| 353 | { |
| 354 | color = lineOBJ[x]; |
| 355 | top = 0x10; |
| 356 | } |
| 357 | |
| 358 | if((mask & 0x20) != 0) |
| 359 | { |
| 360 | if((color & 0x00010000) == 0) |
| 361 | { |
| 362 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 363 | { |
| 364 | case BLDCNT_SFX_NONE: |
| 365 | break; |
| 366 | case BLDCNT_SFX_ALPHA: |
| 367 | { |
| 368 | if(top & gba_state->BLDCNT) |
| 369 | { |
| 370 | UINT32 back = backdrop; |
| 371 | UINT8 top2 = 0x20; |
| 372 | if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))) |
| 373 | { |
| 374 | if(top != 0x01) |
| 375 | { |
| 376 | back = line0[x]; |
| 377 | top2 = 0x01; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))) |
| 382 | { |
| 383 | if(top != 0x02) |
| 384 | { |
| 385 | back = line1[x]; |
| 386 | top2 = 0x02; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))) |
| 391 | { |
| 392 | if(top != 0x04) |
| 393 | { |
| 394 | back = line2[x]; |
| 395 | top2 = 0x04; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))) |
| 400 | { |
| 401 | if(top != 0x10) |
| 402 | { |
| 403 | back = lineOBJ[x]; |
| 404 | top2 = 0x10; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 409 | { |
| 410 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 411 | } |
| 412 | } |
| 413 | break; |
| 414 | } |
| 415 | case BLDCNT_SFX_LIGHTEN: |
| 416 | if(top & gba_state->BLDCNT) |
| 417 | { |
| 418 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 419 | } |
| 420 | break; |
| 421 | case BLDCNT_SFX_DARKEN: |
| 422 | if(top & gba_state->BLDCNT) |
| 423 | { |
| 424 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 425 | } |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | UINT32 back = backdrop; |
| 432 | UINT8 top2 = 0x20; |
| 433 | |
| 434 | if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))) |
| 435 | { |
| 436 | back = line0[x]; |
| 437 | top2 = 0x01; |
| 438 | } |
| 439 | |
| 440 | if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))) |
| 441 | { |
| 442 | back = line1[x]; |
| 443 | top2 = 0x02; |
| 444 | } |
| 445 | |
| 446 | if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))) |
| 447 | { |
| 448 | back = line2[x]; |
| 449 | top2 = 0x04; |
| 450 | } |
| 451 | |
| 452 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 453 | { |
| 454 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 459 | { |
| 460 | case BLDCNT_SFX_LIGHTEN: |
| 461 | if(top & gba_state->BLDCNT) |
| 462 | { |
| 463 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 464 | } |
| 465 | break; |
| 466 | case BLDCNT_SFX_DARKEN: |
| 467 | if(top & gba_state->BLDCNT) |
| 468 | { |
| 469 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 470 | } |
| 471 | break; |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | else if(color & 0x00010000) |
| 477 | { |
| 478 | UINT32 back = backdrop; |
| 479 | UINT8 top2 = 0x20; |
| 480 | |
| 481 | if((mask & 0x01) != 0 && ((UINT8)(line0[x] >> 24) < (UINT8)(back >> 24))) |
| 482 | { |
| 483 | back = line0[x]; |
| 484 | top2 = 0x01; |
| 485 | } |
| 486 | |
| 487 | if((mask & 0x02) != 0 && ((UINT8)(line1[x] >> 24) < (UINT8)(back >> 24))) |
| 488 | { |
| 489 | back = line1[x]; |
| 490 | top2 = 0x02; |
| 491 | } |
| 492 | |
| 493 | if((mask & 0x04) != 0 && ((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24))) |
| 494 | { |
| 495 | back = line2[x]; |
| 496 | top2 = 0x04; |
| 497 | } |
| 498 | |
| 499 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 500 | { |
| 501 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 506 | { |
| 507 | case BLDCNT_SFX_LIGHTEN: |
| 508 | if(top & gba_state->BLDCNT) |
| 509 | { |
| 510 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 511 | } |
| 512 | break; |
| 513 | case BLDCNT_SFX_DARKEN: |
| 514 | if(top & gba_state->BLDCNT) |
| 515 | { |
| 516 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 517 | } |
| 518 | break; |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | lineMix[x] = color; |
| 523 | } |
| 524 | gba_state->gfxBG2Changed = 0; |
| 525 | } |
src/mess/video/gbamode2.c
| r0 | r5698 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | gbamode2.c |
| 4 | |
| 5 | Handles GBA mode 2 screen rendering |
| 6 | |
| 7 | By R. Belmont & Harmony |
| 8 | |
| 9 | ***************************************************************************/ |
| 10 | |
| 11 | void draw_mode2_scanline(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 12 | { |
| 13 | int x = 0; |
| 14 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 15 | |
| 16 | draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed); |
| 17 | draw_roz_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3X, gba_state->BG3Y, gba_state->BG3PA, gba_state->BG3PB, gba_state->BG3PC, gba_state->BG3PD, &gba_state->gfxBG3X, &gba_state->gfxBG3Y, gba_state->gfxBG3Changed); |
| 18 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 19 | |
| 20 | for(x = 0; x < 240; x++) |
| 21 | { |
| 22 | UINT32 color = backdrop; |
| 23 | UINT8 top = 0x20; |
| 24 | |
| 25 | if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24)) |
| 26 | { |
| 27 | color = line2[x]; |
| 28 | top = 0x04; |
| 29 | } |
| 30 | |
| 31 | if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24)) |
| 32 | { |
| 33 | color = line3[x]; |
| 34 | top = 0x08; |
| 35 | } |
| 36 | |
| 37 | if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)) |
| 38 | { |
| 39 | color = lineOBJ[x]; |
| 40 | top = 0x10; |
| 41 | } |
| 42 | |
| 43 | if(top == 0x10 && (color & 0x00010000) != 0) |
| 44 | { |
| 45 | UINT32 back = backdrop; |
| 46 | UINT8 top2 = 0x20; |
| 47 | |
| 48 | if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)) |
| 49 | { |
| 50 | back = line2[x]; |
| 51 | top2 = 0x04; |
| 52 | } |
| 53 | |
| 54 | if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)) |
| 55 | { |
| 56 | back = line3[x]; |
| 57 | top2 = 0x08; |
| 58 | } |
| 59 | |
| 60 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 61 | { |
| 62 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 67 | { |
| 68 | case BLDCNT_SFX_LIGHTEN: |
| 69 | if(top & gba_state->BLDCNT) |
| 70 | { |
| 71 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 72 | } |
| 73 | break; |
| 74 | case BLDCNT_SFX_DARKEN: |
| 75 | if(top & gba_state->BLDCNT) |
| 76 | { |
| 77 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 78 | } |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | lineMix[x] = color; |
| 85 | } |
| 86 | gba_state->gfxBG2Changed = 0; |
| 87 | gba_state->gfxBG3Changed = 0; |
| 88 | } |
| 89 | |
| 90 | void draw_mode2_scanline_nowindow(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 91 | { |
| 92 | int x = 0; |
| 93 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 94 | int effect = gba_state->BLDCNT & BLDCNT_SFX; |
| 95 | |
| 96 | draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed); |
| 97 | draw_roz_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3X, gba_state->BG3Y, gba_state->BG3PA, gba_state->BG3PB, gba_state->BG3PC, gba_state->BG3PD, &gba_state->gfxBG3X, &gba_state->gfxBG3Y, gba_state->gfxBG3Changed); |
| 98 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 99 | |
| 100 | for(x = 0; x < 240; x++) |
| 101 | { |
| 102 | UINT32 color = backdrop; |
| 103 | UINT8 top = 0x20; |
| 104 | |
| 105 | if((UINT8)(line2[x] >> 24) < (UINT8)(color >> 24)) |
| 106 | { |
| 107 | color = line2[x]; |
| 108 | top = 0x04; |
| 109 | } |
| 110 | |
| 111 | if((UINT8)(line3[x] >> 24) < (UINT8)(color >> 24)) |
| 112 | { |
| 113 | color = line3[x]; |
| 114 | top = 0x08; |
| 115 | } |
| 116 | |
| 117 | if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)) |
| 118 | { |
| 119 | color = lineOBJ[x]; |
| 120 | top = 0x10; |
| 121 | } |
| 122 | |
| 123 | if((color & 0x00010000) == 0) |
| 124 | { |
| 125 | switch(effect) |
| 126 | { |
| 127 | case BLDCNT_SFX_NONE: |
| 128 | break; |
| 129 | case BLDCNT_SFX_ALPHA: |
| 130 | if(gba_state->BLDCNT & top) |
| 131 | { |
| 132 | UINT32 back = backdrop; |
| 133 | UINT8 top2 = 0x20; |
| 134 | |
| 135 | if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)) |
| 136 | { |
| 137 | if(top != 0x04) |
| 138 | { |
| 139 | back = line2[x]; |
| 140 | top2 = 0x04; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)) |
| 145 | { |
| 146 | if(top != 0x08) |
| 147 | { |
| 148 | back = line3[x]; |
| 149 | top2 = 0x08; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | if((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24)) |
| 154 | { |
| 155 | if(top != 0x10) |
| 156 | { |
| 157 | back = lineOBJ[x]; |
| 158 | top2 = 0x10; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 163 | { |
| 164 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 165 | } |
| 166 | } |
| 167 | break; |
| 168 | case BLDCNT_SFX_LIGHTEN: |
| 169 | if(top & gba_state->BLDCNT) |
| 170 | { |
| 171 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 172 | } |
| 173 | break; |
| 174 | case BLDCNT_SFX_DARKEN: |
| 175 | if(top & gba_state->BLDCNT) |
| 176 | { |
| 177 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 178 | } |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | UINT32 back = backdrop; |
| 185 | UINT8 top2 = 0x20; |
| 186 | |
| 187 | if((UINT8)(line2[x] >> 24) < (UINT8)(back >> 24)) |
| 188 | { |
| 189 | back = line2[x]; |
| 190 | top2 = 0x04; |
| 191 | } |
| 192 | |
| 193 | if((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24)) |
| 194 | { |
| 195 | back = line3[x]; |
| 196 | top2 = 0x08; |
| 197 | } |
| 198 | |
| 199 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 200 | { |
| 201 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 206 | { |
| 207 | case BLDCNT_SFX_LIGHTEN: |
| 208 | if(top & gba_state->BLDCNT) |
| 209 | { |
| 210 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 211 | } |
| 212 | break; |
| 213 | case BLDCNT_SFX_DARKEN: |
| 214 | if(top & gba_state->BLDCNT) |
| 215 | { |
| 216 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 217 | } |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | lineMix[x] = color; |
| 223 | } |
| 224 | gba_state->gfxBG2Changed = 0; |
| 225 | gba_state->gfxBG3Changed = 0; |
| 226 | } |
| 227 | |
| 228 | void draw_mode2_scanline_all(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int bpp) |
| 229 | { |
| 230 | int x = 0; |
| 231 | UINT32 backdrop = gba_state->gba_pram[0] | 0x30000000; |
| 232 | int inWindow0 = 0; |
| 233 | int inWindow1 = 0; |
| 234 | UINT8 inWin0Mask = gba_state->WININ & 0x00ff; |
| 235 | UINT8 inWin1Mask = gba_state->WININ >> 8; |
| 236 | UINT8 outMask = gba_state->WINOUT & 0x00ff; |
| 237 | |
| 238 | if(gba_state->DISPCNT & DISPCNT_WIN0_EN) |
| 239 | { |
| 240 | UINT8 v0 = gba_state->WIN0V >> 8; |
| 241 | UINT8 v1 = gba_state->WIN0V & 0x00ff; |
| 242 | inWindow0 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0; |
| 243 | if(v1 >= v0) |
| 244 | { |
| 245 | inWindow0 |= (y >= v0 && y < v1) ? 1 : 0; |
| 246 | } |
| 247 | else |
| 248 | { |
| 249 | inWindow0 |= (y >= v0 || y < v1) ? 1 : 0; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | if(gba_state->DISPCNT & DISPCNT_WIN1_EN) |
| 254 | { |
| 255 | UINT8 v0 = gba_state->WIN1V >> 8; |
| 256 | UINT8 v1 = gba_state->WIN1V & 0x00ff; |
| 257 | inWindow1 = ((v0 == v1) && (v0 >= 0xe8)) ? 1 : 0; |
| 258 | if(v1 >= v0) |
| 259 | { |
| 260 | inWindow1 |= (y >= v0 && y < v1) ? 1 : 0; |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | inWindow1 |= (y >= v0 || y < v1) ? 1 : 0; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | draw_roz_scanline(gba_state, line2, y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, &gba_state->gfxBG2X, &gba_state->gfxBG2Y, gba_state->gfxBG2Changed); |
| 269 | draw_roz_scanline(gba_state, line3, y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3X, gba_state->BG3Y, gba_state->BG3PA, gba_state->BG3PB, gba_state->BG3PC, gba_state->BG3PD, &gba_state->gfxBG3X, &gba_state->gfxBG3Y, gba_state->gfxBG3Changed); |
| 270 | draw_gba_oam(gba_state, machine, lineOBJ, y); |
| 271 | draw_gba_oam_window(gba_state, machine, lineOBJWin, y); |
| 272 | |
| 273 | for(x = 0; x < 240; x++) |
| 274 | { |
| 275 | UINT32 color = backdrop; |
| 276 | UINT8 top = 0x20; |
| 277 | UINT8 mask = outMask; |
| 278 | |
| 279 | if((lineOBJWin[x] & 0x80000000) == 0) |
| 280 | { |
| 281 | mask = gba_state->WINOUT >> 8; |
| 282 | } |
| 283 | |
| 284 | if(inWindow1) |
| 285 | { |
| 286 | if(is_in_window(gba_state, x, 1)) |
| 287 | { |
| 288 | mask = inWin1Mask; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | if(inWindow0) |
| 293 | { |
| 294 | if(is_in_window(gba_state, x, 0)) |
| 295 | { |
| 296 | mask = inWin0Mask; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | if((mask & 0x04) != 0 && (line2[x] < color)) |
| 301 | { |
| 302 | color = line2[x]; |
| 303 | top = 0x04; |
| 304 | } |
| 305 | |
| 306 | if((mask & 0x08) != 0 && (UINT8)(line3[x] >> 24) < (UINT8)(color >> 24)) |
| 307 | { |
| 308 | color = line3[x]; |
| 309 | top = 0x08; |
| 310 | } |
| 311 | |
| 312 | if((mask & 0x10) != 0 && (UINT8)(lineOBJ[x] >> 24) < (UINT8)(color >> 24)) |
| 313 | { |
| 314 | color = lineOBJ[x]; |
| 315 | top = 0x10; |
| 316 | } |
| 317 | |
| 318 | if((mask & 0x20) != 0) |
| 319 | { |
| 320 | if((color & 0x00010000) == 0) |
| 321 | { |
| 322 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 323 | { |
| 324 | case BLDCNT_SFX_NONE: |
| 325 | break; |
| 326 | case BLDCNT_SFX_ALPHA: |
| 327 | { |
| 328 | if(top & gba_state->BLDCNT) |
| 329 | { |
| 330 | UINT32 back = backdrop; |
| 331 | UINT8 top2 = 0x20; |
| 332 | if((mask & 0x04) != 0 && (line2[x] < back)) |
| 333 | { |
| 334 | if(top != 0x04) |
| 335 | { |
| 336 | back = line2[x]; |
| 337 | top2 = 0x04; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))) |
| 342 | { |
| 343 | if(top != 0x08) |
| 344 | { |
| 345 | back = line3[x]; |
| 346 | top2 = 0x08; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | if((mask & 0x10) != 0 && ((UINT8)(lineOBJ[x] >> 24) < (UINT8)(back >> 24))) |
| 351 | { |
| 352 | if(top != 0x10) |
| 353 | { |
| 354 | back = lineOBJ[x]; |
| 355 | top2 = 0x10; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 360 | { |
| 361 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 362 | } |
| 363 | } |
| 364 | break; |
| 365 | } |
| 366 | case BLDCNT_SFX_LIGHTEN: |
| 367 | if(top & gba_state->BLDCNT) |
| 368 | { |
| 369 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 370 | } |
| 371 | break; |
| 372 | case BLDCNT_SFX_DARKEN: |
| 373 | if(top & gba_state->BLDCNT) |
| 374 | { |
| 375 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 376 | } |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | UINT32 back = backdrop; |
| 383 | UINT8 top2 = 0x20; |
| 384 | |
| 385 | if((mask & 0x04) != 0 && (line2[x] < back)) |
| 386 | { |
| 387 | back = line2[x]; |
| 388 | top2 = 0x04; |
| 389 | } |
| 390 | |
| 391 | if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))) |
| 392 | { |
| 393 | back = line3[x]; |
| 394 | top2 = 0x08; |
| 395 | } |
| 396 | |
| 397 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 398 | { |
| 399 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 404 | { |
| 405 | case BLDCNT_SFX_LIGHTEN: |
| 406 | if(top & gba_state->BLDCNT) |
| 407 | { |
| 408 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 409 | } |
| 410 | break; |
| 411 | case BLDCNT_SFX_DARKEN: |
| 412 | if(top & gba_state->BLDCNT) |
| 413 | { |
| 414 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 415 | } |
| 416 | break; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | else if(color & 0x00010000) |
| 422 | { |
| 423 | UINT32 back = backdrop; |
| 424 | UINT8 top2 = 0x20; |
| 425 | |
| 426 | if((mask & 0x04) != 0 && (line2[x] < back )) |
| 427 | { |
| 428 | back = line2[x]; |
| 429 | top2 = 0x04; |
| 430 | } |
| 431 | |
| 432 | if((mask & 0x08) != 0 && ((UINT8)(line3[x] >> 24) < (UINT8)(back >> 24))) |
| 433 | { |
| 434 | back = line3[x]; |
| 435 | top2 = 0x08; |
| 436 | } |
| 437 | |
| 438 | if(top2 & (gba_state->BLDCNT >> BLDCNT_TP2_SHIFT)) |
| 439 | { |
| 440 | color = alpha_blend_pixel(color, back, coeff[gba_state->BLDALPHA & 0x1f], coeff[(gba_state->BLDALPHA >> 8) & 0x1f]); |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | switch(gba_state->BLDCNT & BLDCNT_SFX) |
| 445 | { |
| 446 | case BLDCNT_SFX_LIGHTEN: |
| 447 | if(top & gba_state->BLDCNT) |
| 448 | { |
| 449 | color = increase_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 450 | } |
| 451 | break; |
| 452 | case BLDCNT_SFX_DARKEN: |
| 453 | if(top & gba_state->BLDCNT) |
| 454 | { |
| 455 | color = decrease_brightness(color, coeff[gba_state->BLDY & 0x1f]); |
| 456 | } |
| 457 | break; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | lineMix[x] = color; |
| 462 | } |
| 463 | gba_state->gfxBG2Changed = 0; |
| 464 | gba_state->gfxBG3Changed = 0; |
| 465 | } |
src/mess/video/gba.c
| r5697 | r5698 | |
| 1 | | /*************************************************************************** |
| 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | 3 | gba.c |
| 4 | 4 | |
| 5 | 5 | File to handle emulation of the video hardware of the Game Boy Advance |
| 6 | 6 | |
| 7 | | By R. Belmont & MooglyGuy |
| 7 | By R. Belmont & Harmony |
| 8 | 8 | |
| 9 | 9 | ***************************************************************************/ |
| 10 | 10 | |
| r5697 | r5698 | |
| 15 | 15 | #define VERBOSE_LEVEL (0) |
| 16 | 16 | #define DISABLE_ROZ (0) |
| 17 | 17 | |
| 18 | | static UINT16 mosaic_offset[16][4096]; |
| 19 | | |
| 20 | 18 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| 21 | 19 | { |
| 22 | 20 | if( VERBOSE_LEVEL >= n_level ) |
| r5697 | r5698 | |
| 26 | 24 | va_start( v, s_fmt ); |
| 27 | 25 | vsprintf( buf, s_fmt, v ); |
| 28 | 26 | va_end( v ); |
| 29 | | logerror( "%08x: %s", cpu_get_pc(machine->firstcpu), buf ); |
| 27 | logerror( "%08x: %s", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), buf ); |
| 30 | 28 | } |
| 31 | 29 | } |
| 32 | 30 | |
| 33 | | static void draw_4bpp_tile(gba_state *gba_state, UINT16 *scanline, UINT32 gba_vrambase, UINT16 tilenum, int scnx, int tiley, int vflip, int hflip, int pal, int mosX) |
| 31 | static UINT16 mosaic_offset[16][4096]; |
| 32 | static int coeff[32] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 33 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 }; |
| 34 | |
| 35 | /* Drawing functions */ |
| 36 | static void draw_roz_bitmap_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed, int depth); |
| 37 | static void draw_roz_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed); |
| 38 | static void draw_bg_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs); |
| 39 | static void draw_gba_oam_window(gba_state *gba_state, running_machine *machine, UINT32 *scanline, int y); |
| 40 | static void draw_gba_oam(gba_state *gba_state, running_machine *machine, UINT32 *scanline, int y); |
| 41 | static void invalid_gba_draw_function(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux); |
| 42 | |
| 43 | /* Utility functions */ |
| 44 | INLINE int is_in_window(gba_state *gba_state, int x, int window); |
| 45 | INLINE UINT32 alpha_blend_pixel(UINT32 color0, UINT32 color1, int ca, int cb); |
| 46 | INLINE UINT32 increase_brightness(UINT32 color, int coeff); |
| 47 | INLINE UINT32 decrease_brightness(UINT32 color, int coeff); |
| 48 | |
| 49 | #include "gbamode0.c" |
| 50 | #include "gbamode1.c" |
| 51 | #include "gbamode2.c" |
| 52 | #include "gbam345.c" |
| 53 | |
| 54 | void (*gba_draw_scanline_modes[8][3])(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux) = |
| 34 | 55 | { |
| 35 | | int pixx, yofs; |
| 36 | | UINT8 *pgba_vram = (UINT8 *)&gba_state->gba_vram[gba_vrambase>>2], pixel; |
| 37 | | UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram; |
| 56 | /* All modes have three sub-modes: No effects, effects, and windowed effects. */ |
| 57 | { /* Mode 0: 4 non-rotatable tilemaps and 1 OAM layer */ |
| 58 | &draw_mode0_scanline, |
| 59 | &draw_mode0_scanline_nowindow, |
| 60 | &draw_mode0_scanline_all |
| 61 | }, |
| 62 | { /* Mode 1: 2 non-rotatable tilemaps, 1 rotozoomable tilemap, and 1 OAM layer */ |
| 63 | &draw_mode1_scanline, |
| 64 | &draw_mode1_scanline_nowindow, |
| 65 | &draw_mode1_scanline_all |
| 66 | }, |
| 67 | { /* Mode 2: 2 rotozoomable tilemaps, and 1 OAM layer */ |
| 68 | &draw_mode2_scanline, |
| 69 | &draw_mode2_scanline_nowindow, |
| 70 | &draw_mode2_scanline_all |
| 71 | }, |
| 72 | { /* Mode 3: 1 rotatable 8bpp bitmap and one OAM layer */ |
| 73 | &draw_roz_bitmap_mode_scanline, |
| 74 | &draw_roz_bitmap_mode_scanline_nowindow, |
| 75 | &draw_roz_bitmap_mode_scanline_all |
| 76 | }, |
| 77 | { /* Mode 4: 1 rotatable 16bpp bitmap and one OAM layer */ |
| 78 | &draw_roz_bitmap_mode_scanline, |
| 79 | &draw_roz_bitmap_mode_scanline_nowindow, |
| 80 | &draw_roz_bitmap_mode_scanline_all |
| 81 | }, |
| 82 | { /* Mode 5: 1 rotatable 4bpp bitmap and one OAM layer */ |
| 83 | &draw_roz_bitmap_mode_scanline, |
| 84 | &draw_roz_bitmap_mode_scanline_nowindow, |
| 85 | &draw_roz_bitmap_mode_scanline_all |
| 86 | }, |
| 87 | { |
| 88 | &invalid_gba_draw_function, |
| 89 | &invalid_gba_draw_function, |
| 90 | &invalid_gba_draw_function, |
| 91 | }, |
| 92 | { |
| 93 | &invalid_gba_draw_function, |
| 94 | &invalid_gba_draw_function, |
| 95 | &invalid_gba_draw_function, |
| 96 | }, |
| 97 | }; |
| 38 | 98 | |
| 39 | | if (vflip) |
| 99 | static void invalid_gba_draw_function(running_machine *machine, gba_state *gba_state, int y, UINT32* line0, UINT32* line1, UINT32* line2, UINT32* line3, UINT32* lineOBJ, UINT32* lineOBJWin, UINT32* lineMix, int aux) |
| 100 | { |
| 101 | fatalerror( "Invalid screen mode (6 or 7)!\n" ); |
| 102 | } |
| 103 | |
| 104 | static void draw_roz_bitmap_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed, int depth) |
| 105 | { |
| 106 | UINT8 *src8 = (UINT8 *)gba_state->gba_vram; |
| 107 | UINT16 *src16 = (UINT16 *)gba_state->gba_vram; |
| 108 | UINT16 *palette = (UINT16 *)gba_state->gba_pram; |
| 109 | INT32 sx = 240; |
| 110 | INT32 sy = 160; |
| 111 | UINT32 prio = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000; |
| 112 | INT32 dx, dmx, dy, dmy, startx, starty; |
| 113 | INT32 rx, ry, pixx, pixy, x; |
| 114 | |
| 115 | if(depth == 8) |
| 40 | 116 | { |
| 41 | | yofs = 28-(tiley*4); |
| 117 | if(gba_state->DISPCNT & DISPCNT_FRAMESEL) |
| 118 | { |
| 119 | src8 += 0xa000; |
| 120 | } |
| 42 | 121 | } |
| 43 | | else |
| 122 | |
| 123 | // sign extend roz parameters |
| 124 | if (X & 0x08000000) X |= 0xf0000000; |
| 125 | if (Y & 0x08000000) Y |= 0xf0000000; |
| 126 | if (PA & 0x8000) PA |= 0xffff0000; |
| 127 | if (PB & 0x8000) PB |= 0xffff0000; |
| 128 | if (PC & 0x8000) PC |= 0xffff0000; |
| 129 | if (PD & 0x8000) PD |= 0xffff0000; |
| 130 | |
| 131 | // re-assign parameters for convenience's sake |
| 132 | dx = PA; |
| 133 | dmx = PB; |
| 134 | dy = PC; |
| 135 | dmy = PD; |
| 136 | startx = X; |
| 137 | starty = Y; |
| 138 | |
| 139 | if(ypos == 0) |
| 44 | 140 | { |
| 45 | | yofs = tiley*4; |
| 141 | changed = 3; |
| 46 | 142 | } |
| 47 | 143 | |
| 48 | | if (hflip) |
| 144 | if(changed & 1) |
| 49 | 145 | { |
| 50 | | for (pixx = 0; pixx < 8; pixx+= 2) |
| 51 | | { |
| 52 | | pixel = pgba_vram[(tilenum*32)+(3-(pixx/2))+yofs]; |
| 53 | | |
| 54 | | if (pixel & 0xf0) |
| 55 | | { |
| 56 | | scanline[scnx+pixx] = pgba_pram[(pixel>>4)+pal]&0x7fff; |
| 57 | | } |
| 58 | | if (pixel & 0x0f) |
| 59 | | { |
| 60 | | scanline[scnx+pixx+1] = pgba_pram[(pixel&0xf)+pal]&0x7fff; |
| 61 | | } |
| 62 | | } |
| 146 | *currentx = startx; |
| 63 | 147 | } |
| 64 | 148 | else |
| 65 | 149 | { |
| 66 | | for (pixx = 0; pixx < 8; pixx+= 2) |
| 67 | | { |
| 68 | | pixel = pgba_vram[(tilenum*32)+(pixx/2)+yofs]; |
| 69 | | |
| 70 | | if (pixel & 0x0f) |
| 71 | | { |
| 72 | | scanline[scnx+pixx] = pgba_pram[(pixel&0xf)+pal]&0x7fff; |
| 73 | | } |
| 74 | | if (pixel & 0xf0) |
| 75 | | { |
| 76 | | scanline[scnx+pixx+1] = pgba_pram[(pixel>>4)+pal]&0x7fff; |
| 77 | | } |
| 78 | | } |
| 150 | *currentx += dmx; |
| 79 | 151 | } |
| 80 | | } |
| 81 | 152 | |
| 82 | | static void draw_8bpp_tile(gba_state *gba_state, UINT16 *scanline, UINT32 gba_vrambase, UINT16 tilenum, int scnx, int tiley, int vflip, int hflip, int pal, int mosX) |
| 83 | | { |
| 84 | | int pixx, yofs; |
| 85 | | UINT8 *pgba_vram = (UINT8 *)&gba_state->gba_vram[gba_vrambase>>2], pixel; |
| 86 | | UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram; |
| 87 | | |
| 88 | | if (vflip) |
| 153 | if(changed & 2) |
| 89 | 154 | { |
| 90 | | yofs = 56-(tiley*8); |
| 155 | *currenty = starty; |
| 91 | 156 | } |
| 92 | 157 | else |
| 93 | 158 | { |
| 94 | | yofs = tiley*8; |
| 159 | *currenty += dmy; |
| 95 | 160 | } |
| 96 | 161 | |
| 97 | | if (hflip) |
| 162 | rx = *currentx; |
| 163 | ry = *currenty; |
| 164 | |
| 165 | if(ctrl & BGCNT_MOSAIC) |
| 98 | 166 | { |
| 99 | | for (pixx = 0; pixx < 8; pixx++) |
| 167 | INT32 mosaic_line = ((gba_state->MOSAIC & 0x00f0) >> 4) + 1; |
| 168 | INT32 tempy = (ypos / mosaic_line) * mosaic_line; |
| 169 | rx = startx + tempy*dmx; |
| 170 | ry = starty + tempy*dmy; |
| 171 | } |
| 172 | |
| 173 | pixx = rx >> 8; |
| 174 | pixy = ry >> 8; |
| 175 | |
| 176 | for(x = 0; x < 240; x++) |
| 177 | { |
| 178 | if(pixx < 0 || pixy < 0 || pixx >= sx || pixy >= sy) |
| 100 | 179 | { |
| 101 | | pixel = pgba_vram[(tilenum*32)+(7-pixx)+yofs]; |
| 180 | scanline[x] = 0x80000000; |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | if(depth == 8) |
| 185 | { |
| 186 | UINT8 color = src8[pixy*sx + pixx]; |
| 102 | 187 | |
| 103 | | if (pixel) |
| 188 | if(color) |
| 189 | { |
| 190 | scanline[x] = palette[color] | prio; |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | scanline[x] = 0x80000000; |
| 195 | } |
| 196 | } |
| 197 | else if(depth == 16) |
| 104 | 198 | { |
| 105 | | scanline[scnx+pixx] = pgba_pram[pixel+pal]&0x7fff; |
| 199 | scanline[x] = src16[pixy*sx + pixx] | prio; |
| 106 | 200 | } |
| 107 | 201 | } |
| 202 | |
| 203 | rx += dx; |
| 204 | ry += dy; |
| 205 | |
| 206 | pixx = rx >> 8; |
| 207 | pixy = ry >> 8; |
| 108 | 208 | } |
| 109 | | else |
| 209 | |
| 210 | if(ctrl & BGCNT_MOSAIC) |
| 110 | 211 | { |
| 111 | | for (pixx = 0; pixx < 8; pixx++) |
| 212 | INT32 mosaicx = (gba_state->MOSAIC & 0x0f) + 1; |
| 213 | if(mosaicx > 1) |
| 112 | 214 | { |
| 113 | | pixel = pgba_vram[(tilenum*32)+pixx+yofs]; |
| 114 | | |
| 115 | | if (pixel) |
| 215 | INT32 m = 1; |
| 216 | for(x = 0; x < 239; x++) |
| 116 | 217 | { |
| 117 | | scanline[scnx+pixx] = pgba_pram[pixel+pal]&0x7fff; |
| 218 | scanline[x+1] = scanline[x]; |
| 219 | m++; |
| 220 | if(m == mosaicx) |
| 221 | { |
| 222 | m = 1; |
| 223 | x++; |
| 224 | } |
| 118 | 225 | } |
| 119 | 226 | } |
| 120 | 227 | } |
| 121 | 228 | } |
| 122 | 229 | |
| 123 | | static void draw_roz_scanline(gba_state *gba_state, UINT16 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, int priority) |
| 230 | static void draw_roz_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed) |
| 124 | 231 | { |
| 125 | | UINT32 base, mapbase, size, ovr; |
| 232 | UINT32 base, mapbase, size; |
| 126 | 233 | INT32 sizes[4] = { 128, 256, 512, 1024 }; |
| 127 | | INT32 cx, cy, x, ax, ay; |
| 128 | | UINT8 *mgba_vram = (UINT8 *)gba_state->gba_vram, tile; |
| 234 | INT32 cx, cy, x, pixx, pixy; |
| 235 | UINT8 *mgba_vram = (UINT8 *)gba_state->gba_vram; |
| 236 | UINT32 tile; |
| 129 | 237 | UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram; |
| 130 | 238 | UINT16 pixel; |
| 239 | UINT32 prio = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000; |
| 131 | 240 | |
| 132 | | if ((gba_state->DISPCNT & enablemask) && ((ctrl & 3) == priority)) |
| 241 | for(x = 0; x < 240; x++) |
| 133 | 242 | { |
| 243 | scanline[x] = 0x80000000; |
| 244 | } |
| 245 | |
| 246 | if (gba_state->DISPCNT & enablemask) |
| 247 | { |
| 134 | 248 | base = ((ctrl & BGCNT_CHARBASE) >> BGCNT_CHARBASE_SHIFT) * 0x4000; // VRAM base of tiles |
| 135 | 249 | mapbase = ((ctrl & BGCNT_SCREENBASE) >> BGCNT_SCREENBASE_SHIFT) * 0x800; // VRAM base of map |
| 136 | 250 | size = (ctrl & BGCNT_SCREENSIZE) >> BGCNT_SCREENSIZE_SHIFT; // size of map in submaps |
| 137 | | ovr = ctrl & BGCNT_PALETTESET_WRAP; |
| 138 | 251 | |
| 139 | 252 | // sign extend roz parameters |
| 140 | 253 | if (X & 0x08000000) X |= 0xf0000000; |
| r5697 | r5698 | |
| 144 | 257 | if (PC & 0x8000) PC |= 0xffff0000; |
| 145 | 258 | if (PD & 0x8000) PD |= 0xffff0000; |
| 146 | 259 | |
| 147 | | cx = X; |
| 148 | | cy = Y; |
| 260 | if(ypos == 0) |
| 261 | { |
| 262 | changed = 3; |
| 263 | } |
| 149 | 264 | |
| 150 | | cx += ypos * PB; |
| 151 | | cy += ypos * PD; |
| 265 | if(changed & 1) |
| 266 | { |
| 267 | *currentx = X; |
| 268 | } |
| 269 | else |
| 270 | { |
| 271 | *currentx += PB; |
| 272 | } |
| 152 | 273 | |
| 274 | if(changed & 2) |
| 275 | { |
| 276 | *currenty = Y; |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | *currenty += PD; |
| 281 | } |
| 282 | |
| 283 | cx = *currentx; |
| 284 | cy = *currenty; |
| 285 | |
| 153 | 286 | if(ctrl & BGCNT_MOSAIC) |
| 154 | 287 | { |
| 155 | 288 | int mosaicy = ((gba_state->MOSAIC & 0xf0) >> 4) + 1; |
| r5697 | r5698 | |
| 158 | 291 | cy -= y*PD; |
| 159 | 292 | } |
| 160 | 293 | |
| 161 | | ax = cx >> 8; |
| 162 | | ay = cy >> 8; |
| 294 | pixx = cx >> 8; |
| 295 | pixy = cy >> 8; |
| 163 | 296 | |
| 164 | 297 | if(ctrl & BGCNT_PALETTESET_WRAP) |
| 165 | 298 | { |
| 166 | | ax %= sizes[size]; |
| 167 | | ay %= sizes[size]; |
| 168 | | if(ax < 0) |
| 299 | pixx %= sizes[size]; |
| 300 | pixy %= sizes[size]; |
| 301 | if(pixx < 0) |
| 169 | 302 | { |
| 170 | | ax += sizes[size]; |
| 303 | pixx += sizes[size]; |
| 171 | 304 | } |
| 172 | | if(ay < 0) |
| 305 | if(pixy < 0) |
| 173 | 306 | { |
| 174 | | ay += sizes[size]; |
| 307 | pixy += sizes[size]; |
| 175 | 308 | } |
| 176 | 309 | } |
| 177 | 310 | |
| r5697 | r5698 | |
| 179 | 312 | { |
| 180 | 313 | for(x = 0; x < 240; x++) |
| 181 | 314 | { |
| 182 | | if(!(ax < 0 || ay < 0 || ax >= sizes[size] || ay >= sizes[size])) |
| 315 | if(pixx < 0 || pixy < 0 || pixx >= sizes[size] || pixy >= sizes[size]) |
| 183 | 316 | { |
| 184 | | int tilex = ax & 7; |
| 185 | | int tiley = ay & 7; |
| 317 | scanline[x] = 0x80000000; |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | int tilex = pixx & 7; |
| 322 | int tiley = pixy & 7; |
| 186 | 323 | |
| 187 | | tile = mgba_vram[mapbase + (ax / 8) + (ay / 8) * (sizes[size] / 8)]; |
| 188 | | pixel = mgba_vram[base + (tile * 64) + (tiley * 8) + tilex]; |
| 324 | tile = mgba_vram[mapbase + (pixx >> 3) + (pixy >> 3) * (sizes[size] >> 3)]; |
| 325 | pixel = mgba_vram[base + (tile << 6) + (tiley << 3) + tilex]; |
| 189 | 326 | |
| 190 | 327 | // plot it |
| 191 | | if (pixel) |
| 192 | | { |
| 193 | | scanline[x] = pgba_pram[pixel] & 0x7fff; |
| 194 | | } |
| 328 | scanline[x] = pixel ? (pgba_pram[pixel] | prio) : 0x80000000; |
| 195 | 329 | } |
| 196 | 330 | |
| 197 | 331 | cx += PA; |
| 198 | 332 | cy += PC; |
| 199 | 333 | |
| 200 | | ax = cx >> 8; |
| 201 | | ay = cy >> 8; |
| 334 | pixx = cx >> 8; |
| 335 | pixy = cy >> 8; |
| 202 | 336 | |
| 203 | 337 | if(ctrl & BGCNT_PALETTESET_WRAP) |
| 204 | 338 | { |
| 205 | | ax %= sizes[size]; |
| 206 | | ay %= sizes[size]; |
| 207 | | if(ax < 0) |
| 339 | pixx %= sizes[size]; |
| 340 | pixy %= sizes[size]; |
| 341 | if(pixx < 0) |
| 208 | 342 | { |
| 209 | | ax += sizes[size]; |
| 343 | pixx += sizes[size]; |
| 210 | 344 | } |
| 211 | | if(ay < 0) |
| 345 | if(pixy < 0) |
| 212 | 346 | { |
| 213 | | ay += sizes[size]; |
| 347 | pixy += sizes[size]; |
| 214 | 348 | } |
| 215 | 349 | } |
| 216 | 350 | } |
| r5697 | r5698 | |
| 219 | 353 | { |
| 220 | 354 | for(x = 0; x < 240; x++) |
| 221 | 355 | { |
| 222 | | if(!(ax < 0 || ay < 0 || ax >= sizes[size] || ay >= sizes[size])) |
| 356 | if(pixx < 0 || pixy < 0 || pixx >= sizes[size] || pixy >= sizes[size]) |
| 223 | 357 | { |
| 224 | | int tilex = ax & 7; |
| 225 | | int tiley = ay & 7; |
| 358 | scanline[x] = 0x80000000; |
| 359 | } |
| 360 | else |
| 361 | { |
| 362 | int tilex = pixx & 7; |
| 363 | int tiley = pixy & 7; |
| 226 | 364 | |
| 227 | | tile = mgba_vram[mapbase + (ax / 8) + (ay / 8) * (sizes[size] / 8)]; |
| 228 | | pixel = mgba_vram[base + (tile * 64) + (tiley * 8) + tilex]; |
| 365 | tile = mgba_vram[mapbase + (pixx >> 3) + (pixy >> 3) * (sizes[size] >> 3)]; |
| 366 | pixel = mgba_vram[base + (tile << 6) + (tiley << 3) + tilex]; |
| 229 | 367 | |
| 230 | 368 | // plot it |
| 231 | | if (pixel) |
| 232 | | { |
| 233 | | scanline[x] = pgba_pram[pixel] & 0x7fff; |
| 234 | | } |
| 369 | scanline[x] = pixel ? (pgba_pram[pixel] | prio) : 0x80000000; |
| 235 | 370 | } |
| 236 | 371 | |
| 237 | 372 | cx += PA; |
| 238 | 373 | cy += PC; |
| 239 | 374 | |
| 240 | | ax = cx >> 8; |
| 241 | | ay = cy >> 8; |
| 375 | pixx = cx >> 8; |
| 376 | pixy = cy >> 8; |
| 242 | 377 | |
| 243 | 378 | if(ctrl & BGCNT_PALETTESET_WRAP) |
| 244 | 379 | { |
| 245 | | ax %= sizes[size]; |
| 246 | | ay %= sizes[size]; |
| 247 | | if(ax < 0) |
| 380 | pixx %= sizes[size]; |
| 381 | pixy %= sizes[size]; |
| 382 | if(pixx < 0) |
| 248 | 383 | { |
| 249 | | ax += sizes[size]; |
| 384 | pixx += sizes[size]; |
| 250 | 385 | } |
| 251 | | if(ay < 0) |
| 386 | if(pixy < 0) |
| 252 | 387 | { |
| 253 | | ay += sizes[size]; |
| 388 | pixy += sizes[size]; |
| 254 | 389 | } |
| 255 | 390 | } |
| 256 | 391 | } |
| r5697 | r5698 | |
| 277 | 412 | } |
| 278 | 413 | } |
| 279 | 414 | |
| 280 | | static void draw_bg_scanline(gba_state *gba_state, UINT16 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs, int priority) |
| 415 | static void draw_bg_scanline(gba_state *gba_state, UINT32 *scanline, int ypos, UINT32 enablemask, UINT32 ctrl, UINT32 hofs, UINT32 vofs) |
| 281 | 416 | { |
| 282 | | UINT32 base, mapbase, size, mode; |
| 283 | | UINT16 *mgba_vram = (UINT16 *)gba_state->gba_vram, tile; |
| 284 | | int mx, my, tx, mosX, mosY; |
| 417 | UINT8 *vram = (UINT8*)gba_state->gba_vram; |
| 418 | UINT16 *palette = (UINT16*)gba_state->gba_pram; |
| 419 | UINT8 *chardata = &vram[((ctrl & BGCNT_CHARBASE) >> BGCNT_CHARBASE_SHIFT) * 0x4000]; |
| 420 | UINT16 *screendata = (UINT16*)&vram[((ctrl & BGCNT_SCREENBASE) >> BGCNT_SCREENBASE_SHIFT) * 0x800]; |
| 421 | UINT32 priority = ((ctrl & BGCNT_PRIORITY) << 25) + 0x1000000; |
| 422 | INT32 width = 256; |
| 423 | INT32 height = 256; |
| 424 | INT32 maskx, masky, pixx, pixy; |
| 425 | UINT8 use_mosaic = (ctrl & BGCNT_MOSAIC) ? 1 : 0; |
| 426 | INT32 mosaicx = (gba_state->MOSAIC & 0x000f) + 1; |
| 427 | INT32 mosaicy = ((gba_state->MOSAIC & 0x00f0) >> 4) + 1; |
| 428 | INT32 stride; |
| 429 | INT32 x; |
| 285 | 430 | |
| 286 | | if (ctrl & 0x40) // mosaic |
| 431 | if(!(gba_state->DISPCNT & enablemask)) |
| 287 | 432 | { |
| 288 | | mosX = gba_state->MOSAIC & 0xf; |
| 289 | | mosY = (gba_state->MOSAIC>>4) & 0xf; |
| 433 | for(x = 0; x < 240; x++) |
| 434 | { |
| 435 | scanline[x] = 0x80000000; |
| 436 | } |
| 290 | 437 | |
| 291 | | ypos = mosaic_offset[mosY][ypos]; |
| 438 | return; |
| 292 | 439 | } |
| 293 | | else |
| 440 | |
| 441 | switch((ctrl & BGCNT_SCREENSIZE) >> BGCNT_SCREENSIZE_SHIFT) |
| 294 | 442 | { |
| 295 | | mosX = mosY = 0; |
| 443 | case 1: |
| 444 | width = 512; |
| 445 | break; |
| 446 | case 2: |
| 447 | height = 512; |
| 448 | break; |
| 449 | case 3: |
| 450 | width = 512; |
| 451 | height = 512; |
| 452 | break; |
| 296 | 453 | } |
| 297 | 454 | |
| 298 | | if ((gba_state->DISPCNT & enablemask) && ((ctrl & BGCNT_PRIORITY) == priority)) |
| 455 | maskx = width - 1; |
| 456 | masky = height - 1; |
| 457 | |
| 458 | pixx = hofs & maskx; |
| 459 | pixy = (vofs + ypos) & masky; |
| 460 | |
| 461 | if(use_mosaic) |
| 299 | 462 | { |
| 300 | | base = ((ctrl>>2)&3) * 0x4000; // VRAM base of tiles |
| 301 | | mapbase = ((ctrl>>8)&0x1f) * 0x800; // VRAM base of map |
| 302 | | size = ((ctrl>>14) & 3); // size of map in submaps |
| 303 | | mode = (ctrl & 0x80) ? 1 : 0; // 1 for 8bpp, 0 for 4bpp |
| 463 | if((ypos % mosaicy) != 0) |
| 464 | { |
| 465 | mosaicy = (ypos / mosaicy) * mosaicy; |
| 466 | pixy = (vofs + mosaicy) & masky; |
| 467 | } |
| 468 | } |
| 304 | 469 | |
| 305 | | mx = hofs/8; // X tile offset |
| 306 | | my = (ypos + vofs) / 8; // Y tile offset |
| 470 | if(pixy > 255 && height > 256) |
| 471 | { |
| 472 | pixy &= 0x000000ff; |
| 473 | screendata += 0x400; |
| 474 | if(width > 256) |
| 475 | { |
| 476 | screendata += 0x400; |
| 477 | } |
| 478 | } |
| 307 | 479 | |
| 308 | | switch (size) |
| 480 | stride = (pixy >> 3) << 5; |
| 481 | |
| 482 | if(ctrl & BGCNT_PALETTE256) |
| 483 | { |
| 484 | UINT16 *src = screendata + 0x400 * (pixx >> 8) + ((pixx & 255) >> 3) + stride; |
| 485 | INT32 x = 0; |
| 486 | for(x = 0; x < 240; x++) |
| 309 | 487 | { |
| 310 | | case 0: // 32x32 |
| 311 | | for (tx = 0; tx < 31; tx++) |
| 488 | UINT16 data = *src; |
| 489 | INT32 tile = data & TILEOBJ_TILE; |
| 490 | INT32 tilex = pixx & 7; |
| 491 | INT32 tiley = pixy & 7; |
| 492 | UINT8 color; |
| 493 | |
| 494 | if(data & TILEOBJ_HFLIP) |
| 495 | { |
| 496 | tilex = 7 - tilex; |
| 497 | } |
| 498 | if(data & TILEOBJ_VFLIP) |
| 499 | { |
| 500 | tiley = 7 - tiley; |
| 501 | } |
| 502 | |
| 503 | color = chardata[(tile << 6) + (tiley << 3) + tilex]; |
| 504 | |
| 505 | if(color) |
| 506 | { |
| 507 | scanline[x] = palette[color] | priority; |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | scanline[x] = 0x80000000; |
| 512 | } |
| 513 | |
| 514 | if(data & TILEOBJ_HFLIP) |
| 515 | { |
| 516 | if(tilex == 0) |
| 312 | 517 | { |
| 313 | | tile = mgba_vram[(mapbase>>1) + ((tx + mx) % 32) + ((my % 32) * 32)]; |
| 314 | | |
| 315 | | if (mode) |
| 316 | | { |
| 317 | | draw_8bpp_tile(gba_state, scanline, base, (tile&0x3ff)<<1, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, 0, mosX); |
| 318 | | } |
| 319 | | else |
| 320 | | { |
| 321 | | draw_4bpp_tile(gba_state, scanline, base, tile&0x3ff, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, ((tile&0xf000)>>8), mosX); |
| 322 | | } |
| 518 | src++; |
| 323 | 519 | } |
| 324 | | break; |
| 520 | } |
| 521 | else if(tilex == 7) |
| 522 | { |
| 523 | src++; |
| 524 | } |
| 325 | 525 | |
| 326 | | case 1: // 64x32 |
| 327 | | for (tx = 0; tx < 31; tx++) |
| 526 | pixx++; |
| 527 | if(pixx == 256) |
| 528 | { |
| 529 | if(width > 256) |
| 328 | 530 | { |
| 329 | | int mapxofs = ((tx + mx) % 64); |
| 531 | src = screendata + 0x400 + stride; |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | src = screendata + stride; |
| 536 | pixx = 0; |
| 537 | } |
| 538 | } |
| 539 | else if(pixx >= width) |
| 540 | { |
| 541 | pixx = 0; |
| 542 | src = screendata + stride; |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | else |
| 547 | { |
| 548 | UINT16 *src = screendata + 0x400 * (pixx >> 8) + ((pixx & 255) >> 3) + stride; |
| 549 | INT32 x = 0; |
| 550 | for(x = 0; x < 240; x++) |
| 551 | { |
| 552 | UINT16 data = *src; |
| 553 | INT32 tile = data & TILEOBJ_TILE; |
| 554 | INT32 tilex = pixx & 7; |
| 555 | INT32 tiley = pixy & 7; |
| 556 | UINT8 color; |
| 557 | UINT8 palindex; |
| 330 | 558 | |
| 331 | | if (mapxofs >= 32) |
| 332 | | { |
| 333 | | mapxofs %= 32; |
| 334 | | mapxofs += (32*32); // offset to reach the second page of the tilemap |
| 335 | | } |
| 559 | if(data & TILEOBJ_HFLIP) |
| 560 | { |
| 561 | tilex = 7 - tilex; |
| 562 | } |
| 563 | if(data & TILEOBJ_VFLIP) |
| 564 | { |
| 565 | tiley = 7 - tiley; |
| 566 | } |
| 336 | 567 | |
| 337 | | tile = mgba_vram[(mapbase>>1) + mapxofs + ((my % 32) * 32)]; |
| 568 | color = chardata[(tile << 5) + (tiley << 2) + (tilex >> 1)]; |
| 338 | 569 | |
| 339 | | if (mode) |
| 340 | | { |
| 341 | | draw_8bpp_tile(gba_state, scanline, base, (tile&0x3ff)<<1, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, 0, mosX); |
| 342 | | } |
| 343 | | else |
| 344 | | { |
| 345 | | draw_4bpp_tile(gba_state, scanline, base, tile&0x3ff, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, ((tile&0xf000)>>8), mosX); |
| 346 | | } |
| 570 | if(tilex & 1) |
| 571 | { |
| 572 | color >>= 4; |
| 573 | } |
| 574 | else |
| 575 | { |
| 576 | color &= 0x0f; |
| 577 | } |
| 578 | |
| 579 | palindex = (data >> 8) & 0x00f0; |
| 580 | if(color) |
| 581 | { |
| 582 | scanline[x] = palette[palindex + color] | priority; |
| 583 | } |
| 584 | else |
| 585 | { |
| 586 | scanline[x] = 0x80000000; |
| 587 | } |
| 588 | |
| 589 | if(data & TILEOBJ_HFLIP) |
| 590 | { |
| 591 | if(tilex == 0) |
| 592 | { |
| 593 | src++; |
| 347 | 594 | } |
| 348 | | break; |
| 595 | } |
| 596 | else if(tilex == 7) |
| 597 | { |
| 598 | src++; |
| 599 | } |
| 349 | 600 | |
| 350 | | case 2: // 32x64 |
| 351 | | for (tx = 0; tx < 31; tx++) |
| 601 | pixx++; |
| 602 | if(pixx == 256) |
| 603 | { |
| 604 | if(width > 256) |
| 352 | 605 | { |
| 353 | | int mapyofs = (my % 64); |
| 606 | src = screendata + 0x400 + stride; |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | src = screendata + stride; |
| 611 | pixx = 0; |
| 612 | } |
| 613 | } |
| 614 | else if(pixx >= width) |
| 615 | { |
| 616 | pixx = 0; |
| 617 | src = screendata + stride; |
| 618 | } |
| 619 | } |
| 620 | } |
| 354 | 621 | |
| 355 | | if (mapyofs >= 32) |
| 356 | | { |
| 357 | | mapyofs %= 32; |
| 358 | | mapyofs += 32; |
| 359 | | } |
| 622 | if(use_mosaic) |
| 623 | { |
| 624 | if(mosaicx > 1) |
| 625 | { |
| 626 | INT32 m = 1; |
| 627 | for(x = 0; x < 239; x++) |
| 628 | { |
| 629 | scanline[x+1] = scanline[x]; |
| 630 | m++; |
| 631 | if(m == mosaicx) |
| 632 | { |
| 633 | m = 1; |
| 634 | x++; |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | } |
| 360 | 640 | |
| 361 | | tile = mgba_vram[(mapbase>>1) + ((tx + mx) % 32) + (mapyofs * 32)]; |
| 641 | static void draw_gba_oam_window(gba_state *gba_state, running_machine *machine, UINT32 *scanline, int y) |
| 642 | { |
| 643 | INT16 gba_oamindex; |
| 644 | UINT32 tilebytebase, tileindex, tiledrawindex; |
| 645 | UINT32 width, height; |
| 646 | UINT16 *pgba_oam = (UINT16 *)gba_state->gba_oam; |
| 647 | int x = 0; |
| 648 | UINT8 *src = (UINT8*)gba_state->gba_vram; |
| 362 | 649 | |
| 363 | | if (mode) |
| 364 | | { |
| 365 | | draw_8bpp_tile(gba_state, scanline, base, (tile&0x3ff)<<1, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, 0, mosX); |
| 366 | | } |
| 367 | | else |
| 368 | | { |
| 369 | | draw_4bpp_tile(gba_state, scanline, base, tile&0x3ff, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, ((tile&0xf000)>>8), mosX); |
| 370 | | } |
| 371 | | } |
| 372 | | break; |
| 650 | for(x = 0; x < 240; x++) |
| 651 | { |
| 652 | scanline[x] = 0x80000000; |
| 653 | } |
| 373 | 654 | |
| 374 | | case 3: // 64x64 |
| 375 | | #if 0 |
| 376 | | if (1) |
| 377 | | { |
| 378 | | int mapyofs = (my % 64); |
| 655 | if( gba_state->DISPCNT & DISPCNT_OBJWIN_EN ) |
| 656 | { |
| 657 | for( gba_oamindex = 127; gba_oamindex >= 0; gba_oamindex-- ) |
| 658 | { |
| 659 | INT32 sx, sy; |
| 660 | UINT16 attr0, attr1, attr2; |
| 661 | INT32 cury; |
| 379 | 662 | |
| 380 | | if (mapyofs >= 32) |
| 381 | | { |
| 382 | | mapyofs %= 32; |
| 383 | | mapyofs += 64; |
| 384 | | } |
| 663 | attr0 = pgba_oam[(4*gba_oamindex)+0]; |
| 664 | attr1 = pgba_oam[(4*gba_oamindex)+1]; |
| 665 | attr2 = pgba_oam[(4*gba_oamindex)+2]; |
| 385 | 666 | |
| 386 | | // printf("%d yofs %d (ypos %d vofs %d my %d) tileofs %x\n", video_screen_get_vpos(machine->primary_screen), mapyofs, ypos, vofs, my, (mapbase>>1) + (mapyofs * 32)); |
| 667 | sx = (attr1 & OBJ_X_COORD); |
| 668 | sy = (attr0 & OBJ_Y_COORD); |
| 669 | |
| 670 | if(sy > 160) |
| 671 | { |
| 672 | sy -= 256; |
| 673 | } |
| 674 | |
| 675 | if ((attr0 & OBJ_MODE) != OBJ_MODE_WINDOW) |
| 676 | { |
| 677 | continue; |
| 678 | } |
| 679 | else |
| 680 | { |
| 681 | width = 0; |
| 682 | height = 0; |
| 683 | switch (attr0 & OBJ_SHAPE ) |
| 684 | { |
| 685 | case OBJ_SHAPE_SQR: |
| 686 | switch(attr1 & OBJ_SIZE ) |
| 687 | { |
| 688 | case OBJ_SIZE_8: |
| 689 | width = 1; |
| 690 | height = 1; |
| 691 | break; |
| 692 | case OBJ_SIZE_16: |
| 693 | width = 2; |
| 694 | height = 2; |
| 695 | break; |
| 696 | case OBJ_SIZE_32: |
| 697 | width = 4; |
| 698 | height = 4; |
| 699 | break; |
| 700 | case OBJ_SIZE_64: |
| 701 | width = 8; |
| 702 | height = 8; |
| 703 | break; |
| 704 | } |
| 705 | break; |
| 706 | case OBJ_SHAPE_HORIZ: |
| 707 | switch(attr1 & OBJ_SIZE ) |
| 708 | { |
| 709 | case OBJ_SIZE_8: |
| 710 | width = 2; |
| 711 | height = 1; |
| 712 | break; |
| 713 | case OBJ_SIZE_16: |
| 714 | width = 4; |
| 715 | height = 1; |
| 716 | break; |
| 717 | case OBJ_SIZE_32: |
| 718 | width = 4; |
| 719 | height = 2; |
| 720 | break; |
| 721 | case OBJ_SIZE_64: |
| 722 | width = 8; |
| 723 | height = 4; |
| 724 | break; |
| 725 | } |
| 726 | break; |
| 727 | case OBJ_SHAPE_VERT: |
| 728 | switch(attr1 & OBJ_SIZE ) |
| 729 | { |
| 730 | case OBJ_SIZE_8: |
| 731 | width = 1; |
| 732 | height = 2; |
| 733 | break; |
| 734 | case OBJ_SIZE_16: |
| 735 | width = 1; |
| 736 | height = 4; |
| 737 | break; |
| 738 | case OBJ_SIZE_32: |
| 739 | width = 2; |
| 740 | height = 4; |
| 741 | break; |
| 742 | case OBJ_SIZE_64: |
| 743 | width = 4; |
| 744 | height = 8; |
| 745 | break; |
| 746 | } |
| 747 | break; |
| 748 | default: |
| 749 | width = 0; |
| 750 | height = 0; |
| 751 | verboselog(machine, 0, "OAM error: Trying to draw OBJ with OBJ_SHAPE = 3!\n" ); |
| 752 | break; |
| 387 | 753 | } |
| 388 | | #endif |
| 389 | 754 | |
| 390 | | for (tx = 0; tx < 31; tx++) |
| 755 | tiledrawindex = tileindex = (attr2 & OBJ_TILENUM); |
| 756 | tilebytebase = 0x10000; // the index doesn't change in the higher modes, we just ignore sprites that are out of range |
| 757 | |
| 758 | if (attr0 & OBJ_ROZMODE_ROZ) |
| 391 | 759 | { |
| 392 | | int mapxofs = ((tx + mx) % 64); |
| 393 | | int mapyofs = (my % 64); |
| 760 | INT32 fx, fy, ax, ay, rx, ry; |
| 761 | INT16 dx, dy, dmx, dmy; |
| 762 | UINT8 color; |
| 394 | 763 | |
| 395 | | if (mapyofs >= 32) |
| 764 | width *= 8; |
| 765 | height *= 8; |
| 766 | |
| 767 | if ((attr0 & OBJ_ROZMODE) == OBJ_ROZMODE_DISABLE) |
| 396 | 768 | { |
| 397 | | mapyofs %= 32; |
| 398 | | mapyofs += 64; |
| 769 | continue; |
| 399 | 770 | } |
| 400 | 771 | |
| 401 | | if (mapxofs >= 32) |
| 772 | fx = width; |
| 773 | fy = height; |
| 774 | |
| 775 | if((attr0 & OBJ_ROZMODE) == OBJ_ROZMODE_DBLROZ) |
| 402 | 776 | { |
| 403 | | mapxofs %= 32; |
| 404 | | mapxofs += (32*32); // offset to reach the second/fourth page of the tilemap |
| 777 | fx *= 2; |
| 778 | fy *= 2; |
| 405 | 779 | } |
| 406 | 780 | |
| 407 | | tile = mgba_vram[(mapbase>>1) + mapxofs + (mapyofs * 32)]; |
| 781 | cury = y - sy; |
| 408 | 782 | |
| 409 | | if (mode) |
| 783 | if(cury >= 0 && cury < fy) |
| 410 | 784 | { |
| 411 | | draw_8bpp_tile(gba_state, scanline, base, (tile&0x3ff)<<1, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, 0, mosX); |
| 785 | if(sx < 240 || ((sx + fx) & 0x1ff) < 240) |
| 786 | { |
| 787 | int rot = (attr1 & OBJ_SCALE_PARAM) >> OBJ_SCALE_PARAM_SHIFT; |
| 788 | dx = (INT16)pgba_oam[(rot << 4)+3]; |
| 789 | dmx = (INT16)pgba_oam[(rot << 4)+7]; |
| 790 | dy = (INT16)pgba_oam[(rot << 4)+11]; |
| 791 | dmy = (INT16)pgba_oam[(rot << 4)+15]; |
| 792 | |
| 793 | rx = (width << 7) - (fx >> 1)*dx - (fy >> 1)*dmx + cury * dmx; |
| 794 | ry = (height << 7) - (fx >> 1)*dy - (fy >> 1)*dmy + cury * dmy; |
| 795 | |
| 796 | if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256) |
| 797 | { |
| 798 | int inc = 32; |
| 799 | if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200) |
| 800 | { |
| 801 | continue; |
| 802 | } |
| 803 | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D) |
| 804 | { |
| 805 | inc = sx >> 2; |
| 806 | } |
| 807 | else |
| 808 | { |
| 809 | tiledrawindex &= 0x3fe; |
| 810 | } |
| 811 | for(x = 0; x < fx; x++) |
| 812 | { |
| 813 | ax = rx >> 8; |
| 814 | ay = ry >> 8; |
| 815 | |
| 816 | if(ax < 0 || ax >= sx || ay < 0 || ay >= sy) |
| 817 | { |
| 818 | } |
| 819 | else |
| 820 | { |
| 821 | color = src[tilebytebase + ((((tiledrawindex + (ay >> 3) * inc) << 5) + ((ay & 0x07) << 3) + ((ax >> 3) << 6) + (ax & 0x07)) & 0x7fff)]; |
| 822 | |
| 823 | if(color) |
| 824 | { |
| 825 | scanline[sx] = 1; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | sx = (sx + 1) & 0x1ff; |
| 830 | |
| 831 | rx += dx; |
| 832 | ry += dy; |
| 833 | } |
| 834 | } |
| 835 | else |
| 836 | { |
| 837 | int inc = 32; |
| 838 | if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200) |
| 839 | { |
| 840 | continue; |
| 841 | } |
| 842 | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D) |
| 843 | { |
| 844 | inc = sx >> 3; |
| 845 | } |
| 846 | for(x = 0; x < fx; x++) |
| 847 | { |
| 848 | ax = rx >> 8; |
| 849 | ay = ry >> 8; |
| 850 | |
| 851 | if(ax < 0 || ax >= sx || ay < 0 || ay >= sy) |
| 852 | { |
| 853 | } |
| 854 | else |
| 855 | { |
| 856 | color = src[tilebytebase + ((((tiledrawindex + (ay >> 3) * inc) << 5) + ((ay & 0x07) << 2) + ((ax >> 3) << 5) + ((ax & 0x07) >> 1)) & 0x7fff)]; |
| 857 | |
| 858 | if(ax & 1) |
| 859 | { |
| 860 | color >>= 4; |
| 861 | } |
| 862 | else |
| 863 | { |
| 864 | color &= 0x0f; |
| 865 | } |
| 866 | |
| 867 | if(color) |
| 868 | { |
| 869 | scanline[sx] = 1; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | sx = (sx + 1) & 0x1ff; |
| 874 | |
| 875 | rx += dx; |
| 876 | ry += dy; |
| 877 | } |
| 878 | } |
| 879 | } |
| 412 | 880 | } |
| 413 | | else |
| 414 | | { |
| 415 | | draw_4bpp_tile(gba_state, scanline, base, tile&0x3ff, (tx*8)-(hofs % 8), (ypos + vofs) % 8, (tile&0x800)?1:0, (tile&0x400)?1:0, ((tile&0xf000)>>8), mosX); |
| 416 | | } |
| 417 | 881 | } |
| 418 | | break; |
| 419 | | } |
| 420 | | } |
| 421 | | } |
| 882 | else |
| 883 | { |
| 884 | INT32 ax; |
| 885 | int cury = y - sy; |
| 422 | 886 | |
| 423 | | static void draw_mode3_scanline(gba_state *gba_state, UINT16 *scanline, int y) |
| 424 | | { |
| 425 | | int x; |
| 426 | | UINT16 *pgba_vram = (UINT16 *)gba_state->gba_vram; |
| 887 | width *= 8; |
| 888 | height *= 8; |
| 427 | 889 | |
| 428 | | for (x = 0; x < 240; x++) |
| 429 | | { |
| 430 | | scanline[x] = pgba_vram[(240*y)+x]&0x7fff; |
| 431 | | } |
| 432 | | } |
| 890 | if(cury >= 0 && cury < height) |
| 891 | { |
| 892 | if( ( (sx < 240) || ( ( (sx + width) & 0x1ff ) < 240 ) ) && (attr0 & OBJ_ROZMODE_DISABLE) == 0) |
| 893 | { |
| 894 | if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256) |
| 895 | { |
| 896 | int inc = 32; |
| 897 | int address = 0; |
| 898 | if(attr1 & OBJ_VFLIP) |
| 899 | { |
| 900 | cury = height - cury - 1; |
| 901 | } |
| 902 | if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200) |
| 903 | { |
| 904 | continue; |
| 905 | } |
| 433 | 906 | |
| 434 | | static void draw_mode4_scanline(gba_state *gba_state, UINT16 *scanline, int y) |
| 435 | | { |
| 436 | | UINT32 base; |
| 437 | | int x; |
| 438 | | UINT8 *pgba_vram = (UINT8 *)gba_state->gba_vram, pixel; |
| 439 | | UINT16 *pgba_pram = (UINT16 *)gba_state->gba_pram; |
| 907 | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D) |
| 908 | { |
| 909 | inc = width >> 2; |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | tiledrawindex &= 0x3fe; |
| 914 | } |
| 440 | 915 | |
| 441 | | if (gba_state->DISPCNT & DISPCNT_FRAMESEL) |
| 442 | | { |
| 443 | | base = 0xa000; |
| 444 | | } |
| 445 | | else |
| 446 | | { |
| 447 | | base = 0; |
| 448 | | } |
| 916 | ax = 0; |
| 917 | if(attr1 & OBJ_HFLIP) |
| 918 | { |
| 919 | ax = width - 1; |
| 920 | } |
| 449 | 921 | |
| 450 | | for (x = 0; x < 240; x++) |
| 451 | | { |
| 452 | | pixel = pgba_vram[base+(240*y)+x]; |
| 453 | | if (pixel != 0) |
| 454 | | { |
| 455 | | scanline[x] = pgba_pram[pixel]&0x7fff; |
| 456 | | } |
| 457 | | } |
| 458 | | } |
| 922 | address = 0x10000 + ((((tiledrawindex + (cury >> 3) * inc) << 5) + ((cury & 7) << 3) + ((ax >> 3) << 6) + (ax & 7)) & 0x7fff); |
| 459 | 923 | |
| 460 | | static void draw_mode5_scanline(gba_state *gba_state, UINT16 *scanline, int y) |
| 461 | | { |
| 462 | | UINT32 base; |
| 463 | | int x; |
| 464 | | UINT16 *pgba_vram = (UINT16 *)gba_state->gba_vram; |
| 924 | if(attr1 & OBJ_HFLIP) |
| 925 | { |
| 926 | ax = 7; |
| 927 | } |
| 465 | 928 | |
| 466 | | if (gba_state->DISPCNT & DISPCNT_FRAMESEL) |
| 467 | | { |
| 468 | | base = 0xa000>>1; |
| 469 | | } |
| 470 | | else |
| 471 | | { |
| 472 | | base = 0; |
| 473 | | } |
| 929 | for(x = 0; x < width; x++) |
| 930 | { |
| 931 | if(sx < 240) |
| 932 | { |
| 933 | UINT8 color = src[address]; |
| 474 | 934 | |
| 475 | | for (x = 0; x < 160; x++) |
| 476 | | { |
| 477 | | scanline[x] = pgba_vram[base+(160*y)+x]; |
| 935 | if(color) |
| 936 | { |
| 937 | scanline[sx] = 1; |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | sx = (sx + 1) & 0x1ff; |
| 942 | |
| 943 | if(attr1 & OBJ_HFLIP) |
| 944 | { |
| 945 | ax--; |
| 946 | address--; |
| 947 | if(ax == -1) |
| 948 | { |
| 949 | address -= 56; |
| 950 | ax = 7; |
| 951 | } |
| 952 | if(address < 0x10000) |
| 953 | { |
| 954 | address += 0x8000; |
| 955 | } |
| 956 | } |
| 957 | else |
| 958 | { |
| 959 | ax++; |
| 960 | address++; |
| 961 | if(ax == 8) |
| 962 | { |
| 963 | address += 56; |
| 964 | ax = 0; |
| 965 | } |
| 966 | if(address > 0x17fff) |
| 967 | { |
| 968 | address -= 0x8000; |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | else |
| 974 | { |
| 975 | int inc = 32; |
| 976 | int address; |
| 977 | if(attr1 & OBJ_VFLIP) |
| 978 | { |
| 979 | cury = height - cury - 1; |
| 980 | } |
| 981 | if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200) |
| 982 | { |
| 983 | continue; |
| 984 | } |
| 985 | |
| 986 | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D) |
| 987 | { |
| 988 | inc = width >> 3; |
| 989 | } |
| 990 | |
| 991 | ax = 0; |
| 992 | if(attr1 & OBJ_HFLIP) |
| 993 | { |
| 994 | ax = width - 1; |
| 995 | } |
| 996 | |
| 997 | address = 0x10000 + ((((tiledrawindex + (cury >> 3) * inc) << 5) + ((cury & 0x07) << 2) + ((ax >> 3) << 5) + ((ax & 0x07) >> 1)) & 0x7fff); |
| 998 | if(attr1 & OBJ_HFLIP) |
| 999 | { |
| 1000 | ax = 7; |
| 1001 | for(x = width - 1; x >= 0; x--) |
| 1002 | { |
| 1003 | if(sx < 240) |
| 1004 | { |
| 1005 | UINT8 color = src[address]; |
| 1006 | if(x & 1) |
| 1007 | { |
| 1008 | color >>= 4; |
| 1009 | } |
| 1010 | else |
| 1011 | { |
| 1012 | color &= 0x0f; |
| 1013 | } |
| 1014 | |
| 1015 | if(color) |
| 1016 | { |
| 1017 | scanline[sx] = 1; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | sx = (sx + 1) & 0x1ff; |
| 1022 | ax--; |
| 1023 | if((x & 1) == 0) |
| 1024 | { |
| 1025 | address--; |
| 1026 | } |
| 1027 | if(ax == -1) |
| 1028 | { |
| 1029 | ax = 7; |
| 1030 | address -= 28; |
| 1031 | } |
| 1032 | if(address < 0x10000) |
| 1033 | { |
| 1034 | address += 0x8000; |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | else |
| 1039 | { |
| 1040 | for(x = 0; x < width; x++) |
| 1041 | { |
| 1042 | if(sx < 240) |
| 1043 | { |
| 1044 | UINT8 color = src[address]; |
| 1045 | |
| 1046 | if(x & 1) |
| 1047 | { |
| 1048 | color >>= 4; |
| 1049 | } |
| 1050 | else |
| 1051 | { |
| 1052 | color &= 0x0f; |
| 1053 | } |
| 1054 | |
| 1055 | if(color) |
| 1056 | { |
| 1057 | scanline[sx] = 1; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | sx = (sx + 1) & 0x1ff; |
| 1062 | ax++; |
| 1063 | if(x & 1) |
| 1064 | { |
| 1065 | address++; |
| 1066 | } |
| 1067 | if(ax == 8) |
| 1068 | { |
| 1069 | address += 28; |
| 1070 | ax = 0; |
| 1071 | } |
| 1072 | if(address > 0x17fff) |
| 1073 | { |
| 1074 | address -= 0x8000; |
| 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 478 | 1084 | } |
| 479 | 1085 | } |
| 480 | 1086 | |
| 481 | | static void draw_gba_oam(gba_state *gba_state, running_machine *machine, UINT16 *scanline, int y, int priority) |
| 1087 | static void draw_gba_oam(gba_state *gba_state, running_machine *machine, UINT32 *scanline, int y) |
| 482 | 1088 | { |
| 483 | 1089 | INT16 gba_oamindex; |
| 484 | | UINT8 tilex, tiley; |
| 1090 | INT32 mosaiccnt = 0; |
| 1091 | INT32 mosaicy = ((gba_state->MOSAIC & 0xf000) >> 12) + 1; |
| 1092 | INT32 mosaicx = ((gba_state->MOSAIC & 0x0f00) >> 8) + 1; |
| 485 | 1093 | UINT32 tilebytebase, tileindex, tiledrawindex; |
| 486 | 1094 | UINT8 width, height; |
| 487 | 1095 | UINT16 *pgba_oam = (UINT16 *)gba_state->gba_oam; |
| 1096 | UINT8 *src = (UINT8 *)gba_state->gba_vram; |
| 1097 | UINT16 *palette = (UINT16*)gba_state->gba_pram; |
| 1098 | int x = 0; |
| 488 | 1099 | |
| 1100 | for(x = 0; x < 240; x++) |
| 1101 | { |
| 1102 | scanline[x] = 0x80000000; |
| 1103 | } |
| 1104 | |
| 489 | 1105 | if( gba_state->DISPCNT & DISPCNT_OBJ_EN ) |
| 490 | 1106 | { |
| 491 | | for( gba_oamindex = 127; gba_oamindex >= 0; gba_oamindex-- ) |
| 1107 | for( gba_oamindex = 0; gba_oamindex < 128; gba_oamindex++ ) |
| 492 | 1108 | { |
| 493 | 1109 | UINT16 attr0, attr1, attr2; |
| 494 | | INT32 cury, lg; |
| 495 | | UINT8 *src; |
| 496 | | UINT16 j; |
| 1110 | INT32 cury; |
| 1111 | UINT32 prio; |
| 1112 | UINT32 priority; |
| 497 | 1113 | |
| 498 | 1114 | attr0 = pgba_oam[(4*gba_oamindex)+0]; |
| 499 | 1115 | attr1 = pgba_oam[(4*gba_oamindex)+1]; |
| 500 | 1116 | attr2 = pgba_oam[(4*gba_oamindex)+2]; |
| 1117 | priority = (attr2 & OBJ_PRIORITY) >> OBJ_PRIORITY_SHIFT; |
| 1118 | prio = (priority << 25) | ((attr0 & OBJ_MODE) << 6); |
| 501 | 1119 | |
| 502 | | if (((attr0 & OBJ_MODE) != OBJ_MODE_WINDOW) && (((attr2 >> 10) & 3) == priority)) |
| 1120 | if ((attr0 & OBJ_MODE) != OBJ_MODE_WINDOW) |
| 503 | 1121 | { |
| 504 | 1122 | width = 0; |
| 505 | 1123 | height = 0; |
| 506 | | switch (attr0 & OBJ_SHAPE ) |
| 1124 | switch (attr0 & OBJ_SHAPE) |
| 507 | 1125 | { |
| 508 | 1126 | case OBJ_SHAPE_SQR: |
| 509 | 1127 | switch(attr1 & OBJ_SIZE ) |
| r5697 | r5698 | |
| 580 | 1198 | |
| 581 | 1199 | if (attr0 & OBJ_ROZMODE_ROZ) |
| 582 | 1200 | { |
| 583 | | INT16 sx, sy; |
| 584 | | INT32 fx, fy, ax, ay, rx, ry, offs; |
| 585 | | UINT8 blockparam; |
| 1201 | INT32 sx, sy; |
| 1202 | INT32 fx, fy, rx, ry; |
| 586 | 1203 | INT16 dx, dy, dmx, dmy; |
| 587 | | UINT8 color; |
| 588 | 1204 | |
| 589 | 1205 | width *= 8; |
| 590 | 1206 | height *= 8; |
| r5697 | r5698 | |
| 597 | 1213 | sx = (attr1 & OBJ_X_COORD); |
| 598 | 1214 | sy = (attr0 & OBJ_Y_COORD); |
| 599 | 1215 | |
| 600 | | lg = width; |
| 601 | | |
| 602 | | if(sx & 0x100) |
| 1216 | if(sy > 160) |
| 603 | 1217 | { |
| 604 | | sx |= 0xffffff00; |
| 1218 | sy -= 256; |
| 605 | 1219 | } |
| 606 | 1220 | |
| 607 | | if(sy >= 160) |
| 608 | | { |
| 609 | | sy |= 0xffffff00; |
| 610 | | } |
| 611 | | |
| 612 | 1221 | fx = width; |
| 613 | 1222 | fy = height; |
| 614 | 1223 | |
| r5697 | r5698 | |
| 616 | 1225 | { |
| 617 | 1226 | fx *= 2; |
| 618 | 1227 | fy *= 2; |
| 619 | | lg *= 2; |
| 620 | 1228 | } |
| 621 | 1229 | |
| 622 | | if((y < sy) || (y >= sy + fy) || (sx >= 240) || (sx + fx <= 0)) |
| 623 | | { |
| 624 | | continue; |
| 625 | | } |
| 626 | | |
| 627 | 1230 | cury = y - sy; |
| 628 | 1231 | |
| 629 | | blockparam = ((attr1 & OBJ_SCALE_PARAM) >> OBJ_SCALE_PARAM_SHIFT) << 4; |
| 630 | | |
| 631 | | dx = (INT16)pgba_oam[blockparam+3]; |
| 632 | | dmx = (INT16)pgba_oam[blockparam+7]; |
| 633 | | dy = (INT16)pgba_oam[blockparam+11]; |
| 634 | | dmy = (INT16)pgba_oam[blockparam+15]; |
| 635 | | |
| 636 | | rx = (width << 7) - (fx >> 1)*dx - (fy >> 1)*dmx + cury * dmx; |
| 637 | | ry = (height << 7) - (fx >> 1)*dy - (fy >> 1)*dmy + cury * dmy; |
| 638 | | |
| 639 | | if (sx < 0) |
| 1232 | if(cury >= 0 && cury < fy) |
| 640 | 1233 | { |
| 641 | | if(sx + fx <= 0) |
| 1234 | if(sx < 240 || ((sx + fx) & 0x1ff) < 240) |
| 642 | 1235 | { |
| 643 | | continue; |
| 644 | | } |
| 1236 | INT32 oamparam = (attr1 & OBJ_SCALE_PARAM) >> OBJ_SCALE_PARAM_SHIFT; |
| 645 | 1237 | |
| 646 | | lg += sx; |
| 647 | | rx -= sx*dx; |
| 648 | | ry -= sx*dy; |
| 649 | | sx = 0; |
| 650 | | } |
| 651 | | else |
| 652 | | { |
| 653 | | if(sx + fx > 256) |
| 654 | | { |
| 655 | | lg = 256 - sx; |
| 656 | | } |
| 657 | | } |
| 1238 | dx = (INT16)pgba_oam[(oamparam << 4)+3]; |
| 1239 | dmx = (INT16)pgba_oam[(oamparam << 4)+7]; |
| 1240 | dy = (INT16)pgba_oam[(oamparam << 4)+11]; |
| 1241 | dmy = (INT16)pgba_oam[(oamparam << 4)+15]; |
| 658 | 1242 | |
| 659 | | if(attr0 & OBJ_PALMODE_256) |
| 660 | | { |
| 661 | | UINT16 *pgba_pram = (UINT16*)gba_state->gba_pram; |
| 1243 | if(attr0 & OBJ_MOSAIC) |
| 1244 | { |
| 1245 | cury -= (cury % mosaicy); |
| 1246 | } |
| 662 | 1247 | |
| 663 | | src = (UINT8*)&gba_state->gba_vram[tilebytebase >> 2]; |
| 664 | | if(!src) |
| 665 | | { |
| 666 | | continue; |
| 667 | | } |
| 1248 | rx = (width << 7) - (fx >> 1)*dx - (fy >> 1)*dmx + cury*dmx; |
| 1249 | ry = (height << 7) - (fx >> 1)*dy - (fy >> 1)*dmy + cury*dmy; |
| 668 | 1250 | |
| 669 | | src += tiledrawindex * 32; |
| 1251 | if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256) |
| 1252 | { |
| 1253 | INT32 inc = 32; |
| 670 | 1254 | |
| 671 | | for(j = 0; j < lg; ++j, ++sx) |
| 672 | | { |
| 673 | | ax = (rx >> 8); |
| 674 | | ay = (ry >> 8); |
| 1255 | if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200) |
| 1256 | { |
| 1257 | continue; |
| 1258 | } |
| 675 | 1259 | |
| 676 | | if(ax >= 0 && ay >= 0 && ax < width && ay < height) |
| 677 | | { |
| 678 | | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_2D) |
| 1260 | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D) |
| 679 | 1261 | { |
| 680 | | offs = (ax & 0x7) + ((ax & 0xfff8) << 3) + ((ay >> 3) << 10) + ((ay & 0x7) << 3); |
| 1262 | inc = width >> 2; |
| 681 | 1263 | } |
| 682 | 1264 | else |
| 683 | 1265 | { |
| 684 | | offs = (ax & 0x7) + ((ax & 0xfff8) << 3) + (((ay >> 3) * width) << 3) + ((ay & 0x7) << 3); |
| 1266 | tiledrawindex &= 0x3fe; |
| 685 | 1267 | } |
| 686 | 1268 | |
| 687 | | color = src[offs]; |
| 688 | | |
| 689 | | if(color) |
| 1269 | for(x = 0; x < fx; x++) |
| 690 | 1270 | { |
| 691 | | scanline[sx] = pgba_pram[256+color] & 0x7fff; |
| 692 | | } |
| 693 | | } |
| 1271 | INT32 pixx = rx >> 8; |
| 1272 | INT32 pixy = ry >> 8; |
| 694 | 1273 | |
| 695 | | rx += dx; |
| 696 | | ry += dy; |
| 697 | | } |
| 698 | | } |
| 699 | | else |
| 700 | | { |
| 701 | | UINT16 *pgba_pram = (UINT16*)gba_state->gba_pram; |
| 1274 | if(!(pixx < 0 || pixx >= width || pixy < 0 || pixy >= height || sx >= 240)) |
| 1275 | { |
| 1276 | UINT8 color = src[0x10000 + ((((tiledrawindex + (pixy >> 3) * inc) << 5) + ((pixy & 7) << 3) + ((pixx >> 3) << 6) + (pixx & 7)) & 0x7fff)]; |
| 1277 | if(color == 0 && priority < ((scanline[sx] >> 25) & 3)) |
| 1278 | { |
| 1279 | scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio; |
| 1280 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1281 | { |
| 1282 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1283 | } |
| 1284 | } |
| 1285 | else if(color != 0 && prio < (scanline[sx] & 0xff000000)) |
| 1286 | { |
| 1287 | scanline[sx] = palette[256 + color] | prio; |
| 1288 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1289 | { |
| 1290 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1291 | } |
| 1292 | } |
| 702 | 1293 | |
| 703 | | src = (UINT8*)&gba_state->gba_vram[tilebytebase >> 2]; |
| 704 | | if(!src) |
| 705 | | { |
| 706 | | continue; |
| 707 | | } |
| 1294 | if(attr0 & OBJ_MOSAIC) |
| 1295 | { |
| 1296 | mosaiccnt++; |
| 1297 | if(mosaiccnt == mosaicx) |
| 1298 | { |
| 1299 | mosaiccnt = 0; |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 708 | 1303 | |
| 709 | | src += tiledrawindex * 32; |
| 1304 | sx++; |
| 1305 | sx &= 0x1ff; |
| 710 | 1306 | |
| 711 | | for(j = 0; j < lg; ++j, ++sx) |
| 712 | | { |
| 713 | | ax = (rx >> 8); |
| 714 | | ay = (ry >> 8); |
| 1307 | rx += dx; |
| 1308 | ry += dy; |
| 1309 | } |
| 1310 | } |
| 1311 | else |
| 1312 | { |
| 1313 | INT32 inc = 32; |
| 1314 | INT32 palentry = (attr2 >> 8) & 0xf0; |
| 715 | 1315 | |
| 716 | | if(ax >= 0 && ay >= 0 && ax < width && ay < height) |
| 717 | | { |
| 718 | | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_2D) |
| 1316 | if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200) |
| 719 | 1317 | { |
| 720 | | offs = ((ax >> 1) & 0x3) + (((ax >> 1) & 0xfffc) << 3) + ((ay >> 3) << 10) + ((ay & 0x7) << 2); |
| 1318 | continue; |
| 721 | 1319 | } |
| 722 | | else |
| 1320 | |
| 1321 | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D) |
| 723 | 1322 | { |
| 724 | | offs = ((ax >> 1) & 0x3) + (((ax >> 1) & 0xfffc) << 3) + (((ay >> 3) * width) << 2) + ((ay & 0x7) << 2); |
| 1323 | inc = width >> 3; |
| 725 | 1324 | } |
| 726 | 1325 | |
| 727 | | color = src[offs]; |
| 728 | | |
| 729 | | if(ax & 1) |
| 1326 | for(x = 0; x < fx; x++) |
| 730 | 1327 | { |
| 731 | | color >>= 4; |
| 732 | | } |
| 733 | | else |
| 734 | | { |
| 735 | | color &= 0x0f; |
| 736 | | } |
| 1328 | INT32 pixx = rx >> 8; |
| 1329 | INT32 pixy = ry >> 8; |
| 737 | 1330 | |
| 738 | | if(color) |
| 739 | | { |
| 740 | | scanline[sx] = pgba_pram[256 + ((attr2 & 0xf000) >> 8) + color] & 0x7fff; |
| 1331 | if(!(pixx < 0 || pixx >= width || pixy < 0 || pixy >= height || sx >= 240)) |
| 1332 | { |
| 1333 | UINT8 color = src[0x10000 + ((((tiledrawindex + (pixy >> 3) * inc) << 5) + ((pixy & 7) << 2) + ((pixx >> 3) << 5) + ((pixx & 7) >> 1)) & 0x7fff)]; |
| 1334 | |
| 1335 | if(pixx & 1) |
| 1336 | { |
| 1337 | color >>= 4; |
| 1338 | } |
| 1339 | else |
| 1340 | { |
| 1341 | color &= 0x0f; |
| 1342 | } |
| 1343 | |
| 1344 | if(color == 0 && priority < ((scanline[sx] >> 25) & 3)) |
| 1345 | { |
| 1346 | scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio; |
| 1347 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1348 | { |
| 1349 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1350 | } |
| 1351 | } |
| 1352 | else if(color != 0 && prio < (scanline[sx] & 0xff000000)) |
| 1353 | { |
| 1354 | scanline[sx] = palette[256 + palentry + color] | prio; |
| 1355 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1356 | { |
| 1357 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | if(attr0 & OBJ_MOSAIC) |
| 1363 | { |
| 1364 | mosaiccnt++; |
| 1365 | if(mosaiccnt == mosaicx) |
| 1366 | { |
| 1367 | mosaiccnt = 0; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | sx++; |
| 1372 | |
| 1373 | sx &= 0x1ff; |
| 1374 | |
| 1375 | rx += dx; |
| 1376 | ry += dy; |
| 741 | 1377 | } |
| 742 | 1378 | } |
| 743 | | |
| 744 | | rx += dx; |
| 745 | | ry += dy; |
| 746 | 1379 | } |
| 747 | 1380 | } |
| 748 | 1381 | } |
| 749 | 1382 | else |
| 750 | 1383 | { |
| 751 | | INT16 sx, sy; |
| 752 | | int vflip, hflip; |
| 1384 | INT32 sx, sy; |
| 1385 | INT32 vflip = (attr1 & OBJ_VFLIP) ? 1 : 0; |
| 1386 | INT32 hflip = (attr1 & OBJ_HFLIP) ? 1 : 0; |
| 753 | 1387 | |
| 1388 | width *= 8; |
| 1389 | height *= 8; |
| 1390 | |
| 754 | 1391 | if ((attr0 & OBJ_ROZMODE) == OBJ_ROZMODE_DISABLE) |
| 755 | 1392 | { |
| 756 | 1393 | continue; |
| r5697 | r5698 | |
| 758 | 1395 | |
| 759 | 1396 | sx = (attr1 & OBJ_X_COORD); |
| 760 | 1397 | sy = (attr0 & OBJ_Y_COORD); |
| 761 | | vflip = (attr1 & OBJ_VFLIP) ? 1 : 0; |
| 762 | | hflip = (attr1 & OBJ_HFLIP) ? 1 : 0; |
| 763 | 1398 | |
| 764 | | if (sy > 160) |
| 1399 | if(sy > 160) |
| 765 | 1400 | { |
| 766 | | sy = 0 - (255-sy); |
| 1401 | sy -= 256; |
| 767 | 1402 | } |
| 768 | 1403 | |
| 769 | | if (sx > 256) |
| 1404 | cury = y - sy; |
| 1405 | if(cury >= 0 && cury < height) |
| 770 | 1406 | { |
| 771 | | sx = 0 - (511-sx); |
| 772 | | } |
| 773 | | |
| 774 | | // on this scanline? |
| 775 | | if ((y >= sy) && (y < (sy+(height*8)))) |
| 776 | | { |
| 777 | | // Y = scanline we're drawing |
| 778 | | // SY = starting Y position of sprite |
| 779 | | if (vflip) |
| 1407 | if(sx < 240 || ((sx + width) & 0x1ff) < 240) |
| 780 | 1408 | { |
| 781 | | tiley = (sy+(height*8)-1) - y; |
| 782 | | } |
| 783 | | else |
| 784 | | { |
| 785 | | tiley = y - sy; |
| 786 | | } |
| 787 | | |
| 788 | | if (( gba_state->DISPCNT & DISPCNT_VRAM_MAP ) == DISPCNT_VRAM_MAP_2D) |
| 789 | | { |
| 790 | | tiledrawindex = (tileindex + ((tiley/8) * 32)); |
| 791 | | } |
| 792 | | else |
| 793 | | { |
| 794 | | if ((attr0 & OBJ_PALMODE) == OBJ_PALMODE_16) |
| 1409 | if((attr0 & OBJ_PALMODE) == OBJ_PALMODE_256) |
| 795 | 1410 | { |
| 796 | | tiledrawindex = (tileindex + ((tiley/8) * width)); |
| 797 | | } |
| 798 | | else |
| 799 | | { |
| 800 | | tiledrawindex = (tileindex + ((tiley/8) * (width*2))); |
| 801 | | } |
| 802 | | } |
| 1411 | INT32 pixx; |
| 1412 | INT32 inc = 32; |
| 1413 | INT32 address = 0; |
| 803 | 1414 | |
| 804 | | if (hflip) |
| 805 | | { |
| 806 | | tiledrawindex += (width-1); |
| 807 | | for (tilex = 0; tilex < width; tilex++) |
| 808 | | { |
| 809 | | if ((attr0 & OBJ_PALMODE) == OBJ_PALMODE_16) |
| 1415 | if(vflip) |
| 810 | 1416 | { |
| 811 | | draw_4bpp_tile(gba_state, scanline, tilebytebase, tiledrawindex, sx+(tilex*8), tiley % 8, 0, hflip, 256+((attr2&0xf000)>>8), 0); |
| 1417 | cury = height - cury - 1; |
| 812 | 1418 | } |
| 1419 | |
| 1420 | if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200) |
| 1421 | { |
| 1422 | continue; |
| 1423 | } |
| 1424 | |
| 1425 | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D) |
| 1426 | { |
| 1427 | inc = width >> 2; |
| 1428 | } |
| 813 | 1429 | else |
| 814 | 1430 | { |
| 815 | | draw_8bpp_tile(gba_state, scanline, tilebytebase, tiledrawindex, sx+(tilex*8), tiley % 8, 0, hflip, 256, 0); |
| 816 | | tiledrawindex++; |
| 1431 | tiledrawindex &= 0x3fe; |
| 817 | 1432 | } |
| 818 | | tiledrawindex--; |
| 1433 | |
| 1434 | pixx = 0; |
| 1435 | if(hflip) |
| 1436 | { |
| 1437 | pixx = width - 1; |
| 1438 | } |
| 1439 | |
| 1440 | if(attr0 & OBJ_MOSAIC) |
| 1441 | { |
| 1442 | cury -= (cury % mosaicy); |
| 1443 | } |
| 1444 | |
| 1445 | address = 0x10000 + ((((tiledrawindex + (cury >> 3) * inc) << 5) + ((cury & 7) << 3) + ((pixx >> 3) << 6) + (pixx & 7)) & 0x7fff); |
| 1446 | |
| 1447 | if(hflip) |
| 1448 | { |
| 1449 | pixx = 7; |
| 1450 | } |
| 1451 | |
| 1452 | for(x = 0; x < width; x++) |
| 1453 | { |
| 1454 | if(sx < 240) |
| 1455 | { |
| 1456 | UINT8 color = src[address]; |
| 1457 | if(color == 0 && priority < ((scanline[sx] >> 25) & 3)) |
| 1458 | { |
| 1459 | scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio; |
| 1460 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1461 | { |
| 1462 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1463 | } |
| 1464 | } |
| 1465 | else if(color != 0 && prio < (scanline[sx] & 0xff000000)) |
| 1466 | { |
| 1467 | scanline[sx] = palette[256 + color] | prio; |
| 1468 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1469 | { |
| 1470 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1471 | } |
| 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | if(attr0 & OBJ_MOSAIC) |
| 1476 | { |
| 1477 | mosaiccnt++; |
| 1478 | if(mosaiccnt == mosaicx) |
| 1479 | { |
| 1480 | mosaiccnt = 0; |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | sx++; |
| 1485 | sx &= 0x1ff; |
| 1486 | |
| 1487 | if(hflip) |
| 1488 | { |
| 1489 | pixx--; |
| 1490 | address--; |
| 1491 | if(pixx == -1) |
| 1492 | { |
| 1493 | address -= 56; |
| 1494 | pixx = 7; |
| 1495 | } |
| 1496 | if(address < 0x10000) |
| 1497 | { |
| 1498 | address += 0x8000; |
| 1499 | } |
| 1500 | } |
| 1501 | else |
| 1502 | { |
| 1503 | pixx++; |
| 1504 | address++; |
| 1505 | if(pixx == 8) |
| 1506 | { |
| 1507 | address += 56; |
| 1508 | pixx = 0; |
| 1509 | } |
| 1510 | if(address > 0x17fff) |
| 1511 | { |
| 1512 | address -= 0x8000; |
| 1513 | } |
| 1514 | } |
| 1515 | } |
| 819 | 1516 | } |
| 820 | | } |
| 821 | | else |
| 822 | | { |
| 823 | | for (tilex = 0; tilex < width; tilex++) |
| 1517 | else |
| 824 | 1518 | { |
| 825 | | if ((attr0 & OBJ_PALMODE) == OBJ_PALMODE_16) |
| 1519 | INT32 pixx; |
| 1520 | INT32 inc = 32; |
| 1521 | UINT32 address = 0; |
| 1522 | |
| 1523 | if(vflip) |
| 826 | 1524 | { |
| 827 | | draw_4bpp_tile(gba_state, scanline, tilebytebase, tiledrawindex, sx+(tilex*8), tiley % 8, 0, hflip, 256+((attr2&0xf000)>>8), 0); |
| 1525 | cury = height - cury - 1; |
| 828 | 1526 | } |
| 1527 | |
| 1528 | if((gba_state->DISPCNT & DISPCNT_MODE) > 2 && tiledrawindex < 0x200) |
| 1529 | { |
| 1530 | continue; |
| 1531 | } |
| 1532 | |
| 1533 | if((gba_state->DISPCNT & DISPCNT_VRAM_MAP) == DISPCNT_VRAM_MAP_1D) |
| 1534 | { |
| 1535 | inc = width >> 3; |
| 1536 | } |
| 1537 | |
| 1538 | pixx = 0; |
| 1539 | if(hflip) |
| 1540 | { |
| 1541 | pixx = width - 1; |
| 1542 | } |
| 1543 | |
| 1544 | if(attr0 & OBJ_MOSAIC) |
| 1545 | { |
| 1546 | cury -= (cury % mosaicy); |
| 1547 | } |
| 1548 | |
| 1549 | address = 0x10000 + ((((tiledrawindex + (cury >> 3) * inc) << 5) + ((cury & 7) << 2) + ((pixx >> 3) << 5) + ((pixx & 7) >> 1)) & 0x7fff); |
| 1550 | |
| 1551 | if(hflip) |
| 1552 | { |
| 1553 | pixx = 7; |
| 1554 | for(x = width - 1; x >= 0; x--) |
| 1555 | { |
| 1556 | if(sx < 240) |
| 1557 | { |
| 1558 | UINT8 color = src[address]; |
| 1559 | UINT8 palentry = (attr2 >> 8) & 0xf0; |
| 1560 | |
| 1561 | if(x & 1) |
| 1562 | { |
| 1563 | color >>= 4; |
| 1564 | } |
| 1565 | else |
| 1566 | { |
| 1567 | color &= 0x0f; |
| 1568 | } |
| 1569 | |
| 1570 | if(color == 0 && priority < ((scanline[sx] >> 25) & 3)) |
| 1571 | { |
| 1572 | scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio; |
| 1573 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1574 | { |
| 1575 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1576 | } |
| 1577 | } |
| 1578 | else if(color != 0 && prio < (scanline[sx] & 0xff000000)) |
| 1579 | { |
| 1580 | scanline[sx] = palette[256 + palentry + color] | prio; |
| 1581 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1582 | { |
| 1583 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1584 | } |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | sx++; |
| 1589 | sx &= 0x1ff; |
| 1590 | |
| 1591 | pixx--; |
| 1592 | if(!(x & 1)) |
| 1593 | { |
| 1594 | address--; |
| 1595 | } |
| 1596 | if(pixx == -1) |
| 1597 | { |
| 1598 | address -= 28; |
| 1599 | pixx = 7; |
| 1600 | } |
| 1601 | if(address < 0x10000) |
| 1602 | { |
| 1603 | address += 0x8000; |
| 1604 | } |
| 1605 | } |
| 1606 | } |
| 829 | 1607 | else |
| 830 | 1608 | { |
| 831 | | draw_8bpp_tile(gba_state, scanline, tilebytebase, tiledrawindex, sx+(tilex*8), tiley % 8, 0, hflip, 256, 0); |
| 832 | | tiledrawindex++; |
| 1609 | for(x = 0; x < width; x++) |
| 1610 | { |
| 1611 | if(sx < 240) |
| 1612 | { |
| 1613 | UINT8 color = src[address]; |
| 1614 | UINT8 palentry = (attr2 >> 8) & 0xf0; |
| 1615 | |
| 1616 | if(x & 1) |
| 1617 | { |
| 1618 | color >>= 4; |
| 1619 | } |
| 1620 | else |
| 1621 | { |
| 1622 | color &= 0x0f; |
| 1623 | } |
| 1624 | |
| 1625 | if(color == 0 && priority < ((scanline[sx] >> 25) & 3)) |
| 1626 | { |
| 1627 | scanline[sx] = (scanline[sx] & 0xf9ffffff) | prio; |
| 1628 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1629 | { |
| 1630 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1631 | } |
| 1632 | } |
| 1633 | else if(color != 0 && prio < (scanline[sx] & 0xff000000)) |
| 1634 | { |
| 1635 | scanline[sx] = palette[256 + palentry + color] | prio; |
| 1636 | if((attr0 & OBJ_MOSAIC) != 0 && mosaiccnt != 0) |
| 1637 | { |
| 1638 | scanline[sx] = (scanline[sx - 1] & 0xf9ffffff) | prio; |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | if(attr0 & OBJ_MOSAIC) |
| 1644 | { |
| 1645 | mosaiccnt++; |
| 1646 | if(mosaiccnt == mosaicx) |
| 1647 | { |
| 1648 | mosaiccnt = 0; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | sx++; |
| 1653 | sx &= 0x1ff; |
| 1654 | |
| 1655 | pixx++; |
| 1656 | if(x & 1) |
| 1657 | { |
| 1658 | address++; |
| 1659 | } |
| 1660 | if(pixx == 8) |
| 1661 | { |
| 1662 | address += 28; |
| 1663 | pixx = 0; |
| 1664 | } |
| 1665 | if(address > 0x17fff) |
| 1666 | { |
| 1667 | address -= 0x8000; |
| 1668 | } |
| 1669 | } |
| 833 | 1670 | } |
| 834 | | tiledrawindex++; |
| 835 | 1671 | } |
| 836 | 1672 | } |
| 837 | 1673 | } |
| r5697 | r5698 | |
| 841 | 1677 | } |
| 842 | 1678 | } |
| 843 | 1679 | |
| 1680 | INLINE int is_in_window(gba_state *gba_state, int x, int window) |
| 1681 | { |
| 1682 | int x0 = gba_state->WIN0H >> 8; |
| 1683 | int x1 = gba_state->WIN0H & 0x00ff; |
| 1684 | |
| 1685 | if(window == 1) |
| 1686 | { |
| 1687 | x0 = gba_state->WIN1H >> 8; |
| 1688 | x1 = gba_state->WIN1H & 0x00ff; |
| 1689 | } |
| 1690 | |
| 1691 | if(x0 <= x1) |
| 1692 | { |
| 1693 | if(x >= x0 && x < x1) |
| 1694 | { |
| 1695 | return 1; |
| 1696 | } |
| 1697 | } |
| 1698 | else |
| 1699 | { |
| 1700 | if(x >= x0 || x < x1) |
| 1701 | { |
| 1702 | return 1; |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | return 0; |
| 1707 | } |
| 1708 | |
| 1709 | INLINE UINT32 alpha_blend_pixel(UINT32 color0, UINT32 color1, int ca, int cb) |
| 1710 | { |
| 1711 | if(color0 < 0x80000000) |
| 1712 | { |
| 1713 | int r0 = (color0 >> 0) & 0x1f; |
| 1714 | int g0 = (color0 >> 5) & 0x1f; |
| 1715 | int b0 = (color0 >> 10) & 0x1f; |
| 1716 | int r1 = (color1 >> 0) & 0x1f; |
| 1717 | int g1 = (color1 >> 5) & 0x1f; |
| 1718 | int b1 = (color1 >> 10) & 0x1f; |
| 1719 | int r = ((r0 * ca) >> 4) + ((r1 * cb) >> 4); |
| 1720 | int g = ((g0 * ca) >> 4) + ((g1 * cb) >> 4); |
| 1721 | int b = ((b0 * ca) >> 4) + ((b1 * cb) >> 4); |
| 1722 | |
| 1723 | if(r > 0x1f) r = 0x1f; |
| 1724 | if(g > 0x1f) g = 0x1f; |
| 1725 | if(b > 0x1f) b = 0x1f; |
| 1726 | |
| 1727 | return (color0 & 0xffff0000) | (b << 10) | (g << 5) | r; |
| 1728 | } |
| 1729 | return color0; |
| 1730 | } |
| 1731 | |
| 1732 | INLINE UINT32 increase_brightness(UINT32 color, int coeff) |
| 1733 | { |
| 1734 | int r = (color >> 0) & 0x1f; |
| 1735 | int g = (color >> 5) & 0x1f; |
| 1736 | int b = (color >> 10) & 0x1f; |
| 1737 | |
| 1738 | r += ((0x1f - r) * coeff) >> 4; |
| 1739 | g += ((0x1f - g) * coeff) >> 4; |
| 1740 | b += ((0x1f - b) * coeff) >> 4; |
| 1741 | |
| 1742 | if(r > 0x1f) r = 0x1f; |
| 1743 | if(g > 0x1f) g = 0x1f; |
| 1744 | if(b > 0x1f) b = 0x1f; |
| 1745 | |
| 1746 | return (color & 0xffff0000) | (b << 10) | (g << 5) | r; |
| 1747 | } |
| 1748 | |
| 1749 | INLINE UINT32 decrease_brightness(UINT32 color, int coeff) |
| 1750 | { |
| 1751 | int r = (color >> 0) & 0x1f; |
| 1752 | int g = (color >> 5) & 0x1f; |
| 1753 | int b = (color >> 10) & 0x1f; |
| 1754 | |
| 1755 | r -= (r * coeff) >> 4; |
| 1756 | g -= (g * coeff) >> 4; |
| 1757 | b -= (b * coeff) >> 4; |
| 1758 | |
| 1759 | if(r < 0) r = 0; |
| 1760 | if(g < 0) g = 0; |
| 1761 | if(b < 0) b = 0; |
| 1762 | |
| 1763 | return (color & 0xffff0000) | (b << 10) | (g << 5) | r; |
| 1764 | } |
| 1765 | |
| 844 | 1766 | void gba_draw_scanline(running_machine *machine, int y) |
| 845 | 1767 | { |
| 846 | | UINT16 *pgba_pram, *scanline; |
| 847 | | int prio; |
| 848 | 1768 | bitmap_t *bitmap = tmpbitmap; |
| 849 | | int i; |
| 850 | | static UINT16 xferscan[240+2048]; // up to 1024 pixels of slop on either side to allow easier clip handling |
| 1769 | UINT16 *scanline = BITMAP_ADDR16(bitmap, y, 0); |
| 1770 | int i, x; |
| 1771 | static UINT32 xferscan[7][240+2048]; // up to 1024 pixels of slop on either side to allow easier clip handling |
| 851 | 1772 | gba_state *gba_state = machine->driver_data; |
| 1773 | UINT8 submode = 0; |
| 1774 | int bpp = 0; |
| 852 | 1775 | |
| 853 | | pgba_pram = (UINT16 *)gba_state->gba_pram; |
| 854 | | |
| 855 | | scanline = BITMAP_ADDR16(bitmap, y, 0); |
| 856 | | |
| 857 | 1776 | // forced blank |
| 858 | 1777 | if (gba_state->DISPCNT & DISPCNT_BLANK) |
| 859 | 1778 | { |
| r5697 | r5698 | |
| 865 | 1784 | return; |
| 866 | 1785 | } |
| 867 | 1786 | |
| 868 | | // BG color |
| 869 | | for (i = 0; i < 240; i++) |
| 1787 | //printf( "mode = %d\n", gba_state->DISPCNT & 7 ); |
| 1788 | |
| 1789 | if(gba_state->DISPCNT & DISPCNT_OBJWIN_EN) |
| 870 | 1790 | { |
| 871 | | xferscan[1024+i] = pgba_pram[0]&0x7fff; |
| 1791 | submode = 2; |
| 872 | 1792 | } |
| 1793 | else if(gba_state->fxOn) |
| 1794 | { |
| 1795 | submode = 1; |
| 1796 | } |
| 1797 | else |
| 1798 | { |
| 1799 | submode = 0; |
| 1800 | } |
| 873 | 1801 | |
| 874 | | |
| 875 | | // printf("mode %d\n", (gba_state->DISPCNT & 7)); |
| 876 | | |
| 877 | | // if (y == 0) printf("DISPCNT %04x\n", gba_state->DISPCNT); |
| 878 | | |
| 879 | | switch (gba_state->DISPCNT & 7) |
| 1802 | switch(gba_state->DISPCNT & 7) |
| 880 | 1803 | { |
| 881 | | case 0: |
| 882 | | for (prio = 3; prio >= 0; prio--) |
| 883 | | { |
| 884 | | draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3HOFS, gba_state->BG3VOFS, prio); |
| 885 | | draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2HOFS, gba_state->BG2VOFS, prio); |
| 886 | | draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS, prio); |
| 887 | | draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS, prio); |
| 888 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, prio); |
| 889 | | } |
| 890 | | break; |
| 891 | | |
| 892 | | case 1: |
| 893 | | for (prio = 3; prio >= 0; prio--) |
| 894 | | { |
| 895 | | draw_roz_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, prio); |
| 896 | | draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG1_EN, gba_state->BG1CNT, gba_state->BG1HOFS, gba_state->BG1VOFS, prio); |
| 897 | | draw_bg_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG0_EN, gba_state->BG0CNT, gba_state->BG0HOFS, gba_state->BG0VOFS, prio); |
| 898 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, prio); |
| 899 | | } |
| 900 | | break; |
| 901 | | |
| 902 | | case 2: |
| 903 | | for (prio = 3; prio >= 0; prio--) |
| 904 | | { |
| 905 | | draw_roz_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG3_EN, gba_state->BG3CNT, gba_state->BG3X, gba_state->BG3Y, gba_state->BG3PA, gba_state->BG3PB, gba_state->BG3PC, gba_state->BG3PD, prio); |
| 906 | | draw_roz_scanline(gba_state, &xferscan[1024], y, DISPCNT_BG2_EN, gba_state->BG2CNT, gba_state->BG2X, gba_state->BG2Y, gba_state->BG2PA, gba_state->BG2PB, gba_state->BG2PC, gba_state->BG2PD, prio); |
| 907 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, prio); |
| 908 | | } |
| 909 | | break; |
| 910 | | |
| 911 | 1804 | case 3: |
| 912 | | draw_mode3_scanline(gba_state, &xferscan[1024], y); |
| 913 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 3); |
| 914 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 2); |
| 915 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 1); |
| 916 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 0); |
| 1805 | bpp = 16; |
| 917 | 1806 | break; |
| 918 | | |
| 919 | 1807 | case 4: |
| 920 | | draw_mode4_scanline(gba_state, &xferscan[1024], y); |
| 921 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 3); |
| 922 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 2); |
| 923 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 1); |
| 924 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 0); |
| 1808 | bpp = 8; |
| 925 | 1809 | break; |
| 926 | | |
| 927 | 1810 | case 5: |
| 928 | | draw_mode5_scanline(gba_state, &xferscan[1024], y); |
| 929 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 3); |
| 930 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 2); |
| 931 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 1); |
| 932 | | draw_gba_oam(gba_state, machine, &xferscan[1024], y, 0); |
| 1811 | bpp = 4; |
| 933 | 1812 | break; |
| 934 | 1813 | } |
| 935 | 1814 | |
| 1815 | gba_draw_scanline_modes[gba_state->DISPCNT & 7][submode](machine, gba_state, y, &xferscan[0][1024], &xferscan[1][1024], &xferscan[2][1024], &xferscan[3][1024], &xferscan[4][1024], &xferscan[5][1024], &xferscan[6][1024], bpp); |
| 936 | 1816 | |
| 937 | | // copy the working scanline to the real one |
| 938 | | memcpy(scanline, &xferscan[1024], 240*2); |
| 1817 | for(x = 0; x < 240; x++) |
| 1818 | { |
| 1819 | scanline[x] = xferscan[6][1024 + x] & 0x7fff; |
| 1820 | } |
| 939 | 1821 | |
| 940 | 1822 | return; |
| 941 | 1823 | } |
src/mess/drivers/gba.c
| r5697 | r5698 | |
| 4 | 4 | |
| 5 | 5 | Driver file to handle emulation of the Nintendo Game Boy Advance. |
| 6 | 6 | |
| 7 | | By R. Belmont & MooglyGuy |
| 7 | By R. Belmont & Harmony |
| 8 | 8 | |
| 9 | 9 | TODO: |
| 10 | | - Raster interrupts have issues |
| 11 | | - Roz sprites |
| 12 | | - Roz BG support |
| 13 | | - Windows |
| 14 | | - Blending |
| 10 | - Raster timing issues. Castlevania (HOD and AOS)'s raster effects |
| 11 | work if the VBlank is fired on scanline 0, else they're offset by |
| 12 | the height of the vblank region. Is scanline 0 the start of the |
| 13 | visible area? |
| 15 | 14 | |
| 16 | 15 | ***************************************************************************/ |
| 17 | 16 | |
| r5697 | r5698 | |
| 25 | 24 | #include "includes/gb.h" |
| 26 | 25 | #include "sound/dac.h" |
| 27 | 26 | |
| 28 | | #define VERBOSE_LEVEL (0) |
| 27 | #define VERBOSE_LEVEL (2) |
| 29 | 28 | |
| 30 | 29 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| 31 | 30 | { |
| r5697 | r5698 | |
| 36 | 35 | va_start( v, s_fmt ); |
| 37 | 36 | vsprintf( buf, s_fmt, v ); |
| 38 | 37 | va_end( v ); |
| 39 | | logerror( "%08x: %s", cpu_get_pc(machine->firstcpu), buf ); |
| 38 | logerror( "%08x: %s", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), buf ); |
| 40 | 39 | } |
| 41 | 40 | } |
| 42 | 41 | |
| r5697 | r5698 | |
| 86 | 85 | // master enable? |
| 87 | 86 | if (gba_state->IME & 1) |
| 88 | 87 | { |
| 89 | | cpu_set_input_line(machine->firstcpu, ARM7_IRQ_LINE, ASSERT_LINE); |
| 90 | | cpu_set_input_line(machine->firstcpu, ARM7_IRQ_LINE, CLEAR_LINE); |
| 88 | cpu_set_input_line(cputag_get_cpu(machine, "maincpu"), ARM7_IRQ_LINE, ASSERT_LINE); |
| 89 | cpu_set_input_line(cputag_get_cpu(machine, "maincpu"), ARM7_IRQ_LINE, CLEAR_LINE); |
| 91 | 90 | } |
| 92 | 91 | } |
| 93 | 92 | } |
| r5697 | r5698 | |
| 142 | 141 | int ctrl; |
| 143 | 142 | int srcadd, dstadd; |
| 144 | 143 | UINT32 src, dst; |
| 145 | | const address_space *space = cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM); |
| 144 | const address_space *space = cpu_get_address_space(cputag_get_cpu(machine, "maincpu"), ADDRESS_SPACE_PROGRAM); |
| 146 | 145 | gba_state *gba_state = machine->driver_data; |
| 147 | 146 | |
| 148 | 147 | src = gba_state->dma_src[ch]; |
| r5697 | r5698 | |
| 998 | 997 | { |
| 999 | 998 | verboselog(machine, 2, "GBA IO Register Write: DISPCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1000 | 999 | gba_state->DISPCNT = ( gba_state->DISPCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1000 | if(gba_state->DISPCNT & (DISPCNT_WIN0_EN | DISPCNT_WIN1_EN)) |
| 1001 | { |
| 1002 | gba_state->windowOn = 1; |
| 1003 | } |
| 1004 | else |
| 1005 | { |
| 1006 | gba_state->windowOn = 0; |
| 1007 | } |
| 1001 | 1008 | } |
| 1002 | 1009 | if( (mem_mask) & 0xffff0000 ) |
| 1003 | 1010 | { |
| r5697 | r5698 | |
| 1006 | 1013 | } |
| 1007 | 1014 | break; |
| 1008 | 1015 | case 0x0004/4: |
| 1009 | | // printf("DISPSTAT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, mem_mask ); |
| 1010 | 1016 | COMBINE_DATA(&gba_state->DISPSTAT); |
| 1011 | 1017 | break; |
| 1012 | 1018 | case 0x0008/4: |
| r5697 | r5698 | |
| 1109 | 1115 | if( (mem_mask) & 0x0000ffff ) |
| 1110 | 1116 | { |
| 1111 | 1117 | verboselog(machine, 2, "GBA IO Register Write: BG2X_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1112 | | gba_state->BG2X = ( gba_state->BG2X & ~mem_mask ) | ( data & mem_mask ); |
| 1113 | 1118 | } |
| 1114 | 1119 | if( (mem_mask) & 0xffff0000 ) |
| 1115 | 1120 | { |
| 1116 | 1121 | verboselog(machine, 2, "GBA IO Register Write: BG2X_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1117 | | gba_state->BG2X = ( gba_state->BG2X & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1118 | 1122 | } |
| 1123 | COMBINE_DATA(&gba_state->BG2X); |
| 1124 | gba_state->gfxBG2Changed |= 1; |
| 1119 | 1125 | break; |
| 1120 | 1126 | case 0x002c/4: |
| 1121 | 1127 | if( (mem_mask) & 0x0000ffff ) |
| 1122 | 1128 | { |
| 1123 | 1129 | verboselog(machine, 2, "GBA IO Register Write: BG2Y_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1124 | | gba_state->BG2Y = ( gba_state->BG2Y & ~mem_mask ) | ( data & mem_mask ); |
| 1125 | 1130 | } |
| 1126 | 1131 | if( (mem_mask) & 0xffff0000 ) |
| 1127 | 1132 | { |
| 1128 | 1133 | verboselog(machine, 2, "GBA IO Register Write: BG2Y_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1129 | | gba_state->BG2Y = ( gba_state->BG2Y & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1130 | 1134 | } |
| 1135 | COMBINE_DATA(&gba_state->BG2Y); |
| 1136 | gba_state->gfxBG2Changed |= 2; |
| 1131 | 1137 | break; |
| 1132 | 1138 | case 0x0030/4: |
| 1133 | 1139 | if( (mem_mask) & 0x0000ffff ) |
| r5697 | r5698 | |
| 1157 | 1163 | if( (mem_mask) & 0x0000ffff ) |
| 1158 | 1164 | { |
| 1159 | 1165 | verboselog(machine, 2, "GBA IO Register Write: BG3X_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1160 | | gba_state->BG3X = ( gba_state->BG3X & ~mem_mask ) | ( data & mem_mask ); |
| 1161 | 1166 | } |
| 1162 | 1167 | if( (mem_mask) & 0xffff0000 ) |
| 1163 | 1168 | { |
| 1164 | 1169 | verboselog(machine, 2, "GBA IO Register Write: BG3X_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1165 | | gba_state->BG3X = ( gba_state->BG3X & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1166 | 1170 | } |
| 1171 | COMBINE_DATA(&gba_state->BG3X); |
| 1172 | gba_state->gfxBG3Changed |= 1; |
| 1167 | 1173 | break; |
| 1168 | 1174 | case 0x003c/4: |
| 1169 | 1175 | if( (mem_mask) & 0x0000ffff ) |
| 1170 | 1176 | { |
| 1171 | 1177 | verboselog(machine, 2, "GBA IO Register Write: BG3Y_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1172 | | gba_state->BG3Y = ( gba_state->BG3Y & ~mem_mask ) | ( data & mem_mask ); |
| 1173 | 1178 | } |
| 1174 | 1179 | if( (mem_mask) & 0xffff0000 ) |
| 1175 | 1180 | { |
| 1176 | 1181 | verboselog(machine, 2, "GBA IO Register Write: BG3Y_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1177 | | gba_state->BG3Y = ( gba_state->BG3Y & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1178 | 1182 | } |
| 1183 | COMBINE_DATA(&gba_state->BG3Y); |
| 1184 | gba_state->gfxBG3Changed |= 2; |
| 1179 | 1185 | break; |
| 1180 | 1186 | case 0x0040/4: |
| 1181 | 1187 | if( (mem_mask) & 0x0000ffff ) |
| r5697 | r5698 | |
| 1229 | 1235 | { |
| 1230 | 1236 | verboselog(machine, 2, "GBA IO Register Write: BLDCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1231 | 1237 | gba_state->BLDCNT = ( gba_state->BLDCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1238 | if(gba_state->BLDCNT & BLDCNT_SFX) |
| 1239 | { |
| 1240 | gba_state->fxOn = 1; |
| 1241 | } |
| 1242 | else |
| 1243 | { |
| 1244 | gba_state->fxOn = 0; |
| 1245 | } |
| 1232 | 1246 | } |
| 1233 | 1247 | if( (mem_mask) & 0xffff0000 ) |
| 1234 | 1248 | { |
| r5697 | r5698 | |
| 1375 | 1389 | { |
| 1376 | 1390 | const device_config *gb_a_l = devtag_get_device(machine, "direct_a_left"); |
| 1377 | 1391 | const device_config *gb_a_r = devtag_get_device(machine, "direct_a_right"); |
| 1378 | | |
| 1392 | |
| 1379 | 1393 | gba_state->fifo_a_ptr = 17; |
| 1380 | 1394 | gba_state->fifo_a_in = 17; |
| 1381 | 1395 | dac_signed_data_w(gb_a_l, 0x80); |
| r5697 | r5698 | |
| 1387 | 1401 | { |
| 1388 | 1402 | const device_config *gb_b_l = devtag_get_device(machine, "direct_b_left"); |
| 1389 | 1403 | const device_config *gb_b_r = devtag_get_device(machine, "direct_b_right"); |
| 1390 | | |
| 1404 | |
| 1391 | 1405 | gba_state->fifo_b_ptr = 17; |
| 1392 | 1406 | gba_state->fifo_b_in = 17; |
| 1393 | 1407 | dac_signed_data_w(gb_b_l, 0x80); |
| r5697 | r5698 | |
| 1734 | 1748 | // if we still have interrupts, yank the IRQ line again |
| 1735 | 1749 | if (gba_state->IF) |
| 1736 | 1750 | { |
| 1737 | | timer_adjust_oneshot(gba_state->irq_timer, cpu_clocks_to_attotime(machine->firstcpu, 120), 0); |
| 1751 | timer_adjust_oneshot(gba_state->irq_timer, cpu_clocks_to_attotime(cputag_get_cpu(machine, "maincpu"), 120), 0); |
| 1738 | 1752 | } |
| 1739 | 1753 | } |
| 1740 | 1754 | break; |
| r5697 | r5698 | |
| 1777 | 1791 | gba_state->HALTCNT = data & 0x000000ff; |
| 1778 | 1792 | |
| 1779 | 1793 | // either way, wait for an IRQ |
| 1780 | | cpu_spinuntil_int(machine->firstcpu); |
| 1794 | cpu_spinuntil_int(cputag_get_cpu(machine, "maincpu")); |
| 1781 | 1795 | } |
| 1782 | 1796 | } |
| 1783 | 1797 | if( (mem_mask) & 0xffff0000 ) |
| r5697 | r5698 | |
| 1791 | 1805 | } |
| 1792 | 1806 | } |
| 1793 | 1807 | |
| 1808 | INLINE UINT32 COMBINE_DATA32_16(UINT32 prev, UINT32 data, UINT32 mem_mask) |
| 1809 | { |
| 1810 | COMBINE_DATA(&prev); |
| 1811 | switch(mem_mask) |
| 1812 | { |
| 1813 | case 0x000000ff: |
| 1814 | prev &= 0xffff00ff; |
| 1815 | prev |= data << 8; |
| 1816 | break; |
| 1817 | case 0x0000ff00: |
| 1818 | prev &= 0xffffff00; |
| 1819 | prev |= data >> 8; |
| 1820 | break; |
| 1821 | case 0x00ff0000: |
| 1822 | prev &= 0x00ffffff; |
| 1823 | prev |= data << 8; |
| 1824 | break; |
| 1825 | case 0xff000000: |
| 1826 | prev &= 0xffffffff; |
| 1827 | prev |= data << 8; |
| 1828 | break; |
| 1829 | default: |
| 1830 | break; |
| 1831 | } |
| 1832 | return prev; |
| 1833 | } |
| 1834 | |
| 1835 | static WRITE32_HANDLER(gba_pram_w) |
| 1836 | { |
| 1837 | running_machine *machine = space->machine; |
| 1838 | gba_state *gba_state = machine->driver_data; |
| 1839 | |
| 1840 | gba_state->gba_pram[offset] = COMBINE_DATA32_16(gba_state->gba_pram[offset], data, mem_mask); |
| 1841 | } |
| 1842 | |
| 1843 | static WRITE32_HANDLER(gba_vram_w) |
| 1844 | { |
| 1845 | running_machine *machine = space->machine; |
| 1846 | gba_state *gba_state = machine->driver_data; |
| 1847 | |
| 1848 | gba_state->gba_vram[offset] = COMBINE_DATA32_16(gba_state->gba_vram[offset], data, mem_mask); |
| 1849 | } |
| 1850 | |
| 1851 | static WRITE32_HANDLER(gba_oam_w) |
| 1852 | { |
| 1853 | running_machine *machine = space->machine; |
| 1854 | gba_state *gba_state = machine->driver_data; |
| 1855 | |
| 1856 | gba_state->gba_oam[offset] = COMBINE_DATA32_16(gba_state->gba_oam[offset], data, mem_mask); |
| 1857 | } |
| 1858 | |
| 1794 | 1859 | static ADDRESS_MAP_START( gbadvance_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 1795 | 1860 | AM_RANGE(0x00000000, 0x00003fff) AM_ROMBANK(1) |
| 1796 | 1861 | AM_RANGE(0x02000000, 0x0203ffff) AM_RAM AM_MIRROR(0xfc0000) |
| 1797 | 1862 | AM_RANGE(0x03000000, 0x03007fff) AM_RAM AM_MIRROR(0xff8000) |
| 1798 | 1863 | AM_RANGE(0x04000000, 0x040003ff) AM_READWRITE( gba_io_r, gba_io_w ) |
| 1799 | | AM_RANGE(0x05000000, 0x050003ff) AM_RAM AM_BASE_MEMBER(gba_state, gba_pram) // Palette RAM |
| 1800 | | AM_RANGE(0x06000000, 0x06017fff) AM_RAM AM_BASE_MEMBER(gba_state, gba_vram) // VRAM |
| 1801 | | AM_RANGE(0x07000000, 0x070003ff) AM_RAM AM_BASE_MEMBER(gba_state, gba_oam) // OAM |
| 1864 | AM_RANGE(0x05000000, 0x050003ff) AM_RAM_WRITE(gba_pram_w) AM_BASE_MEMBER(gba_state, gba_pram) // Palette RAM |
| 1865 | AM_RANGE(0x06000000, 0x06017fff) AM_RAM_WRITE(gba_vram_w) AM_BASE_MEMBER(gba_state, gba_vram) // VRAM |
| 1866 | AM_RANGE(0x07000000, 0x070003ff) AM_RAM_WRITE(gba_oam_w) AM_BASE_MEMBER(gba_state, gba_oam) // OAM |
| 1802 | 1867 | AM_RANGE(0x08000000, 0x09ffffff) AM_ROM AM_REGION("cartridge", 0) // cartridge ROM (mirror 0) |
| 1803 | 1868 | AM_RANGE(0x0a000000, 0x0bffffff) AM_ROM AM_REGION("cartridge", 0) // cartridge ROM (mirror 1) |
| 1804 | 1869 | AM_RANGE(0x0c000000, 0x0cffffff) AM_ROM AM_REGION("cartridge", 0) // final mirror |
| r5697 | r5698 | |
| 1824 | 1889 | int ch, ctrl; |
| 1825 | 1890 | gba_state *gba_state = machine->driver_data; |
| 1826 | 1891 | int scanline = video_screen_get_vpos(machine->primary_screen); |
| 1827 | | |
| 1892 | |
| 1828 | 1893 | // draw only visible scanlines |
| 1829 | 1894 | if (scanline < 160) |
| 1830 | 1895 | { |
| r5697 | r5698 | |
| 1881 | 1946 | } |
| 1882 | 1947 | |
| 1883 | 1948 | // entering VBL, handle interrupts and DMA triggers |
| 1884 | | if (scanline == 160) |
| 1949 | if (scanline == 0) |
| 1885 | 1950 | { |
| 1886 | 1951 | int ch, ctrl; |
| 1887 | 1952 | |
| r5697 | r5698 | |
| 1925 | 1990 | gba_state->KEYCNT = 0x03ff; |
| 1926 | 1991 | gba_state->RCNT = 0x8000; |
| 1927 | 1992 | gba_state->JOYSTAT = 0x0002; |
| 1993 | gba_state->gfxBG2Changed = 0; |
| 1994 | gba_state->gfxBG3Changed = 0; |
| 1995 | gba_state->gfxBG2X = 0; |
| 1996 | gba_state->gfxBG2Y = 0; |
| 1997 | gba_state->gfxBG3X = 0; |
| 1998 | gba_state->gfxBG3Y = 0; |
| 1928 | 1999 | |
| 2000 | gba_state->windowOn = 0; |
| 2001 | gba_state->fxOn = 0; |
| 2002 | |
| 1929 | 2003 | timer_adjust_oneshot(gba_state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); |
| 1930 | 2004 | timer_adjust_oneshot(gba_state->hbl_timer, attotime_never, 0); |
| 1931 | 2005 | timer_adjust_oneshot(gba_state->dma_timer[0], attotime_never, 0); |
| r5697 | r5698 | |
| 2265 | 2339 | |
| 2266 | 2340 | if (gba_state->eeprom_bits == 0) |
| 2267 | 2341 | { |
| 2268 | | mame_printf_verbose("%08x: EEPROM: %02x to %x\n", cpu_get_pc(space-> machine->firstcpu), gba_state->eep_data, gba_state->eeprom_addr ); |
| 2342 | mame_printf_verbose("%08x: EEPROM: %02x to %x\n", cpu_get_pc(cputag_get_cpu(space->machine, "maincpu")), gba_state->eep_data, gba_state->eeprom_addr ); |
| 2269 | 2343 | gba_state->gba_eeprom[gba_state->eeprom_addr] = gba_state->eep_data; |
| 2270 | 2344 | gba_state->eeprom_addr++; |
| 2271 | 2345 | gba_state->eep_data = 0; |
| r5697 | r5698 | |
| 2304 | 2378 | |
| 2305 | 2379 | if (image_length(image) <= (16*1024*1024)) |
| 2306 | 2380 | { |
| 2307 | | memory_install_read32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_r); |
| 2308 | | memory_install_write32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_w); |
| 2381 | memory_install_read32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_r); |
| 2382 | memory_install_write32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xd000000, 0xdffffff, 0, 0, eeprom_w); |
| 2309 | 2383 | } |
| 2310 | 2384 | else |
| 2311 | 2385 | { |
| 2312 | | memory_install_read32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_r); |
| 2313 | | memory_install_write32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_w); |
| 2386 | memory_install_read32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_r); |
| 2387 | memory_install_write32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xdffff00, 0xdffffff, 0, 0, eeprom_w); |
| 2314 | 2388 | } |
| 2315 | 2389 | break; |
| 2316 | 2390 | } |
| r5697 | r5698 | |
| 2319 | 2393 | nvptr = (UINT8 *)&gba_state->gba_sram; |
| 2320 | 2394 | nvsize = 0x10000; |
| 2321 | 2395 | |
| 2322 | | memory_install_read32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_r); |
| 2323 | | memory_install_write32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_w); |
| 2396 | memory_install_read32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_r); |
| 2397 | memory_install_write32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_w); |
| 2324 | 2398 | break; |
| 2325 | 2399 | } |
| 2326 | 2400 | else if (!memcmp(&ROM[i], "FLASH1M_", 8)) |
| r5697 | r5698 | |
| 2333 | 2407 | nvptr = (UINT8 *)&gba_state->gba_flash64k; |
| 2334 | 2408 | nvsize = 0x10000; |
| 2335 | 2409 | |
| 2336 | | memory_install_read32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_r); |
| 2337 | | memory_install_write32_handler(cpu_get_address_space(image->machine->firstcpu, ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_w); |
| 2410 | memory_install_read32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_r); |
| 2411 | memory_install_write32_handler(cpu_get_address_space(cputag_get_cpu(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_w); |
| 2338 | 2412 | break; |
| 2339 | 2413 | } |
| 2340 | 2414 | else if (!memcmp(&ROM[i], "SIIRTC_V", 8)) |
| r5697 | r5698 | |
| 2431 | 2505 | |
| 2432 | 2506 | static DRIVER_INIT(gbadv) |
| 2433 | 2507 | { |
| 2434 | | memory_set_direct_update_handler( cpu_get_address_space(machine->firstcpu, ADDRESS_SPACE_PROGRAM), gba_direct ); |
| 2508 | memory_set_direct_update_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), gba_direct ); |
| 2435 | 2509 | } |
| 2436 | 2510 | |
| 2437 | 2511 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |