diff options
Diffstat (limited to 'firmware/target/hosted/sdl')
-rw-r--r-- | firmware/target/hosted/sdl/app/load_code-sdl-app.c | 36 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/filesystem-sdl.c | 55 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/filesystem-sdl.h | 37 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/load_code-sdl.c | 52 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/system-sdl.c | 4 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/system-sim.h | 32 |
6 files changed, 215 insertions, 1 deletions
diff --git a/firmware/target/hosted/sdl/app/load_code-sdl-app.c b/firmware/target/hosted/sdl/app/load_code-sdl-app.c new file mode 100644 index 0000000000..686944343f --- /dev/null +++ b/firmware/target/hosted/sdl/app/load_code-sdl-app.c | |||
@@ -0,0 +1,36 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 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 | #define RB_FILESYSTEM_OS | ||
22 | #include "system.h" | ||
23 | #include "file.h" | ||
24 | #include "load_code.h" | ||
25 | |||
26 | void *lc_open(const char *filename, unsigned char *buf, size_t buf_size) | ||
27 | { | ||
28 | char realpath[MAX_PATH]; | ||
29 | const char *fpath = handle_special_dirs(filename, 0, realpath, | ||
30 | sizeof (realpath)); | ||
31 | if (!fpath) | ||
32 | return NULL; | ||
33 | |||
34 | return os_lc_open(fpath); | ||
35 | (void)buf; (void)buf_size; | ||
36 | } | ||
diff --git a/firmware/target/hosted/sdl/filesystem-sdl.c b/firmware/target/hosted/sdl/filesystem-sdl.c new file mode 100644 index 0000000000..5a8e2c417a --- /dev/null +++ b/firmware/target/hosted/sdl/filesystem-sdl.c | |||
@@ -0,0 +1,55 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2014 by Michael Sevakis | ||
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 | #define RB_FILESYSTEM_OS | ||
22 | #include "config.h" | ||
23 | #include "system.h" | ||
24 | #include "thread-sdl.h" | ||
25 | #include "mutex.h" | ||
26 | #include "file.h" | ||
27 | |||
28 | #ifdef HAVE_SDL_THREADS | ||
29 | #define YIELD_THRESHOLD 512 | ||
30 | static bool initialized = false; | ||
31 | static struct mutex readwrite_mtx; | ||
32 | |||
33 | /* Allow other threads to run while performing I/O */ | ||
34 | ssize_t os_sdl_readwrite(int osfd, void *buf, size_t nbyte, bool dowrite) | ||
35 | { | ||
36 | if (!initialized) | ||
37 | { | ||
38 | mutex_init(&readwrite_mtx); | ||
39 | initialized = true; | ||
40 | } | ||
41 | |||
42 | mutex_lock(&readwrite_mtx); | ||
43 | |||
44 | void *mythread = nbyte > YIELD_THRESHOLD ? sim_thread_unlock() : NULL; | ||
45 | |||
46 | ssize_t rc = dowrite ? write(osfd, buf, nbyte) : read(osfd, buf, nbyte); | ||
47 | |||
48 | if (mythread) | ||
49 | sim_thread_lock(mythread); | ||
50 | |||
51 | mutex_unlock(&readwrite_mtx); | ||
52 | return rc; | ||
53 | } | ||
54 | |||
55 | #endif /* HAVE_SDL_THREADS */ | ||
diff --git a/firmware/target/hosted/sdl/filesystem-sdl.h b/firmware/target/hosted/sdl/filesystem-sdl.h new file mode 100644 index 0000000000..934b43b34b --- /dev/null +++ b/firmware/target/hosted/sdl/filesystem-sdl.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2014 by Michael Sevakis | ||
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 | #ifndef _FILESYSTEM_SDL_H_ | ||
22 | #define _FILESYSTEM_SDL_H_ | ||
23 | |||
24 | #ifdef HAVE_SDL_THREADS | ||
25 | #undef os_read | ||
26 | #undef os_write | ||
27 | |||
28 | ssize_t os_sdl_readwrite(int osfd, void *buf, size_t nbyte, bool dowrite); | ||
29 | |||
30 | #define os_read(osfd, buf, nbyte) \ | ||
31 | os_sdl_readwrite((osfd), (buf), (nbyte), false) | ||
32 | #define os_write(osfd, buf, nbyte) \ | ||
33 | os_sdl_readwrite((osfd), (void *)(buf), (nbyte), true) | ||
34 | |||
35 | #endif /* HAVE_SDL_THREADS */ | ||
36 | |||
37 | #endif /* _FILESYSTEM_SDL_H_ */ | ||
diff --git a/firmware/target/hosted/sdl/load_code-sdl.c b/firmware/target/hosted/sdl/load_code-sdl.c new file mode 100644 index 0000000000..ee29853ab5 --- /dev/null +++ b/firmware/target/hosted/sdl/load_code-sdl.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Daniel Stenberg | ||
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 | #define RB_FILESYSTEM_OS | ||
22 | #include <SDL_loadso.h> | ||
23 | #include "system.h" | ||
24 | #include "load_code.h" | ||
25 | #include "filesystem-sdl.h" | ||
26 | #include "debug.h" | ||
27 | |||
28 | void * os_lc_open(const char *ospath) | ||
29 | { | ||
30 | void *handle = SDL_LoadObject(ospath); | ||
31 | if (handle == NULL) | ||
32 | { | ||
33 | DEBUGF("%s(\"%s\") failed\n", __func__, ospath); | ||
34 | DEBUGF(" SDL error '%s'\n", SDL_GetError()); | ||
35 | } | ||
36 | |||
37 | return handle; | ||
38 | } | ||
39 | |||
40 | void * lc_get_header(void *handle) | ||
41 | { | ||
42 | char *ret = SDL_LoadFunction(handle, "__header"); | ||
43 | if (ret == NULL) | ||
44 | ret = SDL_LoadFunction(handle, "___header"); | ||
45 | |||
46 | return ret; | ||
47 | } | ||
48 | |||
49 | void lc_close(void *handle) | ||
50 | { | ||
51 | SDL_UnloadObject(handle); | ||
52 | } | ||
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index fdf79d9333..aa322ddf3a 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c | |||
@@ -51,6 +51,8 @@ | |||
51 | 51 | ||
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | #define SIMULATOR_DEFAULT_ROOT "simdisk" | ||
55 | |||
54 | SDL_Surface *gui_surface; | 56 | SDL_Surface *gui_surface; |
55 | 57 | ||
56 | bool background = true; /* use backgrounds by default */ | 58 | bool background = true; /* use backgrounds by default */ |
@@ -63,7 +65,7 @@ bool debug_buttons = false; | |||
63 | bool lcd_display_redraw = true; /* Used for player simulator */ | 65 | bool lcd_display_redraw = true; /* Used for player simulator */ |
64 | char having_new_lcd = true; /* Used for player simulator */ | 66 | char having_new_lcd = true; /* Used for player simulator */ |
65 | bool sim_alarm_wakeup = false; | 67 | bool sim_alarm_wakeup = false; |
66 | const char *sim_root_dir = NULL; | 68 | const char *sim_root_dir = SIMULATOR_DEFAULT_ROOT; |
67 | 69 | ||
68 | static SDL_Thread *evt_thread = NULL; | 70 | static SDL_Thread *evt_thread = NULL; |
69 | 71 | ||
diff --git a/firmware/target/hosted/sdl/system-sim.h b/firmware/target/hosted/sdl/system-sim.h new file mode 100644 index 0000000000..16c0cdde52 --- /dev/null +++ b/firmware/target/hosted/sdl/system-sim.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2014 by Michael Sevakis | ||
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 | #ifndef _SYSTEM_SIM_H_ | ||
22 | #define _SYSTEM_SIM_H_ | ||
23 | |||
24 | #ifdef WIN32 | ||
25 | #include <time.h> | ||
26 | struct tm * localtime_r(const time_t *restrict timer, | ||
27 | struct tm *restrict result); | ||
28 | struct tm * gmtime_r(const time_t *restrict timer, | ||
29 | struct tm *restrict result); | ||
30 | #endif /* WIN32 */ | ||
31 | |||
32 | #endif /* _SYSTEM_SIM_H_ */ | ||