trunk/src/mame/video/seibuspi.c
| r31933 | r31934 | |
| 229 | 229 | |
| 230 | 230 | /*****************************************************************************/ |
| 231 | 231 | |
| 232 | | void seibuspi_state::drawgfx_blend(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy) |
| 232 | void seibuspi_state::drawgfx_blend(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, UINT32 code, UINT32 color, int flipx, int flipy, int sx, int sy, bitmap_ind8 &primap, int primask) |
| 233 | 233 | { |
| 234 | | const pen_t *pens = &m_palette->pen(gfx->colorbase()); |
| 235 | | const UINT8 *dp; |
| 236 | | int i, j; |
| 237 | | int x1, x2; |
| 238 | | int y1, y2; |
| 239 | | int px, py; |
| 240 | | int xd = 1, yd = 1; |
| 241 | | |
| 242 | 234 | int width = gfx->width(); |
| 243 | 235 | int height = gfx->height(); |
| 244 | 236 | |
| 245 | | x1 = sx; |
| 246 | | x2 = sx + width - 1; |
| 247 | | y1 = sy; |
| 248 | | y2 = sy + height - 1; |
| 237 | int x1 = sx; |
| 238 | int x2 = sx + width - 1; |
| 239 | int y1 = sy; |
| 240 | int y2 = sy + height - 1; |
| 249 | 241 | |
| 250 | 242 | if (x1 > cliprect.max_x || x2 < cliprect.min_x) |
| 251 | 243 | { |
| r31933 | r31934 | |
| 256 | 248 | return; |
| 257 | 249 | } |
| 258 | 250 | |
| 259 | | px = 0; |
| 260 | | py = 0; |
| 251 | int px = 0; |
| 252 | int py = 0; |
| 253 | int xd = 1; |
| 254 | int yd = 1; |
| 261 | 255 | |
| 262 | 256 | if (flipx) |
| 263 | 257 | { |
| r31933 | r31934 | |
| 306 | 300 | y2 = cliprect.max_y; |
| 307 | 301 | } |
| 308 | 302 | |
| 309 | | dp = gfx->get_data(code); |
| 303 | const pen_t *pens = &m_palette->pen(gfx->colorbase()); |
| 304 | const UINT8 *src = gfx->get_data(code); |
| 310 | 305 | |
| 311 | 306 | // draw |
| 312 | | for (j = y1; j <= y2; j++) |
| 307 | for (int y = y1; y <= y2; y++) |
| 313 | 308 | { |
| 314 | | UINT32 *p = &bitmap.pix32(j); |
| 309 | UINT32 *dest = &bitmap.pix32(y); |
| 310 | UINT8 *pri = &primap.pix8(y); |
| 315 | 311 | UINT8 trans_pen = (1 << m_sprite_bpp) - 1; |
| 316 | | int dp_i = (py * width) + px; |
| 312 | int src_i = (py * width) + px; |
| 317 | 313 | py += yd; |
| 318 | 314 | |
| 319 | | for (i = x1; i <= x2; i++) |
| 315 | for (int x = x1; x <= x2; x++) |
| 320 | 316 | { |
| 321 | | UINT8 pen = dp[dp_i]; |
| 322 | | if (pen != trans_pen) |
| 317 | UINT8 pen = src[src_i]; |
| 318 | if (!(pri[x] & primask) && pen != trans_pen) |
| 323 | 319 | { |
| 320 | pri[x] |= primask; |
| 324 | 321 | int global_pen = pen + (color << m_sprite_bpp); |
| 325 | 322 | if (m_alpha_enable && m_alpha_table[global_pen]) |
| 326 | | { |
| 327 | | p[i] = alpha_blend_r32(p[i], pens[global_pen], 0x7f); |
| 328 | | } |
| 323 | dest[x] = alpha_blend_r32(dest[x], pens[global_pen], 0x7f); |
| 329 | 324 | else |
| 330 | | { |
| 331 | | p[i] = pens[global_pen]; |
| 332 | | } |
| 325 | dest[x] = pens[global_pen]; |
| 333 | 326 | } |
| 334 | | dp_i += xd; |
| 327 | src_i += xd; |
| 335 | 328 | } |
| 336 | 329 | } |
| 337 | 330 | } |
| 338 | 331 | |
| 339 | | void seibuspi_state::draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, int pri_mask) |
| 332 | void seibuspi_state::draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, bitmap_ind8 &primap, int priority) |
| 340 | 333 | { |
| 341 | | INT16 xpos, ypos; |
| 342 | | int tile_num, color; |
| 343 | | int width, height; |
| 344 | | int flip_x, flip_y; |
| 345 | | int priority; |
| 346 | | int x1, y1; |
| 347 | 334 | gfx_element *gfx = m_gfxdecode->gfx(2); |
| 348 | 335 | const int has_tile_high = (gfx->elements() > 0x10000) ? 1 : 0; |
| 349 | 336 | const int colormask = (m_sprite_bpp == 6) ? 0x3f : 0x1f; |
| r31933 | r31934 | |
| 362 | 349 | if (m_layer_enable & 0x10) |
| 363 | 350 | return; |
| 364 | 351 | |
| 365 | | for (int a = m_sprite_ram_size / 4 - 2; a >= 0; a -= 2) |
| 352 | for (int a = 0; a < (m_sprite_ram_size / 4); a += 2) |
| 366 | 353 | { |
| 367 | 354 | /* |
| 368 | 355 | Word 0 |
| r31933 | r31934 | |
| 379 | 366 | -------- -------- ---x---- -------- tile_num high (only on RISE10/11 chip) |
| 380 | 367 | -------- -------- ------xx xxxxxxxx xpos |
| 381 | 368 | */ |
| 382 | | tile_num = m_sprite_ram[a + 0] >> 16 & 0xffff; |
| 369 | int tile_num = m_sprite_ram[a + 0] >> 16 & 0xffff; |
| 383 | 370 | if (tile_num == 0) |
| 384 | 371 | continue; |
| 385 | 372 | |
| 386 | 373 | if (has_tile_high) |
| 387 | 374 | tile_num |= m_sprite_ram[a + 1] << 4 & 0x10000; |
| 388 | 375 | |
| 389 | | priority = m_sprite_ram[a + 0] >> 6 & 0x3; |
| 390 | | if (pri_mask != priority) |
| 376 | if (priority != (m_sprite_ram[a + 0] >> 6 & 0x3)) |
| 391 | 377 | continue; |
| 378 | int primask = 1 << priority; |
| 392 | 379 | |
| 393 | | xpos = m_sprite_ram[a + 1] & 0x3ff; |
| 380 | INT16 xpos = m_sprite_ram[a + 1] & 0x3ff; |
| 394 | 381 | if (xpos & 0x200) |
| 395 | 382 | xpos |= 0xfc00; |
| 396 | | ypos = m_sprite_ram[a + 1] >> 16 & 0x1ff; |
| 383 | INT16 ypos = m_sprite_ram[a + 1] >> 16 & 0x1ff; |
| 397 | 384 | if (ypos & 0x100) |
| 398 | 385 | ypos |= 0xfe00; |
| 399 | | color = m_sprite_ram[a + 0] & colormask; |
| 386 | int color = m_sprite_ram[a + 0] & colormask; |
| 400 | 387 | |
| 401 | | width = (m_sprite_ram[a + 0] >> 8 & 0x7) + 1; |
| 402 | | height = (m_sprite_ram[a + 0] >> 12 & 0x7) + 1; |
| 403 | | flip_x = m_sprite_ram[a + 0] >> 11 & 0x1; |
| 404 | | flip_y = m_sprite_ram[a + 0] >> 15 & 0x1; |
| 405 | | x1 = 0; |
| 406 | | y1 = 0; |
| 388 | int width = (m_sprite_ram[a + 0] >> 8 & 0x7) + 1; |
| 389 | int height = (m_sprite_ram[a + 0] >> 12 & 0x7) + 1; |
| 390 | int flip_x = m_sprite_ram[a + 0] >> 11 & 0x1; |
| 391 | int flip_y = m_sprite_ram[a + 0] >> 15 & 0x1; |
| 392 | int x1 = 0; |
| 393 | int y1 = 0; |
| 407 | 394 | |
| 408 | 395 | if (flip_x) |
| 409 | 396 | { |
| r31933 | r31934 | |
| 420 | 407 | { |
| 421 | 408 | for (int y = y1; y < height; y++) |
| 422 | 409 | { |
| 423 | | drawgfx_blend(bitmap, cliprect, gfx, tile_num, color, flip_x, flip_y, xpos + sprite_xtable[flip_x][x], ypos + sprite_ytable[flip_y][y]); |
| 410 | drawgfx_blend(bitmap, cliprect, gfx, tile_num, color, flip_x, flip_y, xpos + sprite_xtable[flip_x][x], ypos + sprite_ytable[flip_y][y], primap, primask); |
| 424 | 411 | |
| 425 | 412 | /* xpos seems to wrap-around to 0 at 512 */ |
| 426 | 413 | if ((xpos + (16 * x) + 16) >= 512) |
| 427 | | { |
| 428 | | drawgfx_blend(bitmap, cliprect, gfx, tile_num, color, flip_x, flip_y, xpos - 512 + sprite_xtable[flip_x][x], ypos + sprite_ytable[flip_y][y]); |
| 429 | | } |
| 414 | drawgfx_blend(bitmap, cliprect, gfx, tile_num, color, flip_x, flip_y, xpos - 512 + sprite_xtable[flip_x][x], ypos + sprite_ytable[flip_y][y], primap, primask); |
| 430 | 415 | |
| 431 | 416 | tile_num++; |
| 432 | 417 | } |
| r31933 | r31934 | |
| 434 | 419 | } |
| 435 | 420 | } |
| 436 | 421 | |
| 437 | | void seibuspi_state::combine_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect, tilemap_t *tile, int x, int y, int opaque, INT16 *rowscroll) |
| 422 | void seibuspi_state::combine_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect, tilemap_t *tile, int sx, int sy, int opaque, INT16 *rowscroll) |
| 438 | 423 | { |
| 439 | | UINT16 *s; |
| 440 | | UINT32 *d; |
| 441 | | UINT8 *t; |
| 424 | UINT16 *src; |
| 425 | UINT32 *dest; |
| 426 | UINT8 *flags; |
| 442 | 427 | UINT32 xscroll_mask, yscroll_mask; |
| 443 | 428 | |
| 444 | 429 | bitmap_ind16 &pen_bitmap = tile->pixmap(); |
| r31933 | r31934 | |
| 446 | 431 | xscroll_mask = pen_bitmap.width() - 1; |
| 447 | 432 | yscroll_mask = pen_bitmap.height() - 1; |
| 448 | 433 | |
| 449 | | for (int j = cliprect.min_y; j <= cliprect.max_y; j++) |
| 434 | for (int y = cliprect.min_y; y <= cliprect.max_y; y++) |
| 450 | 435 | { |
| 451 | | int rx = x; |
| 436 | int rx = sx; |
| 452 | 437 | if (rowscroll) |
| 453 | 438 | { |
| 454 | | rx += rowscroll[(j+y) & yscroll_mask]; |
| 439 | rx += rowscroll[(y + sy) & yscroll_mask]; |
| 455 | 440 | } |
| 456 | 441 | |
| 457 | | d = &bitmap.pix32(j); |
| 458 | | s = &pen_bitmap.pix16((j+y) & yscroll_mask); |
| 459 | | t = &flags_bitmap.pix8((j+y) & yscroll_mask); |
| 460 | | for (int i = cliprect.min_x+rx; i <= cliprect.max_x+rx; i++) |
| 442 | dest = &bitmap.pix32(y); |
| 443 | src = &pen_bitmap.pix16((y + sy) & yscroll_mask); |
| 444 | flags = &flags_bitmap.pix8((y + sy) & yscroll_mask); |
| 445 | for (int x = cliprect.min_x + rx; x <= cliprect.max_x + rx; x++) |
| 461 | 446 | { |
| 462 | | if (opaque || (t[i & xscroll_mask] & (TILEMAP_PIXEL_LAYER0 | TILEMAP_PIXEL_LAYER1))) |
| 447 | if (opaque || (flags[x & xscroll_mask] & (TILEMAP_PIXEL_LAYER0 | TILEMAP_PIXEL_LAYER1))) |
| 463 | 448 | { |
| 464 | | UINT16 pen = s[i & xscroll_mask]; |
| 449 | UINT16 pen = src[x & xscroll_mask]; |
| 465 | 450 | if (m_alpha_enable && m_alpha_table[pen]) |
| 466 | | { |
| 467 | | *d = alpha_blend_r32(*d, m_palette->pen(pen), 0x7f); |
| 468 | | } |
| 451 | *dest = alpha_blend_r32(*dest, m_palette->pen(pen), 0x7f); |
| 469 | 452 | else |
| 470 | | { |
| 471 | | *d = m_palette->pen(pen); |
| 472 | | } |
| 453 | *dest = m_palette->pen(pen); |
| 473 | 454 | } |
| 474 | | ++d; |
| 455 | dest++; |
| 475 | 456 | } |
| 476 | 457 | } |
| 477 | 458 | } |
| r31933 | r31934 | |
| 493 | 474 | fore_rowscroll = NULL; |
| 494 | 475 | } |
| 495 | 476 | |
| 477 | screen.priority().fill(0, cliprect); |
| 478 | |
| 496 | 479 | if (m_layer_enable & 1) |
| 497 | 480 | bitmap.fill(0, cliprect); |
| 498 | | |
| 499 | | if (~m_layer_enable & 1) |
| 481 | else |
| 500 | 482 | combine_tilemap(bitmap, cliprect, m_back_layer, m_scrollram[0] & 0xffff, (m_scrollram[0] >> 16) & 0xffff, 1, back_rowscroll); |
| 501 | 483 | |
| 502 | | draw_sprites(bitmap, cliprect, 0); |
| 484 | draw_sprites(bitmap, cliprect, screen.priority(), 0); |
| 503 | 485 | |
| 504 | 486 | // if fore layer is enabled, draw priority 0 sprites behind back layer |
| 505 | 487 | if ((m_layer_enable & 0x15) == 0) |
| r31933 | r31934 | |
| 507 | 489 | |
| 508 | 490 | // if fore layer is enabled, draw priority 1 sprites behind middle layer |
| 509 | 491 | if (~m_layer_enable & 4) |
| 510 | | draw_sprites(bitmap, cliprect, 1); |
| 492 | draw_sprites(bitmap, cliprect, screen.priority(), 1); |
| 511 | 493 | |
| 512 | 494 | if (~m_layer_enable & 2) |
| 513 | 495 | combine_tilemap(bitmap, cliprect, m_midl_layer, m_scrollram[1] & 0xffff, (m_scrollram[1] >> 16) & 0xffff, 0, midl_rowscroll); |
| 514 | 496 | |
| 515 | 497 | // if fore layer is disabled, draw priority 1 sprites above middle layer |
| 516 | 498 | if (m_layer_enable & 4) |
| 517 | | draw_sprites(bitmap, cliprect, 1); |
| 499 | draw_sprites(bitmap, cliprect, screen.priority(), 1); |
| 518 | 500 | |
| 519 | | draw_sprites(bitmap, cliprect, 2); |
| 501 | draw_sprites(bitmap, cliprect, screen.priority(), 2); |
| 520 | 502 | |
| 521 | 503 | if (~m_layer_enable & 4) |
| 522 | 504 | combine_tilemap(bitmap, cliprect, m_fore_layer, m_scrollram[2] & 0xffff, (m_scrollram[2] >> 16) & 0xffff, 0, fore_rowscroll); |
| 523 | 505 | |
| 524 | | draw_sprites(bitmap, cliprect, 3); |
| 506 | draw_sprites(bitmap, cliprect, screen.priority(), 3); |
| 525 | 507 | |
| 526 | 508 | if (~m_layer_enable & 8) |
| 527 | 509 | combine_tilemap(bitmap, cliprect, m_text_layer, 0, 0, 0, NULL); |
| r31933 | r31934 | |
| 531 | 513 | |
| 532 | 514 | UINT32 seibuspi_state::screen_update_sys386f(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 533 | 515 | { |
| 516 | screen.priority().fill(0, cliprect); |
| 534 | 517 | bitmap.fill(0, cliprect); |
| 535 | 518 | |
| 536 | | draw_sprites(bitmap, cliprect, 0); |
| 537 | | draw_sprites(bitmap, cliprect, 1); |
| 538 | | draw_sprites(bitmap, cliprect, 2); |
| 539 | | draw_sprites(bitmap, cliprect, 3); |
| 519 | draw_sprites(bitmap, cliprect, screen.priority(), 0); |
| 520 | draw_sprites(bitmap, cliprect, screen.priority(), 1); |
| 521 | draw_sprites(bitmap, cliprect, screen.priority(), 2); |
| 522 | draw_sprites(bitmap, cliprect, screen.priority(), 3); |
| 540 | 523 | |
| 541 | 524 | return 0; |
| 542 | 525 | } |