Here's the code I got so far in main.c
Code: Select all
#include <stdio.h>
#include <sys/types.h>
#include <psxetc.h>
#include <psxgte.h>
#include <psxgpu.h>
#include <psxpad.h>
#include <psxapi.h>
// Define display/draw environments for double buffering
DISPENV disp[2];
DRAWENV draw[2];
int i,db;
char pribuff[2][65536];
uint32_t ot[2][1];
char *nextpri;
int db = 0;
typedef struct {
short x,y;
unsigned char r,g,b;
} TIPO_OBJETO;
TIPO_OBJETO jugador;
extern const uint32_t circulo16c[];
extern u_long background[];
TIM_IMAGE tim[2];
// Init function
void init(void)
{
// This not only resets the GPU but it also installs the library's
// ISR subsystem to the kernel
ResetGraph(0);
// Define display environments, first on top and second on bottom
SetDefDispEnv(&disp[0], 0, 0, 320, 240);
//SetDefDispEnv(&disp[1], 0, 240, 320, 240);
// Define drawing environments, first on bottom and second on top
SetDefDrawEnv(&draw[0], 0, 0, 320, 240);
//SetDefDrawEnv(&draw[1], 0, 0, 320, 240);
disp[0].isinter = 1;
// Set and enable clear color
//setRGB0(&draw[0], 128, 96, 0);
//setRGB0(&draw[1], 128, 96, 0);
//draw[0].isbg = 1;
//draw[0].dtd = 1;
// Clear double buffer counter
db = 0;
// Apply the GPU environments
PutDispEnv(&disp[db]);
PutDrawEnv(&draw[db]);
// Load test font
FntLoad(960, 0);
// Open up a test font text stream of 100 characters
FntOpen(0, 8, 320, 224, 0, 100);
//SetDispMask( 1 );
GetTimInfo(circulo16c, &tim[0]);
GetTimInfo(background, &tim[1]);
for (i=1;i>=0;i--)
{
LoadImage(tim[i].prect, tim[i].paddr);
if( tim[i].mode & 0x8 ) LoadImage(tim[i].crect, tim[i].caddr);
}
jugador.x = 50;
jugador.y = 50;
jugador.r = 150;
jugador.g = 100;
jugador.b = 200;
}
// Display function
void display(void)
{
// Flip buffer index
//db = !db;
// Wait for all drawing to complete
DrawSync(0);
// Wait for vertical sync to cap the logic to 60fps (or 50 in PAL mode)
// and prevent screen tearing
VSync(0);
// Switch pages
PutDispEnv(&disp[db]);
PutDrawEnv(&draw[0]);
// Enable display output, ResetGraph() disables it by default
//SetDispMask(1);
}
// Main function, program entrypoint
int main(int argc, const char *argv[])
{
SPRT_16 *sprt;
DR_TPAGE *tpri;
int i,counter=0;
uint8_t pad_buff[2][34];
InitPAD(pad_buff[0], 34, pad_buff[1], 34);
StartPAD();
ChangeClearPAD(0);
// Init stuff
init();
while(1)
{
SetDispMask( 1 );
PADTYPE *pad = (PADTYPE *) pad_buff[0];
ClearOTagR( ot[db], 1 );
nextpri = pribuff[db];
sprt = (SPRT_16*)nextpri;
setSprt16( sprt );
setXY0( sprt, jugador.x, jugador.y );
setRGB0( sprt, jugador.r, jugador.g, jugador.b );
setUV0( sprt, 0, 0 );
setClut( sprt, tim[0].crect->x, tim[0].crect->y );
addPrim( ot[db], sprt );
sprt++;
if (!(pad->btn & PAD_LEFT)) jugador.x--;
if (!(pad->btn & PAD_RIGHT)) jugador.x++;
if (!(pad->btn & PAD_UP)) jugador.y--;
if (!(pad->btn & PAD_DOWN)) jugador.y++;
nextpri = (char*)sprt;
tpri = (DR_TPAGE*)nextpri;
setDrawTPage( tpri, 0, 0,
getTPage(0, 0, tim[0].prect->x, tim[0].prect->y ));
addPrim( ot[db], tpri );
nextpri += sizeof(DR_TPAGE);
// Print the obligatory hello world and counter to show that the
// program isn't locking up to the last created text stream
FntPrint(-1, "HOLA, SOY OSCARIN VALDEZ\n");
FntPrint(-1, "COUNTER=%d\n", counter);
// Draw the last created text stream
FntFlush(-1);
//DrawSync( 0 );
//VSync( 0 );
// Update display
display();
//PutDrawEnv( &draw[0] );
DrawOTag( ot[db] );
db = !db;
// Increment the counter
//counter++;
}
return 0;
}