starting work on ps2 driver

This commit is contained in:
aap
2017-08-12 10:25:25 +02:00
parent e5c2a66bd5
commit aec8c202c6
24 changed files with 1843 additions and 61 deletions

17
src/base.cpp Normal file → Executable file
View File

@@ -261,6 +261,7 @@ Matrix::translate(V3d *translation, CombineOp op)
Matrix tmp;
Matrix trans = identMat;
trans.pos = *translation;
trans.flags &= ~IDENTITY;
switch(op){
case COMBINEREPLACE:
*this = trans;
@@ -483,22 +484,6 @@ Matrix::identityError(void)
return dot(r,r) + dot(u,u) + dot(a,a) + dot(pos,pos);
}
#if 0
bool32
Matrix::isIdentity(void)
{
return matrixIsIdentity((float32*)this);
}
void
Matrix::transpose(Matrix *m1, Matrix *m2)
{
matrixTranspose((float32*)m1, (float32*)m2);
}
#endif
#define PSEP_C '/'
#define PSEP_S "/"
#ifndef _WIN32

56
src/camera.cpp Normal file → Executable file
View File

@@ -184,7 +184,21 @@ cameraSync(ObjectWithFrame *obj)
* and to clip space are handled by separate matrices there.
* On these platforms the two matrices are built in the platform's
* beginUpdate function.
* On the PS2 the 1/2 translation/shear is removed again on the VU1.
* On the PS2 the z- and w-rows are the same and the
* 1/2 translation/shear is removed again on the VU1 by
* subtracting the w-row/2 from the x- and y-rows.
*
* perspective:
* 1/2w 0 ox/2w -ox/2w
* 0 -1/2h -oy/2h oy/2h
* 0 0 1 0
* 0 0 1 0
*
* parallel:
* 1/2w 0 ox/2w -ox/2w
* 0 -1/2h -oy/2h oy/2h
* 0 0 1 0
* 0 0 0 1
*
* RW builds this matrix directly without using explicit
* inversion and matrix multiplication.
@@ -193,8 +207,8 @@ cameraSync(ObjectWithFrame *obj)
Camera *cam = (Camera*)obj;
Matrix inv, proj;
Matrix::invertOrthonormal(&inv, cam->getFrame()->getLTM());
float32 xscl = 2.0f/cam->viewWindow.x;
float32 yscl = 2.0f/cam->viewWindow.y;
float32 xscl = 1.0f/(2.0f*cam->viewWindow.x);
float32 yscl = 1.0f/(2.0f*cam->viewWindow.y);
proj.flags = 0;
proj.right.x = xscl;
@@ -351,6 +365,8 @@ Camera::setNearPlane(float32 near)
{
this->nearPlane = near;
calczShiftScale(this);
if(this->getFrame())
this->getFrame()->updateObjects();
}
void
@@ -358,6 +374,32 @@ Camera::setFarPlane(float32 far)
{
this->farPlane = far;
calczShiftScale(this);
if(this->getFrame())
this->getFrame()->updateObjects();
}
void
Camera::setViewWindow(const V2d *window)
{
this->viewWindow = *window;
if(this->getFrame())
this->getFrame()->updateObjects();
}
void
Camera::setViewOffset(const V2d *offset)
{
this->viewOffset = *offset;
if(this->getFrame())
this->getFrame()->updateObjects();
}
void
Camera::setProjection(int32 proj)
{
this->projection = proj;
if(this->getFrame())
this->getFrame()->updateObjects();
}
int32
@@ -433,10 +475,12 @@ Camera::streamGetSize(void)
void
Camera::setFOV(float32 fov, float32 ratio)
{
V2d v;
float32 a = tan(fov*3.14159f/360.0f);
this->viewWindow.x = a;
this->viewWindow.y = a/ratio;
this->viewOffset.set(0.0f, 0.0f);
v.set(a, a/ratio);
this->setViewWindow(&v);
v.set(0.0f, 0.0f);
this->setViewOffset(&v);
}
}

0
src/d3d/d3ddriver.cpp → src/d3d/d3ddevice.cpp Normal file → Executable file
View File

8
src/engine.cpp Normal file → Executable file
View File

@@ -74,7 +74,9 @@ Engine::open(void)
// Initialize device
// Device and possibly OS specific!
#ifdef RW_GL3
#ifdef RW_PS2
engine->device = ps2::renderdevice;
#elif RW_GL3
engine->device = gl3::renderdevice;
#elif RW_D3D9
engine->device = d3d::renderdevice;
@@ -196,7 +198,7 @@ rasterToImage(Raster*)
}
int
devicesystem(DeviceReq req, void *arg0)
deviceSystem(DeviceReq req, void *arg0)
{
return 1;
}
@@ -210,7 +212,7 @@ Device renderdevice = {
null::setRenderState,
null::getRenderState,
null::im2DRenderIndexedPrimitive,
null::devicesystem
null::deviceSystem
};
}

0
src/gl/gl3driver.cpp → src/gl/gl3device.cpp Normal file → Executable file
View File

2
src/matfx.cpp Normal file → Executable file
View File

@@ -145,7 +145,7 @@ MatFX::get(Material *m)
return *PLUGINOFFSET(MatFX*, m, matFXGlobals.materialOffset);
}
uint32
int32
MatFX::getEffectIndex(uint32 type)
{
for(int i = 0; i < 2; i++)

1
src/pipeline.cpp Normal file → Executable file
View File

@@ -7,7 +7,6 @@
#include "rwplg.h"
#include "rwpipeline.h"
#include "rwobjects.h"
#include "ps2/rwps2.h"
#define COLOR_ARGB(a,r,g,b) \
((uint32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))

1
src/ps2/pds.cpp Normal file → Executable file
View File

@@ -7,6 +7,7 @@
#include "../rwplg.h"
#include "../rwpipeline.h"
#include "../rwobjects.h"
#include "../rwengine.h"
#include "../rwanim.h"
#include "../rwplugins.h"
#include "rwps2.h"

47
src/ps2/ps2.cpp Normal file → Executable file
View File

@@ -92,7 +92,6 @@ readNativeData(Stream *stream, int32, void *object, int32, int32)
uint32 buf[2];
stream->read(buf, 8);
instance->dataSize = buf[0];
instance->arePointersFixed = buf[1];
// TODO: force alignment
instance->data = new uint8[instance->dataSize];
#ifdef RW_PS2
@@ -100,6 +99,10 @@ readNativeData(Stream *stream, int32, void *object, int32, int32)
assert(a % 0x10 == 0);
#endif
stream->read(instance->data, instance->dataSize);
#ifdef RW_PS2
if(!buf[1])
fixDmaOffsets(instance);
#endif
instance->material = geometry->meshHeader->mesh[i].material;
// sizedebug(instance);
}
@@ -118,13 +121,15 @@ writeNativeData(Stream *stream, int32 len, void *object, int32, int32)
InstanceDataHeader *header = (InstanceDataHeader*)geometry->instData;
for(uint32 i = 0; i < header->numMeshes; i++){
InstanceData *instance = &header->instanceMeshes[i];
if(instance->arePointersFixed == 2)
unfixDmaOffsets(instance);
uint32 buf[2];
buf[0] = instance->dataSize;
buf[1] = instance->arePointersFixed;
buf[1] = unfixDmaOffsets(instance);
stream->write(buf, 8);
stream->write(instance->data, instance->dataSize);
#ifdef RW_PS2
if(!buf[1])
fixDmaOffsets(instance);
#endif
}
return stream;
}
@@ -157,13 +162,11 @@ registerNativeDataPlugin(void)
getSizeNativeData);
}
// Patch DMA ref ADDR fields to point to the actual data.
#ifdef RW_PS2
void
fixDmaOffsets(InstanceData *inst)
{
if(inst->arePointersFixed)
return;
uint32 base = (uint32)inst->data;
uint32 *tag = (uint32*)inst->data;
for(;;){
@@ -184,7 +187,6 @@ fixDmaOffsets(InstanceData *inst)
// DMAret
case 0x60000000:
// we're done
inst->arePointersFixed = 2;
return;
default:
@@ -195,15 +197,17 @@ fixDmaOffsets(InstanceData *inst)
}
#endif
void
// Patch DMA ref ADDR fields to qword offsets and return whether
// no ref tags were found.
// Only under RW_PS2 are the addresses actually patched but we need
// the return value for streaming out.
bool32
unfixDmaOffsets(InstanceData *inst)
{
(void)inst;
bool32 norefs = 1;
#ifdef RW_PS2
if(inst->arePointersFixed != 2)
return;
uint32 base = (uint32)inst->data;
#endif
uint32 *tag = (uint32*)inst->data;
for(;;){
switch(tag[0]&0x70000000){
@@ -215,23 +219,23 @@ unfixDmaOffsets(InstanceData *inst)
// DMAref
case 0x30000000:
norefs = 0;
// unfix address and jump to next
#ifdef RW_PS2
tag[1] = (tag[1] - base)>>4;
#endif
tag += 4;
break;
// DMAret
case 0x60000000:
// we're done
inst->arePointersFixed = 0;
return;
return norefs;
default:
fprintf(stderr, "error: unknown DMAtag %X\n", tag[0]);
return;
return norefs;
}
}
#endif
}
// Pipeline
@@ -586,7 +590,6 @@ MatPipeline::instance(Geometry *g, InstanceData *inst, Mesh *m)
InstMeshInfo im = getInstMeshInfo(this, g, m);
inst->dataSize = (im.size+im.size2)<<4;
inst->arePointersFixed = im.numBrokenAttribs == 0;
// TODO: force alignment
inst->data = new uint8[inst->dataSize];
@@ -685,6 +688,8 @@ MatPipeline::instance(Geometry *g, InstanceData *inst, Mesh *m)
if(this->instanceCB)
this->instanceCB(this, g, m, datap);
if(im.numBrokenAttribs)
fixDmaOffsets(inst);
}
uint8*
@@ -766,6 +771,7 @@ objInstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
geo->flags |= Geometry::NATIVE;
}
/*
static void
printVertCounts(InstanceData *inst, int flag)
{
@@ -794,6 +800,7 @@ printVertCounts(InstanceData *inst, int flag)
}
}
}
*/
static void
objUninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
@@ -1241,6 +1248,7 @@ registerADCPlugin(void)
}
// misc stuff
/*
void
printDMA(InstanceData *inst)
@@ -1300,6 +1308,7 @@ sizedebug(InstanceData *inst)
}
}
}
*/
}
}

41
src/ps2/ps2device.cpp Executable file
View File

@@ -0,0 +1,41 @@
#ifdef RW_PS2
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include "../rwbase.h"
#include "../rwerror.h"
#include "../rwplg.h"
#include "../rwpipeline.h"
#include "../rwobjects.h"
#include "../rwengine.h"
#include "../rwanim.h"
#include "../rwplugins.h"
#include "rwps2.h"
#include "rwps2plg.h"
#include "rwps2impl.h"
#define PLUGIN_ID 2
namespace rw {
namespace ps2 {
Device renderdevice = {
16777215.0f, 0.0f,
null::beginUpdate,
null::endUpdate,
null::clearCamera,
null::showRaster,
null::setRenderState,
null::getRenderState,
null::im2DRenderIndexedPrimitive,
null::deviceSystem
};
}
}
#endif

20
src/ps2/rwps2.h Normal file → Executable file
View File

@@ -1,15 +1,19 @@
namespace rw {
#ifdef RW_PS2
struct EngineStartParams
{
};
#endif
namespace ps2 {
void initializePlatform(void);
extern Device renderdevice;
struct InstanceData
{
// 0 - addresses in ref tags need fixing
// 1 - no ref tags, so no fixing
// set by the program:
// 2 - ref tags are fixed, need to unfix before stream write
uint32 arePointersFixed;
uint32 dataSize;
uint8 *data;
Material *material;
@@ -57,10 +61,8 @@ void registerNativeDataPlugin(void);
void printDMA(InstanceData *inst);
void sizedebug(InstanceData *inst);
// only RW_PS2
void fixDmaOffsets(InstanceData *inst);
void unfixDmaOffsets(InstanceData *inst);
//
void fixDmaOffsets(InstanceData *inst); // only RW_PS2
int32 unfixDmaOffsets(InstanceData *inst);
struct PipeAttribute
{

3
src/rwengine.h Normal file → Executable file
View File

@@ -140,6 +140,7 @@ namespace null {
void beginUpdate(Camera*);
void endUpdate(Camera*);
void clearCamera(Camera*, RGBA *col, uint32 mode);
void showRaster(Raster*);
void setRenderState(int32 state, uint32 value);
uint32 getRenderState(int32 state);
@@ -154,7 +155,7 @@ namespace null {
void im2DRenderIndexedPrimitive(PrimitiveType,
void*, int32, void*, int32);
int deviceSystem(DeviceReq req);
int deviceSystem(DeviceReq req, void*);
extern Device renderdevice;
}

3
src/rwobjects.h Normal file → Executable file
View File

@@ -624,6 +624,9 @@ struct Camera
void showRaster(void);
void setNearPlane(float32);
void setFarPlane(float32);
void setViewWindow(const V2d *window);
void setViewOffset(const V2d *offset);
void setProjection(int32 proj);
int32 frustumTestSphere(Sphere *s);
static Camera *streamRead(Stream *stream);
bool streamWrite(Stream *stream);

2
src/rwplugins.h Normal file → Executable file
View File

@@ -130,7 +130,7 @@ struct MatFX
static void setEffects(Material *m, uint32 flags);
static uint32 getEffects(Material *m);
static MatFX *get(Material *m);
uint32 getEffectIndex(uint32 type);
int32 getEffectIndex(uint32 type);
void setBumpTexture(Texture *t);
void setBumpCoefficient(float32 coef);
void setEnvTexture(Texture *t);

7
src/world.cpp Normal file → Executable file
View File

@@ -35,14 +35,19 @@ World::addLight(Light *light)
light->world = this;
if(light->getType() < Light::POINT){
this->directionalLights.append(&light->inWorld);
}else
}else{
this->lights.append(&light->inWorld);
if(light->getFrame())
light->getFrame()->updateObjects();
}
}
void
World::addCamera(Camera *cam)
{
cam->world = this;
if(cam->getFrame())
cam->getFrame()->updateObjects();
}
}