forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cursor? Work this code?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Mon Oct 22, 2007 10:04 pm    Post subject: Cursor? Work this code? Reply with quote

Hey, hey...

I don't know, what is wrong...


If I start the program, the PSP LCD is Black, but the Callbacks work.
But when i will exit the Program over the Callbacks, the PSP LCD freeze...

Got the code:

Code:

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspumd.h>
#include <string.h>
#include <stdlib.h>
#include "wait.h"
//#include "callbacks.h"
//#include "dumpers.h"
#include "graphics.h"
#include "framebuffer.h"
#include <png.h>

PSP_MODULE_INFO("lol", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

#define printf pspDebugScreenPrintf
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))

void dump_threadstatus(void);

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

int x = 0;
int y = 0;
int ox;
int oy;


int main(void)
{

   pspDebugScreenInit();
   pspDebugScreenSetBackColor(0xFFFFFFFF);
   pspDebugScreenSetTextColor(0);
   SetupCallbacks();
   initGraphics();
   SceCtrlData pad;
   sceCtrlSetSamplingMode(1);
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
   sceCtrlReadBufferPositive(&pad, 1);
   
   Image* cursor;
   cursor = loadImage("cursor.png");
   
   while(1)
   {
      
      if (pad.Lx > 150) {
         wait(1);
         x++;
      }
      if (pad.Lx < 110) {
         wait(1);
         x--;
      }
      if (pad.Ly > 150) {
         wait(1);
         y++;
      }
      if (pad.Ly < 110) {
         wait(1);
         y--;
      }
/*
      if (pad.Lx == 255) {
         pad.Lx = 255;
      }
      if (pad.Lx == 0) {
         pad.Lx = 0;
      }
      if (pad.Ly == 255) {
         pad.Ly = 255;
      }
      if (pad.Ly == 0) {
         pad.Ly = 0;
      }
*/   
      if(x != ox & y != oy)
         {
            if (!cursor)
            {
                    //Image load failed
                    printf("Error!\n");
                }
            else
            {
                 sceDisplayWaitVblankStart();
                 blitImageToScreen(0 ,0 ,10 , 10, cursor, x, y);
                 flipScreen();
            }
         }
ox = x;
oy = y;
}
...


I hope someone can help me ;)
_________________
Sry for my english
Back to top
View user's profile Send private message
AllSystemGo



Joined: 02 Jun 2007
Posts: 26

PostPosted: Mon Oct 22, 2007 10:51 pm    Post subject: Reply with quote

You cannot make a infinit loop like that

Code:

while(1)


you should use something like

Code:

while(running)


I'm trying to get you the thread that is talking ab out that but I just can't find one . I'll post the link a bit later.
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Mon Oct 22, 2007 11:43 pm    Post subject: Reply with quote

The common idiom (replacement) for
while (1)
is
for (;;)
Quite a few compilers warn about the former but happily accept the latter.
You use 'break' to get out of the infinite loop as usual.

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Tue Oct 23, 2007 1:58 am    Post subject: Reply with quote

thx, if i have understand all, i must replace

Code:

while(1)


with

Code:

for(;;)


but what did you mean with

Quote:

Quite a few compilers warn about the former but happily accept the latter.
You use 'break' to get out of the infinite loop as usual.

?
_________________
Sry for my english
Back to top
View user's profile Send private message
b1G



Joined: 19 Sep 2007
Posts: 5

PostPosted: Tue Oct 23, 2007 3:30 am    Post subject: Reply with quote

What he means is that sometimes your compiler may give a warning when using while(1) and that they don't give any warnings when using for(;;) even though they do the same thing.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Oct 23, 2007 5:31 am    Post subject: Reply with quote

It's black because you don't blit the cursor until it moves, and it never moves because you don't read the pad inside the loop.

Here's some "fixed" code that works. It shows the cursor to begin, reads the pad in the loop, and exits if you push O as well. Note that your code doesn't erase the cursor. Something to add in. :)

Code:
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspumd.h>
#include <string.h>
#include <stdlib.h>

#include "graphics.h"
#include "framebuffer.h"

#include <png.h>

PSP_MODULE_INFO("lol", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

#define printf pspDebugScreenPrintf
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))

void dump_threadstatus(void);

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

int x = 0;
int y = 0;
int ox;
int oy;


