]> Shamusworld >> Repos - virtualjaguar/blob - src/vj.cpp
Small change to credits
[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>
11 #endif
12
13 //#include <dirent.h>                                                                   // POSIX, but should compile with linux & mingw...
14 #include <time.h>
15 #include <SDL.h>
16 #include "jaguar.h"
17 //#include "crc32.h"
18 //#include "zlib.h"
19 //#include "unzip.h"
20 #include "video.h"
21 #include "gui.h"
22 #include "sdlemu_opengl.h"
23 #include "settings.h"                                                           // Pull in "vjs" struct
24
25 // Uncomment this for speed control (?)
26 //#define SPEED_CONTROL
27
28 // Private function prototypes
29
30 //uint32 JaguarLoadROM(uint8 *, char *);
31 //void JaguarLoadCart(uint8 *, char *);
32 //int gzfilelength(gzFile gd);
33
34 // External variables
35
36 extern uint8 * jaguar_mainRam;
37 extern uint8 * jaguar_bootRom;
38 extern uint8 * jaguar_mainRom;
39
40 // Various paths
41
42 //static char * jaguar_bootRom_path = "./bios/jagboot.rom";
43 //static char  *jaguar_bootRom_path="c:/jaguarEmu/newload.img";
44 //static char  *jaguar_bootRom_path="./bios/JagOS.bin";
45 //char * jaguar_eeproms_path = "./eeproms/";
46 //char jaguar_boot_dir[MAX_PATH];
47
48 //These should go into video.cpp...
49 //And they will!
50 //SDL_Surface * surface, * mainSurface;
51 //int16 * backbuffer = NULL;
52 //SDL_Joystick * joystick;
53 //Uint32 mainSurfaceFlags = SDL_SWSURFACE;
54
55 bool finished = false;
56 bool showGUI = false;
57 bool showMessage = false;
58 uint32 showMessageTimeout;
59 char messageBuffer[200];
60
61 //
62 // The main emulator loop (what else?)
63 //
64 //Maybe we should move the video stuff to TOM? Makes more sense to put it there...
65 //Actually, it would probably be better served in VIDEO.CPP... !!! FIX !!! [DONE]
66 uint32 totalFrames;//temp, so we can grab this from elsewhere...
67 int main(int argc, char * argv[])
68 {
69         uint32 startTime;//, totalFrames;//, endTime;//, w, h;
70         uint32 nNormalLast = 0;
71         int32 nNormalFrac = 0; 
72     int32 nFrameskip = 0;                                                       // Default: Show every frame
73     int32 nFrame = 0;                                                           // No. of Frame
74
75         printf("Virtual Jaguar GCC/SDL Portable Jaguar Emulator v1.0.7\n");
76         printf("Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n");
77         printf("Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n");
78         printf("James L. Hammons (WIN32) and Adam Green (MacOS)\n");
79         printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n");
80
81         bool haveCart = false;                                                  // Assume there is no cartridge...!
82
83         log_init("vj.log");
84         LoadVJSettings();                                                               // Get config file settings...
85
86         // Check the switches... ;-)
87         // NOTE: Command line switches can override any config file settings, thus the
88         //       proliferation of the noXXX switches. ;-)
89
90         for(int i=1; i<argc || argv[i]!=NULL; i++)
91         {
92                 // This would be the most likely place to do the cart loading...
93                 if (argv[i][0] != '-')
94                         haveCart = true;                                                // It looks like we have a cartridge!
95
96                 if (!strcmp(argv[i], "-joystick")) 
97                         vjs.useJoystick = true;
98
99                 if (!strcmp(argv[i], "-joyport"))
100                 {
101                         vjs.joyport = atoi(argv[++i]) + 1;
102                         if (vjs.joyport > 3)
103                                 vjs.joyport = 3;
104                 }
105
106                 if (!strcmp(argv[i], "-frameskip"))
107                 {
108                         nFrameskip = atoi(argv[++i]) + 1;
109                         if (nFrameskip > 10)
110                                 nFrameskip = 10;
111 #ifdef SPEED_CONTROL
112                         nFrameskip = 0;
113 #endif
114                 }
115
116                 if (!strcmp(argv[i], "-bios"))
117                         vjs.useJaguarBIOS = true;
118
119                 if (!strcmp(argv[i], "-nobios"))
120                         vjs.useJaguarBIOS = false;
121
122                 if (!strcmp(argv[i], "-dsp"))
123                         vjs.DSPEnabled = true;
124
125                 if (!strcmp(argv[i], "-nodsp"))
126                         vjs.DSPEnabled = false;
127
128                 if (!strcmp(argv[i], "-pipeline"))
129                         vjs.usePipelinedDSP = true;
130
131                 if (!strcmp(argv[i], "-nopipeline"))
132                         vjs.usePipelinedDSP = false;
133
134                 if (!strcmp(argv[i], "-gl"))
135                         vjs.useOpenGL = true;
136
137                 if (!strcmp(argv[i], "-nogl"))
138                         vjs.useOpenGL = false;
139
140                 if (!strcmp(argv[i], "-fullscreen")) 
141                         vjs.fullscreen = true;
142
143                 if (!strcmp(argv[i], "-window")) 
144                         vjs.fullscreen = false;
145
146                 if (!strcmp(argv[i], "-pal"))
147                         vjs.hardwareTypeNTSC = false;
148
149                 if (!strcmp(argv[i], "-ntsc"))
150                         vjs.hardwareTypeNTSC = true;
151
152                 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?"))
153                 {
154                     printf("Usage: \n\n");
155                         printf("vj [romfile] [switches]\n");
156                         printf("  -? or -help     : Display usage and switches                \n");
157                         printf("  -frameskip 1-10 : Enable frameskip 1 - 10 (default: none)   \n");
158                         printf("  -joystick       : Enable joystick/gamepad                   \n");
159                         printf("  -joyport 0-3    : Select desired joystick port              \n");
160                         printf("  -bios           : Boot cart using Jaguar BIOS ROM           \n");
161                         printf("  -nobios         : Boot cart without using Jaguar BIOS ROM   \n");
162                         printf("  -dsp            : Force VJ to use the DSP                   \n");
163                         printf("  -nodsp          : Force VJ to run without the DSP           \n");
164                         printf("  -pipeline       : Use the DSP pipelined core                \n");
165                         printf("  -nopipeline     : Use the DSP non-pipelined core            \n");
166                         printf("  -gl             : Use OpenGL rendering                      \n");
167                         printf("  -nogl           : Use old non-OpenGL rendering              \n");
168                         printf("  -fullscreen     : Enable fullscreen mode (default: windowed)\n");
169                         printf("  -window         : Enable windowed mode                      \n");
170                         printf("  -pal            : Force VJ to PAL mode (default: NTSC)      \n");
171                         printf("  -ntsc           : Force VJ to NTSC mode                     \n");
172                         printf("\nInvoking Virtual Jagaur with no ROM file will cause it to boot up\n");
173                         printf("with the VJ GUI.\n");
174                         return 1;
175                 }
176     }
177
178         memory_init();
179         version_init();
180         version_display(log_get());
181         jaguar_init();
182
183         // Get the BIOS ROM
184 //      if (vjs.useJaguarBIOS)
185 // What would be nice here would be a way to check if the BIOS was loaded so that we
186 // could disable the pushbutton on the Misc Options menu... !!! FIX !!!
187                 JaguarLoadROM(jaguar_bootRom, vjs.jagBootPath);
188
189         SET32(jaguar_mainRam, 0, 0x00200000);                   // Set top of stack...
190
191         InitVideo();
192         InitGUI();
193
194         // Get the cartridge ROM (if passed in)
195         // Now with crunchy GUI goodness!
196 //      JaguarLoadCart(jaguar_mainRom, (haveCart ? argv[1] : vjs.ROMPath));
197 //Need to find a better way to handle this crap...
198         GUIMain();
199
200 /*      jaguar_reset();
201         
202         totalFrames = 0;
203         startTime = clock();
204         nNormalLast = 0;                                                                        // Last value of timeGetTime()
205         nNormalFrac = 0;                                                                        // Extra fraction we did
206         nNormalLast = SDL_GetTicks();                                           //timeGetTime();
207
208         while (!finished)
209         {
210 #ifdef SPEED_CONTROL
211                 nTime = SDL_GetTicks() - nNormalLast;                   // calcule le temps écoulé depuis le dernier affichage
212                                                                                                                 // nTime est en mili-secondes.
213                 // détermine le nombre de trames à passer + 1
214                 nCount = (nTime * 600 - nNormalFrac) / 10000;
215
216                 // si le nombre de trames à passer + 1 est nul ou négatif,
217                 // ne rien faire pendant 2 ms
218                 if (nCount <= 0) 
219                 { 
220                         //Sleep(2); 
221                         //SDL_Delay(1);
222                 } // No need to do anything for a bit
223                 else
224                 {
225                         nNormalFrac += nCount * 10000;                          // 
226                         nNormalLast += nNormalFrac / 600;                       // add the duration of nNormalFrac frames
227                         nNormalFrac %= 600;                                                     // 
228
229                         // Pas plus de 9 (10-1) trames non affichées 
230                         if (nCount > 10)
231                                 nCount = 10;
232                         for(int i=0; i<nCount-1; i++)
233                                 jaguar_exec(backbuffer, false);
234 #endif
235             // Set up new backbuffer with new pixels and data
236                         JaguarExecute(backbuffer, true);
237                         totalFrames++;
238 //WriteLog("Frame #%u...\n", totalFrames);
239 //extern bool doDSPDis;
240 //if (totalFrames == 373)
241 //      doDSPDis = true;
242
243                         // Some QnD GUI stuff here...
244                         if (showGUI)
245                         {
246                                 extern uint32 gpu_pc, dsp_pc;
247                                 DrawString(backbuffer, 8, 8, false, "GPU PC: %08X", gpu_pc);
248                                 DrawString(backbuffer, 8, 16, false, "DSP PC: %08X", dsp_pc);
249                         }
250
251                         // Simple frameskip
252                         if (nFrame == nFrameskip)
253                         {
254                                 RenderBackbuffer();
255                                 nFrame = 0;
256                         }
257                         else
258                                 nFrame++;
259
260                         joystick_exec();
261
262 #ifdef SPEED_CONTROL
263                 }
264 #endif
265         }*/
266
267         int elapsedTime = clock() - startTime;
268         int fps = (1000 * totalFrames) / elapsedTime;
269         WriteLog("VJ: Ran at an average of %i FPS.\n", fps);
270
271         jaguar_done();
272         version_done();
273         memory_done();
274         VideoDone();                                                                    // Free SDL components last...!
275         log_done();     
276
277     return 0;
278 }