aboutsummaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-05-10 00:40:10 +1000
committerNicholas Tay <nick@windblume.net>2022-05-10 00:47:38 +1000
commit6a1e6a7d6b6a3d987f2fccb3c06f4f5da071f504 (patch)
tree3899a31897c01323fb5d896b08412aa45e939885 /board
parent5270088f730a7e30155a642dcd5c4e9a80055d7a (diff)
downloadclak-6a1e6a7d6b6a3d987f2fccb3c06f4f5da071f504.tar.gz
clak-6a1e6a7d6b6a3d987f2fccb3c06f4f5da071f504.tar.bz2
clak-6a1e6a7d6b6a3d987f2fccb3c06f4f5da071f504.zip
Dynamic load boards as DLL (windows only for now)
The .h files are pretty weird, should look at other C projects to see how they load plugins. This function pointer business with typedefs is kinda weird, not sure where they should live.
Diffstat (limited to '')
-rw-r--r--board/Makefile32
-rw-r--r--board/board.c8
-rw-r--r--board/board.h12
-rw-r--r--board/generate.sh8
-rw-r--r--board/mxblue/board.c12
-rw-r--r--board/mxblue/board.h3
-rw-r--r--board/quack/board.c12
-rw-r--r--board/quack/board.h3
-rw-r--r--board/simple.h9
-rw-r--r--boards.h6
10 files changed, 76 insertions, 29 deletions
diff --git a/board/Makefile b/board/Makefile
new file mode 100644
index 0000000..24cb10c
--- /dev/null
+++ b/board/Makefile
@@ -0,0 +1,32 @@
+BOARDS = mxblue quack
+
+CC = gcc
+CFLAGS += -std=c99 -Wall -Wextra -Wshadow -Werror -pedantic -shared
+
+ifeq ($(OS),Windows_NT)
+ OUTEXT = dll
+else
+ OUTEXT = so
+endif
+
+default: all
+all: $(BOARDS)
+
+# TODO: use "BOARDS" variable to generate this.
+# TODO: have some preset for 'simple' board type? also in the c file.
+mxblue: mxblue.$(OUTEXT)
+quack: quack.$(OUTEXT)
+mxblue.$(OUTEXT): mxblue/board.c mxblue/sound.h
+ $(CC) $(CFLAGS) mxblue/board.c -o mxblue.$(OUTEXT)
+quack.$(OUTEXT): quack/board.c quack/sound.h
+ $(CC) $(CFLAGS) quack/board.c -o quack.$(OUTEXT)
+mxblue/sound.h:
+ xxd -i mxblue/board_down.wav mxblue/sound.h
+quack/sound.h:
+ xxd -i quack/board_down.wav quack/sound.h
+
+clean:
+ rm -f *.o
+ rm -f *.dll
+ rm -f *.so
+ rm -f */sound.h \ No newline at end of file
diff --git a/board/board.c b/board/board.c
new file mode 100644
index 0000000..0410aef
--- /dev/null
+++ b/board/board.c
@@ -0,0 +1,8 @@
+#include "board.h"
+
+static fn_sound_play sound_play;
+
+void board_init(fn_sound_play sp)
+{
+ sound_play = sp;
+} \ No newline at end of file
diff --git a/board/board.h b/board/board.h
new file mode 100644
index 0000000..18f6afa
--- /dev/null
+++ b/board/board.h
@@ -0,0 +1,12 @@
+#ifndef CLAK_BOARD_H_
+#define CLAK_BOARD_H_
+
+#include <stdbool.h>
+
+#include "../clak.h"
+
+typedef void (*fn_board_init)(fn_sound_play sp);
+typedef void (*fn_board_on_down)(void);
+typedef void (*fn_board_on_up)(void);
+
+#endif /* CLAK_BOARD_H_ */ \ No newline at end of file
diff --git a/board/generate.sh b/board/generate.sh
deleted file mode 100644
index 6d8d593..0000000
--- a/board/generate.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-BOARDS='mxblue quack'
-
-cd "$(dirname "$0")"
-for board in $BOARDS; do
- xxd -i $board/board_down.wav $board/sound.h
-done \ No newline at end of file
diff --git a/board/mxblue/board.c b/board/mxblue/board.c
new file mode 100644
index 0000000..14277db
--- /dev/null
+++ b/board/mxblue/board.c
@@ -0,0 +1,12 @@
+#include "sound.h"
+
+#include "../board.c"
+
+void board_on_down(void)
+{
+ sound_play(mxblue_board_down_wav);
+}
+
+void board_on_up(void)
+{
+} \ No newline at end of file
diff --git a/board/mxblue/board.h b/board/mxblue/board.h
deleted file mode 100644
index 7d17f3f..0000000
--- a/board/mxblue/board.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "./sound.h"
-#include "../simple.h"
-SIMPLE_BOARD(mxblue) \ No newline at end of file
diff --git a/board/quack/board.c b/board/quack/board.c
new file mode 100644
index 0000000..893e366
--- /dev/null
+++ b/board/quack/board.c
@@ -0,0 +1,12 @@
+#include "sound.h"
+
+#include "../board.c"
+
+void board_on_down(void)
+{
+ sound_play(quack_board_down_wav);
+}
+
+void board_on_up(void)
+{
+} \ No newline at end of file
diff --git a/board/quack/board.h b/board/quack/board.h
deleted file mode 100644
index 64ba4cb..0000000
--- a/board/quack/board.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "./sound.h"
-#include "../simple.h"
-SIMPLE_BOARD(quack) \ No newline at end of file
diff --git a/board/simple.h b/board/simple.h
deleted file mode 100644
index c2b211b..0000000
--- a/board/simple.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef CLAK_SIMPLE_H_
-#define CLAK_SIMPLE_H_
-
-extern void sound_play(unsigned char *buffer);
-#define SIMPLE_BOARD(name) \
- void name ## _on_down(void) { sound_play( name ## _board_down_wav ); } \
- void name ## _on_up(void) { sound_play( name ## _board_down_wav ); }
-
-#endif /* CLAK_SIMPLE_H_ */ \ No newline at end of file
diff --git a/boards.h b/boards.h
deleted file mode 100644
index 9090570..0000000
--- a/boards.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "board/mxblue/board.h"
-#include "board/quack/board.h"
-
-#define BOARDS \
- BOARD(mxblue) \
- BOARD(quack)