The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## Post some C samples

This is a discussion on Post some C samples within the Developer's Dungeon forums, part of the PSP Development Forum category; Here is an elipse drawing routine I flogged from a LUA thread in this area and converted it to C, ...

 Tweet
1. ## Post some C samples

Here is an elipse drawing routine I flogged from a LUA thread in this
area and converted it to C, and fixed that rouge pixel that hangs out
the right hand side of smaller circles/elipses. I also modified so you define
the center instead of top left corner.
Code:
```void draw_elipse() {

int exx = centerx - mma;
int eyy = centery - mma;

int x0 = exx+(mma);
int y0 = eyy+(mma);
int stretch = mma + mma;

int theta;
for(theta=0; theta<60; theta++) {
xo = (cos(theta)*stretch)+x0;
yo = (sin(theta)*mma)+y0;
DRAW PIXEL HERE xo,yo
}

xo = tballx + stretch;
yo = tbally;
DRAW BLANK (coverup) PIXEL HERE xo,yo
}```
Cheers,
Art.

2. Here is a class to wrap it up in (for any O.O. nuts like me :P)

Code:
```#ifndef CELLIPSE_H
#define CELLIPSE_H

class CEllipse
{
public:
CEllipse();
CEllipse(CEllipse* Ellipse);
CEllipse(int X, int Y, int Radius);

void Draw();

void MoveTo(int X, int Y);

float Circumference();
float Area();

private:

int mX, mY;
};

CEllipse()
{
this->mX       = 0;
this->mY       = 0;
}

CEllipse(CEllipse* Ellipse)
{
this->mX        = Ellipse->mX;
this->mY        = Ellipse->mY;
}

CEllipse(int X, int Y, int Radius)
{
this->mX        = X;
this->mY        = Y;
}

CEllipse::Draw()
{
// Drawing code...
}

CEllipse::MoveTo(int X, int Y)
{
this->mX = X;
this->mY = Y;
}

{
}

float CEllipse::Circumference()
{
return this->mRadius * 6.28;
}

float CEllipse::Area()
{
}

#endif```
Then you should be able to do this:

Code:
```#include "CEllipse.h"

int main()
{
CEllipse* firstEllipse  = new CEllipse(50, 65, 20);
CEllipse* secondEllipse = new CEllipse(firstEllipse);

firstEllipse->MoveTo(60,50);
secondEllipse->Resize(25);

firstEllipse->Draw();
secondEllipse->Draw();

delete firstEllipse;
delete secondEllipse;

return 0;
}```
Sorry for any errors, it's early in the morning

3. Code:
```#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>

#define printf	pspDebugScreenPrintf

PSP_MODULE_INFO("Hello World", 0, 1, 1);

int exit_callback(int arg1, int arg2, void *common);

int CallbackThread(SceSize args, void *argp);

int SetupCallbacks(void);

int main() {
SetupCallbacks();
pspDebugScreenInit();

int exit = 0;

printf("Hello World\n\n");
printf("Press X to continue...\n");
while(exit == 0){
if (pad.Buttons & PSP_CTRL_CROSS) {
exit = 1;
}
}
sceKernelExitGame();
return 0;
}

int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}

int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
return 0;
}

int SetupCallbacks(void) {
int thid = 0;
if(thid >= 0)
{
}
return thid;
}```
Come on a thread for C Samples and no one decided to put Hello World lol :ROFL:

4. Ichigo, you know that you have done some basic faults in your code?

- You don't need stdlib.h and string.h for a program like this
- You have forgot to declare what the pad is (use SceCtrlData pad; )
- You have forgot pspDebugScreenInit(); so if you were to compile it you wouldn't see any text...

I don't know why you have all your functions after the main one but I guess that is just your way of programming.
And I think it would be easier if you would just use sceKernelExitGame(); directly after the if (pad.Buttons & PSP_CTRL_CROSS) so you don't need to use any integers. But that is just me. =P

/SodR

5. i put the exit callbacks as the first functions

6. One of the first thread made here: http://forums.qj.net/f-developers-du...ets-15462.html

Had only 3 exaples tho :P

