aboutsummaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-09-27 17:03:06 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-11-01 16:26:16 +0100
commit980858186149651df5543b6fc99a4f7db0cdd089 (patch)
treed347200b0a562d84df505097651ad0642f207fdd /src/system
parent39f50e601d395bbd2d78d0147ac530b756da2fff (diff)
downloadjancity-980858186149651df5543b6fc99a4f7db0cdd089.tar.gz
WIP
Diffstat (limited to 'src/system')
-rw-r--r--src/system/CMakeLists.txt9
-rw-r--r--src/system/sdl-1.2/privinc/system_private.h15
-rw-r--r--src/system/sdl-1.2/src/stubs.c6
-rw-r--r--src/system/sdl-1.2/src/system.c11
-rw-r--r--src/system/win9x/src/system.c36
5 files changed, 73 insertions, 4 deletions
diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt
index 4c315b9..e541096 100644
--- a/src/system/CMakeLists.txt
+++ b/src/system/CMakeLists.txt
@@ -8,9 +8,16 @@ if(PS1_BUILD)
elseif(SDL1_2_BUILD)
set(src "sdl-1.2/src/system.c")
set(inc ${inc} "sdl-1.2/inc")
+ set(privinc ${privinc} "sdl-1.2/privinc")
set(privdeps ${privdeps} SDL::SDL)
+
+ if(WIN9X_BUILD)
+ set(src ${src} "win9x/src/system.c")
+ else()
+ set(src ${src} "sdl-1.2/src/stubs.c")
+ endif()
endif()
add_library(system ${src})
-target_include_directories(system PUBLIC ${inc})
+target_include_directories(system PUBLIC ${inc} PRIVATE ${privinc})
target_link_libraries(system PRIVATE ${privdeps})
diff --git a/src/system/sdl-1.2/privinc/system_private.h b/src/system/sdl-1.2/privinc/system_private.h
new file mode 100644
index 0000000..70ed8c8
--- /dev/null
+++ b/src/system/sdl-1.2/privinc/system_private.h
@@ -0,0 +1,15 @@
+#ifndef SYSTEM_PRIVATE_H
+#define SYSTEM_PRIVATE_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int system_init_os(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SYSTEM_PRIVATE_H */
diff --git a/src/system/sdl-1.2/src/stubs.c b/src/system/sdl-1.2/src/stubs.c
new file mode 100644
index 0000000..c07a790
--- /dev/null
+++ b/src/system/sdl-1.2/src/stubs.c
@@ -0,0 +1,6 @@
+#include <system_private.h>
+
+int system_init_os(void)
+{
+ return 0;
+}
diff --git a/src/system/sdl-1.2/src/system.c b/src/system/sdl-1.2/src/system.c
index bff5e4f..71d5d7e 100644
--- a/src/system/sdl-1.2/src/system.c
+++ b/src/system/sdl-1.2/src/system.c
@@ -1,7 +1,8 @@
+#include <system.h>
+#include <system_private.h>
#include <gfx.h>
-#include <sfx.h>
#include <net.h>
-#include <system.h>
+#include <sfx.h>
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
@@ -26,7 +27,9 @@ void system_deinit(void)
int system_init(void)
{
- if (SDL_Init(0))
+ if (system_init_os())
+ goto failure;
+ else if (SDL_Init(0))
{
fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
goto failure;
@@ -36,6 +39,8 @@ int system_init(void)
SDL_WM_SetCaption("rts", NULL);
SDL_ShowCursor(0);
+ /* SDL_WM_GrabInput(SDL_GRAB_ON); */
+ SDL_EnableUNICODE(1);
return 0;
failure:
diff --git a/src/system/win9x/src/system.c b/src/system/win9x/src/system.c
new file mode 100644
index 0000000..dd2aa10
--- /dev/null
+++ b/src/system/win9x/src/system.c
@@ -0,0 +1,36 @@
+#include <system_private.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+int system_init_os(void)
+{
+ /* Windows GUI applications do not print stderr or stdout anywhere.
+ * Therefore, it makes sense to redirect them to plaintext files. */
+ if (!(freopen("stderr.txt", "wb", stderr)))
+ {
+ fprintf(stderr, "%s: freopen(3) stderr failed: %s\n",
+ __func__, strerror(errno));
+ return -1;
+ }
+ else if (setvbuf(stderr, NULL, _IONBF, 0))
+ {
+ fprintf(stderr, "%s: setvbuf(3) stderr failed: %s\n",
+ __func__, strerror(errno));
+ return -1;
+ }
+ else if (!(freopen("stdout.txt", "wb", stdout)))
+ {
+ fprintf(stderr, "%s: freopen(3) stdout failed: %s\n",
+ __func__, strerror(errno));
+ return -1;
+ }
+ else if (setvbuf(stdout, NULL, _IONBF, 0))
+ {
+ fprintf(stderr, "%s: setvbuf(3) stdout failed: %s\n",
+ __func__, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}