SDL simulator brought by Nathan Hand and Nick Lanham. This is added as a third

simulator with the hope that once it works fine, we can remove the other two
and only have one unified simulator.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8312 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2006-01-09 11:22:36 +00:00
parent d2a10f5676
commit 0e419987e4
26 changed files with 2181 additions and 7 deletions

View file

@ -88,6 +88,22 @@ else
endif
else # end of x11-simulator
ifeq ($(SIMVER), sdl)
###################################################
# This is the SDL simulator version
$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(BUILDDIR)/libcodec.a
@echo "LD "`basename $@`
@$(CC) $(CFLAGS) -shared $< -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@
ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
# 'x' must be kept or you'll have "Win32 error 5"
# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
# #define ERROR_ACCESS_DENIED 5L
else
@chmod -x $@
endif
else # end of sdl-simulator
###################################################
# This is the win32 simulator version
DLLTOOLFLAGS = --export-all
@ -106,6 +122,7 @@ else
@chmod -x $@
endif
endif # end of win32-simulator
endif
endif # end of simulator section

View file

@ -86,6 +86,22 @@ else
endif
else # end of x11-simulator
ifeq ($(SIMVER), sdl)
###################################################
# This is the SDL simulator version
$(OBJDIR)/%.rock : $(OBJDIR)/%.o $(BUILDDIR)/libplugin.a
@echo "LD "`basename $@`
@$(CC) $(CFLAGS) -shared $< -L$(BUILDDIR) $(CODECLIBS) -lplugin -o $@
ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
# 'x' must be kept or you'll have "Win32 error 5"
# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
# #define ERROR_ACCESS_DENIED 5L
else
@chmod -x $@
endif
else # end of sdl-simulator
###################################################
# This is the win32 simulator version
DLLTOOLFLAGS = --export-all
@ -104,6 +120,7 @@ else
@chmod -x $@
endif
endif # end of win32-simulator
endif
endif # end of simulator section

View file

@ -56,6 +56,22 @@ else
endif
else # end of x11-simulator
ifeq ($(SIMVER), sdl)
###################################################
# This is the SDL simulator version
$(OUTPUT): $(OBJS)
@echo "LD $<"
@$(CC) $(CFLAGS) -shared $(OBJS) -L$(BUILDDIR) -lplugin -o $@
ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
# 'x' must be kept or you'll have "Win32 error 5"
# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
# #define ERROR_ACCESS_DENIED 5L
else
@chmod -x $@
endif
else # end of sdl-simulator
###################################################
# This is the win32 simulator version
DLLTOOLFLAGS = --export-all
@ -74,7 +90,7 @@ else
@chmod -x $@
endif
endif # end of win32-simulator
endif
endif # end of simulator section

View file

@ -72,6 +72,22 @@ else
endif
else # end of x11-simulator
ifeq ($(SIMVER), sdl)
###################################################
# This is the sdl simulator version
$(OUTPUT): $(OBJS)
@echo "LD $@"
@$(CC) $(CFLAGS) -shared $(OBJS) -L$(BUILDDIR) -lplugin -o $@
ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
# 'x' must be kept or you'll have "Win32 error 5"
# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
# #define ERROR_ACCESS_DENIED 5L
else
@chmod -x $@
endif
else # end of sdl-simulator
###################################################
# This is the win32 simulator version
DLLTOOLFLAGS = --export-all
@ -90,7 +106,7 @@ else
@chmod -x $@
endif
endif # end of win32-simulator
endif
endif # end of simulator section

View file

@ -56,6 +56,22 @@ else
endif
else # end of x11-simulator
ifeq ($(SIMVER), sdl)
###################################################
# This is the SDL simulator version
$(OUTPUT): $(OBJS)
@echo "LD $<"
@$(CC) $(CFLAGS) -shared $(OBJS) -L$(BUILDDIR) -lplugin -o $@
ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
# 'x' must be kept or you'll have "Win32 error 5"
# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
# #define ERROR_ACCESS_DENIED 5L
else
@chmod -x $@
endif
else # end of sdl-simulator
###################################################
# This is the win32 simulator version
DLLTOOLFLAGS = --export-all
@ -74,7 +90,7 @@ else
@chmod -x $@
endif
endif # end of win32-simulator
endif
endif # end of simulator section

View file

@ -152,3 +152,5 @@ Anders Kagerin
Peter D'Hoye
Ben Basha
Brandon Low
Nathan Hand
Nick Lanham