7. SG57's collision function:
Code:
```// Based of Ravines
extern int CollisionDetection(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) {
int Collide = 0;
if ((y2 >= y1 && y1 + h1 >= y2) || (y2 + h2 >= y1 && y1 + h1 >= y2 + h2) || (y1 >= y2 && y2 + h2 >= y1) || (y1 + h1 >= y2 && y2 + h2 >= y1 + h1))
{
if (x2 >= x1 && x1 + w1 >= x2) {
Collide = 1;
}
if (x2 + w2 >= x1 && x1 + w1 >= x2 + w2) {
Collide = 1;
}
if (x1 >= x2 && x2 + w2 >= x1) {
Collide = 1;
}
if (x1 + w1 >= x2 && x2 + w2 >= x1 + w1) {
Collide = 1;
}
}
return Collide;
}```
edit- Another collision by me (mainly)
Code:
```//basis from code by canadarox
int function hitTest(int ob1x,int ob1y,int ob1width,int ob1height,int ob2x,int ob2y,int ob2width,int ob2height) {

int hit = 0;

if ((ob1x >= ob2x && ob1x <= (ob2x+ob2width)) && (ob1y >= ob2y & ob1y <= (ob2y+ob2height))) {
hit = 1;
}

if (((ob1x+ob1width) >= ob2x && (ob1x+ob1width) <= (ob2x+ob2width)) && (ob1y >= ob2y & ob1y <= (ob2y+ob2height))) {
hit = 1;
}

if ((ob1x >= ob2x && ob1x <= (ob2x+ob2width)) && ((ob1y+ob1height) >= ob2y && (ob1y+ob1height) <= (ob2y+ob2height))) {
hit = 1;
}

if (((ob1x+ob1width) >= ob2x && (ob1x+ob1width) <= (ob2x+ob2width)) & ((ob1y+ob1height) >= ob2y && (ob1y+ob1height) <= (ob2y+ob2height))) {
hit = 1;
}

return hit;

}```
Arguments:
ob1x = first object's x position
ob1y = first object's y position
ob1width = first object's width
ob1height = first object's height
ob2x = second object's x position
ob2y = second object's y position
ob2width = second object's width
ob2height = second objects height
-= Double Post =-
a simple bare bones menu. Sorry if there are any errors.
Code:
```#define BGR(r,g,b) ((r) | ((g) << 8) | ((b) << 16));
#define red BGR(255,0,0);
#define black BGR(0,0,0);
#define white BGR(255,255,255);
#define blue BGR(0,0,255);

int menustatus = 1;

pspDebugScreenClear();

if(pad.Buttons & PSP_CTRL_UP) {
sceDisplayWaitVblankStart();
}

if{Pad.Buttons & PSP_CTRL_DOWN) {
sceDisplayWaitVblankStart();
}

pspDebugScreenSetTextColor(white);
printTextScreen(50, 50, "Play");

pspDebugScreenSetTextColor(blue);
printTextScreen(50,60,"Options");

pspDebugScreenSetTextColor(red);
printTextScreen(50,70,"Exit");

if( menustatus == 1 ) {
if (pad.Buttons & PSP_CTRL_CROSS) {
//insert game code here
}
}

if( menustatus == 2 ) {
if (pad.Buttons & PSP_CTRL_CROSS) {
//insert game code here
}
}

if( menustatus == 1 ) {
if (pad.Buttons & PSP_CTRL_CROSS) {
break;
}
}

if (menustatus <= 0) {
}

if (menustatus => 4) {
}```

8. This is a nice thread, I will have a look and see what code I can add to it.
-= Double Post =-
This is taken from the XArt Graphics library
This code will draw a circle and with a few little tweeks can be made into a Ellipse drawing function

you will need to create a xsGfxDrawPixel function to draw pixels on the screen

Code:
```void xsGfxDrawCircle(int x, int y, int r, UInt32 color)
{
int i=0;
int j=r;
int p=3 - 2 * r;

while(i <= j) {
xsGfxDrawPixel(x+i,y+j,color);
xsGfxDrawPixel(x-i,y+j,color);
xsGfxDrawPixel(x+i,y-j,color);
xsGfxDrawPixel(x-i,y-j,color);
xsGfxDrawPixel(x+j,y+i,color);
xsGfxDrawPixel(x-j,y+i,color);
xsGfxDrawPixel(x+j,y-i,color);
xsGfxDrawPixel(x-j,y-i,color);

if(p < 0) {
p += 4 * i++ + 6;
} else {
p += 4 * (i++ - j--) + 10;
}
}
}```
handy tip, do not use sin & cos functions for graphics, only use sin & cos for creating fix point math integer lookup tables for dealing with sin & cos

