1 /***************************************************************************
2 * Copyright (C) 2010 PCSX4ALL Team *
3 * Copyright (C) 2010 Unai *
4 * Copyright (C) 2011 notaz *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. *
20 ***************************************************************************/
25 #include "../gpulib/gpu.h"
37 #define FRAME_BUFFER_SIZE (1024*512*2)
38 #define FRAME_WIDTH 1024
39 #define FRAME_HEIGHT 512
40 #define FRAME_OFFSET(x,y) (((y)<<10)+(x))
42 #define isSkip 0 /* skip frame (info coming from GPU) */
44 static int linesInterlace; /* internal lines interlace */
45 static int force_interlace;
47 static bool light = true; /* lighting */
48 static bool blend = true; /* blending */
49 static bool FrameToRead = false; /* load image in progress */
50 static bool FrameToWrite = false; /* store image in progress */
52 static bool enableAbbeyHack = false; /* Abe's Odyssey hack */
61 ///////////////////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////////////////
67 static s32 x_end,y_end;
70 static s32 PacketCount;
71 static s32 PacketIndex;
74 static u32 TextureWindow [4];
75 static u32 DrawingArea [4];
76 static u32 DrawingOffset [2];
88 static u32 tInc, tMsk;
100 static GPUPacket PacketBuffer;
101 static u16 *GPU_FrameBuffer;
104 ///////////////////////////////////////////////////////////////////////////////
106 #include "../gpu_unai/gpu_fixedpoint.h"
108 // Inner loop driver instanciation file
109 #include "../gpu_unai/gpu_inner.h"
112 #define GPU_RGB16(rgb) ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
114 #define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<20)>>20)
115 //#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<21)>>21)
116 #define GPU_EXPANDSIGN_SPRT(x) (((s32)(x)<<21)>>21)
118 //#define GPU_TESTRANGE(x) { if((u32)(x+1024) > 2047) return; }
119 #define GPU_TESTRANGE(x) { if ((x<-1023) || (x>1023)) return; }
121 #define GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
123 // GPU internal image drawing functions
124 #include "../gpu_unai/gpu_raster_image.h"
126 // GPU internal line drawing functions
127 #include "../gpu_unai/gpu_raster_line.h"
129 // GPU internal polygon drawing functions
130 #include "../gpu_unai/gpu_raster_polygon.h"
132 // GPU internal sprite drawing functions
133 #include "../gpu_unai/gpu_raster_sprite.h"
135 // GPU command buffer execution/store
136 #include "../gpu_unai/gpu_command.h"
138 #define unai_do_prim(cmd, list, len) \
139 memcpy(PacketBuffer.U4, list, (len) * 4); \
140 gpuSendPacketFunction(cmd)
142 /////////////////////////////////////////////////////////////////////////////
144 int renderer_init(void)
146 GPU_FrameBuffer = (u16 *)gpu.vram;
149 for(int i=1;i<=(1<<TABLE_BITS);++i)
151 double v = 1.0 / double(i);
152 #ifdef GPU_TABLE_10_BITS
153 v *= double(0xffffffff>>1);
155 v *= double(0x80000000);
157 s_invTable[i-1]=s32(v);
163 extern const unsigned char cmd_lengths[256];
165 void do_cmd_list(unsigned int *list, int list_len)
167 unsigned int cmd, len;
168 unsigned int *list_end = list + list_len;
170 linesInterlace = force_interlace;
171 #ifndef __ARM_ARCH_7A__ /* XXX */
172 linesInterlace |= gpu.status.interlace;
175 for (; list < list_end; list += 1 + len)
178 len = cmd_lengths[cmd];
184 u32 num_vertexes = 1;
185 u32 *list_position = &(list[2]);
188 memcpy(&PacketBuffer.U4[0], list, 4 * 3);
189 gpuDrawLF(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
193 if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end)
196 PacketBuffer.U4[1] = PacketBuffer.U4[2];
197 PacketBuffer.U4[2] = *list_position++;
198 gpuDrawLF(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
204 len += (num_vertexes - 2);
211 u32 num_vertexes = 1;
212 u32 *list_position = &(list[2]);
215 memcpy(&PacketBuffer.U4[0], list, 4 * 4);
216 gpuDrawLG(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
220 if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end)
223 PacketBuffer.U4[0] = PacketBuffer.U4[2];
224 PacketBuffer.U4[1] = PacketBuffer.U4[3];
225 PacketBuffer.U4[2] = *list_position++;
226 PacketBuffer.U4[3] = *list_position++;
227 gpuDrawLG(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
233 len += (num_vertexes - 2) * 2;
239 case 0xA0: // sys -> vid
241 u32 load_width = list[2] & 0xffff;
242 u32 load_height = list[2] >> 16;
243 u32 load_size = load_width * load_height;
245 len += load_size / 2;
251 unai_do_prim(cmd, list, len + 1);
257 void renderer_sync_ecmds(uint32_t *ecmds)
259 unai_do_prim(0xe1, &ecmds[1], 1);
260 unai_do_prim(0xe2, &ecmds[2], 1);
261 unai_do_prim(0xe3, &ecmds[3], 1);
262 unai_do_prim(0xe4, &ecmds[4], 1);
263 unai_do_prim(0xe5, &ecmds[5], 1);
264 unai_do_prim(0xe6, &ecmds[6], 1);
267 void renderer_update_caches(int x, int y, int w, int h)
271 void renderer_flush_queues(void)
275 void renderer_set_interlace(int enable, int is_odd)
281 #include "../../frontend/plugin_lib.h"
283 void renderer_set_config(const struct rearmed_cbs *cbs)
285 force_interlace = cbs->gpu_unai.lineskip;
286 enableAbbeyHack = cbs->gpu_unai.abe_hack;
287 light = !cbs->gpu_unai.no_light;
288 blend = !cbs->gpu_unai.no_blend;