/** @file frontend_saf.c
  SAF frontend for Licar.
*/

#define SAF_PLATFORM_SDL2
#define SAF_SETTING_ENABLE_SAVES 0
#define SAF_PROGRAM_NAME "Licar"

#include "saf.h"

#define LCR_SETTING_RESOLUTION_X SAF_SCREEN_WIDTH
#define LCR_SETTING_RESOLUTION_Y SAF_SCREEN_HEIGHT
#define LCR_SETTING_FPS SAF_FPS
#define LCR_SETTING_MUSIC 0
#define LCR_SETTING_ENABLE_DATA_FILE 0
#define LCR_SETTING_332_COLOR 1
#define LCR_SETTING_SKY_SIZE 1
#define LCR_SETTING_CAR_ANIMATION_SUBDIVIDE 0
#define LCR_PLAY_SOUND_CALLBACK(s) playSound(s);

void playSound(uint8_t sound);

#include "game.h"

void playSound(uint8_t sound)
{
  switch (sound)
  {
    case LCR_SOUND_CLICK:       SAF_playSound(SAF_SOUND_CLICK); break;
    case LCR_SOUND_CRASH_SMALL: SAF_playSound(SAF_SOUND_BUMP);  break;
    case LCR_SOUND_CRASH_BIG:   SAF_playSound(SAF_SOUND_BOOM);  break;
    case LCR_SOUND_FAN:         SAF_playSound(SAF_SOUND_BEEP);  break;
    case LCR_SOUND_ACCELERATOR: SAF_playSound(SAF_SOUND_BEEP);  break;
    default: break;
  }
}

void LCR_drawPixel(unsigned long index, uint16_t color)
{
  SAF_drawPixel(index % SAF_SCREEN_WIDTH,index / SAF_SCREEN_WIDTH,color);
}

char LCR_getNextDataFileChar(void)
{
  return 0;
}

void LCR_appendDataStr(const char *str)
{
}

uint8_t LCR_keyPressed(uint8_t key)
{
  switch (key)
  {
    case LCR_KEY_UP:    return SAF_buttonPressed(SAF_BUTTON_UP);    break;
    case LCR_KEY_RIGHT: return SAF_buttonPressed(SAF_BUTTON_RIGHT); break;
    case LCR_KEY_DOWN:  return SAF_buttonPressed(SAF_BUTTON_DOWN);  break;
    case LCR_KEY_LEFT:  return SAF_buttonPressed(SAF_BUTTON_LEFT);  break;
    case LCR_KEY_A:     return SAF_buttonPressed(SAF_BUTTON_A);     break;
    case LCR_KEY_B:     return SAF_buttonPressed(SAF_BUTTON_B);     break;
    default: break;
  }
 
  return 0;
}

void LCR_sleep(uint16_t timeMs)
{
}

void SAF_init(void)
{
  LCR_gameInit(0,0);
}

uint8_t SAF_loop(void)
{
  return LCR_gameStep(SAF_time());
}
