#include #include #include #include #include #include "platform/platform.h" #include "board/board.h" #define VOLUME 0.15 struct board_state state = {0}; void do_exit(int code) { keyboard_unhook(); fprintf(stderr, "Goodbye.\n"); exit(code); } void on_clean_exit(void) { do_exit(0); } void keyboard_on_down(void) { assert(state.on_down != NULL); state.on_down(&state); } void keyboard_on_up(void) { assert(state.on_up != NULL); state.on_up(&state); } int main(int argc, char **argv) { 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; } /* Initialise board state */ state.sound_play = &sound_play; /* Inject platform-specific impl */ fprintf(stderr, "Loading board...\n"); if (!load_board(&state, argv[1])) { printf("Failed to load board, exiting.\n"); return 1; } state.board_init(&state); fprintf(stderr, "Loaded board: %s\n", state.name); fprintf(stderr, "Initialisating sound system...\n"); if (!sound_init(VOLUME)) { printf("ERROR: Could not initialise sound system.\n"); return 1; } if (!keyboard_hook()) { printf("ERROR: Could not set up keyboard hooks.\n"); return 1; } atexit(on_clean_exit); fprintf(stderr, "Hooks set up, enjoy your stay!\n"); enter_idle(); return 0; }