2 // Virtual Jaguar Emulator
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
10 #include <unistd.h> // Is this necessary anymore?
18 #include "sdlemu_opengl.h"
19 #include "settings.h" // Pull in "vjs" struct
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
25 #ifdef USE_BUILT_IN_BIOS
30 // Private function prototypes
34 extern uint8 * jaguar_mainRam;
35 extern uint8 * jaguar_mainRom;
36 extern uint8 * jaguar_bootRom;
37 extern uint8 * jaguar_CDBootROM;
39 // Global variables (export capable)
40 //should these even be here anymore?
42 bool finished = false;
44 bool showMessage = false;
45 uint32 showMessageTimeout;
46 char messageBuffer[200];
47 bool BIOSLoaded = false;
48 bool CDBIOSLoaded = false;
51 // The main emulator loop (what else?)
53 //Maybe we should move the video stuff to TOM? Makes more sense to put it there...
54 //Actually, it would probably be better served in VIDEO.CPP... !!! FIX !!! [DONE]
55 uint32 totalFrames;//temp, so we can grab this from elsewhere...
56 int main(int argc, char * argv[])
58 //NOTE: This isn't actually used anywhere... !!! FIX !!!
59 int32 nFrameskip = 0; // Default: Show every frame
61 printf("Virtual Jaguar GCC/SDL Portable Jaguar Emulator v1.1.0\n");
62 printf("Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n");
63 printf("Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n");
64 printf("James L. Hammons (WIN32) and Adam Green (MacOS)\n");
65 printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
67 bool haveCart = false; // Assume there is no cartridge...!
70 LoadVJSettings(); // Get config file settings...
72 // Check the switches... ;-)
73 // NOTE: Command line switches can override any config file settings, thus the
74 // proliferation of the noXXX switches. ;-)
76 for(int i=1; i<argc || argv[i]!=NULL; i++)
78 // This would be the most likely place to do the cart loading...
79 if (argv[i][0] != '-')
80 haveCart = true; // It looks like we have a cartridge!
82 if (!strcmp(argv[i], "-joystick"))
83 vjs.useJoystick = true;
85 if (!strcmp(argv[i], "-joyport"))
87 vjs.joyport = atoi(argv[++i]) + 1;
92 if (!strcmp(argv[i], "-frameskip"))
94 nFrameskip = atoi(argv[++i]) + 1;
99 if (!strcmp(argv[i], "-bios"))
100 vjs.useJaguarBIOS = true;
102 if (!strcmp(argv[i], "-nobios"))
103 vjs.useJaguarBIOS = false;
105 if (!strcmp(argv[i], "-dsp"))
106 vjs.DSPEnabled = true;
108 if (!strcmp(argv[i], "-nodsp"))
109 vjs.DSPEnabled = false;
111 if (!strcmp(argv[i], "-pipeline"))
112 vjs.usePipelinedDSP = true;
114 if (!strcmp(argv[i], "-nopipeline"))
115 vjs.usePipelinedDSP = false;
117 if (!strcmp(argv[i], "-gl"))
118 vjs.useOpenGL = true;
120 if (!strcmp(argv[i], "-nogl"))
121 vjs.useOpenGL = false;
123 if (!strcmp(argv[i], "-fullscreen"))
124 vjs.fullscreen = true;
126 if (!strcmp(argv[i], "-window"))
127 vjs.fullscreen = false;
129 if (!strcmp(argv[i], "-pal"))
130 vjs.hardwareTypeNTSC = false;
132 if (!strcmp(argv[i], "-ntsc"))
133 vjs.hardwareTypeNTSC = true;
135 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?"))
137 printf("Usage: \n\n");
138 printf("vj [romfile] [switches]\n");
139 printf(" -? or -help : Display usage and switches \n");
140 printf(" -frameskip 1-10 : Enable frameskip 1 - 10 (default: none) \n");
141 printf(" -joystick : Enable joystick/gamepad \n");
142 printf(" -joyport 0-3 : Select desired joystick port \n");
143 printf(" -bios : Boot cart using Jaguar BIOS ROM \n");
144 printf(" -nobios : Boot cart without using Jaguar BIOS ROM \n");
145 printf(" -dsp : Force VJ to use the DSP \n");
146 printf(" -nodsp : Force VJ to run without the DSP \n");
147 printf(" -pipeline : Use the DSP pipelined core \n");
148 printf(" -nopipeline : Use the DSP non-pipelined core \n");
149 printf(" -gl : Use OpenGL rendering \n");
150 printf(" -nogl : Use old non-OpenGL rendering \n");
151 printf(" -fullscreen : Enable fullscreen mode (default: windowed)\n");
152 printf(" -window : Enable windowed mode \n");
153 printf(" -pal : Force VJ to PAL mode (default: NTSC) \n");
154 printf(" -ntsc : Force VJ to NTSC mode \n");
155 printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
156 printf("with the VJ GUI.\n");
161 // Set up SDL library
162 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
163 // | SDL_INIT_CDROM) < 0)
164 // | SDL_INIT_CDROM | SDL_INIT_NOPARACHUTE) < 0)
166 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
170 WriteLog("VJ: SDL successfully initialized.\n");
172 WriteLog("Initializing memory subsystem...\n");
174 WriteLog("Initializing version...\n");
176 version_display(log_get());
177 WriteLog("Initializing jaguar subsystem...\n");
181 #ifdef USE_BUILT_IN_BIOS
182 WriteLog("VJ: Using built in BIOS/CD BIOS...\n");
183 memcpy(jaguar_bootRom, jagBootROM, 0x20000);
184 memcpy(jaguar_CDBootROM, jagCDROM, 0x40000);
185 BIOSLoaded = CDBIOSLoaded = true;
187 // if (vjs.useJaguarBIOS)
188 // What would be nice here would be a way to check if the BIOS was loaded so that we
189 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
190 WriteLog("About to attempt to load BIOSes...\n");
191 BIOSLoaded = (JaguarLoadROM(jaguar_bootRom, vjs.jagBootPath) == 0x20000 ? true : false);
192 WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
193 CDBIOSLoaded = (JaguarLoadROM(jaguar_CDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
194 WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
197 SET32(jaguar_mainRam, 0, 0x00200000); // Set top of stack...
199 WriteLog("Initializing video subsystem...\n");
201 WriteLog("Initializing GUI subsystem...\n");
204 // Now with crunchy GUI goodness!
205 WriteLog("About to start GUI...\n");
206 GUIMain(haveCart ? argv[1] : NULL);
208 //This is no longer accurate...!
209 // int elapsedTime = clock() - startTime;
210 // int fps = (1000 * totalFrames) / elapsedTime;
211 // WriteLog("VJ: Ran at an average of %i FPS.\n", fps);
219 // Free SDL components last...!
220 // SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_CDROM);
221 SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER);