gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > BoxTest locking up?!?

#124407 - 3D_geek - Thu Apr 05, 2007 8:29 pm

I've got a weird problem going on here. I'm rendering a bunch of objects in 3D - doing a libnds BoxTest() call for each object so I don't draw it if it's off-screen. Once in a while, BoxTest will lock up and never return (there is a 'while(GFX_STATUS&BIT(0));' loop that it's stuck in).

Noodling around in the BoxTest source:
Code:

int BoxTest(v16 x, v16 y, v16 z, v16 height, v16 width, v16 depth)
{
  glPolyFmt(BIT(12) | BIT(13));
  glBegin(GL_TRIANGLES);
  glEnd();
  GFX_BOX_TEST = VERTEX_PACK(x, y);
  GFX_BOX_TEST = VERTEX_PACK(z, height);
  GFX_BOX_TEST = VERTEX_PACK(width, depth);
  while(GFX_STATUS & BIT(0));
  return (GFX_STATUS & BIT(1));
}

The 'while' loop is waiting on "BoxTest,PositionTest,VectorTest Busy (0=Ready, 1=Busy)' - which seems reasonable.

In desperation, I stuck an iprintf into the function to see that the contents of the GFX_STATUS register is immediately after the 'glEnd()' call is usually 0x0600A*0$ (where '*' is 1,2, 3 or 4 and '$' is 0 or 2). But on the times the call locks up, it's 0x0E00A100. The difference is in bit 26. which is 'Command FIFO Empty'...so BoxTest locks up when the command FIFO is empty?!?!?

According to http://nocash.emubase.de/gbatek.htm#ds3dstatus bits 24 to 27 are:
Code:

  24   Command FIFO Full (MSB of above)  (0=No, 1=Yes; Full)
  25   Command FIFO Less Than Half Full  (0=No, 1=Yes; Less than Half-full)
  26   Command FIFO Empty                (0=No, 1=Yes; Empty)
  27   Geometry Engine Busy (0=No, 1=Yes; Busy; Commands are executing)

...meaning that when everything works OK, the Geometry engine is busy (not surprising) and the Command FIFO is not full, it is less than half full but it's not empty. On the occasions the command locks up, the Command FIFO is utterly empty.

Why this would make it lock up is beyond me....any clues?