Code: Select all
#include <sys/types.h>
#include <libetc.h>
#include <libgte.h>
#include <libgpu.h>
#include <libgs.h>
#include <stdio.h>
#define OT_LENGTH 10
#define PACKETMAX 2048
#define PACKETMAX2 PACKETMAX*24
typedef struct {
float x;
float xMove;
float y;
float yMove;
} CameraStruct;
GsOT myOT[2];
GsOT_TAG myOT_TAG[2][1<<OT_LENGTH];
PACKET GPUPacketArea[2][PACKETMAX2];
int ActiveBuffer=0;
CameraStruct Camera;
#include "tiles.h"
// Prototypes
void init(void);
int main(void);
GsIMAGE LoadTIM(u_long *tMemAddress);
void init(void)
{
// Init 320x240 mode
GsInitGraph(320, 240, GsNONINTER|GsOFSGPU, 1, 0);
// Prepare display buffers
GsDefDispBuff(0, 0, 0, 240);
// Prepare ordering tables
myOT[0].length = OT_LENGTH;
myOT[1].length = OT_LENGTH;
myOT[0].org = myOT_TAG[0];
myOT[1].org = myOT_TAG[1];
GsClearOt(0, 0, &myOT[0]);
GsClearOt(0, 0, &myOT[1]);
// Some more things to set
ResetGraph(0);
SetVideoMode(MODE_NTSC);
SetGraphDebug(0);
// Setup debug font
FntLoad(960, 256);
FntOpen(0, 0, 320, 240, 0, 512);
PadInit(0);
}
int main(void)
{
GsIMAGE tim_info;
GsCELL BGcell[64];
GsMAP BGmap;
GsBG BGparams;
int tx,ty,index;
int PadStatus;
init();
// Load the tiles into the framebuffer
tim_info = LoadTIM((u_long*)&tim_tiles[0]);
// Prepare the cell entries
for (ty=0; ty<8; ty=ty+1)
{
for (tx=0; tx<8; tx=tx+1)
{
index = tx + (8 * ty);
BGcell[index].u = 16 * tx;
BGcell[index].v = 16 * ty;
BGcell[index].cba = GetClut(tim_info.cx, tim_info.cy);
BGcell[index].flag = 0;
BGcell[index].tpage = GetTPage((tim_info.pmode & 3), 0, tim_info.px, tim_info.py);
};
};
// Setup a 1x1 tile map
BGmap.cellw = 16;
BGmap.cellh = 16;
BGmap.ncellw = 1;
BGmap.ncellh = 1;
BGmap.base = &BGcell[0]; // Only seems to take tile 3 instead of 0
BGmap.index = 0;
// Setup struct for GsSortBg
BGparams.attribute = (tim_info.pmode & 3) << 24;
BGparams.x = 0;
BGparams.y = 0;
BGparams.w = 320;
BGparams.h = 240;
BGparams.scrollx = BGparams.scrolly = 0;
BGparams.r = BGparams.g = BGparams.b = 128;
BGparams.map = &BGmap;
BGparams.mx = 0;
BGparams.my = 0;
BGparams.scalex = BGparams.scaley = ONE;
BGparams.rotate = 0;
// Setup camera
Camera.x = 0;
Camera.xMove = 0;
Camera.y = 0;
Camera.yMove = 0;
while (1)
{
// Prepare the display buffer for drawing
ActiveBuffer = GsGetActiveBuff();
GsSetWorkBase((PACKET*)GPUPacketArea[ActiveBuffer]);
GsClearOt(0, 0, &myOT[ActiveBuffer]);
// Do controls
PadStatus = PadRead(0);
if (PadStatus & PADLup)
Camera.yMove = Camera.yMove - 0.8f;
if (PadStatus & PADLdown)
Camera.yMove = Camera.yMove + 0.8f;
if (PadStatus & PADLleft)
Camera.xMove = Camera.xMove - 0.8f;
if (PadStatus & PADLright)
Camera.xMove = Camera.xMove + 0.8f;
// Handle camera coords
Camera.x = Camera.x + Camera.xMove;
Camera.y = Camera.y + Camera.yMove;
Camera.xMove = Camera.xMove * 0.8f;
Camera.yMove = Camera.yMove * 0.8f;
// Sort the BG
BGparams.scrollx = Camera.x;
BGparams.scrolly = Camera.y;
GsSortBg(&BGparams, &myOT[ActiveBuffer], 0);
// Display the crap
FntFlush(-1);
DrawSync(0);
VSync(0);
// Then swap display buffers
GsSwapDispBuff();
GsSortClear(0, 0, 0, &myOT[ActiveBuffer]);
GsDrawOt(&myOT[ActiveBuffer]);
};
}
GsIMAGE LoadTIM(u_long *tMemAddress)
{
RECT tRect;
GsIMAGE tTim;
DrawSync(0);
tMemAddress++;
GsGetTimInfo(tMemAddress, &tTim); // SAVE TIM-Info in TIM
tRect.x = tTim.px;
tRect.y = tTim.py;
tRect.w = tTim.pw;
tRect.h = tTim.ph;
LoadImage(&tRect, tTim.pixel); // Load TIM-DATA into VideoRam
DrawSync(0);
if ((tTim.pmode >> 3) & 0x01)
{
tRect.x = tTim.cx;
tRect.y = tTim.cy;
tRect.w = tTim.cw;
tRect.h = tTim.ch;
LoadImage(&tRect, tTim.clut); // load CLUT into VideoRam
}
DrawSync(0); // wait until GPU is ready
return tTim;
}
Any help will be appreciated...
- Lameguy64