]> Shamusworld >> Repos - virtualjaguar/blob - src/vj.cpp
Fixed fullscreen<-->windowed mode swith in OpenGL mode, phase one of
[virtualjaguar] / src / vj.cpp
1 //
2 // Virtual Jaguar Emulator
3 //
4 // Original codebase by David Raingeard (Cal2)
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes/enhancements by James L. Hammons and Adam Green
7 //
8
9 #include <time.h>
10 #include <SDL.h>
11 #include "jaguar.h"
12 #include "video.h"
13 #include "gui.h"
14 #include "sdlemu_opengl.h"
15 #include "settings.h"                                                           // Pull in "vjs" struct
16 #include "log.h"
17 #include "version.h"
18 #include "memory.h"
19 #include "file.h"
20
21 // Uncomment this to use built-in BIOS/CD-ROM BIOS
22 // You'll need a copy of jagboot.h & jagcd.h for this to work...!
23 //#define USE_BUILT_IN_BIOS
24
25 #ifdef USE_BUILT_IN_BIOS
26 #include "jagboot.h"
27 #include "jagcd.h"
28 #endif
29
30 // Private function prototypes
31
32 //
33 // The main emulator loop (what else?)
34 //
35 //Maybe we should move the video stuff to TOM? Makes more sense to put it there...
36 //Actually, it would probably be better served in VIDEO.CPP... !!! FIX !!! [DONE]
37 //uint32 totalFrames;//temp, so we can grab this from elsewhere...
38 int main(int argc, char * argv[])
39 {
40 //NOTE: This isn't actually used anywhere... !!! FIX !!!
41         int32 nFrameskip = 0;                                                   // Default: Show every frame
42
43         printf("Virtual Jaguar GCC/SDL Portable Jaguar Emulator v1.1.0\n");
44         printf("Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n");
45         printf("Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n");
46         printf("James L. Hammons (WIN32) and Adam Green (MacOS)\n");
47         printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
48
49         bool haveCart = false;                                                  // Assume there is no cartridge...!
50
51         log_init("vj.log");
52         LoadVJSettings();                                                               // Get config file settings...
53
54         // Check the switches... ;-)
55         // NOTE: Command line switches can override any config file settings, thus the
56         //       proliferation of the noXXX switches. ;-)
57
58         for(int i=1; i<argc || argv[i]!=NULL; i++)
59         {
60                 // This would be the most likely place to do the cart loading...
61                 if (argv[i][0] != '-')
62                         haveCart = true;                                                // It looks like we have a cartridge!
63
64                 if (!strcmp(argv[i], "-joystick"))
65                         vjs.useJoystick = true;
66
67                 if (!strcmp(argv[i], "-joyport"))
68                 {
69                         vjs.joyport = atoi(argv[++i]) + 1;
70                         if (vjs.joyport > 3)
71                                 vjs.joyport = 3;
72                 }
73
74                 if (!strcmp(argv[i], "-frameskip"))
75                 {
76                         nFrameskip = atoi(argv[++i]) + 1;
77                         if (nFrameskip > 10)
78                                 nFrameskip = 10;
79                 }
80
81                 if (!strcmp(argv[i], "-bios"))
82                         vjs.useJaguarBIOS = true;
83
84                 if (!strcmp(argv[i], "-nobios"))
85                         vjs.useJaguarBIOS = false;
86
87                 if (!strcmp(argv[i], "-dsp"))
88                         vjs.DSPEnabled = true;
89
90                 if (!strcmp(argv[i], "-nodsp"))
91                         vjs.DSPEnabled = false;
92
93                 if (!strcmp(argv[i], "-pipeline"))
94                         vjs.usePipelinedDSP = true;
95
96                 if (!strcmp(argv[i], "-nopipeline"))
97                         vjs.usePipelinedDSP = false;
98
99                 if (!strcmp(argv[i], "-gl"))
100                         vjs.useOpenGL = true;
101
102                 if (!strcmp(argv[i], "-nogl"))
103                         vjs.useOpenGL = false;
104
105                 if (!strcmp(argv[i], "-fullscreen"))
106                         vjs.fullscreen = true;
107
108                 if (!strcmp(argv[i], "-window"))
109                         vjs.fullscreen = false;
110
111                 if (!strcmp(argv[i], "-pal"))
112                         vjs.hardwareTypeNTSC = false;
113
114                 if (!strcmp(argv[i], "-ntsc"))
115                         vjs.hardwareTypeNTSC = true;
116
117                 if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-?"))
118                 {
119                     printf("Usage: \n\n");
120                         printf("vj [romfile] [switches]\n");
121                         printf("  -? or --help    : Display usage and switches                \n");
122                         printf("  -frameskip 1-10 : Enable frameskip 1 - 10 (default: none)   \n");
123                         printf("  -joystick       : Enable joystick/gamepad                   \n");
124                         printf("  -joyport 0-3    : Select desired joystick port              \n");
125                         printf("  -bios           : Boot cart using Jaguar BIOS ROM           \n");
126                         printf("  -nobios         : Boot cart without using Jaguar BIOS ROM   \n");
127                         printf("  -dsp            : Force VJ to use the DSP                   \n");
128                         printf("  -nodsp          : Force VJ to run without the DSP           \n");
129                         printf("  -pipeline       : Use the DSP pipelined core                \n");
130                         printf("  -nopipeline     : Use the DSP non-pipelined core            \n");
131                         printf("  -gl             : Use OpenGL rendering                      \n");
132                         printf("  -nogl           : Use old non-OpenGL rendering              \n");
133                         printf("  -fullscreen     : Enable fullscreen mode (default: windowed)\n");
134                         printf("  -window         : Enable windowed mode                      \n");
135                         printf("  -pal            : Force VJ to PAL mode (default: NTSC)      \n");
136                         printf("  -ntsc           : Force VJ to NTSC mode                     \n");
137                         printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
138                         printf("with the VJ GUI.\n");
139                         return 1;
140                 }
141     }
142
143         // Set up SDL library
144         if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
145         {
146                 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
147                 return -1;
148         }
149
150         WriteLog("VJ: SDL successfully initialized.\n");
151
152 WriteLog("Initializing memory subsystem...\n");
153         InitMemory();
154 WriteLog("Initializing version...\n");
155         InitVersion();
156         version_display(log_get());
157 WriteLog("Initializing jaguar subsystem...\n");
158         jaguar_init();
159
160         // Get the BIOS ROM
161 #ifdef USE_BUILT_IN_BIOS
162         WriteLog("VJ: Using built in BIOS/CD BIOS...\n");
163         memcpy(jaguar_bootRom, jagBootROM, 0x20000);
164         memcpy(jaguar_CDBootROM, jagCDROM, 0x40000);
165         BIOSLoaded = CDBIOSLoaded = true;
166 #else
167 // What would be nice here would be a way to check if the BIOS was loaded so that we
168 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
169 WriteLog("About to attempt to load BIOSes...\n");
170         BIOSLoaded = (JaguarLoadROM(jaguar_bootRom, vjs.jagBootPath) == 0x20000 ? true : false);
171         WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
172         CDBIOSLoaded = (JaguarLoadROM(jaguar_CDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
173         WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
174 #endif
175
176         SET32(jaguar_mainRam, 0, 0x00200000);                   // Set top of stack...
177
178 WriteLog("Initializing video subsystem...\n");
179         InitVideo();
180 WriteLog("Initializing GUI subsystem...\n");
181         InitGUI();
182
183         // Now with crunchy GUI goodness!
184 WriteLog("About to start GUI...\n");
185         GUIMain(haveCart ? argv[1] : NULL);
186
187 //This is no longer accurate...!
188 //      int elapsedTime = clock() - startTime;
189 //      int fps = (1000 * totalFrames) / elapsedTime;
190 //      WriteLog("VJ: Ran at an average of %i FPS.\n", fps);
191
192         jaguar_done();
193         VersionDone();
194         MemoryDone();
195         VideoDone();
196         log_done();
197
198         // Free SDL components last...!
199         SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER);
200         SDL_Quit();
201
202     return 0;
203 }