int main(void)
{
   SceCtrlData pad;

   pspDebugScreenInit();
   pspDebugScreenSetBackColor(0xFFFFFFFF);
   pspDebugScreenSetTextColor(0);

   SetupCallbacks();

   initGraphics();
   sceCtrlSetSamplingMode(1);
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

   Image* cursor;
   cursor = loadImage("cursor.png");
   if (!cursor)
   {
      printf(" Couldn't load cursor.png!\n");
      sceKernelExitGame();
   }
   blitImageToScreen(0 ,0 ,10 , 10, cursor, x, y); // show initially

   while(1)
   {
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_CIRCLE) break;

      if (pad.Lx > 150) x++;
      if (pad.Lx < 110) x--;
      if (pad.Ly > 150) y++;
      if (pad.Ly < 110) y--;
      if (x < 0) x = 0;
      else if (x > 479) x = 479;
      if (y < 0) y = 0;
      else if (y > 271) y = 271;

      if(x != ox && y != oy)
      {
         sceDisplayWaitVblankStart();
         blitImageToScreen(0 ,0 ,10 , 10, cursor, x, y);
         flipScreen();
      }
      ox = x;
      oy = y;
   }
   sceKernelExitGame();
   return 0;
}
Back to top
View user's profile Send private message AIM Address
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Tue Oct 23, 2007 6:27 am    Post subject: Reply with quote

nice job, thx...

lol...the pad is realy not read inside the loop...

but how did I erase the cursor, befor it moves?

with

Code:

pspDebugScreenClear();


i clean the complete LCD...

may be i must disable graphics? and then enable it ?

And a question to a animation:

can i use:

Code:

int x = 0;
int i;

Image* array[3];
array[0] = loadImage("1.png");
array[1] = loadImage("2.png");
array[2] = loadImage("3.png");

blitImageToScreen(0 ,0 ,479 , 271, x, 0, 0);
for(i=0;i<3;i++) x++


what is wrong?
the PSP freeze...

or can i use animated gifs in Homebrew, with SDL ?
_________________
Sry for my english
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Oct 23, 2007 6:49 am    Post subject: Reply with quote

_.-noel-._ wrote:
nice job, thx...

lol...the pad is realy not read inside the loop...

but how did I erase the cursor, befor it moves?


Erasing the cursor means you save what is under where the cursor is about to be drawn, then redraw that before drawing the cursor at its new location.

Quote:

And a question to a animation:

can i use:

Code:

int x = 0;
int i;

Image* array[3];
array[0] = loadImage("1.png");
array[1] = loadImage("2.png");
array[2] = loadImage("3.png");

blitImageToScreen(0 ,0 ,479 , 271, x, 0, 0);
for(i=0;i<3;i++) x++


what is wrong?
the PSP freeze...

or can i use animated gifs in Homebrew, with SDL ?


With anigifs, you'd have to decode each frame into an array, rather like how you load the three pngs above. Your code for that SHOULD be:

Code:
   for(i=0;i<3;i++)
  {
      blitImageToScreen(0 ,0 ,479 , 271, array[i], 0, 0);
      sceDisplayWaitVblankStart();
      flipScreen();
      sceKernelDelayThread(100*1000);
   }


The delay sets the frames per second. 100 ms yields ten frames per second. If you want a second per frame, use 1*1000*1000 instead.
Back to top
View user's profile Send private message AIM Address
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Tue Oct 23, 2007 7:08 am    Post subject: Reply with quote

cool, thx...

my last question(i hope) is:

what is the last parameter for

Code:

blitImageToImage(0, 0, 10, 10, cursor, x, y, *?*);


must this be the picture, where "cursor" is over the picture, may be "bg" ?
_________________
Sry for my english
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Oct 23, 2007 7:19 am    Post subject: Reply with quote

_.-noel-._ wrote:
cool, thx...

my last question(i hope) is:

what is the last parameter for

Code:

blitImageToImage(0, 0, 10, 10, cursor, x, y, *?*);


must this be the picture, where "cursor" is over the picture, may be "bg" ?


On Image to Image, the last parameter is the destination image of course.

Here's the latest fixes I made to the code above. This one shows a background behind the cursor, and I remembered to take into account the cursor alpha. Take a look at the cursor in the arc. Notice that all unset pixels are transparent. When you load a png using loadImage(), it sets an alpha based on the transparency in the png. That way you can do blitAlphaImageToScreen() and have the transparent parts work right. That allows for sprites and cursors and such. Oh, and I fixed the boolean operator on the cursor move test so that it shows the move if EITHER x OR y is different.

