Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/devices/video/poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ class poly_manager
{
BaseType start; // parameter value at start
BaseType dpdx; // dp/dx relative to start
BaseType dpdy; // dp/dy relative to start
};
int16_t startx, stopx; // starting (inclusive)/ending (exclusive) endpoints
std::array<param_t, MaxParams> param; // array of parameter start/delays
Expand Down Expand Up @@ -795,7 +794,6 @@ uint32_t poly_manager<BaseType, ObjectType, MaxParams, Flags>::render_tile(recta
{
extent.param[paramnum].start = v1->p[paramnum] + fullstartx * param_dpdx[paramnum] + fully * param_dpdy[paramnum];
extent.param[paramnum].dpdx = param_dpdx[paramnum];
extent.param[paramnum].dpdy = param_dpdy[paramnum];
}
}
}
Expand Down Expand Up @@ -960,7 +958,6 @@ uint32_t poly_manager<BaseType, ObjectType, MaxParams, Flags>::render_triangle(c
{
extent.param[paramnum].start = param_start[paramnum] + fullstartx * param_dpdx[paramnum] + fully * param_dpdy[paramnum];
extent.param[paramnum].dpdx = param_dpdx[paramnum];
extent.param[paramnum].dpdy = param_dpdy[paramnum];
}
}
}
Expand Down Expand Up @@ -1077,7 +1074,6 @@ uint32_t poly_manager<BaseType, ObjectType, MaxParams, Flags>::render_extents(re
{
extent.param[paramnum].start = srcextent.param[paramnum].start;
extent.param[paramnum].dpdx = srcextent.param[paramnum].dpdx;
extent.param[paramnum].dpdy = srcextent.param[paramnum].dpdy;
}
extent.userdata = srcextent.userdata;

Expand Down Expand Up @@ -1260,7 +1256,6 @@ uint32_t poly_manager<BaseType, ObjectType, MaxParams, Flags>::render_polygon(re

extent.param[paramnum].start = lparam;// - (BaseType(istartx) + 0.5f) * dpdx;
extent.param[paramnum].dpdx = dpdx;
extent.param[paramnum].dpdy = ledge->dpdy[paramnum];
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/mame/sega/model2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
MAME driver by R. Belmont, Olivier Galibert, ElSemi, Angelo Salese and Matthew Daniels.

TODO:
- Mip Mapping still needs to be properly sorted in the renderer;
- outputs and artwork (for gearbox indicators);
- clean-ups;

Expand Down Expand Up @@ -1028,14 +1027,14 @@ void model2_tgp_state::tex1_w(offs_t offset, u32 data)
}
}

u16 model2_state::lumaram_r(offs_t offset)
u8 model2_state::lumaram_r(offs_t offset)
{
return m_lumaram[offset];
}

void model2_state::lumaram_w(offs_t offset, u16 data, u16 mem_mask)
void model2_state::lumaram_w(offs_t offset, u8 data)
{
COMBINE_DATA(&m_lumaram[offset]);
m_lumaram[offset] = data;
}

/* Top Skater reads here and discards the result */
Expand Down Expand Up @@ -1107,8 +1106,6 @@ void model2_state::model2_base_mem(address_map &map)
// format is xGGGGGRRRRRBBBBB (512x400)
map(0x11600000, 0x1167ffff).rw(FUNC(model2_state::fbvram_bankA_r), FUNC(model2_state::fbvram_bankA_w)).flags(i960_cpu_device::BURST); // framebuffer A (last bronx title screen)
map(0x11680000, 0x116fffff).rw(FUNC(model2_state::fbvram_bankB_r), FUNC(model2_state::fbvram_bankB_w)).flags(i960_cpu_device::BURST); // framebuffer B

map(0x12800000, 0x1281ffff).rw(FUNC(model2_state::lumaram_r), FUNC(model2_state::lumaram_w)).umask32(0x0000ffff).flags(i960_cpu_device::BURST); // polygon "luma" RAM
}

