summaryrefslogtreecommitdiff
path: root/uisimulator/sdl
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2006-02-09 11:17:52 +0000
committerDan Everton <dan@iocaine.org>2006-02-09 11:17:52 +0000
commitee2019d591980f44e5f7911a4382dcf855859b8f (patch)
treeeea2c51e818fafecfd377213c3a01b4faf74d6da /uisimulator/sdl
parent0cca6caa8a52bcfeb2a9d77a4b4f0593082417d7 (diff)
downloadrockbox-ee2019d591980f44e5f7911a4382dcf855859b8f.tar.gz
rockbox-ee2019d591980f44e5f7911a4382dcf855859b8f.zip
Made backgrounds runtime optional in SDL sim. Use --background to turn them on. Also removed two unneeded files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8642 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl')
-rw-r--r--uisimulator/sdl/lcd-sdl.c19
-rw-r--r--uisimulator/sdl/thread.c144
-rw-r--r--uisimulator/sdl/uisdl.c65
-rw-r--r--uisimulator/sdl/uisdl.h1
-rw-r--r--uisimulator/sdl/version.h1
5 files changed, 72 insertions, 158 deletions
diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c
index 80a3c96a87..1a6e8da8e8 100644
--- a/uisimulator/sdl/lcd-sdl.c
+++ b/uisimulator/sdl/lcd-sdl.c
@@ -94,7 +94,11 @@ void lcd_update_rect(int x_start, int y_start, int width, int height)
94 SDL_Rect src = {x_start, y_start, xmax, ymax}; 94 SDL_Rect src = {x_start, y_start, xmax, ymax};
95 SDL_Rect dest = {UI_LCD_POSX + x_start, UI_LCD_POSY + y_start, xmax, ymax}; 95 SDL_Rect dest = {UI_LCD_POSX + x_start, UI_LCD_POSY + y_start, xmax, ymax};
96 96
97 97 if (!background) {
98 dest.x -= UI_LCD_POSX;
99 dest.y -= UI_LCD_POSY;
100 }
101
98 SDL_BlitSurface(lcd_surface, &src, gui_surface, &dest); 102 SDL_BlitSurface(lcd_surface, &src, gui_surface, &dest);
99 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); 103 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
100 SDL_Flip(gui_surface); 104 SDL_Flip(gui_surface);
@@ -141,6 +145,12 @@ void lcd_remote_update_rect(int x_start, int y_start,
141 SDL_Rect src = {x_start, y_start, xmax, ymax}; 145 SDL_Rect src = {x_start, y_start, xmax, ymax};
142 SDL_Rect dest = {UI_REMOTE_POSX + x_start, UI_REMOTE_POSY + y_start, xmax, ymax}; 146 SDL_Rect dest = {UI_REMOTE_POSX + x_start, UI_REMOTE_POSY + y_start, xmax, ymax};
143 147
148 if (!background) {
149 dest.x -= UI_REMOTE_POSX;
150 dest.y -= UI_REMOTE_POSY;
151 dest.y += UI_LCD_HEIGHT;
152 }
153
144 SDL_BlitSurface(remote_surface, &src, gui_surface, &dest); 154 SDL_BlitSurface(remote_surface, &src, gui_surface, &dest);
145 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); 155 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
146 SDL_Flip(gui_surface); 156 SDL_Flip(gui_surface);
@@ -176,12 +186,19 @@ void lcd_update(void)
176 } 186 }
177 } 187 }
178 } 188 }
189
179 if (changed) 190 if (changed)
180 { 191 {
192 if (!background) {
193 dest.x -= UI_LCD_POSX;
194 dest.y -= UI_LCD_POSY;
195 }
196
181 SDL_BlitSurface(lcd_surface, NULL, gui_surface, &dest); 197 SDL_BlitSurface(lcd_surface, NULL, gui_surface, &dest);
182 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); 198 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
183 SDL_Flip(gui_surface); 199 SDL_Flip(gui_surface);
184 } 200 }
201
185 lcd_display_redraw = false; 202 lcd_display_redraw = false;
186} 203}
187 204
diff --git a/uisimulator/sdl/thread.c b/uisimulator/sdl/thread.c
deleted file mode 100644
index cb109b5f56..0000000000
--- a/uisimulator/sdl/thread.c
+++ /dev/null
@@ -1,144 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Daniel Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "autoconf.h"
21
22#include <stdio.h>
23
24/* SDL threading wrapper */
25#include <SDL.h>
26#include <SDL_thread.h>
27
28#include "kernel.h"
29#include <sys/time.h>
30
31#ifdef ROCKBOX_HAS_SIMSOUND
32#include "sound.h"
33#endif
34
35long current_tick = 0;
36extern void sim_tick_tasks(void);
37
38static void msleep(int msec)
39{
40 struct timeval delay;
41
42 delay.tv_sec = msec / 1000;
43 delay.tv_usec = (msec % 1000) * 1000;
44 select(0, NULL, NULL, NULL, &delay); /* portable sub-second sleep */
45}
46
47/*
48 * This is not a target thread, so it does not fall under the 1 thread at a
49 * time thing.
50 */
51static int update_tick_thread(void* p)
52{
53 struct timeval start, now;
54 long new_tick;
55
56 (void)p;
57
58 gettimeofday(&start, NULL);
59 while (1)
60 {
61 msleep(5); /* check twice per simulated target tick */
62 gettimeofday(&now, NULL);
63 new_tick = (now.tv_sec - start.tv_sec) * HZ
64 + (now.tv_usec - start.tv_usec) / (1000000/HZ);
65 if (new_tick > current_tick)
66 {
67 sim_tick_tasks();
68 current_tick = new_tick;
69 }
70 }
71}
72
73/*
74 * We emulate the target threads by using SDL threads. We have a mutex
75 * that only allows one thread at a time to execute. It forces each
76 * thread to yield() for the other(s) to run.
77 */
78
79SDL_mutex * mp;
80
81void init_threads(void)
82{
83 SDL_Thread *tick_tid;
84
85 mp=SDL_CreateMutex();
86 /* get mutex to only allow one thread running at a time */
87 SDL_mutexP(mp);
88
89 /* start a tick thread */
90 tick_tid=SDL_CreateThread(update_tick_thread, NULL);
91
92#ifdef ROCKBOX_HAS_SIMSOUND /* start thread that plays PCM data */
93 {
94 SDL_Thread *sound_tid;
95 sound_tid = SDL_CreateThread(sound_playback_thread, NULL);
96 }
97#endif
98
99}
100
101void yield(void)
102{
103 SDL_mutexV(mp); /* return */
104 msleep(1); /* prevent busy loop */
105 SDL_mutexP(mp); /* get it again */
106}
107
108void newfunc(void (*func)(void))
109{
110 SDL_mutexP(mp);
111 func();
112 SDL_mutexV(mp);
113}
114
115
116int create_thread(void (*fp)(void), void* sp, int stk_size)
117{
118 SDL_Thread * tid;
119 int i;
120 int error;
121
122 /* we really don't care about these arguments */
123 (void)sp;
124 (void)stk_size;
125 tid = SDL_CreateThread(
126 (int(*)(void *))newfunc, /* function to start */
127 fp /* start argument */);
128 if(0 == tid) /* don't really have an error number here. */
129 fprintf(stderr, "Couldn't run thread number %d\n", i);
130 else
131 fprintf(stderr, "Thread %d is running\n", (int)SDL_GetThreadID(tid));
132
133 yield();
134
135 return error;
136}
137
138void sim_sleep(int ticks)
139{
140 SDL_mutexV(mp); /* return */
141 msleep((1000/HZ) * ticks);
142 SDL_mutexP(mp); /* get it again */
143}
144
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
index b55e3ee8ff..2dd6b93122 100644
--- a/uisimulator/sdl/uisdl.c
+++ b/uisimulator/sdl/uisdl.c
@@ -18,6 +18,7 @@
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#include <stdlib.h> 20#include <stdlib.h>
21#include <string.h>
21#include "autoconf.h" 22#include "autoconf.h"
22#include "uisdl.h" 23#include "uisdl.h"
23#include "button.h" 24#include "button.h"
@@ -34,6 +35,7 @@ extern void sim_tick_tasks(void);
34void button_event(int key, bool pressed); 35void button_event(int key, bool pressed);
35 36
36SDL_Surface *gui_surface; 37SDL_Surface *gui_surface;
38bool background = false; /* Don't use backgrounds by default */
37 39
38SDL_Thread *gui_thread; 40SDL_Thread *gui_thread;
39SDL_TimerID tick_timer_id; 41SDL_TimerID tick_timer_id;
@@ -94,6 +96,7 @@ void gui_message_loop(void)
94bool gui_startup() 96bool gui_startup()
95{ 97{
96 SDL_Surface *picture_surface; 98 SDL_Surface *picture_surface;
99 int width, height;
97 100
98 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) { 101 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) {
99 fprintf(stderr, "fatal: %s", SDL_GetError()); 102 fprintf(stderr, "fatal: %s", SDL_GetError());
@@ -102,25 +105,47 @@ bool gui_startup()
102 105
103 atexit(SDL_Quit); 106 atexit(SDL_Quit);
104 107
105 if ((gui_surface = SDL_SetVideoMode(UI_WIDTH, UI_HEIGHT, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) { 108 /* Try and load the background image. If it fails go without */
106 fprintf(stderr, "fatal: %s", SDL_GetError()); 109 if (background) {
110 picture_surface = SDL_LoadBMP("UI256.bmp");
111 if (picture_surface == NULL) {
112 background = false;
113 fprintf(stderr, "warn: %s", SDL_GetError());
114 }
115 }
116
117 /* Set things up */
118
119 if (background) {
120 width = UI_WIDTH;
121 height = UI_HEIGHT;
122 } else {
123#ifdef HAVE_REMOTE_LCD
124 width = UI_LCD_WIDTH > UI_REMOTE_WIDTH ? UI_LCD_WIDTH : UI_REMOTE_WIDTH;
125 height = UI_LCD_HEIGHT + UI_REMOTE_HEIGHT;
126#else
127 width = UI_LCD_WIDTH;
128 height = UI_LCD_HEIGHT;
129#endif
130 }
131
132
133 if ((gui_surface = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
134 fprintf(stderr, "fatal: %s\n", SDL_GetError());
107 return false; 135 return false;
108 } 136 }
109 137
110 SDL_WM_SetCaption(UI_TITLE, NULL); 138 SDL_WM_SetCaption(UI_TITLE, NULL);
111 139
112 simlcdinit(); 140 simlcdinit();
113 141
114 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 142 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
115 143
116 picture_surface = SDL_LoadBMP("UI256.bmp"); 144 if (background && picture_surface != NULL) {
117 if (picture_surface == NULL) {
118 fprintf(stderr, "warn: %s", SDL_GetError());
119 } else {
120 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); 145 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
121 SDL_UpdateRect(gui_surface, 0, 0, 0, 0); 146 SDL_UpdateRect(gui_surface, 0, 0, 0, 0);
122 } 147 }
123 148
124 start_tick = SDL_GetTicks(); 149 start_tick = SDL_GetTicks();
125 150
126 return true; 151 return true;
@@ -156,8 +181,24 @@ int sim_app_main(void *param)
156 181
157int main(int argc, char *argv[]) 182int main(int argc, char *argv[])
158{ 183{
159 (void)argc; 184 if (argc >= 1) {
160 (void)argv; 185 int x;
186 for (x = 1; x < argc; x++) {
187 if (!strcmp("--background", argv[x])) {
188 background = true;
189 printf("Using background image.\n");
190 } else if (!strcmp("--old_lcd", argv[x])) {
191 having_new_lcd = false;
192 printf("Using old LCD layout.\n");
193 } else {
194 printf("rockboxui\n");
195 printf("Arguments:\n");
196 printf(" --background \t Use background image of hardware\n");
197 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
198 exit(0);
199 }
200 }
201 }
161 202
162 if (!gui_startup()) 203 if (!gui_startup())
163 return -1; 204 return -1;
diff --git a/uisimulator/sdl/uisdl.h b/uisimulator/sdl/uisdl.h
index ddf0a6ff86..25e31040cd 100644
--- a/uisimulator/sdl/uisdl.h
+++ b/uisimulator/sdl/uisdl.h
@@ -175,6 +175,7 @@
175#endif 175#endif
176 176
177extern SDL_Surface *gui_surface; 177extern SDL_Surface *gui_surface;
178extern bool background; /* True if the background image is enabled */
178 179
179#endif // #ifndef __UISDL_H__ 180#endif // #ifndef __UISDL_H__
180 181
diff --git a/uisimulator/sdl/version.h b/uisimulator/sdl/version.h
deleted file mode 100644
index 1d40c08781..0000000000
--- a/uisimulator/sdl/version.h
+++ /dev/null
@@ -1 +0,0 @@
1#define ROCKBOXUI_VERSION "0.2"