diff options
Diffstat (limited to 'uisimulator/sdl')
-rw-r--r-- | uisimulator/sdl/lcd-bitmap.c | 20 | ||||
-rw-r--r-- | uisimulator/sdl/lcd-charcell.c | 16 | ||||
-rw-r--r-- | uisimulator/sdl/lcd-remote.c | 12 | ||||
-rw-r--r-- | uisimulator/sdl/sound.c | 216 | ||||
-rw-r--r-- | uisimulator/sdl/uisdl.c | 19 | ||||
-rw-r--r-- | uisimulator/sdl/uisdl.h | 11 |
6 files changed, 205 insertions, 89 deletions
diff --git a/uisimulator/sdl/lcd-bitmap.c b/uisimulator/sdl/lcd-bitmap.c index db4a98d823..2fd7576ecc 100644 --- a/uisimulator/sdl/lcd-bitmap.c +++ b/uisimulator/sdl/lcd-bitmap.c | |||
@@ -17,13 +17,15 @@ | |||
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include "debug.h" | ||
20 | #include "uisdl.h" | 21 | #include "uisdl.h" |
21 | #include "lcd-sdl.h" | 22 | #include "lcd-sdl.h" |
22 | 23 | ||
23 | SDL_Surface* lcd_surface; | 24 | SDL_Surface* lcd_surface; |
24 | 25 | ||
25 | #if LCD_DEPTH <= 8 | 26 | #if LCD_DEPTH <= 8 |
26 | SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; | 27 | SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; |
28 | SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; | ||
27 | SDL_Color lcd_color_max = {0, 0, 0, 0}; | 29 | SDL_Color lcd_color_max = {0, 0, 0, 0}; |
28 | #endif | 30 | #endif |
29 | 31 | ||
@@ -60,6 +62,22 @@ void lcd_update_rect(int x_start, int y_start, int width, int height) | |||
60 | get_lcd_pixel); | 62 | get_lcd_pixel); |
61 | } | 63 | } |
62 | 64 | ||
65 | #ifdef CONFIG_BACKLIGHT | ||
66 | void sim_backlight(int value) | ||
67 | { | ||
68 | #if LCD_DEPTH <= 8 | ||
69 | if (value > 0) { | ||
70 | sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); | ||
71 | } else { | ||
72 | sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); | ||
73 | } | ||
74 | |||
75 | lcd_update(); | ||
76 | #else | ||
77 | DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off"); | ||
78 | #endif | ||
79 | } | ||
80 | #endif | ||
63 | 81 | ||
64 | /* initialise simulator lcd driver */ | 82 | /* initialise simulator lcd driver */ |
65 | void sim_lcd_init(void) | 83 | void sim_lcd_init(void) |
diff --git a/uisimulator/sdl/lcd-charcell.c b/uisimulator/sdl/lcd-charcell.c index 5f51e44810..2ef86d0baf 100644 --- a/uisimulator/sdl/lcd-charcell.c +++ b/uisimulator/sdl/lcd-charcell.c | |||
@@ -23,7 +23,8 @@ | |||
23 | #include "lcd-sdl.h" | 23 | #include "lcd-sdl.h" |
24 | 24 | ||
25 | SDL_Surface* lcd_surface; | 25 | SDL_Surface* lcd_surface; |
26 | SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; | 26 | SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; |
27 | SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; | ||
27 | SDL_Color lcd_color_max = {0, 0, 0, 0}; | 28 | SDL_Color lcd_color_max = {0, 0, 0, 0}; |
28 | 29 | ||
29 | /* Defined in lcd-playersim.c */ | 30 | /* Defined in lcd-playersim.c */ |
@@ -104,6 +105,19 @@ void drawrectangles(int color, struct rectangle *points, int count) | |||
104 | SDL_UnlockSurface(lcd_surface); | 105 | SDL_UnlockSurface(lcd_surface); |
105 | } | 106 | } |
106 | 107 | ||
108 | #ifdef CONFIG_BACKLIGHT | ||
109 | void sim_backlight(int value) | ||
110 | { | ||
111 | if (value > 0) { | ||
112 | sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); | ||
113 | } else { | ||
114 | sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); | ||
115 | } | ||
116 | |||
117 | lcd_update(); | ||
118 | } | ||
119 | #endif | ||
120 | |||
107 | /* initialise simulator lcd driver */ | 121 | /* initialise simulator lcd driver */ |
108 | void sim_lcd_init(void) | 122 | void sim_lcd_init(void) |
109 | { | 123 | { |
diff --git a/uisimulator/sdl/lcd-remote.c b/uisimulator/sdl/lcd-remote.c index b5a07d2f20..5ce0447601 100644 --- a/uisimulator/sdl/lcd-remote.c +++ b/uisimulator/sdl/lcd-remote.c | |||
@@ -23,7 +23,8 @@ | |||
23 | 23 | ||
24 | SDL_Surface *remote_surface; | 24 | SDL_Surface *remote_surface; |
25 | 25 | ||
26 | SDL_Color remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0}; | 26 | SDL_Color remote_color_zero = {UI_REMOTE_BGCOLOR, 0}; |
27 | SDL_Color remote_backlight_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0}; | ||
27 | SDL_Color remote_color_max = {0, 0, 0, 0}; | 28 | SDL_Color remote_color_max = {0, 0, 0, 0}; |
28 | 29 | ||
29 | extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; | 30 | extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; |
@@ -44,6 +45,15 @@ void lcd_remote_update_rect(int x_start, int y_start, int width, int height) | |||
44 | (background ? UI_REMOTE_POSY : LCD_HEIGHT), get_lcd_remote_pixel); | 45 | (background ? UI_REMOTE_POSY : LCD_HEIGHT), get_lcd_remote_pixel); |
45 | } | 46 | } |
46 | 47 | ||
48 | void sim_remote_backlight(int value) | ||
49 | { | ||
50 | if (value > 0) { | ||
51 | sdl_set_gradient(remote_surface, &remote_backlight_color_zero, &remote_color_max, (1<<LCD_REMOTE_DEPTH)); | ||
52 | } else { | ||
53 | sdl_set_gradient(remote_surface, &remote_color_zero, &remote_color_max, (1<<LCD_REMOTE_DEPTH)); | ||
54 | } | ||
55 | } | ||
56 | |||
47 | /* initialise simulator lcd remote driver */ | 57 | /* initialise simulator lcd remote driver */ |
48 | void sim_lcd_remote_init(void) | 58 | void sim_lcd_remote_init(void) |
49 | { | 59 | { |
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c index 66df6961b2..4b8427ca90 100644 --- a/uisimulator/sdl/sound.c +++ b/uisimulator/sdl/sound.c | |||
@@ -21,88 +21,170 @@ | |||
21 | 21 | ||
22 | #ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */ | 22 | #ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */ |
23 | 23 | ||
24 | #include <memory.h> | ||
25 | #include <stdlib.h> | 24 | #include <stdlib.h> |
26 | #include "uisdl.h" | 25 | #include <stdbool.h> |
26 | #include <memory.h> | ||
27 | #include "sound.h" | 27 | #include "sound.h" |
28 | #include "SDL.h" | ||
29 | |||
30 | static bool pcm_playing; | ||
31 | static bool pcm_paused; | ||
28 | 32 | ||
29 | static int audio_len; | 33 | static Uint8* pcm_data; |
30 | static char *audio_pos; | 34 | static int pcm_data_size; |
31 | SDL_sem* sem; | ||
32 | 35 | ||
33 | void mixaudio(void *udata, Uint8 *stream, int len) | 36 | static void sdl_dma_start(const void *addr, size_t size) |
34 | { | 37 | { |
35 | (void)udata; | 38 | pcm_playing = true; |
36 | 39 | ||
37 | /* Only play if we have data left */ | 40 | pcm_data = (Uint8 *) addr; |
38 | if ( audio_len == 0 ) | 41 | pcm_data_size = size; |
39 | return; | 42 | |
40 | 43 | SDL_PauseAudio(0); | |
41 | len = (len > audio_len) ? audio_len : len; | ||
42 | memcpy(stream, audio_pos, len); | ||
43 | audio_pos += len; | ||
44 | audio_len -= len; | ||
45 | |||
46 | if(audio_len == 0) { | ||
47 | if(SDL_SemPost(sem)) | ||
48 | fprintf(stderr,"Couldn't post: %s",SDL_GetError()); | ||
49 | |||
50 | } | ||
51 | } | 44 | } |
52 | 45 | ||
53 | int sim_sound_init(void) | 46 | static void sdl_dma_stop() |
54 | { | 47 | { |
55 | SDL_AudioSpec fmt; | 48 | pcm_playing = false; |
56 | 49 | ||
57 | /* Set 16-bit stereo audio at 44Khz */ | 50 | SDL_PauseAudio(1); |
58 | fmt.freq = 44100; | 51 | |
59 | fmt.format = AUDIO_S16SYS; | 52 | pcm_paused = false; |
60 | fmt.channels = 2; | ||
61 | fmt.samples = 512; /* A good value for games */ | ||
62 | fmt.callback = mixaudio; | ||
63 | fmt.userdata = NULL; | ||
64 | |||
65 | sem = SDL_CreateSemaphore(0); | ||
66 | |||
67 | /* Open the audio device and start playing sound! */ | ||
68 | if(SDL_OpenAudio(&fmt, NULL) < 0) { | ||
69 | fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); | ||
70 | return -1; | ||
71 | } | ||
72 | |||
73 | SDL_PauseAudio(0); | ||
74 | return 0; | ||
75 | } | 53 | } |
76 | 54 | ||
77 | int sound_playback_thread(void *p) | 55 | static void (*callback_for_more)(unsigned char**, size_t*) = NULL; |
56 | void pcm_play_data(void (*get_more)(unsigned char** start, size_t* size), | ||
57 | unsigned char* start, size_t size) | ||
78 | { | 58 | { |
79 | int sndret = sim_sound_init(); | 59 | callback_for_more = get_more; |
80 | unsigned char *buf; | 60 | |
81 | long size; | 61 | if (!(start && size)) { |
62 | if (get_more) | ||
63 | get_more(&start, &size); | ||
64 | else | ||
65 | return; | ||
66 | } | ||
67 | |||
68 | if (start && size) { | ||
69 | sdl_dma_start(start, size); | ||
70 | } | ||
71 | } | ||
82 | 72 | ||
83 | (void)p; | 73 | size_t pcm_get_bytes_waiting(void) |
74 | { | ||
75 | return pcm_data_size; | ||
76 | } | ||
84 | 77 | ||
85 | while(sndret) | 78 | void pcm_mute(bool mute) |
86 | SDL_Delay(100000); /* wait forever, can't play sound! */ | 79 | { |
80 | (void) mute; | ||
81 | } | ||
82 | |||
83 | void pcm_play_stop(void) | ||
84 | { | ||
85 | if (pcm_playing) { | ||
86 | sdl_dma_stop(); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void pcm_play_pause(bool play) | ||
91 | { | ||
92 | int next_size; | ||
93 | Uint8 *next_start; | ||
94 | |||
95 | if (!pcm_playing) { | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | if(pcm_paused && play) { | ||
100 | if (pcm_get_bytes_waiting()) { | ||
101 | printf("unpause\n"); | ||
102 | |||
103 | SDL_PauseAudio(0); | ||
104 | } else { | ||
105 | printf("unpause, no data waiting\n"); | ||
106 | |||
107 | void (*get_more)(unsigned char**, size_t*) = callback_for_more; | ||
108 | |||
109 | if (get_more) { | ||
110 | get_more(&next_start, &next_size); | ||
111 | } | ||
112 | |||
113 | if (next_start && next_size) { | ||
114 | sdl_dma_start(next_start, next_size); | ||
115 | } else { | ||
116 | sdl_dma_stop(); | ||
117 | printf("unpause attempted, no data\n"); | ||
118 | } | ||
119 | } | ||
120 | } else if(!pcm_paused && !play) { | ||
121 | printf("pause\n"); | ||
122 | |||
123 | SDL_PauseAudio(1); | ||
124 | } | ||
125 | |||
126 | pcm_paused = !play; | ||
127 | } | ||
128 | |||
129 | bool pcm_is_paused(void) | ||
130 | { | ||
131 | return pcm_paused; | ||
132 | } | ||
133 | |||
134 | bool pcm_is_playing(void) | ||
135 | { | ||
136 | return pcm_playing; | ||
137 | } | ||
138 | |||
139 | void sdl_audio_callback(void *udata, Uint8 *stream, int len) | ||
140 | { | ||
141 | int datalen; | ||
142 | |||
143 | (void) udata; | ||
144 | |||
145 | if (pcm_data_size == 0) { | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | datalen = (len > pcm_data_size) ? pcm_data_size : len; | ||
150 | |||
151 | memcpy(stream, pcm_data, datalen); | ||
152 | |||
153 | pcm_data_size -= datalen; | ||
154 | pcm_data += datalen; | ||
155 | |||
156 | if (pcm_data_size == 0) { | ||
157 | void (*get_more)(unsigned char**, size_t*) = callback_for_more; | ||
158 | if (get_more) { | ||
159 | get_more(&pcm_data, &pcm_data_size); | ||
160 | } else { | ||
161 | pcm_data_size = 0; | ||
162 | pcm_data = NULL; | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | |||
167 | int pcm_init(void) | ||
168 | { | ||
169 | SDL_AudioSpec fmt; | ||
170 | |||
171 | /* Set 16-bit stereo audio at 44Khz */ | ||
172 | fmt.freq = 44100; | ||
173 | fmt.format = AUDIO_S16SYS; | ||
174 | fmt.channels = 2; | ||
175 | fmt.samples = 512; | ||
176 | fmt.callback = sdl_audio_callback; | ||
177 | fmt.userdata = NULL; | ||
178 | |||
179 | /* Open the audio device and start playing sound! */ | ||
180 | if(SDL_OpenAudio(&fmt, NULL) < 0) { | ||
181 | fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); | ||
182 | return -1; | ||
183 | } | ||
87 | 184 | ||
88 | do { | 185 | sdl_dma_stop(); |
89 | while(!sound_get_pcm) | ||
90 | /* TODO: fix a fine thread-synch mechanism here */ | ||
91 | SDL_Delay(100); | ||
92 | do { | ||
93 | sound_get_pcm(&buf, &size); | ||
94 | if(!size) { | ||
95 | sound_get_pcm = NULL; | ||
96 | break; | ||
97 | } | ||
98 | audio_pos = buf; // TODO: is this safe? | ||
99 | audio_len = size; | ||
100 | |||
101 | if(SDL_SemWait(sem)) | ||
102 | fprintf(stderr,"Couldn't wait: %s",SDL_GetError()); | ||
103 | } while(size); | ||
104 | } while(1); | ||
105 | 186 | ||
187 | return 0; | ||
106 | } | 188 | } |
107 | 189 | ||
108 | #endif /* ROCKBOX_HAS_SIMSOUND */ | 190 | #endif /* ROCKBOX_HAS_SIMSOUND */ |
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c index 178090403f..1e36bfa223 100644 --- a/uisimulator/sdl/uisdl.c +++ b/uisimulator/sdl/uisdl.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include "button.h" | 23 | #include "button.h" |
24 | #include "thread.h" | 24 | #include "thread.h" |
25 | #include "kernel.h" | 25 | #include "kernel.h" |
26 | #include "sound.h" | ||
27 | #include "uisdl.h" | 26 | #include "uisdl.h" |
28 | #include "lcd-sdl.h" | 27 | #include "lcd-sdl.h" |
29 | #ifdef HAVE_LCD_BITMAP | 28 | #ifdef HAVE_LCD_BITMAP |
@@ -50,9 +49,6 @@ bool background = false; /* Don't use backgrounds by default */ | |||
50 | 49 | ||
51 | SDL_Thread *gui_thread; | 50 | SDL_Thread *gui_thread; |
52 | SDL_TimerID tick_timer_id; | 51 | SDL_TimerID tick_timer_id; |
53 | #ifdef ROCKBOX_HAS_SIMSOUND | ||
54 | SDL_Thread *sound_thread; | ||
55 | #endif | ||
56 | 52 | ||
57 | bool lcd_display_redraw = true; /* Used for player simulator */ | 53 | bool lcd_display_redraw = true; /* Used for player simulator */ |
58 | char having_new_lcd=true; /* Used for player simulator */ | 54 | char having_new_lcd=true; /* Used for player simulator */ |
@@ -68,8 +64,7 @@ Uint32 tick_timer(Uint32 interval, void *param) | |||
68 | 64 | ||
69 | new_tick = (SDL_GetTicks() - start_tick) * HZ / 1000; | 65 | new_tick = (SDL_GetTicks() - start_tick) * HZ / 1000; |
70 | 66 | ||
71 | if (new_tick != current_tick) | 67 | if (new_tick != current_tick) { |
72 | { | ||
73 | long i; | 68 | long i; |
74 | for (i = new_tick - current_tick; i > 0; i--) | 69 | for (i = new_tick - current_tick; i > 0; i--) |
75 | sim_tick_tasks(); | 70 | sim_tick_tasks(); |
@@ -171,9 +166,6 @@ bool gui_shutdown() | |||
171 | 166 | ||
172 | SDL_KillThread(gui_thread); | 167 | SDL_KillThread(gui_thread); |
173 | SDL_RemoveTimer(tick_timer_id); | 168 | SDL_RemoveTimer(tick_timer_id); |
174 | #ifdef ROCKBOX_HAS_SIMSOUND | ||
175 | SDL_KillThread(sound_thread); | ||
176 | #endif | ||
177 | 169 | ||
178 | for (i = 0; i < threadCount; i++) | 170 | for (i = 0; i < threadCount; i++) |
179 | { | 171 | { |
@@ -223,7 +215,6 @@ int main(int argc, char *argv[]) | |||
223 | background = false; | 215 | background = false; |
224 | } | 216 | } |
225 | 217 | ||
226 | |||
227 | if (!gui_startup()) | 218 | if (!gui_startup()) |
228 | return -1; | 219 | return -1; |
229 | 220 | ||
@@ -235,14 +226,6 @@ int main(int argc, char *argv[]) | |||
235 | 226 | ||
236 | tick_timer_id = SDL_AddTimer(10, tick_timer, NULL); | 227 | tick_timer_id = SDL_AddTimer(10, tick_timer, NULL); |
237 | 228 | ||
238 | #ifdef ROCKBOX_HAS_SIMSOUND | ||
239 | sound_thread = SDL_CreateThread(sound_playback_thread, NULL); | ||
240 | if (sound_thread == NULL) { | ||
241 | printf("Error creating sound thread!\n"); | ||
242 | return -1; | ||
243 | } | ||
244 | #endif | ||
245 | |||
246 | gui_message_loop(); | 229 | gui_message_loop(); |
247 | 230 | ||
248 | return gui_shutdown(); | 231 | return gui_shutdown(); |
diff --git a/uisimulator/sdl/uisdl.h b/uisimulator/sdl/uisdl.h index 989ca364d1..f4a28f9e0f 100644 --- a/uisimulator/sdl/uisdl.h +++ b/uisimulator/sdl/uisdl.h | |||
@@ -139,6 +139,16 @@ | |||
139 | #define UI_LCD_WIDTH 176 | 139 | #define UI_LCD_WIDTH 176 |
140 | #define UI_LCD_HEIGHT 132 | 140 | #define UI_LCD_HEIGHT 132 |
141 | 141 | ||
142 | #elif defined(IPOD_VIDEO) | ||
143 | #define UI_TITLE "iPod Video" | ||
144 | #define UI_WIDTH 320 // width of GUI window | ||
145 | #define UI_HEIGHT 240 // height of GUI window | ||
146 | /* high-colour */ | ||
147 | #define UI_LCD_POSX 0 // x position of lcd | ||
148 | #define UI_LCD_POSY 0 // y position of lcd | ||
149 | #define UI_LCD_WIDTH 320 | ||
150 | #define UI_LCD_HEIGHT 240 | ||
151 | |||
142 | #elif defined(ARCHOS_GMINI120) | 152 | #elif defined(ARCHOS_GMINI120) |
143 | #define UI_TITLE "Gmini 120" | 153 | #define UI_TITLE "Gmini 120" |
144 | #define UI_WIDTH 370 // width of GUI window | 154 | #define UI_WIDTH 370 // width of GUI window |
@@ -151,7 +161,6 @@ | |||
151 | #define UI_LCD_WIDTH 192 // * 1.5 | 161 | #define UI_LCD_WIDTH 192 // * 1.5 |
152 | #define UI_LCD_HEIGHT 96 // * 1.5 | 162 | #define UI_LCD_HEIGHT 96 // * 1.5 |
153 | 163 | ||
154 | |||
155 | #elif defined(IAUDIO_X5) | 164 | #elif defined(IAUDIO_X5) |
156 | #define UI_TITLE "iAudio X5" | 165 | #define UI_TITLE "iAudio X5" |
157 | #define UI_WIDTH 300 // width of GUI window | 166 | #define UI_WIDTH 300 // width of GUI window |