trunk/src/mame/video/midzeus2.c
| r249087 | r249088 | |
| 9 | 9 | #include "emu.h" |
| 10 | 10 | #include "cpu/tms32031/tms32031.h" |
| 11 | 11 | #include "includes/midzeus.h" |
| 12 | | #include "video/polylgcy.h" |
| 12 | #include "video/poly.h" |
| 13 | 13 | #include "video/rgbutil.h" |
| 14 | 14 | |
| 15 | 15 | |
| r249087 | r249088 | |
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | 52 | |
| 53 | /************************************* |
| 54 | * |
| 55 | * Polygon renderer |
| 56 | * |
| 57 | *************************************/ |
| 53 | 58 | |
| 59 | class midzeus2_renderer : public poly_manager<float, mz2_poly_extra_data, 4, 10000> |
| 60 | { |
| 61 | public: |
| 62 | midzeus2_renderer(midzeus2_state &state); |
| 63 | |
| 64 | void render_poly_8bit(INT32 scanline, const extent_t& extent, const mz2_poly_extra_data& object, int threadid); |
| 65 | |
| 66 | void zeus2_draw_quad(const UINT32 *databuffer, UINT32 texoffs, int logit); |
| 67 | |
| 68 | bitmap_rgb32 &screenbits() { return m_screenbits; } |
| 69 | |
| 70 | private: |
| 71 | midzeus2_state& m_state; |
| 72 | bitmap_rgb32 m_screenbits; |
| 73 | }; |
| 74 | |
| 75 | typedef midzeus2_renderer::vertex_t poly_vertex; |
| 76 | typedef midzeus2_renderer::extent_t poly_extent; |
| 77 | |
| 78 | midzeus2_renderer::midzeus2_renderer(midzeus2_state &state) |
| 79 | : poly_manager<float, mz2_poly_extra_data, 4, 10000>(state.machine()) |
| 80 | , m_state(state) |
| 81 | , m_screenbits(state.m_screen->width(), state.m_screen->height()) |
| 82 | { |
| 83 | |
| 84 | } |
| 85 | |
| 86 | |
| 54 | 87 | /************************************* |
| 55 | 88 | * |
| 56 | 89 | * Global variables |
| 57 | 90 | * |
| 58 | 91 | *************************************/ |
| 59 | 92 | |
| 60 | | static legacy_poly_manager *poly; |
| 93 | static midzeus2_renderer* polyNew; |
| 61 | 94 | static UINT8 log_fifo; |
| 62 | 95 | |
| 63 | 96 | static UINT32 zeus_fifo[20]; |
| r249087 | r249088 | |
| 99 | 132 | |
| 100 | 133 | /************************************* |
| 101 | 134 | * |
| 102 | | * Function prototypes |
| 103 | | * |
| 104 | | *************************************/ |
| 105 | | |
| 106 | | static void render_poly_8bit(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid); |
| 107 | | |
| 108 | | /************************************* |
| 109 | | * |
| 110 | 135 | * Macros |
| 111 | 136 | * |
| 112 | 137 | *************************************/ |
| r249087 | r249088 | |
| 258 | 283 | waveram[1] = auto_alloc_array(machine(), UINT32, WAVERAM1_WIDTH * WAVERAM1_HEIGHT * 12/4); |
| 259 | 284 | |
| 260 | 285 | /* initialize polygon engine */ |
| 261 | | poly = poly_alloc(machine(), 10000, sizeof(mz2_poly_extra_data), POLYFLAG_ALLOW_QUADS); |
| 262 | | |
| 286 | polyNew = auto_alloc(machine(), midzeus2_renderer(*this)); |
| 287 | |
| 263 | 288 | /* we need to cleanup on exit */ |
| 264 | 289 | machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(midzeus2_state::exit_handler2), this)); |
| 265 | 290 | |
| r249087 | r249088 | |
| 335 | 360 | } |
| 336 | 361 | #endif |
| 337 | 362 | |
| 338 | | poly_free(poly); |
| 339 | 363 | } |
| 340 | 364 | |
| 341 | 365 | |
| r249087 | r249088 | |
| 350 | 374 | { |
| 351 | 375 | int x, y; |
| 352 | 376 | |
| 353 | | poly_wait(poly, "VIDEO_UPDATE"); |
| 354 | | |
| 377 | polyNew->wait(); |
| 378 | |
| 355 | 379 | if (machine().input().code_pressed(KEYCODE_UP)) { zbase += 1.0f; popmessage("Zbase = %f", (double) zbase); } |
| 356 | 380 | if (machine().input().code_pressed(KEYCODE_DOWN)) { zbase -= 1.0f; popmessage("Zbase = %f", (double) zbase); } |
| 357 | 381 | |
| r249087 | r249088 | |
| 1007 | 1031 | break; |
| 1008 | 1032 | |
| 1009 | 1033 | case 0x38: /* crusnexo/thegrid */ |
| 1010 | | zeus2_draw_quad(databuffer, texoffs, logit); |
| 1034 | polyNew->zeus2_draw_quad(databuffer, texoffs, logit); |
| 1011 | 1035 | break; |
| 1012 | 1036 | |
| 1013 | 1037 | default: |
| r249087 | r249088 | |
| 1036 | 1060 | * |
| 1037 | 1061 | *************************************/ |
| 1038 | 1062 | |
| 1039 | | void midzeus2_state::zeus2_draw_quad(const UINT32 *databuffer, UINT32 texoffs, int logit) |
| 1063 | void midzeus2_renderer::zeus2_draw_quad(const UINT32 *databuffer, UINT32 texoffs, int logit) |
| 1040 | 1064 | { |
| 1041 | | poly_draw_scanline_func callback; |
| 1042 | | mz2_poly_extra_data *extra; |
| 1043 | 1065 | poly_vertex clipvert[8]; |
| 1044 | 1066 | poly_vertex vert[4]; |
| 1045 | 1067 | // float uscale, vscale; |
| r249087 | r249088 | |
| 1064 | 1086 | //if (machine().input().code_pressed(KEYCODE_O) && (texoffs & 0xffff) == 0x119) return; |
| 1065 | 1087 | //if (machine().input().code_pressed(KEYCODE_L) && (texoffs & 0x100)) return; |
| 1066 | 1088 | |
| 1067 | | callback = render_poly_8bit; |
| 1068 | | |
| 1069 | 1089 | /* |
| 1070 | 1090 | 0 38800000 |
| 1071 | 1091 | 1 x2 | x1 |
| r249087 | r249088 | |
| 1179 | 1199 | } |
| 1180 | 1200 | } |
| 1181 | 1201 | |
| 1182 | | numverts = poly_zclip_if_less(4, &vert[0], &clipvert[0], 4, 1.0f / 512.0f / 4.0f); |
| 1202 | numverts = polyNew->zclip_if_less(4, &vert[0], &clipvert[0], 4, 1.0f / 512.0f / 4.0f); |
| 1183 | 1203 | if (numverts < 3) |
| 1184 | 1204 | return; |
| 1185 | 1205 | |
| r249087 | r249088 | |
| 1210 | 1230 | clipvert[i].y += 0.0005f; |
| 1211 | 1231 | } |
| 1212 | 1232 | |
| 1213 | | extra = (mz2_poly_extra_data *)poly_get_extra_data(poly); |
| 1233 | mz2_poly_extra_data& extra = polyNew->object_data_alloc(); |
| 1214 | 1234 | switch (texmode) |
| 1215 | 1235 | { |
| 1216 | 1236 | case 0x01d: /* crusnexo: RHS of score bar */ |
| r249087 | r249088 | |
| 1222 | 1242 | case 0x95d: /* crusnexo */ |
| 1223 | 1243 | case 0xc1d: /* crusnexo */ |
| 1224 | 1244 | case 0xc5d: /* crusnexo */ |
| 1225 | | extra->texwidth = 256; |
| 1245 | extra.texwidth = 256; |
| 1226 | 1246 | break; |
| 1227 | 1247 | |
| 1228 | 1248 | case 0x059: /* crusnexo */ |
| 1229 | 1249 | case 0x0d9: /* crusnexo */ |
| 1230 | 1250 | case 0x119: /* crusnexo: license plates */ |
| 1231 | 1251 | case 0x159: /* crusnexo */ |
| 1232 | | extra->texwidth = 128; |
| 1252 | extra.texwidth = 128; |
| 1233 | 1253 | break; |
| 1234 | 1254 | |
| 1235 | 1255 | case 0x055: /* crusnexo */ |
| 1236 | 1256 | case 0x155: /* crusnexo */ |
| 1237 | | extra->texwidth = 64; |
| 1257 | extra.texwidth = 64; |
| 1238 | 1258 | break; |
| 1239 | 1259 | |
| 1240 | 1260 | default: |
| r249087 | r249088 | |
| 1249 | 1269 | } |
| 1250 | 1270 | } |
| 1251 | 1271 | |
| 1252 | | extra->solidcolor = 0;//m_zeusbase[0x00] & 0x7fff; |
| 1253 | | extra->zoffset = 0;//m_zeusbase[0x7e] >> 16; |
| 1254 | | extra->alpha = 0;//m_zeusbase[0x4e]; |
| 1255 | | extra->transcolor = 0x100;//((databuffer[1] >> 16) & 1) ? 0 : 0x100; |
| 1256 | | extra->texbase = WAVERAM_BLOCK0(zeus_texbase); |
| 1257 | | extra->palbase = waveram0_ptr_from_expanded_addr(m_zeusbase[0x41]); |
| 1272 | extra.solidcolor = 0;//m_zeusbase[0x00] & 0x7fff; |
| 1273 | extra.zoffset = 0;//m_zeusbase[0x7e] >> 16; |
| 1274 | extra.alpha = 0;//m_zeusbase[0x4e]; |
| 1275 | extra.transcolor = 0x100;//((databuffer[1] >> 16) & 1) ? 0 : 0x100; |
| 1276 | extra.texbase = WAVERAM_BLOCK0(zeus_texbase); |
| 1277 | extra.palbase = waveram0_ptr_from_expanded_addr(m_state.m_zeusbase[0x41]); |
| 1258 | 1278 | |
| 1259 | | poly_render_quad_fan(poly, NULL, zeus_cliprect, callback, 4, numverts, &clipvert[0]); |
| 1279 | // Note: Before being converted to the "poly.h" interface, this used to call the polylgcy function |
| 1280 | // poly_render_quad_fan. The behavior seems to be the same as it once was after a few short |
| 1281 | // tests, but the (numverts == 5) statement below may actually be a quad fan instead of a 5-sided |
| 1282 | // polygon. |
| 1283 | if (numverts == 3) |
| 1284 | render_triangle(zeus_cliprect, render_delegate(FUNC(midzeus2_renderer::render_poly_8bit), this), 4, clipvert[0], clipvert[1], clipvert[2]); |
| 1285 | else if (numverts == 4) |
| 1286 | render_polygon<4>(zeus_cliprect, render_delegate(FUNC(midzeus2_renderer::render_poly_8bit), this), 4, clipvert); |
| 1287 | else if (numverts == 5) |
| 1288 | render_polygon<5>(zeus_cliprect, render_delegate(FUNC(midzeus2_renderer::render_poly_8bit), this), 4, clipvert); |
| 1260 | 1289 | } |
| 1261 | 1290 | |
| 1262 | 1291 | |
| r249087 | r249088 | |
| 1267 | 1296 | * |
| 1268 | 1297 | *************************************/ |
| 1269 | 1298 | |
| 1270 | | static void render_poly_8bit(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid) |
| 1299 | void midzeus2_renderer::render_poly_8bit(INT32 scanline, const extent_t& extent, const mz2_poly_extra_data& object, int threadid) |
| 1271 | 1300 | { |
| 1272 | | const mz2_poly_extra_data *extra = (const mz2_poly_extra_data *)extradata; |
| 1273 | | INT32 curz = extent->param[0].start; |
| 1274 | | INT32 curu = extent->param[1].start; |
| 1275 | | INT32 curv = extent->param[2].start; |
| 1276 | | // INT32 curi = extent->param[3].start; |
| 1277 | | INT32 dzdx = extent->param[0].dpdx; |
| 1278 | | INT32 dudx = extent->param[1].dpdx; |
| 1279 | | INT32 dvdx = extent->param[2].dpdx; |
| 1280 | | // INT32 didx = extent->param[3].dpdx; |
| 1281 | | const void *texbase = extra->texbase; |
| 1282 | | const void *palbase = extra->palbase; |
| 1283 | | UINT16 transcolor = extra->transcolor; |
| 1284 | | int texwidth = extra->texwidth; |
| 1301 | INT32 curz = extent.param[0].start; |
| 1302 | INT32 curu = extent.param[1].start; |
| 1303 | INT32 curv = extent.param[2].start; |
| 1304 | // INT32 curi = extent.param[3].start; |
| 1305 | INT32 dzdx = extent.param[0].dpdx; |
| 1306 | INT32 dudx = extent.param[1].dpdx; |
| 1307 | INT32 dvdx = extent.param[2].dpdx; |
| 1308 | // INT32 didx = extent.param[3].dpdx; |
| 1309 | const void *texbase = object.texbase; |
| 1310 | const void *palbase = object.palbase; |
| 1311 | UINT16 transcolor = object.transcolor; |
| 1312 | int texwidth = object.texwidth; |
| 1285 | 1313 | int x; |
| 1286 | 1314 | |
| 1287 | | for (x = extent->startx; x < extent->stopx; x++) |
| 1315 | for (x = extent.startx; x < extent.stopx; x++) |
| 1288 | 1316 | { |
| 1289 | 1317 | UINT16 *depthptr = WAVERAM_PTRDEPTH(zeus_renderbase, scanline, x); |
| 1290 | | INT32 depth = (curz >> 16) + extra->zoffset; |
| 1318 | INT32 depth = (curz >> 16) + object.zoffset; |
| 1291 | 1319 | if (depth > 0x7fff) depth = 0x7fff; |
| 1292 | 1320 | if (depth >= 0 && depth <= *depthptr) |
| 1293 | 1321 | { |