-
Notifications
You must be signed in to change notification settings - Fork 5
/
GS.cpp
1690 lines (1300 loc) · 28.6 KB
/
GS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2007-2009 Gabest
* http://www.gabest.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "stdafx.h"
#include "GSdx.h"
#include "GSUtil.h"
#include "GSRendererSW.h"
#include "GSRendererNull.h"
#include "GSDeviceNull.h"
#include "GSDeviceOGL.h"
#include "GSRendererOGL.h"
#include "GSRendererCL.h"
#ifdef _WINDOWS
#include "GSRendererDX9.h"
#include "GSRendererDX11.h"
#include "GSDevice9.h"
#include "GSDevice11.h"
#include "GSWndDX.h"
#include "GSWndWGL.h"
#include "GSRendererCS.h"
#include "GSSettingsDlg.h"
static HRESULT s_hr = E_FAIL;
#else
#include "GSWndOGL.h"
#include "GSWndEGL.h"
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
extern bool RunLinuxDialog();
#endif
#define PS2E_LT_GS 0x01
#define PS2E_GS_VERSION 0x0006
#define PS2E_X86 0x01 // 32 bit
#define PS2E_X86_64 0x02 // 64 bit
static GSRenderer* s_gs = NULL;
static void (*s_irq)() = NULL;
static uint8* s_basemem = NULL;
static int s_renderer = -1;
static bool s_framelimit = true;
static bool s_vsync = false;
static bool s_exclusive = true;
#ifdef _WINDOWS
static bool s_isgsopen2 = false; // boolean to remove some stuff from the config panel in new PCSX2's/
#endif
bool gsopen_done = false; // crash guard for GSgetTitleInfo2
EXPORT_C_(uint32) PS2EgetLibType()
{
return PS2E_LT_GS;
}
EXPORT_C_(const char*) PS2EgetLibName()
{
return GSUtil::GetLibName();
}
EXPORT_C_(uint32) PS2EgetLibVersion2(uint32 type)
{
const uint32 revision = 0;
const uint32 build = 1;
return (build << 0) | (revision << 8) | (PS2E_GS_VERSION << 16) | (PLUGIN_VERSION << 24);
}
#ifdef _WINDOWS
EXPORT_C_(void) PS2EsetEmuVersion(const char* emuId, uint32 version)
{
s_isgsopen2 = true;
}
#endif
EXPORT_C_(uint32) PS2EgetCpuPlatform()
{
#ifdef _M_AMD64
return PS2E_X86_64;
#else
return PS2E_X86;
#endif
}
EXPORT_C GSsetBaseMem(uint8* mem)
{
s_basemem = mem;
if(s_gs)
{
s_gs->SetRegsMem(s_basemem);
}
}
EXPORT_C GSsetSettingsDir(const char* dir)
{
theApp.SetConfigDir(dir);
}
EXPORT_C_(int) GSinit()
{
if(!GSUtil::CheckSSE())
{
return -1;
}
#ifdef _WINDOWS
s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(!GSUtil::CheckDirectX())
{
return -1;
}
#endif
return 0;
}
EXPORT_C GSshutdown()
{
gsopen_done = false;
delete s_gs;
s_gs = NULL;
s_renderer = -1;
#ifdef _WINDOWS
if(SUCCEEDED(s_hr))
{
::CoUninitialize();
s_hr = E_FAIL;
}
#endif
}
EXPORT_C GSclose()
{
gsopen_done = false;
if(s_gs == NULL) return;
s_gs->ResetDevice();
// Opengl requirement: It must be done before the Detach() of
// the context
delete s_gs->m_dev;
s_gs->m_dev = NULL;
if (s_gs->m_wnd)
{
s_gs->m_wnd->Detach();
}
}
static int _GSopen(void** dsp, char* title, int renderer, int threads = -1)
{
// I really don't know the impact on windows! It could work
#ifdef __linux__
if (theApp.GetConfig("enable_nvidia_multi_thread", 1)) {
setenv("__GL_THREADED_OPTIMIZATIONS", "1", 0);
}
#endif
GSDevice* dev = NULL;
if(renderer == -1)
{
renderer = theApp.GetConfig("renderer", 0);
}
if(threads == -1)
{
threads = theApp.GetConfig("extrathreads", 0);
}
GSWnd* wnd[2];
try
{
if(s_renderer != renderer)
{
// Emulator has made a render change request, which requires a completely
// new s_gs -- if the emu doesn't save/restore the GS state across this
// GSopen call then they'll get corrupted graphics, but that's not my problem.
delete s_gs;
s_gs = NULL;
}
switch(renderer)
{
default:
#ifdef _WINDOWS
case 0: case 1: case 2: case 14:
dev = new GSDevice9();
break;
case 3: case 4: case 5: case 15:
dev = new GSDevice11();
break;
#endif
case 9: case 10: case 11: case 16:
dev = new GSDeviceNull();
break;
case 12: case 13: case 17:
dev = new GSDeviceOGL();
break;
}
if(dev == NULL)
{
return -1;
}
if(s_gs == NULL)
{
switch(renderer)
{
default:
#ifdef _WINDOWS
case 0:
s_gs = (GSRenderer*)new GSRendererDX9();
break;
case 3:
s_gs = (GSRenderer*)new GSRendererDX11();
break;
#endif
case 12:
s_gs = (GSRenderer*)new GSRendererOGL();
break;
case 1: case 4: case 10: case 13:
s_gs = new GSRendererSW(threads);
break;
case 2: case 5: case 11:
s_gs = new GSRendererNull();
break;
case 14: case 15: case 16: case 17:
#ifdef ENABLE_OPENCL
s_gs = new GSRendererCL();
#else
printf("GSdx error: opencl is disabled\n");
#endif
break;
}
if (s_gs == NULL)
return -1;
s_renderer = renderer;
}
if (s_gs->m_wnd == NULL)
{
#ifdef _WINDOWS
switch(renderer)
{
case 12: case 13: case 17:
s_gs->m_wnd = new GSWndWGL();
break;
default:
s_gs->m_wnd = new GSWndDX();
break;
}
#else
wnd[0] = new GSWndOGL();
#ifdef EGL_SUPPORTED
wnd[1] = new GSWndEGL();
#else
wnd[1] = NULL;
#endif
#endif
}
}
catch(std::exception& ex)
{
// Allowing std exceptions to escape the scope of the plugin callstack could
// be problematic, because of differing typeids between DLL and EXE compilations.
// ('new' could throw std::alloc)
printf("GSdx error: Exception caught in GSopen: %s", ex.what());
return -1;
}
s_gs->SetRegsMem(s_basemem);
s_gs->SetIrqCallback(s_irq);
s_gs->SetVSync(s_vsync);
s_gs->SetFrameLimit(s_framelimit);
if(*dsp == NULL)
{
// old-style API expects us to create and manage our own window:
int w = theApp.GetConfig("ModeWidth", 0);
int h = theApp.GetConfig("ModeHeight", 0);
#ifdef __linux__
for(uint32 i = 0; i < 2; i++) {
try
{
if (wnd[i] == NULL) continue;
wnd[i]->Create(title, w, h);
s_gs->m_wnd = wnd[i];
if (i == 0) delete wnd[1];
break;
}
catch (GSDXRecoverableError)
{
wnd[i]->Detach();
delete wnd[i];
}
}
if (s_gs->m_wnd == NULL)
{
GSclose();
return -1;
}
#endif
#ifdef _WINDOWS
if(!s_gs->CreateWnd(title, w, h))
{
GSclose();
return -1;
}
#endif
s_gs->m_wnd->Show();
*dsp = s_gs->m_wnd->GetDisplay();
}
else
{
s_gs->SetMultithreaded(true);
#ifdef __linux__
if (s_gs->m_wnd) {
// A window was already attached to s_gs so we also
// need to restore the window state (Attach)
s_gs->m_wnd->Attach((void*)((uptr*)(dsp)+1), false);
} else {
// No window found, try to attach a GLX win and retry
// with EGL win if failed.
for(uint32 i = 0; i < 2; i++) {
try
{
if (wnd[i] == NULL) continue;
wnd[i]->Attach((void*)((uptr*)(dsp)+1), false);
s_gs->m_wnd = wnd[i];
if (i == 0) delete wnd[1];
break;
}
catch (GSDXRecoverableError)
{
wnd[i]->Detach();
delete wnd[i];
}
}
}
if (s_gs->m_wnd == NULL)
{
return -1;
}
#endif
#ifdef _WINDOWS
s_gs->m_wnd->Attach(*dsp, false);
#endif
}
if(!s_gs->CreateDevice(dev))
{
// This probably means the user has DX11 configured with a video card that is only DX9
// compliant. Cound mean drivr issues of some sort also, but to be sure, that's the most
// common cause of device creation errors. :) --air
GSclose();
return -1;
}
return 0;
}
EXPORT_C_(int) GSopen2(void** dsp, uint32 flags)
{
#ifdef __linux__
// Use ogl renderer as default otherwise it crash at startup
// GSRenderOGL only GSDeviceOGL (not GSDeviceNULL)
int renderer = theApp.GetConfig("renderer", 12);
#else
int renderer = theApp.GetConfig("renderer", 0);
#endif
if(flags & 4)
{
#ifdef _WINDOWS
int best_sw_renderer = GSUtil::CheckDirect3D11Level() >= D3D_FEATURE_LEVEL_10_0 ? 4 : 1; // dx11 / dx9 sw
switch(renderer){
// Use alternative renderer (SW if currently using HW renderer, and vice versa, keeping the same DX level)
case 1: renderer = 0; break; // DX9: SW to HW
case 0: renderer = 1; break; // DX9: HW to SW
case 4: renderer = 3; break; // DX11: SW to HW
case 3: renderer = 4; break; // DX11: HW to SW
case 13: renderer = 12; break; // OGL: SW to HW
case 12: renderer = 13; break; // OGL: HW to SW
default: renderer = best_sw_renderer; // If wasn't using DX (e.g. SDL), use best SW renderer.
}
#endif
#ifdef __linux__
switch(renderer) {
case 13: renderer = 12; break; // OGL: SW to HW
case 12: renderer = 13; break; // OGL: HW to SW
}
#endif
}
int retval = _GSopen(dsp, NULL, renderer);
if (s_gs != NULL)
s_gs->SetAspectRatio(0); // PCSX2 manages the aspect ratios
gsopen_done = true;
return retval;
}
EXPORT_C_(int) GSopen(void** dsp, char* title, int mt)
{
/*
if(!XInitThreads()) return -1;
Display* display = XOpenDisplay(0);
XCloseDisplay(display);
*/
int renderer = 0;
// Legacy GUI expects to acquire vsync from the configuration files.
s_vsync = !!theApp.GetConfig("vsync", 0);
if(mt == 2)
{
// pcsx2 sent a switch renderer request
#ifdef _WINDOWS
renderer = GSUtil::CheckDirect3D11Level() >= D3D_FEATURE_LEVEL_10_0 ? 4 : 1; // dx11 / dx9 sw
#endif
mt = 1;
}
else
{
// normal init
renderer = theApp.GetConfig("renderer", 0);
}
*dsp = NULL;
int retval = _GSopen(dsp, title, renderer);
if(retval == 0 && s_gs)
{
s_gs->SetMultithreaded(!!mt);
}
gsopen_done = true;
return retval;
}
EXPORT_C GSreset()
{
try
{
s_gs->Reset();
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifSoftReset(uint32 mask)
{
try
{
s_gs->SoftReset(mask);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSwriteCSR(uint32 csr)
{
try
{
s_gs->WriteCSR(csr);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSinitReadFIFO(uint8* mem)
{
GL_PERF("Init Read FIFO1");
try
{
s_gs->InitReadFIFO(mem, 1);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSreadFIFO(uint8* mem)
{
GL_PERF("Read FIFO1");
try
{
s_gs->ReadFIFO(mem, 1);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSinitReadFIFO2(uint8* mem, uint32 size)
{
GL_PERF("Init Read FIFO2");
try
{
s_gs->InitReadFIFO(mem, size);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSreadFIFO2(uint8* mem, uint32 size)
{
GL_PERF("Read FIFO2");
try
{
s_gs->ReadFIFO(mem, size);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifTransfer(const uint8* mem, uint32 size)
{
try
{
s_gs->Transfer<3>(mem, size);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifTransfer1(uint8* mem, uint32 addr)
{
try
{
s_gs->Transfer<0>(const_cast<uint8*>(mem) + addr, (0x4000 - addr) / 16);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifTransfer2(uint8* mem, uint32 size)
{
try
{
s_gs->Transfer<1>(const_cast<uint8*>(mem), size);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifTransfer3(uint8* mem, uint32 size)
{
try
{
s_gs->Transfer<2>(const_cast<uint8*>(mem), size);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSvsync(int field)
{
try
{
#ifdef _WINDOWS
if(s_gs->m_wnd->IsManaged())
{
MSG msg;
memset(&msg, 0, sizeof(msg));
while(msg.message != WM_QUIT && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#endif
s_gs->VSync(field);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C_(uint32) GSmakeSnapshot(char* path)
{
try
{
string s(path);
if(!s.empty() && s[s.length() - 1] != DIRECTORY_SEPARATOR)
{
s = s + DIRECTORY_SEPARATOR;
}
return s_gs->MakeSnapshot(s + "gsdx");
}
catch (GSDXRecoverableError)
{
return false;
}
}
EXPORT_C GSkeyEvent(GSKeyEventData* e)
{
try
{
if(gsopen_done)
{
s_gs->KeyEvent(e);
}
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C_(int) GSfreeze(int mode, GSFreezeData* data)
{
try
{
if(mode == FREEZE_SAVE)
{
return s_gs->Freeze(data, false);
}
else if(mode == FREEZE_SIZE)
{
return s_gs->Freeze(data, true);
}
else if(mode == FREEZE_LOAD)
{
return s_gs->Defrost(data);
}
}
catch (GSDXRecoverableError)
{
}
return 0;
}
EXPORT_C GSconfigure()
{
try
{
if(!GSUtil::CheckSSE()) return;
#ifdef _WINDOWS
if(GSSettingsDlg(s_isgsopen2).DoModal() == IDOK)
{
if(s_gs != NULL && s_gs->m_wnd->IsManaged())
{
// Legacy apps like gsdxgui expect this...
GSshutdown();
}
}
#else
if (RunLinuxDialog()) {
theApp.ReloadConfig();
}
#endif
} catch (GSDXRecoverableError)
{
}
}
EXPORT_C_(int) GStest()
{
if(!GSUtil::CheckSSE())
{
return -1;
}
#ifdef _WINDOWS
s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(!GSUtil::CheckDirectX())
{
if(SUCCEEDED(s_hr))
{
::CoUninitialize();
}
s_hr = E_FAIL;
return -1;
}
if(SUCCEEDED(s_hr))
{
::CoUninitialize();
}
s_hr = E_FAIL;
#endif
return 0;
}
EXPORT_C GSabout()
{
}
EXPORT_C GSirqCallback(void (*irq)())
{
s_irq = irq;
if(s_gs)
{
s_gs->SetIrqCallback(s_irq);
}
}
void pt(const char* str){
struct tm *current;
time_t now;
time(&now);
current = localtime(&now);
printf("%02i:%02i:%02i%s", current->tm_hour, current->tm_min, current->tm_sec, str);
}
EXPORT_C_(int) GSsetupRecording(int start, void* data)
{
if (s_gs == NULL) {
printf("GSdx: no s_gs for recording\n");
return 0;
}
#ifdef __linux__
if (theApp.GetConfig("capture_enabled", 0)) {
printf("GSdx: Recording is disabled\n");
return 0;
}
#endif
if(start & 1)
{
printf("GSdx: Recording start command\n");
if( s_gs->BeginCapture() )
pt(" - Capture started\n");
}
else
{
printf("GSdx: Recording end command\n");
s_gs->EndCapture();
pt(" - Capture ended\n");
}
return 1;
}
EXPORT_C GSsetGameCRC(uint32 crc, int options)
{
s_gs->SetGameCRC(crc, options);
}
EXPORT_C GSgetLastTag(uint32* tag)
{
s_gs->GetLastTag(tag);
}
EXPORT_C GSgetTitleInfo2(char* dest, size_t length)
{
if (gsopen_done == false) {
//printf("GSdx: GSgetTitleInfo but GSOpen not yet done. Ignoring\n");
return;
}
string s = "GSdx-Cutie";
// TODO: this gets called from a different thread concurrently with GSOpen (on linux)
if(s_gs == NULL) return;
if(s_gs->m_GStitleInfoBuffer[0])
{
#ifdef _CX11_
std::lock_guard<std::mutex> lock(s_gs->m_pGSsetTitle_Crit);
#else
GSAutoLock lock(&s_gs->m_pGSsetTitle_Crit);
#endif
s = format("GSdx-Cutie| %s", s_gs->m_GStitleInfoBuffer);
if(s.size() > length - 1)
{
s = s.substr(0, length - 1);
}
}
strcpy(dest, s.c_str());
}
EXPORT_C GSsetFrameSkip(int frameskip)
{
s_gs->SetFrameSkip(frameskip);
}
EXPORT_C GSsetVsync(int enabled)
{
s_vsync = !!enabled;
if(s_gs)
{
s_gs->SetVSync(s_vsync);
}
}
EXPORT_C GSsetExclusive(int enabled)
{
s_exclusive = !!enabled;
if(s_gs)
{
s_gs->SetVSync(s_vsync);
}
}
EXPORT_C GSsetFrameLimit(int limit)
{
s_framelimit = !!limit;
if(s_gs)
{
s_gs->SetFrameLimit(s_framelimit);
}
}
#ifdef _WINDOWS
#include <io.h>
#include <fcntl.h>
class Console
{
HANDLE m_console;
string m_title;
public:
Console::Console(LPCSTR title, bool open)
: m_console(NULL)
, m_title(title)
{
if(open) Open();
}
Console::~Console()
{
Close();
}
void Console::Open()
{
if(m_console == NULL)
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
AllocConsole();
SetConsoleTitle(m_title.c_str());
m_console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD size;
size.X = 100;
size.Y = 300;
SetConsoleScreenBufferSize(m_console, size);
GetConsoleScreenBufferInfo(m_console, &csbiInfo);
SMALL_RECT rect;
rect = csbiInfo.srWindow;
rect.Right = rect.Left + 99;
rect.Bottom = rect.Top + 64;
SetConsoleWindowInfo(m_console, TRUE, &rect);
*stdout = *_fdopen(_open_osfhandle((long)m_console, _O_TEXT), "w");
setvbuf(stdout, NULL, _IONBF, 0);
}
}
void Console::Close()
{
if(m_console != NULL)
{
FreeConsole();
m_console = NULL;
}
}
};
// lpszCmdLine:
// First parameter is the renderer.
// Second parameter is the gs file to load and run.
EXPORT_C GSReplay(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
int renderer = -1;