Path: blob/master/libmupen64plus/mupen64plus-video-glide64mk2/src/Glide64/Gfx_1.3.h
2 views
/*1* Glide64 - Glide video plugin for Nintendo 64 emulators.2* Copyright (c) 2002 Dave20013* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920//****************************************************************21//22// Glide64 - Glide Plugin for Nintendo 64 emulators23// Project started on December 29th, 200124//25// Authors:26// Dave2001, original author, founded the project in 2001, left it in 200227// Gugaman, joined the project in 2002, left it in 200228// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 200229// Hiroshi 'KoolSmoky' Morii, joined the project in 200730//31//****************************************************************32//33// To modify Glide64:34// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.35// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.36//37//****************************************************************3839/**********************************************************************************40Common gfx plugin spec, version #1.3 maintained by zilmar ([email protected])4142All questions or suggestions should go through the mailing list.43http://www.egroups.com/group/Plugin64-Dev44***********************************************************************************4546Notes:47------4849Setting the approprate bits in the MI_INTR_REG and calling CheckInterrupts which50are both passed to the DLL in InitiateGFX will generate an Interrupt from with in51the plugin.5253The Setting of the RSP flags and generating an SP interrupt should not be done in54the plugin5556**********************************************************************************/5758// THIS FILE IS A PRECOMPILED HEADER TO DECREASE BUILD TIME. INCLUDE ALL STANDARD59// .H FILES HERE6061#ifndef _GFX_H_INCLUDED__62#define _GFX_H_INCLUDED__6364#include "winlnxdefs.h"65#include "m64p.h"6667#include <stdio.h>68#include <SDL_mutex.h>69#include <fstream>70#include <stdlib.h>71#include <stddef.h> // offsetof72#include <string.h>73#include <stdarg.h>74#include <glide.h>75#include "GlideExtensions.h"76#include "rdp.h"77#include "Keys.h"7879#include <iostream>80#include <fstream>8182#if defined __VISUALC__83#define GLIDE64_TRY __try84#define GLIDE64_CATCH __except (EXCEPTION_EXECUTE_HANDLER)85#else86#define GLIDE64_TRY try87#define GLIDE64_CATCH catch (...)88#endif8990#ifndef WIN3291typedef int HWND;92#endif939495#if defined(__cplusplus)96extern "C" {97#endif9899#define _ENDUSER_RELEASE_100101//********102// Logging103104// ********************************105// ** TAKE OUT BEFORE RELEASE!!! **106//#define LOGGING // log of spec functions called107//#define LOG_KEY // says "Key!!!" in the log when space bar is pressed108109//#define LOG_UCODE110111//#define ALTTAB_FIX112113//#define EXTREME_LOGGING // lots of logging114// note that some of these things are inserted/removed115// from within the code & may not be changed by this define.116117//#define TLUT_LOGGING // log every entry of the TLUT?118// ********************************119120#define FPS // fps counter able? (not enabled necessarily)121122#define LOGNOTKEY // Log if not pressing:123#define LOGKEY 0x11 // this key (CONTROL)124125//#define LOG_COMMANDS // log the whole 64-bit command as (0x........, 0x........)126127#define CATCH_EXCEPTIONS // catch exceptions so it doesn't freeze and will report128// "The gfx plugin has caused an exception" instead.129130#define FLUSH // flush the file buffer. slower logging, but makes sure131// the command is logged before continuing (in case of132// crash or exception, the log will not be cut short)133#ifndef _ENDUSER_RELEASE_134#define RDP_LOGGING // Allow logging (will not log unless checked, but allows the option)135// Logging functions will not be compiled if this is not present.136//#define RDP_ERROR_LOG137#endif138139#define FPS_FRAMES 10 // Number of frames in which to make an FPS count140141//#define SHOW_FULL_TEXVIEWER // shows the entire contents of the texture in the cache viewer,142// usually used to debug clamping issues.143144145// Usually enabled146#define LARGE_TEXTURE_HANDLING // allow large-textured objects to be split?147148#ifdef ALTTAB_FIX149extern HHOOK hhkLowLevelKybd;150extern LRESULT CALLBACK LowLevelKeyboardProc(int nCode,151WPARAM wParam, LPARAM lParam);152#endif153154// Simulations155//#define SIMULATE_VOODOO1156//#define SIMULATE_BANSHEE157//********158159#ifdef EXT_LOGGING160extern std::ofstream extlog;161#define EXT(x) extlog.open("ext.txt",std::ios::app); extlog << x; extlog.close();162#else163#define EXT(x)164#endif165166#ifndef _ENDUSER_RELEASE_167#define UNIMP_LOG // Keep enabled, option in dialog168#define BRIGHT_RED // Keep enabled, option in dialog169#endif170171#define COLORED_DEBUGGER // ;) pretty colors172173#ifdef FPS174extern LARGE_INTEGER fps_last;175extern LARGE_INTEGER fps_next;176extern float fps;177extern wxUint32 fps_count;178#endif179180// rdram mask at 0x400000 bytes (bah, not right for majora's mask)181//#define BMASK 0x7FFFFF182extern unsigned long BMASK;183#define WMASK 0x3FFFFF184#define DMASK 0x1FFFFF185186extern wxUint32 update_screen_count;187extern wxUint32 resolutions[0x18][2];188189int CheckKeyPressed(int key, int mask);190191//#define PERFORMANCE192#ifdef PERFORMANCE193extern int64 perf_cur;194extern int64 perf_next;195#endif196197//#ifdef LOGGING198//extern std::ofstream loga;199//#define LOG(X) loga.open("log.txt",std::ios::app); loga << (...); loga.flush(); loga.close();200201//#else202#ifndef OLD_API203#define LOG(...) WriteLog(M64MSG_INFO, __VA_ARGS__)204#define VLOG(...) WriteLog(M64MSG_VERBOSE, __VA_ARGS__)205#define WARNLOG(...) WriteLog(M64MSG_WARNING, __VA_ARGS__)206#define ERRLOG(...) WriteLog(M64MSG_ERROR, __VA_ARGS__)207#else208#define LOG(...) printf(__VA_ARGS__)209#define VLOG(...)210#define WARNLOG(...) printf(__VA_ARGS__)211#define ERRLOG(X, ...) str.Printf(_T(X), __VA_ARGS__); wxMessageBox(str, _T("Error"), wxOK | wxICON_EXCLAMATION, GFXWindow)212#define ERRLOG(X) str.Printf(_T(X)); wxMessageBox(str, _T("Error"), wxOK | wxICON_EXCLAMATION, GFXWindow)213#endif214215216#ifdef RDP_LOGGING217extern int log_open;218extern std::ofstream rdp_log;219#define OPEN_RDP_LOG() EXT("OPEN_RDP_LOG ()\n"); if (settings.logging && !log_open) { rdp_log.open ("rdp.txt"); log_open=TRUE; }220#define CLOSE_RDP_LOG() EXT("CLOSE_RDP_LOG ()\n"); if (settings.logging && log_open) { rdp_log.close (); log_open=FALSE; }221222#ifdef LOGNOTKEY223#define LRDP(x) EXT("RDP (...)\n"); if (settings.logging && log_open) { if (!CheckKeyPressed(LOGKEY,0x8000)) { rdp_log << x; rdp_log.flush(); } }224#else225#define LRDP(x) EXT("RDP (...)\n"); if (settings.logging && log_open) { rdp_log << x; rdp_log.flush(); }226#endif227228#else229#define OPEN_RDP_LOG()230#define CLOSE_RDP_LOG()231#define LRDP(x)232#endif233234235#ifdef RDP_ERROR_LOG236extern int elog_open;237extern std::ofstream rdp_err;238#define OPEN_RDP_E_LOG() EXT("OPEN_RDP_E_LOG ()\n"); if (settings.elogging && !elog_open) { rdp_err.open ("rdp_e.txt"); elog_open=TRUE; }239#define CLOSE_RDP_E_LOG() EXT("CLOSE_RDP_LOG ()\n"); if (settings.elogging && elog_open) { rdp_err.close (); elog_open=FALSE; }240#define RDP_E(x) if (settings.elogging) { FRDP_E (x); }241#else242#define OPEN_RDP_E_LOG()243#define CLOSE_RDP_E_LOG()244#define RDP_E(x)245#endif246247__inline void FRDP (const char *fmt, ...)248{249#ifdef RDP_LOGGING250if (!settings.logging || !log_open) return;251252#ifdef LOGNOTKEY253if (CheckKeyPressed(LOGKEY,0x8000)) return;254#endif255256va_list ap;257va_start(ap, fmt);258vsprintf(out_buf, fmt, ap);259LRDP (out_buf);260va_end(ap);261#endif262}263__inline void FRDP_E (const char *fmt, ...)264{265#ifdef RDP_ERROR_LOG266if (!settings.elogging || !elog_open) return;267268#ifdef LOGNOTKEY269if (CheckKeyPressed(LOGKEY,0x8000)) return;270#endif271272sprintf (out_buf, "%08lx: (%08lx, %08lx) ", rdp.pc[rdp.pc_i]-8, rdp.cmd0, rdp.cmd1);273rdp_err << out_buf;274275va_list ap2;276va_start(ap2, fmt);277vsprintf(out_buf, fmt, ap2);278rdp_err << out_buf;279rdp_err.flush();280va_end(ap2);281#endif282}283284extern int fullscreen;285extern int romopen;286extern int to_fullscreen;287extern int debugging;288289extern int evoodoo;290extern int ev_fullscreen;291292extern SDL_sem *mutexProcessDList;293extern int exception;294295// extern wxMutex *mutexProcessDList;296297int InitGfx (int);298void ReleaseGfx ();299300// The highest 8 bits are the segment # (1-16), and the lower 24 bits are the offset to301// add to it.302__inline wxUint32 segoffset (wxUint32 so)303{304return (rdp.segment[(so>>24)&0x0f] + (so&BMASK))&BMASK;305}306307/* Plugin types */308#define PLUGIN_TYPE_GFX 2309310// this is already defined in API311/*312#ifdef __WINDOWS__313#define EXPORT __declspec(dllexport)314#define CALL _cdecl315#else316#define EXPORT extern317#define CALL318#endif319*/320/***** Structures *****/321typedef struct {322wxUint16 Version; /* Set to 0x0103 */323wxUint16 Type; /* Set to PLUGIN_TYPE_GFX */324char Name[100]; /* Name of the DLL */325326/* If DLL supports memory these memory options then set them to TRUE or FALSE327if it does not support it */328int NormalMemory; /* a normal wxUint8 array */329int MemoryBswaped; /* a normal wxUint8 array where the memory has been pre330bswap on a dword (32 bits) boundry */331} PLUGIN_INFO;332333/*334typedef struct {335// <removed, already defined in API>336} GFX_INFO;337*/338extern GFX_INFO gfx;339// extern wxWindow * GFXWindow;340extern bool no_dlist;341342typedef GrContext_t (FX_CALL *GRWINOPENEXT)( FxU32 hWnd,343GrScreenResolution_t resolution,344GrScreenRefresh_t refresh,345GrColorFormat_t format,346GrOriginLocation_t origin,347GrPixelFormat_t pixelformat,348int nColBuffers,349int nAuxBuffers) ;350351typedef void (FX_CALL *GRTEXBUFFEREXT)( GrChipID_t tmu,352FxU32 startAddress,353GrLOD_t lodmin,354GrLOD_t lodmax,355GrAspectRatio_t aspect,356GrTextureFormat_t fmt,357FxU32 evenOdd) ;358359typedef void (FX_CALL *GRAUXBUFFEREXT)( GrBuffer_t buffer ) ;360361typedef void (FX_CALL *GRCOLORCOMBINEEXT) (GrCCUColor_t a,362GrCombineMode_t a_mode,363GrCCUColor_t b,364GrCombineMode_t b_mode,365GrCCUColor_t c,366FxBool c_invert,367GrCCUColor_t d,368FxBool d_invert,369FxU32 shift,370FxBool invert) ;371372typedef void (FX_CALL *GRTEXCOLORCOMBINEEXT) (GrChipID_t tmu,373GrTCCUColor_t a,374GrCombineMode_t a_mode,375GrTCCUColor_t b,376GrCombineMode_t b_mode,377GrTCCUColor_t c,378FxBool c_invert,379GrTCCUColor_t d,380FxBool d_invert,381FxU32 shift,382FxBool invert);383384typedef void (FX_CALL *GRCONSTANTCOLORVALUEEXT)385(GrChipID_t tmu,386GrColor_t value);387388typedef void (FX_CALL *GRSTIPPLE)( FxI32 mode) ;389390typedef void (FX_CALL *GRCONFIGWRAPPEREXT)(FxI32, FxI32, FxBool, FxBool);391392typedef GrScreenResolution_t (FX_CALL *GRWRAPPERFULLSCREENRESOLUTIONEXT)(wxUint32*, wxUint32*);393394typedef char ** (FX_CALL *GRQUERYRESOLUTIONSEXT)(FxI32*);395396typedef int (*GETTEXADDR)(int tmu, int texsize);397398extern GRTEXBUFFEREXT grTextureBufferExt;399extern GRTEXBUFFEREXT grTextureAuxBufferExt;400extern GRAUXBUFFEREXT grAuxBufferExt;401extern GRSTIPPLE grStippleModeExt;402extern GRSTIPPLE grStipplePatternExt;403extern GETTEXADDR GetTexAddr;404405#ifndef GR_STIPPLE_DISABLE406#define GR_STIPPLE_DISABLE 0x0407#define GR_STIPPLE_PATTERN 0x1408#define GR_STIPPLE_ROTATE 0x2409#endif410411void ReadSettings ();412void ReadSpecialSettings (const char * name);413void WriteSettings (bool saveEmulationSettings = false);414415#if 0416//TODO: remove417/******************************************************************418Function: CaptureScreen419Purpose: This function dumps the current frame to a file420input: pointer to the directory to save the file to421output: none422*******************************************************************/423EXPORT void CALL CaptureScreen ( char * Directory );424425/******************************************************************426Function: ChangeWindow427Purpose: to change the window between fullscreen and window428mode. If the window was in fullscreen this should429change the screen to window mode and vice vesa.430input: none431output: none432*******************************************************************/433EXPORT void CALL ChangeWindow (void);434435/******************************************************************436Function: CloseDLL437Purpose: This function is called when the emulator is closing438down allowing the dll to de-initialise.439input: none440output: none441*******************************************************************/442EXPORT void CALL CloseDLL (void);443444/******************************************************************445Function: DllAbout446Purpose: This function is optional function that is provided447to give further information about the DLL.448input: a handle to the window that calls this function449output: none450*******************************************************************/451EXPORT void CALL DllAbout ( HWND hParent );452453/******************************************************************454Function: DllConfig455Purpose: This function is optional function that is provided456to allow the user to configure the dll457input: a handle to the window that calls this function458output: none459*******************************************************************/460EXPORT void CALL DllConfig ( HWND hParent );461462/******************************************************************463Function: DllTest464Purpose: This function is optional function that is provided465to allow the user to test the dll466input: a handle to the window that calls this function467output: none468*******************************************************************/469EXPORT void CALL DllTest ( HWND hParent );470471472EXPORT void CALL ReadScreen(void **dest, int *width, int *height);473474/******************************************************************475Function: DrawScreen476Purpose: This function is called when the emulator receives a477WM_PAINT message. This allows the gfx to fit in when478it is being used in the desktop.479input: none480output: none481*******************************************************************/482EXPORT void CALL DrawScreen (void);483484/******************************************************************485Function: GetDllInfo486Purpose: This function allows the emulator to gather information487about the dll by filling in the PluginInfo structure.488input: a pointer to a PLUGIN_INFO stucture that needs to be489filled by the function. (see def above)490output: none491*******************************************************************/492EXPORT void CALL GetDllInfo ( PLUGIN_INFO * PluginInfo );493494/******************************************************************495Function: InitiateGFX496Purpose: This function is called when the DLL is started to give497information from the emulator that the n64 graphics498uses. This is not called from the emulation thread.499Input: Gfx_Info is passed to this function which is defined500above.501Output: TRUE on success502FALSE on failure to initialise503504** note on interrupts **:505To generate an interrupt set the appropriate bit in MI_INTR_REG506and then call the function CheckInterrupts to tell the emulator507that there is a waiting interrupt.508*******************************************************************/509EXPORT int CALL InitiateGFX (GFX_INFO Gfx_Info);510511/******************************************************************512Function: MoveScreen513Purpose: This function is called in response to the emulator514receiving a WM_MOVE passing the xpos and ypos passed515from that message.516input: xpos - the x-coordinate of the upper-left corner of the517client area of the window.518ypos - y-coordinate of the upper-left corner of the519client area of the window.520output: none521*******************************************************************/522EXPORT void CALL MoveScreen (int xpos, int ypos);523524/******************************************************************525Function: ProcessDList526Purpose: This function is called when there is a Dlist to be527processed. (High level GFX list)528input: none529output: none530*******************************************************************/531EXPORT void CALL ProcessDList(void);532533/******************************************************************534Function: ProcessRDPList535Purpose: This function is called when there is a Dlist to be536processed. (Low level GFX list)537input: none538output: none539*******************************************************************/540EXPORT void CALL ProcessRDPList(void);541542/******************************************************************543Function: RomClosed544Purpose: This function is called when a rom is closed.545input: none546output: none547*******************************************************************/548EXPORT void CALL RomClosed (void);549550/******************************************************************551Function: RomOpen552Purpose: This function is called when a rom is open. (from the553emulation thread)554input: none555output: none556*******************************************************************/557EXPORT void CALL RomOpen (void);558559/******************************************************************560Function: ShowCFB561Purpose: Useally once Dlists are started being displayed, cfb is562ignored. This function tells the dll to start displaying563them again.564input: none565output: none566*******************************************************************/567EXPORT void CALL ShowCFB (void);568569/******************************************************************570Function: UpdateScreen571Purpose: This function is called in response to a vsync of the572screen were the VI bit in MI_INTR_REG has already been573set574input: none575output: none576*******************************************************************/577EXPORT void CALL UpdateScreen (void);578579/******************************************************************580Function: ViStatusChanged581Purpose: This function is called to notify the dll that the582ViStatus registers value has been changed.583input: none584output: none585*******************************************************************/586EXPORT void CALL ViStatusChanged (void);587588/******************************************************************589Function: ViWidthChanged590Purpose: This function is called to notify the dll that the591ViWidth registers value has been changed.592input: none593output: none594*******************************************************************/595EXPORT void CALL ViWidthChanged (void);596597598/******************************************************************599Function: FrameBufferWrite600Purpose: This function is called to notify the dll that the601frame buffer has been modified by CPU at the given address.602input: addr rdram address603val val604size 1 = wxUint8, 2 = wxUint16, 4 = wxUint32605output: none606*******************************************************************/607EXPORT void CALL FBWrite(wxUint32, wxUint32);608609typedef struct610{611wxUint32 addr;612wxUint32 val;613wxUint32 size; // 1 = wxUint8, 2 = wxUint16, 4=wxUint32614} FrameBufferModifyEntry;615616/******************************************************************617Function: FrameBufferWriteList618Purpose: This function is called to notify the dll that the619frame buffer has been modified by CPU at the given address.620input: FrameBufferModifyEntry *plist621size = size of the plist, max = 1024622output: none623*******************************************************************/624EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, wxUint32 size);625626/******************************************************************627Function: FrameBufferRead628Purpose: This function is called to notify the dll that the629frame buffer memory is beening read at the given address.630DLL should copy content from its render buffer to the frame buffer631in N64 RDRAM632DLL is responsible to maintain its own frame buffer memory addr list633DLL should copy 4KB block content back to RDRAM frame buffer.634Emulator should not call this function again if other memory635is read within the same 4KB range636input: addr rdram address637val val638size 1 = wxUint8, 2 = wxUint16, 4 = wxUint32639output: none640*******************************************************************/641EXPORT void CALL FBRead(wxUint32 addr);642643/************************************************************************644Function: FBGetFrameBufferInfo645Purpose: This function is called by the emulator core to retrieve depth646buffer information from the video plugin in order to be able647to notify the video plugin about CPU depth buffer read/write648operations649650size:651= 1 byte652= 2 word (16 bit) <-- this is N64 default depth buffer format653= 4 dword (32 bit)654655when depth buffer information is not available yet, set all values656in the FrameBufferInfo structure to 0657658input: FrameBufferInfo *pinfo659pinfo is pointed to a FrameBufferInfo structure which to be660filled in by this function661output: Values are return in the FrameBufferInfo structure662************************************************************************/663EXPORT void CALL FBGetFrameBufferInfo(void *pinfo);664665/******************************************************************666NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE667ORIGINAL SPEC668Function: SetConfigDir669Purpose: To pass the location where config files should be read/670written to.671input: path to config directory672output: none673*******************************************************************/674EXPORT void CALL SetConfigDir(char *configDir);675#endif676677#if defined(__cplusplus)678}679#endif680#endif //_GFX_H_INCLUDED__681682683