SBSPSS/source/gfx/prim.cpp

172 lines
4.3 KiB
C++
Raw Normal View History

2000-08-29 21:54:22 +02:00
///**********************/
/*** Psx Prim Stuff ***/
/**********************/
#include "system\global.h"
#include "gfx\TPage.h"
#include "gfx\AnimTex.h"
#include "gfx\Prim.h"
#include "system\vid.h"
/*****************************************************************************/
2001-08-13 18:30:57 +02:00
sOT *OtList[2],*OtPtr;
2000-08-29 21:54:22 +02:00
u32 DmaStart[2];
u8 *PrimBuffer[2],*PrimListStart,*PrimListEnd;
u8 *CurrPrim,*EndPrim;
int PrimFlipFlag;
/*****************************************************************************/
void PrimInit()
{
// Alloc Lists
2001-05-02 00:40:25 +02:00
OtList[0]=(sOT*)MemAlloc(OTLIST_SIZE*2, "-Ot-");
2001-08-13 18:30:57 +02:00
OtList[1]=OtList[0]+MAX_OT;
2000-08-29 21:54:22 +02:00
PrimBuffer[0]=(u8*)MemAlloc(PRIMPOOL_SIZE*2, "Prim");
PrimBuffer[1]=PrimBuffer[0]+(PRIMPOOL_SIZE);
PrimFlipFlag=0;
2001-08-13 18:30:57 +02:00
OtPtr=(sOT*)OtList[PrimFlipFlag];
2000-08-29 21:54:22 +02:00
CurrPrim=(u8*)PrimBuffer[PrimFlipFlag];
2001-05-18 18:44:51 +02:00
EndPrim=CurrPrim+PRIMPOOL_SIZE;
2000-08-29 21:54:22 +02:00
PrimListStart=PrimBuffer[0];
PrimListEnd=PrimListStart+(PRIMPOOL_SIZE*2);
2001-08-13 18:30:57 +02:00
InitOTagR(OtList[0],MAX_OT);
InitOTagR(OtList[1],MAX_OT);
2001-01-03 16:48:42 +01:00
2000-08-29 21:54:22 +02:00
}
/*****************************************************************************/
void PrimDisplay()
{
2001-08-13 17:19:03 +02:00
while(DrawSync(1));
2001-05-18 18:44:51 +02:00
if ((int)CurrPrim>=(int)EndPrim)
{
ASSERT(!"PRIM OVERFLOW");
}
2001-01-04 23:12:40 +01:00
CAnimTex::AnimateTex();
2001-05-14 21:40:30 +02:00
CPakTex::DMAPakTex();
2001-08-13 18:30:57 +02:00
UnlinkOTagR(OtPtr, MAX_OT, &DmaStart[PrimFlipFlag]);
2000-08-29 21:54:22 +02:00
#ifdef USE_NTAGS
2001-01-04 22:53:14 +01:00
DrawOTag((u32*)&DmaStart[PrimFlipFlag]);
2000-08-29 21:54:22 +02:00
#else
2001-08-13 18:30:57 +02:00
DrawOTag(OtPtr+(MAX_OT-1));
2000-08-29 21:54:22 +02:00
#endif
PrimFlipFlag^=1;
2001-08-13 18:30:57 +02:00
OtPtr=(sOT*)OtList[PrimFlipFlag];
2000-08-29 21:54:22 +02:00
CurrPrim=(u8*)PrimBuffer[PrimFlipFlag];
EndPrim=CurrPrim+(PRIMPOOL_SIZE);
2001-08-13 18:30:57 +02:00
ResetOTagR(OtPtr,MAX_OT);
2000-08-29 21:54:22 +02:00
}
2001-05-22 20:00:51 +02:00
/*****************************************************************************/
void FlushPrimPool()
{
2001-08-13 18:30:57 +02:00
OtPtr=(sOT*)OtList[PrimFlipFlag];
2001-05-22 20:00:51 +02:00
CurrPrim=(u8*)PrimBuffer[PrimFlipFlag];
EndPrim=CurrPrim+(PRIMPOOL_SIZE);
2001-08-13 18:30:57 +02:00
ResetOTagR(OtPtr,MAX_OT);
2001-05-22 20:00:51 +02:00
}
2000-08-29 21:54:22 +02:00
/*** Clipping ****************************************************************/
void PrimClip(RECT *R, u32 Depth)
{
DR_AREA *CPtr=(DR_AREA*)CurrPrim;
RECT Real;
sVidScreen *Scr=VidGetDrawScreen();
Real=*R;
CurrPrim+=sizeof(DR_AREA);
Real.x+=Scr->Draw.clip.x;
Real.y+=Scr->Draw.clip.y;
2001-06-21 21:19:15 +02:00
int xLimit=VidGetScrW();
int yLimit=((FrameFlipFlag^1)+1)*VidGetScrH();
2000-08-29 21:54:22 +02:00
if(Real.x+Real.w>xLimit)Real.w=xLimit-Real.x;
if(Real.y+Real.h>yLimit)Real.h=yLimit-Real.y;
SetDrawArea(CPtr,&Real);
AddPrimToList(CPtr,Depth);
};
/*---------------------------------------------------------------------------*/
void PrimFullScreen(int Depth)
{
RECT FullScreenRect={0,0,VidGetScrW(),VidGetScrH()};
PrimClip(&FullScreenRect,Depth);
}
/*****************************************************************************/
/*** NTag Functions **********************************************************/
/*****************************************************************************/
#ifdef USE_NTAGS
void ClearNTag(sOT *Ptr, long Count)
{
for (; Count; Ptr++,Count--) Ptr->FirstPrim = NULL;
}
/*****************************************************************************/
void UnlinkNTag(sOT *Ptr, long Count, u32 *StartOt)
{
u32 *Tag;
for (; Count; Ptr++,Count--)
{
if ((Tag = Ptr->FirstPrim) == NULL) continue;
setaddr(StartOt, Tag);
StartOt = Ptr->LastPrim;
Ptr->FirstPrim = NULL; // Reset while Im at it!
}
termPrim(StartOt);
}
/*****************************************************************************/
void UnlinkNTagR(sOT *Ptr, long Count, u32 *StartOt)
{
u32 *Tag;
Ptr+=Count-1;
for (; Count; Ptr--,Count--)
{
if ((Tag = Ptr->FirstPrim) == NULL) continue;
setaddr(StartOt, Tag);
StartOt = Ptr->LastPrim;
Ptr->FirstPrim = NULL; // Reset while Im at it!
}
termPrim(StartOt);
}
2001-04-19 01:04:03 +02:00
#endif
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
LINE_F2 *DrawLine(int _x0,int _y0,int _x1,int _y1,int _r,int _g,int _b,int _ot)
{
LINE_F2 *lf2=GetPrimLF2();
lf2->x0=_x0;
lf2->y0=_y0;
lf2->x1=_x1;
lf2->y1=_y1;
setRGB0(lf2,_r,_g,_b);
AddPrimToList(lf2,_ot);
return lf2;
}
/*****************************************************************************/
LINE_G2 *DrawGLine(int _x0,int _y0,int _x1,int _y1,int _r1,int _g1,int _b1,int _r2,int _g2,int _b2,int _ot)
{
LINE_G2 *lg2=GetPrimLG2();
lg2->x0=_x0;
lg2->y0=_y0;
lg2->x1=_x1;
lg2->y1=_y1;
setRGB0(lg2,_r1,_g1,_b1);
setRGB1(lg2,_r2,_g2,_b2);
AddPrimToList(lg2,_ot);
return lg2;
}
2001-06-11 22:36:53 +02:00
/*****************************************************************************/