From 90eee5838efbda962130bfdd6592b4f56c67c6f5 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Thu, 18 Nov 2021 11:53:47 +0100 Subject: [PATCH] feck IO functions --- .gitmodules | 2 +- CMakeLists.txt | 4 ++-- Makefile | 8 ++++++-- fe | 2 +- src/main.c | 31 +++++++++++++++++++++++-------- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/.gitmodules b/.gitmodules index ebd6936..67f360e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "fe"] path = fe - url = https://github.com/rxi/fe + url = https://gitea.planet-casio.com/KikooDX/fe [submodule "raygint"] path = raygint url = https://gitea.planet-casio.com/KikooDX/raygint diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e78e16..3b3f1fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # toolchain file and module path of the fxSDK cmake_minimum_required(VERSION 3.18) -project(CRYSTAL C) +project(FECK C) set(CMAKE_C_STANDARD 99) @@ -36,7 +36,7 @@ if ("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) generate_g3a(TARGET target OUTPUT "${PROJECT_NAME}.g3a" - NAME "" + NAME "${PROJECT_NAME}" ICONS res/icon-uns.png res/icon-sel.png ) else() diff --git a/Makefile b/Makefile index eaa8930..09cba48 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -all: format +all: format out/file.h fxsdk build-cg -ray: clean format +ray: clean format out/file.h mkdir -p build cmake -B build . make -C build @@ -9,6 +9,10 @@ ray: clean format run: ray build/target +out/file.h: + mkdir -p out + cembed -z test.fe > out/file.h + format: clang-format -style=file -i src/**.c inc/**.h || true diff --git a/fe b/fe index ed4cda9..0c0d607 160000 --- a/fe +++ b/fe @@ -1 +1 @@ -Subproject commit ed4cda96bd582cbb08520964ba627efb40f3dd91 +Subproject commit 0c0d60706cb78fa953cbe26db76b32d0b4ef46d2 diff --git a/src/main.c b/src/main.c index a2ab183..120184a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,12 +1,15 @@ #include "fe.h" +#include "file.h" #include "raygint/display.h" -#include #include +#define UNUSED(c) (void)(c) + static fe_Object *f_dblock(fe_Context *ctx, fe_Object *arg); static fe_Object *f_dcolor(fe_Context *ctx, fe_Object *arg); static fe_Object *f_dclear(fe_Context *ctx, fe_Object *arg); static fe_Object *f_drect(fe_Context *ctx, fe_Object *arg); +static char read_custom(fe_Context *ctx, void *udata); static int r = 0; static int g = 0; @@ -18,19 +21,20 @@ main(void) const int size = 0xffffff; void *data = malloc(size); fe_Context *ctx = fe_open(data, size); -#ifdef RAYLIB - FILE *fp = fopen("test.fe", "rb"); int gc = fe_savegc(ctx); - rDisplayInit(); - SetTargetFPS(30); fe_set(ctx, fe_symbol(ctx, "dblock"), fe_cfunc(ctx, f_dblock)); fe_set(ctx, fe_symbol(ctx, "dcolor"), fe_cfunc(ctx, f_dcolor)); fe_set(ctx, fe_symbol(ctx, "dclear"), fe_cfunc(ctx, f_dclear)); fe_set(ctx, fe_symbol(ctx, "drect"), fe_cfunc(ctx, f_drect)); + rDisplayInit(); +#ifdef RAYLIB + SetTargetFPS(30); +#endif + for (;;) { - fe_Object *obj = fe_readfp(ctx, fp); + fe_Object *obj = fe_read(ctx, read_custom, test_fe); /* break if there's nothing left to read */ if (!obj) @@ -45,8 +49,6 @@ main(void) } rDisplayDeinit(); - fclose(fp); -#endif fe_close(ctx); free(data); return 0; @@ -74,6 +76,8 @@ f_dcolor(fe_Context *ctx, fe_Object *arg) static fe_Object * f_dclear(fe_Context *ctx, fe_Object *arg) { + UNUSED(ctx); + UNUSED(arg); dclear(C_RGB(r, g, b)); return NULL; } @@ -88,3 +92,14 @@ f_drect(fe_Context *ctx, fe_Object *arg) drect(x, y, x + w - 1, y + h - 1, C_RGB(r, g, b)); return NULL; } + +static char +read_custom(fe_Context *ctx, void *udata) +{ + static int cursor = 0; + const char *data = (char *)udata; + UNUSED(ctx); + if (data[cursor]) + return data[cursor++]; + return data[cursor]; +}