2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002 Dave2001
4 * Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //****************************************************************
23 // Glide64 - Glide Plugin for Nintendo 64 emulators
24 // Project started on December 29th, 2001
27 // Dave2001, original author, founded the project in 2001, left it in 2002
28 // Gugaman, joined the project in 2002, left it in 2002
29 // Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002
30 // Hiroshi 'KoolSmoky' Morii, joined the project in 2007
32 //****************************************************************
35 // * 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.
36 // * 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.
38 //****************************************************************
40 /**********************************************************************************
41 Common gfx plugin spec, version #1.3 maintained by zilmar (zilmar@emulation64.com)
43 All questions or suggestions should go through the mailing list.
44 http://www.egroups.com/group/Plugin64-Dev
45 ***********************************************************************************
50 Setting the approprate bits in the MI_INTR_REG and calling CheckInterrupts which
51 are both passed to the DLL in InitiateGFX will generate an Interrupt from with in
54 The Setting of the RSP flags and generating an SP interrupt should not be done in
57 **********************************************************************************/
59 // THIS FILE IS A PRECOMPILED HEADER TO DECREASE BUILD TIME. INCLUDE ALL STANDARD
62 #ifndef _GFX_H_INCLUDED__
63 #define _GFX_H_INCLUDED__
65 #include "winlnxdefs.h"
69 #include <SDL_mutex.h>
72 #include <stddef.h> // offsetof
76 #include "GlideExtensions.h"
83 #if defined __VISUALC__
84 #define GLIDE64_TRY __try
85 #define GLIDE64_CATCH __except (EXCEPTION_EXECUTE_HANDLER)
87 #define GLIDE64_TRY try
88 #define GLIDE64_CATCH catch (...)
96 #if defined(__cplusplus)
100 #define _ENDUSER_RELEASE_
105 // ********************************
106 // ** TAKE OUT BEFORE RELEASE!!! **
107 //#define LOGGING // log of spec functions called
108 //#define LOG_KEY // says "Key!!!" in the log when space bar is pressed
109 //#define EXT_LOGGING
110 //#define PERFORMANCE
116 //#define EXTREME_LOGGING // lots of logging
117 // note that some of these things are inserted/removed
118 // from within the code & may not be changed by this define.
120 //#define TLUT_LOGGING // log every entry of the TLUT?
121 // ********************************
123 #define FPS // fps counter able? (not enabled necessarily)
125 //#define LOGNOTKEY // Log if not pressing:
126 //#define LOGKEY 0x11 // this key (CONTROL)
128 //#define LOG_COMMANDS // log the whole 64-bit command as (0x........, 0x........)
130 #define CATCH_EXCEPTIONS // catch exceptions so it doesn't freeze and will report
131 // "The gfx plugin has caused an exception" instead.
133 //#define FLUSH // flush the file buffer. slower logging, but makes sure
134 // the command is logged before continuing (in case of
135 // crash or exception, the log will not be cut short)
136 #ifndef _ENDUSER_RELEASE_
137 #define RDP_LOGGING // Allow logging (will not log unless checked, but allows the option)
138 // Logging functions will not be compiled if this is not present.
139 //#define RDP_ERROR_LOG
142 #define FPS_FRAMES 10 // Number of frames in which to make an FPS count
144 //#define SHOW_FULL_TEXVIEWER // shows the entire contents of the texture in the cache viewer,
145 // usually used to debug clamping issues.
149 //#define LARGE_TEXTURE_HANDLING // allow large-textured objects to be split?
152 extern HHOOK hhkLowLevelKybd;
153 extern LRESULT CALLBACK LowLevelKeyboardProc(int nCode,
154 WPARAM wParam, LPARAM lParam);
158 //#define SIMULATE_VOODOO1
159 //#define SIMULATE_BANSHEE
163 extern std::ofstream extlog;
164 #define EXT(x) extlog.open("ext.txt",std::ios::app); extlog << x; extlog.close();
169 #ifndef _ENDUSER_RELEASE_
170 #define UNIMP_LOG // Keep enabled, option in dialog
171 #define BRIGHT_RED // Keep enabled, option in dialog
174 #define COLORED_DEBUGGER // ;) pretty colors
177 extern LARGE_INTEGER fps_last;
178 extern LARGE_INTEGER fps_next;
180 extern wxUint32 fps_count;
183 // rdram mask at 0x400000 bytes (bah, not right for majora's mask)
184 //#define BMASK 0x7FFFFF
185 extern unsigned long BMASK;
186 #define WMASK 0x3FFFFF
187 #define DMASK 0x1FFFFF
189 extern wxUint32 update_screen_count;
190 extern wxUint32 resolutions[0x18][2];
192 int CheckKeyPressed(int key, int mask);
195 extern int64 perf_cur;
196 extern int64 perf_next;
200 //extern std::ofstream loga;
201 //#define LOG(X) loga.open("log.txt",std::ios::app); loga << (...); loga.flush(); loga.close();
205 #define LOG(...) WriteLog(M64MSG_INFO, __VA_ARGS__)
206 #define VLOG(...) WriteLog(M64MSG_VERBOSE, __VA_ARGS__)
207 #define WARNLOG(...) WriteLog(M64MSG_WARNING, __VA_ARGS__)
208 #define ERRLOG(...) WriteLog(M64MSG_ERROR, __VA_ARGS__)
210 #define LOG(...) printf(__VA_ARGS__)
212 #define WARNLOG(...) printf(__VA_ARGS__)
213 #define ERRLOG(X, ...) str.Printf(_T(X), __VA_ARGS__); wxMessageBox(str, _T("Error"), wxOK | wxICON_EXCLAMATION, GFXWindow)
214 #define ERRLOG(X) str.Printf(_T(X)); wxMessageBox(str, _T("Error"), wxOK | wxICON_EXCLAMATION, GFXWindow)
220 extern std::ofstream rdp_log;
221 #define OPEN_RDP_LOG() EXT("OPEN_RDP_LOG ()\n"); if (settings.logging && !log_open) { rdp_log.open ("rdp.txt"); log_open=TRUE; }
222 #define CLOSE_RDP_LOG() EXT("CLOSE_RDP_LOG ()\n"); if (settings.logging && log_open) { rdp_log.close (); log_open=FALSE; }
225 #define LRDP(x) EXT("RDP (...)\n"); if (settings.logging && log_open) { if (!CheckKeyPressed(LOGKEY,0x8000)) { rdp_log << x; rdp_log.flush(); } }
227 #define LRDP(x) EXT("RDP (...)\n"); if (settings.logging && log_open) { rdp_log << x; rdp_log.flush(); }
231 #define OPEN_RDP_LOG()
232 #define CLOSE_RDP_LOG()
238 extern int elog_open;
239 extern std::ofstream rdp_err;
240 #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; }
241 #define CLOSE_RDP_E_LOG() EXT("CLOSE_RDP_LOG ()\n"); if (settings.elogging && elog_open) { rdp_err.close (); elog_open=FALSE; }
242 #define RDP_E(x) if (settings.elogging) { FRDP_E (x); }
244 #define OPEN_RDP_E_LOG()
245 #define CLOSE_RDP_E_LOG()
249 __inline void FRDP (const char *fmt, ...)
252 if (!settings.logging || !log_open) return;
255 if (CheckKeyPressed(LOGKEY,0x8000)) return;
260 vsprintf(out_buf, fmt, ap);
265 __inline void FRDP_E (const char *fmt, ...)
268 if (!settings.elogging || !elog_open) return;
271 if (CheckKeyPressed(LOGKEY,0x8000)) return;
274 sprintf (out_buf, "%08lx: (%08lx, %08lx) ", rdp.pc[rdp.pc_i]-8, rdp.cmd0, rdp.cmd1);
279 vsprintf(out_buf, fmt, ap2);
286 extern int fullscreen;
288 extern int to_fullscreen;
289 extern int debugging;
292 extern int ev_fullscreen;
294 extern SDL_sem *mutexProcessDList;
295 extern int exception;
297 // extern wxMutex *mutexProcessDList;
302 // The highest 8 bits are the segment # (1-16), and the lower 24 bits are the offset to
304 __inline wxUint32 segoffset (wxUint32 so)
306 return (rdp.segment[(so>>24)&0x0f] + (so&BMASK))&BMASK;
310 #define PLUGIN_TYPE_GFX 2
312 // this is already defined in API
315 #define EXPORT __declspec(dllexport)
318 #define EXPORT extern
322 /***** Structures *****/
324 wxUint16 Version; /* Set to 0x0103 */
325 wxUint16 Type; /* Set to PLUGIN_TYPE_GFX */
326 char Name[100]; /* Name of the DLL */
328 /* If DLL supports memory these memory options then set them to TRUE or FALSE
329 if it does not support it */
330 int NormalMemory; /* a normal wxUint8 array */
331 int MemoryBswaped; /* a normal wxUint8 array where the memory has been pre
332 bswap on a dword (32 bits) boundry */
337 // <removed, already defined in API>
341 // extern wxWindow * GFXWindow;
342 extern bool no_dlist;
344 typedef GrContext_t (FX_CALL *GRWINOPENEXT)( FxU32 hWnd,
345 GrScreenResolution_t resolution,
346 GrScreenRefresh_t refresh,
347 GrColorFormat_t format,
348 GrOriginLocation_t origin,
349 GrPixelFormat_t pixelformat,
353 typedef void (FX_CALL *GRTEXBUFFEREXT)( GrChipID_t tmu,
357 GrAspectRatio_t aspect,
358 GrTextureFormat_t fmt,
361 typedef void (FX_CALL *GRAUXBUFFEREXT)( GrBuffer_t buffer ) ;
363 typedef void (FX_CALL *GRCOLORCOMBINEEXT) (GrCCUColor_t a,
364 GrCombineMode_t a_mode,
366 GrCombineMode_t b_mode,
374 typedef void (FX_CALL *GRTEXCOLORCOMBINEEXT) (GrChipID_t tmu,
376 GrCombineMode_t a_mode,
378 GrCombineMode_t b_mode,
386 typedef void (FX_CALL *GRCONSTANTCOLORVALUEEXT)
390 typedef void (FX_CALL *GRSTIPPLE)( FxI32 mode) ;
392 typedef void (FX_CALL *GRCONFIGWRAPPEREXT)(FxI32, FxI32, FxBool, FxBool);
394 typedef GrScreenResolution_t (FX_CALL *GRWRAPPERFULLSCREENRESOLUTIONEXT)(wxUint32*, wxUint32*);
396 typedef char ** (FX_CALL *GRQUERYRESOLUTIONSEXT)(FxI32*);
398 typedef int (*GETTEXADDR)(int tmu, int texsize);
400 extern GRTEXBUFFEREXT grTextureBufferExt;
401 extern GRTEXBUFFEREXT grTextureAuxBufferExt;
402 extern GRAUXBUFFEREXT grAuxBufferExt;
403 extern GRSTIPPLE grStippleModeExt;
404 extern GRSTIPPLE grStipplePatternExt;
405 extern GETTEXADDR GetTexAddr;
407 #ifndef GR_STIPPLE_DISABLE
408 #define GR_STIPPLE_DISABLE 0x0
409 #define GR_STIPPLE_PATTERN 0x1
410 #define GR_STIPPLE_ROTATE 0x2
413 void ReadSettings ();
414 void ReadSpecialSettings (const char * name);
415 void WriteSettings (bool saveEmulationSettings = false);
419 /******************************************************************
420 Function: CaptureScreen
421 Purpose: This function dumps the current frame to a file
422 input: pointer to the directory to save the file to
424 *******************************************************************/
425 EXPORT void CALL CaptureScreen ( char * Directory );
427 /******************************************************************
428 Function: ChangeWindow
429 Purpose: to change the window between fullscreen and window
430 mode. If the window was in fullscreen this should
431 change the screen to window mode and vice vesa.
434 *******************************************************************/
435 EXPORT void CALL ChangeWindow (void);
437 /******************************************************************
439 Purpose: This function is called when the emulator is closing
440 down allowing the dll to de-initialise.
443 *******************************************************************/
444 EXPORT void CALL CloseDLL (void);
446 /******************************************************************
448 Purpose: This function is optional function that is provided
449 to give further information about the DLL.
450 input: a handle to the window that calls this function
452 *******************************************************************/
453 EXPORT void CALL DllAbout ( HWND hParent );
455 /******************************************************************
457 Purpose: This function is optional function that is provided
458 to allow the user to configure the dll
459 input: a handle to the window that calls this function
461 *******************************************************************/
462 EXPORT void CALL DllConfig ( HWND hParent );
464 /******************************************************************
466 Purpose: This function is optional function that is provided
467 to allow the user to test the dll
468 input: a handle to the window that calls this function
470 *******************************************************************/
471 EXPORT void CALL DllTest ( HWND hParent );
474 EXPORT void CALL ReadScreen(void **dest, int *width, int *height);
476 /******************************************************************
478 Purpose: This function is called when the emulator receives a
479 WM_PAINT message. This allows the gfx to fit in when
480 it is being used in the desktop.
483 *******************************************************************/
484 EXPORT void CALL DrawScreen (void);
486 /******************************************************************
488 Purpose: This function allows the emulator to gather information
489 about the dll by filling in the PluginInfo structure.
490 input: a pointer to a PLUGIN_INFO stucture that needs to be
491 filled by the function. (see def above)
493 *******************************************************************/
494 EXPORT void CALL GetDllInfo ( PLUGIN_INFO * PluginInfo );
496 /******************************************************************
497 Function: InitiateGFX
498 Purpose: This function is called when the DLL is started to give
499 information from the emulator that the n64 graphics
500 uses. This is not called from the emulation thread.
501 Input: Gfx_Info is passed to this function which is defined
503 Output: TRUE on success
504 FALSE on failure to initialise
506 ** note on interrupts **:
507 To generate an interrupt set the appropriate bit in MI_INTR_REG
508 and then call the function CheckInterrupts to tell the emulator
509 that there is a waiting interrupt.
510 *******************************************************************/
511 EXPORT int CALL InitiateGFX (GFX_INFO Gfx_Info);
513 /******************************************************************
515 Purpose: This function is called in response to the emulator
516 receiving a WM_MOVE passing the xpos and ypos passed
518 input: xpos - the x-coordinate of the upper-left corner of the
519 client area of the window.
520 ypos - y-coordinate of the upper-left corner of the
521 client area of the window.
523 *******************************************************************/
524 EXPORT void CALL MoveScreen (int xpos, int ypos);
526 /******************************************************************
527 Function: ProcessDList
528 Purpose: This function is called when there is a Dlist to be
529 processed. (High level GFX list)
532 *******************************************************************/
533 EXPORT void CALL ProcessDList(void);
535 /******************************************************************
536 Function: ProcessRDPList
537 Purpose: This function is called when there is a Dlist to be
538 processed. (Low level GFX list)
541 *******************************************************************/
542 EXPORT void CALL ProcessRDPList(void);
544 /******************************************************************
546 Purpose: This function is called when a rom is closed.
549 *******************************************************************/
550 EXPORT void CALL RomClosed (void);
552 /******************************************************************
554 Purpose: This function is called when a rom is open. (from the
558 *******************************************************************/
559 EXPORT void CALL RomOpen (void);
561 /******************************************************************
563 Purpose: Useally once Dlists are started being displayed, cfb is
564 ignored. This function tells the dll to start displaying
568 *******************************************************************/
569 EXPORT void CALL ShowCFB (void);
571 /******************************************************************
572 Function: UpdateScreen
573 Purpose: This function is called in response to a vsync of the
574 screen were the VI bit in MI_INTR_REG has already been
578 *******************************************************************/
579 EXPORT void CALL UpdateScreen (void);
581 /******************************************************************
582 Function: ViStatusChanged
583 Purpose: This function is called to notify the dll that the
584 ViStatus registers value has been changed.
587 *******************************************************************/
588 EXPORT void CALL ViStatusChanged (void);
590 /******************************************************************
591 Function: ViWidthChanged
592 Purpose: This function is called to notify the dll that the
593 ViWidth registers value has been changed.
596 *******************************************************************/
597 EXPORT void CALL ViWidthChanged (void);
600 /******************************************************************
601 Function: FrameBufferWrite
602 Purpose: This function is called to notify the dll that the
603 frame buffer has been modified by CPU at the given address.
604 input: addr rdram address
606 size 1 = wxUint8, 2 = wxUint16, 4 = wxUint32
608 *******************************************************************/
609 EXPORT void CALL FBWrite(wxUint32, wxUint32);
615 wxUint32 size; // 1 = wxUint8, 2 = wxUint16, 4=wxUint32
616 } FrameBufferModifyEntry;
618 /******************************************************************
619 Function: FrameBufferWriteList
620 Purpose: This function is called to notify the dll that the
621 frame buffer has been modified by CPU at the given address.
622 input: FrameBufferModifyEntry *plist
623 size = size of the plist, max = 1024
625 *******************************************************************/
626 EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, wxUint32 size);
628 /******************************************************************
629 Function: FrameBufferRead
630 Purpose: This function is called to notify the dll that the
631 frame buffer memory is beening read at the given address.
632 DLL should copy content from its render buffer to the frame buffer
634 DLL is responsible to maintain its own frame buffer memory addr list
635 DLL should copy 4KB block content back to RDRAM frame buffer.
636 Emulator should not call this function again if other memory
637 is read within the same 4KB range
638 input: addr rdram address
640 size 1 = wxUint8, 2 = wxUint16, 4 = wxUint32
642 *******************************************************************/
643 EXPORT void CALL FBRead(wxUint32 addr);
645 /************************************************************************
646 Function: FBGetFrameBufferInfo
647 Purpose: This function is called by the emulator core to retrieve depth
648 buffer information from the video plugin in order to be able
649 to notify the video plugin about CPU depth buffer read/write
654 = 2 word (16 bit) <-- this is N64 default depth buffer format
657 when depth buffer information is not available yet, set all values
658 in the FrameBufferInfo structure to 0
660 input: FrameBufferInfo *pinfo
661 pinfo is pointed to a FrameBufferInfo structure which to be
662 filled in by this function
663 output: Values are return in the FrameBufferInfo structure
664 ************************************************************************/
665 EXPORT void CALL FBGetFrameBufferInfo(void *pinfo);
667 /******************************************************************
668 NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
670 Function: SetConfigDir
671 Purpose: To pass the location where config files should be read/
673 input: path to config directory
675 *******************************************************************/
676 EXPORT void CALL SetConfigDir(char *configDir);
679 #if defined(__cplusplus)
682 #endif //_GFX_H_INCLUDED__