-
Notifications
You must be signed in to change notification settings - Fork 0
/
vdlp.cpp
362 lines (301 loc) · 9.6 KB
/
vdlp.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
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
362
/*
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 "VDLP.h"
#include "arm.h"
#include <memory.h>
#include "3doplay.h"
extern _ext_Interface io_interface;
/* === VDL Palette data === */
#define VDL_CONTROL 0x80000000
#define VDL_BACKGROUND 0xE0000000
#define VDL_RGBCTL_MASK 0x60000000
#define VDL_PEN_MASK 0x1F000000
#define VDL_R_MASK 0x00FF0000
#define VDL_G_MASK 0x0000FF00
#define VDL_B_MASK 0x000000FF
#define VDL_B_SHIFT 0
#define VDL_G_SHIFT 8
#define VDL_R_SHIFT 16
#define VDL_PEN_SHIFT 24
#define VDL_RGBSEL_SHIFT 29
/* VDL_RGBCTL_MASK definitions */
#define VDL_FULLRGB 0x00000000
#define VDL_REDONLY 0x60000000
#define VDL_GREENONLY 0x40000000
#define VDL_BLUEONLY 0x20000000
#pragma pack(push,1)
struct cdmaw
{
unsigned int lines:9;//0-8
unsigned int numword:6;//9-14
unsigned int prevover:1;//15
unsigned int currover:1;//16
unsigned int prevtick:1;//17
unsigned int abs:1;//18
unsigned int vmode:1;//19
unsigned int pad0:1;//20
unsigned int enadma:1;//21
unsigned int pad1:1;//22
unsigned int modulo:3;//23-25
unsigned int pad2:6;//26-31
};
union CDMW
{
unsigned int raw;
cdmaw dmaw;
};
struct VDLDatum
{
unsigned char CLUTB[32];
unsigned char CLUTG[32];
unsigned char CLUTR[32];
unsigned int BACKGROUND;
unsigned int HEADVDL;
unsigned int MODULO;
unsigned int CURRENTVDL;
unsigned int CURRENTBMP;
unsigned int PREVIOUSBMP;
unsigned int OUTCONTROLL;
CDMW CLUTDMA;
int linedelay;
};
#pragma pack(pop)
static VDLDatum vdl;
static unsigned char * vram;
unsigned int _vdl_SaveSize()
{
return sizeof(VDLDatum);
}
void _vdl_Save(void *buff)
{
memcpy(buff,&vdl,sizeof(VDLDatum));
}
void _vdl_Load(void *buff)
{
memcpy(&vdl,buff,sizeof(VDLDatum));
}
#define CLUTB vdl.CLUTB
#define CLUTG vdl.CLUTG
#define CLUTR vdl.CLUTR
#define BACKGROUND vdl.BACKGROUND
#define HEADVDL vdl.HEADVDL
#define MODULO vdl.MODULO
#define CURRENTVDL vdl.CURRENTVDL
#define CURRENTBMP vdl.CURRENTBMP
#define PREVIOUSBMP vdl.PREVIOUSBMP
#define OUTCONTROLL vdl.OUTCONTROLL
#define CLUTDMA vdl.CLUTDMA
#define linedelay vdl.linedelay
unsigned int vmreadw(unsigned int addr);
//static AString str;
void _vdl_ProcessVDL( unsigned int addr)
{
HEADVDL=addr;
if((addr&0xfff00000)!=0x200000)
{
//io_interface(EXT_DEBUG_PRINT,(void*)str.print("!!!!VDLP!!!! Êîä çà ãðàíèöàìè VRAM!!! 0x%8.8X",addr).CStr());
}
}
static const unsigned int HOWMAYPIXELEXPECTPERLINE[8] =
{320, 384, 512, 640, 1024, 320, 320, 320};
// ###### Per line implementation ######
int jw=0;
bool doloadclut=false;
__inline void VDLExec()
{
unsigned int NEXTVDL,tmp;
unsigned char ifgnorflag=0;
tmp=vmreadw(CURRENTVDL);
if(tmp==0) // End of list
{
linedelay=511;
doloadclut=false;
}
else
{
CLUTDMA.raw=tmp;
if(CLUTDMA.dmaw.currover)
CURRENTBMP=vmreadw(CURRENTVDL+4);
if(CLUTDMA.dmaw.prevover)
PREVIOUSBMP=vmreadw(CURRENTVDL+8);
if(CLUTDMA.dmaw.abs)
{
NEXTVDL=(CURRENTVDL+vmreadw(CURRENTVDL+12)+16);
//CDebug::DPrint("Relative offset??\n");
}
else
NEXTVDL=vmreadw(CURRENTVDL+12);
CURRENTVDL+=16;
int nmcmd=CLUTDMA.dmaw.numword; //nmcmd-=4;?
for(int i=0; i<nmcmd; i++)
{
int cmd=vmreadw(CURRENTVDL);
// if(CURRENTVDL>0x2DC6C0&&CURRENTVDL<0x2FC290) CURRENTVDL-=4;
//else
CURRENTVDL+=4;
if(!(cmd&0x80000000)/*||!(cmd&0x80)*/)
{
unsigned int coloridx=(cmd&VDL_PEN_MASK)>>VDL_PEN_SHIFT;
if((cmd&VDL_RGBCTL_MASK)==VDL_FULLRGB)
{
CLUTR[coloridx]=((cmd&VDL_R_MASK)>>VDL_R_SHIFT);
CLUTG[coloridx]=((cmd&VDL_G_MASK)>>VDL_G_SHIFT);
CLUTB[coloridx]=((cmd&VDL_B_MASK)>>VDL_B_SHIFT); }
else if(cmd&VDL_RGBCTL_MASK==VDL_REDONLY)
CLUTR[coloridx]=(cmd&VDL_R_MASK)>>VDL_R_SHIFT;
else if(cmd&VDL_RGBCTL_MASK==VDL_GREENONLY)
CLUTG[coloridx]=(cmd&VDL_G_MASK)>>VDL_G_SHIFT;
else if(cmd&VDL_RGBCTL_MASK==VDL_BLUEONLY)
CLUTB[coloridx]=(cmd&VDL_B_MASK)>>VDL_B_SHIFT;
}
else if(!(cmd&0xff000000)==VDL_BACKGROUND)
{
if(ifgnorflag)continue;
BACKGROUND=(( cmd&0xFF )<<16)|
(( cmd&0xFF00 )) |
(((cmd>>16)&0xFF) );
}
else if((cmd&0xE0000000)==0xc0000000)
{
if(ifgnorflag)continue;
OUTCONTROLL=cmd;
ifgnorflag=OUTCONTROLL&2;
//if(!ifgnorflag)break;
}
else if(cmd==0xffffffff)
{
if(ifgnorflag)continue;
for(unsigned int j=0;j<32;j++)
{
CLUTB[j]=CLUTG[j]=CLUTR[j]=((j&0x1f)<<3)|((j>>2)&7);
}
}
else if((cmd&0xff000000)!=0xE1000000 && (cmd&0xC0000000)!=0x80000000)
{
// io_interface(EXT_DEBUG_PRINT,(void*)str.print("::::VDLP:::: Íåèçâåñòíàÿ êîìàíäà... Comm=0x%8.8X",cmd).CStr());
}
}//for(i<nmcmd)
CURRENTVDL=NEXTVDL;
MODULO=HOWMAYPIXELEXPECTPERLINE[CLUTDMA.dmaw.modulo];
if(MODULO!=320)
{
// io_interface(EXT_DEBUG_PRINT,(void*)str.print("::::VDLP:::: Íåñòàíäàðòíûé ýêðàí÷èê... W=%d, DMAWORD=0x%8.8X",MODULO, CLUTDMA.raw).CStr());
}
doloadclut=linedelay=CLUTDMA.dmaw.lines;
}
}
__inline uint32 VRAMOffEval(uint32 addr, uint32 line)
{
return ((((~addr)&2)<<18)+((addr>>2)<<1)+1024*512*line);
}
void _vdl_DoLineNew(int line2x, VDLFrame *frame)
{
int y,i;
int line=line2x&0x7ff;
if(line==0)
{
doloadclut=true;
linedelay=0;
CURRENTVDL=HEADVDL;
VDLExec();
}
y=(line-(16));
if(linedelay==0)
{
VDLExec();
}
if((y>=0) && (y<256)) // 256???
{
if(CLUTDMA.dmaw.enadma)
{
{
unsigned short *dst;
unsigned int *src;
dst=frame->lines[y].line;
src=(unsigned int*)(vram+((PREVIOUSBMP^2) & 0x0FFFFF));
i=320;
while(i--)*dst++=*(unsigned short*)(src++);
}
memcpy(frame->lines[y].xCLUTB,CLUTB,32);
memcpy(frame->lines[y].xCLUTG,CLUTG,32);
memcpy(frame->lines[y].xCLUTR,CLUTR,32);
}
frame->lines[y].xOUTCONTROLL=OUTCONTROLL;
frame->lines[y].xCLUTDMA=CLUTDMA.raw;
frame->lines[y].xBACKGROUND=BACKGROUND;
} // //if((y>=0) && (y<240))
if(CURRENTBMP & 2)
CURRENTBMP+=MODULO*4 - 2;
else
CURRENTBMP+=2;
if(!CLUTDMA.dmaw.prevtick)
{
PREVIOUSBMP=CURRENTBMP;
}
else
{
if(PREVIOUSBMP & 2)
PREVIOUSBMP+=MODULO*4 - 2;
else
PREVIOUSBMP+=2;
}
linedelay--;
OUTCONTROLL&=~1; //Vioff1ln
}
void _vdl_Init(unsigned char *vramstart)
{
vram=vramstart;
static const unsigned int StartupVDL[]=
{ // Startup VDL at addres 0x2B0000
0x00004410, 0x002C0000, 0x002C0000, 0x002B0098,
0x00000000, 0x01080808, 0x02101010, 0x03191919,
0x04212121, 0x05292929, 0x06313131, 0x073A3A3A,
0x08424242, 0x094A4A4A, 0x0A525252, 0x0B5A5A5A,
0x0C636363, 0x0D6B6B6B, 0x0E737373, 0x0F7B7B7B,
0x10848484, 0x118C8C8C, 0x12949494, 0x139C9C9C,
0x14A5A5A5, 0x15ADADAD, 0x16B5B5B5, 0x17BDBDBD,
0x18C5C5C5, 0x19CECECE, 0x1AD6D6D6, 0x1BDEDEDE,
0x1CE6E6E6, 0x1DEFEFEF, 0x1EF8F8F8, 0x1FFFFFFF,
0xE0010101, 0xC001002C, 0x002180EF, 0x002C0000,
0x002C0000, 0x002B00A8, 0x00000000, 0x002C0000,
0x002C0000, 0x002B0000
};
HEADVDL=0xB0000;
for(int i=0;i<(sizeof(StartupVDL)/4);i++)
_mem_write32(HEADVDL+i*4+1024*1024*2,StartupVDL[i]);
//memcpy(vram+HEADVDL, StartupVDL, sizeof(StartupVDL));
for(unsigned int i=0;i<32;i++)
{
CLUTB[i]=CLUTG[i]=CLUTR[i]=((i&0x1f)<<3)|((i>>2)&7);
}
}
unsigned int vmreadw(unsigned int addr)
{
//unsigned int val;
//val=*(unsigned int*)(vram+(addr&0xfffff));
//return val;
return _mem_read32((addr&0xfffff)+1024*1024*2);
}