21
tools/configure vendored
View file

@ -80,6 +80,11 @@ simcc () {
# win32 version
GCCOPTS="$GCCOPTS -mno-cygwin -DNOCYGWIN"
LDOPTS="-lgdi32 -luser32 -mno-cygwin"
elif [ "$simver" = "sdl" ]; then
# sdl version
GCCOPTS="$GCCOPTS `sdl-config --cflags`"
LDOPTS="`sdl-config --libs`"
checksoundcard
else
# x11 version
GCCOPTS="$GCCOPTS"
@ -92,10 +97,15 @@ simcc () {
Linux)
echo "Linux host detected"
GCCOPTS="$GCCOPTS"
LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -lnsl -ldl -lpthread'
if [ "$simver" = "win32" ]; then
LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -lnsl -ldl -lpthread'
crosswincc # setup cross-compiler
elif [ "$simver" = "sdl" ]; then
GCCOPTS="$GCCOPTS `sdl-config --cflags`"
LDOPTS="`sdl-config --libs`"
checksoundcard
else
LDOPTS='-L/usr/X11R6/lib -lX11 -lm -lXt -lXmu -lnsl -ldl -lpthread'
checksoundcard
fi # not a cross-compiler
;;
@ -247,7 +257,7 @@ if [ -z "$simver" ]; then
# Figure out win32/x11 GUI
#
echo ""
echo "Build (W)in32 or (X)11 GUI version? (X)"
echo "Build (W)in32 or (X)11 or (S)DL GUI version? (S)"
option=`input`;
@ -262,8 +272,13 @@ if [ -z "$simver" ]; then
# make sure the code knows this is for win32
extradefines="$extradefines -DWIN32"
;;
*)
[Xx])
simver="x11"
extradefines="$extradefines -DX11"
;;
[Ss]|*)
simver="sdl"
extradefines="$extradefines -DSDL"
;;
esac
echo "Selected $simver simulator"

View file

@ -18,3 +18,6 @@ x11/archos/rockbox112.bmp
common/SOURCES
win32/SOURCES
x11/SOURCES
sdl/*.[ch]
sdl/Makefile
sdl/SOURCES

60
uisimulator/sdl/Makefile Normal file
View file

@ -0,0 +1,60 @@
############################################################################
# __________ __ ___.
# 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.
#
############################################################################
SIMCOMMON = ../common
DEPFILE = $(OBJDIR)/dep-sim
RM = rm -f
DEBUG = -g
# Use this for simulator-only files
INCLUDES = -I. -I$(SIMCOMMON) -I$(OBJDIR) -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)
OUTFILE = $(BUILDDIR)/libsim.a
all: $(OUTFILE)
include $(TOOLSDIR)/make.inc
clean:
@echo "cleaning sim"
@$(RM) $(OBJS) *~ core $(OUTFILE) $(DEPFILE)
@$(MAKE) -C $(SIMCOMMON) clean
$(OUTFILE): $(OBJS)
@echo "AR $@"
@$(AR) ruv $@ $(OBJS) >/dev/null 2>&1
-include $(DEPFILE)

6
uisimulator/sdl/README Normal file
View file

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

7
uisimulator/sdl/SOURCES Normal file
View file

@ -0,0 +1,7 @@
button-x11.c
kernel.c
lcd-x11.c
screenhack.c
thread.c
uisdl.c
sound.c

View file

@ -0,0 +1,307 @@
/***************************************************************************
* __________ __ ___.
* 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_PLAY
k = BUTTON_PLAY;
#endif
break;
case SDLK_KP2:
case SDLK_DOWN:
case SDLK_2:
#ifdef BUTTON_DOWN
k = BUTTON_DOWN;
#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_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

160
uisimulator/sdl/kernel.c Normal file
View file

@ -0,0 +1,160 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 by Jens Arnold
*
* 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 <stddef.h>
#include "kernel.h"
#include "thread.h"
#include "debug.h"
static void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
int set_irq_level (int level)
{
static int _lv = 0;
return (_lv = level);
}
void queue_init(struct event_queue *q)
{
q->read = 0;
q->write = 0;
}
void queue_wait(struct event_queue *q, struct event *ev)
{
while(q->read == q->write)
{
switch_thread();
}
*ev = q->events[(q->read++) & QUEUE_LENGTH_MASK];
}
void queue_wait_w_tmo(struct event_queue *q, struct event *ev, int ticks)
{
unsigned int timeout = current_tick + ticks;
while(q->read == q->write && TIME_BEFORE( current_tick, timeout ))
{
sleep(1);
}
if(q->read != q->write)
{
*ev = q->events[(q->read++) & QUEUE_LENGTH_MASK];
}
else
{
ev->id = SYS_TIMEOUT;
}
}
void queue_post(struct event_queue *q, long id, void *data)
{
int wr;
int oldlevel;
oldlevel = set_irq_level(15<<4);
wr = (q->write++) & QUEUE_LENGTH_MASK;
q->events[wr].id = id;
q->events[wr].data = data;
set_irq_level(oldlevel);
}
bool queue_empty(const struct event_queue* q)
{
return ( q->read == q->write );
}
void queue_clear(struct event_queue* q)
{
/* fixme: This is potentially unsafe in case we do interrupt-like processing */
q->read = 0;
q->write = 0;
}
void switch_thread (void)
{
yield ();
}
void sim_tick_tasks(void)
{
int i;
/* Run through the list of tick tasks */
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
{
if(tick_funcs[i])
{
tick_funcs[i]();
}
}
}
int tick_add_task(void (*f)(void))
{
int i;
/* Add a task if there is room */
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
{
if(tick_funcs[i] == NULL)
{
tick_funcs[i] = f;
return 0;
}
}
DEBUGF("Error! tick_add_task(): out of tasks");
return -1;
}
int tick_remove_task(void (*f)(void))
{
int i;
/* Remove a task if it is there */
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
{
if(tick_funcs[i] == f)
{
tick_funcs[i] = NULL;
return 0;
}
}
return -1;
}
void mutex_init(struct mutex *m)
{
(void)m;
}
void mutex_lock(struct mutex *m)
{
(void)m;
}
void mutex_unlock(struct mutex *m)
{
(void)m;
}

