SPS2 - Direct PS2 Access Environment - Forums


Summary |  Forums |  Bugs |  News |  Source |  Files | 

Discussion Forums: Developers

Admin

Message: 45290
BY: ironchimp
DATE: 2004-Aug-30 12:31
SUBJECT: bus error? seems random....

erm. this code has done me stead for most of the past week, however all of a sudden, it gives me a bus error somwhere in this function.

I'll post it, and leave it for you ppl to ponder while i busy over it all night. hopefully, one of us will find a solution :)

Bit of a background :

'pdl' stands for 'Pauls Drawing library' and is a kind of wrapper for all of my 3d stuf that i've ben doing on vu1. this is the init function for it. its a bit of a mess atm cause i've been trying to fix it.

the bus errot happens somewhre betweeen sending the QW of data to VIF1, and the camera object being created.

commented like a true n00b, it sould be fairly self explanitor what i'm doing.

basically, i'm asking if i'm doing anything silly here? a pair of fresh eyes can spot things easy than mine ;)


----- begin code -----


int pdlSetup(int drawMemK, float viewW, float viewH, float fov, float aspect, float near, float far)
{
pdl_PostMessage("Setting up DrawManager");

// open sps2.
if( (pdl_sps2ID = sps2Init()) < 0)
{
printf("Error Initialising sps2\n");
exit(-1);
}

// open both VU's
pdl_VPU0=open("/dev/ps2vpu0", O_RDWR);
pdl_VPU1=open("/dev/ps2vpu1", O_RDWR);

// if sps2Memory has beenallocated, delete it
if(pdl_drawMemory != NULL) sps2Free(pdl_drawMemory);

// allocate the sps2 memory and validate
pdl_drawMemory = sps2Allocate(KILOBYTES(drawMemK), SPS2_MAP_BLOCK_4K | SPS2_MAP_CACHED, pdl_sps2ID);

// check if memory was allocated
if(pdl_drawMemory == NULL)
{
pdl_PostMessage("Could Not allocate Drawing Memory of Size %d - Exiting", KILOBYTES(drawMemK));
exit(-1);
}

// initialize the screen
sps2UScreenInit(0);

// clear the screen - remove that blue bit that annoys me!
sps2UScreenClear(0,0,0);

printf("screen cleared\n");

pdl_screenWidth = sps2UScreenGetWidth();
pdl_screenHeight = sps2UScreenGetHeight();

// setup the dma transfer registers
pdl_tadr.i32 = 0;

// set the CHCR to NORMAL for sending some init commands to VIF1

pdl_chcr.i32 = 0;
pdl_chcr.s.MOD = CHCR_MOD_NORMAL;
pdl_chcr.s.DIR = 1;
pdl_chcr.s.TTE = 0;
pdl_chcr.s.STR = 1;


// grab the pointer to the first QW in allocated Memory
sps2uint64 * pTmp = (sps2uint64 *)pdl_drawMemory->pvStart;
// set the offset to 511, and the base to 0. fill the first 64 bits with NOP's
*pTmp = VIF_NOP << 32 | VIF_NOP;
++pTmp;
*pTmp = VIF_OFFSET(511) << 32 | VIF_BASE(0);
sps2FlushCache(pdl_sps2ID);

printf("sending base and offset\n");
// sending 1QW
*EE_D1_QWC = 1;

// grab the address of the QW
*EE_D1_MADR = sps2GetPhysicalAddress(pdl_drawMemory->pvStart, pdl_drawMemory);

// BAM! send that bad boy
*EE_D1_CHCR = pdl_chcr.i32;

printf("sent\n");

// now set the CHCR to the chain mode :)
pdl_chcr.i32 = 0;
pdl_chcr.s.MOD = CHCR_MOD_CHAIN;
pdl_chcr.s.DIR = 1;
pdl_chcr.s.TTE = 1;
pdl_chcr.s.STR = 1;


// initialize the font system
//InitFont(KILOBYTES(16));

// generate the 3d transformation matricies etc
pdl_vs = GenerateVSTransform(fov, aspect, near, far);

printf("Getting offsetts\n");
int xOff = (int)(2048 - (pdl_screenWidth*0.5f));
int yOff = (int)(2048 - (pdl_screenHeight*0.5f));

printf("generating vtt\n");
pdl_vt = GenerateVTTransform(viewW, viewH, xOff+(viewW*0.5f), yOff+(viewH*0.5f), PDL_NUM_RESERVED_DEPTHS);

printf("generating cam\n");
pdl_cam = Camera(0,0,0,0,0,1,0,1,0); // default camera - at the origin loking along +z. up is Y axis

printf("setting vertex modes to default\n");
// set the vertexmode. default is model.
pdl_vertexMode = pdl_prevMode = PDL_MODEL;

printf("NULLing pointers\n");
// nullify stray pointers
pdl_pMem = NULL;
pdl_pGTag = NULL;

//reset the matrix stack pointers to point to the beginning
pdl_stackID[0] = pdl_stackID[1] = 0;
pdl_currentMatrix = PDL_STACK_MODEL;

// reset all stack entries to the identity
for(int i=0; i< PDL_MATRIX_STACK_SIZE; i++)
{
pdl_stack[0][i].SetIdentity();
pdl_stack[1][i].SetIdentity();
}

// set teh LIGHTs to standard values
for(int i=0; i<4; i++)
{
pdl_light_pos[i].f[0] = pdl_light_pos[i].f[1] = pdl_light_pos[i].f[2] = pdl_light_pos[i].f[3] = 0;
pdl_light_col[i].f[0] = pdl_light_col[i].f[1] = pdl_light_col[i].f[2] = pdl_light_col[i].f[3] = 128.0f;
}

// set the colour to normal stuff, and the normal as well and the uv coords
pdl_colour.f[0] = pdl_colour.f[1] = pdl_colour.f[2] = pdl_colour.f[3] = 128;
pdl_normal.f[0] = pdl_normal.f [3] = 1.0f;

pdl_texture_uv.i =0;
pdl_settings = pdl_loop = 0;

printf("waiting for dma to finish\n");
// wait for the transfer to stop - we don;t know how the memory will be moved to MicroMem
sps2WaitForDMA(1, pdl_sps2ID);
// calculate the length of the code in DW's

printf("calculating program size\n");
int CodeLength = ((((int)VU_pdl_vcl_end - (int)VU_pdl_vcl_start) +7)>>3);

printf("loading vu1 program\n");
// copy the program to Micro Mem
memcpy(VU1_MICRO_MEM, &VU_pdl_vcl_start, CodeLength *8);


printf("finished loading pdl\n");
// return the sps2 handle to the calling function. they may want it
return pdl_sps2ID;
}


 

Thread View

Thread Author Date
bus error? seems random....ironchimp2004-Aug-30 12:31
      RE: bus error? seems random....ironchimp2004-Aug-30 12:39
      RE: bus error? seems random....sauce2004-Aug-30 21:12
            RE: bus error? seems random....ironchimp2004-Aug-31 01:58
      eh?ironchimp2004-Aug-31 07:34
      RE: bus error? seems random....lordbosh2005-Feb-13 04:22

 

Post a followup to this message

You could post if you were [logged in]