Mercurial > repos > blastem
annotate util.c @ 2688:b42f00a3a937 default tip
Fix default target. Ensure m68k.h and z80.h are built before anything else when no dep info is available
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 31 Mar 2025 21:06:18 -0700 |
parents | 143cb5762ec9 |
children |
rev | line source |
---|---|
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stdio.h> |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <ctype.h> |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
5 #include <stdint.h> |
805 | 6 #include <stdarg.h> |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
8 #include <sys/types.h> |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
9 #include <sys/stat.h> |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
10 #include <errno.h> |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
11 |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
12 #ifdef __ANDROID__ |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
13 #include <android/log.h> |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
14 #include <SDL_system.h> |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
15 #include <jni.h> |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
16 #define info_puts(msg) __android_log_write(ANDROID_LOG_INFO, "BlastEm", msg) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
17 #define warning_puts(msg) __android_log_write(ANDROID_LOG_WARN, "BlastEm", msg) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
18 #define fatal_puts(msg) __android_log_write(ANDROID_LOG_FATAL, "BlastEm", msg) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
19 |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
20 #define info_printf(msg, args) __android_log_vprint(ANDROID_LOG_INFO, "BlastEm", msg, args) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
21 #define warning_printf(msg, args) __android_log_vprint(ANDROID_LOG_WARN, "BlastEm", msg, args) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
22 #define fatal_printf(msg, args) __android_log_vprint(ANDROID_LOG_FATAL, "BlastEm", msg, args) |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
23 #else |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
24 #define info_puts(msg) fputs(msg, stdout); |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
25 #define warning_puts(msg) fputs(msg, stderr); |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
26 #define fatal_puts(msg) fputs(msg, stderr); |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
27 |
883
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
879
diff
changeset
|
28 #define info_printf(msg, args) vprintf(msg, args) |
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
879
diff
changeset
|
29 #define warning_printf(msg, args) vfprintf(stderr, msg, args) |
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
879
diff
changeset
|
30 #define fatal_printf(msg, args) vfprintf(stderr, msg, args) |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
31 #endif |
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
32 |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
33 #include "util.h" |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
34 |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
35 void render_errorbox(char *title, char *message); |
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
36 void render_warnbox(char *title, char *message); |
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
37 void render_infobox(char *title, char *message); |
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
38 extern int headless; |
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
39 |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
40 char * alloc_concat(char const * first, char const * second) |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 int flen = strlen(first); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 int slen = strlen(second); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 char * ret = malloc(flen + slen + 1); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 memcpy(ret, first, flen); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 memcpy(ret+flen, second, slen+1); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 return ret; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
50 char * alloc_concat_m(int num_parts, char const ** parts) |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 int total = 0; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 for (int i = 0; i < num_parts; i++) { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 total += strlen(parts[i]); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 char * ret = malloc(total + 1); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 *ret = 0; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 for (int i = 0; i < num_parts; i++) { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 strcat(ret, parts[i]); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 return ret; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 |
2158
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
64 char * alloc_join(int num_parts, char const **parts, char sep) |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
65 { |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
66 int total = num_parts ? num_parts - 1 : 0; |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
67 for (int i = 0; i < num_parts; i++) { |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
68 total += strlen(parts[i]); |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
69 } |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
70 char * ret = malloc(total + 1); |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
71 char *cur = ret; |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
72 for (int i = 0; i < num_parts; i++) { |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
73 size_t s = strlen(parts[i]); |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
74 if (i) { |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
75 *(cur++) = sep; |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
76 } |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
77 memcpy(cur, parts[i], s); |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
78 cur += s; |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
79 } |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
80 *cur = 0; |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
81 return ret; |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
82 } |
bdd83b47d78a
Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents:
2156
diff
changeset
|
83 |
1292
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
84 typedef struct { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
85 uint32_t start; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
86 uint32_t end; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
87 char *value; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
88 } var_pos; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
89 |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
90 char *replace_vars(char *base, tern_node *vars, uint8_t allow_env) |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
91 { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
92 uint32_t num_vars = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
93 for (char *cur = base; *cur; ++cur) |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
94 { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
95 //TODO: Support escaping $ and allow brace syntax |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
96 if (*cur == '$') { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
97 num_vars++; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
98 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
99 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
100 var_pos *positions = calloc(num_vars, sizeof(var_pos)); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
101 num_vars = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
102 uint8_t in_var = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
103 uint32_t max_var_len = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
104 for (char *cur = base; *cur; ++cur) |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
105 { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
106 if (in_var) { |
1850
30f2821ffd65
Allow rom directory and rom name in screenshot path. Allow rom name in screenshot name. Remove ability for path variables to contain underscores
Michael Pavone <pavone@retrodev.com>
parents:
1818
diff
changeset
|
107 if (!isalnum(*cur)) { |
1292
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
108 positions[num_vars].end = cur-base; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
109 if (positions[num_vars].end - positions[num_vars].start > max_var_len) { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
110 max_var_len = positions[num_vars].end - positions[num_vars].start; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
111 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
112 num_vars++; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
113 in_var = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
114 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
115 } else if (*cur == '$') { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
116 positions[num_vars].start = cur-base+1; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
117 in_var = 1; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
118 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
119 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
120 if (in_var) { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
121 positions[num_vars].end = strlen(base); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
122 if (positions[num_vars].end - positions[num_vars].start > max_var_len) { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
123 max_var_len = positions[num_vars].end - positions[num_vars].start; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
124 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
125 num_vars++; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
126 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
127 char *varname = malloc(max_var_len+1); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
128 uint32_t total_len = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
129 uint32_t cur = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
130 for (uint32_t i = 0; i < num_vars; i++) |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
131 { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
132 total_len += (positions[i].start - 1) - cur; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
133 cur = positions[i].start; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
134 memcpy(varname, base + positions[i].start, positions[i].end-positions[i].start); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
135 varname[positions[i].end-positions[i].start] = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
136 positions[i].value = tern_find_ptr(vars, varname); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
137 if (!positions[i].value && allow_env) { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
138 positions[i].value = getenv(varname); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
139 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
140 if (positions[i].value) { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
141 total_len += strlen(positions[i].value); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
142 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
143 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
144 total_len += strlen(base+cur); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
145 free(varname); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
146 char *output = malloc(total_len+1); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
147 cur = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
148 char *curout = output; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
149 for (uint32_t i = 0; i < num_vars; i++) |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
150 { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
151 if (positions[i].start-1 > cur) { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
152 memcpy(curout, base + cur, (positions[i].start-1) - cur); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
153 curout += (positions[i].start-1) - cur; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
154 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
155 if (positions[i].value) { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
156 strcpy(curout, positions[i].value); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
157 curout += strlen(curout); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
158 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
159 cur = positions[i].end; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
160 }; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
161 if (base[cur]) { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
162 strcpy(curout, base+cur); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
163 } else { |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
164 *curout = 0; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
165 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
166 free(positions); |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
167 return output; |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
168 } |
5905593d6828
Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
Michael Pavone <pavone@retrodev.com>
parents:
1265
diff
changeset
|
169 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
170 void byteswap_rom(int filesize, uint16_t *cart) |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
171 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
172 for(uint16_t *cur = cart; cur - cart < filesize/2; ++cur) |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
173 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
174 *cur = (*cur >> 8) | (*cur << 8); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
175 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
176 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
177 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1058
diff
changeset
|
178 |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 long file_size(FILE * f) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 fseek(f, 0, SEEK_END); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 long fsize = ftell(f); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 fseek(f, 0, SEEK_SET); |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 return fsize; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 char * strip_ws(char * text) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 while (*text && (!isprint(*text) || isblank(*text))) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 text++; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 char * ret = text; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 text = ret + strlen(ret) - 1; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 while (text > ret && (!isprint(*text) || isblank(*text))) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 *text = 0; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 text--; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 return ret; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 char * split_keyval(char * text) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 while (*text && !isblank(*text)) |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 text++; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 if (!*text) { |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 return text; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 } |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 *text = 0; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 return text+1; |
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 } |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
215 |
1783 | 216 uint8_t startswith(const char *haystack, const char *prefix) |
217 { | |
218 return !strncmp(haystack, prefix, strlen(prefix)); | |
219 } | |
220 | |
1305
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
221 void bin_to_hex(uint8_t *output, uint8_t *input, uint64_t size) |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
222 { |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
223 while (size) |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
224 { |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
225 uint8_t digit = *input >> 4; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
226 digit += digit > 9 ? 'a' - 0xa : '0'; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
227 *(output++) = digit; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
228 digit = *(input++) & 0xF; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
229 digit += digit > 9 ? 'a' - 0xa : '0'; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
230 *(output++) = digit; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
231 size--; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
232 } |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
233 *(output++) = 0; |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
234 } |
5ceb316c479a
Allow games to be specified in ROM DB via sha1 instead of product ID. Added a new ROM DB memory map device type fixed for emulating simple fixed value copy protection registers. Used those two features to support Ya Se Chuan Shuo via a ROM DB entry.
Michael Pavone <pavone@retrodev.com>
parents:
1295
diff
changeset
|
235 |
1527
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
236 char *utf16be_to_utf8(uint8_t *buf, uint32_t max_size) |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
237 { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
238 uint8_t *cur = buf; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
239 uint32_t converted_size = 0; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
240 for (uint32_t i = 0; i < max_size; i++, cur+=2) |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
241 { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
242 uint16_t code = *cur << 16 | cur[1]; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
243 if (!code) { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
244 break; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
245 } |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
246 if (code < 0x80) { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
247 converted_size++; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
248 } else if (code < 0x800) { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
249 converted_size += 2; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
250 } else { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
251 //TODO: Deal with surrogate pairs |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
252 converted_size += 3; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
253 } |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
254 } |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
255 char *out = malloc(converted_size + 1); |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
256 char *cur_out = out; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
257 cur = buf; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
258 for (uint32_t i = 0; i < max_size; i++, cur+=2) |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
259 { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
260 uint16_t code = *cur << 16 | cur[1]; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
261 if (!code) { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
262 break; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
263 } |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
264 if (code < 0x80) { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
265 *(cur_out++) = code; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
266 } else if (code < 0x800) { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
267 *(cur_out++) = 0xC0 | code >> 6; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
268 *(cur_out++) = 0x80 | (code & 0x3F); |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
269 } else { |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
270 //TODO: Deal with surrogate pairs |
2322
1a3991ada927
Small fix to utf16 to utf8 util funciton
Michael Pavone <pavone@retrodev.com>
parents:
2215
diff
changeset
|
271 *(cur_out++) = 0xE0 | code >> 12; |
1527
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
272 *(cur_out++) = 0x80 | (code >> 6 & 0x3F); |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
273 *(cur_out++) = 0x80 | (code & 0x3F); |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
274 } |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
275 } |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
276 *cur_out = 0; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
277 return out; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
278 } |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1523
diff
changeset
|
279 |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
280 int utf8_codepoint(const char **text) |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
281 { |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
282 uint8_t initial = **text; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
283 (*text)++; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
284 if (initial < 0x80) { |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
285 return initial; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
286 } |
1594
137dbd05ceab
Fix some issues identified by cppcheck
Michael Pavone <pavone@retrodev.com>
parents:
1592
diff
changeset
|
287 int base = 0; |
137dbd05ceab
Fix some issues identified by cppcheck
Michael Pavone <pavone@retrodev.com>
parents:
1592
diff
changeset
|
288 uint8_t extended_bytes = 0; |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
289 if ((initial & 0xE0) == 0xC0) { |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
290 base = 0x80; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
291 initial &= 0x1F; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
292 extended_bytes = 1; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
293 } else if ((initial & 0xF0) == 0xE0) { |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
294 base = 0x800; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
295 initial &= 0xF; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
296 extended_bytes = 2; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
297 } else if ((initial & 0xF8) == 0xF0) { |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
298 base = 0x10000; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
299 initial &= 0x7; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
300 extended_bytes = 3; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
301 } |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
302 int value = initial; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
303 for (uint8_t i = 0; i < extended_bytes; i++) |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
304 { |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
305 if ((**text & 0xC0) != 0x80) { |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
306 return -1; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
307 } |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
308 value = value << 6; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
309 value |= (**text) & 0x3F; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
310 (*text)++; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
311 } |
2533
bebc3589dedf
Fix bug in utf8_codepoint
Michael Pavone <pavone@retrodev.com>
parents:
2425
diff
changeset
|
312 if (value < base) { |
bebc3589dedf
Fix bug in utf8_codepoint
Michael Pavone <pavone@retrodev.com>
parents:
2425
diff
changeset
|
313 return 0; |
bebc3589dedf
Fix bug in utf8_codepoint
Michael Pavone <pavone@retrodev.com>
parents:
2425
diff
changeset
|
314 } |
bebc3589dedf
Fix bug in utf8_codepoint
Michael Pavone <pavone@retrodev.com>
parents:
2425
diff
changeset
|
315 return value; |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
316 } |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1540
diff
changeset
|
317 |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
318 char is_path_sep(char c) |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
319 { |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
320 #ifdef _WIN32 |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
321 if (c == '\\') { |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
322 return 1; |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
323 } |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
324 #endif |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
325 return c == '/'; |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
326 } |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
327 |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
328 char is_absolute_path(char *path) |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
329 { |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
330 #ifdef _WIN32 |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
331 if (path[1] == ':' && is_path_sep(path[2]) && isalpha(path[0])) { |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
332 return 1; |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
333 } |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
334 #endif |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
335 return is_path_sep(path[0]); |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
336 } |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
337 |
1581
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
338 char * basename_no_extension(const char *path) |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
339 { |
1581
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
340 const char *lastdot = NULL; |
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
341 const char *lastslash = NULL; |
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
342 const char *cur; |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
343 for (cur = path; *cur; cur++) |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
344 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
345 if (*cur == '.') { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
346 lastdot = cur; |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
347 } else if (is_path_sep(*cur)) { |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
348 lastslash = cur + 1; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
349 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
350 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
351 if (!lastdot) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
352 lastdot = cur; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
353 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
354 if (!lastslash) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
355 lastslash = path; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
356 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
357 char *barename = malloc(lastdot-lastslash+1); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
358 memcpy(barename, lastslash, lastdot-lastslash); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
359 barename[lastdot-lastslash] = 0; |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
360 |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
361 return barename; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
362 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
363 |
1523
c416ace65ff1
Fix const correctness for path_extension
Michael Pavone <pavone@retrodev.com>
parents:
1485
diff
changeset
|
364 char *path_extension(char const *path) |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
365 { |
1523
c416ace65ff1
Fix const correctness for path_extension
Michael Pavone <pavone@retrodev.com>
parents:
1485
diff
changeset
|
366 char const *lastdot = NULL; |
c416ace65ff1
Fix const correctness for path_extension
Michael Pavone <pavone@retrodev.com>
parents:
1485
diff
changeset
|
367 char const *lastslash = NULL; |
c416ace65ff1
Fix const correctness for path_extension
Michael Pavone <pavone@retrodev.com>
parents:
1485
diff
changeset
|
368 char const *cur; |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
369 for (cur = path; *cur; cur++) |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
370 { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
371 if (*cur == '.') { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
372 lastdot = cur; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
373 } else if (is_path_sep(*cur)) { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
374 lastslash = cur + 1; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
375 } |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
376 } |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
377 if (!lastdot || (lastslash && lastslash > lastdot)) { |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
378 //no extension |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
379 return NULL; |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
380 } |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
381 return strdup(lastdot+1); |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
382 } |
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
383 |
2156
237068a25523
Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents:
2032
diff
changeset
|
384 uint8_t path_matches_extensions(char *path, const char **ext_list, uint32_t num_exts) |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
385 { |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
386 char *ext = path_extension(path); |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
387 if (!ext) { |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
388 return 0; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
389 } |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
390 uint32_t extidx; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
391 for (extidx = 0; extidx < num_exts; extidx++) |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
392 { |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
393 if (!strcasecmp(ext, ext_list[extidx])) { |
1592
31effaadf877
Fix some memory errors (mostly leaks) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1581
diff
changeset
|
394 free(ext); |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
395 return 1; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
396 } |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
397 } |
1592
31effaadf877
Fix some memory errors (mostly leaks) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1581
diff
changeset
|
398 free(ext); |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
399 return 0; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
400 } |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
401 |
1581
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
402 char * path_dirname(const char *path) |
1438
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
403 { |
1581
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
404 const char *lastslash = NULL; |
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
405 const char *cur; |
1438
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
406 for (cur = path; *cur; cur++) |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
407 { |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
408 if (is_path_sep(*cur)) { |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
409 lastslash = cur; |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
410 } |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
411 } |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
412 if (!lastslash) { |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
413 return NULL; |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
414 } |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
415 char *dir = malloc(lastslash-path+1); |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
416 memcpy(dir, path, lastslash-path); |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
417 dir[lastslash-path] = 0; |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
418 |
1438
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
419 return dir; |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
420 } |
e2bd03ed3190
Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents:
1305
diff
changeset
|
421 |
768
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
422 uint32_t nearest_pow2(uint32_t val) |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
423 { |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
424 uint32_t ret = 1; |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
425 while (ret < val) |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
426 { |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
427 ret = ret << 1; |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
428 } |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
429 return ret; |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
430 } |
2f48a3c187c6
Add support for reading cartridge memory map from ROM database, though without EEPROM support for now
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
431 |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
432 static char * exe_str; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
433 |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
434 void set_exe_str(char * str) |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
435 { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
436 exe_str = str; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
437 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
438 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
439 void fatal_error(char *format, ...) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
440 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
441 va_list args; |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
442 va_start(args, format); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
443 if (!headless) { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
444 //take a guess at the final size |
1265
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
445 int32_t size = strlen(format) * 2; |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
446 char *buf = malloc(size); |
1265
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
447 int32_t actual = vsnprintf(buf, size, format, args); |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
448 if (actual >= size || actual < 0) { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
449 if (actual < 0) { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
450 //seems on windows, vsnprintf is returning -1 when the buffer is too small |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
451 //since we don't know the proper size, a generous multiplier will hopefully suffice |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
452 actual = size * 4; |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
453 } else { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
454 actual++; |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
455 } |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
456 free(buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
457 buf = malloc(actual); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
458 va_end(args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
459 va_start(args, format); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
460 vsnprintf(buf, actual, format, args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
461 } |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
462 fatal_puts(buf); |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
463 render_errorbox("Fatal Error", buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
464 free(buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
465 } else { |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
466 fatal_printf(format, args); |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
467 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
468 va_end(args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
469 exit(1); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
470 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
471 |
1950
417e0fc958cc
Fix non-Windows build break from Windows compat changes
Michael Pavone <pavone@retrodev.com>
parents:
1949
diff
changeset
|
472 #ifndef _WIN32 |
417e0fc958cc
Fix non-Windows build break from Windows compat changes
Michael Pavone <pavone@retrodev.com>
parents:
1949
diff
changeset
|
473 #include <unistd.h> |
417e0fc958cc
Fix non-Windows build break from Windows compat changes
Michael Pavone <pavone@retrodev.com>
parents:
1949
diff
changeset
|
474 #endif |
417e0fc958cc
Fix non-Windows build break from Windows compat changes
Michael Pavone <pavone@retrodev.com>
parents:
1949
diff
changeset
|
475 |
794
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
476 void warning(char *format, ...) |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
477 { |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
478 va_list args; |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
479 va_start(args, format); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
480 #ifndef _WIN32 |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
481 if (headless || (isatty(STDERR_FILENO) && isatty(STDIN_FILENO))) { |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
482 warning_printf(format, args); |
794
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
483 } else { |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
484 #endif |
1265
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
485 int32_t size = strlen(format) * 2; |
794
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
486 char *buf = malloc(size); |
1265
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
487 int32_t actual = vsnprintf(buf, size, format, args); |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
488 if (actual >= size || actual < 0) { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
489 if (actual < 0) { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
490 //seems on windows, vsnprintf is returning -1 when the buffer is too small |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
491 //since we don't know the proper size, a generous multiplier will hopefully suffice |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
492 actual = size * 4; |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
493 } else { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
494 actual++; |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
495 } |
794
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
496 free(buf); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
497 buf = malloc(actual); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
498 va_end(args); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
499 va_start(args, format); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
500 vsnprintf(buf, actual, format, args); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
501 } |
879
a77670cd178d
Send info/warning/fatal messages to logcat on Android
Michael Pavone <pavone@retrodev.com>
parents:
876
diff
changeset
|
502 warning_puts(buf); |
794
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
503 render_infobox("BlastEm Info", buf); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
504 free(buf); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
505 #ifndef _WIN32 |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
506 } |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
507 #endif |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
508 va_end(args); |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
509 } |
792be135d3af
Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
510 |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
511 static uint8_t output_enabled = 1; |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
512 void info_message(char *format, ...) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
513 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
514 va_list args; |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
515 va_start(args, format); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
516 #ifndef _WIN32 |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
517 if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
518 if (output_enabled) { |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
519 info_printf(format, args); |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
520 } |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
521 } else { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
522 #endif |
1265
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
523 int32_t size = strlen(format) * 2; |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
524 char *buf = malloc(size); |
1265
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
525 int32_t actual = vsnprintf(buf, size, format, args); |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
526 if (actual >= size || actual < 0) { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
527 if (actual < 0) { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
528 //seems on windows, vsnprintf is returning -1 when the buffer is too small |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
529 //since we don't know the proper size, a generous multiplier will hopefully suffice |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
530 actual = size * 4; |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
531 } else { |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
532 actual++; |
a344885e7c79
Fix info_message/warning/error functions to deal with limitations of vsnprintf on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1140
diff
changeset
|
533 } |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
534 free(buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
535 buf = malloc(actual); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
536 va_end(args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
537 va_start(args, format); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
538 vsnprintf(buf, actual, format, args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
539 } |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
540 if (output_enabled) { |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
541 info_puts(buf); |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
542 } |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
543 render_infobox("BlastEm Info", buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
544 free(buf); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
545 #ifndef _WIN32 |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
546 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
547 #endif |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
548 va_end(args); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
549 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
773
diff
changeset
|
550 |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
551 void debug_message(char *format, ...) |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
552 { |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
553 va_list args; |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
554 va_start(args, format); |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
555 if (output_enabled) { |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
556 info_printf(format, args); |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
557 } |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
558 } |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
559 |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
560 void disable_stdout_messages(void) |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
561 { |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
562 output_enabled = 0; |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
563 } |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1783
diff
changeset
|
564 |
2032
441d5d6cea2f
Make KDEBUG functionality play nice with gdb remote debugging
Michael Pavone <pavone@retrodev.com>
parents:
1973
diff
changeset
|
565 uint8_t is_stdout_enabled(void) |
441d5d6cea2f
Make KDEBUG functionality play nice with gdb remote debugging
Michael Pavone <pavone@retrodev.com>
parents:
1973
diff
changeset
|
566 { |
441d5d6cea2f
Make KDEBUG functionality play nice with gdb remote debugging
Michael Pavone <pavone@retrodev.com>
parents:
1973
diff
changeset
|
567 return output_enabled; |
441d5d6cea2f
Make KDEBUG functionality play nice with gdb remote debugging
Michael Pavone <pavone@retrodev.com>
parents:
1973
diff
changeset
|
568 } |
441d5d6cea2f
Make KDEBUG functionality play nice with gdb remote debugging
Michael Pavone <pavone@retrodev.com>
parents:
1973
diff
changeset
|
569 |
742
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
570 #ifdef _WIN32 |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
571 #define WINVER 0x501 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
572 #include <winsock2.h> |
795
bce97fc0bb8a
Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
773
diff
changeset
|
573 #include <windows.h> |
bce97fc0bb8a
Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
773
diff
changeset
|
574 #include <shlobj.h> |
742
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
575 |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
576 char * get_home_dir() |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
577 { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
578 static char path[MAX_PATH]; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
579 SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
580 return path; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
581 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
582 |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
583 char * get_exe_dir() |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
584 { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
585 static char path[MAX_PATH]; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
586 HMODULE module = GetModuleHandleA(NULL); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
587 GetModuleFileNameA(module, path, MAX_PATH); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
588 |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
589 int pathsize = strlen(path); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
590 for(char * cur = path + pathsize - 1; cur != path; cur--) |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
591 { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
592 if (*cur == '\\') { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
593 *cur = 0; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
594 break; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
595 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
596 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
597 return path; |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
598 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
599 |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
600 dir_entry *get_dir_list(char *path, size_t *numret) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
601 { |
1674
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
602 dir_entry *ret; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
603 if (path[0] == PATH_SEP[0] && !path[1]) { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
604 int drives = GetLogicalDrives(); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
605 size_t count = 0; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
606 for (int i = 0; i < 26; i++) |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
607 { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
608 if (drives & (1 << i)) { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
609 count++; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
610 } |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
611 } |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
612 ret = calloc(count, sizeof(dir_entry)); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
613 dir_entry *cur = ret; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
614 for (int i = 0; i < 26; i++) |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
615 { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
616 if (drives & (1 << i)) { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
617 cur->name = malloc(4); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
618 cur->name[0] = 'A' + i; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
619 cur->name[1] = ':'; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
620 cur->name[2] = PATH_SEP[0]; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
621 cur->name[3] = 0; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
622 cur->is_dir = 1; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
623 cur++; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
624 } |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
625 } |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
626 if (numret) { |
1674
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
627 *numret = count; |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
628 } |
1674
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
629 } else { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
630 HANDLE dir; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
631 WIN32_FIND_DATA file; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
632 char *pattern = alloc_concat(path, "/*.*"); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
633 dir = FindFirstFile(pattern, &file); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
634 free(pattern); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
635 if (dir == INVALID_HANDLE_VALUE) { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
636 if (numret) { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
637 *numret = 0; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
638 } |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
639 return NULL; |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
640 } |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
641 |
1674
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
642 size_t storage = 64; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
643 ret = malloc(sizeof(dir_entry) * storage); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
644 size_t pos = 0; |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
645 |
1674
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
646 if (path[1] == ':' && (!path[2] || (path[2] == PATH_SEP[0] && !path[3]))) { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
647 //we are in the root of a drive, add a virtual .. entry |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
648 //for navigating to the virtual root directory |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
649 ret[pos].name = strdup(".."); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
650 ret[pos++].is_dir = 1; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
651 } |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
652 |
1674
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
653 do { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
654 if (pos == storage) { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
655 storage = storage * 2; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
656 ret = realloc(ret, sizeof(dir_entry) * storage); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
657 } |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
658 ret[pos].name = strdup(file.cFileName); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
659 ret[pos++].is_dir = (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
660 } while (FindNextFile(dir, &file)); |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
661 |
1674
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
662 FindClose(dir); |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
663 if (numret) { |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
664 *numret = pos; |
c362f2c7766a
Moved fake virtual root stuff to get_dir_list from legacy menu so it can be used in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1673
diff
changeset
|
665 } |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
666 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
667 return ret; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
668 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
669 |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
670 time_t get_modification_time(char *path) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
671 { |
974
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
672 HANDLE results; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
673 WIN32_FIND_DATA file; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
674 results = FindFirstFile(path, &file); |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
675 if (results == INVALID_HANDLE_VALUE) { |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
676 return 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
677 } |
974
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
678 FindClose(results); |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
679 uint64_t wintime = ((uint64_t)file.ftLastWriteTime.dwHighDateTime) << 32 | file.ftLastWriteTime.dwLowDateTime; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
680 //convert to seconds |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
681 wintime /= 10000000; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
682 //adjust for difference between Windows and Unix Epoch |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
683 wintime -= 11644473600LL; |
fd7702bcc034
FindFirstFile makes more sense for getting modification times of a path than using CreateFile and GetFileTimes
Michael Pavone <pavone@retrodev.com>
parents:
972
diff
changeset
|
684 return (time_t)wintime; |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
685 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
686 |
1540
e94cff9cb625
Make sure config directory exists before trying to save config file
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
687 int ensure_dir_exists(const char *path) |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
688 { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
689 if (CreateDirectory(path, NULL)) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
690 return 1; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
691 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
692 if (GetLastError() == ERROR_ALREADY_EXISTS) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
693 return 1; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
694 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
695 if (GetLastError() != ERROR_PATH_NOT_FOUND) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
696 warning("CreateDirectory failed with unexpected error code %X\n", GetLastError()); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
697 return 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
698 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
699 char *parent = strdup(path); |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
700 //Windows technically supports both native and Unix-style path separators |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
701 //so search for both |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
702 char *sep = strrchr(parent, '\\'); |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
703 char *osep = strrchr(parent, '/'); |
1039
86ed81bb574f
Fix bug in ensure_dir_exists that would cause it to fail when mixed path separators were used
Michael Pavone <pavone@retrodev.com>
parents:
1021
diff
changeset
|
704 if (osep && (!sep || osep > sep)) { |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
705 sep = osep; |
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
706 } |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
707 if (!sep || sep == parent) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
708 //relative path, but for some reason we failed |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
709 return 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
710 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
711 *sep = 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
712 if (!ensure_dir_exists(parent)) { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
713 free(parent); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
714 return 0; |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
715 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
716 free(parent); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
717 return CreateDirectory(path, NULL); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
718 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
719 |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
720 static WSADATA wsa_data; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
721 static void socket_cleanup(void) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
722 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
723 WSACleanup(); |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
724 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
725 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
726 void socket_init(void) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
727 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
728 static uint8_t started; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
729 if (!started) { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
730 started = 1; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
731 WSAStartup(MAKEWORD(2,2), &wsa_data); |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
732 atexit(socket_cleanup); |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
733 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
734 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
735 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
736 int socket_blocking(int sock, int should_block) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
737 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
738 u_long param = !should_block; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
739 if (ioctlsocket(sock, FIONBIO, ¶m)) { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
740 return WSAGetLastError(); |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
741 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
742 return 0; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
743 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
744 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
745 void socket_close(int sock) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
746 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
747 closesocket(sock); |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
748 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
749 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
750 int socket_last_error(void) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
751 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
752 return WSAGetLastError(); |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
753 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
754 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
755 int socket_error_is_wouldblock(void) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
756 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
757 return WSAGetLastError() == WSAEWOULDBLOCK; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
758 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
759 |
742
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
760 #else |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
761 #include <fcntl.h> |
1973
cd163b230cf9
Fix handling of remote disconnects
Michael Pavone <pavone@retrodev.com>
parents:
1950
diff
changeset
|
762 #include <signal.h> |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
763 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
764 void socket_init(void) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
765 { |
1973
cd163b230cf9
Fix handling of remote disconnects
Michael Pavone <pavone@retrodev.com>
parents:
1950
diff
changeset
|
766 //SIGPIPE on network sockets is not desired |
cd163b230cf9
Fix handling of remote disconnects
Michael Pavone <pavone@retrodev.com>
parents:
1950
diff
changeset
|
767 //would be better to do this in a more limited way, |
cd163b230cf9
Fix handling of remote disconnects
Michael Pavone <pavone@retrodev.com>
parents:
1950
diff
changeset
|
768 //but the alternatives are not portable |
cd163b230cf9
Fix handling of remote disconnects
Michael Pavone <pavone@retrodev.com>
parents:
1950
diff
changeset
|
769 signal(SIGPIPE, SIG_IGN); |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
770 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
771 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
772 int socket_blocking(int sock, int should_block) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
773 { |
1950
417e0fc958cc
Fix non-Windows build break from Windows compat changes
Michael Pavone <pavone@retrodev.com>
parents:
1949
diff
changeset
|
774 if (fcntl(sock, F_SETFL, should_block ? 0 : O_NONBLOCK)) { |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
775 return errno; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
776 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
777 return 0; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
778 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
779 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
780 void socket_close(int sock) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
781 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
782 close(sock); |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
783 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
784 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
785 int socket_last_error(void) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
786 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
787 return errno; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
788 } |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
789 |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
790 int socket_error_is_wouldblock(void) |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
791 { |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
792 return errno == EAGAIN || errno == EWOULDBLOCK; |
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
793 } |
742
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
794 |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
795 char * get_home_dir() |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
796 { |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
797 return getenv("HOME"); |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
798 } |
2e1b3b258523
Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents:
741
diff
changeset
|
799 |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
800 char * readlink_alloc(char * path) |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
801 { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
802 char * linktext = NULL; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
803 ssize_t linksize = 512; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
804 ssize_t cursize = 0; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
805 do { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
806 if (linksize > cursize) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
807 cursize = linksize; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
808 if (linktext) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
809 free(linktext); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
810 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
811 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
812 linktext = malloc(cursize); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
813 linksize = readlink(path, linktext, cursize-1); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
814 if (linksize == -1) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
815 perror("readlink"); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
816 free(linktext); |
559
6b248602ab84
blastem builds and almost works on OS X now
Mike Pavone <pavone@retrodev.com>
parents:
549
diff
changeset
|
817 return NULL; |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
818 } |
549
32da1e0d5e55
Properly null terminate string returned by readlink in util.c
Michael Pavone <pavone@retrodev.com>
parents:
496
diff
changeset
|
819 } while ((linksize+1) > cursize); |
32da1e0d5e55
Properly null terminate string returned by readlink in util.c
Michael Pavone <pavone@retrodev.com>
parents:
496
diff
changeset
|
820 linktext[linksize] = 0; |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
821 return linktext; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
822 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
823 |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
824 char * get_exe_dir() |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
825 { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
826 static char * exe_dir; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
827 if (!exe_dir) { |
762
206c449eaa81
Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
828 char * cur; |
763
2a25ea5d94f7
Fix sense of HAS_PROC check
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
829 #ifdef HAS_PROC |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
830 char * linktext = readlink_alloc("/proc/self/exe"); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
831 if (!linktext) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
832 goto fallback; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
833 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
834 int linksize = strlen(linktext); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
835 for(cur = linktext + linksize - 1; cur != linktext; cur--) |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
836 { |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
837 if (is_path_sep(*cur)) { |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
838 *cur = 0; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
839 break; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
840 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
841 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
842 if (cur == linktext) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
843 free(linktext); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
844 fallback: |
762
206c449eaa81
Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
845 #endif |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
846 if (!exe_str) { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
847 fputs("/proc/self/exe is not available and set_exe_str was not called!", stderr); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
848 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
849 int pathsize = strlen(exe_str); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
850 for(cur = exe_str + pathsize - 1; cur != exe_str; cur--) |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
851 { |
1008
51885857c019
Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents:
974
diff
changeset
|
852 if (is_path_sep(*cur)) { |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
853 exe_dir = malloc(cur-exe_str+1); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
854 memcpy(exe_dir, exe_str, cur-exe_str); |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
855 exe_dir[cur-exe_str] = 0; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
856 break; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
857 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
858 } |
763
2a25ea5d94f7
Fix sense of HAS_PROC check
Michael Pavone <pavone@retrodev.com>
parents:
762
diff
changeset
|
859 #ifdef HAS_PROC |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
860 } else { |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
861 exe_dir = linktext; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
862 } |
762
206c449eaa81
Get "portable" builds working on Linux and add a build time check for whether /proc exists
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
863 #endif |
496
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
864 } |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
865 return exe_dir; |
6fc71114d145
Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
866 } |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
867 #include <dirent.h> |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
868 |
2682
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
869 #ifdef __ANDROID__ |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
870 static dir_entry *jdir_list_helper(JNIEnv *env, jmethodID meth, char *path, size_t *numret) |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
871 { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
872 jstring jpath = (*env)->NewStringUTF(env, path); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
873 jobject activity = SDL_AndroidGetActivity(); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
874 jobject ret = (*env)->CallObjectMethod(env, activity, meth, jpath); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
875 dir_entry *res = NULL; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
876 if (ret) { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
877 jsize num = (*env)->GetArrayLength(env, ret); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
878 if (numret) { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
879 *numret = num; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
880 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
881 res = calloc(num, sizeof(dir_entry)); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
882 for (jsize i = 0; i < num; i++) |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
883 { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
884 jstring entry = (*env)->GetObjectArrayElement(env, ret, i); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
885 char const *tmp = (*env)->GetStringUTFChars(env, entry, NULL); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
886 jsize len = (*env)->GetStringUTFLength(env, entry); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
887 res[i].name = calloc(len + 1, 1); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
888 res[i].is_dir = tmp[len-1] == '/'; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
889 memcpy(res[i].name, tmp, res[i].is_dir ? len -1 : len); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
890 (*env)->ReleaseStringUTFChars(env, entry, tmp); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
891 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
892 (*env)->DeleteLocalRef(env, ret); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
893 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
894 |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
895 (*env)->DeleteLocalRef(env, activity); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
896 if (!res) { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
897 if (numret) { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
898 *numret = 0; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
899 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
900 return NULL; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
901 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
902 return res; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
903 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
904 #endif |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
905 |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
906 dir_entry *get_dir_list(char *path, size_t *numret) |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
907 { |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
908 #ifdef __ANDROID__ |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
909 debug_message("get_dir_list(%s)\n", path); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
910 if (startswith(path, "content://")) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
911 static const char activity_class_name[] = "com/retrodev/blastem/BlastEmActivity"; |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
912 static const char read_uri_dir_name[] = "readUriDir"; |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
913 JNIEnv *env = SDL_AndroidGetJNIEnv(); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
914 jclass act_class = (*env)->FindClass(env, activity_class_name); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
915 if (!act_class) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
916 fatal_error("Failed to find activity class %s\n", activity_class_name); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
917 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
918 jmethodID meth = (*env)->GetMethodID(env, act_class, read_uri_dir_name, "(Ljava/lang/String;)[Ljava/lang/String;"); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
919 if (!meth) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
920 fatal_error("Failed to find method %s\n", read_uri_dir_name); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
921 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
922 debug_message("get_dir_list(%s) using Storage Access Framework\n", path); |
2682
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
923 return jdir_list_helper(env, meth, path, numret); |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
924 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
925 #endif |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
926 DIR *d = opendir(path); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
927 if (!d) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
928 if (numret) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
929 *numret = 0; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
930 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
931 return NULL; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
932 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
933 size_t storage = 64; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
934 dir_entry *ret = malloc(sizeof(dir_entry) * storage); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
935 size_t pos = 0; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
936 struct dirent* entry; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
937 while (entry = readdir(d)) |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
938 { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
939 if (entry->d_type != DT_REG && entry->d_type != DT_LNK && entry->d_type != DT_DIR) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
940 continue; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
941 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
942 if (pos == storage) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
943 storage = storage * 2; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
944 ret = realloc(ret, sizeof(dir_entry) * storage); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
945 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
946 ret[pos].name = strdup(entry->d_name); |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
947 ret[pos++].is_dir = entry->d_type == DT_DIR; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
948 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
949 if (numret) { |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
950 *numret = pos; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
951 } |
1592
31effaadf877
Fix some memory errors (mostly leaks) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1581
diff
changeset
|
952 closedir(d); |
866
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
953 return ret; |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
954 } |
69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
955 |
957 | 956 time_t get_modification_time(char *path) |
957 { | |
958 struct stat st; | |
959 if (stat(path, &st)) { | |
960 return 0; | |
961 } | |
1021 | 962 #ifdef __APPLE__ |
963 return st.st_mtimespec.tv_sec; | |
964 #else | |
1139
160e3f597cec
Old uncommitted fix for Android build
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
965 //Android's Bionic doesn't support the new style so we'll use the old one instead |
160e3f597cec
Old uncommitted fix for Android build
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
966 return st.st_mtime; |
1021 | 967 #endif |
957 | 968 } |
969 | |
1540
e94cff9cb625
Make sure config directory exists before trying to save config file
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
970 int ensure_dir_exists(const char *path) |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
971 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
972 struct stat st; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
973 if (stat(path, &st)) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
974 if (errno == ENOENT) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
975 char *parent = strdup(path); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
976 char *sep = strrchr(parent, '/'); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
977 if (sep && sep != parent) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
978 *sep = 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
979 if (!ensure_dir_exists(parent)) { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
980 free(parent); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
981 return 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
982 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
983 free(parent); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
984 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
985 return mkdir(path, 0777) == 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
986 } else { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
987 char buf[80]; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
988 strerror_r(errno, buf, sizeof(buf)); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
989 warning("stat failed with error: %s", buf); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
990 return 0; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
991 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
992 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
993 return S_ISDIR(st.st_mode); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
994 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
995 |
741
80a67be1770b
Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents:
549
diff
changeset
|
996 #endif |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
997 |
972
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
998 void free_dir_list(dir_entry *list, size_t numentries) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
999 { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
1000 for (size_t i = 0; i < numentries; i++) |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
1001 { |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
1002 free(list[i].name); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
1003 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
1004 free(list); |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
1005 } |
4899d3ae37b3
Implement Windows versions of recently added functions in util.c and get the Windows build working again
Michael Pavone <pavone@retrodev.com>
parents:
957
diff
changeset
|
1006 |
1484
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1007 static int sort_dir_alpha(const void *a, const void *b) |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1008 { |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1009 const dir_entry *da, *db; |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1010 da = a; |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1011 db = b; |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1012 if (da->is_dir != db->is_dir) { |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1013 return db->is_dir - da->is_dir; |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1014 } |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1015 return strcasecmp(((dir_entry *)a)->name, ((dir_entry *)b)->name); |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1016 } |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1017 |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1018 void sort_dir_list(dir_entry *list, size_t num_entries) |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1019 { |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1020 qsort(list, num_entries, sizeof(dir_entry), sort_dir_alpha); |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1021 } |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1438
diff
changeset
|
1022 |
1852
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1023 uint8_t delete_file(char *path) |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1024 { |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1025 #ifdef _WIN32 |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1026 //TODO: Call Unicode version and prepend special string to remove max path limitation |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1027 return 0 != DeleteFileA(path); |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1028 #else |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1029 return 0 == unlink(path); |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1030 #endif |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1031 } |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1032 |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1033 #ifdef __ANDROID__ |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1034 |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1035 #include <SDL.h> |
1818
243f3a7247f9
Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1036 #ifndef IS_LIB |
1140
4490c9c12272
Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents:
1139
diff
changeset
|
1037 char *read_bundled_file(char *name, uint32_t *sizeret) |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1038 { |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1039 SDL_RWops *rw = SDL_RWFromFile(name, "rb"); |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1040 if (!rw) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1041 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1042 *sizeret = -1; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1043 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1044 return NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1045 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1046 |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1047 long fsize = rw->size(rw); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1048 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1049 *sizeret = fsize; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1050 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1051 char *ret; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1052 if (fsize) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1053 ret = malloc(fsize); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1054 if (SDL_RWread(rw, ret, 1, fsize) != fsize) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1055 free(ret); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1056 ret = NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1057 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1058 } else { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1059 ret = NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1060 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1061 SDL_RWclose(rw); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1062 return ret; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1063 } |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1064 |
2682
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1065 dir_entry *get_bundled_dir_list(char *name, size_t *num_out) |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1066 { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1067 static const char activity_class_name[] = "com/retrodev/blastem/BlastEmActivity"; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1068 static const char get_assets_list_name[] = "getAssetsList"; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1069 JNIEnv *env = SDL_AndroidGetJNIEnv(); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1070 jclass act_class = (*env)->FindClass(env, activity_class_name); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1071 if (!act_class) { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1072 fatal_error("Failed to find activity class %s\n", activity_class_name); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1073 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1074 jmethodID meth = (*env)->GetMethodID(env, act_class, get_assets_list_name, "(Ljava/lang/String;)[Ljava/lang/String;"); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1075 if (!meth) { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1076 fatal_error("Failed to find method %s\n", get_assets_list_name); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1077 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1078 return jdir_list_helper(env, meth, name, num_out); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1079 } |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1080 |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1081 static int open_uri(const char *path, const char *mode) |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1082 { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1083 static const char activity_class_name[] = "com/retrodev/blastem/BlastEmActivity"; |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1084 static const char open_uri_as_fd_name[] = "openUriAsFd"; |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1085 JNIEnv *env = SDL_AndroidGetJNIEnv(); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1086 jclass act_class = (*env)->FindClass(env, activity_class_name); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1087 if (!act_class) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1088 fatal_error("Failed to find activity class %s\n", activity_class_name); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1089 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1090 jmethodID meth = (*env)->GetMethodID(env, act_class, open_uri_as_fd_name, "(Ljava/lang/String;Ljava/lang/String;)I"); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1091 if (!meth) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1092 fatal_error("Failed to find method %s\n", open_uri_as_fd_name); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1093 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1094 jobject activity = SDL_AndroidGetActivity(); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1095 jstring jpath = (*env)->NewStringUTF(env, path); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1096 jstring jmode = (*env)->NewStringUTF(env, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1097 int fd = (*env)->CallIntMethod(env, activity, meth, jpath, jmode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1098 (*env)->DeleteLocalRef(env, activity); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1099 return fd; |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1100 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1101 |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1102 FILE* fopen_wrapper(const char *path, const char *mode) |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1103 { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1104 if (startswith(path, "content://")) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1105 debug_message("fopen_wrapper(%s, %s) - Using Storage Access Framework\n", path, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1106 int fd = open_uri(path, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1107 if (!fd) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1108 return NULL; |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1109 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1110 return fdopen(fd, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1111 } else { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1112 debug_message("fopen_wrapper(%s, %s) - Norma fopen\n", path, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1113 return fopen(path, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1114 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1115 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1116 |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1117 #ifndef DISABLE_ZLIB |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1118 gzFile gzopen_wrapper(const char *path, const char *mode) |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1119 { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1120 if (startswith(path, "content://")) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1121 debug_message("gzopen_wrapper(%s, %s) - Using Storage Access Framework\n", path, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1122 int fd = open_uri(path, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1123 if (!fd) { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1124 return NULL; |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1125 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1126 return gzdopen(fd, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1127 } else { |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1128 debug_message("fopen_wrapper(%s, %s) - Norma gzopen\n", path, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1129 return gzopen(path, mode); |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1130 } |
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1131 } |
1818
243f3a7247f9
Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1132 #endif |
2681
c4256ce2c45a
Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents:
2533
diff
changeset
|
1133 #endif // IS_LIB |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1134 |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1135 char const *get_config_dir() |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1136 { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1137 return SDL_AndroidGetInternalStoragePath(); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1138 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1139 |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1140 char const *get_userdata_dir() |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1141 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1142 return SDL_AndroidGetInternalStoragePath(); |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1143 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1144 |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1145 #else |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1146 |
1818
243f3a7247f9
Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1147 #ifndef IS_LIB |
2425
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1148 char *bundled_file_path(char *name) |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1149 { |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1674
diff
changeset
|
1150 #ifdef DATA_PATH |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1674
diff
changeset
|
1151 char *data_dir = DATA_PATH; |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1674
diff
changeset
|
1152 #else |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1674
diff
changeset
|
1153 char *data_dir = get_exe_dir(); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1674
diff
changeset
|
1154 if (!data_dir) { |
2425
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1155 return NULL; |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1156 } |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1157 #endif |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1158 char const *pieces[] = {data_dir, PATH_SEP, name}; |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1159 return alloc_concat_m(3, pieces); |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1160 } |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1161 |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1162 char *read_bundled_file(char *name, uint32_t *sizeret) |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1163 { |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1164 char *path = bundled_file_path(name); |
794ba17f0716
Make termhelper work when current working directory is not the one that contains blastem
Michael Pavone <pavone@retrodev.com>
parents:
2322
diff
changeset
|
1165 if (!path) { |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1166 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1167 *sizeret = -1; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1168 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1169 return NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1170 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1171 FILE *f = fopen(path, "rb"); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1172 free(path); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1173 if (!f) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1174 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1175 *sizeret = -1; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1176 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1177 return NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1178 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1179 |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1180 long fsize = file_size(f); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1181 if (sizeret) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1182 *sizeret = fsize; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1183 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1184 char *ret; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1185 if (fsize) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1186 //reserve an extra byte in case caller wants |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1187 //to null terminate the data |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1188 ret = malloc(fsize+1); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1189 if (fread(ret, 1, fsize, f) != fsize) { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1190 free(ret); |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1191 ret = NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1192 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1193 } else { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1194 ret = NULL; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1195 } |
1594
137dbd05ceab
Fix some issues identified by cppcheck
Michael Pavone <pavone@retrodev.com>
parents:
1592
diff
changeset
|
1196 fclose(f); |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1197 return ret; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1198 } |
2682
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1199 |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1200 dir_entry *get_bundled_dir_list(char *name, size_t *num_out) |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1201 { |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1202 char *path = bundled_file_path(name); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1203 dir_entry *ret = get_dir_list(path, num_out); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1204 free(path); |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1205 return ret; |
143cb5762ec9
Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents:
2681
diff
changeset
|
1206 } |
1852
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1207 #endif //ISLIB |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1208 |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1209 #ifdef _WIN32 |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1210 char const *get_userdata_dir() |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1211 { |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1212 static char path[MAX_PATH]; |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1213 if (S_OK == SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)) |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1214 { |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1215 return path; |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1216 } |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1217 return NULL; |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1218 } |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1219 |
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1220 char const *get_config_dir() |
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1221 { |
1673
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1594
diff
changeset
|
1222 static char* confdir; |
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1594
diff
changeset
|
1223 if (!confdir) { |
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1594
diff
changeset
|
1224 char const *base = get_userdata_dir(); |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2158
diff
changeset
|
1225 if (base) { |
1673
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1594
diff
changeset
|
1226 confdir = alloc_concat(base, PATH_SEP "blastem"); |
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1594
diff
changeset
|
1227 } |
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1594
diff
changeset
|
1228 } |
ab3b465c052c
Fix Windows implentation of get_config_dir() so config file gets saved to the right place. Fix location for sticky_path file on all platforms
Michael Pavone <pavone@retrodev.com>
parents:
1594
diff
changeset
|
1229 return confdir; |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1230 } |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1231 #define CONFIG_PREFIX "" |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1232 #define SAVE_PREFIX "" |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1233 |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1234 #else |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1235 |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1236 #define CONFIG_PREFIX "/.config" |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1237 #define USERDATA_SUFFIX "/.local/share" |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1238 |
876
540cc4a7d626
Fix Android build breakage
Michael Pavone <pavone@retrodev.com>
parents:
875
diff
changeset
|
1239 char const *get_config_dir() |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1240 { |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1241 static char* confdir; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1242 if (!confdir) { |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1243 char const *base = get_home_dir(); |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1244 if (base) { |
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1245 confdir = alloc_concat(base, CONFIG_PREFIX PATH_SEP "blastem"); |
875
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1246 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1247 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1248 return confdir; |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1249 } |
54ffba3768d6
Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents:
866
diff
changeset
|
1250 |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1251 char const *get_userdata_dir() |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1252 { |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1253 static char* savedir; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1254 if (!savedir) { |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1255 char const *base = get_home_dir(); |
1058
266dc3f31f35
Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
Michael Pavone <pavone@retrodev.com>
parents:
1039
diff
changeset
|
1256 if (base) { |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1257 savedir = alloc_concat(base, USERDATA_SUFFIX); |
955
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1258 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1259 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1260 return savedir; |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1261 } |
229c23b3ab73
Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1262 |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1263 |
1852
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1264 #endif //_WIN32 |
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
1265 #endif //__ANDROID__ |
1295
96ad1b9bbb3a
Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents:
1292
diff
changeset
|
1266 |