Glide Plugin GLES2 port from mupen64plus-ae, but with special FrameSkip code
[mupen64plus-pandora.git] / source / gles2glide64 / src / Glide64 / Gfx_1.3.h
CommitLineData
98e75f2d 1/*
2* Glide64 - Glide video plugin for Nintendo 64 emulators.
3* Copyright (c) 2002 Dave2001
4* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
5*
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
9* any later version.
10*
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.
15*
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
19*/
20
21//****************************************************************
22//
23// Glide64 - Glide Plugin for Nintendo 64 emulators
24// Project started on December 29th, 2001
25//
26// Authors:
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
31//
32//****************************************************************
33//
34// To modify Glide64:
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.
37//
38//****************************************************************
39
40/**********************************************************************************
41Common gfx plugin spec, version #1.3 maintained by zilmar (zilmar@emulation64.com)
42
43All questions or suggestions should go through the mailing list.
44http://www.egroups.com/group/Plugin64-Dev
45***********************************************************************************
46
47Notes:
48------
49
50Setting the approprate bits in the MI_INTR_REG and calling CheckInterrupts which
51are both passed to the DLL in InitiateGFX will generate an Interrupt from with in
52the plugin.
53
54The Setting of the RSP flags and generating an SP interrupt should not be done in
55the plugin
56
57**********************************************************************************/
58
59// THIS FILE IS A PRECOMPILED HEADER TO DECREASE BUILD TIME. INCLUDE ALL STANDARD
60// .H FILES HERE
61
62#ifndef _GFX_H_INCLUDED__
63#define _GFX_H_INCLUDED__
64
65#include "winlnxdefs.h"
66#include "m64p.h"
67
68#include <stdio.h>
69#include <SDL_mutex.h>
70#include <fstream>
71#include <stdlib.h>
72#include <stddef.h> // offsetof
73#include <string.h>
74#include <stdarg.h>
75#include <glide.h>
76#include "GlideExtensions.h"
77#include "rdp.h"
78#include "Keys.h"
79
80#include <iostream>
81#include <fstream>
82
83#if defined __VISUALC__
84#define GLIDE64_TRY __try
85#define GLIDE64_CATCH __except (EXCEPTION_EXECUTE_HANDLER)
86#else
87#define GLIDE64_TRY try
88#define GLIDE64_CATCH catch (...)
89#endif
90
91#ifndef WIN32
92typedef int HWND;
93#endif
94
95
96#if defined(__cplusplus)
97extern "C" {
98#endif
99
100#define _ENDUSER_RELEASE_
101
102//********
103// Logging
104
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
111
112//#define LOG_UCODE
113
114//#define ALTTAB_FIX
115
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.
119
120//#define TLUT_LOGGING // log every entry of the TLUT?
121// ********************************
122
123#define FPS // fps counter able? (not enabled necessarily)
124
125//#define LOGNOTKEY // Log if not pressing:
126//#define LOGKEY 0x11 // this key (CONTROL)
127
128//#define LOG_COMMANDS // log the whole 64-bit command as (0x........, 0x........)
129
130#define CATCH_EXCEPTIONS // catch exceptions so it doesn't freeze and will report
131 // "The gfx plugin has caused an exception" instead.
132
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
140#endif
141
142#define FPS_FRAMES 10 // Number of frames in which to make an FPS count
143
144//#define SHOW_FULL_TEXVIEWER // shows the entire contents of the texture in the cache viewer,
145 // usually used to debug clamping issues.
146
147
148// Usually enabled
149//#define LARGE_TEXTURE_HANDLING // allow large-textured objects to be split?
150
151#ifdef ALTTAB_FIX
152extern HHOOK hhkLowLevelKybd;
153extern LRESULT CALLBACK LowLevelKeyboardProc(int nCode,
154 WPARAM wParam, LPARAM lParam);
155#endif
156
157// Simulations
158//#define SIMULATE_VOODOO1
159//#define SIMULATE_BANSHEE
160//********
161
162#ifdef EXT_LOGGING
163extern std::ofstream extlog;
164#define EXT(x) extlog.open("ext.txt",std::ios::app); extlog << x; extlog.close();
165#else
166#define EXT(x)
167#endif
168
169#ifndef _ENDUSER_RELEASE_
170#define UNIMP_LOG // Keep enabled, option in dialog
171#define BRIGHT_RED // Keep enabled, option in dialog
172#endif
173
174#define COLORED_DEBUGGER // ;) pretty colors
175
176#ifdef FPS
177extern LARGE_INTEGER fps_last;
178extern LARGE_INTEGER fps_next;
179extern float fps;
180extern wxUint32 fps_count;
181#endif
182
183// rdram mask at 0x400000 bytes (bah, not right for majora's mask)
184//#define BMASK 0x7FFFFF
185extern unsigned long BMASK;
186#define WMASK 0x3FFFFF
187#define DMASK 0x1FFFFF
188
189extern wxUint32 update_screen_count;
190extern wxUint32 resolutions[0x18][2];
191
192int CheckKeyPressed(int key, int mask);
193
194#ifdef PERFORMANCE
195extern int64 perf_cur;
196extern int64 perf_next;
197#endif
198
199//#ifdef LOGGING
200//extern std::ofstream loga;
201//#define LOG(X) loga.open("log.txt",std::ios::app); loga << (...); loga.flush(); loga.close();
202
203//#else
204 #ifndef OLD_API
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__)
209#else
210 #define LOG(...) printf(__VA_ARGS__)
211 #define VLOG(...)
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)
215#endif
216
217
218#ifdef RDP_LOGGING
219extern int log_open;
220extern 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; }
223
224#ifdef LOGNOTKEY
225#define LRDP(x) EXT("RDP (...)\n"); if (settings.logging && log_open) { if (!CheckKeyPressed(LOGKEY,0x8000)) { rdp_log << x; rdp_log.flush(); } }
226#else
227#define LRDP(x) EXT("RDP (...)\n"); if (settings.logging && log_open) { rdp_log << x; rdp_log.flush(); }
228#endif
229
230#else
231#define OPEN_RDP_LOG()
232#define CLOSE_RDP_LOG()
233#define LRDP(x)
234#endif
235
236
237#ifdef RDP_ERROR_LOG
238extern int elog_open;
239extern 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); }
243#else
244#define OPEN_RDP_E_LOG()
245#define CLOSE_RDP_E_LOG()
246#define RDP_E(x)
247#endif
248
249__inline void FRDP (const char *fmt, ...)
250{
251#ifdef RDP_LOGGING
252 if (!settings.logging || !log_open) return;
253
254#ifdef LOGNOTKEY
255 if (CheckKeyPressed(LOGKEY,0x8000)) return;
256#endif
257
258 va_list ap;
259 va_start(ap, fmt);
260 vsprintf(out_buf, fmt, ap);
261 LRDP (out_buf);
262 va_end(ap);
263#endif
264}
265__inline void FRDP_E (const char *fmt, ...)
266{
267#ifdef RDP_ERROR_LOG
268 if (!settings.elogging || !elog_open) return;
269
270#ifdef LOGNOTKEY
271 if (CheckKeyPressed(LOGKEY,0x8000)) return;
272#endif
273
274 sprintf (out_buf, "%08lx: (%08lx, %08lx) ", rdp.pc[rdp.pc_i]-8, rdp.cmd0, rdp.cmd1);
275 rdp_err << out_buf;
276
277 va_list ap2;
278 va_start(ap2, fmt);
279 vsprintf(out_buf, fmt, ap2);
280 rdp_err << out_buf;
281 rdp_err.flush();
282 va_end(ap2);
283#endif
284}
285
286extern int fullscreen;
287extern int romopen;
288extern int to_fullscreen;
289extern int debugging;
290
291extern int evoodoo;
292extern int ev_fullscreen;
293
294extern SDL_sem *mutexProcessDList;
295extern int exception;
296
297// extern wxMutex *mutexProcessDList;
298
299int InitGfx (int);
300void ReleaseGfx ();
301
302// The highest 8 bits are the segment # (1-16), and the lower 24 bits are the offset to
303// add to it.
304__inline wxUint32 segoffset (wxUint32 so)
305{
306 return (rdp.segment[(so>>24)&0x0f] + (so&BMASK))&BMASK;
307}
308
309/* Plugin types */
310#define PLUGIN_TYPE_GFX 2
311
312// this is already defined in API
313/*
314#ifdef __WINDOWS__
315#define EXPORT __declspec(dllexport)
316#define CALL _cdecl
317#else
318#define EXPORT extern
319#define CALL
320#endif
321*/
322/***** Structures *****/
323typedef struct {
324 wxUint16 Version; /* Set to 0x0103 */
325 wxUint16 Type; /* Set to PLUGIN_TYPE_GFX */
326 char Name[100]; /* Name of the DLL */
327
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 */
333} PLUGIN_INFO;
334
335/*
336typedef struct {
337// <removed, already defined in API>
338} GFX_INFO;
339*/
340extern GFX_INFO gfx;
341// extern wxWindow * GFXWindow;
342extern bool no_dlist;
343
344typedef 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,
350 int nColBuffers,
351 int nAuxBuffers) ;
352
353typedef void (FX_CALL *GRTEXBUFFEREXT)( GrChipID_t tmu,
354 FxU32 startAddress,
355 GrLOD_t lodmin,
356 GrLOD_t lodmax,
357 GrAspectRatio_t aspect,
358 GrTextureFormat_t fmt,
359 FxU32 evenOdd) ;
360
361typedef void (FX_CALL *GRAUXBUFFEREXT)( GrBuffer_t buffer ) ;
362
363typedef void (FX_CALL *GRCOLORCOMBINEEXT) (GrCCUColor_t a,
364 GrCombineMode_t a_mode,
365 GrCCUColor_t b,
366 GrCombineMode_t b_mode,
367 GrCCUColor_t c,
368 FxBool c_invert,
369 GrCCUColor_t d,
370 FxBool d_invert,
371 FxU32 shift,
372 FxBool invert) ;
373
374typedef void (FX_CALL *GRTEXCOLORCOMBINEEXT) (GrChipID_t tmu,
375 GrTCCUColor_t a,
376 GrCombineMode_t a_mode,
377 GrTCCUColor_t b,
378 GrCombineMode_t b_mode,
379 GrTCCUColor_t c,
380 FxBool c_invert,
381 GrTCCUColor_t d,
382 FxBool d_invert,
383 FxU32 shift,
384 FxBool invert);
385
386typedef void (FX_CALL *GRCONSTANTCOLORVALUEEXT)
387 (GrChipID_t tmu,
388 GrColor_t value);
389
390typedef void (FX_CALL *GRSTIPPLE)( FxI32 mode) ;
391
392typedef void (FX_CALL *GRCONFIGWRAPPEREXT)(FxI32, FxI32, FxBool, FxBool);
393
394typedef GrScreenResolution_t (FX_CALL *GRWRAPPERFULLSCREENRESOLUTIONEXT)(wxUint32*, wxUint32*);
395
396typedef char ** (FX_CALL *GRQUERYRESOLUTIONSEXT)(FxI32*);
397
398typedef int (*GETTEXADDR)(int tmu, int texsize);
399
400extern GRTEXBUFFEREXT grTextureBufferExt;
401extern GRTEXBUFFEREXT grTextureAuxBufferExt;
402extern GRAUXBUFFEREXT grAuxBufferExt;
403extern GRSTIPPLE grStippleModeExt;
404extern GRSTIPPLE grStipplePatternExt;
405extern GETTEXADDR GetTexAddr;
406
407#ifndef GR_STIPPLE_DISABLE
408#define GR_STIPPLE_DISABLE 0x0
409#define GR_STIPPLE_PATTERN 0x1
410#define GR_STIPPLE_ROTATE 0x2
411#endif
412
413void ReadSettings ();
414void ReadSpecialSettings (const char * name);
415void WriteSettings (bool saveEmulationSettings = false);
416
417#if 0
418//TODO: remove
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
423 output: none
424*******************************************************************/
425EXPORT void CALL CaptureScreen ( char * Directory );
426
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.
432 input: none
433 output: none
434*******************************************************************/
435EXPORT void CALL ChangeWindow (void);
436
437/******************************************************************
438 Function: CloseDLL
439 Purpose: This function is called when the emulator is closing
440 down allowing the dll to de-initialise.
441 input: none
442 output: none
443*******************************************************************/
444EXPORT void CALL CloseDLL (void);
445
446/******************************************************************
447 Function: DllAbout
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
451 output: none
452*******************************************************************/
453EXPORT void CALL DllAbout ( HWND hParent );
454
455/******************************************************************
456 Function: DllConfig
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
460 output: none
461*******************************************************************/
462EXPORT void CALL DllConfig ( HWND hParent );
463
464/******************************************************************
465 Function: DllTest
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
469 output: none
470*******************************************************************/
471EXPORT void CALL DllTest ( HWND hParent );
472
473
474EXPORT void CALL ReadScreen(void **dest, int *width, int *height);
475
476/******************************************************************
477 Function: DrawScreen
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.
481 input: none
482 output: none
483*******************************************************************/
484EXPORT void CALL DrawScreen (void);
485
486/******************************************************************
487 Function: GetDllInfo
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)
492 output: none
493*******************************************************************/
494EXPORT void CALL GetDllInfo ( PLUGIN_INFO * PluginInfo );
495
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
502 above.
503 Output: TRUE on success
504 FALSE on failure to initialise
505
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*******************************************************************/
511EXPORT int CALL InitiateGFX (GFX_INFO Gfx_Info);
512
513/******************************************************************
514 Function: MoveScreen
515 Purpose: This function is called in response to the emulator
516 receiving a WM_MOVE passing the xpos and ypos passed
517 from that message.
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.
522 output: none
523*******************************************************************/
524EXPORT void CALL MoveScreen (int xpos, int ypos);
525
526/******************************************************************
527 Function: ProcessDList
528 Purpose: This function is called when there is a Dlist to be
529 processed. (High level GFX list)
530 input: none
531 output: none
532*******************************************************************/
533EXPORT void CALL ProcessDList(void);
534
535/******************************************************************
536 Function: ProcessRDPList
537 Purpose: This function is called when there is a Dlist to be
538 processed. (Low level GFX list)
539 input: none
540 output: none
541*******************************************************************/
542EXPORT void CALL ProcessRDPList(void);
543
544/******************************************************************
545 Function: RomClosed
546 Purpose: This function is called when a rom is closed.
547 input: none
548 output: none
549*******************************************************************/
550EXPORT void CALL RomClosed (void);
551
552/******************************************************************
553 Function: RomOpen
554 Purpose: This function is called when a rom is open. (from the
555 emulation thread)
556 input: none
557 output: none
558*******************************************************************/
559EXPORT void CALL RomOpen (void);
560
561/******************************************************************
562 Function: ShowCFB
563 Purpose: Useally once Dlists are started being displayed, cfb is
564 ignored. This function tells the dll to start displaying
565 them again.
566 input: none
567 output: none
568*******************************************************************/
569EXPORT void CALL ShowCFB (void);
570
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
575 set
576 input: none
577 output: none
578*******************************************************************/
579EXPORT void CALL UpdateScreen (void);
580
581/******************************************************************
582 Function: ViStatusChanged
583 Purpose: This function is called to notify the dll that the
584 ViStatus registers value has been changed.
585 input: none
586 output: none
587*******************************************************************/
588EXPORT void CALL ViStatusChanged (void);
589
590/******************************************************************
591 Function: ViWidthChanged
592 Purpose: This function is called to notify the dll that the
593 ViWidth registers value has been changed.
594 input: none
595 output: none
596*******************************************************************/
597EXPORT void CALL ViWidthChanged (void);
598
599
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
605 val val
606 size 1 = wxUint8, 2 = wxUint16, 4 = wxUint32
607 output: none
608*******************************************************************/
609EXPORT void CALL FBWrite(wxUint32, wxUint32);
610
611typedef struct
612{
613 wxUint32 addr;
614 wxUint32 val;
615 wxUint32 size; // 1 = wxUint8, 2 = wxUint16, 4=wxUint32
616} FrameBufferModifyEntry;
617
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
624 output: none
625*******************************************************************/
626EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, wxUint32 size);
627
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
633 in N64 RDRAM
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
639 val val
640 size 1 = wxUint8, 2 = wxUint16, 4 = wxUint32
641 output: none
642*******************************************************************/
643EXPORT void CALL FBRead(wxUint32 addr);
644
645/************************************************************************
646Function: FBGetFrameBufferInfo
647Purpose: This function is called by the emulator core to retrieve depth
648buffer information from the video plugin in order to be able
649to notify the video plugin about CPU depth buffer read/write
650operations
651
652size:
653= 1 byte
654= 2 word (16 bit) <-- this is N64 default depth buffer format
655= 4 dword (32 bit)
656
657when depth buffer information is not available yet, set all values
658in the FrameBufferInfo structure to 0
659
660input: FrameBufferInfo *pinfo
661pinfo is pointed to a FrameBufferInfo structure which to be
662filled in by this function
663output: Values are return in the FrameBufferInfo structure
664************************************************************************/
665EXPORT void CALL FBGetFrameBufferInfo(void *pinfo);
666
667/******************************************************************
668 NOTE: THIS HAS BEEN ADDED FOR MUPEN64PLUS AND IS NOT PART OF THE
669 ORIGINAL SPEC
670 Function: SetConfigDir
671 Purpose: To pass the location where config files should be read/
672 written to.
673 input: path to config directory
674 output: none
675*******************************************************************/
676EXPORT void CALL SetConfigDir(char *configDir);
677#endif
678
679#if defined(__cplusplus)
680}
681#endif
682#endif //_GFX_H_INCLUDED__