trunk/src/mame/video/hng64.c
| r244678 | r244679 | |
| 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 | | if (tilemap == 0) |
| 13 | | { |
| 14 | | state->m_tilemap0_8x8->mark_all_dirty(); |
| 15 | | state->m_tilemap0_16x16->mark_all_dirty(); |
| 16 | | state->m_tilemap0_16x16_alt->mark_all_dirty(); |
| 17 | | } |
| 18 | | else if (tilemap == 1) |
| 19 | | { |
| 20 | | state->m_tilemap1_8x8->mark_all_dirty(); |
| 21 | | state->m_tilemap1_16x16->mark_all_dirty(); |
| 22 | | state->m_tilemap1_16x16_alt->mark_all_dirty(); |
| 23 | | } |
| 24 | | else if (tilemap == 2) |
| 25 | | { |
| 26 | | state->m_tilemap2_8x8->mark_all_dirty(); |
| 27 | | state->m_tilemap2_16x16->mark_all_dirty(); |
| 28 | | state->m_tilemap2_16x16_alt->mark_all_dirty(); |
| 29 | | } |
| 30 | | else if (tilemap == 3) |
| 31 | | { |
| 32 | | state->m_tilemap3_8x8->mark_all_dirty(); |
| 33 | | state->m_tilemap3_16x16->mark_all_dirty(); |
| 34 | | state->m_tilemap3_16x16_alt->mark_all_dirty(); |
| 35 | | } |
| 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(); |
| 36 | 15 | } |
| 37 | 16 | |
| 38 | | 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 ) |
| 39 | 18 | { |
| 40 | | if (tilemap == 0) |
| 41 | | { |
| 42 | | state->m_tilemap0_8x8->mark_tile_dirty(tile_index); |
| 43 | | state->m_tilemap0_16x16->mark_tile_dirty(tile_index); |
| 44 | | state->m_tilemap0_16x16_alt->mark_tile_dirty(tile_index); |
| 45 | | } |
| 46 | | else if (tilemap == 1) |
| 47 | | { |
| 48 | | state->m_tilemap1_8x8->mark_tile_dirty(tile_index); |
| 49 | | state->m_tilemap1_16x16->mark_tile_dirty(tile_index); |
| 50 | | state->m_tilemap1_16x16_alt->mark_tile_dirty(tile_index); |
| 51 | | } |
| 52 | | else if (tilemap == 2) |
| 53 | | { |
| 54 | | state->m_tilemap2_8x8->mark_tile_dirty(tile_index); |
| 55 | | state->m_tilemap2_16x16->mark_tile_dirty(tile_index); |
| 56 | | state->m_tilemap2_16x16_alt->mark_tile_dirty(tile_index); |
| 57 | | } |
| 58 | | else if (tilemap == 3) |
| 59 | | { |
| 60 | | state->m_tilemap3_8x8->mark_tile_dirty(tile_index); |
| 61 | | state->m_tilemap3_16x16->mark_tile_dirty(tile_index); |
| 62 | | state->m_tilemap3_16x16_alt->mark_tile_dirty(tile_index); |
| 63 | | } |
| 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); |
| 64 | 22 | } |
| 65 | 23 | |
| 66 | 24 | |
| r244678 | r244679 | |
| 105 | 63 | * 0x0e0 in Samurai Shodown/Xrally games, 0x1c0 in all the others, zooming factor? |
| 106 | 64 | */ |
| 107 | 65 | |
| 108 | | 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) |
| 109 | 67 | { |
| 110 | | hng64_state *state = screen.machine().driver_data<hng64_state>(); |
| 111 | 68 | gfx_element *gfx; |
| 112 | | UINT32 *source = state->m_spriteram; |
| 113 | | UINT32 *finish = state->m_spriteram + 0xc000/4; |
| 69 | UINT32 *source = m_spriteram; |
| 70 | UINT32 *finish = m_spriteram + 0xc000/4; |
| 114 | 71 | |
| 115 | 72 | // global offsets in sprite regs |
| 116 | | int spriteoffsx = (state->m_spriteregs[1]>>0)&0xffff; |
| 117 | | int spriteoffsy = (state->m_spriteregs[1]>>16)&0xffff; |
| 73 | int spriteoffsx = (m_spriteregs[1]>>0)&0xffff; |
| 74 | int spriteoffsy = (m_spriteregs[1]>>16)&0xffff; |
| 118 | 75 | |
| 119 | 76 | #if 0 |
| 120 | 77 | for (int iii = 0; iii < 0x0f; iii++) |
| 121 | | osd_printf_debug("%.8x ", state->m_videoregs[iii]); |
| 78 | osd_printf_debug("%.8x ", m_videoregs[iii]); |
| 122 | 79 | osd_printf_debug("\n"); |
| 123 | 80 | #endif |
| 124 | 81 | |
| r244678 | r244679 | |
| 182 | 139 | int zoom_factor; |
| 183 | 140 | |
| 184 | 141 | /* FIXME: regular zoom mode has precision bugs, can be easily seen in Samurai Shodown 64 intro */ |
| 185 | | zoom_factor = (state->m_spriteregs[0] & 0x08000000) ? 0x1000 : 0x100; |
| 142 | zoom_factor = (m_spriteregs[0] & 0x08000000) ? 0x1000 : 0x100; |
| 186 | 143 | if(!zoomx) zoomx=zoom_factor; |
| 187 | 144 | if(!zoomy) zoomy=zoom_factor; |
| 188 | 145 | |
| r244678 | r244679 | |
| 197 | 154 | zoomy += (int)((foomY - floor(foomY)) * (float)0x10000); |
| 198 | 155 | } |
| 199 | 156 | |
| 200 | | if (state->m_spriteregs[0] & 0x00800000) //bpp switch |
| 157 | if (m_spriteregs[0] & 0x00800000) //bpp switch |
| 201 | 158 | { |
| 202 | | gfx= state->m_gfxdecode->gfx(4); |
| 159 | gfx= m_gfxdecode->gfx(4); |
| 203 | 160 | } |
| 204 | 161 | else |
| 205 | 162 | { |
| 206 | | gfx= state->m_gfxdecode->gfx(5); |
| 163 | gfx= m_gfxdecode->gfx(5); |
| 207 | 164 | tileno>>=1; |
| 208 | 165 | pal&=0xf; |
| 209 | 166 | } |
| r244678 | r244679 | |
| 262 | 219 | tileno=(source[4]&0x0007ffff); |
| 263 | 220 | pal =(source[3]&0x00ff0000)>>16; |
| 264 | 221 | |
| 265 | | if (state->m_spriteregs[0] & 0x00800000) //bpp switch |
| 222 | if (m_spriteregs[0] & 0x00800000) //bpp switch |
| 266 | 223 | { |
| 267 | | gfx= state->m_gfxdecode->gfx(4); |
| 224 | gfx= m_gfxdecode->gfx(4); |
| 268 | 225 | } |
| 269 | 226 | else |
| 270 | 227 | { |
| 271 | | gfx= state->m_gfxdecode->gfx(5); |
| 228 | gfx= m_gfxdecode->gfx(5); |
| 272 | 229 | tileno>>=1; |
| 273 | 230 | pal&=0xf; |
| 274 | 231 | } |
| r244678 | r244679 | |
| 328 | 285 | */ |
| 329 | 286 | |
| 330 | 287 | /* this is broken for the 'How to Play' screen in Buriki after attract, disabled for now */ |
| 331 | | 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) |
| 332 | 289 | { |
| 333 | | hng64_state *state = machine.driver_data<hng64_state>(); |
| 334 | | UINT32 *hng64_tcram = state->m_tcram; |
| 290 | UINT32 *hng64_tcram = m_tcram; |
| 335 | 291 | int i, j; |
| 336 | 292 | |
| 337 | 293 | // float colorScaleR, colorScaleG, colorScaleB; |
| r244678 | r244679 | |
| 548 | 504 | WRITE32_MEMBER(hng64_state::hng64_videoram_w) |
| 549 | 505 | { |
| 550 | 506 | int realoff; |
| 551 | | hng64_state *state = machine().driver_data<hng64_state>(); |
| 552 | 507 | COMBINE_DATA(&m_videoram[offset]); |
| 553 | 508 | |
| 554 | 509 | realoff = offset*4; |
| 555 | 510 | |
| 556 | 511 | if ((realoff>=0) && (realoff<0x10000)) |
| 557 | 512 | { |
| 558 | | hng64_mark_tile_dirty(state, 0, offset&0x3fff); |
| 513 | hng64_mark_tile_dirty(0, offset&0x3fff); |
| 559 | 514 | } |
| 560 | 515 | else if ((realoff>=0x10000) && (realoff<0x20000)) |
| 561 | 516 | { |
| 562 | | hng64_mark_tile_dirty(state, 1, offset&0x3fff); |
| 517 | hng64_mark_tile_dirty(1, offset&0x3fff); |
| 563 | 518 | } |
| 564 | 519 | else if ((realoff>=0x20000) && (realoff<0x30000)) |
| 565 | 520 | { |
| 566 | | hng64_mark_tile_dirty(state, 2, offset&0x3fff); |
| 521 | hng64_mark_tile_dirty(2, offset&0x3fff); |
| 567 | 522 | } |
| 568 | 523 | else if ((realoff>=0x30000) && (realoff<0x40000)) |
| 569 | 524 | { |
| 570 | | hng64_mark_tile_dirty(state, 3, offset&0x3fff); |
| 525 | hng64_mark_tile_dirty(3, offset&0x3fff); |
| 571 | 526 | } |
| 572 | 527 | |
| 573 | 528 | // if ((realoff>=0x40000)) osd_printf_debug("offsw %08x %08x\n",realoff,data); |
| r244678 | r244679 | |
| 576 | 531 | } |
| 577 | 532 | |
| 578 | 533 | /* internal set of transparency states for rendering */ |
| 579 | | enum hng64trans_t |
| 580 | | { |
| 581 | | HNG64_TILEMAP_NORMAL = 1, |
| 582 | | HNG64_TILEMAP_ADDITIVE, |
| 583 | | HNG64_TILEMAP_ALPHA |
| 584 | | }; |
| 585 | 534 | |
| 586 | 535 | |
| 587 | | struct blit_parameters |
| 588 | | { |
| 589 | | bitmap_rgb32 * bitmap; |
| 590 | | rectangle cliprect; |
| 591 | | UINT32 tilemap_priority_code; |
| 592 | | UINT8 mask; |
| 593 | | UINT8 value; |
| 594 | | UINT8 alpha; |
| 595 | | hng64trans_t drawformat; |
| 596 | | }; |
| 597 | | |
| 598 | | |
| 599 | | |
| 600 | 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) |
| 601 | 537 | { |
| 602 | 538 | /* start with nothing */ |
| r244678 | r244679 | |
| 673 | 609 | *(UINT32 *)dest = alpha_blend_r32(*(UINT32 *)dest, clut[INPUT_VAL], alpha); \ |
| 674 | 610 | } while (0) |
| 675 | 611 | |
| 676 | | 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, |
| 677 | 613 | UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, int wraparound) |
| 678 | 614 | { |
| 679 | | hng64_state *state = screen.machine().driver_data<hng64_state>(); |
| 680 | | 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); |
| 681 | 616 | bitmap_ind8 &priority_bitmap = screen.priority(); |
| 682 | 617 | bitmap_rgb32 &destbitmap = *blit->bitmap; |
| 683 | 618 | bitmap_ind16 &srcbitmap = tmap->pixmap(); |
| r244678 | r244679 | |
| 851 | 786 | |
| 852 | 787 | |
| 853 | 788 | |
| 854 | | 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, |
| 855 | 790 | UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, |
| 856 | 791 | int wraparound, UINT32 flags, UINT8 priority, UINT8 priority_mask, hng64trans_t drawformat) |
| 857 | 792 | { |
| r244678 | r244679 | |
| 879 | 814 | } |
| 880 | 815 | |
| 881 | 816 | |
| 882 | | 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, |
| 883 | 818 | UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, |
| 884 | 819 | int wraparound, UINT32 flags, UINT8 priority, hng64trans_t drawformat) |
| 885 | 820 | { |
| r244678 | r244679 | |
| 888 | 823 | |
| 889 | 824 | |
| 890 | 825 | |
| 891 | | 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 ) |
| 892 | 827 | { |
| 893 | | hng64_state *state = screen.machine().driver_data<hng64_state>(); |
| 894 | | UINT32 *hng64_videoregs = state->m_videoregs; |
| 895 | | UINT32 *hng64_videoram = state->m_videoram; |
| 828 | UINT32 *hng64_videoregs = m_videoregs; |
| 829 | UINT32 *hng64_videoram = m_videoram; |
| 896 | 830 | tilemap_t* tilemap = 0; |
| 897 | 831 | UINT32 scrollbase = 0; |
| 898 | 832 | UINT32 tileregs = 0; |
| r244678 | r244679 | |
| 903 | 837 | |
| 904 | 838 | int global_dimensions = (global_tileregs&0x03000000)>>24; |
| 905 | 839 | |
| 906 | | if ( (state->m_additive_tilemap_debug&(1 << tm))) |
| 840 | if ( (m_additive_tilemap_debug&(1 << tm))) |
| 907 | 841 | debug_blend_enabled = 1; |
| 908 | 842 | |
| 909 | 843 | if ((global_dimensions != 0) && (global_dimensions != 3)) |
| r244678 | r244679 | |
| 913 | 847 | { |
| 914 | 848 | scrollbase = (hng64_videoregs[0x04]&0x3fff0000)>>16; |
| 915 | 849 | tileregs = (hng64_videoregs[0x02]&0xffff0000)>>16; |
| 916 | | |
| 917 | | if (global_dimensions==0) |
| 918 | | { |
| 919 | | if (tileregs&0x0200) tilemap = state->m_tilemap0_16x16; |
| 920 | | else tilemap = state->m_tilemap0_8x8; |
| 921 | | } |
| 922 | | else |
| 923 | | { |
| 924 | | if (tileregs&0x0200) tilemap = state->m_tilemap0_16x16_alt; |
| 925 | | else tilemap = state->m_tilemap0_8x8; // _alt |
| 926 | | } |
| 927 | 850 | } |
| 928 | 851 | else if (tm==1) |
| 929 | 852 | { |
| 930 | 853 | scrollbase = (hng64_videoregs[0x04]&0x00003fff)>>0; |
| 931 | 854 | tileregs = (hng64_videoregs[0x02]&0x0000ffff)>>0; |
| 932 | | |
| 933 | | if (global_dimensions==0) |
| 934 | | { |
| 935 | | if (tileregs&0x0200) tilemap = state->m_tilemap1_16x16; |
| 936 | | else tilemap = state->m_tilemap1_8x8; |
| 937 | | } |
| 938 | | else |
| 939 | | { |
| 940 | | if (tileregs&0x0200) tilemap = state->m_tilemap1_16x16_alt; |
| 941 | | else tilemap = state->m_tilemap1_8x8; // _alt |
| 942 | | } |
| 943 | 855 | } |
| 944 | 856 | else if (tm==2) |
| 945 | 857 | { |
| 946 | 858 | scrollbase = (hng64_videoregs[0x05]&0x3fff0000)>>16; |
| 947 | 859 | tileregs = (hng64_videoregs[0x03]&0xffff0000)>>16; |
| 948 | | |
| 949 | | if (global_dimensions==0) |
| 950 | | { |
| 951 | | if (tileregs&0x0200) tilemap = state->m_tilemap2_16x16; |
| 952 | | else tilemap = state->m_tilemap2_8x8; |
| 953 | | } |
| 954 | | else |
| 955 | | { |
| 956 | | if (tileregs&0x0200) tilemap = state->m_tilemap2_16x16_alt; |
| 957 | | else tilemap = state->m_tilemap2_8x8; // _alt |
| 958 | | } |
| 959 | 860 | } |
| 960 | 861 | else if (tm==3) |
| 961 | 862 | { |
| 962 | 863 | scrollbase = (hng64_videoregs[0x05]&0x00003fff)>>0; |
| 963 | 864 | tileregs = (hng64_videoregs[0x03]&0x0000ffff)>>0; |
| 865 | } |
| 964 | 866 | |
| 965 | | if (global_dimensions==0) |
| 966 | | { |
| 967 | | if (tileregs&0x0200) tilemap = state->m_tilemap3_16x16; |
| 968 | | else tilemap = state->m_tilemap3_8x8; |
| 969 | | } |
| 970 | | else |
| 971 | | { |
| 972 | | if (tileregs&0x0200) tilemap = state->m_tilemap3_16x16_alt; |
| 973 | | else tilemap = state->m_tilemap3_8x8; // _alt |
| 974 | | } |
| 867 | if (global_dimensions==0) |
| 868 | { |
| 869 | if (tileregs&0x0200) tilemap = m_tilemap[tm].m_tilemap_16x16; |
| 870 | else tilemap = m_tilemap[tm].m_tilemap_8x8; |
| 975 | 871 | } |
| 872 | else |
| 873 | { |
| 874 | if (tileregs&0x0200) tilemap = m_tilemap[tm].m_tilemap_16x16_alt; |
| 875 | else tilemap = m_tilemap[tm].m_tilemap_8x8; // _alt |
| 876 | } |
| 976 | 877 | |
| 977 | 878 | // xrally's pink tilemaps make me think this is a tilemap enable bit. |
| 978 | 879 | // fatfurwa makes me think otherwise. |
| 979 | | //if (!(tileregs & 0x0040)) return; |
| 880 | // if (!(tileregs & 0x0040)) return; |
| 980 | 881 | |
| 981 | 882 | // set the transmask so our manual copy is correct |
| 982 | 883 | if (tileregs & 0x0400) |
| r244678 | r244679 | |
| 1126 | 1027 | bitmap_ind16 &bm = tilemap->pixmap(); |
| 1127 | 1028 | int bmheight = bm.height(); |
| 1128 | 1029 | int bmwidth = bm.width(); |
| 1129 | | const pen_t *paldata = state->m_palette->pens(); |
| 1030 | const pen_t *paldata = m_palette->pens(); |
| 1130 | 1031 | UINT32* dstptr; |
| 1131 | 1032 | UINT16* srcptr; |
| 1132 | 1033 | int xx,yy; |
| r244678 | r244679 | |
| 1222 | 1123 | bitmap_ind16 &bm = tilemap->pixmap(); |
| 1223 | 1124 | int bmheight = bm.height(); |
| 1224 | 1125 | int bmwidth = bm.width(); |
| 1225 | | const pen_t *paldata = state->m_palette->pens(); |
| 1126 | const pen_t *paldata = m_palette->pens(); |
| 1226 | 1127 | UINT32* dstptr; |
| 1227 | 1128 | UINT16* srcptr; |
| 1228 | 1129 | int xx,yy; |
| r244678 | r244679 | |
| 1311 | 1212 | // 0940 - samurai shodown 64 |
| 1312 | 1213 | // 0880 - buriki |
| 1313 | 1214 | |
| 1314 | | // mmmm dbr? ??e? ???? |
| 1215 | // mmmm dbrz zzzz zzzz |
| 1315 | 1216 | // m = mosaic related? |
| 1316 | 1217 | // -- they seem to enable mosaic at the same time as rowscroll in several cases (floor in buriki / ff) |
| 1317 | 1218 | // and also on the rotating logo in buriki.. does it cause some kind of aliasing side-effect, or.. ? |
| 1318 | 1219 | // r = tile size (seems correct) |
| 1319 | 1220 | // b = 4bpp/8bpp (seems correct) (beast busters, samsh64, sasm64 2, xrally switch it for some screens) |
| 1320 | 1221 | // d = line (floor) mode - buriki, fatafurwa, some backgrounds in ss64_2 |
| 1321 | | // e = enable according to sams64_2 debug mode, buriki and xrally.. but NOT fatal fury :-( |
| 1222 | // z = z depth? tilemaps might also be affected by min / max clip values somewhere? (debug layer on buriki has priority 0x020, which would be highest) |
| 1322 | 1223 | |
| 1323 | 1224 | |
| 1324 | 1225 | */ |
| r244678 | r244679 | |
| 1334 | 1235 | UINT32 *hng64_tcram = m_tcram; |
| 1335 | 1236 | UINT32 animmask; |
| 1336 | 1237 | UINT32 animbits; |
| 1337 | | UINT16 tileflags0, tileflags1; |
| 1338 | | UINT16 tileflags2, tileflags3; |
| 1238 | UINT16 tileflags[4]; |
| 1339 | 1239 | |
| 1340 | 1240 | #if 0 |
| 1341 | 1241 | // press in sams64_2 attract mode for a nice debug screen from the game |
| r244678 | r244679 | |
| 1356 | 1256 | |
| 1357 | 1257 | animmask = hng64_videoregs[0x0b]; |
| 1358 | 1258 | animbits = hng64_videoregs[0x0c]; |
| 1359 | | tileflags0 = hng64_videoregs[0x02]>>16; |
| 1360 | | tileflags1 = hng64_videoregs[0x02]&0xffff; |
| 1361 | | tileflags2 = hng64_videoregs[0x03]>>16; |
| 1362 | | tileflags3 = hng64_videoregs[0x03]&0xffff; |
| 1259 | tileflags[0] = hng64_videoregs[0x02]>>16; |
| 1260 | tileflags[1] = hng64_videoregs[0x02]&0xffff; |
| 1261 | tileflags[2] = hng64_videoregs[0x03]>>16; |
| 1262 | tileflags[3] = hng64_videoregs[0x03]&0xffff; |
| 1363 | 1263 | |
| 1364 | 1264 | /* if the auto-animation mask or bits have changed search for tiles using them and mark as dirty */ |
| 1365 | 1265 | if ((m_old_animmask != animmask) || (m_old_animbits != animbits)) |
| r244678 | r244679 | |
| 1369 | 1269 | { |
| 1370 | 1270 | if (hng64_videoram[tile_index+(0x00000/4)]&0x200000) |
| 1371 | 1271 | { |
| 1372 | | hng64_mark_tile_dirty(this, 0, tile_index); |
| 1272 | hng64_mark_tile_dirty(0, tile_index); |
| 1373 | 1273 | } |
| 1374 | 1274 | if (hng64_videoram[tile_index+(0x10000/4)]&0x200000) |
| 1375 | 1275 | { |
| 1376 | | hng64_mark_tile_dirty(this, 1, tile_index); |
| 1276 | hng64_mark_tile_dirty(1, tile_index); |
| 1377 | 1277 | } |
| 1378 | 1278 | if (hng64_videoram[tile_index+(0x20000/4)]&0x200000) |
| 1379 | 1279 | { |
| 1380 | | hng64_mark_tile_dirty(this, 2, tile_index); |
| 1280 | hng64_mark_tile_dirty(2, tile_index); |
| 1381 | 1281 | } |
| 1382 | 1282 | if (hng64_videoram[tile_index+(0x30000/4)]&0x200000) |
| 1383 | 1283 | { |
| 1384 | | hng64_mark_tile_dirty(this, 3, tile_index); |
| 1284 | hng64_mark_tile_dirty(3, tile_index); |
| 1385 | 1285 | } |
| 1386 | 1286 | } |
| 1387 | 1287 | |
| r244678 | r244679 | |
| 1389 | 1289 | m_old_animbits = animbits; |
| 1390 | 1290 | } |
| 1391 | 1291 | |
| 1392 | | if ((m_old_tileflags0&IMPORTANT_DIRTY_TILEFLAG_MASK)!=(tileflags0&IMPORTANT_DIRTY_TILEFLAG_MASK)) |
| 1292 | for (int i = 0; i < 4; i++) |
| 1393 | 1293 | { |
| 1394 | | hng64_mark_all_tiles_dirty(this, 0); |
| 1395 | | m_old_tileflags0 = tileflags0; |
| 1294 | if ((m_old_tileflags[i]&IMPORTANT_DIRTY_TILEFLAG_MASK)!=(tileflags[i]&IMPORTANT_DIRTY_TILEFLAG_MASK)) |
| 1295 | { |
| 1296 | hng64_mark_all_tiles_dirty(i); |
| 1297 | m_old_tileflags[i] = tileflags[i]; |
| 1298 | } |
| 1396 | 1299 | } |
| 1397 | 1300 | |
| 1398 | | if ((m_old_tileflags1&IMPORTANT_DIRTY_TILEFLAG_MASK)!=(tileflags1&IMPORTANT_DIRTY_TILEFLAG_MASK)) |
| 1399 | | { |
| 1400 | | hng64_mark_all_tiles_dirty(this, 1); |
| 1401 | | m_old_tileflags1 = tileflags1; |
| 1402 | | } |
| 1403 | 1301 | |
| 1404 | | if ((m_old_tileflags2&IMPORTANT_DIRTY_TILEFLAG_MASK)!=(tileflags2&IMPORTANT_DIRTY_TILEFLAG_MASK)) |
| 1405 | | { |
| 1406 | | hng64_mark_all_tiles_dirty(this, 2); |
| 1407 | | m_old_tileflags2 = tileflags2; |
| 1408 | | } |
| 1409 | | |
| 1410 | | if ((m_old_tileflags3&IMPORTANT_DIRTY_TILEFLAG_MASK)!=(tileflags3&IMPORTANT_DIRTY_TILEFLAG_MASK)) |
| 1411 | | { |
| 1412 | | hng64_mark_all_tiles_dirty(this, 3); |
| 1413 | | m_old_tileflags3 = tileflags3; |
| 1414 | | } |
| 1415 | | |
| 1416 | | // mark all frames as dirty if for some reason we don't trust the above code |
| 1417 | | //hng64_mark_all_tiles_dirty(this, 0); |
| 1418 | | //hng64_mark_all_tiles_dirty(this, 1); |
| 1419 | | //hng64_mark_all_tiles_dirty(this, 2); |
| 1420 | | //hng64_mark_all_tiles_dirty(this, 3); |
| 1421 | | |
| 1422 | 1302 | hng64_drawtilemap(screen,bitmap,cliprect, 3); |
| 1423 | 1303 | hng64_drawtilemap(screen,bitmap,cliprect, 2); |
| 1424 | 1304 | hng64_drawtilemap(screen,bitmap,cliprect, 1); |
| r244678 | r244679 | |
| 1450 | 1330 | draw_sprites(screen, bitmap,cliprect); |
| 1451 | 1331 | |
| 1452 | 1332 | if(0) |
| 1453 | | transition_control(machine(), bitmap, cliprect); |
| 1333 | transition_control(bitmap, cliprect); |
| 1454 | 1334 | |
| 1455 | 1335 | if (0) |
| 1456 | 1336 | popmessage("%08x %08x %08x %08x %08x", m_spriteregs[0], m_spriteregs[1], m_spriteregs[2], m_spriteregs[3], m_spriteregs[4]); |
| 1457 | 1337 | |
| 1458 | | if (0) |
| 1459 | | popmessage("%08x %08x TR(%04x %04x %04x %04x) SB(%04x %04x %04x %04x) %08x %08x %08x %08x %08x AA(%08x %08x) %08x %08x", |
| 1338 | if (1) |
| 1339 | popmessage("%08x %08x TR(%04x %04x %04x %04x) SB(%04x %04x %04x %04x) %08x %08x %08x %08x %08x AA(%08x %08x) %08x", |
| 1460 | 1340 | hng64_videoregs[0x00], |
| 1461 | 1341 | hng64_videoregs[0x01], |
| 1462 | | (hng64_videoregs[0x02]>>16)&0xf9ff, // ---- bits we're sure about are masked out |
| 1463 | | (hng64_videoregs[0x02]>>0)&0xf9ff, // ss64_2 debug mode indicates that 0x0040 is enable! |
| 1464 | | (hng64_videoregs[0x03]>>16)&0xf9ff, // buriki agrees (debug data on text layer) xrally agress (pink layer) |
| 1465 | | (hng64_videoregs[0x03]>>0)&0xf9ff, // fatal fury doesn't (all backgrounds have it set) joy |
| 1342 | (hng64_videoregs[0x02]>>16)&0x01ff, // ---- bits we're sure about are masked out |
| 1343 | (hng64_videoregs[0x02]>>0)&0x01ff, // ss64_2 debug mode indicates that 0x0040 is enable! |
| 1344 | (hng64_videoregs[0x03]>>16)&0x01ff, // buriki agrees (debug data on text layer) xrally agress (pink layer) |
| 1345 | (hng64_videoregs[0x03]>>0)&0x01ff, // fatal fury doesn't (all backgrounds have it set) joy |
| 1466 | 1346 | (hng64_videoregs[0x04]>>16)&0xffff, |
| 1467 | 1347 | (hng64_videoregs[0x04]>>0)&0xffff, |
| 1468 | 1348 | (hng64_videoregs[0x05]>>16)&0xffff, |
| r244678 | r244679 | |
| 1474 | 1354 | hng64_videoregs[0x0a], |
| 1475 | 1355 | hng64_videoregs[0x0b], |
| 1476 | 1356 | hng64_videoregs[0x0c], |
| 1477 | | hng64_videoregs[0x0d], |
| 1478 | | hng64_videoregs[0x0e]); |
| 1357 | hng64_videoregs[0x0d]); |
| 1479 | 1358 | |
| 1480 | 1359 | if (0) |
| 1481 | 1360 | popmessage("3D: %08x %08x %08x %08x : %08x %08x %08x %08x : %08x %08x %08x %08x", |
| r244678 | r244679 | |
| 1547 | 1426 | |
| 1548 | 1427 | m_old_animmask = -1; |
| 1549 | 1428 | m_old_animbits = -1; |
| 1550 | | m_old_tileflags0 = -1; |
| 1551 | | m_old_tileflags1 = -1; |
| 1552 | | m_old_tileflags2 = -1; |
| 1553 | | m_old_tileflags3 = -1; |
| 1429 | m_old_tileflags[0] = -1; |
| 1430 | m_old_tileflags[1] = -1; |
| 1431 | m_old_tileflags[2] = -1; |
| 1432 | m_old_tileflags[3] = -1; |
| 1554 | 1433 | |
| 1555 | | m_tilemap0_8x8 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile0_8x8_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1556 | | m_tilemap0_16x16 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile0_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1557 | | m_tilemap0_16x16_alt = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile0_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 256, 64); /* 128x128x4 = 0x10000 */ |
| 1434 | m_tilemap[0].m_tilemap_8x8 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile0_8x8_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1435 | m_tilemap[0].m_tilemap_16x16 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile0_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1436 | m_tilemap[0].m_tilemap_16x16_alt = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile0_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 256, 64); /* 128x128x4 = 0x10000 */ |
| 1558 | 1437 | |
| 1559 | | m_tilemap1_8x8 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile1_8x8_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1560 | | m_tilemap1_16x16 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile1_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1561 | | m_tilemap1_16x16_alt = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile1_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 256, 64); /* 128x128x4 = 0x10000 */ |
| 1438 | m_tilemap[1].m_tilemap_8x8 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile1_8x8_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1439 | m_tilemap[1].m_tilemap_16x16 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile1_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1440 | m_tilemap[1].m_tilemap_16x16_alt = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile1_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 256, 64); /* 128x128x4 = 0x10000 */ |
| 1562 | 1441 | |
| 1563 | | m_tilemap2_8x8 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile2_8x8_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1564 | | m_tilemap2_16x16 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile2_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1565 | | m_tilemap2_16x16_alt = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile2_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 256, 64); /* 128x128x4 = 0x10000 */ |
| 1442 | m_tilemap[2].m_tilemap_8x8 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile2_8x8_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1443 | m_tilemap[2].m_tilemap_16x16 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile2_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1444 | m_tilemap[2].m_tilemap_16x16_alt = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile2_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 256, 64); /* 128x128x4 = 0x10000 */ |
| 1566 | 1445 | |
| 1567 | | m_tilemap3_8x8 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile3_8x8_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1568 | | m_tilemap3_16x16 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile3_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1569 | | m_tilemap3_16x16_alt = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile3_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 256, 64); /* 128x128x4 = 0x10000 */ |
| 1446 | m_tilemap[3].m_tilemap_8x8 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile3_8x8_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1447 | m_tilemap[3].m_tilemap_16x16 = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile3_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 128, 128); /* 128x128x4 = 0x10000 */ |
| 1448 | m_tilemap[3].m_tilemap_16x16_alt = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(hng64_state::get_hng64_tile3_16x16_info),this), TILEMAP_SCAN_ROWS, 16, 16, 256, 64); /* 128x128x4 = 0x10000 */ |
| 1570 | 1449 | |
| 1571 | | m_tilemap0_8x8->set_transparent_pen(0); |
| 1572 | | m_tilemap0_16x16->set_transparent_pen(0); |
| 1573 | | m_tilemap0_16x16_alt->set_transparent_pen(0); |
| 1450 | for (int i = 0; i < 4; i++) |
| 1451 | { |
| 1452 | m_tilemap[i].m_tilemap_8x8->set_transparent_pen(0); |
| 1453 | m_tilemap[i].m_tilemap_16x16->set_transparent_pen(0); |
| 1454 | m_tilemap[i].m_tilemap_16x16_alt->set_transparent_pen(0); |
| 1455 | } |
| 1574 | 1456 | |
| 1575 | | m_tilemap1_8x8->set_transparent_pen(0); |
| 1576 | | m_tilemap1_16x16->set_transparent_pen(0); |
| 1577 | | m_tilemap1_16x16_alt->set_transparent_pen(0); |
| 1578 | | |
| 1579 | | m_tilemap2_8x8->set_transparent_pen(0); |
| 1580 | | m_tilemap2_16x16->set_transparent_pen(0); |
| 1581 | | m_tilemap2_16x16_alt->set_transparent_pen(0); |
| 1582 | | |
| 1583 | | m_tilemap3_8x8->set_transparent_pen(0); |
| 1584 | | m_tilemap3_16x16->set_transparent_pen(0); |
| 1585 | | m_tilemap3_16x16_alt->set_transparent_pen(0); |
| 1586 | | |
| 1587 | 1457 | // Debug switch, turn on / off additive blending on a per-tilemap basis |
| 1588 | 1458 | m_additive_tilemap_debug = 0; |
| 1589 | 1459 | |
| r244678 | r244679 | |
| 1634 | 1504 | static void vecmatmul4(float *product, const float *a, const float *b); |
| 1635 | 1505 | static float vecDotProduct(const float *a, const float *b); |
| 1636 | 1506 | static void normalize(float* x); |
| 1637 | | |
| 1638 | 1507 | static void performFrustumClip(struct polygon *p); |
| 1639 | | static void drawShaded(running_machine &machine, struct polygon *p); |
| 1640 | | //static void plot(running_machine &machine, INT32 x, INT32 y, UINT32 color); |
| 1641 | | //static void drawline2d(running_machine &machine, INT32 x0, INT32 y0, INT32 x1, INT32 y1, UINT32 color); |
| 1642 | | //static void DrawWireframe(running_machine &machine, struct polygon *p); |
| 1643 | | |
| 1644 | 1508 | static float uToF(UINT16 input); |
| 1645 | 1509 | |
| 1646 | 1510 | |
| r244678 | r244679 | |
| 1678 | 1542 | |
| 1679 | 1543 | // Operation 0001 |
| 1680 | 1544 | // Camera transformation. |
| 1681 | | static void setCameraTransformation(hng64_state *state, const UINT16* packet) |
| 1545 | void hng64_state::setCameraTransformation(const UINT16* packet) |
| 1682 | 1546 | { |
| 1683 | | float *cameraMatrix = state->m_cameraMatrix; |
| 1547 | float *cameraMatrix = m_cameraMatrix; |
| 1684 | 1548 | |
| 1685 | 1549 | /*////////////// |
| 1686 | 1550 | // PACKET FORMAT |
| r244678 | r244679 | |
| 1725 | 1589 | |
| 1726 | 1590 | // Operation 0010 |
| 1727 | 1591 | // Lighting information |
| 1728 | | static void setLighting(hng64_state *state, const UINT16* packet) |
| 1592 | void hng64_state::setLighting(const UINT16* packet) |
| 1729 | 1593 | { |
| 1730 | | float *lightVector = state->m_lightVector; |
| 1594 | float *lightVector = m_lightVector; |
| 1731 | 1595 | |
| 1732 | 1596 | /*////////////// |
| 1733 | 1597 | // PACKET FORMAT |
| r244678 | r244679 | |
| 1754 | 1618 | lightVector[0] = uToF(packet[3]); |
| 1755 | 1619 | lightVector[1] = uToF(packet[4]); |
| 1756 | 1620 | lightVector[2] = uToF(packet[5]); |
| 1757 | | state->m_lightStrength = uToF(packet[9]); |
| 1621 | m_lightStrength = uToF(packet[9]); |
| 1758 | 1622 | } |
| 1759 | 1623 | |
| 1760 | 1624 | // Operation 0011 |
| 1761 | 1625 | // Palette / Model flags? |
| 1762 | | static void set3dFlags(hng64_state *state, const UINT16* packet) |
| 1626 | void hng64_state::set3dFlags(const UINT16* packet) |
| 1763 | 1627 | { |
| 1764 | 1628 | /*////////////// |
| 1765 | 1629 | // PACKET FORMAT |
| r244678 | r244679 | |
| 1780 | 1644 | // [14] - ???? ... ? '' '' |
| 1781 | 1645 | // [15] - ???? ... ? '' '' |
| 1782 | 1646 | ////////////*/ |
| 1783 | | state->m_paletteState3d = (packet[8] & 0xff00) >> 8; |
| 1647 | m_paletteState3d = (packet[8] & 0xff00) >> 8; |
| 1784 | 1648 | } |
| 1785 | 1649 | |
| 1786 | 1650 | // Operation 0012 |
| 1787 | 1651 | // Projection Matrix. |
| 1788 | | static void setCameraProjectionMatrix(hng64_state *state, const UINT16* packet) |
| 1652 | void hng64_state::setCameraProjectionMatrix(const UINT16* packet) |
| 1789 | 1653 | { |
| 1790 | | float *projectionMatrix = state->m_projectionMatrix; |
| 1654 | float *projectionMatrix = m_projectionMatrix; |
| 1791 | 1655 | |
| 1792 | 1656 | /*////////////// |
| 1793 | 1657 | // PACKET FORMAT |
| r244678 | r244679 | |
| 1843 | 1707 | |
| 1844 | 1708 | // Operation 0100 |
| 1845 | 1709 | // Polygon rasterization. |
| 1846 | | 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) |
| 1847 | 1711 | { |
| 1848 | 1712 | /*////////////// |
| 1849 | 1713 | // PACKET FORMAT |
| r244678 | r244679 | |
| 1880 | 1744 | // [15] - xxxx ... Transformation matrix |
| 1881 | 1745 | ////////////*/ |
| 1882 | 1746 | |
| 1883 | | hng64_state *state = machine.driver_data<hng64_state>(); |
| 1884 | 1747 | UINT32 size[4]; |
| 1885 | 1748 | UINT32 address[4]; |
| 1886 | 1749 | UINT32 megaOffset; |
| r244678 | r244679 | |
| 1894 | 1757 | setIdentity(objectMatrix); |
| 1895 | 1758 | |
| 1896 | 1759 | struct polygon lastPoly = { 0 }; |
| 1897 | | const rectangle &visarea = machine.first_screen()->visible_area(); |
| 1760 | const rectangle &visarea = m_screen->visible_area(); |
| 1898 | 1761 | |
| 1899 | 1762 | ///////////////// |
| 1900 | 1763 | // HEADER INFO // |
| r244678 | r244679 | |
| 1950 | 1813 | //////////////////////////////////////////////*/ |
| 1951 | 1814 | |
| 1952 | 1815 | // 3d ROM Offset |
| 1953 | | UINT16* threeDRoms = (UINT16*)(machine.root_device().memregion("verts")->base()); |
| 1816 | UINT16* threeDRoms = (UINT16*)memregion("verts")->base(); |
| 1954 | 1817 | UINT32 threeDOffset = (((UINT32)packet[2]) << 16) | ((UINT32)packet[3]); |
| 1955 | 1818 | UINT16* threeDPointer = &threeDRoms[threeDOffset * 3]; |
| 1956 | 1819 | |
| 1957 | | if (threeDOffset >= machine.root_device().memregion("verts")->bytes()) |
| 1820 | if (threeDOffset >= memregion("verts")->bytes()) |
| 1958 | 1821 | { |
| 1959 | 1822 | printf("Strange geometry packet: (ignoring)\n"); |
| 1960 | 1823 | printPacket(packet, 1); |
| r244678 | r244679 | |
| 2079 | 1942 | /* FIXME: This isn't correct. |
| 2080 | 1943 | Buriki & Xrally need this line. Roads Edge needs it removed. |
| 2081 | 1944 | So instead we're looking for a bit that is on for XRally & Buriki, but noone else. */ |
| 2082 | | if (state->m_3dregs[0x00/4] & 0x2000) |
| 1945 | if (m_3dregs[0x00/4] & 0x2000) |
| 2083 | 1946 | { |
| 2084 | | if (strcmp(machine.basename(), "roadedge")) |
| 1947 | if (strcmp(machine().basename(), "roadedge")) |
| 2085 | 1948 | polys[*numPolys].palOffset += 0x800; |
| 2086 | 1949 | } |
| 2087 | 1950 | |
| r244678 | r244679 | |
| 2095 | 1958 | // Apply the dynamic palette offset if its flag is set, otherwise stick with the fixed one |
| 2096 | 1959 | if ((packet[1] & 0x0100)) |
| 2097 | 1960 | { |
| 2098 | | explicitPaletteValue1 = state->m_paletteState3d * 0x80; |
| 1961 | explicitPaletteValue1 = m_paletteState3d * 0x80; |
| 2099 | 1962 | explicitPaletteValue2 = 0; // This is probably hiding somewhere in operation 0011 |
| 2100 | 1963 | } |
| 2101 | 1964 | |
| r244678 | r244679 | |
| 2289 | 2152 | //////////////////////////////////// |
| 2290 | 2153 | // Perform the world transformations... |
| 2291 | 2154 | // !! Can eliminate this step with a matrix stack (maybe necessary?) !! |
| 2292 | | setIdentity(state->m_modelViewMatrix); |
| 2293 | | if (state->m_mcu_type != SAMSHO_MCU) |
| 2155 | setIdentity(m_modelViewMatrix); |
| 2156 | if (m_mcu_type != SAMSHO_MCU) |
| 2294 | 2157 | { |
| 2295 | 2158 | // The sams64 games transform the geometry in front of a stationary camera. |
| 2296 | 2159 | // This is fine in sams64_2, since it never calls the 'camera transformation' function |
| 2297 | 2160 | // (thus using the identity matrix for this transform), but sams64 calls the |
| 2298 | 2161 | // camera transformation function with rotation values. |
| 2299 | 2162 | // It remains to be seen what those might do... |
| 2300 | | matmul4(state->m_modelViewMatrix, state->m_modelViewMatrix, state->m_cameraMatrix); |
| 2163 | matmul4(m_modelViewMatrix, m_modelViewMatrix, m_cameraMatrix); |
| 2301 | 2164 | } |
| 2302 | | matmul4(state->m_modelViewMatrix, state->m_modelViewMatrix, objectMatrix); |
| 2165 | matmul4(m_modelViewMatrix, m_modelViewMatrix, objectMatrix); |
| 2303 | 2166 | |
| 2304 | 2167 | // LIGHTING |
| 2305 | | if (packet[1] & 0x0008 && state->m_lightStrength > 0.0f) |
| 2168 | if (packet[1] & 0x0008 && m_lightStrength > 0.0f) |
| 2306 | 2169 | { |
| 2307 | 2170 | for (int v = 0; v < 3; v++) |
| 2308 | 2171 | { |
| 2309 | 2172 | float transformedNormal[4]; |
| 2310 | 2173 | vecmatmul4(transformedNormal, objectMatrix, polys[*numPolys].vert[v].normal); |
| 2311 | 2174 | normalize(transformedNormal); |
| 2312 | | normalize(state->m_lightVector); |
| 2175 | normalize(m_lightVector); |
| 2313 | 2176 | |
| 2314 | | float intensity = vecDotProduct(transformedNormal, state->m_lightVector) * -1.0f; |
| 2177 | float intensity = vecDotProduct(transformedNormal, m_lightVector) * -1.0f; |
| 2315 | 2178 | intensity = (intensity <= 0.0f) ? (0.0f) : (intensity); |
| 2316 | | intensity *= state->m_lightStrength * 128.0f; // Turns 0x0100 into 1.0 |
| 2179 | intensity *= m_lightStrength * 128.0f; // Turns 0x0100 into 1.0 |
| 2317 | 2180 | intensity *= 128.0; // Maps intensity to the range [0.0, 2.0] |
| 2318 | 2181 | if (intensity >= 255.0f) intensity = 255.0f; |
| 2319 | 2182 | |
| r244678 | r244679 | |
| 2356 | 2219 | |
| 2357 | 2220 | |
| 2358 | 2221 | // BEHIND-THE-CAMERA CULL // |
| 2359 | | vecmatmul4(cullRay, state->m_modelViewMatrix, polys[*numPolys].vert[0].worldCoords); |
| 2222 | vecmatmul4(cullRay, m_modelViewMatrix, polys[*numPolys].vert[0].worldCoords); |
| 2360 | 2223 | if (cullRay[2] > 0.0f) // Camera is pointing down -Z |
| 2361 | 2224 | { |
| 2362 | 2225 | polys[*numPolys].visible = 0; |
| r244678 | r244679 | |
| 2369 | 2232 | for (int m = 0; m < polys[*numPolys].n; m++) |
| 2370 | 2233 | { |
| 2371 | 2234 | // Transform and project the vertex into pre-divided homogeneous coordinates... |
| 2372 | | vecmatmul4(eyeCoords, state->m_modelViewMatrix, polys[*numPolys].vert[m].worldCoords); |
| 2373 | | 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); |
| 2374 | 2237 | } |
| 2375 | 2238 | |
| 2376 | 2239 | if (polys[*numPolys].visible) |
| r244678 | r244679 | |
| 2410 | 2273 | } |
| 2411 | 2274 | } |
| 2412 | 2275 | |
| 2413 | | void hng64_command3d(running_machine& machine, const UINT16* packet) |
| 2276 | void hng64_state::hng64_command3d(const UINT16* packet) |
| 2414 | 2277 | { |
| 2415 | | hng64_state *state = machine.driver_data<hng64_state>(); |
| 2416 | 2278 | |
| 2417 | 2279 | /* A temporary place to put some polygons. This will optimize away if the compiler's any good. */ |
| 2418 | 2280 | int numPolys = 0; |
| 2419 | 2281 | dynamic_array<polygon> polys(1024*5); |
| 2420 | 2282 | |
| 2421 | | //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 | |
| 2422 | 2285 | switch (packet[0]) |
| 2423 | 2286 | { |
| 2424 | 2287 | case 0x0000: // Appears to be a NOP. |
| 2425 | 2288 | break; |
| 2426 | 2289 | |
| 2427 | 2290 | case 0x0001: // Camera transformation. |
| 2428 | | setCameraTransformation(state, packet); |
| 2291 | setCameraTransformation(packet); |
| 2429 | 2292 | break; |
| 2430 | 2293 | |
| 2431 | 2294 | case 0x0010: // Lighting information. |
| 2432 | 2295 | //if (packet[9]) printPacket(packet, 1); |
| 2433 | | setLighting(state, packet); |
| 2296 | setLighting(packet); |
| 2434 | 2297 | break; |
| 2435 | 2298 | |
| 2436 | 2299 | case 0x0011: // Palette / Model flags? |
| 2437 | 2300 | //printPacket(packet, 1); printf("\n"); |
| 2438 | | set3dFlags(state, packet); |
| 2301 | set3dFlags(packet); |
| 2439 | 2302 | break; |
| 2440 | 2303 | |
| 2441 | 2304 | case 0x0012: // Projection Matrix |
| 2442 | 2305 | //printPacket(packet, 1); |
| 2443 | | setCameraProjectionMatrix(state, packet); |
| 2306 | setCameraProjectionMatrix(packet); |
| 2444 | 2307 | break; |
| 2445 | 2308 | |
| 2446 | 2309 | case 0x0100: |
| 2447 | 2310 | case 0x0101: // Geometry with full transformations |
| 2448 | 2311 | // HACK. Masks out a piece of geo bbust2's drawShaded() crashes on. |
| 2449 | | 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) |
| 2450 | 2313 | break; |
| 2451 | 2314 | |
| 2452 | | recoverPolygonBlock(machine, packet, polys, &numPolys); |
| 2315 | recoverPolygonBlock( packet, polys, &numPolys); |
| 2453 | 2316 | break; |
| 2454 | 2317 | |
| 2455 | 2318 | case 0x0102: // Geometry with only translation |
| r244678 | r244679 | |
| 2469 | 2332 | miniPacket[7] = 0x7fff; |
| 2470 | 2333 | miniPacket[11] = 0x7fff; |
| 2471 | 2334 | miniPacket[15] = 0x7fff; |
| 2472 | | recoverPolygonBlock(machine, miniPacket, polys, &numPolys); |
| 2335 | recoverPolygonBlock( miniPacket, polys, &numPolys); |
| 2473 | 2336 | |
| 2474 | 2337 | memset(miniPacket, 0, sizeof(UINT16)*16); |
| 2475 | 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]; |
| 2476 | 2340 | miniPacket[7] = 0x7fff; |
| 2477 | 2341 | miniPacket[11] = 0x7fff; |
| 2478 | 2342 | miniPacket[15] = 0x7fff; |
| 2479 | | recoverPolygonBlock(machine, miniPacket, polys, &numPolys); |
| 2343 | recoverPolygonBlock( miniPacket, polys, &numPolys); |
| 2480 | 2344 | break; |
| 2481 | 2345 | |
| 2482 | 2346 | case 0x1000: // Unknown: Some sort of global flags? |
| r244678 | r244679 | |
| 2497 | 2361 | { |
| 2498 | 2362 | if (polys[i].visible) |
| 2499 | 2363 | { |
| 2500 | | //DrawWireframe(machine, &polys[i]); |
| 2501 | | drawShaded(machine, &polys[i]); |
| 2364 | //DrawWireframe( &polys[i]); |
| 2365 | drawShaded( &polys[i]); |
| 2502 | 2366 | } |
| 2503 | 2367 | } |
| 2504 | 2368 | } |
| r244678 | r244679 | |
| 2784 | 2648 | // wireframe rendering // |
| 2785 | 2649 | ///////////////////////// |
| 2786 | 2650 | #ifdef UNUSED_FUNCTION |
| 2787 | | static void plot(running_machine &machine, INT32 x, INT32 y, UINT32 color) |
| 2651 | static void plot( INT32 x, INT32 y, UINT32 color) |
| 2788 | 2652 | { |
| 2789 | 2653 | UINT32* cb = &(colorBuffer3d[(y * machine.first_screen()->visible_area().max_x) + x]); |
| 2790 | 2654 | *cb = color; |
| 2791 | 2655 | } |
| 2792 | 2656 | |
| 2793 | 2657 | // Stolen from http://en.wikipedia.org/wiki/Bresenham's_line_algorithm (no copyright denoted) - the non-optimized version |
| 2794 | | 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) |
| 2795 | 2659 | { |
| 2796 | 2660 | #define SWAP(a,b) tmpswap = a; a = b; b = tmpswap; |
| 2797 | 2661 | |
| r244678 | r244679 | |
| 2829 | 2693 | { |
| 2830 | 2694 | if (steep) |
| 2831 | 2695 | { |
| 2832 | | plot(machine, x0, y0, color); |
| 2696 | plot( x0, y0, color); |
| 2833 | 2697 | } |
| 2834 | 2698 | else |
| 2835 | 2699 | { |
| 2836 | | plot(machine, y0, x0, color); |
| 2700 | plot( y0, x0, color); |
| 2837 | 2701 | } |
| 2838 | 2702 | while (e >= 0) |
| 2839 | 2703 | { |
| r244678 | r244679 | |
| 2847 | 2711 | #undef SWAP |
| 2848 | 2712 | } |
| 2849 | 2713 | |
| 2850 | | static void DrawWireframe(running_machine &machine, struct polygon *p) |
| 2714 | static void DrawWireframe( struct polygon *p) |
| 2851 | 2715 | { |
| 2852 | 2716 | int j; |
| 2853 | 2717 | for (j = 0; j < p->n; j++) |
| r244678 | r244679 | |
| 2855 | 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]); |
| 2856 | 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]); |
| 2857 | 2721 | UINT32 color = rgb_t((UINT8)255, (UINT8)255, (UINT8)0, (UINT8)0); |
| 2858 | | 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); |
| 2859 | 2723 | } |
| 2860 | 2724 | |
| 2861 | 2725 | // SHOWS THE CLIPPING // |
| r244678 | r244679 | |
| 2870 | 2734 | } |
| 2871 | 2735 | #endif |
| 2872 | 2736 | |
| 2873 | | /////////////////////// |
| 2874 | | // polygon rendering // |
| 2875 | | /////////////////////// |
| 2876 | 2737 | |
| 2877 | | struct polygonRasterOptions |
| 2878 | | { |
| 2879 | | UINT8 texType; |
| 2880 | | UINT8 texIndex; |
| 2881 | | UINT8 texPageSmall; |
| 2882 | | UINT8 texPageHorizOffset; |
| 2883 | | UINT8 texPageVertOffset; |
| 2884 | | int palOffset; |
| 2885 | | int palPageSize; |
| 2886 | | int debugColor; |
| 2887 | | }; |
| 2888 | | |
| 2889 | 2738 | /*********************************************************************/ |
| 2890 | 2739 | /** FillSmoothTexPCHorizontalLine **/ |
| 2891 | 2740 | /** Input: Color Buffer (framebuffer), depth buffer, width and **/ |
| r244678 | r244679 | |
| 2895 | 2744 | /** **/ |
| 2896 | 2745 | /** Output: none **/ |
| 2897 | 2746 | /*********************************************************************/ |
| 2898 | | INLINE void FillSmoothTexPCHorizontalLine(running_machine &machine, |
| 2747 | inline void hng64_state::FillSmoothTexPCHorizontalLine( |
| 2899 | 2748 | const polygonRasterOptions& prOptions, |
| 2900 | 2749 | int x_start, int x_end, int y, float z_start, float z_delta, |
| 2901 | 2750 | float w_start, float w_delta, float r_start, float r_delta, |
| 2902 | 2751 | float g_start, float g_delta, float b_start, float b_delta, |
| 2903 | 2752 | float s_start, float s_delta, float t_start, float t_delta) |
| 2904 | 2753 | { |
| 2905 | | hng64_state *state = machine.driver_data<hng64_state>(); |
| 2906 | | float* db = &(state->m_depthBuffer3d[(y * machine.first_screen()->visible_area().max_x) + x_start]); |
| 2907 | | 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]); |
| 2908 | 2756 | |
| 2909 | 2757 | UINT8 paletteEntry = 0; |
| 2910 | 2758 | float t_coord, s_coord; |
| 2911 | | const UINT8 *gfx = state->memregion("textures")->base(); |
| 2759 | const UINT8 *gfx = memregion("textures")->base(); |
| 2912 | 2760 | const UINT8 *textureOffset = &gfx[prOptions.texIndex * 1024 * 1024]; |
| 2913 | 2761 | |
| 2914 | 2762 | for (; x_start <= x_end; x_start++) |
| r244678 | r244679 | |
| 2970 | 2818 | { |
| 2971 | 2819 | // The color out of the texture |
| 2972 | 2820 | paletteEntry %= prOptions.palPageSize; |
| 2973 | | rgb_t color = state->m_palette->pen(prOptions.palOffset + paletteEntry); |
| 2821 | rgb_t color = m_palette->pen(prOptions.palOffset + paletteEntry); |
| 2974 | 2822 | |
| 2975 | 2823 | // Apply the lighting |
| 2976 | 2824 | float rIntensity = (r_start/w_start) / 255.0f; |
| r244678 | r244679 | |
| 3038 | 2886 | // nearest and bilinear filtering: Filtering={0,1} |
| 3039 | 2887 | // replace and modulate application modes: Function={0,1} |
| 3040 | 2888 | //--------------------------------------------------------------------------- |
| 3041 | | static void RasterizeTriangle_SMOOTH_TEX_PC(running_machine &machine, |
| 2889 | void hng64_state::RasterizeTriangle_SMOOTH_TEX_PC( |
| 3042 | 2890 | float A[4], float B[4], float C[4], |
| 3043 | 2891 | float Ca[3], float Cb[3], float Cc[3], // PER-VERTEX RGB COLORS |
| 3044 | 2892 | float Ta[2], float Tb[2], float Tc[2], // PER-VERTEX (S,T) TEX-COORDS |
| r244678 | r244679 | |
| 3232 | 3080 | |
| 3233 | 3081 | // Pass the horizontal line to the filler, this could be put in the routine |
| 3234 | 3082 | // then interpolate for the next values of x and z |
| 3235 | | FillSmoothTexPCHorizontalLine(machine, prOptions, |
| 3083 | FillSmoothTexPCHorizontalLine( prOptions, |
| 3236 | 3084 | x_start, x_end, y_min, z_interp_x, z_delta_x, w_interp_x, w_delta_x, |
| 3237 | 3085 | r_interp_x, r_delta_x, g_interp_x, g_delta_x, b_interp_x, b_delta_x, |
| 3238 | 3086 | s_interp_x, s_delta_x, t_interp_x, t_delta_x); |
| r244678 | r244679 | |
| 3311 | 3159 | |
| 3312 | 3160 | // Pass the horizontal line to the filler, this could be put in the routine |
| 3313 | 3161 | // then interpolate for the next values of x and z |
| 3314 | | FillSmoothTexPCHorizontalLine(machine, prOptions, |
| 3162 | FillSmoothTexPCHorizontalLine( prOptions, |
| 3315 | 3163 | x_start, x_end, y_mid, z_interp_x, z_delta_x, w_interp_x, w_delta_x, |
| 3316 | 3164 | r_interp_x, r_delta_x, g_interp_x, g_delta_x, b_interp_x, b_delta_x, |
| 3317 | 3165 | s_interp_x, s_delta_x, t_interp_x, t_delta_x); |
| r244678 | r244679 | |
| 3326 | 3174 | } |
| 3327 | 3175 | } |
| 3328 | 3176 | |
| 3329 | | static void drawShaded(running_machine &machine, struct polygon *p) |
| 3177 | void hng64_state::drawShaded( struct polygon *p) |
| 3330 | 3178 | { |
| 3331 | 3179 | // The perspective-correct texture divide... |
| 3332 | 3180 | // !!! There is a very good chance the HNG64 hardware does not do perspective-correct texture-mapping !!! |
| r244678 | r244679 | |
| 3354 | 3202 | |
| 3355 | 3203 | for (j = 1; j < p->n-1; j++) |
| 3356 | 3204 | { |
| 3357 | | RasterizeTriangle_SMOOTH_TEX_PC(machine, |
| 3205 | RasterizeTriangle_SMOOTH_TEX_PC( |
| 3358 | 3206 | p->vert[0].clipCoords, p->vert[j].clipCoords, p->vert[j+1].clipCoords, |
| 3359 | 3207 | p->vert[0].light, p->vert[j].light, p->vert[j+1].light, |
| 3360 | 3208 | p->vert[0].texCoords, p->vert[j].texCoords, p->vert[j+1].texCoords, |