Next post will be a thread for having a mouse pointer with X used for mouse down,mouse up etc events in your own apps

9. Playstation Portable SDK for Xcode with SDL

At the moment I have just about completed the graphics part.
when completed this will allow you to develope user mode homebrew on your Mac and run it on a Mac and then run it on a actual PSP when ready.

it will be open source

10. I am working on mirroring the sce file functions to work on the Mac, so sce function calls for file io stuff will work like it was on a PSP

including the ms0:/
when you have ms0:/ in your path names it will be handled as ./ on Mac OS X

11. the SDL has just some basic ObjectiveC code in it to make things like mouse events etc work, all other stuff is in C or C++ and I will be sorting it out soon on the server to be downloaded so others can help out if they like

xsFile is what I am at, also be working on xsImage

these librarys were written for the PSP in user mode.

not yet desided what I will replace xs with as it will be open source so not all will be done by me at the end.

maybe "os" for open source
or "x" for cross platform
or could just take away xs and rename functions like xsGfxInit to gfxInit etc...

12. ok, great :)
What server though?

feel free to have a look.

14. for anyone who has the standard graphics.c, and is looking to load images directly from memory, rather than from a file -
Code:
```typedef struct
{

const unsigned char *buffer;
png_uint_32 bufsize;
png_uint_32 current_pos;

static void read_data_memory(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
if (length > (f->bufsize - f->current_pos)) png_error(png_ptr, "read error in read_data_memory (loadpng)");
memcpy(data, f->buffer + f->current_pos, length);
f->current_pos += length;
}

Image* loadImageMemory(const void *buffer, int bufsize)
{
png_structp png_ptr;
png_infop info_ptr;
unsigned int sig_read = 0;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, x, y;
u32* line;

if (!buffer || (bufsize <= 0)) return NULL;

Image* image = (Image*) malloc(sizeof(Image));
if (!image) return NULL;

png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
free(image);
return NULL;;
}

png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, user_warning_fn);

info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
free(image);
return NULL;
}

memory_reader_state.buffer = (unsigned char *)buffer;

png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);

image->imageWidth = width;
image->imageHeight = height;
image->textureWidth = getNextPower2(width);
image->textureHeight = getNextPower2(height);

png_set_strip_16(png_ptr);
png_set_packing(png_ptr);

if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);

image->data = (Color*) memalign(16, image->textureWidth * image->textureHeight * sizeof(Color));
if (!image->data) {
free(image);
return NULL;
}
line = (u32*) malloc(width * 4);
if (!line) {
free(image->data);
free(image);
return NULL;
}
for (y = 0; y < height; y++) {
png_read_row(png_ptr, (u8*) line, png_bytep_NULL);
for (x = 0; x < width; x++) {
u32 color = line[x];
image->data[x + y * image->textureWidth] =  color;
}
}

free(line);

return image;
}```
Maybe someone can find this useful?

15. for anyone who has the standard graphics.c, and is looking to load images directly from memory, rather than from a file -
Maybe someone can find this useful?
Definately.
If you've got something to do it for Mikmod pls share as well,
because it would be nice to be able to alter the sound file in RAM.

16. Originally Posted by Bronx
oh nice, it works soo far... Not exactly sure what is what though. This is kinda a psp emu for just sdl
If you change #define PSP=0 to #define PSP=1 then type make at the terminal it will compile it for the PSP, at the moment have not added the xsImage for loading in a mouse cursor so PSP not quite ready, but graphics should work fine

as you may see it is still very early in development

