Index: tools/configure
===================================================================
--- tools/configure	(revision 31001)
+++ tools/configure	(working copy)
@@ -649,6 +649,33 @@
  GCCOPTS="$GCCOPTS -ffast-math -fsingle-precision-constant"
 }
 
+ypr0cc () {
+
+ YPR0SDK="/usr/arm-none-linux-gnueabi"
+ PATH=$YPR0SDK/bin:$PATH:
+ YPR0SDK_BIN="/usr/bin"
+ PATHTOSDL="/home/beowulf/Projekte/YP-R0/NewFWs/sdl_port/install"
+ LDOPTS="-L$YPR0SDK/lib -Wl,-rpath,$YPR0SDK/lib $LDOPTS -L $PATHTOSDL/lib"
+ GCCOPTS=`echo $CCOPTS | sed -e s/-ffreestanding// -e s/-nostdlib// -e s/-Wundef//`
+ CCOPTS="$GCCOPTS -fno-builtin -g"
+ GCCOPTIMIZE=''
+ LDOPTS="-lSDL -lpthread -lm -ldl $LDOPTS"
+ GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-z,defs"
+ SHARED_LDFLAG="-shared"
+ SHARED_CFLAGS=''
+ endian="little"
+ thread_support="HAVE_SIGALTSTACK_THREADS"
+
+ # Include path
+ GCCOPTS="-std=gnu99 -I$YPR0SDK/include -I$PATHTOSDL/include/SDL/ -D_GNU_SOURCE=1 -D_REENTRANT"
+
+ # Set up compiler
+ gccchoice="4.2.0"
+ prefixtools "$YPR0SDK_BIN/arm-none-linux-gnueabi-"
+ HOSTCC=$(which gcc)
+ HOSTAR=$(which ar)
+}
+
 androidcc () {
     if [ -z "$ANDROID_SDK_PATH" ]; then
         echo "ERROR: You need the Android SDK installed and have the ANDROID_SDK_PATH"
@@ -1292,7 +1319,7 @@
  202) Nokia N8xx                                 131) Mini2440
  203) Nokia N900          ==ROCKCHIP==           ==HiFiMAN==
  204) Pandora             180) rk27xx generic    190) HM-60x
-                                                 191) HM-801
+ 205) Samsung YP-R0                              191) HM-801
 
 EOF
 
@@ -3230,6 +3257,31 @@
     t_model="app"
     ;;
 
+   205|samsungypr0)
+    application="yes"
+    target_id=78
+    modelname="samsungypr0"
+    target="-DSAMSUNG_YPR0"
+    app_set_paths
+    app_set_lcd_size 240 320
+    memory=32
+    uname=`uname`
+    simcc "sdl-app"
+    tool="cp "
+    boottool="cp "
+    bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
+    bmp2rb_native="$rootdir/tools/bmp2rb -f 4"
+    output="rockbox"
+    bootoutput="rockbox"
+    appextra="recorder:gui:radio"
+    plugins="yes"
+    swcodec="yes"
+    # architecture, manufacturer and model for the target-tree build
+    t_cpu="hosted"
+    t_manufacturer="ypr0"
+    t_model="app"
+    ;;
+
    *)
     echo "Please select a supported target platform!"
     exit 7
Index: apps/plugins/mp3_encoder.c
===================================================================
--- apps/plugins/mp3_encoder.c	(revision 31001)
+++ apps/plugins/mp3_encoder.c	(working copy)
@@ -2513,6 +2513,12 @@
 #define MP3ENC_DONE BUTTON_DOWN
 #define MP3ENC_SELECT BUTTON_SELECT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define MP3ENC_PREV BUTTON_UP
+#define MP3ENC_NEXT BUTTON_DOWN
+#define MP3ENC_DONE BUTTON_POWER
+#define MP3ENC_SELECT BUTTON_CENTER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/stats.c
===================================================================
--- apps/plugins/stats.c	(revision 31001)
+++ apps/plugins/stats.c	(working copy)
@@ -114,6 +114,9 @@
 #elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
 #define STATS_STOP BUTTON_BACK
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define STATS_STOP BUTTON_POWER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/superdom.c
===================================================================
--- apps/plugins/superdom.c	(revision 31001)
+++ apps/plugins/superdom.c	(working copy)
@@ -198,6 +198,14 @@
 #define SUPERDOM_RIGHT BUTTON_RIGHT
 #define SUPERDOM_CANCEL BUTTON_POWER
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define SUPERDOM_OK BUTTON_CENTER
+#define SUPERDOM_UP BUTTON_UP
+#define SUPERDOM_DOWN BUTTON_DOWN
+#define SUPERDOM_LEFT BUTTON_LEFT
+#define SUPERDOM_RIGHT BUTTON_RIGHT
+#define SUPERDOM_CANCEL BUTTON_POWER
+
 #endif
 
 #ifdef HAVE_TOUCHSCREEN
Index: apps/plugins/SOURCES.app_build
===================================================================
--- apps/plugins/SOURCES.app_build	(revision 31001)
+++ apps/plugins/SOURCES.app_build	(working copy)
@@ -1,3 +1,7 @@
+#ifndef HAVE_TOUCHSCREEN
+/* In devices running RockBox as an application, but having a keypad */
+#include "SOURCES"
+#else
 /* plugins common to all models */
 credits.c
 properties.c
@@ -39,3 +43,5 @@
 #endif
 test_viewports.c
 #endif /* HAVE_TEST_PLUGINS */
+
+#endif /* HAVE_TOUCHSCREEN */
Index: apps/plugins/sliding_puzzle.c
===================================================================
--- apps/plugins/sliding_puzzle.c	(revision 31001)
+++ apps/plugins/sliding_puzzle.c	(working copy)
@@ -263,6 +263,15 @@
 #define PUZZLE_SHUFFLE BUTTON_VOL_DOWN
 #define PUZZLE_PICTURE BUTTON_SELECT
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define PUZZLE_QUIT    BUTTON_BACK
+#define PUZZLE_LEFT    BUTTON_LEFT
+#define PUZZLE_RIGHT   BUTTON_RIGHT
+#define PUZZLE_UP      BUTTON_UP
+#define PUZZLE_DOWN    BUTTON_DOWN
+#define PUZZLE_SHUFFLE BUTTON_CENTER
+#define PUZZLE_PICTURE BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/flipit.c
===================================================================
--- apps/plugins/flipit.c	(revision 31001)
+++ apps/plugins/flipit.c	(working copy)
@@ -380,6 +380,18 @@
 #define FLIPIT_STEP_BY_STEP BUTTON_NEXT
 #define FLIPIT_TOGGLE       BUTTON_SELECT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+
+#define FLIPIT_LEFT         BUTTON_LEFT
+#define FLIPIT_RIGHT        BUTTON_RIGHT
+#define FLIPIT_UP           BUTTON_UP
+#define FLIPIT_DOWN         BUTTON_DOWN
+#define FLIPIT_QUIT         BUTTON_POWER
+#define FLIPIT_SHUFFLE      BUTTON_MENU
+#define FLIPIT_SOLVE        BUTTON_USER
+#define FLIPIT_STEP_BY_STEP BUTTON_BACK
+#define FLIPIT_TOGGLE       BUTTON_CENTER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/SUBDIRS.app_build
===================================================================
--- apps/plugins/SUBDIRS.app_build	(revision 31001)
+++ apps/plugins/SUBDIRS.app_build	(working copy)
@@ -1,4 +1,11 @@
-/* For all targets with a bitmap display */
+#ifndef HAVE_TOUCHSCREEN
+/* This is for devices having a keypad, running RockBox as an application */
+#include "SUBDIRS"
+
+#else
+/* For all targets with a bitmap display and a touchscreen
+ * In fact, most of the plugins aren't supposed to be used on a touch(mouse) device
+ */
 #ifdef HAVE_LCD_BITMAP
 
 #ifdef HAVE_TAGCACHE
@@ -15,3 +22,4 @@
 #endif
 
 #endif /* CONFIG_CODEC == SWCODEC */
+#endif /* HAVE_TOUCHSCREEN */
\ No newline at end of file
Index: apps/plugins/chessbox/chessbox_pgn.h
===================================================================
--- apps/plugins/chessbox/chessbox_pgn.h	(revision 31001)
+++ apps/plugins/chessbox/chessbox_pgn.h	(working copy)
@@ -422,6 +422,16 @@
 #define CB_SCROLL_LEFT   (BUTTON_LEFT|BUTTON_REPEAT)
 #define CB_SCROLL_RIGHT  (BUTTON_RIGHT|BUTTON_REPEAT)
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define CB_SELECT  BUTTON_CENTER
+#define CB_UP      BUTTON_UP
+#define CB_DOWN    BUTTON_DOWN
+#define CB_LEFT    BUTTON_LEFT
+#define CB_RIGHT   BUTTON_RIGHT
+#define CB_PLAY    BUTTON_USER
+#define CB_LEVEL   BUTTON_BACK
+#define CB_MENU    BUTTON_MENU
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/oscilloscope.c
===================================================================
--- apps/plugins/oscilloscope.c	(revision 31001)
+++ apps/plugins/oscilloscope.c	(working copy)
@@ -342,6 +342,17 @@
 #define OSCILLOSCOPE_VOL_UP       BUTTON_VOL_UP
 #define OSCILLOSCOPE_VOL_DOWN     BUTTON_VOL_DOWN
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define OSCILLOSCOPE_QUIT         BUTTON_POWER
+#define OSCILLOSCOPE_DRAWMODE     BUTTON_CENTER
+#define OSCILLOSCOPE_ADVMODE      BUTTON_DOWN
+#define OSCILLOSCOPE_ORIENTATION  BUTTON_UP
+#define OSCILLOSCOPE_PAUSE        BUTTON_MENU
+#define OSCILLOSCOPE_SPEED_UP     BUTTON_RIGHT
+#define OSCILLOSCOPE_SPEED_DOWN   BUTTON_LEFT
+#define OSCILLOSCOPE_VOL_UP       BUTTON_BACK
+#define OSCILLOSCOPE_VOL_DOWN     BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/starfield.c
===================================================================
--- apps/plugins/starfield.c	(revision 31001)
+++ apps/plugins/starfield.c	(working copy)
@@ -188,6 +188,14 @@
 #define STARFIELD_DECREASE_NB_STARS  BUTTON_RIGHT
 #define STARFIELD_TOGGLE_COLOR       BUTTON_PLAYPAUSE
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define STARFIELD_QUIT BUTTON_POWER
+#define STARFIELD_INCREASE_ZMOVE BUTTON_UP
+#define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
+#define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
+#define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
+#define STARFIELD_TOGGLE_COLOR BUTTON_CENTER
+
 #endif
 
 #ifdef HAVE_TOUCHSCREEN
Index: apps/plugins/snake2.c
===================================================================
--- apps/plugins/snake2.c	(revision 31001)
+++ apps/plugins/snake2.c	(working copy)
@@ -346,6 +346,15 @@
 #define SNAKE2_PLAYPAUSE BUTTON_PLAYPAUSE
 #define SNAKE2_PLAYPAUSE_TEXT "Play/Pause"
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define SNAKE2_LEFT      BUTTON_LEFT
+#define SNAKE2_RIGHT     BUTTON_RIGHT
+#define SNAKE2_UP        BUTTON_UP
+#define SNAKE2_DOWN      BUTTON_DOWN
+#define SNAKE2_QUIT      BUTTON_BACK
+#define SNAKE2_PLAYPAUSE BUTTON_CENTER
+#define SNAKE2_PLAYPAUSE_TEXT "Center"
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/clix.c
===================================================================
--- apps/plugins/clix.c	(revision 31001)
+++ apps/plugins/clix.c	(working copy)
@@ -195,6 +195,14 @@
 #define CLIX_BUTTON_RIGHT       BUTTON_RIGHT
 #define CLIX_BUTTON_CLICK       BUTTON_SELECT
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define CLIX_BUTTON_QUIT    BUTTON_BACK
+#define CLIX_BUTTON_LEFT    BUTTON_LEFT
+#define CLIX_BUTTON_RIGHT   BUTTON_RIGHT
+#define CLIX_BUTTON_CLICK   BUTTON_CENTER
+#define CLIX_BUTTON_UP      BUTTON_UP
+#define CLIX_BUTTON_DOWN    BUTTON_DOWN
+
 #else
 #error "no keymap"
 #endif
Index: apps/plugins/midi/midiplay.c
===================================================================
--- apps/plugins/midi/midiplay.c	(revision 31001)
+++ apps/plugins/midi/midiplay.c	(working copy)
@@ -233,6 +233,14 @@
 #define BTN_DOWN         BUTTON_DOWN
 #define BTN_PLAY         BUTTON_SELECT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define BTN_QUIT         BUTTON_BACK
+#define BTN_RIGHT        BUTTON_RIGHT
+#define BTN_LEFT         BUTTON_LEFT
+#define BTN_UP           BUTTON_UP
+#define BTN_DOWN         BUTTON_DOWN
+#define BTN_PLAY         BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/snake.c
===================================================================
--- apps/plugins/snake.c	(revision 31001)
+++ apps/plugins/snake.c	(working copy)
@@ -234,6 +234,14 @@
 #define SNAKE_DOWN BUTTON_DOWN
 #define SNAKE_PLAYPAUSE BUTTON_PLAYPAUSE
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define SNAKE_QUIT      BUTTON_BACK
+#define SNAKE_LEFT      BUTTON_LEFT
+#define SNAKE_RIGHT     BUTTON_RIGHT
+#define SNAKE_UP        BUTTON_UP
+#define SNAKE_DOWN      BUTTON_DOWN
+#define SNAKE_PLAYPAUSE BUTTON_CENTER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/bounce.c
===================================================================
--- apps/plugins/bounce.c	(revision 31001)
+++ apps/plugins/bounce.c	(working copy)
@@ -237,6 +237,14 @@
 #define BOUNCE_QUIT BUTTON_POWER
 #define BOUNCE_MODE BUTTON_PLAYPAUSE
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define BOUNCE_LEFT BUTTON_LEFT
+#define BOUNCE_RIGHT BUTTON_RIGHT
+#define BOUNCE_UP   BUTTON_UP
+#define BOUNCE_DOWN BUTTON_DOWN
+#define BOUNCE_QUIT BUTTON_POWER
+#define BOUNCE_MODE BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/cube.c
===================================================================
--- apps/plugins/cube.c	(revision 31001)
+++ apps/plugins/cube.c	(working copy)
@@ -329,6 +329,16 @@
 #define CUBE_PAUSE         BUTTON_DOWN
 #define CUBE_HIGHSPEED     BUTTON_LEFT
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define CUBE_QUIT          BUTTON_POWER
+#define CUBE_NEXT          BUTTON_RIGHT
+#define CUBE_PREV          BUTTON_LEFT
+#define CUBE_INC           BUTTON_UP
+#define CUBE_DEC           BUTTON_DOWN
+#define CUBE_MODE          BUTTON_MENU
+#define CUBE_PAUSE         BUTTON_CENTER
+#define CUBE_HIGHSPEED     BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/minesweeper.c
===================================================================
--- apps/plugins/minesweeper.c	(revision 31001)
+++ apps/plugins/minesweeper.c	(working copy)
@@ -311,6 +311,16 @@
 #   define MINESWP_DISCOVER BUTTON_SELECT
 #   define MINESWP_INFO     BUTTON_PREV
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#   define MINESWP_LEFT     BUTTON_LEFT
+#   define MINESWP_RIGHT    BUTTON_RIGHT
+#   define MINESWP_UP       BUTTON_UP
+#   define MINESWP_DOWN     BUTTON_DOWN
+#   define MINESWP_QUIT     BUTTON_BACK
+#   define MINESWP_TOGGLE   BUTTON_USER
+#   define MINESWP_DISCOVER BUTTON_CENTER
+#   define MINESWP_INFO     BUTTON_MENU
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/lib/pluginlib_actions.c
===================================================================
--- apps/plugins/lib/pluginlib_actions.c	(revision 31001)
+++ apps/plugins/lib/pluginlib_actions.c	(working copy)
@@ -220,6 +220,15 @@
     { PLA_DOWN_REPEAT,       BUTTON_FF|BUTTON_REPEAT,           BUTTON_NONE},
     { PLA_LEFT_REPEAT,       BUTTON_REW|BUTTON_M|BUTTON_REPEAT, BUTTON_NONE},
     { PLA_RIGHT_REPEAT,      BUTTON_FF|BUTTON_M|BUTTON_REPEAT,  BUTTON_NONE},
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+    { PLA_UP,                BUTTON_UP,                        BUTTON_NONE},
+    { PLA_DOWN,              BUTTON_DOWN,                      BUTTON_NONE},
+    { PLA_LEFT,              BUTTON_LEFT,                      BUTTON_NONE},
+    { PLA_RIGHT,             BUTTON_RIGHT,                     BUTTON_NONE},
+    { PLA_UP_REPEAT,         BUTTON_UP|BUTTON_REPEAT,          BUTTON_NONE},
+    { PLA_DOWN_REPEAT,       BUTTON_DOWN|BUTTON_REPEAT,        BUTTON_NONE},
+    { PLA_LEFT_REPEAT,       BUTTON_LEFT|BUTTON_REPEAT,        BUTTON_NONE},
+    { PLA_RIGHT_REPEAT,      BUTTON_RIGHT|BUTTON_REPEAT,       BUTTON_NONE},
 #else
 #   ifndef HAVE_TOUCHSCREEN
 #       error pluginlib_actions: No directions defined
@@ -405,6 +414,12 @@
     {PLA_SELECT,            BUTTON_SELECT,                      BUTTON_NONE},
     {PLA_SELECT_REL,        BUTTON_SELECT|BUTTON_REL,           BUTTON_SELECT},
     {PLA_SELECT_REPEAT,     BUTTON_SELECT|BUTTON_REPEAT,        BUTTON_NONE},
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)                                      
+    {PLA_CANCEL,            BUTTON_BACK,                        BUTTON_NONE},
+    {PLA_EXIT,              BUTTON_BACK|BUTTON_REPEAT,          BUTTON_NONE},
+    {PLA_SELECT,            BUTTON_CENTER,                      BUTTON_NONE},
+    {PLA_SELECT_REL,        BUTTON_CENTER|BUTTON_REL,           BUTTON_CENTER},
+    {PLA_SELECT_REPEAT,     BUTTON_CENTER|BUTTON_REPEAT,        BUTTON_NONE},
 #else
 #   ifndef HAVE_TOUCHSCREEN
 #       error pluginlib_actions: No actions defined
Index: apps/plugins/snow.c
===================================================================
--- apps/plugins/snow.c	(revision 31001)
+++ apps/plugins/snow.c	(working copy)
@@ -91,6 +91,9 @@
 #elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
 #define SNOW_QUIT BUTTON_POWER
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define SNOW_QUIT BUTTON_POWER
+
 #else
 #define SNOW_QUIT BUTTON_OFF
 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
Index: apps/plugins/spacerocks.c
===================================================================
--- apps/plugins/spacerocks.c	(revision 31001)
+++ apps/plugins/spacerocks.c	(working copy)
@@ -278,6 +278,15 @@
 #define AST_RIGHT BUTTON_RIGHT
 #define AST_FIRE BUTTON_SELECT
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define AST_PAUSE       BUTTON_BACK
+#define AST_QUIT        BUTTON_POWER
+#define AST_THRUST      BUTTON_UP
+#define AST_HYPERSPACE  BUTTON_DOWN
+#define AST_LEFT        BUTTON_LEFT
+#define AST_RIGHT       BUTTON_RIGHT
+#define AST_FIRE        BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/reversi/reversi-gui.h
===================================================================
--- apps/plugins/reversi/reversi-gui.h	(revision 31001)
+++ apps/plugins/reversi/reversi-gui.h	(working copy)
@@ -252,6 +252,14 @@
 #define REVERSI_BUTTON_MAKE_MOVE BUTTON_PLAYPAUSE
 #define REVERSI_BUTTON_MENU BUTTON_BACK
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define REVERSI_BUTTON_UP BUTTON_UP
+#define REVERSI_BUTTON_DOWN BUTTON_DOWN
+#define REVERSI_BUTTON_LEFT BUTTON_LEFT
+#define REVERSI_BUTTON_RIGHT BUTTON_RIGHT 
+#define REVERSI_BUTTON_MAKE_MOVE BUTTON_CENTER
+#define REVERSI_BUTTON_MENU BUTTON_MENU
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/logo.c
===================================================================
--- apps/plugins/logo.c	(revision 31001)
+++ apps/plugins/logo.c	(working copy)
@@ -222,6 +222,13 @@
 #define LP_DEC_Y BUTTON_DOWN
 #define LP_INC_Y BUTTON_UP
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define LP_QUIT BUTTON_POWER
+#define LP_DEC_X BUTTON_LEFT
+#define LP_INC_X BUTTON_RIGHT
+#define LP_DEC_Y BUTTON_DOWN
+#define LP_INC_Y BUTTON_UP
+
 #else
 #define LP_QUIT BUTTON_OFF
 #define LP_DEC_X BUTTON_LEFT
Index: apps/plugins/brickmania.c
===================================================================
--- apps/plugins/brickmania.c	(revision 31001)
+++ apps/plugins/brickmania.c	(working copy)
@@ -276,6 +276,14 @@
 #define UP BUTTON_UP
 #define DOWN BUTTON_DOWN
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define QUIT BUTTON_BACK
+#define LEFT BUTTON_LEFT
+#define RIGHT BUTTON_RIGHT
+#define SELECT BUTTON_CENTER
+#define UP BUTTON_UP
+#define DOWN BUTTON_DOWN
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/blackjack.c
===================================================================
--- apps/plugins/blackjack.c	(revision 31001)
+++ apps/plugins/blackjack.c	(working copy)
@@ -466,6 +466,22 @@
 #define BJACK_RIGHT         BUTTON_RIGHT
 #define BJACK_LEFT          BUTTON_LEFT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define BJACK_SELECT_NAME    "CENTER"
+#define BJACK_STAY_NAME     "BACK"
+#define BJACK_QUIT_NAME     "POWER"
+#define BJACK_DOUBLE_NAME   "USER"
+#define BJACK_SELECT        BUTTON_CENTER
+#define BJACK_QUIT          BUTTON_POWER
+#define BJACK_MAX           (BUTTON_LEFT|BUTTON_UP)
+#define BJACK_MIN           (BUTTON_RIGHT|BUTTON_DOWN)
+#define BJACK_STAY          BUTTON_BACK
+#define BJACK_DOUBLEDOWN    BUTTON_USER
+#define BJACK_UP            BUTTON_UP
+#define BJACK_DOWN          BUTTON_DOWN
+#define BJACK_RIGHT         BUTTON_RIGHT
+#define BJACK_LEFT          BUTTON_LEFT
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/stopwatch.c
===================================================================
--- apps/plugins/stopwatch.c	(revision 31001)
+++ apps/plugins/stopwatch.c	(working copy)
@@ -263,6 +263,14 @@
 #define STOPWATCH_SCROLL_UP BUTTON_UP
 #define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define STOPWATCH_QUIT BUTTON_POWER
