BY: ourumov DATE: 2004-Jun-21 12:30 SUBJECT: SPS2 Newbie - ASE LoaderHi, after reading and understanding the first two tutorials (Path3/DMA tutorials) I decided to begin the adventure of coding sth.
Using some old classes I had for an old OGL Project I decided to load an ASE model and display it.
Everything ran fine till I decided to display the model on screen and I would like to know what's the problem since I am sure it's sth I am doing on wrong with DMA transfers. Here comes the code:
#undef DEBUG_DMA
#include <stdio.h>
#include <math.h>
#include <signal.h>
#include "dmavif1.h"
#include "screen.h"
#include <geommath/geommath.h>
#include "camera.h"
#include "p2lassert.h"
/*------------------------*/
#include "point.h"
#include "color.h"
#include "text.h"
/*------------------------*/
int loop_again=1;
point *vertexs;
int *cares;
int num_cares;
int num_vertexs;
// this is executed when ctrl-c is pressed, ideally it stops the loop.
// the deinit functions have to be at the end of the main after the loop.
void sig_handle(int sig)
{
loop_again=0;
}
// distribute sps2 specific global pointers to relevant classes
void DistribGlobPtrs(void * pDescCached, void * pDescUncached)
{
CDmaWrap::m_pDescCached = (sps2Memory_t *) pDescCached;
CDmaWrap::m_pDescUncached = (sps2Memory_t *) pDescUncached;
}
// labels for vu1 dummy-code
extern "C" void VU_vu1dummy_start(void);
extern "C" void VU_vu1dummy_end(void);
int iSPS2Device;
CScreen *cScreen=NULL;
void delete_screen()
{
if (cScreen!=NULL) delete cScreen;
cScreen=NULL;
}
void preload(){
text t;
t.create("./model_ase.ASE");
//Ara procedim a buscar el tamany de tot
t.seek("*MESH_NUMVERTEX");
num_vertexs=t.getint();
t.seek("*MESH_NUMFACES");
num_cares=t.getint();
vertexs=new point[num_vertexs];
cares=new int[num_cares*3];
t.reset();
int i;
i=0;
t.reset();
t.seek("*MESH_VERTEX_LIST");
for(i=0;i<num_vertexs;i++)
{
t.seek("*MESH_VERTEX");
t.getint();
vertexs[i].x=-(double)t.getfloat();
vertexs[i].z=(double)t.getfloat();
vertexs[i].y=(double)t.getfloat();
}
t.reset();
t.seek("*MESH_FACE_LIST");
i=0;
for(i=0;i<num_cares;i++)
{
t.seek("A:");
cares[i*3] = t.getint();
t.seek("B:");
cares[i*3+1]= t.getint();
t.seek("C:");
cares[i*3+2]=t.getint();
t.seek("*MESH_MTLID");
}
}
int main()
{
// Open sps2-library and setup PS2Linux stuff
iSPS2Device = sps2Init();
if (iSPS2Device<0) {
printf("Can't open SPS2 device. Is the module loaded?\n");
exit(-1);
}
preload();
uint32 uAllocDmaMegs = 2;
sps2Memory_t * pDescCached = sps2Allocate(uAllocDmaMegs*1024*1024, SPS2_MAP_BLOCK_4K | SPS2_MAP_CACHED, iSPS2Device);
sps2Memory_t * pDescUncached = sps2Remap(pDescCached, SPS2_MAP_UNCACHED, iSPS2Device);
DistribGlobPtrs(pDescCached, pDescUncached);
void * pAllDmaMem = pDescCached->pvStart;
int iVPU0; iVPU0=open("/dev/ps2vpu0", O_RDWR);
int iVPU1; iVPU1=open("/dev/ps2vpu1", O_RDWR);
for(int sig=0; sig<128; sig++) // catch as many signals as possible
signal(sig, sig_handle);
// Setup Screen
cScreen=new CScreen;
atexit(delete_screen);
cScreen->ScreenSetup();
// Setup a Camera
float fScrWdth = cScreen->GetWidth();
float fScrHgt = cScreen->GetHeight();
float fDepthZ = cScreen->GetDepth();
CCamera cCam;
cCam.SetBitmapSize(fScrWdth, -fScrHgt, fDepthZ);
cCam.SetViewPortOffset(2048, 2048, fDepthZ);
cCam.SetClipPlanes(-10, -10000);
cCam.SetEyePos(Vec3(0,0,1));
float fFov = 0.524f; // total view of 60 degrees
float fMinU = -tanf(fFov);
float fMinV = (fMinU*3)/4;
cCam.SetBoundVRC(fMinU, fMinV, -fMinU, -fMinV);
cCam.SetPosViewPlane(Vec3(0,0,600));
cCam.SetRotViewPlane(Vec3(0,0,1), Vec3(0,1,0));
// Flush Cache
sps2FlushCache(iSPS2Device);
while(loop_again)
{
// tmp
// static uint32 uVal = 0;
/* CDmaVif1 dmaVif1(pAllDmaMem, 11);
dmaVif1.AttachSrcEndTag(DIRECT(10)<<32);
uint32 nloop = 9;
uint32 uPrim = PRIM_SET(3,1,0,0,0,0,0,0,0);
dmaVif1.add64(GIFTAG(nloop, 1, 1, uPrim, 0, 1));
dmaVif1.add64(GIFTAG_REGS1(AD));
//S'envien els 3 včrtexs
dmaVif1.add64(ST_SET(0,0));
dmaVif1.add64(ST);
dmaVif1.add64(RGBAQ_SET(127,0,0,0,0x3f800000));
dmaVif1.add64(RGBAQ);
dmaVif1.add64(XYZ2_SET((-126+2048+uVal)*16,(-60+2048)*16, 500));
dmaVif1.add64(XYZ2);
dmaVif1.add64(ST_SET(0,0x3f800000));
dmaVif1.add64(ST);
dmaVif1.add64(RGBAQ_SET(0,127,0,0,0x3f800000));
dmaVif1.add64(RGBAQ);
dmaVif1.add64(XYZ2_SET((160+2048+uVal)*16,(-50+2048)*16, 500));
dmaVif1.add64(XYZ2);
dmaVif1.add64(ST_SET(0x3f800000,0));
dmaVif1.add64(ST);
dmaVif1.add64(RGBAQ_SET(0,0,127,0,0x3f800000));
dmaVif1.add64(RGBAQ);
dmaVif1.add64(XYZ2_SET((-150+2048)*16,(120+2048)*16, 500));
dmaVif1.add64(XYZ2);
uVal = (uVal+1)%20;
dmaVif1.EndPacket();
dmaVif1.Launch(iSPS2Device);
dmaVif1.Wait();
*/
int i=0;
// int j=0;
for(i=0;i<num_cares;i++)
{
CDmaVif1 dmaVif1(pAllDmaMem, 11);
dmaVif1.AttachSrcEndTag(DIRECT(10)<<32);
uint32 nloop = 9;
uint32 uPrim = PRIM_SET(3,1,0,0,0,0,0,0,0);
dmaVif1.add64(GIFTAG(nloop, 1, 1, uPrim, 0, 1));
dmaVif1.add64(GIFTAG_REGS1(AD));
// printf("%d %d %d\n",(int)(vertexs+cares[i*3+0])->x,(int)(vertexs+cares[i*3+0])->y,500+(int)(vertexs+cares[i*3+0])->z);
//S'envien els 3 včrtexs
dmaVif1.add64(ST_SET(0,0));
dmaVif1.add64(ST);
dmaVif1.add64(RGBAQ_SET(127,0,0,0,0x3f800000));
dmaVif1.add64(RGBAQ);
// dmaVif1.add64(XYZ2_SET((-126+2048+uVal)*16,(-60+2048)*16, 500));
dmaVif1.add64(XYZ2_SET((vertexs+cares[i*3+0])->x,(vertexs+cares[i*3+0])->y,5000+(vertexs+cares[i*3+0])->z));
dmaVif1.add64(XYZ2);
dmaVif1.add64(ST_SET(0,0));
dmaVif1.add64(ST);
dmaVif1.add64(RGBAQ_SET(127,0,0,0,0x3f800000));
dmaVif1.add64(RGBAQ);
// dmaVif1.add64(XYZ2_SET((-126+2048+uVal)*16,(-60+2048)*16, 500));
dmaVif1.add64(XYZ2_SET((vertexs+cares[i*3+1])->x,(vertexs+cares[i*3+1])->y,5000+(vertexs+cares[i*3+1])->z));
dmaVif1.add64(XYZ2);
dmaVif1.add64(ST_SET(0,0));
dmaVif1.add64(ST);
dmaVif1.add64(RGBAQ_SET(127,0,0,0,0x3f800000));
dmaVif1.add64(RGBAQ);
// dmaVif1.add64(XYZ2_SET((-126+2048+uVal)*16,(-60+2048)*16, 500));
dmaVif1.add64(XYZ2_SET((vertexs+cares[i*3+2])->x,(vertexs+cares[i*3+2])->y,5000+(vertexs+cares[i*3+2])->z));
dmaVif1.add64(XYZ2);
dmaVif1.EndPacket();
dmaVif1.Launch(iSPS2Device);
dmaVif1.Wait();
}
cScreen->Swap();
}
return 0;
}
|