M_Header.h
Code: Select all
////////////////////////////////////////////////////////////////////////////////////
// My_Header.h Version 1.0
// By Jason J. Owens
// August 21, 2005 9:24 AM
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef __MY_HEADER__
#define __MY_HEADER__
// Function Prototypes
void screenshot();
///////////////////////////////////////////////////////////////////////////////////////
// Function Definitions
void screenshot()
{
unsigned char bmpHeader24[] = { 0x42, 0x4d, 0x38, 0xfa, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
unsigned char buffer[SCR_WIDTH*3];
unsigned char r,g,b;
int bufferIndex = 0;
unsigned short p;
char savePath="ms0:/PSP/PHOTO/Screenshots/screenshot.bmp";
int file = sceIoOpen(savePath,PSP_O_CREAT | PSP_O_TRUNC | PSP_O_RDWR, 0777); // savePath should hold the path to your file
// write bmp header
sceIoWrite(file,bmpHeader24,54);
// write bmp data
unsigned long vptr0 = VRAM;
int i=0;
for(i=0; i<272; i++)
{
unsigned long vptr=vptr0;
int e=0;
for(e=0; e<480; e++)
{
p = *(unsigned short *)vptr;
r = (p<<3)&0xf8;
g = (p>>2)&0xf8;
b = (p>>7)&0xf8;
buffer[bufferIndex] = b;
bufferIndex++;
buffer[bufferIndex] = g;
bufferIndex++;
buffer[bufferIndex] = r;
bufferIndex++;
vptr+=PIXEL_SIZE*2;
}
// write chunk
sceIoWrite(file,buffer,SCR_WIDTH*3);
bufferIndex=0;
vptr0-=BUF_WIDTH*2;
}
// bmp end
unsigned char end[] = { 0x00, 0x00 };
sceIoWrite(file,end,2);
sceIoClose(file);
}
///////////////////////////////////////////////////////////////////////////////////////
Code: Select all
//////////////////////////////////////////////////////////////////////////////////////////
/* test Version 1.0
* by Jason J. Owens
* August 18, 2005 9:00 AM
*/
//////////////////////////////////////////////////////////////////////////////////////////
// #includes
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <stdlib.h>
#include <stdio.h>
#include <Graphics.h>
#include <My_Header.h>
PSP_MODULE_INFO("test", 0x1000, 1, 1); // Defines module info.
PSP_MAIN_THREAD_ATTR(0); // Defines the main thread's attribute value (optional).
//#define printf pspDebugScreenPrintf // Defines printf, just to make typing easier.
int ExitGame = 0; // Gets set to '1' when getting ready to exit the game.
// Exit callback
int exit_callback(int arg1, int arg2, void *common)
{
ExitGame = 1;
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, THREAD_ATTR_USER, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int Random(int high)
{
return (rand() % (high+1));
}
// Here's the Main Function.
int main(void)
{
pspDebugScreenInit(); // Initializes the Debug text output screen.
SetupCallbacks(); // Sets up the callback thread and returns its thread id.
srand(sceKernelLibcTime((void *) 0)); // seeded with time
InitializeGraphics(1);
int x=0,y=0,x1=0,y1=0,radius=0,xsize=0,ysize=0,r=0,g=0,b=0,a=0,c=0,three_d=0,rand3d=0,text=0;
while(!ExitGame)
{
x=Random(480);
r=Random(255);
y=Random(272);
x1=Random(480);
y1=Random(272);
g=Random(255);
xsize=Random(25);
b=Random(255);
ysize=Random(25);
rand3d=Random(25);
radius=Random(150);
text=20;
switch(Random(5))
{
case 0:
PlotPixel(x,y,r,g,b);
case 1:
PlotPixel(x,y,r,g,b);
case 2:
PlotLine(x,y,x1,y1,r,g,b);
case 3:
PlotCircle(x,y,radius,r,g,b);
case 4:
for(a=0;a<xsize;a++)
{
for(c=0;c<ysize;c++)
{
PlotPixel(x+a,y+c,r,g,b);
}
}
case 5:
for(three_d=0;three_d<rand3d;three_d++)
{
for(a=0;a<xsize;a++)
{
for(c=0;c<ysize;c++)
{
PlotPixel(x+a+three_d,y+c+three_d,r+three_d,g+three_d,b+three_d);
}
}
}
}
}
screenshot();
sceKernelExitGame(); // Returns PSP to the Main Menu.
return 0; // Just for good practice.
}
//////////////////////////////////////////////////////////////////////////////////////////