commit 3e75f74d6ff82d1e4a2d9d905fa9656c1543c017 Author: pcmpstri Date: Fri Aug 22 14:19:18 2025 +1000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f65519e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/** diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..f0fcbad --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +CC = gcc +CFLAGS = -Wall -Wshadow -Werror +LDFLAGS = -lc + +SRCS := $(wildcard src/modules/*.c) +OBJS := $(patsubst src/modules/%.c,%,$(SRCS)) + +%: + mkdir -p build/modules + $(CC) $(CFLAGS) src/modules/$@.c -o build/modules/$@.so -shared -fPIC -rdynamic + +all: $(OBJS) + gcc -std=c23 -g -o build/twm src/core/*.c $(CFLAGS) $(LDFLAGS) -ldl + +clean: + rm -rf build/* diff --git a/src/core/main.c b/src/core/main.c new file mode 100644 index 0000000..1d27d5f --- /dev/null +++ b/src/core/main.c @@ -0,0 +1,7 @@ +#include "twm.h" + +int main(int argc, char* argv[]) { + ModuleDisplay m = load_display_module("modules/fb.so"); + if (m.init == 0) abort(); + return 0; +} diff --git a/src/core/module.c b/src/core/module.c new file mode 100644 index 0000000..00e38f3 --- /dev/null +++ b/src/core/module.c @@ -0,0 +1,34 @@ +#include "twm.h" +#include +#include + +ModuleDisplay load_display_module(char* name) { + void* dl = dlopen(name, RTLD_LAZY); + if (dl == NULL) { + fflush(stdout); + fprintf(stderr, "Failed to load module %s (%s)\n", name, dlerror()); + fflush(stderr); + return (ModuleDisplay){0}; + } + + ModuleDisplay m = {0}; + m.dll = dl; + m.init = (DisplayInit)dlsym(dl, "display_init"); + if (m.init == NULL) goto error; + m.blit = (DisplayBlit)dlsym(dl, "display_blit"); + if (m.blit == NULL) goto error; + m.flip = (DisplayFlip)dlsym(dl, "display_flip"); + if (m.flip == NULL) goto error; + m.close = (DisplayClose)dlsym(dl, "display_close"); + if (m.close == NULL) goto error; + m.put_pixel = (DisplayPutPixel)dlsym(dl, "display_put_pixel"); + if (m.put_pixel == NULL) goto error; + return m; + +error: + fflush(stdout); + fprintf(stderr, "Failed to load module %s (%s)\n", name, dlerror()); + fflush(stderr); + dlclose(dl); + return (ModuleDisplay){0}; +} diff --git a/src/core/module_display.h b/src/core/module_display.h new file mode 100644 index 0000000..4ef1019 --- /dev/null +++ b/src/core/module_display.h @@ -0,0 +1,38 @@ +#include +#include + +typedef struct { + uint8_t red; + uint8_t green; + uint8_t blue; +} Color; + +typedef struct { + int x; + int y; +} Vec2; + +typedef struct { + Vec2 pos; + Vec2 size; +} Rect; + +typedef struct { + Rect size; + Color *data; +} Image; + +typedef bool (*DisplayInit)(void**); +typedef void (*DisplayPutPixel)(void*, Vec2, Color); +typedef void (*DisplayBlit)(void*, Vec2, Image); +typedef void (*DisplayFlip)(void*); +typedef void (*DisplayClose)(void*); + +typedef struct { + void* dll; + DisplayInit init; + DisplayPutPixel put_pixel; + DisplayBlit blit; + DisplayFlip flip; + DisplayClose close; +} ModuleDisplay; diff --git a/src/core/twm.h b/src/core/twm.h new file mode 100644 index 0000000..0cc9567 --- /dev/null +++ b/src/core/twm.h @@ -0,0 +1,8 @@ +#ifndef _TWM_H +#define _TWM_H +#include "module_display.h" +#include + +ModuleDisplay load_display_module(char* name); + +#endif diff --git a/src/module_display.h b/src/module_display.h new file mode 100644 index 0000000..4ef1019 --- /dev/null +++ b/src/module_display.h @@ -0,0 +1,38 @@ +#include +#include + +typedef struct { + uint8_t red; + uint8_t green; + uint8_t blue; +} Color; + +typedef struct { + int x; + int y; +} Vec2; + +typedef struct { + Vec2 pos; + Vec2 size; +} Rect; + +typedef struct { + Rect size; + Color *data; +} Image; + +typedef bool (*DisplayInit)(void**); +typedef void (*DisplayPutPixel)(void*, Vec2, Color); +typedef void (*DisplayBlit)(void*, Vec2, Image); +typedef void (*DisplayFlip)(void*); +typedef void (*DisplayClose)(void*); + +typedef struct { + void* dll; + DisplayInit init; + DisplayPutPixel put_pixel; + DisplayBlit blit; + DisplayFlip flip; + DisplayClose close; +} ModuleDisplay; diff --git a/src/modules/fb.c b/src/modules/fb.c new file mode 100644 index 0000000..466f72f --- /dev/null +++ b/src/modules/fb.c @@ -0,0 +1 @@ +void t(){} diff --git a/src/twm.h b/src/twm.h new file mode 100644 index 0000000..0cc9567 --- /dev/null +++ b/src/twm.h @@ -0,0 +1,8 @@ +#ifndef _TWM_H +#define _TWM_H +#include "module_display.h" +#include + +ModuleDisplay load_display_module(char* name); + +#endif