Code: Select all
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <pspgu.h>
PSP_MODULE_INFO("Line Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
static unsigned int __attribute__((aligned(16))) list[262144];
struct Vertex
{
float x,y,z;
};
int SetupCallbacks();
int done = 0;
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (2)
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2) /* zbuffer seems to be 16-bit? */
void DrawLine(int x1, int y1, int x2, int y2);
void InitGFX();
void Render();
void DrawLine(int x1, int y1, int x2, int y2)
{
unsigned char r=255,b=0,g=0;
unsigned short Color;
Color=((b>>3)<<10) | ((g>>3)<<5) | (r>>3) | 0x8000;
sceGuColor(Color);
struct Vertex* vertices = sceGuGetMemory((2) * sizeof(struct Vertex));
vertices[0].x = x1;
vertices[0].y = y1;
vertices[1].x = x2;
vertices[1].y = y2;
sceGuDrawArray(GU_LINE_STRIP,GU_VERTEX_32BITF|GU_TRANSFORM_2D,(2),0,vertices);
}
void InitGFX()
{
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_5551,(void*)0,BUF_WIDTH);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)FRAME_SIZE,BUF_WIDTH);
sceGuDepthBuffer((void*)(FRAME_SIZE*2),BUF_WIDTH);
sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
sceGuDepthRange(0xc350,0x2710);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
}
void Render()
{
sceGuStart(GU_DIRECT,list);
// clear screen
sceGuClearColor(0);
sceGuClear(GU_COLOR_BUFFER_BIT);
DrawLine(0,0,240,272);
// wait for next frame
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
int main(int argc, char* argv[])
{
SetupCallbacks();
pspDebugScreenInit();
InitGFX();
while(!done)
{
Render();
}
sceGuTerm();
sceKernelExitGame();
return 0;
}