+#define STOPWATCH_START_STOP BUTTON_CENTER
+#define STOPWATCH_RESET_TIMER BUTTON_USER
+#define STOPWATCH_LAP_TIMER BUTTON_MENU
+#define STOPWATCH_SCROLL_UP BUTTON_UP
+#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/fractals/fractal.h
===================================================================
--- apps/plugins/fractals/fractal.h	(revision 31001)
+++ apps/plugins/fractals/fractal.h	(working copy)
@@ -378,6 +378,18 @@
 #define FRACTAL_PRECISION_DEC   BUTTON_VOL_DOWN
 #define FRACTAL_RESET           BUTTON_PREV
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define FRACTAL_QUIT            BUTTON_BACK
+#define FRACTAL_UP              BUTTON_UP
+#define FRACTAL_DOWN            BUTTON_DOWN
+#define FRACTAL_LEFT            BUTTON_LEFT
+#define FRACTAL_RIGHT           BUTTON_RIGHT
+#define FRACTAL_ZOOM_IN         (BUTTON_MENU|BUTTON_REL)
+#define FRACTAL_ZOOM_OUT        (BUTTON_USER|BUTTON_REL)
+#define FRACTAL_PRECISION_INC   (BUTTON_MENU|BUTTON_REPEAT)
+#define FRACTAL_PRECISION_DEC   (BUTTON_USER|BUTTON_REPEAT)
+#define FRACTAL_RESET           BUTTON_POWER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/jewels.c
===================================================================
--- apps/plugins/jewels.c	(revision 31001)
+++ apps/plugins/jewels.c	(working copy)
@@ -314,6 +314,16 @@
 #define HK_SELECT "SELECT"
 #define HK_CANCEL "BACK"
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define JEWELS_UP     BUTTON_UP
+#define JEWELS_DOWN   BUTTON_DOWN
+#define JEWELS_LEFT   BUTTON_LEFT
+#define JEWELS_RIGHT  BUTTON_RIGHT
+#define JEWELS_SELECT BUTTON_CENTER
+#define JEWELS_CANCEL BUTTON_BACK
+#define HK_SELECT "CENTER"
+#define HK_CANCEL "BACK"
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/calculator.c
===================================================================
--- apps/plugins/calculator.c	(revision 31001)
+++ apps/plugins/calculator.c	(working copy)
@@ -431,6 +431,17 @@
 #define CALCULATOR_CALC      BUTTON_NEXT
 #define CALCULATOR_CLEAR     BUTTON_PREV
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+
+#define CALCULATOR_LEFT BUTTON_LEFT
+#define CALCULATOR_RIGHT BUTTON_RIGHT
+#define CALCULATOR_UP   BUTTON_UP
+#define CALCULATOR_DOWN BUTTON_DOWN
+#define CALCULATOR_QUIT BUTTON_POWER
+#define CALCULATOR_INPUT BUTTON_CENTER
+#define CALCULATOR_CALC BUTTON_MENU
+#define CALCULATOR_CLEAR BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/SUBDIRS
===================================================================
--- apps/plugins/SUBDIRS	(revision 31001)
+++ apps/plugins/SUBDIRS	(working copy)
@@ -73,7 +73,7 @@
 #if defined(IRIVER_H300_SERIES) || defined(IRIVER_H100_SERIES) || \
     (CONFIG_KEYPAD == SANSA_FUZE_PAD) || (CONFIG_KEYPAD == SANSA_E200_PAD) || \
     (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
-    (CONFIG_KEYPAD == IPOD_1G2G_PAD)
+    (CONFIG_KEYPAD == IPOD_1G2G_PAD || CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
 /* PDBox is confirmed to run on these player models. */
 pdbox
 #endif
Index: apps/plugins/rockpaint.c
===================================================================
--- apps/plugins/rockpaint.c	(revision 31001)
+++ apps/plugins/rockpaint.c	(working copy)
@@ -243,6 +243,17 @@
 #define ROCKPAINT_LEFT      BUTTON_LEFT
 #define ROCKPAINT_RIGHT     BUTTON_RIGHT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define ROCKPAINT_QUIT      BUTTON_POWER
+#define ROCKPAINT_DRAW      BUTTON_CENTER
+#define ROCKPAINT_MENU      BUTTON_MENU
+#define ROCKPAINT_TOOLBAR   BUTTON_USER
+#define ROCKPAINT_TOOLBAR2  ( BUTTON_USER | BUTTON_REPEAT )
+#define ROCKPAINT_UP        BUTTON_UP
+#define ROCKPAINT_DOWN      BUTTON_DOWN
+#define ROCKPAINT_LEFT      BUTTON_LEFT
+#define ROCKPAINT_RIGHT     BUTTON_RIGHT
+
 #else
 #error "Please define keys for this keypad"
 #endif
Index: apps/plugins/pacbox/pacbox.h
===================================================================
--- apps/plugins/pacbox/pacbox.h	(revision 31001)
+++ apps/plugins/pacbox/pacbox.h	(working copy)
@@ -265,6 +265,17 @@
 #define PACMAN_COIN     BUTTON_VOL_DOWN
 #define PACMAN_MENU     BUTTON_POWER
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+
+#define PACMAN_UP       BUTTON_UP
+#define PACMAN_DOWN     BUTTON_DOWN
+#define PACMAN_LEFT     BUTTON_LEFT
+#define PACMAN_RIGHT    BUTTON_RIGHT
+#define PACMAN_1UP      BUTTON_CENTER
+#define PACMAN_2UP      BUTTON_BACK
+#define PACMAN_COIN     BUTTON_USER
+#define PACMAN_MENU     BUTTON_MENU
+
 #else
 
 #error Keymap not defined!
Index: apps/plugins/fft/fft.c
===================================================================
--- apps/plugins/fft/fft.c	(revision 31001)
+++ apps/plugins/fft/fft.c	(working copy)
@@ -257,6 +257,14 @@
 #   define FFT_FREQ_SCALE   BUTTON_DOWN
 #   define FFT_QUIT         BUTTON_POWER
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#   define FFT_PREV_GRAPH   BUTTON_LEFT
+#   define FFT_NEXT_GRAPH   BUTTON_RIGHT
+#   define FFT_ORIENTATION  BUTTON_USER
+#   define FFT_WINDOW       BUTTON_MENU
+#   define FFT_AMP_SCALE    BUTTON_CENTER
+#   define FFT_QUIT         BUTTON_BACK
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/xobox.c
===================================================================
--- apps/plugins/xobox.c	(revision 31001)
+++ apps/plugins/xobox.c	(working copy)
@@ -277,6 +277,15 @@
 #define DOWN  BUTTON_DOWN
 #define PAUSE BUTTON_SELECT
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+
+#define QUIT BUTTON_POWER
+#define LEFT BUTTON_LEFT
+#define RIGHT BUTTON_RIGHT
+#define UP BUTTON_UP
+#define DOWN BUTTON_DOWN
+#define PAUSE BUTTON_BACK
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/pong.c
===================================================================
--- apps/plugins/pong.c	(revision 31001)
+++ apps/plugins/pong.c	(working copy)
@@ -244,6 +244,14 @@
 #define PONG_RIGHT_UP BUTTON_UP
 #define PONG_RIGHT_DOWN BUTTON_RIGHT
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define PONG_QUIT BUTTON_POWER
+#define PONG_PAUSE BUTTON_CENTER
+#define PONG_LEFT_UP BUTTON_UP
+#define PONG_LEFT_DOWN BUTTON_DOWN
+#define PONG_RIGHT_UP BUTTON_UP
+#define PONG_RIGHT_DOWN BUTTON_DOWN
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/text_viewer/tv_button.h
===================================================================
--- apps/plugins/text_viewer/tv_button.h	(revision 31001)
+++ apps/plugins/text_viewer/tv_button.h	(working copy)
@@ -436,6 +436,16 @@
 #define TV_LINE_DOWN    BUTTON_SCROLL_FWD
 #define TV_BOOKMARK     (BUTTON_DOWN|BUTTON_SELECT)
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define TV_QUIT         BUTTON_BACK
+#define TV_SCROLL_UP    BUTTON_UP
+#define TV_SCROLL_DOWN  BUTTON_DOWN
+#define TV_SCREEN_LEFT  BUTTON_LEFT
+#define TV_SCREEN_RIGHT BUTTON_RIGHT
+#define TV_MENU         BUTTON_MENU
+#define TV_AUTOSCROLL   BUTTON_USER
+#define TV_BOOKMARK     BUTTON_CENTER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/pegbox.c
===================================================================
--- apps/plugins/pegbox.c	(revision 31001)
+++ apps/plugins/pegbox.c	(working copy)
@@ -510,6 +510,24 @@
 #define LVL_DOWN_TEXT "PREV"
 #define SELECT_TEXT "SELECT"
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define PEGBOX_SELECT   BUTTON_CENTER
+#define PEGBOX_QUIT     BUTTON_BACK
+#define PEGBOX_RESTART  BUTTON_MENU
+#define PEGBOX_LVL_UP   BUTTON_USER
+#define PEGBOX_LVL_DOWN BUTTON_POWER
+#define PEGBOX_UP       BUTTON_UP
+#define PEGBOX_DOWN     BUTTON_DOWN
+#define PEGBOX_RIGHT    BUTTON_RIGHT
+#define PEGBOX_LEFT     BUTTON_LEFT
+
+#define SAVE_TEXT "PLAYPAUSE"
+#define QUIT_TEXT "POWER"
+#define RESTART_TEXT "BACK"
+#define LVL_UP_TEXT "Vol+"
+#define LVL_DOWN_TEXT "Vol-"
+#define SELECT_TEXT "SELECT"
+
 #else
 #error Unsupported keymap!
 #endif
Index: apps/plugins/sudoku/sudoku.h
===================================================================
--- apps/plugins/sudoku/sudoku.h	(revision 31001)
+++ apps/plugins/sudoku/sudoku.h	(working copy)
@@ -329,6 +329,15 @@
 #define SUDOKU_BUTTON_MENU BUTTON_SELECT
 #define SUDOKU_BUTTON_POSSIBLE BUTTON_VOL_DOWN
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define SUDOKU_BUTTON_MENU       BUTTON_MENU
+#define SUDOKU_BUTTON_LEFT       BUTTON_LEFT
+#define SUDOKU_BUTTON_RIGHT      BUTTON_RIGHT
+#define SUDOKU_BUTTON_CHANGEDIR  BUTTON_CENTER
+#define SUDOKU_BUTTON_TOGGLE     BUTTON_UP
+#define SUDOKU_BUTTON_TOGGLEBACK BUTTON_DOWN
+#define SUDOKU_BUTTON_POSSIBLE   BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/zxbox/zxbox_keyb.c
===================================================================
--- apps/plugins/zxbox/zxbox_keyb.c	(revision 31001)
+++ apps/plugins/zxbox/zxbox_keyb.c	(working copy)
@@ -232,6 +232,24 @@
 #define KBD_UP     BUTTON_UP
 #define KBD_DOWN   BUTTON_DOWN
 
+#elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
+
+#define KBD_SELECT BUTTON_CENTER
+#define KBD_ABORT  BUTTON_BACK
+#define KBD_LEFT   BUTTON_LEFT
+#define KBD_RIGHT  BUTTON_RIGHT
+#define KBD_UP     BUTTON_UP
+#define KBD_DOWN   BUTTON_DOWN
+
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+
+#define KBD_SELECT BUTTON_CENTER
+#define KBD_ABORT  BUTTON_BACK
+#define KBD_LEFT   BUTTON_LEFT
+#define KBD_RIGHT  BUTTON_RIGHT
+#define KBD_UP     BUTTON_UP
+#define KBD_DOWN   BUTTON_DOWN
+
 #endif
 
 #ifdef HAVE_TOUCHSCREEN
Index: apps/plugins/zxbox/keymaps.h
===================================================================
--- apps/plugins/zxbox/keymaps.h	(revision 31001)
+++ apps/plugins/zxbox/keymaps.h	(working copy)
@@ -226,6 +226,15 @@
 #define ZX_LEFT         BUTTON_LEFT
 #define ZX_RIGHT        BUTTON_RIGHT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+
+#define ZX_MENU         BUTTON_MENU
+#define ZX_UP           BUTTON_UP
+#define ZX_DOWN         BUTTON_DOWN
+#define ZX_SELECT       BUTTON_CENTER
+#define ZX_LEFT         BUTTON_LEFT
+#define ZX_RIGHT        BUTTON_RIGHT
+
 #else
 #error Keymap not defined!
 
Index: apps/plugins/rockblox1d.c
===================================================================
--- apps/plugins/rockblox1d.c	(revision 31001)
+++ apps/plugins/rockblox1d.c	(working copy)
@@ -134,6 +134,10 @@
 #define ONEDROCKBLOX_DOWN              BUTTON_BOTTOMMIDDLE
 #define ONEDROCKBLOX_QUIT              BUTTON_POWER
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define ONEDROCKBLOX_DOWN              BUTTON_CENTER
+#define ONEDROCKBLOX_QUIT              BUTTON_POWER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/battery_bench.c
===================================================================
--- apps/plugins/battery_bench.c	(revision 31001)
+++ apps/plugins/battery_bench.c	(working copy)
@@ -241,6 +241,13 @@
 #define BATTERY_ON_TXT  "SELECT - start"
 #define BATTERY_OFF_TXT "POWER"
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+
+#define BATTERY_ON  BUTTON_USER
+#define BATTERY_OFF BUTTON_POWER
+#define BATTERY_ON_TXT  "User Key - start"
+#define BATTERY_OFF_TXT "Power Key"
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/fireworks.c
===================================================================
--- apps/plugins/fireworks.c	(revision 31001)
+++ apps/plugins/fireworks.c	(working copy)
@@ -131,6 +131,10 @@
 #define BTN_MENU BUTTON_SELECT
 #define BTN_FIRE BUTTON_PLAYPAUSE
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define BTN_MENU BUTTON_MENU
+#define BTN_FIRE BUTTON_CENTER
+
 #elif defined(HAVE_TOUCHSCREEN)
     /* This is a touchscreen target */
 #else
Index: apps/plugins/rockblox.c
===================================================================
--- apps/plugins/rockblox.c	(revision 31001)
+++ apps/plugins/rockblox.c	(working copy)
@@ -379,6 +379,18 @@
 #define ROCKBLOX_DROP          BUTTON_SELECT
 #define ROCKBLOX_RESTART       BUTTON_VOL_DOWN
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+
+#define ROCKBLOX_OFF           BUTTON_BACK
+#define ROCKBLOX_ROTATE_CCW    BUTTON_MENU
+#define ROCKBLOX_ROTATE_CW     BUTTON_USER
+#define ROCKBLOX_ROTATE        BUTTON_UP
+#define ROCKBLOX_DOWN          BUTTON_DOWN
+#define ROCKBLOX_LEFT          BUTTON_LEFT
+#define ROCKBLOX_RIGHT         BUTTON_RIGHT
+#define ROCKBLOX_DROP          BUTTON_CENTER
+#define ROCKBLOX_RESTART       BUTTON_POWER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/mpegplayer/mpegplayer.c
===================================================================
--- apps/plugins/mpegplayer/mpegplayer.c	(revision 31001)
+++ apps/plugins/mpegplayer/mpegplayer.c	(working copy)
@@ -362,6 +362,15 @@
 #define MPEG_RW         BUTTON_LEFT
 #define MPEG_FF         BUTTON_RIGHT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define MPEG_MENU       BUTTON_MENU
+#define MPEG_PAUSE      (BUTTON_CENTER | BUTTON_REL)
+#define MPEG_STOP       (BUTTON_CENTER | BUTTON_REPEAT)
+#define MPEG_VOLDOWN    BUTTON_DOWN
+#define MPEG_VOLUP      BUTTON_UP
+#define MPEG_RW         BUTTON_LEFT
+#define MPEG_FF         BUTTON_RIGHT
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/mpegplayer/mpeg_settings.c
===================================================================
--- apps/plugins/mpegplayer/mpeg_settings.c	(revision 31001)
+++ apps/plugins/mpegplayer/mpeg_settings.c	(working copy)
@@ -248,6 +248,14 @@
 #define MPEG_START_TIME_DOWN        BUTTON_DOWN
 #define MPEG_START_TIME_EXIT        BUTTON_POWER
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define MPEG_START_TIME_SELECT      BUTTON_CENTER
+#define MPEG_START_TIME_LEFT        BUTTON_LEFT
+#define MPEG_START_TIME_RIGHT       BUTTON_RIGHT
+#define MPEG_START_TIME_UP          BUTTON_UP
+#define MPEG_START_TIME_DOWN        BUTTON_DOWN
+#define MPEG_START_TIME_EXIT        BUTTON_BACK
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/solitaire.c
===================================================================
--- apps/plugins/solitaire.c	(revision 31001)
+++ apps/plugins/solitaire.c	(working copy)
@@ -544,6 +544,24 @@
 #   define HK_CUR2STACK      "NEXT"
 #   define HK_REM2STACK      "PREV"
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#   define SOL_QUIT         BUTTON_POWER
+#   define SOL_UP           BUTTON_UP
+#   define SOL_DOWN         BUTTON_DOWN
+#   define SOL_LEFT         BUTTON_LEFT
+#   define SOL_RIGHT        BUTTON_RIGHT
+#   define SOL_MOVE_PRE     BUTTON_CENTER
+#   define SOL_MOVE         (BUTTON_CENTER | BUTTON_REL)
+#   define SOL_DRAW         BUTTON_MENU
+#   define SOL_REM2CUR      (BUTTON_LEFT | BUTTON_USER)
+#   define SOL_CUR2STACK    (BUTTON_CENTER | BUTTON_REPEAT)
+#   define SOL_REM2STACK    (BUTTON_RIGHT | BUTTON_USER)
+#   define HK_MOVE         "Center"
+#   define HK_DRAW         "Menu"
+#   define HK_REM2CUR      "A+LEFT"
+#   define HK_CUR2STACK    "Center.."
+#   define HK_REM2STACK    "A+RIGHT"
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/goban/goban.h
===================================================================
--- apps/plugins/goban/goban.h	(revision 31001)
+++ apps/plugins/goban/goban.h	(working copy)
@@ -364,6 +364,16 @@
 #define  GBN_BUTTON_PLAY               BUTTON_SELECT
 #define  GBN_BUTTON_MENU               BUTTON_POWER
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define  GBN_BUTTON_UP                 BUTTON_UP
+#define  GBN_BUTTON_DOWN               BUTTON_DOWN
+#define  GBN_BUTTON_LEFT               BUTTON_LEFT
+#define  GBN_BUTTON_RIGHT              BUTTON_RIGHT
+#define  GBN_BUTTON_RETREAT            BUTTON_BACK
+#define  GBN_BUTTON_ADVANCE            BUTTON_USER
+#define  GBN_BUTTON_PLAY               BUTTON_CENTER
+#define  GBN_BUTTON_MENU               BUTTON_MENU
+
 #else
 #error Unsupported keypad
 #endif
Index: apps/plugins/calendar.c
===================================================================
--- apps/plugins/calendar.c	(revision 31001)
+++ apps/plugins/calendar.c	(working copy)
@@ -308,6 +308,16 @@
 #define CALENDAR_NEXT_MONTH BUTTON_NEXT
 #define CALENDAR_PREV_MONTH BUTTON_PREV
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define CALENDAR_QUIT       BUTTON_POWER
+#define CALENDAR_SELECT     BUTTON_CENTER
+#define CALENDAR_NEXT_WEEK  BUTTON_DOWN
+#define CALENDAR_PREV_WEEK  BUTTON_UP
+#define CALENDAR_NEXT_DAY   BUTTON_RIGHT
+#define CALENDAR_PREV_DAY   BUTTON_LEFT
+#define CALENDAR_NEXT_MONTH BUTTON_BACK
+#define CALENDAR_PREV_MONTH BUTTON_USER
+
 #else
 #error "No keypad setting."
 #endif
Index: apps/plugins/star.c
===================================================================
--- apps/plugins/star.c	(revision 31001)
+++ apps/plugins/star.c	(working copy)
@@ -480,6 +480,23 @@
 #define STAR_LEVEL_DOWN_NAME "Vol-"
 #define STAR_LEVEL_REPEAT_NAME "PREV LONG"
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+
+#define STAR_QUIT           BUTTON_POWER
+#define STAR_LEFT           BUTTON_LEFT
+#define STAR_RIGHT          BUTTON_RIGHT
+#define STAR_UP             BUTTON_UP
+#define STAR_DOWN           BUTTON_DOWN
+#define STAR_TOGGLE_CONTROL BUTTON_CENTER
+#define STAR_LEVEL_UP       BUTTON_BACK
+#define STAR_LEVEL_DOWN     BUTTON_USER
+#define STAR_LEVEL_REPEAT   BUTTON_MENU
+#define STAR_TOGGLE_CONTROL_NAME "SELECT"
+#define STAR_QUIT_NAME      "POWER"
+#define STAR_LEVEL_UP_NAME  "VOL UP"
+#define STAR_LEVEL_DOWN_NAME "VOL DOWN"
+#define STAR_LEVEL_REPEAT_NAME "A"
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/doom/i_video.c
===================================================================
--- apps/plugins/doom/i_video.c	(revision 31001)
+++ apps/plugins/doom/i_video.c	(working copy)
@@ -424,6 +424,17 @@
 #define DOOMBUTTON_ENTER   BUTTON_NEXT
 #define DOOMBUTTON_WEAPON  BUTTON_PREV
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define DOOMBUTTON_UP      BUTTON_UP
+#define DOOMBUTTON_DOWN    BUTTON_DOWN
+#define DOOMBUTTON_LEFT    BUTTON_LEFT
+#define DOOMBUTTON_RIGHT   BUTTON_RIGHT
+#define DOOMBUTTON_SHOOT   BUTTON_CENTER
+#define DOOMBUTTON_OPEN    BUTTON_MENU
+#define DOOMBUTTON_ESC     BUTTON_BACK
+#define DOOMBUTTON_ENTER   BUTTON_POWER
+#define DOOMBUTTON_WEAPON  BUTTON_USER
+
 #else
 #error Keymap not defined!
 #endif
Index: apps/plugins/imageviewer/imageviewer_button.h
===================================================================
--- apps/plugins/imageviewer/imageviewer_button.h	(revision 31001)
+++ apps/plugins/imageviewer/imageviewer_button.h	(working copy)
@@ -379,6 +379,18 @@
 #define IMGVIEW_MENU            BUTTON_POWER
 #define IMGVIEW_SLIDE_SHOW      BUTTON_NEXT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define IMGVIEW_ZOOM_IN     BUTTON_POWER
+#define IMGVIEW_ZOOM_OUT    BUTTON_USER
+#define IMGVIEW_UP          BUTTON_UP
+#define IMGVIEW_DOWN        BUTTON_DOWN
+#define IMGVIEW_LEFT        BUTTON_LEFT
+#define IMGVIEW_RIGHT       BUTTON_RIGHT
+#define IMGVIEW_NEXT        BUTTON_CENTER
+#define IMGVIEW_PREVIOUS    0xFFFFFFA //not used
+#define IMGVIEW_MENU        BUTTON_MENU
+#define IMGVIEW_QUIT        BUTTON_BACK
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/vu_meter.c
===================================================================
--- apps/plugins/vu_meter.c	(revision 31001)
+++ apps/plugins/vu_meter.c	(working copy)
@@ -338,6 +338,17 @@
 #define LABEL_MENU "PREV"
 #define LABEL_VOLUME "VOL+/VOL-"
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define VUMETER_QUIT BUTTON_BACK
+#define VUMETER_HELP BUTTON_USER
+#define VUMETER_MENU BUTTON_MENU
+#define VUMETER_UP   BUTTON_UP
+#define VUMETER_DOWN BUTTON_DOWN
+#define LABEL_HELP   "User"
+#define LABEL_QUIT   "Back"
+#define LABEL_MENU   "Menu"
+#define LABEL_VOLUME "Up/Down"
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/rockboy/rockboy.c
===================================================================
--- apps/plugins/rockboy/rockboy.c	(revision 31001)
+++ apps/plugins/rockboy/rockboy.c	(working copy)
@@ -342,6 +342,18 @@
         options.SELECT = BUTTON_NEXT;
         options.MENU   = BUTTON_SELECT;
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+        options.UP     = BUTTON_UP;
+        options.DOWN   = BUTTON_DOWN;
+        options.LEFT   = BUTTON_LEFT;
+        options.RIGHT  = BUTTON_RIGHT;
+
+        options.A      = BUTTON_CENTER;
+        options.B      = BUTTON_BACK;
+        options.START  = BUTTON_POWER;
+        options.SELECT = BUTTON_USER;
+        options.MENU   = BUTTON_MENU;
+
 #else
 #error No Keymap Defined!
 #endif
Index: apps/plugins/lamp.c
===================================================================
--- apps/plugins/lamp.c	(revision 31001)
+++ apps/plugins/lamp.c	(working copy)
@@ -147,6 +147,12 @@
 #   define LAMP_UP         BUTTON_UP
 #   define LAMP_DOWN       BUTTON_DOWN
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#   define LAMP_LEFT       BUTTON_LEFT
+#   define LAMP_RIGHT      BUTTON_RIGHT
+#   define LAMP_UP         BUTTON_UP
+#   define LAMP_DOWN       BUTTON_DOWN
+
 #else
 #   error Missing key definitions for this keypad
 #endif
Index: apps/plugins/sokoban.c
===================================================================
--- apps/plugins/sokoban.c	(revision 31001)
+++ apps/plugins/sokoban.c	(working copy)
@@ -526,6 +526,21 @@
 #define BUTTON_SAVE          (BUTTON_SELECT|BUTTON_REPEAT)
 #define BUTTON_SAVE_NAME "SELECT LONG"
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define SOKOBAN_LEFT BUTTON_LEFT
+#define SOKOBAN_RIGHT BUTTON_RIGHT
+#define SOKOBAN_UP BUTTON_UP
+#define SOKOBAN_DOWN BUTTON_DOWN
+#define SOKOBAN_MENU BUTTON_MENU
+#define SOKOBAN_UNDO BUTTON_BACK
+#define SOKOBAN_REDO BUTTON_USER
+//#define SOKOBAN_LEVEL_DOWN (BUTTON_POWER|BUTTON_REL)
+//#define SOKOBAN_LEVEL_REPEAT (BUTTON_CENTER|BUTTON_REPEAT)
+//#define SOKOBAN_LEVEL_UP (BUTTON_MENU|BUTTON_REPEAT)
+#define SOKOBAN_PAUSE (BUTTON_POWER|BUTTON_REPEAT)
+#define BUTTON_SAVE BUTTON_CENTER
+#define BUTTON_SAVE_NAME "CENTER"
+
 #else
 #error No keymap defined!
 #endif
@@ -1398,6 +1413,7 @@
 {
     int button;
     int selection = 0;
+    int i;
     bool menu_quit;
     int start_selected = 0;
     int prev_level = current_info.level.index;
Index: apps/plugins/chopper.c
===================================================================
--- apps/plugins/chopper.c	(revision 31001)
+++ apps/plugins/chopper.c	(working copy)
@@ -179,6 +179,11 @@
 #define ACTION BUTTON_SELECT
 #define ACTIONTEXT "SELECT"
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define QUIT BUTTON_BACK
+#define ACTION BUTTON_CENTER
+#define ACTIONTEXT "CENTER"
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/matrix.c
===================================================================
--- apps/plugins/matrix.c	(revision 31001)
+++ apps/plugins/matrix.c	(working copy)
@@ -182,6 +182,12 @@
 #define MATRIX_SLEEP_LESS BUTTON_DOWN
 #define MATRIX_PAUSE BUTTON_SELECT
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define MATRIX_EXIT BUTTON_POWER
+#define MATRIX_SLEEP_MORE BUTTON_UP
+#define MATRIX_SLEEP_LESS BUTTON_DOWN
+#define MATRIX_PAUSE BUTTON_CENTER
+
 #else
 #error Unsupported keypad
 #endif
Index: apps/plugins/chip8.c
===================================================================
--- apps/plugins/chip8.c	(revision 31001)
+++ apps/plugins/chip8.c	(working copy)
@@ -1193,6 +1193,18 @@
 #define CHIP8_KEY8 BUTTON_VOL_DOWN
 #define CHIP8_KEY9 BUTTON_VOL_UP
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+#define CHIP8_OFF  (BUTTON_POWER|BUTTON_REPEAT)
+#define CHIP8_KEY1 BUTTON_MENU
+#define CHIP8_KEY2 BUTTON_UP
+#define CHIP8_KEY3 BUTTON_DOWN
+#define CHIP8_KEY4 BUTTON_LEFT
+#define CHIP8_KEY5 BUTTON_CENTER
+#define CHIP8_KEY6 BUTTON_RIGHT
+#define CHIP8_KEY7 BUTTON_BACK
+#define CHIP8_KEY8 BUTTON_POWER
+#define CHIP8_KEY9 BUTTON_USER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/chessclock.c
===================================================================
--- apps/plugins/chessclock.c	(revision 31001)
+++ apps/plugins/chessclock.c	(working copy)
@@ -326,6 +326,16 @@
 #define CHC_SETTINGS_OK BUTTON_SELECT
 #define CHC_SETTINGS_CANCEL BUTTON_LEFT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define CHC_QUIT BUTTON_BACK
+#define CHC_STARTSTOP BUTTON_CENTER
+#define CHC_RESET BUTTON_USER
+#define CHC_MENU BUTTON_MENU
+#define CHC_SETTINGS_INC BUTTON_UP
+#define CHC_SETTINGS_DEC BUTTON_DOWN
+#define CHC_SETTINGS_OK BUTTON_CENTER
+#define CHC_SETTINGS_CANCEL BUTTON_BACK
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/mosaique.c
===================================================================
--- apps/plugins/mosaique.c	(revision 31001)
+++ apps/plugins/mosaique.c	(working copy)
@@ -193,6 +193,11 @@
 #define MOSAIQUE_SPEED BUTTON_SELECT
 #define MOSAIQUE_RESTART BUTTON_DOWN
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+#define MOSAIQUE_QUIT BUTTON_POWER
+#define MOSAIQUE_SPEED BUTTON_USER
+#define MOSAIQUE_RESTART BUTTON_CENTER
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/wormlet.c
===================================================================
--- apps/plugins/wormlet.c	(revision 31001)
+++ apps/plugins/wormlet.c	(working copy)
@@ -320,6 +320,16 @@
 #define BTN_QUIT BUTTON_POWER
 #define BTN_STOPRESET BUTTON_VOL_DOWN
 
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+
+#define BTN_DIR_UP BUTTON_UP
+#define BTN_DIR_DOWN BUTTON_DOWN
+#define BTN_DIR_LEFT BUTTON_LEFT
+#define BTN_DIR_RIGHT BUTTON_RIGHT
+#define BTN_STARTPAUSE BUTTON_CENTER
+#define BTN_QUIT BUTTON_POWER
+#define BTN_STOPRESET BUTTON_MENU
+
 #else
 #error No keymap defined!
 #endif
Index: apps/plugins/invadrox.c
===================================================================
--- apps/plugins/invadrox.c	(revision 31001)
+++ apps/plugins/invadrox.c	(working copy)
@@ -228,6 +228,13 @@
 #define RIGHT BUTTON_RIGHT
 #define FIRE  BUTTON_SELECT
 
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+
+#define QUIT BUTTON_BACK
+#define LEFT BUTTON_LEFT
+#define RIGHT BUTTON_RIGHT
+#define FIRE BUTTON_CENTER
+
 #else
     #error INVADROX: Unsupported keypad
 #endif
Index: apps/plugins/pdbox/pdbox.h
===================================================================
--- apps/plugins/pdbox/pdbox.h	(revision 31001)
+++ apps/plugins/pdbox/pdbox.h	(working copy)
@@ -89,7 +89,9 @@
 float rb_atan2(float, float);
 float rb_sinh(float);
 float rb_tan(float);
-#ifndef SIMULATOR
+//#ifndef SIMULATOR
+/*FIXME: is it a correct replacement??? */
+#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
 typedef struct
 {
     int quot;
@@ -165,7 +167,9 @@
 
 #define strncat rb_strncat
 
-#ifndef SIMULATOR
+//#ifndef SIMULATOR
+/*FIXME: is it a correct replacement??? */
+#if !(CONFIG_PLATFORM & PLATFORM_HOSTED)
 #define floor rb_floor
 #define atof rb_atof
 #define atol rb_atol
@@ -282,6 +286,15 @@
     #define PDPOD_WHEELLEFT (BUTTON_SCROLL_BACK)
     #define PDPOD_WHEELRIGHT (BUTTON_SCROLL_FWD)
     #define PDPOD_ACTION (BUTTON_SELECT)
+#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
+    #define PDPOD_QUIT      BUTTON_BACK
+    #define PDPOD_PLAY      BUTTON_USER
+    #define PDPOD_PREVIOUS  BUTTON_LEFT
+    #define PDPOD_NEXT      BUTTON_RIGHT
+    #define PDPOD_MENU      BUTTON_MENU
+    #define PDPOD_WHEELLEFT BUTTON_UP
+    #define PDPOD_WHEELRIGHT BUTTON_DOWN
+    #define PDPOD_ACTION    BUTTON_CENTER
 #else
     #warning "No keys defined for this architecture!"
 #endif
Index: apps/plugin.c
===================================================================
--- apps/plugin.c	(revision 31001)
+++ apps/plugin.c	(working copy)
@@ -434,6 +434,17 @@
 #endif
 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
 #endif /* PLATFORM_NATIVE */
+#if (CONFIG_PLATFORM & PLATFORM_YPR0)
+    &cpu_frequency,
+
+#ifdef HAVE_ADJUSTABLE_CPU_FREQ
+#ifdef CPU_BOOST_LOGGING
+    cpu_boost_,
+#else
+    cpu_boost,
+#endif
+#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
+#endif /* PLATFORM_YPR0 */
 #ifdef HAVE_SCHEDULER_BOOSTCTRL
     trigger_cpu_boost,
     cancel_cpu_boost,
Index: apps/SOURCES
===================================================================
--- apps/SOURCES	(revision 31001)
+++ apps/SOURCES	(working copy)
@@ -332,5 +332,7 @@
 keymaps/keymap-hm801.c
 #elif CONFIG_KEYPAD == SANSA_CONNECT_PAD
 keymaps/keymap-sansa-connect.c
+#elif CONFIG_KEYPAD == SAMSUNG_YPR0_PAD
+keymaps/keymap-ypr0.c
 #endif
 
Index: apps/plugin.h
===================================================================
--- apps/plugin.h	(revision 31001)
+++ apps/plugin.h	(working copy)
@@ -507,6 +507,16 @@
 #endif
 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
 #endif /* PLATFORM_NATIVE */
+#if (CONFIG_PLATFORM & PLATFORM_YPR0)
+    long *cpu_frequency;
+#ifdef HAVE_ADJUSTABLE_CPU_FREQ
+#ifdef CPU_BOOST_LOGGING
+    void (*cpu_boost_)(bool on_off,char*location,int line);
+#else
+    void (*cpu_boost)(bool on_off);
+#endif
+#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
+#endif /* PLATFORM_YPR0 */
 #ifdef HAVE_SCHEDULER_BOOSTCTRL
     void (*trigger_cpu_boost)(void);
     void (*cancel_cpu_boost)(void);
Index: apps/keymaps/keymap-ypr0.c
===================================================================
--- apps/keymaps/keymap-ypr0.c	(revision 0)
+++ apps/keymaps/keymap-ypr0.c	(revision 0)
@@ -0,0 +1,293 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: keymap-sdl.c 28704 2010-11-29 11:28:53Z teru $
+ *
+ * Copyright (C) 2011 Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/* Button Code Definitions for Samsung YP-R0 target */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "action.h"
+#include "button.h"
+#include "settings.h"
+
+/*
+ * The format of the list is as follows
+ * { Action Code,   Button code,    Prereq button code }
+ * if there's no need to check the previous button's value, use BUTTON_NONE
+ * Insert LAST_ITEM_IN_LIST at the end of each mapping
+ */
+
+static const struct button_mapping button_context_standard[]  = {
+    { ACTION_STD_PREV,        BUTTON_UP,                    BUTTON_NONE },
+    { ACTION_STD_PREVREPEAT,  BUTTON_UP|BUTTON_REPEAT,      BUTTON_NONE },
+    { ACTION_STD_NEXT,        BUTTON_DOWN,                  BUTTON_NONE },
+    { ACTION_STD_NEXTREPEAT,  BUTTON_DOWN|BUTTON_REPEAT,    BUTTON_NONE },
+
+    { ACTION_STD_OK,          BUTTON_CENTER|BUTTON_REL,     BUTTON_CENTER },
+    { ACTION_STD_OK,          BUTTON_RIGHT|BUTTON_REL,      BUTTON_RIGHT },
+    { ACTION_STD_CANCEL,      BUTTON_LEFT|BUTTON_REL,       BUTTON_LEFT },
+    { ACTION_STD_CANCEL,      BUTTON_BACK|BUTTON_REL,       BUTTON_NONE },
+    { ACTION_STD_MENU,        BUTTON_BACK|BUTTON_REPEAT,    BUTTON_BACK },
+    { ACTION_TREE_WPS,        BUTTON_USER|BUTTON_REPEAT,    BUTTON_USER },
+
+    { ACTION_STD_CONTEXT,     BUTTON_MENU|BUTTON_REL,       BUTTON_NONE },
+    { ACTION_STD_QUICKSCREEN, BUTTON_MENU|BUTTON_REPEAT,    BUTTON_MENU },
+    { ACTION_STD_KEYLOCK,     BUTTON_POWER|BUTTON_REL,      BUTTON_NONE },
+
+    LAST_ITEM_IN_LIST
+}; /* button_context_standard */
+
+static const struct button_mapping button_context_wps[]  = {
+    { ACTION_WPS_BROWSE,         BUTTON_BACK|BUTTON_REL,        BUTTON_NONE },
+    { ACTION_WPS_MENU,           BUTTON_BACK|BUTTON_REPEAT,     BUTTON_BACK },
+    { ACTION_WPS_HOTKEY,         BUTTON_USER|BUTTON_REL,        BUTTON_NONE },
+    /* NOTE: this is available only enabling AB-Repeat mode */
+    { ACTION_WPSAB_SINGLE,       BUTTON_USER|BUTTON_REL,        BUTTON_USER },
+    { ACTION_STD_KEYLOCK,        BUTTON_POWER|BUTTON_REL,       BUTTON_NONE },
+    { ACTION_WPS_CONTEXT,        BUTTON_MENU|BUTTON_REL,        BUTTON_NONE },
+    { ACTION_WPS_QUICKSCREEN,    BUTTON_MENU|BUTTON_REPEAT,     BUTTON_MENU },
+    { ACTION_WPS_PLAY,           BUTTON_CENTER,                 BUTTON_NONE },
+
+    { ACTION_WPS_SKIPNEXT,       BUTTON_RIGHT|BUTTON_REL,       BUTTON_RIGHT },
+    { ACTION_WPS_SKIPPREV,       BUTTON_LEFT|BUTTON_REL,        BUTTON_LEFT },
+
+    { ACTION_WPS_SEEKBACK,       BUTTON_LEFT|BUTTON_REPEAT,     BUTTON_NONE },
+    { ACTION_WPS_SEEKFWD,        BUTTON_RIGHT|BUTTON_REPEAT,    BUTTON_NONE },
+    { ACTION_WPS_STOPSEEK,       BUTTON_LEFT|BUTTON_REL,        BUTTON_LEFT|BUTTON_REPEAT },
+    { ACTION_WPS_STOPSEEK,       BUTTON_RIGHT|BUTTON_REL,       BUTTON_RIGHT|BUTTON_REPEAT },
+
+    { ACTION_WPS_VOLDOWN,        BUTTON_DOWN|BUTTON_REL,        BUTTON_NONE },
+    { ACTION_WPS_VOLUP,          BUTTON_UP|BUTTON_REL,          BUTTON_NONE },
+    { ACTION_WPS_VOLDOWN,        BUTTON_DOWN|BUTTON_REPEAT,     BUTTON_NONE },
+    { ACTION_WPS_VOLUP,          BUTTON_UP|BUTTON_REPEAT,       BUTTON_NONE },
+    { ACTION_WPS_STOP,           BUTTON_POWER|BUTTON_REPEAT,    BUTTON_POWER },
+
+   // ACTION_WPS_ID3SCREEN,/* optional */
+   // ACTION_WPS_QUICKSCREEN,/* optional */
+    LAST_ITEM_IN_LIST
+}; /* button_context_wps */
+
+static const struct button_mapping button_context_list[]  = {
+    { ACTION_STD_KEYLOCK,     BUTTON_POWER|BUTTON_REL,      BUTTON_NONE },
+    { ACTION_TREE_STOP,       BUTTON_POWER|BUTTON_REPEAT,    BUTTON_POWER },
+
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
+}; /* button_context_list */
+
+static const struct button_mapping button_context_tree[]  = {
+    { ACTION_STD_KEYLOCK,     BUTTON_POWER|BUTTON_REL,        BUTTON_NONE },
+    { ACTION_TREE_HOTKEY,      BUTTON_USER|BUTTON_REL,        BUTTON_NONE },
+
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST)
+}; /* button_context_tree */
+
+static const struct button_mapping button_context_listtree_scroll_with_combo[]  = {
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE),
+};
+
+static const struct button_mapping button_context_listtree_scroll_without_combo[]  = {
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE),
+};
+
+static const struct button_mapping button_context_settings[]  = {
+
+    { ACTION_SETTINGS_INC,          BUTTON_RIGHT|BUTTON_REL,     BUTTON_NONE },
+    { ACTION_SETTINGS_INCREPEAT,    BUTTON_RIGHT|BUTTON_REPEAT,  BUTTON_NONE },
+    { ACTION_SETTINGS_DEC,          BUTTON_LEFT|BUTTON_REL,      BUTTON_NONE },
+    { ACTION_SETTINGS_DECREPEAT,    BUTTON_LEFT|BUTTON_REPEAT,   BUTTON_NONE },
+    { ACTION_STD_OK,                BUTTON_CENTER,               BUTTON_NONE },
+    { ACTION_STD_CANCEL,            BUTTON_BACK|BUTTON_REL,      BUTTON_NONE },
+
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
+}; /* button_context_settings */
+
+static const struct button_mapping button_context_settings_right_is_inc[]  = {
+
+    { ACTION_SETTINGS_INC,          BUTTON_RIGHT|BUTTON_REL,                BUTTON_NONE },
+    { ACTION_SETTINGS_INCREPEAT,    BUTTON_RIGHT|BUTTON_REPEAT,             BUTTON_NONE },
+    { ACTION_SETTINGS_DEC,          BUTTON_LEFT|BUTTON_REL,                 BUTTON_NONE },
+    { ACTION_SETTINGS_DECREPEAT,    BUTTON_LEFT|BUTTON_REPEAT,              BUTTON_NONE },
+    { ACTION_STD_OK,                BUTTON_CENTER|BUTTON_REL,               BUTTON_NONE },
+    { ACTION_STD_CANCEL,            BUTTON_BACK|BUTTON_REL,                 BUTTON_NONE },
+    
+    LAST_ITEM_IN_LIST
+
+//    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
+}; /* button_context_settingsgraphical */
+
+static const struct button_mapping button_context_yesno[]  = {
+    { ACTION_YESNO_ACCEPT,  BUTTON_CENTER,  BUTTON_NONE },
+
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
+}; /* button_context_settings_yesno */
+
+static const struct button_mapping button_context_colorchooser[]  = {
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_SETTINGS),
+}; /* button_context_colorchooser */
+
+static const struct button_mapping button_context_eq[]  = {
+
+    { ACTION_SETTINGS_INC,       BUTTON_RIGHT,               BUTTON_NONE },
+    { ACTION_SETTINGS_INCREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
+    { ACTION_SETTINGS_DEC,       BUTTON_LEFT,                BUTTON_NONE },
+    { ACTION_SETTINGS_DECREPEAT, BUTTON_LEFT|BUTTON_REPEAT,  BUTTON_NONE },
+    { ACTION_STD_OK,             BUTTON_MENU,                BUTTON_NONE },
+    { ACTION_STD_OK,             BUTTON_CENTER,              BUTTON_NONE },
+    { ACTION_STD_CANCEL,         BUTTON_BACK|BUTTON_REL,     BUTTON_NONE },
+    { ACTION_STD_PREV,           BUTTON_UP,                  BUTTON_NONE },
+    { ACTION_STD_PREVREPEAT,     BUTTON_UP|BUTTON_REPEAT,    BUTTON_NONE },
+    { ACTION_STD_NEXT,           BUTTON_DOWN,                BUTTON_NONE },
+    { ACTION_STD_NEXTREPEAT,     BUTTON_DOWN|BUTTON_REPEAT,  BUTTON_NONE },
+
+    LAST_ITEM_IN_LIST
+}; /* button_context_eq */
+
+/** Bookmark Screen **/
+static const struct button_mapping button_context_bmark[]  = {
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST),
+}; /* button_context_bmark */
+
+static const struct button_mapping button_context_time[]  = {
+
+    { ACTION_SETTINGS_INC,          BUTTON_UP,                   BUTTON_NONE },
+    { ACTION_SETTINGS_INCREPEAT,    BUTTON_UP|BUTTON_REPEAT,     BUTTON_NONE },
+    { ACTION_SETTINGS_DEC,          BUTTON_DOWN,                 BUTTON_NONE },
+    { ACTION_SETTINGS_DECREPEAT,    BUTTON_DOWN|BUTTON_REPEAT,   BUTTON_NONE },
+    { ACTION_STD_OK,                BUTTON_CENTER,               BUTTON_NONE },
+    { ACTION_STD_CANCEL,            BUTTON_BACK|BUTTON_REL,      BUTTON_NONE },
+    { ACTION_STD_PREV,              BUTTON_LEFT,                 BUTTON_NONE },
+    { ACTION_STD_PREVREPEAT,        BUTTON_LEFT|BUTTON_REPEAT,   BUTTON_NONE },
+    { ACTION_STD_NEXT,              BUTTON_RIGHT,                BUTTON_NONE },
+    { ACTION_STD_NEXTREPEAT,        BUTTON_RIGHT|BUTTON_REPEAT,  BUTTON_NONE },
+    
+    LAST_ITEM_IN_LIST
+    //LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS),
+}; /* button_context_time */
+
+static const struct button_mapping button_context_quickscreen[]  = {
+
+    { ACTION_STD_CANCEL,    BUTTON_BACK|BUTTON_REL,         BUTTON_NONE },
+    { ACTION_QS_TOP,        BUTTON_UP|BUTTON_REL,           BUTTON_NONE },
+    { ACTION_QS_TOP,        BUTTON_UP|BUTTON_REPEAT,        BUTTON_NONE },
+    { ACTION_QS_DOWN,       BUTTON_DOWN|BUTTON_REL,         BUTTON_NONE },
+    { ACTION_QS_DOWN,       BUTTON_DOWN|BUTTON_REPEAT,      BUTTON_NONE },
+    { ACTION_QS_LEFT,       BUTTON_LEFT|BUTTON_REL,         BUTTON_NONE },
+    { ACTION_QS_LEFT,       BUTTON_LEFT|BUTTON_REPEAT,      BUTTON_NONE },
+    { ACTION_QS_RIGHT,      BUTTON_RIGHT|BUTTON_REL,        BUTTON_NONE },
+    { ACTION_QS_RIGHT,      BUTTON_RIGHT|BUTTON_REPEAT,     BUTTON_NONE },
+    { ACTION_STD_CANCEL,    BUTTON_MENU|BUTTON_REL,         BUTTON_NONE },
+
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
+}; /* button_context_quickscreen */
+
+static const struct button_mapping button_context_pitchscreen[]  = {
+
+    { ACTION_PS_INC_SMALL,   BUTTON_UP|BUTTON_REPEAT,     BUTTON_NONE },
+    { ACTION_PS_INC_SMALL,   BUTTON_UP|BUTTON_REL,        BUTTON_NONE },
+    { ACTION_PS_INC_BIG,     BUTTON_RIGHT|BUTTON_REPEAT,  BUTTON_NONE },
+    { ACTION_PS_INC_BIG,     BUTTON_RIGHT|BUTTON_REL,     BUTTON_NONE },
+    { ACTION_PS_DEC_SMALL,   BUTTON_DOWN|BUTTON_REPEAT,   BUTTON_NONE },
+    { ACTION_PS_DEC_SMALL,   BUTTON_DOWN|BUTTON_REL,      BUTTON_NONE },
+    { ACTION_PS_DEC_BIG,     BUTTON_LEFT|BUTTON_REPEAT,   BUTTON_NONE },
+    { ACTION_PS_DEC_BIG,     BUTTON_LEFT|BUTTON_REL,      BUTTON_NONE },
+    { ACTION_PS_RESET,       BUTTON_MENU|BUTTON_REL,      BUTTON_NONE },
+    { ACTION_PS_TOGGLE_MODE, BUTTON_CENTER|BUTTON_REL,    BUTTON_NONE },
+    { ACTION_PS_SLOWER,      BUTTON_USER,                 BUTTON_NONE },
+    { ACTION_PS_FASTER,      BUTTON_POWER,                BUTTON_NONE },
+    { ACTION_PS_EXIT,        BUTTON_BACK|BUTTON_REL,      BUTTON_NONE },
+
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
+}; /* button_context_pitchcreen */
+
+static const struct button_mapping button_context_keyboard[]  = {
+
+    { ACTION_KBD_PAGE_FLIP,    BUTTON_MENU|BUTTON_REL,          BUTTON_NONE },
+    { ACTION_KBD_SELECT,       BUTTON_CENTER,                   BUTTON_NONE },
+    { ACTION_KBD_ABORT,        BUTTON_BACK|BUTTON_REL,          BUTTON_NONE },
+    { ACTION_KBD_DONE,         BUTTON_USER,                     BUTTON_NONE },
+    { ACTION_KBD_UP,           BUTTON_UP,                       BUTTON_NONE },
+    { ACTION_KBD_UP,           BUTTON_UP|BUTTON_REPEAT,         BUTTON_NONE },
+    { ACTION_KBD_DOWN,         BUTTON_DOWN,                     BUTTON_NONE },
+    { ACTION_KBD_DOWN,         BUTTON_DOWN|BUTTON_REPEAT,       BUTTON_NONE },
+    { ACTION_KBD_LEFT,         BUTTON_LEFT,                     BUTTON_NONE },
+    { ACTION_KBD_LEFT,         BUTTON_LEFT|BUTTON_REPEAT,       BUTTON_NONE },
+    { ACTION_KBD_RIGHT,        BUTTON_RIGHT,                    BUTTON_NONE },
+    { ACTION_KBD_RIGHT,        BUTTON_RIGHT|BUTTON_REPEAT,      BUTTON_NONE },
+    { ACTION_KBD_BACKSPACE,    BUTTON_USER,                     BUTTON_NONE },
+
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
+}; /* button_context_keyboard */
+
+static const struct button_mapping button_context_radio[]  = {
+    LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS)
+}; /* button_context_radio */
+
+const struct button_mapping* get_context_mapping(int context)
+{
+    switch (context)
+    {
+        case CONTEXT_STD:
+            return button_context_standard;
+        case CONTEXT_WPS:
+            return button_context_wps;
+
+        case CONTEXT_LIST:
+            return button_context_list;
+        case CONTEXT_MAINMENU:
+        case CONTEXT_TREE:
+            if (global_settings.hold_lr_for_scroll_in_list)
+                return button_context_listtree_scroll_without_combo;
+            else
+                return button_context_listtree_scroll_with_combo;
+        case CONTEXT_CUSTOM|CONTEXT_TREE:
+            return button_context_tree;
+
+        case CONTEXT_SETTINGS:
+            return button_context_settings;
+        case CONTEXT_CUSTOM|CONTEXT_SETTINGS:
+        case CONTEXT_SETTINGS_RECTRIGGER:
+            return button_context_settings_right_is_inc;
+
+        case CONTEXT_SETTINGS_COLOURCHOOSER:
+            return button_context_colorchooser;
+        case CONTEXT_SETTINGS_EQ:
+            return button_context_eq;
+
+        case CONTEXT_SETTINGS_TIME:
+            return button_context_time;
+
+        case CONTEXT_YESNOSCREEN:
+            return button_context_yesno;
+        case CONTEXT_FM:
+            return button_context_radio;
+        case CONTEXT_BOOKMARKSCREEN:
+            return button_context_bmark;
+        case CONTEXT_QUICKSCREEN:
+            return button_context_quickscreen;
+        case CONTEXT_PITCHSCREEN:
+            return button_context_pitchscreen;
+        case CONTEXT_KEYBOARD:
+            return button_context_keyboard;
+    }
+    return button_context_standard;
+}
Index: firmware/export/ascodec.h
===================================================================
--- firmware/export/ascodec.h	(revision 31001)
+++ firmware/export/ascodec.h	(working copy)
@@ -28,4 +28,8 @@
 #include "ascodec-target.h"
 #endif
 
