From 6b9f686913efc3725b2690033cd4f398e07076ba Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 3 Jul 2021 00:49:03 +0200 Subject: Add project source code --- src/system/CMakeLists.txt | 13 +++++++++++++ src/system/inc/system.h | 17 +++++++++++++++++ src/system/ps1/inc/system/port.h | 17 +++++++++++++++++ src/system/ps1/src/init.c | 32 ++++++++++++++++++++++++++++++++ src/system/sdl-1.2/inc/system/port.h | 13 +++++++++++++ src/system/sdl-1.2/src/system.c | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 src/system/CMakeLists.txt create mode 100644 src/system/inc/system.h create mode 100644 src/system/ps1/inc/system/port.h create mode 100644 src/system/ps1/src/init.c create mode 100644 src/system/sdl-1.2/inc/system/port.h create mode 100644 src/system/sdl-1.2/src/system.c (limited to 'src/system') 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 + +#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 +#include +#include +#include +#include + +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 +#include +#include +#include +#include +#include + +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; +} -- cgit v1.2.3