1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-04 10:03:36 +00:00

Add necessary include files

This commit is contained in:
Sergey Lipskiy 2013-10-21 13:00:47 +07:00
parent fd3fe0b7b7
commit 85a743adaf
13 changed files with 2389 additions and 0 deletions

View File

@ -34,6 +34,8 @@ set(GLideN64_SOURCES
VI.cpp
)
include_directories( inc )
set(GLideN64_SOURCES_WIN
Config.cpp
)

39
inc/callbacks.h Normal file
View File

@ -0,0 +1,39 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - api/callbacks.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This file contains the definitions for callback functions which will be
* called from the other Core modules
*/
#if !defined(API_CALLBACKS_H)
#define API_CALLBACKS_H
#include "m64p_types.h"
#include "m64p_frontend.h"
/* Functions for use by the Core, to send information back to the front-end app */
extern m64p_error SetDebugCallback(ptr_DebugCallback pFunc, void *Context);
extern m64p_error SetStateCallback(ptr_StateCallback pFunc, void *Context);
extern void DebugMessage(int level, const char *message, ...);
extern void StateChanged(m64p_core_param param_type, int new_value);
#endif /* API_CALLBACKS_H */

30
inc/config.h Normal file
View File

@ -0,0 +1,30 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - api/config.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This file contains the Core configuration functions
*/
#include "m64p_types.h"
/* these functions are only to be used within the Core library */
m64p_error ConfigInit(const char *ConfigDirOverride, const char *DataDirOverride);
m64p_error ConfigShutdown(void);

46
inc/debugger.h Normal file
View File

@ -0,0 +1,46 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - api/debugger.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This file contains the definitions for debugger functions which will be
* called from the other Core modules
*/
#if !defined(API_DEBUGGER_H)
#define API_DEBUGGER_H
#include "m64p_types.h"
/* Debugger Definitions */
typedef enum {
DEBUG_UI_INIT = 1,
DEBUG_UI_UPDATE,
DEBUG_UI_VI,
DEBUG_CORE_COMPARE
} eDbgCallbackType;
/* Functions for use by the Core, to send information back to the front-end app */
extern void DebuggerCallback(eDbgCallbackType type, unsigned int param);
extern void CoreCompareCallback(void);
extern void CoreCompareDataSync(int length, void *ptr);
#endif /* API_DEBUGGER_H */

90
inc/m64p_common.h Normal file
View File