Code:
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspumd.h>
#include <string.h>
#include <stdlib.h>

#include "graphics.h"
#include "framebuffer.h"

#include <png.h>

PSP_MODULE_INFO("lol", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

#define printf pspDebugScreenPrintf
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))

void dump_threadstatus(void);

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

int x = 0;
int y = 0;
int ox;
int oy;


int main(void)
{
   SceCtrlData pad;
   Image* cursor;
   Image* background;

   pspDebugScreenInit();
   pspDebugScreenSetBackColor(0xFFFFFFFF);
   pspDebugScreenSetTextColor(0);

   SetupCallbacks();

   initGraphics();
   sceCtrlSetSamplingMode(1);
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

   background = loadImage("background.png");
   if (!background)
   {
      printf(" Couldn't load background.png!\n");
      sceKernelExitGame();
   }
   cursor = loadImage("cursor.png");
   if (!cursor)
   {
      printf(" Couldn't load cursor.png!\n");
      sceKernelExitGame();
   }
   blitImageToScreen(0 ,0 , 480, 272, background, 0, 0);
   blitAlphaImageToScreen(0 ,0 , 10, 10, cursor, x, y); // show initially
   sceDisplayWaitVblankStart();
   flipScreen();

   while(1)
   {
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_CIRCLE) break;

      if (pad.Lx > 150) x++;
      if (pad.Lx < 110) x--;
      if (pad.Ly > 150) y++;
      if (pad.Ly < 110) y--;
      if (x < 0) x = 0;
      else if (x > 479) x = 479;
      if (y < 0) y = 0;
      else if (y > 271) y = 271;

      if(x != ox || y != oy)
      {
         blitImageToScreen(0 ,0 , 480, 272, background, 0, 0);
         blitAlphaImageToScreen(0 ,0 , 10, 10, cursor, x, y);
         sceDisplayWaitVblankStart();
         flipScreen();
      }
      ox = x;
      oy = y;
   }
   sceKernelExitGame();
   return 0;
}


EBOOT.PBP, background.png, and cursor.png:
http://www.mediafire.com/?8g0tuzjmnmo
Back to top
View user's profile Send private message AIM Address
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Oct 23, 2007 7:31 am    Post subject: Reply with quote

Oh, if you want a faster cursor, you can change the pad code to be like this:

Code:
      if (pad.Lx > 144) x+=(pad.Lx-128)>>4;
      if (pad.Lx < 112) x-=(128-pad.Lx)>>4;
      if (pad.Ly > 144) y+=(pad.Ly-128)>>4;
      if (pad.Ly < 112) y-=(128-pad.Ly)>>4;


That makes the cursor move farther the more you push the analog pad.
Back to top
View user's profile Send private message AIM Address
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Tue Oct 23, 2007 7:37 am    Post subject: Reply with quote

wow...
thanks...

"i love u"
JoKe

you have help me a lot...

and all the others ;)

next question comes in

8-16 hurs
(i musst sleep...
at my time its 11.38 pm [or 23.38])

CyA all
/=0
_________________
Sry for my english
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Oct 23, 2007 12:37 pm    Post subject: Reply with quote

Another update. You asked about anigif earlier - well here's a compile of giflib for the PSP and modifications to the test app to show how to use anigifs in the program. Maybe not the most efficient method, but simple. It creates one image for the anigif, then converts the current frame into image format before blitting it. If you had more anigifs to deal with, maybe you'd allocate enough images to hold all the frames, then convert them at the start of the app.

Two archives.

The test app - code as well as EBOOT and required files.
http://www.mediafire.com/?0pkxfndolbz

GIFLIB - the whole directory already compiled. You can just decompress it, cd to lib and "make install" to install the lib and include.
http://www.mediafire.com/?etzdjrhxuzd

Making giflib was pretty much like making flac (or many other libs).

Code:
Making giflib on the PSP
========================

1 - Download latest giflib source archive from SourceForge.

http://sourceforge.net/project/showfiles.php?group_id=102202&package_id=119585

2 - Unpack archive.

3 - Edit config.sub: look for

   ps2)
      basic_machine=i386-ibm
      ;;


and paste this right after it

   psp)
      basic_machine=mipsallegrexel-psp
      os=-elf
      ;;

4 - Run:

CFLAGS="-ffast-math -fsigned-char -G0" LDFLAGS="-L$(psp-config --pspsdk-path)/lib -lc -lpspuser" ./configure --host=psp --prefix=$(psp-config --psp-prefix)
cd lib
make
make install