+#ifdef SAMSUNG_YPR0
+#include "ascodec-target.h"
 #endif
+
+#endif
Index: firmware/export/rbpaths.h
===================================================================
--- firmware/export/rbpaths.h	(revision 31001)
+++ firmware/export/rbpaths.h	(working copy)
@@ -57,6 +57,18 @@
 #define PLAYLIST_CATALOG_DEFAULT_DIR "/Playlists"
 
 #define paths_init()
+
+#elif (CONFIG_PLATFORM & PLATFORM_YPR0)
+#undef ROCKBOX_LIBRARY_PATH
+#define ROCKBOX_LIBRARY_PATH ROCKBOX_DIR
+
+#define PLUGIN_DIR          ROCKBOX_DIR "/rocks"
+#define CODECS_DIR          ROCKBOX_DIR "/codecs"
+
+#define REC_BASE_DIR        ROCKBOX_DIR "/"
+#define PLAYLIST_CATALOG_DEFAULT_DIR ROCKBOX_DIR "/Playlists"
+#define paths_init()
+
 #else /* application */
 
 #define PLUGIN_DIR          ROCKBOX_LIBRARY_PATH "/rockbox/rocks"
@@ -80,7 +92,13 @@
 #define PLUGIN_DEMOS_DIR    PLUGIN_DIR "/demos"
 #define VIEWERS_DIR         PLUGIN_DIR "/viewers"
 
