diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-01-29 23:58:04 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-01-30 01:16:18 +0100 |
| commit | a27a35bd778d9afe9f04e7aed69d950bc4d980e8 (patch) | |
| tree | cad17cb68da4a210538c15a7fba2289374c4fcc1 /src | |
| parent | c2e2343054e8d11ebaaf426d6ca105e79e93da6a (diff) | |
| download | jancity-a27a35bd778d9afe9f04e7aed69d950bc4d980e8.tar.gz | |
WIP ESP32 port
Diffstat (limited to 'src')
36 files changed, 512 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8325820..a2fa2e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ # Avoid C11 since it is not supported by the i386-mingw32 toolchain. -set(cflags ${cflags} -Wall -g3 -ffunction-sections -fdata-sections -pedantic) +set(cflags ${cflags} -Wall -g3 -ffunction-sections -fdata-sections) set(components building @@ -13,6 +13,7 @@ set(components input instance keyboard + main menu mouse net @@ -34,13 +35,18 @@ set(interfaces target_compile_options(${PROJECT_NAME} PUBLIC ${cflags}) # Dependencies for main.c -target_link_libraries(${PROJECT_NAME} PRIVATE system menu) +target_link_libraries(${PROJECT_NAME} PRIVATE main system menu) foreach(c ${components}) add_subdirectory("${c}") target_compile_options(${c} PUBLIC ${cflags}) - target_compile_features(${c} PUBLIC c_std_99) - set_target_properties(${c} PROPERTIES C_STANDARD 99 C_EXTENSIONS OFF) + + if(${c} STREQUAL "net" AND NOT ESP32_BUILD) + # ESP32 builds pull non-portable header files (e.g.: xt_utils.h). + set_target_properties(${c} PROPERTIES C_STANDARD 99 C_EXTENSIONS OFF) + target_compile_options(${c} PUBLIC -pedantic) + target_compile_features(${c} PUBLIC c_std_99) + endif() endforeach() foreach(i ${interfaces}) diff --git a/src/container/CMakeLists.txt b/src/container/CMakeLists.txt index 740fe37..981d7c9 100644 --- a/src/container/CMakeLists.txt +++ b/src/container/CMakeLists.txt @@ -4,6 +4,8 @@ if(PS1_BUILD) set(inc ${inc} "ps1/inc") elseif(SDL1_2_BUILD) set(inc ${inc} "sdl-1.2/inc") +elseif(ESP32_BUILD) + set(inc ${inc} "esp32/inc") endif() add_library(container "src/container.c") diff --git a/src/container/esp32/inc/container/port.h b/src/container/esp32/inc/container/port.h new file mode 100644 index 0000000..f3d9ffb --- /dev/null +++ b/src/container/esp32/inc/container/port.h @@ -0,0 +1,6 @@ +#ifndef CONTAINER_ESP32_H +#define CONTAINER_ESP32_H + +#define container_load(path, list, n) container_load_ex(path, list, n) + +#endif /* CONTAINER_ESP32_H */ diff --git a/src/gfx/CMakeLists.txt b/src/gfx/CMakeLists.txt index 86f99c2..bdeb63a 100644 --- a/src/gfx/CMakeLists.txt +++ b/src/gfx/CMakeLists.txt @@ -26,6 +26,15 @@ elseif(SDL1_2_BUILD) "sdl-1.2/src/quad.c") set(deps ${deps} SDL::SDL) set(privdeps ${privdeps} header SDL::SDL_gfx) +elseif(ESP32_BUILD) + set(inc ${inc} "esp32/inc") + set(privinc ${privinc} "esp32/privinc") + set(src ${src} + "esp32/src/env.c" + "esp32/src/line.c" + "esp32/src/rect.c" + "esp32/src/sprite.c" + "esp32/src/quad.c") endif() add_library(gfx ${src}) diff --git a/src/gfx/esp32/inc/gfx/port.h b/src/gfx/esp32/inc/gfx/port.h new file mode 100644 index 0000000..36a294f --- /dev/null +++ b/src/gfx/esp32/inc/gfx/port.h @@ -0,0 +1,55 @@ +#ifndef GFX_ESP32_H +#define GFX_ESP32_H + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct sprite +{ + short x, y, w, h; + unsigned char u, v; + bool transparent; +}; + +struct quad +{ + unsigned char r, g, b; + short x0, x1, x2, x3; + short y0, y1, y2, y3; + unsigned char u0, u1, u2, u3; + unsigned char v0, v1, v2, v3; + short w, h; + bool transparent; +}; + +struct rect +{ + unsigned char r, g, b; + short x, y, w, h; + bool stp; +}; + +struct stp_4line +{ + short x, y; + unsigned char r, g, b; + + struct stp_4line_vtx + { + unsigned char r, g, b; + short x, y; + } vertices[4]; +}; + +#define common_get_or_ret(t, x, ret) \ + struct t x##__, *const x = &x##__ + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_ESP32_H */ diff --git a/src/gfx/esp32/privinc/esp32/gfx_private.h b/src/gfx/esp32/privinc/esp32/gfx_private.h new file mode 100644 index 0000000..0eeae11 --- /dev/null +++ b/src/gfx/esp32/privinc/esp32/gfx_private.h @@ -0,0 +1,21 @@ +#ifndef GFX_ESP32_PRIVATE_H +#define GFX_ESP32_PRIVATE_H + +#include <gfx.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +enum +{ + SCREEN_W = 320, + SCREEN_H = 240 +}; + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_ESP32_PRIVATE_H */ diff --git a/src/gfx/esp32/src/env.c b/src/gfx/esp32/src/env.c new file mode 100644 index 0000000..1d6d080 --- /dev/null +++ b/src/gfx/esp32/src/env.c @@ -0,0 +1,61 @@ +#include <gfx.h> +#include <gfx_private.h> +#include <esp32/gfx_private.h> +#include <errno.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int screen_w = SCREEN_W, screen_h = SCREEN_H; + +void gfx_deinit(void) +{ +} + +int gfx_display_size(short *const w, short *const h) +{ + *w = SCREEN_W; + *h = SCREEN_H; + return 0; +} + +int gfx_init(void) +{ + return -1; +} + +bool gfx_inside_drawenv(const short x, const short y, const short w, + const short h) +{ + return (x + w >= 0) + && x < screen_w + && (y + h >= 0) + && y < screen_h; +} + +int gfx_toggle_fullscreen(void) +{ + return -1; +} + +int gfx_set_fullscreen(const short w, const short h) +{ + return -1; +} + +bool gfx_fullscreen_available(void) +{ + return false; +} + +bool gfx_fullscreen(void) +{ + return true; +} + +int gfx_draw(void) +{ + return -1; +} diff --git a/src/gfx/esp32/src/line.c b/src/gfx/esp32/src/line.c new file mode 100644 index 0000000..67bfcea --- /dev/null +++ b/src/gfx/esp32/src/line.c @@ -0,0 +1,17 @@ +#include <gfx.h> +#include <gfx/port.h> +#include <esp32/gfx_private.h> +#include <stddef.h> + +void stp_4line_init(struct stp_4line *const l) +{ +} + +void semitrans_stp_4line_init(struct stp_4line *r) +{ +} + +int stp_4line_sort(struct stp_4line *const r) +{ + return 0; +} diff --git a/src/gfx/esp32/src/quad.c b/src/gfx/esp32/src/quad.c new file mode 100644 index 0000000..05eb5e9 --- /dev/null +++ b/src/gfx/esp32/src/quad.c @@ -0,0 +1,15 @@ +#include <gfx.h> +#include <gfx/port.h> +#include <esp32/gfx_private.h> +#include <stddef.h> +#include <stdlib.h> + +int quad_from_sprite(const struct sprite *const s, struct quad *const q) +{ + return -1; +} + +int quad_sort(struct quad *const q) +{ + return -1; +} diff --git a/src/gfx/esp32/src/rect.c b/src/gfx/esp32/src/rect.c new file mode 100644 index 0000000..2fa9b85 --- /dev/null +++ b/src/gfx/esp32/src/rect.c @@ -0,0 +1,19 @@ +#include <gfx.h> +#include <gfx/port.h> +#include <esp32/gfx_private.h> + +int rect_sort(struct rect *const r) +{ + return -1; +} + +void rect_init(struct rect *const r) +{ + *r = (const struct rect){0}; +} + +void semitrans_rect_init(struct rect *const r) +{ + rect_init(r); + r->stp = true; +} diff --git a/src/gfx/esp32/src/sprite.c b/src/gfx/esp32/src/sprite.c new file mode 100644 index 0000000..dcddad0 --- /dev/null +++ b/src/gfx/esp32/src/sprite.c @@ -0,0 +1,23 @@ +#include <gfx.h> +#include <gfx/port.h> +#include <esp32/gfx_private.h> + +void sprite_free(struct sprite *const s) +{ +} + +int sprite_clone(const struct sprite *const src, struct sprite *const dst) +{ + *dst = *src; + return 0; +} + +int sprite_from_fp(struct sprite *const s, FILE *const f) +{ + return -1; +} + +int sprite_sort(struct sprite *const s) +{ + return -1; +} diff --git a/src/keyboard/CMakeLists.txt b/src/keyboard/CMakeLists.txt index 2cdf85c..cc1561f 100644 --- a/src/keyboard/CMakeLists.txt +++ b/src/keyboard/CMakeLists.txt @@ -9,6 +9,9 @@ elseif(SDL1_2_BUILD) set(src ${src} "sdl-1.2/src/keyboard.c") set(inc ${inc} "sdl-1.2/inc") set(privdeps ${privdeps} SDL::SDL) +elseif(ESP32_BUILD) + set(src ${src} "esp32/src/keyboard.c") + set(inc ${inc} "esp32/inc") endif() add_library(keyboard ${src}) diff --git a/src/keyboard/esp32/inc/keyboard/port.h b/src/keyboard/esp32/inc/keyboard/port.h new file mode 100644 index 0000000..9b228ac --- /dev/null +++ b/src/keyboard/esp32/inc/keyboard/port.h @@ -0,0 +1,20 @@ +#ifndef KEYBOARD_SDL_1_2_H +#define KEYBOARD_SDL_1_2_H + +#include <keyboard.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct keyboard_port +{ + int dummy; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* KEYBOARD_SDL_1_2_H */ diff --git a/src/keyboard/esp32/src/keyboard.c b/src/keyboard/esp32/src/keyboard.c new file mode 100644 index 0000000..64298bd --- /dev/null +++ b/src/keyboard/esp32/src/keyboard.c @@ -0,0 +1,12 @@ +#include <keyboard.h> +#include <keyboard/port.h> +#include <keyboard/key.h> + +void keyboard_update(struct keyboard *const k) +{ +} + +bool keyboard_available(void) +{ + return false; +} diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt new file mode 100644 index 0000000..a9a02a7 --- /dev/null +++ b/src/main/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(main "src/main.c") +target_include_directories(main PUBLIC "inc") +target_link_libraries(main PRIVATE menu system) + +if(ESP32_BUILD) + target_sources(${PROJECT_NAME} PRIVATE "esp32/src/main.c") +else() + target_sources(${PROJECT_NAME} PRIVATE "std/src/main.c") +endif() diff --git a/src/main/esp32/src/main.c b/src/main/esp32/src/main.c new file mode 100644 index 0000000..77ca051 --- /dev/null +++ b/src/main/esp32/src/main.c @@ -0,0 +1,6 @@ +#include <engine_main.h> + +void app_main(void) +{ + engine_main(); +} diff --git a/src/main/inc/engine_main.h b/src/main/inc/engine_main.h new file mode 100644 index 0000000..9cb7fb3 --- /dev/null +++ b/src/main/inc/engine_main.h @@ -0,0 +1,15 @@ +#ifndef MAIN_PRIVATE_H +#define MAIN_PRIVATE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +int engine_main(void); + +#ifdef __cplusplus +} +#endif + +#endif /* MAIN_PRIVATE_H */ diff --git a/src/main/src/main.c b/src/main/src/main.c new file mode 100644 index 0000000..246cb7b --- /dev/null +++ b/src/main/src/main.c @@ -0,0 +1,15 @@ +#include <engine_main.h> +#include <menu.h> +#include <system.h> +#include <stdlib.h> + +int engine_main(void) +{ + int ret = 0; + + if (system_init() || menu()) + ret = -1; + + system_deinit(); + return ret; +} diff --git a/src/main.c b/src/main/std/src/main.c index 8933639..8933639 100644 --- a/src/main.c +++ b/src/main/std/src/main.c diff --git a/src/mouse/CMakeLists.txt b/src/mouse/CMakeLists.txt index 57525ec..6e00c64 100644 --- a/src/mouse/CMakeLists.txt +++ b/src/mouse/CMakeLists.txt @@ -7,6 +7,8 @@ if(PS1_BUILD) elseif(SDL1_2_BUILD) set(src ${src} "sdl-1.2/src/mouse.c") set(privdeps ${privdeps} SDL::SDL) +elseif(ESP32_BUILD) + set(src ${src} "esp32/src/mouse.c") endif() add_library(mouse ${src}) diff --git a/src/mouse/esp32/src/mouse.c b/src/mouse/esp32/src/mouse.c new file mode 100644 index 0000000..865d4c1 --- /dev/null +++ b/src/mouse/esp32/src/mouse.c @@ -0,0 +1,11 @@ +#include <mouse.h> +#include <stdbool.h> + +void mouse_update(struct mouse *const m) +{ +} + +bool mouse_available(void) +{ + return false; +} diff --git a/src/net/CMakeLists.txt b/src/net/CMakeLists.txt index 03329c9..83369c9 100644 --- a/src/net/CMakeLists.txt +++ b/src/net/CMakeLists.txt @@ -14,6 +14,9 @@ else() if(WIN9X_BUILD OR ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") set(src ${src} "win9x/src/serial.c") + elseif(ESP32_BUILD) + include($ENV{IDF_PATH}/tools/cmake/idf.cmake) + set(priv_deps ${priv_deps} idf::lwip idf::esp_phy) else() # Assume POSIX if the command below executes successfully execute_process(COMMAND uname -m RESULT_VARIABLE result OUTPUT_QUIET) diff --git a/src/pad/CMakeLists.txt b/src/pad/CMakeLists.txt index 6470865..c85499a 100644 --- a/src/pad/CMakeLists.txt +++ b/src/pad/CMakeLists.txt @@ -10,6 +10,9 @@ elseif(SDL1_2_BUILD) set(src ${src} "sdl-1.2/src/pad.c") set(inc ${inc} "sdl-1.2/inc") set(deps ${deps} SDL::SDL) +elseif(ESP32_BUILD) + set(src ${src} "esp32/src/pad.c") + set(inc ${inc} "esp32/inc") endif() add_library(pad ${src}) diff --git a/src/pad/esp32/inc/pad/port.h b/src/pad/esp32/inc/pad/port.h new file mode 100644 index 0000000..3f42422 --- /dev/null +++ b/src/pad/esp32/inc/pad/port.h @@ -0,0 +1,18 @@ +#ifndef PAD_ESP32_H +#define PAD_ESP32_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct pad_port +{ + int dummy; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* PAD_SDL_1_2_H */ diff --git a/src/pad/esp32/src/pad.c b/src/pad/esp32/src/pad.c new file mode 100644 index 0000000..78dd24d --- /dev/null +++ b/src/pad/esp32/src/pad.c @@ -0,0 +1,20 @@ +#include <pad.h> +#include <stdio.h> + +void pad_port_update(struct pad *const p) +{ +} + +void pad_init(const int id, struct pad *const p) +{ +} + +size_t pad_count(void) +{ + return 1; +} + +const char *pad_name(const int id) +{ + return NULL; +} diff --git a/src/settings/CMakeLists.txt b/src/settings/CMakeLists.txt index f7442e4..c94f02e 100644 --- a/src/settings/CMakeLists.txt +++ b/src/settings/CMakeLists.txt @@ -7,6 +7,8 @@ if(PS1_BUILD) set(inc ${inc} "ps1/inc") elseif(SDL1_2_BUILD) set(inc ${inc} "sdl-1.2/inc") +elseif(ESP32_BUILD) + set(inc ${inc} "esp32/inc") endif() target_include_directories(settings PUBLIC ${inc}) diff --git a/src/settings/esp32/inc/settings/port.h b/src/settings/esp32/inc/settings/port.h new file mode 100644 index 0000000..6332842 --- /dev/null +++ b/src/settings/esp32/inc/settings/port.h @@ -0,0 +1,15 @@ +#ifndef SETTINGS_PORT_H +#define SETTINGS_PORT_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define settings_load(...) settings_load_ex(__VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif /* SETTINGS_PORT_H */ diff --git a/src/sfx/CMakeLists.txt b/src/sfx/CMakeLists.txt index f36931d..4e5d658 100644 --- a/src/sfx/CMakeLists.txt +++ b/src/sfx/CMakeLists.txt @@ -11,6 +11,10 @@ elseif(SDL1_2_BUILD) set(inc ${inc} "sdl-1.2/inc") set(deps ${deps} SDL::SDL_mixer) set(privdeps ${privdeps} SDL::SDL header) +elseif(ESP32_BUILD) + set(src + "esp32/src/sound.c") + set(inc ${inc} "esp32/inc") endif() add_library(sfx ${src}) diff --git a/src/sfx/esp32/inc/sfx/port.h b/src/sfx/esp32/inc/sfx/port.h new file mode 100644 index 0000000..fb8d482 --- /dev/null +++ b/src/sfx/esp32/inc/sfx/port.h @@ -0,0 +1,20 @@ +#ifndef SFX_ESP32_H +#define SFX_ESP32_H + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct sound +{ + bool loop; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* SFX_SDL1_2_H */ diff --git a/src/sfx/esp32/src/sound.c b/src/sfx/esp32/src/sound.c new file mode 100644 index 0000000..a6a757f --- /dev/null +++ b/src/sfx/esp32/src/sound.c @@ -0,0 +1,28 @@ +#include <sfx.h> +#include <sfx/port.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdio.h> + +void sfx_free(struct sound *const s) +{ +} + +int sfx_play(const struct sound *const s) +{ + return -1; +} + +int sfx_sound_from_fp(struct sound *const s, FILE *const f, const size_t sz) +{ + return -1; +} + +void sfx_deinit(void) +{ +} + +int sfx_init(void) +{ + return -1; +} diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index 26a8803..7ddd98c 100644 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -17,6 +17,10 @@ elseif(SDL1_2_BUILD) else() set(src ${src} "sdl-1.2/src/stubs.c") endif() +elseif(ESP32_BUILD) + set(src "esp32/src/system.c") + set(inc ${inc} "esp32/inc") + set(privinc ${privinc} "esp32/privinc") endif() add_library(system ${src}) diff --git a/src/system/esp32/inc/system/port.h b/src/system/esp32/inc/system/port.h new file mode 100644 index 0000000..6566c31 --- /dev/null +++ b/src/system/esp32/inc/system/port.h @@ -0,0 +1,13 @@ +#ifndef INIT_ESP32_H +#define INIT_ESP32_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_SDL_H */ diff --git a/src/system/esp32/privinc/system_private.h b/src/system/esp32/privinc/system_private.h new file mode 100644 index 0000000..70ed8c8 --- /dev/null +++ b/src/system/esp32/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/esp32/src/stubs.c b/src/system/esp32/src/stubs.c new file mode 100644 index 0000000..c07a790 --- /dev/null +++ b/src/system/esp32/src/stubs.c @@ -0,0 +1,6 @@ +#include <system_private.h> + +int system_init_os(void) +{ + return 0; +} diff --git a/src/system/esp32/src/system.c b/src/system/esp32/src/system.c new file mode 100644 index 0000000..6221e2e --- /dev/null +++ b/src/system/esp32/src/system.c @@ -0,0 +1,25 @@ +#include <system.h> +#include <system_private.h> +#include <gfx.h> +#include <net.h> +#include <sfx.h> +#include <stdio.h> +#include <stdlib.h> + +bool system_can_exit(void) +{ + return false; +} + +void system_loop(void) +{ +} + +void system_deinit(void) +{ +} + +int system_init(void) +{ + return -1; +} diff --git a/src/transport/CMakeLists.txt b/src/transport/CMakeLists.txt index b903a81..f0b0e11 100644 --- a/src/transport/CMakeLists.txt +++ b/src/transport/CMakeLists.txt @@ -8,5 +8,8 @@ endif() add_library(transport ${src}) target_include_directories(transport PUBLIC "inc" PRIVATE "privinc") -enable_testing() -add_subdirectory(test) + +if(NOT CMAKE_CROSSCOMPILING) + enable_testing() + add_subdirectory(test) +endif() |