The only odd thing is gif_err.c uses fprintf(stderr,...), and I wasn't sure what to do about stderr, so if you look at main.c for the code, you'll see I just fake it. If anyone has better stderr code, please post it. :)
Back to top
View user's profile Send private message AIM Address
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Tue Oct 23, 2007 9:15 pm    Post subject: edited! Reply with quote

J.F. wrote:
_.-noel-._ wrote:
cool, thx...

my last question(i hope) is:

what is the last parameter for

Code:

blitImageToImage(0, 0, 10, 10, cursor, x, y, *?*);


must this be the picture, where "cursor" is over the picture, may be "bg" ?


On Image to Image, the last parameter is the destination image of course.




Okay, but what is "destination image" i don't understand it...

---

Can i use in

Code:
blitImageToScreen


this:

Code:

blitImageToScreen(0 ,0 ,cusror->imageHeight , cursor->imageWidth, cursor, 0, 0);


And, in
Code:

      if(x != ox || y != oy)
      {
         blitImageToScreen(0 ,0 , 480, 272, background, 0, 0);
         blitAlphaImageToScreen(0 ,0 , 10, 10, cursor, x, y);
         sceDisplayWaitVblankStart();
         flipScreen();
      }


must there the

Code:
blitImageToScreen(0 ,0 , 480, 272, background, 0, 0);


because i have an animated background, and if i move the pad, it load the animation new... or not ?

--edit--

okay, new problem...

i want to load 22 pictures, but when i start the program, it load not all images.. then the psp freeze and shut down....

is the psp ram full?
what is happened?

my code:

Code:

void load(void)
{

     Image* load[22];

     load[0] = loadImage("images/load/1.png");

     load[1] = loadImage("images/load/2.png");

     load[2] = loadImage("images/load/3.png");
    load[3] = loadImage("images/load/4.png");
    load[4] = loadImage("images/load/5.png");
    load[5] = loadImage("images/load/6.png");
    load[6] = loadImage("images/load/7.png");
    load[7] = loadImage("images/load/8.png");
    load[8] = loadImage("images/load/9.png");
    load[9] = loadImage("images/load/10.png");
    load[10] = loadImage("images/load/11.png");
    load[11] = loadImage("images/load/12.png");
    load[12] = loadImage("images/load/13.png");
    load[13] = loadImage("images/load/14.png");
    load[14] = loadImage("images/load/15.png");
    load[15] = loadImage("images/load/16.png");
    load[16] = loadImage("images/load/17.png");
    load[17] = loadImage("images/load/18.png");
    load[18] = loadImage("images/load/19.png");
    load[19] = loadImage("images/load/20.png");
    load[20] = loadImage("images/load/21.png");
    load[21] = loadImage("images/load/22.png");
   for(i=0;i<20;i++)
   {
   if (!load[i])
   {
      printf(" Couldn't load: load[i]!\n");
      sceKernelExitGame();
   }
   }

   for(i=0;i<22;i++)
   {
      blitImageToScreen(0 ,0 ,479 , 271, load[i], 0, 0);
      sceDisplayWaitVblankStart();
      flipScreen();
                freeImage(load[i]);
      sceKernelDelayThread(100*1000);
   }

}


but the psp freeze may be after image 19 or 20 ...
_________________
Sry for my english
Back to top
View user's profile Send private message
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Tue Oct 23, 2007 11:26 pm    Post subject: Reply with quote

okay, i have tested, it show all images...
but, now, i have a new problem...
hire is my code...
i don't know, what is wrong?
after
Code:

splash();

the psp LCD is black, and it goes to the XMB...

Code:

Code:

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspumd.h>
#include <string.h>
#include <stdlib.h>
#include "wait.h"
#include "graphics.h"
#include "framebuffer.h"
#include <png.h>