-#ifdef APPLICATION
+#if (CONFIG_PLATFORM & PLATFORM_YPR0)
+#define PLUGIN_DATA_DIR          PLUGIN_DIR
+#define PLUGIN_GAMES_DATA_DIR    PLUGIN_DATA_DIR
+#define PLUGIN_APPS_DATA_DIR     PLUGIN_DATA_DIR
+#define PLUGIN_DEMOS_DATA_DIR    PLUGIN_DATA_DIR
+#define VIEWERS_DATA_DIR         PLUGIN_DATA_DIR
+#elif defined(APPLICATION)
 #define PLUGIN_DATA_DIR          "/.rockbox/rocks.data"
 #define PLUGIN_GAMES_DATA_DIR    PLUGIN_DATA_DIR
 #define PLUGIN_APPS_DATA_DIR     PLUGIN_DATA_DIR
Index: firmware/export/audiohw.h
===================================================================
--- firmware/export/audiohw.h	(revision 31001)
+++ firmware/export/audiohw.h	(working copy)
@@ -79,7 +79,7 @@
 #elif defined(HAVE_DUMMY_CODEC)
 #include "dummy_codec.h"
 #endif
-#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
+#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !(CONFIG_PLATFORM & PLATFORM_YPR0)
 /* #include <SDL_audio.h> gives errors in other code areas,
  * we don't really need it here, so don't. but it should maybe be fixed */
 #ifndef SIMULATOR /* simulator gets values from the target .h files */
Index: firmware/export/config.h
===================================================================
--- firmware/export/config.h	(revision 31001)
+++ firmware/export/config.h	(working copy)
@@ -89,6 +89,7 @@
 #define PLATFORM_MAEMO5  (1<<5)
 #define PLATFORM_MAEMO   (PLATFORM_MAEMO4|PLATFORM_MAEMO5)
 #define PLATFORM_PANDORA (1<<6)
+#define PLATFORM_YPR0    (1<<7)
 
 /* CONFIG_KEYPAD */
 #define PLAYER_PAD          1
@@ -482,6 +483,8 @@
 #include "config/nokian900.h"
 #elif defined(PANDORA)
 #include "config/pandora.h"
+#elif defined(SAMSUNG_YPR0)
+#include "config/ypr0.h"
 #else
 /* no known platform */
 #endif
Index: firmware/export/config/ypr0.h
===================================================================
--- firmware/export/config/ypr0.h	(revision 0)
+++ firmware/export/config/ypr0.h	(revision 0)
@@ -0,0 +1,182 @@
+/*
+ * This config file is for the RockBox as application on the Samsung YP-R0 player.
+ * The target name for ifdefs is: SAMSUNG_YPR0; or CONFIG_PLATFORM & PLAFTORM_YPR0
+ */
+
+#define TARGET_TREE /* this target is using the target tree system */
+//#define DEBUG
+//#undef NDEBUG
+
+/* We don't run on hardware directly */
+/* YP-R0 need it too of course */
+#define CONFIG_PLATFORM (PLATFORM_HOSTED|PLATFORM_SDL|PLATFORM_YPR0)
+
+//#define CPU_ARM
+//#define ARM_ARCH 4
+
+/* For Rolo and boot loader */
+#define MODEL_NUMBER 100
+
+#define MODEL_NAME   "Samsung YP-R0"
+
+/* Indeed to check that */
+/*TODO: R0 should charge battery automatically, no software stuff to manage that. Just to know about some as3543 registers, that should be set after loading samsung's afe.ko module 
+ */
+/*TODO: implement USB data transfer management -> see safe mode script and think a way to implemtent it in the code */
+#define USB_NONE
+
+/* Hardware controlled charging with monitoring */
+//#define CONFIG_CHARGING CHARGING_MONITOR
+
+/* There is only USB charging */
+//#define HAVE_USB_POWER
+
+/* define this if you have a bitmap LCD display */
+#define HAVE_LCD_BITMAP
+
+/* define this if you have a colour LCD */
+#define HAVE_LCD_COLOR
+
+/* define this if the LCD needs to be shutdown */
+/* TODO: Our framebuffer must be closed... */
+#define HAVE_LCD_SHUTDOWN
+
+/* define this if you want album art for this target */
+#define HAVE_ALBUMART
+
+/* define this to enable bitmap scaling */
+#define HAVE_BMP_SCALING
+
+/* define this to enable JPEG decoding */
+#define HAVE_JPEG
+
+/* define this if you have access to the quickscreen */
+#define HAVE_QUICKSCREEN
+
+/* define this if you have access to the pitchscreen */
+#define HAVE_PITCHSCREEN
+
+/* define this if you would like tagcache to build on this target */
+#define HAVE_TAGCACHE
+
+/* LCD dimensions
+ *
+ * overriden by configure for application builds */
+#ifndef LCD_WIDTH
+#define LCD_WIDTH  240
+#endif
+
+#ifndef LCD_HEIGHT
+#define LCD_HEIGHT 320
+#endif
+
+#define LCD_DEPTH  16
+/* Check that but should not matter */
+#define LCD_PIXELFORMAT 565
+
+/* YP-R0 has the backlight */
+#define HAVE_BACKLIGHT
+
+/* Define this for LCD backlight brightness available */
+#define HAVE_BACKLIGHT_BRIGHTNESS
+
+/* Main LCD backlight brightness range and defaults */
+/* 0 is turned off. 31 is the real maximum for the ASCODEC DCDC but samsung doesn't use any value over 15, so it safer to don't go up too much */
+#define MIN_BRIGHTNESS_SETTING          1
+#define MAX_BRIGHTNESS_SETTING          15
+#define DEFAULT_BRIGHTNESS_SETTING      4
+
+/* Which backlight fading type? */
+/* TODO: ASCODEC has an auto dim feature, so disabling the supply to leds should do the trick. But for now I tested SW fading only */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
+/* define this if you have RTC RAM available for settings */
+/* TODO: in theory we could use that, ascodec offers us such a ram. we have also a small device, part of the nand of 1 MB size, that Samsung uses to store region code etc and it's almost unused space */
+//#define HAVE_RTC_RAM
+
+/* define this if you have a real-time clock */
+//#define CONFIG_RTC APPLICATION
+#define CONFIG_RTC RTC_AS3514
+#define HAVE_RTC_ALARM
+
+/* The number of bytes reserved for loadable codecs */
+#define CODEC_SIZE 0x100000
+
+/* The number of bytes reserved for loadable plugins */
+/* NOTE: increased from 1 MB to 3 MB */
+#define PLUGIN_BUFFER_SIZE 0x200000
+
+/* We can do AB-repeat -> we use User key, our hotkey */
+#define AB_REPEAT_ENABLE
+#define ACTION_WPSAB_SINGLE ACTION_WPS_HOTKEY
+
+/* Define this if you do software codec */
+#define CONFIG_CODEC SWCODEC
+
+/* R0 KeyPad configuration for plugins */
+#define CONFIG_KEYPAD SAMSUNG_YPR0_PAD
+/* It's better to close /dev/r0Btn at shutdown */
+#define BUTTON_DRIVER_CLOSE
+
+/* Use SDL audio/pcm in a SDL app build */
+//#define HAVE_SDL
+#define HAVE_SDL_AUDIO
+/* On our YPR0 we need to have a better contol also on this device */
+/*TODO: still some issues */
+#define HAVE_AS3514
+#define HAVE_AS3543
+
+#define HAVE_SW_TONE_CONTROLS
+
+/* FM Tuner */
+//#define CONFIG_TUNER SI4700
+//#define HAVE_TUNER_PWR_CTRL
+
+/*TODO: In R0 there is an interrupt for this. I need just to understand the ioctl codes [already done] but how to use them, which structure to pass ecc */
+//#define HAVE_HEADPHONE_DETECTION
+
+/* Define current usage levels. */
+/*TODO: to be filled with correct values after implementing power management */
+#define CURRENT_NORMAL     88 /* 18 hours from a 1600 mAh battery */  
+#define CURRENT_BACKLIGHT  30 /* TBD */ 
+#define CURRENT_RECORD     0  /* no recording yet */ 
+
+//#define BATTERY_CAPACITY_DEFAULT 600 /* default battery capacity */
+//#define BATTERY_CAPACITY_MIN 600  /* min. capacity selectable */
+//#define BATTERY_CAPACITY_MAX 700 /* max. capacity selectable */
+//#define BATTERY_CAPACITY_INC 50   /* capacity increment */
+//#define BATTERY_TYPES_COUNT  1    /* only one type */
+
+/* Charging implemented in a target-specific algorithm */
+//#define CONFIG_CHARGING CHARGING_TARGET
+//#define HAVE_RESET_BATTERY_FILTER
+
+/* Offset ( in the firmware file's header ) to the file CRC */
+#define FIRMWARE_OFFSET_FILE_CRC 0
+
+/* Offset ( in the firmware file's header ) to the real data */
+#define FIRMWARE_OFFSET_FILE_DATA 8
+
+//????
+#define CONFIG_LCD LCD_COWOND2
+
+/* Define this if a programmable hotkey is mapped */
+#define HAVE_HOTKEY
+
+/* Define this if you have a software controlled poweroff */
+#define HAVE_SW_POWEROFF
+
+/* Define this if you have adjustable CPU frequency */
+//#define HAVE_ADJUSTABLE_CPU_FREQ
+/* Define this to the CPU frequency */
+/* NOTE: cpu frequency scaling is handled externally by our linux kernel. In the starter script you can see the configuration for this */
+#define CPU_FREQ            532000000
+/* 0.8Vcore using 200 MHz */
+//#define CPUFREQ_DEFAULT     200000000
+/* This is 400 MHz -> not so powersaving-ful */
+//#define CPUFREQ_NORMAL      400000000
+/* Max IMX37 Cpu Frequency */
+//#define CPUFREQ_MAX         CPU_FREQ
+
+/* TODO: my idea is to create a folder in the cramfs [/.rockbox], mounting it by the starter script as the current working directory, so no issues of any type keeping the rockbox folder as in all other players */
+#define BOOTDIR "/mnt/mmc/rockbox"
\ No newline at end of file
Index: firmware/export/as3514.h
===================================================================
--- firmware/export/as3514.h	(revision 31001)
+++ firmware/export/as3514.h	(working copy)
@@ -131,9 +131,14 @@
 /* Headphone volume goes from -81.0 ... +6dB */
 #define VOLUME_MIN -810
 #else
+#ifdef SAMSUNG_YPR0
+/* Headphone volume goes from -40.5 ... +6dB */
+#define VOLUME_MIN -405
+#else
 /* Headphone volume goes from -73.5 ... +6dB */
 #define VOLUME_MIN -735
 #endif
+#endif
 #define VOLUME_MAX   60
 
 /*** Audio Registers ***/
Index: firmware/pcm_mixer.c
===================================================================
--- firmware/pcm_mixer.c	(revision 31001)
+++ firmware/pcm_mixer.c	(working copy)
@@ -75,7 +75,7 @@
     ({ start = (void *)(((uintptr_t)start + 3) & ~3); \
        size &= ~3; })
 
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if ((CONFIG_PLATFORM & PLATFORM_NATIVE) || (CONFIG_PLATFORM & PLATFORM_YPR0))
 
 /* Include any implemented CPU-optimized mixdown routines */
 #if defined(CPU_ARM)
Index: firmware/system.c
===================================================================
--- firmware/system.c	(revision 31001)
+++ firmware/system.c	(working copy)
@@ -26,7 +26,7 @@
 #include "string.h"
 #include "file.h"
 
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#if ((CONFIG_PLATFORM & PLATFORM_NATIVE) || (CONFIG_PLATFORM & PLATFORM_YPR0))
 long cpu_frequency SHAREDBSS_ATTR = CPU_FREQ;
 #endif
 
Index: firmware/sound.c
===================================================================
--- firmware/sound.c	(revision 31001)
+++ firmware/sound.c	(working copy)
@@ -235,7 +235,7 @@
     dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0);
 #endif
 
-#ifndef HAVE_SDL_AUDIO
+#if !defined(HAVE_SDL_AUDIO) || defined(SAMSUNG_YPR0)
 #if CONFIG_CODEC == MAS3507D
     dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
 #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
@@ -670,7 +670,7 @@
   && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \
   && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \
   && !defined (HAVE_WM8750) && !defined (HAVE_WM8751) \
