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
This commit is contained in:
Dan Everton 2006-02-13 21:46:28 +00:00
parent dd39e33663
commit 3ba0060ac1
11 changed files with 322 additions and 141 deletions

View file

@ -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;

View file

@ -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)

View file

@ -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)
{

View file

@ -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)
{

View file

@ -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 int audio_len;
static char *audio_pos;
SDL_sem* sem;
static bool pcm_playing;
static bool pcm_paused;
void mixaudio(void *udata, Uint8 *stream, int len)
static Uint8* pcm_data;
static int pcm_data_size;
static void sdl_dma_start(const void *addr, size_t size)
{
(void)udata;
pcm_playing = true;
/* Only play if we have data left */
if ( audio_len == 0 )
return;
pcm_data = (Uint8 *) addr;
pcm_data_size = size;
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());
}
SDL_PauseAudio(0);
}
int sim_sound_init(void)
static void sdl_dma_stop()
{
SDL_AudioSpec fmt;
pcm_playing = false;
/* 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;
SDL_PauseAudio(1);
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_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;
(void)p;
if (!(start && size)) {
if (get_more)
get_more(&start, &size);
else
return;
}
while(sndret)
SDL_Delay(100000); /* wait forever, can't play sound! */
if (start && size) {
sdl_dma_start(start, size);
}
}
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;
size_t pcm_get_bytes_waiting(void)
{
return pcm_data_size;
}
if(SDL_SemWait(sem))
fprintf(stderr,"Couldn't wait: %s",SDL_GetError());
} while(size);
} while(1);
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;
}
sdl_dma_stop();
return 0;
}
#endif /* ROCKBOX_HAS_SIMSOUND */

View file

@ -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();

View file

@ -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

View file

@ -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

View file

@ -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 */

View file

@ -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

View file

@ -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 */