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