summaryrefslogtreecommitdiffstats
path: root/uisimulator
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2006-02-13 21:46:28 +0000
committerDan Everton <dan@iocaine.org>2006-02-13 21:46:28 +0000
commit3ba0060ac1fa1c39596c51d4bf259142e6d1847f (patch)
tree71428db81254a9901fbf3e8a92c71f0f57410cd2 /uisimulator
parentdd39e33663a4b617c3f88f48845681e772386a7f (diff)
downloadrockbox-3ba0060ac1fa1c39596c51d4bf259142e6d1847f.tar.gz
rockbox-3ba0060ac1fa1c39596c51d4bf259142e6d1847f.zip
Backlight support for 8-bit targets in SDL sim. Redo sound handling. Still doesn't work right, but is closer to how the actual Rockbox system does it. Move some stub functions in to Win32 and X11 sims to keep them compiling.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8686 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/common/stubs.c57
-rw-r--r--uisimulator/sdl/lcd-bitmap.c20
-rw-r--r--uisimulator/sdl/lcd-charcell.c16
-rw-r--r--uisimulator/sdl/lcd-remote.c12
-rw-r--r--uisimulator/sdl/sound.c216
-rw-r--r--uisimulator/sdl/uisdl.c19
-rw-r--r--uisimulator/sdl/uisdl.h11
-rw-r--r--uisimulator/win32/lcd-win32.c15
-rw-r--r--uisimulator/win32/sound.c46
-rw-r--r--uisimulator/x11/lcd-x11.c16
-rw-r--r--uisimulator/x11/sound.c45
11 files changed, 327 insertions, 146 deletions
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index d4862a0f85..b06c812772 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -32,49 +32,6 @@
#include "ata.h" /* for volume definitions */
extern char having_new_lcd;
-static bool playing = false;
-
-/* Stubs for PCM audio playback. */
-bool pcm_is_playing(void)
-{
- return playing;
-}
-
-void pcm_mute(bool state)
-{
- (void)state;
-}
-
-void pcm_play_pause(bool state)
-{
- (void)state;
-}
-
-bool pcm_is_paused(void)
-{
- return false;
-}
-
-void pcm_play_stop(void)
-{
- playing = false;
-}
-
-void pcm_init(void)
-{
-}
-
-void (*sound_get_pcm)(unsigned char** start, long* size);
-void pcm_play_data(void (*get_more)(unsigned char** start, long* size))
-{
- sound_get_pcm = get_more;
- playing = true;
-}
-
-long pcm_get_bytes_waiting(void)
-{
- return 0;
-}
#if CONFIG_CODEC != SWCODEC
void audio_set_buffer_margin(int seconds)
@@ -83,20 +40,6 @@ void audio_set_buffer_margin(int seconds)
}
#endif
-#ifdef CONFIG_BACKLIGHT
-void sim_backlight(int value)
-{
- DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off");
-}
-#endif
-
-#ifdef HAVE_REMOTE_LCD
-void sim_remote_backlight(int value)
-{
- DEBUGF("remote backlight: %s\n", (value > 0) ? "on" : "off");
-}
-#endif
-
int fat_startsector(void)
{
return 63;
diff --git a/uisimulator/sdl/lcd-bitmap.c b/uisimulator/sdl/lcd-bitmap.c
index db4a98d823..2fd7576ecc 100644
--- a/uisimulator/sdl/lcd-bitmap.c
+++ b/uisimulator/sdl/lcd-bitmap.c
@@ -17,13 +17,15 @@
*
****************************************************************************/
+#include "debug.h"
#include "uisdl.h"
#include "lcd-sdl.h"
SDL_Surface* lcd_surface;
#if LCD_DEPTH <= 8
-SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
+SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
+SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
SDL_Color lcd_color_max = {0, 0, 0, 0};
#endif
@@ -60,6 +62,22 @@ void lcd_update_rect(int x_start, int y_start, int width, int height)
get_lcd_pixel);
}
+#ifdef CONFIG_BACKLIGHT
+void sim_backlight(int value)
+{
+#if LCD_DEPTH <= 8
+ if (value > 0) {
+ sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, (1<<LCD_DEPTH));
+ } else {
+ sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH));
+ }
+
+ lcd_update();
+#else
+ DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off");
+#endif
+}
+#endif
/* initialise simulator lcd driver */
void sim_lcd_init(void)
diff --git a/uisimulator/sdl/lcd-charcell.c b/uisimulator/sdl/lcd-charcell.c
index 5f51e44810..2ef86d0baf 100644
--- a/uisimulator/sdl/lcd-charcell.c
+++ b/uisimulator/sdl/lcd-charcell.c
@@ -23,7 +23,8 @@
#include "lcd-sdl.h"
SDL_Surface* lcd_surface;
-SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
+SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
+SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
SDL_Color lcd_color_max = {0, 0, 0, 0};
/* Defined in lcd-playersim.c */
@@ -104,6 +105,19 @@ void drawrectangles(int color, struct rectangle *points, int count)
SDL_UnlockSurface(lcd_surface);
}
+#ifdef CONFIG_BACKLIGHT
+void sim_backlight(int value)
+{
+ if (value > 0) {
+ sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, (1<<LCD_DEPTH));
+ } else {
+ sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH));
+ }
+
+ lcd_update();
+}
+#endif
+
/* initialise simulator lcd driver */
void sim_lcd_init(void)
{
diff --git a/uisimulator/sdl/lcd-remote.c b/uisimulator/sdl/lcd-remote.c
index b5a07d2f20..5ce0447601 100644
--- a/uisimulator/sdl/lcd-remote.c
+++ b/uisimulator/sdl/lcd-remote.c
@@ -23,7 +23,8 @@
SDL_Surface *remote_surface;
-SDL_Color remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0};
+SDL_Color remote_color_zero = {UI_REMOTE_BGCOLOR, 0};
+SDL_Color remote_backlight_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0};
SDL_Color remote_color_max = {0, 0, 0, 0};
extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
@@ -44,6 +45,15 @@ void lcd_remote_update_rect(int x_start, int y_start, int width, int height)
(background ? UI_REMOTE_POSY : LCD_HEIGHT), get_lcd_remote_pixel);
}
+void sim_remote_backlight(int value)
+{
+ if (value > 0) {
+ sdl_set_gradient(remote_surface, &remote_backlight_color_zero, &remote_color_max, (1<<LCD_REMOTE_DEPTH));
+ } else {
+ sdl_set_gradient(remote_surface, &remote_color_zero, &remote_color_max, (1<<LCD_REMOTE_DEPTH));
+ }
+}
+
/* initialise simulator lcd remote driver */
void sim_lcd_remote_init(void)
{
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c
index 66df6961b2..4b8427ca90 100644
--- a/uisimulator/sdl/sound.c
+++ b/uisimulator/sdl/sound.c
@@ -21,88 +21,170 @@
#ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */
-#include <memory.h>
#include <stdlib.h>
-#include "uisdl.h"
+#include <stdbool.h>
+#include <memory.h>
#include "sound.h"
+#include "SDL.h"
+
+static bool pcm_playing;
+static bool pcm_paused;
-static int audio_len;
-static char *audio_pos;
-SDL_sem* sem;
+static Uint8* pcm_data;
+static int pcm_data_size;
-void mixaudio(void *udata, Uint8 *stream, int len)
+static void sdl_dma_start(const void *addr, size_t size)
{
- (void)udata;
-
- /* Only play if we have data left */
- if ( audio_len == 0 )
- return;
-
- len = (len > audio_len) ? audio_len : len;
- memcpy(stream, audio_pos, len);
- audio_pos += len;
- audio_len -= len;
-
- if(audio_len == 0) {
- if(SDL_SemPost(sem))
- fprintf(stderr,"Couldn't post: %s",SDL_GetError());
-
- }
+ pcm_playing = true;
+
+ pcm_data = (Uint8 *) addr;
+ pcm_data_size = size;
+
+ SDL_PauseAudio(0);
}
-int sim_sound_init(void)
+static void sdl_dma_stop()
{
- SDL_AudioSpec fmt;
-
- /* Set 16-bit stereo audio at 44Khz */
- fmt.freq = 44100;
- fmt.format = AUDIO_S16SYS;
- fmt.channels = 2;
- fmt.samples = 512; /* A good value for games */
- fmt.callback = mixaudio;
- fmt.userdata = NULL;
-
- sem = SDL_CreateSemaphore(0);
-
- /* Open the audio device and start playing sound! */
- if(SDL_OpenAudio(&fmt, NULL) < 0) {
- fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
- return -1;
- }
-
- SDL_PauseAudio(0);
- return 0;
+ pcm_playing = false;
+
+ SDL_PauseAudio(1);
+
+ pcm_paused = false;
}
-int sound_playback_thread(void *p)
+static void (*callback_for_more)(unsigned char**, size_t*) = NULL;
+void pcm_play_data(void (*get_more)(unsigned char** start, size_t* size),
+ unsigned char* start, size_t size)
{
- int sndret = sim_sound_init();
- unsigned char *buf;
- long size;
+ callback_for_more = get_more;
+
+ if (!(start && size)) {
+ if (get_more)
+ get_more(&start, &size);
+ else
+ return;
+ }
+
+ if (start && size) {
+ sdl_dma_start(start, size);
+ }
+}
- (void)p;
+size_t pcm_get_bytes_waiting(void)
+{
+ return pcm_data_size;
+}
- while(sndret)
- SDL_Delay(100000); /* wait forever, can't play sound! */
+void pcm_mute(bool mute)
+{
+ (void) mute;
+}
+
+void pcm_play_stop(void)
+{
+ if (pcm_playing) {
+ sdl_dma_stop();
+ }
+}
+
+void pcm_play_pause(bool play)
+{
+ int next_size;
+ Uint8 *next_start;
+
+ if (!pcm_playing) {
+ return;
+ }
+
+ if(pcm_paused && play) {
+ if (pcm_get_bytes_waiting()) {
+ printf("unpause\n");
+
+ SDL_PauseAudio(0);
+ } else {
+ printf("unpause, no data waiting\n");
+
+ void (*get_more)(unsigned char**, size_t*) = callback_for_more;
+
+ if (get_more) {
+ get_more(&next_start, &next_size);
+ }
+
+ if (next_start && next_size) {
+ sdl_dma_start(next_start, next_size);
+ } else {
+ sdl_dma_stop();
+ printf("unpause attempted, no data\n");
+ }
+ }
+ } else if(!pcm_paused && !play) {
+ printf("pause\n");
+
+ SDL_PauseAudio(1);
+ }
+
+ pcm_paused = !play;
+}
+
+bool pcm_is_paused(void)
+{
+ return pcm_paused;
+}
+
+bool pcm_is_playing(void)
+{
+ return pcm_playing;
+}
+
+void sdl_audio_callback(void *udata, Uint8 *stream, int len)
+{
+ int datalen;
+
+ (void) udata;
+
+ if (pcm_data_size == 0) {
+ return;
+ }
+
+ datalen = (len > pcm_data_size) ? pcm_data_size : len;
+
+ memcpy(stream, pcm_data, datalen);
+
+ pcm_data_size -= datalen;
+ pcm_data += datalen;
+
+ if (pcm_data_size == 0) {
+ void (*get_more)(unsigned char**, size_t*) = callback_for_more;
+ if (get_more) {
+ get_more(&pcm_data, &pcm_data_size);
+ } else {
+ pcm_data_size = 0;
+ pcm_data = NULL;
+ }
+ }
+}
+
+int pcm_init(void)
+{
+ SDL_AudioSpec fmt;
+
+ /* Set 16-bit stereo audio at 44Khz */
+ fmt.freq = 44100;
+ fmt.format = AUDIO_S16SYS;
+ fmt.channels = 2;
+ fmt.samples = 512;
+ fmt.callback = sdl_audio_callback;
+ fmt.userdata = NULL;
+
+ /* Open the audio device and start playing sound! */
+ if(SDL_OpenAudio(&fmt, NULL) < 0) {
+ fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
+ return -1;
+ }
- do {
- while(!sound_get_pcm)
- /* TODO: fix a fine thread-synch mechanism here */
- SDL_Delay(100);
- do {
- sound_get_pcm(&buf, &size);
- if(!size) {
- sound_get_pcm = NULL;
- break;
- }
- audio_pos = buf; // TODO: is this safe?
- audio_len = size;
-
- if(SDL_SemWait(sem))
- fprintf(stderr,"Couldn't wait: %s",SDL_GetError());
- } while(size);
- } while(1);
+ sdl_dma_stop();
+ return 0;
}
#endif /* ROCKBOX_HAS_SIMSOUND */
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
index 178090403f..1e36bfa223 100644
--- a/uisimulator/sdl/uisdl.c
+++ b/uisimulator/sdl/uisdl.c
@@ -23,7 +23,6 @@
#include "button.h"
#include "thread.h"
#include "kernel.h"
-#include "sound.h"
#include "uisdl.h"
#include "lcd-sdl.h"
#ifdef HAVE_LCD_BITMAP
@@ -50,9 +49,6 @@ bool background = false; /* Don't use backgrounds by default */
SDL_Thread *gui_thread;
SDL_TimerID tick_timer_id;
-#ifdef ROCKBOX_HAS_SIMSOUND
-SDL_Thread *sound_thread;
-#endif
bool lcd_display_redraw = true; /* Used for player simulator */
char having_new_lcd=true; /* Used for player simulator */
@@ -68,8 +64,7 @@ Uint32 tick_timer(Uint32 interval, void *param)
new_tick = (SDL_GetTicks() - start_tick) * HZ / 1000;
- if (new_tick != current_tick)
- {
+ if (new_tick != current_tick) {
long i;
for (i = new_tick - current_tick; i > 0; i--)
sim_tick_tasks();
@@ -171,9 +166,6 @@ bool gui_shutdown()
SDL_KillThread(gui_thread);
SDL_RemoveTimer(tick_timer_id);
-#ifdef ROCKBOX_HAS_SIMSOUND
- SDL_KillThread(sound_thread);
-#endif
for (i = 0; i < threadCount; i++)
{
@@ -223,7 +215,6 @@ int main(int argc, char *argv[])
background = false;
}
-
if (!gui_startup())
return -1;
@@ -235,14 +226,6 @@ int main(int argc, char *argv[])
tick_timer_id = SDL_AddTimer(10, tick_timer, NULL);
-#ifdef ROCKBOX_HAS_SIMSOUND
- sound_thread = SDL_CreateThread(sound_playback_thread, NULL);
- if (sound_thread == NULL) {
- printf("Error creating sound thread!\n");
- return -1;
- }
-#endif
-
gui_message_loop();
return gui_shutdown();
diff --git a/uisimulator/sdl/uisdl.h b/uisimulator/sdl/uisdl.h
index 989ca364d1..f4a28f9e0f 100644
--- a/uisimulator/sdl/uisdl.h
+++ b/uisimulator/sdl/uisdl.h
@@ -139,6 +139,16 @@
#define UI_LCD_WIDTH 176
#define UI_LCD_HEIGHT 132
+#elif defined(IPOD_VIDEO)
+#define UI_TITLE "iPod Video"
+#define UI_WIDTH 320 // width of GUI window
+#define UI_HEIGHT 240 // height of GUI window
+/* high-colour */
+#define UI_LCD_POSX 0 // x position of lcd
+#define UI_LCD_POSY 0 // y position of lcd
+#define UI_LCD_WIDTH 320
+#define UI_LCD_HEIGHT 240
+
#elif defined(ARCHOS_GMINI120)
#define UI_TITLE "Gmini 120"
#define UI_WIDTH 370 // width of GUI window
@@ -151,7 +161,6 @@
#define UI_LCD_WIDTH 192 // * 1.5
#define UI_LCD_HEIGHT 96 // * 1.5
-
#elif defined(IAUDIO_X5)
#define UI_TITLE "iAudio X5"
#define UI_WIDTH 300 // width of GUI window
diff --git a/uisimulator/win32/lcd-win32.c b/uisimulator/win32/lcd-win32.c
index a50fbd11f6..8afd025a16 100644
--- a/uisimulator/win32/lcd-win32.c
+++ b/uisimulator/win32/lcd-win32.c
@@ -22,6 +22,7 @@
#include "uisw32.h"
#include "lcd.h"
#include "lcd-playersim.h"
+#include "debug.h"
#if LCD_DEPTH == 16
unsigned short bitmap[LCD_HEIGHT][LCD_WIDTH]; /* the ui display */
@@ -309,3 +310,17 @@ void simlcdinit(void)
#endif
}
+#ifdef CONFIG_BACKLIGHT
+void sim_backlight(int value)
+{
+ DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off");
+}
+#endif
+
+#ifdef HAVE_REMOTE_LCD
+void sim_remote_backlight(int value)
+{
+ DEBUGF("remote backlight: %s\n", (value > 0) ? "on" : "off");
+}
+#endif
+
diff --git a/uisimulator/win32/sound.c b/uisimulator/win32/sound.c
index 02a5a888d9..54140f59e4 100644
--- a/uisimulator/win32/sound.c
+++ b/uisimulator/win32/sound.c
@@ -33,6 +33,8 @@
#include "thread-win32.h"
#include "debug.h"
+static bool playing = false;
+
void pcm_play_stop(void);
static void sound_play_chunk(HWAVEOUT wave_out, LPWAVEHDR header,
@@ -152,4 +154,48 @@ void sound_playback_thread(void)
}
}
+
+/* Stubs for PCM audio playback. */
+bool pcm_is_playing(void)
+{
+ return playing;
+}
+
+void pcm_mute(bool state)
+{
+ (void)state;
+}
+
+void pcm_play_pause(bool state)
+{
+ (void)state;
+}
+
+bool pcm_is_paused(void)
+{
+ return false;
+}
+
+void pcm_play_stop(void)
+{
+ playing = false;
+}
+
+void pcm_init(void)
+{
+}
+
+void (*sound_get_pcm)(unsigned char** start, long* size);
+void pcm_play_data(void (*get_more)(unsigned char** start, long* size))
+{
+ sound_get_pcm = get_more;
+ playing = true;
+}
+
+long pcm_get_bytes_waiting(void)
+{
+ return 0;
+}
+
+
#endif /* ROCKBOX_HAS_SIMSOUND */
diff --git a/uisimulator/x11/lcd-x11.c b/uisimulator/x11/lcd-x11.c
index 0a3b40e163..c85848c18b 100644
--- a/uisimulator/x11/lcd-x11.c
+++ b/uisimulator/x11/lcd-x11.c
@@ -32,6 +32,7 @@
#include "screenhack.h"
#include "config.h"
+#include "debug.h"
/*
* Specific implementations for X11, using the generic LCD API and data.
@@ -244,3 +245,18 @@ void lcd_update (void)
}
#endif
+
+#ifdef CONFIG_BACKLIGHT
+void sim_backlight(int value)
+{
+ DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off");
+}
+#endif
+
+#ifdef HAVE_REMOTE_LCD
+void sim_remote_backlight(int value)
+{
+ DEBUGF("remote backlight: %s\n", (value > 0) ? "on" : "off");
+}
+#endif
+
diff --git a/uisimulator/x11/sound.c b/uisimulator/x11/sound.c
index dd875e41f5..06d9c014ff 100644
--- a/uisimulator/x11/sound.c
+++ b/uisimulator/x11/sound.c
@@ -21,6 +21,7 @@
#ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -31,6 +32,8 @@
#include "sound.h"
+static bool playing = false;
+
int sim_sound_init(void)
{
int fd;
@@ -92,4 +95,46 @@ void sound_playback_thread(void)
}
+/* Stubs for PCM audio playback. */
+bool pcm_is_playing(void)
+{
+ return playing;
+}
+
+void pcm_mute(bool state)
+{
+ (void)state;
+}
+
+void pcm_play_pause(bool state)
+{
+ (void)state;
+}
+
+bool pcm_is_paused(void)
+{
+ return false;
+}
+
+void pcm_play_stop(void)
+{
+ playing = false;
+}
+
+void pcm_init(void)
+{
+}
+
+void (*sound_get_pcm)(unsigned char** start, long* size);
+void pcm_play_data(void (*get_more)(unsigned char** start, long* size))
+{
+ sound_get_pcm = get_more;
+ playing = true;
+}
+
+long pcm_get_bytes_waiting(void)
+{
+ return 0;
+}
+
#endif /* ROCKBOX_HAS_SIMSOUND */