diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2006-02-03 15:19:58 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2006-02-03 15:19:58 +0000 |
commit | fc72c5375813a6bbc0845aca984147a944a7e62a (patch) | |
tree | 347a6a9297f9f4d3131c8268f450d6ba227d0246 | |
parent | 347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4 (diff) |
Patch #1417462 by Dan Everton - Improved SDL simulator
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8546 a1c6a512-1295-4272-9138-f99709370657
29 files changed, 887 insertions, 1012 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 4943bc04e2..e18d8e6a57 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -71,7 +71,11 @@ typedef struct mydir MYDIR; #if 1 /* maybe this needs disabling for MSVC... */ static unsigned int rockbox2sim(int opt) { +#ifdef WIN32 + int newopt = O_BINARY; +#else int newopt = 0; +#endif if(opt & 1) newopt |= O_WRONLY; if(opt & 2) diff --git a/uisimulator/common/lcd-common.c b/uisimulator/common/lcd-common.c index 119c440318..a28e619706 100644 --- a/uisimulator/common/lcd-common.c +++ b/uisimulator/common/lcd-common.c @@ -24,7 +24,9 @@ #include "lcd.h" -#if defined(WIN32) && !defined(SDL) +#if defined(SDL) +#include "lcd-sdl.h" +#elif defined(WIN32) #include "lcd-win32.h" #else #include "lcd-x11.h" diff --git a/uisimulator/sdl/Makefile b/uisimulator/sdl/Makefile index 989ac65223..5c5693e98c 100644 --- a/uisimulator/sdl/Makefile +++ b/uisimulator/sdl/Makefile @@ -40,7 +40,7 @@ SOURCES = $(SRC) DIRS = . -CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) $(GCCOPTS) +CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) $(GCCOPTS) -W -Wall OUTFILE = $(BUILDDIR)/libsim.a @@ -48,13 +48,19 @@ all: $(OUTFILE) include $(TOOLSDIR)/make.inc +$(OUTFILE): $(OBJS) $(BUILDDIR)/UI256.bmp + @echo "AR $@" + @$(AR) ruv $@ $(OBJS) >/dev/null 2>&1 + clean: @echo "cleaning sim" - @$(RM) $(OBJS) *~ core $(OUTFILE) $(DEPFILE) + @$(RM) $(OBJS) *~ core $(OUTFILE) $(DEPFILE) \ + $(BUILDDIR)/UI256.bmp $(DEPFILE) @$(MAKE) -C $(SIMCOMMON) clean -$(OUTFILE): $(OBJS) - @echo "AR $@" - @$(AR) ruv $@ $(OBJS) >/dev/null 2>&1 +################## Specific dependencies ################## +$(BUILDDIR)/UI256.bmp: UI-$(ARCHOS).bmp + @echo UI + @cp $< $@ -include $(DEPFILE) diff --git a/uisimulator/sdl/SOURCES b/uisimulator/sdl/SOURCES index 32d70b50bf..cbb39a4e6a 100644 --- a/uisimulator/sdl/SOURCES +++ b/uisimulator/sdl/SOURCES @@ -1,7 +1,6 @@ -button-x11.c +button.c kernel.c -lcd-x11.c -screenhack.c -thread.c -uisdl.c +lcd-sdl.c sound.c +thread-sdl.c +uisdl.c diff --git a/uisimulator/sdl/UI-fmrecorder.bmp b/uisimulator/sdl/UI-fmrecorder.bmp Binary files differnew file mode 100644 index 0000000000..53f705b9ef --- /dev/null +++ b/uisimulator/sdl/UI-fmrecorder.bmp diff --git a/uisimulator/sdl/UI-gmini120.bmp b/uisimulator/sdl/UI-gmini120.bmp Binary files differnew file mode 100644 index 0000000000..afeaf74801 --- /dev/null +++ b/uisimulator/sdl/UI-gmini120.bmp diff --git a/uisimulator/sdl/UI-h100.bmp b/uisimulator/sdl/UI-h100.bmp Binary files differnew file mode 100644 index 0000000000..caeb81bc4b --- /dev/null +++ b/uisimulator/sdl/UI-h100.bmp diff --git a/uisimulator/sdl/UI-h120.bmp b/uisimulator/sdl/UI-h120.bmp Binary files differnew file mode 100644 index 0000000000..caeb81bc4b --- /dev/null +++ b/uisimulator/sdl/UI-h120.bmp diff --git a/uisimulator/sdl/UI-h300.bmp b/uisimulator/sdl/UI-h300.bmp Binary files differnew file mode 100644 index 0000000000..5f099b717a --- /dev/null +++ b/uisimulator/sdl/UI-h300.bmp diff --git a/uisimulator/sdl/UI-ipodcolor.bmp b/uisimulator/sdl/UI-ipodcolor.bmp Binary files differnew file mode 100644 index 0000000000..de5dad4ffe --- /dev/null +++ b/uisimulator/sdl/UI-ipodcolor.bmp diff --git a/uisimulator/sdl/UI-ipodnano.bmp b/uisimulator/sdl/UI-ipodnano.bmp Binary files differnew file mode 100644 index 0000000000..e33f7e81da --- /dev/null +++ b/uisimulator/sdl/UI-ipodnano.bmp diff --git a/uisimulator/sdl/UI-ondiofm.bmp b/uisimulator/sdl/UI-ondiofm.bmp Binary files differnew file mode 100644 index 0000000000..e258720d28 --- /dev/null +++ b/uisimulator/sdl/UI-ondiofm.bmp diff --git a/uisimulator/sdl/UI-ondiosp.bmp b/uisimulator/sdl/UI-ondiosp.bmp Binary files differnew file mode 100644 index 0000000000..c62c2334a3 --- /dev/null +++ b/uisimulator/sdl/UI-ondiosp.bmp diff --git a/uisimulator/sdl/UI-player.bmp b/uisimulator/sdl/UI-player.bmp Binary files differnew file mode 100644 index 0000000000..db4003b120 --- /dev/null +++ b/uisimulator/sdl/UI-player.bmp diff --git a/uisimulator/sdl/UI-recorder.bmp b/uisimulator/sdl/UI-recorder.bmp Binary files differnew file mode 100644 index 0000000000..98937fea2d --- /dev/null +++ b/uisimulator/sdl/UI-recorder.bmp diff --git a/uisimulator/sdl/UI-recorderv2.bmp b/uisimulator/sdl/UI-recorderv2.bmp Binary files differnew file mode 100644 index 0000000000..53f705b9ef --- /dev/null +++ b/uisimulator/sdl/UI-recorderv2.bmp diff --git a/uisimulator/sdl/button-x11.c b/uisimulator/sdl/button-x11.c deleted file mode 100644 index b0ab81a86a..0000000000 --- a/uisimulator/sdl/button-x11.c +++ /dev/null @@ -1,317 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Björn Stenberg - * - * 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. - * - ****************************************************************************/ -#include <stdlib.h> -#include "config.h" -#include "button.h" -#include "kernel.h" -#include "debug.h" -#include "backlight.h" -#include "misc.h" -#include <SDL.h> - -extern int screenhack_handle_events(bool *release); - -struct event_queue button_queue; - -static int button_state = 0; /* keeps track of pressed keys */ -static long lastbtn; /* Last valid button status */ - -/* how often we check to see if a button is pressed */ -#define POLL_FREQUENCY HZ/25 - -/* how long until repeat kicks in */ -#define REPEAT_START 8 - -/* the speed repeat starts at */ -#define REPEAT_INTERVAL_START 4 - -/* speed repeat finishes at */ -#define REPEAT_INTERVAL_FINISH 2 - -/* mostly copied from real button.c */ -void button_read (void); - -static void button_tick(void) -{ - static int tick = 0; - static int count = 0; - static int repeat_speed = REPEAT_INTERVAL_START; - static int repeat_count = 0; - static bool repeat = false; - int diff; - int btn; - - /* only poll every X ticks */ - if ( ++tick >= POLL_FREQUENCY ) - { - bool post = false; - button_read(); - btn = button_state; - - /* Find out if a key has been released */ - diff = btn ^ lastbtn; - if(diff && (btn & diff) == 0) - { - queue_post(&button_queue, BUTTON_REL | diff, NULL); - } - else - { - if ( btn ) - { - /* normal keypress */ - if ( btn != lastbtn ) - { - post = true; - repeat = false; - repeat_speed = REPEAT_INTERVAL_START; - - } - else /* repeat? */ - { - if ( repeat ) - { - count--; - if (count == 0) { - post = true; - /* yes we have repeat */ - repeat_speed--; - if (repeat_speed < REPEAT_INTERVAL_FINISH) - repeat_speed = REPEAT_INTERVAL_FINISH; - count = repeat_speed; - - repeat_count++; - - } - } - else - { - if (count++ > REPEAT_START) - { - post = true; - repeat = true; - repeat_count = 0; - /* initial repeat */ - count = REPEAT_INTERVAL_START; - } - } - } - if ( post ) - { - if (repeat) - queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); - else - queue_post(&button_queue, btn, NULL); -#ifdef HAVE_REMOTE_LCD - if(btn & BUTTON_REMOTE) - remote_backlight_on(); - else -#endif - backlight_on(); - - } - } - else - { - repeat = false; - count = 0; - } - } - lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); - tick = 0; - } -} - -/* - * Read SDL keys and translate to rockbox buttons - */ - -void button_read (void) -{ - int k; - bool release = false; /* is this a release event */ - int ev = screenhack_handle_events(&release); - - switch (ev) - { - case SDLK_KP4: - case SDLK_LEFT: - case SDLK_4: - k = BUTTON_LEFT; - break; - - case SDLK_KP6: - case SDLK_RIGHT: - case SDLK_6: - k = BUTTON_RIGHT; - break; - - case SDLK_KP8: - case SDLK_UP: - case SDLK_8: -#ifdef BUTTON_UP - k = BUTTON_UP; -#elif defined BUTTON_SCROLL_BACK - k = BUTTON_SCROLL_BACK; -#elif defined BUTTON_PLAY - k = BUTTON_PLAY; -#endif - break; - - case SDLK_KP2: - case SDLK_DOWN: - case SDLK_2: -#ifdef BUTTON_DOWN - k = BUTTON_DOWN; -#elif defined BUTTON_SCROLL_FWD - k = BUTTON_SCROLL_FWD; -#elif defined BUTTON_STOP - k = BUTTON_STOP; -#endif - break; - -#ifdef BUTTON_ON - case SDLK_KP_PLUS: - case SDLK_q: - k = BUTTON_ON; - break; -#endif - -#ifdef BUTTON_OFF - case SDLK_KP_ENTER: - case SDLK_a: - k = BUTTON_OFF; - break; -#endif - -#ifdef BUTTON_POWER - case SDLK_KP_MINUS: - case SDLK_p: - k = BUTTON_POWER; -#endif - -#ifdef BUTTON_F1 - case SDLK_KP_DIVIDE: - case SDLK_F1: - k = BUTTON_F1; - break; - - case SDLK_KP_MULTIPLY: - case SDLK_F2: - k = BUTTON_F2; - break; - - case SDLK_KP_MINUS: - case SDLK_F3: - k = BUTTON_F3; - break; -#elif defined(BUTTON_REC) - case SDLK_KP_DIVIDE: - case SDLK_F1: - k = BUTTON_REC; - break; -#endif - - case SDLK_KP5: - case SDLK_5: - case SDLK_SPACE: -#ifdef BUTTON_PLAY - k = BUTTON_PLAY; -#elif defined(BUTTON_SELECT) - k = BUTTON_SELECT; -#endif - break; - -#ifdef HAVE_LCD_BITMAP - case SDLK_7: - if(!release) - screen_dump(); - break; -#endif - - case SDLK_KP_PERIOD: - case SDLK_INSERT: -#ifdef BUTTON_MENU - k = BUTTON_MENU; -#elif defined(BUTTON_MODE) - k = BUTTON_MODE; -#endif - break; - - default: - k = 0; - if(ev) - DEBUGF("received ev %d\n", ev); - break; - } - - if (release) - button_state &= ~k; - else - button_state |= k; -} - -/* Again copied from real button.c... */ - -long button_get(bool block) -{ - struct event ev; - - if ( block || !queue_empty(&button_queue) ) - { - queue_wait(&button_queue, &ev); - return ev.id; - } - return BUTTON_NONE; -} - -long button_get_w_tmo(int ticks) -{ - struct event ev; - queue_wait_w_tmo(&button_queue, &ev, ticks); - return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE; -} - -void button_init(void) -{ - tick_add_task(button_tick); -} - -int button_status(void) -{ - return lastbtn; -} - -void button_clear_queue(void) -{ - queue_clear(&button_queue); -} - -#ifdef HAS_BUTTON_HOLD -bool button_hold(void) { - /* temp fix for hold button on irivers */ - return false; -} -#endif - -#ifdef HAS_REMOTE_BUTTON_HOLD -bool remote_button_hold(void) { - /* temp fix for hold button on irivers */ - return false; -} -#endif diff --git a/uisimulator/sdl/button.c b/uisimulator/sdl/button.c new file mode 100644 index 0000000000..5def88b9af --- /dev/null +++ b/uisimulator/sdl/button.c @@ -0,0 +1,275 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Felix Arends + * + * 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. + * + ****************************************************************************/ + +#include "uisdl.h" +#include "config.h" +#include "button.h" +#include "kernel.h" +#include "backlight.h" +#include "misc.h" + +/* how long until repeat kicks in */ +#define REPEAT_START 6 + +/* the speed repeat starts at */ +#define REPEAT_INTERVAL_START 4 + +/* speed repeat finishes at */ +#define REPEAT_INTERVAL_FINISH 2 + +struct event_queue button_queue; + +static int btn = 0; /* Hopefully keeps track of currently pressed keys... */ + +void button_event(int key, bool pressed) +{ + bool post = false; + int new_btn = 0; + int diff = 0; + static int count = 0; + static int lastbtn; + static int repeat_speed = REPEAT_INTERVAL_START; + static int repeat_count = 0; + static bool repeat = false; + + switch (key) + { + case SDLK_KP4: + case SDLK_LEFT: + new_btn = BUTTON_LEFT; + break; + case SDLK_KP6: + case SDLK_RIGHT: + new_btn = BUTTON_RIGHT; + break; + + case SDLK_KP8: + case SDLK_UP: +#ifdef BUTTON_UP + new_btn = BUTTON_UP; +#elif defined BUTTON_SCROLL_FWD + new_btn = BUTTON_SCROLL_FWD; +#elif defined BUTTON_PLAY + new_btn = BUTTON_PLAY; +#endif + break; + + case SDLK_KP2: + case SDLK_DOWN: +#ifdef BUTTON_DOWN + new_btn = BUTTON_DOWN; +#elif defined BUTTON_SCROLL_BACK + new_btn = BUTTON_SCROLL_BACK; +#elif defined BUTTON_STOP + new_btn = BUTTON_STOP; +#endif + break; + + case SDLK_KP_PLUS: +#ifdef BUTTON_ON + new_btn = BUTTON_ON; +#elif defined(BUTTON_SELECT) && defined(BUTTON_PLAY) + new_btn = BUTTON_PLAY; +#endif + break; + +#ifdef BUTTON_OFF + case SDLK_RETURN: + new_btn = BUTTON_OFF; + break; +#endif + +#ifdef BUTTON_F1 + case SDLK_KP_DIVIDE: + case SDLK_F1: + new_btn = BUTTON_F1; + break; + case SDLK_KP_MULTIPLY: + case SDLK_F2: + new_btn = BUTTON_F2; + break; + case SDLK_KP_MINUS: + case SDLK_F3: + new_btn = BUTTON_F3; + break; +#elif defined(BUTTON_REC) + case SDLK_KP_DIVIDE: + case SDLK_F1: + new_btn = BUTTON_REC; + break; +#endif + + case SDLK_KP5: + case SDLK_SPACE: +#if defined(BUTTON_PLAY) && !defined(BUTTON_SELECT) + new_btn = BUTTON_PLAY; +#elif defined(BUTTON_SELECT) + new_btn = BUTTON_SELECT; +#endif + break; + +#ifdef HAVE_LCD_BITMAP + case SDLK_KP0: + case SDLK_F5: + if(pressed) + { + screen_dump(); + return; + } + break; +#endif + + case SDLK_PERIOD: + case SDLK_INSERT: +#ifdef BUTTON_MENU + new_btn = BUTTON_MENU; +#elif defined(BUTTON_MODE) + new_btn = BUTTON_MODE; +#endif + break; + } + + if (pressed) + btn |= new_btn; + else + btn &= ~new_btn; + + /* Lots of stuff copied from real button.c. Not good, I think... */ + + /* Find out if a key has been released */ + diff = btn ^ lastbtn; + + if(diff && (btn & diff) == 0) + { + queue_post(&button_queue, BUTTON_REL | diff, NULL); + } + else + { + if ( btn ) + { + /* normal keypress */ + if ( btn != lastbtn ) + { + post = true; + repeat = false; + repeat_speed = REPEAT_INTERVAL_START; + + } + else /* repeat? */ + { + if ( repeat ) + { + count--; + if (count == 0) + { + post = true; + /* yes we have repeat */ + repeat_speed--; + if (repeat_speed < REPEAT_INTERVAL_FINISH) + repeat_speed = REPEAT_INTERVAL_FINISH; + count = repeat_speed; + + repeat_count++; + } + } + else + { + if (count++ > REPEAT_START) + { + post = true; + repeat = true; + repeat_count = 0; + /* initial repeat */ + count = REPEAT_INTERVAL_START; + } + } + } + if ( post ) + { + if(repeat) + queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); + else + queue_post(&button_queue, btn, NULL); + +#ifdef HAVE_REMOTE_LCD + if(btn & BUTTON_REMOTE) + remote_backlight_on(); + else +#endif + backlight_on(); + + } + } + else + { + repeat = false; + count = 0; + } + } + lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); +} + +/* Again copied from real button.c... */ + +long button_get(bool block) +{ + struct event ev; + + if ( block || !queue_empty(&button_queue) ) { + queue_wait(&button_queue, &ev); + return ev.id; + } + return BUTTON_NONE; +} + +long button_get_w_tmo(int ticks) +{ + struct event ev; + queue_wait_w_tmo(&button_queue, &ev, ticks); + return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE; +} + +void button_init(void) +{ +} + +int button_status(void) +{ + return btn; +} + +void button_clear_queue(void) +{ + queue_clear(&button_queue); +} + +#ifdef HAS_BUTTON_HOLD +bool button_hold(void) { + /* temp fix for hold button on irivers */ + return false; +} +#endif + +#ifdef HAS_REMOTE_BUTTON_HOLD +bool remote_button_hold(void) { + /* temp fix for hold button on irivers */ + return false; +} +#endif + diff --git a/uisimulator/sdl/kernel.c b/uisimulator/sdl/kernel.c index 947d82a550..2621ecebdd 100644 --- a/uisimulator/sdl/kernel.c +++ b/uisimulator/sdl/kernel.c @@ -7,7 +7,7 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2005 by Jens Arnold + * Copyright (C) 2002 by Felix Arends * * 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. @@ -17,11 +17,18 @@ * ****************************************************************************/ -#include <stddef.h> +#include <stdlib.h> +#include "uisdl.h" #include "kernel.h" +#include "thread-sdl.h" #include "thread.h" #include "debug.h" +/* (Daniel 2002-10-31) Mingw32 requires this errno variable to be present. + I'm not quite sure why and I don't know if this breaks the MSVC compile. + If it does, we should put this within #ifdef __MINGW32__ */ +int errno; + static void (*tick_funcs[MAX_NUM_TICK_TASKS])(void); int set_irq_level (int level) @@ -148,6 +155,7 @@ int tick_remove_task(void (*f)(void)) return -1; } +/* TODO: Implement mutexes for win32 */ void mutex_init(struct mutex *m) { (void)m; @@ -162,4 +170,3 @@ void mutex_unlock(struct mutex *m) { (void)m; } - diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c new file mode 100644 index 0000000000..758ab90ef9 --- /dev/null +++ b/uisimulator/sdl/lcd-sdl.c @@ -0,0 +1,291 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 Dan Everton + * + * 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. + * + ****************************************************************************/ + +#include "uisdl.h" +#include "lcd.h" +#include "lcd-playersim.h" + +SDL_Surface* lcd_surface; + +#if LCD_DEPTH == 16 +#else +SDL_Color lcd_palette[(1<<LCD_DEPTH)]; +SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; +SDL_Color lcd_color_max = {0, 0, 0, 0}; + +#endif + +#ifdef HAVE_LCD_BITMAP + +#ifdef HAVE_REMOTE_LCD +SDL_Surface *remote_surface; +SDL_Color remote_palette[(1<<LCD_REMOTE_DEPTH)]; +SDL_Color remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0}; +SDL_Color remote_color_max = {0, 0, 0, 0}; + +#endif + +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 x, y; + int xmax, ymax; + + ymax = y_start + height; + xmax = x_start + width; + + if(xmax > LCD_WIDTH) + xmax = LCD_WIDTH; + if(ymax >= LCD_HEIGHT) + ymax = LCD_HEIGHT; + + SDL_LockSurface(lcd_surface); + + int bpp = lcd_surface->format->BytesPerPixel; + + for (x = x_start; x < xmax; x++) + { + for (y = y_start; y < ymax; y++) + { + Uint8 *p = (Uint8 *)lcd_surface->pixels + y * lcd_surface->pitch + x * bpp; + +#if LCD_DEPTH == 1 + *(Uint32 *)p = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1); +#elif LCD_DEPTH == 2 + *(Uint32 *)p = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3); +#elif LCD_DEPTH == 16 +#if LCD_PIXELFORMAT == RGB565SWAPPED + unsigned bits = lcd_framebuffer[y][x]; + *(Uint32 *)p = (bits >> 8) | (bits << 8); +#else + *(Uint32 *)p = lcd_framebuffer[y][x]; +#endif +#endif + } + } + + SDL_UnlockSurface(lcd_surface); + + SDL_Rect src = {x_start, y_start, xmax, ymax}; + SDL_Rect dest = {UI_LCD_POSX + x_start, UI_LCD_POSY + y_start, xmax, ymax}; + + + SDL_BlitSurface(lcd_surface, &src, gui_surface, &dest); + SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); + SDL_Flip(gui_surface); + +} + +#ifdef HAVE_REMOTE_LCD + +extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; + +void lcd_remote_update (void) +{ + lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT); +} + +void lcd_remote_update_rect(int x_start, int y_start, + int width, int height) +{ + int x, y; + int xmax, ymax; + + ymax = y_start + height; + xmax = x_start + width; + + if(xmax > LCD_REMOTE_WIDTH) + xmax = LCD_REMOTE_WIDTH; + if(ymax >= LCD_REMOTE_HEIGHT) + ymax = LCD_REMOTE_HEIGHT; + + SDL_LockSurface(remote_surface); + + int bpp = remote_surface->format->BytesPerPixel; + + for (x = x_start; x < xmax; x++) + for (y = y_start; y < ymax; y++) + { + Uint8 *p = (Uint8 *)remote_surface->pixels + y * remote_surface->pitch + x * bpp; + + *(Uint32 *)p = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1); + } + + SDL_UnlockSurface(remote_surface); + + SDL_Rect src = {x_start, y_start, xmax, ymax}; + SDL_Rect dest = {UI_REMOTE_POSX + x_start, UI_REMOTE_POSY + y_start, xmax, ymax}; + + SDL_BlitSurface(remote_surface, &src, gui_surface, &dest); + SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); + SDL_Flip(gui_surface); + +} + +#endif /* HAVE_REMOTE_LCD */ +#endif /* HAVE_LCD_BITMAP */ + +#ifdef HAVE_LCD_CHARCELLS +/* Defined in lcd-playersim.c */ +extern void lcd_print_char(int x, int y); +extern bool lcd_display_redraw; +extern unsigned char hardware_buffer_lcd[11][2]; +static unsigned char lcd_buffer_copy[11][2]; + +void lcd_update(void) +{ + int x, y; + bool changed = false; + SDL_Rect dest = {UI_LCD_POSX, UI_LCD_POSY, UI_LCD_WIDTH, UI_LCD_HEIGHT}; + + for (y = 0; y < 2; y++) + { + for (x = 0; x < 11; x++) + { + if (lcd_display_redraw || + lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y]) + { + lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y]; + lcd_print_char(x, y); + changed = true; + } + } + } + if (changed) + { + SDL_BlitSurface(lcd_surface, NULL, gui_surface, &dest); + SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); + SDL_Flip(gui_surface); + } + lcd_display_redraw = false; +} + +void drawdots(int color, struct coordinate *points, int count) +{ + int bpp = lcd_surface->format->BytesPerPixel; + + SDL_LockSurface(lcd_surface); + + while (count--) + { + Uint8 *p = (Uint8 *)lcd_surface->pixels + (points[count].y) * lcd_surface->pitch + (points[count].x) * bpp; + + *p = color; + } + + SDL_UnlockSurface(lcd_surface); +} + +void drawrectangles(int color, struct rectangle *points, int count) +{ + int bpp = lcd_surface->format->BytesPerPixel; + + SDL_LockSurface(lcd_surface); + + while (count--) + { + int x; + int y; + int ix; + int iy; + + for (x = points[count].x, ix = 0; ix < points[count].width; x++, ix++) + { + for (y = points[count].y, iy = 0; iy < points[count].height; y++, iy++) + { + Uint8 *p = (Uint8 *)lcd_surface->pixels + y * lcd_surface->pitch + x * bpp; + + *p = color; + } + } + } + + SDL_UnlockSurface(lcd_surface); +} +#endif /* HAVE_LCD_CHARCELLS */ + +#if LCD_DEPTH <= 8 +/* set a range of bitmap indices to a gradient from startcolour to endcolour */ +void lcdcolors(int index, int count, SDL_Color *start, SDL_Color *end) +{ + int i; + + count--; + for (i = 0; i <= count; i++) + { + lcd_palette[i+index].r = start->r + + (end->r - start->r) * i / count; + lcd_palette[i+index].g = start->g + + (end->g - start->g) * i / count; + lcd_palette[i+index].b = start->b + + (end->b - start->b) * i / count; + } + + SDL_SetPalette(lcd_surface, SDL_LOGPAL|SDL_PHYSPAL, lcd_palette, index, count); +} +#endif + +#ifdef HAVE_REMOTE_LCD +/* set a range of bitmap indices to a gradient from startcolour to endcolour */ +void lcdremotecolors(int index, int count, SDL_Color *start, SDL_Color *end) +{ + int i; + + count--; + for (i = 0; i <= count; i++) + { + remote_palette[i+index].r = start->r + + (end->r - start->r) * i / count; + remote_palette[i+index].g = start->g + + (end->g - start->g) * i / count; + remote_palette[i+index].b = start->b + + (end->b - start->b) * i / count; + } + + SDL_SetPalette(remote_surface, SDL_LOGPAL|SDL_PHYSPAL, remote_palette, index, count); +} +#endif + +/* initialise simulator lcd driver */ +void simlcdinit(void) +{ +#if LCD_DEPTH == 16 + lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH, LCD_HEIGHT, 16, + 0, 0, 0, 0); +#else + lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH, LCD_HEIGHT, 8, + 0, 0, 0, 0); +#endif + +#if LCD_DEPTH <= 8 + lcdcolors(0, (1<<LCD_DEPTH), &lcd_color_zero, &lcd_color_max); +#endif + +#ifdef HAVE_REMOTE_LCD + remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, 8, + 0, 0, 0, 0); + + lcdremotecolors(0, (1<<LCD_REMOTE_DEPTH), &remote_color_zero, &remote_color_max); +#endif +} diff --git a/uisimulator/sdl/lcd-sdl.h b/uisimulator/sdl/lcd-sdl.h new file mode 100644 index 0000000000..312ae0d01f --- /dev/null +++ b/uisimulator/sdl/lcd-sdl.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 Dan Everton + * + * 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. + * + ****************************************************************************/ + +#ifndef __LCDSDL_H__ +#define __LCDSDL_H__ + +#include "uisdl.h" +#include "lcd.h" + +extern SDL_Surface* lcd_surface; +#if LCD_DEPTH <= 8 +extern SDL_Color lcd_palette[(1<<LCD_DEPTH)]; +#endif + +#ifdef HAVE_REMOTE_LCD +extern SDL_Surface* remote_surface; +extern SDL_Color remote_palette[(1<<LCD_REMOTE_DEPTH)]; +#endif + +void simlcdinit(void); + +#endif // #ifndef __LCDSDL_H__ + diff --git a/uisimulator/sdl/lcd-x11.c b/uisimulator/sdl/lcd-x11.c deleted file mode 100644 index c30d857d8c..0000000000 --- a/uisimulator/sdl/lcd-x11.c +++ /dev/null @@ -1,212 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 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. - * - ****************************************************************************/ - -#include <stdio.h> -#include <string.h> -#include <stdarg.h> -#include <stdlib.h> -#include <ctype.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#include <errno.h> -#include <ctype.h> -#include <time.h> - -#include "screenhack.h" -#include "system.h" -#include "config.h" - -/* - * Specific implementations for X11, using the generic LCD API and data. - */ - -#include "lcd-x11.h" -#include "lcd-playersim.h" - -#include <SDL.h> - -extern SDL_Surface *surface; - -extern void screen_resized(int width, int height); -extern bool lcd_display_redraw; - -#ifdef HAVE_LCD_BITMAP -#if LCD_DEPTH==16 -fb_data lcd_framebuffer_copy[LCD_HEIGHT][LCD_WIDTH*2]; -#else -fb_data lcd_framebuffer_copy[LCD_HEIGHT][LCD_WIDTH]; -#endif - -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 x; - int y; - int p=0; - int xmax; - int ymax; - int colors[LCD_WIDTH * LCD_HEIGHT]; - struct coordinate points[LCD_WIDTH * LCD_HEIGHT]; - -#if 0 - fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n", - counter++, x_start, y_start, width, height); -#endif - ymax = y_start + height; - xmax = x_start + width; - - if(xmax > LCD_WIDTH) - xmax = LCD_WIDTH; - if(ymax >= LCD_HEIGHT) - ymax = LCD_HEIGHT; - - for (x = x_start; x < xmax; x++) - for (y = y_start; y < ymax; y++) - { -#if LCD_DEPTH == 1 - Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255); - Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0); - points[p].x = x + MARGIN_X; - points[p].y = y + MARGIN_Y; - colors[p] = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1) ? sdl_black : sdl_white; -#elif LCD_DEPTH == 2 - unsigned gray = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3) * 85; - points[p].x = x + MARGIN_X; - points[p].y = y + MARGIN_Y; - colors[p] = SDL_MapRGB(surface->format, 255-gray, 255-gray, 255-gray); -#elif LCD_DEPTH == 16 -#if LCD_PIXELFORMAT == RGB565SWAPPED - unsigned short pixel = swap16(lcd_framebuffer[y][x]); - unsigned r = ((pixel >> 11) & 0x1f) << 3; - unsigned g = ((pixel >> 5) & 0x3f) << 2; - unsigned b = (pixel & 0x1f) << 3; - points[p].x = x + MARGIN_X; - points[p].y = y + MARGIN_Y; - colors[p] = SDL_MapRGB(surface->format, r, g, b); -#else - unsigned r = ((lcd_framebuffer[y][x] >> 11) & 0x1f) << 3; - unsigned g = ((lcd_framebuffer[y][x] >> 5) & 0x3f) << 2; - unsigned b = ((lcd_framebuffer[y][x]) & 0x1f) << 3; - points[p].x = x + MARGIN_X; - points[p].y = y + MARGIN_Y; - colors[p] = SDL_MapRGB(surface->format, r, g, b); -#endif -#endif - p++; - } - - dots(colors, &points[0], p); - /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/ - SDL_UpdateRect(surface, 0, 0, 0, 0); - lcd_display_redraw=false; -} - -#ifdef LCD_REMOTE_HEIGHT -extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; -unsigned char lcd_remote_framebuffer_copy[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; - -#define REMOTE_START_Y (LCD_HEIGHT + 2*MARGIN_Y) - -void lcd_remote_update (void) -{ - lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT); -} - -void lcd_remote_update_rect(int x_start, int y_start, - int width, int height) -{ - int x; - int y; - int p=0; - int xmax; - int ymax; - struct coordinate points[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT]; - int colors[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT]; - Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255); - Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0); - -#if 0 - fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n", - counter++, x_start, y_start, width, height); -#endif - ymax = y_start + height; - xmax = x_start + width; - - if(xmax > LCD_REMOTE_WIDTH) - xmax = LCD_REMOTE_WIDTH; - if(ymax >= LCD_REMOTE_HEIGHT) - ymax = LCD_REMOTE_HEIGHT; - - for (x = x_start; x < xmax; x++) - for (y = y_start; y < ymax; y++) { - colors[p] = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1) ? sdl_black : sdl_white; - points[p].x = x + MARGIN_X; - points[p].y = y + MARGIN_Y + REMOTE_START_Y; - p++; - } - - dots(colors, &points[0], p); - /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/ - SDL_UpdateRect(surface, 0, 0, 0, 0); - lcd_display_redraw=false; -} - - -#endif - -#endif -#ifdef HAVE_LCD_CHARCELLS - -/* Defined in lcd-playersim.c */ -extern void lcd_print_char(int x, int y); -extern unsigned char lcd_buffer[2][11]; - -extern unsigned char hardware_buffer_lcd[11][2]; -static unsigned char lcd_buffer_copy[11][2]; - -void lcd_update (void) -{ - bool changed=false; - int x, y; - for (y=0; y<2; y++) { - for (x=0; x<11; x++) { - if (lcd_display_redraw || - lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y]) { - lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y]; - lcd_print_char(x, y); - changed=true; - } - } - } - if (changed) - { - SDL_UpdateRect(surface, 0, 0, 0, 0); - } - lcd_display_redraw=false; -} - -#endif diff --git a/uisimulator/sdl/screenhack.c b/uisimulator/sdl/screenhack.c deleted file mode 100644 index ad138c282e..0000000000 --- a/uisimulator/sdl/screenhack.c +++ /dev/null @@ -1,232 +0,0 @@ -/* xscreensaver, Copyright (c) 1992, 1995, 1997, 1998 - * Jamie Zawinski <jwz@jwz.org> - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation. No representations are made about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * And remember: X Windows is to graphics hacking as roman numerals are to - * the square root of pi. - */ - -/* This file contains simple code to open a window or draw on the root. - The idea being that, when writing a graphics hack, you can just link - with this .o to get all of the uninteresting junk out of the way. - - - create a procedure `screenhack(dpy, window)' - - - create a variable `char *progclass' which names this program's - resource class. - - - create a variable `char defaults []' for the default resources, and - null-terminate it. - - - create a variable `XrmOptionDescRec options[]' for the command-line, - and null-terminate it. - - And that's it... - */ - -#include <stdio.h> -#include <string.h> -#include <SDL.h> -#include "lcd-x11.h" -#include "screenhack.h" -#include "version.h" - -#include "debug.h" -#include "config.h" - -#ifndef isupper -# define isupper(c) ((c) >= 'A' && (c) <= 'Z') -#endif -#ifndef _tolower -# define _tolower(c) ((c) - 'A' + 'a') -#endif - -#define KEYBOARD_GENERIC \ - "Keyboard Rockbox\n" \ - "-------- ------------\n" \ - "4, Left LEFT\n" \ - "6, Right RIGHT\n" - -#if CONFIG_KEYPAD == PLAYER_PAD -#define KEYBOARD_SPECIFIC \ - "8, Up PLAY\n" \ - "2, Down STOP\n" \ - "+, Q ON\n" \ - "., INS MENU\n" - -#elif CONFIG_KEYPAD == RECORDER_PAD -#define KEYBOARD_SPECIFIC \ - "8, Up UP\n" \ - "2, Down DOWN\n" \ - "5, Space PLAY\n" \ - "+, Q ON\n" \ - "Enter, A OFF\n" \ - "/, (F1) F1\n" \ - "*, (F2) F2\n" \ - "-, (F3) F3\n" - -#elif CONFIG_KEYPAD == ONDIO_PAD -#define KEYBOARD_SPECIFIC \ - "8, Up UP\n" \ - "2, Down DOWN\n" \ - "., INS MENU\n" \ - "Enter, A OFF\n" - -#elif CONFIG_KEYPAD == IRIVER_H100_PAD -#define KEYBOARD_SPECIFIC \ - "8, Up UP\n" \ - "2, Down DOWN\n" \ - "5, Space SELECT\n" \ - "+, Q ON\n" \ - "Enter, A OFF\n" \ - "., INS MODE\n" \ - "/, (F1) RECORD\n" - -#elif CONFIG_KEYPAD == IRIVER_H300_PAD -#define KEYBOARD_SPECIFIC \ - "8, Up UP\n" \ - "2, Down DOWN\n" \ - "4, Left LEFT\n" \ - "6, Right RIGHT\n" \ - "5, Space SELECT\n" \ - "+, Q ON\n" \ - "Enter, A OFF\n" \ - "., INS MODE\n" \ - "/, (F1) RECORD\n" - -#elif CONFIG_KEYPAD == GMINI100_PAD -#define KEYBOARD_SPECIFIC \ - "8, Up UP\n" \ - "2, Down DOWN\n" \ - "5, Space PLAY\n" \ - "+, Q ON\n" \ - "Enter, A OFF\n" \ - "., INS MENU\n" - -#elif (CONFIG_KEYPAD == IPOD_4G_PAD) -#define KEYBOARD_SPECIFIC \ - "[not written yet]" - -#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD) -#define KEYBOARD_SPECIFIC \ - "[not written yet]" - -#endif - - -SDL_Surface *surface; - -char having_new_lcd = true; - -extern int display_zoom; - -/* Dead-trivial event handling. - */ -int screenhack_handle_event(SDL_Event *event, bool *release) -{ - int key = 0; - - *release = false; - - switch (event->type) { - case SDL_KEYDOWN: - { - key = event->key.keysym.sym; - *release = false; - } - break; - case SDL_KEYUP: - { - key = event->key.keysym.sym; - *release = true; - } - break; - case SDL_QUIT: - { - SDL_Quit(); - exit(0); - } - break; - default: - break; - } - - return key; -} - -int screenhack_handle_events(bool *release) -{ - int key = 0; - SDL_Event event; - - if (SDL_PollEvent(&event)) { - key = screenhack_handle_event(&event, release); - } - - return key; -} - - -int main (int argc, char **argv) -{ - int window_width; - int window_height; - - if (argc > 1) - { - int x; - for (x=1; x<argc; x++) { - if (!strcmp("--old_lcd", argv[x])) { - having_new_lcd=false; - printf("Using old LCD layout.\n"); - } else if (!strcmp("--zoom", argv[x])) { - if (++x < argc) { - display_zoom=atoi(argv[x]); - printf("Window zoom is %d\n", display_zoom); - if (display_zoom < 1 || display_zoom > 5) { - printf("fatal: --zoom argument must be between 1 and 5\n"); - exit(0); - } - } else { - printf("fatal: --zoom requires an integer argument\n"); - exit(0); - } - } else { - printf("rockboxui\n"); - printf("Arguments:\n"); - printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n"); - printf(" --zoom [1-5]\t window zoom\n"); - printf(KEYBOARD_GENERIC KEYBOARD_SPECIFIC); - exit(0); - } - } - } - - window_width = (LCD_WIDTH + 2*MARGIN_X) * display_zoom; - window_height = (LCD_HEIGHT + 2*MARGIN_Y) * display_zoom; -#ifdef LCD_REMOTE_HEIGHT - window_height += (LCD_REMOTE_HEIGHT + 2*MARGIN_Y) * display_zoom; -#endif - - if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)) { - fprintf(stderr, "fatal: %s", SDL_GetError()); - exit(-1); - } - - atexit(SDL_Quit); - - if ((surface = SDL_SetVideoMode(window_width, window_height, 24, 0)) == NULL) { - fprintf(stderr, "fatal: %s", SDL_GetError()); - exit(-1); - } - - screenhack(); /* doesn't return */ - return 0; -} diff --git a/uisimulator/sdl/screenhack.h b/uisimulator/sdl/screenhack.h deleted file mode 100644 index 4c7a8307a4..0000000000 --- a/uisimulator/sdl/screenhack.h +++ /dev/null @@ -1,33 +0,0 @@ -/* xscreensaver, Copyright (c) 1992-1997 Jamie Zawinski <jwz@jwz.org> - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation. No representations are made about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - */ - -#ifndef __SCREENHACK_H__ -#define __SCREENHACK_H__ - -#include <stdlib.h> -#include <stdbool.h> - -#ifdef __hpux - /* Which of the ten billion standards does values.h belong to? - What systems always have it? */ -# include <values.h> -#endif - -#include <stdio.h> -#include <SDL.h> - -extern void screenhack(); -extern int screenhack_handle_event(SDL_Event*, bool *); -extern int screenhack_handle_events(bool *); -extern void screen_redraw(); -extern void screen_resized(); - -#endif /* __SCREENHACK_H__ */ diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c index 388b188448..66df6961b2 100644 --- a/uisimulator/sdl/sound.c +++ b/uisimulator/sdl/sound.c @@ -21,24 +21,15 @@ #ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */ -#include <stdio.h> +#include <memory.h> #include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <SDL.h> - +#include "uisdl.h" #include "sound.h" -//static Uint8 *audio_chunk; static int audio_len; static char *audio_pos; SDL_sem* sem; -/* The audio function callback takes the following parameters: - stream: A pointer to the audio buffer to be filled - len: The length (in bytes) of the audio buffer -*/ void mixaudio(void *udata, Uint8 *stream, int len) { (void)udata; @@ -59,8 +50,6 @@ void mixaudio(void *udata, Uint8 *stream, int len) } } - - int sim_sound_init(void) { SDL_AudioSpec fmt; @@ -80,15 +69,12 @@ int sim_sound_init(void) fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); return -1; } + SDL_PauseAudio(0); return 0; - - //... - - //SDL_CloseAudio(); } -int sound_playback_thread(void* p) +int sound_playback_thread(void *p) { int sndret = sim_sound_init(); unsigned char *buf; @@ -97,12 +83,12 @@ int sound_playback_thread(void* p) (void)p; while(sndret) - sleep(100000); /* wait forever, can't play sound! */ + SDL_Delay(100000); /* wait forever, can't play sound! */ do { while(!sound_get_pcm) /* TODO: fix a fine thread-synch mechanism here */ - usleep(10000); + SDL_Delay(100); do { sound_get_pcm(&buf, &size); if(!size) { @@ -111,11 +97,13 @@ int sound_playback_thread(void* p) } audio_pos = buf; // TODO: is this safe? audio_len = size; - //printf("len: %i\n",audio_len); + if(SDL_SemWait(sem)) fprintf(stderr,"Couldn't wait: %s",SDL_GetError()); } while(size); } while(1); + } #endif /* ROCKBOX_HAS_SIMSOUND */ + diff --git a/uisimulator/sdl/sprintf.h b/uisimulator/sdl/sprintf.h index 64a22f3c6e..24e1d4e352 100644 --- a/uisimulator/sdl/sprintf.h +++ b/uisimulator/sdl/sprintf.h @@ -1,12 +1,36 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Felix Arends + * + * 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. + * + ****************************************************************************/ + +#ifndef __SPRINTF_H__ +#define __SPRINTF_H__ + +#include <stddef.h> #include <stdarg.h> #include <stdio.h> -int rockbox_snprintf (char *buf, size_t size, const char *fmt, ...); -int rockbox_vsnprintf (char *buf, int size, const char *fmt, va_list ap); +int snprintf (char *buf, size_t size, const char *fmt, ...); +char *strtok_r (char *, const char *, char **); + int rockbox_fprintf (int fd, const char *fmt, ...); +#define fprintf rockbox_fprintf -#ifndef NO_REDEFINES_PLEASE -#define snprintf rockbox_snprintf +int rockbox_vsnprintf (char *buf, int size, const char *fmt, va_list ap); #define vsnprintf rockbox_vsnprintf -#define fprintf rockbox_fprintf -#endif + +#endif /* __SPRINTF_H__ */ diff --git a/uisimulator/sdl/thread-sdl.c b/uisimulator/sdl/thread-sdl.c new file mode 100644 index 0000000000..41a60c9bc5 --- /dev/null +++ b/uisimulator/sdl/thread-sdl.c @@ -0,0 +1,78 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 Dan Everton + * + * 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. + * + ****************************************************************************/ + +#include <time.h> +#include <SDL.h> +#include <SDL_thread.h> +#include <stdlib.h> +#include "thread-sdl.h" +#include "kernel.h" +#include "debug.h" + +SDL_Thread *threads[256]; +int threadCount = 0; +long current_tick = 0; +SDL_mutex *m; + +void yield(void) +{ + SDL_mutexV(m); + SDL_Delay(1); + SDL_mutexP(m); +} + +void sim_sleep(int ticks) +{ + SDL_mutexV(m); + SDL_Delay((1000/HZ) * ticks); + SDL_mutexP(m); +} + +int runthread(void *data) +{ + SDL_mutexV(m); + ((void(*)())data) (); + SDL_mutexV(m); + return 0; +} + +int create_thread(void (*fp)(void), void* sp, int stk_size) +{ + /** Avoid compiler warnings */ + (void)sp; + (void)stk_size; + + if (threadCount == 256) { + return -1; + } + + threads[threadCount++] = SDL_CreateThread(runthread, fp); + + return 0; +} + +void init_threads(void) +{ + m = SDL_CreateMutex(); + + if (SDL_mutexP(m) == -1) { + fprintf(stderr, "Couldn't lock mutex\n"); + exit(-1); + } +} diff --git a/uisimulator/sdl/lcd-x11.h b/uisimulator/sdl/thread-sdl.h index 07911b2530..a661f582a4 100644 --- a/uisimulator/sdl/lcd-x11.h +++ b/uisimulator/sdl/thread-sdl.h @@ -1,13 +1,13 @@ /*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> + * Copyright (C) 2006 Dan Everton * * 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. @@ -17,10 +17,7 @@ * ****************************************************************************/ -#define MARGIN_X 3 -#define MARGIN_Y 3 - -/* include the "real" lcd.h file here */ -#include <lcd.h> - +extern SDL_Thread* threads[256]; +extern int threadCount; +extern SDL_mutex* mutex; diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c index e17a925313..b55e3ee8ff 100644 --- a/uisimulator/sdl/uisdl.c +++ b/uisimulator/sdl/uisdl.c @@ -7,7 +7,7 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> + * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org> * * 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. @@ -16,211 +16,170 @@ * KIND, either express or implied. * ****************************************************************************/ -#include <stdio.h> -#include <string.h> -#include <stdarg.h> -#include <stdlib.h> -#include <ctype.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#include <errno.h> -#include <ctype.h> -#include <time.h> - -#include <SDL.h> - -#include "config.h" -#include "screenhack.h" - -#include "version.h" - -#include "lcd-x11.h" -#include "lcd-playersim.h" - -#define MAX(x,y) ((x)>(y)?(x):(y)) -#define MIN(x,y) ((x)<(y)?(x):(y)) - -#define PROGNAME "rockboxui" - -/* -- -- */ - -extern SDL_Surface *surface; -int display_zoom=2; +#include <stdlib.h> +#include "autoconf.h" +#include "uisdl.h" +#include "button.h" +#include "thread.h" +#include "thread-sdl.h" +#include "kernel.h" +#include "sound.h" + +// extern functions +extern void app_main (void *); // mod entry point +extern void new_key(int key); +extern void sim_tick_tasks(void); + +void button_event(int key, bool pressed); + +SDL_Surface *gui_surface; + +SDL_Thread *gui_thread; +SDL_TimerID tick_timer_id; +#ifdef ROCKBOX_HAS_SIMSOUND +SDL_Thread *sound_thread; +#endif -bool lcd_display_redraw=true; +bool lcd_display_redraw=true; // Used for player simulator +char having_new_lcd=true; // Used for player simulator -char *progclass = "rockboxui"; +long start_tick; -void init_window () +Uint32 tick_timer(Uint32 interval, void *param) { - /* stub */ -} + long new_tick; -/* used for the player sim */ -void drawdots(int color, struct coordinate *points, int count) -{ - SDL_Rect rect; + (void) interval; + (void) param; - while (count--) { - rect.x = points[count].x * display_zoom; - rect.y = points[count].y * display_zoom; - rect.w = display_zoom; - rect.h = display_zoom; + new_tick = (SDL_GetTicks() - start_tick) * HZ / 1000; - SDL_FillRect(surface, &rect, color); + if (new_tick != current_tick) + { + long i; + for (i = new_tick - current_tick; i > 0; i--) + sim_tick_tasks(); + current_tick = new_tick; } -} - -void drawrect(int color, int x1, int y1, int x2, int y2) -{ - SDL_Rect rect; - rect.x = x1 * display_zoom; - rect.y = y1 * display_zoom; - rect.w = (x2-x1) * display_zoom; - rect.h = (y2-y1) * display_zoom; - - SDL_FillRect(surface, &rect, color); + return 1; } -#if 0 -static void help(void) +void gui_message_loop(void) { - printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n" - "usage: " PROGNAME "\n"); + SDL_Event event; + bool done = false; + + while(!done && SDL_WaitEvent(&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); + break; + case SDL_QUIT: + done = true; + break; + default: + //printf("Unhandled event\n"); + break; + } + } } -#endif -void dots(int *colors, struct coordinate *points, int count) +bool gui_startup() { - int bpp = surface->format->BytesPerPixel; + SDL_Surface *picture_surface; - if (SDL_MUSTLOCK(surface)) { - if (SDL_LockSurface(surface)) { - fprintf(stderr, "cannot lock surface: %s", SDL_GetError()); - exit(-1); - } + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) { + fprintf(stderr, "fatal: %s", SDL_GetError()); + return false; } - while (count--) { - int x_off, y_off; + atexit(SDL_Quit); - for (x_off = 0; x_off < display_zoom; x_off++) { - for (y_off = 0; y_off < display_zoom; y_off++) { - int x = points[count].x*display_zoom + x_off; - int y = points[count].y*display_zoom + y_off; + if ((gui_surface = SDL_SetVideoMode(UI_WIDTH, UI_HEIGHT, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) { + fprintf(stderr, "fatal: %s", SDL_GetError()); + return false; + } - Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; + SDL_WM_SetCaption(UI_TITLE, NULL); - switch (bpp) { - case 1: - *p = colors[count]; - break; + simlcdinit(); - case 2: - *(Uint16 *)p = colors[count]; - break; + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - case 3: - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { - p[0] = (colors[count] >> 16) & 0xff; - p[1] = (colors[count] >> 8) & 0xff; - p[2] = (colors[count]) & 0xff; + picture_surface = SDL_LoadBMP("UI256.bmp"); + if (picture_surface == NULL) { + fprintf(stderr, "warn: %s", SDL_GetError()); } else { - p[2] = (colors[count] >> 16) & 0xff; - p[1] = (colors[count] >> 8) & 0xff; - p[0] = (colors[count]) & 0xff; + SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); + SDL_UpdateRect(gui_surface, 0, 0, 0, 0); } - break; - case 4: - *(Uint32 *)p = colors[count]; - break; - } - } - } - } - - if (SDL_MUSTLOCK(surface)) { - SDL_UnlockSurface(surface); - } + start_tick = SDL_GetTicks(); - SDL_UpdateRect(surface, 0, 0, 0, 0); + return true; } -/* this is where the applicaton starts */ -extern void app_main(void); - -void screenhack() +bool gui_shutdown() { -#if 0 - Bool helpme; + int i; - /* This doesn't work, but I don't know why (Daniel 1999-12-01) */ - helpme = get_boolean_resource ("help", "Boolean"); - if(helpme) - help(); + SDL_KillThread(gui_thread); + SDL_RemoveTimer(tick_timer_id); +#ifdef ROCKBOX_HAS_SIMSOUND + SDL_KillThread(sound_thread); #endif - printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n"); + for (i = 0; i < threadCount; i++) + { + SDL_KillThread(threads[i]); + } - init_window(); + return true; +} - screen_redraw(); +/** + * Thin wrapper around normal app_main() to stop gcc complaining about types. + */ +int sim_app_main(void *param) +{ + app_main(param); - app_main(); + return 0; } -/* used for the player sim */ -void drawrectangles(int color, struct rectangle *points, int count) +int main(int argc, char *argv[]) { - SDL_Rect rect; - Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255); - Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0); - - while (count--) { - rect.x = points[count].x * display_zoom; - rect.y = points[count].y * display_zoom; - rect.w = points[count].width * display_zoom; - rect.h = points[count].height * display_zoom; - - SDL_FillRect(surface, &rect, color ? sdl_white : sdl_black); + (void)argc; + (void)argv; + + if (!gui_startup()) + return -1; + + gui_thread = SDL_CreateThread(sim_app_main, NULL); + if (gui_thread == NULL) { + printf("Error creating GUI thread!\n"); + return -1; } -} + tick_timer_id = SDL_AddTimer(10, tick_timer, NULL); -void screen_redraw() -{ - /* draw a border around the screen */ - int X1 = 0; - int Y1 = 0; - int X2 = LCD_WIDTH + 2*MARGIN_X - 1; - int Y2 = LCD_HEIGHT + 2*MARGIN_Y - 1; - - drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y1, X2, Y1+1); - drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X2, Y1, X2+1, Y2); - drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y2, X2, Y2+1); - drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y1, X1+1, Y2); - - lcd_display_redraw = true; - lcd_update(); - -#ifdef LCD_REMOTE_HEIGHT - /* draw a border around the remote LCD screen */ - int RX1 = 0; - int RY1 = Y2 + 1; - int RX2 = LCD_REMOTE_WIDTH + 2*MARGIN_X - 1; - int RY2 = RY1 + LCD_REMOTE_HEIGHT + 2*MARGIN_Y - 1; - - drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY1, RX2, RY1+1); - drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX2, RY1, RX2+1, RY2); - drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY2, RX2, RY2+1); - drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY1, RX1+1, RY2); - - lcd_display_redraw = true; - lcd_remote_update(); +#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(); } + |