the psp.cpp is were you code stuff for the PSP and there is three lines you need in any loop when you compile it for Mac to prevent it from giving you the beachball
-= Double Post =-
Originally Posted by Alexisonfire
for anyone who has the standard graphics.c, and is looking to load images directly from memory, rather than from a file -
Code:
```typedef struct
{

const unsigned char *buffer;
png_uint_32 bufsize;
png_uint_32 current_pos;

static void read_data_memory(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
if (length > (f->bufsize - f->current_pos)) png_error(png_ptr, "read error in read_data_memory (loadpng)");
memcpy(data, f->buffer + f->current_pos, length);
f->current_pos += length;
}

Image* loadImageMemory(const void *buffer, int bufsize)
{
png_structp png_ptr;
png_infop info_ptr;
unsigned int sig_read = 0;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, x, y;
u32* line;

if (!buffer || (bufsize <= 0)) return NULL;

Image* image = (Image*) malloc(sizeof(Image));
if (!image) return NULL;

png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
free(image);
return NULL;;
}

png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, user_warning_fn);

info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
free(image);
return NULL;
}

memory_reader_state.buffer = (unsigned char *)buffer;

png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);

image->imageWidth = width;
image->imageHeight = height;
image->textureWidth = getNextPower2(width);
image->textureHeight = getNextPower2(height);

png_set_strip_16(png_ptr);
png_set_packing(png_ptr);

if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);

image->data = (Color*) memalign(16, image->textureWidth * image->textureHeight * sizeof(Color));
if (!image->data) {
free(image);
return NULL;
}
line = (u32*) malloc(width * 4);
if (!line) {
free(image->data);
free(image);
return NULL;
}
for (y = 0; y < height; y++) {
png_read_row(png_ptr, (u8*) line, png_bytep_NULL);
for (x = 0; x < width; x++) {
u32 color = line[x];
image->data[x + y * image->textureWidth] =  color;
}
}

free(line);

return image;
}```
Maybe someone can find this useful?
I may use it to add png support to the xsGraphics libary

17. for anyone who has the standard graphics.c, and is looking to load images directly from memory, rather than from a file -
Then once your png is in RAM, how do you associate the buffer that has your
png in it with this function?

18. Originally Posted by Art
Then once your png is in RAM, how do you associate the buffer that has your
png in it with this function?
I've just been using this function to read in the section data of an eboot that contains the icon0.png, etc, then using this function to load them directly.

I would imagine it's something similar to this,
Code:
```int total_size;
FILE *infile;
Image* theImage;

infile = fopen("ms0:/whatever.png", "rb");

fseek(infile, 0, SEEK_END); total_size = ftell(infile); fseek(infile, 0, SEEK_SET);

void *buffer; int size;

size = total_size;
buffer = malloc(size);

fread(buffer, size, 1, infile);

theImage = loadImageMemory(buffer, size);

fclose(infile);```

19. Originally Posted by Art
Then once your png is in RAM, how do you associate the buffer that has your
png in it with this function?

20. Here's USB Mode.

Code:
```
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspusb.h>
#include <pspusbstor.h>
#include <string.h>```
Functions:
Code:
```
// Defines
#define     printf     pspDebugScreenPrintf

// Functions
{
u32 startResult;
int status;

if (loadResult & 0x80000000) return -1;
else
startResult = sceKernelStartModule(loadResult, 0, NULL, &status, NULL);

if (loadResult != startResult) return -2;

return 0;
}

void initUSB()
{
u32 retVal;

retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);

if (retVal != 0) {
printf("Error starting USB Bus driver (0x%08X)\n", retVal);
}

retVal = sceUsbStart(PSP_USBSTOR_DRIVERNAME, 0, 0);
if (retVal != 0) {
printf("Error starting USB Mass Storage driver (0x%08X)\n", retVal);
}

retVal = sceUsbstorBootSetCapacity(0x800000);
if (retVal != 0) {
printf("Error setting capacity with USB Mass Storage driver (0x%08X)\n", retVal);
}

retVal = 0;
}

void usbMode(const char* what)
{
u32 retVal;

if (stricmp(what, "on")==0) {
retVal = sceUsbActivate(0x1c8);
}
else if (stricmp(what, "off")==0) {
retVal = sceUsbDeactivate(0);
}
}```
Call this just inside of your int main:
Code:
`initUSB();`
Example:
Code:
```usbMode("on");

or

usbMode("off");```
Put this in your 'Makefile':
Code:
```In LIBS=
-lpspusb -lpspusbstor```

