trunk/src/mame/includes/model2.h
| r249090 | r249091 | |
| 1 | 1 | // license:BSD-3-Clause |
| 2 | 2 | // copyright-holders:R. Belmont, Olivier Galibert, ElSemi, Angelo Salese |
| 3 | | #include "video/polylgcy.h" |
| 3 | #include "video/poly.h" |
| 4 | 4 | #include "audio/dsbz80.h" |
| 5 | 5 | #include "audio/segam1audio.h" |
| 6 | 6 | #include "machine/eepromser.h" |
| r249090 | r249091 | |
| 9 | 9 | #include "machine/315-5881_crypt.h" |
| 10 | 10 | #include "machine/315-5838_317-0229_comp.h" |
| 11 | 11 | |
| 12 | class model2_renderer; |
| 12 | 13 | struct raster_state; |
| 13 | 14 | struct geo_state; |
| 14 | 15 | |
| 15 | | |
| 16 | 16 | class model2_state : public driver_device |
| 17 | 17 | { |
| 18 | 18 | public: |
| r249090 | r249091 | |
| 107 | 107 | int m_jnet_time_out; |
| 108 | 108 | UINT32 m_geo_read_start_address; |
| 109 | 109 | UINT32 m_geo_write_start_address; |
| 110 | | legacy_poly_manager *m_poly; |
| 110 | model2_renderer *m_poly; |
| 111 | 111 | raster_state *m_raster; |
| 112 | 112 | geo_state *m_geo; |
| 113 | 113 | bitmap_rgb32 m_sys24_bitmap; |
| r249090 | r249091 | |
| 219 | 219 | TIMER_DEVICE_CALLBACK_MEMBER(model2_timer_cb); |
| 220 | 220 | TIMER_DEVICE_CALLBACK_MEMBER(model2_interrupt); |
| 221 | 221 | TIMER_DEVICE_CALLBACK_MEMBER(model2c_interrupt); |
| 222 | | void model2_exit(); |
| 223 | 222 | DECLARE_WRITE8_MEMBER(scsp_irq); |
| 224 | 223 | DECLARE_READ_LINE_MEMBER(copro_tgp_fifoin_pop_ok); |
| 225 | 224 | DECLARE_READ32_MEMBER(copro_tgp_fifoin_pop); |
| r249090 | r249091 | |
| 237 | 236 | void model2_3d_frame_end( bitmap_rgb32 &bitmap, const rectangle &cliprect ); |
| 238 | 237 | }; |
| 239 | 238 | |
| 239 | |
| 240 | /***************************** |
| 241 | * |
| 242 | * Modern polygon renderer |
| 243 | * |
| 244 | *****************************/ |
| 245 | |
| 246 | struct m2_poly_extra_data |
| 247 | { |
| 248 | model2_state * state; |
| 249 | UINT32 lumabase; |
| 250 | UINT32 colorbase; |
| 251 | UINT32 * texsheet; |
| 252 | UINT32 texwidth; |
| 253 | UINT32 texheight; |
| 254 | UINT32 texx, texy; |
| 255 | UINT8 texmirrorx; |
| 256 | UINT8 texmirrory; |
| 257 | }; |
| 258 | |
| 259 | |
| 260 | INLINE UINT16 get_texel( UINT32 base_x, UINT32 base_y, int x, int y, UINT32 *sheet ) |
| 261 | { |
| 262 | UINT32 baseoffs = ((base_y/2)*512)+(base_x/2); |
| 263 | UINT32 texeloffs = ((y/2)*512)+(x/2); |
| 264 | UINT32 offset = baseoffs + texeloffs; |
| 265 | UINT32 texel = sheet[offset>>1]; |
| 266 | |
| 267 | if ( offset & 1 ) |
| 268 | texel >>= 16; |
| 269 | |
| 270 | if ( (y & 1) == 0 ) |
| 271 | texel >>= 8; |
| 272 | |
| 273 | if ( (x & 1) == 0 ) |
| 274 | texel >>= 4; |
| 275 | |
| 276 | return (texel & 0x0f); |
| 277 | } |
| 278 | |
| 279 | struct triangle; |
| 280 | |
| 281 | class model2_renderer : public poly_manager<float, m2_poly_extra_data, 4, 4000> |
| 282 | { |
| 283 | |
| 284 | public: |
| 285 | typedef void (model2_renderer::*scanline_render_func)(INT32 scanline, const extent_t& extent, const m2_poly_extra_data& object, int threadid); |
| 286 | |
| 287 | public: |
| 288 | model2_renderer(model2_state& state) |
| 289 | : poly_manager<float, m2_poly_extra_data, 4, 4000>(state.machine()) |
| 290 | , m_state(state) |
| 291 | , m_destmap(state.m_screen->width(), state.m_screen->height()) |
| 292 | { |
| 293 | m_renderfuncs[0] = &model2_renderer::model2_3d_render_0; |
| 294 | m_renderfuncs[1] = &model2_renderer::model2_3d_render_1; |
| 295 | m_renderfuncs[2] = &model2_renderer::model2_3d_render_2; |
| 296 | m_renderfuncs[3] = &model2_renderer::model2_3d_render_3; |
| 297 | m_renderfuncs[4] = &model2_renderer::model2_3d_render_4; |
| 298 | m_renderfuncs[5] = &model2_renderer::model2_3d_render_5; |
| 299 | m_renderfuncs[6] = &model2_renderer::model2_3d_render_6; |
| 300 | m_renderfuncs[7] = &model2_renderer::model2_3d_render_7; |
| 301 | } |
| 302 | |
| 303 | bitmap_rgb32& destmap() { return m_destmap; } |
| 304 | |
| 305 | void model2_3d_render(triangle *tri, const rectangle &cliprect); |
| 306 | |
| 307 | /* checker = 0, textured = 0, transparent = 0 */ |
| 308 | #define MODEL2_FUNC 0 |
| 309 | #define MODEL2_FUNC_NAME model2_3d_render_0 |
| 310 | #include "video/model2rd.inc" |
| 311 | #undef MODEL2_FUNC |
| 312 | #undef MODEL2_FUNC_NAME |
| 313 | |
| 314 | /* checker = 0, textured = 0, translucent = 1 */ |
| 315 | #define MODEL2_FUNC 1 |
| 316 | #define MODEL2_FUNC_NAME model2_3d_render_1 |
| 317 | #include "video/model2rd.inc" |
| 318 | #undef MODEL2_FUNC |
| 319 | #undef MODEL2_FUNC_NAME |
| 320 | |
| 321 | /* checker = 0, textured = 1, translucent = 0 */ |
| 322 | #define MODEL2_FUNC 2 |
| 323 | #define MODEL2_FUNC_NAME model2_3d_render_2 |
| 324 | #include "video/model2rd.inc" |
| 325 | #undef MODEL2_FUNC |
| 326 | #undef MODEL2_FUNC_NAME |
| 327 | |
| 328 | /* checker = 0, textured = 1, translucent = 1 */ |
| 329 | #define MODEL2_FUNC 3 |
| 330 | #define MODEL2_FUNC_NAME model2_3d_render_3 |
| 331 | #include "video/model2rd.inc" |
| 332 | #undef MODEL2_FUNC |
| 333 | #undef MODEL2_FUNC_NAME |
| 334 | |
| 335 | /* checker = 1, textured = 0, translucent = 0 */ |
| 336 | #define MODEL2_FUNC 4 |
| 337 | #define MODEL2_FUNC_NAME model2_3d_render_4 |
| 338 | #include "video/model2rd.inc" |
| 339 | #undef MODEL2_FUNC |
| 340 | #undef MODEL2_FUNC_NAME |
| 341 | |
| 342 | /* checker = 1, textured = 0, translucent = 1 */ |
| 343 | #define MODEL2_FUNC 5 |
| 344 | #define MODEL2_FUNC_NAME model2_3d_render_5 |
| 345 | #include "video/model2rd.inc" |
| 346 | #undef MODEL2_FUNC |
| 347 | #undef MODEL2_FUNC_NAME |
| 348 | |
| 349 | /* checker = 1, textured = 1, translucent = 0 */ |
| 350 | #define MODEL2_FUNC 6 |
| 351 | #define MODEL2_FUNC_NAME model2_3d_render_6 |
| 352 | #include "video/model2rd.inc" |
| 353 | #undef MODEL2_FUNC |
| 354 | #undef MODEL2_FUNC_NAME |
| 355 | |
| 356 | /* checker = 1, textured = 1, translucent = 1 */ |
| 357 | #define MODEL2_FUNC 7 |
| 358 | #define MODEL2_FUNC_NAME model2_3d_render_7 |
| 359 | #include "video/model2rd.inc" |
| 360 | #undef MODEL2_FUNC |
| 361 | #undef MODEL2_FUNC_NAME |
| 362 | |
| 363 | scanline_render_func m_renderfuncs[8]; |
| 364 | |
| 365 | private: |
| 366 | model2_state& m_state; |
| 367 | bitmap_rgb32 m_destmap; |
| 368 | }; |
| 369 | |
| 370 | typedef model2_renderer::vertex_t poly_vertex; |
| 371 | |
| 372 | |
| 373 | /******************************************* |
| 374 | * |
| 375 | * Basic Data Types |
| 376 | * |
| 377 | *******************************************/ |
| 378 | |
| 379 | struct plane |
| 380 | { |
| 381 | poly_vertex normal; |
| 382 | float distance; |
| 383 | }; |
| 384 | |
| 385 | struct texture_parameter |
| 386 | { |
| 387 | float diffuse; |
| 388 | float ambient; |
| 389 | UINT32 specular_control; |
| 390 | float specular_scale; |
| 391 | }; |
| 392 | |
| 393 | struct triangle |
| 394 | { |
| 395 | void * next; |
| 396 | poly_vertex v[3]; |
| 397 | UINT16 z; |
| 398 | UINT16 texheader[4]; |
| 399 | UINT8 luma; |
| 400 | INT16 viewport[4]; |
| 401 | INT16 center[2]; |
| 402 | }; |
| 403 | |
| 404 | struct quad_m2 |
| 405 | { |
| 406 | poly_vertex v[4]; |
| 407 | UINT16 z; |
| 408 | UINT16 texheader[4]; |
| 409 | UINT8 luma; |
| 410 | }; |
| 411 | |
| 412 | |
| 413 | |
| 240 | 414 | /*----------- defined in video/model2.c -----------*/ |
| 241 | 415 | void model2_3d_set_zclip( running_machine &machine, UINT8 clip ); |
trunk/src/mame/video/model2.c
| r249090 | r249091 | |
| 89 | 89 | *********************************************************************************************************************************/ |
| 90 | 90 | #include "emu.h" |
| 91 | 91 | #include "video/segaic24.h" |
| 92 | | #include "video/polylgcy.h" |
| 93 | 92 | #include "includes/model2.h" |
| 94 | 93 | |
| 95 | 94 | #define MODEL2_VIDEO_DEBUG 0 |
| r249090 | r249091 | |
| 102 | 101 | |
| 103 | 102 | /******************************************* |
| 104 | 103 | * |
| 105 | | * Basic Data Types |
| 106 | | * |
| 107 | | *******************************************/ |
| 108 | | |
| 109 | | struct plane |
| 110 | | { |
| 111 | | poly_vertex normal; |
| 112 | | float distance; |
| 113 | | }; |
| 114 | | |
| 115 | | struct texture_parameter |
| 116 | | { |
| 117 | | float diffuse; |
| 118 | | float ambient; |
| 119 | | UINT32 specular_control; |
| 120 | | float specular_scale; |
| 121 | | }; |
| 122 | | |
| 123 | | struct triangle |
| 124 | | { |
| 125 | | void * next; |
| 126 | | poly_vertex v[3]; |
| 127 | | UINT16 z; |
| 128 | | UINT16 texheader[4]; |
| 129 | | UINT8 luma; |
| 130 | | INT16 viewport[4]; |
| 131 | | INT16 center[2]; |
| 132 | | }; |
| 133 | | |
| 134 | | struct quad_m2 |
| 135 | | { |
| 136 | | poly_vertex v[4]; |
| 137 | | UINT16 z; |
| 138 | | UINT16 texheader[4]; |
| 139 | | UINT8 luma; |
| 140 | | }; |
| 141 | | |
| 142 | | struct m2_poly_extra_data |
| 143 | | { |
| 144 | | model2_state * state; |
| 145 | | UINT32 lumabase; |
| 146 | | UINT32 colorbase; |
| 147 | | UINT32 * texsheet; |
| 148 | | UINT32 texwidth; |
| 149 | | UINT32 texheight; |
| 150 | | UINT32 texx, texy; |
| 151 | | UINT8 texmirrorx; |
| 152 | | UINT8 texmirrory; |
| 153 | | }; |
| 154 | | |
| 155 | | |
| 156 | | /******************************************* |
| 157 | | * |
| 158 | 104 | * Generic 3D Math Functions |
| 159 | 105 | * |
| 160 | 106 | *******************************************/ |
| r249090 | r249091 | |
| 834 | 780 | } |
| 835 | 781 | |
| 836 | 782 | /***********************************************************************************************/ |
| 837 | | |
| 838 | | INLINE UINT16 get_texel( UINT32 base_x, UINT32 base_y, int x, int y, UINT32 *sheet ) |
| 839 | | { |
| 840 | | UINT32 baseoffs = ((base_y/2)*512)+(base_x/2); |
| 841 | | UINT32 texeloffs = ((y/2)*512)+(x/2); |
| 842 | | UINT32 offset = baseoffs + texeloffs; |
| 843 | | UINT32 texel = sheet[offset>>1]; |
| 844 | | |
| 845 | | if ( offset & 1 ) |
| 846 | | texel >>= 16; |
| 847 | | |
| 848 | | if ( (y & 1) == 0 ) |
| 849 | | texel >>= 8; |
| 850 | | |
| 851 | | if ( (x & 1) == 0 ) |
| 852 | | texel >>= 4; |
| 853 | | |
| 854 | | return (texel & 0x0f); |
| 855 | | } |
| 856 | | |
| 857 | | /* checker = 0, textured = 0, transparent = 0 */ |
| 858 | | #define MODEL2_FUNC 0 |
| 859 | | #define MODEL2_FUNC_NAME model2_3d_render_0 |
| 860 | | #include "model2rd.inc" |
| 861 | | #undef MODEL2_FUNC |
| 862 | | #undef MODEL2_FUNC_NAME |
| 863 | | |
| 864 | | /* checker = 0, textured = 0, translucent = 1 */ |
| 865 | | #define MODEL2_FUNC 1 |
| 866 | | #define MODEL2_FUNC_NAME model2_3d_render_1 |
| 867 | | #include "model2rd.inc" |
| 868 | | #undef MODEL2_FUNC |
| 869 | | #undef MODEL2_FUNC_NAME |
| 870 | | |
| 871 | | /* checker = 0, textured = 1, translucent = 0 */ |
| 872 | | #define MODEL2_FUNC 2 |
| 873 | | #define MODEL2_FUNC_NAME model2_3d_render_2 |
| 874 | | #include "model2rd.inc" |
| 875 | | #undef MODEL2_FUNC |
| 876 | | #undef MODEL2_FUNC_NAME |
| 877 | | |
| 878 | | /* checker = 0, textured = 1, translucent = 1 */ |
| 879 | | #define MODEL2_FUNC 3 |
| 880 | | #define MODEL2_FUNC_NAME model2_3d_render_3 |
| 881 | | #include "model2rd.inc" |
| 882 | | #undef MODEL2_FUNC |
| 883 | | #undef MODEL2_FUNC_NAME |
| 884 | | |
| 885 | | /* checker = 1, textured = 0, translucent = 0 */ |
| 886 | | #define MODEL2_FUNC 4 |
| 887 | | #define MODEL2_FUNC_NAME model2_3d_render_4 |
| 888 | | #include "model2rd.inc" |
| 889 | | #undef MODEL2_FUNC |
| 890 | | #undef MODEL2_FUNC_NAME |
| 891 | | |
| 892 | | /* checker = 1, textured = 0, translucent = 1 */ |
| 893 | | #define MODEL2_FUNC 5 |
| 894 | | #define MODEL2_FUNC_NAME model2_3d_render_5 |
| 895 | | #include "model2rd.inc" |
| 896 | | #undef MODEL2_FUNC |
| 897 | | #undef MODEL2_FUNC_NAME |
| 898 | | |
| 899 | | /* checker = 1, textured = 1, translucent = 0 */ |
| 900 | | #define MODEL2_FUNC 6 |
| 901 | | #define MODEL2_FUNC_NAME model2_3d_render_6 |
| 902 | | #include "model2rd.inc" |
| 903 | | #undef MODEL2_FUNC |
| 904 | | #undef MODEL2_FUNC_NAME |
| 905 | | |
| 906 | | /* checker = 1, textured = 1, translucent = 1 */ |
| 907 | | #define MODEL2_FUNC 7 |
| 908 | | #define MODEL2_FUNC_NAME model2_3d_render_7 |
| 909 | | #include "model2rd.inc" |
| 910 | | #undef MODEL2_FUNC |
| 911 | | #undef MODEL2_FUNC_NAME |
| 912 | | |
| 783 | |
| 913 | 784 | /***********************************************************************************************/ |
| 914 | 785 | |
| 915 | | static const poly_draw_scanline_func render_funcs[8] = |
| 786 | void model2_renderer::model2_3d_render(triangle *tri, const rectangle &cliprect) |
| 916 | 787 | { |
| 917 | | model2_3d_render_0, /* checker = 0, textured = 0, translucent = 0 */ |
| 918 | | model2_3d_render_1, /* checker = 0, textured = 0, translucent = 1 */ |
| 919 | | model2_3d_render_2, /* checker = 0, textured = 1, translucent = 0 */ |
| 920 | | model2_3d_render_3, /* checker = 0, textured = 1, translucent = 1 */ |
| 921 | | model2_3d_render_4, /* checker = 1, textured = 0, translucent = 0 */ |
| 922 | | model2_3d_render_5, /* checker = 1, textured = 0, translucent = 1 */ |
| 923 | | model2_3d_render_6, /* checker = 1, textured = 1, translucent = 0 */ |
| 924 | | model2_3d_render_7 /* checker = 1, textured = 1, translucent = 1 */ |
| 925 | | }; |
| 788 | model2_renderer *poly = m_state.m_poly; |
| 789 | m2_poly_extra_data& extra = poly->object_data_alloc(); |
| 790 | UINT8 renderer; |
| 926 | 791 | |
| 927 | | static void model2_3d_render( model2_state *state, bitmap_rgb32 &bitmap, triangle *tri, const rectangle &cliprect ) |
| 928 | | { |
| 929 | | legacy_poly_manager *poly = state->m_poly; |
| 930 | | m2_poly_extra_data *extra = (m2_poly_extra_data *)poly_get_extra_data(poly); |
| 931 | | UINT8 renderer; |
| 932 | | |
| 933 | 792 | /* select renderer based on attributes (bit15 = checker, bit14 = textured, bit13 = transparent */ |
| 934 | 793 | renderer = (tri->texheader[0] >> 13) & 7; |
| 935 | 794 | |
| r249090 | r249091 | |
| 937 | 796 | rectangle vp(tri->viewport[0] - 8, tri->viewport[2] - 8, (384-tri->viewport[3])+90, (384-tri->viewport[1])+90); |
| 938 | 797 | vp &= cliprect; |
| 939 | 798 | |
| 940 | | extra->state = state; |
| 941 | | extra->lumabase = ((tri->texheader[1] & 0xFF) << 7) + ((tri->luma >> 5) ^ 0x7); |
| 942 | | extra->colorbase = (tri->texheader[3] >> 6) & 0x3FF; |
| 799 | extra.state = &m_state; |
| 800 | extra.lumabase = ((tri->texheader[1] & 0xFF) << 7) + ((tri->luma >> 5) ^ 0x7); |
| 801 | extra.colorbase = (tri->texheader[3] >> 6) & 0x3FF; |
| 943 | 802 | |
| 944 | 803 | if (renderer & 2) |
| 945 | 804 | { |
| 946 | | extra->texwidth = 32 << ((tri->texheader[0] >> 0) & 0x7); |
| 947 | | extra->texheight = 32 << ((tri->texheader[0] >> 3) & 0x7); |
| 948 | | extra->texx = 32 * ((tri->texheader[2] >> 0) & 0x1f); |
| 949 | | extra->texy = 32 * (((tri->texheader[2] >> 6) & 0x1f) + ( tri->texheader[2] & 0x20 )); |
| 805 | extra.texwidth = 32 << ((tri->texheader[0] >> 0) & 0x7); |
| 806 | extra.texheight = 32 << ((tri->texheader[0] >> 3) & 0x7); |
| 807 | extra.texx = 32 * ((tri->texheader[2] >> 0) & 0x1f); |
| 808 | extra.texy = 32 * (((tri->texheader[2] >> 6) & 0x1f) + ( tri->texheader[2] & 0x20 )); |
| 950 | 809 | /* TODO: Virtua Striker contradicts with this. */ |
| 951 | | extra->texmirrorx = 0;//(tri->texheader[0] >> 9) & 1; |
| 952 | | extra->texmirrory = 0;//(tri->texheader[0] >> 8) & 1; |
| 953 | | extra->texsheet = (tri->texheader[2] & 0x1000) ? state->m_textureram1 : state->m_textureram0; |
| 810 | extra.texmirrorx = 0;//(tri->texheader[0] >> 9) & 1; |
| 811 | extra.texmirrory = 0;//(tri->texheader[0] >> 8) & 1; |
| 812 | extra.texsheet = (tri->texheader[2] & 0x1000) ? m_state.m_textureram1 : m_state.m_textureram0; |
| 954 | 813 | |
| 955 | 814 | tri->v[0].pz = 1.0f / (1.0f + tri->v[0].pz); |
| 956 | 815 | tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * (1.0f / 8.0f); |
| r249090 | r249091 | |
| 962 | 821 | tri->v[2].pu = tri->v[2].pu * tri->v[2].pz * (1.0f / 8.0f); |
| 963 | 822 | tri->v[2].pv = tri->v[2].pv * tri->v[2].pz * (1.0f / 8.0f); |
| 964 | 823 | |
| 965 | | poly_render_triangle(poly, &bitmap, vp, render_funcs[renderer], 3, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 824 | // Note : The class model2_renderer has an array of function pointers in it named m_renderfuncs, in theory this simply |
| 825 | // needs to be passed into the render_triangle function as such model2_renderer::m_renderfuncs[renderer], but |
| 826 | // I was unable to make it work when converting to the new polygon rasterizer interface. |
| 827 | switch (renderer) |
| 828 | { |
| 829 | case 0: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_0), this), 3, tri->v[0], tri->v[1], tri->v[2]); break; |
| 830 | case 1: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_1), this), 3, tri->v[0], tri->v[1], tri->v[2]); break; |
| 831 | case 2: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_2), this), 3, tri->v[0], tri->v[1], tri->v[2]); break; |
| 832 | case 3: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_3), this), 3, tri->v[0], tri->v[1], tri->v[2]); break; |
| 833 | case 4: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_4), this), 3, tri->v[0], tri->v[1], tri->v[2]); break; |
| 834 | case 5: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_5), this), 3, tri->v[0], tri->v[1], tri->v[2]); break; |
| 835 | case 6: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_6), this), 3, tri->v[0], tri->v[1], tri->v[2]); break; |
| 836 | case 7: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_7), this), 3, tri->v[0], tri->v[1], tri->v[2]); break; |
| 837 | } |
| 966 | 838 | } |
| 967 | 839 | else |
| 968 | | poly_render_triangle(poly, &bitmap, vp, render_funcs[renderer], 0, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 840 | { |
| 841 | switch (renderer) |
| 842 | { |
| 843 | case 0: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_0), this), 0, tri->v[0], tri->v[1], tri->v[2]); break; |
| 844 | case 1: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_1), this), 0, tri->v[0], tri->v[1], tri->v[2]); break; |
| 845 | case 2: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_2), this), 0, tri->v[0], tri->v[1], tri->v[2]); break; |
| 846 | case 3: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_3), this), 0, tri->v[0], tri->v[1], tri->v[2]); break; |
| 847 | case 4: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_4), this), 0, tri->v[0], tri->v[1], tri->v[2]); break; |
| 848 | case 5: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_5), this), 0, tri->v[0], tri->v[1], tri->v[2]); break; |
| 849 | case 6: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_6), this), 0, tri->v[0], tri->v[1], tri->v[2]); break; |
| 850 | case 7: render_triangle(vp, render_delegate(FUNC(model2_renderer::model2_3d_render_7), this), 0, tri->v[0], tri->v[1], tri->v[2]); break; |
| 851 | } |
| 852 | } |
| 969 | 853 | } |
| 970 | 854 | |
| 971 | 855 | /* |
| r249090 | r249091 | |
| 1019 | 903 | void model2_state::model2_3d_frame_end( bitmap_rgb32 &bitmap, const rectangle &cliprect ) |
| 1020 | 904 | { |
| 1021 | 905 | raster_state *raster = m_raster; |
| 1022 | | INT32 z; |
| 906 | INT32 z; |
| 1023 | 907 | |
| 1024 | 908 | /* if we have nothing to render, bail */ |
| 1025 | 909 | if ( raster->tri_list_index == 0 ) |
| r249090 | r249091 | |
| 1063 | 947 | } |
| 1064 | 948 | #endif |
| 1065 | 949 | |
| 950 | m_poly->destmap().fill(0x00000000, cliprect); |
| 951 | |
| 1066 | 952 | /* go through the Z levels, and render each bucket */ |
| 1067 | 953 | for( z = raster->max_z; z >= raster->min_z; z-- ) |
| 1068 | 954 | { |
| r249090 | r249091 | |
| 1077 | 963 | { |
| 1078 | 964 | /* project and render */ |
| 1079 | 965 | model2_3d_project( tri ); |
| 1080 | | model2_3d_render( this, bitmap, tri, cliprect ); |
| 966 | m_poly->model2_3d_render(tri, cliprect); |
| 1081 | 967 | |
| 1082 | 968 | tri = (triangle *)tri->next; |
| 1083 | 969 | } |
| 1084 | 970 | } |
| 1085 | 971 | } |
| 1086 | | poly_wait(m_poly, "End of frame"); |
| 972 | m_poly->wait("End of frame"); |
| 973 | |
| 974 | copybitmap_trans(bitmap, m_poly->destmap(), 0, 0, 0, 0, cliprect, 0x00000000); |
| 1087 | 975 | } |
| 1088 | 976 | |
| 1089 | 977 | /* 3D Rasterizer main data input port */ |
| r249090 | r249091 | |
| 2694 | 2582 | /***********************************************************************************************/ |
| 2695 | 2583 | |
| 2696 | 2584 | |
| 2697 | | void model2_state::model2_exit() |
| 2698 | | { |
| 2699 | | poly_free(m_poly); |
| 2700 | | } |
| 2701 | | |
| 2702 | 2585 | VIDEO_START_MEMBER(model2_state,model2) |
| 2703 | 2586 | { |
| 2704 | 2587 | const rectangle &visarea = m_screen->visible_area(); |
| r249090 | r249091 | |
| 2707 | 2590 | |
| 2708 | 2591 | m_sys24_bitmap.allocate(width, height+4); |
| 2709 | 2592 | |
| 2710 | | m_poly = poly_alloc(machine(), 4000, sizeof(m2_poly_extra_data), 0); |
| 2711 | | machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(model2_state::model2_exit), this)); |
| 2593 | m_poly = auto_alloc(machine(), model2_renderer(*this)); |
| 2712 | 2594 | |
| 2713 | 2595 | /* initialize the hardware rasterizer */ |
| 2714 | 2596 | model2_3d_init( machine(), (UINT16*)memregion("user3")->base() ); |
trunk/src/mame/video/model2rd.inc
| r249090 | r249091 | |
| 56 | 56 | |
| 57 | 57 | #ifndef MODEL2_TEXTURED |
| 58 | 58 | /* non-textured render path */ |
| 59 | | static void MODEL2_FUNC_NAME(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid) |
| 59 | void MODEL2_FUNC_NAME(INT32 scanline, const extent_t& extent, const m2_poly_extra_data& object, int threadid) |
| 60 | 60 | { |
| 61 | 61 | #if !defined( MODEL2_TRANSLUCENT) |
| 62 | | const m2_poly_extra_data *extra = (const m2_poly_extra_data *)extradata; |
| 63 | | model2_state *state = extra->state; |
| 64 | | bitmap_rgb32 *destmap = (bitmap_rgb32 *)dest; |
| 62 | model2_state *state = object.state; |
| 63 | bitmap_rgb32 *destmap = (bitmap_rgb32 *)&m_destmap; |
| 65 | 64 | UINT32 *p = &destmap->pix32(scanline); |
| 66 | 65 | |
| 67 | 66 | /* extract color information */ |
| r249090 | r249091 | |
| 69 | 68 | const UINT16 *colortable_g = (const UINT16 *)&state->m_colorxlat[0x4000/4]; |
| 70 | 69 | const UINT16 *colortable_b = (const UINT16 *)&state->m_colorxlat[0x8000/4]; |
| 71 | 70 | const UINT16 *lumaram = (const UINT16 *)state->m_lumaram.target(); |
| 72 | | UINT32 lumabase = extra->lumabase; |
| 73 | | UINT32 color = extra->colorbase; |
| 71 | UINT32 lumabase = object.lumabase; |
| 72 | UINT32 color = object.colorbase; |
| 74 | 73 | UINT8 luma; |
| 75 | 74 | UINT32 tr, tg, tb; |
| 76 | 75 | int x; |
| r249090 | r249091 | |
| 98 | 97 | /* build the final color */ |
| 99 | 98 | color = rgb_t(tr, tg, tb); |
| 100 | 99 | |
| 101 | | for(x = extent->startx; x < extent->stopx; x++) |
| 100 | for(x = extent.startx; x < extent.stopx; x++) |
| 102 | 101 | #if defined(MODEL2_CHECKER) |
| 103 | 102 | if ((x^scanline) & 1) p[x] = color; |
| 104 | 103 | #else |
| r249090 | r249091 | |
| 109 | 108 | |
| 110 | 109 | #else |
| 111 | 110 | /* textured render path */ |
| 112 | | static void MODEL2_FUNC_NAME(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid) |
| 111 | void MODEL2_FUNC_NAME(INT32 scanline, const extent_t& extent, const m2_poly_extra_data& object, int threadid) |
| 113 | 112 | { |
| 114 | | const m2_poly_extra_data *extra = (const m2_poly_extra_data *)extradata; |
| 115 | | model2_state *state = extra->state; |
| 116 | | bitmap_rgb32 *destmap = (bitmap_rgb32 *)dest; |
| 113 | model2_state *state = object.state; |
| 114 | bitmap_rgb32 *destmap = (bitmap_rgb32 *)&m_destmap; |
| 117 | 115 | UINT32 *p = &destmap->pix32(scanline); |
| 118 | 116 | |
| 119 | | UINT32 tex_width = extra->texwidth; |
| 120 | | UINT32 tex_height = extra->texheight; |
| 117 | UINT32 tex_width = object.texwidth; |
| 118 | UINT32 tex_height = object.texheight; |
| 121 | 119 | |
| 122 | 120 | /* extract color information */ |
| 123 | 121 | const UINT16 *colortable_r = (const UINT16 *)&state->m_colorxlat[0x0000/4]; |
| 124 | 122 | const UINT16 *colortable_g = (const UINT16 *)&state->m_colorxlat[0x4000/4]; |
| 125 | 123 | const UINT16 *colortable_b = (const UINT16 *)&state->m_colorxlat[0x8000/4]; |
| 126 | 124 | const UINT16 *lumaram = (const UINT16 *)state->m_lumaram.target(); |
| 127 | | UINT32 colorbase = extra->colorbase; |
| 128 | | UINT32 lumabase = extra->lumabase; |
| 129 | | UINT32 tex_x = extra->texx; |
| 130 | | UINT32 tex_y = extra->texy; |
| 125 | UINT32 colorbase = object.colorbase; |
| 126 | UINT32 lumabase = object.lumabase; |
| 127 | UINT32 tex_x = object.texx; |
| 128 | UINT32 tex_y = object.texy; |
| 131 | 129 | UINT32 tex_x_mask, tex_y_mask; |
| 132 | | UINT32 tex_mirr_x = extra->texmirrorx; |
| 133 | | UINT32 tex_mirr_y = extra->texmirrory; |
| 134 | | UINT32 *sheet = extra->texsheet; |
| 135 | | float ooz = extent->param[0].start; |
| 136 | | float uoz = extent->param[1].start; |
| 137 | | float voz = extent->param[2].start; |
| 138 | | float dooz = extent->param[0].dpdx; |
| 139 | | float duoz = extent->param[1].dpdx; |
| 140 | | float dvoz = extent->param[2].dpdx; |
| 130 | UINT32 tex_mirr_x = object.texmirrorx; |
| 131 | UINT32 tex_mirr_y = object.texmirrory; |
| 132 | UINT32 *sheet = object.texsheet; |
| 133 | float ooz = extent.param[0].start; |
| 134 | float uoz = extent.param[1].start; |
| 135 | float voz = extent.param[2].start; |
| 136 | float dooz = extent.param[0].dpdx; |
| 137 | float duoz = extent.param[1].dpdx; |
| 138 | float dvoz = extent.param[2].dpdx; |
| 141 | 139 | int x; |
| 142 | 140 | |
| 143 | 141 | tex_x_mask = tex_width - 1; |
| r249090 | r249091 | |
| 149 | 147 | colortable_g += ((colorbase >> 5) & 0x1f) << 8; |
| 150 | 148 | colortable_b += ((colorbase >> 10) & 0x1f) << 8; |
| 151 | 149 | |
| 152 | | for(x = extent->startx; x < extent->stopx; x++, uoz += duoz, voz += dvoz, ooz += dooz) |
| 150 | for(x = extent.startx; x < extent.stopx; x++, uoz += duoz, voz += dvoz, ooz += dooz) |
| 153 | 151 | { |
| 154 | 152 | float z = recip_approx(ooz) * 256.0f; |
| 155 | 153 | INT32 u = uoz * z; |