diff options
-rw-r--r-- | apps/main.c | 13 | ||||
-rw-r--r-- | firmware/SOURCES | 21 | ||||
-rw-r--r-- | firmware/drivers/audio/sdl.c | 186 | ||||
-rw-r--r-- | firmware/drivers/button.c | 9 | ||||
-rw-r--r-- | firmware/export/audiohw.h | 6 | ||||
-rw-r--r-- | firmware/export/config/sim.h | 4 | ||||
-rw-r--r-- | firmware/export/system.h | 1 | ||||
-rw-r--r-- | firmware/kernel.c | 5 | ||||
-rw-r--r-- | firmware/libc/include/stdlib.h | 3 | ||||
-rw-r--r-- | firmware/sound.c | 85 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/button-sdl.c (renamed from uisimulator/sdl/button.c) | 121 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/button-sdl.h (renamed from uisimulator/sdl/sound.h) | 26 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/kernel-sdl.c (renamed from uisimulator/sdl/kernel-sdl.c) | 17 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/lcd-bitmap.c (renamed from uisimulator/sdl/lcd-bitmap.c) | 3 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/lcd-bitmap.h (renamed from uisimulator/sdl/lcd-bitmap.h) | 0 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/lcd-charcells.c (renamed from uisimulator/sdl/lcd-charcells.c) | 9 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/lcd-charcells.h (renamed from uisimulator/sdl/lcd-charcells.h) | 0 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/lcd-remote-bitmap.c (renamed from uisimulator/sdl/lcd-remote-bitmap.c) | 3 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/lcd-remote-bitmap.h (renamed from uisimulator/sdl/lcd-remote-bitmap.h) | 0 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/lcd-sdl.c (renamed from uisimulator/sdl/lcd-sdl.c) | 3 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/lcd-sdl.h (renamed from uisimulator/sdl/lcd-sdl.h) | 1 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/pcm-sdl.c (renamed from uisimulator/sdl/sound.c) | 131 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/sim-ui-defines.h (renamed from uisimulator/sdl/uisdl.h) | 5 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/system-sdl.c (renamed from uisimulator/sdl/uisdl.c) | 218 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/system-sdl.h (renamed from uisimulator/sdl/system-sdl.h) | 5 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/thread-sdl.c (renamed from uisimulator/sdl/thread-sdl.c) | 65 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/thread-sdl.h (renamed from uisimulator/sdl/thread-sdl.h) | 15 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/timer-sdl.c (renamed from uisimulator/sdl/timer.c) | 0 | ||||
-rwxr-xr-x | tools/configure | 4 | ||||
-rw-r--r-- | uisimulator/common/io.c | 4 | ||||
-rw-r--r-- | uisimulator/common/powermgmt-sim.c | 4 | ||||
-rw-r--r-- | uisimulator/common/stubs.c | 16 | ||||
-rw-r--r-- | uisimulator/sdl/Makefile | 64 | ||||
-rw-r--r-- | uisimulator/sdl/README | 6 | ||||
-rw-r--r-- | uisimulator/sdl/SOURCES | 15 | ||||
-rw-r--r-- | uisimulator/sdl/button-sdl.h | 46 | ||||
-rw-r--r-- | uisimulator/sdl/timefuncs.h | 7 | ||||
-rw-r--r-- | uisimulator/uisimulator.make | 7 |
38 files changed, 505 insertions, 623 deletions
diff --git a/apps/main.c b/apps/main.c index b043dacede..e4b9286b4e 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -124,8 +124,14 @@ const char appsversion[]=APPSVERSION; | |||
124 | 124 | ||
125 | static void init(void); | 125 | static void init(void); |
126 | 126 | ||
127 | #ifdef SIMULATOR | 127 | #ifdef HAVE_SDL |
128 | void app_main(void) | 128 | #if defined(WIN32) && defined(main) |
129 | /* Don't use SDL_main on windows -> no more stdio redirection */ | ||
130 | #undef main | ||
131 | #endif | ||
132 | int main(int argc, char *argv[]) | ||
133 | { | ||
134 | sys_handle_argv(argc, argv); | ||
129 | #else | 135 | #else |
130 | /* main(), and various functions called by main() and init() may be | 136 | /* main(), and various functions called by main() and init() may be |
131 | * be INIT_ATTR. These functions must not be called after the final call | 137 | * be INIT_ATTR. These functions must not be called after the final call |
@@ -133,8 +139,8 @@ void app_main(void) | |||
133 | * see definition of INIT_ATTR in config.h */ | 139 | * see definition of INIT_ATTR in config.h */ |
134 | int main(void) INIT_ATTR __attribute__((noreturn)); | 140 | int main(void) INIT_ATTR __attribute__((noreturn)); |
135 | int main(void) | 141 | int main(void) |
136 | #endif | ||
137 | { | 142 | { |
143 | #endif | ||
138 | int i; | 144 | int i; |
139 | CHART(">init"); | 145 | CHART(">init"); |
140 | init(); | 146 | init(); |
@@ -313,6 +319,7 @@ static void init_tagcache(void) | |||
313 | 319 | ||
314 | static void init(void) | 320 | static void init(void) |
315 | { | 321 | { |
322 | system_init(); | ||
316 | kernel_init(); | 323 | kernel_init(); |
317 | buffer_init(); | 324 | buffer_init(); |
318 | enable_irq(); | 325 | enable_irq(); |
diff --git a/firmware/SOURCES b/firmware/SOURCES index 68074dbbec..47249a2d6d 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -18,6 +18,22 @@ rolo.c | |||
18 | thread.c | 18 | thread.c |
19 | timer.c | 19 | timer.c |
20 | #endif /* SIMULATOR */ | 20 | #endif /* SIMULATOR */ |
21 | #ifdef HAVE_SDL | ||
22 | target/hosted/sdl/button-sdl.c | ||
23 | target/hosted/sdl/kernel-sdl.c | ||
24 | #ifdef HAVE_LCD_BITMAP | ||
25 | target/hosted/sdl/lcd-bitmap.c | ||
26 | #elif defined(HAVE_LCD_CHARCELLS) | ||
27 | target/hosted/sdl/lcd-charcells.c | ||
28 | #endif | ||
29 | #ifdef HAVE_REMOTE_LCD | ||
30 | target/hosted/sdl/lcd-remote-bitmap.c | ||
31 | #endif | ||
32 | target/hosted/sdl/lcd-sdl.c | ||
33 | target/hosted/sdl/system-sdl.c | ||
34 | target/hosted/sdl/thread-sdl.c | ||
35 | target/hosted/sdl/timer-sdl.c | ||
36 | #endif | ||
21 | panic.c | 37 | panic.c |
22 | debug.c | 38 | debug.c |
23 | 39 | ||
@@ -292,6 +308,11 @@ drivers/audio/ak4537.c | |||
292 | #elif defined(HAVE_UDA1341) | 308 | #elif defined(HAVE_UDA1341) |
293 | drivers/audio/uda1341.c | 309 | drivers/audio/uda1341.c |
294 | #endif /* defined(HAVE_*) */ | 310 | #endif /* defined(HAVE_*) */ |
311 | #elif defined(HAVE_SDL_AUDIO) | ||
312 | drivers/audio/sdl.c | ||
313 | #if CONFIG_CODEC == SWCODEC | ||
314 | target/hosted/sdl/pcm-sdl.c | ||
315 | #endif | ||
295 | #endif /* !defined(SIMULATOR) && !defined(BOOTLOADER) */ | 316 | #endif /* !defined(SIMULATOR) && !defined(BOOTLOADER) */ |
296 | 317 | ||
297 | /* USB Stack */ | 318 | /* USB Stack */ |
diff --git a/firmware/drivers/audio/sdl.c b/firmware/drivers/audio/sdl.c new file mode 100644 index 0000000000..c063192873 --- /dev/null +++ b/firmware/drivers/audio/sdl.c | |||
@@ -0,0 +1,186 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright © 2010 Thomas Martitz | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <SDL_audio.h> | ||
23 | #include "config.h" | ||
24 | #include "audiohw.h" | ||
25 | |||
26 | /** | ||
27 | * Audio Hardware api. Make them do nothing as we cannot properly simulate with | ||
28 | * SDL. if we used DSP we would run code that doesn't actually run on the target | ||
29 | **/ | ||
30 | |||
31 | extern void pcm_set_mixer_volume(int); | ||
32 | |||
33 | void audiohw_set_volume(int volume) | ||
34 | { | ||
35 | #if CONFIG_CODEC == SWCODEC | ||
36 | pcm_set_mixer_volume( | ||
37 | SDL_MIX_MAXVOLUME * ((volume - VOLUME_MIN) / 10) / (VOLUME_RANGE / 10)); | ||
38 | #else | ||
39 | (void)volume; | ||
40 | #endif | ||
41 | } | ||
42 | |||
43 | const struct sound_settings_info audiohw_settings[] = { | ||
44 | [SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25}, | ||
45 | /* Bass and treble tone controls */ | ||
46 | #ifdef AUDIOHW_HAVE_BASS | ||
47 | [SOUND_BASS] = {"dB", 0, 1, -24, 24, 0}, | ||
48 | #endif | ||
49 | #ifdef AUDIOHW_HAVE_TREBLE | ||
50 | [SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0}, | ||
51 | #endif | ||
52 | [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0}, | ||
53 | [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0}, | ||
54 | [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100}, | ||
55 | #if defined(HAVE_RECORDING) | ||
56 | [SOUND_LEFT_GAIN] = {"dB", 1, 1,-128, 96, 0}, | ||
57 | [SOUND_RIGHT_GAIN] = {"dB", 1, 1,-128, 96, 0}, | ||
58 | [SOUND_MIC_GAIN] = {"dB", 1, 1,-128, 108, 16}, | ||
59 | #endif | ||
60 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) | ||
61 | [SOUND_BASS_CUTOFF] = {"", 0, 1, 1, 4, 1}, | ||
62 | #endif | ||
63 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) | ||
64 | [SOUND_TREBLE_CUTOFF] = {"", 0, 1, 1, 4, 1}, | ||
65 | #endif | ||
66 | #if defined(AUDIOHW_HAVE_DEPTH_3D) | ||
67 | [SOUND_DEPTH_3D] = {"%", 0, 1, 0, 15, 0}, | ||
68 | #endif | ||
69 | /* Hardware EQ tone controls */ | ||
70 | #if defined(AUDIOHW_HAVE_EQ_BAND1) | ||
71 | [SOUND_EQ_BAND1_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
72 | #endif | ||
73 | #if defined(AUDIOHW_HAVE_EQ_BAND2) | ||
74 | [SOUND_EQ_BAND2_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
75 | #endif | ||
76 | #if defined(AUDIOHW_HAVE_EQ_BAND3) | ||
77 | [SOUND_EQ_BAND3_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
78 | #endif | ||
79 | #if defined(AUDIOHW_HAVE_EQ_BAND4) | ||
80 | [SOUND_EQ_BAND4_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
81 | #endif | ||
82 | #if defined(AUDIOHW_HAVE_EQ_BAND5) | ||
83 | [SOUND_EQ_BAND5_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
84 | #endif | ||
85 | #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY) | ||
86 | [SOUND_EQ_BAND1_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
87 | #endif | ||
88 | #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY) | ||
89 | [SOUND_EQ_BAND2_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
90 | #endif | ||
91 | #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY) | ||
92 | [SOUND_EQ_BAND3_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
93 | #endif | ||
94 | #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY) | ||
95 | [SOUND_EQ_BAND4_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
96 | #endif | ||
97 | #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY) | ||
98 | [SOUND_EQ_BAND5_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
99 | #endif | ||
100 | #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH) | ||
101 | [SOUND_EQ_BAND2_WIDTH] = {"", 0, 1, 0, 1, 0}, | ||
102 | #endif | ||
103 | #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH) | ||
104 | [SOUND_EQ_BAND3_WIDTH] = {"", 0, 1, 0, 1, 0}, | ||
105 | #endif | ||
106 | #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH) | ||
107 | [SOUND_EQ_BAND4_WIDTH] = {"", 0, 1, 0, 1, 0}, | ||
108 | #endif | ||
109 | |||
110 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
111 | [SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0}, | ||
112 | [SOUND_AVC] = {"", 0, 1, -1, 4, 0}, | ||
113 | [SOUND_MDB_STRENGTH] = {"dB", 0, 1, 0, 127, 48}, | ||
114 | [SOUND_MDB_HARMONICS] = {"%", 0, 1, 0, 100, 50}, | ||
115 | [SOUND_MDB_CENTER] = {"Hz", 0, 10, 20, 300, 60}, | ||
116 | [SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90}, | ||
117 | [SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0}, | ||
118 | [SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0}, | ||
119 | #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ | ||
120 | }; | ||
121 | |||
122 | /** | ||
123 | * stubs here, for the simulator | ||
124 | **/ | ||
125 | |||
126 | #if defined(AUDIOHW_HAVE_PRESCALER) | ||
127 | void audiohw_set_prescaler(int value) { (void)value; } | ||
128 | #endif | ||
129 | #if defined(AUDIOHW_HAVE_BALANCE) | ||
130 | void audiohw_set_balance(int value) { (void)value; } | ||
131 | #endif | ||
132 | #if defined(AUDIOHW_HAVE_BASS) | ||
133 | void audiohw_set_bass(int value) { (void)value; } | ||
134 | #endif | ||
135 | #if defined(AUDIOHW_HAVE_TREBLE) | ||
136 | void audiohw_set_treble(int value) { (void)value; } | ||
137 | #endif | ||
138 | #if CONFIG_CODEC != SWCODEC | ||
139 | void audiohw_set_channel(int value) { (void)value; } | ||
140 | void audiohw_set_stereo_width(int value){ (void)value; } | ||
141 | #endif | ||
142 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) | ||
143 | void audiohw_set_bass_cutoff(int value) { (void)value; } | ||
144 | #endif | ||
145 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) | ||
146 | void audiohw_set_treble_cutoff(int value){ (void)value; } | ||
147 | #endif | ||
148 | /* EQ-based tone controls */ | ||
149 | #if defined(AUDIOHW_HAVE_EQ) | ||
150 | void audiohw_set_eq_band_gain(unsigned int band, int value) | ||
151 | { (void)band; (void)value; } | ||
152 | #endif | ||
153 | #if defined(AUDIOHW_HAVE_EQ_FREQUENCY) | ||
154 | void audiohw_set_eq_band_frequency(unsigned int band, int value) | ||
155 | { (void)band; (void)value; } | ||
156 | #endif | ||
157 | #if defined(AUDIOHW_HAVE_EQ_WIDTH) | ||
158 | void audiohw_set_eq_band_width(unsigned int band, int value) | ||
159 | { (void)band; (void)value; } | ||
160 | #endif | ||
161 | #if defined(AUDIOHW_HAVE_DEPTH_3D) | ||
162 | void audiohw_set_depth_3d(int value) | ||
163 | { (void)value; } | ||
164 | #endif | ||
165 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
166 | int mas_codec_readreg(int reg) | ||
167 | { | ||
168 | (void)reg; | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | int mas_codec_writereg(int reg, unsigned int val) | ||
173 | { | ||
174 | (void)reg; | ||
175 | (void)val; | ||
176 | return 0; | ||
177 | } | ||
178 | int mas_writemem(int bank, int addr, const unsigned long* src, int len) | ||
179 | { | ||
180 | (void)bank; | ||
181 | (void)addr; | ||
182 | (void)src; | ||
183 | (void)len; | ||
184 | return 0; | ||
185 | } | ||
186 | #endif | ||
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 100957b77a..f116ad646e 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -429,7 +429,6 @@ void button_init(void) | |||
429 | tick_add_task(button_tick); | 429 | tick_add_task(button_tick); |
430 | } | 430 | } |
431 | 431 | ||
432 | #ifndef SIMULATOR | ||
433 | #ifdef BUTTON_DRIVER_CLOSE | 432 | #ifdef BUTTON_DRIVER_CLOSE |
434 | void button_close(void) | 433 | void button_close(void) |
435 | { | 434 | { |
@@ -443,9 +442,10 @@ void button_close(void) | |||
443 | */ | 442 | */ |
444 | static int button_flip(int button) | 443 | static int button_flip(int button) |
445 | { | 444 | { |
446 | int newbutton; | 445 | int newbutton = button; |
447 | 446 | ||
448 | newbutton = button & | 447 | #ifndef SIMULATOR |
448 | newbutton &= | ||
449 | ~(BUTTON_LEFT | BUTTON_RIGHT | 449 | ~(BUTTON_LEFT | BUTTON_RIGHT |
450 | #if defined(BUTTON_UP) && defined(BUTTON_DOWN) | 450 | #if defined(BUTTON_UP) && defined(BUTTON_DOWN) |
451 | | BUTTON_UP | BUTTON_DOWN | 451 | | BUTTON_UP | BUTTON_DOWN |
@@ -503,7 +503,7 @@ static int button_flip(int button) | |||
503 | if (button & BUTTON_PREV) | 503 | if (button & BUTTON_PREV) |
504 | newbutton |= BUTTON_NEXT; | 504 | newbutton |= BUTTON_NEXT; |
505 | #endif | 505 | #endif |
506 | 506 | #endif /* !SIMULATOR */ | |
507 | return newbutton; | 507 | return newbutton; |
508 | } | 508 | } |
509 | 509 | ||
@@ -523,7 +523,6 @@ void button_set_flip(bool flip) | |||
523 | } | 523 | } |
524 | } | 524 | } |
525 | #endif /* HAVE_LCD_FLIP */ | 525 | #endif /* HAVE_LCD_FLIP */ |
526 | #endif /* SIMULATOR */ | ||
527 | 526 | ||
528 | #ifdef HAVE_BACKLIGHT | 527 | #ifdef HAVE_BACKLIGHT |
529 | void set_backlight_filter_keypress(bool value) | 528 | void set_backlight_filter_keypress(bool value) |
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h index d7ee551e40..b8214e67b9 100644 --- a/firmware/export/audiohw.h +++ b/firmware/export/audiohw.h | |||
@@ -66,6 +66,10 @@ | |||
66 | #elif defined(HAVE_AK4537) | 66 | #elif defined(HAVE_AK4537) |
67 | #include "ak4537.h" | 67 | #include "ak4537.h" |
68 | #endif | 68 | #endif |
69 | #if defined(HAVE_SDL_AUDIO) | ||
70 | /* #include <SDL_audio.h> gives errors in other code areas, | ||
71 | * we don't really need it here, so don't. but it should maybe be fixed */ | ||
72 | #endif | ||
69 | 73 | ||
70 | 74 | ||
71 | 75 | ||
@@ -369,7 +373,7 @@ void audiohw_postinit(void); | |||
369 | */ | 373 | */ |
370 | void audiohw_close(void); | 374 | void audiohw_close(void); |
371 | 375 | ||
372 | #ifdef AUDIOHW_HAVE_CLIPPING | 376 | #if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) |
373 | /** | 377 | /** |
374 | * Set new volume value | 378 | * Set new volume value |
375 | * @param val to set. | 379 | * @param val to set. |
diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h index 6d2e6d24ea..d65b0fbbf8 100644 --- a/firmware/export/config/sim.h +++ b/firmware/export/config/sim.h | |||
@@ -80,6 +80,8 @@ | |||
80 | 80 | ||
81 | #undef HAVE_SPEAKER | 81 | #undef HAVE_SPEAKER |
82 | 82 | ||
83 | #undef BUTTON_DRIVER_CLOSE | ||
84 | |||
83 | #if CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG | 85 | #if CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG |
84 | #undef CONFIG_BACKLIGHT_FADING | 86 | #undef CONFIG_BACKLIGHT_FADING |
85 | /* simulate SW_SETTING, as we handle sdl very similary */ | 87 | /* simulate SW_SETTING, as we handle sdl very similary */ |
@@ -97,4 +99,6 @@ | |||
97 | #define DEFAULT_BRIGHTNESS_SETTING MAX_BRIGHTNESS_SETTING | 99 | #define DEFAULT_BRIGHTNESS_SETTING MAX_BRIGHTNESS_SETTING |
98 | #endif | 100 | #endif |
99 | 101 | ||
102 | #define HAVE_SDL | ||
103 | #define HAVE_SDL_AUDIO | ||
100 | #define _ISOC99_SOURCE 1 | 104 | #define _ISOC99_SOURCE 1 |
diff --git a/firmware/export/system.h b/firmware/export/system.h index bd31c03028..fc582aac03 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h | |||
@@ -235,6 +235,7 @@ enum { | |||
235 | #if !defined(SIMULATOR) && !defined(__PCTOOL__) | 235 | #if !defined(SIMULATOR) && !defined(__PCTOOL__) |
236 | #include "system-target.h" | 236 | #include "system-target.h" |
237 | #else /* SIMULATOR */ | 237 | #else /* SIMULATOR */ |
238 | #include "system-sdl.h" | ||
238 | static inline uint16_t swap16(uint16_t value) | 239 | static inline uint16_t swap16(uint16_t value) |
239 | /* | 240 | /* |
240 | result[15..8] = value[ 7..0]; | 241 | result[15..8] = value[ 7..0]; |
diff --git a/firmware/kernel.c b/firmware/kernel.c index 64c8142540..d8c67e8485 100644 --- a/firmware/kernel.c +++ b/firmware/kernel.c | |||
@@ -22,14 +22,11 @@ | |||
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include "config.h" | 23 | #include "config.h" |
24 | #include "kernel.h" | 24 | #include "kernel.h" |
25 | #ifdef SIMULATOR | ||
26 | #include "system-sdl.h" | ||
27 | #include "debug.h" | ||
28 | #endif | ||
29 | #include "thread.h" | 25 | #include "thread.h" |
30 | #include "cpu.h" | 26 | #include "cpu.h" |
31 | #include "system.h" | 27 | #include "system.h" |
32 | #include "panic.h" | 28 | #include "panic.h" |
29 | #include "debug.h" | ||
33 | 30 | ||
34 | /* Make this nonzero to enable more elaborate checks on objects */ | 31 | /* Make this nonzero to enable more elaborate checks on objects */ |
35 | #if defined(DEBUG) || defined(SIMULATOR) | 32 | #if defined(DEBUG) || defined(SIMULATOR) |
diff --git a/firmware/libc/include/stdlib.h b/firmware/libc/include/stdlib.h index 5f6db6da8a..57553367c4 100644 --- a/firmware/libc/include/stdlib.h +++ b/firmware/libc/include/stdlib.h | |||
@@ -29,6 +29,7 @@ void *malloc(size_t); | |||
29 | void *calloc (size_t nmemb, size_t size); | 29 | void *calloc (size_t nmemb, size_t size); |
30 | void free(void *); | 30 | void free(void *); |
31 | void *realloc(void *, size_t); | 31 | void *realloc(void *, size_t); |
32 | int atexit(void (*)(void)); | ||
32 | 33 | ||
33 | #define RAND_MAX INT_MAX | 34 | #define RAND_MAX INT_MAX |
34 | 35 | ||
@@ -51,7 +52,7 @@ void exit(int status); | |||
51 | #endif | 52 | #endif |
52 | 53 | ||
53 | int atoi (const char *str); | 54 | int atoi (const char *str); |
54 | 55 | ||
55 | #ifdef __cplusplus | 56 | #ifdef __cplusplus |
56 | } | 57 | } |
57 | #endif | 58 | #endif |
diff --git a/firmware/sound.c b/firmware/sound.c index fb2f353d71..dccca12264 100644 --- a/firmware/sound.c +++ b/firmware/sound.c | |||
@@ -43,89 +43,6 @@ | |||
43 | 43 | ||
44 | extern bool audio_is_initialized; | 44 | extern bool audio_is_initialized; |
45 | 45 | ||
46 | #ifdef SIMULATOR | ||
47 | extern void audiohw_set_volume(int value); | ||
48 | /* dummy for sim */ | ||
49 | const struct sound_settings_info audiohw_settings[] = { | ||
50 | [SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25}, | ||
51 | /* Bass and treble tone controls */ | ||
52 | #ifdef AUDIOHW_HAVE_BASS | ||
53 | [SOUND_BASS] = {"dB", 0, 1, -24, 24, 0}, | ||
54 | #endif | ||
55 | #ifdef AUDIOHW_HAVE_TREBLE | ||
56 | [SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0}, | ||
57 | #endif | ||
58 | [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0}, | ||
59 | [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0}, | ||
60 | [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100}, | ||
61 | #if defined(HAVE_RECORDING) | ||
62 | [SOUND_LEFT_GAIN] = {"dB", 1, 1,-128, 96, 0}, | ||
63 | [SOUND_RIGHT_GAIN] = {"dB", 1, 1,-128, 96, 0}, | ||
64 | [SOUND_MIC_GAIN] = {"dB", 1, 1,-128, 108, 16}, | ||
65 | #endif | ||
66 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) | ||
67 | [SOUND_BASS_CUTOFF] = {"", 0, 1, 1, 4, 1}, | ||
68 | #endif | ||
69 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) | ||
70 | [SOUND_TREBLE_CUTOFF] = {"", 0, 1, 1, 4, 1}, | ||
71 | #endif | ||
72 | #if defined(AUDIOHW_HAVE_DEPTH_3D) | ||
73 | [SOUND_DEPTH_3D] = {"%", 0, 1, 0, 15, 0}, | ||
74 | #endif | ||
75 | /* Hardware EQ tone controls */ | ||
76 | #if defined(AUDIOHW_HAVE_EQ_BAND1) | ||
77 | [SOUND_EQ_BAND1_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
78 | #endif | ||
79 | #if defined(AUDIOHW_HAVE_EQ_BAND2) | ||
80 | [SOUND_EQ_BAND2_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
81 | #endif | ||
82 | #if defined(AUDIOHW_HAVE_EQ_BAND3) | ||
83 | [SOUND_EQ_BAND3_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
84 | #endif | ||
85 | #if defined(AUDIOHW_HAVE_EQ_BAND4) | ||
86 | [SOUND_EQ_BAND4_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
87 | #endif | ||
88 | #if defined(AUDIOHW_HAVE_EQ_BAND5) | ||
89 | [SOUND_EQ_BAND5_GAIN] = {"dB", 0, 1, -12, 12, 0}, | ||
90 | #endif | ||
91 | #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY) | ||
92 | [SOUND_EQ_BAND1_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
93 | #endif | ||
94 | #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY) | ||
95 | [SOUND_EQ_BAND2_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
96 | #endif | ||
97 | #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY) | ||
98 | [SOUND_EQ_BAND3_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
99 | #endif | ||
100 | #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY) | ||
101 | [SOUND_EQ_BAND4_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
102 | #endif | ||
103 | #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY) | ||
104 | [SOUND_EQ_BAND5_FREQUENCY] = {"", 0, 1, 1, 4, 1}, | ||
105 | #endif | ||
106 | #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH) | ||
107 | [SOUND_EQ_BAND2_WIDTH] = {"", 0, 1, 0, 1, 0}, | ||
108 | #endif | ||
109 | #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH) | ||
110 | [SOUND_EQ_BAND3_WIDTH] = {"", 0, 1, 0, 1, 0}, | ||
111 | #endif | ||
112 | #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH) | ||
113 | [SOUND_EQ_BAND4_WIDTH] = {"", 0, 1, 0, 1, 0}, | ||
114 | #endif | ||
115 | |||
116 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
117 | [SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0}, | ||
118 | [SOUND_AVC] = {"", 0, 1, -1, 4, 0}, | ||
119 | [SOUND_MDB_STRENGTH] = {"dB", 0, 1, 0, 127, 48}, | ||
120 | [SOUND_MDB_HARMONICS] = {"%", 0, 1, 0, 100, 50}, | ||
121 | [SOUND_MDB_CENTER] = {"Hz", 0, 10, 20, 300, 60}, | ||
122 | [SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90}, | ||
123 | [SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0}, | ||
124 | [SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0}, | ||
125 | #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ | ||
126 | }; | ||
127 | #endif | ||
128 | |||
129 | const char *sound_unit(int setting) | 46 | const char *sound_unit(int setting) |
130 | { | 47 | { |
131 | return audiohw_settings[setting].unit; | 48 | return audiohw_settings[setting].unit; |
@@ -356,7 +273,7 @@ static void set_prescaled_volume(void) | |||
356 | 273 | ||
357 | #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) | 274 | #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) |
358 | audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r)); | 275 | audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r)); |
359 | #elif defined(HAVE_JZ4740_CODEC) | 276 | #elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) |
360 | audiohw_set_volume(current_volume); | 277 | audiohw_set_volume(current_volume); |
361 | #endif | 278 | #endif |
362 | #else /* SIMULATOR */ | 279 | #else /* SIMULATOR */ |
diff --git a/uisimulator/sdl/button.c b/firmware/target/hosted/sdl/button-sdl.c index 2bb7764782..51ba8cff92 100644 --- a/uisimulator/sdl/button.c +++ b/firmware/target/hosted/sdl/button-sdl.c | |||
@@ -19,7 +19,8 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include "uisdl.h" | 22 | #include <math.h> |
23 | #include "sim-ui-defines.h" | ||
23 | #include "lcd-charcells.h" | 24 | #include "lcd-charcells.h" |
24 | #include "lcd-remote.h" | 25 | #include "lcd-remote.h" |
25 | #include "config.h" | 26 | #include "config.h" |
@@ -61,6 +62,8 @@ int remote_type(void) | |||
61 | } | 62 | } |
62 | #endif | 63 | #endif |
63 | 64 | ||
65 | static int xy2button(int x, int y); | ||
66 | |||
64 | struct event_queue button_queue; | 67 | struct event_queue button_queue; |
65 | 68 | ||
66 | static int btn = 0; /* Hopefully keeps track of currently pressed keys... */ | 69 | static int btn = 0; /* Hopefully keeps track of currently pressed keys... */ |
@@ -78,8 +81,109 @@ bool remote_button_hold(void) { | |||
78 | return remote_hold_button_state; | 81 | return remote_hold_button_state; |
79 | } | 82 | } |
80 | #endif | 83 | #endif |
84 | static void button_event(int key, bool pressed); | ||
85 | extern bool debug_wps; | ||
86 | extern bool mapping; | ||
87 | static void gui_message_loop(void) | ||
88 | { | ||
89 | SDL_Event event; | ||
90 | static int x,y,xybutton = 0; | ||
91 | |||
92 | if (SDL_PollEvent(&event)) | ||
93 | { | ||
94 | switch(event.type) | ||
95 | { | ||
96 | case SDL_KEYDOWN: | ||
97 | button_event(event.key.keysym.sym, true); | ||
98 | break; | ||
99 | case SDL_KEYUP: | ||
100 | button_event(event.key.keysym.sym, false); | ||
101 | case SDL_MOUSEBUTTONDOWN: | ||
102 | switch ( event.button.button ) { | ||
103 | #ifdef HAVE_SCROLLWHEEL | ||
104 | case SDL_BUTTON_WHEELUP: | ||
105 | button_event( SDLK_UP, true ); | ||
106 | break; | ||
107 | case SDL_BUTTON_WHEELDOWN: | ||
108 | button_event( SDLK_DOWN, true ); | ||
109 | break; | ||
110 | #endif | ||
111 | case SDL_BUTTON_LEFT: | ||
112 | case SDL_BUTTON_MIDDLE: | ||
113 | if ( mapping && background ) { | ||
114 | x = event.button.x; | ||
115 | y = event.button.y; | ||
116 | } | ||
117 | if ( background ) { | ||
118 | xybutton = xy2button( event.button.x, event.button.y ); | ||
119 | if( xybutton ) | ||
120 | button_event( xybutton, true ); | ||
121 | } | ||
122 | break; | ||
123 | default: | ||
124 | break; | ||
125 | } | ||
126 | |||
127 | if (debug_wps && event.button.button == 1) | ||
128 | { | ||
129 | if ( background ) | ||
130 | #ifdef HAVE_REMOTE | ||
131 | if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */ | ||
132 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 ); | ||
133 | else | ||
134 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 ); | ||
135 | #else | ||
136 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 ); | ||
137 | #endif | ||
138 | else | ||
139 | if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */ | ||
140 | printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom ); | ||
141 | #ifdef HAVE_REMOTE | ||
142 | else | ||
143 | printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT ); | ||
144 | #endif | ||
145 | } | ||
146 | break; | ||
147 | case SDL_MOUSEBUTTONUP: | ||
148 | switch ( event.button.button ) { | ||
149 | /* The scrollwheel button up events are ignored as they are queued immediately */ | ||
150 | case SDL_BUTTON_LEFT: | ||
151 | case SDL_BUTTON_MIDDLE: | ||
152 | if ( mapping && background ) { | ||
153 | printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, | ||
154 | #define SQUARE(x) ((x)*(x)) | ||
155 | y, (int)sqrt( SQUARE(x-(int)event.button.x) | ||
156 | + SQUARE(y-(int)event.button.y)) ); | ||
157 | } | ||
158 | if ( background && xybutton ) { | ||
159 | button_event( xybutton, false ); | ||
160 | xybutton = 0; | ||
161 | } | ||
162 | #ifdef HAVE_TOUCHSCREEN | ||
163 | else { | ||
164 | button_event(BUTTON_TOUCHSCREEN, false); | ||
165 | } | ||
166 | #endif | ||
167 | break; | ||
168 | default: | ||
169 | break; | ||
170 | } | ||
171 | break; | ||
172 | |||
173 | |||
174 | case SDL_QUIT: | ||
175 | { | ||
176 | exit(EXIT_SUCCESS); | ||
177 | break; | ||
178 | } | ||
179 | default: | ||
180 | /*printf("Unhandled event\n"); */ | ||
181 | break; | ||
182 | } | ||
183 | } | ||
184 | } | ||
81 | 185 | ||
82 | void button_event(int key, bool pressed) | 186 | static void button_event(int key, bool pressed) |
83 | { | 187 | { |
84 | int new_btn = 0; | 188 | int new_btn = 0; |
85 | static bool usb_connected = false; | 189 | static bool usb_connected = false; |
@@ -1380,7 +1484,6 @@ int button_read_device(int* data) | |||
1380 | int button_read_device(void) | 1484 | int button_read_device(void) |
1381 | { | 1485 | { |
1382 | #endif | 1486 | #endif |
1383 | |||
1384 | #ifdef HAS_BUTTON_HOLD | 1487 | #ifdef HAS_BUTTON_HOLD |
1385 | int hold_button = button_hold(); | 1488 | int hold_button = button_hold(); |
1386 | 1489 | ||
@@ -1396,7 +1499,9 @@ int button_read_device(void) | |||
1396 | 1499 | ||
1397 | if (hold_button) | 1500 | if (hold_button) |
1398 | return BUTTON_NONE; | 1501 | return BUTTON_NONE; |
1502 | else | ||
1399 | #endif | 1503 | #endif |
1504 | gui_message_loop(); | ||
1400 | 1505 | ||
1401 | return btn; | 1506 | return btn; |
1402 | } | 1507 | } |
@@ -1430,8 +1535,9 @@ void mouse_tick_task(void) | |||
1430 | } | 1535 | } |
1431 | #endif | 1536 | #endif |
1432 | 1537 | ||
1433 | void button_init_sdl(void) | 1538 | void button_init_device(void) |
1434 | { | 1539 | { |
1540 | SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); | ||
1435 | #ifdef HAVE_TOUCHSCREEN | 1541 | #ifdef HAVE_TOUCHSCREEN |
1436 | tick_add_task(mouse_tick_task); | 1542 | tick_add_task(mouse_tick_task); |
1437 | #endif | 1543 | #endif |
@@ -1441,6 +1547,10 @@ void button_init_sdl(void) | |||
1441 | /* Run sim with --mapping to get coordinates */ | 1547 | /* Run sim with --mapping to get coordinates */ |
1442 | /* or --debugbuttons to check */ | 1548 | /* or --debugbuttons to check */ |
1443 | /* The First matching button is returned */ | 1549 | /* The First matching button is returned */ |
1550 | struct button_map { | ||
1551 | int button, x, y, radius; | ||
1552 | char *description; | ||
1553 | }; | ||
1444 | 1554 | ||
1445 | #ifdef SANSA_FUZE | 1555 | #ifdef SANSA_FUZE |
1446 | struct button_map bm[] = { | 1556 | struct button_map bm[] = { |
@@ -1892,7 +2002,8 @@ struct button_map bm[] = { | |||
1892 | }; | 2002 | }; |
1893 | #endif | 2003 | #endif |
1894 | 2004 | ||
1895 | int xy2button( int x, int y) { | 2005 | static int xy2button( int x, int y) |
2006 | { | ||
1896 | int i; | 2007 | int i; |
1897 | extern bool debug_buttons; | 2008 | extern bool debug_buttons; |
1898 | 2009 | ||
diff --git a/uisimulator/sdl/sound.h b/firmware/target/hosted/sdl/button-sdl.h index 5f4cc6eaf0..75a68c49bc 100644 --- a/uisimulator/sdl/sound.h +++ b/firmware/target/hosted/sdl/button-sdl.h | |||
@@ -1,13 +1,13 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * __________ __ ___. | 2 | * __________ __ ___. |
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
7 | * \/ \/ \/ \/ \/ | 7 | * \/ \/ \/ \/ \/ |
8 | * $Id$ | 8 | * $Id$ |
9 | * | 9 | * |
10 | * Copyright (C) 2005 by Daniel Stenberg <daniel@haxx.se> | 10 | * Copyright (C) 2009 by Thomas Martitz |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or | 12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU General Public License | 13 | * modify it under the terms of the GNU General Public License |
@@ -19,6 +19,14 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | int sound_playback_thread(void* p); | ||
23 | 22 | ||
24 | extern void (*sound_get_pcm)(unsigned char** start, long* size); | 23 | #ifndef __BUTTON_SDL_H__ |
24 | #define __BUTTON_SDL_H__ | ||
25 | |||
26 | #include <stdbool.h> | ||
27 | #include "config.h" | ||
28 | |||
29 | bool button_hold(void); | ||
30 | void button_init_device(void); | ||
31 | |||
32 | #endif /* __BUTTON_SDL_H__ */ | ||
diff --git a/uisimulator/sdl/kernel-sdl.c b/firmware/target/hosted/sdl/kernel-sdl.c index 3288a6f97a..d796921e35 100644 --- a/uisimulator/sdl/kernel-sdl.c +++ b/firmware/target/hosted/sdl/kernel-sdl.c | |||
@@ -20,14 +20,15 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <stdio.h> | ||
23 | #include <SDL.h> | 24 | #include <SDL.h> |
24 | #include <SDL_thread.h> | 25 | #include <SDL_thread.h> |
25 | #include "memory.h" | 26 | #include "memory.h" |
26 | #include "system-sdl.h" | 27 | #include "system-sdl.h" |
27 | #include "uisdl.h" | ||
28 | #include "kernel.h" | ||
29 | #include "thread-sdl.h" | 28 | #include "thread-sdl.h" |
29 | #include "kernel.h" | ||
30 | #include "thread.h" | 30 | #include "thread.h" |
31 | #include "panic.h" | ||
31 | #include "debug.h" | 32 | #include "debug.h" |
32 | 33 | ||
33 | static SDL_TimerID tick_timer_id; | 34 | static SDL_TimerID tick_timer_id; |
@@ -90,19 +91,19 @@ void sim_exit_irq_handler(void) | |||
90 | SDL_UnlockMutex(sim_irq_mtx); | 91 | SDL_UnlockMutex(sim_irq_mtx); |
91 | } | 92 | } |
92 | 93 | ||
93 | bool sim_kernel_init(void) | 94 | static bool sim_kernel_init(void) |
94 | { | 95 | { |
95 | sim_irq_mtx = SDL_CreateMutex(); | 96 | sim_irq_mtx = SDL_CreateMutex(); |
96 | if (sim_irq_mtx == NULL) | 97 | if (sim_irq_mtx == NULL) |
97 | { | 98 | { |
98 | fprintf(stderr, "Cannot create sim_handler_mtx\n"); | 99 | panicf("Cannot create sim_handler_mtx\n"); |
99 | return false; | 100 | return false; |
100 | } | 101 | } |
101 | 102 | ||
102 | sim_thread_cond = SDL_CreateCond(); | 103 | sim_thread_cond = SDL_CreateCond(); |
103 | if (sim_thread_cond == NULL) | 104 | if (sim_thread_cond == NULL) |
104 | { | 105 | { |
105 | fprintf(stderr, "Cannot create sim_thread_cond\n"); | 106 | panicf("Cannot create sim_thread_cond\n"); |
106 | return false; | 107 | return false; |
107 | } | 108 | } |
108 | 109 | ||
@@ -141,6 +142,12 @@ Uint32 tick_timer(Uint32 interval, void *param) | |||
141 | 142 | ||
142 | void tick_start(unsigned int interval_in_ms) | 143 | void tick_start(unsigned int interval_in_ms) |
143 | { | 144 | { |
145 | if (!sim_kernel_init()) | ||
146 | { | ||
147 | panicf("Could not initialize kernel!"); | ||
148 | exit(-1); | ||
149 | } | ||
150 | |||
144 | if (tick_timer_id != NULL) | 151 | if (tick_timer_id != NULL) |
145 | { | 152 | { |
146 | SDL_RemoveTimer(tick_timer_id); | 153 | SDL_RemoveTimer(tick_timer_id); |
diff --git a/uisimulator/sdl/lcd-bitmap.c b/firmware/target/hosted/sdl/lcd-bitmap.c index 0bd90196e4..6dfbffff37 100644 --- a/uisimulator/sdl/lcd-bitmap.c +++ b/firmware/target/hosted/sdl/lcd-bitmap.c | |||
@@ -20,7 +20,8 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include "debug.h" | 22 | #include "debug.h" |
23 | #include "uisdl.h" | 23 | #include "sim-ui-defines.h" |
24 | #include "system.h" | ||
24 | #include "lcd-sdl.h" | 25 | #include "lcd-sdl.h" |
25 | #include "screendump.h" | 26 | #include "screendump.h" |
26 | 27 | ||
diff --git a/uisimulator/sdl/lcd-bitmap.h b/firmware/target/hosted/sdl/lcd-bitmap.h index a898744b41..a898744b41 100644 --- a/uisimulator/sdl/lcd-bitmap.h +++ b/firmware/target/hosted/sdl/lcd-bitmap.h | |||
diff --git a/uisimulator/sdl/lcd-charcells.c b/firmware/target/hosted/sdl/lcd-charcells.c index 05513ab266..900cbb04dd 100644 --- a/uisimulator/sdl/lcd-charcells.c +++ b/firmware/target/hosted/sdl/lcd-charcells.c | |||
@@ -19,17 +19,18 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include <string.h> | ||
23 | #include <unistd.h> | ||
24 | #include <fcntl.h> | ||
25 | #include "system.h" | ||
22 | #include "debug.h" | 26 | #include "debug.h" |
23 | #include "lcd.h" | 27 | #include "lcd.h" |
24 | #include "lcd-charcell.h" | 28 | #include "lcd-charcell.h" |
25 | #include "screendump.h" | 29 | #include "screendump.h" |
26 | #include "general.h" | 30 | #include "general.h" |
27 | #include <string.h> | ||
28 | #include <unistd.h> | ||
29 | #include <fcntl.h> | ||
30 | 31 | ||
31 | #include "lcd-playersim.h" | 32 | #include "lcd-playersim.h" |
32 | #include "uisdl.h" | 33 | #include "sim-ui-defines.h" |
33 | #include "lcd-sdl.h" | 34 | #include "lcd-sdl.h" |
34 | 35 | ||
35 | /* can't include file.h here */ | 36 | /* can't include file.h here */ |
diff --git a/uisimulator/sdl/lcd-charcells.h b/firmware/target/hosted/sdl/lcd-charcells.h index 890594f766..890594f766 100644 --- a/uisimulator/sdl/lcd-charcells.h +++ b/firmware/target/hosted/sdl/lcd-charcells.h | |||
diff --git a/uisimulator/sdl/lcd-remote-bitmap.c b/firmware/target/hosted/sdl/lcd-remote-bitmap.c index c44e476288..9972f3e423 100644 --- a/uisimulator/sdl/lcd-remote-bitmap.c +++ b/firmware/target/hosted/sdl/lcd-remote-bitmap.c | |||
@@ -19,10 +19,11 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include "uisdl.h" | 22 | #include "sim-ui-defines.h" |
23 | #include "lcd-sdl.h" | 23 | #include "lcd-sdl.h" |
24 | #include "lcd-remote-bitmap.h" | 24 | #include "lcd-remote-bitmap.h" |
25 | #include "screendump.h" | 25 | #include "screendump.h" |
26 | #include "system.h" /* background */ | ||
26 | 27 | ||
27 | SDL_Surface *remote_surface = 0; | 28 | SDL_Surface *remote_surface = 0; |
28 | 29 | ||
diff --git a/uisimulator/sdl/lcd-remote-bitmap.h b/firmware/target/hosted/sdl/lcd-remote-bitmap.h index 0a92ee6b79..0a92ee6b79 100644 --- a/uisimulator/sdl/lcd-remote-bitmap.h +++ b/firmware/target/hosted/sdl/lcd-remote-bitmap.h | |||
diff --git a/uisimulator/sdl/lcd-sdl.c b/firmware/target/hosted/sdl/lcd-sdl.c index f1ffe8a76a..15e4ba95c3 100644 --- a/uisimulator/sdl/lcd-sdl.c +++ b/firmware/target/hosted/sdl/lcd-sdl.c | |||
@@ -19,8 +19,9 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include <SDL.h> | ||
22 | #include "lcd-sdl.h" | 23 | #include "lcd-sdl.h" |
23 | #include "uisdl.h" | 24 | #include "sim-ui-defines.h" |
24 | #include "system.h" /* for MIN() and MAX() */ | 25 | #include "system.h" /* for MIN() and MAX() */ |
25 | 26 | ||
26 | int display_zoom = 1; | 27 | int display_zoom = 1; |
diff --git a/uisimulator/sdl/lcd-sdl.h b/firmware/target/hosted/sdl/lcd-sdl.h index 9ffa5246cf..1f57b06b95 100644 --- a/uisimulator/sdl/lcd-sdl.h +++ b/firmware/target/hosted/sdl/lcd-sdl.h | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | /* Default display zoom level */ | 28 | /* Default display zoom level */ |
29 | extern int display_zoom; | 29 | extern int display_zoom; |
30 | extern SDL_Surface *gui_surface; | ||
30 | 31 | ||
31 | void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, | 32 | void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, |
32 | int height, int max_x, int max_y, | 33 | int height, int max_x, int max_y, |
diff --git a/uisimulator/sdl/sound.c b/firmware/target/hosted/sdl/pcm-sdl.c index 0f8d5d4934..1772db94f4 100644 --- a/uisimulator/sdl/sound.c +++ b/firmware/target/hosted/sdl/pcm-sdl.c | |||
@@ -8,6 +8,7 @@ | |||
8 | * $Id$ | 8 | * $Id$ |
9 | * | 9 | * |
10 | * Copyright (C) 2005 by Nick Lanham | 10 | * Copyright (C) 2005 by Nick Lanham |
11 | * Copyright (C) 2010 by Thomas Martitz | ||
11 | * | 12 | * |
12 | * This program is free software; you can redistribute it and/or | 13 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU General Public License | 14 | * modify it under the terms of the GNU General Public License |
@@ -23,17 +24,20 @@ | |||
23 | 24 | ||
24 | #include <stdlib.h> | 25 | #include <stdlib.h> |
25 | #include <stdbool.h> | 26 | #include <stdbool.h> |
26 | #include <memory.h> | 27 | #include <SDL.h> |
27 | #include "kernel.h" | 28 | #include "config.h" |
29 | #include "debug.h" | ||
28 | #include "sound.h" | 30 | #include "sound.h" |
29 | #include "audiohw.h" | 31 | #include "audiohw.h" |
32 | #include "system.h" | ||
30 | 33 | ||
31 | #include "pcm.h" | 34 | #include "pcm.h" |
32 | #include "pcm_sampr.h" | 35 | #include "pcm_sampr.h" |
33 | #include "SDL.h" | ||
34 | 36 | ||
35 | /*#define LOGF_ENABLE*/ | 37 | #ifdef DEBUG |
36 | #include "logf.h" | 38 | #include <stdio.h> |
39 | extern bool debug_audio; | ||
40 | #endif | ||
37 | 41 | ||
38 | static int sim_volume = 0; | 42 | static int sim_volume = 0; |
39 | 43 | ||
@@ -45,23 +49,19 @@ static size_t pcm_data_size; | |||
45 | static size_t pcm_sample_bytes; | 49 | static size_t pcm_sample_bytes; |
46 | static size_t pcm_channel_bytes; | 50 | static size_t pcm_channel_bytes; |
47 | 51 | ||
48 | static struct pcm_udata | 52 | struct pcm_udata |
49 | { | 53 | { |
50 | Uint8 *stream; | 54 | Uint8 *stream; |
51 | Uint32 num_in; | 55 | Uint32 num_in; |
52 | Uint32 num_out; | 56 | Uint32 num_out; |
57 | #ifdef DEBUG | ||
53 | FILE *debug; | 58 | FILE *debug; |
59 | #endif | ||
54 | } udata; | 60 | } udata; |
55 | 61 | ||
56 | static SDL_AudioSpec obtained; | 62 | static SDL_AudioSpec obtained; |
57 | static SDL_AudioCVT cvt; | 63 | static SDL_AudioCVT cvt; |
58 | 64 | ||
59 | extern bool debug_audio; | ||
60 | |||
61 | #ifndef MIN | ||
62 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) | ||
63 | #endif | ||
64 | |||
65 | void pcm_play_lock(void) | 65 | void pcm_play_lock(void) |
66 | { | 66 | { |
67 | SDL_LockAudio(); | 67 | SDL_LockAudio(); |
@@ -102,11 +102,13 @@ void pcm_play_dma_start(const void *addr, size_t size) | |||
102 | void pcm_play_dma_stop(void) | 102 | void pcm_play_dma_stop(void) |
103 | { | 103 | { |
104 | SDL_PauseAudio(1); | 104 | SDL_PauseAudio(1); |
105 | #ifdef DEBUG | ||
105 | if (udata.debug != NULL) { | 106 | if (udata.debug != NULL) { |
106 | fclose(udata.debug); | 107 | fclose(udata.debug); |
107 | udata.debug = NULL; | 108 | udata.debug = NULL; |
108 | DEBUGF("Audio debug file closed\n"); | 109 | DEBUGF("Audio debug file closed\n"); |
109 | } | 110 | } |
111 | #endif | ||
110 | } | 112 | } |
111 | 113 | ||
112 | void pcm_play_dma_pause(bool pause) | 114 | void pcm_play_dma_pause(bool pause) |
@@ -122,13 +124,14 @@ size_t pcm_get_bytes_waiting(void) | |||
122 | return pcm_data_size; | 124 | return pcm_data_size; |
123 | } | 125 | } |
124 | 126 | ||
125 | extern int sim_volume; /* in firmware/sound.c */ | 127 | void write_to_soundcard(struct pcm_udata *udata) |
126 | static void write_to_soundcard(struct pcm_udata *udata) { | 128 | { |
129 | #ifdef DEBUG | ||
127 | if (debug_audio && (udata->debug == NULL)) { | 130 | if (debug_audio && (udata->debug == NULL)) { |
128 | udata->debug = fopen("audiodebug.raw", "ab"); | 131 | udata->debug = fopen("audiodebug.raw", "ab"); |
129 | DEBUGF("Audio debug file open\n"); | 132 | DEBUGF("Audio debug file open\n"); |
130 | } | 133 | } |
131 | 134 | #endif | |
132 | if (cvt.needed) { | 135 | if (cvt.needed) { |
133 | Uint32 rd = udata->num_in; | 136 | Uint32 rd = udata->num_in; |
134 | Uint32 wr = (double)rd * cvt.len_ratio; | 137 | Uint32 wr = (double)rd * cvt.len_ratio; |
@@ -162,10 +165,11 @@ static void write_to_soundcard(struct pcm_udata *udata) { | |||
162 | udata->num_in = cvt.len / pcm_sample_bytes; | 165 | udata->num_in = cvt.len / pcm_sample_bytes; |
163 | udata->num_out = cvt.len_cvt / pcm_sample_bytes; | 166 | udata->num_out = cvt.len_cvt / pcm_sample_bytes; |
164 | 167 | ||
168 | #ifdef DEBUG | ||
165 | if (udata->debug != NULL) { | 169 | if (udata->debug != NULL) { |
166 | fwrite(cvt.buf, sizeof(Uint8), cvt.len_cvt, udata->debug); | 170 | fwrite(cvt.buf, sizeof(Uint8), cvt.len_cvt, udata->debug); |
167 | } | 171 | } |
168 | 172 | #endif | |
169 | free(cvt.buf); | 173 | free(cvt.buf); |
170 | } | 174 | } |
171 | else { | 175 | else { |
@@ -191,26 +195,27 @@ static void write_to_soundcard(struct pcm_udata *udata) { | |||
191 | break; | 195 | break; |
192 | } | 196 | } |
193 | } | 197 | } |
194 | 198 | #ifdef DEBUG | |
195 | if (udata->debug != NULL) { | 199 | if (udata->debug != NULL) { |
196 | fwrite(udata->stream, sizeof(Uint8), wr, udata->debug); | 200 | fwrite(udata->stream, sizeof(Uint8), wr, udata->debug); |
197 | } | 201 | } |
202 | #endif | ||
198 | } | 203 | } |
199 | } else { | 204 | } else { |
200 | udata->num_in = udata->num_out = MIN(udata->num_in, udata->num_out); | 205 | udata->num_in = udata->num_out = MIN(udata->num_in, udata->num_out); |
201 | SDL_MixAudio(udata->stream, pcm_data, | 206 | SDL_MixAudio(udata->stream, pcm_data, |
202 | udata->num_out * pcm_sample_bytes, sim_volume); | 207 | udata->num_out * pcm_sample_bytes, sim_volume); |
203 | 208 | #ifdef DEBUG | |
204 | if (udata->debug != NULL) { | 209 | if (udata->debug != NULL) { |
205 | fwrite(pcm_data, sizeof(Uint8), udata->num_out * pcm_sample_bytes, | 210 | fwrite(pcm_data, sizeof(Uint8), udata->num_out * pcm_sample_bytes, |
206 | udata->debug); | 211 | udata->debug); |
207 | } | 212 | } |
213 | #endif | ||
208 | } | 214 | } |
209 | } | 215 | } |
210 | 216 | ||
211 | static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len) | 217 | void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len) |
212 | { | 218 | { |
213 | logf("sdl_audio_callback: len %d, pcm %d\n", len, pcm_data_size); | ||
214 | udata->stream = stream; | 219 | udata->stream = stream; |
215 | 220 | ||
216 | /* Write what we have in the PCM buffer */ | 221 | /* Write what we have in the PCM buffer */ |
@@ -221,6 +226,7 @@ static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len) | |||
221 | while (len > 0) { | 226 | while (len > 0) { |
222 | if ((ssize_t)pcm_data_size <= 0) { | 227 | if ((ssize_t)pcm_data_size <= 0) { |
223 | pcm_data_size = 0; | 228 | pcm_data_size = 0; |
229 | |||
224 | if (pcm_callback_for_more) | 230 | if (pcm_callback_for_more) |
225 | pcm_callback_for_more(&pcm_data, &pcm_data_size); | 231 | pcm_callback_for_more(&pcm_data, &pcm_data_size); |
226 | } | 232 | } |
@@ -302,14 +308,20 @@ const void * pcm_rec_dma_get_peak_buffer(void) | |||
302 | 308 | ||
303 | void pcm_play_dma_init(void) | 309 | void pcm_play_dma_init(void) |
304 | { | 310 | { |
311 | if (SDL_InitSubSystem(SDL_INIT_AUDIO)) | ||
312 | { | ||
313 | DEBUGF("Could not initialize SDL audio subsystem!\n"); | ||
314 | return; | ||
315 | } | ||
316 | |||
305 | SDL_AudioSpec wanted_spec; | 317 | SDL_AudioSpec wanted_spec; |
318 | #ifdef DEBUG | ||
306 | udata.debug = NULL; | 319 | udata.debug = NULL; |
307 | |||
308 | if (debug_audio) { | 320 | if (debug_audio) { |
309 | udata.debug = fopen("audiodebug.raw", "wb"); | 321 | udata.debug = fopen("audiodebug.raw", "wb"); |
310 | DEBUGF("Audio debug file open\n"); | 322 | DEBUGF("Audio debug file open\n"); |
311 | } | 323 | } |
312 | 324 | #endif | |
313 | /* Set 16-bit stereo audio at 44Khz */ | 325 | /* Set 16-bit stereo audio at 44Khz */ |
314 | wanted_spec.freq = 44100; | 326 | wanted_spec.freq = 44100; |
315 | wanted_spec.format = AUDIO_S16SYS; | 327 | wanted_spec.format = AUDIO_S16SYS; |
@@ -322,7 +334,7 @@ void pcm_play_dma_init(void) | |||
322 | 334 | ||
323 | /* Open the audio device and start playing sound! */ | 335 | /* Open the audio device and start playing sound! */ |
324 | if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) { | 336 | if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) { |
325 | fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); | 337 | DEBUGF("Unable to open audio: %s\n", SDL_GetError()); |
326 | return; | 338 | return; |
327 | } | 339 | } |
328 | 340 | ||
@@ -339,7 +351,7 @@ void pcm_play_dma_init(void) | |||
339 | pcm_channel_bytes = 2; | 351 | pcm_channel_bytes = 2; |
340 | break; | 352 | break; |
341 | default: | 353 | default: |
342 | fprintf(stderr, "Unknown sample format obtained: %u\n", | 354 | DEBUGF("Unknown sample format obtained: %u\n", |
343 | (unsigned)obtained.format); | 355 | (unsigned)obtained.format); |
344 | return; | 356 | return; |
345 | } | 357 | } |
@@ -353,74 +365,9 @@ void pcm_postinit(void) | |||
353 | { | 365 | { |
354 | } | 366 | } |
355 | 367 | ||
356 | #endif /* CONFIG_CODEC == SWCODEC */ | 368 | void pcm_set_mixer_volume(int volume) |
357 | |||
358 | /** | ||
359 | * Audio Hardware api. Make them do nothing as we cannot properly simulate with | ||
360 | * SDL. if we used DSP we would run code that doesn't actually run on the target | ||
361 | **/ | ||
362 | void audiohw_set_volume(int volume) | ||
363 | { | 369 | { |
364 | sim_volume = SDL_MIX_MAXVOLUME * ((volume - VOLUME_MIN) / 10) / (VOLUME_RANGE / 10); | 370 | sim_volume = volume; |
365 | } | ||
366 | #if defined(AUDIOHW_HAVE_PRESCALER) | ||
367 | void audiohw_set_prescaler(int value) { (void)value; } | ||
368 | #endif | ||
369 | #if defined(AUDIOHW_HAVE_BALANCE) | ||
370 | void audiohw_set_balance(int value) { (void)value; } | ||
371 | #endif | ||
372 | #if defined(AUDIOHW_HAVE_BASS) | ||
373 | void audiohw_set_bass(int value) { (void)value; } | ||
374 | #endif | ||
375 | #if defined(AUDIOHW_HAVE_TREBLE) | ||
376 | void audiohw_set_treble(int value) { (void)value; } | ||
377 | #endif | ||
378 | #if CONFIG_CODEC != SWCODEC | ||
379 | void audiohw_set_channel(int value) { (void)value; } | ||
380 | void audiohw_set_stereo_width(int value){ (void)value; } | ||
381 | #endif | ||
382 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) | ||
383 | void audiohw_set_bass_cutoff(int value) { (void)value; } | ||
384 | #endif | ||
385 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) | ||
386 | void audiohw_set_treble_cutoff(int value){ (void)value; } | ||
387 | #endif | ||
388 | /* EQ-based tone controls */ | ||
389 | #if defined(AUDIOHW_HAVE_EQ) | ||
390 | void audiohw_set_eq_band_gain(unsigned int band, int value) | ||
391 | { (void)band; (void)value; } | ||
392 | #endif | ||
393 | #if defined(AUDIOHW_HAVE_EQ_FREQUENCY) | ||
394 | void audiohw_set_eq_band_frequency(unsigned int band, int value) | ||
395 | { (void)band; (void)value; } | ||
396 | #endif | ||
397 | #if defined(AUDIOHW_HAVE_EQ_WIDTH) | ||
398 | void audiohw_set_eq_band_width(unsigned int band, int value) | ||
399 | { (void)band; (void)value; } | ||
400 | #endif | ||
401 | #if defined(AUDIOHW_HAVE_DEPTH_3D) | ||
402 | void audiohw_set_depth_3d(int value) | ||
403 | { (void)value; } | ||
404 | #endif | ||
405 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
406 | int mas_codec_readreg(int reg) | ||
407 | { | ||
408 | (void)reg; | ||
409 | return 0; | ||
410 | } | 371 | } |
411 | 372 | ||
412 | int mas_codec_writereg(int reg, unsigned int val) | 373 | #endif /* CONFIG_CODEC == SWCODEC */ |
413 | { | ||
414 | (void)reg; | ||
415 | (void)val; | ||
416 | return 0; | ||
417 | } | ||
418 | int mas_writemem(int bank, int addr, const unsigned long* src, int len) | ||
419 | { | ||
420 | (void)bank; | ||
421 | (void)addr; | ||
422 | (void)src; | ||
423 | (void)len; | ||
424 | return 0; | ||
425 | } | ||
426 | #endif | ||
diff --git a/uisimulator/sdl/uisdl.h b/firmware/target/hosted/sdl/sim-ui-defines.h index dac84ffb74..567a618fc3 100644 --- a/uisimulator/sdl/uisdl.h +++ b/firmware/target/hosted/sdl/sim-ui-defines.h | |||
@@ -397,12 +397,9 @@ | |||
397 | #define UI_LCD_POSX 101 | 397 | #define UI_LCD_POSX 101 |
398 | #define UI_LCD_POSY 195 | 398 | #define UI_LCD_POSY 195 |
399 | 399 | ||
400 | #else | 400 | #elif defined(SIMULATOR) |
401 | #error no UI defines | 401 | #error no UI defines |
402 | #endif | 402 | #endif |
403 | extern SDL_Surface *gui_surface; | ||
404 | extern bool background; /* True if the background image is enabled */ | ||
405 | extern int display_zoom; | ||
406 | 403 | ||
407 | #endif /* #ifndef __UISDL_H__ */ | 404 | #endif /* #ifndef __UISDL_H__ */ |
408 | 405 | ||
diff --git a/uisimulator/sdl/uisdl.c b/firmware/target/hosted/sdl/system-sdl.c index 8cf4b42ba0..693e8d1b57 100644 --- a/uisimulator/sdl/uisdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c | |||
@@ -19,15 +19,13 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include <SDL.h> | ||
22 | #include <stdlib.h> | 23 | #include <stdlib.h> |
23 | #include <string.h> | 24 | #include <string.h> |
24 | #include <setjmp.h> | 25 | #include <setjmp.h> |
25 | #include "autoconf.h" | ||
26 | #include "button.h" | ||
27 | #include "system-sdl.h" | 26 | #include "system-sdl.h" |
28 | #include "thread.h" | 27 | #include "thread-sdl.h" |
29 | #include "kernel.h" | 28 | #include "sim-ui-defines.h" |
30 | #include "uisdl.h" | ||
31 | #include "lcd-sdl.h" | 29 | #include "lcd-sdl.h" |
32 | #ifdef HAVE_LCD_BITMAP | 30 | #ifdef HAVE_LCD_BITMAP |
33 | #include "lcd-bitmap.h" | 31 | #include "lcd-bitmap.h" |
@@ -37,162 +35,58 @@ | |||
37 | #ifdef HAVE_REMOTE_LCD | 35 | #ifdef HAVE_REMOTE_LCD |
38 | #include "lcd-remote-bitmap.h" | 36 | #include "lcd-remote-bitmap.h" |
39 | #endif | 37 | #endif |
40 | #include "thread-sdl.h" | 38 | #include "panic.h" |
41 | #include "SDL_mutex.h" | 39 | #include "debug.h" |
42 | #include "SDL_thread.h" | ||
43 | #include "math.h" | ||
44 | 40 | ||
41 | SDL_Surface *gui_surface; | ||
45 | 42 | ||
46 | /* extern functions */ | 43 | bool background = true; /* use backgrounds by default */ |
47 | extern void new_key(int key); | ||
48 | extern int xy2button( int x, int y); | ||
49 | void button_event(int key, bool pressed); | ||
50 | |||
51 | SDL_Surface *gui_surface; | ||
52 | bool background = true; /* use backgrounds by default */ | ||
53 | #ifdef HAVE_REMOTE_LCD | 44 | #ifdef HAVE_REMOTE_LCD |
54 | static bool showremote = true; /* include remote by default */ | 45 | bool showremote = true; /* include remote by default */ |
55 | #endif | 46 | #endif |
56 | bool mapping = false; | 47 | bool mapping = false; |
57 | bool debug_buttons = false; | 48 | bool debug_buttons = false; |
58 | 49 | ||
59 | bool lcd_display_redraw = true; /* Used for player simulator */ | 50 | bool lcd_display_redraw = true; /* Used for player simulator */ |
60 | char having_new_lcd = true; /* Used for player simulator */ | 51 | char having_new_lcd = true; /* Used for player simulator */ |
61 | bool sim_alarm_wakeup = false; | 52 | bool sim_alarm_wakeup = false; |
62 | const char *sim_root_dir = NULL; | 53 | const char *sim_root_dir = NULL; |
54 | extern int display_zoom; | ||
63 | 55 | ||
56 | #ifdef DEBUG | ||
64 | bool debug_audio = false; | 57 | bool debug_audio = false; |
58 | #endif | ||
65 | 59 | ||
66 | bool debug_wps = false; | 60 | bool debug_wps = false; |
67 | int wps_verbose_level = 3; | 61 | int wps_verbose_level = 3; |
68 | 62 | ||
69 | 63 | ||
70 | void irq_button_event(int key, bool pressed) { | 64 | void sys_poweroff(void) |
71 | sim_enter_irq_handler(); | ||
72 | button_event( key, pressed ); | ||
73 | sim_exit_irq_handler(); | ||
74 | } | ||
75 | |||
76 | int sqr( int a ) { | ||
77 | return a*a; | ||
78 | } | ||
79 | |||
80 | void gui_message_loop(void) | ||
81 | { | 65 | { |
82 | SDL_Event event; | 66 | /* Order here is relevent to prevent deadlocks and use of destroyed |
83 | bool done = false; | 67 | sync primitives by kernel threads */ |
84 | static int x,y,xybutton = 0; | 68 | sim_thread_shutdown(); |
85 | 69 | sim_kernel_shutdown(); | |
86 | while(!done && SDL_WaitEvent(&event)) | 70 | SDL_Quit(); |
87 | { | ||
88 | switch(event.type) | ||
89 | { | ||
90 | case SDL_KEYDOWN: | ||
91 | irq_button_event(event.key.keysym.sym, true); | ||
92 | break; | ||
93 | case SDL_KEYUP: | ||
94 | irq_button_event(event.key.keysym.sym, false); | ||
95 | case SDL_MOUSEBUTTONDOWN: | ||
96 | switch ( event.button.button ) { | ||
97 | #ifdef HAVE_SCROLLWHEEL | ||
98 | case SDL_BUTTON_WHEELUP: | ||
99 | irq_button_event( SDLK_UP, true ); | ||
100 | break; | ||
101 | case SDL_BUTTON_WHEELDOWN: | ||
102 | irq_button_event( SDLK_DOWN, true ); | ||
103 | break; | ||
104 | #endif | ||
105 | case SDL_BUTTON_LEFT: | ||
106 | case SDL_BUTTON_MIDDLE: | ||
107 | if ( mapping && background ) { | ||
108 | x = event.button.x; | ||
109 | y = event.button.y; | ||
110 | } | ||
111 | if ( background ) { | ||
112 | xybutton = xy2button( event.button.x, event.button.y ); | ||
113 | if( xybutton ) | ||
114 | irq_button_event( xybutton, true ); | ||
115 | } | ||
116 | break; | ||
117 | default: | ||
118 | break; | ||
119 | } | ||
120 | |||
121 | if (debug_wps && event.button.button == 1) | ||
122 | { | ||
123 | if ( background ) | ||
124 | #ifdef HAVE_REMOTE | ||
125 | if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */ | ||
126 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 ); | ||
127 | else | ||
128 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 ); | ||
129 | #else | ||
130 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 ); | ||
131 | #endif | ||
132 | else | ||
133 | if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */ | ||
134 | printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom ); | ||
135 | #ifdef HAVE_REMOTE | ||
136 | else | ||
137 | printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT ); | ||
138 | #endif | ||
139 | } | ||
140 | break; | ||
141 | case SDL_MOUSEBUTTONUP: | ||
142 | switch ( event.button.button ) { | ||
143 | /* The scrollwheel button up events are ignored as they are queued immediately */ | ||
144 | case SDL_BUTTON_LEFT: | ||
145 | case SDL_BUTTON_MIDDLE: | ||
146 | if ( mapping && background ) { | ||
147 | printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, y, (int)sqrt( sqr(x-(int)event.button.x) + sqr(y-(int)event.button.y)) ); | ||
148 | } | ||
149 | if ( background && xybutton ) { | ||
150 | irq_button_event( xybutton, false ); | ||
151 | xybutton = 0; | ||
152 | } | ||
153 | #ifdef HAVE_TOUCHSCREEN | ||
154 | else { | ||
155 | irq_button_event(BUTTON_TOUCHSCREEN, false); | ||
156 | } | ||
157 | #endif | ||
158 | break; | ||
159 | default: | ||
160 | break; | ||
161 | } | ||
162 | break; | ||
163 | |||
164 | |||
165 | case SDL_QUIT: | ||
166 | done = true; | ||
167 | break; | ||
168 | default: | ||
169 | /*printf("Unhandled event\n"); */ | ||
170 | break; | ||
171 | } | ||
172 | } | ||
173 | } | 71 | } |
174 | 72 | ||
175 | bool gui_startup(void) | 73 | void system_init(void) |
176 | { | 74 | { |
177 | SDL_Surface *picture_surface; | 75 | SDL_Surface *picture_surface; |
178 | int width, height; | 76 | int width, height; |
179 | 77 | ||
180 | if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) { | 78 | if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER)) |
181 | fprintf(stderr, "fatal: %s\n", SDL_GetError()); | 79 | panicf("%s", SDL_GetError()); |
182 | return false; | ||
183 | } | ||
184 | |||
185 | atexit(SDL_Quit); | ||
186 | 80 | ||
187 | /* Try and load the background image. If it fails go without */ | 81 | /* Try and load the background image. If it fails go without */ |
188 | if (background) { | 82 | if (background) { |
189 | picture_surface = SDL_LoadBMP("UI256.bmp"); | 83 | picture_surface = SDL_LoadBMP("UI256.bmp"); |
190 | if (picture_surface == NULL) { | 84 | if (picture_surface == NULL) { |
191 | background = false; | 85 | background = false; |
192 | fprintf(stderr, "warn: %s\n", SDL_GetError()); | 86 | DEBUGF("warn: %s\n", SDL_GetError()); |
193 | } | 87 | } |
194 | } | 88 | } |
195 | 89 | ||
196 | /* Set things up */ | 90 | /* Set things up */ |
197 | if (background) | 91 | if (background) |
198 | { | 92 | { |
@@ -217,8 +111,7 @@ bool gui_startup(void) | |||
217 | 111 | ||
218 | 112 | ||
219 | if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) { | 113 | if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) { |
220 | fprintf(stderr, "fatal: %s\n", SDL_GetError()); | 114 | panicf("%s", SDL_GetError()); |
221 | return false; | ||
222 | } | 115 | } |
223 | 116 | ||
224 | SDL_WM_SetCaption(UI_TITLE, NULL); | 117 | SDL_WM_SetCaption(UI_TITLE, NULL); |
@@ -229,43 +122,38 @@ bool gui_startup(void) | |||
229 | sim_lcd_remote_init(); | 122 | sim_lcd_remote_init(); |
230 | #endif | 123 | #endif |
231 | 124 | ||
232 | SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); | ||
233 | |||
234 | if (background && picture_surface != NULL) { | 125 | if (background && picture_surface != NULL) { |
235 | SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); | 126 | SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); |
236 | SDL_UpdateRect(gui_surface, 0, 0, 0, 0); | 127 | SDL_UpdateRect(gui_surface, 0, 0, 0, 0); |
237 | } | 128 | } |
238 | |||
239 | return true; | ||
240 | } | 129 | } |
241 | 130 | ||
242 | bool gui_shutdown(void) | 131 | void system_exception_wait(void) |
243 | { | 132 | { |
244 | /* Order here is relevent to prevent deadlocks and use of destroyed | 133 | sim_thread_exception_wait(); |
245 | sync primitives by kernel threads */ | ||
246 | thread_sdl_shutdown(); | ||
247 | sim_kernel_shutdown(); | ||
248 | return true; | ||
249 | } | 134 | } |
250 | 135 | ||
251 | #if defined(WIN32) && defined(main) | 136 | void system_reboot(void) |
252 | /* Don't use SDL_main on windows -> no more stdio redirection */ | 137 | { |
253 | #undef main | 138 | sim_thread_exception_wait(); |
254 | #endif | 139 | } |
255 | 140 | ||
256 | int main(int argc, char *argv[]) | 141 | void sys_handle_argv(int argc, char *argv[]) |
257 | { | 142 | { |
258 | if (argc >= 1) | 143 | if (argc >= 1) |
259 | { | 144 | { |
260 | int x; | 145 | int x; |
261 | for (x = 1; x < argc; x++) | 146 | for (x = 1; x < argc; x++) |
262 | { | 147 | { |
148 | #ifdef DEBUG | ||
263 | if (!strcmp("--debugaudio", argv[x])) | 149 | if (!strcmp("--debugaudio", argv[x])) |
264 | { | 150 | { |
265 | debug_audio = true; | 151 | debug_audio = true; |
266 | printf("Writing debug audio file.\n"); | 152 | printf("Writing debug audio file.\n"); |
267 | } | 153 | } |
268 | else if (!strcmp("--debugwps", argv[x])) | 154 | else |
155 | #endif | ||
156 | if (!strcmp("--debugwps", argv[x])) | ||
269 | { | 157 | { |
270 | debug_wps = true; | 158 | debug_wps = true; |
271 | printf("WPS debug mode enabled.\n"); | 159 | printf("WPS debug mode enabled.\n"); |
@@ -325,7 +213,9 @@ int main(int argc, char *argv[]) | |||
325 | { | 213 | { |
326 | printf("rockboxui\n"); | 214 | printf("rockboxui\n"); |
327 | printf("Arguments:\n"); | 215 | printf("Arguments:\n"); |
216 | #ifdef DEBUG | ||
328 | printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n"); | 217 | printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n"); |
218 | #endif | ||
329 | printf(" --debugwps \t Print advanced WPS debug info\n"); | 219 | printf(" --debugwps \t Print advanced WPS debug info\n"); |
330 | printf(" --nobackground \t Disable the background image\n"); | 220 | printf(" --nobackground \t Disable the background image\n"); |
331 | #ifdef HAVE_REMOTE_LCD | 221 | #ifdef HAVE_REMOTE_LCD |
@@ -340,29 +230,7 @@ int main(int argc, char *argv[]) | |||
340 | } | 230 | } |
341 | } | 231 | } |
342 | } | 232 | } |
343 | |||
344 | if (display_zoom > 1) { | 233 | if (display_zoom > 1) { |
345 | background = false; | 234 | background = false; |
346 | } | 235 | } |
347 | |||
348 | if (!sim_kernel_init()) { | ||
349 | fprintf(stderr, "sim_kernel_init failed\n"); | ||
350 | return -1; | ||
351 | } | ||
352 | |||
353 | if (!gui_startup()) { | ||
354 | fprintf(stderr, "gui_startup failed\n"); | ||
355 | return -1; | ||
356 | } | ||
357 | |||
358 | /* app_main will be called by the new main thread */ | ||
359 | if (!thread_sdl_init(NULL)) { | ||
360 | fprintf(stderr, "thread_sdl_init failed\n"); | ||
361 | return -1; | ||
362 | } | ||
363 | |||
364 | gui_message_loop(); | ||
365 | |||
366 | return gui_shutdown(); | ||
367 | } | 236 | } |
368 | |||
diff --git a/uisimulator/sdl/system-sdl.h b/firmware/target/hosted/sdl/system-sdl.h index 04e033e330..917e6e89da 100644 --- a/uisimulator/sdl/system-sdl.h +++ b/firmware/target/hosted/sdl/system-sdl.h | |||
@@ -41,9 +41,12 @@ int set_irq_level(int level); | |||
41 | 41 | ||
42 | void sim_enter_irq_handler(void); | 42 | void sim_enter_irq_handler(void); |
43 | void sim_exit_irq_handler(void); | 43 | void sim_exit_irq_handler(void); |
44 | bool sim_kernel_init(void); | ||
45 | void sim_kernel_shutdown(void); | 44 | void sim_kernel_shutdown(void); |
45 | void sys_poweroff(void); | ||
46 | void sys_handle_argv(int argc, char *argv[]); | ||
46 | 47 | ||
48 | extern bool background; /* True if the background image is enabled */ | ||
49 | extern int display_zoom; | ||
47 | extern long start_tick; | 50 | extern long start_tick; |
48 | 51 | ||
49 | #endif /* _SYSTEM_SDL_H_ */ | 52 | #endif /* _SYSTEM_SDL_H_ */ |
diff --git a/uisimulator/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c index e9b5fc205d..fbe2621d40 100644 --- a/uisimulator/sdl/thread-sdl.c +++ b/firmware/target/hosted/sdl/thread-sdl.c | |||
@@ -56,12 +56,15 @@ struct thread_entry threads[MAXTHREADS]; | |||
56 | * in their start routines responding to messages so this is the only | 56 | * in their start routines responding to messages so this is the only |
57 | * way to get them back in there so they may exit */ | 57 | * way to get them back in there so they may exit */ |
58 | static jmp_buf thread_jmpbufs[MAXTHREADS]; | 58 | static jmp_buf thread_jmpbufs[MAXTHREADS]; |
59 | /* this mutex locks out other Rockbox threads while one runs, | ||
60 | * that enables us to simulate a cooperative environment even if | ||
61 | * the host is preemptive */ | ||
59 | static SDL_mutex *m; | 62 | static SDL_mutex *m; |
60 | static volatile bool threads_exit = false; | 63 | static volatile bool threads_exit = false; |
61 | 64 | ||
62 | extern long start_tick; | 65 | extern long start_tick; |
63 | 66 | ||
64 | void thread_sdl_shutdown(void) | 67 | void sim_thread_shutdown(void) |
65 | { | 68 | { |
66 | int i; | 69 | int i; |
67 | 70 | ||
@@ -79,6 +82,7 @@ void thread_sdl_shutdown(void) | |||
79 | for (i = 0; i < MAXTHREADS; i++) | 82 | for (i = 0; i < MAXTHREADS; i++) |
80 | { | 83 | { |
81 | struct thread_entry *thread = &threads[i]; | 84 | struct thread_entry *thread = &threads[i]; |
85 | /* exit all current threads, except the main one */ | ||
82 | if (thread->context.t != NULL) | 86 | if (thread->context.t != NULL) |
83 | { | 87 | { |
84 | /* Signal thread on delay or block */ | 88 | /* Signal thread on delay or block */ |
@@ -128,30 +132,9 @@ static struct thread_entry * find_empty_thread_slot(void) | |||
128 | return thread; | 132 | return thread; |
129 | } | 133 | } |
130 | 134 | ||
131 | /* Do main thread creation in this file scope to avoid the need to double- | ||
132 | return to a prior call-level which would be unaware of the fact setjmp | ||
133 | was used */ | ||
134 | extern void app_main(void *param); | ||
135 | static int thread_sdl_app_main(void *param) | ||
136 | { | ||
137 | SDL_LockMutex(m); | ||
138 | cores[CURRENT_CORE].running = &threads[0]; | ||
139 | |||
140 | /* Set the jump address for return */ | ||
141 | if (setjmp(thread_jmpbufs[0]) == 0) | ||
142 | { | ||
143 | app_main(param); | ||
144 | /* should not ever be reached but... */ | ||
145 | THREAD_PANICF("app_main returned!\n"); | ||
146 | } | ||
147 | |||
148 | /* Unlock and exit */ | ||
149 | SDL_UnlockMutex(m); | ||
150 | return 0; | ||
151 | } | ||
152 | 135 | ||
153 | /* Initialize SDL threading */ | 136 | /* Initialize SDL threading */ |
154 | bool thread_sdl_init(void *param) | 137 | void init_threads(void) |
155 | { | 138 | { |
156 | struct thread_entry *thread; | 139 | struct thread_entry *thread; |
157 | int n; | 140 | int n; |
@@ -164,7 +147,7 @@ bool thread_sdl_init(void *param) | |||
164 | if (SDL_LockMutex(m) == -1) | 147 | if (SDL_LockMutex(m) == -1) |
165 | { | 148 | { |
166 | fprintf(stderr, "Couldn't lock mutex\n"); | 149 | fprintf(stderr, "Couldn't lock mutex\n"); |
167 | return false; | 150 | return; |
168 | } | 151 | } |
169 | 152 | ||
170 | /* Initialize all IDs */ | 153 | /* Initialize all IDs */ |
@@ -180,30 +163,21 @@ bool thread_sdl_init(void *param) | |||
180 | thread->name = "main"; | 163 | thread->name = "main"; |
181 | thread->state = STATE_RUNNING; | 164 | thread->state = STATE_RUNNING; |
182 | thread->context.s = SDL_CreateSemaphore(0); | 165 | thread->context.s = SDL_CreateSemaphore(0); |
166 | thread->context.t = NULL; /* NULL for the implicit main thread */ | ||
183 | cores[CURRENT_CORE].running = thread; | 167 | cores[CURRENT_CORE].running = thread; |
184 | 168 | ||
185 | if (thread->context.s == NULL) | 169 | if (thread->context.s == NULL) |
186 | { | 170 | { |
187 | fprintf(stderr, "Failed to create main semaphore\n"); | 171 | fprintf(stderr, "Failed to create main semaphore\n"); |
188 | return false; | 172 | return; |
189 | } | ||
190 | |||
191 | thread->context.t = SDL_CreateThread(thread_sdl_app_main, param); | ||
192 | |||
193 | if (thread->context.t == NULL) | ||
194 | { | ||
195 | SDL_DestroySemaphore(thread->context.s); | ||
196 | fprintf(stderr, "Failed to create main thread\n"); | ||
197 | return false; | ||
198 | } | 173 | } |
199 | 174 | ||
200 | THREAD_SDL_DEBUGF("Main thread: %p\n", thread); | 175 | THREAD_SDL_DEBUGF("Main thread: %p\n", thread); |
201 | 176 | ||
202 | SDL_UnlockMutex(m); | 177 | return; |
203 | return true; | ||
204 | } | 178 | } |
205 | 179 | ||
206 | void thread_sdl_exception_wait(void) | 180 | void sim_thread_exception_wait(void) |
207 | { | 181 | { |
208 | while (1) | 182 | while (1) |
209 | { | 183 | { |
@@ -214,7 +188,7 @@ void thread_sdl_exception_wait(void) | |||
214 | } | 188 | } |
215 | 189 | ||
216 | /* A way to yield and leave the threading system for extended periods */ | 190 | /* A way to yield and leave the threading system for extended periods */ |
217 | void thread_sdl_thread_lock(void *me) | 191 | void sim_thread_lock(void *me) |
218 | { | 192 | { |
219 | SDL_LockMutex(m); | 193 | SDL_LockMutex(m); |
220 | cores[CURRENT_CORE].running = (struct thread_entry *)me; | 194 | cores[CURRENT_CORE].running = (struct thread_entry *)me; |
@@ -223,7 +197,7 @@ void thread_sdl_thread_lock(void *me) | |||
223 | thread_exit(); | 197 | thread_exit(); |
224 | } | 198 | } |
225 | 199 | ||
226 | void * thread_sdl_thread_unlock(void) | 200 | void * sim_thread_unlock(void) |
227 | { | 201 | { |
228 | struct thread_entry *current = cores[CURRENT_CORE].running; | 202 | struct thread_entry *current = cores[CURRENT_CORE].running; |
229 | SDL_UnlockMutex(m); | 203 | SDL_UnlockMutex(m); |
@@ -529,19 +503,6 @@ unsigned int create_thread(void (*function)(void), | |||
529 | return thread->id; | 503 | return thread->id; |
530 | } | 504 | } |
531 | 505 | ||
532 | void init_threads(void) | ||
533 | { | ||
534 | /* Main thread is already initialized */ | ||
535 | if (cores[CURRENT_CORE].running != &threads[0]) | ||
536 | { | ||
537 | THREAD_PANICF("Wrong main thread in init_threads: %p\n", | ||
538 | cores[CURRENT_CORE].running); | ||
539 | } | ||
540 | |||
541 | THREAD_SDL_DEBUGF("First Thread: %d (%s)\n", | ||
542 | 0, THREAD_SDL_GET_NAME(&threads[0])); | ||
543 | } | ||
544 | |||
545 | #ifndef ALLOW_REMOVE_THREAD | 506 | #ifndef ALLOW_REMOVE_THREAD |
546 | static void remove_thread(unsigned int thread_id) | 507 | static void remove_thread(unsigned int thread_id) |
547 | #else | 508 | #else |
diff --git a/uisimulator/sdl/thread-sdl.h b/firmware/target/hosted/sdl/thread-sdl.h index f221aa5a72..9384e6060d 100644 --- a/uisimulator/sdl/thread-sdl.h +++ b/firmware/target/hosted/sdl/thread-sdl.h | |||
@@ -22,16 +22,11 @@ | |||
22 | #ifndef __THREADSDL_H__ | 22 | #ifndef __THREADSDL_H__ |
23 | #define __THREADSDL_H__ | 23 | #define __THREADSDL_H__ |
24 | 24 | ||
25 | #include "SDL_thread.h" | 25 | /* extra thread functions that only apply when running on hosting platforms */ |
26 | 26 | void sim_thread_lock(void *me); | |
27 | extern SDL_Thread *gui_thread; /* The "main" thread */ | 27 | void * sim_thread_unlock(void); |
28 | void thread_sdl_thread_lock(void *me); | 28 | void sim_thread_exception_wait(void); |
29 | void * thread_sdl_thread_unlock(void); | 29 | void sim_thread_shutdown(void); /* Shut down all kernel threads gracefully */ |
30 | void thread_sdl_exception_wait(void); | ||
31 | bool thread_sdl_init(void *param); /* Init the sim threading API - thread created calls app_main */ | ||
32 | void thread_sdl_shutdown(void); /* Shut down all kernel threads gracefully */ | ||
33 | void thread_sdl_lock(void); /* Sync with SDL threads */ | ||
34 | void thread_sdl_unlock(void); /* Sync with SDL threads */ | ||
35 | 30 | ||
36 | #endif /* #ifndef __THREADSDL_H__ */ | 31 | #endif /* #ifndef __THREADSDL_H__ */ |
37 | 32 | ||
diff --git a/uisimulator/sdl/timer.c b/firmware/target/hosted/sdl/timer-sdl.c index 369aeab929..369aeab929 100644 --- a/uisimulator/sdl/timer.c +++ b/firmware/target/hosted/sdl/timer-sdl.c | |||
diff --git a/tools/configure b/tools/configure index 6b58e432ed..bf49be8a9e 100755 --- a/tools/configure +++ b/tools/configure | |||
@@ -2973,6 +2973,10 @@ EOF | |||
2973 | 2973 | ||
2974 | if test -n "$t_cpu"; then | 2974 | if test -n "$t_cpu"; then |
2975 | TARGET_INC="-I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer/$t_model" | 2975 | TARGET_INC="-I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer/$t_model" |
2976 | if [ "$simulator" = "yes" ]; then # a few more includes for the sim target tree | ||
2977 | TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/sdl/" | ||
2978 | TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/" | ||
2979 | fi | ||
2976 | TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer" | 2980 | TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu/$t_manufacturer" |
2977 | TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu" | 2981 | TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/$t_cpu" |
2978 | GCCOPTS="$GCCOPTS" | 2982 | GCCOPTS="$GCCOPTS" |
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index cddb19c9a8..bdcc7e6ca1 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c | |||
@@ -233,7 +233,7 @@ static ssize_t io_trigger_and_wait(int cmd) | |||
233 | { | 233 | { |
234 | /* Allow other rockbox threads to run */ | 234 | /* Allow other rockbox threads to run */ |
235 | io.accum = 0; | 235 | io.accum = 0; |
236 | mythread = thread_sdl_thread_unlock(); | 236 | mythread = sim_thread_unlock(); |
237 | } | 237 | } |
238 | 238 | ||
239 | switch (cmd) | 239 | switch (cmd) |
@@ -249,7 +249,7 @@ static ssize_t io_trigger_and_wait(int cmd) | |||
249 | /* Regain our status as current */ | 249 | /* Regain our status as current */ |
250 | if (mythread != NULL) | 250 | if (mythread != NULL) |
251 | { | 251 | { |
252 | thread_sdl_thread_lock(mythread); | 252 | sim_thread_lock(mythread); |
253 | } | 253 | } |
254 | 254 | ||
255 | return result; | 255 | return result; |
diff --git a/uisimulator/common/powermgmt-sim.c b/uisimulator/common/powermgmt-sim.c index e2ce8c10d2..dbd3149fbb 100644 --- a/uisimulator/common/powermgmt-sim.c +++ b/uisimulator/common/powermgmt-sim.c | |||
@@ -157,10 +157,6 @@ void shutdown_hw(void) | |||
157 | { | 157 | { |
158 | } | 158 | } |
159 | 159 | ||
160 | void sys_poweroff(void) | ||
161 | { | ||
162 | } | ||
163 | |||
164 | void cancel_shutdown(void) | 160 | void cancel_shutdown(void) |
165 | { | 161 | { |
166 | } | 162 | } |
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index d1ec4ec6c2..d4a9af126c 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c | |||
@@ -314,25 +314,9 @@ void cpu_sleep(bool enabled) | |||
314 | (void)enabled; | 314 | (void)enabled; |
315 | } | 315 | } |
316 | 316 | ||
317 | void button_set_flip(bool yesno) | ||
318 | { | ||
319 | (void)yesno; | ||
320 | } | ||
321 | |||
322 | #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING | 317 | #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING |
323 | void touchpad_set_sensitivity(int level) | 318 | void touchpad_set_sensitivity(int level) |
324 | { | 319 | { |
325 | (void)level; | 320 | (void)level; |
326 | } | 321 | } |
327 | #endif | 322 | #endif |
328 | |||
329 | void system_exception_wait(void) | ||
330 | { | ||
331 | thread_sdl_exception_wait(); | ||
332 | } | ||
333 | |||
334 | void system_reboot(void) | ||
335 | { | ||
336 | thread_sdl_exception_wait(); | ||
337 | } | ||
338 | |||
diff --git a/uisimulator/sdl/Makefile b/uisimulator/sdl/Makefile deleted file mode 100644 index dc76b35d68..0000000000 --- a/uisimulator/sdl/Makefile +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | ############################################################################ | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # $Id$ | ||
9 | # | ||
10 | # Copyright (C) 2002, 2008 by Daniel Stenberg <daniel@haxx.se> | ||
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 | SIMCOMMON = ../common | ||
21 | |||
22 | DEPFILE = $(OBJDIR)/dep-sim | ||
23 | |||
24 | RM = rm -f | ||
25 | DEBUG = -g | ||
26 | |||
27 | # Use this for simulator-only files | ||
28 | INCLUDES = -I. -I$(SIMCOMMON) -I$(OBJDIR) $(TARGET_INC) -I$(FIRMDIR)/export \ | ||
29 | -I$(APPSDIR) -I$(BUILDDIR) | ||
30 | |||
31 | # This sets up 'SRC' based on the files mentioned in SOURCES | ||
32 | include $(TOOLSDIR)/makesrc.inc | ||
33 | |||
34 | OBJS := $(SRC:%.c=$(OBJDIR)/%.o) | ||
35 | |||
36 | DEFINES := -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR \ | ||
37 | $(TARGET) -DAPPSVERSION=\"$(VERSION)\" -DMEM=${MEMORYSIZE} $(EXTRA_DEFINES) | ||
38 | |||
39 | SOURCES = $(SRC) | ||
40 | |||
41 | DIRS = . | ||
42 | |||
43 | CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) $(GCCOPTS) -W -Wall | ||
44 | |||
45 | OUTFILE = $(BUILDDIR)/libsim.a | ||
46 | |||
47 | all: $(OUTFILE) | ||
48 | |||
49 | include $(TOOLSDIR)/make.inc | ||
50 | |||
51 | $(OUTFILE): $(OBJS) $(BUILDDIR)/UI256.bmp | ||
52 | $(call PRINTS,AR+RANLIB $(@F))$(AR) ruv $@ $(OBJS) >/dev/null 2>&1 | ||
53 | $(SILENT)$(RANLIB) $@ | ||
54 | |||
55 | clean: | ||
56 | $(call PRINTS,cleaning sim)$(RM) $(OBJS) *~ core $(OUTFILE) $(DEPFILE) \ | ||
57 | $(BUILDDIR)/UI256.bmp $(DEPFILE) | ||
58 | $(SILENT)$(MAKE) -C $(SIMCOMMON) clean | ||
59 | |||
60 | ################## Specific dependencies ################## | ||
61 | $(BUILDDIR)/UI256.bmp: UI-$(MODELNAME).bmp | ||
62 | $(call PRINTS,UI)cp $< $@ | ||
63 | |||
64 | -include $(DEPFILE) | ||
diff --git a/uisimulator/sdl/README b/uisimulator/sdl/README deleted file mode 100644 index 0a293f6ad2..0000000000 --- a/uisimulator/sdl/README +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | To build: | ||
2 | |||
3 | $ ../tools/configure | ||
4 | [answer questions] | ||
5 | $ make | ||
6 | $ ./rockboxui | ||
diff --git a/uisimulator/sdl/SOURCES b/uisimulator/sdl/SOURCES deleted file mode 100644 index 1d5b498248..0000000000 --- a/uisimulator/sdl/SOURCES +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | button.c | ||
2 | kernel-sdl.c | ||
3 | #ifdef HAVE_LCD_BITMAP | ||
4 | lcd-bitmap.c | ||
5 | #elif defined(HAVE_LCD_CHARCELLS) | ||
6 | lcd-charcells.c | ||
7 | #endif | ||
8 | #ifdef HAVE_REMOTE_LCD | ||
9 | lcd-remote-bitmap.c | ||
10 | #endif | ||
11 | lcd-sdl.c | ||
12 | sound.c | ||
13 | timer.c | ||
14 | thread-sdl.c | ||
15 | uisdl.c | ||
diff --git a/uisimulator/sdl/button-sdl.h b/uisimulator/sdl/button-sdl.h deleted file mode 100644 index 948af62c5b..0000000000 --- a/uisimulator/sdl/button-sdl.h +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Thomas Martitz | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | |||
23 | #ifndef _BUTTON_SDL_H_ | ||
24 | #define _BUTTON_SDL_H_ | ||
25 | |||
26 | #include <stdbool.h> | ||
27 | #include "config.h" | ||
28 | #include "button-target.h" | ||
29 | |||
30 | #undef HAVE_LCD_FLIP | ||
31 | |||
32 | #undef button_init_device | ||
33 | #define button_init_device() | ||
34 | |||
35 | struct button_map { | ||
36 | int button, x, y, radius; | ||
37 | char *description; | ||
38 | }; | ||
39 | |||
40 | int xy2button( int x, int y); | ||
41 | bool button_hold(void); | ||
42 | void button_init_sdl(void); | ||
43 | #undef button_init_device | ||
44 | #define button_init_device() button_init_sdl() | ||
45 | |||
46 | #endif | ||
diff --git a/uisimulator/sdl/timefuncs.h b/uisimulator/sdl/timefuncs.h deleted file mode 100644 index de17fcdc73..0000000000 --- a/uisimulator/sdl/timefuncs.h +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | #include <time.h> | ||
2 | #include <stdbool.h> | ||
3 | |||
4 | /* struct tm defined */ | ||
5 | struct tm *get_time(void); | ||
6 | int set_time(const struct tm *tm); | ||
7 | bool valid_time(const struct tm *tm); | ||
diff --git a/uisimulator/uisimulator.make b/uisimulator/uisimulator.make index 121f31e0f6..86fcb2a3d2 100644 --- a/uisimulator/uisimulator.make +++ b/uisimulator/uisimulator.make | |||
@@ -8,13 +8,10 @@ | |||
8 | # | 8 | # |
9 | 9 | ||
10 | INCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \ | 10 | INCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \ |
11 | -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR) | ||
11 | 12 | ||
12 | SIMINCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \ | 13 | SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS) |
13 | -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR) | ||
14 | 14 | ||
15 | SIMFLAGS += $(SIMINCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS) | ||
16 | |||
17 | SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/sdl/SOURCES) | ||
18 | SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/common/SOURCES) | 15 | SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/common/SOURCES) |
19 | SIMOBJ = $(call c2obj,$(SIMSRC)) | 16 | SIMOBJ = $(call c2obj,$(SIMSRC)) |
20 | OTHER_SRC += $(SIMSRC) | 17 | OTHER_SRC += $(SIMSRC) |