SDL and PSP 3000

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
yargon
Posts: 5
Joined: Mon Jul 13, 2009 11:54 am

SDL and PSP 3000

Post by yargon »

Hi, I am having a problem with the SDL in the PSP 3000.
I made a small code but did not work, the PSP crashes and restarts, or even the emulator (JPCSP) can run this example, the emulator reports the this error:

10234 [user_main] ERROR memory - write32 - Invalid memory address: 0x8AC PC = 089016C0

Below is my source:

main.cpp:

Code: Select all

/* Test SDL OpenGL support. */
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272

static GLfloat delta = 1.0f;
static GLfloat angle;

extern "C" int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
    int done = 0;

    if &#40;SDL_Init&#40;SDL_INIT_VIDEO | SDL_INIT_JOYSTICK&#41; < 0&#41;
    &#123;
        return 1;
    &#125;

    if &#40;SDL_SetVideoMode&#40;SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_OPENGL | SDL_FULLSCREEN&#41; == NULL&#41;
    &#123;
        SDL_Quit&#40;&#41;;
        return 1;
    &#125;

    glViewport&#40;0, 0, SCREEN_WIDTH, SCREEN_HEIGHT&#41;;
    glMatrixMode&#40;GL_PROJECTION&#41;;
    glLoadIdentity&#40;&#41;;
    glOrtho&#40;-2, 2, -2, 2, -2, 2&#41;;
    glMatrixMode&#40;GL_MODELVIEW&#41;;
    glLoadIdentity&#40;&#41;;

  while &#40;!done&#41;
    &#123;
        glClearColor&#40;0.0f, 0.0f, 0.0f, 0.0f&#41;;

        angle += delta;
        glMatrixMode&#40;GL_MODELVIEW&#41;;
        glLoadIdentity&#40;&#41;;
        glRotatef&#40;angle * 1.32f, 0.0f, 0.0f, 1.0f&#41;;

        glShadeModel&#40;GL_SMOOTH&#41;;

        glClear&#40;GL_COLOR_BUFFER_BIT&#41;;
        glBegin&#40;GL_TRIANGLES&#41;;
            glColor3f&#40;0.0f, 0.0f, 1.0f&#41;; glVertex3f&#40;1.0f, 0.0f, 0.0f&#41;;
            glColor3f&#40;0.0f, 1.0f, 0.0f&#41;; glVertex3f&#40;0.0f, 1.0f, 0.0f&#41;;
            glColor3f&#40;1.0f, 0.0f, 0.0f&#41;; glVertex3f&#40;0.0f, 0.0f, 1.0f&#41;;
        glEnd&#40;&#41;;
        glFinish&#40;&#41;;

        SDL_GL_SwapBuffers&#40;&#41;;
    &#125;

    return 0;
&#125;
Makefile:

Code: Select all

TARGET = main
PSPSDK = $&#40;shell psp-config --pspsdk-path&#41;
PSPPREFIX = $&#40;shell psp-config --psp-prefix&#41;
PSPBIN = $&#40;PSPPREFIX&#41;/bin
SDL_CONFIG = $&#40;PSPBIN&#41;/sdl-config

OBJS =  $&#40;TARGET&#41;.o

DEFAULT_CFLAGS = $&#40;shell $&#40;SDL_CONFIG&#41; --cflags&#41;

MORE_CFLAGS = -O2 -fsingle-precision-constant

CFLAGS = $&#40;DEFAULT_CFLAGS&#41; $&#40;MORE_CFLAGS&#41;
CXXFLAGS = $&#40;DEFAULT_CFLAGS&#41; $&#40;MORE_CFLAGS&#41; -fno-exceptions

LDFLAGS = -L$&#40;PSPPREFIX&#41;/lib
LIBS = -lGL -lGLU -lpspvfpu $&#40;shell $&#40;SDL_CONFIG&#41; --libs&#41; -lstdc++ -lm

EXTRA_TARGETS = EBOOT.PBP

include $&#40;PSPSDK&#41;/lib/build.mak
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

You're obviously trying to write at a forbidden address. I suggest you to use psplink, or if that doesnt work, disasm your ELF with prxtool and check for the address that causes the exception (0x089016C0). That should give you the hint about which function triggers the excep.
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
iceman755
Posts: 30
Joined: Mon Jul 21, 2008 1:12 am

Post by iceman755 »

I don't see a PSP_MODULE_INFO call in your code so if there is no error about this when you compile (first time you type make compiler complains about PSP_MODULE_INFO, second time you type make it compile) maybe you are using an old version of SDL that was in kernel mode, for the newest firmwares it must be in user mode (newest SDL is in user mode, I think).

But I'm sure the crash is because in your makefile you aren't building it for the newest firmwares (missing BUILD_PRX =1).
"Libera eas de ore leonis, ne absorbeat eas tartarus, ne cadant in obscurum"
yargon
Posts: 5
Joined: Mon Jul 13, 2009 11:54 am

Post by yargon »

I found the error using the psplink (disasm), the function that the error is occurring is the glViewport, but I think it makes sense, I compiled an example of using GLUT Nehe (PSPGL) and worked in PSP3000, i noted that the SDL uses the PSPGL, I believe it was for work, another detail that I noticed was that when I moved my code of structured (functional) oriented to the object, simply did not work more, the same error occurs in memory, someone knows the reason?

Grateful.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Maybe the link order... the GL libs should be AFTER the SDL libs seeing as he SDL libs use the GL libs and not the other way around.
yargon
Posts: 5
Joined: Mon Jul 13, 2009 11:54 am

SDL and PSP 3000

Post by yargon »

