aboutsummaryrefslogtreecommitdiff
path: root/src/gfx
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-01-29 23:58:04 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-01-30 01:16:18 +0100
commita27a35bd778d9afe9f04e7aed69d950bc4d980e8 (patch)
treecad17cb68da4a210538c15a7fba2289374c4fcc1 /src/gfx
parentc2e2343054e8d11ebaaf426d6ca105e79e93da6a (diff)
downloadjancity-a27a35bd778d9afe9f04e7aed69d950bc4d980e8.tar.gz
WIP ESP32 port
Diffstat (limited to 'src/gfx')
-rw-r--r--src/gfx/CMakeLists.txt9
-rw-r--r--src/gfx/esp32/inc/gfx/port.h55
-rw-r--r--src/gfx/esp32/privinc/esp32/gfx_private.h21
-rw-r--r--src/gfx/esp32/src/env.c61
-rw-r--r--src/gfx/esp32/src/line.c17
-rw-r--r--src/gfx/esp32/src/quad.c15
-rw-r--r--src/gfx/esp32/src/rect.c19
-rw-r--r--src/gfx/esp32/src/sprite.c23
8 files changed, 220 insertions, 0 deletions
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;
+}