#include "functions.h"

void init()
{
    #ifndef PSP
        if (SDL_Init(SDL_INIT_VIDEO) < 0)
        {
            printf("Unable to init SDL: %s\n", SDL_GetError());
        }
        atexit(SDL_Quit);
        screen = SDL_SetVideoMode(SCREENWIDTH, SCREENHEIGHT, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
        if ( !screen )
        {
            printf("Unable to set %ix%i video: %s\n", SCREENWIDTH, SCREENHEIGHT, SDL_GetError());
        }
        TTF_Init();
        titleFont = TTF_OpenFont("sfsquarehead.ttf", 24);
        font = TTF_OpenFont("sfsquarehead.ttf", 10);
        SDL_WM_SetCaption("Pong", NULL);
    #else
        //SetupCallbacks();
        SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK);
        screen = SDL_SetVideoMode(SCREENWIDTH, SCREENHEIGHT, 32, SDL_SWSURFACE);
		if(SDL_NumJoysticks()>0)
			joy=SDL_JoystickOpen(0);
		screen=SDL_SetVideoMode(SCREENWIDTH, SCREENHEIGHT, 32, SDL_SWSURFACE);
		SDL_ShowCursor(SDL_DISABLE);
		TTF_Init();
		titleFont = TTF_OpenFont("sfsquarehead.ttf", 24);
		font = TTF_OpenFont("sfsquarehead.ttf", 10);
		scePowerSetClockFrequency(333, 333, 166);
    #endif
}

SDL_Surface *load_image(std::string filename)
{
    SDL_Surface *loadedImage = NULL;
    SDL_Surface *optimizedImage = NULL;

    loadedImage = IMG_Load(filename.c_str());

    if( loadedImage != NULL )
    {
        optimizedImage = SDL_DisplayFormat(loadedImage);
        SDL_FreeSurface(loadedImage);

        if( optimizedImage != NULL )
        {
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 255, 0, 255 ) );
        }
    }

    return optimizedImage;
}