21. Originally Posted by Slasher
for anyone who has the standard graphics.c, and is looking to load images directly from memory, rather than from a file -
Code:
```typedef struct
{

const unsigned char *buffer;
png_uint_32 bufsize;
png_uint_32 current_pos;

static void read_data_memory(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
if (length > (f->bufsize - f->current_pos)) png_error(png_ptr, "read error in read_data_memory (loadpng)");
memcpy(data, f->buffer + f->current_pos, length);
f->current_pos += length;
}

Image* loadImageMemory(const void *buffer, int bufsize)
{
png_structp png_ptr;
png_infop info_ptr;
unsigned int sig_read = 0;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, x, y;
u32* line;

if (!buffer || (bufsize <= 0)) return NULL;

Image* image = (Image*) malloc(sizeof(Image));
if (!image) return NULL;

png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
free(image);
return NULL;;
}

png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, user_warning_fn);

info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
free(image);
return NULL;
}

memory_reader_state.buffer = (unsigned char *)buffer;

png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);

image->imageWidth = width;
image->imageHeight = height;
image->textureWidth = getNextPower2(width);
image->textureHeight = getNextPower2(height);

png_set_strip_16(png_ptr);
png_set_packing(png_ptr);

if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);

image->data = (Color*) memalign(16, image->textureWidth * image->textureHeight * sizeof(Color));
if (!image->data) {
free(image);
return NULL;
}
line = (u32*) malloc(width * 4);
if (!line) {
free(image->data);
free(image);
return NULL;
}
for (y = 0; y < height; y++) {
png_read_row(png_ptr, (u8*) line, png_bytep_NULL);
for (x = 0; x < width; x++) {
u32 color = line[x];
image->data[x + y * image->textureWidth] =  color;
}
}

free(line);

return image;
}```
Maybe someone can find this useful?
I'd love to use it, but get errors for just having included it in my source

the first of which is that user_warning_fn is being used uninitialised.
Then If I define the variable, there are other errors.

22. whoops
Code:
```void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
{
}```

23. I use my own usb.c and usb.h made it myself .....
usb.c
Spoiler for usb.c:

Code:
```#include <pspkernel.h>

#include <pspiofilemgr.h>

#include <pspmodulemgr.h>

#include <pspdisplay.h>

#include <pspdebug.h>

#include <pspusb.h>

#include <pspusbstor.h>

#include <pspctrl.h>

#include <pspsdk.h>

#include "usb.h"

#define printf  pspDebugScreenPrintf

{

pspKernelSetKernelPC();

pspSdkInstallNoDeviceCheckPatch();

pspDebugInstallKprintfHandler(NULL);

}

{

u32 startResult;

int status;

if (loadResult & 0x80000000)

return -1;

else

startResult =

sceKernelStartModule(loadResult, 0, NULL, &status, NULL);

if (loadResult != startResult)

return -2;

return 0;

}

{

if(sceUsbGetState() & PSP_USB_ACTIVATED){

AODusb();

return 0;

}

int retVal =0;

retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);

if (retVal != 0) {

printf("Error starting USB Bus driver (0x%08X)\n", retVal);

}

retVal = sceUsbStart(PSP_USBSTOR_DRIVERNAME, 0, 0);

if (retVal != 0) {

printf("Error starting USB Mass Storage driver (0x%08X)\n",

retVal);

}

retVal = sceUsbstorBootSetCapacity(0x800000);

if (retVal != 0) {

printf

("Error setting capacity with USB Mass Storage driver (0x%08X)\n",

retVal);

}

retVal = 0;

}

// Activate or DeActivate USB

int AODusb()

{

if(sceUsbGetState() & PSP_USB_ACTIVATED){

sceUsbDeactivate(0x1c8);

} else {

sceUsbActivate(0x1c8);

}

return 1;

}

sceUsbDeactivate(0x1c8);

int Activate_usb()

{

if(sceUsbGetState() & PSP_USB_ACTIVATED){

return 0;

} else {

sceUsbActivate(0x1c8);

}

return 1;

}

int Deactivate_usb()

{

if(sceUsbGetState() & PSP_USB_ACTIVATED){

sceUsbDeactivate(0x1c8);

return 1;

} else {

return 0;

}

}```
Code:

