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 

SDL and PSP 3000

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



Joined: 13 Jul 2009
Posts: 5

PostPosted: Mon Jul 27, 2009 12:06 pm    Post subject: SDL and PSP 3000 Reply with quote

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:

/* 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(int argc, char *argv[])
{
    int done = 0;

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
    {
        return 1;
    }

    if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_OPENGL | SDL_FULLSCREEN) == NULL)
    {
        SDL_Quit();
        return 1;
    }

    glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2, 2, -2, 2, -2, 2);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

  while (!done)
    {
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

        angle += delta;
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotatef(angle * 1.32f, 0.0f, 0.0f, 1.0f);

        glShadeModel(GL_SMOOTH);

        glClear(GL_COLOR_BUFFER_BIT);
        glBegin(GL_TRIANGLES);
            glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(1.0f, 0.0f, 0.0f);
            glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f);
            glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 1.0f);
        glEnd();
        glFinish();

        SDL_GL_SwapBuffers();
    }

    return 0;
}


Makefile:
Code:

TARGET = main
PSPSDK = $(shell psp-config --pspsdk-path)
PSPPREFIX = $(shell psp-config --psp-prefix)
PSPBIN = $(PSPPREFIX)/bin
SDL_CONFIG = $(PSPBIN)/sdl-config

OBJS =  $(TARGET).o

DEFAULT_CFLAGS = $(shell $(SDL_CONFIG) --cflags)

MORE_CFLAGS = -O2 -fsingle-precision-constant

CFLAGS = $(DEFAULT_CFLAGS) $(MORE_CFLAGS)
CXXFLAGS = $(DEFAULT_CFLAGS) $(MORE_CFLAGS) -fno-exceptions

LDFLAGS = -L$(PSPPREFIX)/lib
LIBS = -lGL -lGLU -lpspvfpu $(shell $(SDL_CONFIG) --libs) -lstdc++ -lm

EXTRA_TARGETS = EBOOT.PBP

include $(PSPSDK)/lib/build.mak
Back to top
View user's profile Send private message
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Mon Jul 27, 2009 6:59 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
iceman755



Joined: 21 Jul 2008
Posts: 34

PostPosted: Tue Jul 28, 2009 12:18 am    Post subject: Reply with quote

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"
Back to top
View user's profile Send private message
yargon



Joined: 13 Jul 2009
Posts: 5

PostPosted: Wed Aug 05, 2009 8:30 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Aug 05, 2009 12:05 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
yargon



Joined: 13 Jul 2009
Posts: 5

PostPosted: Sun Aug 09, 2009 6:47 am    Post subject: SDL and PSP 3000 Reply with quote

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:

#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(20400);

SDL_Surface* screen = NULL;

int SDL_main(int argc, char *argv[])
{
   int done = 0;

   if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
   {
      fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
      return 1;
   }

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


makefile
Code:

TARGET = sdltest
PSPSDK = $(shell psp-config --pspsdk-path)
PSPPREFIX = $(shell psp-config --psp-prefix)
PSPBIN = $(PSPPREFIX)/bin
SDL_CONFIG = $(PSPBIN)/sdl-config
OBJS =  main.o

DEFAULT_CFLAGS = $(shell $(SDL_CONFIG) --cflags)
MORE_CFLAGS = -O2 -fsingle-precision-constant

CFLAGS = $(DEFAULT_CFLAGS) $(MORE_CFLAGS)
CXXFLAGS = $(DEFAULT_CFLAGS) $(MORE_CFLAGS) -fno-exceptions

LDFLAGS = -L$(PSPPREFIX)/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 $(PSPSDK)/lib/build.mak


SDL is there any way out to make a simple 2D game?

Thank you!
Back to top
View user's profile Send private message
iceman755



Joined: 21 Jul 2008
Posts: 34

PostPosted: Sun Aug 09, 2009 11:07 am    Post subject: Reply with quote

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:
#include <pspkernel.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>

#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272

PSP_MODULE_INFO("SDLTEST",0, 1, 0);

PSP_HEAP_SIZE_KB(20400);

SDL_Surface* screen = NULL;

int main(int argc, char *argv[])
{
   int done = 0;

   if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
   {
      fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
      return 1;
   }

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


makefile
Code:
TARGET = SDLTest
OBJS = main.o

PSPSDK=$(shell psp-config --pspsdk-path)
PSPBIN = $(shell psp-config —psp-prefix)/bin
CFLAGS = -O2 -G0 -Wall -g
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

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 $(PSPSDK)/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"
Back to top
View user's profile Send private message
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