-  && !defined(HAVE_AK4537)) || (CONFIG_PLATFORM & PLATFORM_HOSTED)
+  && !defined(HAVE_AK4537)) || (CONFIG_PLATFORM & PLATFORM_HOSTED) && !(CONFIG_PLATFORM & PLATFORM_YPR0)
 int sound_val2phys(int setting, int value)
 {
 #if CONFIG_CODEC == MAS3587F
Index: firmware/SOURCES
===================================================================
--- firmware/SOURCES	(revision 31001)
+++ firmware/SOURCES	(working copy)
@@ -7,7 +7,7 @@
 general.c
 load_code.c
 powermgmt.c
-#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
+#if ((CONFIG_PLATFORM & PLATFORM_HOSTED) && !(CONFIG_PLATFORM & PLATFORM_YPR0))
 target/hosted/powermgmt.c
 target/hosted/rtc.c
 #endif
@@ -30,7 +30,7 @@
 #endif /* PLATFORM_NATIVE */
 panic.c
 
-#ifdef HAVE_SDL
+#if defined(HAVE_SDL)
 target/hosted/sdl/button-sdl.c
 target/hosted/sdl/kernel-sdl.c
 #ifdef HAVE_LCD_BITMAP
@@ -57,6 +57,35 @@
 #endif
 #endif
 
+#if (CONFIG_PLATFORM & PLATFORM_YPR0)
+target/hosted/powermgmt.c
+#if (CONFIG_RTC == RTC_AS3514)
+drivers/rtc/rtc_as3514.c
+#else
+target/hosted/rtc.c
+#endif
+target/hosted/ypr0/button-ypr0.c
+target/hosted/ypr0/kernel-sdl.c
+target/hosted/ypr0/lcd-ypr0.c
+target/hosted/ypr0/system-ypr0.c
+#ifdef HAVE_SDL_THREADS
+target/hosted/ypr0/thread-sdl.c
+#else
+thread.c
+#endif
+target/hosted/ypr0/timer-sdl.c
+#ifdef HAVE_BACKLIGHT
+target/hosted/ypr0/backlight-ypr0.c
+#endif
+target/hosted/ypr0/ascodec-ypr0.c
+target/hosted/ypr0/powermgmt-ypr0.c
+//target/hosted/ypr0/powermgmt-ascodec.c
+//target/arm/adc-as3514.c
+//CPU optimizations
+//target/arm/system-arm.c
+//target/arm/pcm-mixer-armv4.c
+#endif
+
 /* Maemo specific files */
 #if (CONFIG_PLATFORM & PLATFORM_MAEMO)
 target/hosted/maemo/maemo-thread.c
@@ -360,6 +389,9 @@
 #elif defined (HAVE_DUMMY_CODEC)
 drivers/audio/dummy_codec.c
 #endif /* defined(HAVE_*) */
+#elif defined(SAMSUNG_YPR0) && defined(HAVE_AS3514)
+drivers/audio/as3514.c
+target/hosted/ypr0/pcm-ypr0.c
 #elif defined(HAVE_SDL_AUDIO)
 drivers/audio/sdl.c
 #if CONFIG_CODEC == SWCODEC
Index: firmware/target/hosted/sdl/pcm-sdl.c
===================================================================
--- firmware/target/hosted/sdl/pcm-sdl.c	(revision 31001)
+++ firmware/target/hosted/sdl/pcm-sdl.c	(working copy)
@@ -51,7 +51,11 @@
 extern bool debug_audio;
 #endif
 
+#if (CONFIG_PLATFORM & PLATFORM_YPR0)
+static int sim_volume = SDL_MIX_MAXVOLUME * ((VOLUME_MAX - VOLUME_MIN) / 10) / (VOLUME_RANGE / 10);
+#else
 static int sim_volume = 0;
+#endif
 
 #if CONFIG_CODEC == SWCODEC
 static int cvt_status = -1;
Index: firmware/target/hosted/ypr0/kernel-sdl.c
===================================================================
--- firmware/target/hosted/ypr0/kernel-sdl.c	(revision 0)
+++ firmware/target/hosted/ypr0/kernel-sdl.c	(revision 0)
@@ -0,0 +1,213 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: kernel-sdl.c 29516 2011-03-05 15:31:52Z thomasjfox $
+ *
+ * Copyright (C) 2002 by Felix Arends
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <SDL.h>
+#include <SDL_thread.h>
+#include <inttypes.h>
+#include "system-sdl.h"
+#include "thread-sdl.h"
+#include "kernel.h"
+#include "thread.h"
+#include "panic.h"
+#include "debug.h"
+
+static SDL_TimerID tick_timer_id;
+long start_tick;
+
+#ifndef HAVE_SDL_THREADS
+/* for the wait_for_interrupt function */
+static SDL_cond *wfi_cond;
+static SDL_mutex *wfi_mutex;
+#endif
+/* Condition to signal that "interrupts" may proceed */
+static SDL_cond *sim_thread_cond;
+/* Mutex to serialize changing levels and exclude other threads while
+ * inside a handler */
+static SDL_mutex *sim_irq_mtx;
+/* Level: 0 = enabled, not 0 = disabled */
+static int volatile interrupt_level = HIGHEST_IRQ_LEVEL;
+/* How many handers waiting? Not strictly needed because CondSignal is a
+ * noop if no threads were waiting but it filters-out calls to functions
+ * with higher overhead and provides info when debugging. */
+static int handlers_pending = 0;
+/* 1 = executing a handler; prevents CondSignal calls in set_irq_level
+ * while in a handler */
+static int status_reg = 0;
+
+/* Nescessary logic:
+ * 1) All threads must pass unblocked
+ * 2) Current handler must always pass unblocked
+ * 3) Threads must be excluded when irq routine is running
+ * 4) No more than one handler routine should execute at a time
+ */
+int set_irq_level(int level)
+{
+    SDL_LockMutex(sim_irq_mtx);
+
+    int oldlevel = interrupt_level;
+
+    if (status_reg == 0 && level == 0 && oldlevel != 0)
+    {
+        /* Not in a handler and "interrupts" are going from disabled to
+         * enabled; signal any pending handlers still waiting */
+        if (handlers_pending > 0)
+            SDL_CondBroadcast(sim_thread_cond);
+    }
+
+    interrupt_level = level; /* save new level */
+
+    SDL_UnlockMutex(sim_irq_mtx);
+    return oldlevel;
+}
+
+void sim_enter_irq_handler(void)
+{
+    SDL_LockMutex(sim_irq_mtx);
+    handlers_pending++;
+
+    /* Check each time before proceeding: disabled->enabled->...->disabled
+     * is possible on an app thread before a handler thread is ever granted
+     * the mutex; a handler can also leave "interrupts" disabled during
+     * its execution */
+    while (interrupt_level != 0)
+        SDL_CondWait(sim_thread_cond, sim_irq_mtx);
+
+    status_reg = 1;
+}
+
+void sim_exit_irq_handler(void)
+{
+    /* If any others are waiting, give the signal */
+    if (--handlers_pending > 0)
+        SDL_CondSignal(sim_thread_cond);
+
+    status_reg = 0;
+    SDL_UnlockMutex(sim_irq_mtx);
+#ifndef HAVE_SDL_THREADS
+    SDL_CondSignal(wfi_cond);
+#endif
+}
+
+static bool sim_kernel_init(void)
+{
+    sim_irq_mtx = SDL_CreateMutex();
+    if (sim_irq_mtx == NULL)
+    {
+        panicf("Cannot create sim_handler_mtx\n");
+        return false;
+    }
+
+    sim_thread_cond = SDL_CreateCond();
+    if (sim_thread_cond == NULL)
+    {
+        panicf("Cannot create sim_thread_cond\n");
+        return false;
+    }
+#ifndef HAVE_SDL_THREADS
+    wfi_cond = SDL_CreateCond();
+    if (wfi_cond == NULL)
+    {
+        panicf("Cannot create wfi\n");
+        return false;
+    }
+    wfi_mutex = SDL_CreateMutex();
+    if (wfi_mutex == NULL)
+    {
+        panicf("Cannot create wfi mutex\n");
+        return false;
+    }
+#endif
+    return true;
+}
+
+void sim_kernel_shutdown(void)
+{
+    SDL_RemoveTimer(tick_timer_id);
+#ifndef HAVE_SDL_THREADS
+    SDL_DestroyCond(wfi_cond);
+    SDL_UnlockMutex(wfi_mutex);
+    SDL_DestroyMutex(wfi_mutex);
+#endif
+    enable_irq();
+    while(handlers_pending > 0)
+        SDL_Delay(10);
+
+    SDL_DestroyMutex(sim_irq_mtx);
+    SDL_DestroyCond(sim_thread_cond); 
+}
+
+Uint32 tick_timer(Uint32 interval, void *param)
+{
+    long new_tick;
+
+    (void) interval;
+    (void) param;
+    
+    new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ);
+        
+    while(new_tick != current_tick)
+    {
+        sim_enter_irq_handler();
+
+        /* Run through the list of tick tasks - increments tick
+         * on each iteration. */
+        call_tick_tasks();
+
+        sim_exit_irq_handler();
+    }
+    
+    return interval;
+}
+
+void tick_start(unsigned int interval_in_ms)
+{
+    if (!sim_kernel_init())
+    {
+        panicf("Could not initialize kernel!");
+        exit(-1);
+    }
+
+    if (tick_timer_id != NULL)
+    {
+        SDL_RemoveTimer(tick_timer_id);
+        tick_timer_id = NULL;
+    }
+    else
+    {
+        start_tick = SDL_GetTicks();
+    }
+
+    tick_timer_id = SDL_AddTimer(interval_in_ms, tick_timer, NULL);
+#ifndef HAVE_SDL_THREADS
+    SDL_LockMutex(wfi_mutex);
+#endif
+}
+
+#ifndef HAVE_SDL_THREADS
+void wait_for_interrupt(void)
+{
+    /* the exit may come at any time, during the CondWait or before,
+     * so check it twice */
+    SDL_CondWait(wfi_cond, wfi_mutex);
+}
+#endif
Index: firmware/target/hosted/ypr0/timer-sdl.c
===================================================================
--- firmware/target/hosted/ypr0/timer-sdl.c	(revision 0)
+++ firmware/target/hosted/ypr0/timer-sdl.c	(revision 0)
@@ -0,0 +1,61 @@
+/***************************************************************************
+*             __________               __   ___.
+*   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+*   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+*   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+*   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+*                     \/            \/     \/    \/            \/
+* $Id: timer-sdl.c 29516 2011-03-05 15:31:52Z thomasjfox $
+*
+* Copyright (C) 2005 Kévin Ferrare
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#include "timer.h"
+#include <SDL_timer.h>
+
+static int timer_prio = -1;
+void (*global_timer_callback)(void);
+SDL_TimerID timerId;
+
+Uint32 SDL_timer_callback(Uint32 interval, void *param){
+    (void)param;
+    global_timer_callback();
+    return(interval);
+}
+
+#define cycles_to_miliseconds(cycles) \
+    ((int)((1000*cycles)/TIMER_FREQ))
+
+bool timer_register(int reg_prio, void (*unregister_callback)(void),
+                    long cycles, void (*timer_callback)(void))
+{
+    (void)unregister_callback;
+    if (reg_prio <= timer_prio || cycles == 0)
+        return false;
+    timer_prio=reg_prio;
+    global_timer_callback=timer_callback;
+    timerId=SDL_AddTimer(cycles_to_miliseconds(cycles), SDL_timer_callback, 0);
+    return true;
+}
+
+bool timer_set_period(long cycles)
+{
+    SDL_RemoveTimer (timerId);
+    timerId=SDL_AddTimer(cycles_to_miliseconds(cycles), SDL_timer_callback, 0);
+    return true;
+}
+
+void timer_unregister(void)
+{
+    SDL_RemoveTimer (timerId);
+    timer_prio = -1;
+}
Index: firmware/target/hosted/ypr0/button-ypr0.c
===================================================================
--- firmware/target/hosted/ypr0/button-ypr0.c	(revision 0)
+++ firmware/target/hosted/ypr0/button-ypr0.c	(revision 0)
@@ -0,0 +1,128 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: button-sdl.c 30482 2011-09-08 14:53:28Z kugel $
+ *
+ * Copyright (C) 2011 Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <stdlib.h>         /* EXIT_SUCCESS */
+#include "config.h"
+#include "button.h"
+#include "kernel.h"
+#include "system.h"
+#include "button-target.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+static int r0Btn_fd = 0;
+
+/* Conversion from physical keypress code to logic key code */
+int key_to_button(int keyboard_button)
+{
+    int new_btn = BUTTON_NONE;
+    switch (keyboard_button)
+    {
+        case R0BTN_LEFT:
+            new_btn = BUTTON_LEFT;
+            break;
+        case R0BTN_RIGHT:
+            new_btn = BUTTON_RIGHT;
+            break;
+        case R0BTN_UP:
+            new_btn = BUTTON_UP;
+            break;
+        case R0BTN_DOWN:
+            new_btn = BUTTON_DOWN;
+            break;
+        case R0BTN_CENTRAL:
+            new_btn = BUTTON_CENTER;
+            break;
+        case R0BTN_F1:
+            new_btn = BUTTON_USER;
+            break;
+        case R0BTN_F2:
+            new_btn = BUTTON_BACK;
+            break;
+        case R0BTN_F3:
+            new_btn = BUTTON_MENU;
+            break;
+        case R0BTN_F4:
+            new_btn = BUTTON_POWER;
+            break;
+        default:
+            break;
+    }
+
+    return new_btn;
+}
+
+int button_read_device(void)
+{
+    int key = 0;
+    int new_btn = 0;
+    key = r0_read_key();
+
+    new_btn = key_to_button(key);
+/*        
+    if (pressed)
+        btn |= new_btn;
+    else
+        btn &= ~new_btn;
+*/
+    return new_btn;
+}
+
+/* Samsung keypad driver doesn't allow multiple key combinations :( */
+int r0_read_key()
+{
+    unsigned char keys;
+    int key = 0;
+
+    if (r0Btn_fd < 0)
+        return 0;
+    /* r0Btn device gives us 4 bytes "chucks". We read 1 byte a time, then RB will avoid for us 0 bytes */
+    if (read(r0Btn_fd, &keys, 1))
+    {
+        key = (int)keys;
+    } else {
+        key = 0;
+    }
+
+    return key;
+}
+
+/* Open the keypad device: it is offered by r0Btn.ko module */
+void button_init_device(void)
+{
+    r0Btn_fd = open("/dev/r0Btn", O_RDONLY);
+    if (r0Btn_fd < 0) {
+        printf("/dev/r0Btn open error!");
+   }
+}
+
+#ifdef BUTTON_DRIVER_CLOSE
+/*FIXME: I'm not sure it's called at shutdown...give a check! */
+void button_close_device(void)
+{
+    if (r0Btn_fd >= 0) {
+        close(r0Btn_fd);
+        printf("/dev/r0Btn closed!");
+    }
+}
+#endif /* BUTTON_DRIVER_CLOSE */
\ No newline at end of file
Index: firmware/target/hosted/ypr0/button-target.h
===================================================================
--- firmware/target/hosted/ypr0/button-target.h	(revision 0)
+++ firmware/target/hosted/ypr0/button-target.h	(revision 0)
@@ -0,0 +1,72 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: button-target.h 29248 2011-02-08 20:05:25Z thomasjfox $
+ *
+ * Copyright (C) 2011 by Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef _BUTTON_TARGET_H_
+#define _BUTTON_TARGET_H_
+
+#include <stdbool.h>
+#include "config.h"
+
+#undef button_init_device
+void button_init_device(void);
+#undef button_close_device
+void button_close_device(void);
+int button_read_device(void);
+int key_to_button(int keyboard_button);
+int r0_read_key(void);
+/* TODO: to be implemented */
+//void headphone_detect_event(void);
+//void headphone_init(void);
+
+/* Logical buttons key codes */
+#define BUTTON_NONE         0x00000000
+#define BUTTON_UP           0x00000001
+#define BUTTON_DOWN         0x00000002
+#define BUTTON_LEFT         0x00000004
+#define BUTTON_RIGHT        0x00000008
+#define BUTTON_USER         0x00000010
+#define BUTTON_CENTER       0x00010000
+#define BUTTON_MENU         0x00000020
+#define BUTTON_BACK         0x00000040
+#define BUTTON_POWER        0x00000400
+
+/* R0 physical key codes */
+#define R0BTN_F4            1  //PowerKey
+#define R0BTN_UP            2
+#define R0BTN_DOWN          3
+#define R0BTN_RIGHT         4
+#define R0BTN_LEFT          5
+#define R0BTN_CENTRAL       6
+#define R0BTN_F3            7  //ContextKey
+#define R0BTN_F2            8  //BackKey
+#define R0BTN_F1            11 //UserKey
+
+#define BUTTON_MAIN 0x1FFF
+
+/* No remote */
+#define BUTTON_REMOTE 0
+
+/* Software power-off */
+#define POWEROFF_BUTTON BUTTON_POWER
+/* About 3 seconds */
+#define POWEROFF_COUNT 10
+                
+#endif /* _BUTTON_TARGET_H_ */
\ No newline at end of file
Index: firmware/target/hosted/ypr0/i2c-target.h
===================================================================
--- firmware/target/hosted/ypr0/i2c-target.h	(revision 0)
+++ firmware/target/hosted/ypr0/i2c-target.h	(revision 0)
@@ -0,0 +1,25 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: i2c-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
+ *
+ * Copyright (C) 2010 by Thomas Martitz
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __I2C_TARGET_H__
+#define __I2C_TARGET_H__
+
+#endif /* __I2C_TARGET_H__ */
Index: firmware/target/hosted/ypr0/pcm-ypr0.c
===================================================================
--- firmware/target/hosted/ypr0/pcm-ypr0.c	(revision 0)
+++ firmware/target/hosted/ypr0/pcm-ypr0.c	(revision 0)
@@ -0,0 +1,408 @@
+/***************************************************************************
+ *             __________               __   ___.                  
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___  
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /  
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <   
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \  
+ *                     \/            \/     \/    \/            \/ 
+ * $Id: pcm-sdl.c 30403 2011-09-01 12:15:43Z jethead71 $
+ *
+ * Copyright (C) 2005 by Nick Lanham
+ * Copyright (C) 2010 by Thomas Martitz
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "autoconf.h"
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <SDL.h>
+#include "config.h"
+#include "debug.h"
+#include "sound.h"
+#include "audiohw.h"
+#include "system.h"
+#include "panic.h"
+
+#include "pcm.h"
+#include "pcm-internal.h"
+#include "pcm_sampr.h"
+
+/*#define LOGF_ENABLE*/
+#include "logf.h"
+
+#ifdef DEBUG
+#include <stdio.h>
+extern bool debug_audio;
+#endif
+
+#if CONFIG_CODEC == SWCODEC
+static int cvt_status = -1;
+
+static Uint8* pcm_data;
+static size_t pcm_data_size;
+static size_t pcm_sample_bytes;
+static size_t pcm_channel_bytes;
+
+static struct pcm_udata
+{
+    Uint8 *stream;
+    Uint32 num_in;
+    Uint32 num_out;
+#ifdef DEBUG
+    FILE  *debug;
+#endif
+} udata;
+
+static SDL_AudioSpec obtained;
+static SDL_AudioCVT cvt;
+static int audio_locked = 0;
+static SDL_mutex *audio_lock;
+
+void pcm_play_lock(void)
+{
+    if (++audio_locked == 1)
+        SDL_LockMutex(audio_lock);
+}
+
+void pcm_play_unlock(void)
+{
+    if (--audio_locked == 0)
+        SDL_UnlockMutex(audio_lock);
+}
+
+static void pcm_dma_apply_settings_nolock(void)
+{
+    cvt_status = SDL_BuildAudioCVT(&cvt, AUDIO_S16SYS, 2, pcm_sampr,
+                    obtained.format, obtained.channels, obtained.freq);
+
+    if (cvt_status < 0) {
+        cvt.len_ratio = (double)obtained.freq / (double)pcm_sampr;
+    }
+}
+
+void pcm_dma_apply_settings(void)
+{
+    pcm_play_lock();
+    pcm_dma_apply_settings_nolock();
+    pcm_play_unlock();
+}
+
+void pcm_play_dma_start(const void *addr, size_t size)
+{
+    pcm_dma_apply_settings_nolock();
+
+    pcm_data = (Uint8 *) addr;
+    pcm_data_size = size;
+
+    SDL_PauseAudio(0);
+}
+
+void pcm_play_dma_stop(void)
+{
+    SDL_PauseAudio(1);
+#ifdef DEBUG
+    if (udata.debug != NULL) {
+        fclose(udata.debug);
+        udata.debug = NULL;
+        DEBUGF("Audio debug file closed\n");
+    }
+#endif
+}
+
+void pcm_play_dma_pause(bool pause)
+{
+    if (pause)
+        SDL_PauseAudio(1);
+    else
+        SDL_PauseAudio(0);
+}
+
+size_t pcm_get_bytes_waiting(void)
+{
+    return pcm_data_size;
+}
+
+static void write_to_soundcard(struct pcm_udata *udata)
+{
+#ifdef DEBUG
+    if (debug_audio && (udata->debug == NULL)) {
+        udata->debug = fopen("audiodebug.raw", "ab");
+        DEBUGF("Audio debug file open\n");
+    }
+#endif
+    if (cvt.needed) {
+        Uint32 rd = udata->num_in;
+        Uint32 wr = (double)rd * cvt.len_ratio;
+
+        if (wr > udata->num_out) {
+            wr = udata->num_out;
+            rd = (double)wr / cvt.len_ratio;
+
+            if (rd > udata->num_in)
+            {
+                rd = udata->num_in;
+                wr = (double)rd * cvt.len_ratio;
+            }
+        }
+
+        if (wr == 0 || rd == 0)
+        {
+            udata->num_out = udata->num_in = 0;
+            return;
+        }
+
+        if (cvt_status > 0) {
+            cvt.len = rd * pcm_sample_bytes;
+            cvt.buf = (Uint8 *) malloc(cvt.len * cvt.len_mult);
+
+            memcpy(cvt.buf, pcm_data, cvt.len);
+
+            SDL_ConvertAudio(&cvt);
+            SDL_MixAudio(udata->stream, cvt.buf, cvt.len_cvt, SDL_MIX_MAXVOLUME);
+
+            udata->num_in = cvt.len / pcm_sample_bytes;
+            udata->num_out = cvt.len_cvt / pcm_sample_bytes;
+
+#ifdef DEBUG
+            if (udata->debug != NULL) {
+               fwrite(cvt.buf, sizeof(Uint8), cvt.len_cvt, udata->debug);
+            }
+#endif
+            free(cvt.buf);
+        }
+        else {
+            /* Convert is bad, so do silence */
+            Uint32 num = wr*obtained.channels;
+            udata->num_in = rd;
+            udata->num_out = wr;
+
+            switch (pcm_channel_bytes)
+            {
+            case 1:
+            {
+                Uint8 *stream = udata->stream;
+                while (num-- > 0)
+                    *stream++ = obtained.silence;
+                break;
+                }
+            case 2:
+            {
+                Uint16 *stream = (Uint16 *)udata->stream;
+                while (num-- > 0)
+                    *stream++ = obtained.silence;
+                break;
+                }
+            }
+#ifdef DEBUG
+            if (udata->debug != NULL) {
+               fwrite(udata->stream, sizeof(Uint8), wr, udata->debug);
+            }
+#endif
+        }
+    } else {
+        udata->num_in = udata->num_out = MIN(udata->num_in, udata->num_out);
+        SDL_MixAudio(udata->stream, pcm_data, 
+                     udata->num_out * pcm_sample_bytes, SDL_MIX_MAXVOLUME);
+#ifdef DEBUG
+        if (udata->debug != NULL) {
+           fwrite(pcm_data, sizeof(Uint8), udata->num_out * pcm_sample_bytes,
+                  udata->debug);
+        }
+#endif
+    }
+}
+
+static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len)
+{
+    logf("sdl_audio_callback: len %d, pcm %d\n", len, pcm_data_size);
+
+    bool new_buffer = false;
+    udata->stream = stream;
+
+    SDL_LockMutex(audio_lock);
+
+    /* Write what we have in the PCM buffer */
+    if (pcm_data_size > 0)
+        goto start;
+
+    /* Audio card wants more? Get some more then. */
+    while (len > 0) {
+        new_buffer = true;
+        pcm_play_get_more_callback((void **)&pcm_data, &pcm_data_size);
+    start:
+        if (pcm_data_size != 0) {
+            udata->num_in  = pcm_data_size / pcm_sample_bytes;
+            udata->num_out = len / pcm_sample_bytes;
+
+            write_to_soundcard(udata);
+
+            udata->num_in  *= pcm_sample_bytes;
+            udata->num_out *= pcm_sample_bytes;
+
+
+            if (new_buffer)
+            {
+                new_buffer = false;
+                pcm_play_dma_started_callback();
+
+                if ((size_t)len > udata->num_out)
+                {
+                    int delay = pcm_data_size*250 / pcm_sampr - 1;
+                
+                    if (delay > 0)
+                    {
+                        SDL_UnlockMutex(audio_lock);
+                        SDL_Delay(delay);
+                        SDL_LockMutex(audio_lock);
+
+                        if (!pcm_is_playing())
+                            break;
+                    }
+                }
+            }
+
+            pcm_data      += udata->num_in;
+            pcm_data_size -= udata->num_in;
+            udata->stream += udata->num_out;
+            len           -= udata->num_out;
+        } else {
+            DEBUGF("sdl_audio_callback: No Data.\n");
+            break;
+        }
+    }
+
+    SDL_UnlockMutex(audio_lock);
+}
+
+const void * pcm_play_dma_get_peak_buffer(int *count)
+{
+    uintptr_t addr = (uintptr_t)pcm_data;
+    *count = pcm_data_size / 4;
+    return (void *)((addr + 2) & ~3);
+}
+
+#ifdef HAVE_RECORDING
+void pcm_rec_lock(void)
+{
+}
+
+void pcm_rec_unlock(void)
+{
+}
+
+void pcm_rec_dma_init(void)
+{
+}
+
+void pcm_rec_dma_close(void)
+{
+}
+
+void pcm_rec_dma_start(void *start, size_t size)
+{
+    (void)start;
+    (void)size;
+}
+
+void pcm_rec_dma_stop(void)
+{
+}
+
+const void * pcm_rec_dma_get_peak_buffer(void)
+{
+    return NULL;
+}
+
+void audiohw_set_recvol(int left, int right, int type)
+{
+    (void)left;
+    (void)right;
+    (void)type;
+}
+
+#ifdef HAVE_SPDIF_IN
+unsigned long spdif_measure_frequency(void)
+{
+    return 0;
+}
+#endif
+
+#endif /* HAVE_RECORDING */
+
+void pcm_play_dma_init(void)
+{
+    if (SDL_InitSubSystem(SDL_INIT_AUDIO))
+    {
+        DEBUGF("Could not initialize SDL audio subsystem!\n");
+        return;
+    }
+
+    audio_lock = SDL_CreateMutex();
+
+    if (!audio_lock)
+    {
+        panicf("Could not create audio_lock\n");
+        return;
+    }
+
+    SDL_AudioSpec wanted_spec;
+#ifdef DEBUG
+    udata.debug = NULL;
+    if (debug_audio) {
+        udata.debug = fopen("audiodebug.raw", "wb");
+        DEBUGF("Audio debug file open\n");
+    }
+#endif
+    /* Set 16-bit stereo audio at 44Khz */
+    wanted_spec.freq = 44100;
+    wanted_spec.format = AUDIO_S16SYS;
+    wanted_spec.channels = 2;
+    wanted_spec.samples = 2048;
+    wanted_spec.callback =
+        (void (SDLCALL *)(void *userdata,
+            Uint8 *stream, int len))sdl_audio_callback;
+    wanted_spec.userdata = &udata;
+
+    /* Open the audio device and start playing sound! */
+    if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) {
+        DEBUGF("Unable to open audio: %s\n", SDL_GetError());
+        return;
+    }
+
+    switch (obtained.format)
+    {
+    case AUDIO_U8:
+    case AUDIO_S8:
+        pcm_channel_bytes = 1;
+        break;
+    case AUDIO_U16LSB:
+    case AUDIO_S16LSB:
+    case AUDIO_U16MSB:
+    case AUDIO_S16MSB:
+        pcm_channel_bytes = 2;
+        break;
+    default:
+        DEBUGF("Unknown sample format obtained: %u\n",
+                (unsigned)obtained.format);
+        return;
+    }
+
+    pcm_sample_bytes = obtained.channels * pcm_channel_bytes;
+
+    pcm_dma_apply_settings_nolock();
+}
+
+void pcm_play_dma_postinit(void)
+{
+}
+
+#endif /* CONFIG_CODEC == SWCODEC */
Index: firmware/target/hosted/ypr0/system-sdl.h
===================================================================
--- firmware/target/hosted/ypr0/system-sdl.h	(revision 0)
+++ firmware/target/hosted/ypr0/system-sdl.h	(revision 0)
@@ -0,0 +1,60 @@
+/***************************************************************************
+ *             __________               __   ___.                  
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___  
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /  
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <   
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \  
+ *                     \/            \/     \/    \/            \/ 
+ * $Id: system-sdl.h 29516 2011-03-05 15:31:52Z thomasjfox $
+ *
+ * Copyright (C) 2007 by Michael Sevakis
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef _SYSTEM_SDL_H_
+#define _SYSTEM_SDL_H_
+
+#include <stdbool.h>
+#include "config.h"
+#include "gcc_extensions.h"
+
+#define HIGHEST_IRQ_LEVEL 1
+
+int set_irq_level(int level);
+
+#define disable_irq() \
+    ((void)set_irq_level(HIGHEST_IRQ_LEVEL))
+
+#define enable_irq()  \
+    ((void)set_irq_level(0))
+
+#define disable_irq_save() \
+    set_irq_level(HIGHEST_IRQ_LEVEL)
+
+#define restore_irq(level) \
+    ((void)set_irq_level(level))
+
+void sim_enter_irq_handler(void);
+void sim_exit_irq_handler(void);
+void sim_kernel_shutdown(void);
+void sys_poweroff(void);
+void sys_handle_argv(int argc, char *argv[]);
+void gui_message_loop(void);
+void sim_do_exit(void) NORETURN_ATTR;
+#ifndef HAVE_SDL_THREADS
+void wait_for_interrupt(void);
+#endif
+
+extern bool background;  /* True if the background image is enabled */
+extern bool showremote;
+extern int display_zoom;
+extern long start_tick;
+
+#endif /* _SYSTEM_SDL_H_ */
Index: firmware/target/hosted/ypr0/powermgmt-ypr0.c
===================================================================
--- firmware/target/hosted/ypr0/powermgmt-ypr0.c	(revision 0)
+++ firmware/target/hosted/ypr0/powermgmt-ypr0.c	(revision 0)
@@ -0,0 +1,140 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: powermgmt-sim.c 29543 2011-03-08 19:33:30Z thomasjfox $
+ *
+ * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
+ * Revisions copyright (C) 2005 by Gerald Van Baren
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "config.h"
+#include "system.h"
+#include <time.h>
+#include "kernel.h"
+#include "powermgmt.h"
+#include "ascodec-target.h"
+#include "stdio.h"
+
+#if 0 /*still unused*/
+/* The battery manufacturer's website shows discharge curves down to 3.0V,
+   so 'dangerous' and 'shutoff' levels of 3.4V and 3.3V should be safe.
+ */
+const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
+{
+    3550
+};
+
+const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
+{
+    3450
+};
+
+/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
+const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
+{
+    { 3300, 3692, 3740, 3772, 3798, 3828, 3876, 3943, 4013, 4094, 4194 }
+};
+
+#if CONFIG_CHARGING
+/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
+const unsigned short percent_to_volt_charge[11] =
+{
+    3417, 3802, 3856, 3888, 3905, 3931, 3973, 4025, 4084, 4161, 4219
+};
+#endif /* CONFIG_CHARGING */
+#endif
+
+#define BATT_MINMVOLT   3450      /* minimum millivolts of battery */
+#define BATT_MAXMVOLT   4150      /* maximum millivolts of battery */
+#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in
+                                     minutes */
+
+extern void send_battery_level_event(void);
+extern int last_sent_battery_level;
+extern int battery_percent;
+
+static unsigned int battery_millivolts = BATT_MAXMVOLT;
+/* estimated remaining time in minutes */
+static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME;
+
+static void battery_status_update(void)
+{
+    static time_t last_change = 0;
+    //static bool charging = false;
+    time_t now;
+
+    time(&now);
+
+    if (last_change < now) {
+        last_change = now;
+
+        //battery_millivolts = (adc_read(3) * 5125 + 512) >> 10;
+        //printf("BAT: %i", battery_millivolts);
+
+        battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) /
+                            (BATT_MAXMVOLT - BATT_MINMVOLT);
+
+        powermgmt_est_runningtime_min =
+            battery_percent * BATT_MAXRUNTIME / 100;
+    }
+
+    send_battery_level_event();
+}
+
+void battery_read_info(int *voltage, int *level)
+{
+    battery_status_update();
+
+    if (voltage)
+        *voltage = battery_millivolts;
+
+    if (level)
+        *level = battery_percent;
+}
+
+unsigned int battery_voltage(void)
+{
+    battery_status_update();
+    return battery_millivolts;
+}
+
+int battery_level(void)
+{
+    battery_status_update();
+    return battery_percent;
+}
+
+int battery_time(void)
+{
+    battery_status_update();
+    return powermgmt_est_runningtime_min;
+}
+
+bool battery_level_safe(void)
+{
+    return battery_level() >= 10;
+}
+
+void set_battery_capacity(int capacity)
+{
+  (void)capacity;
+}
+
+#if BATTERY_TYPES_COUNT > 1
+void set_battery_type(int type)
+{
+    (void)type;
+}
+#endif
Index: firmware/target/hosted/ypr0/system-ypr0.c
===================================================================
--- firmware/target/hosted/ypr0/system-ypr0.c	(revision 0)
+++ firmware/target/hosted/ypr0/system-ypr0.c	(revision 0)
@@ -0,0 +1,256 @@
+/***************************************************************************
+ *             __________               __   ___.                  
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___  
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /  
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <   
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \  
+ *                     \/            \/     \/    \/            \/ 
+ * $Id: system-sdl.c 29925 2011-05-25 20:11:03Z thomasjfox $
+ *
+ * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <SDL.h>
+#include <SDL_thread.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "system.h"
+#include "thread-sdl.h"
+#include "system-sdl.h"
+
+//#include "lcd-sdl.h"
+#ifdef HAVE_LCD_BITMAP
+#include "lcd-bitmap.h"
+#elif defined(HAVE_LCD_CHARCELLS)
+#include "lcd-charcells.h"
+#endif
+#ifdef HAVE_REMOTE_LCD
+#include "lcd-remote-bitmap.h"
+#endif
+#include "panic.h"
+#include "debug.h"
+
+#include "ascodec-target.h"
+
+SDL_Surface    *gui_surface;
+
+bool            mapping = false;
+bool            debug_buttons = false;
+bool            sim_alarm_wakeup = false;
+const char     *sim_root_dir = NULL;
+
+static SDL_Thread *evt_thread = NULL;
+
+#ifdef DEBUG
+bool debug_audio = false;
+#endif
+
+bool debug_wps = false;
+int wps_verbose_level = 3;
+
+/*
+ * This thread will read the buttons in an interrupt like fashion, and
+ * also initializes SDL_INIT_VIDEO and the surfaces
+ *
+ * it must be done in the same thread (at least on windows) because events only
+ * work in the thread which called SDL_Init(SubSystem) with SDL_INIT_VIDEO
+ *
+ * This is an SDL thread and relies on preemptive behavoir of the host
+ **/
+static int sdl_event_thread(void * param)
+{
+    /* let system_init proceed */
+    SDL_SemPost((SDL_sem *)param);
+
+    /*
+     * finally enter the button loop */
+//    gui_message_loop();
+
+
+    /* Order here is relevent to prevent deadlocks and use of destroyed
+       sync primitives by kernel threads */
+#ifdef HAVE_SDL_THREADS
+    sim_thread_shutdown(); /* not needed for native threads */
+#endif
+    return 0;
+}
+
+void shutdown_hw(void)
+{
+    /* Shut down SDL event loop */
+    SDL_Event event;
+    memset(&event, 0, sizeof(SDL_Event));
+    event.type = SDL_USEREVENT;
+    SDL_PushEvent(&event);
+#ifdef HAVE_SDL_THREADS
+    /* since sim_thread_shutdown() grabs the mutex we need to let it free,
+     * otherwise SDL_WaitThread will deadlock */
+    struct thread_entry* t = sim_thread_unlock();
+#endif
+    /* wait for event thread to finish */
+    SDL_WaitThread(evt_thread, NULL);
+
+#ifdef HAVE_SDL_THREADS
+    /* lock again before entering the scheduler */
+    sim_thread_lock(t);
+    /* sim_thread_shutdown() will cause sim_do_exit() to be called via longjmp,
+     * but only if we let the sdl thread scheduler exit the other threads */
+    while(1) yield();
+#else
+    sim_do_exit();
+#endif
+    
+    /* Something that we need to do before exit on our platform YPR0 */
+    
+    ascodec_close();
+}
+
+void sim_do_exit()
+{
+    sim_kernel_shutdown();
+
+    SDL_Quit();
+    exit(EXIT_SUCCESS);
+}
+
+uintptr_t *stackbegin;
+uintptr_t *stackend;
+void system_init(void)
+{
+    SDL_sem *s;
+    /* fake stack, OS manages size (and growth) */
+    stackbegin = stackend = (uintptr_t*)&s;
+
+    if (SDL_Init(SDL_INIT_TIMER))
+        panicf("%s", SDL_GetError());
+
+    s = SDL_CreateSemaphore(0); /* 0-count so it blocks */
+
+    evt_thread = SDL_CreateThread(sdl_event_thread, s);
+
+    /* wait for sdl_event_thread to run so that it can initialize the surfaces
+     * and video subsystem needed for SDL events */
+    SDL_SemWait(s);
+    /* cleanup */
+    SDL_DestroySemaphore(s);
+    
+    /* Here begins our platform specific initilization for various things */
+    
+    ascodec_init();
+}
+
+
+void system_reboot(void)
+{
+#ifdef HAVE_SDL_THREADS
+    sim_thread_exception_wait();
+#else
+    sim_do_exit();
+#endif
+}
+
+void system_exception_wait(void)
+{
+    system_reboot();
+}
+
+#ifdef HAVE_ADJUSTABLE_CPU_FREQ
+/* This is the Linux Kernel CPU governor... */
+int set_cpu_freq(int speed)
+    {
+        FILE * cpu_dev;
+        cpu_dev = fopen ("/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed","w");
+        if (cpu_dev == NULL)
+            {
+                return 0;
+            }
+        else
+            {
+                char temp[10];
+                sprintf(temp, "%i", speed);
+                fputs (temp, cpu_dev);
+                fclose (cpu_dev);
+                return 1;
+            }
+    }
+
+void set_cpu_frequency(long frequency)
+{
+    switch (frequency)
+    {
+        case CPUFREQ_MAX:
+            set_cpu_freq(532000);
+            cpu_frequency = CPUFREQ_MAX;
+            break;
+        case CPUFREQ_NORMAL:
+            set_cpu_freq(400000);
+            cpu_frequency = CPUFREQ_NORMAL;
+            break;
+        default:
+            set_cpu_freq(200000);
+            cpu_frequency = CPUFREQ_DEFAULT;
+            break;
+    }
+}
+#endif
+
+void sys_handle_argv(int argc, char *argv[])
+{
+    if (argc >= 1) 
+    {
+        int x;
+        for (x = 1; x < argc; x++) 
+        {
+#ifdef DEBUG
+            if (!strcmp("--debugaudio", argv[x])) 
+            {
+                debug_audio = true;
+                printf("Writing debug audio file.\n");
+            }
+            else 
+#endif
+                if (!strcmp("--debugwps", argv[x]))
+            {
+                debug_wps = true;
+                printf("WPS debug mode enabled.\n");
+            }
+            else if (!strcmp("--alarm", argv[x]))
+            {
+                sim_alarm_wakeup = true;
+                printf("Simulating alarm wakeup.\n");
+            }
+            else if (!strcmp("--root", argv[x]))
+            {
+                x++;
+                if (x < argc)
+                {
+                    sim_root_dir = argv[x];
+                    printf("Root directory: %s\n", sim_root_dir);
+                }
+            }
+            else 
+            {
+                printf("rockbox\n");
+                printf("Arguments:\n");
+#ifdef DEBUG
+                printf("  --debugaudio \t Write raw PCM data to audiodebug.raw\n");
+#endif
+                printf("  --debugwps \t Print advanced WPS debug info\n");
+                printf("  --alarm \t Simulate a wake-up on alarm\n");
+                printf("  --root [DIR]\t Set root directory\n");
+                printf("  --mapping \t Output coordinates and radius for mapping backgrounds\n");
+                exit(0);
+            }
+        }
+    }
+}
Index: firmware/target/hosted/ypr0/system-target.h
===================================================================
--- firmware/target/hosted/ypr0/system-target.h	(revision 0)
+++ firmware/target/hosted/ypr0/system-target.h	(revision 0)
@@ -0,0 +1,3 @@
+#include "system-sdl.h"
+
+#define NEED_GENERIC_BYTESWAPS
Index: firmware/target/hosted/ypr0/backlight-ypr0.c
===================================================================
--- firmware/target/hosted/ypr0/backlight-ypr0.c	(revision 0)
+++ firmware/target/hosted/ypr0/backlight-ypr0.c	(revision 0)
@@ -0,0 +1,91 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: backlight-gigabeat-s.c 25800 2010-05-04 10:07:53Z jethead71 $
+ *
+ * Copyright (C) 2011 by Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "config.h"
+#include "system.h"
+#include "backlight.h"
+#include "backlight-target.h"
+#include "lcd.h"
+#include "as3514.h"
+#include "ascodec-target.h"
+#include <fcntl.h>
+#include "unistd.h"
+
+static bool backlight_on_status = true; /* Is on or off? */
+
+bool _backlight_init(void)
+{
+    /* We have nothing to do */
+    return true;
+}
+
+void _backlight_on(void)
+{
+    if (!backlight_on_status)
+    {
+        /* Turn on lcd power before backlight */
+        _backlight_lcd_power();
+        /* Original app sets this to 0xb1 when backlight is on... */
+        ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0xb1);
+    }
+
+    backlight_on_status = true;
+
+}
+
+void _backlight_off(void)
+{
+    if (backlight_on_status) {
+        /* Disabling the DCDC15 completely, keeps brightness register value */
+        ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0x00);
+        /* Turn off lcd power then */
+        _backlight_lcd_sleep();
+    }
+
+    backlight_on_status = false;
+}
+
+void _backlight_set_brightness(int brightness)
+{
+    /* Just another check... */
+    if (brightness > MAX_BRIGHTNESS_SETTING)
+        brightness = MAX_BRIGHTNESS_SETTING;
+    if (brightness < MIN_BRIGHTNESS_SETTING)
+        brightness = MIN_BRIGHTNESS_SETTING;
+    ascodec_write_pmu(AS3543_BACKLIGHT, 0x3, brightness << 3 & 0xf8);
+}
+
+/*TODO: see if LCD sleep could be implemented in a better way -> ie using a rockbox feature */
+//#ifdef HAVE_LCD_SLEEP
+/* Turn off LCD power supply */
+void _backlight_lcd_sleep(void)
+{
+    int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
+    write(fp, "1", 1);
+    close(fp);
+}
+/* Turn on LCD screen */
+void _backlight_lcd_power(void)
+{
+    int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
+    write(fp, "0", 1);
+    close(fp);
+}
+//#endif
\ No newline at end of file
Index: firmware/target/hosted/ypr0/adc-target.h
===================================================================
--- firmware/target/hosted/ypr0/adc-target.h	(revision 0)
+++ firmware/target/hosted/ypr0/adc-target.h	(revision 0)
@@ -0,0 +1,25 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: adc-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
+ *
+ * Copyright (C) 2011 by Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __ADC_TARGET_H__
+#define __ADC_TARGET_H__
+
+#endif /* __ADC_TARGET_H__ */
Index: firmware/target/hosted/ypr0/lcd-bitmap.h
===================================================================
--- firmware/target/hosted/ypr0/lcd-bitmap.h	(revision 0)
+++ firmware/target/hosted/ypr0/lcd-bitmap.h	(revision 0)
@@ -0,0 +1,28 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \ 
+ *                     \/            \/     \/    \/            \/
+ * $Id: lcd-bitmap.h 26065 2010-05-15 21:02:47Z kugel $
+ *
+ * Copyright (C) 2006 Dan Everton
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __LCDBITMAP_H__
+#define __LCDBITMAP_H__
+
+#include "lcd.h"
+
+#endif /* #ifndef __LCDBITMAP_H__ */
+
Index: firmware/target/hosted/ypr0/backlight-target.h
===================================================================
--- firmware/target/hosted/ypr0/backlight-target.h	(revision 0)
+++ firmware/target/hosted/ypr0/backlight-target.h	(revision 0)
@@ -0,0 +1,31 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: backlight-target.h 19322 2008-12-04 04:16:53Z jethead71 $
+ *
+ * Copyright (C) 2011 by Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef BACKLIGHT_TARGET_H
+#define BACKLIGHT_TARGET_H
+
+bool _backlight_init(void);
+void _backlight_on(void);
+void _backlight_off(void);
+void _backlight_set_brightness(int brightness);
+void _backlight_lcd_sleep(void);
+void _backlight_lcd_power(void);
+
+#endif /* BACKLIGHT_TARGET_H */
Index: firmware/target/hosted/ypr0/usb-target.h
===================================================================
--- firmware/target/hosted/ypr0/usb-target.h	(revision 0)
+++ firmware/target/hosted/ypr0/usb-target.h	(revision 0)
@@ -0,0 +1,25 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: usb-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
+ *
+ * Copyright (C) 2010 by Thomas Martitz
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __USB_TARGET_H__
+#define __USB_TARGET_H__
+
+#endif /* __USB_TARGET_H__ */
Index: firmware/target/hosted/ypr0/thread-sdl.c
===================================================================
--- firmware/target/hosted/ypr0/thread-sdl.c	(revision 0)
+++ firmware/target/hosted/ypr0/thread-sdl.c	(revision 0)
@@ -0,0 +1,680 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: thread-sdl.c 29521 2011-03-05 17:48:06Z kugel $
+ *
+ * Copyright (C) 2006 Dan Everton
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <stdbool.h>
+#include <time.h>
+#include <SDL.h>
+#include <SDL_thread.h>
+#include <stdlib.h>
+#include <string.h> /* memset() */
+#include <setjmp.h>
+#include "system-sdl.h"
+#include "thread-sdl.h"
+#include "system.h"
+#include "kernel.h"
+#include "thread.h"
+#include "debug.h"
+
+/* Define this as 1 to show informational messages that are not errors. */
+#define THREAD_SDL_DEBUGF_ENABLED 0
+
+#if THREAD_SDL_DEBUGF_ENABLED
+#define THREAD_SDL_DEBUGF(...) DEBUGF(__VA_ARGS__)
+static char __name[32];
+#define THREAD_SDL_GET_NAME(thread) \
+    ({ thread_get_name(__name, ARRAYLEN(__name), thread); __name; })
+#else
+#define THREAD_SDL_DEBUGF(...)
+#define THREAD_SDL_GET_NAME(thread)
+#endif
+
+#define THREAD_PANICF(str...) \
+    ({ fprintf(stderr, str); exit(-1); })
+
+/* Thread/core entries as in rockbox core */
+static struct core_entry cores[NUM_CORES];
+struct thread_entry threads[MAXTHREADS];
+/* Jump buffers for graceful exit - kernel threads don't stay neatly
+ * in their start routines responding to messages so this is the only
+ * way to get them back in there so they may exit */
+static jmp_buf thread_jmpbufs[MAXTHREADS];
+/* this mutex locks out other Rockbox threads while one runs,
+ * that enables us to simulate a cooperative environment even if
+ * the host is preemptive */
+static SDL_mutex *m;
+#define THREADS_RUN                 0
+#define THREADS_EXIT                1
+#define THREADS_EXIT_COMMAND_DONE   2
+static volatile int threads_status = THREADS_RUN;
+
+extern long start_tick;
+
+void sim_thread_shutdown(void)
+{
+    int i;
+
+    /* This *has* to be a push operation from a thread not in the pool
+       so that they may be dislodged from their blocking calls. */
+
+    /* Tell all threads jump back to their start routines, unlock and exit
+       gracefully - we'll check each one in turn for it's status. Threads
+       _could_ terminate via remove_thread or multiple threads could exit
+       on each unlock but that is safe. */
+
+    /* Do this before trying to acquire lock */
+    threads_status = THREADS_EXIT;
+
+    /* Take control */
+    SDL_LockMutex(m);
+
+    /* Signal all threads on delay or block */
+    for (i = 0; i < MAXTHREADS; i++)
+    {
+        struct thread_entry *thread = &threads[i];
+        if (thread->context.s == NULL)
+            continue;
+        SDL_SemPost(thread->context.s);
+    }
+
+    /* Wait for all threads to finish and cleanup old ones. */
+    for (i = 0; i < MAXTHREADS; i++)
+    {
+        struct thread_entry *thread = &threads[i];
+        SDL_Thread *t = thread->context.t;
+
+        if (t != NULL)
+        {
+            SDL_UnlockMutex(m);
+            /* Wait for it to finish */
+            SDL_WaitThread(t, NULL);
+            /* Relock for next thread signal */
+            SDL_LockMutex(m);
+            /* Already waited and exiting thread would have waited .told,
+             * replacing it with t. */
+            thread->context.told = NULL;
+        }
+        else
+        {
+            /* Wait on any previous thread in this location-- could be one not quite
+             * finished exiting but has just unlocked the mutex. If it's NULL, the
+             * call returns immediately.
+             *
+             * See remove_thread below for more information. */
+            SDL_WaitThread(thread->context.told, NULL);
+        }
+    }
+
+    SDL_UnlockMutex(m);
+
+    /* Signal completion of operation */
+    threads_status = THREADS_EXIT_COMMAND_DONE;
+}
+
+static void new_thread_id(unsigned int slot_num,
+                          struct thread_entry *thread)
+{
+    unsigned int version =
+        (thread->id + (1u << THREAD_ID_VERSION_SHIFT))
+            & THREAD_ID_VERSION_MASK;
+
+    if (version == 0)
+        version = 1u << THREAD_ID_VERSION_SHIFT;
+
+    thread->id = version | (slot_num & THREAD_ID_SLOT_MASK);
+}
+
+static struct thread_entry * find_empty_thread_slot(void)
+{
+    struct thread_entry *thread = NULL;
+    int n;
+
+    for (n = 0; n < MAXTHREADS; n++)
+    {
+        int state = threads[n].state;
+
+        if (state == STATE_KILLED)
+        {
+            thread = &threads[n];
+            break;
+        }
+    }
+
+    return thread;
+}
+
+
+/* Initialize SDL threading */
+void init_threads(void)
+{
+    struct thread_entry *thread;
+    int n;
+
+    memset(cores, 0, sizeof(cores));
+    memset(threads, 0, sizeof(threads));
+
+    m = SDL_CreateMutex();
+
+    if (SDL_LockMutex(m) == -1)
+    {
+        fprintf(stderr, "Couldn't lock mutex\n");
+        return;
+    }
+
+    /* Initialize all IDs */
+    for (n = 0; n < MAXTHREADS; n++)
+        threads[n].id = THREAD_ID_INIT(n);
+
+    /* Slot 0 is reserved for the main thread - initialize it here and
+       then create the SDL thread - it is possible to have a quick, early
+       shutdown try to access the structure. */
+    thread = &threads[0];
+    thread->stack = (uintptr_t *)"       ";
+    thread->stack_size = 8;
+    thread->name = "main";
+    thread->state = STATE_RUNNING;
+    thread->context.s = SDL_CreateSemaphore(0);
+    thread->context.t = NULL; /* NULL for the implicit main thread */
+    cores[CURRENT_CORE].running = thread;
+ 
+    if (thread->context.s == NULL)
+    {
+        fprintf(stderr, "Failed to create main semaphore\n");
+        return;
+    }
+
+    /* Tell all threads jump back to their start routines, unlock and exit
+       gracefully - we'll check each one in turn for it's status. Threads
+       _could_ terminate via remove_thread or multiple threads could exit
+       on each unlock but that is safe. */
+
+    /* Setup jump for exit */
+    if (setjmp(thread_jmpbufs[0]) == 0)
+    {
+        THREAD_SDL_DEBUGF("Main thread: %p\n", thread);
+        return;
+    }
+
+    SDL_UnlockMutex(m);
+
+    /* Set to 'COMMAND_DONE' when other rockbox threads have exited. */
+    while (threads_status < THREADS_EXIT_COMMAND_DONE)
+        SDL_Delay(10);
+
+    SDL_DestroyMutex(m);
+
+    /* We're the main thead - perform exit - doesn't return. */
+    sim_do_exit();
+}
+
+void sim_thread_exception_wait(void)
+{
+    while (1)
+    {
+        SDL_Delay(HZ/10);
+        if (threads_status != THREADS_RUN)
+            thread_exit();
+    }
+}
+
+/* A way to yield and leave the threading system for extended periods */
+void sim_thread_lock(void *me)
+{
+    SDL_LockMutex(m);
+    cores[CURRENT_CORE].running = (struct thread_entry *)me;
+
+    if (threads_status != THREADS_RUN)
+        thread_exit();
+}
+
+void * sim_thread_unlock(void)
+{
+    struct thread_entry *current = cores[CURRENT_CORE].running;
+    SDL_UnlockMutex(m);
+    return current;
+}
+
+struct thread_entry * thread_id_entry(unsigned int thread_id)
+{
+    return &threads[thread_id & THREAD_ID_SLOT_MASK];
+}
+
+static void add_to_list_l(struct thread_entry **list,
+                          struct thread_entry *thread)
+{
+    if (*list == NULL)
+    {
+        /* Insert into unoccupied list */
+        thread->l.next = thread;
+        thread->l.prev = thread;
+        *list = thread;
+    }
+    else
+    {
+        /* Insert last */
+        thread->l.next = *list;
+        thread->l.prev = (*list)->l.prev;
+        thread->l.prev->l.next = thread;
+        (*list)->l.prev = thread;
+    }
+}
+
+static void remove_from_list_l(struct thread_entry **list,
+                               struct thread_entry *thread)
+{
+    if (thread == thread->l.next)
+    {
+        /* The only item */
+        *list = NULL;
+        return;
+    }
+
+    if (thread == *list)
+    {
+        /* List becomes next item */
+        *list = thread->l.next;
+    }
+
+    /* Fix links to jump over the removed entry. */
+    thread->l.prev->l.next = thread->l.next;
+    thread->l.next->l.prev = thread->l.prev;
+}
+
+unsigned int thread_self(void)
+{
+    return cores[CURRENT_CORE].running->id;
+}
+
+struct thread_entry* thread_self_entry(void)
+{
+    return cores[CURRENT_CORE].running;
+}
+
+void switch_thread(void)
+{
+    struct thread_entry *current = cores[CURRENT_CORE].running;
+
+    enable_irq();
+
+    switch (current->state)
+    {
+    case STATE_RUNNING:
+    {
+        SDL_UnlockMutex(m);
+        /* Any other thread waiting already will get it first */
+        SDL_LockMutex(m);
+        break;
+        } /* STATE_RUNNING: */
+
+    case STATE_BLOCKED:
+    {
+        int oldlevel;
+
+        SDL_UnlockMutex(m);
+        SDL_SemWait(current->context.s);
+        SDL_LockMutex(m);
+
+        oldlevel = disable_irq_save();
+        current->state = STATE_RUNNING;
+        restore_irq(oldlevel);
+        break;
+        } /* STATE_BLOCKED: */
+
+    case STATE_BLOCKED_W_TMO:
+    {
+        int result, oldlevel;
+
+        SDL_UnlockMutex(m);
+        result = SDL_SemWaitTimeout(current->context.s, current->tmo_tick);
+        SDL_LockMutex(m);
+
+        oldlevel = disable_irq_save();
+
+        if (current->state == STATE_BLOCKED_W_TMO)
+        {
+            /* Timed out */
+            remove_from_list_l(current->bqp, current);
+
+#ifdef HAVE_WAKEUP_EXT_CB
+            if (current->wakeup_ext_cb != NULL)
+                current->wakeup_ext_cb(current);
+#endif
+            current->state = STATE_RUNNING;
+        }
+
+        if (result == SDL_MUTEX_TIMEDOUT)
+        {
+            /* Other signals from an explicit wake could have been made before
+             * arriving here if we timed out waiting for the semaphore. Make
+             * sure the count is reset. */
+            while (SDL_SemValue(current->context.s) > 0)
+                SDL_SemTryWait(current->context.s);
+        }
+
+        restore_irq(oldlevel);
+        break;
+        } /* STATE_BLOCKED_W_TMO: */
+
+    case STATE_SLEEPING:
+    {
+        SDL_UnlockMutex(m);
+        SDL_SemWaitTimeout(current->context.s, current->tmo_tick);
+        SDL_LockMutex(m);
+        current->state = STATE_RUNNING;
+        break;
+        } /* STATE_SLEEPING: */
+    }
+
+    cores[CURRENT_CORE].running = current;
+
+    if (threads_status != THREADS_RUN)
+        thread_exit();
+}
+
+void sleep_thread(int ticks)
+{
+    struct thread_entry *current = cores[CURRENT_CORE].running;
+    int rem;
+
+    current->state = STATE_SLEEPING;
+
+    rem = (SDL_GetTicks() - start_tick) % (1000/HZ);
+    if (rem < 0)
+        rem = 0;
+
+    current->tmo_tick = (1000/HZ) * ticks + ((1000/HZ)-1) - rem;
+}
+
+void block_thread(struct thread_entry *current)
+{
+    current->state = STATE_BLOCKED;
+    add_to_list_l(current->bqp, current);
+}
+
+void block_thread_w_tmo(struct thread_entry *current, int ticks)
+{
+    current->state = STATE_BLOCKED_W_TMO;
+    current->tmo_tick = (1000/HZ)*ticks;
+    add_to_list_l(current->bqp, current);
+}
+
+unsigned int wakeup_thread(struct thread_entry **list)
+{
+    struct thread_entry *thread = *list;
+
+    if (thread != NULL)
+    {
+        switch (thread->state)
+        {
+        case STATE_BLOCKED:
+        case STATE_BLOCKED_W_TMO:
+            remove_from_list_l(list, thread);
+            thread->state = STATE_RUNNING;
+            SDL_SemPost(thread->context.s);
+            return THREAD_OK;
+        }
+    }
+
+    return THREAD_NONE;
+}
+
+unsigned int thread_queue_wake(struct thread_entry **list)
+{
+    unsigned int result = THREAD_NONE;
+
+    for (;;)
+    {
+        unsigned int rc = wakeup_thread(list);
+
+        if (rc == THREAD_NONE)
+            break;
+
+        result |= rc;        
+    }
+
+    return result;
+}
+
+void thread_thaw(unsigned int thread_id)
+{
+    struct thread_entry *thread = thread_id_entry(thread_id);
+
+    if (thread->id == thread_id && thread->state == STATE_FROZEN)
+    {
+        thread->state = STATE_RUNNING;
+        SDL_SemPost(thread->context.s);
+    }
+}
+
+int runthread(void *data)
+{
+    struct thread_entry *current;
+    jmp_buf *current_jmpbuf;
+
+    /* Cannot access thread variables before locking the mutex as the
+       data structures may not be filled-in yet. */
+    SDL_LockMutex(m);
+    cores[CURRENT_CORE].running = (struct thread_entry *)data;
+    current = cores[CURRENT_CORE].running;
+    current_jmpbuf = &thread_jmpbufs[current - threads];
+
+    /* Setup jump for exit */
+    if (setjmp(*current_jmpbuf) == 0)
+    {
+        /* Run the thread routine */
+        if (current->state == STATE_FROZEN)
+        {
+            SDL_UnlockMutex(m);
+            SDL_SemWait(current->context.s);
+            SDL_LockMutex(m);
+            cores[CURRENT_CORE].running = current;
+        }
+
+        if (threads_status == THREADS_RUN)
+        {
+            current->context.start();
+            THREAD_SDL_DEBUGF("Thread Done: %d (%s)\n",
+                              current - threads, THREAD_SDL_GET_NAME(current));
+            /* Thread routine returned - suicide */
+        }
+
+        thread_exit();
+    }
+    else
+    {
+        /* Unlock and exit */
+        SDL_UnlockMutex(m);
+    }
+
+    return 0;
+}
+
+unsigned int create_thread(void (*function)(void),
+                           void* stack, size_t stack_size,
+                           unsigned flags, const char *name)
+{
+    struct thread_entry *thread;
+    SDL_Thread* t;
+    SDL_sem *s;
+
+    THREAD_SDL_DEBUGF("Creating thread: (%s)\n", name ? name : "");
+
+    thread = find_empty_thread_slot();
+    if (thread == NULL)
+    {
+        DEBUGF("Failed to find thread slot\n");
+        return 0;
+    }
+
+    s = SDL_CreateSemaphore(0);
+    if (s == NULL)
+    {
+        DEBUGF("Failed to create semaphore\n");
+        return 0;
+    }
+
+    t = SDL_CreateThread(runthread, thread);
+    if (t == NULL)
+    {
+        DEBUGF("Failed to create SDL thread\n");
+        SDL_DestroySemaphore(s);
+        return 0;
+    }
+
+    thread->stack = stack;
+    thread->stack_size = stack_size;
+    thread->name = name;
+    thread->state = (flags & CREATE_THREAD_FROZEN) ?
+        STATE_FROZEN : STATE_RUNNING;
+    thread->context.start = function;
+    thread->context.t = t;
+    thread->context.s = s;
+
+    THREAD_SDL_DEBUGF("New Thread: %d (%s)\n",
+                      thread - threads, THREAD_SDL_GET_NAME(thread));
+
+    return thread->id;
+}
+
+#ifndef ALLOW_REMOVE_THREAD
+static void remove_thread(unsigned int thread_id)
+#else
+void remove_thread(unsigned int thread_id)
+#endif
+{
+    struct thread_entry *current = cores[CURRENT_CORE].running;
+    struct thread_entry *thread = thread_id_entry(thread_id);
+
+    SDL_Thread *t;
+    SDL_sem *s;
+
+    if (thread->id != thread_id)
+        return;
+
+    int oldlevel = disable_irq_save();
+
+    t = thread->context.t;
+    s = thread->context.s;
+
+    /* Wait the last thread here and keep this one or SDL will leak it since
+     * it doesn't free its own library allocations unless a wait is performed.
+     * Such behavior guards against the memory being invalid by the time
+     * SDL_WaitThread is reached and also against two different threads having
+     * the same pointer. It also makes SDL_WaitThread a non-concurrent function.
+     *
+     * However, see more below about SDL_KillThread.
+     */
+    SDL_WaitThread(thread->context.told, NULL);
+
+    thread->context.t = NULL;
+    thread->context.s = NULL;
+    thread->context.told = t;
+
+    if (thread != current)
+    {
+        switch (thread->state)
+        {
+        case STATE_BLOCKED:
+        case STATE_BLOCKED_W_TMO:
+            /* Remove thread from object it's waiting on */
+            remove_from_list_l(thread->bqp, thread);
+
+#ifdef HAVE_WAKEUP_EXT_CB
+            if (thread->wakeup_ext_cb != NULL)
+                thread->wakeup_ext_cb(thread);
+#endif
+            break;
+        }
+
+        SDL_SemPost(s);
+    }
+
+    THREAD_SDL_DEBUGF("Removing thread: %d (%s)\n",
+        thread - threads, THREAD_SDL_GET_NAME(thread));
+
+    new_thread_id(thread->id, thread);
+    thread->state = STATE_KILLED;
+    thread_queue_wake(&thread->queue);
+
+    SDL_DestroySemaphore(s);
+
+    if (thread == current)
+    {
+        /* Do a graceful exit - perform the longjmp back into the thread
+           function to return */
+        restore_irq(oldlevel);
+        longjmp(thread_jmpbufs[current - threads], 1);
+    }
+
+    /* SDL_KillThread frees the old pointer too because it uses SDL_WaitThread
+     * to wait for the host to remove it. */
+    thread->context.told = NULL;
+    SDL_KillThread(t);
+    restore_irq(oldlevel);
+}
+
+void thread_exit(void)
+{
+    unsigned int id = thread_self();
+    remove_thread(id);
+    /* This should never and must never be reached - if it is, the
+     * state is corrupted */
+    THREAD_PANICF("thread_exit->K:*R (ID: %d)", id);
+    while (1);
+}
+
+void thread_wait(unsigned int thread_id)
+{
+    struct thread_entry *current = cores[CURRENT_CORE].running;
+    struct thread_entry *thread = thread_id_entry(thread_id);
+
+    if (thread->id == thread_id && thread->state != STATE_KILLED)
+    {
+        current->bqp = &thread->queue;
+        block_thread(current);
+        switch_thread();
+    }
+}
+
+int thread_stack_usage(const struct thread_entry *thread)
+{
+    return 50;
+    (void)thread;
+}
+
+/* Return name if one or ID if none */
+void thread_get_name(char *buffer, int size,
+                     struct thread_entry *thread)
+{
+    if (size <= 0)
+        return;
+
+    *buffer = '\0';
+
+    if (thread)
+    {
+        /* Display thread name if one or ID if none */
+        bool named = thread->name && *thread->name;
+        const char *fmt = named ? "%s" : "%04lX";
+        intptr_t name = named ?
+            (intptr_t)thread->name : (intptr_t)thread->id;
+        snprintf(buffer, size, fmt, name);
+    }
+}
Index: firmware/target/hosted/ypr0/ascodec-ypr0.c
===================================================================
--- firmware/target/hosted/ypr0/ascodec-ypr0.c	(revision 0)
+++ firmware/target/hosted/ypr0/ascodec-ypr0.c	(revision 0)
@@ -0,0 +1,212 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $
+ *
+ * Module wrapper for AS3543 audio codec, using /dev/afe (afe.ko) of Samsung YP-R0
+ *
+ * Copyright (c) 2011 Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "fcntl.h"
+#include "unistd.h"
+#include "stdio.h"
+#include "string.h"
+#include "sys/ioctl.h"
+#include "stdlib.h"
+
+#include "ascodec-target.h"
+
+int afe_dev = -1;
+
+/* Write to a normal register */
+#define IOCTL_REG_WRITE 0x40034101
+/* Write to a PMU register */
+#define IOCTL_SUBREG_WRITE 0x40034103
+/* Read from a normal register */
+#define IOCTL_REG_READ 0x80034102
+/* Read from a PMU register */
+#define IOCTL_SUBREG_READ 0x80034103
+
+static struct mutex as_mtx;
+
+int ascodec_init(void) {
+
+    afe_dev = open("/dev/afe", O_RDWR);
+    
+    mutex_init(&as_mtx);
+    
+    return afe_dev;
+
+}
+
+void ascodec_close(void) {
+
+    if (afe_dev >= 0) {
+        close(afe_dev);
+    }
+
+}
+
+/* Read functions returns -1 if fail, otherwise the register's value if success */
+// That does not hold anymore!!!
+/* Write functions return >= 0 if success, otherwise -1 if fail */
+
+void ascodec_write(unsigned int reg, unsigned int value)
+{
+    int retval = -1;
+    struct codec_req_struct y;
+    struct codec_req_struct *p;
+    p = &y;
+    p->reg = reg;
+    p->value = value;
+    retval = ioctl(afe_dev, IOCTL_REG_WRITE, p);
+//    return retval;
+}
+
+int ascodec_read(unsigned int reg)
+{
+    int retval = -1;
+    struct codec_req_struct y;
+    struct codec_req_struct *p;
+    p = &y;
+    p->reg = reg;
+    retval = ioctl(afe_dev, IOCTL_REG_READ, p);
+    if (retval >= 0)
+        return p->value;
+    else
+        return retval;
+}
+
+void ascodec_write_pmu(unsigned int index, unsigned int subreg,
+                                     unsigned int value)
+{
+    int retval = -1;
+    struct codec_req_struct y;
+    struct codec_req_struct *p;
+    p = &y;
+    p->reg = index;
+    p->subreg = subreg;
+    p->value = value;
+    retval = ioctl(afe_dev, IOCTL_SUBREG_WRITE, p);
+//    return retval;
+}
+
+int ascodec_read_pmu(unsigned int index, unsigned int subreg)
+{
+    int retval = -1;
+    struct codec_req_struct y;
+    struct codec_req_struct *p;
+    p = &y;
+    p->reg = index;
+    p->subreg = subreg;
+    retval = ioctl(afe_dev, IOCTL_SUBREG_READ, p);
+    if (retval >= 0)
+        return p->value;
+    else
+        return retval;
+}
+
+/* Helpers to set/clear bits */
+void ascodec_set(unsigned int reg, unsigned int bits)
+{
+    ascodec_write(reg, ascodec_read(reg) | bits);
+}
+
+void ascodec_clear(unsigned int reg, unsigned int bits)
+{
+    ascodec_write(reg, ascodec_read(reg) & ~bits);
+}
+
+void ascodec_write_masked(unsigned int reg, unsigned int bits,
+                                unsigned int mask)
+{
+    ascodec_write(reg, (ascodec_read(reg) & ~mask) | (bits & mask));
+}
+
+/*FIXME: doesn't work */
+int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data)
+{
+    unsigned int i;
+
+    for (i=index; i<len; i++) {
+        data[i] = ascodec_read(i);
+        printf("Register %i: value=%i\n",index,data[i]);
+    }
+    
+    printf("TOTAL: %i\n", i);
+
+    return i;
+}
+
+/*
+ * NOTE:
+ * After the conversion to interrupts, ascodec_(lock|unlock) are only used by
+ * adc-as3514.c to protect against other threads corrupting the result by using
+ * the ADC at the same time.
+ * 
+ * Concurrent ascodec_(async_)?(read|write) calls are instead protected
+ * by the R0's Kernel I2C driver for ascodec (mutexed), so it's automatically safe
+ */
+
+void ascodec_lock(void)
+{
+    mutex_lock(&as_mtx);
+}
+
+void ascodec_unlock(void)
+{
+    mutex_unlock(&as_mtx);
+}
+
+/* Read 10-bit channel data */
+unsigned short adc_read(int channel)
+{
+    unsigned short data = 0;
+
+    if ((unsigned)channel >= NUM_ADC_CHANNELS)
+        return 0;
+
+    ascodec_lock();
+
+    /* Select channel */
+    ascodec_write(AS3514_ADC_0, (channel << 4));
+    unsigned char buf[2];
+
+        /*
+         * The AS3514 ADC will trigger an interrupt when the conversion
+         * is finished, if the corresponding enable bit in IRQ_ENRD2
+         * is set.
+         * Previously the code did not wait and this apparently did
+         * not pose any problems, but this should be more correct.
+         * Without the wait the data read back may be completely or
+         * partially (first one of the two bytes) stale.
+         */
+    /*FIXME: not implemented*/
+    ascodec_wait_adc_finished();
+
+        /* Read data */
+    ascodec_readbytes(AS3514_ADC_0, 2, buf);
+    data = (((buf[0] & 0x3) << 8) | buf[1]);
+    
+    ascodec_unlock();
+    
+    return data;
+}
+
+void adc_init(void)
+{
+}
\ No newline at end of file
Index: firmware/target/hosted/ypr0/ascodec-target.h
===================================================================
--- firmware/target/hosted/ypr0/ascodec-target.h	(revision 0)
+++ firmware/target/hosted/ypr0/ascodec-target.h	(revision 0)
@@ -0,0 +1,92 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $
+ *
+ * Module wrapper for AS3543 audio codec, using /dev/afe (afe.ko) of Samsung YP-R0
+ *
+ * Copyright (c) 2011 Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef _ASCODEC_TARGET_H
+#define _ASCODEC_TARGET_H
+
+#include "as3514.h"
+#include "kernel.h"
+#include "adc.h"
+#include "ascodec.h"
+
+/* ioctl parameter struct */
+
+struct codec_req_struct {
+/* This works for every kind of afe.ko module requests */
+            unsigned char reg; /* Main register address */
+            unsigned char subreg; /* Set this only if you are reading/writing a PMU register*/
+            unsigned char value; /* To be read if reading a register; to be set if writing to a register */
+};
+
+int ascodec_init(void);
+void ascodec_close(void);
+void ascodec_write(unsigned int reg, unsigned int value);
+int ascodec_read(unsigned int reg);
+void ascodec_write_pmu(unsigned int index, unsigned int subreg, unsigned int value);
+int ascodec_read_pmu(unsigned int index, unsigned int subreg);
+void ascodec_set(unsigned int reg, unsigned int bits);
+void ascodec_clear(unsigned int reg, unsigned int bits);
+void ascodec_write_masked(unsigned int reg, unsigned int bits, unsigned int mask);
+int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data);
+unsigned short adc_read(int channel);
+void ascodec_lock(void);
+void ascodec_unlock(void);
+
+static inline bool ascodec_chg_status(void)
+{
+    return ascodec_read(AS3514_IRQ_ENRD0) & CHG_STATUS;
+}
+
+static inline bool ascodec_endofch(void)
+{
+    return ascodec_read(AS3514_IRQ_ENRD0) & CHG_ENDOFCH;
+}
+
+static inline void ascodec_monitor_endofch(void)
+{
+    ascodec_write(AS3514_IRQ_ENRD0, IRQ_ENDOFCH);
+}
+
+static inline void ascodec_wait_adc_finished(void)
+{
+    /*
+     * FIXME: not implemented
+     *
+     * If irqs are not available on the target platform,
+     * this should be most likely implemented by polling
+     * AS3514_IRQ_ENRD2 in the same way powermgmt-ascodec.c
+     * is polling IRQ_ENDOFCH.
+     */
+}
+
+static inline void ascodec_write_charger(int value)
+{
+    ascodec_write_pmu(AS3543_CHARGER, 1, value);
+}
+
+static inline int ascodec_read_charger(void)
+{
+    return ascodec_read_pmu(AS3543_CHARGER, 1);
+}
+
+#endif /* !_ASCODEC_TARGET_H */
Index: firmware/target/hosted/ypr0/lcd-ypr0.c
===================================================================
--- firmware/target/hosted/ypr0/lcd-ypr0.c	(revision 0)
+++ firmware/target/hosted/ypr0/lcd-ypr0.c	(revision 0)
@@ -0,0 +1,342 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: lcd-bitmap.c 29248 2011-02-08 20:05:25Z thomasjfox $
+ *
+ * Copyright (C) 2006 Dan Everton
+ * Copyright (C) 2011 Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "string.h"
+#include <fcntl.h>
+#include <linux/fb.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+
+#include "debug.h"
+#include "system.h"
+#include "screendump.h"
+#include "lcd.h"
+
+int fbfd = 0;
+struct fb_var_screeninfo vinfo;
+struct fb_fix_screeninfo finfo;
+long int screensize = 0;
+char *fbp = 0;
+
+void lcd_update(void)
+{
+    /* update a full screen rect */
+    lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
+}
+
+void lcd_update_rect(int x_start, int y_start, int width, int height)
+{
+    int pixels = width * height;
+    fb_data* p = &lcd_framebuffer[y_start][x_start];
+    /* We move it to the starting point */
+    char* out = &fbp[(x_start+(y_start*LCD_WIDTH))*2];
+    
+    //if (x + width >= LCD_WIDTH)
+    //    width = LCD_WIDTH - x;
+    //if (y + height >= LCD_HEIGHT)
+    //    height = LCD_HEIGHT - y;
+    
+    //memcpy(out, p, pixels * 2);
+
+    /* Copy display bitmap to framebuffer device */
+    if (LCD_WIDTH == width) {
+        /* Write all lines at once */
+        memcpy(out, p, pixels * 2);
+    } else {
+//        out += (x_start)+(y_start*LCD_HEIGHT);
+/*FIXME: this in reality doesn't do what is supposed to do. It just refresh only some lines (so the whole width of a line) */
+/* We need to implement it correctly. Also refresh one single pixel must work to avoid graphical glitches */
+       memcpy(out, p, (height*LCD_WIDTH)*2);
+       /*
+        do {
+            out += (x_start)*2;
+            memcpy(out, p, (width)*2);
+            out += (LCD_WIDTH - (width + x_start))*2;
+            p += (LCD_WIDTH - (width + x_start))*2;
+       */
+           /* Write a single line */
+        //    memcpy(out, p, width * 2);
+        //    p += LCD_WIDTH;
+        //    out += LCD_WIDTH;
+        //} while (--height);
+    }
+}
+
+void lcd_shutdown(void)
+{
+    printf("FB closed.");
+    munmap(fbp, screensize);
+    close(fbfd);
+}
+
+void lcd_init_device(void)
+{
+    /* Open the framebuffer device */
+    fbfd = open("/dev/fb0", O_RDWR);
+    if (fbfd == -1) {
+        perror("Error: cannot open framebuffer device");
+        exit(1);
+    }
+    printf("The framebuffer device was opened successfully.\n");
+
+    /* Get the fixed properties */
+    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
+        perror("Error reading fixed information");
+        exit(2);
+    }
+
+    /* Now we get the settable settings, and we set 16 bit bpp */
+    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
+        perror("Error reading variable information");
+        exit(3);
+    }
+    
+    vinfo.bits_per_pixel = 16;
+    
+    if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &vinfo)) {
+            perror("fbset(ioctl)");
+            exit(4);
+    }
+
+    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
+
+    // Figure out the size of the screen in bytes
+    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
+
+    // Map the device to memory
+    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
+    if ((int)fbp == -1) {
+        perror("Error: failed to map framebuffer device to memory");
+        exit(4);
+    }
+    printf("The framebuffer device was mapped to memory successfully.\n");
+}
+
+
+
+#ifdef HAVE_LCD_COLOR
+/**
+ * |R|   |1.000000 -0.000001  1.402000| |Y'|
+ * |G| = |1.000000 -0.334136 -0.714136| |Pb|
+ * |B|   |1.000000  1.772000  0.000000| |Pr|
+ * Scaled, normalized, rounded and tweaked to yield RGB 565:
+ * |R|   |74   0 101| |Y' -  16| >> 9
+ * |G| = |74 -24 -51| |Cb - 128| >> 8
+ * |B|   |74 128   0| |Cr - 128| >> 9
+ */
+#define YFAC    (74)
+#define RVFAC   (101)
+#define GUFAC   (-24)
+#define GVFAC   (-51)
+#define BUFAC   (128)
+
+static inline int clamp(int val, int min, int max)
+{
+    if (val < min)
+        val = min;
+    else if (val > max)
+        val = max;
+    return val;
+}
+
+void lcd_yuv_set_options(unsigned options)
+{
+    (void)options;
+}
+
+/* Draw a partial YUV colour bitmap - similiar behavior to lcd_blit_yuv
+   in the core */
+void lcd_blit_yuv(unsigned char * const src[3],
+                  int src_x, int src_y, int stride,
+                  int x, int y, int width, int height)
+{
+    const unsigned char *ysrc, *usrc, *vsrc;
+    int linecounter;
+    fb_data *dst, *row_end;
+    long z;
+
+    /* width and height must be >= 2 and an even number */
+    width &= ~1;
+    linecounter = height >> 1;
+
+#if LCD_WIDTH >= LCD_HEIGHT
+    dst     = &lcd_framebuffer[y][x];
+    row_end = dst + width;
+#else
+    dst     = &lcd_framebuffer[x][LCD_WIDTH - y - 1];
+    row_end = dst + LCD_WIDTH * width;
+#endif
+
+    z    = stride * src_y;
+    ysrc = src[0] + z + src_x;
+    usrc = src[1] + (z >> 2) + (src_x >> 1);
+    vsrc = src[2] + (usrc - src[1]);
+
+    /* stride => amount to jump from end of last row to start of next */
+    stride -= width;
+
+    /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
+
+    do
+    {
+        do
+        {
+            int y, cb, cr, rv, guv, bu, r, g, b;
+
+            y  = YFAC*(*ysrc++ - 16);
+            cb = *usrc++ - 128;
+            cr = *vsrc++ - 128;
+
+            rv  =            RVFAC*cr;
+            guv = GUFAC*cb + GVFAC*cr;
+            bu  = BUFAC*cb;
+
+            r = y + rv;
+            g = y + guv;
+            b = y + bu;
+
+            if ((unsigned)(r | g | b) > 64*256-1)
+            {
+                r = clamp(r, 0, 64*256-1);
+                g = clamp(g, 0, 64*256-1);
+                b = clamp(b, 0, 64*256-1);
+            }
+
+            *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
+
+#if LCD_WIDTH >= LCD_HEIGHT
+            dst++;
+#else
+            dst += LCD_WIDTH;
+#endif
+
+            y = YFAC*(*ysrc++ - 16);
+            r = y + rv;
+            g = y + guv;
+            b = y + bu;
+
+            if ((unsigned)(r | g | b) > 64*256-1)
+            {
+                r = clamp(r, 0, 64*256-1);
+                g = clamp(g, 0, 64*256-1);
+                b = clamp(b, 0, 64*256-1);
+            }
+
+            *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
+
+#if LCD_WIDTH >= LCD_HEIGHT
+            dst++;
+#else
+            dst += LCD_WIDTH;
+#endif
+        }
+        while (dst < row_end);
+
+        ysrc    += stride;
+        usrc    -= width >> 1;
+        vsrc    -= width >> 1;
+
+#if LCD_WIDTH >= LCD_HEIGHT
+        row_end += LCD_WIDTH;
+        dst     += LCD_WIDTH - width;
+#else
+        row_end -= 1;
+        dst     -= LCD_WIDTH*width + 1;
+#endif
+
+        do
+        {
+            int y, cb, cr, rv, guv, bu, r, g, b;
+
+            y  = YFAC*(*ysrc++ - 16);
+            cb = *usrc++ - 128;
+            cr = *vsrc++ - 128;
+
+            rv  =            RVFAC*cr;
+            guv = GUFAC*cb + GVFAC*cr;
+            bu  = BUFAC*cb;
+
+            r = y + rv;
+            g = y + guv;
+            b = y + bu;
+
+            if ((unsigned)(r | g | b) > 64*256-1)
+            {
+                r = clamp(r, 0, 64*256-1);
+                g = clamp(g, 0, 64*256-1);
+                b = clamp(b, 0, 64*256-1);
+            }
+
+            *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
+
+#if LCD_WIDTH >= LCD_HEIGHT
+            dst++;
+#else
+            dst += LCD_WIDTH;
+#endif
+
+            y = YFAC*(*ysrc++ - 16);
+            r = y + rv;
+            g = y + guv;
+            b = y + bu;
+
+            if ((unsigned)(r | g | b) > 64*256-1)
+            {
+                r = clamp(r, 0, 64*256-1);
+                g = clamp(g, 0, 64*256-1);
+                b = clamp(b, 0, 64*256-1);
+            }
+
+            *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
+
+#if LCD_WIDTH >= LCD_HEIGHT
+            dst++;
+#else
+            dst += LCD_WIDTH;
+#endif
+        }
+        while (dst < row_end);
+
+        ysrc    += stride;
+        usrc    += stride >> 1;
+        vsrc    += stride >> 1;
+
+#if LCD_WIDTH >= LCD_HEIGHT
+        row_end += LCD_WIDTH;
+        dst     += LCD_WIDTH - width;
+#else
+        row_end -= 1;
+        dst     -= LCD_WIDTH*width + 1;
+#endif
+    }
+    while (--linecounter > 0);
+
+#if LCD_WIDTH >= LCD_HEIGHT
+    lcd_update_rect(x, y, width, height);
+#else
+    lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
+#endif
+}
+#endif /* HAVE_LCD_COLOR */
Index: firmware/target/hosted/ypr0/thread-sdl.h
===================================================================
--- firmware/target/hosted/ypr0/thread-sdl.h	(revision 0)
+++ firmware/target/hosted/ypr0/thread-sdl.h	(revision 0)
@@ -0,0 +1,34 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: thread-sdl.h 29327 2011-02-18 22:46:01Z kugel $
+ *
+ * Copyright (C) 2006 Dan Everton
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __THREADSDL_H__
+#define __THREADSDL_H__
+
+#ifdef HAVE_SDL_THREADS
+/* extra thread functions that only apply when running on hosting platforms */
+void sim_thread_lock(void *me);
+void * sim_thread_unlock(void);
+void sim_thread_exception_wait(void);
+void sim_thread_shutdown(void); /* Shut down all kernel threads gracefully */
+#endif
+
+#endif /* #ifndef __THREADSDL_H__ */
+
Index: firmware/common/rbpaths.c
===================================================================
--- firmware/common/rbpaths.c	(revision 31001)
+++ firmware/common/rbpaths.c	(working copy)
@@ -71,6 +71,9 @@
 #if (CONFIG_PLATFORM & PLATFORM_ANDROID)
     mkdir("/sdcard/rockbox");
     mkdir("/sdcard/rockbox/rocks.data");
