 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
kozine
Joined: 18 Mar 2006 Posts: 6 Location: England, United Kingdom
|
Posted: Sat Apr 15, 2006 5:31 am Post subject: In need of help with C |
|
|
Hey guys,
This is my first post at these forums. Yesterday I moved from LUA to C and am in need of help.
My code compiles successfully, when I load it up on my PSP I just get a blank screen. My PSP doesnt crash as I can still return to the eloader. Here is my code:
| Code: |
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include "graphics.h"
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
#define printf pspDebugScreenPrintf
PSP_MODULE_INFO("Button Basher", 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);
sceKernelRegisterExitCall back(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;
}
int main() {
char *buffer = "menubg.png";
Image* menubg;
pspDebugScreenInit();
SetupCallbacks();
initGraphics();
sprintf(buffer, "menubg.png");
menubg = loadImage(buffer);
if (!menubg) {
//Image load failed
printf("Image load failed! Please email youleben@gmail.com!\n");
} else {
int x = 0;
int y = 0;
sceDisplayWaitVblankStart ();
while (x < 480) {
while (y < 272) {
blitAlphaImageToScreen(0, 0, 480, 272, menubg, x, y);
}
flipScreen();
}
}
sceKernelSleepThread();
return 0;
}
|
Ive placed the image in the same folder as my eboot.pbp file aswell on my PSP. Any help is appreciated! _________________
 |
|
| Back to top |
|
 |
Lynxie
Joined: 15 Apr 2006 Posts: 2
|
Posted: Sat Apr 15, 2006 6:44 am Post subject: |
|
|
Increment x and y and things will move, you'll find others by yourself :)
Last edited by Lynxie on Sat Apr 15, 2006 6:47 am; edited 1 time in total |
|
| Back to top |
|
 |
kozine
Joined: 18 Mar 2006 Posts: 6 Location: England, United Kingdom
|
Posted: Sat Apr 15, 2006 6:47 am Post subject: |
|
|
What do you mean? Dont forget im new to this lol ;) _________________
 |
|
| Back to top |
|
 |
Lynxie
Joined: 15 Apr 2006 Posts: 2
|
Posted: Sat Apr 15, 2006 7:01 am Post subject: |
|
|
| Code: | int x = 0;
int y = 0;
sceDisplayWaitVblankStart ();
while (x < 480) {
while (y < 272) {
blitAlphaImageToScreen(0, 0, 480, 272, menubg, x, y);
}
flipScreen();
} |
x and y are always equals to 0. |
|
| Back to top |
|
 |
neofar

Joined: 21 Jan 2004 Posts: 47 Location: Spain
|
Posted: Sat Apr 15, 2006 7:56 am Post subject: |
|
|
| Code: | while (y < 272) {
blitAlphaImageToScreen(0, 0, 480, 272, menubg, x, y);
} |
the program NEVER exit of this lines ...... y is always < 272 .... never exit!!!!!!! |
|
| Back to top |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Sat Apr 15, 2006 4:18 pm Post subject: |
|
|
char *buffer = "menubg.png";
Image* menubg;
sprintf(buffer, "menubg.png");
menubg = loadImage(buffer);
this is a pointer you can't assign to a pointer some data, plus you try to sprintf into the space pointed by buffer which wasn't even alloched so you must change this in this way:
| Code: | char *buffer;
#define IMAGE "menubg.png"
buffer = malloc(strlen(IMAGE));
sprintf(buffer, "menubg.png");
|
i'm not so sure if image *menubg is right because i don't know how the libpng work |
|
| Back to top |
|
 |
PeterM
Joined: 31 Dec 2005 Posts: 125 Location: Edinburgh, UK
|
Posted: Sat Apr 15, 2006 8:15 pm Post subject: |
|
|
I know it's not what you want to hear, but you really really really should learn C on a PC compiler with a real time debugger before trying on the PSP.
You will save yourself many frustrating late nights. It cannot be understated. |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sat Apr 15, 2006 8:34 pm Post subject: |
|
|
| Quote: | | Code: | char *buffer;
#define IMAGE "menubg.png"
buffer = malloc(strlen(IMAGE));
sprintf(buffer, "menubg.png"); |
|
This is wrong. It should be
| Code: | | buffer = malloc(strlen(IMAGE)+1); |
to avoid a stack overrun.
The original code did have storage allocated for buffer because it was initialised, unfortunately, you are not supposed to write to constant strings in C.
ie.
| Code: |
char *buffer = "hello"; //OK, buffer points to constant string
buffer[0] = 'b'; //not OK, writing to constant string
|
or
| Code: |
char buffer[]="hello";//OK, buffer points to variable string
buffer[0] = 'b'; //fine
|
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
Sonicadvance1
Joined: 13 Oct 2005 Posts: 10
|
Posted: Sun Apr 16, 2006 5:47 am Post subject: |
|
|
if you look closely at his code you can see this
| Code: | while (x < 480) {
while (y < 272) {
blitAlphaImageToScreen(0, 0, 480, 272, menubg, x, y);
}
flipScreen();
} |
he has two while loops and he blits the image to the screen which is 480x272 for an infinite amount of times and if the inside loop accually completed, it would flip the screen each time the outside loop went through.
Not too sure as to why he would want to blit the same image 272*480 times though. Prolly just a noob mistake.
And also, welcome to C/C++. Please try to enjoy yourself |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|