src/mame/video/gticlub.c
| r14632 | r14633 | |
| 6 | 6 | #include "video/konicdev.h" |
| 7 | 7 | #include "video/gticlub.h" |
| 8 | 8 | |
| 9 | /* |
| 10 | TODO: |
| 11 | - Fog equation and parameters are probably not accurate. |
| 12 | - Winding Heat (and maybe others) have slight Z-fighting problems. |
| 13 | - 3D isn't always turned off properly (during title screens for example). |
| 14 | Figure out what controls this. Video mixer, layer priority or some 3D register? |
| 9 | 15 | |
| 16 | */ |
| 17 | |
| 18 | #define POLY_Z 0 |
| 19 | #define POLY_BRI 2 |
| 20 | #define POLY_FOG 1 |
| 21 | #define POLY_U 3 |
| 22 | #define POLY_V 4 |
| 23 | #define POLY_W 5 |
| 24 | |
| 25 | #define ZBUFFER_MAX 10000000000.0f |
| 26 | |
| 27 | #define LOG_POLY_FIFO 0 |
| 28 | |
| 29 | #if LOG_POLY_FIFO |
| 30 | static int count = 0; |
| 31 | #endif |
| 32 | |
| 10 | 33 | typedef struct _poly_extra_data poly_extra_data; |
| 11 | 34 | struct _poly_extra_data |
| 12 | 35 | { |
| 13 | 36 | UINT32 color; |
| 14 | 37 | int texture_x, texture_y; |
| 38 | int texture_width, texture_height; |
| 15 | 39 | int texture_page; |
| 16 | 40 | int texture_palette; |
| 17 | 41 | int texture_mirror_x; |
| 18 | 42 | int texture_mirror_y; |
| 43 | int light_r, light_g, light_b; |
| 44 | int ambient_r, ambient_g, ambient_b; |
| 45 | int fog_r, fog_g, fog_b; |
| 46 | UINT32 flags; |
| 19 | 47 | }; |
| 20 | 48 | |
| 21 | 49 | static UINT8 gticlub_led_reg[2]; |
| r14632 | r14633 | |
| 120 | 148 | } |
| 121 | 149 | default: |
| 122 | 150 | { |
| 123 | | mame_printf_debug("K001006_w: chip %d, device %02X, write %04X to %08X\n", chip, K001006_device_sel[chip], data & 0xffff, K001006_addr[0]++); |
| 151 | //mame_printf_debug("K001006_w: chip %d, device %02X, write %04X to %08X\n", chip, K001006_device_sel[chip], data & 0xffff, K001006_addr[0]++); |
| 124 | 152 | } |
| 125 | 153 | } |
| 126 | 154 | } |
| r14632 | r14633 | |
| 181 | 209 | static UINT32 *K001005_3d_fifo; |
| 182 | 210 | static int K001005_3d_fifo_ptr = 0; |
| 183 | 211 | |
| 184 | | static int tex_mirror_table[4][128]; |
| 212 | static int *tex_mirror_table[2][8]; |
| 185 | 213 | |
| 186 | 214 | static int K001005_bitmap_page = 0; |
| 187 | 215 | |
| 188 | 216 | static poly_manager *poly; |
| 189 | 217 | static poly_vertex prev_v[4]; |
| 190 | | static int prev_poly_type; |
| 191 | 218 | |
| 219 | static UINT32 fog_r, fog_g, fog_b; |
| 220 | static UINT32 ambient_r, ambient_g, ambient_b; |
| 221 | static UINT32 light_r, light_g, light_b; |
| 222 | |
| 223 | static UINT32 reg_far_z; |
| 224 | static float far_z; |
| 225 | static float fog_density = 1.5f; |
| 226 | |
| 192 | 227 | static UINT8 *gfxrom; |
| 193 | 228 | |
| 194 | | |
| 195 | 229 | static void K001005_exit(running_machine &machine) |
| 196 | 230 | { |
| 197 | 231 | poly_free(poly); |
| r14632 | r14633 | |
| 199 | 233 | |
| 200 | 234 | void K001005_init(running_machine &machine) |
| 201 | 235 | { |
| 202 | | int i; |
| 236 | int i,k; |
| 203 | 237 | |
| 204 | 238 | int width = machine.primary_screen->width(); |
| 205 | 239 | int height = machine.primary_screen->height(); |
| r14632 | r14633 | |
| 219 | 253 | |
| 220 | 254 | K001005_3d_fifo = auto_alloc_array(machine, UINT32, 0x10000); |
| 221 | 255 | |
| 222 | | poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS); |
| 256 | poly = poly_alloc(machine, 10000, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS); |
| 223 | 257 | machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(K001005_exit), &machine)); |
| 224 | 258 | |
| 225 | | for (i=0; i < 128; i++) |
| 259 | for (k=0; k < 8; k++) |
| 226 | 260 | { |
| 227 | | tex_mirror_table[0][i] = i & 0x3f; |
| 228 | | tex_mirror_table[1][i] = i & 0x3f; |
| 229 | | tex_mirror_table[2][i] = ((i & 0x3f) >= 0x20) ? (0x1f - (i & 0x1f)) : i & 0x1f; |
| 230 | | tex_mirror_table[3][i] = ((i & 0x7f) >= 0x40) ? (0x3f - (i & 0x3f)) : i & 0x3f; |
| 261 | tex_mirror_table[0][k] = auto_alloc_array(machine, int, 128); |
| 262 | tex_mirror_table[1][k] = auto_alloc_array(machine, int, 128); |
| 263 | |
| 264 | int size = (k+1)*8; |
| 265 | |
| 266 | for (i=0; i < 128; i++) |
| 267 | { |
| 268 | tex_mirror_table[0][k][i] = i % size; |
| 269 | tex_mirror_table[1][k][i] = (i % (size*2)) >= size ? ((size - 1) - (i % size)) : i % size; |
| 270 | } |
| 231 | 271 | } |
| 232 | 272 | |
| 233 | 273 | K001005_status = 0; |
| r14632 | r14633 | |
| 237 | 277 | K001005_3d_fifo_ptr = 0; |
| 238 | 278 | K001005_bitmap_page = 0; |
| 239 | 279 | |
| 240 | | memset(prev_v, 0, sizeof(prev_v)); |
| 241 | | prev_poly_type = 0; |
| 280 | memset(prev_v, 0, sizeof(poly_vertex)*4); |
| 242 | 281 | } |
| 243 | 282 | |
| 244 | 283 | // rearranges the texture data to a more practical order |
| r14632 | r14633 | |
| 386 | 425 | K001005_fifo_write_ptr++; |
| 387 | 426 | K001005_fifo_write_ptr &= 0x7ff; |
| 388 | 427 | |
| 428 | // process the current vertex data if a sync command is being sent (usually means the global registers are being changed) |
| 429 | if (data == 0x80000000) |
| 430 | { |
| 431 | render_polygons(space->machine()); |
| 432 | K001005_3d_fifo_ptr = 0; |
| 433 | } |
| 434 | |
| 389 | 435 | K001005_3d_fifo[K001005_3d_fifo_ptr++] = data; |
| 390 | 436 | |
| 437 | #if LOG_POLY_FIFO |
| 438 | printf("0x%08X, ", data); |
| 439 | count++; |
| 440 | if (count >= 8) |
| 441 | { |
| 442 | count = 0; |
| 443 | printf("\n"); |
| 444 | } |
| 445 | #endif |
| 446 | |
| 391 | 447 | // !!! HACK to get past the FIFO B test (GTI Club & Thunder Hurricane) !!! |
| 392 | 448 | if (cpu_get_pc(&space->device()) == 0x201ee) |
| 393 | 449 | { |
| r14632 | r14633 | |
| 404 | 460 | break; |
| 405 | 461 | } |
| 406 | 462 | |
| 407 | | case 0x100: break; |
| 463 | case 0x100: break; |
| 408 | 464 | |
| 409 | | // case 0x10a: poly_r = data & 0xff; break; |
| 410 | | // case 0x10b: poly_g = data & 0xff; break; |
| 411 | | // case 0x10c: poly_b = data & 0xff; break; |
| 465 | case 0x101: break; // viewport x and width? |
| 466 | case 0x102: break; // viewport y and height? |
| 412 | 467 | |
| 468 | case 0x104: break; // viewport center x? (usually 0xff) |
| 469 | case 0x105: break; // viewport center y? (usually 0xbf) |
| 470 | |
| 471 | case 0x108: // far Z value, 4 exponent bits? |
| 472 | { |
| 473 | // this register seems to hold the 4 missing exponent bits... |
| 474 | reg_far_z = (reg_far_z & 0x0000ffff) | ((data & 0xf) << 16); |
| 475 | UINT32 fz = reg_far_z << 11; |
| 476 | far_z = *(float*)&fz; |
| 477 | if (far_z == 0.0f) // just in case... |
| 478 | far_z = 1.0f; |
| 479 | break; |
| 480 | } |
| 481 | |
| 482 | case 0x109: // far Z value |
| 483 | { |
| 484 | // the SHARC code throws away the bottom 11 bits of mantissa and the top 5 bits (to fit in a 16-bit register?) |
| 485 | reg_far_z = (reg_far_z & 0xffff0000) | (data & 0xffff); |
| 486 | UINT32 fz = reg_far_z << 11; |
| 487 | far_z = *(float*)&fz; |
| 488 | if (far_z == 0.0f) // just in case... |
| 489 | far_z = 1.0f; |
| 490 | break; |
| 491 | } |
| 492 | |
| 493 | case 0x10a: light_r = data & 0xff; break; |
| 494 | case 0x10b: light_g = data & 0xff; break; |
| 495 | case 0x10c: light_b = data & 0xff; break; |
| 496 | |
| 497 | case 0x10d: ambient_r = data & 0xff; break; |
| 498 | case 0x10e: ambient_g = data & 0xff; break; |
| 499 | case 0x10f: ambient_b = data & 0xff; break; |
| 500 | |
| 501 | case 0x110: fog_r = data & 0xff; break; |
| 502 | case 0x111: fog_g = data & 0xff; break; |
| 503 | case 0x112: fog_b = data & 0xff; break; |
| 504 | |
| 413 | 505 | case 0x11a: |
| 414 | 506 | K001005_status = data; |
| 415 | 507 | K001005_fifo_write_ptr = 0; |
| r14632 | r14633 | |
| 417 | 509 | |
| 418 | 510 | if (data == 2 && K001005_3d_fifo_ptr > 0) |
| 419 | 511 | { |
| 420 | | K001005_swap_buffers(space->machine()); |
| 421 | 512 | render_polygons(space->machine()); |
| 422 | 513 | poly_wait(poly, "render_polygons"); |
| 514 | |
| 515 | #if LOG_POLY_FIFO |
| 516 | count = 0; |
| 517 | printf("\nrender %d\n", K001005_3d_fifo_ptr); |
| 518 | printf("------------------------------------\n"); |
| 519 | #endif |
| 520 | |
| 423 | 521 | K001005_3d_fifo_ptr = 0; |
| 522 | K001005_swap_buffers(space->machine()); |
| 424 | 523 | } |
| 425 | 524 | break; |
| 426 | 525 | |
| r14632 | r14633 | |
| 451 | 550 | |
| 452 | 551 | } |
| 453 | 552 | |
| 553 | static void draw_scanline_2d(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid) |
| 554 | { |
| 555 | const poly_extra_data *extra = (const poly_extra_data *)extradata; |
| 556 | bitmap_rgb32 *destmap = (bitmap_rgb32 *)dest; |
| 557 | UINT32 *fb = &destmap->pix32(scanline); |
| 558 | float *zb = (float*)&K001005_zbuffer->pix32(scanline); |
| 559 | UINT32 color = extra->color; |
| 560 | int x; |
| 561 | |
| 562 | for (x = extent->startx; x < extent->stopx; x++) |
| 563 | { |
| 564 | if (color & 0xff000000) |
| 565 | { |
| 566 | fb[x] = color; |
| 567 | zb[x] = 0x7fffffff; // FIXME |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | static void draw_scanline_2d_tex(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid) |
| 573 | { |
| 574 | const poly_extra_data *extra = (const poly_extra_data *)extradata; |
| 575 | bitmap_rgb32 *destmap = (bitmap_rgb32 *)dest; |
| 576 | UINT8 *texrom = gfxrom + (extra->texture_page * 0x40000); |
| 577 | int pal_chip = (extra->texture_palette & 0x8) ? 1 : 0; |
| 578 | int palette_index = (extra->texture_palette & 0x7) * 256; |
| 579 | float u = extent->param[POLY_U].start; |
| 580 | float v = extent->param[POLY_V].start; |
| 581 | float du = extent->param[POLY_U].dpdx; |
| 582 | float dv = extent->param[POLY_V].dpdx; |
| 583 | UINT32 *fb = &destmap->pix32(scanline); |
| 584 | float *zb = (float*)&K001005_zbuffer->pix32(scanline); |
| 585 | UINT32 color = extra->color; |
| 586 | int texture_mirror_x = extra->texture_mirror_x; |
| 587 | int texture_mirror_y = extra->texture_mirror_y; |
| 588 | int texture_x = extra->texture_x; |
| 589 | int texture_y = extra->texture_y; |
| 590 | int texture_width = extra->texture_width; |
| 591 | int texture_height = extra->texture_height; |
| 592 | int x; |
| 593 | |
| 594 | int *x_mirror_table = tex_mirror_table[texture_mirror_x][texture_width]; |
| 595 | int *y_mirror_table = tex_mirror_table[texture_mirror_y][texture_height]; |
| 596 | |
| 597 | for (x = extent->startx; x < extent->stopx; x++) |
| 598 | { |
| 599 | int iu = (int)(u); |
| 600 | int iv = (int)(v); |
| 601 | int iiv, iiu, texel; |
| 602 | |
| 603 | iiu = texture_x + x_mirror_table[(iu >> 4) & 0x7f]; |
| 604 | iiv = texture_y + y_mirror_table[(iv >> 4) & 0x7f]; |
| 605 | |
| 606 | texel = texrom[((iiv & 0x1ff) * 512) + (iiu & 0x1ff)]; |
| 607 | color = K001006_palette[pal_chip][palette_index + texel]; |
| 608 | |
| 609 | if (color & 0xff000000) |
| 610 | { |
| 611 | fb[x] = color; |
| 612 | zb[x] = 0x7fffffff; // FIXME |
| 613 | } |
| 614 | |
| 615 | u += du; |
| 616 | v += dv; |
| 617 | } |
| 618 | } |
| 619 | |
| 454 | 620 | static void draw_scanline(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid) |
| 455 | 621 | { |
| 456 | 622 | const poly_extra_data *extra = (const poly_extra_data *)extradata; |
| 457 | 623 | bitmap_rgb32 *destmap = (bitmap_rgb32 *)dest; |
| 458 | | float z = extent->param[0].start; |
| 459 | | float dz = extent->param[0].dpdx; |
| 624 | float z = extent->param[POLY_Z].start; |
| 625 | float dz = extent->param[POLY_Z].dpdx; |
| 626 | float bri = extent->param[POLY_BRI].start; |
| 627 | float dbri = extent->param[POLY_BRI].dpdx; |
| 628 | float fog = extent->param[POLY_FOG].start; |
| 629 | float dfog = extent->param[POLY_FOG].dpdx; |
| 460 | 630 | UINT32 *fb = &destmap->pix32(scanline); |
| 461 | | UINT32 *zb = &K001005_zbuffer->pix32(scanline); |
| 631 | float *zb = (float*)&K001005_zbuffer->pix32(scanline); |
| 462 | 632 | UINT32 color = extra->color; |
| 463 | 633 | int x; |
| 464 | 634 | |
| 635 | int poly_light_r = extra->light_r + extra->ambient_r; |
| 636 | int poly_light_g = extra->light_g + extra->ambient_g; |
| 637 | int poly_light_b = extra->light_b + extra->ambient_b; |
| 638 | if (poly_light_r > 255) poly_light_r = 255; |
| 639 | if (poly_light_g > 255) poly_light_g = 255; |
| 640 | if (poly_light_b > 255) poly_light_b = 255; |
| 641 | int poly_fog_r = extra->fog_r; |
| 642 | int poly_fog_g = extra->fog_g; |
| 643 | int poly_fog_b = extra->fog_b; |
| 644 | |
| 465 | 645 | for (x = extent->startx; x < extent->stopx; x++) |
| 466 | 646 | { |
| 467 | | UINT32 iz = (UINT32)z >> 16; |
| 647 | int ibri = (int)(bri); |
| 648 | int ifog = (int)(fog); |
| 468 | 649 | |
| 469 | | if (iz <= zb[x]) |
| 650 | if (ibri < 0) ibri = 0; if (ibri > 255) ibri = 255; |
| 651 | if (ifog < 0) ifog = 0; if (ifog > 65536) ifog = 65536; |
| 652 | |
| 653 | if (z <= zb[x]) |
| 470 | 654 | { |
| 471 | 655 | if (color & 0xff000000) |
| 472 | 656 | { |
| 473 | | fb[x] = color; |
| 474 | | zb[x] = iz; |
| 657 | int r = (color >> 16) & 0xff; |
| 658 | int g = (color >> 8) & 0xff; |
| 659 | int b = color & 0xff; |
| 660 | |
| 661 | r = ((((r * poly_light_r * ibri) >> 16) * ifog) + (poly_fog_r * (65536 - ifog))) >> 16; |
| 662 | g = ((((g * poly_light_g * ibri) >> 16) * ifog) + (poly_fog_g * (65536 - ifog))) >> 16; |
| 663 | b = ((((b * poly_light_b * ibri) >> 16) * ifog) + (poly_fog_b * (65536 - ifog))) >> 16; |
| 664 | |
| 665 | if (r < 0) r = 0; if (r > 255) r = 255; |
| 666 | if (g < 0) g = 0; if (g > 255) g = 255; |
| 667 | if (b < 0) b = 0; if (b > 255) b = 255; |
| 668 | |
| 669 | fb[x] = (color & 0xff000000) | (r << 16) | (g << 8) | b; |
| 670 | zb[x] = z; |
| 475 | 671 | } |
| 476 | 672 | } |
| 477 | 673 | |
| 478 | 674 | z += dz; |
| 675 | bri += dbri; |
| 676 | fog += dfog; |
| 479 | 677 | } |
| 480 | 678 | } |
| 481 | 679 | |
| r14632 | r14633 | |
| 486 | 684 | UINT8 *texrom = gfxrom + (extra->texture_page * 0x40000); |
| 487 | 685 | int pal_chip = (extra->texture_palette & 0x8) ? 1 : 0; |
| 488 | 686 | int palette_index = (extra->texture_palette & 0x7) * 256; |
| 489 | | float z = extent->param[0].start; |
| 490 | | float u = extent->param[1].start; |
| 491 | | float v = extent->param[2].start; |
| 492 | | float w = extent->param[3].start; |
| 493 | | float dz = extent->param[0].dpdx; |
| 494 | | float du = extent->param[1].dpdx; |
| 495 | | float dv = extent->param[2].dpdx; |
| 496 | | float dw = extent->param[3].dpdx; |
| 687 | float z = extent->param[POLY_Z].start; |
| 688 | float u = extent->param[POLY_U].start; |
| 689 | float v = extent->param[POLY_V].start; |
| 690 | float w = extent->param[POLY_W].start; |
| 691 | float dz = extent->param[POLY_Z].dpdx; |
| 692 | float du = extent->param[POLY_U].dpdx; |
| 693 | float dv = extent->param[POLY_V].dpdx; |
| 694 | float dw = extent->param[POLY_W].dpdx; |
| 695 | float bri = extent->param[POLY_BRI].start; |
| 696 | float dbri = extent->param[POLY_BRI].dpdx; |
| 697 | float fog = extent->param[POLY_FOG].start; |
| 698 | float dfog = extent->param[POLY_FOG].dpdx; |
| 497 | 699 | int texture_mirror_x = extra->texture_mirror_x; |
| 498 | 700 | int texture_mirror_y = extra->texture_mirror_y; |
| 499 | 701 | int texture_x = extra->texture_x; |
| 500 | 702 | int texture_y = extra->texture_y; |
| 703 | int texture_width = extra->texture_width; |
| 704 | int texture_height = extra->texture_height; |
| 501 | 705 | int x; |
| 502 | 706 | |
| 707 | int poly_light_r = extra->light_r + extra->ambient_r; |
| 708 | int poly_light_g = extra->light_g + extra->ambient_g; |
| 709 | int poly_light_b = extra->light_b + extra->ambient_b; |
| 710 | if (poly_light_r > 255) poly_light_r = 255; |
| 711 | if (poly_light_g > 255) poly_light_g = 255; |
| 712 | if (poly_light_b > 255) poly_light_b = 255; |
| 713 | int poly_fog_r = extra->fog_r; |
| 714 | int poly_fog_g = extra->fog_g; |
| 715 | int poly_fog_b = extra->fog_b; |
| 716 | |
| 503 | 717 | UINT32 *fb = &destmap->pix32(scanline); |
| 504 | | UINT32 *zb = &K001005_zbuffer->pix32(scanline); |
| 718 | float *zb = (float*)&K001005_zbuffer->pix32(scanline); |
| 719 | int *x_mirror_table = tex_mirror_table[texture_mirror_x][texture_width]; |
| 720 | int *y_mirror_table = tex_mirror_table[texture_mirror_y][texture_height]; |
| 505 | 721 | |
| 506 | 722 | for (x = extent->startx; x < extent->stopx; x++) |
| 507 | 723 | { |
| 508 | | UINT32 iz = (UINT32)z >> 16; |
| 509 | | //int iu = u >> 16; |
| 510 | | //int iv = v >> 16; |
| 724 | int ibri = (int)(bri); |
| 725 | int ifog = (int)(fog); |
| 511 | 726 | |
| 512 | | if (iz < zb[x]) |
| 727 | if (ibri < 0) ibri = 0; if (ibri > 255) ibri = 255; |
| 728 | if (ifog < 0) ifog = 0; if (ifog > 65536) ifog = 65536; |
| 729 | |
| 730 | if (z <= zb[x]) |
| 513 | 731 | { |
| 514 | 732 | float oow = 1.0f / w; |
| 515 | 733 | UINT32 color; |
| r14632 | r14633 | |
| 519 | 737 | iu = u * oow; |
| 520 | 738 | iv = v * oow; |
| 521 | 739 | |
| 522 | | iiu = texture_x + tex_mirror_table[texture_mirror_x][(iu >> 4) & 0x7f]; |
| 523 | | iiv = texture_y + tex_mirror_table[texture_mirror_y][(iv >> 4) & 0x7f]; |
| 740 | iiu = texture_x + x_mirror_table[(iu >> 4) & 0x7f]; |
| 741 | iiv = texture_y + y_mirror_table[(iv >> 4) & 0x7f]; |
| 742 | |
| 524 | 743 | texel = texrom[((iiv & 0x1ff) * 512) + (iiu & 0x1ff)]; |
| 525 | 744 | color = K001006_palette[pal_chip][palette_index + texel]; |
| 526 | 745 | |
| 527 | 746 | if (color & 0xff000000) |
| 528 | 747 | { |
| 529 | | fb[x] = color; |
| 530 | | zb[x] = iz; |
| 748 | int r = (color >> 16) & 0xff; |
| 749 | int g = (color >> 8) & 0xff; |
| 750 | int b = color & 0xff; |
| 751 | |
| 752 | r = ((((r * poly_light_r * ibri) >> 16) * ifog) + (poly_fog_r * (65536 - ifog))) >> 16; |
| 753 | g = ((((g * poly_light_g * ibri) >> 16) * ifog) + (poly_fog_g * (65536 - ifog))) >> 16; |
| 754 | b = ((((b * poly_light_b * ibri) >> 16) * ifog) + (poly_fog_b * (65536 - ifog))) >> 16; |
| 755 | |
| 756 | if (r < 0) r = 0; if (r > 255) r = 255; |
| 757 | if (g < 0) g = 0; if (g > 255) g = 255; |
| 758 | if (b < 0) b = 0; if (b > 255) b = 255; |
| 759 | |
| 760 | fb[x] = 0xff000000 | (r << 16) | (g << 8) | b; |
| 761 | zb[x] = z; |
| 531 | 762 | } |
| 532 | 763 | } |
| 533 | 764 | |
| r14632 | r14633 | |
| 535 | 766 | v += dv; |
| 536 | 767 | z += dz; |
| 537 | 768 | w += dw; |
| 769 | bri += dbri; |
| 770 | fog += dfog; |
| 538 | 771 | } |
| 539 | 772 | } |
| 540 | 773 | |
| 541 | 774 | static void render_polygons(running_machine &machine) |
| 542 | 775 | { |
| 543 | | int i, j; |
| 544 | 776 | const rectangle visarea = machine.primary_screen->visible_area(); |
| 777 | poly_vertex v[4]; |
| 778 | int poly_type; |
| 779 | int brightness; |
| 545 | 780 | |
| 546 | | // mame_printf_debug("K001005_fifo_ptr = %08X\n", K001005_3d_fifo_ptr); |
| 781 | poly_vertex *vertex1; |
| 782 | poly_vertex *vertex2; |
| 783 | poly_vertex *vertex3; |
| 784 | poly_vertex *vertex4; |
| 547 | 785 | |
| 548 | | for (i=0; i < K001005_3d_fifo_ptr; i++) |
| 549 | | { |
| 550 | | if (K001005_3d_fifo[i] == 0x80000003) |
| 551 | | { |
| 552 | | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 553 | | poly_vertex v[4]; |
| 554 | | int r, g, b, a; |
| 555 | | UINT32 color; |
| 556 | | int index = i; |
| 786 | UINT32 *fifo = K001005_3d_fifo; |
| 557 | 787 | |
| 558 | | ++index; |
| 788 | int index = 0; |
| 559 | 789 | |
| 560 | | for (j=0; j < 4; j++) |
| 561 | | { |
| 562 | | int x, y; |
| 790 | do |
| 791 | { |
| 792 | UINT32 cmd = fifo[index++]; |
| 563 | 793 | |
| 564 | | x = ((K001005_3d_fifo[index] >> 0) & 0x3fff); |
| 565 | | y = ((K001005_3d_fifo[index] >> 16) & 0x1fff); |
| 566 | | x |= ((x & 0x2000) ? 0xffffc000 : 0); |
| 567 | | y |= ((y & 0x1000) ? 0xffffe000 : 0); |
| 568 | | ++index; |
| 794 | // Current guesswork on the command word bits: |
| 795 | // 0x01: Z-buffer disable? |
| 796 | // 0x02: Almost always set (only exception is 0x80000020 in Thunder Hurricane attract mode) |
| 797 | // 0x04: |
| 798 | // 0x08: |
| 799 | // 0x10: Texture mirror enable |
| 800 | // 0x20: Gouraud shading enable? |
| 801 | // 0x40: Unused? |
| 802 | // 0x80: Used by textured polygons. |
| 569 | 803 | |
| 570 | | v[j].x = ((float)(x) / 16.0f) + 256.0f; |
| 571 | | v[j].y = ((float)(-y) / 16.0f) + 192.0f; |
| 572 | | v[j].p[0] = 0; /* ??? */ |
| 573 | | } |
| 574 | | |
| 575 | | ++index; |
| 576 | | |
| 577 | | r = (K001005_3d_fifo[index] >> 0) & 0xff; |
| 578 | | g = (K001005_3d_fifo[index] >> 8) & 0xff; |
| 579 | | b = (K001005_3d_fifo[index] >> 16) & 0xff; |
| 580 | | a = (K001005_3d_fifo[index] >> 24) & 0xff; |
| 581 | | color = (a << 24) | (r << 16) | (g << 8) | (b); |
| 582 | | ++index; |
| 583 | | |
| 584 | | extra->color = color; |
| 585 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[1], &v[2]); |
| 586 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[2], &v[3]); |
| 587 | | // poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, 4, v); |
| 588 | | |
| 589 | | i = index - 1; |
| 590 | | } |
| 591 | | else if (K001005_3d_fifo[i] == 0x800000ae || K001005_3d_fifo[i] == 0x8000008e || |
| 592 | | K001005_3d_fifo[i] == 0x80000096 || K001005_3d_fifo[i] == 0x800000b6 || |
| 593 | | K001005_3d_fifo[i] == 0x8000002e || K001005_3d_fifo[i] == 0x8000000e || |
| 594 | | K001005_3d_fifo[i] == 0x80000016 || K001005_3d_fifo[i] == 0x80000036 || |
| 595 | | K001005_3d_fifo[i] == 0x800000aa || K001005_3d_fifo[i] == 0x800000a8 || |
| 596 | | K001005_3d_fifo[i] == 0x800000b2) |
| 804 | if (cmd == 0x800000ae || cmd == 0x8000008e || cmd == 0x80000096 || cmd == 0x800000b6 || |
| 805 | cmd == 0x8000002e || cmd == 0x8000000e || cmd == 0x80000016 || cmd == 0x80000036 || |
| 806 | cmd == 0x800000aa || cmd == 0x800000a8 || cmd == 0x800000b2 || cmd == 0x8000009e || |
| 807 | cmd == 0x80000092 || cmd == 0x8000008a || cmd == 0x80000094 || cmd == 0x8000009a || |
| 808 | cmd == 0x8000009c || cmd == 0x8000008c || cmd == 0x800000ac || cmd == 0x800000b4) |
| 597 | 809 | { |
| 598 | 810 | // 0x00: xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx Command |
| 599 | 811 | // |
| 600 | 812 | // 0x01: xxxx---- -------- -------- -------- Texture palette |
| 813 | // 0x01: ----xx-- -------- -------- -------- Unknown flags, set by commands 0x7b...0x7e |
| 814 | // 0x01: ------xx x------- -------- -------- Texture width / 8 - 1 |
| 815 | // 0x01: -------- -xxx---- -------- -------- Texture height / 8 - 1 |
| 601 | 816 | // 0x01: -------- -------x xxxx---- -------- Texture page |
| 602 | 817 | // 0x01: -------- -------- ----x-x- x-x-x-x- Texture X / 8 |
| 603 | 818 | // 0x01: -------- -------- -----x-x -x-x-x-x Texture Y / 8 |
| 604 | 819 | |
| 820 | // texture, Z |
| 821 | |
| 822 | int tex_x, tex_y; |
| 823 | UINT32 color = 0; |
| 605 | 824 | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 606 | | poly_vertex v[4]; |
| 607 | | int tx, ty; |
| 608 | | UINT32 color = 0; |
| 609 | | UINT32 header; |
| 610 | | UINT32 command; |
| 611 | | int num_verts = 0; |
| 612 | | int index = i; |
| 613 | | int poly_type = 0; |
| 614 | 825 | |
| 615 | | command = K001005_3d_fifo[index++]; |
| 616 | | header = K001005_3d_fifo[index++]; |
| 826 | UINT32 header = fifo[index++]; |
| 617 | 827 | |
| 618 | | for (j=0; j < 4; j++) |
| 828 | int last_vertex = 0; |
| 829 | int vert_num = 0; |
| 830 | do |
| 619 | 831 | { |
| 620 | | INT16 u2, v2; |
| 621 | 832 | int x, y, z; |
| 622 | | int end = 0; |
| 833 | INT16 tu, tv; |
| 623 | 834 | |
| 624 | | x = ((K001005_3d_fifo[index] >> 0) & 0x3fff); |
| 625 | | y = ((K001005_3d_fifo[index] >> 16) & 0x1fff); |
| 835 | x = (fifo[index] >> 0) & 0x3fff; |
| 836 | y = (fifo[index] >> 16) & 0x1fff; |
| 626 | 837 | x |= ((x & 0x2000) ? 0xffffc000 : 0); |
| 627 | 838 | y |= ((y & 0x1000) ? 0xffffe000 : 0); |
| 628 | 839 | |
| 629 | | poly_type = K001005_3d_fifo[index] & 0x4000; |
| 630 | | end = K001005_3d_fifo[index] & 0x8000; |
| 631 | | ++index; |
| 840 | poly_type = fifo[index] & 0x4000; // 0 = triangle, 1 = quad |
| 841 | last_vertex = fifo[index] & 0x8000; |
| 842 | index++; |
| 632 | 843 | |
| 633 | | z = K001005_3d_fifo[index]; |
| 634 | | ++index; |
| 844 | z = fifo[index] & 0xffffff00; |
| 845 | brightness = fifo[index] & 0xff; |
| 846 | index++; |
| 635 | 847 | |
| 636 | | if (end) |
| 848 | if (last_vertex) |
| 637 | 849 | { |
| 638 | | color = K001005_3d_fifo[index]; |
| 639 | | ++index; |
| 640 | | |
| 641 | | u2 = (K001005_3d_fifo[index] >> 16) & 0xffff; |
| 642 | | v2 = (K001005_3d_fifo[index] >> 0) & 0xffff; |
| 643 | | ++index; |
| 850 | color = fifo[index++]; |
| 644 | 851 | } |
| 645 | | else |
| 646 | | { |
| 647 | | u2 = (K001005_3d_fifo[index] >> 16) & 0xffff; |
| 648 | | v2 = (K001005_3d_fifo[index] >> 0) & 0xffff; |
| 649 | | ++index; |
| 650 | | } |
| 651 | 852 | |
| 652 | | v[j].x = ((float)(x) / 16.0f) + 256.0f; |
| 653 | | v[j].y = ((float)(-y) / 16.0f) + 192.0f; |
| 654 | | v[j].p[0] = *(float*)(&z); |
| 655 | | v[j].p[3] = 1.0f / v[j].p[0]; |
| 656 | | v[j].p[1] = u2 * v[j].p[3]; |
| 657 | | v[j].p[2] = v2 * v[j].p[3]; |
| 853 | tu = (fifo[index] >> 16) & 0xffff; |
| 854 | tv = (fifo[index] & 0xffff); |
| 855 | index++; |
| 658 | 856 | |
| 659 | | ++num_verts; |
| 660 | | |
| 661 | | if (end) |
| 662 | | break; |
| 857 | v[vert_num].x = ((float)(x) / 16.0f) + 256.0f; |
| 858 | v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8; |
| 859 | v[vert_num].p[POLY_Z] = *(float*)(&z); |
| 860 | v[vert_num].p[POLY_W] = 1.0f / v[vert_num].p[POLY_Z]; |
| 861 | v[vert_num].p[POLY_U] = tu * v[vert_num].p[POLY_W]; |
| 862 | v[vert_num].p[POLY_V] = tv * v[vert_num].p[POLY_W]; |
| 863 | v[vert_num].p[POLY_BRI] = brightness; |
| 864 | v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) * ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f; |
| 865 | //v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f; |
| 866 | if (v[vert_num].p[POLY_FOG] < 0.0f) v[vert_num].p[POLY_FOG] = 0.0f; |
| 867 | if (v[vert_num].p[POLY_FOG] > 65536.0f) v[vert_num].p[POLY_FOG] = 65536.0f; |
| 868 | vert_num++; |
| 663 | 869 | } |
| 870 | while (!last_vertex); |
| 664 | 871 | |
| 665 | | ty = ((header & 0x400) >> 5) | |
| 666 | | ((header & 0x100) >> 4) | |
| 667 | | ((header & 0x040) >> 3) | |
| 668 | | ((header & 0x010) >> 2) | |
| 669 | | ((header & 0x004) >> 1) | |
| 670 | | ((header & 0x001) >> 0); |
| 872 | tex_y = ((header & 0x400) >> 5) | |
| 873 | ((header & 0x100) >> 4) | |
| 874 | ((header & 0x040) >> 3) | |
| 875 | ((header & 0x010) >> 2) | |
| 876 | ((header & 0x004) >> 1) | |
| 877 | ((header & 0x001) >> 0); |
| 671 | 878 | |
| 672 | | tx = ((header & 0x800) >> 6) | |
| 673 | | ((header & 0x200) >> 5) | |
| 674 | | ((header & 0x080) >> 4) | |
| 675 | | ((header & 0x020) >> 3) | |
| 676 | | ((header & 0x008) >> 2) | |
| 677 | | ((header & 0x002) >> 1); |
| 879 | tex_x = ((header & 0x800) >> 6) | |
| 880 | ((header & 0x200) >> 5) | |
| 881 | ((header & 0x080) >> 4) | |
| 882 | ((header & 0x020) >> 3) | |
| 883 | ((header & 0x008) >> 2) | |
| 884 | ((header & 0x002) >> 1); |
| 678 | 885 | |
| 679 | | extra->texture_x = tx * 8; |
| 680 | | extra->texture_y = ty * 8; |
| 681 | | |
| 886 | extra->texture_x = tex_x * 8; |
| 887 | extra->texture_y = tex_y * 8; |
| 888 | extra->texture_width = (header >> 23) & 0x7; |
| 889 | extra->texture_height = (header >> 20) & 0x7; |
| 682 | 890 | extra->texture_page = (header >> 12) & 0x1f; |
| 683 | 891 | extra->texture_palette = (header >> 28) & 0xf; |
| 684 | | |
| 685 | | extra->texture_mirror_x = ((command & 0x10) ? 0x2 : 0) | ((header & 0x00400000) ? 0x1 : 0); |
| 686 | | extra->texture_mirror_y = ((command & 0x10) ? 0x2 : 0) | ((header & 0x00400000) ? 0x1 : 0); |
| 687 | | |
| 892 | extra->texture_mirror_x = ((cmd & 0x10) ? 0x1 : 0); |
| 893 | extra->texture_mirror_y = ((cmd & 0x10) ? 0x1 : 0); |
| 688 | 894 | extra->color = color; |
| 895 | extra->light_r = light_r; extra->light_g = light_g; extra->light_b = light_b; |
| 896 | extra->ambient_r = ambient_r; extra->ambient_g = ambient_g; extra->ambient_b = ambient_b; |
| 897 | extra->fog_r = fog_r; extra->fog_g = fog_g; extra->fog_b = fog_b; |
| 898 | extra->flags = cmd; |
| 689 | 899 | |
| 690 | | if (num_verts < 3) |
| 900 | if ((cmd & 0x20) == 0) // possibly enable flag for gouraud shading (fixes some shading errors) |
| 691 | 901 | { |
| 692 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &prev_v[2], &v[0], &v[1]); |
| 693 | | if (prev_poly_type) |
| 694 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &prev_v[2], &prev_v[3], &v[0]); |
| 695 | | // if (prev_poly_type) |
| 696 | | // poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &prev_v[2], &prev_v[3], &v[0], &v[1]); |
| 697 | | // else |
| 698 | | // poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &prev_v[2], &v[0], &v[1]); |
| 902 | v[0].p[POLY_BRI] = brightness; |
| 903 | v[1].p[POLY_BRI] = brightness; |
| 904 | } |
| 699 | 905 | |
| 700 | | memcpy(&prev_v[0], &prev_v[2], sizeof(poly_vertex)); |
| 701 | | memcpy(&prev_v[1], &prev_v[3], sizeof(poly_vertex)); |
| 702 | | memcpy(&prev_v[2], &v[0], sizeof(poly_vertex)); |
| 703 | | memcpy(&prev_v[3], &v[1], sizeof(poly_vertex)); |
| 704 | | } |
| 705 | | else |
| 906 | if (poly_type == 0) // triangle |
| 706 | 907 | { |
| 707 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &v[0], &v[1], &v[2]); |
| 708 | | if (num_verts > 3) |
| 709 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &v[2], &v[3], &v[0]); |
| 710 | | // poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, num_verts, v); |
| 908 | if (vert_num == 1) |
| 909 | { |
| 910 | vertex1 = &prev_v[2]; |
| 911 | vertex2 = &prev_v[3]; |
| 912 | vertex3 = &v[0]; |
| 913 | } |
| 914 | else if (vert_num == 2) |
| 915 | { |
| 916 | vertex1 = &prev_v[3]; |
| 917 | vertex2 = &v[0]; |
| 918 | vertex3 = &v[1]; |
| 919 | } |
| 920 | else |
| 921 | { |
| 922 | vertex1 = &v[0]; |
| 923 | vertex2 = &v[1]; |
| 924 | vertex3 = &v[2]; |
| 925 | } |
| 711 | 926 | |
| 712 | | memcpy(prev_v, v, sizeof(poly_vertex) * 4); |
| 927 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, vertex1, vertex2, vertex3); |
| 928 | |
| 929 | memcpy(&prev_v[1], vertex1, sizeof(poly_vertex)); |
| 930 | memcpy(&prev_v[2], vertex2, sizeof(poly_vertex)); |
| 931 | memcpy(&prev_v[3], vertex3, sizeof(poly_vertex)); |
| 713 | 932 | } |
| 714 | | |
| 715 | | prev_poly_type = poly_type; |
| 716 | | |
| 717 | | while ((K001005_3d_fifo[index] & 0xffffff00) != 0x80000000 && index < K001005_3d_fifo_ptr) |
| 933 | else // quad |
| 718 | 934 | { |
| 719 | | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 720 | | int new_verts = 0; |
| 721 | | |
| 722 | | if (poly_type) |
| 935 | if (vert_num == 1) |
| 723 | 936 | { |
| 724 | | memcpy(&v[0], &prev_v[2], sizeof(poly_vertex)); |
| 725 | | memcpy(&v[1], &prev_v[3], sizeof(poly_vertex)); |
| 937 | vertex1 = &prev_v[1]; |
| 938 | vertex2 = &prev_v[2]; |
| 939 | vertex3 = &prev_v[3]; |
| 940 | vertex4 = &v[0]; |
| 726 | 941 | } |
| 942 | else if (vert_num == 2) |
| 943 | { |
| 944 | vertex1 = &prev_v[2]; |
| 945 | vertex2 = &prev_v[3]; |
| 946 | vertex3 = &v[0]; |
| 947 | vertex4 = &v[1]; |
| 948 | } |
| 949 | else if (vert_num == 3) |
| 950 | { |
| 951 | vertex1 = &prev_v[3]; |
| 952 | vertex2 = &v[0]; |
| 953 | vertex3 = &v[1]; |
| 954 | vertex4 = &v[2]; |
| 955 | } |
| 727 | 956 | else |
| 728 | 957 | { |
| 729 | | memcpy(&v[0], &prev_v[1], sizeof(poly_vertex)); |
| 730 | | memcpy(&v[1], &prev_v[2], sizeof(poly_vertex)); |
| 958 | vertex1 = &v[0]; |
| 959 | vertex2 = &v[1]; |
| 960 | vertex3 = &v[2]; |
| 961 | vertex4 = &v[3]; |
| 731 | 962 | } |
| 732 | 963 | |
| 733 | | for (j=2; j < 4; j++) |
| 734 | | { |
| 735 | | INT16 u2, v2; |
| 964 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, vertex1, vertex2, vertex3); |
| 965 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, vertex3, vertex4, vertex1); |
| 966 | |
| 967 | memcpy(&prev_v[0], vertex1, sizeof(poly_vertex)); |
| 968 | memcpy(&prev_v[1], vertex2, sizeof(poly_vertex)); |
| 969 | memcpy(&prev_v[2], vertex3, sizeof(poly_vertex)); |
| 970 | memcpy(&prev_v[3], vertex4, sizeof(poly_vertex)); |
| 971 | } |
| 972 | |
| 973 | while ((fifo[index] & 0xffffff00) != 0x80000000 && index < K001005_3d_fifo_ptr) |
| 974 | { |
| 975 | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 976 | int new_verts = 0; |
| 977 | |
| 978 | memcpy(&v[0], &prev_v[2], sizeof(poly_vertex)); |
| 979 | memcpy(&v[1], &prev_v[3], sizeof(poly_vertex)); |
| 980 | |
| 981 | last_vertex = 0; |
| 982 | vert_num = 2; |
| 983 | do |
| 984 | { |
| 736 | 985 | int x, y, z; |
| 737 | | int end = 0; |
| 986 | INT16 tu, tv; |
| 738 | 987 | |
| 739 | 988 | x = ((K001005_3d_fifo[index] >> 0) & 0x3fff); |
| 740 | 989 | y = ((K001005_3d_fifo[index] >> 16) & 0x1fff); |
| 741 | 990 | x |= ((x & 0x2000) ? 0xffffc000 : 0); |
| 742 | 991 | y |= ((y & 0x1000) ? 0xffffe000 : 0); |
| 743 | 992 | |
| 744 | | poly_type = K001005_3d_fifo[index] & 0x4000; |
| 745 | | end = K001005_3d_fifo[index] & 0x8000; |
| 746 | | ++index; |
| 993 | poly_type = fifo[index] & 0x4000; |
| 994 | last_vertex = fifo[index] & 0x8000; |
| 995 | index++; |
| 747 | 996 | |
| 748 | | z = K001005_3d_fifo[index]; |
| 749 | | ++index; |
| 750 | | |
| 751 | | if (end) |
| 997 | z = fifo[index] & 0xffffff00; |
| 998 | brightness = fifo[index] & 0xff; |
| 999 | index++; |
| 1000 | |
| 1001 | if (last_vertex) |
| 752 | 1002 | { |
| 753 | | color = K001005_3d_fifo[index]; |
| 754 | | ++index; |
| 755 | | |
| 756 | | u2 = (K001005_3d_fifo[index] >> 16) & 0xffff; |
| 757 | | v2 = (K001005_3d_fifo[index] >> 0) & 0xffff; |
| 758 | | ++index; |
| 1003 | color = fifo[index++]; |
| 759 | 1004 | } |
| 760 | | else |
| 761 | | { |
| 762 | | u2 = (K001005_3d_fifo[index] >> 16) & 0xffff; |
| 763 | | v2 = (K001005_3d_fifo[index] >> 0) & 0xffff; |
| 764 | | ++index; |
| 765 | | } |
| 766 | 1005 | |
| 767 | | v[j].x = ((float)(x) / 16.0f) + 256.0f; |
| 768 | | v[j].y = ((float)(-y) / 16.0f) + 192.0f; |
| 769 | | v[j].p[0] = *(float*)(&z); |
| 770 | | v[j].p[3] = 1.0f / v[j].p[0]; |
| 771 | | v[j].p[1] = u2 * v[j].p[3]; |
| 772 | | v[j].p[2] = v2 * v[j].p[3]; |
| 1006 | tu = (K001005_3d_fifo[index] >> 16) & 0xffff; |
| 1007 | tv = (K001005_3d_fifo[index] >> 0) & 0xffff; |
| 1008 | index++; |
| 773 | 1009 | |
| 774 | | ++new_verts; |
| 1010 | v[vert_num].x = ((float)(x) / 16.0f) + 256.0f; |
| 1011 | v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8; |
| 1012 | v[vert_num].p[POLY_Z] = *(float*)(&z); |
| 1013 | v[vert_num].p[POLY_W] = 1.0f / v[vert_num].p[POLY_Z]; |
| 1014 | v[vert_num].p[POLY_U] = tu * v[vert_num].p[POLY_W]; |
| 1015 | v[vert_num].p[POLY_V] = tv * v[vert_num].p[POLY_W]; |
| 1016 | v[vert_num].p[POLY_BRI] = brightness; |
| 1017 | v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) * ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f; |
| 1018 | //v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f; |
| 1019 | if (v[vert_num].p[POLY_FOG] < 0.0f) v[vert_num].p[POLY_FOG] = 0.0f; |
| 1020 | if (v[vert_num].p[POLY_FOG] > 65536.0f) v[vert_num].p[POLY_FOG] = 65536.0f; |
| 775 | 1021 | |
| 776 | | if (end) |
| 777 | | break; |
| 1022 | vert_num++; |
| 1023 | new_verts++; |
| 778 | 1024 | } |
| 1025 | while (!last_vertex); |
| 779 | 1026 | |
| 780 | | extra->texture_x = tx * 8; |
| 781 | | extra->texture_y = ty * 8; |
| 1027 | extra->texture_x = tex_x * 8; |
| 1028 | extra->texture_y = tex_y * 8; |
| 1029 | extra->texture_width = (header >> 23) & 0x7; |
| 1030 | extra->texture_height = (header >> 20) & 0x7; |
| 782 | 1031 | |
| 783 | 1032 | extra->texture_page = (header >> 12) & 0x1f; |
| 784 | 1033 | extra->texture_palette = (header >> 28) & 0xf; |
| 785 | 1034 | |
| 786 | | extra->texture_mirror_x = ((command & 0x10) ? 0x2 : 0) | ((header & 0x00400000) ? 0x1 : 0); |
| 787 | | extra->texture_mirror_y = ((command & 0x10) ? 0x2 : 0) | ((header & 0x00400000) ? 0x1 : 0); |
| 1035 | extra->texture_mirror_x = ((cmd & 0x10) ? 0x1 : 0);// & ((header & 0x00400000) ? 0x1 : 0); |
| 1036 | extra->texture_mirror_y = ((cmd & 0x10) ? 0x1 : 0);// & ((header & 0x00400000) ? 0x1 : 0); |
| 788 | 1037 | |
| 789 | 1038 | extra->color = color; |
| 1039 | extra->light_r = light_r; extra->light_g = light_g; extra->light_b = light_b; |
| 1040 | extra->ambient_r = ambient_r; extra->ambient_g = ambient_g; extra->ambient_b = ambient_b; |
| 1041 | extra->fog_r = fog_r; extra->fog_g = fog_g; extra->fog_b = fog_b; |
| 1042 | extra->flags = cmd; |
| 790 | 1043 | |
| 791 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &v[0], &v[1], &v[2]); |
| 792 | | if (new_verts > 1) |
| 793 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, &v[2], &v[3], &v[0]); |
| 794 | | // poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 4, new_verts + 2, v); |
| 1044 | if ((cmd & 0x20) == 0) // possibly enable flag for gouraud shading (fixes some shading errors) |
| 1045 | { |
| 1046 | v[0].p[POLY_BRI] = brightness; |
| 1047 | v[1].p[POLY_BRI] = brightness; |
| 1048 | } |
| 795 | 1049 | |
| 796 | | memcpy(prev_v, v, sizeof(poly_vertex) * 4); |
| 1050 | if (new_verts == 1) |
| 1051 | { |
| 1052 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, &v[0], &v[1], &v[2]); |
| 1053 | |
| 1054 | memcpy(&prev_v[1], &v[0], sizeof(poly_vertex)); |
| 1055 | memcpy(&prev_v[2], &v[1], sizeof(poly_vertex)); |
| 1056 | memcpy(&prev_v[3], &v[2], sizeof(poly_vertex)); |
| 1057 | } |
| 1058 | else if (new_verts == 2) |
| 1059 | { |
| 1060 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, &v[0], &v[1], &v[2]); |
| 1061 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_tex, 6, &v[2], &v[3], &v[0]); |
| 1062 | |
| 1063 | memcpy(&prev_v[0], &v[0], sizeof(poly_vertex)); |
| 1064 | memcpy(&prev_v[1], &v[1], sizeof(poly_vertex)); |
| 1065 | memcpy(&prev_v[2], &v[2], sizeof(poly_vertex)); |
| 1066 | memcpy(&prev_v[3], &v[3], sizeof(poly_vertex)); |
| 1067 | } |
| 797 | 1068 | }; |
| 798 | | |
| 799 | | i = index - 1; |
| 800 | 1069 | } |
| 801 | | else if (K001005_3d_fifo[i] == 0x80000006 || K001005_3d_fifo[i] == 0x80000026 || |
| 802 | | K001005_3d_fifo[i] == 0x80000020 || K001005_3d_fifo[i] == 0x80000022) |
| 1070 | else if (cmd == 0x80000006 || cmd == 0x80000026 || cmd == 0x80000002 || cmd == 0x80000020 || cmd == 0x80000022) |
| 803 | 1071 | { |
| 1072 | // no texture, Z |
| 1073 | |
| 804 | 1074 | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 805 | | poly_vertex v[4]; |
| 1075 | UINT32 color; |
| 806 | 1076 | int r, g, b, a; |
| 807 | | UINT32 color; |
| 808 | | int num_verts = 0; |
| 809 | | int index = i; |
| 810 | | int poly_type = 0; |
| 811 | 1077 | |
| 812 | | ++index; |
| 813 | | |
| 814 | | for (j=0; j < 4; j++) |
| 1078 | int last_vertex = 0; |
| 1079 | int vert_num = 0; |
| 1080 | do |
| 815 | 1081 | { |
| 816 | 1082 | int x, y, z; |
| 817 | | int end = 0; |
| 818 | 1083 | |
| 819 | | x = ((K001005_3d_fifo[index] >> 0) & 0x3fff); |
| 820 | | y = ((K001005_3d_fifo[index] >> 16) & 0x1fff); |
| 1084 | x = (fifo[index] >> 0) & 0x3fff; |
| 1085 | y = (fifo[index] >> 16) & 0x1fff; |
| 821 | 1086 | x |= ((x & 0x2000) ? 0xffffc000 : 0); |
| 822 | 1087 | y |= ((y & 0x1000) ? 0xffffe000 : 0); |
| 823 | 1088 | |
| 824 | | poly_type = K001005_3d_fifo[index] & 0x4000; |
| 825 | | end = K001005_3d_fifo[index] & 0x8000; |
| 826 | | ++index; |
| 1089 | poly_type = fifo[index] & 0x4000; // 0 = triangle, 1 = quad |
| 1090 | last_vertex = fifo[index] & 0x8000; |
| 1091 | index++; |
| 827 | 1092 | |
| 828 | | z = K001005_3d_fifo[index]; |
| 829 | | ++index; |
| 1093 | z = fifo[index] & 0xffffff00; |
| 1094 | brightness = fifo[index] & 0xff; |
| 1095 | index++; |
| 830 | 1096 | |
| 831 | | v[j].x = ((float)(x) / 16.0f) + 256.0f; |
| 832 | | v[j].y = ((float)(-y) / 16.0f) + 192.0f; |
| 833 | | v[j].p[0] = *(float*)(&z); |
| 834 | | |
| 835 | | ++num_verts; |
| 836 | | |
| 837 | | if (end) |
| 838 | | break; |
| 1097 | v[vert_num].x = ((float)(x) / 16.0f) + 256.0f; |
| 1098 | v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8; |
| 1099 | v[vert_num].p[POLY_Z] = *(float*)(&z); |
| 1100 | v[vert_num].p[POLY_BRI] = brightness; |
| 1101 | v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) * ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f; |
| 1102 | //v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f; |
| 1103 | if (v[vert_num].p[POLY_FOG] < 0.0f) v[vert_num].p[POLY_FOG] = 0.0f; |
| 1104 | if (v[vert_num].p[POLY_FOG] > 65536.0f) v[vert_num].p[POLY_FOG] = 65536.0f; |
| 1105 | vert_num++; |
| 839 | 1106 | } |
| 1107 | while (!last_vertex); |
| 840 | 1108 | |
| 841 | | r = (K001005_3d_fifo[index] >> 0) & 0xff; |
| 842 | | g = (K001005_3d_fifo[index] >> 8) & 0xff; |
| 843 | | b = (K001005_3d_fifo[index] >> 16) & 0xff; |
| 844 | | a = (K001005_3d_fifo[index] >> 24) & 0xff; |
| 1109 | r = (fifo[index] >> 0) & 0xff; |
| 1110 | g = (fifo[index] >> 8) & 0xff; |
| 1111 | b = (fifo[index] >> 16) & 0xff; |
| 1112 | a = (fifo[index] >> 24) & 0xff; |
| 845 | 1113 | color = (a << 24) | (r << 16) | (g << 8) | (b); |
| 846 | 1114 | index++; |
| 847 | 1115 | |
| 848 | 1116 | extra->color = color; |
| 1117 | extra->light_r = light_r; extra->light_g = light_g; extra->light_b = light_b; |
| 1118 | extra->ambient_r = ambient_r; extra->ambient_g = ambient_g; extra->ambient_b = ambient_b; |
| 1119 | extra->fog_r = fog_r; extra->fog_g = fog_g; extra->fog_b = fog_b; |
| 1120 | extra->flags = cmd; |
| 849 | 1121 | |
| 850 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[1], &v[2]); |
| 851 | | if (num_verts > 3) |
| 852 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[2], &v[3], &v[0]); |
| 853 | | // poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, num_verts, v); |
| 1122 | if ((cmd & 0x20) == 0) // possibly enable flag for gouraud shading (fixes some shading errors) |
| 1123 | { |
| 1124 | v[0].p[POLY_BRI] = brightness; |
| 1125 | v[1].p[POLY_BRI] = brightness; |
| 1126 | } |
| 854 | 1127 | |
| 855 | | memcpy(prev_v, v, sizeof(poly_vertex) * 4); |
| 1128 | if (poly_type == 0) // triangle |
| 1129 | { |
| 1130 | if (vert_num == 1) |
| 1131 | { |
| 1132 | vertex1 = &prev_v[2]; |
| 1133 | vertex2 = &prev_v[3]; |
| 1134 | vertex3 = &v[0]; |
| 1135 | } |
| 1136 | else if (vert_num == 2) |
| 1137 | { |
| 1138 | vertex1 = &prev_v[3]; |
| 1139 | vertex2 = &v[0]; |
| 1140 | vertex3 = &v[1]; |
| 1141 | } |
| 1142 | else |
| 1143 | { |
| 1144 | vertex1 = &v[0]; |
| 1145 | vertex2 = &v[1]; |
| 1146 | vertex3 = &v[2]; |
| 1147 | } |
| 856 | 1148 | |
| 857 | | while ((K001005_3d_fifo[index] & 0xffffff00) != 0x80000000 && index < K001005_3d_fifo_ptr) |
| 1149 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 3, vertex1, vertex2, vertex3); |
| 1150 | |
| 1151 | memcpy(&prev_v[1], vertex1, sizeof(poly_vertex)); |
| 1152 | memcpy(&prev_v[2], vertex2, sizeof(poly_vertex)); |
| 1153 | memcpy(&prev_v[3], vertex3, sizeof(poly_vertex)); |
| 1154 | } |
| 1155 | else // quad |
| 858 | 1156 | { |
| 859 | | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 860 | | int new_verts = 0; |
| 861 | | |
| 862 | | if (poly_type) |
| 1157 | if (vert_num == 1) |
| 863 | 1158 | { |
| 864 | | memcpy(&v[0], &prev_v[2], sizeof(poly_vertex)); |
| 865 | | memcpy(&v[1], &prev_v[3], sizeof(poly_vertex)); |
| 1159 | vertex1 = &prev_v[1]; |
| 1160 | vertex2 = &prev_v[2]; |
| 1161 | vertex3 = &prev_v[3]; |
| 1162 | vertex4 = &v[0]; |
| 866 | 1163 | } |
| 1164 | else if (vert_num == 2) |
| 1165 | { |
| 1166 | vertex1 = &prev_v[2]; |
| 1167 | vertex2 = &prev_v[3]; |
| 1168 | vertex3 = &v[0]; |
| 1169 | vertex4 = &v[1]; |
| 1170 | } |
| 1171 | else if (vert_num == 3) |
| 1172 | { |
| 1173 | vertex1 = &prev_v[3]; |
| 1174 | vertex2 = &v[0]; |
| 1175 | vertex3 = &v[1]; |
| 1176 | vertex4 = &v[2]; |
| 1177 | } |
| 867 | 1178 | else |
| 868 | 1179 | { |
| 869 | | memcpy(&v[0], &prev_v[1], sizeof(poly_vertex)); |
| 870 | | memcpy(&v[1], &prev_v[2], sizeof(poly_vertex)); |
| 1180 | vertex1 = &v[0]; |
| 1181 | vertex2 = &v[1]; |
| 1182 | vertex3 = &v[2]; |
| 1183 | vertex4 = &v[3]; |
| 871 | 1184 | } |
| 872 | 1185 | |
| 873 | | for (j=2; j < 4; j++) |
| 1186 | poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 3, vertex1, vertex2, vertex3, vertex4); |
| 1187 | |
| 1188 | memcpy(&prev_v[0], vertex1, sizeof(poly_vertex)); |
| 1189 | memcpy(&prev_v[1], vertex2, sizeof(poly_vertex)); |
| 1190 | memcpy(&prev_v[2], vertex3, sizeof(poly_vertex)); |
| 1191 | memcpy(&prev_v[3], vertex4, sizeof(poly_vertex)); |
| 1192 | } |
| 1193 | |
| 1194 | while ((fifo[index] & 0xffffff00) != 0x80000000 && index < K001005_3d_fifo_ptr) |
| 1195 | { |
| 1196 | int new_verts = 0; |
| 1197 | |
| 1198 | memcpy(&v[0], &prev_v[2], sizeof(poly_vertex)); |
| 1199 | memcpy(&v[1], &prev_v[3], sizeof(poly_vertex)); |
| 1200 | |
| 1201 | last_vertex = 0; |
| 1202 | vert_num = 2; |
| 1203 | do |
| 874 | 1204 | { |
| 875 | 1205 | int x, y, z; |
| 876 | | int end = 0; |
| 877 | 1206 | |
| 878 | | x = ((K001005_3d_fifo[index] >> 0) & 0x3fff); |
| 879 | | y = ((K001005_3d_fifo[index] >> 16) & 0x1fff); |
| 1207 | x = ((fifo[index] >> 0) & 0x3fff); |
| 1208 | y = ((fifo[index] >> 16) & 0x1fff); |
| 880 | 1209 | x |= ((x & 0x2000) ? 0xffffc000 : 0); |
| 881 | 1210 | y |= ((y & 0x1000) ? 0xffffe000 : 0); |
| 882 | 1211 | |
| 883 | | poly_type = K001005_3d_fifo[index] & 0x4000; |
| 884 | | end = K001005_3d_fifo[index] & 0x8000; |
| 885 | | ++index; |
| 1212 | poly_type = fifo[index] & 0x4000; |
| 1213 | last_vertex = fifo[index] & 0x8000; |
| 1214 | index++; |
| 886 | 1215 | |
| 887 | | z = K001005_3d_fifo[index]; |
| 888 | | ++index; |
| 1216 | z = fifo[index] & 0xffffff00; |
| 1217 | brightness = fifo[index] & 0xff; |
| 1218 | index++; |
| 889 | 1219 | |
| 890 | | v[j].x = ((float)(x) / 16.0f) + 256.0f; |
| 891 | | v[j].y = ((float)(-y) / 16.0f) + 192.0f; |
| 892 | | v[j].p[0] = *(float*)(&z); |
| 1220 | v[vert_num].x = ((float)(x) / 16.0f) + 256.0f; |
| 1221 | v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8; |
| 1222 | v[vert_num].p[POLY_Z] = *(float*)(&z); |
| 1223 | v[vert_num].p[POLY_BRI] = brightness; |
| 1224 | v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) * ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f; |
| 1225 | //v[vert_num].p[POLY_FOG] = (1.0f / (exp( ((v[vert_num].p[POLY_Z] * fog_density) / far_z) ))) * 65536.0f; |
| 1226 | if (v[vert_num].p[POLY_FOG] < 0.0f) v[vert_num].p[POLY_FOG] = 0.0f; |
| 1227 | if (v[vert_num].p[POLY_FOG] > 65536.0f) v[vert_num].p[POLY_FOG] = 65536.0f; |
| 893 | 1228 | |
| 894 | | ++new_verts; |
| 895 | | |
| 896 | | if (end) |
| 897 | | break; |
| 1229 | vert_num++; |
| 1230 | new_verts++; |
| 898 | 1231 | } |
| 1232 | while (!last_vertex); |
| 899 | 1233 | |
| 900 | | r = (K001005_3d_fifo[index] >> 0) & 0xff; |
| 901 | | g = (K001005_3d_fifo[index] >> 8) & 0xff; |
| 902 | | b = (K001005_3d_fifo[index] >> 16) & 0xff; |
| 903 | | a = (K001005_3d_fifo[index] >> 24) & 0xff; |
| 1234 | r = (fifo[index] >> 0) & 0xff; |
| 1235 | g = (fifo[index] >> 8) & 0xff; |
| 1236 | b = (fifo[index] >> 16) & 0xff; |
| 1237 | a = (fifo[index] >> 24) & 0xff; |
| 904 | 1238 | color = (a << 24) | (r << 16) | (g << 8) | (b); |
| 905 | 1239 | index++; |
| 906 | 1240 | |
| 907 | 1241 | extra->color = color; |
| 1242 | extra->light_r = light_r; extra->light_g = light_g; extra->light_b = light_b; |
| 1243 | extra->ambient_r = ambient_r; extra->ambient_g = ambient_g; extra->ambient_b = ambient_b; |
| 1244 | extra->fog_r = fog_r; extra->fog_g = fog_g; extra->fog_b = fog_b; |
| 1245 | extra->flags = cmd; |
| 908 | 1246 | |
| 909 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[1], &v[2]); |
| 910 | | if (new_verts > 1) |
| 911 | | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, &v[0], &v[2], &v[3]); |
| 912 | | // poly_render_polygon(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 1, new_verts + 2, v); |
| 1247 | if ((cmd & 0x20) == 0) // possibly enable flag for gouraud shading (fixes some shading errors) |
| 1248 | { |
| 1249 | v[0].p[POLY_BRI] = brightness; |
| 1250 | v[1].p[POLY_BRI] = brightness; |
| 1251 | } |
| 913 | 1252 | |
| 914 | | memcpy(prev_v, v, sizeof(poly_vertex) * 4); |
| 915 | | }; |
| 1253 | if (new_verts == 1) |
| 1254 | { |
| 1255 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 3, &v[0], &v[1], &v[2]); |
| 1256 | |
| 1257 | memcpy(&prev_v[1], &v[0], sizeof(poly_vertex)); |
| 1258 | memcpy(&prev_v[2], &v[1], sizeof(poly_vertex)); |
| 1259 | memcpy(&prev_v[3], &v[2], sizeof(poly_vertex)); |
| 1260 | } |
| 1261 | else if (new_verts == 2) |
| 1262 | { |
| 1263 | poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline, 3, &v[0], &v[1], &v[2], &v[3]); |
| 916 | 1264 | |
| 917 | | i = index - 1; |
| 1265 | memcpy(&prev_v[0], &v[0], sizeof(poly_vertex)); |
| 1266 | memcpy(&prev_v[1], &v[1], sizeof(poly_vertex)); |
| 1267 | memcpy(&prev_v[2], &v[2], sizeof(poly_vertex)); |
| 1268 | memcpy(&prev_v[3], &v[3], sizeof(poly_vertex)); |
| 1269 | } |
| 1270 | } |
| 918 | 1271 | } |
| 919 | | else if (K001005_3d_fifo[i] == 0x80000000) |
| 1272 | else if (cmd == 0x80000003 || cmd == 0x80000001) |
| 920 | 1273 | { |
| 1274 | // no texture, no Z |
| 921 | 1275 | |
| 1276 | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 1277 | int r, g, b, a; |
| 1278 | UINT32 color; |
| 1279 | |
| 1280 | int last_vertex = 0; |
| 1281 | int vert_num = 0; |
| 1282 | do |
| 1283 | { |
| 1284 | int x, y; |
| 1285 | |
| 1286 | x = ((fifo[index] >> 0) & 0x3fff); |
| 1287 | y = ((fifo[index] >> 16) & 0x1fff); |
| 1288 | x |= ((x & 0x2000) ? 0xffffc000 : 0); |
| 1289 | y |= ((y & 0x1000) ? 0xffffe000 : 0); |
| 1290 | |
| 1291 | poly_type = fifo[index] & 0x4000; |
| 1292 | last_vertex = fifo[index] & 0x8000; |
| 1293 | index++; |
| 1294 | |
| 1295 | v[vert_num].x = ((float)(x) / 16.0f) + 256.0f; |
| 1296 | v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8; |
| 1297 | vert_num++; |
| 1298 | } |
| 1299 | while (!last_vertex); |
| 1300 | |
| 1301 | // unknown word |
| 1302 | index++; |
| 1303 | |
| 1304 | r = (fifo[index] >> 0) & 0xff; |
| 1305 | g = (fifo[index] >> 8) & 0xff; |
| 1306 | b = (fifo[index] >> 16) & 0xff; |
| 1307 | a = (fifo[index] >> 24) & 0xff; |
| 1308 | color = (a << 24) | (r << 16) | (g << 8) | (b); |
| 1309 | index++; |
| 1310 | |
| 1311 | extra->color = color; |
| 1312 | extra->flags = cmd; |
| 1313 | |
| 1314 | if (poly_type == 0) |
| 1315 | { |
| 1316 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_2d, 0, &v[0], &v[1], &v[2]); |
| 1317 | } |
| 1318 | else |
| 1319 | { |
| 1320 | poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_2d, 0, &v[0], &v[1], &v[2], &v[3]); |
| 1321 | } |
| 922 | 1322 | } |
| 923 | | else if ((K001005_3d_fifo[i] & 0xffffff00) == 0x80000000) |
| 1323 | else if (cmd == 0x8000008b) |
| 924 | 1324 | { |
| 1325 | // texture, no Z |
| 1326 | |
| 1327 | int tex_x, tex_y; |
| 1328 | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 1329 | int r, g, b, a; |
| 1330 | UINT32 color = 0; |
| 1331 | |
| 1332 | UINT32 header = fifo[index++]; |
| 1333 | |
| 1334 | int last_vertex = 0; |
| 1335 | int vert_num = 0; |
| 1336 | do |
| 1337 | { |
| 1338 | int x, y; |
| 1339 | INT16 tu, tv; |
| 1340 | |
| 1341 | x = ((fifo[index] >> 0) & 0x3fff); |
| 1342 | y = ((fifo[index] >> 16) & 0x1fff); |
| 1343 | x |= ((x & 0x2000) ? 0xffffc000 : 0); |
| 1344 | y |= ((y & 0x1000) ? 0xffffe000 : 0); |
| 1345 | |
| 1346 | poly_type = fifo[index] & 0x4000; |
| 1347 | last_vertex = fifo[index] & 0x8000; |
| 1348 | index++; |
| 1349 | |
| 1350 | if (last_vertex) |
| 1351 | { |
| 1352 | // unknown word |
| 1353 | index++; |
| 1354 | |
| 1355 | color = fifo[index++]; |
| 1356 | } |
| 1357 | |
| 1358 | tu = (fifo[index] >> 16) & 0xffff; |
| 1359 | tv = (fifo[index] & 0xffff); |
| 1360 | index++; |
| 1361 | |
| 1362 | v[vert_num].x = ((float)(x) / 16.0f) + 256.0f; |
| 1363 | v[vert_num].y = ((float)(-y) / 16.0f) + 192.0f + 8; |
| 1364 | v[vert_num].p[POLY_U] = tu; |
| 1365 | v[vert_num].p[POLY_V] = tv; |
| 1366 | vert_num++; |
| 1367 | } |
| 1368 | while (!last_vertex); |
| 1369 | |
| 1370 | r = (color >> 0) & 0xff; |
| 1371 | g = (color >> 8) & 0xff; |
| 1372 | b = (color >> 16) & 0xff; |
| 1373 | a = (color >> 24) & 0xff; |
| 1374 | extra->color = (a << 24) | (r << 16) | (g << 8) | (b); |
| 1375 | extra->flags = cmd; |
| 1376 | |
| 1377 | tex_y = ((header & 0x400) >> 5) | |
| 1378 | ((header & 0x100) >> 4) | |
| 1379 | ((header & 0x040) >> 3) | |
| 1380 | ((header & 0x010) >> 2) | |
| 1381 | ((header & 0x004) >> 1) | |
| 1382 | ((header & 0x001) >> 0); |
| 1383 | |
| 1384 | tex_x = ((header & 0x800) >> 6) | |
| 1385 | ((header & 0x200) >> 5) | |
| 1386 | ((header & 0x080) >> 4) | |
| 1387 | ((header & 0x020) >> 3) | |
| 1388 | ((header & 0x008) >> 2) | |
| 1389 | ((header & 0x002) >> 1); |
| 1390 | |
| 1391 | extra->texture_x = tex_x * 8; |
| 1392 | extra->texture_y = tex_y * 8; |
| 1393 | extra->texture_width = (header >> 23) & 0x7; |
| 1394 | extra->texture_height = (header >> 20) & 0x7; |
| 1395 | |
| 1396 | extra->texture_page = (header >> 12) & 0x1f; |
| 1397 | extra->texture_palette = (header >> 28) & 0xf; |
| 1398 | |
| 1399 | extra->texture_mirror_x = ((cmd & 0x10) ? 0x1 : 0); |
| 1400 | extra->texture_mirror_y = ((cmd & 0x10) ? 0x1 : 0); |
| 1401 | |
| 1402 | if (poly_type == 0) |
| 1403 | { |
| 1404 | poly_render_triangle(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_2d_tex, 5, &v[0], &v[1], &v[2]); |
| 1405 | } |
| 1406 | else |
| 1407 | { |
| 1408 | poly_render_quad(poly, K001005_bitmap[K001005_bitmap_page], visarea, draw_scanline_2d_tex, 5, &v[0], &v[1], &v[2], &v[3]); |
| 1409 | } |
| 1410 | } |
| 1411 | else if (cmd == 0x80000000) |
| 1412 | { |
| 1413 | |
| 1414 | } |
| 1415 | else if (cmd == 0x80000018) |
| 1416 | { |
| 1417 | |
| 1418 | } |
| 1419 | else if ((cmd & 0xffffff00) == 0x80000000) |
| 1420 | { |
| 925 | 1421 | /* |
| 926 | | mame_printf_debug("Unknown polygon type %08X:\n", K001005_3d_fifo[i]); |
| 927 | | for (j=0; j < 0x20; j++) |
| 928 | | { |
| 929 | | mame_printf_debug(" %02X: %08X\n", j, K001005_3d_fifo[i+1+j]); |
| 930 | | } |
| 931 | | mame_printf_debug("\n"); |
| 932 | | */ |
| 1422 | mame_printf_debug("Unknown polygon type %08X:\n", fifo[index-1]); |
| 1423 | for (int i=0; i < 0x20; i++) |
| 1424 | { |
| 1425 | mame_printf_debug(" %02X: %08X\n", i, fifo[index+i]); |
| 1426 | } |
| 1427 | mame_printf_debug("\n"); |
| 1428 | */ |
| 1429 | |
| 1430 | printf("Unknown polygon type %08X:\n", fifo[index-1]); |
| 1431 | for (int i=0; i < 0x20; i++) |
| 1432 | { |
| 1433 | printf(" %02X: %08X\n", i, fifo[index+i]); |
| 1434 | } |
| 1435 | printf("\n"); |
| 933 | 1436 | } |
| 1437 | else |
| 1438 | { |
| 1439 | |
| 1440 | } |
| 934 | 1441 | } |
| 1442 | while (index < K001005_3d_fifo_ptr); |
| 935 | 1443 | } |
| 936 | 1444 | |
| 1445 | |
| 937 | 1446 | void K001005_draw(bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 938 | 1447 | { |
| 939 | 1448 | int i, j; |
| r14632 | r14633 | |
| 961 | 1470 | |
| 962 | 1471 | //if (K001005_status == 2) |
| 963 | 1472 | { |
| 1473 | float zvalue = ZBUFFER_MAX; |
| 964 | 1474 | K001005_bitmap[K001005_bitmap_page]->fill(machine.pens[0]&0x00ffffff, K001005_cliprect); |
| 965 | | K001005_zbuffer->fill(0xffffffff, K001005_cliprect); |
| 1475 | K001005_zbuffer->fill(*(int*)&zvalue, K001005_cliprect); |
| 966 | 1476 | } |
| 967 | 1477 | } |
| 968 | 1478 | |
| 1479 | /* |
| 969 | 1480 | static int tick = 0; |
| 970 | 1481 | static int debug_tex_page = 0; |
| 971 | 1482 | static int debug_tex_palette = 0; |
| 1483 | */ |
| 972 | 1484 | |
| 973 | 1485 | VIDEO_START( gticlub ) |
| 974 | 1486 | { |
| 975 | 1487 | gticlub_led_reg[0] = gticlub_led_reg[1] = 0x7f; |
| 1488 | /* |
| 976 | 1489 | tick = 0; |
| 977 | 1490 | debug_tex_page = 0; |
| 978 | 1491 | debug_tex_palette = 0; |
| 1492 | */ |
| 979 | 1493 | |
| 980 | 1494 | K001006_init(machine); |
| 981 | 1495 | K001005_init(machine); |
| r14632 | r14633 | |
| 991 | 1505 | |
| 992 | 1506 | k001604_draw_front_layer(k001604, bitmap, cliprect); |
| 993 | 1507 | |
| 1508 | #if 0 |
| 994 | 1509 | tick++; |
| 995 | 1510 | if( tick >= 5 ) { |
| 996 | 1511 | tick = 0; |
| r14632 | r14633 | |
| 1017 | 1532 | debug_tex_palette = 0; |
| 1018 | 1533 | } |
| 1019 | 1534 | |
| 1020 | | #if 0 |
| 1021 | 1535 | if (debug_tex_page > 0) |
| 1022 | 1536 | { |
| 1023 | 1537 | char string[200]; |