+#elif (CONFIG_PLATFORM & PLATFORM_YPR0)
+    /* We don't need to create some special folders on R0 */
+    return;
 #else
     char config_dir[MAX_PATH];
 
@@ -91,6 +94,7 @@
 #endif
 }
 
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
 static bool try_path(const char* filename, unsigned flags)
 {
     if (flags & IS_FILE)
@@ -105,7 +109,9 @@
     }
     return false;
 }
+#endif /* !(CONFIG_PLATFORM & PLATFORM_YPR0) */
 
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
 static const char* _get_user_file_path(const char *path,
                                        unsigned flags,
                                        char* buf,
@@ -143,13 +149,14 @@
 
     return ret;
 }
+#endif /* !(CONFIG_PLATFORM & PLATFORM_YPR0) */
 
 int app_open(const char *name, int o, ...)
 {
-    char realpath[MAX_PATH];
     va_list ap;
     int fd;
-    
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
+    char realpath[MAX_PATH];
     if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
     {
         int flags = IS_FILE;
@@ -157,6 +164,7 @@
             flags |= NEED_WRITE;
         name = _get_user_file_path(name, flags, realpath, sizeof(realpath));
     }
+#endif
     va_start(ap, o);
     fd = open(name, o, va_arg(ap, unsigned int));
     va_end(ap);
@@ -171,64 +179,73 @@
 
 int app_remove(const char *name)
 {
+    const char *fname = name;
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
     char realpath[MAX_PATH];
-    const char *fname = name;
     if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
     {
         fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath));
     }
