/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta_reference/plugins/zzogl-pg/opengl/GSmain.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta_reference/plugins/zzogl-pg/opengl/GSmain.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 174 - (show annotations) (download)
Mon Sep 13 17:24:24 2010 UTC (9 years, 11 months ago) by william
File size: 22335 byte(s)
merge r171-173 from https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/debug/0.X/0.9.X/0.9.7/r3113
-- pick up:
* local versioning support from trunk
* get rig of annoying warnings
1 /* ZeroGS KOSMOS
2 * Copyright (C) 2005-2006 zerofrog@gmail.com
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #if defined(_WIN32)
19 #include <windows.h>
20 #include "Win32.h"
21 #include <io.h>
22 #endif
23
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <math.h>
29
30 #include <list>
31 #include <vector>
32 #include <map>
33 #include <string>
34
35 using namespace std;
36
37 #include "GS.h"
38 #include "Mem.h"
39 #include "Regs.h"
40 #include "Profile.h"
41
42 #include "zerogs.h"
43 #include "targets.h"
44 #include "ZeroGSShaders/zerogsshaders.h"
45
46 #ifdef _MSC_VER
47 #pragma warning(disable:4244)
48 #endif
49
50 GSinternal gs;
51 char GStitle[256];
52 GSconf conf;
53 int ppf;
54 primInfo *prim;
55 FILE *gsLog;
56 int g_GSMultiThreaded = 0;
57 void (*GSirq)();
58 u8* g_pBasePS2Mem = NULL;
59 int g_TransferredToGPU = 0;
60 std::string s_strIniPath("inis/"); // Air's new ini path (r2361)
61
62 //static bool g_bHidden = 0;
63 int g_GameSettings = 0;
64 int CurrentSavestate = 0; // Number of SaveSlot. Default is 0
65 bool SaveStateExists = true; // We could not know save slot status before first change occured
66 const char* SaveStateFile = NULL; // Name of SaveFile for access check.
67
68 // statistics
69 u32 g_nGenVars = 0, g_nTexVars = 0, g_nAlphaVars = 0, g_nResolve = 0;
70
71 #define VER 1
72 const unsigned char zgsversion = PS2E_GS_VERSION;
73 unsigned char zgsrevision = 0; // revision and build gives plugin version
74 unsigned char zgsbuild = VER;
75 unsigned char zgsminor = 0;
76
77 #ifdef _DEBUG
78 char *libraryName = "ZZ Ogl PG (Debug) ";
79 #elif defined(ZEROGS_DEVBUILD)
80 char *libraryName = "ZZ Ogl PG (Dev)";
81 #else
82 char *libraryName = "ZZ Ogl PG ";
83 #endif
84
85 static const char* s_aa[5] = { "AA none |", "AA 2x |", "AA 4x |", "AA 8x |", "AA 16x |" };
86 static const char* s_naa[3] = { "native res |", "res /2 |", "res /4 |" };
87 static const char* pbilinear[] = { "off", "normal", "forced" };
88
89 extern GIFRegHandler g_GIFPackedRegHandlers[];
90 extern GIFRegHandler g_GIFRegHandlers[];
91 GIFRegHandler g_GIFTempRegHandlers[16] = {0};
92 extern int g_nPixelShaderVer;
93 extern int g_nFrameRender;
94 extern int g_nFramesSkipped;
95
96 int s_frameskipping = 0;
97 u32 CALLBACK PS2EgetLibType()
98 {
99 return PS2E_LT_GS;
100 }
101
102 char* CALLBACK PS2EgetLibName()
103 {
104 return libraryName;
105 }
106
107 u32 CALLBACK PS2EgetLibVersion2(u32 type)
108 {
109 return (zgsversion << 16) | (zgsrevision << 8) | zgsbuild | (zgsminor << 24);
110 }
111
112 GLWindow GLWin;
113
114 #ifdef _WIN32
115 HWND GShwnd = NULL;
116 #endif
117
118 u32 THR_KeyEvent = 0; // Value for key event processing between threads
119 bool THR_bShift = false;
120
121 namespace ZZLog
122 {
123 bool IsLogging()
124 {
125 // gsLog can be null if the config dialog is used prior to Pcsx2 starting an emulation session.
126 // (GSinit won't have been called then)
127 return (gsLog != NULL && conf.log);
128 }
129
130 void WriteToScreen(const char* pstr, u32 ms)
131 {
132 ZeroGS::AddMessage(pstr, ms);
133 }
134
135 void _Message(const char *str)
136 {
137 SysMessage(str);
138 }
139
140 void _Log(const char *str)
141 {
142 if (IsLogging()) fprintf(gsLog, str);
143 }
144
145 void _WriteToConsole(const char *str)
146 {
147 printf("ZZogl-PG: %s", str);
148 }
149
150 void _Print(const char *str)
151 {
152 printf("ZZogl-PG: %s", str);
153
154 if (IsLogging()) fprintf(gsLog, str);
155 }
156
157 void Message(const char *fmt, ...)
158 {
159 va_list list;
160 char tmp[512];
161
162 va_start(list, fmt);
163 vsprintf(tmp, fmt, list);
164 va_end(list);
165
166 SysMessage(tmp);
167 }
168
169 void Log(const char *fmt, ...)
170 {
171 va_list list;
172
173 va_start(list, fmt);
174
175 if (IsLogging()) vfprintf(gsLog, fmt, list);
176
177 va_end(list);
178 }
179
180 void WriteToConsole(const char *fmt, ...)
181 {
182 va_list list;
183
184 va_start(list, fmt);
185
186 printf("ZZogl-PG: ");
187 vprintf(fmt, list);
188 va_end(list);
189 }
190
191 void Print(const char *fmt, ...)
192 {
193 va_list list;
194
195 va_start(list, fmt);
196
197 if (IsLogging()) vfprintf(gsLog, fmt, list);
198
199 printf("ZZogl-PG: ");
200
201 vprintf(fmt, list);
202
203 va_end(list);
204 }
205
206 void Greg_Log(const char *fmt, ...)
207 {
208 // Not currently used
209 #if 0
210 va_list list;
211 char tmp[512];
212
213 va_start(list, fmt);
214
215 if (IsLogging()) vfprintf(gsLog, fmt, list);
216
217 va_end(list);
218
219 #endif
220 }
221
222 void Prim_Log(const char *fmt, ...)
223 {
224 #if defined(ZEROGS_DEVBUILD) && defined(WRITE_PRIM_LOGS)
225 va_list list;
226 char tmp[512];
227
228 va_start(list, fmt);
229
230 if (conf.log /*& 0x00000010*/)
231 {
232 if (IsLogging()) vfprintf(gsLog, fmt, list);
233
234 printf("ZZogl-PG(PRIM): ");
235
236 vprintf(fmt, list);
237 }
238
239 va_end(list);
240
241 #endif
242 }
243
244 void GS_Log(const char *fmt, ...)
245 {
246 #ifdef ZEROGS_DEVBUILD
247 va_list list;
248
249 va_start(list, fmt);
250
251 if (IsLogging())
252 {
253 vfprintf(gsLog, fmt, list);
254 fprintf(gsLog, "\n");
255 }
256
257 printf("ZZogl-PG(GS): ");
258
259 vprintf(fmt, list);
260 printf("\n");
261 va_end(list);
262 #endif
263 }
264
265 void Warn_Log(const char *fmt, ...)
266 {
267 #ifdef ZEROGS_DEVBUILD
268 va_list list;
269
270 va_start(list, fmt);
271
272 if (IsLogging())
273 {
274 vfprintf(gsLog, fmt, list);
275 fprintf(gsLog, "\n");
276 }
277
278 printf("ZZogl-PG(Warning): ");
279
280 vprintf(fmt, list);
281 va_end(list);
282 printf("\n");
283 #endif
284 }
285
286 void Debug_Log(const char *fmt, ...)
287 {
288 #if _DEBUG
289 va_list list;
290
291 va_start(list, fmt);
292
293 if (IsLogging())
294 {
295 vfprintf(gsLog, fmt, list);
296 fprintf(gsLog, "\n");
297 }
298
299 printf("ZZogl-PG(Debug): ");
300
301 vprintf(fmt, list);
302 printf("\n");
303 va_end(list);
304
305
306 #endif
307 }
308
309 void Error_Log(const char *fmt, ...)
310 {
311 va_list list;
312
313 va_start(list, fmt);
314
315 if (IsLogging())
316 {
317 vfprintf(gsLog, fmt, list);
318 fprintf(gsLog, "\n");
319 }
320
321 printf("ZZogl-PG(Error): ");
322
323 vprintf(fmt, list);
324 printf("\n");
325 va_end(list);
326 }
327 };
328
329 void CALLBACK GSsetBaseMem(void* pmem)
330 {
331 g_pBasePS2Mem = (u8*)pmem;
332 }
333
334 void CALLBACK GSsetSettingsDir(const char* dir)
335 {
336 s_strIniPath = (dir == NULL) ? "inis/" : dir;
337 }
338
339 extern int VALIDATE_THRESH;
340 extern u32 TEXDESTROY_THRESH;
341
342 int g_LastCRC = 0;
343
344 void CALLBACK GSsetGameCRC(int crc, int options)
345 {
346 // TEXDESTROY_THRESH starts out at 16.
347 VALIDATE_THRESH = 8;
348 conf.mrtdepth = ((conf.gamesettings & GAME_DISABLEMRTDEPTH) != 0);
349
350 if (!conf.mrtdepth)
351 ZZLog::Error_Log("Disabling MRT depth writing.");
352 else
353 ZZLog::Error_Log("Enabling MRT depth writing.");
354
355 g_GameSettings |= GAME_PATH3HACK;
356
357 bool CRCValueChanged = (g_LastCRC != crc);
358
359 g_LastCRC = crc;
360
361 ZZLog::Error_Log("CRC = %x", crc);
362
363 if (CRCValueChanged && (crc != 0))
364 {
365 for (int i = 0; i < GAME_INFO_INDEX; i++)
366 {
367 if (crc_game_list[i].crc == crc)
368 {
369 if (crc_game_list[i].v_thresh > 0) VALIDATE_THRESH = crc_game_list[i].v_thresh;
370
371 if (crc_game_list[i].t_thresh > 0) TEXDESTROY_THRESH = crc_game_list[i].t_thresh;
372
373 conf.gamesettings |= crc_game_list[i].flags;
374
375 g_GameSettings = conf.gamesettings | options;
376
377 ZZLog::Error_Log("Found CRC[%x] in crc game list.", crc);
378
379 return;
380 }
381 }
382 }
383
384 g_GameSettings = conf.gamesettings | options;
385 }
386
387 void CALLBACK GSsetFrameSkip(int frameskip)
388 {
389 FUNCLOG
390 s_frameskipping |= frameskip;
391
392 if (frameskip && g_nFrameRender > 1)
393 {
394 for (int i = 0; i < 16; ++i)
395 {
396 g_GIFPackedRegHandlers[i] = GIFPackedRegHandlerNOP;
397 }
398
399 // still keep certain handlers
400 g_GIFPackedRegHandlers[6] = GIFRegHandlerTEX0_1;
401 g_GIFPackedRegHandlers[7] = GIFRegHandlerTEX0_2;
402 g_GIFPackedRegHandlers[14] = GIFPackedRegHandlerA_D;
403
404 g_GIFRegHandlers[0] = GIFRegHandlerNOP;
405 g_GIFRegHandlers[1] = GIFRegHandlerNOP;
406 g_GIFRegHandlers[2] = GIFRegHandlerNOP;
407 g_GIFRegHandlers[3] = GIFRegHandlerNOP;
408 g_GIFRegHandlers[4] = GIFRegHandlerNOP;
409 g_GIFRegHandlers[5] = GIFRegHandlerNOP;
410 g_GIFRegHandlers[12] = GIFRegHandlerNOP;
411 g_GIFRegHandlers[13] = GIFRegHandlerNOP;
412 g_GIFRegHandlers[26] = GIFRegHandlerNOP;
413 g_GIFRegHandlers[27] = GIFRegHandlerNOP;
414
415 g_nFrameRender = 0;
416 }
417 else if (!frameskip && g_nFrameRender <= 0)
418 {
419 g_nFrameRender = 1;
420
421 if (g_GIFTempRegHandlers[0] == NULL) return; // not init yet
422
423 // restore
424 memcpy(g_GIFPackedRegHandlers, g_GIFTempRegHandlers, sizeof(g_GIFTempRegHandlers));
425
426 g_GIFRegHandlers[0] = GIFRegHandlerPRIM;
427 g_GIFRegHandlers[1] = GIFRegHandlerRGBAQ;
428 g_GIFRegHandlers[2] = GIFRegHandlerST;
429 g_GIFRegHandlers[3] = GIFRegHandlerUV;
430 g_GIFRegHandlers[4] = GIFRegHandlerXYZF2;
431 g_GIFRegHandlers[5] = GIFRegHandlerXYZ2;
432 g_GIFRegHandlers[12] = GIFRegHandlerXYZF3;
433 g_GIFRegHandlers[13] = GIFRegHandlerXYZ2;
434 g_GIFRegHandlers[26] = GIFRegHandlerPRMODECONT;
435 g_GIFRegHandlers[27] = GIFRegHandlerPRMODE;
436 }
437 }
438
439 void CALLBACK GSreset()
440 {
441 FUNCLOG
442
443 memset(&gs, 0, sizeof(gs));
444
445 ZeroGS::GSStateReset();
446
447 gs.prac = 1;
448 prim = &gs._prim[0];
449 gs.nTriFanVert = -1;
450 gs.imageTransfer = -1;
451 gs.q = 1;
452 }
453
454 void CALLBACK GSgifSoftReset(u32 mask)
455 {
456 FUNCLOG
457
458 if (mask & 1) memset(&gs.path[0], 0, sizeof(gs.path[0]));
459 if (mask & 2) memset(&gs.path[1], 0, sizeof(gs.path[1]));
460 if (mask & 4) memset(&gs.path[2], 0, sizeof(gs.path[2]));
461
462 gs.imageTransfer = -1;
463 gs.q = 1;
464 gs.nTriFanVert = -1;
465 }
466
467 s32 CALLBACK GSinit()
468 {
469 FUNCLOG
470
471 memcpy(g_GIFTempRegHandlers, g_GIFPackedRegHandlers, sizeof(g_GIFTempRegHandlers));
472
473 gsLog = fopen("logs/gsLog.txt", "w");
474
475 if (gsLog == NULL)
476 {
477 gsLog = fopen("gsLog.txt", "w");
478
479 if (gsLog == NULL)
480 {
481 SysMessage("Can't create gsLog.txt");
482 return -1;
483 }
484 }
485
486 setvbuf(gsLog, NULL, _IONBF, 0);
487
488 ZZLog::GS_Log("Calling GSinit.");
489
490 GSreset();
491 ZZLog::GS_Log("GSinit finished.");
492 return 0;
493 }
494
495 void CALLBACK GSshutdown()
496 {
497 FUNCLOG
498
499 if (gsLog != NULL) fclose(gsLog);
500 }
501
502 // keyboard functions
503 void OnKeyboardF5(int shift)
504 {
505 FUNCLOG
506
507 char strtitle[256];
508
509 if (shift)
510 {
511 if (g_nPixelShaderVer == SHADER_REDUCED)
512 {
513 conf.bilinear = 0;
514 sprintf(strtitle, "reduced shaders don't support bilinear filtering");
515 }
516 else
517 {
518 conf.bilinear = (conf.bilinear + 1) % 3;
519 sprintf(strtitle, "bilinear filtering - %s", pbilinear[conf.bilinear]);
520 }
521 }
522 else
523 {
524 conf.interlace++;
525
526 if (conf.interlace > 2) conf.interlace = 0;
527
528 if (conf.interlace < 2)
529 sprintf(strtitle, "interlace on - mode %d", conf.interlace);
530 else
531 sprintf(strtitle, "interlace off");
532 }
533
534 ZeroGS::AddMessage(strtitle);
535
536 SaveConfig();
537 }
538
539 void OnKeyboardF6(int shift)
540 {
541 FUNCLOG
542
543 char strtitle[256];
544
545 if (shift)
546 {
547 conf.aa--; // -1
548 if (conf.aa > 4) conf.aa = 4; // u8 in unsigned, so negative value is 255.
549 sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa]);
550 ZeroGS::SetAA(conf.aa);
551 }
552 else
553 {
554 conf.aa++;
555 if (conf.aa > 4) conf.aa = 0;
556 sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa]);
557 ZeroGS::SetAA(conf.aa);
558 }
559
560 ZeroGS::AddMessage(strtitle);
561
562 SaveConfig();
563 }
564
565 void OnKeyboardF7(int shift)
566 {
567 FUNCLOG
568
569 char strtitle[256];
570
571 if (!shift)
572 {
573 extern bool g_bDisplayFPS;
574 g_bDisplayFPS ^= 1;
575 }
576 else
577 {
578 conf.options ^= GSOPTION_WIREFRAME;
579 glPolygonMode(GL_FRONT_AND_BACK, (conf.options&GSOPTION_WIREFRAME) ? GL_LINE : GL_FILL);
580 sprintf(strtitle, "wireframe rendering - %s", (conf.options&GSOPTION_WIREFRAME) ? "on" : "off");
581 }
582 }
583
584 void OnKeyboardF61(int shift)
585 {
586 FUNCLOG
587
588 char strtitle[256];
589
590 if (shift)
591 {
592 conf.negaa--; // -1
593 if (conf.negaa > 2) conf.negaa = 2; // u8 in unsigned, so negative value is 255.
594 sprintf(strtitle, "down resolution - %s", s_naa[conf.negaa]);
595 ZeroGS::SetNegAA(conf.negaa);
596 }
597 else
598 {
599 conf.negaa++;
600 if (conf.negaa > 2) conf.negaa = 0;
601 sprintf(strtitle, "down resolution - %s", s_naa[conf.negaa]);
602 ZeroGS::SetNegAA(conf.negaa);
603 }
604
605 ZeroGS::AddMessage(strtitle);
606 SaveConfig();
607 }
608
609 typedef struct GameHackStruct
610 {
611 const char HackName[40];
612 u32 HackMask;
613 } GameHack;
614
615 #define HACK_NUMBER 30
616
617 GameHack HackinshTable[HACK_NUMBER] =
618 {
619 {"*** 0 No Hack", 0},
620 {"*** 1 TexTargets Check", GAME_TEXTURETARGS},
621 {"*** 2 Autoreset Targets", GAME_AUTORESET},
622 {"*** 3 Interlace 2x", GAME_INTERLACE2X},
623 {"*** 4 TexA hack", GAME_TEXAHACK},
624 {"*** 5 No Target Resolve", GAME_NOTARGETRESOLVE},
625 {"*** 6 Exact color", GAME_EXACTCOLOR},
626 {"*** 7 No color clamp", GAME_NOCOLORCLAMP},
627 {"*** 8 FFX hack", GAME_FFXHACK},
628 {"*** 9 No Alpha Fail", GAME_NOALPHAFAIL},
629 {"***10 No Depth Update", GAME_NODEPTHUPDATE},
630 {"***11 Quick Resolve 1", GAME_QUICKRESOLVE1},
631 {"***12 No quick resolve", GAME_NOQUICKRESOLVE},
632 {"***13 Notaget clut", GAME_NOTARGETCLUT},
633 {"***14 No Stencil", GAME_NOSTENCIL},
634 {"***15 No Depth resolve", GAME_NODEPTHRESOLVE},
635 {"***16 Full 16 bit", GAME_FULL16BITRES},
636 {"***17 Resolve promoted", GAME_RESOLVEPROMOTED},
637 {"***18 Fast Update", GAME_FASTUPDATE},
638 {"***19 No Alpha Test", GAME_NOALPHATEST},
639 {"***20 Disable MRT deprh", GAME_DISABLEMRTDEPTH},
640 {"***21 32 bit targes", GAME_32BITTARGS},
641 {"***22 path 3 hack", GAME_PATH3HACK},
642 {"***23 parallelise calls", GAME_DOPARALLELCTX},
643 {"***24 specular highligths", GAME_XENOSPECHACK},
644 {"***25 partial pointers", GAME_PARTIALPOINTERS},
645 {"***26 partial depth", GAME_PARTIALDEPTH},
646 {"***27 reget hack", GAME_REGETHACK},
647
648 {"***28 gust hack", GAME_GUSTHACK},
649 {"***29 log-Z", GAME_NOLOGZ}
650 };
651
652 int CurrentHackSetting = 0;
653
654 void OnKeyboardF9(int shift)
655 {
656 FUNCLOG
657
658 // printf ("A %d\n", HackinshTable[CurrentHackSetting].HackMask);
659 conf.gamesettings &= !(HackinshTable[CurrentHackSetting].HackMask);
660
661 if (shift)
662 {
663 CurrentHackSetting--;
664
665 if (CurrentHackSetting == -1) CurrentHackSetting = HACK_NUMBER - 1;
666 }
667 else
668 {
669 CurrentHackSetting++;
670
671 if (CurrentHackSetting == HACK_NUMBER) CurrentHackSetting = 0;
672 }
673
674 conf.gamesettings |= HackinshTable[CurrentHackSetting].HackMask;
675
676 g_GameSettings = conf.gamesettings;
677 ZeroGS::AddMessage(HackinshTable[CurrentHackSetting].HackName);
678 SaveConfig();
679 }
680
681 void OnKeyboardF1(int shift)
682 {
683 FUNCLOG
684 char strtitle[256];
685 sprintf(strtitle, "Saving in savestate %d", CurrentSavestate);
686 SaveStateExists = true;
687 ZeroGS::AddMessage(HackinshTable[CurrentHackSetting].HackName);
688 }
689
690 #ifdef _WIN32
691
692 #ifdef _DEBUG
693 HANDLE g_hCurrentThread = NULL;
694 #endif
695
696
697 extern LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
698 extern HINSTANCE hInst;
699 #endif
700
701
702 s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread)
703 {
704 FUNCLOG
705
706 bool err;
707
708 g_GSMultiThreaded = multithread;
709
710 ZZLog::GS_Log("Calling GSopen.");
711
712 #ifdef _WIN32
713 #ifdef _DEBUG
714 g_hCurrentThread = GetCurrentThread();
715 #endif
716 #endif
717
718 LoadConfig();
719 strcpy(GStitle, Title);
720
721 err = GLWin.CreateWindow(pDsp);
722 if (!err)
723 {
724 ZZLog::GS_Log("Failed to create window. Exiting...");
725 return -1;
726 }
727
728 ZZLog::Error_Log("Using %s:%d.%d.%d.", libraryName, zgsrevision, zgsbuild, zgsminor);
729 ZZLog::Error_Log("Creating ZZOgl window.");
730
731 if (!ZeroGS::Create(conf.width, conf.height)) return -1;
732
733 ZZLog::Error_Log("Initialization successful.");
734
735 switch (conf.bilinear)
736 {
737 case 2:
738 ZeroGS::AddMessage("bilinear filtering - forced", 1000);
739 break;
740
741 case 1:
742 ZeroGS::AddMessage("bilinear filtering - normal", 1000);
743 break;
744
745 default:
746 break;
747 }
748
749 if (conf.aa)
750 {
751 char strtitle[64];
752 sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa]);
753 ZeroGS::AddMessage(strtitle, 1000);
754 }
755
756 luPerfFreq = GetCPUTicks();
757
758 gs.path[0].mode = gs.path[1].mode = gs.path[2].mode = 0;
759
760 ZZLog::GS_Log("GSopen finished.");
761
762 return 0;
763 }
764
765 #ifdef _WIN32
766 void ProcessMessages()
767 {
768 MSG msg;
769
770 ZeroMemory(&msg, sizeof(msg));
771
772 while (1)
773 {
774 if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
775 {
776 switch (msg.message)
777 {
778
779 case WM_KEYDOWN :
780 int my_KeyEvent = msg.wParam;
781 bool my_bShift = !!(GetKeyState(VK_SHIFT) & 0x8000);
782
783 switch (msg.wParam)
784 {
785
786 case VK_F5:
787 OnKeyboardF5(my_bShift);
788 break;
789
790 case VK_F6:
791 OnKeyboardF6(my_bShift);
792 break;
793
794 case VK_F7:
795 OnKeyboardF7(my_bShift);
796 break;
797
798 case VK_F9:
799 OnKeyboardF9(my_bShift);
800 break;
801
802 case VK_ESCAPE:
803
804 if (conf.options & GSOPTION_FULLSCREEN)
805 {
806 // destroy that msg
807 conf.options &= ~GSOPTION_FULLSCREEN;
808 ZeroGS::ChangeDeviceSize(conf.width, conf.height);
809 UpdateWindow(GShwnd);
810 continue; // so that msg doesn't get sent
811 }
812 else
813 {
814 SendMessage(GShwnd, WM_DESTROY, 0, 0);
815 //g_bHidden = 1;
816 return;
817 }
818
819 break;
820 }
821
822 break;
823 }
824
825 TranslateMessage(&msg);
826 DispatchMessage(&msg);
827 }
828 else
829 {
830 break;
831 }
832 }
833
834 if ((GetKeyState(VK_MENU) & 0x8000) && (GetKeyState(VK_RETURN) & 0x8000))
835 {
836 conf.options ^= GSOPTION_FULLSCREEN;
837
838 ZeroGS::SetChangeDeviceSize(
839 (conf.options&GSOPTION_FULLSCREEN) ? 1280 : conf.width,
840 (conf.options&GSOPTION_FULLSCREEN) ? 960 : conf.height);
841 }
842 }
843
844 #else // linux
845
846 void ProcessMessages()
847 {
848 FUNCLOG
849
850 // check resizing
851 GLWin.ResizeCheck();
852
853 if (THR_KeyEvent) // This values was passed from GSKeyEvents which could be in another thread
854 {
855 int my_KeyEvent = THR_KeyEvent;
856 bool my_bShift = THR_bShift;
857 THR_KeyEvent = 0;
858
859 switch (my_KeyEvent)
860 {
861 case XK_F5:
862 OnKeyboardF5(my_bShift);
863 break;
864
865 case XK_F6:
866 OnKeyboardF6(my_bShift);
867 break;
868
869 case XK_F7:
870 OnKeyboardF7(my_bShift);
871 break;
872
873 case XK_F9:
874 OnKeyboardF9(my_bShift);
875 break;
876 }
877 }
878 }
879
880 #endif // linux
881
882 void CALLBACK GSclose()
883 {
884 FUNCLOG
885
886 ZeroGS::Destroy(1);
887
888 GLWin.CloseWindow();
889
890 SaveStateFile = NULL;
891 SaveStateExists = true; // default value
892 }
893
894 void CALLBACK GSirqCallback(void (*callback)())
895 {
896 FUNCLOG
897
898 GSirq = callback;
899 }
900
901 void CALLBACK GSwriteCSR(u32 write)
902 {
903 FUNCLOG
904
905 gs.CSRw = write;
906 }
907
908 void CALLBACK GSchangeSaveState(int newstate, const char* filename)
909 {
910 FUNCLOG
911
912 char str[255];
913 sprintf(str, "save state %d", newstate);
914 ZeroGS::AddMessage(str);
915 CurrentSavestate = newstate;
916
917 SaveStateFile = filename;
918 SaveStateExists = (_access(SaveStateFile, 0) == 0);
919 }
920
921 void CALLBACK GSmakeSnapshot(char *path)
922 {
923 FUNCLOG
924
925 FILE *bmpfile;
926 char filename[256];
927 u32 snapshotnr = 0;
928
929 // increment snapshot value & try to get filename
930
931 for (;;)
932 {
933 snapshotnr++;
934
935 sprintf(filename, "%ssnap%03ld.%s", path, snapshotnr, (conf.options&GSOPTION_TGASNAP) ? "bmp" : "jpg");
936
937 bmpfile = fopen(filename, "rb");
938
939 if (bmpfile == NULL) break;
940
941 fclose(bmpfile);
942 }
943
944 // try opening new snapshot file
945 if ((bmpfile = fopen(filename, "wb")) == NULL)
946 {
947 char strdir[255];
948
949 #ifdef _WIN32
950 sprintf(strdir, "%s", path);
951 CreateDirectory(strdir, NULL);
952 #else
953 sprintf(strdir, "mkdir %s", path);
954 system(strdir);
955 #endif
956
957 if ((bmpfile = fopen(filename, "wb")) == NULL) return;
958 }
959
960 fclose(bmpfile);
961
962 // get the bits
963 ZeroGS::SaveSnapshot(filename);
964 }
965
966 int UPDATE_FRAMES = 16;
967 int g_nFrame = 0;
968 int g_nRealFrame = 0;
969
970 float fFPS = 0;
971
972 void CALLBACK GSvsync(int interlace)
973 {
974 FUNCLOG
975
976 //ZZLog::GS_Log("Calling GSvsync.");
977
978 static u32 dwTime = timeGetTime();
979 static int nToNextUpdate = 1;
980 char strtitle[256];
981
982 GL_REPORT_ERRORD();
983
984 g_nRealFrame++;
985
986 ZeroGS::RenderCRTC(!interlace);
987
988 ProcessMessages();
989
990 if (--nToNextUpdate <= 0)
991 {
992
993 u32 d = timeGetTime();
994 fFPS = UPDATE_FRAMES * 1000.0f / (float)max(d - dwTime, 1);
995 dwTime = d;
996 g_nFrame += UPDATE_FRAMES;
997
998 #if !defined(ZEROGS_DEVBUILD)
999 const char* g_pShaders[4] = { "full", "reduced", "accurate", "accurate-reduced" };
1000 const char* g_pInterlace[3] = { "interlace 0 |", "interlace 1 |", "" };
1001 const char* g_pBilinear[3] = { "", "bilinear |", "forced bilinear |" };
1002
1003 if (SaveStateFile != NULL && !SaveStateExists)
1004 SaveStateExists = (access(SaveStateFile, 0) == 0);
1005 else
1006 SaveStateExists = true;
1007
1008 sprintf(strtitle, "ZZ Open GL 0.%d.%d | %.1f fps | %s%s%s savestate %d%s | shaders %s | (%.1f)", zgsbuild, zgsminor, fFPS,
1009 g_pInterlace[conf.interlace], g_pBilinear[conf.bilinear],
1010 (conf.aa >= conf.negaa) ? (conf.aa ? s_aa[conf.aa - conf.negaa] : "") : (conf.negaa ? s_naa[conf.negaa - conf.aa] : ""),
1011 CurrentSavestate, (SaveStateExists ? "" : "*"),
1012 g_pShaders[g_nPixelShaderVer], (ppf&0xfffff) / (float)UPDATE_FRAMES);
1013
1014 #else
1015 sprintf(strtitle, "%d | %.1f fps (sk:%d%%) | g: %.1f, t: %.1f, a: %.1f, r: %.1f | p: %.1f | tex: %d %d (%d kbpf)", g_nFrame, fFPS,
1016 100*g_nFramesSkipped / g_nFrame,
1017 g_nGenVars / (float)UPDATE_FRAMES, g_nTexVars / (float)UPDATE_FRAMES, g_nAlphaVars / (float)UPDATE_FRAMES,
1018 g_nResolve / (float)UPDATE_FRAMES, (ppf&0xfffff) / (float)UPDATE_FRAMES,
1019 ZeroGS::g_MemTargs.listTargets.size(), ZeroGS::g_MemTargs.listClearedTargets.size(), g_TransferredToGPU >> 10);
1020
1021 //_snprintf(strtitle, 512, "%x %x", *(int*)(g_pbyGSMemory + 256 * 0x3e0c + 4), *(int*)(g_pbyGSMemory + 256 * 0x3e04 + 4));
1022
1023 #endif
1024
1025 // if( g_nFrame > 100 && fFPS > 60.0f ) {
1026 // ZZLog::Debug_Log("Set profile.");
1027 // g_bWriteProfile = 1;
1028 // }
1029 if (!(conf.options & GSOPTION_FULLSCREEN)) GLWin.SetTitle(strtitle);
1030
1031 if (fFPS < 16) UPDATE_FRAMES = 4;
1032 else if (fFPS < 32) UPDATE_FRAMES = 8;
1033 else UPDATE_FRAMES = 16;
1034
1035 nToNextUpdate = UPDATE_FRAMES;
1036
1037 g_TransferredToGPU = 0;
1038 g_nGenVars = 0;
1039 g_nTexVars = 0;
1040 g_nAlphaVars = 0;
1041 g_nResolve = 0;
1042
1043 ppf = 0;
1044
1045 g_nFramesSkipped = 0;
1046 }
1047
1048 #if defined(ZEROGS_DEVBUILD)
1049 if (g_bWriteProfile)
1050 {
1051 //g_bWriteProfile = 0;
1052 DVProfWrite("prof.txt", UPDATE_FRAMES);
1053 DVProfClear();
1054 }
1055
1056 #endif
1057 GL_REPORT_ERRORD();
1058 }
1059
1060 void CALLBACK GSreadFIFO(u64 *pMem)
1061 {
1062 FUNCLOG
1063
1064 //ZZLog::GS_Log("Calling GSreadFIFO.");
1065
1066 ZeroGS::TransferLocalHost((u32*)pMem, 1);
1067 }
1068
1069 void CALLBACK GSreadFIFO2(u64 *pMem, int qwc)
1070 {
1071 FUNCLOG
1072
1073 //ZZLog::GS_Log("Calling GSreadFIFO2.");
1074
1075 ZeroGS::TransferLocalHost((u32*)pMem, qwc);
1076 }
1077
1078 int CALLBACK GSsetupRecording(int start, void* pData)
1079 {
1080 FUNCLOG
1081
1082 if (start)
1083 {
1084 if (conf.options & GSOPTION_CAPTUREAVI) return 1;
1085
1086 ZeroGS::StartCapture();
1087
1088 conf.options |= GSOPTION_CAPTUREAVI;
1089
1090 ZZLog::Warn_Log("Started recording zerogs.avi.");
1091 }
1092 else
1093 {
1094 if (!(conf.options & GSOPTION_CAPTUREAVI)) return 1;
1095
1096 conf.options &= ~GSOPTION_CAPTUREAVI;
1097
1098 ZeroGS::StopCapture();
1099
1100 ZZLog::Warn_Log("Stopped recording.");
1101 }
1102
1103 return 1;
1104 }
1105
1106 s32 CALLBACK GSfreeze(int mode, freezeData *data)
1107 {
1108 FUNCLOG
1109
1110 switch (mode)
1111 {
1112 case FREEZE_LOAD:
1113 if (!ZeroGS::Load(data->data)) ZZLog::Error_Log("GS: Bad load format!");
1114 g_nRealFrame += 100;
1115 break;
1116
1117 case FREEZE_SAVE:
1118 ZeroGS::Save(data->data);
1119 break;
1120
1121 case FREEZE_SIZE:
1122 data->size = ZeroGS::Save(NULL);
1123 break;
1124
1125 default:
1126 break;
1127 }
1128
1129 return 0;
1130 }

  ViewVC Help
Powered by ViewVC 1.1.22