/* common map for 5881 protection */
Expand Down Expand Up @@ -1244,8 +1241,11 @@ void model2_tgp_state::model2_tgp_mem(address_map &map)
map(0x00980000, 0x00980003).rw(FUNC(model2_tgp_state::copro_ctl1_r), FUNC(model2_tgp_state::copro_ctl1_w));
map(0x00980008, 0x0098000b).w(FUNC(model2_tgp_state::geo_ctl1_w));

map(0x10800000, 0x10800003).nopr(); // polygon count register

map(0x12000000, 0x121fffff).ram().w(FUNC(model2o_state::tex0_w)).mirror(0x200000).share("textureram0").flags(i960_cpu_device::BURST); // texture RAM 0
map(0x12400000, 0x125fffff).ram().w(FUNC(model2o_state::tex1_w)).mirror(0x200000).share("textureram1").flags(i960_cpu_device::BURST); // texture RAM 1
map(0x12800000, 0x1281ffff).rw(FUNC(model2_tgp_state::lumaram_r), FUNC(model2_tgp_state::lumaram_w)).umask32(0x000000ff).flags(i960_cpu_device::BURST); // polygon "luma" RAM
}

/* original Model 2 overrides */
Expand Down Expand Up @@ -1390,6 +1390,7 @@ void model2b_state::model2b_crx_mem(address_map &map)
map(0x11300000, 0x113fffff).ram().share("textureram1").flags(i960_cpu_device::BURST); // texture RAM 1 (2b/2c)
map(0x11400000, 0x1140ffff).rw(FUNC(model2b_state::lumaram_r), FUNC(model2b_state::lumaram_w)).flags(i960_cpu_device::BURST); // polygon "luma" RAM (2b/2c)
map(0x12800000, 0x1281ffff).rw(FUNC(model2b_state::lumaram_r), FUNC(model2b_state::lumaram_w)).umask32(0x0000ffff).flags(i960_cpu_device::BURST); // polygon "luma" RAM
map(0x11400000, 0x1140ffff).rw(FUNC(model2b_state::lumaram_r), FUNC(model2b_state::lumaram_w)).umask16(0x00ff).flags(i960_cpu_device::BURST); // polygon "luma" RAM (2b/2c)

map(0x01c00000, 0x01c0001f).rw("io", FUNC(sega_315_5649_device::read), FUNC(sega_315_5649_device::write)).umask32(0x00ff00ff);
map(0x01c00040, 0x01c00043).nopw();
Expand Down Expand Up @@ -1426,6 +1427,7 @@ void model2c_state::model2c_crx_mem(address_map &map)
map(0x11200000, 0x113fffff).ram().share("textureram1").flags(i960_cpu_device::BURST); // texture RAM 1 (2b/2c)
map(0x11400000, 0x1140ffff).rw(FUNC(model2c_state::lumaram_r), FUNC(model2c_state::lumaram_w)).flags(i960_cpu_device::BURST); // polygon "luma" RAM (2b/2c)
map(0x12800000, 0x1281ffff).rw(FUNC(model2c_state::lumaram_r), FUNC(model2c_state::lumaram_w)).umask32(0x0000ffff).flags(i960_cpu_device::BURST); // polygon "luma" RAM
map(0x11400000, 0x1140ffff).rw(FUNC(model2c_state::lumaram_r), FUNC(model2c_state::lumaram_w)).umask16(0x00ff).flags(i960_cpu_device::BURST); // polygon "luma" RAM (2b/2c)

map(0x01c00000, 0x01c0001f).rw("io", FUNC(sega_315_5649_device::read), FUNC(sega_315_5649_device::write)).umask32(0x00ff00ff);
map(0x01c80000, 0x01c80001).rw(FUNC(model2c_state::model2_serial_r), FUNC(model2c_state::model2_serial_w)).umask16(0x00ff);
Expand Down
29 changes: 19 additions & 10 deletions src/mame/sega/model2.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class model2_state : public driver_device
required_shared_ptr<u32> m_textureram1;
std::unique_ptr<u16[]> m_palram;
std::unique_ptr<u16[]> m_colorxlat;
std::unique_ptr<u16[]> m_lumaram;
std::unique_ptr<u8[]> m_lumaram;
u8 m_gamma_table[256]{};
std::unique_ptr<model2_renderer> m_poly;