210
uisimulator/sdl/lcd-x11.c Normal file
View file

@ -0,0 +1,210 @@
/***************************************************************************
* __________ __ ___.
* 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 "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) << 6;
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 b = ((lcd_framebuffer[y][x] >> 11) & 0x1f) << 3;
unsigned g = ((lcd_framebuffer[y][x] >> 5) & 0x3f) << 2;
unsigned r = ((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);
#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

26
uisimulator/sdl/lcd-x11.h Normal file
View file

@ -0,0 +1,26 @@
/***************************************************************************
* __________ __ ___.
* 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.
*
****************************************************************************/
#define MARGIN_X 3
#define MARGIN_Y 3
/* include the "real" lcd.h file here */
#include <lcd.h>

View file

@ -0,0 +1,228 @@
/* 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]"
#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;
}

View file

@ -0,0 +1,33 @@
/* 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__ */

119
uisimulator/sdl/sound.c Normal file
View file

@ -0,0 +1,119 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 by Nick Lanham
*
* 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 "autoconf.h"
#ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <SDL.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;
/* 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());
}
}
int sim_sound_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; /* 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;
//...
//SDL_CloseAudio();
}
void sound_playback_thread(void)
{
int sndret = sim_sound_init();
unsigned char *buf;
long size;
while(sndret)
sleep(100000); /* wait forever, can't play sound! */
do {
while(!sound_get_pcm)
/* TODO: fix a fine thread-synch mechanism here */
usleep(10000);
do {
sound_get_pcm(&buf, &size);
if(!size) {
sound_get_pcm = NULL;
break;
}
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 */

22
uisimulator/sdl/sound.h Normal file
View file

@ -0,0 +1,22 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 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.
*
****************************************************************************/
void sound_playback_thread(void);
extern void (*sound_get_pcm)(unsigned char** start, long* size);

12
uisimulator/sdl/sprintf.h Normal file
View file

@ -0,0 +1,12 @@
#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 rockbox_fprintf (int fd, const char *fmt, ...);
#ifndef NO_REDEFINES_PLEASE
#define snprintf rockbox_snprintf
#define vsnprintf rockbox_vsnprintf
#define fprintf rockbox_fprintf
#endif

148
uisimulator/sdl/thread.c Normal file
View file

@ -0,0 +1,148 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Daniel 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 "autoconf.h"
#include <stdio.h>
#include <pthread.h>
#include "kernel.h"
#include <sys/time.h>
#ifdef ROCKBOX_HAS_SIMSOUND
#include "sound.h"
#endif
long current_tick = 0;
extern void sim_tick_tasks(void);
static void msleep(int msec)
{
struct timeval delay;
delay.tv_sec = msec / 1000;
delay.tv_usec = (msec % 1000) * 1000;
select(0, NULL, NULL, NULL, &delay); /* portable sub-second sleep */
}
/*
* This is not a target thread, so it does not fall under the 1 thread at a
* time thing.
*/
static void update_tick_thread()
{
struct timeval start, now;
long new_tick;
gettimeofday(&start, NULL);
while (1)
{
msleep(5); /* check twice per simulated target tick */
gettimeofday(&now, NULL);
new_tick = (now.tv_sec - start.tv_sec) * HZ
+ (now.tv_usec - start.tv_usec) / (1000000/HZ);
if (new_tick > current_tick)
{
sim_tick_tasks();
current_tick = new_tick;
}
}
}
/*
* We emulate the target threads by using pthreads. We have a mutex that only
* allows one thread at a time to execute. It forces each thread to yield()
* for the other(s) to run.
*/
pthread_mutex_t mp;
void init_threads(void)
{
pthread_t tick_tid;
pthread_mutex_init(&mp, NULL);
/* get mutex to only allow one thread running at a time */
pthread_mutex_lock(&mp);
/* start a tick thread */
pthread_create(&tick_tid, NULL, (void *(*)(void *)) update_tick_thread,
NULL);
#ifdef ROCKBOX_HAS_SIMSOUND /* start thread that plays PCM data */
{
pthread_t sound_tid;
pthread_create(&sound_tid, NULL,
(void *(*)(void *)) sound_playback_thread,
NULL);
}
#endif
}
/*
int pthread_create(pthread_t *new_thread_ID,
const pthread_attr_t *attr,
void * (*start_func)(void *), void *arg);
*/
void yield(void)
{
pthread_mutex_unlock(&mp); /* return */
msleep(1); /* prevent busy loop */
pthread_mutex_lock(&mp); /* get it again */
}
void newfunc(void (*func)(void))
{
pthread_mutex_lock(&mp);
func();
pthread_mutex_unlock(&mp);
}
int create_thread(void (*fp)(void), void* sp, int stk_size)
{
pthread_t tid;
int i;
int error;
/* we really don't care about these arguments */
(void)sp;
(void)stk_size;
error = pthread_create(&tid,
NULL, /* default attributes please */
(void *(*)(void *)) newfunc, /* function to start */
fp /* start argument */);
if(0 != error)
fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
else
fprintf(stderr, "Thread %ld is running\n", (long)tid);
yield();
return error;
}
void sim_sleep(int ticks)
{
pthread_mutex_unlock(&mp); /* return */
msleep((1000/HZ) * ticks);
pthread_mutex_lock(&mp); /* get it again */
}

View file

@ -0,0 +1,7 @@
#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);

226
uisimulator/sdl/uisdl.c Normal file
View file

@ -0,0 +1,226 @@
/***************************************************************************
* __________ __ ___.
* 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 <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;
bool lcd_display_redraw=true;
char *progclass = "rockboxui";
void init_window ()
{
/* stub */
}
/* used for the player sim */
void drawdots(int color, struct coordinate *points, int count)
{
SDL_Rect rect;
while (count--) {
rect.x = points[count].x * display_zoom;
rect.y = points[count].y * display_zoom;
rect.w = display_zoom;
rect.h = display_zoom;
SDL_FillRect(surface, &rect, color);
}
}
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);
}
#if 0
static void help(void)
{
printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n"
"usage: " PROGNAME "\n");
}
#endif
void dots(int *colors, struct coordinate *points, int count)
{
int bpp = surface->format->BytesPerPixel;
if (SDL_MUSTLOCK(surface)) {
if (SDL_LockSurface(surface)) {
fprintf(stderr, "cannot lock surface: %s", SDL_GetError());
exit(-1);
}
}
while (count--) {
int x_off, y_off;
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;
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
switch (bpp) {
case 1:
*p = colors[count];
break;
case 2:
*(Uint16 *)p = colors[count];
break;
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;
} else {
p[2] = (colors[count] >> 16) & 0xff;
p[1] = (colors[count] >> 8) & 0xff;
p[0] = (colors[count]) & 0xff;
}
break;
case 4:
*(Uint32 *)p = colors[count];
break;
}
}
}
}
if (SDL_MUSTLOCK(surface)) {
SDL_UnlockSurface(surface);
}
SDL_UpdateRect(surface, 0, 0, 0, 0);
}
/* this is where the applicaton starts */
extern void app_main(void);
void screenhack()
{
#if 0
Bool helpme;
/* This doesn't work, but I don't know why (Daniel 1999-12-01) */
helpme = get_boolean_resource ("help", "Boolean");
if(helpme)
help();
#endif
printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n");
init_window();
screen_redraw();
app_main();
}
/* used for the player sim */
void drawrectangles(int color, struct rectangle *points, int count)
{
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 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();
#endif
}

