trunk/src/mame/video/model3.c
| r29617 | r29618 | |
| 9 | 9 | #define pv p[2] |
| 10 | 10 | |
| 11 | 11 | |
| 12 | | |
| 13 | | |
| 14 | | |
| 15 | | struct TRIANGLE |
| 16 | | { |
| 17 | | poly_vertex v[3]; |
| 18 | | UINT8 texture_x, texture_y; |
| 19 | | UINT8 texture_width, texture_height; |
| 20 | | UINT8 transparency; |
| 21 | | UINT8 texture_format, param; |
| 22 | | int intensity; |
| 23 | | UINT32 color; |
| 24 | | }; |
| 25 | | |
| 26 | 12 | struct cached_texture |
| 27 | 13 | { |
| 28 | 14 | cached_texture *next; |
| r29617 | r29618 | |
| 52 | 38 | #define MAX_TRIANGLES 131072 |
| 53 | 39 | |
| 54 | 40 | |
| 55 | | /* forward declarations */ |
| 56 | | static void real3d_traverse_display_list(running_machine &machine); |
| 57 | | static void draw_model(running_machine &machine, UINT32 addr); |
| 58 | | static void init_matrix_stack(running_machine &machine); |
| 59 | | static void get_top_matrix(model3_state *state, MATRIX *out); |
| 60 | | static void push_matrix_stack(model3_state *state); |
| 61 | | static void pop_matrix_stack(model3_state *state); |
| 62 | | static void multiply_matrix_stack(model3_state *state, MATRIX matrix); |
| 63 | | static void translate_matrix_stack(model3_state *state, float x, float y, float z); |
| 64 | | static void traverse_list(running_machine &machine, UINT32 address); |
| 65 | | static void draw_block(running_machine &machine, UINT32 address); |
| 66 | | static void draw_viewport(running_machine &machine, int pri, UINT32 address); |
| 67 | | static void invalidate_texture(running_machine &machine, int page, int texx, int texy, int texwidth, int texheight); |
| 68 | | |
| 69 | 41 | /*****************************************************************************/ |
| 70 | 42 | |
| 71 | | |
| 72 | | |
| 73 | | |
| 74 | | |
| 75 | | |
| 76 | | |
| 77 | | |
| 78 | | |
| 79 | | |
| 80 | | |
| 81 | | |
| 82 | | |
| 83 | | |
| 84 | | |
| 85 | | |
| 86 | | |
| 87 | | |
| 88 | 43 | /* matrix stack */ |
| 89 | 44 | #define MATRIX_STACK_SIZE 256 |
| 90 | 45 | |
| r29617 | r29618 | |
| 107 | 62 | |
| 108 | 63 | void model3_state::model3_exit() |
| 109 | 64 | { |
| 110 | | invalidate_texture(machine(), 0, 0, 0, 6, 5); |
| 111 | | invalidate_texture(machine(), 1, 0, 0, 6, 5); |
| 65 | invalidate_texture(0, 0, 0, 6, 5); |
| 66 | invalidate_texture(1, 0, 0, 6, 5); |
| 112 | 67 | poly_free(m_poly); |
| 113 | 68 | } |
| 114 | 69 | |
| r29617 | r29618 | |
| 148 | 103 | m_viewport_region_width = 496; |
| 149 | 104 | m_viewport_region_height = 384; |
| 150 | 105 | |
| 151 | | init_matrix_stack(machine()); |
| 106 | init_matrix_stack(); |
| 152 | 107 | } |
| 153 | 108 | |
| 154 | | static void draw_tile_4bit(running_machine &machine, bitmap_ind16 &bitmap, int tx, int ty, int tilenum) |
| 109 | void model3_state::draw_tile_4bit(bitmap_ind16 &bitmap, int tx, int ty, int tilenum) |
| 155 | 110 | { |
| 156 | | model3_state *state = machine.driver_data<model3_state>(); |
| 157 | 111 | int x, y; |
| 158 | | UINT8 *tile_base = (UINT8*)state->m_m3_char_ram; |
| 112 | UINT8 *tile_base = (UINT8*)m_m3_char_ram; |
| 159 | 113 | UINT8 *tile; |
| 160 | 114 | |
| 161 | 115 | int data = (BYTE_REVERSE16(tilenum)); |
| r29617 | r29618 | |
| 172 | 126 | UINT16 pix0, pix1; |
| 173 | 127 | tile0 = *tile >> 4; |
| 174 | 128 | tile1 = *tile & 0xf; |
| 175 | | pix0 = state->m_pal_lookup[c + tile0]; |
| 176 | | pix1 = state->m_pal_lookup[c + tile1]; |
| 129 | pix0 = m_pal_lookup[c + tile0]; |
| 130 | pix1 = m_pal_lookup[c + tile1]; |
| 177 | 131 | if((pix0 & 0x8000) == 0) |
| 178 | 132 | { |
| 179 | 133 | d[x+0] = pix0; |
| r29617 | r29618 | |
| 187 | 141 | } |
| 188 | 142 | } |
| 189 | 143 | |
| 190 | | static void draw_tile_8bit(running_machine &machine, bitmap_ind16 &bitmap, int tx, int ty, int tilenum) |
| 144 | void model3_state::draw_tile_8bit(bitmap_ind16 &bitmap, int tx, int ty, int tilenum) |
| 191 | 145 | { |
| 192 | | model3_state *state = machine.driver_data<model3_state>(); |
| 193 | 146 | int x, y; |
| 194 | | UINT8 *tile_base = (UINT8*)state->m_m3_char_ram; |
| 147 | UINT8 *tile_base = (UINT8*)m_m3_char_ram; |
| 195 | 148 | UINT8 *tile; |
| 196 | 149 | |
| 197 | 150 | int data = (BYTE_REVERSE16(tilenum)); |
| r29617 | r29618 | |
| 208 | 161 | UINT8 tile0; |
| 209 | 162 | UINT16 pix; |
| 210 | 163 | tile0 = tile[xx^4]; |
| 211 | | pix = state->m_pal_lookup[c + tile0]; |
| 164 | pix = m_pal_lookup[c + tile0]; |
| 212 | 165 | if((pix & 0x8000) == 0) |
| 213 | 166 | { |
| 214 | 167 | d[x] = pix; |
| r29617 | r29618 | |
| 219 | 172 | } |
| 220 | 173 | } |
| 221 | 174 | #ifdef UNUSED_FUNCTION |
| 222 | | static void draw_texture_sheet(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 175 | void model3_state::draw_texture_sheet(bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 223 | 176 | { |
| 224 | | model3_state *state = machine.driver_data<model3_state>(); |
| 225 | 177 | int x,y; |
| 226 | 178 | for(y = cliprect.min_y; y <= cliprect.max_y; y++) |
| 227 | 179 | { |
| 228 | 180 | UINT16 *d = &bitmap.pix16(y); |
| 229 | 181 | int index = (y*2)*2048; |
| 230 | 182 | for(x = cliprect.min_x; x <= cliprect.max_x; x++) { |
| 231 | | UINT16 pix = state->m_texture_ram[0][index]; |
| 183 | UINT16 pix = m_texture_ram[0][index]; |
| 232 | 184 | index+=4; |
| 233 | 185 | if(pix != 0) { |
| 234 | 186 | d[x] = pix; |
| r29617 | r29618 | |
| 238 | 190 | } |
| 239 | 191 | #endif |
| 240 | 192 | |
| 241 | | static void draw_layer(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int bitdepth) |
| 193 | void model3_state::draw_layer(bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int bitdepth) |
| 242 | 194 | { |
| 243 | | model3_state *state = machine.driver_data<model3_state>(); |
| 244 | 195 | int x, y; |
| 245 | 196 | int tile_index = 0; |
| 246 | | UINT16 *tiles = (UINT16*)&state->m_m3_tile_ram[layer * 0x400]; |
| 197 | UINT16 *tiles = (UINT16*)&m_m3_tile_ram[layer * 0x400]; |
| 247 | 198 | |
| 248 | 199 | //logerror("Layer %d: X: %d, Y: %d\n", layer, x1, y1); |
| 249 | 200 | |
| 250 | 201 | if(layer > 1) { |
| 251 | | int modr = (state->m_layer_modulate2 >> 8) & 0xff; |
| 252 | | int modg = (state->m_layer_modulate2 >> 16) & 0xff; |
| 253 | | int modb = (state->m_layer_modulate2 >> 24) & 0xff; |
| 202 | int modr = (m_layer_modulate2 >> 8) & 0xff; |
| 203 | int modg = (m_layer_modulate2 >> 16) & 0xff; |
| 204 | int modb = (m_layer_modulate2 >> 24) & 0xff; |
| 254 | 205 | if(modr & 0x80) { |
| 255 | | state->m_layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; |
| 206 | m_layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; |
| 256 | 207 | } else { |
| 257 | | state->m_layer_modulate_r = (modr & 0x7f) << 10; |
| 208 | m_layer_modulate_r = (modr & 0x7f) << 10; |
| 258 | 209 | } |
| 259 | 210 | if(modg & 0x80) { |
| 260 | | state->m_layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; |
| 211 | m_layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; |
| 261 | 212 | } else { |
| 262 | | state->m_layer_modulate_g = (modr & 0x7f) << 5; |
| 213 | m_layer_modulate_g = (modr & 0x7f) << 5; |
| 263 | 214 | } |
| 264 | 215 | if(modb & 0x80) { |
| 265 | | state->m_layer_modulate_b = -(0x7f - (modr & 0x7f)); |
| 216 | m_layer_modulate_b = -(0x7f - (modr & 0x7f)); |
| 266 | 217 | } else { |
| 267 | | state->m_layer_modulate_b = (modr & 0x7f); |
| 218 | m_layer_modulate_b = (modr & 0x7f); |
| 268 | 219 | } |
| 269 | 220 | } else { |
| 270 | | int modr = (state->m_layer_modulate1 >> 8) & 0xff; |
| 271 | | int modg = (state->m_layer_modulate1 >> 16) & 0xff; |
| 272 | | int modb = (state->m_layer_modulate1 >> 24) & 0xff; |
| 221 | int modr = (m_layer_modulate1 >> 8) & 0xff; |
| 222 | int modg = (m_layer_modulate1 >> 16) & 0xff; |
| 223 | int modb = (m_layer_modulate1 >> 24) & 0xff; |
| 273 | 224 | if(modr & 0x80) { |
| 274 | | state->m_layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; |
| 225 | m_layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; |
| 275 | 226 | } else { |
| 276 | | state->m_layer_modulate_r = (modr & 0x7f) << 10; |
| 227 | m_layer_modulate_r = (modr & 0x7f) << 10; |
| 277 | 228 | } |
| 278 | 229 | if(modg & 0x80) { |
| 279 | | state->m_layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; |
| 230 | m_layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; |
| 280 | 231 | } else { |
| 281 | | state->m_layer_modulate_g = (modr & 0x7f) << 5; |
| 232 | m_layer_modulate_g = (modr & 0x7f) << 5; |
| 282 | 233 | } |
| 283 | 234 | if(modb & 0x80) { |
| 284 | | state->m_layer_modulate_b = -(0x7f - (modr & 0x7f)); |
| 235 | m_layer_modulate_b = -(0x7f - (modr & 0x7f)); |
| 285 | 236 | } else { |
| 286 | | state->m_layer_modulate_b = (modr & 0x7f); |
| 237 | m_layer_modulate_b = (modr & 0x7f); |
| 287 | 238 | } |
| 288 | 239 | } |
| 289 | 240 | |
| r29617 | r29618 | |
| 294 | 245 | tile_index = ((y/8) * 64); |
| 295 | 246 | for (x = cliprect.min_x; x <= cliprect.max_x; x+=8) { |
| 296 | 247 | UINT16 tile = tiles[tile_index ^ 0x2]; |
| 297 | | draw_tile_4bit(machine, bitmap, x, y, tile); |
| 248 | draw_tile_4bit(bitmap, x, y, tile); |
| 298 | 249 | ++tile_index; |
| 299 | 250 | } |
| 300 | 251 | } |
| r29617 | r29618 | |
| 306 | 257 | tile_index = ((y/8) * 64); |
| 307 | 258 | for (x = cliprect.min_x; x <= cliprect.max_x; x+=8) { |
| 308 | 259 | UINT16 tile = tiles[tile_index ^ 0x2]; |
| 309 | | draw_tile_8bit(machine, bitmap, x, y, tile); |
| 260 | draw_tile_8bit(bitmap, x, y, tile); |
| 310 | 261 | ++tile_index; |
| 311 | 262 | } |
| 312 | 263 | } |
| r29617 | r29618 | |
| 314 | 265 | } |
| 315 | 266 | |
| 316 | 267 | #ifdef UNUSED_FUNCTION |
| 317 | | static void copy_screen(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 268 | static void copy_screen(bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 318 | 269 | { |
| 319 | | model3_state *state = machine.driver_data<model3_state>(); |
| 320 | 270 | int x,y; |
| 321 | 271 | for(y=cliprect.min_y; y <= cliprect.max_y; y++) { |
| 322 | 272 | UINT16 *d = &bitmap.pix16(y); |
| 323 | | UINT16 *s = &state->m_bitmap3d.pix16(y); |
| 273 | UINT16 *s = &m_bitmap3d.pix16(y); |
| 324 | 274 | for(x=cliprect.min_x; x <= cliprect.max_x; x++) { |
| 325 | 275 | UINT16 pix = s[x]; |
| 326 | 276 | if(!(pix & 0x8000)) { |
| r29617 | r29618 | |
| 374 | 324 | bitmap.fill(0, cliprect); |
| 375 | 325 | |
| 376 | 326 | if (!(m_debug_layer_disable & 0x8)) |
| 377 | | draw_layer(machine(), bitmap, cliprect, 3, (m_layer_enable >> 3) & 0x1); |
| 327 | draw_layer(bitmap, cliprect, 3, (m_layer_enable >> 3) & 0x1); |
| 378 | 328 | |
| 379 | 329 | if (!(m_debug_layer_disable & 0x4)) |
| 380 | | draw_layer(machine(), bitmap, cliprect, 2, (m_layer_enable >> 2) & 0x1); |
| 330 | draw_layer(bitmap, cliprect, 2, (m_layer_enable >> 2) & 0x1); |
| 381 | 331 | |
| 382 | 332 | if( !(m_debug_layer_disable & 0x10) ) |
| 383 | 333 | { |
| r29617 | r29618 | |
| 385 | 335 | if(m_real3d_display_list) { |
| 386 | 336 | m_zbuffer.fill(0, cliprect); |
| 387 | 337 | m_bitmap3d.fill(0x8000, cliprect); |
| 388 | | real3d_traverse_display_list(machine()); |
| 338 | real3d_traverse_display_list(); |
| 389 | 339 | } |
| 390 | 340 | #endif |
| 391 | 341 | copybitmap_trans(bitmap, m_bitmap3d, 0, 0, 0, 0, cliprect, 0x8000); |
| 392 | 342 | } |
| 393 | 343 | |
| 394 | 344 | if (!(m_debug_layer_disable & 0x2)) |
| 395 | | draw_layer(machine(), bitmap, cliprect, 1, (m_layer_enable >> 1) & 0x1); |
| 345 | draw_layer(bitmap, cliprect, 1, (m_layer_enable >> 1) & 0x1); |
| 396 | 346 | |
| 397 | 347 | if (!(m_debug_layer_disable & 0x1)) |
| 398 | | draw_layer(machine(), bitmap, cliprect, 0, (m_layer_enable >> 0) & 0x1); |
| 348 | draw_layer(bitmap, cliprect, 0, (m_layer_enable >> 0) & 0x1); |
| 399 | 349 | |
| 400 | 350 | //copy_screen(bitmap, cliprect); |
| 401 | 351 | |
| r29617 | r29618 | |
| 495 | 445 | 1024 pixels / 32 pixel resolution vertically |
| 496 | 446 | 2048 pixels / 32 pixel resolution horizontally |
| 497 | 447 | */ |
| 498 | | static void invalidate_texture(running_machine &machine, int page, int texx, int texy, int texwidth, int texheight) |
| 448 | void model3_state::invalidate_texture(int page, int texx, int texy, int texwidth, int texheight) |
| 499 | 449 | { |
| 500 | | model3_state *state = machine.driver_data<model3_state>(); |
| 501 | 450 | int wtiles = 1 << texwidth; |
| 502 | 451 | int htiles = 1 << texheight; |
| 503 | | int x, y; |
| 504 | 452 | |
| 505 | | for (y = 0; y < htiles; y++) |
| 506 | | for (x = 0; x < wtiles; x++) |
| 507 | | while (state->m_texcache[page][texy + y][texx + x] != NULL) |
| 453 | for (int y = 0; y < htiles; y++) |
| 454 | for (int x = 0; x < wtiles; x++) |
| 455 | while (m_texcache[page][texy + y][texx + x] != NULL) |
| 508 | 456 | { |
| 509 | | cached_texture *freeme = state->m_texcache[page][texy + y][texx + x]; |
| 510 | | state->m_texcache[page][texy + y][texx + x] = freeme->next; |
| 511 | | auto_free(machine, freeme); |
| 457 | cached_texture *freeme = m_texcache[page][texy + y][texx + x]; |
| 458 | m_texcache[page][texy + y][texx + x] = freeme->next; |
| 459 | auto_free(machine(), freeme); |
| 512 | 460 | } |
| 513 | 461 | } |
| 514 | 462 | |
| 515 | | static cached_texture *get_texture(running_machine &machine, int page, int texx, int texy, int texwidth, int texheight, int format) |
| 463 | cached_texture *model3_state::get_texture(int page, int texx, int texy, int texwidth, int texheight, int format) |
| 516 | 464 | { |
| 517 | | model3_state *state = machine.driver_data<model3_state>(); |
| 518 | | cached_texture *tex = state->m_texcache[page][texy][texx]; |
| 465 | cached_texture *tex = m_texcache[page][texy][texx]; |
| 519 | 466 | int pixheight = 32 << texheight; |
| 520 | 467 | int pixwidth = 32 << texwidth; |
| 521 | 468 | UINT32 alpha = ~0; |
| 522 | 469 | int x, y; |
| 523 | 470 | |
| 524 | 471 | /* if we have one already, validate it */ |
| 525 | | for (tex = state->m_texcache[page][texy][texx]; tex != NULL; tex = tex->next) |
| 472 | for (tex = m_texcache[page][texy][texx]; tex != NULL; tex = tex->next) |
| 526 | 473 | if (tex->width == texwidth && tex->height == texheight && tex->format == format) |
| 527 | 474 | return tex; |
| 528 | 475 | |
| 529 | 476 | /* create a new texture */ |
| 530 | | tex = (cached_texture *)auto_alloc_array(machine, UINT8, sizeof(cached_texture) + (2 * pixwidth * 2 * pixheight) * sizeof(rgb_t)); |
| 477 | tex = (cached_texture *)auto_alloc_array(machine(), UINT8, sizeof(cached_texture) + (2 * pixwidth * 2 * pixheight) * sizeof(rgb_t)); |
| 531 | 478 | tex->width = texwidth; |
| 532 | 479 | tex->height = texheight; |
| 533 | 480 | tex->format = format; |
| 534 | 481 | |
| 535 | 482 | /* set the new texture */ |
| 536 | | tex->next = state->m_texcache[page][texy][texx]; |
| 537 | | state->m_texcache[page][texy][texx] = tex; |
| 483 | tex->next = m_texcache[page][texy][texx]; |
| 484 | m_texcache[page][texy][texx] = tex; |
| 538 | 485 | |
| 539 | 486 | /* decode it */ |
| 540 | 487 | for (y = 0; y < pixheight; y++) |
| 541 | 488 | { |
| 542 | | const UINT16 *texsrc = &state->m_texture_ram[page][(texy * 32 + y) * 2048 + texx * 32]; |
| 489 | const UINT16 *texsrc = &m_texture_ram[page][(texy * 32 + y) * 2048 + texx * 32]; |
| 543 | 490 | rgb_t *dest = tex->data + 2 * pixwidth * y; |
| 544 | 491 | |
| 545 | 492 | switch (format) |
| r29617 | r29618 | |
| 660 | 607 | 50, 51, 54, 55, 58, 59, 62, 63 |
| 661 | 608 | }; |
| 662 | 609 | |
| 663 | | INLINE void write_texture16(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data) |
| 610 | inline void model3_state::write_texture16(int xpos, int ypos, int width, int height, int page, UINT16 *data) |
| 664 | 611 | { |
| 665 | 612 | int x,y,i,j; |
| 666 | 613 | |
| r29617 | r29618 | |
| 668 | 615 | { |
| 669 | 616 | for(x=xpos; x < xpos+width; x+=8) |
| 670 | 617 | { |
| 671 | | UINT16 *texture = &state->m_texture_ram[page][y*2048+x]; |
| 618 | UINT16 *texture = &m_texture_ram[page][y*2048+x]; |
| 672 | 619 | int b = 0; |
| 673 | 620 | for(j=y; j < y+8; j++) { |
| 674 | 621 | for(i=x; i < x+8; i++) { |
| r29617 | r29618 | |
| 683 | 630 | } |
| 684 | 631 | |
| 685 | 632 | #ifdef UNUSED_FUNCTION |
| 686 | | INLINE void write_texture8(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data) |
| 633 | inline void model3_state::write_texture8(int xpos, int ypos, int width, int height, int page, UINT16 *data) |
| 687 | 634 | { |
| 688 | 635 | int x,y,i,j; |
| 689 | 636 | UINT16 color = 0x7c00; |
| r29617 | r29618 | |
| 692 | 639 | { |
| 693 | 640 | for(x=xpos; x < xpos+width; x+=8) |
| 694 | 641 | { |
| 695 | | UINT16 *texture = &state->m_texture_ram[page][y*2048+x]; |
| 642 | UINT16 *texture = &m_texture_ram[page][y*2048+x]; |
| 696 | 643 | for(j=y; j < y+4; j++) { |
| 697 | 644 | for(i=x; i < x+8; i++) { |
| 698 | 645 | *texture = color; |
| r29617 | r29618 | |
| 705 | 652 | } |
| 706 | 653 | #endif |
| 707 | 654 | |
| 708 | | static void real3d_upload_texture(running_machine &machine, UINT32 header, UINT32 *data) |
| 655 | void model3_state::real3d_upload_texture(UINT32 header, UINT32 *data) |
| 709 | 656 | { |
| 710 | | model3_state *state = machine.driver_data<model3_state>(); |
| 711 | 657 | int width = 32 << ((header >> 14) & 0x7); |
| 712 | 658 | int height = 32 << ((header >> 17) & 0x7); |
| 713 | 659 | int xpos = (header & 0x3f) * 32; |
| r29617 | r29618 | |
| 719 | 665 | { |
| 720 | 666 | case 0x00: /* Texture with mipmaps */ |
| 721 | 667 | //if(bitdepth) { |
| 722 | | write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data); |
| 723 | | invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7); |
| 668 | write_texture16(xpos, ypos, width, height, page, (UINT16*)data); |
| 669 | invalidate_texture(page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7); |
| 724 | 670 | //} else { |
| 725 | 671 | /* TODO: 8-bit textures are weird. need to figure out some additional bits */ |
| 726 | 672 | //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header); |
| r29617 | r29618 | |
| 729 | 675 | break; |
| 730 | 676 | case 0x01: /* Texture without mipmaps */ |
| 731 | 677 | //if(bitdepth) { |
| 732 | | write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data); |
| 733 | | invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7); |
| 678 | write_texture16(xpos, ypos, width, height, page, (UINT16*)data); |
| 679 | invalidate_texture(page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7); |
| 734 | 680 | //} else { |
| 735 | 681 | /* TODO: 8-bit textures are weird. need to figure out some additional bits */ |
| 736 | 682 | //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header); |
| r29617 | r29618 | |
| 757 | 703 | { |
| 758 | 704 | int length = (m_texture_fifo[i] / 2) + 2; |
| 759 | 705 | UINT32 header = m_texture_fifo[i+1]; |
| 760 | | real3d_upload_texture(machine(), header, &m_texture_fifo[i+2]); |
| 706 | real3d_upload_texture(header, &m_texture_fifo[i+2]); |
| 761 | 707 | i += length; |
| 762 | 708 | }; |
| 763 | 709 | } |
| 764 | 710 | m_texture_fifo_pos = 0; |
| 765 | 711 | m_zbuffer.fill(0); |
| 766 | 712 | m_bitmap3d.fill(0x8000); |
| 767 | | real3d_traverse_display_list(machine()); |
| 768 | | //state->m_real3d_display_list = 1; |
| 713 | real3d_traverse_display_list(); |
| 714 | //m_real3d_display_list = 1; |
| 769 | 715 | } |
| 770 | 716 | |
| 771 | 717 | void model3_state::real3d_display_list1_dma(UINT32 src, UINT32 dst, int length, int byteswap) |
| r29617 | r29618 | |
| 815 | 761 | address = space.read_dword((src+0)); |
| 816 | 762 | header = space.read_dword((src+4)); |
| 817 | 763 | } |
| 818 | | real3d_upload_texture(space.machine(), header, (UINT32*)&m_vrom[address]); |
| 764 | real3d_upload_texture(header, (UINT32*)&m_vrom[address]); |
| 819 | 765 | } |
| 820 | 766 | } |
| 821 | 767 | |
| r29617 | r29618 | |
| 897 | 843 | memcpy(out, &tmp, sizeof(MATRIX)); |
| 898 | 844 | } |
| 899 | 845 | |
| 900 | | static void init_matrix_stack(running_machine &machine) |
| 846 | void model3_state::init_matrix_stack() |
| 901 | 847 | { |
| 902 | | model3_state *state = machine.driver_data<model3_state>(); |
| 903 | 848 | MATRIX *matrix_stack; |
| 904 | | matrix_stack = state->m_matrix_stack = auto_alloc_array_clear(machine, MATRIX, MATRIX_STACK_SIZE); |
| 849 | matrix_stack = m_matrix_stack = auto_alloc_array_clear(machine(), MATRIX, MATRIX_STACK_SIZE); |
| 905 | 850 | |
| 906 | 851 | /* initialize the first matrix as identity */ |
| 907 | 852 | matrix_stack[0][0][0] = 1.0f; |
| r29617 | r29618 | |
| 921 | 866 | matrix_stack[0][3][2] = 0.0f; |
| 922 | 867 | matrix_stack[0][3][3] = 1.0f; |
| 923 | 868 | |
| 924 | | state->m_matrix_stack_ptr = 0; |
| 869 | m_matrix_stack_ptr = 0; |
| 925 | 870 | } |
| 926 | 871 | |
| 927 | | static void get_top_matrix(model3_state *state, MATRIX *out) |
| 872 | void model3_state::get_top_matrix(MATRIX *out) |
| 928 | 873 | { |
| 929 | | memcpy( out, &state->m_matrix_stack[state->m_matrix_stack_ptr], sizeof(MATRIX)); |
| 874 | memcpy(out, &m_matrix_stack[m_matrix_stack_ptr], sizeof(MATRIX)); |
| 930 | 875 | } |
| 931 | 876 | |
| 932 | | static void push_matrix_stack(model3_state *state) |
| 877 | void model3_state::push_matrix_stack() |
| 933 | 878 | { |
| 934 | | state->m_matrix_stack_ptr++; |
| 935 | | if (state->m_matrix_stack_ptr >= MATRIX_STACK_SIZE) |
| 879 | m_matrix_stack_ptr++; |
| 880 | if (m_matrix_stack_ptr >= MATRIX_STACK_SIZE) |
| 936 | 881 | fatalerror("push_matrix_stack: matrix stack overflow\n"); |
| 937 | 882 | |
| 938 | | memcpy( &state->m_matrix_stack[state->m_matrix_stack_ptr], &state->m_matrix_stack[state->m_matrix_stack_ptr-1], sizeof(MATRIX)); |
| 883 | memcpy(&m_matrix_stack[m_matrix_stack_ptr], &m_matrix_stack[m_matrix_stack_ptr - 1], sizeof(MATRIX)); |
| 939 | 884 | } |
| 940 | 885 | |
| 941 | | static void pop_matrix_stack(model3_state *state) |
| 886 | void model3_state::pop_matrix_stack() |
| 942 | 887 | { |
| 943 | | state->m_matrix_stack_ptr--; |
| 944 | | if (state->m_matrix_stack_ptr < 0) |
| 888 | m_matrix_stack_ptr--; |
| 889 | if (m_matrix_stack_ptr < 0) |
| 945 | 890 | fatalerror("pop_matrix_stack: matrix stack underflow\n"); |
| 946 | 891 | } |
| 947 | 892 | |
| 948 | | static void multiply_matrix_stack(model3_state *state, MATRIX matrix) |
| 893 | void model3_state::multiply_matrix_stack(MATRIX matrix) |
| 949 | 894 | { |
| 950 | | matrix_multiply(matrix, state->m_matrix_stack[state->m_matrix_stack_ptr], &state->m_matrix_stack[state->m_matrix_stack_ptr]); |
| 895 | matrix_multiply(matrix, m_matrix_stack[m_matrix_stack_ptr], &m_matrix_stack[m_matrix_stack_ptr]); |
| 951 | 896 | } |
| 952 | 897 | |
| 953 | | static void translate_matrix_stack(model3_state *state, float x, float y, float z) |
| 898 | void model3_state::translate_matrix_stack(float x, float y, float z) |
| 954 | 899 | { |
| 955 | 900 | MATRIX tm; |
| 956 | 901 | |
| r29617 | r29618 | |
| 959 | 904 | tm[2][0] = 0.0f; tm[2][1] = 0.0f; tm[2][2] = 1.0f; tm[2][3] = 0.0f; |
| 960 | 905 | tm[3][0] = x; tm[3][1] = y; tm[3][2] = z; tm[3][3] = 1.0f; |
| 961 | 906 | |
| 962 | | matrix_multiply(tm, state->m_matrix_stack[state->m_matrix_stack_ptr], &state->m_matrix_stack[state->m_matrix_stack_ptr]); |
| 907 | matrix_multiply(tm, m_matrix_stack[m_matrix_stack_ptr], &m_matrix_stack[m_matrix_stack_ptr]); |
| 963 | 908 | } |
| 964 | 909 | |
| 965 | 910 | /*****************************************************************************/ |
| r29617 | r29618 | |
| 1037 | 982 | return clip_verts; |
| 1038 | 983 | } |
| 1039 | 984 | |
| 1040 | | static void render_one(running_machine &machine, TRIANGLE *tri) |
| 985 | void model3_state::render_one(TRIANGLE *tri) |
| 1041 | 986 | { |
| 1042 | | model3_state *state = machine.driver_data<model3_state>(); |
| 1043 | | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(state->m_poly); |
| 987 | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(m_poly); |
| 1044 | 988 | poly_draw_scanline_func callback = NULL; |
| 1045 | 989 | |
| 1046 | 990 | tri->v[0].pz = 1.0f / tri->v[0].pz; |
| 1047 | 991 | tri->v[1].pz = 1.0f / tri->v[1].pz; |
| 1048 | 992 | tri->v[2].pz = 1.0f / tri->v[2].pz; |
| 1049 | 993 | |
| 1050 | | extra->zbuffer = &state->m_zbuffer; |
| 994 | extra->zbuffer = &m_zbuffer; |
| 1051 | 995 | if (tri->param & TRI_PARAM_TEXTURE_ENABLE) |
| 1052 | 996 | { |
| 1053 | 997 | tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * 256.0f; |
| r29617 | r29618 | |
| 1057 | 1001 | tri->v[2].pu = tri->v[2].pu * tri->v[2].pz * 256.0f; |
| 1058 | 1002 | tri->v[2].pv = tri->v[2].pv * tri->v[2].pz * 256.0f; |
| 1059 | 1003 | |
| 1060 | | extra->texture = get_texture(machine, (tri->param & TRI_PARAM_TEXTURE_PAGE) ? 1 : 0, tri->texture_x, tri->texture_y, tri->texture_width, tri->texture_height, tri->texture_format); |
| 1004 | extra->texture = get_texture((tri->param & TRI_PARAM_TEXTURE_PAGE) ? 1 : 0, tri->texture_x, tri->texture_y, tri->texture_width, tri->texture_height, tri->texture_format); |
| 1061 | 1005 | extra->texture_param = tri->param; |
| 1062 | 1006 | extra->polygon_transparency = tri->transparency; |
| 1063 | 1007 | extra->polygon_intensity = tri->intensity; |
| r29617 | r29618 | |
| 1068 | 1012 | callback = (tri->transparency >= 32) ? draw_scanline_normal : draw_scanline_trans; |
| 1069 | 1013 | else |
| 1070 | 1014 | callback = draw_scanline_alpha; |
| 1071 | | poly_render_triangle(state->m_poly, &state->m_bitmap3d, state->m_clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 1015 | poly_render_triangle(m_poly, &m_bitmap3d, m_clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 1072 | 1016 | } |
| 1073 | 1017 | else |
| 1074 | 1018 | { |
| r29617 | r29618 | |
| 1076 | 1020 | extra->polygon_intensity = tri->intensity; |
| 1077 | 1021 | extra->color = tri->color; |
| 1078 | 1022 | |
| 1079 | | poly_render_triangle(state->m_poly, &state->m_bitmap3d, state->m_clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 1023 | poly_render_triangle(m_poly, &m_bitmap3d, m_clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 1080 | 1024 | } |
| 1081 | 1025 | } |
| 1082 | 1026 | |
| 1083 | | static void draw_model(running_machine &machine, UINT32 addr) |
| 1027 | void model3_state::draw_model(UINT32 addr) |
| 1084 | 1028 | { |
| 1085 | | model3_state *state = machine.driver_data<model3_state>(); |
| 1086 | | UINT32 *model = (addr >= 0x100000) ? &state->m_vrom[addr] : &state->m_polygon_ram[addr]; |
| 1029 | UINT32 *model = (addr >= 0x100000) ? &m_vrom[addr] : &m_polygon_ram[addr]; |
| 1087 | 1030 | UINT32 header[7]; |
| 1088 | 1031 | int index = 0; |
| 1089 | 1032 | int last_polygon = FALSE, first_polygon = TRUE, back_face = FALSE; |
| r29617 | r29618 | |
| 1097 | 1040 | MATRIX transform_matrix; |
| 1098 | 1041 | float center_x, center_y; |
| 1099 | 1042 | |
| 1100 | | if(state->m_step < 0x15) { /* position coordinates are 17.15 fixed-point in Step 1.0 */ |
| 1043 | if(m_step < 0x15) { /* position coordinates are 17.15 fixed-point in Step 1.0 */ |
| 1101 | 1044 | fixed_point_fraction = 1.0f / 32768.0f; |
| 1102 | 1045 | } else { /* 13.19 fixed-point in other Steps */ |
| 1103 | 1046 | fixed_point_fraction = 1.0f / 524288.0f; |
| 1104 | 1047 | } |
| 1105 | 1048 | |
| 1106 | | get_top_matrix(state, &transform_matrix); |
| 1049 | get_top_matrix(&transform_matrix); |
| 1107 | 1050 | |
| 1108 | 1051 | /* current viewport center coordinates on screen */ |
| 1109 | | center_x = (float)(state->m_viewport_region_x + (state->m_viewport_region_width / 2)); |
| 1110 | | center_y = (float)(state->m_viewport_region_y + (state->m_viewport_region_height / 2)); |
| 1052 | center_x = (float)(m_viewport_region_x + (m_viewport_region_width / 2)); |
| 1053 | center_y = (float)(m_viewport_region_y + (m_viewport_region_height / 2)); |
| 1111 | 1054 | |
| 1112 | 1055 | memset(prev_vertex, 0, sizeof(prev_vertex)); |
| 1113 | 1056 | |
| r29617 | r29618 | |
| 1224 | 1167 | (normal[1] * transform_matrix[1][2]) + |
| 1225 | 1168 | (normal[2] * transform_matrix[2][2]); |
| 1226 | 1169 | |
| 1227 | | sn[0] *= state->m_coordinate_system[0][1]; |
| 1228 | | sn[1] *= state->m_coordinate_system[1][2]; |
| 1229 | | sn[2] *= state->m_coordinate_system[2][0]; |
| 1170 | sn[0] *= m_coordinate_system[0][1]; |
| 1171 | sn[1] *= m_coordinate_system[1][2]; |
| 1172 | sn[2] *= m_coordinate_system[2][0]; |
| 1230 | 1173 | |
| 1231 | 1174 | /* TODO: depth bias */ |
| 1232 | 1175 | /* transform vertices */ |
| r29617 | r29618 | |
| 1243 | 1186 | matrix_multiply_vector(transform_matrix, vect, &p[i]); |
| 1244 | 1187 | |
| 1245 | 1188 | /* apply coordinate system */ |
| 1246 | | clip_vert[i].x = p[i][0] * state->m_coordinate_system[0][1]; |
| 1247 | | clip_vert[i].y = p[i][1] * state->m_coordinate_system[1][2]; |
| 1248 | | clip_vert[i].pz = p[i][2] * state->m_coordinate_system[2][0]; |
| 1189 | clip_vert[i].x = p[i][0] * m_coordinate_system[0][1]; |
| 1190 | clip_vert[i].y = p[i][1] * m_coordinate_system[1][2]; |
| 1191 | clip_vert[i].pz = p[i][2] * m_coordinate_system[2][0]; |
| 1249 | 1192 | clip_vert[i].pu = vertex[i].pu * texture_coord_scale; |
| 1250 | 1193 | clip_vert[i].pv = vertex[i].pv * texture_coord_scale; |
| 1251 | 1194 | } |
| 1252 | 1195 | |
| 1253 | 1196 | /* clip against view frustum */ |
| 1254 | | num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[0], clip_vert); |
| 1255 | | num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[1], clip_vert); |
| 1256 | | num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[2], clip_vert); |
| 1257 | | num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[3], clip_vert); |
| 1258 | | num_vertices = clip_polygon(clip_vert, num_vertices, state->m_clip_plane[4], clip_vert); |
| 1197 | num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[0], clip_vert); |
| 1198 | num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[1], clip_vert); |
| 1199 | num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[2], clip_vert); |
| 1200 | num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[3], clip_vert); |
| 1201 | num_vertices = clip_polygon(clip_vert, num_vertices, m_clip_plane[4], clip_vert); |
| 1259 | 1202 | |
| 1260 | 1203 | /* backface culling */ |
| 1261 | 1204 | if( (header[6] & 0x800000) && (!(header[1] & 0x0010)) ) { |
| r29617 | r29618 | |
| 1271 | 1214 | /* homogeneous Z-divide, screen-space transformation */ |
| 1272 | 1215 | for(i=0; i < num_vertices; i++) { |
| 1273 | 1216 | float ooz = 1.0f / clip_vert[i].pz; |
| 1274 | | clip_vert[i].x = ((clip_vert[i].x * ooz) * state->m_viewport_focal_length) + center_x; |
| 1275 | | clip_vert[i].y = ((clip_vert[i].y * ooz) * state->m_viewport_focal_length) + center_y; |
| 1217 | clip_vert[i].x = ((clip_vert[i].x * ooz) * m_viewport_focal_length) + center_x; |
| 1218 | clip_vert[i].y = ((clip_vert[i].y * ooz) * m_viewport_focal_length) + center_y; |
| 1276 | 1219 | } |
| 1277 | 1220 | |
| 1278 | 1221 | // lighting |
| 1279 | 1222 | if ((header[6] & 0x10000) == 0) |
| 1280 | 1223 | { |
| 1281 | | dot = dot_product3(sn, state->m_parallel_light); |
| 1282 | | intensity = ((dot * state->m_parallel_light_intensity) + state->m_ambient_light_intensity) * 256.0f; |
| 1224 | dot = dot_product3(sn, m_parallel_light); |
| 1225 | intensity = ((dot * m_parallel_light_intensity) + m_ambient_light_intensity) * 256.0f; |
| 1283 | 1226 | if (intensity > 256) |
| 1284 | 1227 | { |
| 1285 | 1228 | intensity = 256; |
| r29617 | r29618 | |
| 1316 | 1259 | tri.param |= (header[2] & 0x1) ? TRI_PARAM_TEXTURE_MIRROR_V : 0; |
| 1317 | 1260 | tri.param |= (header[6] & 0x80000000) ? TRI_PARAM_ALPHA_TEST : 0; |
| 1318 | 1261 | |
| 1319 | | render_one(machine, &tri); |
| 1262 | render_one(&tri); |
| 1320 | 1263 | } |
| 1321 | 1264 | } |
| 1322 | 1265 | } |
| r29617 | r29618 | |
| 1326 | 1269 | /*****************************************************************************/ |
| 1327 | 1270 | /* display list parser */ |
| 1328 | 1271 | |
| 1329 | | static UINT32 *get_memory_pointer(model3_state *state, UINT32 address) |
| 1272 | UINT32 *model3_state::get_memory_pointer(UINT32 address) |
| 1330 | 1273 | { |
| 1331 | 1274 | if (address & 0x800000) |
| 1332 | 1275 | { |
| 1333 | 1276 | if (address >= 0x840000) { |
| 1334 | 1277 | fatalerror("get_memory_pointer: invalid display list memory address %08X\n", address); |
| 1335 | 1278 | } |
| 1336 | | return &state->m_display_list_ram[address & 0x7fffff]; |
| 1279 | return &m_display_list_ram[address & 0x7fffff]; |
| 1337 | 1280 | } |
| 1338 | 1281 | else |
| 1339 | 1282 | { |
| 1340 | 1283 | if (address >= 0x100000) { |
| 1341 | 1284 | fatalerror("get_memory_pointer: invalid node ram address %08X\n", address); |
| 1342 | 1285 | } |
| 1343 | | return &state->m_culling_ram[address]; |
| 1286 | return &m_culling_ram[address]; |
| 1344 | 1287 | } |
| 1345 | 1288 | } |
| 1346 | 1289 | |
| 1347 | | static void load_matrix(model3_state *state, int matrix_num, MATRIX *out) |
| 1290 | void model3_state::load_matrix(int matrix_num, MATRIX *out) |
| 1348 | 1291 | { |
| 1349 | | float *matrix = (float *)get_memory_pointer(state, state->m_matrix_base_address + matrix_num * 12); |
| 1292 | float *matrix = (float *)get_memory_pointer(m_matrix_base_address + matrix_num * 12); |
| 1350 | 1293 | |
| 1351 | 1294 | (*out)[0][0] = matrix[3]; (*out)[0][1] = matrix[6]; (*out)[0][2] = matrix[9]; (*out)[0][3] = 0.0f; |
| 1352 | 1295 | (*out)[1][0] = matrix[4]; (*out)[1][1] = matrix[7]; (*out)[1][2] = matrix[10]; (*out)[1][3] = 0.0f; |
| r29617 | r29618 | |
| 1354 | 1297 | (*out)[3][0] = matrix[0]; (*out)[3][1] = matrix[1]; (*out)[3][2] = matrix[2]; (*out)[3][3] = 1.0f; |
| 1355 | 1298 | } |
| 1356 | 1299 | |
| 1357 | | static void traverse_list4(running_machine &machine, int lod_num, UINT32 address) |
| 1300 | void model3_state::traverse_list4(int lod_num, UINT32 address) |
| 1358 | 1301 | { |
| 1359 | | model3_state *state = machine.driver_data<model3_state>(); |
| 1360 | | |
| 1361 | 1302 | /* does something with the LOD selection */ |
| 1362 | | UINT32 *list = get_memory_pointer(state, address); |
| 1303 | UINT32 *list = get_memory_pointer(address); |
| 1363 | 1304 | UINT32 link = list[0]; |
| 1364 | 1305 | |
| 1365 | | draw_model(machine, link & 0xffffff); |
| 1306 | draw_model(link & 0xffffff); |
| 1366 | 1307 | } |
| 1367 | 1308 | |
| 1368 | | static void traverse_list(running_machine &machine, UINT32 address) |
| 1309 | void model3_state::traverse_list(UINT32 address) |
| 1369 | 1310 | { |
| 1370 | | model3_state *state = machine.driver_data<model3_state>(); |
| 1371 | | UINT32 *list = get_memory_pointer(state, address); |
| 1311 | UINT32 *list = get_memory_pointer(address); |
| 1372 | 1312 | int list_ptr = 0; |
| 1373 | 1313 | |
| 1374 | | if (state->m_list_depth > 2) |
| 1314 | if (m_list_depth > 2) |
| 1375 | 1315 | return; |
| 1376 | 1316 | |
| 1377 | | state->m_list_depth++; |
| 1317 | m_list_depth++; |
| 1378 | 1318 | |
| 1379 | 1319 | /* find the end of the list */ |
| 1380 | 1320 | while (1) |
| r29617 | r29618 | |
| 1395 | 1335 | address = list[--list_ptr] & 0xffffff; |
| 1396 | 1336 | if (address != 0 && address != 0x800800) |
| 1397 | 1337 | //if (address != 0) |
| 1398 | | draw_block(machine, address); |
| 1338 | draw_block(address); |
| 1399 | 1339 | } |
| 1400 | 1340 | |
| 1401 | | state->m_list_depth--; |
| 1341 | m_list_depth--; |
| 1402 | 1342 | } |
| 1403 | 1343 | |
| 1404 | | INLINE void process_link(running_machine &machine, UINT32 address, UINT32 link) |
| 1344 | inline void model3_state::process_link(UINT32 address, UINT32 link) |
| 1405 | 1345 | { |
| 1406 | 1346 | if (link != 0 && link != 0x0fffffff && link != 0x00800800 && link != 0x01000000) |
| 1407 | 1347 | { |
| 1408 | 1348 | switch (link >> 24) |
| 1409 | 1349 | { |
| 1410 | 1350 | case 0x00: /* link to another node */ |
| 1411 | | draw_block(machine, link & 0xffffff); |
| 1351 | draw_block(link & 0xffffff); |
| 1412 | 1352 | break; |
| 1413 | 1353 | |
| 1414 | 1354 | case 0x01: |
| 1415 | 1355 | case 0x03: /* both of these link to models, is there any difference ? */ |
| 1416 | | draw_model(machine, link & 0xffffff); |
| 1356 | draw_model(link & 0xffffff); |
| 1417 | 1357 | break; |
| 1418 | 1358 | |
| 1419 | 1359 | case 0x04: /* list of links */ |
| 1420 | | traverse_list(machine, link & 0xffffff); |
| 1360 | traverse_list(link & 0xffffff); |
| 1421 | 1361 | break; |
| 1422 | 1362 | |
| 1423 | 1363 | default: |
| r29617 | r29618 | |
| 1427 | 1367 | } |
| 1428 | 1368 | } |
| 1429 | 1369 | |
| 1430 | | static void draw_block(running_machine &machine, UINT32 address) |
| 1370 | void model3_state::draw_block(UINT32 address) |
| 1431 | 1371 | { |
| 1432 | | model3_state *state = machine.driver_data<model3_state>(); |
| 1433 | | const UINT32 *node = get_memory_pointer(state, address); |
| 1372 | const UINT32 *node = get_memory_pointer(address); |
| 1434 | 1373 | UINT32 link; |
| 1435 | 1374 | int node_matrix; |
| 1436 | 1375 | float x, y, z; |
| 1437 | 1376 | MATRIX matrix; |
| 1438 | 1377 | int offset; |
| 1439 | 1378 | |
| 1440 | | offset = (state->m_step < 0x15) ? 2 : 0; |
| 1379 | offset = (m_step < 0x15) ? 2 : 0; |
| 1441 | 1380 | link = node[7 - offset]; |
| 1442 | 1381 | |
| 1443 | 1382 | /* apply matrix and translation */ |
| 1444 | 1383 | node_matrix = node[3 - offset] & 0xfff; |
| 1445 | | load_matrix(state, node_matrix, &matrix); |
| 1384 | load_matrix(node_matrix, &matrix); |
| 1446 | 1385 | |
| 1447 | | push_matrix_stack(state); |
| 1386 | push_matrix_stack(); |
| 1448 | 1387 | |
| 1449 | 1388 | if (node[0] & 0x10) |
| 1450 | 1389 | { |
| 1451 | 1390 | x = *(float *)&node[4 - offset]; |
| 1452 | 1391 | y = *(float *)&node[5 - offset]; |
| 1453 | 1392 | z = *(float *)&node[6 - offset]; |
| 1454 | | translate_matrix_stack(state, x, y, z); |
| 1393 | translate_matrix_stack(x, y, z); |
| 1455 | 1394 | } |
| 1456 | 1395 | else if (node_matrix != 0) |
| 1457 | | multiply_matrix_stack(state, matrix); |
| 1396 | multiply_matrix_stack(matrix); |
| 1458 | 1397 | |
| 1459 | 1398 | /* bit 0x08 of word 0 indicates a pointer list */ |
| 1460 | 1399 | if (node[0] & 0x08) |
| 1461 | | traverse_list4(machine, (node[3 - offset] >> 12) & 0x7f, link & 0xffffff); |
| 1400 | traverse_list4((node[3 - offset] >> 12) & 0x7f, link & 0xffffff); |
| 1462 | 1401 | else |
| 1463 | | process_link(machine, address, link); |
| 1402 | process_link(address, link); |
| 1464 | 1403 | |
| 1465 | | pop_matrix_stack(state); |
| 1404 | pop_matrix_stack(); |
| 1466 | 1405 | |
| 1467 | 1406 | /* handle the second link */ |
| 1468 | 1407 | link = node[8 - offset]; |
| 1469 | | process_link(machine, address, link); |
| 1408 | process_link(address, link); |
| 1470 | 1409 | } |
| 1471 | 1410 | |
| 1472 | | static void draw_viewport(running_machine &machine, int pri, UINT32 address) |
| 1411 | void model3_state::draw_viewport(int pri, UINT32 address) |
| 1473 | 1412 | { |
| 1474 | | model3_state *state = machine.driver_data<model3_state>(); |
| 1475 | | const UINT32 *node = get_memory_pointer(state, address); |
| 1413 | const UINT32 *node = get_memory_pointer(address); |
| 1476 | 1414 | UINT32 link_address; |
| 1477 | 1415 | float /*viewport_left, viewport_right, */viewport_top, viewport_bottom; |
| 1478 | 1416 | float /*fov_x,*/ fov_y; |
| r29617 | r29618 | |
| 1484 | 1422 | /* traverse to the link node before drawing this viewport */ |
| 1485 | 1423 | /* check this is correct as this affects the rendering order */ |
| 1486 | 1424 | if (link_address != 0x01000000) |
| 1487 | | draw_viewport(machine, pri, link_address); |
| 1425 | draw_viewport(pri, link_address); |
| 1488 | 1426 | |
| 1489 | 1427 | /* skip if this isn't the right priority */ |
| 1490 | 1428 | if (pri != ((node[0] >> 3) & 3)) |
| 1491 | 1429 | return; |
| 1492 | 1430 | |
| 1493 | 1431 | /* set viewport parameters */ |
| 1494 | | state->m_viewport_region_x = (node[26] & 0xffff) >> 4; /* 12.4 fixed point */ |
| 1495 | | state->m_viewport_region_y = ((node[26] >> 16) & 0xffff) >> 4; |
| 1496 | | state->m_viewport_region_width = (node[20] & 0xffff) >> 2; /* 14.2 fixed point */ |
| 1497 | | state->m_viewport_region_height = ((node[20] >> 16) & 0xffff) >> 2; |
| 1432 | m_viewport_region_x = (node[26] & 0xffff) >> 4; /* 12.4 fixed point */ |
| 1433 | m_viewport_region_y = ((node[26] >> 16) & 0xffff) >> 4; |
| 1434 | m_viewport_region_width = (node[20] & 0xffff) >> 2; /* 14.2 fixed point */ |
| 1435 | m_viewport_region_height = ((node[20] >> 16) & 0xffff) >> 2; |
| 1498 | 1436 | |
| 1499 | 1437 | /* frustum plane angles */ |
| 1500 | 1438 | //viewport_left = RADIAN_TO_DEGREE(asin(*(float *)&node[12])); |
| r29617 | r29618 | |
| 1503 | 1441 | viewport_bottom = RADIAN_TO_DEGREE(asin(*(float *)&node[18])); |
| 1504 | 1442 | |
| 1505 | 1443 | /* build clipping planes */ |
| 1506 | | state->m_clip_plane[0].x = *(float *)&node[13]; state->m_clip_plane[0].y = 0.0f; state->m_clip_plane[0].z = *(float *)&node[12]; state->m_clip_plane[0].d = 0.0f; |
| 1507 | | state->m_clip_plane[1].x = *(float *)&node[17]; state->m_clip_plane[1].y = 0.0f; state->m_clip_plane[1].z = *(float *)&node[16]; state->m_clip_plane[1].d = 0.0f; |
| 1508 | | state->m_clip_plane[2].x = 0.0f; state->m_clip_plane[2].y = *(float *)&node[15]; state->m_clip_plane[2].z = *(float *)&node[14]; state->m_clip_plane[2].d = 0.0f; |
| 1509 | | state->m_clip_plane[3].x = 0.0f; state->m_clip_plane[3].y = *(float *)&node[19]; state->m_clip_plane[3].z = *(float *)&node[18]; state->m_clip_plane[3].d = 0.0f; |
| 1510 | | state->m_clip_plane[4].x = 0.0f; state->m_clip_plane[4].y = 0.0f; state->m_clip_plane[4].z = 1.0f; state->m_clip_plane[4].d = 1.0f; |
| 1444 | m_clip_plane[0].x = *(float *)&node[13]; m_clip_plane[0].y = 0.0f; m_clip_plane[0].z = *(float *)&node[12]; m_clip_plane[0].d = 0.0f; |
| 1445 | m_clip_plane[1].x = *(float *)&node[17]; m_clip_plane[1].y = 0.0f; m_clip_plane[1].z = *(float *)&node[16]; m_clip_plane[1].d = 0.0f; |
| 1446 | m_clip_plane[2].x = 0.0f; m_clip_plane[2].y = *(float *)&node[15]; m_clip_plane[2].z = *(float *)&node[14]; m_clip_plane[2].d = 0.0f; |
| 1447 | m_clip_plane[3].x = 0.0f; m_clip_plane[3].y = *(float *)&node[19]; m_clip_plane[3].z = *(float *)&node[18]; m_clip_plane[3].d = 0.0f; |
| 1448 | m_clip_plane[4].x = 0.0f; m_clip_plane[4].y = 0.0f; m_clip_plane[4].z = 1.0f; m_clip_plane[4].d = 1.0f; |
| 1511 | 1449 | |
| 1512 | 1450 | /* compute field of view */ |
| 1513 | 1451 | //fov_x = viewport_left + viewport_right; |
| 1514 | 1452 | fov_y = viewport_top + viewport_bottom; |
| 1515 | | state->m_viewport_focal_length = (state->m_viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f ); |
| 1453 | m_viewport_focal_length = (m_viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f ); |
| 1516 | 1454 | |
| 1517 | | state->m_matrix_base_address = node[22]; |
| 1455 | m_matrix_base_address = node[22]; |
| 1518 | 1456 | /* TODO: where does node[23] point to ? LOD table ? */ |
| 1519 | 1457 | |
| 1520 | 1458 | /* set lighting parameters */ |
| 1521 | | state->m_parallel_light[0] = -*(float *)&node[5]; |
| 1522 | | state->m_parallel_light[1] = *(float *)&node[6]; |
| 1523 | | state->m_parallel_light[2] = *(float *)&node[4]; |
| 1524 | | state->m_parallel_light_intensity = *(float *)&node[7]; |
| 1525 | | state->m_ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f; |
| 1459 | m_parallel_light[0] = -*(float *)&node[5]; |
| 1460 | m_parallel_light[1] = *(float *)&node[6]; |
| 1461 | m_parallel_light[2] = *(float *)&node[4]; |
| 1462 | m_parallel_light_intensity = *(float *)&node[7]; |
| 1463 | m_ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f; |
| 1526 | 1464 | |
| 1527 | 1465 | /* set coordinate system matrix */ |
| 1528 | | load_matrix(state, 0, &state->m_coordinate_system); |
| 1466 | load_matrix(0, &m_coordinate_system); |
| 1529 | 1467 | |
| 1530 | 1468 | /* process a link */ |
| 1531 | | process_link(machine, link_address, node[2]); |
| 1469 | process_link(link_address, node[2]); |
| 1532 | 1470 | } |
| 1533 | 1471 | |
| 1534 | 1472 | |
| 1535 | | static void real3d_traverse_display_list(running_machine &machine) |
| 1473 | void model3_state::real3d_traverse_display_list() |
| 1536 | 1474 | { |
| 1537 | | model3_state *state = machine.driver_data<model3_state>(); |
| 1538 | | int pri; |
| 1475 | init_matrix_stack(); |
| 1539 | 1476 | |
| 1540 | | init_matrix_stack(machine); |
| 1477 | for (int pri = 0; pri < 4; pri++) |
| 1478 | draw_viewport(pri, 0x800000); |
| 1541 | 1479 | |
| 1542 | | for (pri = 0; pri < 4; pri++) |
| 1543 | | draw_viewport(machine, pri, 0x800000); |
| 1544 | | |
| 1545 | | poly_wait(state->m_poly, "real3d_traverse_display_list"); |
| 1480 | poly_wait(m_poly, "real3d_traverse_display_list"); |
| 1546 | 1481 | } |