2015-01-26 19:23:45 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
#include <cmath>
|
|
|
|
#include <cassert>
|
2015-01-18 18:35:23 +00:00
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
#include <rw.h>
|
|
|
|
#include <src/gtaplg.h>
|
|
|
|
|
2015-01-18 18:35:23 +00:00
|
|
|
#include "ps2.h"
|
|
|
|
#include "dma.h"
|
|
|
|
#include "gif.h"
|
|
|
|
#include "gs.h"
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2015-01-28 20:15:49 +00:00
|
|
|
Matrix projMat, viewMat, worldMat;
|
|
|
|
|
2015-01-18 18:35:23 +00:00
|
|
|
extern uint32 MyDmaPacket[];
|
|
|
|
extern Matrix vuMat;
|
2015-01-28 20:15:49 +00:00
|
|
|
extern Matrix vuLightMat;
|
2015-01-18 18:35:23 +00:00
|
|
|
extern float vuOffset[];
|
|
|
|
extern uint64 vuGIFtag[];
|
|
|
|
extern float vuMatcolor[];
|
|
|
|
extern float vuSurfProps[];
|
|
|
|
extern uint32 vuGeometry[];
|
|
|
|
extern uint32 mpgCall[];
|
|
|
|
extern uint32 geometryCall[];
|
|
|
|
extern uint32 defaultPipe[];
|
|
|
|
extern uint32 skinPipe[];
|
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::Clump *clump;
|
2015-01-18 18:35:23 +00:00
|
|
|
|
|
|
|
void
|
2015-01-25 21:27:03 +00:00
|
|
|
drawAtomic(rw::Atomic *atomic)
|
2015-01-18 18:35:23 +00:00
|
|
|
{
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::Geometry *geo = atomic->geometry;
|
2015-01-18 18:35:23 +00:00
|
|
|
assert(geo->instData != NULL);
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::ps2::InstanceDataHeader *instData =
|
|
|
|
(rw::ps2::InstanceDataHeader*)geo->instData;
|
2015-01-28 20:15:49 +00:00
|
|
|
rw::MeshHeader *meshHeader = geo->meshHeader;
|
|
|
|
rw::Mesh *mesh;
|
|
|
|
uint8 *color;
|
2015-01-18 18:35:23 +00:00
|
|
|
|
|
|
|
atomic->frame->updateLTM();
|
2015-01-28 20:15:49 +00:00
|
|
|
matCopy(vuLightMat, atomic->frame->ltm);
|
2015-01-18 18:35:23 +00:00
|
|
|
matMult(vuMat, atomic->frame->ltm);
|
2015-01-28 20:15:49 +00:00
|
|
|
rw::Skin *skin = *PLUGINOFFSET(rw::Skin*, geo, rw::skinGlobals.offset);
|
2015-06-18 22:05:37 +01:00
|
|
|
for(uint i = 0; i < instData->numMeshes; i++){
|
2015-01-18 18:35:23 +00:00
|
|
|
if(instData->instanceMeshes[i].arePointersFixed == 0)
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::ps2::fixDmaOffsets(&instData->instanceMeshes[i]);
|
2015-01-18 18:35:23 +00:00
|
|
|
geometryCall[1] = (uint32)instData->instanceMeshes[i].data;
|
2015-01-28 20:15:49 +00:00
|
|
|
mesh = &meshHeader->mesh[i];
|
|
|
|
color = mesh->material->color;
|
2015-01-18 18:35:23 +00:00
|
|
|
|
2015-06-18 22:05:37 +01:00
|
|
|
vuGIFtag[0] = MAKE_GIF_TAG(0,1,1,0xC|0x10,0,3);
|
|
|
|
vuGIFtag[1] = 0x412;
|
2015-01-28 20:15:49 +00:00
|
|
|
vuMatcolor[0] = color[0]/255.0f;
|
|
|
|
vuMatcolor[1] = color[1]/255.0f;
|
|
|
|
vuMatcolor[2] = color[2]/255.0f;
|
|
|
|
vuMatcolor[3] = color[3]/2.0f/255.0f;
|
2015-06-18 22:05:37 +01:00
|
|
|
// only when modulating textures actually
|
|
|
|
vuMatcolor[0] /= 2.0f;
|
|
|
|
vuMatcolor[1] /= 2.0f;
|
|
|
|
vuMatcolor[2] /= 2.0f;
|
2015-01-25 21:27:03 +00:00
|
|
|
if(rw::skinGlobals.offset && skin){
|
2015-01-18 18:35:23 +00:00
|
|
|
geometryCall[3] = 0x020000DC;
|
|
|
|
mpgCall[1] = (uint32)skinPipe;
|
|
|
|
}else{
|
|
|
|
geometryCall[3] = 0x02000114;
|
|
|
|
mpgCall[1] = (uint32)defaultPipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_REG32(D1_QWC, 0x00);
|
|
|
|
SET_REG32(D1_TADR, (uint)MyDmaPacket & 0x0FFFFFFF);
|
|
|
|
FlushCache(0);
|
|
|
|
SET_REG32(D1_CHCR, MAKE_DN_CHCR(1, 1, 0, 1, 0, 1));
|
|
|
|
DMA_WAIT(D1_CHCR);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
draw(void)
|
|
|
|
{
|
|
|
|
Matrix m;
|
|
|
|
static float rot = 0.0f;
|
|
|
|
|
|
|
|
gsClear();
|
|
|
|
|
2015-01-28 20:15:49 +00:00
|
|
|
matMakeIdentity(viewMat);
|
|
|
|
// matTranslate(viewMat, 0.0f, 0.0f, -34.0f);
|
|
|
|
// matTranslate(viewMat, 0.0f, 0.0f, -10.0f);
|
|
|
|
matTranslate(viewMat, 0.0f, 0.0f, -8.0f);
|
|
|
|
matRotateX(viewMat, rot);
|
|
|
|
matRotateY(viewMat, rot);
|
|
|
|
matRotateZ(viewMat, rot);
|
2015-01-18 18:35:23 +00:00
|
|
|
|
2015-01-28 20:15:49 +00:00
|
|
|
matCopy(vuMat, projMat);
|
|
|
|
matMult(vuMat, viewMat);
|
2015-01-18 18:35:23 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < clump->numAtomics; i++){
|
|
|
|
char *name = PLUGINOFFSET(char, clump->atomicList[i]->frame,
|
2015-01-25 21:27:03 +00:00
|
|
|
gta::nodeNameOffset);
|
2015-01-18 18:35:23 +00:00
|
|
|
if(strstr(name, "_dam") || strstr(name, "_vlo"))
|
|
|
|
continue;
|
|
|
|
matCopy(m, vuMat);
|
|
|
|
drawAtomic(clump->atomicList[i]);
|
|
|
|
matCopy(vuMat, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
rot += 0.01f;
|
|
|
|
if(rot > 2*M_PI)
|
|
|
|
rot -= 2*M_PI;
|
|
|
|
}
|
|
|
|
|
2015-06-18 22:05:37 +01:00
|
|
|
GIF_DECLARE_PACKET(gifDmaBuf2, 256)
|
|
|
|
|
|
|
|
uint32
|
|
|
|
uploadTGA(rw::Image *tga)
|
|
|
|
{
|
|
|
|
GsState *g = gsCurState;
|
|
|
|
uint32 destAddr = g->currentMemPtr;
|
|
|
|
uint32 size = tga->width*tga->height*4;
|
|
|
|
g->currentMemPtr += size;
|
|
|
|
|
|
|
|
printf("image @ %x\n", destAddr);
|
|
|
|
|
|
|
|
GIF_BEGIN_PACKET(gifDmaBuf2);
|
|
|
|
GIF_TAG(gifDmaBuf2, 4, 1, 0, 0, 0, 1, 0x0e);
|
|
|
|
GIF_DATA_AD(gifDmaBuf2, GS_BITBLTBUF,
|
|
|
|
MAKE_GS_BITBLTBUF(0, 0, 0,
|
|
|
|
destAddr/4/64, tga->width/64, PSMCT32));
|
|
|
|
GIF_DATA_AD(gifDmaBuf2, GS_TRXPOS,
|
|
|
|
MAKE_GS_TRXPOS(0, 0, 0, 0, 0));
|
|
|
|
GIF_DATA_AD(gifDmaBuf2, GS_TRXREG,
|
|
|
|
MAKE_GS_TRXREG(tga->width, tga->height));
|
|
|
|
GIF_DATA_AD(gifDmaBuf2, GS_TRXDIR, 0);
|
|
|
|
GIF_SEND_PACKET(gifDmaBuf2);
|
|
|
|
|
|
|
|
GIF_BEGIN_PACKET(gifDmaBuf2);
|
|
|
|
GIF_TAG(gifDmaBuf2, size/0x10, 1, 0, 0, 2, 0, 0);
|
|
|
|
GIF_SEND_PACKET(gifDmaBuf2);
|
|
|
|
|
|
|
|
FlushCache(0);
|
|
|
|
SET_REG32(D2_QWC, MAKE_DN_QWC(size/0x10));
|
|
|
|
SET_REG32(D2_MADR, MAKE_DN_MADR(tga->pixels, 0));
|
|
|
|
SET_REG32(D2_CHCR, MAKE_DN_CHCR(1, 0, 0, 0, 0, 1));
|
|
|
|
DMA_WAIT(D2_CHCR);
|
|
|
|
|
|
|
|
int logw = 0, logh = 0;
|
|
|
|
int s;
|
|
|
|
for(s = 1; s < tga->width; s *= 2)
|
|
|
|
logw++;
|
|
|
|
for(s = 1; s < tga->height; s *= 2)
|
|
|
|
logh++;
|
|
|
|
|
|
|
|
GIF_BEGIN_PACKET(gifDmaBuf2);
|
|
|
|
GIF_TAG(gifDmaBuf2, 3, 1, 0, 0, 0, 1, 0x0e);
|
|
|
|
GIF_DATA_AD(gifDmaBuf2, GS_TEXFLUSH, 1);
|
|
|
|
GIF_DATA_AD(gifDmaBuf2, GS_TEX0_1,
|
|
|
|
MAKE_GS_TEX0(destAddr/4/64, tga->width/64, PSMCT32,
|
|
|
|
logw, logh, 0, 0, 0, 0, 0, 0, 0));
|
|
|
|
GIF_DATA_AD(gifDmaBuf2, GS_TEX1_1,
|
|
|
|
MAKE_GS_TEX1(0, 0, 1, 1, 0, 0, 0));
|
|
|
|
GIF_SEND_PACKET(gifDmaBuf2);
|
|
|
|
|
|
|
|
return destAddr;
|
|
|
|
}
|
|
|
|
|
2015-01-18 18:35:23 +00:00
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
GsState gss;
|
|
|
|
gsCurState = &gss;
|
|
|
|
|
|
|
|
dmaReset(1);
|
|
|
|
|
|
|
|
// gsInitState(NONINTERLACED, PAL, FRAME);
|
|
|
|
// gsInitState(INTERLACED, PAL, FRAME);
|
|
|
|
gsInitState(INTERLACED, PAL, FIELD);
|
|
|
|
gsCurState->clearcol = 0x80404040;
|
|
|
|
|
|
|
|
gsInit();
|
|
|
|
|
2015-01-26 19:23:45 +00:00
|
|
|
gta::registerEnvSpecPlugin();
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::registerMatFXPlugin();
|
2015-01-26 19:23:45 +00:00
|
|
|
rw::registerMaterialRightsPlugin();
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::registerAtomicRightsPlugin();
|
2015-01-26 19:23:45 +00:00
|
|
|
rw::registerHAnimPlugin();
|
2015-01-25 21:27:03 +00:00
|
|
|
gta::registerNodeNamePlugin();
|
|
|
|
gta::registerBreakableModelPlugin();
|
|
|
|
gta::registerExtraVertColorPlugin();
|
|
|
|
rw::ps2::registerADCPlugin();
|
|
|
|
rw::registerSkinPlugin();
|
|
|
|
rw::registerNativeDataPlugin();
|
2015-01-26 19:23:45 +00:00
|
|
|
// rw::ps2::registerNativeDataPlugin();
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::registerMeshPlugin();
|
|
|
|
|
2015-06-18 22:05:37 +01:00
|
|
|
rw::uint32 len;
|
|
|
|
rw::uint8 *data = rw::getFileContents("host:player-vc-ps2.dff", &len);
|
|
|
|
// rw::uint8 *data = rw::getFileContents("host:od_newscafe_dy-ps2.dff", &len);
|
|
|
|
// rw::uint8 *data = rw::getFileContents("host:admiral-ps2.dff", &len);
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::StreamMemory in;
|
2015-01-18 18:35:23 +00:00
|
|
|
in.open(data, len);
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::findChunk(&in, rw::ID_CLUMP, NULL, NULL);
|
|
|
|
clump = rw::Clump::streamRead(&in);
|
2015-01-18 18:35:23 +00:00
|
|
|
in.close();
|
|
|
|
delete[] data;
|
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
data = new rw::uint8[256*1024];
|
|
|
|
rw::StreamMemory out;
|
2015-01-18 18:35:23 +00:00
|
|
|
out.open(data, 0, 256*1024);
|
|
|
|
clump->streamWrite(&out);
|
|
|
|
// cf = fopen("host:out-ps2.dff", "wb");
|
|
|
|
// assert(cf != NULL);
|
|
|
|
// fwrite(data, out.getLength(), 1, cf);
|
|
|
|
// fclose(cf);
|
|
|
|
out.close();
|
|
|
|
delete[] data;
|
|
|
|
|
2015-06-18 22:05:37 +01:00
|
|
|
rw::Image *tga = rw::readTGA("host:player_.tga");
|
|
|
|
printf("read tga\n");
|
|
|
|
|
|
|
|
uint32 destAddr = uploadTGA(tga);
|
|
|
|
/*
|
|
|
|
rw::writeTGA(tga, "host:out.tga");
|
|
|
|
printf("wrote tga\n");
|
|
|
|
*/
|
|
|
|
|
2015-01-18 18:35:23 +00:00
|
|
|
|
|
|
|
vuOffset[0] = 2048.0f;
|
|
|
|
vuOffset[1] = 2048.0f;
|
|
|
|
|
|
|
|
for(int i = 0; i < clump->numAtomics; i++){
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::Atomic *a = clump->atomicList[i];
|
2015-01-18 18:35:23 +00:00
|
|
|
char *name =
|
2015-01-25 21:27:03 +00:00
|
|
|
PLUGINOFFSET(char, a->frame, gta::nodeNameOffset);
|
2015-01-18 18:35:23 +00:00
|
|
|
printf("%s\n", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// gsDumpState();
|
|
|
|
|
|
|
|
// matPerspective(mathProjectionMat, 60.0f, (float)gss.width/gss.height,
|
|
|
|
// matPerspective(mathProjectionMat, 60.0f, (float)gss.width/gss.dh,
|
|
|
|
// matPerspective(mathProjectionMat, 60.0f, 4.0/3.0, 1.0f, 100.0f);
|
|
|
|
// matPerspective(mathProjectionMat, 60.0f, 16.0/9.0, 1.0f, 100.0f);
|
2015-01-28 20:15:49 +00:00
|
|
|
matPerspective2(projMat, 60.0f, 4.0/3.0, gss.width,gss.height,
|
2015-01-18 18:35:23 +00:00
|
|
|
1.0f, 100.0f, 16777216, 1);
|
|
|
|
|
|
|
|
for(;;){
|
|
|
|
draw();
|
|
|
|
gsFlip();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|