368
365
float min_z, max_z;
370
367
/* extract P0(n-1) */
371
object.v[1].x = u2f( raster.command_buffer[2] << 8 );
372
object.v[1].y = u2f( raster.command_buffer[3] << 8 );
373
object.v[1].pz = u2f( raster.command_buffer[4] << 8 );
368
object.v[1].x = u2f( raster->command_buffer[2] << 8 );
369
object.v[1].y = u2f( raster->command_buffer[3] << 8 );
370
object.v[1].pz = u2f( raster->command_buffer[4] << 8 );
375
372
/* extract P1(n-1) */
376
object.v[0].x = u2f( raster.command_buffer[5] << 8 );
377
object.v[0].y = u2f( raster.command_buffer[6] << 8 );
378
object.v[0].pz = u2f( raster.command_buffer[7] << 8 );
373
object.v[0].x = u2f( raster->command_buffer[5] << 8 );
374
object.v[0].y = u2f( raster->command_buffer[6] << 8 );
375
object.v[0].pz = u2f( raster->command_buffer[7] << 8 );
380
377
/* extract P0(n) */
381
object.v[2].x = u2f( raster.command_buffer[11] << 8 );
382
object.v[2].y = u2f( raster.command_buffer[12] << 8 );
383
object.v[2].pz = u2f( raster.command_buffer[13] << 8 );
378
object.v[2].x = u2f( raster->command_buffer[11] << 8 );
379
object.v[2].y = u2f( raster->command_buffer[12] << 8 );
380
object.v[2].pz = u2f( raster->command_buffer[13] << 8 );
385
382
/* extract P1(n) */
386
object.v[3].x = u2f( raster.command_buffer[14] << 8 );
387
object.v[3].y = u2f( raster.command_buffer[15] << 8 );
388
object.v[3].pz = u2f( raster.command_buffer[16] << 8 );
383
object.v[3].x = u2f( raster->command_buffer[14] << 8 );
384
object.v[3].y = u2f( raster->command_buffer[15] << 8 );
385
object.v[3].pz = u2f( raster->command_buffer[16] << 8 );
390
387
/* always calculate the min z and max z value */
391
388
min_z = object.v[0].pz;
608
605
float min_z, max_z;
610
607
/* extract P0(n-1) */
611
object.v[1].x = u2f( raster.command_buffer[2] << 8 );
612
object.v[1].y = u2f( raster.command_buffer[3] << 8 );
613
object.v[1].pz = u2f( raster.command_buffer[4] << 8 );
608
object.v[1].x = u2f( raster->command_buffer[2] << 8 );
609
object.v[1].y = u2f( raster->command_buffer[3] << 8 );
610
object.v[1].pz = u2f( raster->command_buffer[4] << 8 );
615
612
/* extract P1(n-1) */
616
object.v[0].x = u2f( raster.command_buffer[5] << 8 );
617
object.v[0].y = u2f( raster.command_buffer[6] << 8 );
618
object.v[0].pz = u2f( raster.command_buffer[7] << 8 );
613
object.v[0].x = u2f( raster->command_buffer[5] << 8 );
614
object.v[0].y = u2f( raster->command_buffer[6] << 8 );
615
object.v[0].pz = u2f( raster->command_buffer[7] << 8 );
620
617
/* extract P0(n) */
621
object.v[2].x = u2f( raster.command_buffer[11] << 8 );
622
object.v[2].y = u2f( raster.command_buffer[12] << 8 );
623
object.v[2].pz = u2f( raster.command_buffer[13] << 8 );
618
object.v[2].x = u2f( raster->command_buffer[11] << 8 );
619
object.v[2].y = u2f( raster->command_buffer[12] << 8 );
620
object.v[2].pz = u2f( raster->command_buffer[13] << 8 );
625
622
/* for triangles, the rope of P1(n) is achieved by P0(n-1) (linktype 3) */
626
raster.command_buffer[14] = raster.command_buffer[11];
627
raster.command_buffer[15] = raster.command_buffer[12];
628
raster.command_buffer[16] = raster.command_buffer[13];
623
raster->command_buffer[14] = raster->command_buffer[11];
624
raster->command_buffer[15] = raster->command_buffer[12];
625
raster->command_buffer[16] = raster->command_buffer[13];
630
627
/* always calculate the min z and max z values */
631
628
min_z = object.v[0].pz;
1041
for( i = 0; i < raster.tri_list_index; i++ )
1043
for( i = 0; i < raster->tri_list_index; i++ )
1044
1046
fprintf( f, "index: %d\n", i );
1045
fprintf( f, "v0.x = %f, v0.y = %f, v0.z = %f\n", raster.tri_list[i].v[0].x, raster.tri_list[i].v[0].y, raster.tri_list[i].v[0].pz );
1046
fprintf( f, "v1.x = %f, v1.y = %f, v1.z = %f\n", raster.tri_list[i].v[1].x, raster.tri_list[i].v[1].y, raster.tri_list[i].v[1].pz );
1047
fprintf( f, "v2.x = %f, v2.y = %f, v2.z = %f\n", raster.tri_list[i].v[2].x, raster.tri_list[i].v[2].y, raster.tri_list[i].v[2].pz );
1047
fprintf( f, "v0.x = %f, v0.y = %f, v0.z = %f\n", raster->tri_list[i].v[0].x, raster->tri_list[i].v[0].y, raster->tri_list[i].v[0].pz );
1048
fprintf( f, "v1.x = %f, v1.y = %f, v1.z = %f\n", raster->tri_list[i].v[1].x, raster->tri_list[i].v[1].y, raster->tri_list[i].v[1].pz );
1049
fprintf( f, "v2.x = %f, v2.y = %f, v2.z = %f\n", raster->tri_list[i].v[2].x, raster->tri_list[i].v[2].y, raster->tri_list[i].v[2].pz );
1049
fprintf( f, "tri z: %04x\n", raster.tri_list[i].pz );
1050
fprintf( f, "texheader - 0: %04x\n", raster.tri_list[i].texheader[0] );
1051
fprintf( f, "texheader - 1: %04x\n", raster.tri_list[i].texheader[1] );
1052
fprintf( f, "texheader - 2: %04x\n", raster.tri_list[i].texheader[2] );
1053
fprintf( f, "texheader - 3: %04x\n", raster.tri_list[i].texheader[3] );
1054
fprintf( f, "luma: %02x\n", raster.tri_list[i].luma );
1055
fprintf( f, "vp.sx: %04x\n", raster.tri_list[i].viewport[0] );
1056
fprintf( f, "vp.sy: %04x\n", raster.tri_list[i].viewport[1] );
1057
fprintf( f, "vp.ex: %04x\n", raster.tri_list[i].viewport[2] );
1058
fprintf( f, "vp.ey: %04x\n", raster.tri_list[i].viewport[3] );
1059
fprintf( f, "vp.swx: %04x\n", raster.tri_list[i].center[0] );
1060
fprintf( f, "vp.swy: %04x\n", raster.tri_list[i].center[1] );
1051
fprintf( f, "tri z: %04x\n", raster->tri_list[i].pz );
1052
fprintf( f, "texheader - 0: %04x\n", raster->tri_list[i].texheader[0] );
1053
fprintf( f, "texheader - 1: %04x\n", raster->tri_list[i].texheader[1] );
1054
fprintf( f, "texheader - 2: %04x\n", raster->tri_list[i].texheader[2] );
1055
fprintf( f, "texheader - 3: %04x\n", raster->tri_list[i].texheader[3] );
1056
fprintf( f, "luma: %02x\n", raster->tri_list[i].luma );
1057
fprintf( f, "vp.sx: %04x\n", raster->tri_list[i].viewport[0] );
1058
fprintf( f, "vp.sy: %04x\n", raster->tri_list[i].viewport[1] );
1059
fprintf( f, "vp.ex: %04x\n", raster->tri_list[i].viewport[2] );
1060
fprintf( f, "vp.ey: %04x\n", raster->tri_list[i].viewport[3] );
1061
fprintf( f, "vp.swx: %04x\n", raster->tri_list[i].center[0] );
1062
fprintf( f, "vp.swy: %04x\n", raster->tri_list[i].center[1] );
1061
1063
fprintf( f, "\n---\n\n" );
1064
fprintf( f, "min_z = %04x, max_z = %04x\n", raster.min_z, raster.max_z );
1066
fprintf( f, "min_z = %04x, max_z = %04x\n", raster->min_z, raster->max_z );
1071
1073
/* go through the Z levels, and render each bucket */
1072
for( z = raster.max_z; z >= raster.min_z; z-- )
1074
for( z = raster->max_z; z >= raster->min_z; z-- )
1074
1076
/* see if we have items at this z level */
1075
if ( raster.tri_sorted_list[z] != NULL )
1077
if ( raster->tri_sorted_list[z] != NULL )
1077
1079
/* get a pointer to the first triangle */
1078
triangle *tri = raster.tri_sorted_list[z];
1080
triangle *tri = raster->tri_sorted_list[z];
1080
1082
/* and loop clipping and rendering each triangle */
1081
1083
while( tri != NULL )
1083
1085
/* project and render */
1084
1086
model2_3d_project( tri );
1085
model2_3d_render( bitmap, tri, cliprect );
1087
model2_3d_render( state, bitmap, tri, cliprect );
1087
1089
tri = (triangle *)tri->next;
1091
poly_wait(poly, "End of frame");
1093
poly_wait(state->m_poly, "End of frame");
1094
1096
/* 3D Rasterizer main data input port */
1095
static void model2_3d_push( UINT32 input )
1097
static void model2_3d_push( raster_state *raster, UINT32 input )
1097
1099
/* see if we have a command in progress */
1098
if ( raster.cur_command != 0 )
1100
if ( raster->cur_command != 0 )
1100
raster.command_buffer[raster.command_index++] = input;
1102
raster->command_buffer[raster->command_index++] = input;
1102
switch( raster.cur_command )
1104
switch( raster->cur_command )
1104
1106
case 0x00: /* NOP */
1157
1159
/* make sure we have all the data */
1158
if ( raster.command_index < 6 )
1160
if ( raster->command_index < 6 )
1161
1163
/* coordinates are 12 bit signed */
1163
1165
/* extract the viewport start x */
1164
raster.viewport[0] = (raster.command_buffer[0] >> 12) & 0xFFF;
1166
raster->viewport[0] = (raster->command_buffer[0] >> 12) & 0xFFF;
1166
if ( raster.viewport[0] & 0x800 )
1167
raster.viewport[0] = -( 0x800 - (raster.viewport[0] & 0x7FF) );
1168
if ( raster->viewport[0] & 0x800 )
1169
raster->viewport[0] = -( 0x800 - (raster->viewport[0] & 0x7FF) );
1169
1171
/* extract the viewport start y */
1170
raster.viewport[1] = raster.command_buffer[0] & 0xFFF;
1172
raster->viewport[1] = raster->command_buffer[0] & 0xFFF;
1172
if ( raster.viewport[1] & 0x800 )
1173
raster.viewport[1] = -( 0x800 - (raster.viewport[1] & 0x7FF) );
1174
if ( raster->viewport[1] & 0x800 )
1175
raster->viewport[1] = -( 0x800 - (raster->viewport[1] & 0x7FF) );
1175
1177
/* extract the viewport end x */
1176
raster.viewport[2] = (raster.command_buffer[1] >> 12) & 0xFFF;
1178
raster->viewport[2] = (raster->command_buffer[1] >> 12) & 0xFFF;
1178
if ( raster.viewport[2] & 0x800 )
1179
raster.viewport[2] = -( 0x800 - (raster.viewport[2] & 0x7FF) );
1180
if ( raster->viewport[2] & 0x800 )
1181
raster->viewport[2] = -( 0x800 - (raster->viewport[2] & 0x7FF) );
1181
1183
/* extract the viewport end y */
1182
raster.viewport[3] = raster.command_buffer[1] & 0xFFF;
1184
raster->viewport[3] = raster->command_buffer[1] & 0xFFF;
1184
if ( raster.viewport[3] & 0x800 )
1185
raster.viewport[3] = -( 0x800 - (raster.viewport[3] & 0x7FF) );
1186
if ( raster->viewport[3] & 0x800 )
1187
raster->viewport[3] = -( 0x800 - (raster->viewport[3] & 0x7FF) );
1187
1189
/* extract the centers */
1188
1190
for( i = 0; i < 4; i++ )
1191
raster.center[i][0] = (raster.command_buffer[2+i] >> 12) & 0xFFF;
1193
raster->center[i][0] = (raster->command_buffer[2+i] >> 12) & 0xFFF;
1193
if ( raster.center[i][0] & 0x800 )
1194
raster.center[i][0] = -( 0x800 - (raster.center[i][0] & 0x7FF) );
1195
if ( raster->center[i][0] & 0x800 )
1196
raster->center[i][0] = -( 0x800 - (raster->center[i][0] & 0x7FF) );
1197
raster.center[i][1] = raster.command_buffer[2+i] & 0xFFF;
1199
raster->center[i][1] = raster->command_buffer[2+i] & 0xFFF;
1199
if ( raster.center[i][1] & 0x800 )
1200
raster.center[i][1] = -( 0x800 - (raster.center[i][1] & 0x7FF) );
1201
if ( raster->center[i][1] & 0x800 )
1202
raster->center[i][1] = -( 0x800 - (raster->center[i][1] & 0x7FF) );
1203
1205
/* done with this command */
1204
raster.cur_command = 0;
1206
raster->cur_command = 0;
1208
1210
case 0x04: /* Texture/Log Data write */
1210
1212
/* make sure we have enough data */
1211
if ( raster.command_index < 2 )
1213
if ( raster->command_index < 2 )
1214
1216
/* see if the count is non-zero */
1215
if ( raster.command_buffer[1] > 0 )
1217
if ( raster->command_buffer[1] > 0 )
1217
1219
/* see if we have data available */
1218
if ( raster.command_index >= 3 )
1220
if ( raster->command_index >= 3 )
1220
1222
/* get the address */
1221
UINT32 address = raster.command_buffer[0];
1223
UINT32 address = raster->command_buffer[0];
1223
1225
/* do the write */
1224
1226
if ( address & 0x800000 )
1225
raster.texture_ram[address&0xFFFF] = raster.command_buffer[2];
1227
raster->texture_ram[address&0xFFFF] = raster->command_buffer[2];
1227
raster.log_ram[address&0xFFFF] = raster.command_buffer[2];
1229
raster->log_ram[address&0xFFFF] = raster->command_buffer[2];
1229
1231
/* increment the address and decrease the count */
1230
raster.command_buffer[0]++;
1231
raster.command_buffer[1]--;
1232
raster->command_buffer[0]++;
1233
raster->command_buffer[1]--;
1233
1235
/* decrease the index, so we keep placing data in the same slot */
1234
raster.command_index--;
1236
raster->command_index--;
1238
1240
/* see if we're done with this command */
1239
if ( raster.command_buffer[1] == 0 )
1240
raster.cur_command = 0;
1241
if ( raster->command_buffer[1] == 0 )
1242
raster->cur_command = 0;
1244
1246
case 0x08: /* ZSort mode */
1246
1248
/* save the zsort mode value */
1247
raster.z_adjust = u2f( raster.command_buffer[0] << 8 );
1249
raster->z_adjust = u2f( raster->command_buffer[0] << 8 );
1249
1251
/* done with this command */
1250
raster.cur_command = 0;
1252
raster->cur_command = 0;
1256
fatalerror( "SEGA 3D: Unknown rasterizer command %08x\n", raster.cur_command );
1258
fatalerror( "SEGA 3D: Unknown rasterizer command %08x\n", raster->cur_command );
1547
1551
point.pz = u2f( *input++ );
1549
1553
/* transform with the current matrix */
1550
transform_point( &point, geo.matrix );
1554
transform_point( &point, geo->matrix );
1552
1556
/* calculate the dot product of the normal and the light vector */
1553
dotl = dot_product( &normal, &geo.light );
1557
dotl = dot_product( &normal, &geo->light );
1555
1559
/* calculate the dot product of the normal and the point */
1556
1560
dotp = dot_product( &normal, &point );
1558
1562
/* apply focus */
1559
point.x *= geo.focus.x;
1560
point.y *= geo.focus.y;
1563
point.x *= geo->focus.x;
1564
point.y *= geo->focus.y;
1562
1566
/* determine wether this is the front or the back of the polygon */
1563
1567
face = 0x100; /* rear */
1564
1568
if ( dotp >= 0 ) face = 0; /* front */
1566
1570
/* get the texture parameters */
1567
texparam = &geo.texture_parameters[(attr>>18) & 0x1f];
1571
texparam = &geo->texture_parameters[(attr>>18) & 0x1f];
1569
1573
/* calculate luminance and specular */
1570
1574
if ( (dotl * dotp) < 0 ) luminance = 0;
1571
1575
else luminance = fabs( dotl );
1573
specular = ((2*dotl) * normal.pz) - geo.light.pz;
1577
specular = ((2*dotl) * normal.pz) - geo->light.pz;
1574
1578
if ( specular < 0 ) specular = 0;
1575
1579
if ( texparam->specular_control == 0 ) specular = 0;
1576
1580
if ( (texparam->specular_control >> 1) != 0 ) specular *= specular;
2060
2069
UINT32 *obp; /* Object Pointer */
2062
2071
/* push the initial set of data to the 3d rasterizer */
2063
model2_3d_push( opcode >> 23 );
2064
model2_3d_push( tpa );
2065
model2_3d_push( tha );
2072
model2_3d_push( raster, opcode >> 23 );
2073
model2_3d_push( raster, tpa );
2074
model2_3d_push( raster, tha );
2067
2076
/* select where we're reading polygon information from */
2068
2077
if ( oba & 0x01000000 )
2070
2079
/* Fast polygon RAM */
2071
obp = &geo.polygon_ram0[oba & 0x7FFF];
2080
obp = &geo->polygon_ram0[oba & 0x7FFF];
2073
2082
else if ( oba & 0x00800000 )
2075
2084
/* Polygon ROM */
2076
obp = &geo.polygon_rom[oba & 0x7FFFFF];
2085
obp = &geo->polygon_rom[oba & 0x7FFFFF];
2080
2089
/* Slow Polygon RAM */
2081
obp = &geo.polygon_ram1[oba & 0x7FFF];
2090
obp = &geo->polygon_ram1[oba & 0x7FFF];
2084
switch( geo.mode & 3 )
2093
switch( geo->mode & 3 )
2086
2095
/* Normals present, No Specular */
2087
case 0: geo_parse_np_ns( obp, obc ); break;
2096
case 0: geo_parse_np_ns( geo, obp, obc ); break;
2089
2098
/* Normals present, Specular */
2090
case 1: geo_parse_np_s( obp, obc ); break;
2099
case 1: geo_parse_np_s( geo, obp, obc ); break;
2092
2101
/* No Normals present, No Specular */
2093
case 2: geo_parse_nn_ns( obp, obc ); break;
2102
case 2: geo_parse_nn_ns( geo, obp, obc ); break;
2095
2104
/* No Normals present, Specular */
2096
case 3: geo_parse_nn_s( obp, obc ); break;
2105
case 3: geo_parse_nn_s( geo, obp, obc ); break;
2099
2108
/* move by 4 parameters */
2103
2112
/* Command 02: Direct Data */
2104
static UINT32 * geo_direct_data( UINT32 opcode, UINT32 *input )
2113
static UINT32 * geo_direct_data( geo_state *geo, UINT32 opcode, UINT32 *input )
2115
raster_state *raster = geo->raster;
2106
2116
UINT32 tpa = *input++; /* Texture Point Address */
2107
2117
UINT32 tha = *input++; /* Texture Header Address */
2110
2120
/* push the initial set of data to the 3d rasterizer */
2111
model2_3d_push( (opcode >> 23) - 1 );
2112
model2_3d_push( tpa );
2113
model2_3d_push( tha );
2121
model2_3d_push( raster, (opcode >> 23) - 1 );
2122
model2_3d_push( raster, tpa );
2123
model2_3d_push( raster, tha );
2115
2125
/* push the initial points */
2116
model2_3d_push( (*input++) >> 8 ); /* x */
2117
model2_3d_push( (*input++) >> 8 ); /* y */
2118
model2_3d_push( (*input++) >> 8 ); /* z */
2126
model2_3d_push( raster, (*input++) >> 8 ); /* x */
2127
model2_3d_push( raster, (*input++) >> 8 ); /* y */
2128
model2_3d_push( raster, (*input++) >> 8 ); /* z */
2120
model2_3d_push( (*input++) >> 8 ); /* x */
2121
model2_3d_push( (*input++) >> 8 ); /* y */
2122
model2_3d_push( (*input++) >> 8 ); /* z */
2130
model2_3d_push( raster, (*input++) >> 8 ); /* x */
2131
model2_3d_push( raster, (*input++) >> 8 ); /* y */
2132
model2_3d_push( raster, (*input++) >> 8 ); /* z */
2132
2142
/* push attributes */
2133
model2_3d_push( attr & 0x00FFFFFF );
2143
model2_3d_push( raster, attr & 0x00FFFFFF );
2135
2145
/* push luma */
2136
model2_3d_push( (*input++) >> 8 );
2146
model2_3d_push( raster, (*input++) >> 8 );
2138
2148
/* push distance */
2139
model2_3d_push( (*input++) >> 8 );
2149
model2_3d_push( raster, (*input++) >> 8 );
2141
2151
/* push the next point */
2142
model2_3d_push( (*input++) >> 8 ); /* x */
2143
model2_3d_push( (*input++) >> 8 ); /* y */
2144
model2_3d_push( (*input++) >> 8 ); /* z */
2152
model2_3d_push( raster, (*input++) >> 8 ); /* x */
2153
model2_3d_push( raster, (*input++) >> 8 ); /* y */
2154
model2_3d_push( raster, (*input++) >> 8 ); /* z */
2146
2156
/* if it's a quad, output another point */
2147
2157
if ( attr & 1 )
2149
model2_3d_push( (*input++) >> 8 ); /* x */
2150
model2_3d_push( (*input++) >> 8 ); /* y */
2151
model2_3d_push( (*input++) >> 8 ); /* z */
2159
model2_3d_push( raster, (*input++) >> 8 ); /* x */
2160
model2_3d_push( raster, (*input++) >> 8 ); /* y */
2161
model2_3d_push( raster, (*input++) >> 8 ); /* z */
2155
2165
/* we're done */
2156
model2_3d_push( 0 );
2166
model2_3d_push( raster, 0 );
2161
2171
/* Command 03: Window Data */
2162
static UINT32 * geo_window_data( UINT32 opcode, UINT32 *input )
2172
static UINT32 * geo_window_data( geo_state *geo, UINT32 opcode, UINT32 *input )
2174
raster_state *raster = geo->raster;
2164
2175
UINT32 x, y, i;
2166
2177
/* start by pushing the opcode */
2167
model2_3d_push( opcode >> 23 );
2178
model2_3d_push( raster, opcode >> 23 );
2170
2181
we're going to move 6 coordinates to the 3d rasterizer:
2189
model2_3d_push( x | y );
2200
model2_3d_push( raster, x | y );
2195
2206
/* Command 04: Texture Data Write */
2196
static UINT32 * geo_texture_data( UINT32 opcode, UINT32 *input )
2207
static UINT32 * geo_texture_data( geo_state *geo, UINT32 opcode, UINT32 *input )
2209
raster_state *raster = geo->raster;
2198
2210
UINT32 i, count;
2200
2212
/* start by pushing the opcode */
2201
model2_3d_push( opcode >> 23 );
2213
model2_3d_push( raster, opcode >> 23 );
2203
2215
/* push the starting address/dsp id */
2204
model2_3d_push( *input++ );
2216
model2_3d_push( raster, *input++ );
2206
2218
/* get the count */
2207
2219
count = *input++;
2209
2221
/* push the count */
2210
model2_3d_push( count );
2222
model2_3d_push( raster, count );
2212
2224
/* loop and send the data */
2213
2225
for( i = 0; i < count; i++ )
2214
model2_3d_push( *input++ );
2226
model2_3d_push( raster, *input++ );
2219
2231
/* Command 05: Polygon Data */
2220
static UINT32 * geo_polygon_data( UINT32 opcode, UINT32 *input )
2232
static UINT32 * geo_polygon_data( geo_state *geo, UINT32 opcode, UINT32 *input )
2222
2234
UINT32 address, count, i;
2284
2296
/* Command 07: Geo Mode */
2285
static UINT32 * geo_mode( UINT32 opcode, UINT32 *input )
2297
static UINT32 * geo_mode( geo_state *geo, UINT32 opcode, UINT32 *input )
2289
2301
/* read in the mode */
2290
geo.mode = *input++;
2302
geo->mode = *input++;
2295
2307
/* Command 08: ZSort Mode */
2296
static UINT32 * geo_zsort_mode( UINT32 opcode, UINT32 *input )
2308
static UINT32 * geo_zsort_mode( geo_state *geo, UINT32 opcode, UINT32 *input )
2310
raster_state *raster = geo->raster;
2298
2312
/* push the opcode */
2299
model2_3d_push( opcode >> 23 );
2313
model2_3d_push( raster, opcode >> 23 );
2301
2315
/* push the mode */
2302
model2_3d_push( (*input++) >> 8 );
2316
model2_3d_push( raster, (*input++) >> 8 );
2307
2321
/* Command 09: Focal Distance */
2308
static UINT32 * geo_focal_distance( UINT32 opcode, UINT32 *input )
2322
static UINT32 * geo_focal_distance( geo_state *geo, UINT32 opcode, UINT32 *input )
2312
2326
/* read the x focus value */
2313
geo.focus.x = u2f( *input++ );
2327
geo->focus.x = u2f( *input++ );
2315
2329
/* read the y focus value */
2316
geo.focus.y = u2f( *input++ );
2330
geo->focus.y = u2f( *input++ );
2321
2335
/* Command 0A: Light Source Vector Write */
2322
static UINT32 * geo_light_source( UINT32 opcode, UINT32 *input )
2336
static UINT32 * geo_light_source( geo_state *geo, UINT32 opcode, UINT32 *input )
2326
2340
/* read the x light value */
2327
geo.light.x = u2f( *input++ );
2341
geo->light.x = u2f( *input++ );
2329
2343
/* read the y light value */
2330
geo.light.y = u2f( *input++ );
2344
geo->light.y = u2f( *input++ );
2332
2346
/* read the z light value */
2333
geo.light.pz = u2f( *input++ );
2347
geo->light.pz = u2f( *input++ );
2338
2352
/* Command 0B: Transformation Matrix Write */
2339
static UINT32 * geo_matrix_write( UINT32 opcode, UINT32 *input )
2353
static UINT32 * geo_matrix_write( geo_state *geo, UINT32 opcode, UINT32 *input )
2497
2513
/* Command 14: Log Data Write */
2498
static UINT32 * geo_log_data( UINT32 opcode, UINT32 *input )
2514
static UINT32 * geo_log_data( geo_state *geo, UINT32 opcode, UINT32 *input )
2516
raster_state *raster = geo->raster;
2500
2517
UINT32 i, count;
2502
2519
/* start by pushing the opcode */
2503
model2_3d_push( opcode >> 23 );
2520
model2_3d_push( raster, opcode >> 23 );
2505
2522
/* push the starting address/dsp id */
2506
model2_3d_push( *input++ );
2523
model2_3d_push( raster, *input++ );
2508
2525
/* get the count */
2509
2526
count = *input++;
2511
2528
/* push the count */
2512
model2_3d_push( count << 2 );
2529
model2_3d_push( raster, count << 2 );
2514
2531
/* loop and send the data */
2515
2532
for( i = 0; i < count; i++ )
2517
2534
UINT32 data = *input++;
2519
model2_3d_push( data & 0xff );
2520
model2_3d_push( (data >> 8) & 0xff );
2521
model2_3d_push( (data >> 16) & 0xff );
2522
model2_3d_push( (data >> 24) & 0xff );
2536
model2_3d_push( raster, data & 0xff );
2537
model2_3d_push( raster, (data >> 8) & 0xff );
2538
model2_3d_push( raster, (data >> 16) & 0xff );
2539
model2_3d_push( raster, (data >> 24) & 0xff );
2528
2545
/* Command 16: LOD */
2529
static UINT32 * geo_lod( UINT32 opcode, UINT32 *input )
2546
static UINT32 * geo_lod( geo_state *geo, UINT32 opcode, UINT32 *input )
2533
2550
/* read in the LOD */
2534
geo.lod = u2f(*input++);
2551
geo->lod = u2f(*input++);
2539
2556
/* Command 1D: Code Upload (undocumented, unsupported) */
2540
static UINT32 * geo_code_upload( UINT32 opcode, UINT32 *input )
2557
static UINT32 * geo_code_upload( geo_state *geo, UINT32 opcode, UINT32 *input )
2542
2559
UINT32 flags, count, i;
2612
static UINT32 * geo_process_command( UINT32 opcode, UINT32 *input )
2629
static UINT32 * geo_process_command( geo_state *geo, UINT32 opcode, UINT32 *input )
2614
2631
switch( opcode >> 23 )
2616
case 0x00: input = geo_nop( opcode, input ); break;
2617
case 0x01: input = geo_object_data( opcode, input ); break;
2618
case 0x02: input = geo_direct_data( opcode, input ); break;
2619
case 0x03: input = geo_window_data( opcode, input ); break;
2620
case 0x04: input = geo_texture_data( opcode, input ); break;
2621
case 0x05: input = geo_polygon_data( opcode, input ); break;
2622
case 0x06: input = geo_texture_parameters( opcode, input ); break;
2623
case 0x07: input = geo_mode( opcode, input ); break;
2624
case 0x08: input = geo_zsort_mode( opcode, input ); break;
2625
case 0x09: input = geo_focal_distance( opcode, input ); break;
2626
case 0x0A: input = geo_light_source( opcode, input ); break;
2627
case 0x0B: input = geo_matrix_write( opcode, input ); break;
2628
case 0x0C: input = geo_translate_write( opcode, input ); break;
2629
case 0x0D: input = geo_data_mem_push( opcode, input ); break;
2630
case 0x0E: input = geo_test( opcode, input ); break;
2631
case 0x0F: input = geo_end( opcode, input ); break;
2632
case 0x10: input = geo_dummy( opcode, input ); break;
2633
case 0x11: input = geo_object_data( opcode, input ); break;
2634
case 0x12: input = geo_direct_data( opcode, input ); break;
2635
case 0x13: input = geo_window_data( opcode, input ); break;
2636
case 0x14: input = geo_log_data( opcode, input ); break;
2637
case 0x15: input = geo_polygon_data( opcode, input ); break;
2638
case 0x16: input = geo_lod( opcode, input ); break;
2639
case 0x17: input = geo_mode( opcode, input ); break;
2640
case 0x18: input = geo_zsort_mode( opcode, input ); break;
2641
case 0x19: input = geo_focal_distance( opcode, input ); break;
2642
case 0x1A: input = geo_light_source( opcode, input ); break;
2643
case 0x1B: input = geo_matrix_write( opcode, input ); break;
2644
case 0x1C: input = geo_translate_write( opcode, input ); break;
2645
case 0x1D: input = geo_code_upload( opcode, input ); break;
2646
case 0x1E: input = geo_code_jump( opcode, input ); break;
2647
case 0x1F: input = geo_end( opcode, input ); break;
2633
case 0x00: input = geo_nop( geo, opcode, input ); break;
2634
case 0x01: input = geo_object_data( geo, opcode, input ); break;
2635
case 0x02: input = geo_direct_data( geo, opcode, input ); break;
2636
case 0x03: input = geo_window_data( geo, opcode, input ); break;
2637
case 0x04: input = geo_texture_data( geo, opcode, input ); break;
2638
case 0x05: input = geo_polygon_data( geo, opcode, input ); break;
2639
case 0x06: input = geo_texture_parameters( geo, opcode, input ); break;
2640
case 0x07: input = geo_mode( geo, opcode, input ); break;
2641
case 0x08: input = geo_zsort_mode( geo, opcode, input ); break;
2642
case 0x09: input = geo_focal_distance( geo, opcode, input ); break;
2643
case 0x0A: input = geo_light_source( geo, opcode, input ); break;
2644
case 0x0B: input = geo_matrix_write( geo, opcode, input ); break;
2645
case 0x0C: input = geo_translate_write( geo, opcode, input ); break;
2646
case 0x0D: input = geo_data_mem_push( geo, opcode, input ); break;
2647
case 0x0E: input = geo_test( geo, opcode, input ); break;
2648
case 0x0F: input = geo_end( geo, opcode, input ); break;
2649
case 0x10: input = geo_dummy( geo, opcode, input ); break;
2650
case 0x11: input = geo_object_data( geo, opcode, input ); break;
2651
case 0x12: input = geo_direct_data( geo, opcode, input ); break;
2652
case 0x13: input = geo_window_data( geo, opcode, input ); break;
2653
case 0x14: input = geo_log_data( geo, opcode, input ); break;
2654
case 0x15: input = geo_polygon_data( geo, opcode, input ); break;
2655
case 0x16: input = geo_lod( geo, opcode, input ); break;
2656
case 0x17: input = geo_mode( geo, opcode, input ); break;
2657
case 0x18: input = geo_zsort_mode( geo, opcode, input ); break;
2658
case 0x19: input = geo_focal_distance( geo, opcode, input ); break;
2659
case 0x1A: input = geo_light_source( geo, opcode, input ); break;
2660
case 0x1B: input = geo_matrix_write( geo, opcode, input ); break;
2661
case 0x1C: input = geo_translate_write( geo, opcode, input ); break;
2662
case 0x1D: input = geo_code_upload( geo, opcode, input ); break;
2663
case 0x1E: input = geo_code_jump( geo, opcode, input ); break;
2664
case 0x1F: input = geo_end( geo, opcode, input ); break;
2653
static void geo_parse( void )
2670
static void geo_parse( model2_state *state )
2655
UINT32 address = (geo_read_start_address/4);
2656
UINT32 *input = &model2_bufferram[address];
2672
UINT32 address = (state->m_geo_read_start_address/4);
2673
UINT32 *input = &state->m_bufferram[address];
2659
while( input != NULL && (input - model2_bufferram) < 0x20000 )
2676
while( input != NULL && (input - state->m_bufferram) < 0x20000 )
2661
2678
/* read in the opcode */
2662
2679
opcode = *input++;
2668
2685
address = (opcode & 0x7FFFF) / 4;
2670
2687
/* update our pointer */
2671
input = &model2_bufferram[address];
2688
input = &state->m_bufferram[address];
2677
2694
/* process it */
2678
input = geo_process_command( opcode, input );
2695
input = geo_process_command( state->m_geo, opcode, input );
2682
2699
/***********************************************************************************************/
2684
static bitmap_t *sys24_bitmap = NULL;
2686
2702
static void model2_exit(running_machine &machine)
2704
model2_state *state = machine.driver_data<model2_state>();
2705
poly_free(state->m_poly);
2691
2708
VIDEO_START(model2)
2693
const rectangle &visarea = machine->primary_screen->visible_area();
2710
model2_state *state = machine.driver_data<model2_state>();
2711
const rectangle &visarea = machine.primary_screen->visible_area();
2694
2712
int width = visarea.max_x - visarea.min_x;
2695
2713
int height = visarea.max_y - visarea.min_y;
2697
2715
sys24_tile_vh_start(machine, 0x3fff);
2698
sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16));
2700
poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0);
2701
machine->add_notifier(MACHINE_NOTIFY_EXIT, model2_exit);
2716
state->m_sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16));
2718
state->m_poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0);
2719
machine.add_notifier(MACHINE_NOTIFY_EXIT, model2_exit);
2721
/* initialize the hardware rasterizer */
2722
model2_3d_init( machine, (UINT16*)machine.region("user3")->base() );
2703
2724
/* initialize the geometry engine */
2704
geo_init( machine, (UINT32*)machine->region("user2")->base() );
2706
/* initialize the hardware rasterizer */
2707
model2_3d_init( machine, (UINT16*)machine->region("user3")->base() );
2725
geo_init( machine, (UINT32*)machine.region("user2")->base() );
2710
static void convert_bitmap( running_machine *machine, bitmap_t *dst, bitmap_t *src, const rectangle *rect )
2728
static void convert_bitmap( running_machine &machine, bitmap_t *dst, bitmap_t *src, const rectangle *rect )
2719
2737
for( x = rect->min_x; x < rect->max_x; x++ )
2722
d[x] = machine->pens[s[x]];
2740
d[x] = machine.pens[s[x]];
2727
VIDEO_UPDATE(model2)
2745
SCREEN_UPDATE(model2)
2747
model2_state *state = screen->machine().driver_data<model2_state>();
2729
2748
logerror("--- frame ---\n");
2731
bitmap_fill(bitmap, cliprect, screen->machine->pens[0]);
2732
bitmap_fill(sys24_bitmap, cliprect, 0);
2734
sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 7, 0, 0);
2735
sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 6, 0, 0);
2736
sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 5, 0, 0);
2737
sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 4, 0, 0);
2739
convert_bitmap(screen->machine, bitmap, sys24_bitmap, cliprect);
2750
bitmap_fill(bitmap, cliprect, screen->machine().pens[0]);
2751
bitmap_fill(state->m_sys24_bitmap, cliprect, 0);
2753
sys24_tile_draw(screen->machine(), state->m_sys24_bitmap, cliprect, 7, 0, 0);
2754
sys24_tile_draw(screen->machine(), state->m_sys24_bitmap, cliprect, 6, 0, 0);
2755
sys24_tile_draw(screen->machine(), state->m_sys24_bitmap, cliprect, 5, 0, 0);
2756
sys24_tile_draw(screen->machine(), state->m_sys24_bitmap, cliprect, 4, 0, 0);
2758
convert_bitmap(screen->machine(), bitmap, state->m_sys24_bitmap, cliprect);
2741
2760
/* tell the rasterizer we're starting a frame */
2742
model2_3d_frame_start();
2761
model2_3d_frame_start(state);
2744
2763
/* let the geometry engine do it's thing */
2747
2766
/* have the rasterizer output the frame */
2748
model2_3d_frame_end( bitmap, cliprect );
2750
bitmap_fill(sys24_bitmap, cliprect, 0);
2751
sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 3, 0, 0);
2752
sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 2, 0, 0);
2753
sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 1, 0, 0);
2754
sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 0, 0, 0);
2756
convert_bitmap(screen->machine, bitmap, sys24_bitmap, cliprect);
2767
model2_3d_frame_end( state, bitmap, cliprect );
2769
bitmap_fill(state->m_sys24_bitmap, cliprect, 0);
2770
sys24_tile_draw(screen->machine(), state->m_sys24_bitmap, cliprect, 3, 0, 0);
2771
sys24_tile_draw(screen->machine(), state->m_sys24_bitmap, cliprect, 2, 0, 0);
2772
sys24_tile_draw(screen->machine(), state->m_sys24_bitmap, cliprect, 1, 0, 0);
2773
sys24_tile_draw(screen->machine(), state->m_sys24_bitmap, cliprect, 0, 0, 0);
2775
convert_bitmap(screen->machine(), bitmap, state->m_sys24_bitmap, cliprect);