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