I tried to reorder the links but did not work ... i rewrite my code to try to use only 2D, but also did not work in PSP, but the Emulator JPCSP work (an error occurred -> (3890 [user_main] ERROR hle - Unmapped @ import 0x08800000), but if you choose to continue the game normally works, because the game hangs in PSP3000.

main.c

Code: Select all

#include <pspkernel.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>

#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272

PSP_HEAP_SIZE_KB&#40;20400&#41;;

SDL_Surface* screen = NULL;

int SDL_main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
	int done = 0;

	if &#40;SDL_Init&#40;SDL_INIT_VIDEO | SDL_INIT_JOYSTICK&#41; < 0&#41;
	&#123;
		fprintf&#40;stderr, "Unable to initialize SDL&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
		return 1;
	&#125;

	screen = SDL_SetVideoMode&#40;SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE | SDL_FULLSCREEN&#41;;
	if &#40;screen == NULL&#41;
	&#123;
		fprintf&#40;stderr, "Unable to create OpenGL screen&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
		SDL_Quit&#40;&#41;;
		return 1;
	&#125;
	//while &#40;!done&#41;
	&#123;
		SDL_FillRect&#40;screen, NULL, 0x00FFFFFF&#41;;
		SDL_Rect r;
		r.x = 50;
		r.y = 30;
		r.w = 100;
		r.h = 75;
		SDL_FillRect&#40;screen, &r, 0x00000000&#41;;
		
		SDL_Flip&#40;screen&#41;;
	&#125;
	return 0;
&#125;
makefile

Code: Select all

TARGET = sdltest
PSPSDK = $&#40;shell psp-config --pspsdk-path&#41;
PSPPREFIX = $&#40;shell psp-config --psp-prefix&#41;
PSPBIN = $&#40;PSPPREFIX&#41;/bin
SDL_CONFIG = $&#40;PSPBIN&#41;/sdl-config
OBJS =  main.o

DEFAULT_CFLAGS = $&#40;shell $&#40;SDL_CONFIG&#41; --cflags&#41;
MORE_CFLAGS = -O2 -fsingle-precision-constant

CFLAGS = $&#40;DEFAULT_CFLAGS&#41; $&#40;MORE_CFLAGS&#41;
CXXFLAGS = $&#40;DEFAULT_CFLAGS&#41; $&#40;MORE_CFLAGS&#41; -fno-exceptions

LDFLAGS = -L$&#40;PSPPREFIX&#41;/lib
LIBS = -L/usr/local/pspdev/psp/lib -lSDLmain -lSDL -lm -L/usr/local/pspdev/psp/sdk/lib -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspvfpu -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel
 
BUILD_PRX = 1
PSP_FW_VERSION = 500

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SDL Test

include $&#40;PSPSDK&#41;/lib/build.mak
SDL is there any way out to make a simple 2D game?

Thank you!
iceman755
Posts: 30
Joined: Mon Jul 21, 2008 1:12 am

Post by iceman755 »

I'll say it once again, maybe you are using and old version of SDL.

Try your code with this changes (little, but they are):

main.c

Code: Select all

#include <pspkernel.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <SDL/SDL.h> 

#define SCREEN_WIDTH 480 
#define SCREEN_HEIGHT 272 

PSP_MODULE_INFO&#40;"SDLTEST",0, 1, 0&#41;;

PSP_HEAP_SIZE_KB&#40;20400&#41;; 

SDL_Surface* screen = NULL; 

int main&#40;int argc, char *argv&#91;&#93;&#41; 
&#123; 
   int done = 0; 

   if &#40;SDL_Init&#40;SDL_INIT_VIDEO | SDL_INIT_JOYSTICK&#41; < 0&#41; 
   &#123; 
      fprintf&#40;stderr, "Unable to initialize SDL&#58; %s\n", SDL_GetError&#40;&#41;&#41;; 
      return 1; 
   &#125; 

   screen = SDL_SetVideoMode&#40;SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE | SDL_FULLSCREEN&#41;; 
   if &#40;screen == NULL&#41; 
   &#123; 
      fprintf&#40;stderr, "Unable to create OpenGL screen&#58; %s\n", SDL_GetError&#40;&#41;&#41;; 
      SDL_Quit&#40;&#41;; 
      return 1; 
   &#125; 
   //while &#40;!done&#41; 
   &#123; 
      SDL_FillRect&#40;screen, NULL, 0x00FFFFFF&#41;; 
      SDL_Rect r; 
      r.x = 50; 
      r.y = 30; 
      r.w = 100; 
      r.h = 75; 
      SDL_FillRect&#40;screen, &r, 0x00000000&#41;; 
       
      SDL_Flip&#40;screen&#41;; 
   &#125; 
   return 0; 
&#125; 
makefile

Code: Select all

TARGET = SDLTest
OBJS = main.o 

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
PSPBIN = $&#40;shell psp-config —psp-prefix&#41;/bin
CFLAGS = -O2 -G0 -Wall -g
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti 
ASFLAGS = $&#40;CFLAGS&#41; 

LIBS = -lz -lm  -lSDL -lGL -lpspvfpu -lpsphprm -lpspaudio -lpspgu

BUILD_PRX =1
PSP_FW_VERSION = 500
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SDL Test
include $&#40;PSPSDK&#41;/lib/build.mak
And this is the resulting EBOOT.PBP:
http://www.mediafire.com/?ammj2xmzezw

I didn't run it in a PSP3000 (I don't have one), but it works fine in a Slim, just try it and see what happens (observation: to exit you must turn off complete the PSP, because there is no exit callback implemented).
"Libera eas de ore leonis, ne absorbeat eas tartarus, ne cadant in obscurum"
Post Reply