Initial commit
This commit is contained in:
commit
3e75f74d6f
|
@ -0,0 +1 @@
|
|||
build/**
|
|
@ -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/*
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#include "twm.h"
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
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};
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
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;
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _TWM_H
|
||||
#define _TWM_H
|
||||
#include "module_display.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
ModuleDisplay load_display_module(char* name);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
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;
|
|
@ -0,0 +1 @@
|
|||
void t(){}
|
Loading…
Reference in New Issue