aboutsummaryrefslogtreecommitdiff
path: root/clak.c
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 /clak.c
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 'clak.c')
-rw-r--r--clak.c58
1 files changed, 18 insertions, 40 deletions
diff --git a/clak.c b/clak.c
index 7a19f4a..145709f 100644
--- a/clak.c
+++ b/clak.c
@@ -1,37 +1,13 @@
#include <stdio.h>
#include <unistd.h>
#include <string.h>
-#include <stdbool.h>
#include <stdlib.h>
-#define VOLUME 0.15
-
-#define BOARD(x) { .name = #x, .on_down = x ## _on_down, .on_up = x ## _on_up },
-#include "boards.h"
-
+#include "clak.h"
#include "platform/platform.h"
+#include "board/board.h"
-typedef struct {
- char *name;
- void (*on_down)(void);
- void (*on_up)(void);
-} Board;
-
-Board boards[] = {
- BOARDS
-};
-int const boards_n = sizeof(boards) / sizeof(boards[0]);
-
-Board *board = NULL;
-
-Board *get_board(char *board_name)
-{
- for (int i = 0; i < boards_n; ++i) {
- if (strcmp(boards[i].name, board_name) == 0)
- return &boards[i];
- }
- return NULL;
-}
+#define VOLUME 0.15
void do_exit(int code)
{
@@ -41,30 +17,32 @@ void do_exit(int code)
}
void on_clean_exit(void) { do_exit(0); }
+fn_board_on_down board_on_down;
+fn_board_on_up board_on_up;
+
void keyboard_on_down(void)
{
- if (board == NULL)
- return;
- board->on_down();
+ board_on_down();
}
void keyboard_on_up(void)
{
- if (board == NULL)
- return;
- board->on_up();
+ board_on_up();
}
int main(int argc, char **argv)
{
- if (argc < 2 || (board = get_board(argv[1])) == NULL) {
- printf("Please provide a valid board name.\n");
- printf("Valid boards: ");
- for (int i = 0; i < boards_n; ++i) {
- printf("%s%s", boards[i].name, (i == boards_n - 1) ? "\n" : ", ");
- }
+ fprintf(stderr, "Clak: This is Clak, Nicholas Tay, version: 0.1.0.\n");
+
+ if (argc < 2) {
+ printf("ERROR: Please provide a board name.\n");
+ // TODO: List valid boards.
+ return 1;
+ }
+ if (!load_board(argv[1], &board_on_down, &board_on_up)) {
return 1;
}
+ fprintf(stderr, "Loaded board: %s\n", argv[1]);
if (!sound_init(VOLUME)) {
printf("ERROR: Could not initialise sound system.\n");
@@ -75,7 +53,7 @@ int main(int argc, char **argv)
return 1;
}
atexit(on_clean_exit);
- fprintf(stderr, "Hooks set up, welcome to Clak!\n");
+ fprintf(stderr, "Hooks set up, enjoy your stay!\n");
enter_idle();