PSP_MODULE_INFO("lol", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

#define printf pspDebugScreenPrintf

void dump_threadstatus(void);

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

int x = 0;
int y = 0;
int ox;
int oy;
int i;

void splash(void) {
   Image* splash;
   splash = loadImage("images/splash.png");
   if (!splash)
   {
      printf(" Couldn't load splash!\n");
      sceKernelExitGame();
   }
   sceDisplayWaitVblankStart();
   blitImageToScreen(0 ,0 ,480 , 272, splash, 0, 0);
   flipScreen();
   wait(240);
}

void load(void)
{

     Image* load[22];

     load[0] = loadImage("images/load/1.png");

     load[1] = loadImage("images/load/2.png");

     load[2] = loadImage("images/load/3.png");
    load[3] = loadImage("images/load/4.png");
    load[4] = loadImage("images/load/5.png");
    load[5] = loadImage("images/load/6.png");
    load[6] = loadImage("images/load/7.png");
    load[7] = loadImage("images/load/8.png");
    load[8] = loadImage("images/load/9.png");
    load[9] = loadImage("images/load/10.png");
    load[10] = loadImage("images/load/11.png");
    load[11] = loadImage("images/load/12.png");
    load[12] = loadImage("images/load/13.png");
    load[13] = loadImage("images/load/14.png");
    load[14] = loadImage("images/load/15.png");
    load[15] = loadImage("images/load/16.png");
    load[16] = loadImage("images/load/17.png");
    load[17] = loadImage("images/load/18.png");
    load[18] = loadImage("images/load/19.png");
    load[19] = loadImage("images/load/20.png");
    load[20] = loadImage("images/load/21.png");
    load[21] = loadImage("images/load/22.png");
   for(i=0;i<22;i++)
   {
   if (!load[i])
   {
      printf(" Couldn't load: load!\n");
      sceKernelExitGame();
   }
   }

   for(i=0;i<22;i++)
   {
      blitImageToScreen(0 ,0 ,479 , 271, load[i], 0, 0);
      sceDisplayWaitVblankStart();
      flipScreen();
      sceKernelDelayThread(1*1000*1000);
   }

}

void border(void)
{
   Image* border;
   border = loadImage("images/border.png");
   if (!border)
   {
      printf(" Couldn't load border.png!\n");
      sceKernelExitGame();
   }
   sceDisplayWaitVblankStart();
   blitImageToScreen(0 ,0 ,480 , 272, border, 0, 0);
   flipScreen();
}
int main(void)
{
   
   SceCtrlData pad;
   
   Image* cursor;

   pspDebugScreenInit();
   pspDebugScreenSetBackColor(0xFFFFFFFF);
   pspDebugScreenSetTextColor(0);

   SetupCallbacks();

   initGraphics();
   sceCtrlSetSamplingMode(1);
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
   
   cursor = loadImage("images/cursor.png");
   if (!cursor)
   {
      printf(" Couldn't load cursor.png!\n");
      sceKernelExitGame();
   }


   splash();
   load();
   
   Image* lines[20];
   lines[0] = loadImage("images/lines/1.png");

    lines[1] = loadImage("images/lines/2.png");

    lines[2] = loadImage("images/lines/3.png");
   lines[3] = loadImage("images/lines/4.png");
   lines[4] = loadImage("images/lines/5.png");
   lines[5] = loadImage("images/lines/6.png");
   lines[6] = loadImage("images/lines/7.png");
   lines[7] = loadImage("images/lines/8.png");
   lines[8] = loadImage("images/lines/9.png");
   lines[9] = loadImage("images/lines/10.png");
   lines[10] = loadImage("images/lines/11.png");
   lines[11] = loadImage("images/lines/12.png");
   lines[12] = loadImage("images/lines/13.png");
   lines[13] = loadImage("images/lines/14.png");
   lines[14] = loadImage("images/lines/15.png");
   lines[15] = loadImage("images/lines/16.png");
   lines[16] = loadImage("images/lines/17.png");
   lines[17] = loadImage("images/lines/18.png");
   lines[18] = loadImage("images/lines/19.png");
   lines[19] = loadImage("images/lines/20.png");
   for(i=0;i<20;i++)
   {
   if (!lines[i])
   {
      printf(" Couldn't load: lines[i]!\n");
      sceKernelExitGame();
   }
   }
   
   //border();
   blitAlphaImageToScreen(0 ,0 , 10, 10, cursor, x, y);
   sceDisplayWaitVblankStart();
   flipScreen();
   
   for(i=0;i<20;i++)
   {
      blitImageToScreen(0 ,0 ,479 , 271, lines[i], 0, 0);
      sceDisplayWaitVblankStart();
      flipScreen();
      sceKernelDelayThread(1*1000*1000);
   
   while(1)
   {
   
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_CIRCLE) sceKernelExitGame();

      if (pad.Lx > 150) x++;
      if (pad.Lx < 110) x--;
      if (pad.Ly > 150) y++;
      if (pad.Ly < 110) y--;
      if (x < 0) x = 0;
      else if (x > 479) x = 479;
      if (y < 0) y = 0;
      else if (y > 271) y = 271;

      if(x != ox || y != oy)
      {
         blitImageToScreen(0 ,0 , 480, 272, lines[i], 0, 0);
         blitAlphaImageToScreen(0 ,0 , 10, 10, cursor, x, y);
         sceDisplayWaitVblankStart();
         flipScreen();
      }
      ox = x;
      oy = y;
   }
   if(i==20) i=0;
   }
   return 0;
}



