Add a header with some plugin helper functions. Mess with the comments in PluginCallbacks.h a bit.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2417 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-01-09 01:26:52 +00:00
parent bee1bde1b3
commit eb54a7185b
2 changed files with 290 additions and 22 deletions

262
common/include/PS2Eext.h Normal file
View File

@ -0,0 +1,262 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PS2EEXT_H_INCLUDED
#define PS2EEXT_H_INCLUDED
#include <stdio.h>
#include <string>
#include <cstdarg>
#ifdef _MSC_VER
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#define EXPORT_C_(type) extern "C" type CALLBACK
#else
#include <gtk/gtk.h>
#include <cstring>
#define EXPORT_C_(type) extern "C" type
#endif
//#include "PS2Edefs.h"
static void __forceinline SysMessage(const char *fmt, ...);
static void __forceinline PluginNullConfigure(std::string desc, s32 &log);
static void __forceinline PluginNullAbout(const char *aboutText);
enum FileMode
{
READ_FILE = 0,
WRITE_FILE
};
struct PluginLog
{
bool WriteToFile, WriteToConsole;
FILE *LogFile;
bool Open(std::string logname)
{
LogFile = fopen(logname.c_str(), "w");
if (LogFile)
{
setvbuf(LogFile, NULL, _IONBF, 0);
return true;
}
return false;
}
void Close()
{
if (LogFile) fclose(LogFile);
}
void Write(const char *fmt, ...)
{
va_list list;
if (LogFile == NULL) return;
va_start(list, fmt);
if (WriteToFile) vfprintf(LogFile, fmt, list);
if (WriteToConsole) vfprintf(stdout, fmt, list);
va_end(list);
}
void WriteLn(const char *fmt, ...)
{
va_list list;
if (LogFile == NULL) return;
va_start(list, fmt);
if (WriteToFile) vfprintf(LogFile, fmt, list);
if (WriteToConsole) vfprintf(stdout, fmt, list);
va_end(list);
if (WriteToFile) fprintf(LogFile, "\n");
if (WriteToConsole) fprintf(stdout, "\n");
}
void Message(const char *fmt, ...)
{
va_list list;
char buf[256];
if (LogFile == NULL) return;
va_start(list, fmt);
vsprintf(buf, fmt, list);
va_end(list);
SysMessage(buf);
}
};
struct PluginConf
{
FILE *ConfFile;
char *PluginName;
bool Open(std::string name, FileMode mode = READ_FILE)
{
if (mode == READ_FILE)
{
ConfFile = fopen(name.c_str(), "r");
}
else
{
ConfFile = fopen(name.c_str(), "w");
}
if (ConfFile == NULL) return false;
return true;
}
void Close()
{
fclose(ConfFile);
}
int ReadInt(std::string item)
{
int value = -1;
std::string buf = item + " = %d\n";
if (ConfFile) fscanf(ConfFile, buf.c_str(), &value);
return value;
}
void WriteInt(std::string item, int value)
{
std::string buf = item + " = %d\n";
if (ConfFile) fprintf(ConfFile, buf.c_str(), value);
}
};
#ifdef __LINUX__
static void __forceinline SysMessage(const char *fmt, ...)
{
va_list list;
char msg[512];
va_start(list, fmt);
vsprintf(msg, fmt, list);
va_end(list);
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s", msg);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
static bool loggingValue = false;
static void __forceinline set_logging(GtkToggleButton *check)
{
loggingValue = gtk_toggle_button_get_active(check);
}
static void __forceinline send_ok(GtkDialog *dialog)
{
int ret = (loggingValue) ? 1 : 0;
gtk_dialog_response (dialog, ret);
}
static void __forceinline PluginNullConfigure(std::string desc, int &log)
{
GtkWidget *dialog, *label, *okay_button, *check_box;
/* Create the widgets */
dialog = gtk_dialog_new();
label = gtk_label_new (desc.c_str());
okay_button = gtk_button_new_with_label("Ok");
check_box = gtk_check_button_new_with_label("Logging");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), (log != 0));
/* Ensure that the dialog box is destroyed when the user clicks ok, and that we get the check box value. */
g_signal_connect_swapped(GTK_OBJECT (okay_button), "clicked", G_CALLBACK(send_ok), dialog);
g_signal_connect_swapped(GTK_OBJECT (check_box), "toggled", G_CALLBACK(set_logging), check_box);
/* Add all our widgets, and show everything we've added to the dialog. */
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), okay_button);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), check_box);
gtk_widget_show_all (dialog);
log = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
static void __forceinline PluginNullAbout(const char *aboutText)
{
SysMessage(aboutText);
}
#define ENTRY_POINT /* We don't need no stinkin' entry point! */
#else
static void __forceinline SysMessage(const char *fmt, ...)
{
va_list list;
char tmp[512];
va_start(list,fmt);
vsprintf(tmp,fmt,list);
va_end(list);
MessageBox( GetActiveWindow(), tmp, "Message", MB_SETFOREGROUND | MB_OK );
}
static void __forceinline PluginNullConfigure(std::string desc, s32 &log)
{
/* To do: Write a dialog box that displays a dialog box with the text in desc,
and a check box that says "Logging", checked if log !=0, and set log to
1 if it is checked on return, and 0 if it isn't. */
SysMessage("This space intentionally left blank.");
}
static void __forceinline PluginNullAbout(const char *aboutText)
{
SysMessage(aboutText);
}
#define ENTRY_POINT \
HINSTANCE hInst; \
\
BOOL APIENTRY DllMain(HANDLE hModule, /* DLL INIT*/ \
DWORD dwReason, \
LPVOID lpReserved) \
{ \
hInst = (HINSTANCE)hModule; \
return TRUE; /* very quick :)*/ \
}
#endif
#endif // PS2EEXT_H_INCLUDED