-
+#endif
     return remove(fname);
 }
 
 int app_rename(const char *old, const char *new)
 {
-    char realpath_old[MAX_PATH], realpath_new[MAX_PATH];
-
     const char *final_old = old;
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
+    char realpath_old[MAX_PATH];
     if (!strncmp(ROCKBOX_DIR, old, ROCKBOX_DIR_LEN))
     {
         final_old = _get_user_file_path(old, NEED_WRITE, realpath_old, sizeof(realpath_old));
     }
-
+#endif
     const char *final_new = new;
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
+    char realpath_new[MAX_PATH];
     if (!strncmp(ROCKBOX_DIR, new, ROCKBOX_DIR_LEN))
     {
         final_new = _get_user_file_path(new, NEED_WRITE, realpath_new, sizeof(realpath_new));
     }
-
+#endif
     return rename(final_old, final_new);
 }
 
 DIR *app_opendir(const char *name)
 {
+    const char *fname = name;
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
     char realpath[MAX_PATH];
-    const char *fname = name;
     if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
     {
         fname = _get_user_file_path(name, 0, realpath, sizeof(realpath));
     }
+#endif
     return opendir(fname);
 }
 
 int app_mkdir(const char* name)
 {
+    const char *fname = name;
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
     char realpath[MAX_PATH];
-    const char *fname = name;
     if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
     {
         fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath));
     }