i dont know, how i must load the animated background...
i have tried this....but i think it dont work...

but so far, i didn't come ^^
because after "splash" the psp goto the XMB...
_________________
Sry for my english
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Oct 24, 2007 4:16 am    Post subject: Reply with quote

To answer a few questions:

blitImage2Image() blits one image into a second image. You would use this if the image you wanted to blit to the screen was made of multiple images that you wanted to put together at the start rather than during the main loop.

Your program clearly exits in splash because it didn't load. You couldn't see the printf because you don't wait after printing - you just exit. Put a wait after any printing so you have time to read the message.

In my example, I had one background image, but you can have as many as you like (or have memory for). You could have

Code:
blitImageToScreen(0 ,0 , 480, 272, background[currBack], 0, 0);


and change currBack under various conditions. You could also construct the background image from lots of smaller images. That is common in 2D games. The main 480x272 background could be drawn from 60x34 smaller images of 8x8 each. Rather than describe the background, you describe which 8x8 cell makes each spot in the 60x34 map. That is where the blitImage2Image comes in handy. You go in a loop of 60x34 where you look up which source cell to blit into the background image.
Back to top
View user's profile Send private message AIM Address
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Wed Oct 24, 2007 6:34 am    Post subject: Reply with quote

thx, bit the last thing i didnt understand...

i have edited my code, befor you post...

now, i load, the "load", and after that, the cursor, the border(at top) and the animated background...

but i won't work fine...
here is my code:

Code:

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspumd.h>
#include <string.h>
#include <stdlib.h>
#include "wait.h"
#include "graphics.h"
#include "framebuffer.h"
#include <png.h>