View File

@ -28,7 +28,7 @@
//
// Design Philosophies:
//
// 1. Core APIs are established using a pair of DLL bindings (one for plugin callbacks
// 1. Core APIs are established using a pair of DLL/library bindings (one for plugin callbacks
// and one for emulator callbacks), which pass structures of function pointers.
//
// 2. Plugin instance data should be attached to the end of the plugin's callback api
@ -37,7 +37,7 @@
//
// 3. All plugin callbacks use __fastcall calling convention (which passes the first
// two parameters int he ECX and EDX registers). Most compilers support this, and
// register parameter passing is actually the standard convetion on x86/64.
// register parameter passing is actually the standard convention on x86/64.
//
// Rationale: This design improves code generation efficiency, especially when using
// points 2 and 3 together (typically reduces 2 or 3 dereferences to 1 dereference).
@ -208,7 +208,10 @@ enum OSDIconTypes
// [TODO] -- dunno. What else?
// Emulators implementing their own custom non-standard icon extensions should do so
// somewhere after OSD_Icon_ReserveEnd. All values below this are
// somewhere after OSD_Icon_ReserveEnd. All values below this are reserved.
// .
// .
// .
OSD_Icon_ReserveEnd = 0x1000
};
@ -252,10 +255,10 @@ typedef struct _PS2E_ConsoleWriterAPI
// Appends an automatic newline to the specified formatted output.
void (PS2E_CALLBACK* WriteLn)( const char* fmt, ... );
// This function always appends a newline
// This function always appends a newline.
void (PS2E_CALLBACK* Error)( const char* fmt, ... );
// This function always appends a newline
// This function always appends a newline.
void (PS2E_CALLBACK* Warning)( const char* fmt, ... );
void* reserved[4];
@ -281,10 +284,10 @@ typedef struct _PS2E_ConsoleWriterWideAPI
// Appends an automatic newline to the specified formatted output.
void (PS2E_CALLBACK* WriteLn)( const wchar_t* fmt, ... );
// This function always appends a newline
// This function always appends a newline.
void (PS2E_CALLBACK* Error)( const wchar_t* fmt, ... );
// This function always appends a newline
// This function always appends a newline.
void (PS2E_CALLBACK* Warning)( const wchar_t* fmt, ... );
void* reserved[4];
@ -323,7 +326,7 @@ typedef struct _PS2E_MenuItemInfo
// Specifies the style of the menu, either Normal, Checked, Radio, or Separator.
// This option is overridden if the SubMenu field is non-NULL (in such case the
// menu assumes submenu mode)
// menu assumes submenu mode).
PS2E_MenuItemStyle Style;
// Specifies the handle of a sub menu to bind to this menu. If NULL, the menu is
@ -333,7 +336,7 @@ typedef struct _PS2E_MenuItemInfo
// Menu that this item is attached to. When this struct is passed into AddMenuItem,
// the menu item will be automatically appended to the menu specified in this field
// if the field is non-NULL (if the field is NULL then no action is taken).
// if the field is non-NULL (if the field is NULL, then no action is taken).
PS2E_MenuHandle OwnerMenu;
// When FALSE the menu item will appear grayed out to the user, and unselectable.
@ -353,7 +356,7 @@ typedef struct _PS2E_MenuItemInfo
// --------------------------------------------------------------------------------------
typedef struct _PS2E_MenuItemAPI
{
// Allocates a new MenuItem and returns it's handle. The returned item can be added to any
// Allocates a new MenuItem and returns its handle. The returned item can be added to any
// menu.
PS2E_MenuItemHandle (PS2E_CALLBACK* MenuItem_Create)( PS2E_THISPTR thisptr );
@ -399,13 +402,13 @@ typedef struct _PS2E_MenuItemAPI
// Assigns a pointer value that the plugin can use to attach user-defined data to
// specific menu items. The value can be any integer typecast if you don't actually
// eed more than an integer's worth of data.
// need more than an integers worth of data.
void (PS2E_CALLBACK* MenuItem_SetUserData)( PS2E_MenuItemHandle mitem, void* dataptr );
// Assigns a submenu to the menu item, causing it to open the sub menu in cascade
// fashion. When a submenu is assigned, the Style attribute of the menu will be
// ignored. Passing NULL into this function will clear the submenu and return the
// menu item to whatever it's current Style attribute is set to.
// menu item to whatever its current Style attribute is set to.
void (PS2E_CALLBACK* MenuItem_SetSubMenu)( PS2E_MenuItemHandle mitem, PS2E_MenuHandle submenu );
// Assigns the callback function for this menu (important!). If passed NULL, the menu
@ -487,7 +490,7 @@ typedef struct _PS2E_SessionInfo
//
typedef struct _PS2E_EmulatorInfo
{
// brief name of the emulator (ex: "PCSX2") [required]
// Brief name of the emulator (ex: "PCSX2") [required]
// Depending on the design of the emulator, this string may optionally include version
// information, however that is not recommended since it can inhibit backward support.
const char* EmuName;
@ -591,7 +594,7 @@ typedef struct _PS2E_EmulatorInfo
// Deletes the specified menu and frees its allocated memory resources. NULL pointers are
// safely ignored. Any menu items also attached to this menu will be deleted. Even if you
// do not explicitly delete your plugin's menu resources, the emulator will do automatic
// cleanup after the plugin's instance is free'd.
// cleanup after the plugin's instance is freed.
void (PS2E_CALLBACK* Menu_Delete)( PS2E_MenuHandle handle );
// Adds the specified menu item to this menu. Menu items can only belong to one menu at a
@ -1030,7 +1033,7 @@ typedef struct _PS2E_ComponentAPI_Mcd
// has its status polled - so its overhead should be minimal when possible.
//
// Returns:
// 0 if the card is not available, or 1 if it is available.
// False if the card is not available, or True if it is available.
//
BOOL (PS2E_CALLBACK* McdIsPresent)( PS2E_THISPTR thisptr, uint port, uint slot );
@ -1041,7 +1044,7 @@ typedef struct _PS2E_ComponentAPI_Mcd
// read op has finished).
//
// Returns:
// 0 on failure, and 1 on success. Emulator may use GetLastError to retrieve additional
// False on failure, and True on success. Emulator may use GetLastError to retrieve additional
// information for logging or displaying to the user.
//
BOOL (PS2E_CALLBACK* McdRead)( PS2E_THISPTR thisptr, uint port, uint slot, u8 *dest, u32 adr, int size );
@ -1052,7 +1055,7 @@ typedef struct _PS2E_ComponentAPI_Mcd
// has finished). Write cache flushing is optional.
//
// Returns:
// 0 on failure, and 1 on success. Emulator may use GetLastError to retrieve additional
// False on failure, and True on success. Emulator may use GetLastError to retrieve additional
// information for logging or displaying to the user.
//
BOOL (PS2E_CALLBACK* McdSave)( PS2E_THISPTR thisptr, uint port, uint slot, const u8 *src, u32 adr, int size );
@ -1064,7 +1067,7 @@ typedef struct _PS2E_ComponentAPI_Mcd
// has finished). Write cache flushing is optional.
//
// Returns:
// 0 on failure, and 1 on success. Emulator may use GetLastError to retrieve additional
// False on failure, and True on success. Emulator may use GetLastError to retrieve additional
// information for logging or displaying to the user.
//
BOOL (PS2E_CALLBACK* McdEraseBlock)( PS2E_THISPTR thisptr, uint port, uint slot, u32 adr );
@ -1086,9 +1089,12 @@ enum PS2E_KeyEventTypes
PS2E_KEY_DOWN
};
#define PS2E_SHIFT 1
#define PS2E_CONTROL 2
#define PS2E_ALT 4
enum PS2E_KeyModifiers
{
PS2E_SHIFT = 1,
PS2E_CONTROL = 2,
PS2E_ALT = 4
};
// --------------------------------------------------------------------------------------
// PS2E_KeyEvent
@ -1131,7 +1137,7 @@ typedef struct _PS2E_ComponentAPI_Pad
// A plugin should behave reasonably when a pad that's not plugged in is polled.
//
// Returns:
// 0 if the card/pad is not available, or 1 if it is available.
// False if the card/pad is not available, or True if it is available.
//
BOOL (PS2E_CALLBACK* PadIsPresent)( PS2E_THISPTR thisptr, uint port, uint slot );