aboutsummaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2021-07-03 00:49:03 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-30 08:20:20 +0200
commit6b9f686913efc3725b2690033cd4f398e07076ba (patch)
treee9aa91a6b9f617d78123ebe7ad272fc42a60d306 /src/system
parentc9e6ae44a9aeb89b3f48f3443d6baa80103f7445 (diff)
downloadjancity-6b9f686913efc3725b2690033cd4f398e07076ba.tar.gz
Add project source code
Diffstat (limited to 'src/system')
-rw-r--r--src/system/CMakeLists.txt13
-rw-r--r--src/system/inc/system.h17
-rw-r--r--src/system/ps1/inc/system/port.h17
-rw-r--r--src/system/ps1/src/init.c32
-rw-r--r--src/system/sdl-1.2/inc/system/port.h13
-rw-r--r--src/system/sdl-1.2/src/system.c36
6 files changed, 128 insertions, 0 deletions
diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt
new file mode 100644
index 0000000..679d5b4
--- /dev/null
+++ b/src/system/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(inc "inc")
+
+if(PS1_BUILD)
+ set(src "ps1/src/init.c")
+ set(inc ${inc} "ps1/inc")
+elseif(SDL1_2_BUILD)
+ set(src "sdl-1.2/src/system.c")
+ set(inc ${inc} "sdl-1.2/inc")
+endif()
+
+add_library(system ${src})
+target_include_directories(system PUBLIC ${inc})
+target_link_libraries(system PRIVATE gfx sfx)
diff --git a/src/system/inc/system.h b/src/system/inc/system.h
new file mode 100644
index 0000000..5338a0b
--- /dev/null
+++ b/src/system/inc/system.h
@@ -0,0 +1,17 @@
+#ifndef SYSTEM_H
+#define SYSTEM_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int system_init(void);
+void system_deinit(void);
+void system_loop(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SYSTEM_H */
diff --git a/src/system/ps1/inc/system/port.h b/src/system/ps1/inc/system/port.h
new file mode 100644
index 0000000..395097e
--- /dev/null
+++ b/src/system/ps1/inc/system/port.h
@@ -0,0 +1,17 @@
+#ifndef INIT_PS1_H
+#define INIT_PS1_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+extern volatile bool vblank_set;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INIT_PS1_H */
diff --git a/src/system/ps1/src/init.c b/src/system/ps1/src/init.c
new file mode 100644
index 0000000..a644e47
--- /dev/null
+++ b/src/system/ps1/src/init.c
@@ -0,0 +1,32 @@
+#include <gfx.h>
+#include <sfx.h>
+#include <system.h>
+#include <psx.h>
+#include <stdbool.h>
+
+volatile bool vblank_set;
+
+static void vblank(void *const arg)
+{
+ vblank_set = true;
+}
+
+void system_deinit(void)
+{
+ gfx_deinit();
+ sfx_deinit();
+}
+
+int system_init(void)
+{
+ SetVBlankHandler(vblank);
+
+ if (gfx_init() || sfx_init())
+ return -1;
+
+ return 0;
+}
+
+void system_loop(void)
+{
+}
diff --git a/src/system/sdl-1.2/inc/system/port.h b/src/system/sdl-1.2/inc/system/port.h
new file mode 100644
index 0000000..3838026
--- /dev/null
+++ b/src/system/sdl-1.2/inc/system/port.h
@@ -0,0 +1,13 @@
+#ifndef INIT_SDL_1_2_H
+#define INIT_SDL_1_2_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INIT_SDL_H */
diff --git a/src/system/sdl-1.2/src/system.c b/src/system/sdl-1.2/src/system.c
new file mode 100644
index 0000000..a738a75
--- /dev/null
+++ b/src/system/sdl-1.2/src/system.c
@@ -0,0 +1,36 @@
+#include <gfx.h>
+#include <sfx.h>
+#include <system.h>
+#include <SDL/SDL.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void system_loop(void)
+{
+ SDL_PumpEvents();
+}
+
+void system_deinit(void)
+{
+ gfx_deinit();
+ sfx_deinit();
+ SDL_Quit();
+}
+
+int system_init(void)
+{
+ if (SDL_Init(0))
+ {
+ fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
+ goto failure;
+ }
+ else if (gfx_init() || sfx_init())
+ goto failure;
+
+ SDL_WM_SetCaption("rts", NULL);
+ return 0;
+
+failure:
+ system_deinit();
+ return -1;
+}