]> Shamusworld >> Repos - virtualjaguar/blob - src/vj.cpp
Added jaguar memory locations to memory.cpp.
[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 <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 L. 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                         if (vjs.joyport > 3)
79                                 vjs.joyport = 3;
80                 }
81
82                 if (!strcmp(argv[i], "-frameskip"))
83                 {
84                         nFrameskip = atoi(argv[++i]) + 1;
85                         if (nFrameskip > 10)
86                                 nFrameskip = 10;
87                 }
88
89                 if (!strcmp(argv[i], "-bios"))
90                         vjs.useJaguarBIOS = true;
91
92                 if (!strcmp(argv[i], "-nobios"))
93                         vjs.useJaguarBIOS = false;
94
95                 if (!strcmp(argv[i], "-dsp"))
96                         vjs.DSPEnabled = true;
97
98                 if (!strcmp(argv[i], "-nodsp"))
99                         vjs.DSPEnabled = false;
100
101                 if (!strcmp(argv[i], "-pipeline"))
102                         vjs.usePipelinedDSP = true;
103
104                 if (!strcmp(argv[i], "-nopipeline"))
105                         vjs.usePipelinedDSP = false;
106
107                 if (!strcmp(argv[i], "-gl"))
108                         vjs.useOpenGL = true;
109
110                 if (!strcmp(argv[i], "-nogl"))
111                         vjs.useOpenGL = false;
112
113                 if (!strcmp(argv[i], "-fullscreen"))
114                         vjs.fullscreen = true;
115
116                 if (!strcmp(argv[i], "-window"))
117                         vjs.fullscreen = false;
118
119                 if (!strcmp(argv[i], "-pal"))
120                         vjs.hardwareTypeNTSC = false;
121
122                 if (!strcmp(argv[i], "-ntsc"))
123                         vjs.hardwareTypeNTSC = true;
124
125                 if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-?"))
126                 {
127                     printf("Usage: \n\n");
128                         printf("vj [romfile] [switches]\n");
129                         printf("  -? or --help    : Display usage and switches                \n");
130                         printf("  -frameskip 1-10 : Enable frameskip 1 - 10 (default: none)   \n");
131                         printf("  -joystick       : Enable joystick/gamepad                   \n");
132                         printf("  -joyport 0-3    : Select desired joystick port              \n");
133                         printf("  -bios           : Boot cart using Jaguar BIOS ROM           \n");
134                         printf("  -nobios         : Boot cart without using Jaguar BIOS ROM   \n");
135                         printf("  -dsp            : Force VJ to use the DSP                   \n");
136                         printf("  -nodsp          : Force VJ to run without the DSP           \n");
137                         printf("  -pipeline       : Use the DSP pipelined core                \n");
138                         printf("  -nopipeline     : Use the DSP non-pipelined core            \n");
139                         printf("  -gl             : Use OpenGL rendering                      \n");
140                         printf("  -nogl           : Use old non-OpenGL rendering              \n");
141                         printf("  -fullscreen     : Enable fullscreen mode (default: windowed)\n");
142                         printf("  -window         : Enable windowed mode                      \n");
143                         printf("  -pal            : Force VJ to PAL mode (default: NTSC)      \n");
144                         printf("  -ntsc           : Force VJ to NTSC mode                     \n");
145                         printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
146                         printf("with the VJ GUI.\n");
147                         return 1;
148                 }
149     }
150
151         // Set up SDL library
152         if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
153         {
154                 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
155                 return -1;
156         }
157
158         WriteLog("VJ: SDL successfully initialized.\n");
159
160 //      WriteLog("Initializing memory subsystem...\n");
161 //      MemoryInit();
162 #ifdef VJ_RELEASE_VERSION
163         WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
164 #else
165         WriteLog("Virtual Jaguar SVN %s (Last full build was on %s %s)\n", __DATE__, __DATE__, __TIME__);
166 #endif
167         WriteLog("Initializing jaguar subsystem...\n");
168         JaguarInit();
169
170         // Get the BIOS ROM
171 #ifdef USE_BUILT_IN_BIOS
172         WriteLog("VJ: Using built in BIOS/CD BIOS...\n");
173         memcpy(jaguarBootROM, jagBootROM, 0x20000);
174         memcpy(jaguarCDBootROM, jagCDROM, 0x40000);
175         BIOSLoaded = CDBIOSLoaded = true;
176 #else
177 // What would be nice here would be a way to check if the BIOS was loaded so that we
178 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
179 WriteLog("About to attempt to load BIOSes...\n");
180         BIOSLoaded = (JaguarLoadROM(jaguarBootROM, vjs.jagBootPath) == 0x20000 ? true : false);
181         WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
182         CDBIOSLoaded = (JaguarLoadROM(jaguarCDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
183         WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
184 #endif
185
186         SET32(jaguarMainRAM, 0, 0x00200000);                    // Set top of stack...
187
188 WriteLog("Initializing video subsystem...\n");
189         VideoInit();
190 WriteLog("Initializing GUI subsystem...\n");
191 #warning "!!! FIX !!! (GUIInit())"
192 //      GUIInit();
193
194         // Now with crunchy GUI goodness!
195 WriteLog("About to start GUI...\n");
196 #warning "!!! FIX !!! (GUIMain(...))"
197 //      GUIMain(haveCart ? argv[1] : NULL);
198
199 //This is no longer accurate...!
200 //      int elapsedTime = clock() - startTime;
201 //      int fps = (1000 * totalFrames) / elapsedTime;
202 //      WriteLog("VJ: Ran at an average of %i FPS.\n", fps);
203
204         JaguarDone();
205         VideoDone();
206 //      MemoryDone();
207         LogDone();
208
209         // Free SDL components last...!
210         SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER);
211         SDL_Quit();
212
213         return 0;
214 }