+#endif
     return mkdir(fname);
 }
 
 int app_rmdir(const char* name)
 {
+    const char *fname = name;
+#if !(CONFIG_PLATFORM & PLATFORM_YPR0)
     char realpath[MAX_PATH];
-    const char *fname = name;
     if (!strncmp(ROCKBOX_DIR, name, ROCKBOX_DIR_LEN))
     {
         fname = _get_user_file_path(name, NEED_WRITE, realpath, sizeof(realpath));
     }
+#endif
     return rmdir(fname);
-}
+}
\ No newline at end of file
Index: firmware/powermgmt.c
===================================================================
--- firmware/powermgmt.c	(revision 31001)
+++ firmware/powermgmt.c	(working copy)
@@ -510,6 +510,7 @@
      * the disk is spinning unless we are in USB mode (the disk will most
      * likely always be spinning in USB mode) or charging.
      */
+
     if (!storage_disk_is_active() || usb_inserted()
 #if CONFIG_CHARGING >= CHARGING_MONITOR
             || charger_input_state == CHARGER
@@ -665,7 +666,6 @@
 #ifdef HAVE_STORAGE_FLUSH
         storage_flush();
 #endif
-
         if (storage_disk_is_active())
             storage_spindown(1);
     }
@@ -680,7 +680,7 @@
        shutdown_timeout in power_thread_step will force a power off */
     while (storage_disk_is_active())
         sleep(HZ/10);
-
+    
 #ifndef HAVE_LCD_COLOR
     lcd_set_contrast(0);
 #endif
Index: firmware/drivers/rtc/rtc_as3514.c
===================================================================
--- firmware/drivers/rtc/rtc_as3514.c	(revision 31001)
+++ firmware/drivers/rtc/rtc_as3514.c	(working copy)
@@ -141,11 +141,11 @@
         seconds = 24*3600;
 
     seconds -= tm.tm_sec;
-
+#ifndef SAMSUNG_YPR0
     /* disable MCLK, it is a wakeup source and prevents proper shutdown */
     CGU_AUDIO = (2 << 0) | (1 << 11);
     CGU_PLLBSUP = (1 << 2) | (1 << 3);
-
+#endif
     /* write wakeup register */
     alarm.seconds = seconds;
     alarm.enabled = true;
Index: firmware/drivers/audio/as3514.c
===================================================================
--- firmware/drivers/audio/as3514.c	(revision 31001)
+++ firmware/drivers/audio/as3514.c	(working copy)
@@ -78,6 +78,7 @@
 #endif
 };
 
+#ifndef SAMSUNG_YPR0
 /* Shadow registers */
 static uint8_t as3514_regs[AS3514_NUM_AUDIO_REGS]; /* 8-bit registers */
 
@@ -110,7 +111,29 @@
 {
     as3514_write(reg, (as3514_regs[reg] & ~mask) | (bits & mask));
 }
+#else
+static void as3514_write(unsigned int reg, unsigned int value)
+{
+    ascodec_write(reg, value);
+}
 
+/* Helpers to set/clear bits */
+static void as3514_set(unsigned int reg, unsigned int bits)
+{
+    ascodec_write(reg, ascodec_read(reg) | bits);
+}
+
+static void as3514_clear(unsigned int reg, unsigned int bits)
+{
+    ascodec_write(reg, ascodec_read(reg) & ~bits);
+}
+
+static void as3514_write_masked(unsigned int reg, unsigned int bits,
+                                unsigned int mask)
+{
+    ascodec_write(reg, (ascodec_read(reg) & ~mask) | (bits & mask));
+}
+#endif
 /* convert tenth of dB volume to master volume register value */
 int tenthdb2master(int db)
 {
@@ -145,8 +168,11 @@
  */
 void audiohw_preinit(void)
 {
+
+#ifndef SAMSUNG_YPR0
     /* read all reg values */
     ascodec_readbytes(0x0, AS3514_NUM_AUDIO_REGS, as3514_regs);
+#endif
 
 #ifdef HAVE_AS3543
 
@@ -284,9 +310,14 @@
 #if CONFIG_CPU == AS3525v2 
 #define MIXER_MAX_VOLUME 0x1b
 #else /* lets leave the AS3514 alone until its better tested*/
+#ifdef SAMSUNG_YPR0
+#define MIXER_MAX_VOLUME 0x1a
+#else
 #define MIXER_MAX_VOLUME 0x16
 #endif
+#endif
 
+#ifndef SAMSUNG_YPR0
     if (vol_r <= MIXER_MAX_VOLUME) {
         mix_r = vol_r;
         hph_r = 0;
@@ -302,7 +333,16 @@
         mix_l = MIXER_MAX_VOLUME;
         hph_l = vol_l - MIXER_MAX_VOLUME;
     }    
+#else
+/* Okay. This is shit coded indeed. It is just a test.
+    Some considerations: Samsung keeps DAC constantly to 0x1a volume. It modifies only the headphone amp volume
+*/
 
+    mix_r = 0x1a;
+    mix_l = 0x1a;
+    hph_l = vol_l;
+    hph_r = vol_r;
+#endif
 
     as3514_write_masked(AS3514_DAC_R, mix_r, AS3514_VOL_MASK);
     as3514_write_masked(AS3514_DAC_L, mix_l, AS3514_VOL_MASK);
Index: uisimulator/common/SOURCES
===================================================================
--- uisimulator/common/SOURCES	(revision 31001)
+++ uisimulator/common/SOURCES	(working copy)
@@ -12,7 +12,9 @@
 io.c
 sim_tasks.c
 /* this is still needed for application since it has some stubs */
-#if !(CONFIG_PLATFORM & PLATFORM_MAEMO)
+#if !(CONFIG_PLATFORM & PLATFORM_MAEMO) && !(SAMSUNG_YPR0)
 powermgmt-sim.c
 #endif
+#ifndef SAMSUNG_YPR0
 stubs.c
+#endif
\ No newline at end of file
