-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
361 lines (263 loc) · 7.04 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
This file is part of 3d'oh, a multiplatform 3do emulator written by Gabriel Ernesto Cabral.
3d'oh is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
3d'oh is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with 3d'oh. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <SDL/SDL.h>
#include "freedocore.h"
#include "common.h"
#include "timer.h"
#ifdef DREAMCAST
#include "kos.h"
extern uint8 romdisk[];
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_MALLOCSTATS);
KOS_INIT_ROMDISK(romdisk);
#endif
char* pNVRam;
extern _ext_Interface io_interface;
_ext_Interface fd_interface;
//SDL_Event event;
int onsector=0;
char biosFile[100];
char imageFile[100];
bool __temporalfixes;
int HightResMode;
int __tex__scaler;
int count_samples=0;
int initEmu(int xres,int yres, int bpp, int armclock);
uint32 ReverseBytes(uint32 value)
{
return (value & 0x000000FFU) << 24 | (value & 0x0000FF00U) << 8 |
(value & 0x00FF0000U) >> 8 | (value & 0xFF000000U) >> 24;
}
void readNvRam(void *pnvram)
{
FILE* bios1;
long fsize;
char *buffer;
NvRamStr *nvramStruct;
// nvramStruct=(NvRamStr *)malloc(sizeof(NvRamStr));
nvramStruct=(NvRamStr *)pnvram;
////////////////
// Fill out the volume header.
nvramStruct->recordType = 0x01;
int x;
for (x = 0; x < 5; x++) nvramStruct->syncBytes[x] = (char)'Z';
nvramStruct->recordVersion = 0x02;
nvramStruct->flags = 0x00;
for (x = 0; x < 32; x++) nvramStruct->comment[x] = 0;
nvramStruct->label[0] = (char)'n';
nvramStruct->label[1] = (char)'v';
nvramStruct->label[2] = (char)'r';
nvramStruct->label[3] = (char)'a';
nvramStruct->label[4] = (char)'m';
for (x = 5; x < 32; x++) nvramStruct->label[x] = 0;
nvramStruct->id = ReverseBytes(0xFFFFFFFF);
nvramStruct->blockSize = ReverseBytes(0x00000001); // Yep, one byte per block.
nvramStruct->blockCount = ReverseBytes(0x00008000); // 32K worth of NVRAM data.
nvramStruct->rootDirId = ReverseBytes(0xFFFFFFFE);
nvramStruct->rootDirBlocks = ReverseBytes(0x00000000);
nvramStruct->rootDirBlockSize = ReverseBytes(0x00000001);
nvramStruct->lastRootDirCopy = ReverseBytes(0x00000000);
nvramStruct->rootDirCopies[0] = ReverseBytes(0x00000084);
for (x = 1; x < 8; x++) nvramStruct->rootDirCopies[x] = 0;
////////////////
// After this point, I could not find the proper structure for the data.
int w = sizeof(NvRamStr) / 4;
/* uint32_t nvramData
nvramData[w++] = ReverseBytes(0x855A02B6);
nvramData[w++] = ReverseBytes(0x00000098);
nvramData[w++] = ReverseBytes(0x00000098);
nvramData[w++] = ReverseBytes(0x00000014);
nvramData[w++] = ReverseBytes(0x00000014);
nvramData[w++] = ReverseBytes(0x7AA565BD);
nvramData[w++] = ReverseBytes(0x00000084);
nvramData[w++] = ReverseBytes(0x00000084);
nvramData[w++] = ReverseBytes(0x00007668); // This is blocks remaining.
nvramData[w++] = ReverseBytes(0x00000014);
*/
// buffer = (char*)malloc(32*1024);
// pnvram=(void *)nvramStruct;
}
void loadRom1(void *prom)
{
fsReadBios(biosFile, prom);
}
void *swapFrame(void *curr_frame)
{
// printf("swap frame\n");
return curr_frame;
}
void * emuinterface(int procedure, void *datum)
{
typedef void *(*func_type)(void);
void *therom;
switch(procedure)
{
case EXT_READ_ROMS:
loadRom1(datum);
break;
case EXT_READ2048:
fsReadBlock(datum,onsector);
break;
case EXT_GET_DISC_SIZE:
return (void *) fsReadDiscSize();
break;
case EXT_ON_SECTOR:
onsector=*((int*)&datum);
break;
case EXT_READ_NVRAM:
readNvRam(datum);
break;
case EXT_WRITE_NVRAM:
break;
case EXT_PUSH_SAMPLE:
soundFillBuffer(*((unsigned int*)&datum));
count_samples++;
break;
case EXT_SWAPFRAME:
return swapFrame(datum);
break;
case EXT_GETP_PBUSDATA:
return (void *)inputRead();
break;
case EXT_GET_PBUSLEN:
return (void *)inputLength();
break;
case EXT_FRAMETRIGGER_MT:
break;
default:
// return _freedo_Interface(procedure,datum);
break;
};
return (void *)readNvRam;
}
void readConfiguration()
{
configOpen("config.ini");
// configReadInt("general","biosfile");
// configReadInt("general","screenwidth");
// configReadInt("general","screenheight");
configClose();
}
int main(int argc, char *argv[])
{
printf("3d'oh! MAIN\n");
int biosset=0;
int imageset=0;
fsInit();
#ifdef DREAMCAST
chdir("/rd");
#endif
readConfiguration();
#ifndef DREAMCAST
if(argc>1){
int i;
for(i=0;i<argc;i++)
{
// printf("%s\n",argv[i]);
if(strcmp(argv[i],"-b")==0){
/*set bios filename*/
sprintf(biosFile,"bios/%s",argv[i+1]);
biosset=1;
}
if(strcmp(argv[i],"-i")==0){
/*set image (iso) filename*/
sprintf(imageFile,"games/%s",argv[i+1]);
imageset=1;
}
}
}
if((biosset)&&(imageset))
{
if(!initEmu(800,600,32,12500000)) return 0;
/*free resources*/
fd_interface(FDP_DESTROY,(void *)0);
soundClose();
fsClose();
// SDL_Quit();
}else{
printf("3d'oh! - a 3do emulator\nUsage 3doemu -b biosfile -i isofile\n");
}
#else
sprintf(biosFile,"bios/bios.bin");
sprintf(imageFile,"games/game.iso");
initEmu(640,480,32,12500000);
fd_interface(FDP_DESTROY,(void *)0);
soundClose();
// SDL_Quit();
#endif
return 0;
}
///int main(int argc, char *argv[])
int initEmu(int xres,int yres, int bpp, int armclock)
{
printf("INFO: starting 3d'oh! emulator\n");
int arm_clock=armclock;
int tex_quality=0;
int quit=0;
int waitfps;
// memset(frame,0,sizeof(VDLFrame));
// printf("frame %p\n",frame);
io_interface=&emuinterface;
fd_interface=&_freedo_Interface;
videoInit(xres,yres,bpp);
// toggleFullscreen(screen);
soundInit();
inputInit();
if(!fsOpenIso(imageFile)) return 0;
//init freedo core
void *prom;
void *profile;
fd_interface(FDP_SET_ARMCLOCK,(void *)arm_clock);
fd_interface(FDP_SET_TEXQUALITY,(void *)tex_quality);
// io_interface(FDP_INIT,0);
// profile=io_interface(FDP_GETP_PROFILE,0);
_3do_Init();
int frame_end,framerate;
int time_start=0;
int frame_start=0;
int frames=0;
int debug=0;
time_start = timerGettime();
while(!quit){
videoFlip();
soundRun();
quit = inputQuit();
/* Framerate control */
waitfps=timerGettime()-frame_end;
if(waitfps<17)
{
SE_timer_waitframerate(17-waitfps);
}
frame_end=timerGettime();
frames++;
/* Calculate Frames Per Second */
if((frame_end-time_start)>=1000)
{
printf("framerate:%d fps samples:%d\n",frames,count_samples);
frames=0;
count_samples=0;
time_start = timerGettime();
}
}
/* Close everything and return */
videoClose();
soundClose();
inputClose();
#ifndef DREAMCAST
SDL_Quit();
#endif
return 1;
}