Spoiler for USB.h:

and here is usb.h
Code:
```#ifndef _USB_H_

#define _USB_H_

#ifdef __cplusplus

extern "C" {

#endif

int AODusb();

int Activate_usb();

int Deactivate_usb();

#ifdef __cplusplus

}

#endif

#endif```

-= Double Post =-
Originally Posted by Twenty 2
Does anyone have a bunch of code like getting time and getting the psp username just a bunch of functions like that?
Code:
```#include <psputility.h>
char nick[256];

sceUtilityGetSystemParamString(1, nick, 256);
//nick will be your nick name```
there is an SDK sample for this:
Spoiler for SDK SAMPLE:

Code:
```/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - Sample to demonstrate proper use of the systemparam functions
*
* Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
*
* \$Id: main.c 1869 2006-04-09 14:21:59Z tyranid \$
*/
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <stdio.h>
#include <string.h>
#include <pspmoduleinfo.h>
#include <psputility.h>

/* Define the module info section */
PSP_MODULE_INFO("SystemParam Sample", 0, 1, 0);

//Just to leave room for expansion
#define NUM_SYSTEMPARAMS 15

/* Define printf, just to make typing easier */
#define printf  pspDebugScreenPrintf

/* 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);

return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
if (thid >= 0)
return thid;
}

void printSystemParam(int id, int iVal, char *sVal) {
switch(id) {
case(PSP_SYSTEMPARAM_ID_STRING_NICKNAME):
printf("%-17s: %s\n", "Nickname", sVal);
break;
printf("%-17s: %d\n", "AdHoc Channel", iVal);
break;
case(PSP_SYSTEMPARAM_ID_INT_WLAN_POWERSAVE):
printf("%-17s: %s\n", "WLAN Powersave", iVal == 0 ? "enabled   " : "disabled");
break;
case(PSP_SYSTEMPARAM_ID_INT_DATE_FORMAT):
switch(iVal) {
case(PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD):
printf("%-17s: YYYYMMDD\n", "Date Format");
break;
case(PSP_SYSTEMPARAM_DATE_FORMAT_MMDDYYYY):
printf("%-17s: MMDDYYYY\n", "Date Format");
break;
case(PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY):
printf("%-17s: DDMMYYYY\n", "Date Format");
break;
default:
printf("%-17s: INVALID\n", "Date Format");
}
break;
case(PSP_SYSTEMPARAM_ID_INT_TIME_FORMAT):
switch(iVal) {
case(PSP_SYSTEMPARAM_TIME_FORMAT_24HR):
printf("%-17s: 24HR\n", "Time Format");
break;
case(PSP_SYSTEMPARAM_TIME_FORMAT_12HR):
printf("%-17s: 12HR\n", "Time Format");
break;
default:
printf("%-17s: INVALID\n", "Time Format");
}
break;
case(PSP_SYSTEMPARAM_ID_INT_TIMEZONE):
printf("%-17s: %d\n", "Timezone", iVal);
break;
case(PSP_SYSTEMPARAM_ID_INT_DAYLIGHTSAVINGS):
switch(iVal) {
case(PSP_SYSTEMPARAM_DAYLIGHTSAVINGS_STD):
printf("%-17s: standard\n", "Daylight Savings");
break;
case(PSP_SYSTEMPARAM_DAYLIGHTSAVINGS_SAVING):
printf("%-17s: saving\n", "Daylight Savings");
break;
default:
printf("%-17s: INVALID\n", "Daylight Savings");
}
break;
case(PSP_SYSTEMPARAM_ID_INT_LANGUAGE):
switch(iVal) {
case(PSP_SYSTEMPARAM_LANGUAGE_JAPANESE):
printf("%-17s: Japanese\n", "Language");
break;
case(PSP_SYSTEMPARAM_LANGUAGE_ENGLISH):
printf("%-17s: English\n", "Language");
break;
case(PSP_SYSTEMPARAM_LANGUAGE_FRENCH):
printf("%-17s: French\n", "Language");
break;
case(PSP_SYSTEMPARAM_LANGUAGE_SPANISH):
printf("%-17s: Spanish\n", "Language");
break;
case(PSP_SYSTEMPARAM_LANGUAGE_GERMAN):
printf("%-17s: German\n", "Language");
break;
case(PSP_SYSTEMPARAM_LANGUAGE_ITALIAN):
printf("%-17s: Italian\n", "Language");
break;
case(PSP_SYSTEMPARAM_LANGUAGE_DUTCH):
printf("%-17s: Dutch\n", "Language");
break;
case(PSP_SYSTEMPARAM_LANGUAGE_PORTUGUESE):
printf("%-17s: Portuguese\n", "Language");
break;
case(PSP_SYSTEMPARAM_LANGUAGE_KOREAN):
printf("%-17s: Korean\n", "Language");
break;
default:
printf("%-17s: INVALID\n", "Language");
}
break;
case(PSP_SYSTEMPARAM_ID_INT_UNKNOWN):
printf("%-17s: %d (1 on NA PSPs and 0 on JAP PSPs, v1.5+ only)\n", "Unknown:", iVal);
break;
default:
printf("%-17s: int 0x%08X, string '%s'\n", "Unknown", iVal, sVal);
}
}

/* main routine */
int main(int argc, char *argv[])
{
char sVal[256];
int iVal;
int i;

//init screen and callbacks
pspDebugScreenInit();
pspDebugScreenClear();

SetupCallbacks();

//fetch and print out power and battery information
pspDebugScreenSetXY(0, 0);
printf("SystemParam Sample v1.0 by John_K\n\n");

for (i = 0; i <= NUM_SYSTEMPARAMS; i++) {
memset(sVal, 0, 256);
if(sceUtilityGetSystemParamInt(i, &iVal) != PSP_SYSTEMPARAM_RETVAL_FAIL)
printSystemParam(i, iVal, sVal);
if(sceUtilityGetSystemParamString(i, sVal, 256) != PSP_SYSTEMPARAM_RETVAL_FAIL)
printSystemParam(i, iVal, sVal);
}

sceKernelExitGame();

return 0;
}```
MakeFiel:
Code:
```PSPSDK = \$(shell psp-config --pspsdk-path)
PSPLIBSDIR = \$(PSPSDK)/..
TARGET = sysparamsample
OBJS = main.o

LIBS = -lpsputility

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = \$(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = \$(CFLAGS)

include \$(PSPSDK)/lib/build.mak```