Expand Down Expand Up @@ -204,8 +204,8 @@ class model2_state : public driver_device
void geo_init(memory_region *polygon_rom);
u32 render_mode_r();
void render_mode_w(u32 data);
u16 lumaram_r(offs_t offset);
void lumaram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
u8 lumaram_r(offs_t offset);
void lumaram_w(offs_t offset, u8 data);
u16 fbvram_bankA_r(offs_t offset);
void fbvram_bankA_w(offs_t offset, u16 data, u16 mem_mask = ~0);
u16 fbvram_bankB_r(offs_t offset);
Expand Down Expand Up @@ -618,13 +618,20 @@ struct m2_poly_extra_data
u32 lumabase;
u32 colorbase;
u8 checker;
u32 * texsheet[6];
u32 texwidth[6];
u32 texheight[6];
u32 texx[6];
u32 texy[6];
u32 * texsheet[2];
u32 texwidth;
u32 texheight;
u32 texx;
u32 texy;
u8 texwrapx;
u8 texwrapy;
u8 texmirrorx;
u8 texmirrory;
u8 utex;
u8 utexminlod;
u32 utexx;
u32 utexy;
s32 texlod;
u8 luma;
};

Expand Down Expand Up @@ -689,7 +696,7 @@ class model2_renderer : public poly_manager<float, m2_poly_extra_data, 4>
int16_t m_xoffs = 0, m_yoffs = 0;

template <bool Translucent>
u32 fetch_bilinear_texel(const m2_poly_extra_data& object, const u32 miplevel, const float fu, const float fv);
u32 fetch_bilinear_texel(const m2_poly_extra_data& object, const s32 miplevel, s32 fu, s32 fv);
};

typedef model2_renderer::vertex_t poly_vertex;
Expand Down Expand Up @@ -733,6 +740,7 @@ struct model2_state::triangle
u16 z = 0;
u16 texheader[4] = { 0, 0, 0, 0 };
u8 luma = 0;
s32 texlod = 0;
int16_t viewport[4] = { 0, 0, 0, 0 };
int16_t center[2] = { 0, 0 };
u8 window = 0;
Expand All @@ -750,6 +758,7 @@ struct model2_state::quad_m2
u16 z = 0;
u16 texheader[4] = { 0, 0, 0, 0 };
u8 luma = 0;
s32 texlod = 0;
};

/*******************************************
Expand Down Expand Up @@ -789,7 +798,7 @@ struct model2_state::raster_state
u16 min_z = 0; // Minimum sortable Z value
u16 max_z = 0; // Maximum sortable Z value
u16 texture_ram[0x10000]; // Texture RAM pointer
u8 log_ram[0x40000]; // Log RAM pointer
u8 log_ram[0x8000]; // Log RAM pointer
u8 cur_window = 0; // Current window
plane clip_plane[4][4]; // Polygon clipping planes
};
Expand Down
76 changes: 35 additions & 41 deletions src/mame/sega/model2_v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,12 @@

- Texturing code could use a real good speed optimization.
- The U and V coordinates provided by the game are in 13.3 fixed point format.
- The luma/texel combination algorithm is not known. There are currently some small color glitches here and
there, and this might be the culprit.
- The log tables and distance coefficients are used to calculate the number of texels per world unit that need to
be used to render a texture. Textures can also be provided with smaller levels of details and a LOD bit selector
in the texture header tells the rasterizer which texture map to use. The rasterizer then can average two texture
maps to do mip mapping. More information can be found on the 2B manual, on the 'Texturing' and 'Data Format' chapters.
This is currently unemulated. We always use the texture data from the bigger texture map.
- The rasterizer supports up to 128x128 'microtex' textures, which are supposed to be higher resolution textures used
to display more detail when a texture is real close to the viewer. This is currently unemulated.
- The rasterizer supports 128x128 'microtextures' which are typically used to add more details to a texture when it is
close enough to the viewer.

*********************************************************************************************************************************/