@ -0,0 +1,90 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - m64p_common.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This header file defines typedefs for function pointers to common Core
* and plugin functions, for use by the front-end and plugin modules to attach
* to the dynamic libraries.
*/
#if !defined(M64P_COMMON_H)
#define M64P_COMMON_H
#include "m64p_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* PluginGetVersion()
*
* This function retrieves version information from a library. This
* function is the same for the core library and the plugins.
*/
typedef m64p_error (*ptr_PluginGetVersion)(m64p_plugin_type *, int *, int *, const char **, int *);
#if defined(M64P_PLUGIN_PROTOTYPES) || defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL PluginGetVersion(m64p_plugin_type *, int *, int *, const char **, int *);
#endif
/* CoreGetAPIVersions()
*
* This function retrieves API version information from the core.
*/
typedef m64p_error (*ptr_CoreGetAPIVersions)(int *, int *, int *, int *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreGetAPIVersions(int *, int *, int *, int *);
#endif
/* CoreErrorMessage()
*
* This function returns a pointer to a NULL-terminated string giving a
* human-readable description of the error.
*/
typedef const char * (*ptr_CoreErrorMessage)(m64p_error);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT const char * CALL CoreErrorMessage(m64p_error);
#endif
/* PluginStartup()
*
* This function initializes a plugin for use by allocating memory, creating
* data structures, and loading the configuration data.
*/
typedef m64p_error (*ptr_PluginStartup)(m64p_dynlib_handle, void *, void (*)(void *, int, const char *));
#if defined(M64P_PLUGIN_PROTOTYPES) || defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handle, void *, void (*)(void *, int, const char *));
#endif
/* PluginShutdown()
*
* This function destroys data structures and releases memory allocated by
* the plugin library.
*/
typedef m64p_error (*ptr_PluginShutdown)(void);
#if defined(M64P_PLUGIN_PROTOTYPES) || defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL PluginShutdown(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* #define M64P_COMMON_H */

242
inc/m64p_config.h Normal file
View File

@ -0,0 +1,242 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - m64p_config.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This header file defines typedefs for function pointers to the Core's
* configuration handling functions.
*/
#if !defined(M64P_CONFIG_H)
#define M64P_CONFIG_H
#include "m64p_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ConfigListSections()
*
* This function is called to enumerate the list of Sections in the Mupen64Plus
* configuration file. It is expected that there will be a section named "Core"
* for core-specific configuration data, "Graphics" for common graphics options,
* and one or more sections for each plugin library.
*/
typedef m64p_error (*ptr_ConfigListSections)(void *, void (*)(void *, const char *));
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigListSections(void *, void (*)(void *, const char *));
#endif
/* ConfigOpenSection()
*
* This function is used to give a configuration section handle to the front-end
* which may be used to read or write configuration parameter values in a given
* section of the configuration file.
*/
typedef m64p_error (*ptr_ConfigOpenSection)(const char *, m64p_handle *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigOpenSection(const char *, m64p_handle *);
#endif
/* ConfigListParameters()
*
* This function is called to enumerate the list of Parameters in a given
* Section of the Mupen64Plus configuration file.
*/
typedef m64p_error (*ptr_ConfigListParameters)(m64p_handle, void *, void (*)(void *, const char *, m64p_type));
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigListParameters(m64p_handle, void *, void (*)(void *, const char *, m64p_type));
#endif
/* ConfigSaveFile()
*
* This function saves the entire current Mupen64Plus configuration to disk.
*/
typedef m64p_error (*ptr_ConfigSaveFile)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigSaveFile(void);
#endif
/* ConfigSaveSection()
*
* This function saves one section of the current Mupen64Plus configuration to disk.
*/
typedef m64p_error (*ptr_ConfigSaveSection)(const char *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigSaveSection(const char *);
#endif
/* ConfigHasUnsavedChanges()
*
* This function determines if a given Section (or all sections) of the Mupen64Plus Core configuration file has been modified since it was last saved or loaded.
*/
typedef int (*ptr_ConfigHasUnsavedChanges)(const char *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT int CALL ConfigHasUnsavedChanges(const char *);
#endif
/* ConfigDeleteSection()
*
* This function deletes a section from the Mupen64Plus configuration data.
*/
typedef m64p_error (*ptr_ConfigDeleteSection)(const char *SectionName);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigDeleteSection(const char *SectionName);
#endif
/* ConfigRevertChanges()
*
* This function reverts changes previously made to one section of the configuration file, so that it will match with the configuration at the last time that it was loaded from or saved to disk.
*/
typedef m64p_error (*ptr_ConfigRevertChanges)(const char *SectionName);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigRevertChanges(const char *SectionName);
#endif
/* ConfigSetParameter()
*
* This function sets the value of one of the emulator's configuration
* parameters.
*/
typedef m64p_error (*ptr_ConfigSetParameter)(m64p_handle, const char *, m64p_type, const void *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigSetParameter(m64p_handle, const char *, m64p_type, const void *);
#endif
/* ConfigGetParameter()
*
* This function retrieves the value of one of the emulator's parameters.
*/
typedef m64p_error (*ptr_ConfigGetParameter)(m64p_handle, const char *, m64p_type, void *, int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigGetParameter(m64p_handle, const char *, m64p_type, void *, int);
#endif
/* ConfigGetParameterType()
*
* This function retrieves the type of one of the emulator's parameters.
*/
typedef m64p_error (*ptr_ConfigGetParameterType)(m64p_handle, const char *, m64p_type *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigGetParameterType(m64p_handle, const char *, m64p_type *);
#endif
/* ConfigGetParameterHelp()
*
* This function retrieves the help information about one of the emulator's
* parameters.
*/
typedef const char * (*ptr_ConfigGetParameterHelp)(m64p_handle, const char *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT const char * CALL ConfigGetParameterHelp(m64p_handle, const char *);
#endif
/* ConfigSetDefault***()
*
* These functions are used to set the value of a configuration parameter if it
* is not already present in the configuration file. This may happen if a new
* user runs the emulator, or an upgraded module uses a new parameter, or the
* user deletes his or her configuration file. If the parameter is already
* present in the given section of the configuration file, then no action will
* be taken and this function will return successfully.
*/
typedef m64p_error (*ptr_ConfigSetDefaultInt)(m64p_handle, const char *, int, const char *);
typedef m64p_error (*ptr_ConfigSetDefaultFloat)(m64p_handle, const char *, float, const char *);
typedef m64p_error (*ptr_ConfigSetDefaultBool)(m64p_handle, const char *, int, const char *);
typedef m64p_error (*ptr_ConfigSetDefaultString)(m64p_handle, const char *, const char *, const char *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL ConfigSetDefaultInt(m64p_handle, const char *, int, const char *);
EXPORT m64p_error CALL ConfigSetDefaultFloat(m64p_handle, const char *, float, const char *);
EXPORT m64p_error CALL ConfigSetDefaultBool(m64p_handle, const char *, int, const char *);
EXPORT m64p_error CALL ConfigSetDefaultString(m64p_handle, const char *, const char *, const char *);
#endif
/* ConfigGetParam***()
*
* These functions retrieve the value of one of the emulator's parameters in
* the given section, and return the value directly to the calling function. If
* an errors occurs (such as an invalid Section handle, or invalid
* configuration parameter name), then an error will be sent to the front-end
* via the DebugCallback() function, and either a 0 (zero) or an empty string
* will be returned.
*/
typedef int (*ptr_ConfigGetParamInt)(m64p_handle, const char *);
typedef float (*ptr_ConfigGetParamFloat)(m64p_handle, const char *);
typedef int (*ptr_ConfigGetParamBool)(m64p_handle, const char *);
typedef const char * (*ptr_ConfigGetParamString)(m64p_handle, const char *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT int CALL ConfigGetParamInt(m64p_handle, const char *);
EXPORT float CALL ConfigGetParamFloat(m64p_handle, const char *);
EXPORT int CALL ConfigGetParamBool(m64p_handle, const char *);
EXPORT const char * CALL ConfigGetParamString(m64p_handle, const char *);
#endif
/* ConfigGetSharedDataFilepath()
*
* This function is provided to allow a plugin to retrieve a full pathname to a
* given shared data file. This type of file is intended to be shared among
* multiple users on a system, so it is likely to be read-only.
*/
typedef const char * (*ptr_ConfigGetSharedDataFilepath)(const char *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT const char * CALL ConfigGetSharedDataFilepath(const char *);
#endif
/* ConfigGetUserConfigPath()
*
* This function may be used by the plugins or front-end to get a path to the
* directory for storing user-specific configuration files. This will be the
* directory where "mupen64plus.cfg" is located.
*/
typedef const char * (*ptr_ConfigGetUserConfigPath)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT const char * CALL ConfigGetUserConfigPath(void);
#endif
/* ConfigGetUserDataPath()
*
* This function may be used by the plugins or front-end to get a path to the
* directory for storing user-specific data files. This may be used to store
* files such as screenshots, saved game states, or hi-res textures.
*/
typedef const char * (*ptr_ConfigGetUserDataPath)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT const char * CALL ConfigGetUserDataPath(void);
#endif
/* ConfigGetUserCachePath()
*
* This function may be used by the plugins or front-end to get a path to the
* directory for storing cached user-specific data files. Files in this
* directory may be deleted by the user to save space, so critical information
* should not be stored here. This directory may be used to store files such
* as the ROM browser cache.
*/
typedef const char * (*ptr_ConfigGetUserCachePath)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT const char * CALL ConfigGetUserCachePath(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* #define M64P_CONFIG_H */

202
inc/m64p_debugger.h Normal file
View File

@ -0,0 +1,202 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - m64p_debugger.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This header file defines typedefs for function pointers to Core Debugger
* functions.
*/
#if !defined(M64P_DEBUGGER_H)
#define M64P_DEBUGGER_H
#include "m64p_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* DebugSetCallbacks()
*
* This function is called by the front-end to supply debugger callback
* function pointers. If debugger is enabled and then later disabled within the
* UI, this function may be called with NULL pointers in order to disable the
* callbacks.
*/
typedef m64p_error (*ptr_DebugSetCallbacks)(void (*)(void), void (*)(unsigned int), void (*)(void));
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL DebugSetCallbacks(void (*)(void), void (*)(unsigned int), void (*)(void));
#endif
/* DebugSetCoreCompare()
*
* This function is called by the front-end to supply callback function pointers
* for the Core Comparison feature.
*/
typedef m64p_error (*ptr_DebugSetCoreCompare)(void (*)(unsigned int), void (*)(int, void *));
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL DebugSetCoreCompare(void (*)(unsigned int), void (*)(int, void *));
#endif
/* DebugSetRunState()
*
* This function sets the run state of the R4300 CPU emulator.
*/
typedef m64p_error (*ptr_DebugSetRunState)(int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL DebugSetRunState(int);
#endif
/* DebugGetState()
*
* This function reads and returns a debugger state variable, which are
* enumerated in m64p_types.h.
*/
typedef int (*ptr_DebugGetState)(m64p_dbg_state);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT int CALL DebugGetState(m64p_dbg_state);
#endif
/* DebugStep()
*
* This function signals the debugger to advance one instruction when in the
* stepping mode.
*/
typedef m64p_error (*ptr_DebugStep)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL DebugStep(void);
#endif
/* DebugDecodeOp()
*
* This is a helper function for the debugger front-end. This instruction takes
* a PC value and an R4300 instruction opcode and writes the disassembled
* instruction mnemonic and arguments into character buffers. This is intended
* to be used to display disassembled code.
*/
typedef void (*ptr_DebugDecodeOp)(unsigned int, char *, char *, int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT void CALL DebugDecodeOp(unsigned int, char *, char *, int);
#endif
/* DebugMemGetRecompInfo()
*
* This function is used by the front-end to retrieve disassembly information
* about recompiled code. For example, the dynamic recompiler may take a single
* R4300 instruction and compile it into 10 x86 instructions. This function may
* then be used to retrieve the disassembled code of the 10 x86 instructions.
*/
typedef void * (*ptr_DebugMemGetRecompInfo)(m64p_dbg_mem_info, unsigned int, int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT void * CALL DebugMemGetRecompInfo(m64p_dbg_mem_info, unsigned int, int);
#endif
/* DebugMemGetMemInfo()
*
* This function returns an integer value regarding the memory location address,
* corresponding to the information requested by mem_info_type, which is a type
* enumerated in m64p_types.h.
*/
typedef int (*ptr_DebugMemGetMemInfo)(m64p_dbg_mem_info, unsigned int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT int CALL DebugMemGetMemInfo(m64p_dbg_mem_info, unsigned int);
#endif
/* DebugMemGetPointer()
*
* This function returns a memory pointer (in x86 memory space) to a block of
* emulated N64 memory. This may be used to retrieve a pointer to a special N64
* block (such as the serial, video, or audio registers) or the RDRAM.
*/
typedef void * (*ptr_DebugMemGetPointer)(m64p_dbg_memptr_type);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT void * CALL DebugMemGetPointer(m64p_dbg_memptr_type);
#endif
/* DebugMemRead**()
*
* These functions retrieve a value from the emulated N64 memory. The returned
* value will be correctly byte-swapped for the host architecture.
*/
typedef unsigned long long (*ptr_DebugMemRead64)(unsigned int);
typedef unsigned int (*ptr_DebugMemRead32)(unsigned int);
typedef unsigned short (*ptr_DebugMemRead16)(unsigned int);
typedef unsigned char (*ptr_DebugMemRead8)(unsigned int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT unsigned long long CALL DebugMemRead64(unsigned int);
EXPORT unsigned int CALL DebugMemRead32(unsigned int);
EXPORT unsigned short CALL DebugMemRead16(unsigned int);
EXPORT unsigned char CALL DebugMemRead8(unsigned int);
#endif
/* DebugMemWrite**()
*
* These functions write a value into the emulated N64 memory. The given value
* will be correctly byte-swapped before storage.
*/
typedef void (*ptr_DebugMemWrite64)(unsigned int, unsigned long long);
typedef void (*ptr_DebugMemWrite32)(unsigned int, unsigned int);
typedef void (*ptr_DebugMemWrite16)(unsigned int, unsigned short);
typedef void (*ptr_DebugMemWrite8)(unsigned int, unsigned char);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT void CALL DebugMemWrite64(unsigned int, unsigned long long);
EXPORT void CALL DebugMemWrite32(unsigned int, unsigned int);
EXPORT void CALL DebugMemWrite16(unsigned int, unsigned short);
EXPORT void CALL DebugMemWrite8(unsigned int, unsigned char);
#endif
/* DebugGetCPUDataPtr()
*
* This function returns a memory pointer (in x86 memory space) to a specific
* register in the emulated R4300 CPU.
*/
typedef void * (*ptr_DebugGetCPUDataPtr)(m64p_dbg_cpu_data);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT void * CALL DebugGetCPUDataPtr(m64p_dbg_cpu_data);
#endif
/* DebugBreakpointLookup()
*
* This function searches through all current breakpoints in the debugger to
* find one that matches the given input parameters. If a matching breakpoint
* is found, the index number is returned. If no breakpoints are found, -1 is
* returned.
*/
typedef int (*ptr_DebugBreakpointLookup)(unsigned int, unsigned int, unsigned int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT int CALL DebugBreakpointLookup(unsigned int, unsigned int, unsigned int);
#endif
/* DebugBreakpointCommand()
*
* This function is used to process common breakpoint commands, such as adding,
* removing, or searching the breakpoints. The meanings of the index and ptr
* input parameters vary by command.
*/
typedef int (*ptr_DebugBreakpointCommand)(m64p_dbg_bkp_command, unsigned int, void *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT int CALL DebugBreakpointCommand(m64p_dbg_bkp_command, unsigned int, void *);
#endif
#ifdef __cplusplus
}
#endif
#endif /* #define M64P_DEBUGGER_H */

141
inc/m64p_frontend.h Normal file
View File

@ -0,0 +1,141 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - m64p_frontend.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This header file defines typedefs for function pointers to Core functions
* designed for use by the front-end user interface.
*/
#if !defined(M64P_FRONTEND_H)
#define M64P_FRONTEND_H
#include "m64p_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* pointer types to the callback functions in the front-end application */
typedef void (*ptr_DebugCallback)(void *Context, int level, const char *message);
typedef void (*ptr_StateCallback)(void *Context, m64p_core_param param_type, int new_value);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT void CALL DebugCallback(void *Context, int level, const char *message);
EXPORT void CALL StateCallback(void *Context, m64p_core_param param_type, int new_value);
#endif
/* CoreStartup()
*
* This function initializes libmupen64plus for use by allocating memory,
* creating data structures, and loading the configuration file.
*/
typedef m64p_error (*ptr_CoreStartup)(int, const char *, const char *, void *, ptr_DebugCallback, void *, ptr_StateCallback);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreStartup(int, const char *, const char *, void *, ptr_DebugCallback, void *, ptr_StateCallback);
#endif
/* CoreShutdown()
*
* This function saves the configuration file, then destroys data structures
* and releases memory allocated by the core library.
*/
typedef m64p_error (*ptr_CoreShutdown)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreShutdown(void);
#endif
/* CoreAttachPlugin()
*
* This function attaches the given plugin to the emulator core. There can only
* be one plugin of each type attached to the core at any given time.
*/
typedef m64p_error (*ptr_CoreAttachPlugin)(m64p_plugin_type, m64p_dynlib_handle);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreAttachPlugin(m64p_plugin_type, m64p_dynlib_handle);
#endif
/* CoreDetachPlugin()
*
* This function detaches the given plugin from the emulator core, and re-attaches
* the 'dummy' plugin functions.
*/
typedef m64p_error (*ptr_CoreDetachPlugin)(m64p_plugin_type);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreDetachPlugin(m64p_plugin_type);
#endif
/* CoreDoCommand()
*
* This function sends a command to the emulator core.
*/
typedef m64p_error (*ptr_CoreDoCommand)(m64p_command, int, void *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreDoCommand(m64p_command, int, void *);
#endif
/* CoreOverrideVidExt()
*
* This function overrides the core's internal SDL-based OpenGL functions. This
* override functionality allows a front-end to define its own video extension
* functions to be used instead of the SDL functions. If any of the function
* pointers in the structure are NULL, the override function will be disabled
* and the core's internal SDL functions will be used.
*/
typedef m64p_error (*ptr_CoreOverrideVidExt)(m64p_video_extension_functions *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreOverrideVidExt(m64p_video_extension_functions *);
#endif
/* CoreAddCheat()
*
* This function will add a Cheat Function to a list of currently active cheats
* which are applied to the open ROM.
*/
typedef m64p_error (*ptr_CoreAddCheat)(const char *, m64p_cheat_code *, int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreAddCheat(const char *, m64p_cheat_code *, int);
#endif
/* CoreCheatEnabled()
*
* This function will enable or disable a Cheat Function which is in the list of
* currently active cheats.
*/
typedef m64p_error (*ptr_CoreCheatEnabled)(const char *, int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreCheatEnabled(const char *, int);
#endif
/* CoreGetRomSettings()
*
* This function will retrieve the ROM settings from the mupen64plus INI file for
* the ROM image corresponding to the given CRC values.
*/
typedef m64p_error (*ptr_CoreGetRomSettings)(m64p_rom_settings *, int, int, int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL CoreGetRomSettings(m64p_rom_settings *, int, int, int);
#endif
#ifdef __cplusplus
}
#endif
#endif /* #define M64P_FRONTEND_H */

271
inc/m64p_plugin.h Normal file
View File

@ -0,0 +1,271 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - m64p_plugin.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2002 Hacktarux *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#if !defined(M64P_PLUGIN_H)
#define M64P_PLUGIN_H
#include "m64p_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/*** Controller plugin's ****/
#define PLUGIN_NONE 1
#define PLUGIN_MEMPAK 2
#define PLUGIN_RUMBLE_PAK 3 /* not implemented for non raw data */
#define PLUGIN_TRANSFER_PAK 4 /* not implemented for non raw data */
#define PLUGIN_RAW 5 /* the controller plugin is passed in raw data */
/***** Structures *****/
typedef struct {
unsigned char * RDRAM;
unsigned char * DMEM;
unsigned char * IMEM;
unsigned int * MI_INTR_REG;
unsigned int * SP_MEM_ADDR_REG;
unsigned int * SP_DRAM_ADDR_REG;
unsigned int * SP_RD_LEN_REG;
unsigned int * SP_WR_LEN_REG;
unsigned int * SP_STATUS_REG;
unsigned int * SP_DMA_FULL_REG;
unsigned int * SP_DMA_BUSY_REG;
unsigned int * SP_PC_REG;
unsigned int * SP_SEMAPHORE_REG;
unsigned int * DPC_START_REG;
unsigned int * DPC_END_REG;
unsigned int * DPC_CURRENT_REG;
unsigned int * DPC_STATUS_REG;
unsigned int * DPC_CLOCK_REG;
unsigned int * DPC_BUFBUSY_REG;
unsigned int * DPC_PIPEBUSY_REG;
unsigned int * DPC_TMEM_REG;
void (*CheckInterrupts)(void);
void (*ProcessDlistList)(void);
void (*ProcessAlistList)(void);
void (*ProcessRdpList)(void);
void (*ShowCFB)(void);
} RSP_INFO;
typedef struct {
unsigned char * HEADER; /* This is the rom header (first 40h bytes of the rom) */
unsigned char * RDRAM;
unsigned char * DMEM;
unsigned char * IMEM;
unsigned int * MI_INTR_REG;
unsigned int * DPC_START_REG;
unsigned int * DPC_END_REG;
unsigned int * DPC_CURRENT_REG;
unsigned int * DPC_STATUS_REG;
unsigned int * DPC_CLOCK_REG;
unsigned int * DPC_BUFBUSY_REG;
unsigned int * DPC_PIPEBUSY_REG;
unsigned int * DPC_TMEM_REG;
unsigned int * VI_STATUS_REG;
unsigned int * VI_ORIGIN_REG;
unsigned int * VI_WIDTH_REG;
unsigned int * VI_INTR_REG;
unsigned int * VI_V_CURRENT_LINE_REG;
unsigned int * VI_TIMING_REG;
unsigned int * VI_V_SYNC_REG;
unsigned int * VI_H_SYNC_REG;
unsigned int * VI_LEAP_REG;
unsigned int * VI_H_START_REG;
unsigned int * VI_V_START_REG;
unsigned int * VI_V_BURST_REG;
unsigned int * VI_X_SCALE_REG;
unsigned int * VI_Y_SCALE_REG;
void (*CheckInterrupts)(void);
} GFX_INFO;
typedef struct {
unsigned char * RDRAM;
unsigned char * DMEM;
unsigned char * IMEM;
unsigned int * MI_INTR_REG;
unsigned int * AI_DRAM_ADDR_REG;
unsigned int * AI_LEN_REG;
unsigned int * AI_CONTROL_REG;
unsigned int * AI_STATUS_REG;
unsigned int * AI_DACRATE_REG;
unsigned int * AI_BITRATE_REG;
void (*CheckInterrupts)(void);
} AUDIO_INFO;
typedef struct {
int Present;
int RawData;
int Plugin;
} CONTROL;
typedef union {
unsigned int Value;
struct {
unsigned R_DPAD : 1;
unsigned L_DPAD : 1;
unsigned D_DPAD : 1;
unsigned U_DPAD : 1;
unsigned START_BUTTON : 1;
unsigned Z_TRIG : 1;
unsigned B_BUTTON : 1;
unsigned A_BUTTON : 1;
unsigned R_CBUTTON : 1;
unsigned L_CBUTTON : 1;
unsigned D_CBUTTON : 1;
unsigned U_CBUTTON : 1;
unsigned R_TRIG : 1;
unsigned L_TRIG : 1;
unsigned Reserved1 : 1;
unsigned Reserved2 : 1;
signed X_AXIS : 8;
signed Y_AXIS : 8;
};
} BUTTONS;
typedef struct {
CONTROL *Controls; /* A pointer to an array of 4 controllers .. eg:
CONTROL Controls[4]; */
} CONTROL_INFO;
/* common plugin function pointer types */
typedef void (*ptr_RomClosed)(void);
typedef int (*ptr_RomOpen)(void);
#if defined(M64P_PLUGIN_PROTOTYPES)
EXPORT int CALL RomOpen(void);
EXPORT void CALL RomClosed(void);
#endif
/* video plugin function pointer types */
typedef void (*ptr_ChangeWindow)(void);
typedef int (*ptr_InitiateGFX)(GFX_INFO Gfx_Info);
typedef void (*ptr_MoveScreen)(int x, int y);
typedef void (*ptr_ProcessDList)(void);
typedef void (*ptr_ProcessRDPList)(void);
typedef void (*ptr_ShowCFB)(void);
typedef void (*ptr_UpdateScreen)(void);
typedef void (*ptr_ViStatusChanged)(void);
typedef void (*ptr_ViWidthChanged)(void);
typedef void (*ptr_ReadScreen2)(void *dest, int *width, int *height, int front);
typedef void (*ptr_SetRenderingCallback)(void (*callback)(int));
typedef void (*ptr_ResizeVideoOutput)(int width, int height);
#if defined(M64P_PLUGIN_PROTOTYPES)
EXPORT void CALL ChangeWindow(void);
EXPORT int CALL InitiateGFX(GFX_INFO Gfx_Info);
EXPORT void CALL MoveScreen(int x, int y);
EXPORT void CALL ProcessDList(void);
EXPORT void CALL ProcessRDPList(void);
EXPORT void CALL ShowCFB(void);
EXPORT void CALL UpdateScreen(void);
EXPORT void CALL ViStatusChanged(void);
EXPORT void CALL ViWidthChanged(void);
EXPORT void CALL ReadScreen2(void *dest, int *width, int *height, int front);
EXPORT void CALL SetRenderingCallback(void (*callback)(int));
EXPORT void CALL ResizeVideoOutput(int width, int height);
#endif
/* frame buffer plugin spec extension */
typedef struct
{
unsigned int addr;
unsigned int size;
unsigned int width;
unsigned int height;
} FrameBufferInfo;
typedef void (*ptr_FBRead)(unsigned int addr);
typedef void (*ptr_FBWrite)(unsigned int addr, unsigned int size);
typedef void (*ptr_FBGetFrameBufferInfo)(void *p);
#if defined(M64P_PLUGIN_PROTOTYPES)
EXPORT void CALL FBRead(unsigned int addr);
EXPORT void CALL FBWrite(unsigned int addr, unsigned int size);
EXPORT void CALL FBGetFrameBufferInfo(void *p);
#endif
/* audio plugin function pointers */
typedef void (*ptr_AiDacrateChanged)(int SystemType);
typedef void (*ptr_AiLenChanged)(void);
typedef int (*ptr_InitiateAudio)(AUDIO_INFO Audio_Info);
typedef void (*ptr_ProcessAList)(void);
typedef void (*ptr_SetSpeedFactor)(int percent);
typedef void (*ptr_VolumeUp)(void);
typedef void (*ptr_VolumeDown)(void);
typedef int (*ptr_VolumeGetLevel)(void);
typedef void (*ptr_VolumeSetLevel)(int level);
typedef void (*ptr_VolumeMute)(void);
typedef const char * (*ptr_VolumeGetString)(void);
#if defined(M64P_PLUGIN_PROTOTYPES)
EXPORT void CALL AiDacrateChanged(int SystemType);
EXPORT void CALL AiLenChanged(void);
EXPORT int CALL InitiateAudio(AUDIO_INFO Audio_Info);
EXPORT void CALL ProcessAList(void);
EXPORT void CALL SetSpeedFactor(int percent);
EXPORT void CALL VolumeUp(void);
EXPORT void CALL VolumeDown(void);
EXPORT int CALL VolumeGetLevel(void);
EXPORT void CALL VolumeSetLevel(int level);
EXPORT void CALL VolumeMute(void);
EXPORT const char * CALL VolumeGetString(void);
#endif
/* input plugin function pointers */
typedef void (*ptr_ControllerCommand)(int Control, unsigned char *Command);
typedef void (*ptr_GetKeys)(int Control, BUTTONS *Keys);
typedef void (*ptr_InitiateControllers)(CONTROL_INFO ControlInfo);
typedef void (*ptr_ReadController)(int Control, unsigned char *Command);
typedef void (*ptr_SDL_KeyDown)(int keymod, int keysym);
typedef void (*ptr_SDL_KeyUp)(int keymod, int keysym);
#if defined(M64P_PLUGIN_PROTOTYPES)
EXPORT void CALL ControllerCommand(int Control, unsigned char *Command);
EXPORT void CALL GetKeys(int Control, BUTTONS *Keys);
EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo);
EXPORT void CALL ReadController(int Control, unsigned char *Command);
EXPORT void CALL SDL_KeyDown(int keymod, int keysym);
EXPORT void CALL SDL_KeyUp(int keymod, int keysym);
#endif
/* RSP plugin function pointers */
typedef unsigned int (*ptr_DoRspCycles)(unsigned int Cycles);
typedef void (*ptr_InitiateRSP)(RSP_INFO Rsp_Info, unsigned int *CycleCount);
#if defined(M64P_PLUGIN_PROTOTYPES)
EXPORT unsigned int CALL DoRspCycles(unsigned int Cycles);
EXPORT void CALL InitiateRSP(RSP_INFO Rsp_Info, unsigned int *CycleCount);
#endif
#ifdef __cplusplus
}
#endif
#endif /* M64P_PLUGIN_H */

351
inc/m64p_types.h Normal file
View File

@ -0,0 +1,351 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - m64p_types.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2012 CasualJames *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#if !defined(M64P_TYPES_H)
#define M64P_TYPES_H
/* ----------------------------------------- */
/* Platform-specific stuff */
/* ----------------------------------------- */
/* necessary headers */
#if defined(WIN32)
#include <windows.h>
#endif
/* DLL handles and function declaration specifiers */
#if defined(WIN32)
#define IMPORT extern "C" __declspec(dllimport)
#define EXPORT __declspec(dllexport)
#define CALL __cdecl
typedef HMODULE m64p_dynlib_handle;
#else
#define IMPORT extern "C"
#define EXPORT __attribute__((visibility("default")))
#define CALL
typedef void * m64p_dynlib_handle;
#endif
/* ----------------------------------------- */
/* Structures and Types for Core library API */
/* ----------------------------------------- */
typedef void * m64p_handle;
typedef void (*m64p_frame_callback)(unsigned int FrameIndex);
typedef void (*m64p_input_callback)(void);
typedef void (*m64p_audio_callback)(void);
typedef void (*m64p_vi_callback)(void);
typedef enum {
M64TYPE_INT = 1,
M64TYPE_FLOAT,
M64TYPE_BOOL,
M64TYPE_STRING
} m64p_type;
typedef enum {
M64MSG_ERROR = 1,
M64MSG_WARNING,
M64MSG_INFO,
M64MSG_STATUS,
M64MSG_VERBOSE
} m64p_msg_level;
typedef enum {
M64ERR_SUCCESS = 0,
M64ERR_NOT_INIT, /* Function is disallowed before InitMupen64Plus() is called */
M64ERR_ALREADY_INIT, /* InitMupen64Plus() was called twice */
M64ERR_INCOMPATIBLE, /* API versions between components are incompatible */
M64ERR_INPUT_ASSERT, /* Invalid parameters for function call, such as ParamValue=NULL for GetCoreParameter() */
M64ERR_INPUT_INVALID, /* Invalid input data, such as ParamValue="maybe" for SetCoreParameter() to set a BOOL-type value */
M64ERR_INPUT_NOT_FOUND, /* The input parameter(s) specified a particular item which was not found */
M64ERR_NO_MEMORY, /* Memory allocation failed */
M64ERR_FILES, /* Error opening, creating, reading, or writing to a file */
M64ERR_INTERNAL, /* Internal error (bug) */
M64ERR_INVALID_STATE, /* Current program state does not allow operation */
M64ERR_PLUGIN_FAIL, /* A plugin function returned a fatal error */
M64ERR_SYSTEM_FAIL, /* A system function call, such as an SDL or file operation, failed */
M64ERR_UNSUPPORTED, /* Function call is not supported (ie, core not built with debugger) */
M64ERR_WRONG_TYPE /* A given input type parameter cannot be used for desired operation */
} m64p_error;
typedef enum {
M64CAPS_DYNAREC = 1,
M64CAPS_DEBUGGER = 2,
M64CAPS_CORE_COMPARE = 4
} m64p_core_caps;
typedef enum {
M64PLUGIN_NULL = 0,
M64PLUGIN_RSP = 1,
M64PLUGIN_GFX,
M64PLUGIN_AUDIO,
M64PLUGIN_INPUT,
M64PLUGIN_CORE
} m64p_plugin_type;
typedef enum {
M64EMU_STOPPED = 1,
M64EMU_RUNNING,
M64EMU_PAUSED
} m64p_emu_state;
typedef enum {
M64VIDEO_NONE = 1,
M64VIDEO_WINDOWED,
M64VIDEO_FULLSCREEN
} m64p_video_mode;
typedef enum {
M64VIDEOFLAG_SUPPORT_RESIZING = 1
} m64p_video_flags;
typedef enum {
M64CORE_EMU_STATE = 1,
M64CORE_VIDEO_MODE,
M64CORE_SAVESTATE_SLOT,
M64CORE_SPEED_FACTOR,
M64CORE_SPEED_LIMITER,
M64CORE_VIDEO_SIZE,
M64CORE_AUDIO_VOLUME,
M64CORE_AUDIO_MUTE,
M64CORE_INPUT_GAMESHARK,
M64CORE_STATE_LOADCOMPLETE,
M64CORE_STATE_SAVECOMPLETE
} m64p_core_param;
typedef enum {
M64CMD_NOP = 0,
M64CMD_ROM_OPEN,
M64CMD_ROM_CLOSE,
M64CMD_ROM_GET_HEADER,
M64CMD_ROM_GET_SETTINGS,
M64CMD_EXECUTE,
M64CMD_STOP,
M64CMD_PAUSE,
M64CMD_RESUME,
M64CMD_CORE_STATE_QUERY,
M64CMD_STATE_LOAD,
M64CMD_STATE_SAVE,
M64CMD_STATE_SET_SLOT,
M64CMD_SEND_SDL_KEYDOWN,
M64CMD_SEND_SDL_KEYUP,
M64CMD_SET_FRAME_CALLBACK,
M64CMD_TAKE_NEXT_SCREENSHOT,
M64CMD_CORE_STATE_SET,
M64CMD_READ_SCREEN,
M64CMD_RESET,
M64CMD_ADVANCE_FRAME
} m64p_command;
typedef struct {
unsigned int address;
int value;
} m64p_cheat_code;
/* ----------------------------------------- */
/* Structures to hold ROM image information */
/* ----------------------------------------- */
typedef enum
{
SYSTEM_NTSC = 0,
SYSTEM_PAL,
SYSTEM_MPAL
} m64p_system_type;
typedef struct
{
unsigned char init_PI_BSB_DOM1_LAT_REG; /* 0x00 */
unsigned char init_PI_BSB_DOM1_PGS_REG; /* 0x01 */
unsigned char init_PI_BSB_DOM1_PWD_REG; /* 0x02 */
unsigned char init_PI_BSB_DOM1_PGS_REG2; /* 0x03 */
unsigned int ClockRate; /* 0x04 */
unsigned int PC; /* 0x08 */
unsigned int Release; /* 0x0C */
unsigned int CRC1; /* 0x10 */
unsigned int CRC2; /* 0x14 */
unsigned int Unknown[2]; /* 0x18 */
unsigned char Name[20]; /* 0x20 */
unsigned int unknown; /* 0x34 */
unsigned int Manufacturer_ID; /* 0x38 */
unsigned short Cartridge_ID; /* 0x3C - Game serial number */
unsigned short Country_code; /* 0x3E */
} m64p_rom_header;
typedef struct
{
char goodname[256];
char MD5[33];
unsigned char savetype;
unsigned char status; /* Rom status on a scale from 0-5. */
unsigned char players; /* Local players 0-4, 2/3/4 way Netplay indicated by 5/6/7. */
unsigned char rumble; /* 0 - No, 1 - Yes boolean for rumble support. */
} m64p_rom_settings;
/* ----------------------------------------- */
/* Structures and Types for the Debugger */
/* ----------------------------------------- */
typedef enum {
M64P_DBG_RUN_STATE = 1,
M64P_DBG_PREVIOUS_PC,
M64P_DBG_NUM_BREAKPOINTS,
M64P_DBG_CPU_DYNACORE,
M64P_DBG_CPU_NEXT_INTERRUPT
} m64p_dbg_state;
typedef enum {
M64P_DBG_MEM_TYPE = 1,
M64P_DBG_MEM_FLAGS,
M64P_DBG_MEM_HAS_RECOMPILED,
M64P_DBG_MEM_NUM_RECOMPILED,
M64P_DBG_RECOMP_OPCODE = 16,
M64P_DBG_RECOMP_ARGS,
M64P_DBG_RECOMP_ADDR
} m64p_dbg_mem_info;
typedef enum {
M64P_MEM_NOMEM = 0,
M64P_MEM_NOTHING,
M64P_MEM_RDRAM,
M64P_MEM_RDRAMREG,
M64P_MEM_RSPMEM,
M64P_MEM_RSPREG,
M64P_MEM_RSP,
M64P_MEM_DP,
M64P_MEM_DPS,
M64P_MEM_VI,
M64P_MEM_AI,
M64P_MEM_PI,
M64P_MEM_RI,
M64P_MEM_SI,
M64P_MEM_FLASHRAMSTAT,
M64P_MEM_ROM,
M64P_MEM_PIF,
M64P_MEM_MI,
M64P_MEM_BREAKPOINT
} m64p_dbg_mem_type;
typedef enum {
M64P_MEM_FLAG_READABLE = 0x01,
M64P_MEM_FLAG_WRITABLE = 0x02,
M64P_MEM_FLAG_READABLE_EMUONLY = 0x04, // the EMUONLY flags signify that emulated code can read/write here, but debugger cannot
M64P_MEM_FLAG_WRITABLE_EMUONLY = 0x08
} m64p_dbg_mem_flags;
typedef enum {
M64P_DBG_PTR_RDRAM = 1,
M64P_DBG_PTR_PI_REG,
M64P_DBG_PTR_SI_REG,
M64P_DBG_PTR_VI_REG,
M64P_DBG_PTR_RI_REG,
M64P_DBG_PTR_AI_REG
} m64p_dbg_memptr_type;
typedef enum {
M64P_CPU_PC = 1,
M64P_CPU_REG_REG,
M64P_CPU_REG_HI,
M64P_CPU_REG_LO,
M64P_CPU_REG_COP0,
M64P_CPU_REG_COP1_DOUBLE_PTR,
M64P_CPU_REG_COP1_SIMPLE_PTR,
M64P_CPU_REG_COP1_FGR_64,
M64P_CPU_TLB
} m64p_dbg_cpu_data;
typedef enum {
M64P_BKP_CMD_ADD_ADDR = 1,
M64P_BKP_CMD_ADD_STRUCT,
M64P_BKP_CMD_REPLACE,
M64P_BKP_CMD_REMOVE_ADDR,
M64P_BKP_CMD_REMOVE_IDX,
M64P_BKP_CMD_ENABLE,
M64P_BKP_CMD_DISABLE,
M64P_BKP_CMD_CHECK
} m64p_dbg_bkp_command;
#define M64P_MEM_INVALID 0xFFFFFFFF // invalid memory read will return this
#define BREAKPOINTS_MAX_NUMBER 128
#define BPT_FLAG_ENABLED 0x01
#define BPT_FLAG_CONDITIONAL 0x02
#define BPT_FLAG_COUNTER 0x04
#define BPT_FLAG_READ 0x08
#define BPT_FLAG_WRITE 0x10
#define BPT_FLAG_EXEC 0x20
#define BPT_FLAG_LOG 0x40 //Log to the console when this breakpoint hits.
#define BPT_CHECK_FLAG(a, b) ((a.flags & b) == b)
#define BPT_SET_FLAG(a, b) a.flags = (a.flags | b);
#define BPT_CLEAR_FLAG(a, b) a.flags = (a.flags & (~b));
#define BPT_TOGGLE_FLAG(a, b) a.flags = (a.flags ^ b);
typedef struct _breakpoint {
unsigned int address;
unsigned int endaddr;
unsigned int flags;
//unsigned int condition; //Placeholder for breakpoint condition
} breakpoint;
/* ------------------------------------------------- */
/* Structures and Types for Core Video Extension API */
/* ------------------------------------------------- */
typedef struct {
unsigned int uiWidth;
unsigned int uiHeight;
} m64p_2d_size;
typedef enum {
M64P_GL_DOUBLEBUFFER = 1,
M64P_GL_BUFFER_SIZE,
M64P_GL_DEPTH_SIZE,
M64P_GL_RED_SIZE,
M64P_GL_GREEN_SIZE,
M64P_GL_BLUE_SIZE,
M64P_GL_ALPHA_SIZE,
M64P_GL_SWAP_CONTROL,
M64P_GL_MULTISAMPLEBUFFERS,
M64P_GL_MULTISAMPLESAMPLES
} m64p_GLattr;
typedef struct {
unsigned int Functions;
m64p_error (*VidExtFuncInit)(void);
m64p_error (*VidExtFuncQuit)(void);
m64p_error (*VidExtFuncListModes)(m64p_2d_size *, int *);
m64p_error (*VidExtFuncSetMode)(int, int, int, int, int);
void * (*VidExtFuncGLGetProc)(const char*);
m64p_error (*VidExtFuncGLSetAttr)(m64p_GLattr, int);
m64p_error (*VidExtFuncGLGetAttr)(m64p_GLattr, int *);
m64p_error (*VidExtFuncGLSwapBuf)(void);
m64p_error (*VidExtFuncSetCaption)(const char *);
m64p_error (*VidExtFuncToggleFS)(void);
m64p_error (*VidExtFuncResizeWindow)(int, int);
} m64p_video_extension_functions;
#endif /* define M64P_TYPES_H */

154
inc/m64p_vidext.h Normal file
View File

@ -0,0 +1,154 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - m64p_vidext.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This header file defines typedefs for function pointers to the core's
* video extension functions.
*/
#if !defined(M64P_VIDEXT_H)
#define M64P_VIDEXT_H
#include "m64p_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* VidExt_Init()
*
* This function should be called from within the InitiateGFX() video plugin
* function call. The default SDL implementation of this function simply calls
* SDL_InitSubSystem(SDL_INIT_VIDEO). It does not open a rendering window or
* switch video modes.
*/
typedef m64p_error (*ptr_VidExt_Init)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_Init(void);
#endif
/* VidExt_Quit()
*
* This function closes any open rendering window and shuts down the video
* system. The default SDL implementation of this function calls
* SDL_QuitSubSystem(SDL_INIT_VIDEO). This function should be called from
* within the RomClose() video plugin function.
*/
typedef m64p_error (*ptr_VidExt_Quit)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_Quit(void);
#endif
/* VidExt_ListFullscreenModes()
*
* This function is used to enumerate the available resolutions for fullscreen
* video modes. A pointer to an array is passed into the function, which is
* then filled with resolution sizes.
*/
typedef m64p_error (*ptr_VidExt_ListFullscreenModes)(m64p_2d_size *, int *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_ListFullscreenModes(m64p_2d_size *, int *);
#endif
/* VidExt_SetVideoMode()
*
* This function creates a rendering window or switches into a fullscreen
* video mode. Any desired OpenGL attributes should be set before calling
* this function.
*/
typedef m64p_error (*ptr_VidExt_SetVideoMode)(int, int, int, m64p_video_mode, m64p_video_flags);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_SetVideoMode(int, int, int, m64p_video_mode, m64p_video_flags);
#endif
/* VidExt_ResizeWindow()
*
* This function resizes the opengl rendering window to match the given size.
*/
typedef m64p_error (*ptr_VidExt_ResizeWindow)(int, int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_ResizeWindow(int, int);
#endif
/* VidExt_SetCaption()
*
* This function sets the caption text of the emulator rendering window.
*/
typedef m64p_error (*ptr_VidExt_SetCaption)(const char *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_SetCaption(const char *);
#endif
/* VidExt_ToggleFullScreen()
*
* This function toggles between fullscreen and windowed rendering modes.
*/
typedef m64p_error (*ptr_VidExt_ToggleFullScreen)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_ToggleFullScreen(void);
#endif
/* VidExt_GL_GetProcAddress()
*
* This function is used to get a pointer to an OpenGL extension function. This
* is only necessary on the Windows platform, because the OpenGL implementation
* shipped with Windows only supports OpenGL version 1.1.
*/
typedef void * (*ptr_VidExt_GL_GetProcAddress)(const char *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT void * CALL VidExt_GL_GetProcAddress(const char *);
#endif
/* VidExt_GL_SetAttribute()
*
* This function is used to set certain OpenGL attributes which must be
* specified before creating the rendering window with VidExt_SetVideoMode.
*/
typedef m64p_error (*ptr_VidExt_GL_SetAttribute)(m64p_GLattr, int);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_GL_SetAttribute(m64p_GLattr, int);
#endif
/* VidExt_GL_GetAttribute()
*
* This function is used to get the value of OpenGL attributes. These values may
* be changed when calling VidExt_SetVideoMode.
*/
typedef m64p_error (*ptr_VidExt_GL_GetAttribute)(m64p_GLattr, int *);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_GL_GetAttribute(m64p_GLattr, int *);
#endif
/* VidExt_GL_SwapBuffers()
*
* This function is used to swap the front/back buffers after rendering an
* output video frame.
*/
typedef m64p_error (*ptr_VidExt_GL_SwapBuffers)(void);
#if defined(M64P_CORE_PROTOTYPES)
EXPORT m64p_error CALL VidExt_GL_SwapBuffers(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* #define M64P_VIDEXT_H */

38
inc/vidext.h Normal file
View File

@ -0,0 +1,38 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-core - api/vidext.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2009 Richard Goedeken *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This file contains the definitions for the video extension functions which
* will be called from other Core modules.
*/
#if !defined(API_VIDEXT_H)
#define API_VIDEXT_H
#include "m64p_types.h"
/* global function for use by frontend.c */
extern m64p_error OverrideVideoFunctions(m64p_video_extension_functions *VideoFunctionStruct);
/* these functions are only used by the core */
extern int VidExt_InFullscreenMode(void);
extern int VidExt_VideoRunning(void);
#endif /* API_VIDEXT_H */

783
inc/vidext_sdl2_compat.h Normal file
View File

@ -0,0 +1,783 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <SDL_surface.h>
typedef struct
{
Uint8 *src;
int src_w, src_h;
int src_pitch;
int src_skip;
Uint8 *dst;
int dst_w, dst_h;
int dst_pitch;
int dst_skip;
SDL_PixelFormat *src_fmt;
SDL_PixelFormat *dst_fmt;
Uint8 *table;
int flags;
Uint32 colorkey;
Uint8 r, g, b, a;
} SDL_BlitInfo;
/* Blit mapping definition */
typedef struct SDL_BlitMap
{
SDL_Surface *dst;
int identity;
SDL_blit blit;
void *data;
SDL_BlitInfo info;
/* the version count matches the destination; mismatch indicates
an invalid mapping */
Uint32 dst_palette_version;
Uint32 src_palette_version;
} SDL_BlitMap;
typedef struct SDL_VideoInfo
{
Uint32 hw_available:1;
Uint32 wm_available:1;
Uint32 UnusedBits1:6;
Uint32 UnusedBits2:1;
Uint32 blit_hw:1;
Uint32 blit_hw_CC:1;
Uint32 blit_hw_A:1;
Uint32 blit_sw:1;
Uint32 blit_sw_CC:1;
Uint32 blit_sw_A:1;
Uint32 blit_fill:1;
Uint32 UnusedBits3:16;
Uint32 video_mem;
SDL_PixelFormat *vfmt;
int current_w;
int current_h;
} SDL_VideoInfo;
#define SDL_ANYFORMAT 0x00100000
#define SDL_HWPALETTE 0x00200000
#define SDL_FULLSCREEN 0x00800000
#define SDL_RESIZABLE 0x01000000
#define SDL_NOFRAME 0x02000000
#define SDL_OPENGL 0x04000000
#define SDL_HWSURFACE 0x08000001 /**< \note Not used */
#define SDL_BUTTON_WHEELUP 4
#define SDL_BUTTON_WHEELDOWN 5
int initialized_video = 0;
static SDL_Window *SDL_VideoWindow = NULL;
static SDL_Surface *SDL_WindowSurface = NULL;
static SDL_Surface *SDL_VideoSurface = NULL;
static SDL_Surface *SDL_ShadowSurface = NULL;
static SDL_Surface *SDL_PublicSurface = NULL;
static SDL_Rect SDL_VideoViewport;
static char *wm_title = NULL;
static Uint32 SDL_VideoFlags = 0;
static SDL_GLContext *SDL_VideoContext = NULL;
static SDL_Surface *SDL_VideoIcon;
static void
SDL_WM_SetCaption(const char *title, const char *icon)
{
if (wm_title) {
SDL_free(wm_title);
}
if (title) {
wm_title = SDL_strdup(title);
} else {
wm_title = NULL;
}
SDL_SetWindowTitle(SDL_VideoWindow, wm_title);
}
static int
GetVideoDisplay()
{
const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
if ( !variable ) {
variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
}
if ( variable ) {
return SDL_atoi(variable);
} else {
return 0;
}
}
static const SDL_VideoInfo *
SDL_GetVideoInfo(void)
{
static SDL_VideoInfo info;
SDL_DisplayMode mode;
/* Memory leak, compatibility code, who cares? */
if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) {
info.vfmt = SDL_AllocFormat(mode.format);
info.current_w = mode.w;
info.current_h = mode.h;
}
return &info;
}
static SDL_Rect **
SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
{
int i, nmodes;
SDL_Rect **modes;
if (!initialized_video) {
return NULL;
}
if (!(flags & SDL_FULLSCREEN)) {
return (SDL_Rect **) (-1);
}
if (!format) {
format = SDL_GetVideoInfo()->vfmt;
}
/* Memory leak, but this is a compatibility function, who cares? */
nmodes = 0;
modes = NULL;
for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
SDL_DisplayMode mode;
int bpp;
SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
if (!mode.w || !mode.h) {
return (SDL_Rect **) (-1);
}
/* Copied from src/video/SDL_pixels.c:SDL_PixelFormatEnumToMasks */
if (SDL_BYTESPERPIXEL(mode.format) <= 2) {
bpp = SDL_BITSPERPIXEL(mode.format);
} else {
bpp = SDL_BYTESPERPIXEL(mode.format) * 8;
}
if (bpp != format->BitsPerPixel) {
continue;
}
if (nmodes > 0 && modes[nmodes - 1]->w == mode.w
&& modes[nmodes - 1]->h == mode.h) {
continue;
}
modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
if (!modes) {
return NULL;
}
modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
if (!modes[nmodes]) {
return NULL;
}
modes[nmodes]->x = 0;
modes[nmodes]->y = 0;
modes[nmodes]->w = mode.w;
modes[nmodes]->h = mode.h;
++nmodes;
}
if (modes) {
modes[nmodes] = NULL;
}
return modes;
}
static void
SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
{
int i;
if (screen == SDL_ShadowSurface) {
for (i = 0; i < numrects; ++i) {
SDL_BlitSurface(SDL_ShadowSurface, &rects[i], SDL_VideoSurface,
&rects[i]);
}
/* Fall through to video surface update */
screen = SDL_VideoSurface;
}
if (screen == SDL_VideoSurface) {
if (SDL_VideoViewport.x || SDL_VideoViewport.y) {
SDL_Rect *stackrects = SDL_stack_alloc(SDL_Rect, numrects);
SDL_Rect *stackrect;
const SDL_Rect *rect;
/* Offset all the rectangles before updating */
for (i = 0; i < numrects; ++i) {
rect = &rects[i];
stackrect = &stackrects[i];
stackrect->x = SDL_VideoViewport.x + rect->x;
stackrect->y = SDL_VideoViewport.y + rect->y;
stackrect->w = rect->w;
stackrect->h = rect->h;
}
SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, stackrects, numrects);
SDL_stack_free(stackrects);
} else {
SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, rects, numrects);
}
}
}
static void
SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
{
if (screen) {
SDL_Rect rect;
/* Fill the rectangle */
rect.x = (int) x;
rect.y = (int) y;
rect.w = (int) (w ? w : screen->w);
rect.h = (int) (h ? h : screen->h);
SDL_UpdateRects(screen, 1, &rect);
}
}
static int
SDL_Flip(SDL_Surface * screen)
{
SDL_UpdateRect(screen, 0, 0, 0, 0);
return 0;
}
/*
* Calculate the pad-aligned scanline width of a surface
*/
static int
SDL_CalculatePitch(SDL_Surface * surface)
{
int pitch;
/* Surface should be 4-byte aligned for speed */
pitch = surface->w * surface->format->BytesPerPixel;
switch (surface->format->BitsPerPixel) {
case 1:
pitch = (pitch + 7) / 8;
break;
case 4:
pitch = (pitch + 1) / 2;
break;
default:
break;
}
pitch = (pitch + 3) & ~3; /* 4-byte aligning */
return (pitch);
}
static void
SDL_InvalidateMap(SDL_BlitMap * map)
{
if (!map) {
return;
}
if (map->dst) {
/* Release our reference to the surface - see the note below */
if (--map->dst->refcount <= 0) {
SDL_FreeSurface(map->dst);
}
}
map->dst = NULL;
map->src_palette_version = 0;
map->dst_palette_version = 0;
if (map->info.table) {
SDL_free(map->info.table);
map->info.table = NULL;
}
}
static void
SDL_GL_SwapBuffers(void)
{
SDL_GL_SwapWindow(SDL_VideoWindow);
}
static int
SDL_WM_ToggleFullScreen(SDL_Surface * surface)
{
int length;
void *pixels;
Uint8 *src, *dst;
int row;
int window_w;
int window_h;
if (!SDL_PublicSurface) {
SDL_SetError("SDL_SetVideoMode() hasn't been called");
return 0;
}
/* Copy the old bits out */
length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel;
pixels = SDL_malloc(SDL_PublicSurface->h * length);
if (pixels && SDL_PublicSurface->pixels) {
src = (Uint8*)SDL_PublicSurface->pixels;
dst = (Uint8*)pixels;
for (row = 0; row < SDL_PublicSurface->h; ++row) {
SDL_memcpy(dst, src, length);
src += SDL_PublicSurface->pitch;
dst += length;
}
}
/* Do the physical mode switch */
if (SDL_GetWindowFlags(SDL_VideoWindow) & SDL_WINDOW_FULLSCREEN) {
if (SDL_SetWindowFullscreen(SDL_VideoWindow, 0) < 0) {
return 0;
}
SDL_PublicSurface->flags &= ~SDL_FULLSCREEN;
} else {
if (SDL_SetWindowFullscreen(SDL_VideoWindow, 1) < 0) {
return 0;
}
SDL_PublicSurface->flags |= SDL_FULLSCREEN;
}
/* Recreate the screen surface */
SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow);
if (!SDL_WindowSurface) {
/* We're totally hosed... */
return 0;
}
/* Center the public surface in the window surface */
SDL_GetWindowSize(SDL_VideoWindow, &window_w, &window_h);
SDL_VideoViewport.x = (window_w - SDL_VideoSurface->w)/2;
SDL_VideoViewport.y = (window_h - SDL_VideoSurface->h)/2;
SDL_VideoViewport.w = SDL_VideoSurface->w;
SDL_VideoViewport.h = SDL_VideoSurface->h;
/* Do some shuffling behind the application's back if format changes */
if (SDL_VideoSurface->format->format != SDL_WindowSurface->format->format) {
if (SDL_ShadowSurface) {
if (SDL_ShadowSurface->format->format == SDL_WindowSurface->format->format) {
/* Whee! We don't need a shadow surface anymore! */
SDL_VideoSurface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(SDL_VideoSurface);
SDL_free(SDL_ShadowSurface->pixels);
SDL_VideoSurface = SDL_ShadowSurface;
SDL_VideoSurface->flags |= SDL_PREALLOC;
SDL_ShadowSurface = NULL;
} else {
/* No problem, just change the video surface format */
SDL_FreeFormat(SDL_VideoSurface->format);
SDL_VideoSurface->format = SDL_WindowSurface->format;
SDL_VideoSurface->format->refcount++;
SDL_InvalidateMap(SDL_ShadowSurface->map);
}
} else {
/* We can make the video surface the shadow surface */
SDL_ShadowSurface = SDL_VideoSurface;
SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface);
SDL_ShadowSurface->pixels = SDL_malloc(SDL_ShadowSurface->h * SDL_ShadowSurface->pitch);
if (!SDL_ShadowSurface->pixels) {
/* Uh oh, we're hosed */
SDL_ShadowSurface = NULL;
return 0;
}
SDL_ShadowSurface->flags &= ~SDL_PREALLOC;
SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0);
SDL_VideoSurface->flags = SDL_ShadowSurface->flags;
SDL_VideoSurface->flags |= SDL_PREALLOC;
SDL_FreeFormat(SDL_VideoSurface->format);
SDL_VideoSurface->format = SDL_WindowSurface->format;
SDL_VideoSurface->format->refcount++;
SDL_VideoSurface->w = SDL_ShadowSurface->w;
SDL_VideoSurface->h = SDL_ShadowSurface->h;
}
}
/* Update the video surface */
SDL_VideoSurface->pitch = SDL_WindowSurface->pitch;
SDL_VideoSurface->pixels = (void *)((Uint8 *)SDL_WindowSurface->pixels +
SDL_VideoViewport.y * SDL_VideoSurface->pitch +
SDL_VideoViewport.x * SDL_VideoSurface->format->BytesPerPixel);
SDL_SetClipRect(SDL_VideoSurface, NULL);
/* Copy the old bits back */
if (pixels) {
src = (Uint8*)pixels;
dst = (Uint8*)SDL_PublicSurface->pixels;
for (row = 0; row < SDL_PublicSurface->h; ++row) {
SDL_memcpy(dst, src, length);
src += length;
dst += SDL_PublicSurface->pitch;
}
SDL_Flip(SDL_PublicSurface);
SDL_free(pixels);
}
/* We're done! */
return 1;
}
static void
ClearVideoSurface()
{
if (SDL_ShadowSurface) {
SDL_FillRect(SDL_ShadowSurface, NULL,
SDL_MapRGB(SDL_ShadowSurface->format, 0, 0, 0));
}
SDL_FillRect(SDL_WindowSurface, NULL, 0);
SDL_UpdateWindowSurface(SDL_VideoWindow);
}
static int
SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
{
int w, h;
/* We can't resize something we don't have... */
if (!SDL_VideoSurface) {
return -1;
}
/* We probably have to recreate the window in fullscreen mode */
if (flags & SDL_FULLSCREEN) {
return -1;
}
/* I don't think there's any change we can gracefully make in flags */
if (flags != SDL_VideoFlags) {
return -1;
}
if (bpp != SDL_VideoSurface->format->BitsPerPixel) {
return -1;
}
/* Resize the window */
SDL_GetWindowSize(SDL_VideoWindow, &w, &h);
if (w != width || h != height) {
SDL_SetWindowSize(SDL_VideoWindow, width, height);
}
/* If we're in OpenGL mode, just resize the stub surface and we're done! */
if (flags & SDL_OPENGL) {
SDL_VideoSurface->w = width;
SDL_VideoSurface->h = height;
return 0;
}
SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow);
if (!SDL_WindowSurface) {
return -1;
}
if (SDL_VideoSurface->format != SDL_WindowSurface->format) {
return -1;
}
SDL_VideoSurface->w = width;
SDL_VideoSurface->h = height;
SDL_VideoSurface->pixels = SDL_WindowSurface->pixels;
SDL_VideoSurface->pitch = SDL_WindowSurface->pitch;
SDL_SetClipRect(SDL_VideoSurface, NULL);
if (SDL_ShadowSurface) {
SDL_ShadowSurface->w = width;
SDL_ShadowSurface->h = height;
SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface);
SDL_ShadowSurface->pixels =
SDL_realloc(SDL_ShadowSurface->pixels,
SDL_ShadowSurface->h * SDL_ShadowSurface->pitch);
SDL_SetClipRect(SDL_ShadowSurface, NULL);
SDL_InvalidateMap(SDL_ShadowSurface->map);
} else {
SDL_PublicSurface = SDL_VideoSurface;
}
ClearVideoSurface();
return 0;
}
static int
SDL_CompatEventFilter(void *userdata, SDL_Event * event)
{
SDL_Event fake;
switch (event->type) {
case SDL_WINDOWEVENT:
switch (event->window.event) {
case SDL_WINDOWEVENT_CLOSE:
fake.type = SDL_QUIT;
SDL_PushEvent(&fake);
break;
}
case SDL_TEXTINPUT:
{
/* FIXME: Generate an old style key repeat event if needed */
//printf("TEXTINPUT: '%s'\n", event->text.text);
break;
}
case SDL_MOUSEMOTION:
{
event->motion.x -= SDL_VideoViewport.x;
event->motion.y -= SDL_VideoViewport.y;
break;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
event->button.x -= SDL_VideoViewport.x;
event->button.y -= SDL_VideoViewport.y;
break;
}
case SDL_MOUSEWHEEL:
{
Uint8 button;
int x, y;
if (event->wheel.y == 0) {
break;
}
SDL_GetMouseState(&x, &y);
if (event->wheel.y > 0) {
button = SDL_BUTTON_WHEELUP;
} else {
button = SDL_BUTTON_WHEELDOWN;
}
fake.button.button = button;
fake.button.x = x;
fake.button.y = y;
fake.button.windowID = event->wheel.windowID;
fake.type = SDL_MOUSEBUTTONDOWN;
fake.button.state = SDL_PRESSED;
SDL_PushEvent(&fake);
fake.type = SDL_MOUSEBUTTONUP;
fake.button.state = SDL_RELEASED;
SDL_PushEvent(&fake);
break;
}
}
return 1;
}
static void
GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
{
int display = GetVideoDisplay();
const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
const char *center = SDL_getenv("SDL_VIDEO_CENTERED");
if (window) {
if (SDL_sscanf(window, "%d,%d", x, y) == 2) {
return;
}
if (SDL_strcmp(window, "center") == 0) {
center = window;
}
}
if (center) {
*x = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
*y = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
}
}
static SDL_Surface *
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
{
SDL_DisplayMode desktop_mode;
int display = GetVideoDisplay();
int window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display);
int window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display);
int window_w;
int window_h;
Uint32 window_flags;
Uint32 surface_flags;
if (!initialized_video) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
return NULL;
}
initialized_video = 1;
}
SDL_GetDesktopDisplayMode(display, &desktop_mode);
if (width == 0) {
width = desktop_mode.w;
}
if (height == 0) {
height = desktop_mode.h;
}
if (bpp == 0) {
bpp = SDL_BITSPERPIXEL(desktop_mode.format);
}
/* See if we can simply resize the existing window and surface */
if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) {
return SDL_PublicSurface;
}
/* Destroy existing window */
SDL_PublicSurface = NULL;
if (SDL_ShadowSurface) {
SDL_ShadowSurface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(SDL_ShadowSurface);
SDL_ShadowSurface = NULL;
}
if (SDL_VideoSurface) {
SDL_VideoSurface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(SDL_VideoSurface);
SDL_VideoSurface = NULL;
}
if (SDL_VideoContext) {
/* SDL_GL_MakeCurrent(0, NULL); *//* Doesn't do anything */
SDL_GL_DeleteContext(SDL_VideoContext);
SDL_VideoContext = NULL;
}
if (SDL_VideoWindow) {
SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y);
SDL_DestroyWindow(SDL_VideoWindow);
}
/* Set up the event filter */
if (!SDL_GetEventFilter(NULL, NULL)) {
SDL_SetEventFilter(SDL_CompatEventFilter, NULL);
}
/* Create a new window */
window_flags = SDL_WINDOW_SHOWN;
if (flags & SDL_FULLSCREEN) {
window_flags |= SDL_WINDOW_FULLSCREEN;
}
if (flags & SDL_OPENGL) {
window_flags |= SDL_WINDOW_OPENGL;
}
if (flags & SDL_RESIZABLE) {
window_flags |= SDL_WINDOW_RESIZABLE;
}
if (flags & SDL_NOFRAME) {
window_flags |= SDL_WINDOW_BORDERLESS;
}
GetEnvironmentWindowPosition(width, height, &window_x, &window_y);
SDL_VideoWindow =
SDL_CreateWindow(wm_title, window_x, window_y, width, height,
window_flags);
if (!SDL_VideoWindow) {
return NULL;
}
SDL_SetWindowIcon(SDL_VideoWindow, SDL_VideoIcon);
window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
surface_flags = 0;
if (window_flags & SDL_WINDOW_FULLSCREEN) {
surface_flags |= SDL_FULLSCREEN;
}
if ((window_flags & SDL_WINDOW_OPENGL) && (flags & SDL_OPENGL)) {
surface_flags |= SDL_OPENGL;
}
if (window_flags & SDL_WINDOW_RESIZABLE) {
surface_flags |= SDL_RESIZABLE;
}
if (window_flags & SDL_WINDOW_BORDERLESS) {
surface_flags |= SDL_NOFRAME;
}
SDL_VideoFlags = flags;
/* If we're in OpenGL mode, just create a stub surface and we're done! */
if (flags & SDL_OPENGL) {
SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow);
if (!SDL_VideoContext) {
return NULL;
}
if (SDL_GL_MakeCurrent(SDL_VideoWindow, SDL_VideoContext) < 0) {
return NULL;
}
SDL_VideoSurface =
SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
if (!SDL_VideoSurface) {
return NULL;
}
SDL_VideoSurface->flags |= surface_flags;
SDL_PublicSurface = SDL_VideoSurface;
return SDL_PublicSurface;
}
/* Create the screen surface */
SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow);
if (!SDL_WindowSurface) {
return NULL;
}
/* Center the public surface in the window surface */
SDL_GetWindowSize(SDL_VideoWindow, &window_w, &window_h);
SDL_VideoViewport.x = (window_w - width)/2;
SDL_VideoViewport.y = (window_h - height)/2;
SDL_VideoViewport.w = width;
SDL_VideoViewport.h = height;
SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0);
SDL_VideoSurface->flags |= surface_flags;
SDL_VideoSurface->flags |= SDL_DONTFREE;
SDL_FreeFormat(SDL_VideoSurface->format);
SDL_VideoSurface->format = SDL_WindowSurface->format;
SDL_VideoSurface->format->refcount++;
SDL_VideoSurface->w = width;
SDL_VideoSurface->h = height;
SDL_VideoSurface->pitch = SDL_WindowSurface->pitch;
SDL_VideoSurface->pixels = (void *)((Uint8 *)SDL_WindowSurface->pixels +
SDL_VideoViewport.y * SDL_VideoSurface->pitch +
SDL_VideoViewport.x * SDL_VideoSurface->format->BytesPerPixel);
SDL_SetClipRect(SDL_VideoSurface, NULL);
/* Create a shadow surface if necessary */
if ((bpp != SDL_VideoSurface->format->BitsPerPixel)
&& !(flags & SDL_ANYFORMAT)) {
SDL_ShadowSurface =
SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0);
if (!SDL_ShadowSurface) {
return NULL;
}
SDL_ShadowSurface->flags |= surface_flags;
SDL_ShadowSurface->flags |= SDL_DONTFREE;
/* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
if (SDL_ShadowSurface->format->palette) {
SDL_ShadowSurface->flags |= SDL_HWPALETTE;
//TODO SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
// SDL_ShadowSurface->format->BitsPerPixel);
}
SDL_FillRect(SDL_ShadowSurface, NULL,
SDL_MapRGB(SDL_ShadowSurface->format, 0, 0, 0));
}
SDL_PublicSurface =
(SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface);
ClearVideoSurface();
/* We're finally done! */
return SDL_PublicSurface;
}