SDL launching error

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

Moderators: cheriff, TyRaNiD

Post Reply
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

SDL launching error

Post by jojojoris »

I'm trying to make a basic SDL program for my Slim.
This is the source:
main.c

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <pspkernel.h> 
#include <pspdebug.h>

#include <SDL/SDL.h>

/* Exit callback */ 
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123; 
          sceKernelExitGame&#40;&#41;; 
          return 0; 
&#125; 
 
/* Callback thread */ 
int CallbackThread&#40;SceSize args, void *argp&#41; &#123; 
          int cbid; 
 
          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;; 
          sceKernelRegisterExitCallback&#40;cbid&#41;; 
 
          sceKernelSleepThreadCB&#40;&#41;; 
 
          return 0; 
&#125; 
 
/* Sets up the callback thread and returns its thread id */ 
int SetupCallbacks&#40;void&#41; &#123; 
          int thid = 0; 
 
          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;; 
          if&#40;thid >= 0&#41; &#123; 
                    sceKernelStartThread&#40;thid, 0, 0&#41;; 
          &#125; 
 
          return thid; 
&#125; 

void Slock&#40;SDL_Surface *screen&#41;
&#123;
  if &#40; SDL_MUSTLOCK&#40;screen&#41; &#41;
  &#123;
    if &#40; SDL_LockSurface&#40;screen&#41; < 0 &#41;
    &#123;
      return;
    &#125;
  &#125;
&#125;

void Sulock&#40;SDL_Surface *screen&#41;
&#123;
  if &#40; SDL_MUSTLOCK&#40;screen&#41; &#41;
  &#123;
    SDL_UnlockSurface&#40;screen&#41;;
  &#125;
&#125;

void DrawPixel&#40;SDL_Surface *screen, int x, int y,
                                    Uint8 R, Uint8 G, Uint8 B&#41;
&#123;
  Uint32 color = SDL_MapRGB&#40;screen->format, R, G, B&#41;;
  switch &#40;screen->format->BytesPerPixel&#41;
  &#123;
    case 1&#58; // Assuming 8-bpp
      &#123;
        Uint8 *bufp;
        bufp = &#40;Uint8 *&#41;screen->pixels + y*screen->pitch + x;
        *bufp = color;
      &#125;
      break;
    case 2&#58; // Probably 15-bpp or 16-bpp
      &#123;
        Uint16 *bufp;
        bufp = &#40;Uint16 *&#41;screen->pixels + y*screen->pitch/2 + x;
        *bufp = color;
      &#125;
      break;
    case 3&#58; // Slow 24-bpp mode, usually not used
      &#123;
        Uint8 *bufp;
        bufp = &#40;Uint8 *&#41;screen->pixels + y*screen->pitch + x * 3;
        if&#40;SDL_BYTEORDER == SDL_LIL_ENDIAN&#41;
        &#123;
          bufp&#91;0&#93; = color;
          bufp&#91;1&#93; = color >> 8;
          bufp&#91;2&#93; = color >> 16;
        &#125; else &#123;
          bufp&#91;2&#93; = color;
          bufp&#91;1&#93; = color >> 8;
          bufp&#91;0&#93; = color >> 16;
        &#125;
      &#125;
      break;
    case 4&#58; // Probably 32-bpp
      &#123;
        Uint32 *bufp;
        bufp = &#40;Uint32 *&#41;screen->pixels + y*screen->pitch/4 + x;
        *bufp = color;
      &#125;
      break;
  &#125;
&#125;

void DrawScene&#40;SDL_Surface *screen&#41;
&#123;
  //Slock&#40;screen&#41;;
  int x,y;
  x=0;
  y=0;
  for&#40;x=0;x<480;x++&#41;
  &#123;
    for&#40;y=0;y<272;y++&#41;
    &#123;
      DrawPixel&#40;screen, x,y,y/2,y/2,x/3&#41;;
    &#125;
  &#125;
  //Sulock&#40;screen&#41;;
  SDL_Flip&#40;screen&#41;;
&#125;

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
  if &#40; SDL_Init&#40;SDL_INIT_AUDIO|SDL_INIT_VIDEO&#41; < 0 &#41;
  &#123;
	pspDebugScreenPrintf&#40;"Unable to init SDL&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
    exit&#40;1&#41;;
  &#125;

  SDL_Surface *screen;
  screen=SDL_SetVideoMode&#40;480,272,0,SDL_HWSURFACE|SDL_DOUBLEBUF&#41;;
  if &#40; screen == NULL &#41;
  &#123;
	  pspDebugScreenPrintf&#40;"Unable to set 480x272 video&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
    exit&#40;1&#41;;
  &#125;
  int done=0;

  while&#40;done == 0&#41;
  &#123;
    SDL_Event event;

    while &#40; SDL_PollEvent&#40;&event&#41; &#41;
    &#123;
      if &#40; event.type == SDL_QUIT &#41;  &#123;  done = 1;  &#125;

      if &#40; event.type == SDL_KEYDOWN &#41;
      &#123;
        if &#40; event.key.keysym.sym == SDLK_ESCAPE &#41; &#123; done = 1; &#125;
      &#125;
    &#125;

    DrawScene&#40;screen&#41;;
  &#125;
  SDL_Quit&#40;&#41;;
  sceKernelSleepThread&#40;&#41;;
  return 0;
&#125;
and my makefile:

Code: Select all

TARGET = SDL_test
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;
LIBDIR =

LIBS = -lmad -lpspaudiolib -lpspaudio -lpsppower
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SDL_test
PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;

PSPBIN = $&#40;PSPSDK&#41;/../bin
CFLAGS += $&#40;shell $&#40;PSPBIN&#41;/sdl-config --cflags&#41;
LIBS += $&#40;shell $&#40;PSPBIN&#41;/sdl-config --libs&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
Compiling works

But when i put in into my GAME directory on my psp and try to start it, it gives an error: "The game could not be started"
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Post Reply