24. Originally Posted by Slasher
whoops
Code:
```void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
{
}```
Still no luck The first of a few errors I get when I include it now is
implicit declaration of the function getNextPower2 (there isn't one),
and something about "memalign"... is there anything else left out?

Have you used this yourself, nad know it to work?

25. For these USB samples, you ought to graciously ignore errors starting USB, if you want full compatibility with firmwares 2.0+.

On 2.8, for instance, we currently can't do USB, so with your code, you would just hang the program on 2.8. Better to just return an error code to the calling function, and let it decide what to do about the lack of USB, rather than sleeping the thread.

26. Originally Posted by Art
Still no luck The first of a few errors I get when I include it now is
implicit declaration of the function getNextPower2 (there isn't one),
and something about "memalign"... is there anything else left out?

Have you used this yourself, nad know it to work?
Whoops, there's a few other things I left out. My fault.
Hah, here's a working gfx.c/h.
http://slasher.team-duck.com/development/gfx.c
http://slasher.team-duck.com/development/gfx.h

Sorry for the trouble

27. Are you sopposed to replace graphics.c and graphics.h with those files,
and then use as normal?

28. Damn.. he's banned!
Still stuck with this
Replacing Graphics.c & Graphics.h with the above files breaks a working
program straight away. This might be the only way I can get a graphic font
into any program since I'm having trouble with fontlib as well...

Pls post if you have a game source with the pngs biult into the source files.

29. If you want to use OSlib, you can do it with a minor modification to the OSlib source, recompile the library, and off you go. ;)

30. Here's a sample given to me by will1234.
It's easy in hind sight

Page 1 of 4 1 2 3 4 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 08:53 PM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY