summaryrefslogtreecommitdiff
path: root/firmware/target/hosted
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted')
-rw-r--r--firmware/target/hosted/agptek/debug-agptek.c6
-rw-r--r--firmware/target/hosted/aigo/power-erosq.c55
-rw-r--r--firmware/target/hosted/alsa-controls.h2
-rw-r--r--firmware/target/hosted/filesystem-hosted.h3
-rw-r--r--firmware/target/hosted/filesystem-unix.c6
-rw-r--r--firmware/target/hosted/filesystem-win32.c5
-rw-r--r--firmware/target/hosted/lcd-linuxfb.c24
-rw-r--r--firmware/target/hosted/power-linux.c5
-rw-r--r--firmware/target/hosted/sdl/app/button-application.c26
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c88
-rw-r--r--firmware/target/hosted/sdl/kernel-sdl.c12
-rw-r--r--firmware/target/hosted/sdl/key_to_touch-sdl.c19
-rw-r--r--firmware/target/hosted/sdl/lcd-bitmap.c9
-rw-r--r--firmware/target/hosted/sdl/lcd-sdl.c13
-rw-r--r--firmware/target/hosted/sdl/lcd-sdl.h4
-rw-r--r--firmware/target/hosted/sdl/pcm-sdl.c88
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c116
-rw-r--r--firmware/target/hosted/sdl/thread-sdl.c4
18 files changed, 277 insertions, 208 deletions
diff --git a/firmware/target/hosted/agptek/debug-agptek.c b/firmware/target/hosted/agptek/debug-agptek.c
index a9b829f7ec..de4bc946bc 100644
--- a/firmware/target/hosted/agptek/debug-agptek.c
+++ b/firmware/target/hosted/agptek/debug-agptek.c
@@ -37,6 +37,8 @@
37 37
38static int line = 0; 38static int line = 0;
39 39
40extern int hwver;
41
40bool dbg_hw_info(void) 42bool dbg_hw_info(void)
41{ 43{
42 int btn = 0; 44 int btn = 0;
@@ -61,6 +63,10 @@ bool dbg_hw_info(void)
61 lcd_putsf(0, line++, "Boot ver: %s", verstr); 63 lcd_putsf(0, line++, "Boot ver: %s", verstr);
62 } 64 }
63 65
66#ifdef EROS_Q
67 lcd_putsf(0, line++, "hwver: %d", hwver);
68#endif
69
64 lcd_putsf(0, line++, "pcm srate: %d", pcm_alsa_get_rate()); 70 lcd_putsf(0, line++, "pcm srate: %d", pcm_alsa_get_rate());
65 lcd_putsf(0, line++, "pcm xruns: %d", pcm_alsa_get_xruns()); 71 lcd_putsf(0, line++, "pcm xruns: %d", pcm_alsa_get_xruns());
66#ifdef HAVE_HEADPHONE_DETECTION 72#ifdef HAVE_HEADPHONE_DETECTION
diff --git a/firmware/target/hosted/aigo/power-erosq.c b/firmware/target/hosted/aigo/power-erosq.c
index 73fa5fe972..7c4515f616 100644
--- a/firmware/target/hosted/aigo/power-erosq.c
+++ b/firmware/target/hosted/aigo/power-erosq.c
@@ -28,17 +28,34 @@
28#include "power.h" 28#include "power.h"
29#include "panic.h" 29#include "panic.h"
30#include "sysfs.h" 30#include "sysfs.h"
31#include "tick.h"
31 32
32const char * const sysfs_bat_voltage = 33const char * const sysfs_bat_voltage[2] = {
33 "/sys/class/power_supply/battery/voltage_now"; 34 "/sys/class/power_supply/battery/voltage_now",
35 "/sys/class/power_supply/axp_battery/voltage_now",
36};
34 37
35const char * const sysfs_bat_capacity = 38const char * const sysfs_bat_capacity[2] = {
36 "/sys/class/power_supply/battery/capacity"; 39 "/sys/class/power_supply/battery/capacity",
40 "/sys/class/power_supply/axp_battery/capacity",
41};
42
43const char * const sysfs_bat_status[2] = {
44 "/sys/class/power_supply/battery/status",
45 "/sys/class/power_supply/axp_battery/status",
46};
47
48int hwver = 1; /* Exported */
37 49
38unsigned int erosq_power_get_battery_voltage(void) 50unsigned int erosq_power_get_battery_voltage(void)
39{ 51{
40 int battery_voltage; 52 int battery_voltage;
41 sysfs_get_int(sysfs_bat_voltage, &battery_voltage); 53 int x = sysfs_get_int(sysfs_bat_voltage[hwver == 4], &battery_voltage);
54
55 if (!x && hwver != 4) {
56 hwver = 4;
57 sysfs_get_int(sysfs_bat_voltage[hwver == 4], &battery_voltage);
58 }
42 59
43 return battery_voltage/1000; 60 return battery_voltage/1000;
44} 61}
@@ -46,7 +63,33 @@ unsigned int erosq_power_get_battery_voltage(void)
46unsigned int erosq_power_get_battery_capacity(void) 63unsigned int erosq_power_get_battery_capacity(void)
47{ 64{
48 int battery_capacity; 65 int battery_capacity;
49 sysfs_get_int(sysfs_bat_capacity, &battery_capacity); 66 int x = sysfs_get_int(sysfs_bat_capacity[hwver == 4], &battery_capacity);
67
68 if (!x && hwver != 4) {
69 hwver = 4;
70 sysfs_get_int(sysfs_bat_capacity[hwver == 4], &battery_capacity);
71 }
50 72
51 return battery_capacity; 73 return battery_capacity;
52} 74}
75
76/* We get called multiple times per tick, let's cut that back! */
77static long last_tick = 0;
78static bool last_power = false;
79
80bool charging_state(void)
81{
82 if ((current_tick - last_tick) > HZ/2 ) {
83 char buf[12] = {0};
84 int x = sysfs_get_string(sysfs_bat_status[hwver == 4], buf, sizeof(buf));
85
86 if (!x && hwver != 4) {
87 hwver = 4;
88 sysfs_get_string(sysfs_bat_status[hwver == 4], buf, sizeof(buf));
89 }
90
91 last_tick = current_tick;
92 last_power = (strncmp(buf, "Charging", 8) == 0);
93 }
94 return last_power;
95}
diff --git a/firmware/target/hosted/alsa-controls.h b/firmware/target/hosted/alsa-controls.h
index af3e584cd9..b868ef52fb 100644
--- a/firmware/target/hosted/alsa-controls.h
+++ b/firmware/target/hosted/alsa-controls.h
@@ -36,6 +36,8 @@ void alsa_controls_close(void);
36 36
37/* check wether a control exists */ 37/* check wether a control exists */
38bool alsa_has_control(const char *name); 38bool alsa_has_control(const char *name);
39/* find a control element ID by name, return -1 of not found or index into array */
40int alsa_controls_find(const char *name);
39/* find a control element enum index by name, return -1 if not found */ 41/* find a control element enum index by name, return -1 if not found */
40int alsa_controls_find_enum(const char *name, const char *enum_name); 42int alsa_controls_find_enum(const char *name, const char *enum_name);
41/* set a control, potentially supports several values */ 43/* set a control, potentially supports several values */
diff --git a/firmware/target/hosted/filesystem-hosted.h b/firmware/target/hosted/filesystem-hosted.h
index b9c7ce648a..348a921f82 100644
--- a/firmware/target/hosted/filesystem-hosted.h
+++ b/firmware/target/hosted/filesystem-hosted.h
@@ -21,9 +21,6 @@
21#ifndef _FILESYSTEM_HOSTED_H_ 21#ifndef _FILESYSTEM_HOSTED_H_
22#define _FILESYSTEM_HOSTED_H_ 22#define _FILESYSTEM_HOSTED_H_
23 23
24#include "mv.h"
25
26int os_volume_path(IF_MV(int volume, ) char *buffer, size_t bufsize);
27void * os_lc_open(const char *ospath); 24void * os_lc_open(const char *ospath);
28 25
29#endif /* _FILESYSTEM_HOSTED_H_ */ 26#endif /* _FILESYSTEM_HOSTED_H_ */
diff --git a/firmware/target/hosted/filesystem-unix.c b/firmware/target/hosted/filesystem-unix.c
index f0d7de640d..4869d07263 100644
--- a/firmware/target/hosted/filesystem-unix.c
+++ b/firmware/target/hosted/filesystem-unix.c
@@ -33,6 +33,8 @@
33#include "pathfuncs.h" 33#include "pathfuncs.h"
34#include "string-extra.h" 34#include "string-extra.h"
35 35
36int os_volume_path(IF_MV(int volume, ) char *buffer, size_t bufsize);
37
36#define SAME_FILE_INFO(sb1p, sb2p) \ 38#define SAME_FILE_INFO(sb1p, sb2p) \
37 ((sb1p)->st_dev == (sb2p)->st_dev && (sb1p)->st_ino == (sb2p)->st_ino) 39 ((sb1p)->st_dev == (sb2p)->st_dev && (sb1p)->st_ino == (sb2p)->st_ino)
38 40
@@ -207,9 +209,9 @@ int os_opendir_and_fd(const char *osdirname, DIR **osdirpp, int *osfdp)
207} 209}
208 210
209/* do we really need this in the app? (in the sim, yes) */ 211/* do we really need this in the app? (in the sim, yes) */
210void volume_size(IF_MV(int volume,) unsigned long *sizep, unsigned long *freep) 212void volume_size(IF_MV(int volume,) sector_t *sizep, sector_t *freep)
211{ 213{
212 unsigned long size = 0, free = 0; 214 sector_t size = 0, free = 0;
213 char volpath[MAX_PATH]; 215 char volpath[MAX_PATH];
214 struct statfs fs; 216 struct statfs fs;
215 217
diff --git a/firmware/target/hosted/filesystem-win32.c b/firmware/target/hosted/filesystem-win32.c
index fac10d003b..ebb7f283ac 100644
--- a/firmware/target/hosted/filesystem-win32.c
+++ b/firmware/target/hosted/filesystem-win32.c
@@ -30,6 +30,7 @@
30#include "debug.h" 30#include "debug.h"
31#include "pathfuncs.h" 31#include "pathfuncs.h"
32#include "string-extra.h" 32#include "string-extra.h"
33#include "mv.h"
33 34
34#define SAME_FILE_INFO(lpInfo1, lpInfo2) \ 35#define SAME_FILE_INFO(lpInfo1, lpInfo2) \
35 ((lpInfo1)->dwVolumeSerialNumber == (lpInfo2)->dwVolumeSerialNumber && \ 36 ((lpInfo1)->dwVolumeSerialNumber == (lpInfo2)->dwVolumeSerialNumber && \
@@ -469,7 +470,9 @@ int os_modtime(const char *path, time_t modtime)
469 return 0; 470 return 0;
470} 471}
471 472
472void volume_size(IF_MV(int volume,) unsigned long *sizep, unsigned long *freep) 473int os_volume_path(IF_MV(int volume, ) char *buffer, size_t bufsize);
474
475void volume_size(IF_MV(int volume,) sector_t *sizep, sector_t *freep)
473{ 476{
474 ULARGE_INTEGER free = { .QuadPart = 0 }, 477 ULARGE_INTEGER free = { .QuadPart = 0 },
475 size = { .QuadPart = 0 }; 478 size = { .QuadPart = 0 };
diff --git a/firmware/target/hosted/lcd-linuxfb.c b/firmware/target/hosted/lcd-linuxfb.c
index 14c8c30f89..5dda5cf1cc 100644
--- a/firmware/target/hosted/lcd-linuxfb.c
+++ b/firmware/target/hosted/lcd-linuxfb.c
@@ -59,14 +59,21 @@ void lcd_init_device(void)
59 panicf("Cannot read framebuffer fixed information"); 59 panicf("Cannot read framebuffer fixed information");
60 } 60 }
61 61
62#if 0 62 if(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
63 /* check resolution and framebuffer size */
64 if(vinfo.xres != LCD_WIDTH || vinfo.yres != LCD_HEIGHT || vinfo.bits_per_pixel != LCD_DEPTH)
65 { 63 {
66 panicf("Unexpected framebuffer resolution: %dx%dx%d\n", vinfo.xres, 64 panicf("Cannot read framebuffer variable information");
67 vinfo.yres, vinfo.bits_per_pixel); 65 }
66
67 /* Make sure we match our desired bitdepth */
68 if (vinfo.bits_per_pixel != LCD_DEPTH || vinfo.xres != LCD_WIDTH || vinfo.yres != LCD_HEIGHT) {
69 vinfo.bits_per_pixel = LCD_DEPTH;
70 vinfo.xres = LCD_WIDTH;
71 vinfo.yres = LCD_HEIGHT;
72 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo)) {
73 panicf("Cannot set framebuffer to %dx%dx%d",
74 vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
75 }
68 } 76 }
69#endif
70 /* Note: we use a framebuffer size of width*height*bbp. We cannot trust the 77 /* Note: we use a framebuffer size of width*height*bbp. We cannot trust the
71 * values returned by the driver for line_length */ 78 * values returned by the driver for line_length */
72 79
@@ -77,11 +84,6 @@ void lcd_init_device(void)
77 panicf("Cannot map framebuffer"); 84 panicf("Cannot map framebuffer");
78 } 85 }
79 86
80 if(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
81 {
82 panicf("Cannot read framebuffer variable information");
83 }
84
85 memset(framebuffer, 0, finfo.smem_len); 87 memset(framebuffer, 0, finfo.smem_len);
86 88
87#ifdef HAVE_LCD_ENABLE 89#ifdef HAVE_LCD_ENABLE
diff --git a/firmware/target/hosted/power-linux.c b/firmware/target/hosted/power-linux.c
index ddd7ad63e3..8d263eebec 100644
--- a/firmware/target/hosted/power-linux.c
+++ b/firmware/target/hosted/power-linux.c
@@ -33,9 +33,13 @@
33#include "usb.h" 33#include "usb.h"
34#endif 34#endif
35 35
36#ifdef BATTERY_DEV_NAME
36#define BATTERY_STATUS_PATH "/sys/class/power_supply/" BATTERY_DEV_NAME "/status" 37#define BATTERY_STATUS_PATH "/sys/class/power_supply/" BATTERY_DEV_NAME "/status"
38#endif
39
37#define POWER_STATUS_PATH "/sys/class/power_supply/" POWER_DEV_NAME "/online" 40#define POWER_STATUS_PATH "/sys/class/power_supply/" POWER_DEV_NAME "/online"
38 41
42#ifdef BATTERY_DEV_NAME
39/* We get called multiple times per tick, let's cut that back! */ 43/* We get called multiple times per tick, let's cut that back! */
40static long last_tick = 0; 44static long last_tick = 0;
41static bool last_power = false; 45static bool last_power = false;
@@ -51,6 +55,7 @@ bool charging_state(void)
51 } 55 }
52 return last_power; 56 return last_power;
53} 57}
58#endif
54 59
55unsigned int power_input_status(void) 60unsigned int power_input_status(void)
56{ 61{
diff --git a/firmware/target/hosted/sdl/app/button-application.c b/firmware/target/hosted/sdl/app/button-application.c
index 9c313b76b1..8071df201a 100644
--- a/firmware/target/hosted/sdl/app/button-application.c
+++ b/firmware/target/hosted/sdl/app/button-application.c
@@ -40,23 +40,23 @@ int key_to_button(int keyboard_key)
40#if (CONFIG_PLATFORM & PLATFORM_MAEMO4) 40#if (CONFIG_PLATFORM & PLATFORM_MAEMO4)
41 case SDLK_ESCAPE: 41 case SDLK_ESCAPE:
42#endif 42#endif
43 case SDLK_KP7: 43 case SDLK_KP_7:
44 new_btn = BUTTON_TOPLEFT; 44 new_btn = BUTTON_TOPLEFT;
45 break; 45 break;
46 case SDLK_KP8: 46 case SDLK_KP_8:
47 case SDLK_UP: 47 case SDLK_UP:
48 new_btn = BUTTON_TOPMIDDLE; 48 new_btn = BUTTON_TOPMIDDLE;
49 break; 49 break;
50#if (CONFIG_PLATFORM & PLATFORM_MAEMO4) 50#if (CONFIG_PLATFORM & PLATFORM_MAEMO4)
51 case SDLK_F7: 51 case SDLK_F7:
52#endif 52#endif
53 case SDLK_KP9: 53 case SDLK_KP_9:
54 new_btn = BUTTON_TOPRIGHT; 54 new_btn = BUTTON_TOPRIGHT;
55 break; 55 break;
56#if (CONFIG_PLATFORM & PLATFORM_PANDORA) 56#if (CONFIG_PLATFORM & PLATFORM_PANDORA)
57 case SDLK_RSHIFT: 57 case SDLK_RSHIFT:
58#endif 58#endif
59 case SDLK_KP4: 59 case SDLK_KP_4:
60 case SDLK_LEFT: 60 case SDLK_LEFT:
61 new_btn = BUTTON_MIDLEFT; 61 new_btn = BUTTON_MIDLEFT;
62 break; 62 break;
@@ -64,40 +64,32 @@ int key_to_button(int keyboard_key)
64 case SDLK_RETURN: 64 case SDLK_RETURN:
65 case SDLK_KP_ENTER: 65 case SDLK_KP_ENTER:
66#endif 66#endif
67 case SDLK_KP5: 67 case SDLK_KP_5:
68 new_btn = BUTTON_CENTER; 68 new_btn = BUTTON_CENTER;
69 break; 69 break;
70#if (CONFIG_PLATFORM & PLATFORM_PANDORA) 70#if (CONFIG_PLATFORM & PLATFORM_PANDORA)
71 case SDLK_RCTRL: 71 case SDLK_RCTRL:
72#endif 72#endif
73 case SDLK_KP6: 73 case SDLK_KP_6:
74 case SDLK_RIGHT: 74 case SDLK_RIGHT:
75 new_btn = BUTTON_MIDRIGHT; 75 new_btn = BUTTON_MIDRIGHT;
76 break; 76 break;
77#if (CONFIG_PLATFORM & PLATFORM_MAEMO4) 77#if (CONFIG_PLATFORM & PLATFORM_MAEMO4)
78 case SDLK_F6: 78 case SDLK_F6:
79#endif 79#endif
80 case SDLK_KP1: 80 case SDLK_KP_1:
81 new_btn = BUTTON_BOTTOMLEFT; 81 new_btn = BUTTON_BOTTOMLEFT;
82 break; 82 break;
83 case SDLK_KP2: 83 case SDLK_KP_2:
84 case SDLK_DOWN: 84 case SDLK_DOWN:
85 new_btn = BUTTON_BOTTOMMIDDLE; 85 new_btn = BUTTON_BOTTOMMIDDLE;
86 break; 86 break;
87#if (CONFIG_PLATFORM & PLATFORM_MAEMO4) 87#if (CONFIG_PLATFORM & PLATFORM_MAEMO4)
88 case SDLK_F8: 88 case SDLK_F8:
89#endif 89#endif
90 case SDLK_KP3: 90 case SDLK_KP_3:
91 new_btn = BUTTON_BOTTOMRIGHT; 91 new_btn = BUTTON_BOTTOMRIGHT;
92 break; 92 break;
93#ifdef HAVE_SCROLLWHEEL
94 case SDL_BUTTON_WHEELUP:
95 new_btn = BUTTON_SCROLL_BACK;
96 break;
97 case SDL_BUTTON_WHEELDOWN:
98 new_btn = BUTTON_SCROLL_FWD;
99 break;
100#endif
101 case SDL_BUTTON_RIGHT: 93 case SDL_BUTTON_RIGHT:
102 new_btn = BUTTON_MIDLEFT; 94 new_btn = BUTTON_MIDLEFT;
103 break; 95 break;
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index 1055d7e0b9..8af6f3ffaf 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -107,6 +107,30 @@ static void touchscreen_event(int x, int y)
107} 107}
108#endif 108#endif
109 109
110#if defined(HAVE_SCROLLWHEEL) || ((defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK)))
111static void scrollwheel_event(int x, int y)
112{
113 int new_btn = 0;
114 if (y > 0)
115 new_btn = BUTTON_SCROLL_BACK;
116 else if (y < 0)
117 new_btn = BUTTON_SCROLL_FWD;
118 else
119 return;
120
121#ifdef HAVE_BACKLIGHT
122 backlight_on();
123#endif
124#ifdef HAVE_BUTTON_LIGHT
125 buttonlight_on();
126#endif
127 reset_poweroff_timer();
128 if (new_btn && !queue_full(&button_queue))
129 queue_post(&button_queue, new_btn, 1<<24);
130
131 (void)x;
132}
133#endif
110static void mouse_event(SDL_MouseButtonEvent *event, bool button_up) 134static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
111{ 135{
112#define SQUARE(x) ((x)*(x)) 136#define SQUARE(x) ((x)*(x))
@@ -118,10 +142,6 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
118 if(button_up) { 142 if(button_up) {
119 switch ( event->button ) 143 switch ( event->button )
120 { 144 {
121#ifdef HAVE_SCROLLWHEEL
122 case SDL_BUTTON_WHEELUP:
123 case SDL_BUTTON_WHEELDOWN:
124#endif
125 case SDL_BUTTON_MIDDLE: 145 case SDL_BUTTON_MIDDLE:
126 case SDL_BUTTON_RIGHT: 146 case SDL_BUTTON_RIGHT:
127 button_event( event->button, false ); 147 button_event( event->button, false );
@@ -145,13 +165,9 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
145#endif 165#endif
146 break; 166 break;
147 } 167 }
148 } else { /* button down */ 168 } else { /* button down */
149 switch ( event->button ) 169 switch ( event->button )
150 { 170 {
151#ifdef HAVE_SCROLLWHEEL
152 case SDL_BUTTON_WHEELUP:
153 case SDL_BUTTON_WHEELDOWN:
154#endif
155 case SDL_BUTTON_MIDDLE: 171 case SDL_BUTTON_MIDDLE:
156 case SDL_BUTTON_RIGHT: 172 case SDL_BUTTON_RIGHT:
157 button_event( event->button, true ); 173 button_event( event->button, true );
@@ -215,18 +231,15 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
215 231
216static bool event_handler(SDL_Event *event) 232static bool event_handler(SDL_Event *event)
217{ 233{
218 SDLKey ev_key; 234 SDL_Keycode ev_key;
219 235
220 switch(event->type) 236 switch(event->type)
221 { 237 {
222 case SDL_ACTIVEEVENT: 238 case SDL_WINDOWEVENT:
223 if (event->active.state & SDL_APPINPUTFOCUS) 239 if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
224 { 240 sdl_app_has_input_focus = 1;
225 if (event->active.gain == 1) 241 else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
226 sdl_app_has_input_focus = 1; 242 sdl_app_has_input_focus = 0;
227 else
228 sdl_app_has_input_focus = 0;
229 }
230 break; 243 break;
231 case SDL_KEYDOWN: 244 case SDL_KEYDOWN:
232 case SDL_KEYUP: 245 case SDL_KEYUP:
@@ -275,6 +288,13 @@ static bool event_handler(SDL_Event *event)
275 mouse_event(mev, event->type == SDL_MOUSEBUTTONUP); 288 mouse_event(mev, event->type == SDL_MOUSEBUTTONUP);
276 break; 289 break;
277 } 290 }
291#ifdef HAVE_SCROLLWHEEL
292 case SDL_MOUSEWHEEL:
293 {
294 scrollwheel_event(event->wheel.x, event->wheel.y);
295 break;
296 }
297#endif
278 case SDL_QUIT: 298 case SDL_QUIT:
279 /* Will post SDL_USEREVENT in shutdown_hw() if successful. */ 299 /* Will post SDL_USEREVENT in shutdown_hw() if successful. */
280 sdl_sys_quit(); 300 sdl_sys_quit();
@@ -340,7 +360,7 @@ static void button_event(int key, bool pressed)
340 } 360 }
341 return; 361 return;
342#endif 362#endif
343#ifdef HAVE_MULTIDRIVE 363#ifdef HAVE_HOTSWAP
344 case EXT_KEY: 364 case EXT_KEY:
345 if (!pressed) 365 if (!pressed)
346 sim_trigger_external(!storage_present(1)); 366 sim_trigger_external(!storage_present(1));
@@ -362,7 +382,7 @@ static void button_event(int key, bool pressed)
362 } 382 }
363 return; 383 return;
364#endif 384#endif
365 385
366#ifdef HAS_REMOTE_BUTTON_HOLD 386#ifdef HAS_REMOTE_BUTTON_HOLD
367 case SDLK_j: 387 case SDLK_j:
368 if(pressed) 388 if(pressed)
@@ -379,7 +399,7 @@ static void button_event(int key, bool pressed)
379 if(pressed) 399 if(pressed)
380 switch(_remote_type) 400 switch(_remote_type)
381 { 401 {
382 case REMOTETYPE_UNPLUGGED: 402 case REMOTETYPE_UNPLUGGED:
383 _remote_type=REMOTETYPE_H100_LCD; 403 _remote_type=REMOTETYPE_H100_LCD;
384 DEBUGF("Changed remote type to H100\n"); 404 DEBUGF("Changed remote type to H100\n");
385 break; 405 break;
@@ -399,7 +419,7 @@ static void button_event(int key, bool pressed)
399 break; 419 break;
400#endif 420#endif
401#ifndef APPLICATION 421#ifndef APPLICATION
402 case SDLK_KP0: 422 case SDLK_KP_0:
403 case SDLK_F5: 423 case SDLK_F5:
404 if(pressed) 424 if(pressed)
405 { 425 {
@@ -430,32 +450,17 @@ static void button_event(int key, bool pressed)
430#endif 450#endif
431 break; 451 break;
432 } 452 }
433 /* Call to make up for scrollwheel target implementation. This is 453
434 * not handled in the main button.c driver, but on the target
435 * implementation (look at button-e200.c for example if you are trying to
436 * figure out why using button_get_data needed a hack before).
437 */
438#if defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK) 454#if defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK)
439 if((new_btn == BUTTON_SCROLL_FWD || new_btn == BUTTON_SCROLL_BACK) && 455 if((new_btn == BUTTON_SCROLL_FWD || new_btn == BUTTON_SCROLL_BACK) &&
440 pressed) 456 pressed)
441 { 457 {
442 /* Clear these buttons from the data - adding them to the queue is 458 scrollwheel_event(0, new_btn == BUTTON_SCROLL_FWD ? -1 : 1);
443 * handled in the scrollwheel drivers for the targets. They do not
444 * store the scroll forward/back buttons in their button data for
445 * the button_read call.
446 */
447#ifdef HAVE_BACKLIGHT
448 backlight_on();
449#endif
450#ifdef HAVE_BUTTON_LIGHT
451 buttonlight_on();
452#endif
453 reset_poweroff_timer();
454 queue_post(&button_queue, new_btn, 1<<24);
455 new_btn &= ~(BUTTON_SCROLL_FWD | BUTTON_SCROLL_BACK); 459 new_btn &= ~(BUTTON_SCROLL_FWD | BUTTON_SCROLL_BACK);
456 } 460 }
457#endif 461#endif
458 462
463 /* Update global button press state */
459 if (pressed) 464 if (pressed)
460 btn |= new_btn; 465 btn |= new_btn;
461 else 466 else
@@ -496,5 +501,4 @@ int button_read_device(void)
496 501
497void button_init_device(void) 502void button_init_device(void)
498{ 503{
499 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
500} 504}
diff --git a/firmware/target/hosted/sdl/kernel-sdl.c b/firmware/target/hosted/sdl/kernel-sdl.c
index 5c16f86749..bcad39b4d8 100644
--- a/firmware/target/hosted/sdl/kernel-sdl.c
+++ b/firmware/target/hosted/sdl/kernel-sdl.c
@@ -153,7 +153,7 @@ void sim_kernel_shutdown(void)
153 SDL_Delay(10); 153 SDL_Delay(10);
154 154
155 SDL_DestroyMutex(sim_irq_mtx); 155 SDL_DestroyMutex(sim_irq_mtx);
156 SDL_DestroyCond(sim_thread_cond); 156 SDL_DestroyCond(sim_thread_cond);
157} 157}
158 158
159Uint32 tick_timer(Uint32 interval, void *param) 159Uint32 tick_timer(Uint32 interval, void *param)
@@ -162,9 +162,9 @@ Uint32 tick_timer(Uint32 interval, void *param)
162 162
163 (void) interval; 163 (void) interval;
164 (void) param; 164 (void) param;
165 165
166 new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ); 166 new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ);
167 167
168 while(new_tick != current_tick) 168 while(new_tick != current_tick)
169 { 169 {
170 sim_enter_irq_handler(); 170 sim_enter_irq_handler();
@@ -175,7 +175,7 @@ Uint32 tick_timer(Uint32 interval, void *param)
175 175
176 sim_exit_irq_handler(); 176 sim_exit_irq_handler();
177 } 177 }
178 178
179 return interval; 179 return interval;
180} 180}
181 181
@@ -187,10 +187,10 @@ void tick_start(unsigned int interval_in_ms)
187 exit(-1); 187 exit(-1);
188 } 188 }
189 189
190 if (tick_timer_id != NULL) 190 if (tick_timer_id != 0)
191 { 191 {
192 SDL_RemoveTimer(tick_timer_id); 192 SDL_RemoveTimer(tick_timer_id);
193 tick_timer_id = NULL; 193 tick_timer_id = 0;
194 } 194 }
195 else 195 else
196 { 196 {
diff --git a/firmware/target/hosted/sdl/key_to_touch-sdl.c b/firmware/target/hosted/sdl/key_to_touch-sdl.c
index d56d06ba74..b7052e043f 100644
--- a/firmware/target/hosted/sdl/key_to_touch-sdl.c
+++ b/firmware/target/hosted/sdl/key_to_touch-sdl.c
@@ -52,12 +52,12 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
52 } 52 }
53 break; 53 break;
54#ifndef APPLICATION 54#ifndef APPLICATION
55 case SDLK_KP7: 55 case SDLK_KP_7:
56 case SDLK_7: 56 case SDLK_7:
57 case SDLK_HOME: 57 case SDLK_HOME:
58 new_btn = BUTTON_TOPLEFT; 58 new_btn = BUTTON_TOPLEFT;
59 break; 59 break;
60 case SDLK_KP8: 60 case SDLK_KP_8:
61 case SDLK_8: 61 case SDLK_8:
62 case SDLK_UP: 62 case SDLK_UP:
63#ifdef HAVE_SCROLLWHEEL 63#ifdef HAVE_SCROLLWHEEL
@@ -65,32 +65,32 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
65#endif 65#endif
66 new_btn = BUTTON_TOPMIDDLE; 66 new_btn = BUTTON_TOPMIDDLE;
67 break; 67 break;
68 case SDLK_KP9: 68 case SDLK_KP_9:
69 case SDLK_9: 69 case SDLK_9:
70 case SDLK_PAGEUP: 70 case SDLK_PAGEUP:
71 new_btn = BUTTON_TOPRIGHT; 71 new_btn = BUTTON_TOPRIGHT;
72 break; 72 break;
73 case SDLK_KP4: 73 case SDLK_KP_4:
74 case SDLK_u: 74 case SDLK_u:
75 case SDLK_LEFT: 75 case SDLK_LEFT:
76 new_btn = BUTTON_MIDLEFT; 76 new_btn = BUTTON_MIDLEFT;
77 break; 77 break;
78 case SDLK_KP5: 78 case SDLK_KP_5:
79 case SDLK_i: 79 case SDLK_i:
80 case SDL_BUTTON_MIDDLE: 80 case SDL_BUTTON_MIDDLE:
81 new_btn = BUTTON_CENTER; 81 new_btn = BUTTON_CENTER;
82 break; 82 break;
83 case SDLK_KP6: 83 case SDLK_KP_6:
84 case SDLK_o: 84 case SDLK_o:
85 case SDLK_RIGHT: 85 case SDLK_RIGHT:
86 new_btn = BUTTON_MIDRIGHT; 86 new_btn = BUTTON_MIDRIGHT;
87 break; 87 break;
88 case SDLK_KP1: 88 case SDLK_KP_1:
89 case SDLK_j: 89 case SDLK_j:
90 case SDLK_END: 90 case SDLK_END:
91 new_btn = BUTTON_BOTTOMLEFT; 91 new_btn = BUTTON_BOTTOMLEFT;
92 break; 92 break;
93 case SDLK_KP2: 93 case SDLK_KP_2:
94 case SDLK_k: 94 case SDLK_k:
95#ifdef HAVE_SCROLLWHEEL 95#ifdef HAVE_SCROLLWHEEL
96 case SDL_BUTTON_WHEELDOWN: 96 case SDL_BUTTON_WHEELDOWN:
@@ -98,7 +98,7 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
98 case SDLK_DOWN: 98 case SDLK_DOWN:
99 new_btn = BUTTON_BOTTOMMIDDLE; 99 new_btn = BUTTON_BOTTOMMIDDLE;
100 break; 100 break;
101 case SDLK_KP3: 101 case SDLK_KP_3:
102 case SDLK_l: 102 case SDLK_l:
103 case SDLK_PAGEDOWN: 103 case SDLK_PAGEDOWN:
104 new_btn = BUTTON_BOTTOMRIGHT; 104 new_btn = BUTTON_BOTTOMRIGHT;
@@ -106,4 +106,5 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
106#endif 106#endif
107 } 107 }
108 return new_btn; 108 return new_btn;
109
109} 110}
diff --git a/firmware/target/hosted/sdl/lcd-bitmap.c b/firmware/target/hosted/sdl/lcd-bitmap.c
index ea30afea3b..ef284eeb48 100644
--- a/firmware/target/hosted/sdl/lcd-bitmap.c
+++ b/firmware/target/hosted/sdl/lcd-bitmap.c
@@ -164,12 +164,12 @@ void sim_backlight(int value)
164#else /* LCD_DEPTH > 8 */ 164#else /* LCD_DEPTH > 8 */
165#if defined(HAVE_TRANSFLECTIVE_LCD) && defined(HAVE_LCD_SLEEP) 165#if defined(HAVE_TRANSFLECTIVE_LCD) && defined(HAVE_LCD_SLEEP)
166 if (!lcd_active()) 166 if (!lcd_active())
167 SDL_SetAlpha(lcd_surface, SDL_SRCALPHA, 0); 167 SDL_SetSurfaceAlphaMod(lcd_surface, 0);
168 else 168 else
169 SDL_SetAlpha(lcd_surface, SDL_SRCALPHA, 169 SDL_SetSurfaceAlphaMod(lcd_surface,
170 MAX(BACKLIGHT_OFF_ALPHA, (value * 255) / 100)); 170 MAX(BACKLIGHT_OFF_ALPHA, (value * 255) / 100));
171#else 171#else
172 SDL_SetAlpha(lcd_surface, SDL_SRCALPHA, (value * 255) / 100); 172 SDL_SetSurfaceAlphaMod(lcd_surface, (value * 255) / 100);
173#endif 173#endif
174#endif /* LCD_DEPTH */ 174#endif /* LCD_DEPTH */
175 175
@@ -187,6 +187,7 @@ void lcd_init_device(void)
187 SIM_LCD_WIDTH * display_zoom, 187 SIM_LCD_WIDTH * display_zoom,
188 SIM_LCD_HEIGHT * display_zoom, 188 SIM_LCD_HEIGHT * display_zoom,
189 LCD_DEPTH, 0, 0, 0, 0); 189 LCD_DEPTH, 0, 0, 0, 0);
190 SDL_SetSurfaceBlendMode(lcd_surface, SDL_BLENDMODE_BLEND);
190#elif LCD_DEPTH <= 8 191#elif LCD_DEPTH <= 8
191 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 192 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
192 SIM_LCD_WIDTH * display_zoom, 193 SIM_LCD_WIDTH * display_zoom,
@@ -222,7 +223,7 @@ void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
222 if (lcd_ex_getpixel) { 223 if (lcd_ex_getpixel) {
223 sdl_update_rect(lcd_surface, x_start, y_start, width, height, 224 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
224 LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel); 225 LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
225 sdl_gui_update(lcd_surface, x_start, y_start, width, 226 sdl_gui_update(lcd_surface, x_start, y_start, width,
226 height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT, 227 height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
227 background ? UI_LCD_POSX : 0, 228 background ? UI_LCD_POSX : 0,
228 background ? UI_LCD_POSY : 0); 229 background ? UI_LCD_POSY : 0);
diff --git a/firmware/target/hosted/sdl/lcd-sdl.c b/firmware/target/hosted/sdl/lcd-sdl.c
index 8cbb6c5651..1e9daeffd3 100644
--- a/firmware/target/hosted/sdl/lcd-sdl.c
+++ b/firmware/target/hosted/sdl/lcd-sdl.c
@@ -115,12 +115,17 @@ void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
115 (ui_y + y_start) * display_zoom, 115 (ui_y + y_start) * display_zoom,
116 width * display_zoom, height * display_zoom}; 116 width * display_zoom, height * display_zoom};
117 117
118 if (surface->flags & SDL_SRCALPHA) /* alpha needs a black background */ 118 uint8_t alpha;
119 if (SDL_GetSurfaceAlphaMod(surface,&alpha) == 0 && alpha < 255)
119 SDL_FillRect(gui_surface, &dest, 0); 120 SDL_FillRect(gui_surface, &dest, 0);
120 121
121 SDL_BlitSurface(surface, &src, gui_surface, &dest); 122 SDL_BlitSurface(surface, &src, gui_surface, &dest); /* alpha needs a black background */
122 123
123 SDL_Flip(gui_surface); 124 SDL_Texture *sdlTexture = SDL_CreateTextureFromSurface(sdlRenderer, gui_surface);
125 SDL_RenderClear(sdlRenderer);
126 SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
127 SDL_RenderPresent(sdlRenderer);
128 SDL_DestroyTexture(sdlTexture);
124} 129}
125 130
126/* set a range of bitmap indices to a gradient from startcolour to endcolour */ 131/* set a range of bitmap indices to a gradient from startcolour to endcolour */
@@ -136,7 +141,7 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
136 palette[i].b = start->b + (end->b - start->b) * i / (steps - 1); 141 palette[i].b = start->b + (end->b - start->b) * i / (steps - 1);
137 } 142 }
138 143
139 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps); 144 SDL_SetPaletteColors(surface->format->palette, palette, first , steps);
140} 145}
141 146
142int lcd_get_dpi(void) 147int lcd_get_dpi(void)
diff --git a/firmware/target/hosted/sdl/lcd-sdl.h b/firmware/target/hosted/sdl/lcd-sdl.h
index a964c9bc40..3f1334e4a2 100644
--- a/firmware/target/hosted/sdl/lcd-sdl.h
+++ b/firmware/target/hosted/sdl/lcd-sdl.h
@@ -3,7 +3,7 @@
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
@@ -27,6 +27,7 @@
27 27
28/* Default display zoom level */ 28/* Default display zoom level */
29extern SDL_Surface *gui_surface; 29extern SDL_Surface *gui_surface;
30extern SDL_Renderer *sdlRenderer;
30 31
31void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, 32void 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,
@@ -39,4 +40,3 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
39 int first, int steps); 40 int first, int steps);
40 41
41#endif /* #ifndef __LCDSDL_H__ */ 42#endif /* #ifndef __LCDSDL_H__ */
42
diff --git a/firmware/target/hosted/sdl/pcm-sdl.c b/firmware/target/hosted/sdl/pcm-sdl.c
index 940403002f..dec12af2f1 100644
--- a/firmware/target/hosted/sdl/pcm-sdl.c
+++ b/firmware/target/hosted/sdl/pcm-sdl.c
@@ -1,10 +1,10 @@
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 Nick Lanham 10 * Copyright (C) 2005 by Nick Lanham
@@ -85,8 +85,43 @@ void pcm_play_unlock(void)
85 SDL_UnlockMutex(audio_lock); 85 SDL_UnlockMutex(audio_lock);
86} 86}
87 87
88static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len);
88static void pcm_dma_apply_settings_nolock(void) 89static void pcm_dma_apply_settings_nolock(void)
89{ 90{
91 SDL_AudioSpec wanted_spec;
92 wanted_spec.freq = pcm_sampr;
93 wanted_spec.format = AUDIO_S16SYS;
94 wanted_spec.channels = 2;
95 wanted_spec.samples = 2048;
96 wanted_spec.callback =
97 (void (SDLCALL *)(void *userdata,
98 Uint8 *stream, int len))sdl_audio_callback;
99 wanted_spec.userdata = &udata;
100 SDL_CloseAudio();
101 /* Open the audio device and start playing sound! */
102 if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) {
103 DEBUGF("Unable to open audio: %s\n", SDL_GetError());
104 return;
105 }
106 switch (obtained.format)
107 {
108 case AUDIO_U8:
109 case AUDIO_S8:
110 pcm_channel_bytes = 1;
111 break;
112 case AUDIO_U16LSB:
113 case AUDIO_S16LSB:
114 case AUDIO_U16MSB:
115 case AUDIO_S16MSB:
116 pcm_channel_bytes = 2;
117 break;
118 default:
119 DEBUGF("Unknown sample format obtained: %u\n",
120 (unsigned)obtained.format);
121 return;
122 }
123 pcm_sample_bytes = obtained.channels * pcm_channel_bytes;
124
90 cvt_status = SDL_BuildAudioCVT(&cvt, AUDIO_S16SYS, 2, pcm_sampr, 125 cvt_status = SDL_BuildAudioCVT(&cvt, AUDIO_S16SYS, 2, pcm_sampr,
91 obtained.format, obtained.channels, obtained.freq); 126 obtained.format, obtained.channels, obtained.freq);
92 127
@@ -104,7 +139,6 @@ void pcm_dma_apply_settings(void)
104 139
105void pcm_play_dma_start(const void *addr, size_t size) 140void pcm_play_dma_start(const void *addr, size_t size)
106{ 141{
107 pcm_dma_apply_settings_nolock();
108 142
109 pcm_data = addr; 143 pcm_data = addr;
110 pcm_data_size = size; 144 pcm_data_size = size;
@@ -257,9 +291,7 @@ static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len)
257 291
258 if (delay > 0) 292 if (delay > 0)
259 { 293 {
260 SDL_UnlockMutex(audio_lock);
261 SDL_Delay(delay); 294 SDL_Delay(delay);
262 SDL_LockMutex(audio_lock);
263 295
264 if (!pcm_is_playing()) 296 if (!pcm_is_playing())
265 break; 297 break;
@@ -340,7 +372,6 @@ void pcm_play_dma_init(void)
340 return; 372 return;
341 } 373 }
342 374
343 SDL_AudioSpec wanted_spec;
344#ifdef DEBUG 375#ifdef DEBUG
345 udata.debug = NULL; 376 udata.debug = NULL;
346 if (debug_audio) { 377 if (debug_audio) {
@@ -348,43 +379,6 @@ void pcm_play_dma_init(void)
348 DEBUGF("Audio debug file open\n"); 379 DEBUGF("Audio debug file open\n");
349 } 380 }
350#endif 381#endif
351 /* Set 16-bit stereo audio at 44Khz */
352 wanted_spec.freq = 44100;
353 wanted_spec.format = AUDIO_S16SYS;
354 wanted_spec.channels = 2;
355 wanted_spec.samples = 2048;
356 wanted_spec.callback =
357 (void (SDLCALL *)(void *userdata,
358 Uint8 *stream, int len))sdl_audio_callback;
359 wanted_spec.userdata = &udata;
360
361 /* Open the audio device and start playing sound! */
362 if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) {
363 DEBUGF("Unable to open audio: %s\n", SDL_GetError());
364 return;
365 }
366
367 switch (obtained.format)
368 {
369 case AUDIO_U8:
370 case AUDIO_S8:
371 pcm_channel_bytes = 1;
372 break;
373 case AUDIO_U16LSB:
374 case AUDIO_S16LSB:
375 case AUDIO_U16MSB:
376 case AUDIO_S16MSB:
377 pcm_channel_bytes = 2;
378 break;
379 default:
380 DEBUGF("Unknown sample format obtained: %u\n",
381 (unsigned)obtained.format);
382 return;
383 }
384
385 pcm_sample_bytes = obtained.channels * pcm_channel_bytes;
386
387 pcm_dma_apply_settings_nolock();
388} 382}
389 383
390void pcm_play_dma_postinit(void) 384void pcm_play_dma_postinit(void)
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index e53643f449..56cff3f1be 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -1,10 +1,10 @@
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) 2006 by Daniel Everton <dan@iocaine.org> 10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
@@ -50,6 +50,8 @@
50#define SIMULATOR_DEFAULT_ROOT "simdisk" 50#define SIMULATOR_DEFAULT_ROOT "simdisk"
51 51
52SDL_Surface *gui_surface; 52SDL_Surface *gui_surface;
53SDL_Window *window;
54SDL_Renderer *sdlRenderer;
53 55
54bool background = true; /* use backgrounds by default */ 56bool background = true; /* use backgrounds by default */
55#ifdef HAVE_REMOTE_LCD 57#ifdef HAVE_REMOTE_LCD
@@ -72,26 +74,12 @@ bool debug_audio = false;
72bool debug_wps = false; 74bool debug_wps = false;
73int wps_verbose_level = 3; 75int wps_verbose_level = 3;
74 76
75/* 77static void sdl_window_setup(void)
76 * This thread will read the buttons in an interrupt like fashion, and
77 * also initializes SDL_INIT_VIDEO and the surfaces
78 *
79 * it must be done in the same thread (at least on windows) because events only
80 * work in the thread which called SDL_Init(SubSystem) with SDL_INIT_VIDEO
81 *
82 * This is an SDL thread and relies on preemptive behavoir of the host
83 **/
84static int sdl_event_thread(void * param)
85{ 78{
86 SDL_InitSubSystem(SDL_INIT_VIDEO);
87
88#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
89 SDL_sem *wait_for_maemo_startup;
90#endif
91 SDL_Surface *picture_surface = NULL; 79 SDL_Surface *picture_surface = NULL;
92 int width, height; 80 int width, height;
93 int depth; 81 int depth;
94 Uint32 flags; 82 Uint32 flags = 0;
95 83
96 /* Try and load the background image. If it fails go without */ 84 /* Try and load the background image. If it fails go without */
97 if (background) { 85 if (background) {
@@ -101,14 +89,14 @@ static int sdl_event_thread(void * param)
101 DEBUGF("warn: %s\n", SDL_GetError()); 89 DEBUGF("warn: %s\n", SDL_GetError());
102 } 90 }
103 } 91 }
104 92
105 /* Set things up */ 93 /* Set things up */
106 if (background) 94 if (background)
107 { 95 {
108 width = UI_WIDTH; 96 width = UI_WIDTH;
109 height = UI_HEIGHT; 97 height = UI_HEIGHT;
110 } 98 }
111 else 99 else
112 { 100 {
113#ifdef HAVE_REMOTE_LCD 101#ifdef HAVE_REMOTE_LCD
114 if (showremote) 102 if (showremote)
@@ -128,17 +116,47 @@ static int sdl_event_thread(void * param)
128 if (depth < 8) 116 if (depth < 8)
129 depth = 16; 117 depth = 16;
130 118
131 flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
132#if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) 119#if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA))
133 /* Fullscreen mode for maemo app */ 120 /* Fullscreen mode for maemo app */
134 flags |= SDL_FULLSCREEN; 121 flags |= SDL_WINDOW_FULLSCREEN;
135#endif 122#endif
136 123
137 SDL_WM_SetCaption(UI_TITLE, NULL); 124 if ((window = SDL_CreateWindow(UI_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
138 125 width * display_zoom, height * display_zoom , flags)) == NULL)
139 if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, depth, flags)) == NULL) { 126 panicf("%s", SDL_GetError());
127 if ((sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
140 panicf("%s", SDL_GetError()); 128 panicf("%s", SDL_GetError());
129 if ((gui_surface = SDL_CreateRGBSurface(0, width * display_zoom, height * display_zoom, depth,
130 0, 0, 0, 0)) == NULL)
131 panicf("%s", SDL_GetError());
132
133 /* If we have a background, blit it over to the display surface */
134 if (background && picture_surface)
135 {
136 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
137 SDL_FreeSurface(picture_surface);
141 } 138 }
139}
140
141/*
142 * This thread will read the buttons in an interrupt like fashion, and
143 * also initializes SDL_INIT_VIDEO and the surfaces
144 *
145 * it must be done in the same thread (at least on windows) because events only
146 * work in the thread that called SDL_InitSubSystem(SDL_INIT_VIDEO)
147 *
148 * This is an SDL thread and relies on preemptive behavoir of the host
149 **/
150static int sdl_event_thread(void * param)
151{
152#ifdef __WIN32 /* Fails on Linux and MacOS */
153 SDL_InitSubSystem(SDL_INIT_VIDEO);
154 sdl_window_setup();
155#endif
156
157#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
158 SDL_sem *wait_for_maemo_startup;
159#endif
142 160
143#if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) 161#if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA))
144 /* SDL touch screen fix: Work around a SDL assumption that returns 162 /* SDL touch screen fix: Work around a SDL assumption that returns
@@ -152,14 +170,10 @@ static int sdl_event_thread(void * param)
152 SDL_SetCursor(hiddenCursor); 170 SDL_SetCursor(hiddenCursor);
153#endif 171#endif
154 172
155 if (background && picture_surface != NULL)
156 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
157
158#if (CONFIG_PLATFORM & PLATFORM_MAEMO) 173#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
159 /* start maemo thread: Listen to display on/off events and battery monitoring */ 174 /* start maemo thread: Listen to display on/off events and battery monitoring */
160 wait_for_maemo_startup = SDL_CreateSemaphore(0); /* 0-count so it blocks */ 175 wait_for_maemo_startup = SDL_CreateSemaphore(0); /* 0-count so it blocks */
161 SDL_Thread *maemo_thread = SDL_CreateThread(maemo_thread_func, wait_for_maemo_startup); 176 SDL_Thread *maemo_thread = SDL_CreateThread(maemo_thread_func, NULL, wait_for_maemo_startup);
162
163 SDL_SemWait(wait_for_maemo_startup); 177 SDL_SemWait(wait_for_maemo_startup);
164 SDL_DestroySemaphore(wait_for_maemo_startup); 178 SDL_DestroySemaphore(wait_for_maemo_startup);
165#endif 179#endif
@@ -184,9 +198,6 @@ static int sdl_event_thread(void * param)
184 SDL_FreeCursor(hiddenCursor); 198 SDL_FreeCursor(hiddenCursor);
185#endif 199#endif
186 200
187 if(picture_surface)
188 SDL_FreeSurface(picture_surface);
189
190 /* Order here is relevent to prevent deadlocks and use of destroyed 201 /* Order here is relevent to prevent deadlocks and use of destroyed
191 sync primitives by kernel threads */ 202 sync primitives by kernel threads */
192#ifdef HAVE_SDL_THREADS 203#ifdef HAVE_SDL_THREADS
@@ -251,15 +262,16 @@ void system_init(void)
251 g_type_init(); 262 g_type_init();
252#endif 263#endif
253 264
254 if (SDL_Init(SDL_INIT_TIMER)) 265 if (SDL_InitSubSystem(SDL_INIT_TIMER))
255 panicf("%s", SDL_GetError()); 266 panicf("%s", SDL_GetError());
256 267
257 s = SDL_CreateSemaphore(0); /* 0-count so it blocks */ 268#ifndef __WIN32 /* Fails on Windows */
258 269 SDL_InitSubSystem(SDL_INIT_VIDEO);
259 evt_thread = SDL_CreateThread(sdl_event_thread, s); 270 sdl_window_setup();
271#endif
260 272
261 /* wait for sdl_event_thread to run so that it can initialize the surfaces 273 s = SDL_CreateSemaphore(0); /* 0-count so it blocks */
262 * and video subsystem needed for SDL events */ 274 evt_thread = SDL_CreateThread(sdl_event_thread, NULL, s);
263 SDL_SemWait(s); 275 SDL_SemWait(s);
264 /* cleanup */ 276 /* cleanup */
265 SDL_DestroySemaphore(s); 277 SDL_DestroySemaphore(s);
@@ -303,29 +315,29 @@ int hostfs_flush(void)
303 315
304void sys_handle_argv(int argc, char *argv[]) 316void sys_handle_argv(int argc, char *argv[])
305{ 317{
306 if (argc >= 1) 318 if (argc >= 1)
307 { 319 {
308 int x; 320 int x;
309 for (x = 1; x < argc; x++) 321 for (x = 1; x < argc; x++)
310 { 322 {
311#ifdef DEBUG 323#ifdef DEBUG
312 if (!strcmp("--debugaudio", argv[x])) 324 if (!strcmp("--debugaudio", argv[x]))
313 { 325 {
314 debug_audio = true; 326 debug_audio = true;
315 printf("Writing debug audio file.\n"); 327 printf("Writing debug audio file.\n");
316 } 328 }
317 else 329 else
318#endif 330#endif
319 if (!strcmp("--debugwps", argv[x])) 331 if (!strcmp("--debugwps", argv[x]))
320 { 332 {
321 debug_wps = true; 333 debug_wps = true;
322 printf("WPS debug mode enabled.\n"); 334 printf("WPS debug mode enabled.\n");
323 } 335 }
324 else if (!strcmp("--nobackground", argv[x])) 336 else if (!strcmp("--nobackground", argv[x]))
325 { 337 {
326 background = false; 338 background = false;
327 printf("Disabling background image.\n"); 339 printf("Disabling background image.\n");
328 } 340 }
329#ifdef HAVE_REMOTE_LCD 341#ifdef HAVE_REMOTE_LCD
330 else if (!strcmp("--noremote", argv[x])) 342 else if (!strcmp("--noremote", argv[x]))
331 { 343 {
@@ -346,7 +358,7 @@ void sys_handle_argv(int argc, char *argv[])
346 display_zoom=atof(argv[x]); 358 display_zoom=atof(argv[x]);
347 else 359 else
348 display_zoom = 2; 360 display_zoom = 2;
349 printf("Window zoom is %d\n", display_zoom); 361 printf("Window zoom is %f\n", display_zoom);
350 } 362 }
351 else if (!strcmp("--alarm", argv[x])) 363 else if (!strcmp("--alarm", argv[x]))
352 { 364 {
@@ -372,7 +384,7 @@ void sys_handle_argv(int argc, char *argv[])
372 debug_buttons = true; 384 debug_buttons = true;
373 printf("Printing background button clicks.\n"); 385 printf("Printing background button clicks.\n");
374 } 386 }
375 else 387 else
376 { 388 {
377 printf("rockboxui\n"); 389 printf("rockboxui\n");
378 printf("Arguments:\n"); 390 printf("Arguments:\n");
diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c
index 17a0f847b5..abd6339cee 100644
--- a/firmware/target/hosted/sdl/thread-sdl.c
+++ b/firmware/target/hosted/sdl/thread-sdl.c
@@ -340,7 +340,7 @@ unsigned int create_thread(void (*function)(void),
340 return 0; 340 return 0;
341 } 341 }
342 342
343 SDL_Thread *t = SDL_CreateThread(runthread, thread); 343 SDL_Thread *t = SDL_CreateThread(runthread, NULL, thread);
344 if (t == NULL) 344 if (t == NULL)
345 { 345 {
346 DEBUGF("Failed to create SDL thread\n"); 346 DEBUGF("Failed to create SDL thread\n");
@@ -447,7 +447,7 @@ void init_threads(void)
447 thread->context.s = SDL_CreateSemaphore(0); 447 thread->context.s = SDL_CreateSemaphore(0);
448 thread->context.t = NULL; /* NULL for the implicit main thread */ 448 thread->context.t = NULL; /* NULL for the implicit main thread */
449 __running_self_entry() = thread; 449 __running_self_entry() = thread;
450 450
451 if (thread->context.s == NULL) 451 if (thread->context.s == NULL)
452 { 452 {
453 fprintf(stderr, "Failed to create main semaphore\n"); 453 fprintf(stderr, "Failed to create main semaphore\n");