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 ***************************************************************************/
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 VIDEO_WIDTH 320
44 static bool isSkip = false; /* skip frame (info coming from GPU) */
45 static int linesInterlace = 0; /* internal lines interlace */
49 static bool light = true; /* lighting */
50 static bool blend = true; /* blending */
51 static bool FrameToRead = false; /* load image in progress */
52 static bool FrameToWrite = false; /* store image in progress */
54 static bool enableAbbeyHack = false; /* Abe's Odyssey hack */
63 ///////////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////////
69 static s32 x_end,y_end;
72 static s32 PacketCount;
73 static s32 PacketIndex;
76 static u32 TextureWindow [4];
77 static u32 DrawingArea [4];
78 static u32 DrawingOffset [2];
90 static u32 tInc, tMsk;
102 static GPUPacket PacketBuffer;
103 static u16 *GPU_FrameBuffer;
106 ///////////////////////////////////////////////////////////////////////////////
108 #include "../gpu_unai/gpu_fixedpoint.h"
110 // Inner loop driver instanciation file
111 #include "../gpu_unai/gpu_inner.h"
114 #define GPU_RGB16(rgb) ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
116 #define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<20)>>20)
117 //#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<21)>>21)
118 #define GPU_EXPANDSIGN_SPRT(x) (((s32)(x)<<21)>>21)
120 //#define GPU_TESTRANGE(x) { if((u32)(x+1024) > 2047) return; }
121 #define GPU_TESTRANGE(x) { if ((x<-1023) || (x>1023)) return; }
123 #define GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
125 // GPU internal image drawing functions
126 #include "../gpu_unai/gpu_raster_image.h"
128 // GPU internal line drawing functions
129 #include "../gpu_unai/gpu_raster_line.h"
131 // GPU internal polygon drawing functions
132 #include "../gpu_unai/gpu_raster_polygon.h"
134 // GPU internal sprite drawing functions
135 #include "../gpu_unai/gpu_raster_sprite.h"
137 // GPU command buffer execution/store
138 #include "../gpu_unai/gpu_command.h"
140 #define unai_do_prim(cmd, list) \
141 PacketBuffer.U4 = list; \
142 gpuSendPacketFunction(cmd)
144 /////////////////////////////////////////////////////////////////////////////
146 int renderer_init(void)
148 GPU_FrameBuffer = (u16 *)gpu.vram;
151 for(int i=1;i<=(1<<TABLE_BITS);++i)
153 double v = 1.0 / double(i);
154 #ifdef GPU_TABLE_10_BITS
155 v *= double(0xffffffff>>1);
157 v *= double(0x80000000);
159 s_invTable[i-1]=s32(v);
165 extern const unsigned char cmd_lengths[256];
167 void do_cmd_list(unsigned int *list, int list_len)
169 unsigned int cmd, len;
171 unsigned int *list_end = list + list_len;
173 for (; list < list_end; list += 1 + len)
175 short *slist = (short *)list;
177 len = cmd_lengths[cmd];
179 unai_do_prim(cmd, list);
185 u32 num_vertexes = 1;
186 u32 *list_position = &(list[2]);
190 if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end)
198 len += (num_vertexes - 2);
205 u32 num_vertexes = 1;
206 u32 *list_position = &(list[2]);
210 if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end)
218 len += ((num_vertexes * 2) - 2);
223 case 0xA0: // sys -> vid
225 u32 load_width = slist[4];
226 u32 load_height = slist[5];
227 u32 load_size = load_width * load_height;
229 len += load_size / 2;
236 void renderer_sync_ecmds(uint32_t *ecmds)
238 unai_do_prim(0xe1, &ecmds[1]);
239 unai_do_prim(0xe2, &ecmds[2]);
240 unai_do_prim(0xe3, &ecmds[3]);
241 unai_do_prim(0xe4, &ecmds[4]);
242 unai_do_prim(0xe5, &ecmds[5]);
243 unai_do_prim(0xe6, &ecmds[6]);
246 void renderer_invalidate_caches(int x, int y, int w, int h)
250 void renderer_flush_queues(void)