trunk/src/mame/video/hng64.c
| r244675 | r244676 | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | |
| 10 | | static void hng64_mark_all_tiles_dirty( hng64_state *state, int tilemap ) |
| 10 | void hng64_state::hng64_mark_all_tiles_dirty( int tilemap ) |
| 11 | 11 | { |
| 12 | | state->m_tilemap[tilemap].m_tilemap_8x8->mark_all_dirty(); |
| 13 | | state->m_tilemap[tilemap].m_tilemap_16x16->mark_all_dirty(); |
| 14 | | state->m_tilemap[tilemap].m_tilemap_16x16_alt->mark_all_dirty(); |
| 12 | m_tilemap[tilemap].m_tilemap_8x8->mark_all_dirty(); |
| 13 | m_tilemap[tilemap].m_tilemap_16x16->mark_all_dirty(); |
| 14 | m_tilemap[tilemap].m_tilemap_16x16_alt->mark_all_dirty(); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | | static void hng64_mark_tile_dirty( hng64_state *state, int tilemap, int tile_index ) |
| 17 | void hng64_state::hng64_mark_tile_dirty( int tilemap, int tile_index ) |
| 18 | 18 | { |
| 19 | | state->m_tilemap[tilemap].m_tilemap_8x8->mark_tile_dirty(tile_index); |
| 20 | | state->m_tilemap[tilemap].m_tilemap_16x16->mark_tile_dirty(tile_index); |
| 21 | | state->m_tilemap[tilemap].m_tilemap_16x16_alt->mark_tile_dirty(tile_index); |
| 19 | m_tilemap[tilemap].m_tilemap_8x8->mark_tile_dirty(tile_index); |
| 20 | m_tilemap[tilemap].m_tilemap_16x16->mark_tile_dirty(tile_index); |
| 21 | m_tilemap[tilemap].m_tilemap_16x16_alt->mark_tile_dirty(tile_index); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| r244675 | r244676 | |
| 63 | 63 | * 0x0e0 in Samurai Shodown/Xrally games, 0x1c0 in all the others, zooming factor? |
| 64 | 64 | */ |
| 65 | 65 | |
| 66 | | static void draw_sprites(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 66 | void hng64_state::draw_sprites(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 67 | 67 | { |
| 68 | | hng64_state *state = screen.machine().driver_data<hng64_state>(); |
| 69 | 68 | gfx_element *gfx; |
| 70 | | UINT32 *source = state->m_spriteram; |
| 71 | | UINT32 *finish = state->m_spriteram + 0xc000/4; |
| 69 | UINT32 *source = m_spriteram; |
| 70 | UINT32 *finish = m_spriteram + 0xc000/4; |
| 72 | 71 | |
| 73 | 72 | // global offsets in sprite regs |
| 74 | | int spriteoffsx = (state->m_spriteregs[1]>>0)&0xffff; |
| 75 | | int spriteoffsy = (state->m_spriteregs[1]>>16)&0xffff; |
| 73 | int spriteoffsx = (m_spriteregs[1]>>0)&0xffff; |
| 74 | int spriteoffsy = (m_spriteregs[1]>>16)&0xffff; |
| 76 | 75 | |
| 77 | 76 | #if 0 |
| 78 | 77 | for (int iii = 0; iii < 0x0f; iii++) |
| 79 | | osd_printf_debug("%.8x ", state->m_videoregs[iii]); |
| 78 | osd_printf_debug("%.8x ", m_videoregs[iii]); |
| 80 | 79 | osd_printf_debug("\n"); |
| 81 | 80 | #endif |
| 82 | 81 | |
| r244675 | r244676 | |
| 140 | 139 | int zoom_factor; |
| 141 | 140 | |
| 142 | 141 | /* FIXME: regular zoom mode has precision bugs, can be easily seen in Samurai Shodown 64 intro */ |
| 143 | | zoom_factor = (state->m_spriteregs[0] & 0x08000000) ? 0x1000 : 0x100; |
| 142 | zoom_factor = (m_spriteregs[0] & 0x08000000) ? 0x1000 : 0x100; |
| 144 | 143 | if(!zoomx) zoomx=zoom_factor; |
| 145 | 144 | if(!zoomy) zoomy=zoom_factor; |
| 146 | 145 | |
| r244675 | r244676 | |
| 155 | 154 | zoomy += (int)((foomY - floor(foomY)) * (float)0x10000); |
| 156 | 155 | } |
| 157 | 156 | |
| 158 | | if (state->m_spriteregs[0] & 0x00800000) //bpp switch |
| 157 | if (m_spriteregs[0] & 0x00800000) //bpp switch |
| 159 | 158 | { |
| 160 | | gfx= state->m_gfxdecode->gfx(4); |
| 159 | gfx= m_gfxdecode->gfx(4); |
| 161 | 160 | } |
| 162 | 161 | else |
| 163 | 162 | { |
| 164 | | gfx= state->m_gfxdecode->gfx(5); |
| 163 | gfx= m_gfxdecode->gfx(5); |
| 165 | 164 | tileno>>=1; |
| 166 | 165 | pal&=0xf; |
| 167 | 166 | } |
| r244675 | r244676 | |
| 220 | 219 | tileno=(source[4]&0x0007ffff); |
| 221 | 220 | pal =(source[3]&0x00ff0000)>>16; |
| 222 | 221 | |
| 223 | | if (state->m_spriteregs[0] & 0x00800000) //bpp switch |
| 222 | if (m_spriteregs[0] & 0x00800000) //bpp switch |
| 224 | 223 | { |
| 225 | | gfx= state->m_gfxdecode->gfx(4); |
| 224 | gfx= m_gfxdecode->gfx(4); |
| 226 | 225 | } |
| 227 | 226 | else |
| 228 | 227 | { |
| 229 | | gfx= state->m_gfxdecode->gfx(5); |
| 228 | gfx= m_gfxdecode->gfx(5); |
| 230 | 229 | tileno>>=1; |
| 231 | 230 | pal&=0xf; |
| 232 | 231 | } |
| r244675 | r244676 | |
| 286 | 285 | */ |
| 287 | 286 | |
| 288 | 287 | /* this is broken for the 'How to Play' screen in Buriki after attract, disabled for now */ |
| 289 | | static void transition_control(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 288 | void hng64_state::transition_control( bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 290 | 289 | { |
| 291 | | hng64_state *state = machine.driver_data<hng64_state>(); |
| 292 | | UINT32 *hng64_tcram = state->m_tcram; |
| 290 | UINT32 *hng64_tcram = m_tcram; |
| 293 | 291 | int i, j; |
| 294 | 292 | |
| 295 | 293 | // float colorScaleR, colorScaleG, colorScaleB; |
| r244675 | r244676 | |
| 506 | 504 | WRITE32_MEMBER(hng64_state::hng64_videoram_w) |
| 507 | 505 | { |
| 508 | 506 | int realoff; |
| 509 | | hng64_state *state = machine().driver_data<hng64_state>(); |
| 510 | 507 | COMBINE_DATA(&m_videoram[offset]); |
| 511 | 508 | |
| 512 | 509 | realoff = offset*4; |
| 513 | 510 | |
| 514 | 511 | if ((realoff>=0) && (realoff<0x10000)) |
| 515 | 512 | { |
| 516 | | hng64_mark_tile_dirty(state, 0, offset&0x3fff); |
| 513 | hng64_mark_tile_dirty(0, offset&0x3fff); |
| 517 | 514 | } |
| 518 | 515 | else if ((realoff>=0x10000) && (realoff<0x20000)) |
| 519 | 516 | { |
| 520 | | hng64_mark_tile_dirty(state, 1, offset&0x3fff); |
| 517 | hng64_mark_tile_dirty(1, offset&0x3fff); |
| 521 | 518 | } |
| 522 | 519 | else if ((realoff>=0x20000) && (realoff<0x30000)) |
| 523 | 520 | { |
| 524 | | hng64_mark_tile_dirty(state, 2, offset&0x3fff); |
| 521 | hng64_mark_tile_dirty(2, offset&0x3fff); |
| 525 | 522 | } |
| 526 | 523 | else if ((realoff>=0x30000) && (realoff<0x40000)) |
| 527 | 524 | { |
| 528 | | hng64_mark_tile_dirty(state, 3, offset&0x3fff); |
| 525 | hng64_mark_tile_dirty(3, offset&0x3fff); |
| 529 | 526 | } |
| 530 | 527 | |
| 531 | 528 | // if ((realoff>=0x40000)) osd_printf_debug("offsw %08x %08x\n",realoff,data); |
| r244675 | r244676 | |
| 534 | 531 | } |
| 535 | 532 | |
| 536 | 533 | /* internal set of transparency states for rendering */ |
| 537 | | enum hng64trans_t |
| 538 | | { |
| 539 | | HNG64_TILEMAP_NORMAL = 1, |
| 540 | | HNG64_TILEMAP_ADDITIVE, |
| 541 | | HNG64_TILEMAP_ALPHA |
| 542 | | }; |
| 543 | 534 | |
| 544 | 535 | |
| 545 | | struct blit_parameters |
| 546 | | { |
| 547 | | bitmap_rgb32 * bitmap; |
| 548 | | rectangle cliprect; |
| 549 | | UINT32 tilemap_priority_code; |
| 550 | | UINT8 mask; |
| 551 | | UINT8 value; |
| 552 | | UINT8 alpha; |
| 553 | | hng64trans_t drawformat; |
| 554 | | }; |
| 555 | | |
| 556 | | |
| 557 | | |
| 558 | 536 | static void hng64_configure_blit_parameters(blit_parameters *blit, tilemap_t *tmap, bitmap_rgb32 &dest, const rectangle &cliprect, UINT32 flags, UINT8 priority, UINT8 priority_mask, hng64trans_t drawformat) |
| 559 | 537 | { |
| 560 | 538 | /* start with nothing */ |
| r244675 | r244676 | |
| 631 | 609 | *(UINT32 *)dest = alpha_blend_r32(*(UINT32 *)dest, clut[INPUT_VAL], alpha); \ |
| 632 | 610 | } while (0) |
| 633 | 611 | |
| 634 | | static void hng64_tilemap_draw_roz_core(screen_device &screen, tilemap_t *tmap, const blit_parameters *blit, |
| 612 | void hng64_state::hng64_tilemap_draw_roz_core(screen_device &screen, tilemap_t *tmap, const blit_parameters *blit, |
| 635 | 613 | UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, int wraparound) |
| 636 | 614 | { |
| 637 | | hng64_state *state = screen.machine().driver_data<hng64_state>(); |
| 638 | | const pen_t *clut = &state->m_palette->pen(blit->tilemap_priority_code >> 16); |
| 615 | const pen_t *clut = &m_palette->pen(blit->tilemap_priority_code >> 16); |
| 639 | 616 | bitmap_ind8 &priority_bitmap = screen.priority(); |
| 640 | 617 | bitmap_rgb32 &destbitmap = *blit->bitmap; |
| 641 | 618 | bitmap_ind16 &srcbitmap = tmap->pixmap(); |
| r244675 | r244676 | |
| 809 | 786 | |
| 810 | 787 | |
| 811 | 788 | |
| 812 | | static void hng64_tilemap_draw_roz_primask(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap, |
| 789 | void hng64_state::hng64_tilemap_draw_roz_primask(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap, |
| 813 | 790 | UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, |
| 814 | 791 | int wraparound, UINT32 flags, UINT8 priority, UINT8 priority_mask, hng64trans_t drawformat) |
| 815 | 792 | { |
| r244675 | r244676 | |
| 837 | 814 | } |
| 838 | 815 | |
| 839 | 816 | |
| 840 | | INLINE void hng64_tilemap_draw_roz(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap, |
| 817 | inline void hng64_state::hng64_tilemap_draw_roz(screen_device &screen, bitmap_rgb32 &dest, const rectangle &cliprect, tilemap_t *tmap, |
| 841 | 818 | UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, |
| 842 | 819 | int wraparound, UINT32 flags, UINT8 priority, hng64trans_t drawformat) |
| 843 | 820 | { |
| r244675 | r244676 | |
| 846 | 823 | |
| 847 | 824 | |
| 848 | 825 | |
| 849 | | static void hng64_drawtilemap(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int tm ) |
| 826 | void hng64_state::hng64_drawtilemap(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, int tm ) |
| 850 | 827 | { |
| 851 | | hng64_state *state = screen.machine().driver_data<hng64_state>(); |
| 852 | | UINT32 *hng64_videoregs = state->m_videoregs; |
| 853 | | UINT32 *hng64_videoram = state->m_videoram; |
| 828 | UINT32 *hng64_videoregs = m_videoregs; |
| 829 | UINT32 *hng64_videoram = m_videoram; |
| 854 | 830 | tilemap_t* tilemap = 0; |
| 855 | 831 | UINT32 scrollbase = 0; |
| 856 | 832 | UINT32 tileregs = 0; |
| r244675 | r244676 | |
| 861 | 837 | |
| 862 | 838 | int global_dimensions = (global_tileregs&0x03000000)>>24; |
| 863 | 839 | |
| 864 | | if ( (state->m_additive_tilemap_debug&(1 << tm))) |
| 840 | if ( (m_additive_tilemap_debug&(1 << tm))) |
| 865 | 841 | debug_blend_enabled = 1; |
| 866 | 842 | |
| 867 | 843 | if ((global_dimensions != 0) && (global_dimensions != 3)) |
| r244675 | r244676 | |
| 890 | 866 | |
| 891 | 867 | if (global_dimensions==0) |
| 892 | 868 | { |
| 893 | | if (tileregs&0x0200) tilemap = state->m_tilemap[tm].m_tilemap_16x16; |
| 894 | | else tilemap = state->m_tilemap[tm].m_tilemap_8x8; |
| 869 | if (tileregs&0x0200) tilemap = m_tilemap[tm].m_tilemap_16x16; |
| 870 | else tilemap = m_tilemap[tm].m_tilemap_8x8; |
| 895 | 871 | } |
| 896 | 872 | else |
| 897 | 873 | { |
| 898 | | if (tileregs&0x0200) tilemap = state->m_tilemap[tm].m_tilemap_16x16_alt; |
| 899 | | else tilemap = state->m_tilemap[tm].m_tilemap_8x8; // _alt |
| 874 | if (tileregs&0x0200) tilemap = m_tilemap[tm].m_tilemap_16x16_alt; |
| 875 | else tilemap = m_tilemap[tm].m_tilemap_8x8; // _alt |
| 900 | 876 | } |
| 901 | 877 | |
| 902 | 878 | // xrally's pink tilemaps make me think this is a tilemap enable bit. |
| r244675 | r244676 | |
| 1051 | 1027 | bitmap_ind16 &bm = tilemap->pixmap(); |
| 1052 | 1028 | int bmheight = bm.height(); |
| 1053 | 1029 | int bmwidth = bm.width(); |
| 1054 | | const pen_t *paldata = state->m_palette->pens(); |
| 1030 | const pen_t *paldata = m_palette->pens(); |
| 1055 | 1031 | UINT32* dstptr; |
| 1056 | 1032 | UINT16* srcptr; |
| 1057 | 1033 | int xx,yy; |
| r244675 | r244676 | |
| 1147 | 1123 | bitmap_ind16 &bm = tilemap->pixmap(); |
| 1148 | 1124 | int bmheight = bm.height(); |
| 1149 | 1125 | int bmwidth = bm.width(); |
| 1150 | | const pen_t *paldata = state->m_palette->pens(); |
| 1126 | const pen_t *paldata = m_palette->pens(); |
| 1151 | 1127 | UINT32* dstptr; |
| 1152 | 1128 | UINT16* srcptr; |
| 1153 | 1129 | int xx,yy; |
| r244675 | r244676 | |
| 1293 | 1269 | { |
| 1294 | 1270 | if (hng64_videoram[tile_index+(0x00000/4)]&0x200000) |
| 1295 | 1271 | { |
| 1296 | | hng64_mark_tile_dirty(this, 0, tile_index); |
| 1272 | hng64_mark_tile_dirty(0, tile_index); |
| 1297 | 1273 | } |
| 1298 | 1274 | if (hng64_videoram[tile_index+(0x10000/4)]&0x200000) |
| 1299 | 1275 | { |
| 1300 | | hng64_mark_tile_dirty(this, 1, tile_index); |
| 1276 | hng64_mark_tile_dirty(1, tile_index); |
| 1301 | 1277 | } |
| 1302 | 1278 | if (hng64_videoram[tile_index+(0x20000/4)]&0x200000) |
| 1303 | 1279 | { |
| 1304 | | hng64_mark_tile_dirty(this, 2, tile_index); |
| 1280 | hng64_mark_tile_dirty(2, tile_index); |
| 1305 | 1281 | } |
| 1306 | 1282 | if (hng64_videoram[tile_index+(0x30000/4)]&0x200000) |
| 1307 | 1283 | { |
| 1308 | | hng64_mark_tile_dirty(this, 3, tile_index); |
| 1284 | hng64_mark_tile_dirty(3, tile_index); |
| 1309 | 1285 | } |
| 1310 | 1286 | } |
| 1311 | 1287 | |
| r244675 | r244676 | |
| 1317 | 1293 | { |
| 1318 | 1294 | if ((m_old_tileflags[i]&IMPORTANT_DIRTY_TILEFLAG_MASK)!=(tileflags[i]&IMPORTANT_DIRTY_TILEFLAG_MASK)) |
| 1319 | 1295 | { |
| 1320 | | hng64_mark_all_tiles_dirty(this, i); |
| 1296 | hng64_mark_all_tiles_dirty(i); |
| 1321 | 1297 | m_old_tileflags[i] = tileflags[i]; |
| 1322 | 1298 | } |
| 1323 | 1299 | } |
| r244675 | r244676 | |
| 1354 | 1330 | draw_sprites(screen, bitmap,cliprect); |
| 1355 | 1331 | |
| 1356 | 1332 | if(0) |
| 1357 | | transition_control(machine(), bitmap, cliprect); |
| 1333 | transition_control(bitmap, cliprect); |
| 1358 | 1334 | |
| 1359 | 1335 | if (0) |
| 1360 | 1336 | popmessage("%08x %08x %08x %08x %08x", m_spriteregs[0], m_spriteregs[1], m_spriteregs[2], m_spriteregs[3], m_spriteregs[4]); |
| r244675 | r244676 | |
| 1528 | 1504 | static void vecmatmul4(float *product, const float *a, const float *b); |
| 1529 | 1505 | static float vecDotProduct(const float *a, const float *b); |
| 1530 | 1506 | static void normalize(float* x); |
| 1531 | | |
| 1532 | 1507 | static void performFrustumClip(struct polygon *p); |
| 1533 | | static void drawShaded(running_machine &machine, struct polygon *p); |
| 1534 | | //static void plot(running_machine &machine, INT32 x, INT32 y, UINT32 color); |
| 1535 | | //static void drawline2d(running_machine &machine, INT32 x0, INT32 y0, INT32 x1, INT32 y1, UINT32 color); |
| 1536 | | //static void DrawWireframe(running_machine &machine, struct polygon *p); |
| 1537 | | |
| 1538 | 1508 | static float uToF(UINT16 input); |
| 1539 | 1509 | |
| 1540 | 1510 | |
| r244675 | r244676 | |
| 1572 | 1542 | |
| 1573 | 1543 | // Operation 0001 |
| 1574 | 1544 | // Camera transformation. |
| 1575 | | static void setCameraTransformation(hng64_state *state, const UINT16* packet) |
| 1545 | void hng64_state::setCameraTransformation(const UINT16* packet) |
| 1576 | 1546 | { |
| 1577 | | float *cameraMatrix = state->m_cameraMatrix; |
| 1547 | float *cameraMatrix = m_cameraMatrix; |
| 1578 | 1548 | |
| 1579 | 1549 | /*////////////// |
| 1580 | 1550 | // PACKET FORMAT |
| r244675 | r244676 | |
| 1619 | 1589 | |
| 1620 | 1590 | // Operation 0010 |
| 1621 | 1591 | // Lighting information |
| 1622 | | static void setLighting(hng64_state *state, const UINT16* packet) |
| 1592 | void hng64_state::setLighting(const UINT16* packet) |
| 1623 | 1593 | { |
| 1624 | | float *lightVector = state->m_lightVector; |
| 1594 | float *lightVector = m_lightVector; |
| 1625 | 1595 | |
| 1626 | 1596 | /*////////////// |
| 1627 | 1597 | // PACKET FORMAT |
| r244675 | r244676 | |
| 1648 | 1618 | lightVector[0] = uToF(packet[3]); |
| 1649 | 1619 | lightVector[1] = uToF(packet[4]); |
| 1650 | 1620 | lightVector[2] = uToF(packet[5]); |
| 1651 | | state->m_lightStrength = uToF(packet[9]); |
| 1621 | m_lightStrength = uToF(packet[9]); |
| 1652 | 1622 | } |
| 1653 | 1623 | |
| 1654 | 1624 | // Operation 0011 |
| 1655 | 1625 | // Palette / Model flags? |
| 1656 | | static void set3dFlags(hng64_state *state, const UINT16* packet) |
| 1626 | void hng64_state::set3dFlags(const UINT16* packet) |
| 1657 | 1627 | { |
| 1658 | 1628 | /*////////////// |
| 1659 | 1629 | // PACKET FORMAT |
| r244675 | r244676 | |
| 1674 | 1644 | // [14] - ???? ... ? '' '' |
| 1675 | 1645 | // [15] - ???? ... ? '' '' |
| 1676 | 1646 | ////////////*/ |
| 1677 | | state->m_paletteState3d = (packet[8] & 0xff00) >> 8; |
| 1647 | m_paletteState3d = (packet[8] & 0xff00) >> 8; |
| 1678 | 1648 | } |
| 1679 | 1649 | |
| 1680 | 1650 | // Operation 0012 |
| 1681 | 1651 | // Projection Matrix. |
| 1682 | | static void setCameraProjectionMatrix(hng64_state *state, const UINT16* packet) |
| 1652 | void hng64_state::setCameraProjectionMatrix(const UINT16* packet) |
| 1683 | 1653 | { |
| 1684 | | float *projectionMatrix = state->m_projectionMatrix; |
| 1654 | float *projectionMatrix = m_projectionMatrix; |
| 1685 | 1655 | |
| 1686 | 1656 | /*////////////// |
| 1687 | 1657 | // PACKET FORMAT |
| r244675 | r244676 | |
| 1737 | 1707 | |
| 1738 | 1708 | // Operation 0100 |
| 1739 | 1709 | // Polygon rasterization. |
| 1740 | | static void recoverPolygonBlock(running_machine& machine, const UINT16* packet, struct polygon* polys, int* numPolys) |
| 1710 | void hng64_state::recoverPolygonBlock(const UINT16* packet, struct polygon* polys, int* numPolys) |
| 1741 | 1711 | { |
| 1742 | 1712 | /*////////////// |
| 1743 | 1713 | // PACKET FORMAT |
| r244675 | r244676 | |
| 1774 | 1744 | // [15] - xxxx ... Transformation matrix |
| 1775 | 1745 | ////////////*/ |
| 1776 | 1746 | |
| 1777 | | hng64_state *state = machine.driver_data<hng64_state>(); |
| 1778 | 1747 | UINT32 size[4]; |
| 1779 | 1748 | UINT32 address[4]; |
| 1780 | 1749 | UINT32 megaOffset; |
| r244675 | r244676 | |
| 1788 | 1757 | setIdentity(objectMatrix); |
| 1789 | 1758 | |
| 1790 | 1759 | struct polygon lastPoly = { 0 }; |
| 1791 | | const rectangle &visarea = machine.first_screen()->visible_area(); |
| 1760 | const rectangle &visarea = m_screen->visible_area(); |
| 1792 | 1761 | |
| 1793 | 1762 | ///////////////// |
| 1794 | 1763 | // HEADER INFO // |
| r244675 | r244676 | |
| 1844 | 1813 | //////////////////////////////////////////////*/ |
| 1845 | 1814 | |
| 1846 | 1815 | // 3d ROM Offset |
| 1847 | | UINT16* threeDRoms = (UINT16*)(machine.root_device().memregion("verts")->base()); |
| 1816 | UINT16* threeDRoms = (UINT16*)memregion("verts")->base(); |
| 1848 | 1817 | UINT32 threeDOffset = (((UINT32)packet[2]) << 16) | ((UINT32)packet[3]); |
| 1849 | 1818 | UINT16* threeDPointer = &threeDRoms[threeDOffset * 3]; |
| 1850 | 1819 | |
| 1851 | | if (threeDOffset >= machine.root_device().memregion("verts")->bytes()) |
| 1820 | if (threeDOffset >= memregion("verts")->bytes()) |
| 1852 | 1821 | { |
| 1853 | 1822 | printf("Strange geometry packet: (ignoring)\n"); |
| 1854 | 1823 | printPacket(packet, 1); |
| r244675 | r244676 | |
| 1973 | 1942 | /* FIXME: This isn't correct. |
| 1974 | 1943 | Buriki & Xrally need this line. Roads Edge needs it removed. |
| 1975 | 1944 | So instead we're looking for a bit that is on for XRally & Buriki, but noone else. */ |
| 1976 | | if (state->m_3dregs[0x00/4] & 0x2000) |
| 1945 | if (m_3dregs[0x00/4] & 0x2000) |
| 1977 | 1946 | { |
| 1978 | | if (strcmp(machine.basename(), "roadedge")) |
| 1947 | if (strcmp(machine().basename(), "roadedge")) |
| 1979 | 1948 | polys[*numPolys].palOffset += 0x800; |
| 1980 | 1949 | } |
| 1981 | 1950 | |
| r244675 | r244676 | |
| 1989 | 1958 | // Apply the dynamic palette offset if its flag is set, otherwise stick with the fixed one |
| 1990 | 1959 | if ((packet[1] & 0x0100)) |
| 1991 | 1960 | { |
| 1992 | | explicitPaletteValue1 = state->m_paletteState3d * 0x80; |
| 1961 | explicitPaletteValue1 = m_paletteState3d * 0x80; |
| 1993 | 1962 | explicitPaletteValue2 = 0; // This is probably hiding somewhere in operation 0011 |
| 1994 | 1963 | } |
| 1995 | 1964 | |
| r244675 | r244676 | |
| 2183 | 2152 | //////////////////////////////////// |
| 2184 | 2153 | // Perform the world transformations... |
| 2185 | 2154 | // !! Can eliminate this step with a matrix stack (maybe necessary?) !! |
| 2186 | | setIdentity(state->m_modelViewMatrix); |
| 2187 | | if (state->m_mcu_type != SAMSHO_MCU) |
| 2155 | setIdentity(m_modelViewMatrix); |
| 2156 | if (m_mcu_type != SAMSHO_MCU) |
| 2188 | 2157 | { |
| 2189 | 2158 | // The sams64 games transform the geometry in front of a stationary camera. |
| 2190 | 2159 | // This is fine in sams64_2, since it never calls the 'camera transformation' function |
| 2191 | 2160 | // (thus using the identity matrix for this transform), but sams64 calls the |
| 2192 | 2161 | // camera transformation function with rotation values. |
| 2193 | 2162 | // It remains to be seen what those might do... |
| 2194 | | matmul4(state->m_modelViewMatrix, state->m_modelViewMatrix, state->m_cameraMatrix); |
| 2163 | matmul4(m_modelViewMatrix, m_modelViewMatrix, m_cameraMatrix); |
| 2195 | 2164 | } |
| 2196 | | matmul4(state->m_modelViewMatrix, state->m_modelViewMatrix, objectMatrix); |
| 2165 | matmul4(m_modelViewMatrix, m_modelViewMatrix, objectMatrix); |
| 2197 | 2166 | |
| 2198 | 2167 | // LIGHTING |
| 2199 | | if (packet[1] & 0x0008 && state->m_lightStrength > 0.0f) |
| 2168 | if (packet[1] & 0x0008 && m_lightStrength > 0.0f) |
| 2200 | 2169 | { |
| 2201 | 2170 | for (int v = 0; v < 3; v++) |
| 2202 | 2171 | { |
| 2203 | 2172 | float transformedNormal[4]; |
| 2204 | 2173 | vecmatmul4(transformedNormal, objectMatrix, polys[*numPolys].vert[v].normal); |
| 2205 | 2174 | normalize(transformedNormal); |
| 2206 | | normalize(state->m_lightVector); |
| 2175 | normalize(m_lightVector); |
| 2207 | 2176 | |
| 2208 | | float intensity = vecDotProduct(transformedNormal, state->m_lightVector) * -1.0f; |
| 2177 | float intensity = vecDotProduct(transformedNormal, m_lightVector) * -1.0f; |
| 2209 | 2178 | intensity = (intensity <= 0.0f) ? (0.0f) : (intensity); |
| 2210 | | intensity *= state->m_lightStrength * 128.0f; // Turns 0x0100 into 1.0 |
| 2179 | intensity *= m_lightStrength * 128.0f; // Turns 0x0100 into 1.0 |
| 2211 | 2180 | intensity *= 128.0; // Maps intensity to the range [0.0, 2.0] |
| 2212 | 2181 | if (intensity >= 255.0f) intensity = 255.0f; |
| 2213 | 2182 | |
| r244675 | r244676 | |
| 2250 | 2219 | |
| 2251 | 2220 | |
| 2252 | 2221 | // BEHIND-THE-CAMERA CULL // |
| 2253 | | vecmatmul4(cullRay, state->m_modelViewMatrix, polys[*numPolys].vert[0].worldCoords); |
| 2222 | vecmatmul4(cullRay, m_modelViewMatrix, polys[*numPolys].vert[0].worldCoords); |
| 2254 | 2223 | if (cullRay[2] > 0.0f) // Camera is pointing down -Z |
| 2255 | 2224 | { |
| 2256 | 2225 | polys[*numPolys].visible = 0; |
| r244675 | r244676 | |
| 2263 | 2232 | for (int m = 0; m < polys[*numPolys].n; m++) |
| 2264 | 2233 | { |
| 2265 | 2234 | // Transform and project the vertex into pre-divided homogeneous coordinates... |
| 2266 | | vecmatmul4(eyeCoords, state->m_modelViewMatrix, polys[*numPolys].vert[m].worldCoords); |
| 2267 | | vecmatmul4(polys[*numPolys].vert[m].clipCoords, state->m_projectionMatrix, eyeCoords); |
| 2235 | vecmatmul4(eyeCoords, m_modelViewMatrix, polys[*numPolys].vert[m].worldCoords); |
| 2236 | vecmatmul4(polys[*numPolys].vert[m].clipCoords, m_projectionMatrix, eyeCoords); |
| 2268 | 2237 | } |
| 2269 | 2238 | |
| 2270 | 2239 | if (polys[*numPolys].visible) |
| r244675 | r244676 | |
| 2304 | 2273 | } |
| 2305 | 2274 | } |
| 2306 | 2275 | |
| 2307 | | void hng64_command3d(running_machine& machine, const UINT16* packet) |
| 2276 | void hng64_state::hng64_command3d(const UINT16* packet) |
| 2308 | 2277 | { |
| 2309 | | hng64_state *state = machine.driver_data<hng64_state>(); |
| 2310 | 2278 | |
| 2311 | 2279 | /* A temporary place to put some polygons. This will optimize away if the compiler's any good. */ |
| 2312 | 2280 | int numPolys = 0; |
| 2313 | 2281 | dynamic_array<polygon> polys(1024*5); |
| 2314 | 2282 | |
| 2315 | | //printf("packet type : %04x %04x|%04x %04x|%04x %04x|%04x %04x\n", packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]); |
| 2283 | //printf("packet type : %04x %04x|%04x %04x|%04x %04x|%04x %04x | %04x %04x %04x %04x %04x %04x %04x %04x\n", packet[0],packet[1],packet[2],packet[3],packet[4],packet[5],packet[6],packet[7], packet[8], packet[9], packet[10], packet[11], packet[12], packet[13], packet[14], packet[15]); |
| 2284 | |
| 2316 | 2285 | switch (packet[0]) |
| 2317 | 2286 | { |
| 2318 | 2287 | case 0x0000: // Appears to be a NOP. |
| 2319 | 2288 | break; |
| 2320 | 2289 | |
| 2321 | 2290 | case 0x0001: // Camera transformation. |
| 2322 | | setCameraTransformation(state, packet); |
| 2291 | setCameraTransformation(packet); |
| 2323 | 2292 | break; |
| 2324 | 2293 | |
| 2325 | 2294 | case 0x0010: // Lighting information. |
| 2326 | 2295 | //if (packet[9]) printPacket(packet, 1); |
| 2327 | | setLighting(state, packet); |
| 2296 | setLighting(packet); |
| 2328 | 2297 | break; |
| 2329 | 2298 | |
| 2330 | 2299 | case 0x0011: // Palette / Model flags? |
| 2331 | 2300 | //printPacket(packet, 1); printf("\n"); |
| 2332 | | set3dFlags(state, packet); |
| 2301 | set3dFlags(packet); |
| 2333 | 2302 | break; |
| 2334 | 2303 | |
| 2335 | 2304 | case 0x0012: // Projection Matrix |
| 2336 | 2305 | //printPacket(packet, 1); |
| 2337 | | setCameraProjectionMatrix(state, packet); |
| 2306 | setCameraProjectionMatrix(packet); |
| 2338 | 2307 | break; |
| 2339 | 2308 | |
| 2340 | 2309 | case 0x0100: |
| 2341 | 2310 | case 0x0101: // Geometry with full transformations |
| 2342 | 2311 | // HACK. Masks out a piece of geo bbust2's drawShaded() crashes on. |
| 2343 | | if (packet[2] == 0x0003 && packet[3] == 0x8f37 && state->m_mcu_type == SHOOT_MCU) |
| 2312 | if (packet[2] == 0x0003 && packet[3] == 0x8f37 && m_mcu_type == SHOOT_MCU) |
| 2344 | 2313 | break; |
| 2345 | 2314 | |
| 2346 | | recoverPolygonBlock(machine, packet, polys, &numPolys); |
| 2315 | recoverPolygonBlock( packet, polys, &numPolys); |
| 2347 | 2316 | break; |
| 2348 | 2317 | |
| 2349 | 2318 | case 0x0102: // Geometry with only translation |
| r244675 | r244676 | |
| 2363 | 2332 | miniPacket[7] = 0x7fff; |
| 2364 | 2333 | miniPacket[11] = 0x7fff; |
| 2365 | 2334 | miniPacket[15] = 0x7fff; |
| 2366 | | recoverPolygonBlock(machine, miniPacket, polys, &numPolys); |
| 2335 | recoverPolygonBlock( miniPacket, polys, &numPolys); |
| 2367 | 2336 | |
| 2368 | 2337 | memset(miniPacket, 0, sizeof(UINT16)*16); |
| 2369 | 2338 | for (int i = 0; i < 7; i++) miniPacket[i] = packet[i+8]; |
| 2339 | for (int i = 0; i < 7; i++) miniPacket[i] = packet[i+8]; |
| 2370 | 2340 | miniPacket[7] = 0x7fff; |
| 2371 | 2341 | miniPacket[11] = 0x7fff; |
| 2372 | 2342 | miniPacket[15] = 0x7fff; |
| 2373 | | recoverPolygonBlock(machine, miniPacket, polys, &numPolys); |
| 2343 | recoverPolygonBlock( miniPacket, polys, &numPolys); |
| 2374 | 2344 | break; |
| 2375 | 2345 | |
| 2376 | 2346 | case 0x1000: // Unknown: Some sort of global flags? |
| r244675 | r244676 | |
| 2391 | 2361 | { |
| 2392 | 2362 | if (polys[i].visible) |
| 2393 | 2363 | { |
| 2394 | | //DrawWireframe(machine, &polys[i]); |
| 2395 | | drawShaded(machine, &polys[i]); |
| 2364 | //DrawWireframe( &polys[i]); |
| 2365 | drawShaded( &polys[i]); |
| 2396 | 2366 | } |
| 2397 | 2367 | } |
| 2398 | 2368 | } |
| r244675 | r244676 | |
| 2678 | 2648 | // wireframe rendering // |
| 2679 | 2649 | ///////////////////////// |
| 2680 | 2650 | #ifdef UNUSED_FUNCTION |
| 2681 | | static void plot(running_machine &machine, INT32 x, INT32 y, UINT32 color) |
| 2651 | static void plot( INT32 x, INT32 y, UINT32 color) |
| 2682 | 2652 | { |
| 2683 | 2653 | UINT32* cb = &(colorBuffer3d[(y * machine.first_screen()->visible_area().max_x) + x]); |
| 2684 | 2654 | *cb = color; |
| 2685 | 2655 | } |
| 2686 | 2656 | |
| 2687 | 2657 | // Stolen from http://en.wikipedia.org/wiki/Bresenham's_line_algorithm (no copyright denoted) - the non-optimized version |
| 2688 | | static void drawline2d(running_machine &machine, INT32 x0, INT32 y0, INT32 x1, INT32 y1, UINT32 color) |
| 2658 | static void drawline2d( INT32 x0, INT32 y0, INT32 x1, INT32 y1, UINT32 color) |
| 2689 | 2659 | { |
| 2690 | 2660 | #define SWAP(a,b) tmpswap = a; a = b; b = tmpswap; |
| 2691 | 2661 | |
| r244675 | r244676 | |
| 2723 | 2693 | { |
| 2724 | 2694 | if (steep) |
| 2725 | 2695 | { |
| 2726 | | plot(machine, x0, y0, color); |
| 2696 | plot( x0, y0, color); |
| 2727 | 2697 | } |
| 2728 | 2698 | else |
| 2729 | 2699 | { |
| 2730 | | plot(machine, y0, x0, color); |
| 2700 | plot( y0, x0, color); |
| 2731 | 2701 | } |
| 2732 | 2702 | while (e >= 0) |
| 2733 | 2703 | { |
| r244675 | r244676 | |
| 2741 | 2711 | #undef SWAP |
| 2742 | 2712 | } |
| 2743 | 2713 | |
| 2744 | | static void DrawWireframe(running_machine &machine, struct polygon *p) |
| 2714 | static void DrawWireframe( struct polygon *p) |
| 2745 | 2715 | { |
| 2746 | 2716 | int j; |
| 2747 | 2717 | for (j = 0; j < p->n; j++) |
| r244675 | r244676 | |
| 2749 | 2719 | // osd_printf_debug("now drawing : %f %f %f, %f %f %f\n", p->vert[j].clipCoords[0], p->vert[j].clipCoords[1], p->vert[j].clipCoords[2], p->vert[(j+1)%p->n].clipCoords[0], p->vert[(j+1)%p->n].clipCoords[1], p->vert[(j+1)%p->n].clipCoords[2]); |
| 2750 | 2720 | // osd_printf_debug("%f %f %f %f\n", p->vert[j].clipCoords[0], p->vert[j].clipCoords[1], p->vert[(j+1)%p->n].clipCoords[0], p->vert[(j+1)%p->n].clipCoords[1]); |
| 2751 | 2721 | UINT32 color = rgb_t((UINT8)255, (UINT8)255, (UINT8)0, (UINT8)0); |
| 2752 | | drawline2d(machine, p->vert[j].clipCoords[0], p->vert[j].clipCoords[1], p->vert[(j+1)%p->n].clipCoords[0], p->vert[(j+1)%p->n].clipCoords[1], color); |
| 2722 | drawline2d( p->vert[j].clipCoords[0], p->vert[j].clipCoords[1], p->vert[(j+1)%p->n].clipCoords[0], p->vert[(j+1)%p->n].clipCoords[1], color); |
| 2753 | 2723 | } |
| 2754 | 2724 | |
| 2755 | 2725 | // SHOWS THE CLIPPING // |
| r244675 | r244676 | |
| 2764 | 2734 | } |
| 2765 | 2735 | #endif |
| 2766 | 2736 | |
| 2767 | | /////////////////////// |
| 2768 | | // polygon rendering // |
| 2769 | | /////////////////////// |
| 2770 | 2737 | |
| 2771 | | struct polygonRasterOptions |
| 2772 | | { |
| 2773 | | UINT8 texType; |
| 2774 | | UINT8 texIndex; |
| 2775 | | UINT8 texPageSmall; |
| 2776 | | UINT8 texPageHorizOffset; |
| 2777 | | UINT8 texPageVertOffset; |
| 2778 | | int palOffset; |
| 2779 | | int palPageSize; |
| 2780 | | int debugColor; |
| 2781 | | }; |
| 2782 | | |
| 2783 | 2738 | /*********************************************************************/ |
| 2784 | 2739 | /** FillSmoothTexPCHorizontalLine **/ |
| 2785 | 2740 | /** Input: Color Buffer (framebuffer), depth buffer, width and **/ |
| r244675 | r244676 | |
| 2789 | 2744 | /** **/ |
| 2790 | 2745 | /** Output: none **/ |
| 2791 | 2746 | /*********************************************************************/ |
| 2792 | | INLINE void FillSmoothTexPCHorizontalLine(running_machine &machine, |
| 2747 | inline void hng64_state::FillSmoothTexPCHorizontalLine( |
| 2793 | 2748 | const polygonRasterOptions& prOptions, |
| 2794 | 2749 | int x_start, int x_end, int y, float z_start, float z_delta, |
| 2795 | 2750 | float w_start, float w_delta, float r_start, float r_delta, |
| 2796 | 2751 | float g_start, float g_delta, float b_start, float b_delta, |
| 2797 | 2752 | float s_start, float s_delta, float t_start, float t_delta) |
| 2798 | 2753 | { |
| 2799 | | hng64_state *state = machine.driver_data<hng64_state>(); |
| 2800 | | float* db = &(state->m_depthBuffer3d[(y * machine.first_screen()->visible_area().max_x) + x_start]); |
| 2801 | | UINT32* cb = &(state->m_colorBuffer3d[(y * machine.first_screen()->visible_area().max_x) + x_start]); |
| 2754 | float* db = &(m_depthBuffer3d[(y * m_screen->visible_area().max_x) + x_start]); |
| 2755 | UINT32* cb = &(m_colorBuffer3d[(y * m_screen->visible_area().max_x) + x_start]); |
| 2802 | 2756 | |
| 2803 | 2757 | UINT8 paletteEntry = 0; |
| 2804 | 2758 | float t_coord, s_coord; |
| 2805 | | const UINT8 *gfx = state->memregion("textures")->base(); |
| 2759 | const UINT8 *gfx = memregion("textures")->base(); |
| 2806 | 2760 | const UINT8 *textureOffset = &gfx[prOptions.texIndex * 1024 * 1024]; |
| 2807 | 2761 | |
| 2808 | 2762 | for (; x_start <= x_end; x_start++) |
| r244675 | r244676 | |
| 2864 | 2818 | { |
| 2865 | 2819 | // The color out of the texture |
| 2866 | 2820 | paletteEntry %= prOptions.palPageSize; |
| 2867 | | rgb_t color = state->m_palette->pen(prOptions.palOffset + paletteEntry); |
| 2821 | rgb_t color = m_palette->pen(prOptions.palOffset + paletteEntry); |
| 2868 | 2822 | |
| 2869 | 2823 | // Apply the lighting |
| 2870 | 2824 | float rIntensity = (r_start/w_start) / 255.0f; |
| r244675 | r244676 | |
| 2932 | 2886 | // nearest and bilinear filtering: Filtering={0,1} |
| 2933 | 2887 | // replace and modulate application modes: Function={0,1} |
| 2934 | 2888 | //--------------------------------------------------------------------------- |
| 2935 | | static void RasterizeTriangle_SMOOTH_TEX_PC(running_machine &machine, |
| 2889 | void hng64_state::RasterizeTriangle_SMOOTH_TEX_PC( |
| 2936 | 2890 | float A[4], float B[4], float C[4], |
| 2937 | 2891 | float Ca[3], float Cb[3], float Cc[3], // PER-VERTEX RGB COLORS |
| 2938 | 2892 | float Ta[2], float Tb[2], float Tc[2], // PER-VERTEX (S,T) TEX-COORDS |
| r244675 | r244676 | |
| 3126 | 3080 | |
| 3127 | 3081 | // Pass the horizontal line to the filler, this could be put in the routine |
| 3128 | 3082 | // then interpolate for the next values of x and z |
| 3129 | | FillSmoothTexPCHorizontalLine(machine, prOptions, |
| 3083 | FillSmoothTexPCHorizontalLine( prOptions, |
| 3130 | 3084 | x_start, x_end, y_min, z_interp_x, z_delta_x, w_interp_x, w_delta_x, |
| 3131 | 3085 | r_interp_x, r_delta_x, g_interp_x, g_delta_x, b_interp_x, b_delta_x, |
| 3132 | 3086 | s_interp_x, s_delta_x, t_interp_x, t_delta_x); |
| r244675 | r244676 | |
| 3205 | 3159 | |
| 3206 | 3160 | // Pass the horizontal line to the filler, this could be put in the routine |
| 3207 | 3161 | // then interpolate for the next values of x and z |
| 3208 | | FillSmoothTexPCHorizontalLine(machine, prOptions, |
| 3162 | FillSmoothTexPCHorizontalLine( prOptions, |
| 3209 | 3163 | x_start, x_end, y_mid, z_interp_x, z_delta_x, w_interp_x, w_delta_x, |
| 3210 | 3164 | r_interp_x, r_delta_x, g_interp_x, g_delta_x, b_interp_x, b_delta_x, |
| 3211 | 3165 | s_interp_x, s_delta_x, t_interp_x, t_delta_x); |
| r244675 | r244676 | |
| 3220 | 3174 | } |
| 3221 | 3175 | } |
| 3222 | 3176 | |
| 3223 | | static void drawShaded(running_machine &machine, struct polygon *p) |
| 3177 | void hng64_state::drawShaded( struct polygon *p) |
| 3224 | 3178 | { |
| 3225 | 3179 | // The perspective-correct texture divide... |
| 3226 | 3180 | // !!! There is a very good chance the HNG64 hardware does not do perspective-correct texture-mapping !!! |
| r244675 | r244676 | |
| 3248 | 3202 | |
| 3249 | 3203 | for (j = 1; j < p->n-1; j++) |
| 3250 | 3204 | { |
| 3251 | | RasterizeTriangle_SMOOTH_TEX_PC(machine, |
| 3205 | RasterizeTriangle_SMOOTH_TEX_PC( |
| 3252 | 3206 | p->vert[0].clipCoords, p->vert[j].clipCoords, p->vert[j+1].clipCoords, |
| 3253 | 3207 | p->vert[0].light, p->vert[j].light, p->vert[j+1].light, |
| 3254 | 3208 | p->vert[0].texCoords, p->vert[j].texCoords, p->vert[j+1].texCoords, |