I managed to get something compiled rather easily. When I ran it on my PSP, I was expecting something to go wrong, like getting one of the error messages or having my PSP explode, but what happened was completely unexpected. The screen was all black, except for an unmovable cursor in the upper left corner. I tinkered around with the code for a while, but all I managed to do was make the cursor blink when I tried different video modes.
I was completely clueless about what was going on (and still am), so I decided to compile the lesson2.cpp from the topic I mentioned above, and exactly the same thing occured.
Here is my code, in case that is the source of the problem:
Code: Select all
//////// Includes ////////
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <SDL.h>
//////// Definitions ////////
#define printf pspDebugScreenPrintf
#define PSP_SCREEN_WIDTH 480
#define PSP_SCREEN_HEIGHT 272
//////// Function Prototypes ////////
void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B);
void Slock(SDL_Surface *screen);
void Sulock(SDL_Surface *screen);
//////// Main Function ////////
extern "C" int SDL_main(int argc, char *argv[])
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("Unable to initiate video:\n%s", SDL_GetError());
sceKernelSleepThread();
}
atexit(SDL_Quit);
SDL_Surface *screen;
screen = SDL_SetVideoMode(480, 272, 32, SDL_SWSURFACE | SDL_FULLSCREEN);
if(screen == NULL)
{
printf("Unable to set 480x272x32 video mode:\n%s", SDL_GetError());
sceKernelSleepThread();
}
while(1)
{
Slock(screen);
for(int ly=0; ly >= PSP_SCREEN_HEIGHT; ly++)
{
for(int lx=0; lx >= PSP_SCREEN_WIDTH; lx++)
{
DrawPixel(screen, lx, ly, rand()%256, rand()%256, rand()%256);
}
}
Sulock(screen);
SDL_Flip(screen);
}
sceKernelSleepThread();
return 0;
}
//////// Function Definitions ////////
void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B)
{
Uint32 color = SDL_MapRGB(screen->format, R, G, B);
switch (screen->format->BytesPerPixel)
{
case 1: // Assuming 8-bpp
{
Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
*bufp = color;
}
break;
case 2: // Probably 15-bpp or 16-bpp
{
Uint16 *bufp;
bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
*bufp = color;
}
break;
case 3: // Slow 24-bpp mode, usually not used
{
Uint8 *bufp;
bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
{
bufp[0] = color;
bufp[1] = color >> 8;
bufp[2] = color >> 16;
}
else
{
bufp[2] = color;
bufp[1] = color >> 8;
bufp[0] = color >> 16;
}
}
break;
case 4: // Probably 32-bpp
{
Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;
}
break;
}
}
void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}
void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}
Code: Select all
TARGET = sdltest
OBJS = main.o
INCDIR =
CFLAGS = -G0 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS= -lpspgu
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SDL Test
PSPSDK=$(shell psp-config --pspsdk-path)
PSPBIN = $(PSPSDK)/../bin
CFLAGS += `$(PSPBIN)/sdl-config --cflags`
LIBS += `$(PSPBIN)/sdl-config --libs`
include $(PSPSDK)/lib/build.mak
Thanks in advance.