1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus-core - api/common.c *
3 * Mupen64Plus homepage: https://mupen64plus.org/ *
4 * Copyright (C) 2009 Richard Goedeken *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
22/* This file contains the Core common functions which will be exported
23 * outside of the core library.
24 */
25
26#include <stddef.h>
27#include <stdlib.h>
28
29#define M64P_CORE_PROTOTYPES 1
30#include "../main/version.h"
31#include "m64p_common.h"
32#include "m64p_types.h"
33
34EXPORT m64p_error CALL PluginGetVersion(m64p_plugin_type *PluginType, int *PluginVersion, int *APIVersion, const char **PluginNamePtr, int *Capabilities)
35{
36 /* set version info */
37 if (PluginType != NULL)
38 *PluginType = M64PLUGIN_CORE;
39
40 if (PluginVersion != NULL)
41 *PluginVersion = MUPEN_CORE_VERSION;
42
43 if (APIVersion != NULL)
44 *APIVersion = FRONTEND_API_VERSION;
45
46 if (PluginNamePtr != NULL)
47 *PluginNamePtr = MUPEN_CORE_NAME;
48
49 if (Capabilities != NULL)
50 {
51 *Capabilities = 0;
52#if defined(DBG)
53 *Capabilities |= M64CAPS_DEBUGGER;
54#endif
55#if defined(DYNAREC)
56 *Capabilities |= M64CAPS_DYNAREC;
57#endif
58#if defined(COMPARE_CORE)
59 *Capabilities |= M64CAPS_CORE_COMPARE;
60#endif
61 }
62
63 return M64ERR_SUCCESS;
64}
65
66EXPORT m64p_error CALL CoreGetAPIVersions(int *ConfigVersion, int *DebugVersion, int *VidextVersion, int *ExtraVersion)
67{
68 /* set version info */
69 if (ConfigVersion != NULL)
70 *ConfigVersion = CONFIG_API_VERSION;
71
72 if (DebugVersion != NULL)
73 *DebugVersion = DEBUG_API_VERSION;
74
75 if (VidextVersion != NULL)
76 *VidextVersion = VIDEXT_API_VERSION;
77
78 if (ExtraVersion != NULL)
79 *ExtraVersion = 0;
80
81 return M64ERR_SUCCESS;
82}
83
84static const char *ErrorMessages[] = {
85 "SUCCESS: No error",
86 "NOT_INIT: A function was called before it's associated module was initialized",
87 "ALREADY_INIT: Initialization function called twice",
88 "INCOMPATIBLE: API versions between components are incompatible",
89 "INPUT_ASSERT: Invalid function parameters, such as a NULL pointer",
90 "INPUT_INVALID: An input function parameter is logically invalid",
91 "INPUT_NOT_FOUND: The input parameter(s) specified a particular item which was not found",
92 "NO_MEMORY: Memory allocation failed",
93 "FILES: Error opening, creating, reading, or writing to a file",
94 "INTERNAL: logical inconsistency in program code. Probably a bug.",
95 "INVALID_STATE: An operation was requested which is not allowed in the current state",
96 "PLUGIN_FAIL: A plugin function returned a fatal error",
97 "SYSTEM_FAIL: A system function call, such as an SDL or file operation, failed",
98 "UNSUPPORTED: Function call is not supported (ie, core not built with debugger)",
99 "WRONG_TYPE: A given input type parameter cannot be used for desired operation" };
100
101EXPORT const char * CALL CoreErrorMessage(m64p_error ReturnCode)
102{
103 size_t i = (size_t) ReturnCode;
104
105 if (i >= (sizeof(ErrorMessages) / sizeof(char *)))
106 return "ERROR: Invalid m64p_error code given to CoreErrorMessage()";
107
108 return ErrorMessages[i];
109}
110
111