-
Notifications
You must be signed in to change notification settings - Fork 0
/
_3do_sys.cpp
324 lines (276 loc) · 9.16 KB
/
_3do_sys.cpp
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
/*
3DOplay v1.8.2 is 3do emulator based on FreeDOcore
3doplay.do.am
Developer: Viktor Ivanov
Any uses of the 3DOplay sources or any other material published by Viktor Ivanov have to be accompanied with full credits.
All rights reserved.
*/
/*
www.freedo.org
The first and only working 3DO multiplayer emulator.
The FreeDO licensed under modified GNU LGPL, with following notes:
* The owners and original authors of the FreeDO have full right to develop closed source derivative work.
* Any non-commercial uses of the FreeDO sources or any knowledge obtained by studying or reverse engineering
of the sources, or any other material published by FreeDO have to be accompanied with full credits.
* Any commercial uses of FreeDO sources or any knowledge obtained by studying or reverse engineering of the sources,
or any other material published by FreeDO is strictly forbidden without owners approval.
The above notes are taking precedence over GNU LGPL in conflicting situations.
Project authors:
Alexander Troosh
Maxim Grishin
Allen Wright
John Sammons
Felix Lazarev
*/
#include "stdafx.h"
#include "3doplay.h"
#include "arm.h"
#include "vdlp.h"
#include "dsp.h"
#include "clio.h"
#include "madam.h"
#include "sport.h"
#include "xbus.h"
#include "DiagPort.h"
#include "quarz.h"
#include <windows.h>
_ext_Interface io_interface;
extern void* Getp_NVRAM();
extern void* Getp_ROMS();
extern void* Getp_RAMS();
__inline uint32 _bswap(uint32 x)
{
return (x>>24) | ((x>>8)&0x0000FF00L) | ((x&0x0000FF00L)<<8) | (x<<24);
}
extern void* _xbplug_MainDevice(int proc, void* data);
int _3do_Init()
{
unsigned char *Memory;
unsigned char *rom;
Memory=_arm_Init();
io_interface(EXT_READ_ROMS,Getp_ROMS());
rom=(unsigned char*)Getp_ROMS();
for(int i=(1024*1024*2)-4;i>=0;i-=4) *(int *)(rom+i)=_bswap(*(int *)(rom+i));
_vdl_Init(Memory+0x200000); // Visible only VRAM to it
_sport_Init(Memory+0x200000); // Visible only VRAM to it
_madam_Init(Memory);
_xbus_Init(_xbplug_MainDevice);
_clio_Init(0x40); // 0x40 for start from 3D0-CD, 0x01/0x02 from PhotoCD ?? (NO use 0x40/0x02 for BIOS test)
_dsp_Init();
_diag_Init(-1); // Select test, use -1 -- if d'nt need tests
/*
00 DIAGNOSTICS TEST (run of test: 1F, 24, 25, 32, 50, 51, 60, 61, 62, 68, 71, 75, 80, 81, 90)
01 AUTO-DIAG TEST (run of test: 1F, 24, 25, 32, 50, 51, 60, 61, 62, 68, 80, 81, 90)
12 DRAM1 DATA TEST
1A DRAM2 DATA TEST
1E EARLY RAM TEST
1F RAM DATA TEST
22 VRAM1 DATA TEST
24 VRAM1 FLASH TEST
25 VRAM1 SPORT TEST
32 SRAM DATA TEST
50 MADAM TEST
51 CLIO TEST
60 CD-ROM POLL TEST
61 CD-ROM PATH TEST
62 CD-ROM READ TEST ???
63 CD-ROM AutoAdjustValue TEST
67 CD-ROM#2 AutoAdjustValue TEST
68 DEV#15 POLL TEST
71 JOYPAD1 PRESS TEST
75 JOYPAD1 AUDIO TEST
80 SIN WAVE TEST
81 MUTING TEST
90 COLORBAR
F0 CHECK TESTTOOL ???
F1 REVISION TEST
FF TEST END (halt)
*/
_xbus_DevLoad(0,NULL);
_qrz_Init();
return 0;
}
VDLFrame *curr_frame;
bool scipframe;
void _3do_InternalFrame(int cicles)
{
int line;
_qrz_PushARMCycles(cicles);
if(_qrz_QueueDSP())
{
io_interface(EXT_PUSH_SAMPLE,(void*)_dsp_Loop());
}
while(_qrz_QueueTimer())_clio_DoTimers();
if(_qrz_QueueVDL())
{
line=_qrz_VDCurrLine();
_clio_UpdateVCNT(line, _qrz_VDHalfFrame());
if(!scipframe)_vdl_DoLineNew(line,curr_frame);
if(line==16 && scipframe) io_interface(EXT_FRAMETRIGGER_MT,NULL);
//line=_qrz_VDCurrOverline();
if(line==_clio_v0line())
{
_clio_GenerateFiq(1<<0,0);
}
if(line==_clio_v1line())
{
_clio_GenerateFiq(1<<1,0);
_madam_KeyPressed((unsigned char*)io_interface(EXT_GETP_PBUSDATA,NULL),(int)io_interface(EXT_GET_PBUSLEN,NULL));
curr_frame->srcw=320;
curr_frame->srch=240;
if(!scipframe)curr_frame=(VDLFrame*)io_interface(EXT_SWAPFRAME,curr_frame);
}
}
}
void __fastcall _3do_Frame(VDLFrame *frame, bool __scipframe=false)
{
int i,line,cnt=0;
curr_frame=frame;
scipframe=__scipframe;
for(i=0;i<(12500000/60);)
{
if(Get_madam_FSM()==FSM_INPROCESS)
{
_madam_HandleCEL();
Set_madam_FSM(FSM_IDLE);
continue;
}
cnt+=_arm_Execute();
if(cnt>>4){_3do_InternalFrame(cnt);i+=cnt;cnt=0;}
}
}
void _3do_Destroy()
{
_arm_Destroy();
_xbus_Destroy();
}
unsigned int _3do_SaveSize()
{
unsigned int tmp;
tmp=_arm_SaveSize();
tmp+=_vdl_SaveSize();
tmp+=_dsp_SaveSize();
tmp+=_clio_SaveSize();
tmp+=_qrz_SaveSize();
tmp+=_sport_SaveSize();
tmp+=_madam_SaveSize();
tmp+=_xbus_SaveSize();
tmp+=16*4;
return tmp;
}
void _3do_Save(void *buff)
{
unsigned char *data=(unsigned char*)buff;
int *indexes=(int*)buff;
indexes[0]=0x97970101;
indexes[1]=16*4;
indexes[2]=indexes[1]+_arm_SaveSize();
indexes[3]=indexes[2]+_vdl_SaveSize();
indexes[4]=indexes[3]+_dsp_SaveSize();
indexes[5]=indexes[4]+_clio_SaveSize();
indexes[6]=indexes[5]+_qrz_SaveSize();
indexes[7]=indexes[6]+_sport_SaveSize();
indexes[8]=indexes[7]+_madam_SaveSize();
indexes[9]=indexes[8]+_xbus_SaveSize();
_arm_Save(&data[indexes[1]]);
_vdl_Save(&data[indexes[2]]);
_dsp_Save(&data[indexes[3]]);
_clio_Save(&data[indexes[4]]);
_qrz_Save(&data[indexes[5]]);
_sport_Save(&data[indexes[6]]);
_madam_Save(&data[indexes[7]]);
_xbus_Save(&data[indexes[8]]);
}
bool _3do_Load(void *buff)
{
unsigned char *data=(unsigned char*)buff;
int *indexes=(int*)buff;
if(indexes[0]!=0x97970101)return false;
_arm_Load(&data[indexes[1]]);
_vdl_Load(&data[indexes[2]]);
_dsp_Load(&data[indexes[3]]);
_clio_Load(&data[indexes[4]]);
_qrz_Load(&data[indexes[5]]);
_sport_Load(&data[indexes[6]]);
_madam_Load(&data[indexes[7]]);
_xbus_Load(&data[indexes[8]]);
return true;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
extern uint32 *profiling;
extern uint32 *profiling3;
extern int ARM_CLOCK;
void _3do_OnSector(unsigned int sector)
{
io_interface(EXT_ON_SECTOR,(void*)sector);
}
void _3do_Read2048(void *buff)
{
io_interface(EXT_READ2048,(void*)buff);
}
unsigned int _3do_DiscSize()
{
return (unsigned int)io_interface(EXT_GET_DISC_SIZE,NULL);
}
int HightResMode=0;
bool __temporalfixes=false;
int speedfixes=0;
int sf=0;
int sdf=0, unknownflag11=0;
FREEDOCORE_API void* A3doplayInterface(int procedure, void *datum)
{
int line;
switch(procedure)
{
case FDP_INIT:
sf=0x4C4B40;
io_interface=(_ext_Interface)datum;
return (void*)_3do_Init();
case FDP_DESTROY:
_3do_Destroy();
break;
case FDP_DO_EXECFRAME:
_3do_Frame((VDLFrame*)datum);
break;
case FDP_DO_EXECFRAME_MT:
_3do_Frame((VDLFrame*)datum, true);
break;
case FDP_DO_FRAME_MT:
line=0;
while(line<263)_vdl_DoLineNew(line++,(VDLFrame*)datum);
((VDLFrame*)datum)->srcw=320;
((VDLFrame*)datum)->srch=240;
break;
case FDP_GET_SAVE_SIZE:
return (void*)_3do_SaveSize();
case FDP_DO_SAVE:
_3do_Save(datum);
break;
case FDP_DO_LOAD:
return (void*)_3do_Load(datum);
case FDP_GETP_NVRAM:
return Getp_NVRAM();
case FDP_GETP_RAMS:
return Getp_RAMS();
case FDP_GETP_ROMS:
return Getp_ROMS();
case FDP_GETP_PROFILE:
return profiling;
case FDP_FREEDOCORE_VERSION:
return (void*)0x10802;
case FDP_SET_ARMCLOCK:
ARM_CLOCK=(int)datum;
break;
case FDP_SET_TEXQUALITY:
if(datum)HightResMode=1;
else HightResMode=0;
break;
case FDP_BUGTEMPORALFIX:
__temporalfixes=(bool)datum;
break;
case FDP_GETP_WRCOUNT:
return profiling3;
};
return NULL;
}