344
uisimulator/sdl/uisw32.c Normal file
View file

@ -0,0 +1,344 @@
/***************************************************************************
* __________ __ ___.
* 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 <windows.h>
#include <process.h>
#include <stdlib.h>
#include <fcntl.h>
#include "autoconf.h"
#include "uisw32.h"
#include "resource.h"
#include "button.h"
#include "thread.h"
#include "thread-win32.h"
#include "kernel.h"
#include "sound.h"
#ifndef LR_VGACOLOR /* Should be under MINGW32 builds? */
#define LR_VGACOLOR LR_COLOR
#endif
// 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);
// variables
HWND hGUIWnd; // the GUI window handle
unsigned int uThreadID; // id of mod thread
PBYTE lpKeys;
bool bActive; // window active?
HANDLE hGUIThread; // thread for GUI
#ifdef ROCKBOX_HAS_SIMSOUND
HANDLE hSoundThread; // thread for sound
#endif
bool bIsWinNT; // Windows NT derivate?
bool lcd_display_redraw=true; // Used for player simulator
char having_new_lcd=true; // Used for player simulator
// GUIWndProc
// window proc for GUI simulator
LRESULT CALLBACK GUIWndProc (
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
static HBITMAP hBkgnd;
static HDC hMemDc;
static LARGE_INTEGER persec, tick1, ticknow;
long new_tick;
switch (uMsg)
{
case WM_TIMER:
QueryPerformanceCounter(&ticknow);
new_tick = ((ticknow.QuadPart-tick1.QuadPart)*HZ)/persec.QuadPart;
if (new_tick != current_tick)
{
long i;
for (i = new_tick - current_tick; i > 0; i--)
sim_tick_tasks();
current_tick = new_tick;
}
return TRUE;
case WM_ACTIVATE:
if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE)
bActive = true;
else
bActive = false;
return TRUE;
case WM_CREATE:
QueryPerformanceFrequency(&persec);
QueryPerformanceCounter(&tick1);
SetTimer (hWnd, TIMER_EVENT, 1, NULL);
// load background image
hBkgnd = (HBITMAP)LoadImage (GetModuleHandle (NULL),
MAKEINTRESOURCE(IDB_UI), IMAGE_BITMAP, 0, 0, LR_VGACOLOR);
hMemDc = CreateCompatibleDC (GetDC (hWnd));
SelectObject (hMemDc, hBkgnd);
return TRUE;
case WM_SIZING:
{
LPRECT r = (LPRECT)lParam;
char s[256];
int v;
int h_add = GetSystemMetrics (SM_CXSIZEFRAME) * 2 + 4;
int v_add = GetSystemMetrics (SM_CYSIZEFRAME) * 2
+ GetSystemMetrics (SM_CYCAPTION) + 4;
switch (wParam)
{
case WMSZ_BOTTOM:
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
r->right = r->left + v * UI_WIDTH / 5 + h_add;
break;
case WMSZ_RIGHT:
v = (r->right - r->left) / (UI_WIDTH / 5);
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
r->right = r->left + v * UI_WIDTH / 5 + h_add;
break;
case WMSZ_TOP:
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
r->top = r->bottom - v * UI_HEIGHT / 5 - v_add;
r->right = r->left + v * UI_WIDTH / 5 + h_add;
break;
case WMSZ_LEFT:
v = (r->right - r->left) / (UI_WIDTH / 5);
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
r->left = r->right - v * UI_WIDTH / 5 - h_add;
break;
case WMSZ_BOTTOMRIGHT:
v = ((r->right - r->left) * UI_HEIGHT
+(r->bottom - r->top) * UI_WIDTH)
/ (2 * UI_WIDTH * UI_HEIGHT / 5);
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
r->right = r->left + v * UI_WIDTH / 5 + h_add;
break;
case WMSZ_BOTTOMLEFT:
v = ((r->right - r->left) * UI_HEIGHT
+(r->bottom - r->top) * UI_WIDTH)
/ (2 * UI_WIDTH * UI_HEIGHT / 5);
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
r->left = r->right - v * UI_WIDTH / 5 - h_add;
break;
case WMSZ_TOPRIGHT:
v = ((r->right - r->left) * UI_HEIGHT
+(r->bottom - r->top) * UI_WIDTH)
/ (2 * UI_WIDTH * UI_HEIGHT / 5);
r->top = r->bottom - v * UI_HEIGHT / 5 - v_add;
r->right = r->left + v * UI_WIDTH / 5 + h_add;
break;
case WMSZ_TOPLEFT:
v = ((r->right - r->left) * UI_HEIGHT
+(r->bottom - r->top) * UI_WIDTH)
/ (2 * UI_WIDTH * UI_HEIGHT / 5);
r->top = r->bottom - v * UI_HEIGHT / 5 - v_add;
r->left = r->right - v * UI_WIDTH / 5 - h_add;
break;
}
wsprintf (s, UI_TITLE " @%d%%",
(r->right - r->left - h_add + 1) * 100 / UI_WIDTH);
SetWindowText (hWnd, s);
return TRUE;
}
case WM_ERASEBKGND:
{
HDC hDc = (HDC) wParam;
RECT r;
GetClientRect (hWnd, &r);
// blit background image to screen
SetStretchBltMode(hDc, bIsWinNT ? HALFTONE : COLORONCOLOR);
StretchBlt (hDc, 0, 0, r.right, r.bottom,
hMemDc, 0, 0, UI_WIDTH, UI_HEIGHT, SRCCOPY);
return TRUE;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
RECT r;
HDC hDc = BeginPaint (hWnd, &ps);
GetClientRect (hWnd, &r);
// draw lcd screen
SetStretchBltMode(hDc, bIsWinNT ? HALFTONE : COLORONCOLOR);
StretchDIBits (hDc,
UI_LCD_POSX * r.right / UI_WIDTH,
UI_LCD_POSY * r.bottom / UI_HEIGHT,
UI_LCD_WIDTH * r.right / UI_WIDTH,
UI_LCD_HEIGHT * r.bottom / UI_HEIGHT,
0, 0, LCD_WIDTH, LCD_HEIGHT,
bitmap, (BITMAPINFO *) &bmi, DIB_RGB_COLORS,
SRCCOPY);
#ifdef HAVE_REMOTE_LCD
StretchDIBits (hDc,
UI_REMOTE_POSX * r.right / UI_WIDTH,
UI_REMOTE_POSY * r.bottom / UI_HEIGHT,
UI_REMOTE_WIDTH * r.right / UI_WIDTH,
UI_REMOTE_HEIGHT * r.bottom / UI_HEIGHT,
0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
remote_bitmap, (BITMAPINFO *) &remote_bmi,
DIB_RGB_COLORS, SRCCOPY);
#endif
EndPaint (hWnd, &ps);
return TRUE;
}
case WM_CLOSE:
// close simulator
KillTimer (hWnd, TIMER_EVENT);
hGUIWnd = NULL;
PostQuitMessage (0);
break;
case WM_DESTROY:
// close simulator
hGUIWnd = NULL;
PostQuitMessage (0);
break;
case WM_KEYDOWN:
button_event(wParam, true);
break;
case WM_KEYUP:
button_event(wParam, false);
break;
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
// GUIStartup
// register window class, show window, init GUI
BOOL GUIStartup ()
{
WNDCLASS wc;
// create window class
ZeroMemory (&wc, sizeof(wc));
wc.hbrBackground = GetSysColorBrush (COLOR_WINDOW);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hInstance = GetModuleHandle (NULL);
wc.lpfnWndProc = GUIWndProc;
wc.lpszClassName = "RockBoxUISimulator";
wc.style = CS_HREDRAW | CS_VREDRAW;
if (RegisterClass (&wc) == 0)
return FALSE;
// create window
hGUIWnd = CreateWindowEx (
WS_EX_OVERLAPPEDWINDOW,
"RockBoxUISimulator", UI_TITLE,
WS_VISIBLE | WS_SYSMENU | WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
UI_WIDTH + GetSystemMetrics (SM_CXSIZEFRAME) * 2 +4,
UI_HEIGHT + GetSystemMetrics (SM_CYSIZEFRAME) * 2 +
GetSystemMetrics (SM_CYCAPTION) +4,
NULL, NULL, GetModuleHandle (NULL), NULL);
if (hGUIWnd == NULL)
return FALSE;
simlcdinit();
return TRUE;
}
// GUIDown
// destroy window, unregister window class
int GUIDown ()
{
int i;
DestroyWindow (hGUIWnd);
CloseHandle (hGUIThread);
#ifdef ROCKBOX_HAS_SIMSOUND
CloseHandle (hSoundThread);
#endif
for (i = 0; i < nThreads; i++)
{
CloseHandle (lpThreads[i]);
}
return 0;
}
// GUIMessageLoop
// standard message loop for GUI window
void GUIMessageLoop ()
{
MSG msg;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
// WinMain
// program entry point
int WINAPI WinMain (
HINSTANCE hInstance, // current instance
HINSTANCE hPrevInstance, // previous instance
LPSTR lpCmd, // command line
int nShowCmd // show command
)
{
DWORD dwThreadID;
(void)hInstance;
(void)hPrevInstance;
(void)lpCmd;
(void)nShowCmd;
/* default file mode should be O_BINARY to be consistent with rockbox */
_fmode = _O_BINARY;
bIsWinNT = ((GetVersion() & 0x80000000) == 0);
if (!GUIStartup ())
return 0;
hGUIThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)app_main,
NULL, 0, &dwThreadID);
if (hGUIThread == NULL)
return MessageBox (NULL, "Error creating gui thread!", "Error", MB_OK);
#ifdef ROCKBOX_HAS_SIMSOUND
hSoundThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)
sound_playback_thread, NULL, 0, &dwThreadID);
if (hSoundThread == NULL)
MessageBox (NULL, "Error creating sound thread!", "Warning", MB_OK);
#endif
GUIMessageLoop ();
return GUIDown ();
}

