From 6a1e6a7d6b6a3d987f2fccb3c06f4f5da071f504 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Tue, 10 May 2022 00:40:10 +1000 Subject: 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. --- board/Makefile | 32 ++++++++++++++++++++++++++++++++ board/board.c | 8 ++++++++ board/board.h | 12 ++++++++++++ board/generate.sh | 8 -------- board/mxblue/board.c | 12 ++++++++++++ board/mxblue/board.h | 3 --- board/quack/board.c | 12 ++++++++++++ board/quack/board.h | 3 --- board/simple.h | 9 --------- 9 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 board/Makefile create mode 100644 board/board.c create mode 100644 board/board.h delete mode 100644 board/generate.sh create mode 100644 board/mxblue/board.c delete mode 100644 board/mxblue/board.h create mode 100644 board/quack/board.c delete mode 100644 board/quack/board.h delete mode 100644 board/simple.h (limited to 'board') 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 + +#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 -- cgit