PSP_MODULE_INFO("--", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

#define printf pspDebugScreenPrintf

void dump_threadstatus(void);

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

int x = 0;
int y = 0;
int i;
int error = 0;

int main(void)
{
   
   SceCtrlData pad;
   
   Image* splash;
   Image* cursor;
   Image* border;
   Image* load[19];
   Image* lines[19];
   
   pspDebugScreenInit();
   pspDebugScreenClear();
   pspDebugScreenSetBackColor(0xFFFFFFFF);
   pspDebugScreenSetTextColor(0);

   SetupCallbacks();

   initGraphics();
   sceCtrlSetSamplingMode(1);
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

   cursor = loadImage("images/cursor.png");
   if (!cursor)
   {
      printf(" Couldn't load cursor.png!\n");
      wait(240);
      sceKernelExitGame();
   }
   border = loadImage("images/border.png");
   if (!border)
   {
      printf(" Couldn't load border.png!\n");
      wait(240);
      sceKernelExitGame();
   }
   splash = loadImage("images/splash.png");
   if (!splash)
   {
      printf(" Couldn't load splash!\n");
      wait(240);
      sceKernelExitGame();
   }
   
   
   sceDisplayWaitVblankStart();
   blitImageToScreen(0 ,0 , splash->imageWidth, splash->imageHeight, splash, 0, 0);
   printTextScreen(140, 262, "Please wait, while loading...", 0);
   flipScreen();
   freeImage(splash);

    load[0] = loadImage("images/load/1.png");

    load[1] = loadImage("images/load/2.png");

    load[2] = loadImage("images/load/3.png");
   load[3] = loadImage("images/load/4.png");
   load[4] = loadImage("images/load/5.png");
   load[5] = loadImage("images/load/6.png");
   load[6] = loadImage("images/load/7.png");
   load[7] = loadImage("images/load/8.png");
   load[8] = loadImage("images/load/9.png");
   load[9] = loadImage("images/load/10.png");
   load[10] = loadImage("images/load/11.png");
   load[11] = loadImage("images/load/12.png");
   load[12] = loadImage("images/load/13.png");
   load[13] = loadImage("images/load/14.png");
   load[14] = loadImage("images/load/15.png");
   load[15] = loadImage("images/load/16.png");
   load[16] = loadImage("images/load/17.png");
   load[17] = loadImage("images/load/18.png");
   load[18] = loadImage("images/load/19.png");
   //load[19] = loadImage("images/load/20.png");
   //load[20] = loadImage("images/load/21.png");
   //load[21] = loadImage("images/load/22.png");
   for(i=0;i<19;i++)
   {
      blitImageToScreen(0 ,0 , load[i]->imageWidth, load[i]->imageHeight, load[i], 0, 0);
      sceDisplayWaitVblankStart();
      flipScreen();
      freeImage(load[i]);
      sceKernelDelayThread(100*1000);
   }
   //-----------------------------------------------------------------------------------------------------//
   //-----------------------------------------------------------------------------------------------------//
   lines[0] = loadImage("images/lines/1.png");

    lines[1] = loadImage("images/lines/2.png");

    lines[2] = loadImage("images/lines/3.png");
   lines[3] = loadImage("images/lines/4.png");
   lines[4] = loadImage("images/lines/5.png");
   lines[5] = loadImage("images/lines/6.png");
   lines[6] = loadImage("images/lines/7.png");
   lines[7] = loadImage("images/lines/8.png");
   lines[8] = loadImage("images/lines/9.png");
   lines[9] = loadImage("images/lines/10.png");
   lines[10] = loadImage("images/lines/11.png");
   lines[11] = loadImage("images/lines/12.png");
   lines[12] = loadImage("images/lines/13.png");
   lines[13] = loadImage("images/lines/14.png");
   lines[14] = loadImage("images/lines/15.png");
   lines[15] = loadImage("images/lines/16.png");
   lines[16] = loadImage("images/lines/17.png");
   lines[17] = loadImage("images/lines/18.png");
   lines[18] = loadImage("images/lines/19.png");
   //lines[19] = loadImage("images/lines/20.png");
   pspDebugScreenClear();
   while(1){
   for(i=0;i<19;i++)
   {
      blitImageToScreen(0 ,0 , lines[i]->imageWidth, lines[i]->imageHeight, lines[i], 0, 0);
      blitAlphaImageToScreen(0, 0, border->imageWidth, border->imageHeight, border, 0, 0);
      blitAlphaImageToScreen(0 ,0 , cursor->imageWidth, cursor->imageHeight, cursor, x, y);
      sceDisplayWaitVblankStart();
      flipScreen();
      sceDisplayWaitVblankStart();
      flipScreen();
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_CIRCLE) printf("lol");

      if (pad.Lx > 144) x+=(pad.Lx-128)>>4;
      if (pad.Lx < 112) x-=(128-pad.Lx)>>4;
      if (pad.Ly > 144) y+=(pad.Ly-128)>>4;
      if (pad.Ly < 112) y-=(128-pad.Ly)>>4;
      if (x < 0) x = 0;
      else if (x > 479) x = 479;
      if (y < 0) y = 0;
      else if (y > 271) y = 271;
   }
   }
   return 0;
}


i dont know, how i can "make" i++ and the other loop...
...

I hope somebody can fix this for me <3

The background must be animated, the cursor must move, and the border must stay there ^^

at my code, all this work, but it always load "all"...
_________________
Sry for my english
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Oct 24, 2007 7:38 am    Post subject: Reply with quote

Well, you flip the screen twice in your loop. That means you'll never see anything but the second screen. Only flip once per loop. Get rid of the second

Code:
      sceDisplayWaitVblankStart();
      flipScreen();
Back to top
View user's profile Send private message AIM Address
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Wed Oct 24, 2007 8:32 am    Post subject: Reply with quote

oO

and then it works perfectly?
_________________
Sry for my english
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Oct 24, 2007 9:23 am    Post subject: Reply with quote

_.-noel-._ wrote:
oO

and then it works perfectly?


Assuming you made your images right, it should at least show something. :)

Remember when making the pngs to make the background transparent in whatever picture editing software you're using. I use GIMP, and when you make a new image, you have to go into "Advanced options" and set "Fill with:" to "Transparency". If your image is solid, blitAlphaImageToScreen() will simply overwrite everything that was there before.

Look at that cursor in my archive (expand it to 800% for a good view). You'll notice that the area around the cursor is transparent, not filled with a background color.
Back to top
View user's profile Send private message AIM Address
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Thu Oct 25, 2007 12:56 am    Post subject: Reply with quote

okay..

new problem...

How many Images can i put in an array?

only 19?
(with 480 x 272)

Or can i load the images every time from the MS?
but then the PSP is slower....or?

