changes and fixes for ps2

This commit is contained in:
aap 2021-10-14 13:31:30 +02:00
parent 5501c4fdc7
commit 453ae4b9ee
7 changed files with 70 additions and 30 deletions

View File

@ -999,7 +999,7 @@ StreamFile*
StreamFile::open(const char *path, const char *mode)
{
assert(this->file == nil);
this->file = fopen(path, mode);
this->file = engine->filefuncs.rwfopen(path, mode);
if(this->file == nil){
RWERROR((ERR_FILE, path));
return nil;
@ -1011,38 +1011,38 @@ void
StreamFile::close(void)
{
assert(this->file);
fclose(this->file);
engine->filefuncs.rwfclose(this->file);
this->file = nil;
}
uint32
StreamFile::write8(const void *data, uint32 length)
{
return (uint32)fwrite(data, 1, length, this->file);
return (uint32)engine->filefuncs.rwfwrite(data, 1, length, this->file);
}
uint32
StreamFile::read8(void *data, uint32 length)
{
return (uint32)fread(data, 1, length, this->file);
return (uint32)engine->filefuncs.rwfread(data, 1, length, this->file);
}
void
StreamFile::seek(int32 offset, int32 whence)
{
fseek(this->file, offset, whence);
engine->filefuncs.rwfseek(this->file, offset, whence);
}
uint32
StreamFile::tell(void)
{
return ftell(this->file);
return engine->filefuncs.rwftell(this->file);
}
bool
StreamFile::eof(void)
{
return ( feof(this->file) != 0 );
return engine->filefuncs.rwfeof(this->file) != 0;
}
bool
@ -1106,15 +1106,15 @@ findPointer(void *p, void **list, int32 num)
uint8*
getFileContents(const char *name, uint32 *len)
{
FILE *cf = fopen(name, "rb");
void *cf = engine->filefuncs.rwfopen(name, "rb");
if(cf == nil)
return nil;
fseek(cf, 0, SEEK_END);
*len = ftell(cf);
fseek(cf, 0, SEEK_SET);
engine->filefuncs.rwfseek(cf, 0, SEEK_END);
*len = engine->filefuncs.rwftell(cf);
engine->filefuncs.rwfseek(cf, 0, SEEK_SET);
uint8 *data = rwNewT(uint8, *len, MEMDUR_EVENT);
fread(data, 1, *len, cf);
fclose(cf);
engine->filefuncs.rwfread(data, 1, *len, cf);
engine->filefuncs.rwfclose(cf);
return data;
}

View File

@ -254,6 +254,13 @@ Engine::open(EngineOpenParams *p)
engine = (Engine*)rwNew(Engine::s_plglist.size, MEMDUR_GLOBAL);
engine->currentCamera = nil;
engine->currentWorld = nil;
engine->filefuncs.rwfopen = (void *(*)(const char*, const char*))fopen;
engine->filefuncs.rwfclose = (int (*)(void*))fclose;
engine->filefuncs.rwfseek = (int (*)(void*, long, int))fseek;
engine->filefuncs.rwftell = (long (*)(void*))ftell;
engine->filefuncs.rwfread = (size_t (*)(void*, size_t, size_t, void*))fread;
engine->filefuncs.rwfwrite = (size_t (*)(const void*, size_t, size_t, void*))fwrite;
engine->filefuncs.rwfeof = (int (*)(void*))feof;
// Initialize device
// Device and possibly OS specific!

View File

@ -931,15 +931,15 @@ char*
Image::getFilename(const char *name)
{
ImageGlobals *g = PLUGINOFFSET(ImageGlobals, engine, imageModuleOffset);
FILE *f;
void *f;
char *s, *p = g->searchPaths;
size_t len = strlen(name)+1;
if(g->numSearchPaths == 0){
s = rwStrdup(name, MEMDUR_EVENT);
makePath(s);
f = fopen(s, "rb");
f = engine->filefuncs.rwfopen(s, "rb");
if(f){
fclose(f);
engine->filefuncs.rwfclose(f);
printf("found %s\n", s);
return s;
}
@ -955,9 +955,9 @@ Image::getFilename(const char *name)
strcpy(s, p);
strcat(s, name);
makePath(s);
f = fopen(s, "r");
f = engine->filefuncs.rwfopen(s, "r");
if(f){
fclose(f);
engine->filefuncs.rwfclose(f);
printf("found %s\n", name);
return s;
}

View File

@ -1219,7 +1219,7 @@ rasterCreateTexture(Raster *raster)
// this obviously only works with 32 bit pointers, but it's only needed on the PS2 anyway
*xferchain++ = (uint32)(uintptr)p - 0x50;
*xferchain++ = 0; // VIF nop
*xferchain++ = 0x50000000 | sz+5; // VIF DIRECT 2 qwords
*xferchain++ = 0x50000000 | sz+5; // VIF DIRECT
}else{
// Add to existing transfer
xferchain[-4] = 0x30000000 | (xferchain[-4]&0xFFFF) + sz+5; // last DMAref
@ -1243,7 +1243,7 @@ rasterCreateTexture(Raster *raster)
*p++ = 0;
// TRXPOS
*(uint64*)p = paltrxpos;
*(uint64*)p = (uint64)paltrxpos<<32;
p += 2;
*p++ = 0x51;
*p++ = 0;
@ -1291,10 +1291,10 @@ rasterCreateTexture(Raster *raster)
xferchain[1] = xferchain[-15];
xferchain[2] = xferchain[-14];
xferchain[3] = xferchain[-13];
xferchain += 4;
// Add to last transfer
xferchain[-16] = 0x30000000 | (xferchain[-16]&0xFFFF) + sz+5; // last DMAref
xferchain[-13] = 0x50000000 | (xferchain[-13]&0xFFFF) + sz+5; // last DIRECT
xferchain += 4;
pp->numTransfers--;
}
@ -1302,7 +1302,7 @@ rasterCreateTexture(Raster *raster)
// this obviously only works with 32 bit pointers, but it's only needed on the PS2 anyway
*xferchain++ = (uint32)(uintptr)p - 0x50;
*xferchain++ = 0; // VIF nop
*xferchain++ = 0x50000000 | sz+5; // VIF DIRECT 2 qwords
*xferchain++ = 0x50000000 | sz+5; // VIF DIRECT
}
}
raster->originalPixels = raster->pixels;

View File

@ -38,6 +38,28 @@ struct Im2DVertex
float getV(void) { return this->v; }
};
struct Im3DVertex
{
V3d position;
uint8 r, g, b, a;
float32 u, v;
void setX(float32 x) { this->position.x = x; }
void setY(float32 y) { this->position.y = y; }
void setZ(float32 z) { this->position.z = z; }
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
this->r = r; this->g = g; this->b = b; this->a = a; }
void setU(float32 u) { this->u = u; }
void setV(float32 v) { this->v = v; }
float getX(void) { return this->position.x; }
float getY(void) { return this->position.y; }
float getZ(void) { return this->position.z; }
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
float getU(void) { return this->u; }
float getV(void) { return this->v; }
};
struct InstanceData
{

View File

@ -151,7 +151,7 @@ struct RGBA
uint8 blue;
uint8 alpha;
};
inline RGBA makeRGBA(uint8 r, uint8 g, uint8 b, uint8 a) { RGBA c = { r, g, b, a }; return c; }
inline RGBA makeRGBA(uint8 r, uint8 g, uint8 b, uint8 a) { RGBA c; c.red = r; c.green = g; c.blue = b; c.alpha = a; return c; }
inline bool32 equal(const RGBA &c1, const RGBA &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
#define RWRGBAINT(r, g, b, a) ((uint32)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((g)&0xff)<<8)|((r)&0xff)))
@ -162,7 +162,7 @@ struct RGBAf
float32 blue;
float32 alpha;
};
inline RGBAf makeRGBAf(float32 r, float32 g, float32 b, float32 a) { RGBAf c = { r, g, b, a }; return c; }
inline RGBAf makeRGBAf(float32 r, float32 g, float32 b, float32 a) { RGBAf c; c.red = r; c.green = g; c.blue = b; c.alpha = a; return c; }
inline bool32 equal(const RGBAf &c1, const RGBAf &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
inline RGBAf add(const RGBAf &a, const RGBAf &b) { return makeRGBAf(a.red+b.red, a.green+b.green, a.blue+b.blue, a.alpha+b.alpha); }
inline RGBAf modulate(const RGBAf &a, const RGBAf &b) { return makeRGBAf(a.red*b.red, a.green*b.green, a.blue*b.blue, a.alpha*b.alpha); }
@ -215,7 +215,7 @@ struct V2d
this->x = x; this->y = y; }
};
inline V2d makeV2d(float32 x, float32 y) { V2d v = { x, y }; return v; }
inline V2d makeV2d(float32 x, float32 y) { V2d v; v.x = x; v.y = y; return v; }
inline bool32 equal(const V2d &v1, const V2d &v2) { return v1.x == v2.x && v1.y == v2.y; }
inline V2d neg(const V2d &a) { return makeV2d(-a.x, -a.y); }
inline V2d add(const V2d &a, const V2d &b) { return makeV2d(a.x+b.x, a.y+b.y); }
@ -233,7 +233,7 @@ struct V3d
static void transformVectors(V3d *out, const V3d *in, int32 n, const Matrix *m);
};
inline V3d makeV3d(float32 x, float32 y, float32 z) { V3d v = { x, y, z }; return v; }
inline V3d makeV3d(float32 x, float32 y, float32 z) { V3d v; v.x = x; v.y = y; v.z = z; return v; }
inline bool32 equal(const V3d &v1, const V3d &v2) { return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z; }
inline V3d neg(const V3d &a) { return makeV3d(-a.x, -a.y, -a.z); }
inline V3d add(const V3d &a, const V3d &b) { return makeV3d(a.x+b.x, a.y+b.y, a.z+b.z); }
@ -281,8 +281,8 @@ struct Quat
Quat *rotate(const V3d *axis, float32 angle, CombineOp op = rw::COMBINEPOSTCONCAT);
};
inline Quat makeQuat(float32 w, float32 x, float32 y, float32 z) { Quat q = { x, y, z, w }; return q; }
inline Quat makeQuat(float32 w, const V3d &vec) { Quat q = { vec.x, vec.y, vec.z, w }; return q; }
inline Quat makeQuat(float32 w, float32 x, float32 y, float32 z) { Quat q; q.x = x; q.y = y; q.z = z; q.w = w; return q; }
inline Quat makeQuat(float32 w, const V3d &vec) { return makeQuat(w, vec.x, vec.y, vec.z); }
inline Quat add(const Quat &q, const Quat &p) { return makeQuat(q.w+p.w, q.x+p.x, q.y+p.y, q.z+p.z); }
inline Quat sub(const Quat &q, const Quat &p) { return makeQuat(q.w-p.w, q.x-p.x, q.y-p.y, q.z-p.z); }
inline Quat negate(const Quat &q) { return makeQuat(-q.w, -q.x, -q.y, -q.z); }
@ -509,9 +509,8 @@ public:
class StreamFile : public Stream
{
void *file;
public:
FILE *file;
StreamFile(void) { file = nil; }
void close(void);
uint32 write8(const void *data, uint32 length);

View File

@ -121,6 +121,17 @@ struct MemoryFunctions
void *(*rwmustrealloc)(void *p, size_t sz, uint32 hint);
};
struct FileFunctions
{
void *(*rwfopen)(const char *path, const char *mode);
int (*rwfclose)(void *fp);
int (*rwfseek)(void *fp, long offset, int whence);
long (*rwftell)(void *fp);
size_t (*rwfread)(void *ptr, size_t size, size_t nmemb, void *fp);
size_t (*rwfwrite)(const void *ptr, size_t size, size_t nmemb, void *fp);
int (*rwfeof)(void *fp);
};
struct SubSystemInfo
{
char name[80];
@ -155,6 +166,7 @@ struct Engine
Camera *currentCamera;
World *currentWorld;
LinkList frameDirtyList;
FileFunctions filefuncs;
// Dynamically allocated because of plugins
Driver *driver[NUM_PLATFORMS];