trunk/src/mame/drivers/namcos23.c
| r249082 | r249083 | |
| 1234 | 1234 | |
| 1235 | 1235 | #include "emu.h" |
| 1236 | 1236 | #include <float.h> |
| 1237 | | #include "video/polylgcy.h" |
| 1237 | #include "video/poly.h" |
| 1238 | 1238 | #include "cpu/mips/mips3.h" |
| 1239 | 1239 | #include "cpu/h8/h83002.h" |
| 1240 | 1240 | #include "cpu/h8/h83337.h" |
| r249082 | r249083 | |
| 1264 | 1264 | |
| 1265 | 1265 | enum { MODEL, FLUSH }; |
| 1266 | 1266 | |
| 1267 | enum { RENDER_MAX_ENTRIES = 1000, POLY_MAX_ENTRIES = 10000 }; |
| 1268 | |
| 1269 | class namcos23_state; |
| 1270 | struct namcos23_render_data; |
| 1271 | |
| 1272 | class namcos23_renderer : public poly_manager<float, namcos23_render_data, 4, POLY_MAX_ENTRIES> |
| 1273 | { |
| 1274 | public: |
| 1275 | namcos23_renderer(namcos23_state &state); |
| 1276 | |
| 1277 | void render_flush(bitmap_rgb32& bitmap); |
| 1278 | void render_scanline(INT32 scanline, const extent_t& extent, const namcos23_render_data& object, int threadid); |
| 1279 | |
| 1280 | private: |
| 1281 | namcos23_state& m_state; |
| 1282 | bitmap_rgb32 m_bitmap; |
| 1283 | }; |
| 1284 | |
| 1285 | typedef namcos23_renderer::vertex_t poly_vertex; |
| 1286 | |
| 1287 | |
| 1267 | 1288 | struct namcos23_render_entry |
| 1268 | 1289 | { |
| 1269 | 1290 | int type; |
| r249082 | r249083 | |
| 1296 | 1317 | poly_vertex pv[16]; |
| 1297 | 1318 | }; |
| 1298 | 1319 | |
| 1299 | | enum { RENDER_MAX_ENTRIES = 1000, POLY_MAX_ENTRIES = 10000 }; |
| 1300 | | |
| 1301 | | |
| 1302 | 1320 | struct c417_t |
| 1303 | 1321 | { |
| 1304 | 1322 | UINT16 ram[0x10000]; |
| r249082 | r249083 | |
| 1344 | 1362 | |
| 1345 | 1363 | struct render_t |
| 1346 | 1364 | { |
| 1347 | | legacy_poly_manager *polymgr; |
| 1365 | namcos23_renderer *polymgr; |
| 1348 | 1366 | int cur; |
| 1349 | 1367 | int poly_count; |
| 1350 | 1368 | int count[2]; |
| r249082 | r249083 | |
| 1540 | 1558 | void render_apply_matrot(INT32 xi, INT32 yi, INT32 zi, const namcos23_render_entry *re, INT32 &x, INT32 &y, INT32 &z); |
| 1541 | 1559 | void render_project(poly_vertex &pv); |
| 1542 | 1560 | void render_one_model(const namcos23_render_entry *re); |
| 1543 | | void render_flush(bitmap_rgb32 &bitmap); |
| 1544 | 1561 | void render_run(bitmap_rgb32 &bitmap); |
| 1545 | 1562 | }; |
| 1546 | 1563 | |
| r249082 | r249083 | |
| 1567 | 1584 | |
| 1568 | 1585 | ***************************************************************************/ |
| 1569 | 1586 | |
| 1587 | namcos23_renderer::namcos23_renderer(namcos23_state &state) |
| 1588 | : poly_manager<float, namcos23_render_data, 4, POLY_MAX_ENTRIES>(state.machine()), |
| 1589 | m_state(state), |
| 1590 | m_bitmap(state.m_screen->width(), state.m_screen->height()) |
| 1591 | {} |
| 1592 | |
| 1570 | 1593 | // 3D hardware, to throw at least in part in video/namcos23.c |
| 1571 | 1594 | |
| 1572 | 1595 | inline INT32 namcos23_state::u32_to_s24(UINT32 v) |
| r249082 | r249083 | |
| 1857 | 1880 | |
| 1858 | 1881 | |
| 1859 | 1882 | |
| 1860 | | static void render_scanline(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid) |
| 1883 | void namcos23_renderer::render_scanline(INT32 scanline, const extent_t& extent, const namcos23_render_data& object, int threadid) |
| 1861 | 1884 | { |
| 1862 | | const namcos23_render_data *rd = (const namcos23_render_data *)extradata; |
| 1885 | const namcos23_render_data& rd = object; |
| 1863 | 1886 | |
| 1864 | | float w = extent->param[0].start; |
| 1865 | | float u = extent->param[1].start; |
| 1866 | | float v = extent->param[2].start; |
| 1867 | | float l = extent->param[3].start; |
| 1868 | | float dw = extent->param[0].dpdx; |
| 1869 | | float du = extent->param[1].dpdx; |
| 1870 | | float dv = extent->param[2].dpdx; |
| 1871 | | float dl = extent->param[3].dpdx; |
| 1872 | | bitmap_rgb32 *bitmap = (bitmap_rgb32 *)dest; |
| 1873 | | UINT32 *img = &bitmap->pix32(scanline, extent->startx); |
| 1887 | float w = extent.param[0].start; |
| 1888 | float u = extent.param[1].start; |
| 1889 | float v = extent.param[2].start; |
| 1890 | float l = extent.param[3].start; |
| 1891 | float dw = extent.param[0].dpdx; |
| 1892 | float du = extent.param[1].dpdx; |
| 1893 | float dv = extent.param[2].dpdx; |
| 1894 | float dl = extent.param[3].dpdx; |
| 1895 | UINT32 *img = &m_bitmap.pix32(scanline, extent.startx); |
| 1874 | 1896 | |
| 1875 | | for(int x = extent->startx; x < extent->stopx; x++) { |
| 1897 | for(int x = extent.startx; x < extent.stopx; x++) { |
| 1876 | 1898 | float z = w ? 1/w : 0; |
| 1877 | | UINT32 pcol = rd->texture_lookup(*rd->machine, rd->pens, u*z, v*z); |
| 1899 | UINT32 pcol = rd.texture_lookup(*rd.machine, rd.pens, u*z, v*z); |
| 1878 | 1900 | float ll = l*z; |
| 1879 | 1901 | *img = (light(pcol >> 16, ll) << 16) | (light(pcol >> 8, ll) << 8) | light(pcol, ll); |
| 1880 | 1902 | |
| r249082 | r249083 | |
| 2013 | 2035 | |
| 2014 | 2036 | namcos23_poly_entry *p = render.polys + render.poly_count; |
| 2015 | 2037 | |
| 2016 | | p->vertex_count = poly_zclip_if_less(ne, pv, p->pv, 4, 0.001f); |
| 2038 | p->vertex_count = render.polymgr->zclip_if_less(ne, pv, p->pv, 4, 0.001f); |
| 2017 | 2039 | |
| 2018 | 2040 | if(p->vertex_count >= 3) { |
| 2019 | 2041 | for(int i=0; i<p->vertex_count; i++) { |
| r249082 | r249083 | |
| 2047 | 2069 | return p1->zkey < p2->zkey ? 1 : p1->zkey > p2->zkey ? -1 : 0; |
| 2048 | 2070 | } |
| 2049 | 2071 | |
| 2050 | | void namcos23_state::render_flush(bitmap_rgb32 &bitmap) |
| 2072 | void namcos23_renderer::render_flush(bitmap_rgb32& bitmap) |
| 2051 | 2073 | { |
| 2052 | | render_t &render = m_render; |
| 2074 | render_t &render = m_state.m_render; |
| 2053 | 2075 | |
| 2054 | 2076 | if(!render.poly_count) |
| 2055 | 2077 | return; |
| r249082 | r249083 | |
| 2063 | 2085 | |
| 2064 | 2086 | for(int i=0; i<render.poly_count; i++) { |
| 2065 | 2087 | const namcos23_poly_entry *p = render.poly_order[i]; |
| 2066 | | namcos23_render_data *rd = (namcos23_render_data *)poly_get_extra_data(render.polymgr); |
| 2067 | | *rd = p->rd; |
| 2068 | | poly_render_triangle_fan(render.polymgr, &bitmap, scissor, render_scanline, 4, p->vertex_count, p->pv); |
| 2088 | namcos23_render_data& extra = render.polymgr->object_data_alloc(); |
| 2089 | extra = p->rd; |
| 2090 | |
| 2091 | if (p->vertex_count == 3) |
| 2092 | render_triangle(scissor, render_delegate(FUNC(namcos23_renderer::render_scanline), this), 4, p->pv[0], p->pv[1], p->pv[2]); |
| 2093 | else if (p->vertex_count == 4) |
| 2094 | render_polygon<4>(scissor, render_delegate(FUNC(namcos23_renderer::render_scanline), this), 4, p->pv); |
| 2095 | else if (p->vertex_count == 5) |
| 2096 | render_polygon<5>(scissor, render_delegate(FUNC(namcos23_renderer::render_scanline), this), 4, p->pv); |
| 2069 | 2097 | } |
| 2070 | 2098 | render.poly_count = 0; |
| 2099 | |
| 2100 | copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, scissor); |
| 2071 | 2101 | } |
| 2072 | 2102 | |
| 2073 | 2103 | void namcos23_state::render_run(bitmap_rgb32 &bitmap) |
| r249082 | r249083 | |
| 2082 | 2112 | render_one_model(re); |
| 2083 | 2113 | break; |
| 2084 | 2114 | case FLUSH: |
| 2085 | | render_flush(bitmap); |
| 2115 | render.polymgr->render_flush(bitmap); |
| 2086 | 2116 | break; |
| 2087 | 2117 | } |
| 2088 | 2118 | re++; |
| 2089 | 2119 | } |
| 2090 | | render_flush(bitmap); |
| 2091 | | |
| 2092 | | poly_wait(render.polymgr, "render_run"); |
| 2120 | render.polymgr->render_flush(bitmap); |
| 2121 | render.polymgr->wait(); |
| 2093 | 2122 | } |
| 2094 | 2123 | |
| 2095 | 2124 | |
| r249082 | r249083 | |
| 2161 | 2190 | m_bgtilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(namcos23_state::TextTilemapGetInfo),this), TILEMAP_SCAN_ROWS, 16, 16, 64, 64); |
| 2162 | 2191 | m_bgtilemap->set_transparent_pen(0xf); |
| 2163 | 2192 | m_bgtilemap->set_scrolldx(860, 860); |
| 2164 | | m_render.polymgr = poly_alloc(machine(), 10000, sizeof(namcos23_render_data), 0); |
| 2193 | m_render.polymgr = auto_alloc(machine(), namcos23_renderer(*this)); |
| 2165 | 2194 | } |
| 2166 | 2195 | |
| 2167 | 2196 | |