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"
20 #ifdef THREAD_RENDERING
21 #include "../gpulib/gpulib_thread_if.h"
22 #define do_cmd_list real_do_cmd_list
23 #define renderer_init real_renderer_init
24 #define renderer_finish real_renderer_finish
25 #define renderer_sync_ecmds real_renderer_sync_ecmds
26 #define renderer_update_caches real_renderer_update_caches
27 #define renderer_flush_queues real_renderer_flush_queues
28 #define renderer_set_interlace real_renderer_set_interlace
29 #define renderer_set_config real_renderer_set_config
30 #define renderer_notify_res_change real_renderer_notify_res_change
31 #define renderer_notify_update_lace real_renderer_notify_update_lace
32 #define renderer_sync real_renderer_sync
33 #define ex_regs scratch_ex_regs
39 #define INFO_DRAWSTART 1
40 #define INFO_DRAWEND 2
41 #define INFO_DRAWOFF 3
43 #define SHADETEXBIT(x) ((x>>24) & 0x1)
44 #define SEMITRANSBIT(x) ((x>>25) & 0x1)
45 #define PSXRGB(r,g,b) ((g<<10)|(b<<5)|r)
47 #define DATAREGISTERMODES unsigned short
50 #define DR_VRAMTRANSFER 1
52 #define GPUSTATUS_READYFORVRAM 0x08000000
56 #define SWAP16(x) ({ uint16_t y=(x); (((y)>>8 & 0xff) | ((y)<<8 & 0xff00)); })
57 #define SWAP32(x) ({ uint32_t y=(x); (((y)>>24 & 0xfful) | ((y)>>8 & 0xff00ul) | ((y)<<8 & 0xff0000ul) | ((y)<<24 & 0xff000000ul)); })
62 #define HOST2LE32(x) SWAP32(x)
63 #define HOST2BE32(x) (x)
64 #define LE2HOST32(x) SWAP32(x)
65 #define BE2HOST32(x) (x)
67 #define HOST2LE16(x) SWAP16(x)
68 #define HOST2BE16(x) (x)
69 #define LE2HOST16(x) SWAP16(x)
70 #define BE2HOST16(x) (x)
74 // little endian config
75 #define HOST2LE32(x) (x)
76 #define HOST2BE32(x) SWAP32(x)
77 #define LE2HOST32(x) (x)
78 #define BE2HOST32(x) SWAP32(x)
80 #define HOST2LE16(x) (x)
81 #define HOST2BE16(x) SWAP16(x)
82 #define LE2HOST16(x) (x)
83 #define BE2HOST16(x) SWAP16(x)
87 #define GETLEs16(X) ((int16_t)GETLE16((uint16_t *)X))
88 #define GETLEs32(X) ((int16_t)GETLE32((uint16_t *)X))
90 #define GETLE16(X) LE2HOST16(*(uint16_t *)X)
91 #define GETLE32_(X) LE2HOST32(*(uint32_t *)X)
92 #define GETLE16D(X) ({uint32_t val = GETLE32(X); (val<<16 | val >> 16);})
93 #define PUTLE16(X, Y) do{*((uint16_t *)X)=HOST2LE16((uint16_t)Y);}while(0)
94 #define PUTLE32_(X, Y) do{*((uint32_t *)X)=HOST2LE16((uint32_t)Y);}while(0)
96 #define GETLE32(X) (*(uint16_t *)(X)|(((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 !defined(__BIG_ENDIAN__) || defined(__x86_64__) || defined(__i386__)
239 #ifndef __LITTLE_ENDIAN__
240 #define __LITTLE_ENDIAN__
244 #ifdef __LITTLE_ENDIAN__
245 #define RED(x) (x & 0xff)
246 #define BLUE(x) ((x>>16) & 0xff)
247 #define GREEN(x) ((x>>8) & 0xff)
248 #define COLOR(x) (x & 0xffffff)
249 #elif defined __BIG_ENDIAN__
250 #define RED(x) ((x>>24) & 0xff)
251 #define BLUE(x) ((x>>8) & 0xff)
252 #define GREEN(x) ((x>>16) & 0xff)
253 #define COLOR(x) SWAP32(x & 0xffffff)
256 PSXDisplay_t PSXDisplay;
257 unsigned char *psxVub;
259 unsigned short *psxVuw;
260 unsigned short *psxVuw_eom;
261 signed short *psxVsw;
266 uint32_t lGPUInfoVals[16];
268 VRAMLoad_t VRAMWrite;
271 DATAREGISTERMODES DataWriteMode;
272 DATAREGISTERMODES DataReadMode;
274 BOOL bCheckMask = FALSE;
275 unsigned short sSetMask = 0;
276 unsigned long lSetMask = 0;
282 /////////////////////////////////////////////////////////////////////////////
284 static void set_vram(void *vram)
288 psxVsb=(signed char *)psxVub; // different ways of accessing PSX VRAM
289 psxVsw=(signed short *)psxVub;
290 psxVsl=(int32_t *)psxVub;
291 psxVuw=(unsigned short *)psxVub;
292 psxVul=(uint32_t *)psxVub;
294 psxVuw_eom=psxVuw+1024*512; // pre-calc of end of vram
297 int renderer_init(void)
301 PSXDisplay.RGB24 = FALSE; // init some stuff
302 PSXDisplay.Interlaced = FALSE;
303 PSXDisplay.DrawOffset.x = 0;
304 PSXDisplay.DrawOffset.y = 0;
305 PSXDisplay.DisplayMode.x= 320;
306 PSXDisplay.DisplayMode.y= 240;
307 PSXDisplay.Disabled = FALSE;
308 PSXDisplay.Range.x0=0;
309 PSXDisplay.Range.x1=0;
310 PSXDisplay.Double = 1;
312 DataWriteMode = DR_NORMAL;
313 lGPUstatusRet = 0x14802000;
318 void renderer_finish(void)
322 void renderer_notify_res_change(void)
326 extern const unsigned char cmd_lengths[256];
328 int do_cmd_list(uint32_t *list, int list_len, int *last_cmd)
330 unsigned int cmd = 0, len;
331 uint32_t *list_start = list;
332 uint32_t *list_end = list + list_len;
334 for (; list < list_end; list += 1 + len)
337 len = cmd_lengths[cmd];
338 if (list + 1 + len > list_end) {
344 if (cmd == 0xa0 || cmd == 0xc0)
345 break; // image i/o, forward to upper layer
346 else if ((cmd & 0xf8) == 0xe0)
347 gpu.ex_regs[cmd & 7] = list[0];
350 primTableJ[cmd]((void *)list);
356 u32 num_vertexes = 2;
357 u32 *list_position = &(list[3]);
361 if(list_position >= list_end) {
366 if((*list_position & 0xf000f000) == 0x50005000)
373 len += (num_vertexes - 2);
379 u32 num_vertexes = 2;
380 u32 *list_position = &(list[4]);
384 if(list_position >= list_end) {
389 if((*list_position & 0xf000f000) == 0x50005000)
396 len += (num_vertexes - 2) * 2;
401 case 0xA0: // sys -> vid
403 short *slist = (void *)list;
404 u32 load_width = slist[4];
405 u32 load_height = slist[5];
406 u32 load_size = load_width * load_height;
408 len += load_size / 2;
416 gpu.ex_regs[1] &= ~0x1ff;
417 gpu.ex_regs[1] |= lGPUstatusRet & 0x1ff;
420 return list - list_start;
423 void renderer_sync_ecmds(uint32_t *ecmds)
425 cmdTexturePage((unsigned char *)&ecmds[1]);
426 cmdTextureWindow((unsigned char *)&ecmds[2]);
427 cmdDrawAreaStart((unsigned char *)&ecmds[3]);
428 cmdDrawAreaEnd((unsigned char *)&ecmds[4]);
429 cmdDrawOffset((unsigned char *)&ecmds[5]);
430 cmdSTP((unsigned char *)&ecmds[6]);
433 void renderer_update_caches(int x, int y, int w, int h)
437 void renderer_flush_queues(void)
441 void renderer_set_interlace(int enable, int is_odd)
445 void renderer_sync(void)
449 void renderer_notify_update_lace(int updated)
453 #include "../../frontend/plugin_lib.h"
455 void renderer_set_config(const struct rearmed_cbs *cbs)
457 iUseDither = cbs->gpu_peops.iUseDither;
458 dwActFixes = cbs->gpu_peops.dwActFixes;
459 if (cbs->pl_set_gpu_caps)
460 cbs->pl_set_gpu_caps(0);