i have 1 animation with 22 Images ant 1 Animation with 20 Iages...

PlZ Help
_________________
Sry for my english
Back to top
View user's profile Send private message
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Thu Oct 25, 2007 2:15 am    Post subject: Reply with quote

J.F. wrote:
Another update. You asked about anigif earlier - well here's a compile of giflib for the PSP and modifications to the test app to show how to use anigifs in the program. Maybe not the most efficient method, but simple. It creates one image for the anigif, then converts the current frame into image format before blitting it. If you had more anigifs to deal with, maybe you'd allocate enough images to hold all the frames, then convert them at the start of the app.

Two archives.

The test app - code as well as EBOOT and required files.
http://www.mediafire.com/?0pkxfndolbz

GIFLIB - the whole directory already compiled. You can just decompress it, cd to lib and "make install" to install the lib and include.
http://www.mediafire.com/?etzdjrhxuzd

Making giflib was pretty much like making flac (or many other libs).

Code:
Making giflib on the PSP
========================

1 - Download latest giflib source archive from SourceForge.

http://sourceforge.net/project/showfiles.php?group_id=102202&package_id=119585

2 - Unpack archive.

3 - Edit config.sub: look for

   ps2)
      basic_machine=i386-ibm
      ;;


and paste this right after it

   psp)
      basic_machine=mipsallegrexel-psp
      os=-elf
      ;;

4 - Run:

CFLAGS="-ffast-math -fsigned-char -G0" LDFLAGS="-L$(psp-config --pspsdk-path)/lib -lc -lpspuser" ./configure --host=psp --prefix=$(psp-config --psp-prefix)
cd lib
make
make install


The only odd thing is gif_err.c uses fprintf(stderr,...), and I wasn't sure what to do about stderr, so if you look at main.c for the code, you'll see I just fake it. If anyone has better stderr code, please post it. :)


Okay, i can't load the firs file down....

and if i want to compile it at myself, it give me some errors...
and you 2# link goes, but if i want to extract the files, it give me an error...

...
_________________
Sry for my english
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Thu Oct 25, 2007 4:14 am    Post subject: Reply with quote

_.-noel-._ wrote:
okay..

new problem...

How many Images can i put in an array?

only 19?
(with 480 x 272)

Or can i load the images every time from the MS?
but then the PSP is slower....or?

i have 1 animation with 22 Images ant 1 Animation with 20 Iages...

PlZ Help


480x272x4x20 ~ 10MB

Most people don't store the entire image for animations unless they are small. It's better to keep them in some kind of difference format (simple compression) to use less space, then generate them on the fly. You could also load them off the memstick on the fly, but that would slow things down quite a bit. One thing you can do - not use 32 bit images. Using 16 bit images cuts the memory used in half. Especially where you only have opaque/fully transparent pixel data, the 5551 format would be very good for sprites and cursors and such.

MediaFire can get bogged down at times. I've put both directories in a single arc on sendspace here:
http://www.sendspace.com/file/gjlk3c

That link won't last as long as mediafire, but I don't think sendspace bogs down as much BECAUSE they toss old links.
Back to top
View user's profile Send private message AIM Address
_.-noel-._



Joined: 13 Aug 2007
Posts: 49

PostPosted: Thu Oct 25, 2007 4:19 am    Post subject: Reply with quote

okay, i dont know, what you mean....
_________________
Sry for my english
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Thu Oct 25, 2007 5:47 am    Post subject: Reply with quote

Look at your images. It's worse than I originally calculated since image dimensions are rounded up to the next power of two so that they can be used as textures. So a 480x272 png loaded as an image will have memory allocated for a 512x512 texture. This is an 8888 (32 bit ABGR) texture, so each texel takes 4 bytes. So the space occupied by one 480x272 image is 512x512x4, or 1MB. So 20 such images will take 20 MB of space. So it's no wonder you're having trouble getting your program to run.

You need to cut back on how you use images. The PSP simply doesn't have the ram for that. You need to compress the images in some manner and only decompress them into a single image when you wish to use it. Or load each image from the memstick when you want it (and put up with the slow down).

First, don't use 480x272 images if you don't need to. Rather than one 480x272 image for borders, make a few small images that handle the corners, a segment of the side, and a segment of the top. Then use those to draw the borders around the screen. One side or the top is all you need - just invert the image to do the other side or bottom. One corner is all you need as well - just flip it around for the corner you want to draw. Do everything you can to conserve space.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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