- Move uisimulator/sdl/*.[ch] into the target tree, under firmware/target/hosted/sdl, uisdl.c is split up across button-sdl.c and system-sdl.c.

- Refactor the program startup. main() is now in main.c like on target, and the implicit application thread will now act as our main thread (previously a separate one was created for this in thread initialization).

This is part of Rockbox as an application and is the first step to make an application port from the uisimulator. In a further step the sim bits from the sdl build will be separated out.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26065 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2010-05-15 21:02:47 +00:00
parent dcf442e61f
commit 3d0cee8abb
38 changed files with 508 additions and 626 deletions

View file

@ -124,8 +124,14 @@ const char appsversion[]=APPSVERSION;
static void init(void); static void init(void);
#ifdef SIMULATOR #ifdef HAVE_SDL
void app_main(void) #if defined(WIN32) && defined(main)
/* Don't use SDL_main on windows -> no more stdio redirection */
#undef main
#endif
int main(int argc, char *argv[])
{
sys_handle_argv(argc, argv);
#else #else
/* main(), and various functions called by main() and init() may be /* main(), and various functions called by main() and init() may be
* be INIT_ATTR. These functions must not be called after the final call * be INIT_ATTR. These functions must not be called after the final call
@ -133,8 +139,8 @@ void app_main(void)
* see definition of INIT_ATTR in config.h */ * see definition of INIT_ATTR in config.h */
int main(void) INIT_ATTR __attribute__((noreturn)); int main(void) INIT_ATTR __attribute__((noreturn));
int main(void) int main(void)
#endif
{ {
#endif
int i; int i;
CHART(">init"); CHART(">init");
init(); init();
@ -313,6 +319,7 @@ static void init_tagcache(void)
static void init(void) static void init(void)
{ {
system_init();
kernel_init(); kernel_init();
buffer_init(); buffer_init();
enable_irq(); enable_irq();

View file

@ -18,6 +18,22 @@ rolo.c
thread.c thread.c
timer.c timer.c
#endif /* SIMULATOR */ #endif /* SIMULATOR */
#ifdef HAVE_SDL
target/hosted/sdl/button-sdl.c
target/hosted/sdl/kernel-sdl.c
#ifdef HAVE_LCD_BITMAP
target/hosted/sdl/lcd-bitmap.c
#elif defined(HAVE_LCD_CHARCELLS)
target/hosted/sdl/lcd-charcells.c
#endif
#ifdef HAVE_REMOTE_LCD
target/hosted/sdl/lcd-remote-bitmap.c
#endif
target/hosted/sdl/lcd-sdl.c
target/hosted/sdl/system-sdl.c
target/hosted/sdl/thread-sdl.c
target/hosted/sdl/timer-sdl.c
#endif
panic.c panic.c
debug.c debug.c
@ -292,6 +308,11 @@ drivers/audio/ak4537.c
#elif defined(HAVE_UDA1341) #elif defined(HAVE_UDA1341)
drivers/audio/uda1341.c drivers/audio/uda1341.c
#endif /* defined(HAVE_*) */ #endif /* defined(HAVE_*) */
#elif defined(HAVE_SDL_AUDIO)
drivers/audio/sdl.c
#if CONFIG_CODEC == SWCODEC
target/hosted/sdl/pcm-sdl.c
#endif
#endif /* !defined(SIMULATOR) && !defined(BOOTLOADER) */ #endif /* !defined(SIMULATOR) && !defined(BOOTLOADER) */
/* USB Stack */ /* USB Stack */

View file

@ -0,0 +1,186 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright © 2010 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 <SDL_audio.h>
#include "config.h"
#include "audiohw.h"
/**
* Audio Hardware api. Make them do nothing as we cannot properly simulate with
* SDL. if we used DSP we would run code that doesn't actually run on the target
**/
extern void pcm_set_mixer_volume(int);
void audiohw_set_volume(int volume)
{
#if CONFIG_CODEC == SWCODEC
pcm_set_mixer_volume(
SDL_MIX_MAXVOLUME * ((volume - VOLUME_MIN) / 10) / (VOLUME_RANGE / 10));
#else
(void)volume;
#endif
}
const struct sound_settings_info audiohw_settings[] = {
[SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25},
/* Bass and treble tone controls */
#ifdef AUDIOHW_HAVE_BASS
[SOUND_BASS] = {"dB", 0, 1, -24, 24, 0},
#endif
#ifdef AUDIOHW_HAVE_TREBLE
[SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0},
#endif
[SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
[SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
[SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
#if defined(HAVE_RECORDING)
[SOUND_LEFT_GAIN] = {"dB", 1, 1,-128, 96, 0},
[SOUND_RIGHT_GAIN] = {"dB", 1, 1,-128, 96, 0},
[SOUND_MIC_GAIN] = {"dB", 1, 1,-128, 108, 16},
#endif
#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
[SOUND_BASS_CUTOFF] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
[SOUND_TREBLE_CUTOFF] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_DEPTH_3D)
[SOUND_DEPTH_3D] = {"%", 0, 1, 0, 15, 0},
#endif
/* Hardware EQ tone controls */
#if defined(AUDIOHW_HAVE_EQ_BAND1)
[SOUND_EQ_BAND1_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND2)
[SOUND_EQ_BAND2_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND3)
[SOUND_EQ_BAND3_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND4)
[SOUND_EQ_BAND4_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND5)
[SOUND_EQ_BAND5_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
[SOUND_EQ_BAND1_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
[SOUND_EQ_BAND2_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
[SOUND_EQ_BAND3_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
[SOUND_EQ_BAND4_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
[SOUND_EQ_BAND5_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
[SOUND_EQ_BAND2_WIDTH] = {"", 0, 1, 0, 1, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
[SOUND_EQ_BAND3_WIDTH] = {"", 0, 1, 0, 1, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
[SOUND_EQ_BAND4_WIDTH] = {"", 0, 1, 0, 1, 0},
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
[SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0},
[SOUND_AVC] = {"", 0, 1, -1, 4, 0},
[SOUND_MDB_STRENGTH] = {"dB", 0, 1, 0, 127, 48},
[SOUND_MDB_HARMONICS] = {"%", 0, 1, 0, 100, 50},
[SOUND_MDB_CENTER] = {"Hz", 0, 10, 20, 300, 60},
[SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90},
[SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0},
[SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0},
#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
};
/**
* stubs here, for the simulator
**/
#if defined(AUDIOHW_HAVE_PRESCALER)
void audiohw_set_prescaler(int value) { (void)value; }
#endif
#if defined(AUDIOHW_HAVE_BALANCE)
void audiohw_set_balance(int value) { (void)value; }
#endif
#if defined(AUDIOHW_HAVE_BASS)
void audiohw_set_bass(int value) { (void)value; }
#endif
#if defined(AUDIOHW_HAVE_TREBLE)
void audiohw_set_treble(int value) { (void)value; }
#endif
#if CONFIG_CODEC != SWCODEC
void audiohw_set_channel(int value) { (void)value; }
void audiohw_set_stereo_width(int value){ (void)value; }
#endif
#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
void audiohw_set_bass_cutoff(int value) { (void)value; }
#endif
#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
void audiohw_set_treble_cutoff(int value){ (void)value; }
#endif
/* EQ-based tone controls */
#if defined(AUDIOHW_HAVE_EQ)
void audiohw_set_eq_band_gain(unsigned int band, int value)
{ (void)band; (void)value; }
#endif
#if defined(AUDIOHW_HAVE_EQ_FREQUENCY)
void audiohw_set_eq_band_frequency(unsigned int band, int value)
{ (void)band; (void)value; }
#endif
#if defined(AUDIOHW_HAVE_EQ_WIDTH)
void audiohw_set_eq_band_width(unsigned int band, int value)
{ (void)band; (void)value; }
#endif
#if defined(AUDIOHW_HAVE_DEPTH_3D)
void audiohw_set_depth_3d(int value)
{ (void)value; }
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
int mas_codec_readreg(int reg)
{
(void)reg;
return 0;
}
int mas_codec_writereg(int reg, unsigned int val)
{
(void)reg;
(void)val;
return 0;
}
int mas_writemem(int bank, int addr, const unsigned long* src, int len)
{
(void)bank;
(void)addr;
(void)src;
(void)len;
return 0;
}
#endif

View file

@ -429,7 +429,6 @@ void button_init(void)
tick_add_task(button_tick); tick_add_task(button_tick);
} }
#ifndef SIMULATOR
#ifdef BUTTON_DRIVER_CLOSE #ifdef BUTTON_DRIVER_CLOSE
void button_close(void) void button_close(void)
{ {
@ -443,9 +442,10 @@ void button_close(void)
*/ */
static int button_flip(int button) static int button_flip(int button)
{ {
int newbutton; int newbutton = button;
newbutton = button & #ifndef SIMULATOR
newbutton &=
~(BUTTON_LEFT | BUTTON_RIGHT ~(BUTTON_LEFT | BUTTON_RIGHT
#if defined(BUTTON_UP) && defined(BUTTON_DOWN) #if defined(BUTTON_UP) && defined(BUTTON_DOWN)
| BUTTON_UP | BUTTON_DOWN | BUTTON_UP | BUTTON_DOWN
@ -503,7 +503,7 @@ static int button_flip(int button)
if (button & BUTTON_PREV) if (button & BUTTON_PREV)
newbutton |= BUTTON_NEXT; newbutton |= BUTTON_NEXT;
#endif #endif
#endif /* !SIMULATOR */
return newbutton; return newbutton;
} }
@ -523,7 +523,6 @@ void button_set_flip(bool flip)
} }
} }
#endif /* HAVE_LCD_FLIP */ #endif /* HAVE_LCD_FLIP */
#endif /* SIMULATOR */
#ifdef HAVE_BACKLIGHT #ifdef HAVE_BACKLIGHT
void set_backlight_filter_keypress(bool value) void set_backlight_filter_keypress(bool value)

View file

@ -66,6 +66,10 @@
#elif defined(HAVE_AK4537) #elif defined(HAVE_AK4537)
#include "ak4537.h" #include "ak4537.h"
#endif #endif
#if defined(HAVE_SDL_AUDIO)
/* #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 */
#endif
@ -369,7 +373,7 @@ void audiohw_postinit(void);
*/ */
void audiohw_close(void); void audiohw_close(void);
#ifdef AUDIOHW_HAVE_CLIPPING #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO)
/** /**
* Set new volume value * Set new volume value
* @param val to set. * @param val to set.

View file

@ -80,6 +80,8 @@
#undef HAVE_SPEAKER #undef HAVE_SPEAKER
#undef BUTTON_DRIVER_CLOSE
#if CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG #if CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG
#undef CONFIG_BACKLIGHT_FADING #undef CONFIG_BACKLIGHT_FADING
/* simulate SW_SETTING, as we handle sdl very similary */ /* simulate SW_SETTING, as we handle sdl very similary */
@ -97,4 +99,6 @@
#define DEFAULT_BRIGHTNESS_SETTING MAX_BRIGHTNESS_SETTING #define DEFAULT_BRIGHTNESS_SETTING MAX_BRIGHTNESS_SETTING
#endif #endif
#define HAVE_SDL
#define HAVE_SDL_AUDIO
#define _ISOC99_SOURCE 1 #define _ISOC99_SOURCE 1

View file

@ -235,6 +235,7 @@ enum {
#if !defined(SIMULATOR) && !defined(__PCTOOL__) #if !defined(SIMULATOR) && !defined(__PCTOOL__)
#include "system-target.h" #include "system-target.h"
#else /* SIMULATOR */ #else /* SIMULATOR */
#include "system-sdl.h"
static inline uint16_t swap16(uint16_t value) static inline uint16_t swap16(uint16_t value)
/* /*
result[15..8] = value[ 7..0]; result[15..8] = value[ 7..0];

View file

@ -22,14 +22,11 @@
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
#include "kernel.h" #include "kernel.h"
#ifdef SIMULATOR
#include "system-sdl.h"
#include "debug.h"
#endif
#include "thread.h" #include "thread.h"
#include "cpu.h" #include "cpu.h"
#include "system.h" #include "system.h"
#include "panic.h" #include "panic.h"
#include "debug.h"
/* Make this nonzero to enable more elaborate checks on objects */ /* Make this nonzero to enable more elaborate checks on objects */
#if defined(DEBUG) || defined(SIMULATOR) #if defined(DEBUG) || defined(SIMULATOR)

View file

@ -29,6 +29,7 @@ void *malloc(size_t);
void *calloc (size_t nmemb, size_t size); void *calloc (size_t nmemb, size_t size);
void free(void *); void free(void *);
void *realloc(void *, size_t); void *realloc(void *, size_t);
int atexit(void (*)(void));
#define RAND_MAX INT_MAX #define RAND_MAX INT_MAX

View file

@ -43,89 +43,6 @@
extern bool audio_is_initialized; extern bool audio_is_initialized;
#ifdef SIMULATOR
extern void audiohw_set_volume(int value);
/* dummy for sim */
const struct sound_settings_info audiohw_settings[] = {
[SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25},
/* Bass and treble tone controls */
#ifdef AUDIOHW_HAVE_BASS
[SOUND_BASS] = {"dB", 0, 1, -24, 24, 0},
#endif
#ifdef AUDIOHW_HAVE_TREBLE
[SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0},
#endif
[SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
[SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
[SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
#if defined(HAVE_RECORDING)
[SOUND_LEFT_GAIN] = {"dB", 1, 1,-128, 96, 0},
[SOUND_RIGHT_GAIN] = {"dB", 1, 1,-128, 96, 0},
[SOUND_MIC_GAIN] = {"dB", 1, 1,-128, 108, 16},
#endif
#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
[SOUND_BASS_CUTOFF] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
[SOUND_TREBLE_CUTOFF] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_DEPTH_3D)
[SOUND_DEPTH_3D] = {"%", 0, 1, 0, 15, 0},
#endif
/* Hardware EQ tone controls */
#if defined(AUDIOHW_HAVE_EQ_BAND1)
[SOUND_EQ_BAND1_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND2)
[SOUND_EQ_BAND2_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND3)
[SOUND_EQ_BAND3_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND4)
[SOUND_EQ_BAND4_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND5)
[SOUND_EQ_BAND5_GAIN] = {"dB", 0, 1, -12, 12, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
[SOUND_EQ_BAND1_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
[SOUND_EQ_BAND2_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
[SOUND_EQ_BAND3_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
[SOUND_EQ_BAND4_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
[SOUND_EQ_BAND5_FREQUENCY] = {"", 0, 1, 1, 4, 1},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
[SOUND_EQ_BAND2_WIDTH] = {"", 0, 1, 0, 1, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
[SOUND_EQ_BAND3_WIDTH] = {"", 0, 1, 0, 1, 0},
#endif
#if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
[SOUND_EQ_BAND4_WIDTH] = {"", 0, 1, 0, 1, 0},
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
[SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0},
[SOUND_AVC] = {"", 0, 1, -1, 4, 0},
[SOUND_MDB_STRENGTH] = {"dB", 0, 1, 0, 127, 48},
[SOUND_MDB_HARMONICS] = {"%", 0, 1, 0, 100, 50},
[SOUND_MDB_CENTER] = {"Hz", 0, 10, 20, 300, 60},
[SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90},
[SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0},
[SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0},
#endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
};
#endif
const char *sound_unit(int setting) const char *sound_unit(int setting)
{ {
return audiohw_settings[setting].unit; return audiohw_settings[setting].unit;
@ -356,7 +273,7 @@ static void set_prescaled_volume(void)
#elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985)
audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r)); audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r));
#elif defined(HAVE_JZ4740_CODEC) #elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO)
audiohw_set_volume(current_volume); audiohw_set_volume(current_volume);
#endif #endif
#else /* SIMULATOR */ #else /* SIMULATOR */

View file

@ -19,7 +19,8 @@
* *
****************************************************************************/ ****************************************************************************/
#include "uisdl.h" #include <math.h>
#include "sim-ui-defines.h"
#include "lcd-charcells.h" #include "lcd-charcells.h"
#include "lcd-remote.h" #include "lcd-remote.h"
#include "config.h" #include "config.h"
@ -61,6 +62,8 @@ int remote_type(void)
} }
#endif #endif
static int xy2button(int x, int y);
struct event_queue button_queue; struct event_queue button_queue;
static int btn = 0; /* Hopefully keeps track of currently pressed keys... */ static int btn = 0; /* Hopefully keeps track of currently pressed keys... */
@ -78,8 +81,109 @@ bool remote_button_hold(void) {
return remote_hold_button_state; return remote_hold_button_state;
} }
#endif #endif
static void button_event(int key, bool pressed);
extern bool debug_wps;
extern bool mapping;
static void gui_message_loop(void)
{
SDL_Event event;
static int x,y,xybutton = 0;
void button_event(int key, bool pressed) if (SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
button_event(event.key.keysym.sym, true);
break;
case SDL_KEYUP:
button_event(event.key.keysym.sym, false);
case SDL_MOUSEBUTTONDOWN:
switch ( event.button.button ) {
#ifdef HAVE_SCROLLWHEEL
case SDL_BUTTON_WHEELUP:
button_event( SDLK_UP, true );
break;
case SDL_BUTTON_WHEELDOWN:
button_event( SDLK_DOWN, true );
break;
#endif
case SDL_BUTTON_LEFT:
case SDL_BUTTON_MIDDLE:
if ( mapping && background ) {
x = event.button.x;
y = event.button.y;
}
if ( background ) {
xybutton = xy2button( event.button.x, event.button.y );
if( xybutton )
button_event( xybutton, true );
}
break;
default:
break;
}
if (debug_wps && event.button.button == 1)
{
if ( background )
#ifdef HAVE_REMOTE
if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
else
printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 );
#else
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
#endif
else
if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom );
#ifdef HAVE_REMOTE
else
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT );
#endif
}
break;
case SDL_MOUSEBUTTONUP:
switch ( event.button.button ) {
/* The scrollwheel button up events are ignored as they are queued immediately */
case SDL_BUTTON_LEFT:
case SDL_BUTTON_MIDDLE:
if ( mapping && background ) {
printf(" { SDLK_, %d, %d, %d, \"\" },\n", x,
#define SQUARE(x) ((x)*(x))
y, (int)sqrt( SQUARE(x-(int)event.button.x)
+ SQUARE(y-(int)event.button.y)) );
}
if ( background && xybutton ) {
button_event( xybutton, false );
xybutton = 0;
}
#ifdef HAVE_TOUCHSCREEN
else {
button_event(BUTTON_TOUCHSCREEN, false);
}
#endif
break;
default:
break;
}
break;
case SDL_QUIT:
{
exit(EXIT_SUCCESS);
break;
}
default:
/*printf("Unhandled event\n"); */
break;
}
}
}
static void button_event(int key, bool pressed)
{ {
int new_btn = 0; int new_btn = 0;
static bool usb_connected = false; static bool usb_connected = false;
@ -1380,7 +1484,6 @@ int button_read_device(int* data)
int button_read_device(void) int button_read_device(void)
{ {
#endif #endif
#ifdef HAS_BUTTON_HOLD #ifdef HAS_BUTTON_HOLD
int hold_button = button_hold(); int hold_button = button_hold();
@ -1396,7 +1499,9 @@ int button_read_device(void)
if (hold_button) if (hold_button)
return BUTTON_NONE; return BUTTON_NONE;
else
#endif #endif
gui_message_loop();
return btn; return btn;
} }
@ -1430,8 +1535,9 @@ void mouse_tick_task(void)
} }
#endif #endif
void button_init_sdl(void) void button_init_device(void)
{ {
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
#ifdef HAVE_TOUCHSCREEN #ifdef HAVE_TOUCHSCREEN
tick_add_task(mouse_tick_task); tick_add_task(mouse_tick_task);
#endif #endif
@ -1441,6 +1547,10 @@ void button_init_sdl(void)
/* Run sim with --mapping to get coordinates */ /* Run sim with --mapping to get coordinates */
/* or --debugbuttons to check */ /* or --debugbuttons to check */
/* The First matching button is returned */ /* The First matching button is returned */
struct button_map {
int button, x, y, radius;
char *description;
};
#ifdef SANSA_FUZE #ifdef SANSA_FUZE
struct button_map bm[] = { struct button_map bm[] = {
@ -1892,7 +2002,8 @@ struct button_map bm[] = {
}; };
#endif #endif
int xy2button( int x, int y) { static int xy2button( int x, int y)
{
int i; int i;
extern bool debug_buttons; extern bool debug_buttons;

View file

@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/ * \/ \/ \/ \/ \/
* $Id$ * $Id$
* *
* Copyright (C) 2005 by Daniel Stenberg <daniel@haxx.se> * Copyright (C) 2009 by Thomas Martitz
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -19,6 +19,14 @@
* *
****************************************************************************/ ****************************************************************************/
int sound_playback_thread(void* p);
extern void (*sound_get_pcm)(unsigned char** start, long* size); #ifndef __BUTTON_SDL_H__
#define __BUTTON_SDL_H__
#include <stdbool.h>
#include "config.h"
bool button_hold(void);
void button_init_device(void);
#endif /* __BUTTON_SDL_H__ */

View file

@ -20,14 +20,15 @@
****************************************************************************/ ****************************************************************************/
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <SDL.h> #include <SDL.h>
#include <SDL_thread.h> #include <SDL_thread.h>
#include "memory.h" #include "memory.h"
#include "system-sdl.h" #include "system-sdl.h"
#include "uisdl.h"
#include "kernel.h"
#include "thread-sdl.h" #include "thread-sdl.h"
#include "kernel.h"
#include "thread.h" #include "thread.h"
#include "panic.h"
#include "debug.h" #include "debug.h"
static SDL_TimerID tick_timer_id; static SDL_TimerID tick_timer_id;
@ -90,19 +91,19 @@ void sim_exit_irq_handler(void)
SDL_UnlockMutex(sim_irq_mtx); SDL_UnlockMutex(sim_irq_mtx);
} }
bool sim_kernel_init(void) static bool sim_kernel_init(void)
{ {
sim_irq_mtx = SDL_CreateMutex(); sim_irq_mtx = SDL_CreateMutex();
if (sim_irq_mtx == NULL) if (sim_irq_mtx == NULL)
{ {
fprintf(stderr, "Cannot create sim_handler_mtx\n"); panicf("Cannot create sim_handler_mtx\n");
return false; return false;
} }
sim_thread_cond = SDL_CreateCond(); sim_thread_cond = SDL_CreateCond();
if (sim_thread_cond == NULL) if (sim_thread_cond == NULL)
{ {
fprintf(stderr, "Cannot create sim_thread_cond\n"); panicf("Cannot create sim_thread_cond\n");
return false; return false;
} }
@ -141,6 +142,12 @@ Uint32 tick_timer(Uint32 interval, void *param)
void tick_start(unsigned int interval_in_ms) void tick_start(unsigned int interval_in_ms)
{ {
if (!sim_kernel_init())
{
panicf("Could not initialize kernel!");
exit(-1);
}
if (tick_timer_id != NULL) if (tick_timer_id != NULL)
{ {
SDL_RemoveTimer(tick_timer_id); SDL_RemoveTimer(tick_timer_id);

View file

@ -20,7 +20,8 @@
****************************************************************************/ ****************************************************************************/
#include "debug.h" #include "debug.h"
#include "uisdl.h" #include "sim-ui-defines.h"
#include "system.h"
#include "lcd-sdl.h" #include "lcd-sdl.h"
#include "screendump.h" #include "screendump.h"

View file

@ -19,17 +19,18 @@
* *
****************************************************************************/ ****************************************************************************/
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "system.h"
#include "debug.h" #include "debug.h"
#include "lcd.h" #include "lcd.h"
#include "lcd-charcell.h" #include "lcd-charcell.h"
#include "screendump.h" #include "screendump.h"
#include "general.h" #include "general.h"
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "lcd-playersim.h" #include "lcd-playersim.h"
#include "uisdl.h" #include "sim-ui-defines.h"
#include "lcd-sdl.h" #include "lcd-sdl.h"
/* can't include file.h here */ /* can't include file.h here */

View file

@ -19,10 +19,11 @@
* *
****************************************************************************/ ****************************************************************************/
#include "uisdl.h" #include "sim-ui-defines.h"
#include "lcd-sdl.h" #include "lcd-sdl.h"
#include "lcd-remote-bitmap.h" #include "lcd-remote-bitmap.h"
#include "screendump.h" #include "screendump.h"
#include "system.h" /* background */
SDL_Surface *remote_surface = 0; SDL_Surface *remote_surface = 0;

View file

@ -19,8 +19,9 @@
* *
****************************************************************************/ ****************************************************************************/
#include <SDL.h>
#include "lcd-sdl.h" #include "lcd-sdl.h"
#include "uisdl.h" #include "sim-ui-defines.h"
#include "system.h" /* for MIN() and MAX() */ #include "system.h" /* for MIN() and MAX() */
int display_zoom = 1; int display_zoom = 1;

View file

@ -27,6 +27,7 @@
/* Default display zoom level */ /* Default display zoom level */
extern int display_zoom; extern int display_zoom;
extern SDL_Surface *gui_surface;
void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
int height, int max_x, int max_y, int height, int max_x, int max_y,

View file

@ -8,6 +8,7 @@
* $Id$ * $Id$
* *
* Copyright (C) 2005 by Nick Lanham * Copyright (C) 2005 by Nick Lanham
* Copyright (C) 2010 by Thomas Martitz
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -23,17 +24,20 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <memory.h> #include <SDL.h>
#include "kernel.h" #include "config.h"
#include "debug.h"
#include "sound.h" #include "sound.h"
#include "audiohw.h" #include "audiohw.h"
#include "system.h"
#include "pcm.h" #include "pcm.h"
#include "pcm_sampr.h" #include "pcm_sampr.h"
#include "SDL.h"
/*#define LOGF_ENABLE*/ #ifdef DEBUG
#include "logf.h" #include <stdio.h>
extern bool debug_audio;
#endif
static int sim_volume = 0; static int sim_volume = 0;
@ -45,23 +49,19 @@ static size_t pcm_data_size;
static size_t pcm_sample_bytes; static size_t pcm_sample_bytes;
static size_t pcm_channel_bytes; static size_t pcm_channel_bytes;
static struct pcm_udata struct pcm_udata
{ {
Uint8 *stream; Uint8 *stream;
Uint32 num_in; Uint32 num_in;
Uint32 num_out; Uint32 num_out;
#ifdef DEBUG
FILE *debug; FILE *debug;
#endif
} udata; } udata;
static SDL_AudioSpec obtained; static SDL_AudioSpec obtained;
static SDL_AudioCVT cvt; static SDL_AudioCVT cvt;
extern bool debug_audio;
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
void pcm_play_lock(void) void pcm_play_lock(void)
{ {
SDL_LockAudio(); SDL_LockAudio();
@ -102,11 +102,13 @@ void pcm_play_dma_start(const void *addr, size_t size)
void pcm_play_dma_stop(void) void pcm_play_dma_stop(void)
{ {
SDL_PauseAudio(1); SDL_PauseAudio(1);
#ifdef DEBUG
if (udata.debug != NULL) { if (udata.debug != NULL) {
fclose(udata.debug); fclose(udata.debug);
udata.debug = NULL; udata.debug = NULL;
DEBUGF("Audio debug file closed\n"); DEBUGF("Audio debug file closed\n");
} }
#endif
} }
void pcm_play_dma_pause(bool pause) void pcm_play_dma_pause(bool pause)
@ -122,13 +124,14 @@ size_t pcm_get_bytes_waiting(void)
return pcm_data_size; return pcm_data_size;
} }
extern int sim_volume; /* in firmware/sound.c */ void write_to_soundcard(struct pcm_udata *udata)
static void write_to_soundcard(struct pcm_udata *udata) { {
#ifdef DEBUG
if (debug_audio && (udata->debug == NULL)) { if (debug_audio && (udata->debug == NULL)) {
udata->debug = fopen("audiodebug.raw", "ab"); udata->debug = fopen("audiodebug.raw", "ab");
DEBUGF("Audio debug file open\n"); DEBUGF("Audio debug file open\n");
} }
#endif
if (cvt.needed) { if (cvt.needed) {
Uint32 rd = udata->num_in; Uint32 rd = udata->num_in;
Uint32 wr = (double)rd * cvt.len_ratio; Uint32 wr = (double)rd * cvt.len_ratio;
@ -162,10 +165,11 @@ static void write_to_soundcard(struct pcm_udata *udata) {
udata->num_in = cvt.len / pcm_sample_bytes; udata->num_in = cvt.len / pcm_sample_bytes;
udata->num_out = cvt.len_cvt / pcm_sample_bytes; udata->num_out = cvt.len_cvt / pcm_sample_bytes;
#ifdef DEBUG
if (udata->debug != NULL) { if (udata->debug != NULL) {
fwrite(cvt.buf, sizeof(Uint8), cvt.len_cvt, udata->debug); fwrite(cvt.buf, sizeof(Uint8), cvt.len_cvt, udata->debug);
} }
#endif
free(cvt.buf); free(cvt.buf);
} }
else { else {
@ -191,26 +195,27 @@ static void write_to_soundcard(struct pcm_udata *udata) {
break; break;
} }
} }
#ifdef DEBUG
if (udata->debug != NULL) { if (udata->debug != NULL) {
fwrite(udata->stream, sizeof(Uint8), wr, udata->debug); fwrite(udata->stream, sizeof(Uint8), wr, udata->debug);
} }
#endif
} }
} else { } else {
udata->num_in = udata->num_out = MIN(udata->num_in, udata->num_out); udata->num_in = udata->num_out = MIN(udata->num_in, udata->num_out);
SDL_MixAudio(udata->stream, pcm_data, SDL_MixAudio(udata->stream, pcm_data,
udata->num_out * pcm_sample_bytes, sim_volume); udata->num_out * pcm_sample_bytes, sim_volume);
#ifdef DEBUG
if (udata->debug != NULL) { if (udata->debug != NULL) {
fwrite(pcm_data, sizeof(Uint8), udata->num_out * pcm_sample_bytes, fwrite(pcm_data, sizeof(Uint8), udata->num_out * pcm_sample_bytes,
udata->debug); udata->debug);
} }
#endif
} }
} }
static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len) 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);
udata->stream = stream; udata->stream = stream;
/* Write what we have in the PCM buffer */ /* Write what we have in the PCM buffer */
@ -221,6 +226,7 @@ static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len)
while (len > 0) { while (len > 0) {
if ((ssize_t)pcm_data_size <= 0) { if ((ssize_t)pcm_data_size <= 0) {
pcm_data_size = 0; pcm_data_size = 0;
if (pcm_callback_for_more) if (pcm_callback_for_more)
pcm_callback_for_more(&pcm_data, &pcm_data_size); pcm_callback_for_more(&pcm_data, &pcm_data_size);
} }
@ -302,14 +308,20 @@ const void * pcm_rec_dma_get_peak_buffer(void)
void pcm_play_dma_init(void) void pcm_play_dma_init(void)
{ {
SDL_AudioSpec wanted_spec; if (SDL_InitSubSystem(SDL_INIT_AUDIO))
udata.debug = NULL; {
DEBUGF("Could not initialize SDL audio subsystem!\n");
return;
}
SDL_AudioSpec wanted_spec;
#ifdef DEBUG
udata.debug = NULL;
if (debug_audio) { if (debug_audio) {
udata.debug = fopen("audiodebug.raw", "wb"); udata.debug = fopen("audiodebug.raw", "wb");
DEBUGF("Audio debug file open\n"); DEBUGF("Audio debug file open\n");
} }
#endif
/* Set 16-bit stereo audio at 44Khz */ /* Set 16-bit stereo audio at 44Khz */
wanted_spec.freq = 44100; wanted_spec.freq = 44100;
wanted_spec.format = AUDIO_S16SYS; wanted_spec.format = AUDIO_S16SYS;
@ -322,7 +334,7 @@ void pcm_play_dma_init(void)
/* Open the audio device and start playing sound! */ /* Open the audio device and start playing sound! */
if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) { if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) {
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); DEBUGF("Unable to open audio: %s\n", SDL_GetError());
return; return;
} }
@ -339,7 +351,7 @@ void pcm_play_dma_init(void)
pcm_channel_bytes = 2; pcm_channel_bytes = 2;
break; break;
default: default:
fprintf(stderr, "Unknown sample format obtained: %u\n", DEBUGF("Unknown sample format obtained: %u\n",
(unsigned)obtained.format); (unsigned)obtained.format);
return; return;
} }
@ -353,74 +365,9 @@ void pcm_postinit(void)
{ {
} }
void pcm_set_mixer_volume(int volume)
{
sim_volume = volume;
}
#endif /* CONFIG_CODEC == SWCODEC */ #endif /* CONFIG_CODEC == SWCODEC */
/**
* Audio Hardware api. Make them do nothing as we cannot properly simulate with
* SDL. if we used DSP we would run code that doesn't actually run on the target
**/
void audiohw_set_volume(int volume)
{
sim_volume = SDL_MIX_MAXVOLUME * ((volume - VOLUME_MIN) / 10) / (VOLUME_RANGE / 10);
}
#if defined(AUDIOHW_HAVE_PRESCALER)
void audiohw_set_prescaler(int value) { (void)value; }
#endif
#if defined(AUDIOHW_HAVE_BALANCE)
void audiohw_set_balance(int value) { (void)value; }
#endif
#if defined(AUDIOHW_HAVE_BASS)
void audiohw_set_bass(int value) { (void)value; }
#endif
#if defined(AUDIOHW_HAVE_TREBLE)
void audiohw_set_treble(int value) { (void)value; }
#endif
#if CONFIG_CODEC != SWCODEC
void audiohw_set_channel(int value) { (void)value; }
void audiohw_set_stereo_width(int value){ (void)value; }
#endif
#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
void audiohw_set_bass_cutoff(int value) { (void)value; }
#endif
#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
void audiohw_set_treble_cutoff(int value){ (void)value; }
#endif
/* EQ-based tone controls */
#if defined(AUDIOHW_HAVE_EQ)
void audiohw_set_eq_band_gain(unsigned int band, int value)
{ (void)band; (void)value; }
#endif
#if defined(AUDIOHW_HAVE_EQ_FREQUENCY)
void audiohw_set_eq_band_frequency(unsigned int band, int value)
{ (void)band; (void)value; }
#endif
#if defined(AUDIOHW_HAVE_EQ_WIDTH)
void audiohw_set_eq_band_width(unsigned int band, int value)
{ (void)band; (void)value; }
#endif
#if defined(AUDIOHW_HAVE_DEPTH_3D)
void audiohw_set_depth_3d(int value)
{ (void)value; }
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
int mas_codec_readreg(int reg)
{
(void)reg;
return 0;
}
int mas_codec_writereg(int reg, unsigned int val)
{
(void)reg;
(void)val;
return 0;
}
int mas_writemem(int bank, int addr, const unsigned long* src, int len)
{
(void)bank;
(void)addr;
(void)src;
(void)len;
return 0;
}
#endif

View file

@ -397,12 +397,9 @@
#define UI_LCD_POSX 101 #define UI_LCD_POSX 101
#define UI_LCD_POSY 195 #define UI_LCD_POSY 195
#else #elif defined(SIMULATOR)
#error no UI defines #error no UI defines
#endif #endif
extern SDL_Surface *gui_surface;
extern bool background; /* True if the background image is enabled */
extern int display_zoom;
#endif /* #ifndef __UISDL_H__ */ #endif /* #ifndef __UISDL_H__ */

View file

@ -19,15 +19,13 @@
* *
****************************************************************************/ ****************************************************************************/
#include <SDL.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <setjmp.h> #include <setjmp.h>
#include "autoconf.h"
#include "button.h"
#include "system-sdl.h" #include "system-sdl.h"
#include "thread.h" #include "thread-sdl.h"
#include "kernel.h" #include "sim-ui-defines.h"
#include "uisdl.h"
#include "lcd-sdl.h" #include "lcd-sdl.h"
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
#include "lcd-bitmap.h" #include "lcd-bitmap.h"
@ -37,21 +35,14 @@
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
#include "lcd-remote-bitmap.h" #include "lcd-remote-bitmap.h"
#endif #endif
#include "thread-sdl.h" #include "panic.h"
#include "SDL_mutex.h" #include "debug.h"
#include "SDL_thread.h"
#include "math.h"
/* extern functions */
extern void new_key(int key);
extern int xy2button( int x, int y);
void button_event(int key, bool pressed);
SDL_Surface *gui_surface; SDL_Surface *gui_surface;
bool background = true; /* use backgrounds by default */ bool background = true; /* use backgrounds by default */
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
static bool showremote = true; /* include remote by default */ bool showremote = true; /* include remote by default */
#endif #endif
bool mapping = false; bool mapping = false;
bool debug_buttons = false; bool debug_buttons = false;
@ -60,136 +51,39 @@ bool lcd_display_redraw = true; /* Used for player simulator */
char having_new_lcd = true; /* Used for player simulator */ char having_new_lcd = true; /* Used for player simulator */
bool sim_alarm_wakeup = false; bool sim_alarm_wakeup = false;
const char *sim_root_dir = NULL; const char *sim_root_dir = NULL;
extern int display_zoom;
#ifdef DEBUG
bool debug_audio = false; bool debug_audio = false;
#endif
bool debug_wps = false; bool debug_wps = false;
int wps_verbose_level = 3; int wps_verbose_level = 3;
void irq_button_event(int key, bool pressed) { void sys_poweroff(void)
sim_enter_irq_handler();
button_event( key, pressed );
sim_exit_irq_handler();
}
int sqr( int a ) {
return a*a;
}
void gui_message_loop(void)
{ {
SDL_Event event; /* Order here is relevent to prevent deadlocks and use of destroyed
bool done = false; sync primitives by kernel threads */
static int x,y,xybutton = 0; sim_thread_shutdown();
sim_kernel_shutdown();
while(!done && SDL_WaitEvent(&event)) SDL_Quit();
{
switch(event.type)
{
case SDL_KEYDOWN:
irq_button_event(event.key.keysym.sym, true);
break;
case SDL_KEYUP:
irq_button_event(event.key.keysym.sym, false);
case SDL_MOUSEBUTTONDOWN:
switch ( event.button.button ) {
#ifdef HAVE_SCROLLWHEEL
case SDL_BUTTON_WHEELUP:
irq_button_event( SDLK_UP, true );
break;
case SDL_BUTTON_WHEELDOWN:
irq_button_event( SDLK_DOWN, true );
break;
#endif
case SDL_BUTTON_LEFT:
case SDL_BUTTON_MIDDLE:
if ( mapping && background ) {
x = event.button.x;
y = event.button.y;
}
if ( background ) {
xybutton = xy2button( event.button.x, event.button.y );
if( xybutton )
irq_button_event( xybutton, true );
}
break;
default:
break;
} }
if (debug_wps && event.button.button == 1) void system_init(void)
{
if ( background )
#ifdef HAVE_REMOTE
if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
else
printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 );
#else
printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
#endif
else
if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom );
#ifdef HAVE_REMOTE
else
printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT );
#endif
}
break;
case SDL_MOUSEBUTTONUP:
switch ( event.button.button ) {
/* The scrollwheel button up events are ignored as they are queued immediately */
case SDL_BUTTON_LEFT:
case SDL_BUTTON_MIDDLE:
if ( mapping && background ) {
printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, y, (int)sqrt( sqr(x-(int)event.button.x) + sqr(y-(int)event.button.y)) );
}
if ( background && xybutton ) {
irq_button_event( xybutton, false );
xybutton = 0;
}
#ifdef HAVE_TOUCHSCREEN
else {
irq_button_event(BUTTON_TOUCHSCREEN, false);
}
#endif
break;
default:
break;
}
break;
case SDL_QUIT:
done = true;
break;
default:
/*printf("Unhandled event\n"); */
break;
}
}
}
bool gui_startup(void)
{ {
SDL_Surface *picture_surface; SDL_Surface *picture_surface;
int width, height; int width, height;
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) { if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER))
fprintf(stderr, "fatal: %s\n", SDL_GetError()); panicf("%s", SDL_GetError());
return false;
}
atexit(SDL_Quit);
/* Try and load the background image. If it fails go without */ /* Try and load the background image. If it fails go without */
if (background) { if (background) {
picture_surface = SDL_LoadBMP("UI256.bmp"); picture_surface = SDL_LoadBMP("UI256.bmp");
if (picture_surface == NULL) { if (picture_surface == NULL) {
background = false; background = false;
fprintf(stderr, "warn: %s\n", SDL_GetError()); DEBUGF("warn: %s\n", SDL_GetError());
} }
} }
@ -217,8 +111,7 @@ bool gui_startup(void)
if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) { if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
fprintf(stderr, "fatal: %s\n", SDL_GetError()); panicf("%s", SDL_GetError());
return false;
} }
SDL_WM_SetCaption(UI_TITLE, NULL); SDL_WM_SetCaption(UI_TITLE, NULL);
@ -229,43 +122,38 @@ bool gui_startup(void)
sim_lcd_remote_init(); sim_lcd_remote_init();
#endif #endif
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
if (background && picture_surface != NULL) { if (background && picture_surface != NULL) {
SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
SDL_UpdateRect(gui_surface, 0, 0, 0, 0); SDL_UpdateRect(gui_surface, 0, 0, 0, 0);
} }
return true;
} }
bool gui_shutdown(void) void system_exception_wait(void)
{ {
/* Order here is relevent to prevent deadlocks and use of destroyed sim_thread_exception_wait();
sync primitives by kernel threads */
thread_sdl_shutdown();
sim_kernel_shutdown();
return true;
} }
#if defined(WIN32) && defined(main) void system_reboot(void)
/* Don't use SDL_main on windows -> no more stdio redirection */ {
#undef main sim_thread_exception_wait();
#endif }
int main(int argc, char *argv[]) void sys_handle_argv(int argc, char *argv[])
{ {
if (argc >= 1) if (argc >= 1)
{ {
int x; int x;
for (x = 1; x < argc; x++) for (x = 1; x < argc; x++)
{ {
#ifdef DEBUG
if (!strcmp("--debugaudio", argv[x])) if (!strcmp("--debugaudio", argv[x]))
{ {
debug_audio = true; debug_audio = true;
printf("Writing debug audio file.\n"); printf("Writing debug audio file.\n");
} }
else if (!strcmp("--debugwps", argv[x])) else
#endif
if (!strcmp("--debugwps", argv[x]))
{ {
debug_wps = true; debug_wps = true;
printf("WPS debug mode enabled.\n"); printf("WPS debug mode enabled.\n");
@ -325,7 +213,9 @@ int main(int argc, char *argv[])
{ {
printf("rockboxui\n"); printf("rockboxui\n");
printf("Arguments:\n"); printf("Arguments:\n");
#ifdef DEBUG
printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n"); printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
#endif
printf(" --debugwps \t Print advanced WPS debug info\n"); printf(" --debugwps \t Print advanced WPS debug info\n");
printf(" --nobackground \t Disable the background image\n"); printf(" --nobackground \t Disable the background image\n");
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
@ -340,29 +230,7 @@ int main(int argc, char *argv[])
} }
} }
} }
if (display_zoom > 1) { if (display_zoom > 1) {
background = false; background = false;
} }
if (!sim_kernel_init()) {
fprintf(stderr, "sim_kernel_init failed\n");
return -1;
} }
if (!gui_startup()) {
fprintf(stderr, "gui_startup failed\n");
return -1;
}
/* app_main will be called by the new main thread */
if (!thread_sdl_init(NULL)) {
fprintf(stderr, "thread_sdl_init failed\n");
return -1;
}
gui_message_loop();
return gui_shutdown();
}

View file

@ -41,9 +41,12 @@ int set_irq_level(int level);
void sim_enter_irq_handler(void); void sim_enter_irq_handler(void);
void sim_exit_irq_handler(void); void sim_exit_irq_handler(void);
bool sim_kernel_init(void);
void sim_kernel_shutdown(void); void sim_kernel_shutdown(void);
void sys_poweroff(void);
void sys_handle_argv(int argc, char *argv[]);
extern bool background; /* True if the background image is enabled */
extern int display_zoom;
extern long start_tick; extern long start_tick;
#endif /* _SYSTEM_SDL_H_ */ #endif /* _SYSTEM_SDL_H_ */

View file

@ -56,12 +56,15 @@ struct thread_entry threads[MAXTHREADS];
* in their start routines responding to messages so this is the only * in their start routines responding to messages so this is the only
* way to get them back in there so they may exit */ * way to get them back in there so they may exit */
static jmp_buf thread_jmpbufs[MAXTHREADS]; 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; static SDL_mutex *m;
static volatile bool threads_exit = false; static volatile bool threads_exit = false;
extern long start_tick; extern long start_tick;
void thread_sdl_shutdown(void) void sim_thread_shutdown(void)
{ {
int i; int i;
@ -79,6 +82,7 @@ void thread_sdl_shutdown(void)
for (i = 0; i < MAXTHREADS; i++) for (i = 0; i < MAXTHREADS; i++)
{ {
struct thread_entry *thread = &threads[i]; struct thread_entry *thread = &threads[i];
/* exit all current threads, except the main one */
if (thread->context.t != NULL) if (thread->context.t != NULL)
{ {
/* Signal thread on delay or block */ /* Signal thread on delay or block */
@ -128,30 +132,9 @@ static struct thread_entry * find_empty_thread_slot(void)
return thread; return thread;
} }
/* Do main thread creation in this file scope to avoid the need to double-
return to a prior call-level which would be unaware of the fact setjmp
was used */
extern void app_main(void *param);
static int thread_sdl_app_main(void *param)
{
SDL_LockMutex(m);
cores[CURRENT_CORE].running = &threads[0];
/* Set the jump address for return */
if (setjmp(thread_jmpbufs[0]) == 0)
{
app_main(param);
/* should not ever be reached but... */
THREAD_PANICF("app_main returned!\n");
}
/* Unlock and exit */
SDL_UnlockMutex(m);
return 0;
}
/* Initialize SDL threading */ /* Initialize SDL threading */
bool thread_sdl_init(void *param) void init_threads(void)
{ {
struct thread_entry *thread; struct thread_entry *thread;
int n; int n;
@ -164,7 +147,7 @@ bool thread_sdl_init(void *param)
if (SDL_LockMutex(m) == -1) if (SDL_LockMutex(m) == -1)
{ {
fprintf(stderr, "Couldn't lock mutex\n"); fprintf(stderr, "Couldn't lock mutex\n");
return false; return;
} }
/* Initialize all IDs */ /* Initialize all IDs */
@ -180,30 +163,21 @@ bool thread_sdl_init(void *param)
thread->name = "main"; thread->name = "main";
thread->state = STATE_RUNNING; thread->state = STATE_RUNNING;
thread->context.s = SDL_CreateSemaphore(0); thread->context.s = SDL_CreateSemaphore(0);
thread->context.t = NULL; /* NULL for the implicit main thread */
cores[CURRENT_CORE].running = thread; cores[CURRENT_CORE].running = thread;
if (thread->context.s == NULL) if (thread->context.s == NULL)
{ {
fprintf(stderr, "Failed to create main semaphore\n"); fprintf(stderr, "Failed to create main semaphore\n");
return false; return;
}
thread->context.t = SDL_CreateThread(thread_sdl_app_main, param);
if (thread->context.t == NULL)
{
SDL_DestroySemaphore(thread->context.s);
fprintf(stderr, "Failed to create main thread\n");
return false;
} }
THREAD_SDL_DEBUGF("Main thread: %p\n", thread); THREAD_SDL_DEBUGF("Main thread: %p\n", thread);
SDL_UnlockMutex(m); return;
return true;
} }
void thread_sdl_exception_wait(void) void sim_thread_exception_wait(void)
{ {
while (1) while (1)
{ {
@ -214,7 +188,7 @@ void thread_sdl_exception_wait(void)
} }
/* A way to yield and leave the threading system for extended periods */ /* A way to yield and leave the threading system for extended periods */
void thread_sdl_thread_lock(void *me) void sim_thread_lock(void *me)
{ {
SDL_LockMutex(m); SDL_LockMutex(m);
cores[CURRENT_CORE].running = (struct thread_entry *)me; cores[CURRENT_CORE].running = (struct thread_entry *)me;
@ -223,7 +197,7 @@ void thread_sdl_thread_lock(void *me)
thread_exit(); thread_exit();
} }
void * thread_sdl_thread_unlock(void) void * sim_thread_unlock(void)
{ {
struct thread_entry *current = cores[CURRENT_CORE].running; struct thread_entry *current = cores[CURRENT_CORE].running;
SDL_UnlockMutex(m); SDL_UnlockMutex(m);
@ -529,19 +503,6 @@ unsigned int create_thread(void (*function)(void),
return thread->id; return thread->id;
} }
void init_threads(void)
{
/* Main thread is already initialized */
if (cores[CURRENT_CORE].running != &threads[0])
{
THREAD_PANICF("Wrong main thread in init_threads: %p\n",
cores[CURRENT_CORE].running);
}
THREAD_SDL_DEBUGF("First Thread: %d (%s)\n",
0, THREAD_SDL_GET_NAME(&threads[0]));
}
#ifndef ALLOW_REMOVE_THREAD #ifndef ALLOW_REMOVE_THREAD
static void remove_thread(unsigned int thread_id) static void remove_thread(unsigned int thread_id)
#else #else

View file

@ -22,16 +22,11 @@
#ifndef __THREADSDL_H__ #ifndef __THREADSDL_H__
#define __THREADSDL_H__ #define __THREADSDL_H__
#include "SDL_thread.h" /* extra thread functions that only apply when running on hosting platforms */
void sim_thread_lock(void *me);
extern SDL_Thread *gui_thread; /* The "main" thread */ void * sim_thread_unlock(void);
void thread_sdl_thread_lock(void *me); void sim_thread_exception_wait(void);
void * thread_sdl_thread_unlock(void); void sim_thread_shutdown(void); /* Shut down all kernel threads gracefully */
void thread_sdl_exception_wait(void);
bool thread_sdl_init(void *param); /* Init the sim threading API - thread created calls app_main */
void thread_sdl_shutdown(void); /* Shut down all kernel threads gracefully */
void thread_sdl_lock(void); /* Sync with SDL threads */
void thread_sdl_unlock(void); /* Sync with SDL threads */
#endif /* #ifndef __THREADSDL_H__ */ #endif /* #ifndef __THREADSDL_H__ */

4
tools/configure vendored
View file

@ -2973,6 +2973,10 @@ EOF
if test -n "$t_cpu"; then if test -n "$t_cpu"; then
TARGET_INC="-I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer/$t_model" TARGET_INC="-I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer/$t_model"
if [ "$simulator" = "yes" ]; then # a few more includes for the sim target tree
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/sdl/"
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/"
fi
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer" TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer"
TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu" TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu"
GCCOPTS="$GCCOPTS" GCCOPTS="$GCCOPTS"

View file

@ -233,7 +233,7 @@ static ssize_t io_trigger_and_wait(int cmd)
{ {
/* Allow other rockbox threads to run */ /* Allow other rockbox threads to run */
io.accum = 0; io.accum = 0;
mythread = thread_sdl_thread_unlock(); mythread = sim_thread_unlock();
} }
switch (cmd) switch (cmd)
@ -249,7 +249,7 @@ static ssize_t io_trigger_and_wait(int cmd)
/* Regain our status as current */ /* Regain our status as current */
if (mythread != NULL) if (mythread != NULL)
{ {
thread_sdl_thread_lock(mythread); sim_thread_lock(mythread);
} }
return result; return result;

View file

@ -157,10 +157,6 @@ void shutdown_hw(void)
{ {
} }
void sys_poweroff(void)
{
}
void cancel_shutdown(void) void cancel_shutdown(void)
{ {
} }

View file

@ -314,25 +314,9 @@ void cpu_sleep(bool enabled)
(void)enabled; (void)enabled;
} }
void button_set_flip(bool yesno)
{
(void)yesno;
}
#ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
void touchpad_set_sensitivity(int level) void touchpad_set_sensitivity(int level)
{ {
(void)level; (void)level;
} }
#endif #endif
void system_exception_wait(void)
{
thread_sdl_exception_wait();
}
void system_reboot(void)
{
thread_sdl_exception_wait();
}

View file

@ -1,64 +0,0 @@
############################################################################
# __________ __ ___.
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
# \/ \/ \/ \/ \/
# $Id$
#
# Copyright (C) 2002, 2008 by Daniel Stenberg <daniel@haxx.se>
#
# All files in this archive are subject to the GNU General Public License.
# See the file COPYING in the source tree root for full license agreement.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################
SIMCOMMON = ../common
DEPFILE = $(OBJDIR)/dep-sim
RM = rm -f
DEBUG = -g
# Use this for simulator-only files
INCLUDES = -I. -I$(SIMCOMMON) -I$(OBJDIR) $(TARGET_INC) -I$(FIRMDIR)/export \
-I$(APPSDIR) -I$(BUILDDIR)
# This sets up 'SRC' based on the files mentioned in SOURCES
include $(TOOLSDIR)/makesrc.inc
OBJS := $(SRC:%.c=$(OBJDIR)/%.o)
DEFINES := -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR \
$(TARGET) -DAPPSVERSION=\"$(VERSION)\" -DMEM=${MEMORYSIZE} $(EXTRA_DEFINES)
SOURCES = $(SRC)
DIRS = .
CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) $(GCCOPTS) -W -Wall
OUTFILE = $(BUILDDIR)/libsim.a
all: $(OUTFILE)
include $(TOOLSDIR)/make.inc
$(OUTFILE): $(OBJS) $(BUILDDIR)/UI256.bmp
$(call PRINTS,AR+RANLIB $(@F))$(AR) ruv $@ $(OBJS) >/dev/null 2>&1
$(SILENT)$(RANLIB) $@
clean:
$(call PRINTS,cleaning sim)$(RM) $(OBJS) *~ core $(OUTFILE) $(DEPFILE) \
$(BUILDDIR)/UI256.bmp $(DEPFILE)
$(SILENT)$(MAKE) -C $(SIMCOMMON) clean
################## Specific dependencies ##################
$(BUILDDIR)/UI256.bmp: UI-$(MODELNAME).bmp
$(call PRINTS,UI)cp $< $@
-include $(DEPFILE)

View file

@ -1,6 +0,0 @@
To build:
$ ../tools/configure
[answer questions]
$ make
$ ./rockboxui

View file

@ -1,15 +0,0 @@
button.c
kernel-sdl.c
#ifdef HAVE_LCD_BITMAP
lcd-bitmap.c
#elif defined(HAVE_LCD_CHARCELLS)
lcd-charcells.c
#endif
#ifdef HAVE_REMOTE_LCD
lcd-remote-bitmap.c
#endif
lcd-sdl.c
sound.c
timer.c
thread-sdl.c
uisdl.c

View file

@ -1,46 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2009 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 _BUTTON_SDL_H_
#define _BUTTON_SDL_H_
#include <stdbool.h>
#include "config.h"
#include "button-target.h"
#undef HAVE_LCD_FLIP
#undef button_init_device
#define button_init_device()
struct button_map {
int button, x, y, radius;
char *description;
};
int xy2button( int x, int y);
bool button_hold(void);
void button_init_sdl(void);
#undef button_init_device
#define button_init_device() button_init_sdl()
#endif

View file

@ -1,7 +0,0 @@
#include <time.h>
#include <stdbool.h>
/* struct tm defined */
struct tm *get_time(void);
int set_time(const struct tm *tm);
bool valid_time(const struct tm *tm);

View file

@ -8,13 +8,10 @@
# #
INCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \ INCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \
-I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR)
SIMINCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \ SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS)
-I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR)
SIMFLAGS += $(SIMINCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS)
SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/sdl/SOURCES)
SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/common/SOURCES) SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/common/SOURCES)
SIMOBJ = $(call c2obj,$(SIMSRC)) SIMOBJ = $(call c2obj,$(SIMSRC))
OTHER_SRC += $(SIMSRC) OTHER_SRC += $(SIMSRC)