]> Shamusworld >> Repos - virtualjaguar/blob - src/vj.cpp
Update for 1.1.0 release
[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 #endif
12
13 #include <time.h>
14 #include <SDL.h>
15 #include "jaguar.h"
16 #include "video.h"
17 #include "gui.h"
18 #include "sdlemu_opengl.h"
19 #include "settings.h"                                                           // Pull in "vjs" struct
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 // External variables
33
34 extern uint8 * jaguar_mainRam;
35 extern uint8 * jaguar_mainRom;
36 extern uint8 * jaguar_bootRom;
37 extern uint8 * jaguar_CDBootROM;
38
39 // Global variables (export capable)
40 //should these even be here anymore?
41
42 bool finished = false;
43 bool showGUI = false;
44 bool showMessage = false;
45 uint32 showMessageTimeout;
46 char messageBuffer[200];
47 bool BIOSLoaded = false;
48 bool CDBIOSLoaded = false;
49
50 //
51 // The main emulator loop (what else?)
52 //
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[])
57 {
58 //NOTE: This isn't actually used anywhere... !!! FIX !!!
59         int32 nFrameskip = 0;                                                   // Default: Show every frame
60
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");
66
67         bool haveCart = false;                                                  // Assume there is no cartridge...!
68
69         log_init("vj.log");
70         LoadVJSettings();                                                               // Get config file settings...
71
72         // Check the switches... ;-)
73         // NOTE: Command line switches can override any config file settings, thus the
74         //       proliferation of the noXXX switches. ;-)
75
76         for(int i=1; i<argc || argv[i]!=NULL; i++)
77         {
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!
81
82                 if (!strcmp(argv[i], "-joystick")) 
83                         vjs.useJoystick = true;
84
85                 if (!strcmp(argv[i], "-joyport"))
86                 {
87                         vjs.joyport = atoi(argv[++i]) + 1;
88                         if (vjs.joyport > 3)
89                                 vjs.joyport = 3;
90                 }
91
92                 if (!strcmp(argv[i], "-frameskip"))
93                 {
94                         nFrameskip = atoi(argv[++i]) + 1;
95                         if (nFrameskip > 10)
96                                 nFrameskip = 10;
97                 }
98
99                 if (!strcmp(argv[i], "-bios"))
100                         vjs.useJaguarBIOS = true;
101
102                 if (!strcmp(argv[i], "-nobios"))
103                         vjs.useJaguarBIOS = false;
104
105                 if (!strcmp(argv[i], "-dsp"))
106                         vjs.DSPEnabled = true;
107
108                 if (!strcmp(argv[i], "-nodsp"))
109                         vjs.DSPEnabled = false;
110
111                 if (!strcmp(argv[i], "-pipeline"))
112                         vjs.usePipelinedDSP = true;
113
114                 if (!strcmp(argv[i], "-nopipeline"))
115                         vjs.usePipelinedDSP = false;
116
117                 if (!strcmp(argv[i], "-gl"))
118                         vjs.useOpenGL = true;
119
120                 if (!strcmp(argv[i], "-nogl"))
121                         vjs.useOpenGL = false;
122
123                 if (!strcmp(argv[i], "-fullscreen")) 
124                         vjs.fullscreen = true;
125
126                 if (!strcmp(argv[i], "-window")) 
127                         vjs.fullscreen = false;
128
129                 if (!strcmp(argv[i], "-pal"))
130                         vjs.hardwareTypeNTSC = false;
131
132                 if (!strcmp(argv[i], "-ntsc"))
133                         vjs.hardwareTypeNTSC = true;
134
135                 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?"))
136                 {
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");
157                         return 1;
158                 }
159     }
160
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)
165         {
166                 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
167                 return -1;
168         }
169
170         WriteLog("VJ: SDL successfully initialized.\n");
171
172 WriteLog("Initializing memory subsystem...\n");
173         InitMemory();
174 WriteLog("Initializing version...\n");
175         InitVersion();
176         version_display(log_get());
177 WriteLog("Initializing jaguar subsystem...\n");
178         jaguar_init();
179
180         // Get the BIOS ROM
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;
186 #else
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 "));
195 #endif
196
197         SET32(jaguar_mainRam, 0, 0x00200000);                   // Set top of stack...
198
199 WriteLog("Initializing video subsystem...\n");
200         InitVideo();
201 WriteLog("Initializing GUI subsystem...\n");
202         InitGUI();
203
204         // Now with crunchy GUI goodness!
205 WriteLog("About to start GUI...\n");
206         GUIMain(haveCart ? argv[1] : NULL);
207
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);
212
213         jaguar_done();
214         VersionDone();
215         MemoryDone();
216         VideoDone();
217         log_done();     
218
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);
222         SDL_Quit();
223
224     return 0;
225 }