Expand Down Expand Up @@ -230,8 +227,8 @@ static int32_t clip_polygon(poly_vertex *v, int32_t num_vertices, poly_vertex *v
out[outcount].x = cur->x + ((v[nextvert].x - cur->x) * scale);
out[outcount].y = cur->y + ((v[nextvert].y - cur->y) * scale);
out[outcount].pz = cur->pz + ((v[nextvert].pz - cur->pz) * scale);
out[outcount].pu = (u16)((float)cur->pu + (((float)v[nextvert].pu - (float)cur->pu) * scale));
out[outcount].pv = (u16)((float)cur->pv + (((float)v[nextvert].pv - (float)cur->pv) * scale));
out[outcount].pu = cur->pu + ((v[nextvert].pu - cur->pu) * scale);
out[outcount].pv = cur->pv + ((v[nextvert].pv - cur->pv) * scale);
outcount++;
}

Expand Down Expand Up @@ -412,6 +409,10 @@ void model2_state::model2_3d_process_quad( raster_state *raster, u32 attr )
/* set the luma value of this quad */
object.luma = (raster->command_buffer[9] >> 15) & 0xff;

/* set the texture LOD of this quad */
object.texlod = ((raster->command_buffer[10] >> 8) & 0x7f80) - 0x3f80;
object.texlod += raster->log_ram[raster->command_buffer[10] & 0x7fff];

/* determine whether we can cull this quad */
cull = check_culling(raster,attr,min_z,max_z);

Expand Down Expand Up @@ -488,6 +489,7 @@ void model2_state::model2_3d_process_quad( raster_state *raster, u32 attr )
tri->texheader[2] = object.texheader[2];
tri->texheader[3] = object.texheader[3];
tri->luma = object.luma;
tri->texlod = object.texlod;

/* set the viewport */
tri->viewport[0] = raster->viewport[0];
Expand Down Expand Up @@ -638,6 +640,10 @@ void model2_state::model2_3d_process_triangle( raster_state *raster, u32 attr )
/* set the luma value of this triangle */
object.luma = (raster->command_buffer[9] >> 15) & 0xff;

/* set the texture LOD of this triangle */
object.texlod = ((raster->command_buffer[10] >> 8) & 0x7f80) - 0x3f80;
object.texlod += raster->log_ram[raster->command_buffer[10] & 0x7fff];

/* determine whether we can cull this triangle */
cull = check_culling(raster,attr,min_z,max_z);

Expand Down Expand Up @@ -715,6 +721,7 @@ void model2_state::model2_3d_process_triangle( raster_state *raster, u32 attr )
tri->texheader[2] = object.texheader[2];
tri->texheader[3] = object.texheader[3];
tri->luma = object.luma;
tri->texlod = object.texlod;

/* set the viewport */
tri->viewport[0] = raster->viewport[0];
Expand Down Expand Up @@ -806,43 +813,29 @@ void model2_renderer::model2_3d_render(triangle *tri, const rectangle &cliprect)
extra.lumabase = (tri->texheader[1] & 0xff) << 7;
extra.colorbase = (tri->texheader[3] >> 6) & 0x3ff;
extra.luma = tri->luma;
extra.texlod = tri->texlod;

if (renderer & 2)
{
extra.texmirrorx = (tri->texheader[0] >> 8) & 1;
extra.texmirrory = (tri->texheader[0] >> 9) & 1;

u32* sheet = (tri->texheader[2] & 0x1000) ? m_state.m_textureram1 : m_state.m_textureram0;
u32 width = 32 << ((tri->texheader[0] >> 0) & 0x7);
u32 height = 32 << ((tri->texheader[0] >> 3) & 0x7);
u32 posx = 32 * ( (tri->texheader[2] >> 0) & 0x3f );
u32 posy = 32 * ( (tri->texheader[2] >> 6) & 0x1f );

// 6 mips levels
// each mip level has half width and half height of the level above
// mips are located recursively in the bottom right corner of 2048x1024
// each level has flipped ram banks compared to the level above
for (u32 mip = 0; mip < 6; mip++)
{
extra.texsheet[mip] = sheet;
extra.texwidth[mip] = width;
extra.texheight[mip] = height;
extra.texx[mip] = posx;
extra.texy[mip] = posy;

width /= 2;
height /= 2;
posx = 2048 - (2048 - posx) / 2;
posy = 1024 - (1024 - posy) / 2;
if (sheet == m_state.m_textureram0)
{
sheet = m_state.m_textureram1;
}
else
{
sheet = m_state.m_textureram0;
}
}
// disable smooth wrapping if mirroring is enabled
extra.texwrapx = (tri->texheader[0] >> 6) & 1 & ~extra.texmirrorx;
extra.texwrapy = (tri->texheader[0] >> 7) & 1 & ~extra.texmirrory;

extra.texsheet[0] = (tri->texheader[2] & 0x1000) ? m_state.m_textureram1 : m_state.m_textureram0;
extra.texsheet[1] = (tri->texheader[2] & 0x1000) ? m_state.m_textureram0 : m_state.m_textureram1;
extra.texwidth = 32 << ((tri->texheader[0] >> 0) & 0x7);
extra.texheight = 32 << ((tri->texheader[0] >> 3) & 0x7);
extra.texx = 32 * ((tri->texheader[2] >> 0) & 0x3f);
extra.texy = 32 * ((tri->texheader[2] >> 6) & 0x1f);

// microtexture parameters
extra.utex = (tri->texheader[0] >> 12) & 1;
extra.utexminlod = (tri->texheader[0] >> 10) & 3;
extra.utexx = ((tri->texheader[2] >> 13) & 1) * 128;
extra.utexy = ((tri->texheader[2] >> 14) & 3) * 128;

tri->v[0].pz = 1.0f / (tri->v[0].pz + std::numeric_limits<float>::min());
tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * (1.0f / 8.0f);
Expand Down Expand Up @@ -1155,7 +1148,7 @@ void model2_state::model2_3d_push( raster_state *raster, u32 input )
if ( address & 0x800000 )
raster->texture_ram[address & 0xffff] = raster->command_buffer[2];
else
raster->log_ram[address & 0xffff] = raster->command_buffer[2];
raster->log_ram[address & 0x7fff] = raster->command_buffer[2];

/* increment the address and decrease the count */
raster->command_buffer[0]++;
Expand Down Expand Up @@ -2612,7 +2605,7 @@ void model2_state::video_start()
/* init various video-related pointers */
m_palram = make_unique_clear<u16[]>(0x4000/2);
m_colorxlat = make_unique_clear<u16[]>(0xc000/2);
m_lumaram = make_unique_clear<u16[]>(0x10000/2);
m_lumaram = make_unique_clear<u8[]>(0x8000);
m_fbvramA = make_unique_clear<u16[]>(0x80000/2);
m_fbvramB = make_unique_clear<u16[]>(0x80000/2);

Expand All @@ -2631,7 +2624,7 @@ void model2_state::video_start()
save_item(NAME(m_render_mode));
save_pointer(NAME(m_palram), 0x4000/2);
save_pointer(NAME(m_colorxlat), 0xc000/2);
save_pointer(NAME(m_lumaram), 0x10000/2);
save_pointer(NAME(m_lumaram), 0x8000);
save_pointer(NAME(m_gamma_table), 256);
}

Expand Down Expand Up @@ -2689,6 +2682,7 @@ void model2_state::tri_list_dump(FILE *dst)
fprintf( dst, "texheader - 2: %04x\n", m_raster->tri_list[i].texheader[2] );
fprintf( dst, "texheader - 3: %04x\n", m_raster->tri_list[i].texheader[3] );
fprintf( dst, "luma: %02x\n", m_raster->tri_list[i].luma );
fprintf( dst, "texlod: %08x\n", m_raster->tri_list[i].texlod );
fprintf( dst, "vp.sx: %04x\n", m_raster->tri_list[i].viewport[0] );
fprintf( dst, "vp.sy: %04x\n", m_raster->tri_list[i].viewport[1] );
fprintf( dst, "vp.ex: %04x\n", m_raster->tri_list[i].viewport[2] );
Expand Down
Loading
Loading