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
|
/***************************************************************************
* Copyright (C) 2010 PCSX4ALL Team *
* Copyright (C) 2010 Unai *
* Copyright (C) 2011 notaz *
* *
* This program 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. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. *
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gpu.h"
#define u8 uint8_t
#define s8 int8_t
#define u16 uint16_t
#define s16 int16_t
#define u32 uint32_t
#define s32 int32_t
#define s64 int64_t
#define INLINE static
#define FRAME_BUFFER_SIZE (1024*512*2)
#define FRAME_WIDTH 1024
#define FRAME_HEIGHT 512
#define FRAME_OFFSET(x,y) (((y)<<10)+(x))
#define isSkip 0 /* skip frame (info coming from GPU) */
#define alt_fps 0
static int linesInterlace; /* internal lines interlace */
static int force_interlace;
static bool light = true; /* lighting */
static bool blend = true; /* blending */
static bool FrameToRead = false; /* load image in progress */
static bool FrameToWrite = false; /* store image in progress */
static bool enableAbbeyHack = false; /* Abe's Odyssey hack */
static u8 BLEND_MODE;
static u8 TEXT_MODE;
static u8 Masking;
static u16 PixelMSB;
static u16 PixelData;
///////////////////////////////////////////////////////////////////////////////
// GPU Global data
///////////////////////////////////////////////////////////////////////////////
// Dma Transfers info
static s32 px,py;
static s32 x_end,y_end;
static u16* pvram;
static s32 PacketCount;
static s32 PacketIndex;
// Rasterizer status
static u32 TextureWindow [4];
static u32 DrawingArea [4];
static u32 DrawingOffset [2];
static u16* TBA;
static u16* CBA;
// Inner Loops
static s32 u4, du4;
static s32 v4, dv4;
static s32 r4, dr4;
static s32 g4, dg4;
static s32 b4, db4;
static u32 lInc;
static u32 tInc, tMsk;
union GPUPacket
{
u32 U4[16];
s32 S4[16];
u16 U2[32];
s16 S2[32];
u8 U1[64];
s8 S1[64];
};
static GPUPacket PacketBuffer;
static u16 *GPU_FrameBuffer;
static u32 GPU_GP1;
///////////////////////////////////////////////////////////////////////////////
#include "../gpu_unai/gpu_fixedpoint.h"
// Inner loop driver instanciation file
#include "../gpu_unai/gpu_inner.h"
// GPU Raster Macros
#define GPU_RGB16(rgb) ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<20)>>20)
//#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<21)>>21)
#define GPU_EXPANDSIGN_SPRT(x) (((s32)(x)<<21)>>21)
//#define GPU_TESTRANGE(x) { if((u32)(x+1024) > 2047) return; }
#define GPU_TESTRANGE(x) { if ((x<-1023) || (x>1023)) return; }
#define GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
// GPU internal image drawing functions
#include "../gpu_unai/gpu_raster_image.h"
// GPU internal line drawing functions
#include "../gpu_unai/gpu_raster_line.h"
// GPU internal polygon drawing functions
#include "../gpu_unai/gpu_raster_polygon.h"
// GPU internal sprite drawing functions
#include "../gpu_unai/gpu_raster_sprite.h"
// GPU command buffer execution/store
#include "../gpu_unai/gpu_command.h"
#define unai_do_prim(cmd, list, len) \
memcpy(PacketBuffer.U4, list, (len) * 4); \
gpuSendPacketFunction(cmd)
/////////////////////////////////////////////////////////////////////////////
int renderer_init(void)
{
GPU_FrameBuffer = (u16 *)gpu.vram;
// s_invTable
for(int i=1;i<=(1<<TABLE_BITS);++i)
{
double v = 1.0 / double(i);
#ifdef GPU_TABLE_10_BITS
v *= double(0xffffffff>>1);
#else
v *= double(0x80000000);
#endif
s_invTable[i-1]=s32(v);
}
return 0;
}
extern const unsigned char cmd_lengths[256];
void do_cmd_list(unsigned int *list, int list_len)
{
unsigned int cmd, len;
unsigned int *list_end = list + list_len;
linesInterlace = force_interlace;
#ifndef __ARM_ARCH_7A__ /* XXX */
linesInterlace |= gpu.status.interlace;
#endif
for (; list < list_end; list += 1 + len)
{
cmd = *list >> 24;
len = cmd_lengths[cmd];
switch(cmd)
{
case 0x48 ... 0x4F:
{
u32 num_vertexes = 1;
u32 *list_position = &(list[2]);
u32 PRIM = cmd;
memcpy(&PacketBuffer.U4[0], list, 4 * 3);
gpuDrawLF(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
while(1)
{
if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end)
break;
PacketBuffer.U4[1] = PacketBuffer.U4[2];
PacketBuffer.U4[2] = *list_position++;
gpuDrawLF(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
num_vertexes++;
}
if(num_vertexes > 2)
len += (num_vertexes - 2);
break;
}
case 0x58 ... 0x5F:
{
u32 num_vertexes = 1;
u32 *list_position = &(list[2]);
u32 PRIM = cmd;
memcpy(&PacketBuffer.U4[0], list, 4 * 4);
gpuDrawLG(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
while(1)
{
if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end)
break;
PacketBuffer.U4[0] = PacketBuffer.U4[2];
PacketBuffer.U4[1] = PacketBuffer.U4[3];
PacketBuffer.U4[2] = *list_position++;
PacketBuffer.U4[3] = *list_position++;
gpuDrawLG(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
num_vertexes++;
}
if(num_vertexes > 2)
len += (num_vertexes - 2) * 2;
break;
}
#ifdef TEST
case 0xA0: // sys -> vid
{
u32 load_width = list[2] & 0xffff;
u32 load_height = list[2] >> 16;
u32 load_size = load_width * load_height;
len += load_size / 2;
break;
}
#endif
default:
unai_do_prim(cmd, list, len + 1);
break;
}
}
}
void renderer_sync_ecmds(uint32_t *ecmds)
{
unai_do_prim(0xe1, &ecmds[1], 1);
unai_do_prim(0xe2, &ecmds[2], 1);
unai_do_prim(0xe3, &ecmds[3], 1);
unai_do_prim(0xe4, &ecmds[4], 1);
unai_do_prim(0xe5, &ecmds[5], 1);
unai_do_prim(0xe6, &ecmds[6], 1);
}
void renderer_invalidate_caches(int x, int y, int w, int h)
{
}
void renderer_flush_queues(void)
{
}
void renderer_set_interlace(int enable, int is_odd)
{
}
#ifndef TEST
#include "../../frontend/plugin_lib.h"
void renderer_set_config(const struct rearmed_cbs *cbs)
{
force_interlace = cbs->gpu_unai.lineskip;
enableAbbeyHack = cbs->gpu_unai.abe_hack;
light = !cbs->gpu_unai.no_light;
blend = !cbs->gpu_unai.no_blend;
}
#endif
|