#include <pspdisplay.h>
#include <pspctrl.h> // Allows us to read input from the PSP's keys
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h> // <Manipulate the PNG Image files
#include <stdio.h> // Has some C functions (sprintf() to parse strings)
#include <graphics.h>
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
#define printf pspDebugScreenPrintf
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) // Returns X if greater than Y, or returns Y if less
PSP_MODULE_INFO("Image Displayer", 0, 1, 1);
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
struct object {
int x;
int y;
int obj_state; // 0 = ground, 1 = jumping, 2 = falling
}
int main() {
SceCtrlData pad;
struct object box;
box.x = 50;
box.y = 230;
//char buffer[200]; // Block of memory of 200 variables for a string (maximum length it can be)
Image* ourImage;
SetupCallbacks();
pspDebugScreenInit();
initGraphics();
//sprintf(buffer, "ourImage.png");
ourImage = loadImage("ourImage.png");
if(ourImage)
{
// This is a cycle, or frame. It'll keep happening, 60 times a second.
while(1)
{
// First, find out what the state of the control pad is.
sceCtrlPeekBufferPositive(&pad, 1);
// Change the position of the box based on this state.
if(pad.Buttons & PSP_CTRL_LEFT)
box.x-=4;
else
if(pad.Buttons & PSP_CTRL_RIGHT)
box.x+=4;
// Wait for the end of the cycle
sceDisplayWaitVblankStart();
// Render the screen
fillScreenRect(RGB(70, 130, 150), 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
blitAlphaImageToScreen(0 ,0 ,32 , 32, ourImage, box.x, box.y);
printTextScreen(70,70,"Hello",255);
flipScreen(); // Just updates the screen
// Go again
}
}
sceKernelSleepThread(); // Wait for home
return 0;
}