2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002 Dave2001
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //****************************************************************
22 // Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)
23 // Project started on December 29th, 2001
26 // * 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.
27 // * 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.
29 // Official Glide64 development channel: #Glide64 on EFnet
31 // Original author: Dave2001 (Dave2999@hotmail.com)
32 // Other authors: Gonetz, Gugaman
34 //****************************************************************
36 // ** NOTE: this file has been modified from it's original version, which can be
37 // downloaded along with Project64 **
39 /**********************************************************************************
40 Common gfx plugin spec, version #1.3 maintained by zilmar (zilmar@emulation64.com)
42 All questions or suggestions should go through the mailing list.
43 http://www.egroups.com/group/Plugin64-Dev
44 ***********************************************************************************
49 Setting the approprate bits in the MI_INTR_REG and calling CheckInterrupts which
50 are both passed to the DLL in InitiateGFX will generate an Interrupt from with in
53 The Setting of the RSP flags and generating an SP interrupt should not be done in
56 **********************************************************************************/
58 // THIS FILE IS A PRECOMPILED HEADER TO DECREASE BUILD TIME. INCLUDE ALL STANDARD
61 #ifndef _GFX_H_INCLUDED__
62 #define _GFX_H_INCLUDED__
64 #if defined(WIN32) && defined(GCC)
65 // ZIGGY ARRRRGG what a pain in the #$@$
66 //# include "Gfx #1.3-mangling.h"
73 #define _WIN32_WINNT 0x0400
78 #include "winlnxdefs.h"
85 #include <cstddef> // offsetof
98 #if defined(__cplusplus)
102 // tooltips have an error on debug mode, this can be overcome by clicking ignore,
103 // but I'd rather just disable tooltips altogether since nobody else should
104 // have the debug version anyway.
106 //#ifndef __INTEL_COMPILER // tooltips don't work with intel compiler
112 # define _FINAL_RELEASE_
115 // # define _FINAL_RELEASE_
117 // //# define _FINAL_RELEASE_
123 // ********************************
124 // ** TAKE OUT BEFORE RELEASE!!! **
125 //#define LOGGING // log of spec functions called
126 //#define LOG_KEY // says "Key!!!" in the log when space bar is pressed
132 //#define EXTREME_LOGGING // lots of logging
133 // note that some of these things are inserted/removed
134 // from within the code & may not be changed by this define.
136 //#define TLUT_LOGGING // log every entry of the TLUT?
137 // ********************************
139 #define FPS // fps counter able? (not enabled necessarily)
141 #define LOGNOTKEY // Log if not pressing:
143 #define LOGKEY VK_LCONTROL // this key
146 #define LOGKEY KMOD_LCTRL
147 inline int GetAsyncKeyState(int key
) {
148 return (SDL_GetModState() & key
) != 0;
152 #define LOG_COMMANDS // log the whole 64-bit command as (0x........, 0x........)
154 #define CATCH_EXCEPTIONS // catch exceptions so it doesn't freeze and will report
155 // "The gfx plugin has caused an exception" instead.
157 #define FLUSH // flush the file buffer. slower logging, but makes sure
158 // the command is logged before continuing (in case of
159 // crash or exception, the log will not be cut short)
160 #ifndef _FINAL_RELEASE_
161 #define RDP_LOGGING // Allow logging (will not log unless checked, but allows the option)
162 // Logging functions will not be compiled if this is not present.
163 //#define RDP_ERROR_LOG
166 #define FPS_FRAMES 10 // Number of frames in which to make an FPS count
168 //#define SHOW_FULL_TEXVIEWER // shows the entire contents of the texture in the cache viewer,
169 // usually used to debug clamping issues.
173 #define LARGE_TEXTURE_HANDLING // allow large-textured objects to be split?
176 extern HHOOK hhkLowLevelKybd
;
177 extern LRESULT CALLBACK
LowLevelKeyboardProc(int nCode
,
178 WPARAM wParam
, LPARAM lParam
);
182 //#define SIMULATE_VOODOO1
183 //#define SIMULATE_BANSHEE
187 extern std::ofstream extlog
;
188 #define EXT(x) extlog.open("ext.txt",ios::app); extlog << x; extlog.close();
193 #ifndef _FINAL_RELEASE_
194 #define UNIMP_LOG // Keep enabled, option in dialog
195 #define BRIGHT_RED // Keep enabled, option in dialog
198 #define COLORED_DEBUGGER // ;) pretty colors
201 extern LARGE_INTEGER perf_freq
;
202 extern LARGE_INTEGER fps_last
;
203 extern LARGE_INTEGER fps_next
;
205 extern DWORD fps_count
;
208 // rdram mask at 0x400000 bytes (bah, not right for majora's mask)
209 //#define BMASK 0x7FFFFF
210 extern unsigned long BMASK
;
211 #define WMASK 0x3FFFFF
212 #define DMASK 0x1FFFFF
215 extern long max_tex_size
;
216 extern long sup_mirroring
;
217 extern BOOL sup_32bit_tex
;
218 extern DWORD update_screen_count
;
220 extern DWORD resolutions
[0x18][2];
222 //#define PERFORMANCE
224 extern __int64 perf_cur
;
225 extern __int64 perf_next
;
229 extern std::ofstream loga
;
230 #define LOG(x) loga.open("log.txt",ios::app); loga << x; loga.flush(); loga.close();
238 extern BOOL log_open
;
239 extern std::ofstream rdp_log
;
240 //#define rdp_log std::cerr;
241 #define OPEN_RDP_LOG() EXT("OPEN_RDP_LOG ()\n"); if (settings.logging && !log_open) { /*rdp_log.open ("rdp.txt");*/ log_open=TRUE; }
242 #define CLOSE_RDP_LOG() EXT("CLOSE_RDP_LOG ()\n"); if (settings.logging && log_open) { /*rdp_log.close ();*/ log_open=FALSE; }
245 #define RDP(x) EXT("RDP (...)\n"); if (dumping && settings.logging && log_open) { if (!(GetAsyncKeyState(LOGKEY)&0x8000)) { fprintf(stderr, x);/*rdp_log << x; rdp_log.flush();*/ } }
247 #define RDP(x) EXT("RDP (...)\n"); if (dumping && settings.logging && log_open) { fprintf(stderr, x);/*rdp_log << x; rdp_log.flush();*/ }
251 #define OPEN_RDP_LOG()
252 #define CLOSE_RDP_LOG()
258 extern BOOL elog_open
;
259 extern std::ofstream rdp_err
;
260 //#define rdp_err std::cerr
261 #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; }
262 #define CLOSE_RDP_E_LOG() EXT("CLOSE_RDP_LOG ()\n"); if (settings.elogging && elog_open) { /*rdp_err.close (); */elog_open=FALSE; }
263 #define RDP_E(x) if (dumping && settings.elogging) { FRDP_E (x); }
265 #define OPEN_RDP_E_LOG()
266 #define CLOSE_RDP_E_LOG()
272 __inline
void FRDP (const char *fmt
, ...)
275 if (!dumping
|| !settings
.logging
|| !log_open
) return;
278 if (GetAsyncKeyState(LOGKEY
)&0x8000) return;
283 vsprintf(out_buf
, fmt
, ap
);
288 __inline
void FRDP_E (const char *fmt
, ...)
291 if (!dumping
|| !settings
.elogging
|| !elog_open
) return;
294 if (GetAsyncKeyState(LOGKEY
)&0x8000) return;
297 sprintf (out_buf
, "%08x: (%08x, %08x) ", rdp
.pc
[rdp
.pc_i
]-8, rdp
.cmd0
, rdp
.cmd1
);
302 vsprintf(out_buf
, fmt
, ap2
);
303 // rdp_err << out_buf;
305 fprintf(stderr
, out_buf
);
315 inline void FRDP (const char *fmt
, ...) {}
316 inline void FRDP_E (const char *fmt
, ...) {}
321 extern BOOL fullscreen
;
323 extern BOOL to_fullscreen
;
324 extern BOOL debugging
;
325 extern HINSTANCE hInstance
;
328 extern BOOL ev_fullscreen
;
330 extern BOOL exception
;
332 extern PROPSHEETHEADER m_PropSheet
;
333 extern PROPSHEETPAGE m_psp
[3];
338 void DrawFrameBuffer ();
340 // The highest 8 bits are the segment # (1-16), and the lower 24 bits are the offset to
342 __inline DWORD
segoffset (DWORD so
)
344 return (rdp
.segment
[(so
>>24)&0x0f] + (so
&BMASK
))&BMASK
;
348 #define PLUGIN_TYPE_GFX 2
350 #define EXPORT __declspec(dllexport)
353 /***** Structures *****/
355 WORD Version
; /* Set to 0x0103 */
356 WORD Type
; /* Set to PLUGIN_TYPE_GFX */
357 char Name
[100]; /* Name of the DLL */
359 /* If DLL supports memory these memory options then set them to TRUE or FALSE
360 if it does not support it */
361 BOOL NormalMemory
; /* a normal BYTE array */
362 BOOL MemoryBswaped
; /* a normal BYTE array where the memory has been pre
363 bswap on a dword (32 bits) boundry */
367 HWND hWnd
; /* Render window */
368 HWND hStatusBar
; /* if render window does not have a status bar then this is NULL */
370 BOOL MemoryBswaped
; // If this is set to TRUE, then the memory has been pre
371 // bswap on a dword (32 bits) boundry
372 // eg. the first 8 bytes are stored like this:
375 BYTE
* HEADER
; // This is the rom header (first 40h bytes of the rom
376 // This will be in the same memory format as the rest of the memory.
383 DWORD
* DPC_START_REG
;
385 DWORD
* DPC_CURRENT_REG
;
386 DWORD
* DPC_STATUS_REG
;
387 DWORD
* DPC_CLOCK_REG
;
388 DWORD
* DPC_BUFBUSY_REG
;
389 DWORD
* DPC_PIPEBUSY_REG
;
390 DWORD
* DPC_TMEM_REG
;
392 DWORD
* VI_STATUS_REG
;
393 DWORD
* VI_ORIGIN_REG
;
394 DWORD
* VI_WIDTH_REG
;
396 DWORD
* VI_V_CURRENT_LINE_REG
;
397 DWORD
* VI_TIMING_REG
;
398 DWORD
* VI_V_SYNC_REG
;
399 DWORD
* VI_H_SYNC_REG
;
401 DWORD
* VI_H_START_REG
;
402 DWORD
* VI_V_START_REG
;
403 DWORD
* VI_V_BURST_REG
;
404 DWORD
* VI_X_SCALE_REG
;
405 DWORD
* VI_Y_SCALE_REG
;
407 void (*CheckInterrupts
)( void );
411 extern BOOL no_dlist
;
413 typedef GrContext_t (FX_CALL
*GRWINOPENEXT
)( FxU32 hWnd
,
414 GrScreenResolution_t resolution
,
415 GrScreenRefresh_t refresh
,
416 GrColorFormat_t format
,
417 GrOriginLocation_t origin
,
418 GrPixelFormat_t pixelformat
,
422 typedef void (FX_CALL
*GRTEXBUFFEREXT
)( GrChipID_t tmu
,
426 GrAspectRatio_t aspect
,
427 GrTextureFormat_t fmt
,
430 typedef void (FX_CALL
*GRAUXBUFFEREXT
)( GrBuffer_t buffer
) ;
432 typedef void (FX_CALL
*GRCOLORCOMBINEEXT
) (GrCCUColor_t a
,
433 GrCombineMode_t a_mode
,
435 GrCombineMode_t b_mode
,
443 typedef void (FX_CALL
*GRTEXCOLORCOMBINEEXT
) (GrChipID_t tmu
,
445 GrCombineMode_t a_mode
,
447 GrCombineMode_t b_mode
,
455 typedef void (FX_CALL
*GRCONSTANTCOLORVALUEEXT
)
459 typedef void (FX_CALL
*GRSTIPPLE
)( FxI32 mode
) ;
461 typedef void (FX_CALL
*GRCONFIGWRAPPEREXT
)(HINSTANCE instance
, HWND hwnd
);
463 typedef GrScreenResolution_t (FX_CALL
*GRWRAPPERFULLSCREENRESOLUTIONEXT
)();
465 // ZIGGY framebuffer copy extension
466 // allow to copy the depth or color buffer from back/front to front/back
467 // (GL has separate back and front depth buffer, unlike glide, so this extension
468 // makes sense only in a wrapper)
469 #define GR_FBCOPY_MODE_DEPTH 0
470 #define GR_FBCOPY_MODE_COLOR 1
471 #define GR_FBCOPY_BUFFER_BACK 0
472 #define GR_FBCOPY_BUFFER_FRONT 1
473 typedef void (FX_CALL
*GRFRAMEBUFFERCOPYEXT
)(int x
, int y
, int w
, int h
,
474 int buffer_from
, int buffer_to
, int mode
);
476 extern GRFRAMEBUFFERCOPYEXT grFramebufferCopyExt
;
478 extern GRTEXBUFFEREXT grTextureBufferExt
;
479 extern GRTEXBUFFEREXT grTextureAuxBufferExt
;
480 extern GRAUXBUFFEREXT grAuxBufferExt
;
481 extern GRSTIPPLE grStippleModeExt
;
482 extern GRSTIPPLE grStipplePatternExt
;
484 #ifndef GR_STIPPLE_DISABLE
485 #define GR_STIPPLE_DISABLE 0x0
486 #define GR_STIPPLE_PATTERN 0x1
487 #define GR_STIPPLE_ROTATE 0x2
490 void ReadSettings ();
491 void ReadSpecialSettings (char name
[21]);
492 void WriteSettings ();
494 /******************************************************************
495 Function: CaptureScreen
496 Purpose: This function dumps the current frame to a file
497 input: pointer to the directory to save the file to
499 *******************************************************************/
500 EXPORT
void CALL
CaptureScreen ( char * Directory
);
502 /******************************************************************
503 Function: ChangeWindow
504 Purpose: to change the window between fullscreen and window
505 mode. If the window was in fullscreen this should
506 change the screen to window mode and vice vesa.
509 *******************************************************************/
510 EXPORT
void CALL
ChangeWindow (void);
512 /******************************************************************
514 Purpose: This function is called when the emulator is closing
515 down allowing the dll to de-initialise.
518 *******************************************************************/
519 EXPORT
void CALL
CloseDLL (void);
521 /******************************************************************
523 Purpose: This function is optional function that is provided
524 to give further information about the DLL.
525 input: a handle to the window that calls this function
527 *******************************************************************/
528 EXPORT
void CALL
DllAbout ( HWND hParent
);
530 /******************************************************************
532 Purpose: This function is optional function that is provided
533 to allow the user to configure the dll
534 input: a handle to the window that calls this function
536 *******************************************************************/
537 EXPORT
void CALL
DllConfig ( HWND hParent
);
539 /******************************************************************
541 Purpose: This function is optional function that is provided
542 to allow the user to test the dll
543 input: a handle to the window that calls this function
545 *******************************************************************/
546 EXPORT
void CALL
DllTest ( HWND hParent
);
549 EXPORT
void CALL
ReadScreen(void **dest
, long *width
, long *height
);
551 /******************************************************************
553 Purpose: This function is called when the emulator receives a
554 WM_PAINT message. This allows the gfx to fit in when
555 it is being used in the desktop.
558 *******************************************************************/
559 EXPORT
void CALL
DrawScreen (void);
561 /******************************************************************
563 Purpose: This function allows the emulator to gather information
564 about the dll by filling in the PluginInfo structure.
565 input: a pointer to a PLUGIN_INFO stucture that needs to be
566 filled by the function. (see def above)
568 *******************************************************************/
569 EXPORT
void CALL
GetDllInfo ( PLUGIN_INFO
* PluginInfo
);
571 /******************************************************************
572 Function: InitiateGFX
573 Purpose: This function is called when the DLL is started to give
574 information from the emulator that the n64 graphics
575 uses. This is not called from the emulation thread.
576 Input: Gfx_Info is passed to this function which is defined
578 Output: TRUE on success
579 FALSE on failure to initialise
581 ** note on interrupts **:
582 To generate an interrupt set the appropriate bit in MI_INTR_REG
583 and then call the function CheckInterrupts to tell the emulator
584 that there is a waiting interrupt.
585 *******************************************************************/
586 EXPORT BOOL CALL
InitiateGFX (GFX_INFO Gfx_Info
);
588 /******************************************************************
590 Purpose: This function is called in response to the emulator
591 receiving a WM_MOVE passing the xpos and ypos passed
593 input: xpos - the x-coordinate of the upper-left corner of the
594 client area of the window.
595 ypos - y-coordinate of the upper-left corner of the
596 client area of the window.
598 *******************************************************************/
599 EXPORT
void CALL
MoveScreen (int xpos
, int ypos
);
601 /******************************************************************
602 Function: ProcessDList
603 Purpose: This function is called when there is a Dlist to be
604 processed. (High level GFX list)
607 *******************************************************************/
608 EXPORT
void CALL
ProcessDList(void);
610 /******************************************************************
611 Function: ProcessRDPList
612 Purpose: This function is called when there is a Dlist to be
613 processed. (Low level GFX list)
616 *******************************************************************/
617 EXPORT
void CALL
ProcessRDPList(void);
619 /******************************************************************
621 Purpose: This function is called when a rom is closed.
624 *******************************************************************/
625 EXPORT
void CALL
RomClosed (void);
627 /******************************************************************
629 Purpose: This function is called when a rom is open. (from the
633 *******************************************************************/
634 EXPORT
void CALL
RomOpen (void);
636 /******************************************************************
638 Purpose: Useally once Dlists are started being displayed, cfb is
639 ignored. This function tells the dll to start displaying
643 *******************************************************************/
644 EXPORT
void CALL
ShowCFB (void);
646 /******************************************************************
647 Function: UpdateScreen
648 Purpose: This function is called in response to a vsync of the
649 screen were the VI bit in MI_INTR_REG has already been
653 *******************************************************************/
654 EXPORT
void CALL
UpdateScreen (void);
656 /******************************************************************
657 Function: ViStatusChanged
658 Purpose: This function is called to notify the dll that the
659 ViStatus registers value has been changed.
662 *******************************************************************/
663 EXPORT
void CALL
ViStatusChanged (void);
665 /******************************************************************
666 Function: ViWidthChanged
667 Purpose: This function is called to notify the dll that the
668 ViWidth registers value has been changed.
671 *******************************************************************/
672 EXPORT
void CALL
ViWidthChanged (void);
675 /******************************************************************
676 Function: FrameBufferWrite
677 Purpose: This function is called to notify the dll that the
678 frame buffer has been modified by CPU at the given address.
679 input: addr rdram address
681 size 1 = BYTE, 2 = WORD, 4 = DWORD
683 *******************************************************************/
684 EXPORT
void CALL
FBWrite(DWORD
, DWORD
);
690 DWORD size
; // 1 = BYTE, 2 = WORD, 4=DWORD
691 } FrameBufferModifyEntry
;
693 /******************************************************************
694 Function: FrameBufferWriteList
695 Purpose: This function is called to notify the dll that the
696 frame buffer has been modified by CPU at the given address.
697 input: FrameBufferModifyEntry *plist
698 size = size of the plist, max = 1024
700 *******************************************************************/
701 EXPORT
void CALL
FBWList(FrameBufferModifyEntry
*plist
, DWORD size
);
703 /******************************************************************
704 Function: FrameBufferRead
705 Purpose: This function is called to notify the dll that the
706 frame buffer memory is beening read at the given address.
707 DLL should copy content from its render buffer to the frame buffer
709 DLL is responsible to maintain its own frame buffer memory addr list
710 DLL should copy 4KB block content back to RDRAM frame buffer.
711 Emulator should not call this function again if other memory
712 is read within the same 4KB range
713 input: addr rdram address
715 size 1 = BYTE, 2 = WORD, 4 = DWORD
717 *******************************************************************/
718 EXPORT
void CALL
FBRead(DWORD addr
);
720 /************************************************************************
721 Function: FBGetFrameBufferInfo
722 Purpose: This function is called by the emulator core to retrieve depth
723 buffer information from the video plugin in order to be able
724 to notify the video plugin about CPU depth buffer read/write
729 = 2 word (16 bit) <-- this is N64 default depth buffer format
732 when depth buffer information is not available yet, set all values
733 in the FrameBufferInfo structure to 0
735 input: FrameBufferInfo *pinfo
736 pinfo is pointed to a FrameBufferInfo structure which to be
737 filled in by this function
738 output: Values are return in the FrameBufferInfo structure
739 ************************************************************************/
740 EXPORT
void CALL
FBGetFrameBufferInfo(void *pinfo
);
742 /******************************************************************
743 NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
745 Function: SetConfigDir
746 Purpose: To pass the location where config files should be read/
748 input: path to config directory
750 *******************************************************************/
751 EXPORT
void CALL
SetConfigDir( char *configDir
);
753 #if defined(__cplusplus)
756 #endif //_GFX_H_INCLUDED__