123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /*
- * Plugins manager - The peTI-NESulator Project
- * plugins.c
- *
- * Created by Manoel TRAPIER on 02/04/07.
- * Copyright (c) 2003-2018 986-Studio. All rights reserved.
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <os_dependent.h>
- #include <plugins/manager.h>
- typedef struct Plugin_
- {
- char *name;
-
- PluginInit init;
- PluginDeinit deinit;
- } Plugin;
- typedef struct KeyHandler_
- {
- byte key;
-
- PluginKeypress func;
-
- struct KeyHandler_ *next;
-
- } KeyHandler;
- KeyHandler *keyHandlersList = NULL;
- #include "plugins_list.h"
- void plugin_list()
- {
- Plugin *ptr = &(Plugins[0]);
- int i = 1;
- console_printf(Console_Default, "Available plugins:\n");
- while(ptr->name != NULL)
- {
- console_printf(Console_Default, "%d - %s\n", i, ptr->name);
- ptr++; i++;
- }
- }
- int plugin_load(int id)
- {
- Plugin *ptr = &(Plugins[0]);
- int i = id;
-
- console_printf(Console_Default, "%s(%d)", __func__, id);
-
- for ( ; i > 1 && ptr->name != NULL; i -- )
- {
- console_printf(Console_Default, "%d - %s\n", i, ptr->name);
- ptr ++;
- }
- if (ptr == NULL)
- return -1;
- return ptr->init();
- }
- int plugin_unload(int id)
- {
- Plugin *ptr = &(Plugins[0]);
-
- for ( ; id == 0 && ptr != NULL; id -- )
- ptr ++;
- if (ptr == NULL)
- return -1;
- return ptr->deinit();
- }
- /* Available functions for plugins */
- int plugin_install_keypressHandler(byte key, PluginKeypress func)
- {
- KeyHandler *ptr;
-
- if (keyHandlersList == NULL)
- {
- keyHandlersList = (KeyHandler*) malloc(sizeof(KeyHandler));
-
- keyHandlersList->key = key;
- keyHandlersList->func = func;
- keyHandlersList->next = NULL;
- }
- else
- {
- ptr = keyHandlersList;
-
- while(ptr->next != NULL)
- ptr = ptr->next;
-
- ptr->next = (KeyHandler*) malloc(sizeof(KeyHandler));
-
- ptr = ptr->next;
-
- ptr->key = key;
- ptr->func = func;
- ptr->next = NULL;
- }
-
- return 0;
- }
- int plugin_remove_keypressHandler(byte key, PluginKeypress func)
- { /* actually do nothing, we cant remove plugin online */
- return 0;
- }
- /* Available functions outside of plugins */
- int plugin_keypress(byte key)
- {
- KeyHandler *ptr = keyHandlersList;
-
- while(ptr != NULL)
- {
- if (ptr->key == key)
- {
- ptr->func();
- }
- ptr = ptr->next;
- }
-
- return 0;
- }
|