1 /***************************************************************************
2 copyright : (C) 2001 by Pete Bernert, 2011 notaz
4 ***************************************************************************/
5 /***************************************************************************
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. See also the license.txt file for *
11 * additional informations. *
13 ***************************************************************************/
18 #include "../gpulib/gpu.h"
19 #include "../../include/arm_features.h"
21 #ifdef THREAD_RENDERING
22 #include "../gpulib/gpulib_thread_if.h"
23 #define do_cmd_list real_do_cmd_list
24 #define renderer_init real_renderer_init
25 #define renderer_finish real_renderer_finish
26 #define renderer_sync_ecmds real_renderer_sync_ecmds
27 #define renderer_update_caches real_renderer_update_caches
28 #define renderer_flush_queues real_renderer_flush_queues
29 #define renderer_set_interlace real_renderer_set_interlace
30 #define renderer_set_config real_renderer_set_config
31 #define renderer_notify_res_change real_renderer_notify_res_change
32 #define renderer_notify_update_lace real_renderer_notify_update_lace
33 #define renderer_sync real_renderer_sync
34 #define ex_regs scratch_ex_regs
40 #define INFO_DRAWSTART 1
41 #define INFO_DRAWEND 2
42 #define INFO_DRAWOFF 3
44 #define SHADETEXBIT(x) ((x>>24) & 0x1)
45 #define SEMITRANSBIT(x) ((x>>25) & 0x1)
46 #define PSXRGB(r,g,b) ((g<<10)|(b<<5)|r)
48 #define DATAREGISTERMODES unsigned short
51 #define DR_VRAMTRANSFER 1
53 #define GPUSTATUS_READYFORVRAM 0x08000000
57 #define SWAP16(x) __builtin_bswap16(x)
58 #define SWAP32(x) __builtin_bswap32(x)
60 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
63 #define HOST2LE32(x) SWAP32(x)
64 #define HOST2BE32(x) (x)
65 #define LE2HOST32(x) SWAP32(x)
66 #define BE2HOST32(x) (x)
68 #define HOST2LE16(x) SWAP16(x)
69 #define HOST2BE16(x) (x)
70 #define LE2HOST16(x) SWAP16(x)
71 #define BE2HOST16(x) (x)
75 // little endian config
76 #define HOST2LE32(x) (x)
77 #define HOST2BE32(x) SWAP32(x)
78 #define LE2HOST32(x) (x)
79 #define BE2HOST32(x) SWAP32(x)
81 #define HOST2LE16(x) (x)
82 #define HOST2BE16(x) SWAP16(x)
83 #define LE2HOST16(x) (x)
84 #define BE2HOST16(x) SWAP16(x)
88 #define GETLEs16(X) ((int16_t)GETLE16((uint16_t *)(X)))
90 #define GETLE16(X) LE2HOST16(*(uint16_t *)(X))
91 #define GETLE32_(X) LE2HOST32(*(uint32_t *)(X))
92 #define PUTLE16(X, Y) do{*((uint16_t *)(X))=HOST2LE16((uint16_t)(Y));}while(0)
93 #define PUTLE32_(X, Y) do{*((uint32_t *)(X))=HOST2LE32((uint32_t)(Y));}while(0)
94 #if defined(__arm__) && !defined(HAVE_ARMV6)
95 // for (very) old ARMs with no unaligned loads?
96 #define GETLE32(X) (*(uint16_t *)(X)|((uint32_t)((uint16_t *)(X))[1]<<16))
97 #define PUTLE32(X, Y) do{uint16_t *p_=(uint16_t *)(X);uint32_t y_=Y;p_[0]=y_;p_[1]=y_>>16;}while(0)
99 #define GETLE32 GETLE32_
100 #define PUTLE32 PUTLE32_
103 /////////////////////////////////////////////////////////////////////////////
105 typedef struct VRAMLOADTTAG
113 unsigned short *ImagePtr;
116 /////////////////////////////////////////////////////////////////////////////
118 typedef struct PSXPOINTTAG
124 typedef struct PSXSPOINTTAG
130 typedef struct PSXRECTTAG
138 // linux defines for some windows stuff
142 #define BOOL unsigned short
143 #define LOWORD(l) ((unsigned short)(l))
144 #define HIWORD(l) ((unsigned short)(((uint32_t)(l) >> 16) & 0xFFFF))
145 #define max(a,b) (((a) > (b)) ? (a) : (b))
146 #define min(a,b) (((a) < (b)) ? (a) : (b))
147 #define DWORD uint32_t
149 #define __int64 long long int
152 typedef struct RECTTAG
160 /////////////////////////////////////////////////////////////////////////////
162 typedef struct TWINTAG
168 /////////////////////////////////////////////////////////////////////////////
170 typedef struct PSXDISPLAYTAG
172 PSXPoint_t DisplayModeNew;
173 PSXPoint_t DisplayMode;
174 PSXPoint_t DisplayPosition;
175 PSXPoint_t DisplayEnd;
180 int32_t InterlacedNew;
184 PSXSPoint_t DrawOffset;
190 /////////////////////////////////////////////////////////////////////////////
194 extern int32_t GlobalTextAddrX,GlobalTextAddrY,GlobalTextTP;
195 extern int32_t GlobalTextABR,GlobalTextPAGE;
196 extern short ly0,lx0,ly1,lx1,ly2,lx2,ly3,lx3;
197 extern long lLowerpart;
198 extern BOOL bCheckMask;
199 extern unsigned short sSetMask;
200 extern unsigned long lSetMask;
204 extern short DrawSemiTrans;
208 extern BOOL bUsingTWin;
210 extern void (*primTableJ[256])(unsigned char *);
211 extern void (*primTableSkip[256])(unsigned char *);
212 extern unsigned short usMirror;
214 extern uint32_t dwCfgFixes;
215 extern uint32_t dwActFixes;
216 extern int iUseFixes;
217 extern int iUseDither;
218 extern BOOL bDoVSyncUpdate;
219 extern int32_t drawX;
220 extern int32_t drawY;
221 extern int32_t drawW;
222 extern int32_t drawH;
229 #define KEY_RESETTEXSTORE 1
230 #define KEY_SHOWFPS 2
231 #define KEY_RESETOPAQUE 4
232 #define KEY_RESETDITHER 8
233 #define KEY_RESETFILTER 16
234 #define KEY_RESETADVBLEND 32
235 #define KEY_BADTEXTURES 128
236 #define KEY_CHECKTHISOUT 256
238 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
239 #define RED(x) (x & 0xff)
240 #define BLUE(x) ((x>>16) & 0xff)
241 #define GREEN(x) ((x>>8) & 0xff)
242 #define COLOR(x) (x & 0xffffff)
244 #define RED(x) ((x>>24) & 0xff)
245 #define BLUE(x) ((x>>8) & 0xff)
246 #define GREEN(x) ((x>>16) & 0xff)
247 #define COLOR(x) SWAP32(x & 0xffffff)
250 PSXDisplay_t PSXDisplay;
251 unsigned char *psxVub;
252 unsigned short *psxVuw;
253 unsigned short *psxVuw_eom;
256 uint32_t lGPUInfoVals[16];
258 VRAMLoad_t VRAMWrite;
261 DATAREGISTERMODES DataWriteMode;
262 DATAREGISTERMODES DataReadMode;
264 BOOL bCheckMask = FALSE;
265 unsigned short sSetMask = 0;
266 unsigned long lSetMask = 0;
272 /////////////////////////////////////////////////////////////////////////////
274 static void set_vram(void *vram)
277 psxVuw=(unsigned short *)psxVub;
278 psxVuw_eom=psxVuw+1024*512; // pre-calc of end of vram
281 int renderer_init(void)
285 PSXDisplay.RGB24 = FALSE; // init some stuff
286 PSXDisplay.Interlaced = FALSE;
287 PSXDisplay.DrawOffset.x = 0;
288 PSXDisplay.DrawOffset.y = 0;
289 PSXDisplay.DisplayMode.x= 320;
290 PSXDisplay.DisplayMode.y= 240;
291 PSXDisplay.Disabled = FALSE;
292 PSXDisplay.Range.x0=0;
293 PSXDisplay.Range.x1=0;
294 PSXDisplay.Double = 1;
296 DataWriteMode = DR_NORMAL;
297 lGPUstatusRet = 0x14802000;
302 void renderer_finish(void)
306 void renderer_notify_res_change(void)
310 extern const unsigned char cmd_lengths[256];
312 int do_cmd_list(uint32_t *list, int list_len, int *last_cmd)
314 unsigned int cmd = 0, len;
315 uint32_t *list_start = list;
316 uint32_t *list_end = list + list_len;
318 for (; list < list_end; list += 1 + len)
320 cmd = GETLE32(list) >> 24;
321 len = cmd_lengths[cmd];
322 if (list + 1 + len > list_end) {
328 if (cmd == 0xa0 || cmd == 0xc0)
329 break; // image i/o, forward to upper layer
330 else if ((cmd & 0xf8) == 0xe0)
331 gpu.ex_regs[cmd & 7] = GETLE32(list);
334 primTableJ[cmd]((void *)list);
340 u32 num_vertexes = 2;
341 u32 *list_position = &(list[3]);
345 if(list_position >= list_end) {
350 if((*list_position & HOST2LE32(0xf000f000)) == HOST2LE32(0x50005000))
357 len += (num_vertexes - 2);
363 u32 num_vertexes = 2;
364 u32 *list_position = &(list[4]);
368 if(list_position >= list_end) {
373 if((*list_position & HOST2LE32(0xf000f000)) == HOST2LE32(0x50005000))
380 len += (num_vertexes - 2) * 2;
385 case 0xA0: // sys -> vid
387 short *slist = (void *)list;
388 u32 load_width = LE2HOST32(slist[4]);
389 u32 load_height = LE2HOST32(slist[5]);
390 u32 load_size = load_width * load_height;
392 len += load_size / 2;
400 gpu.ex_regs[1] &= ~0x1ff;
401 gpu.ex_regs[1] |= lGPUstatusRet & 0x1ff;
404 return list - list_start;
407 void renderer_sync_ecmds(uint32_t *ecmds_)
409 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
410 // the funcs below expect LE
411 uint32_t i, ecmds[8];
412 for (i = 1; i <= 6; i++)
413 ecmds[i] = HTOLE32(ecmds_[i]);
415 uint32_t *ecmds = ecmds_;
417 cmdTexturePage((unsigned char *)&ecmds[1]);
418 cmdTextureWindow((unsigned char *)&ecmds[2]);
419 cmdDrawAreaStart((unsigned char *)&ecmds[3]);
420 cmdDrawAreaEnd((unsigned char *)&ecmds[4]);
421 cmdDrawOffset((unsigned char *)&ecmds[5]);
422 cmdSTP((unsigned char *)&ecmds[6]);
425 void renderer_update_caches(int x, int y, int w, int h)
429 void renderer_flush_queues(void)
433 void renderer_set_interlace(int enable, int is_odd)
437 void renderer_sync(void)
441 void renderer_notify_update_lace(int updated)
445 #include "../../frontend/plugin_lib.h"
447 void renderer_set_config(const struct rearmed_cbs *cbs)
449 iUseDither = cbs->gpu_peops.iUseDither;
450 dwActFixes = cbs->gpu_peops.dwActFixes;
451 if (cbs->pl_set_gpu_caps)
452 cbs->pl_set_gpu_caps(0);