156
uisimulator/sdl/uisw32.h Normal file
View file

@ -0,0 +1,156 @@
/***************************************************************************
* __________ __ ___.
* 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 __UISW32_H__
#define __UISW32_H__
#ifdef _MSC_VER
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif
#include <windows.h>
#include "lcd-win32.h"
#if defined(ARCHOS_RECORDER)
#define UI_TITLE "Jukebox Recorder"
#define UI_WIDTH 270 // width of GUI window
#define UI_HEIGHT 406 // height of GUI window
#define UI_LCD_BGCOLOR 90, 145, 90 // bkgnd color of LCD (no backlight)
#define UI_LCD_BGCOLORLIGHT 126, 229, 126 // bkgnd color of LCD (backlight)
#define UI_LCD_BLACK 0, 0, 0 // black
#define UI_LCD_POSX 80 // x position of lcd
#define UI_LCD_POSY 104 // y position of lcd (96 for real aspect)
#define UI_LCD_WIDTH 112
#define UI_LCD_HEIGHT 64 // (80 for real aspect)
#elif defined(ARCHOS_PLAYER)
#define UI_TITLE "Jukebox Player"
#define UI_WIDTH 284 // width of GUI window
#define UI_HEIGHT 420 // height of GUI window
#define UI_LCD_BGCOLOR 90, 145, 90 // bkgnd color of LCD (no backlight)
#define UI_LCD_BGCOLORLIGHT 126, 229, 126 // bkgnd color of LCD (backlight)
#define UI_LCD_BLACK 0, 0, 0 // black
#define UI_LCD_POSX 75 // x position of lcd
#define UI_LCD_POSY 111 // y position of lcd
#define UI_LCD_WIDTH 132
#define UI_LCD_HEIGHT 75
#elif defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2)
#define UI_TITLE "Jukebox FM Recorder"
#define UI_WIDTH 285 // width of GUI window
#define UI_HEIGHT 414 // height of GUI window
#define UI_LCD_BGCOLOR 90, 145, 90 // bkgnd color of LCD (no backlight)
#define UI_LCD_BGCOLORLIGHT 126, 229, 126 // bkgnd color of LCD (backlight)
#define UI_LCD_BLACK 0, 0, 0 // black
#define UI_LCD_POSX 87 // x position of lcd
#define UI_LCD_POSY 77 // y position of lcd (69 for real aspect)
#define UI_LCD_WIDTH 112
#define UI_LCD_HEIGHT 64 // (80 for real aspect)
#elif defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM)
#define UI_TITLE "Ondio"
#define UI_WIDTH 155 // width of GUI window
#define UI_HEIGHT 334 // height of GUI window
#define UI_LCD_BGCOLOR 90, 145, 90 // bkgnd color of LCD (no backlight)
#define UI_LCD_BGCOLORLIGHT 90, 145, 90 // bkgnd color of LCD (backlight)
#define UI_LCD_BLACK 0, 0, 0 // black
#define UI_LCD_POSX 21 // x position of lcd
#define UI_LCD_POSY 82 // y position of lcd (74 for real aspect)
#define UI_LCD_WIDTH 112
#define UI_LCD_HEIGHT 64 // (80 for real aspect)
#elif defined(IRIVER_H100_SERIES)
#define UI_TITLE "iriver H1x0"
#define UI_WIDTH 379 // width of GUI window
#define UI_HEIGHT 508 // height of GUI window
#define UI_LCD_BGCOLOR 90, 145, 90 // bkgnd color of LCD (no backlight)
#define UI_LCD_BGCOLORLIGHT 230, 216, 173 // bkgnd color of LCD (backlight)
#define UI_LCD_BLACK 0, 0, 0 // black
#define UI_LCD_POSX 109 // x position of lcd
#define UI_LCD_POSY 23 // y position of lcd
#define UI_LCD_WIDTH 160
#define UI_LCD_HEIGHT 128
#define UI_REMOTE_BGCOLOR 90, 145, 90 // bkgnd of remote lcd (no bklight)
#define UI_REMOTE_BGCOLORLIGHT 250, 180, 130 // bkgnd of remote lcd (bklight)
#define UI_REMOTE_POSX 50 // x position of remote lcd
#define UI_REMOTE_POSY 403 // y position of remote lcd
#define UI_REMOTE_WIDTH 128
#define UI_REMOTE_HEIGHT 64
#elif defined(IRIVER_H300_SERIES)
#define UI_TITLE "iriver H300"
#define UI_WIDTH 288 // width of GUI window
#define UI_HEIGHT 581 // height of GUI window
/* high-colour */
#define UI_LCD_POSX 26 // x position of lcd
#define UI_LCD_POSY 36 // y position of lcd
#define UI_LCD_WIDTH 220
#define UI_LCD_HEIGHT 176
#define UI_REMOTE_BGCOLOR 90, 145, 90 // bkgnd of remote lcd (no bklight)
#define UI_REMOTE_BGCOLORLIGHT 250, 180, 130 // bkgnd of remote lcd (bklight)
#define UI_REMOTE_POSX 12 // x position of remote lcd
#define UI_REMOTE_POSY 478 // y position of remote lcd
#define UI_REMOTE_WIDTH 128
#define UI_REMOTE_HEIGHT 64
#elif defined(IPOD_COLOR)
#define UI_TITLE "iPod Color"
#define UI_WIDTH 261 // width of GUI window
#define UI_HEIGHT 493 // height of GUI window
/* high-colour */
#define UI_LCD_POSX 21 // x position of lcd
#define UI_LCD_POSY 16 // y position of lcd
#define UI_LCD_WIDTH 220
#define UI_LCD_HEIGHT 176
#elif defined(IPOD_NANO)
#define UI_TITLE "iPod Nano"
#define UI_WIDTH 199 // width of GUI window
#define UI_HEIGHT 421 // height of GUI window
/* high-colour */
#define UI_LCD_POSX 13 // x position of lcd
#define UI_LCD_POSY 14 // y position of lcd
#define UI_LCD_WIDTH 176
#define UI_LCD_HEIGHT 132
#elif defined(ARCHOS_GMINI120)
#define UI_TITLE "Gmini 120"
#define UI_WIDTH 370 // width of GUI window
#define UI_HEIGHT 264 // height of GUI window
#define UI_LCD_BGCOLOR 90, 145, 90 // bkgnd color of LCD (no backlight)
#define UI_LCD_BGCOLORLIGHT 230, 160, 60 // bkgnd color of LCD (backlight)
#define UI_LCD_BLACK 0, 0, 0 // black
#define UI_LCD_POSX 85 // x position of lcd
#define UI_LCD_POSY 61 // y position of lcd (74 for real aspect)
#define UI_LCD_WIDTH 192 // * 1.5
#define UI_LCD_HEIGHT 96 // * 1.5
#endif
#define TIMER_EVENT 0x34928340
extern HWND hGUIWnd; // the GUI window handle
extern unsigned int uThreadID; // id of mod thread
extern bool bActive;
// typedefs
typedef unsigned char uchar;
typedef unsigned int uint32;
#endif // #ifndef __UISW32_H__

View file

@ -0,0 +1 @@
#define ROCKBOXUI_VERSION "0.2"