Commit | Line | Data |
---|---|---|
b094071f | 1 | /*************************************************************************** |
2 | copyright : (C) 2001 by Pete Bernert, 2011 notaz | |
3 | ||
4 | ***************************************************************************/ | |
5 | /*************************************************************************** | |
6 | * * | |
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. * | |
12 | * * | |
13 | ***************************************************************************/ | |
14 | ||
15 | #include <stdio.h> | |
16 | #include <stdlib.h> | |
17 | #include <string.h> | |
62d7fa95 | 18 | #include "../gpulib/gpu.h" |
0a371c2c | 19 | #include "../../include/arm_features.h" |
b094071f | 20 | |
21 | #define u32 uint32_t | |
22 | ||
23 | #define INFO_TW 0 | |
24 | #define INFO_DRAWSTART 1 | |
25 | #define INFO_DRAWEND 2 | |
26 | #define INFO_DRAWOFF 3 | |
27 | ||
28 | #define SHADETEXBIT(x) ((x>>24) & 0x1) | |
29 | #define SEMITRANSBIT(x) ((x>>25) & 0x1) | |
30 | #define PSXRGB(r,g,b) ((g<<10)|(b<<5)|r) | |
31 | ||
32 | #define DATAREGISTERMODES unsigned short | |
33 | ||
34 | #define DR_NORMAL 0 | |
35 | #define DR_VRAMTRANSFER 1 | |
36 | ||
37 | #define GPUSTATUS_READYFORVRAM 0x08000000 | |
38 | ||
39 | // byteswappings | |
40 | ||
ae097dfb PC |
41 | #define SWAP16(x) __builtin_bswap16(x) |
42 | #define SWAP32(x) __builtin_bswap32(x) | |
b094071f | 43 | |
04bd10b1 | 44 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
b094071f | 45 | |
46 | // big endian config | |
47 | #define HOST2LE32(x) SWAP32(x) | |
48 | #define HOST2BE32(x) (x) | |
49 | #define LE2HOST32(x) SWAP32(x) | |
50 | #define BE2HOST32(x) (x) | |
51 | ||
52 | #define HOST2LE16(x) SWAP16(x) | |
53 | #define HOST2BE16(x) (x) | |
54 | #define LE2HOST16(x) SWAP16(x) | |
55 | #define BE2HOST16(x) (x) | |
56 | ||
57 | #else | |
58 | ||
59 | // little endian config | |
60 | #define HOST2LE32(x) (x) | |
61 | #define HOST2BE32(x) SWAP32(x) | |
62 | #define LE2HOST32(x) (x) | |
63 | #define BE2HOST32(x) SWAP32(x) | |
64 | ||
65 | #define HOST2LE16(x) (x) | |
66 | #define HOST2BE16(x) SWAP16(x) | |
67 | #define LE2HOST16(x) (x) | |
68 | #define BE2HOST16(x) SWAP16(x) | |
69 | ||
70 | #endif | |
71 | ||
0a371c2c | 72 | #define GETLEs16(X) ((int16_t)GETLE16((uint16_t *)(X))) |
b094071f | 73 | |
0a371c2c | 74 | #define GETLE16(X) LE2HOST16(*(uint16_t *)(X)) |
75 | #define GETLE32_(X) LE2HOST32(*(uint32_t *)(X)) | |
76 | #define PUTLE16(X, Y) do{*((uint16_t *)(X))=HOST2LE16((uint16_t)(Y));}while(0) | |
77 | #define PUTLE32_(X, Y) do{*((uint32_t *)(X))=HOST2LE32((uint32_t)(Y));}while(0) | |
78 | #if defined(__arm__) && !defined(HAVE_ARMV6) | |
79 | // for (very) old ARMs with no unaligned loads? | |
80 | #define GETLE32(X) (*(uint16_t *)(X)|((uint32_t)((uint16_t *)(X))[1]<<16)) | |
b094071f | 81 | #define PUTLE32(X, Y) do{uint16_t *p_=(uint16_t *)(X);uint32_t y_=Y;p_[0]=y_;p_[1]=y_>>16;}while(0) |
82 | #else | |
83 | #define GETLE32 GETLE32_ | |
84 | #define PUTLE32 PUTLE32_ | |
85 | #endif | |
86 | ||
87 | ///////////////////////////////////////////////////////////////////////////// | |
88 | ||
89 | typedef struct VRAMLOADTTAG | |
90 | { | |
91 | short x; | |
92 | short y; | |
93 | short Width; | |
94 | short Height; | |
95 | short RowsRemaining; | |
96 | short ColsRemaining; | |
97 | unsigned short *ImagePtr; | |
98 | } VRAMLoad_t; | |
99 | ||
100 | ///////////////////////////////////////////////////////////////////////////// | |
101 | ||
102 | typedef struct PSXPOINTTAG | |
103 | { | |
104 | int32_t x; | |
105 | int32_t y; | |
106 | } PSXPoint_t; | |
107 | ||
108 | typedef struct PSXSPOINTTAG | |
109 | { | |
110 | short x; | |
111 | short y; | |
112 | } PSXSPoint_t; | |
113 | ||
114 | typedef struct PSXRECTTAG | |
115 | { | |
116 | short x0; | |
117 | short x1; | |
118 | short y0; | |
119 | short y1; | |
120 | } PSXRect_t; | |
121 | ||
122 | // linux defines for some windows stuff | |
123 | ||
124 | #define FALSE 0 | |
125 | #define TRUE 1 | |
126 | #define BOOL unsigned short | |
127 | #define LOWORD(l) ((unsigned short)(l)) | |
128 | #define HIWORD(l) ((unsigned short)(((uint32_t)(l) >> 16) & 0xFFFF)) | |
129 | #define max(a,b) (((a) > (b)) ? (a) : (b)) | |
130 | #define min(a,b) (((a) < (b)) ? (a) : (b)) | |
131 | #define DWORD uint32_t | |
132 | #ifndef __int64 | |
133 | #define __int64 long long int | |
134 | #endif | |
135 | ||
136 | typedef struct RECTTAG | |
137 | { | |
138 | int left; | |
139 | int top; | |
140 | int right; | |
141 | int bottom; | |
142 | }RECT; | |
143 | ||
144 | ///////////////////////////////////////////////////////////////////////////// | |
145 | ||
146 | typedef struct TWINTAG | |
147 | { | |
148 | PSXRect_t Position; | |
149 | int xmask, ymask; | |
150 | } TWin_t; | |
151 | ||
152 | ///////////////////////////////////////////////////////////////////////////// | |
153 | ||
154 | typedef struct PSXDISPLAYTAG | |
155 | { | |
156 | PSXPoint_t DisplayModeNew; | |
157 | PSXPoint_t DisplayMode; | |
158 | PSXPoint_t DisplayPosition; | |
159 | PSXPoint_t DisplayEnd; | |
160 | ||
161 | int32_t Double; | |
162 | int32_t Height; | |
163 | int32_t PAL; | |
164 | int32_t InterlacedNew; | |
165 | int32_t Interlaced; | |
166 | int32_t RGB24New; | |
167 | int32_t RGB24; | |
168 | PSXSPoint_t DrawOffset; | |
169 | int32_t Disabled; | |
170 | PSXRect_t Range; | |
171 | ||
172 | } PSXDisplay_t; | |
173 | ||
174 | ///////////////////////////////////////////////////////////////////////////// | |
175 | ||
176 | // draw.c | |
177 | ||
178 | extern int32_t GlobalTextAddrX,GlobalTextAddrY,GlobalTextTP; | |
179 | extern int32_t GlobalTextABR,GlobalTextPAGE; | |
180 | extern short ly0,lx0,ly1,lx1,ly2,lx2,ly3,lx3; | |
181 | extern long lLowerpart; | |
182 | extern BOOL bCheckMask; | |
183 | extern unsigned short sSetMask; | |
184 | extern unsigned long lSetMask; | |
185 | extern short g_m1; | |
186 | extern short g_m2; | |
187 | extern short g_m3; | |
188 | extern short DrawSemiTrans; | |
189 | ||
190 | // prim.c | |
191 | ||
192 | extern BOOL bUsingTWin; | |
193 | extern TWin_t TWin; | |
194 | extern void (*primTableJ[256])(unsigned char *); | |
195 | extern void (*primTableSkip[256])(unsigned char *); | |
196 | extern unsigned short usMirror; | |
197 | extern int iDither; | |
198 | extern uint32_t dwCfgFixes; | |
199 | extern uint32_t dwActFixes; | |
200 | extern int iUseFixes; | |
201 | extern int iUseDither; | |
202 | extern BOOL bDoVSyncUpdate; | |
203 | extern int32_t drawX; | |
204 | extern int32_t drawY; | |
205 | extern int32_t drawW; | |
206 | extern int32_t drawH; | |
207 | ||
208 | // gpu.h | |
209 | ||
210 | #define OPAQUEON 10 | |
211 | #define OPAQUEOFF 11 | |
212 | ||
213 | #define KEY_RESETTEXSTORE 1 | |
214 | #define KEY_SHOWFPS 2 | |
215 | #define KEY_RESETOPAQUE 4 | |
216 | #define KEY_RESETDITHER 8 | |
217 | #define KEY_RESETFILTER 16 | |
218 | #define KEY_RESETADVBLEND 32 | |
219 | #define KEY_BADTEXTURES 128 | |
220 | #define KEY_CHECKTHISOUT 256 | |
221 | ||
04bd10b1 | 222 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
b094071f | 223 | #define RED(x) (x & 0xff) |
224 | #define BLUE(x) ((x>>16) & 0xff) | |
225 | #define GREEN(x) ((x>>8) & 0xff) | |
226 | #define COLOR(x) (x & 0xffffff) | |
04bd10b1 | 227 | #else |
b094071f | 228 | #define RED(x) ((x>>24) & 0xff) |
229 | #define BLUE(x) ((x>>8) & 0xff) | |
230 | #define GREEN(x) ((x>>16) & 0xff) | |
231 | #define COLOR(x) SWAP32(x & 0xffffff) | |
232 | #endif | |
233 | ||
234 | PSXDisplay_t PSXDisplay; | |
235 | unsigned char *psxVub; | |
b094071f | 236 | unsigned short *psxVuw; |
237 | unsigned short *psxVuw_eom; | |
b094071f | 238 | |
239 | long lGPUstatusRet; | |
240 | uint32_t lGPUInfoVals[16]; | |
241 | ||
242 | VRAMLoad_t VRAMWrite; | |
243 | VRAMLoad_t VRAMRead; | |
244 | ||
245 | DATAREGISTERMODES DataWriteMode; | |
246 | DATAREGISTERMODES DataReadMode; | |
247 | ||
248 | BOOL bCheckMask = FALSE; | |
249 | unsigned short sSetMask = 0; | |
250 | unsigned long lSetMask = 0; | |
251 | long lLowerpart; | |
252 | ||
857275a9 | 253 | #if defined(__GNUC__) && __GNUC__ >= 6 |
254 | #pragma GCC diagnostic ignored "-Wmisleading-indentation" | |
255 | #endif | |
256 | ||
62d7fa95 | 257 | #include "soft.c" |
258 | #include "prim.c" | |
b094071f | 259 | |
260 | ///////////////////////////////////////////////////////////////////////////// | |
261 | ||
9ee0fd5b | 262 | static void set_vram(void *vram) |
b094071f | 263 | { |
9ee0fd5b | 264 | psxVub=vram; |
b094071f | 265 | psxVuw=(unsigned short *)psxVub; |
b094071f | 266 | psxVuw_eom=psxVuw+1024*512; // pre-calc of end of vram |
9ee0fd5b | 267 | } |
268 | ||
269 | int renderer_init(void) | |
270 | { | |
271 | set_vram(gpu.vram); | |
b094071f | 272 | |
273 | PSXDisplay.RGB24 = FALSE; // init some stuff | |
274 | PSXDisplay.Interlaced = FALSE; | |
275 | PSXDisplay.DrawOffset.x = 0; | |
276 | PSXDisplay.DrawOffset.y = 0; | |
277 | PSXDisplay.DisplayMode.x= 320; | |
278 | PSXDisplay.DisplayMode.y= 240; | |
279 | PSXDisplay.Disabled = FALSE; | |
280 | PSXDisplay.Range.x0=0; | |
281 | PSXDisplay.Range.x1=0; | |
282 | PSXDisplay.Double = 1; | |
283 | ||
284 | DataWriteMode = DR_NORMAL; | |
285 | lGPUstatusRet = 0x14802000; | |
286 | ||
287 | return 0; | |
288 | } | |
289 | ||
e929dec5 | 290 | void renderer_finish(void) |
291 | { | |
292 | } | |
293 | ||
294 | void renderer_notify_res_change(void) | |
295 | { | |
296 | } | |
297 | ||
b094071f | 298 | extern const unsigned char cmd_lengths[256]; |
299 | ||
b243416b | 300 | int do_cmd_list(unsigned int *list, int list_len, int *last_cmd) |
b094071f | 301 | { |
b243416b | 302 | unsigned int cmd = 0, len; |
303 | unsigned int *list_start = list; | |
b094071f | 304 | unsigned int *list_end = list + list_len; |
305 | ||
306 | for (; list < list_end; list += 1 + len) | |
307 | { | |
ae097dfb | 308 | cmd = GETLE32(list) >> 24; |
b094071f | 309 | len = cmd_lengths[cmd]; |
b243416b | 310 | if (list + 1 + len > list_end) { |
311 | cmd = -1; | |
312 | break; | |
313 | } | |
314 | ||
315 | #ifndef TEST | |
316 | if (cmd == 0xa0 || cmd == 0xc0) | |
317 | break; // image i/o, forward to upper layer | |
318 | else if ((cmd & 0xf8) == 0xe0) | |
ae097dfb | 319 | gpu.ex_regs[cmd & 7] = GETLE32(list); |
b243416b | 320 | #endif |
b094071f | 321 | |
322 | primTableJ[cmd]((void *)list); | |
323 | ||
324 | switch(cmd) | |
325 | { | |
326 | case 0x48 ... 0x4F: | |
327 | { | |
b243416b | 328 | u32 num_vertexes = 2; |
329 | u32 *list_position = &(list[3]); | |
b094071f | 330 | |
331 | while(1) | |
332 | { | |
804789d7 | 333 | if(list_position >= list_end) { |
334 | cmd = -1; | |
335 | goto breakloop; | |
336 | } | |
337 | ||
ae097dfb | 338 | if((*list_position & HOST2LE32(0xf000f000)) == HOST2LE32(0x50005000)) |
b094071f | 339 | break; |
340 | ||
341 | list_position++; | |
342 | num_vertexes++; | |
343 | } | |
344 | ||
b243416b | 345 | len += (num_vertexes - 2); |
b094071f | 346 | break; |
347 | } | |
348 | ||
349 | case 0x58 ... 0x5F: | |
350 | { | |
b243416b | 351 | u32 num_vertexes = 2; |
352 | u32 *list_position = &(list[4]); | |
b094071f | 353 | |
354 | while(1) | |
355 | { | |
804789d7 | 356 | if(list_position >= list_end) { |
357 | cmd = -1; | |
358 | goto breakloop; | |
359 | } | |
360 | ||
ae097dfb | 361 | if((*list_position & HOST2LE32(0xf000f000)) == HOST2LE32(0x50005000)) |
b094071f | 362 | break; |
363 | ||
364 | list_position += 2; | |
365 | num_vertexes++; | |
366 | } | |
367 | ||
b243416b | 368 | len += (num_vertexes - 2) * 2; |
b094071f | 369 | break; |
370 | } | |
371 | ||
9a6e7816 | 372 | #ifdef TEST |
b094071f | 373 | case 0xA0: // sys -> vid |
374 | { | |
9a6e7816 | 375 | short *slist = (void *)list; |
ae097dfb PC |
376 | u32 load_width = LE2HOST32(slist[4]); |
377 | u32 load_height = LE2HOST32(slist[5]); | |
b094071f | 378 | u32 load_size = load_width * load_height; |
379 | ||
380 | len += load_size / 2; | |
381 | break; | |
382 | } | |
9a6e7816 | 383 | #endif |
b094071f | 384 | } |
385 | } | |
b243416b | 386 | |
804789d7 | 387 | breakloop: |
b243416b | 388 | gpu.ex_regs[1] &= ~0x1ff; |
389 | gpu.ex_regs[1] |= lGPUstatusRet & 0x1ff; | |
390 | ||
391 | *last_cmd = cmd; | |
392 | return list - list_start; | |
b094071f | 393 | } |
394 | ||
4ad17db3 | 395 | void renderer_sync_ecmds(uint32_t *ecmds_) |
5b745e5b | 396 | { |
4ad17db3 | 397 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
398 | // the funcs below expect LE | |
399 | uint32_t i, ecmds[8]; | |
400 | for (i = 1; i <= 6; i++) | |
401 | ecmds[i] = HTOLE32(ecmds_[i]); | |
402 | #else | |
403 | uint32_t *ecmds = ecmds_; | |
404 | #endif | |
5b745e5b | 405 | cmdTexturePage((unsigned char *)&ecmds[1]); |
406 | cmdTextureWindow((unsigned char *)&ecmds[2]); | |
407 | cmdDrawAreaStart((unsigned char *)&ecmds[3]); | |
408 | cmdDrawAreaEnd((unsigned char *)&ecmds[4]); | |
409 | cmdDrawOffset((unsigned char *)&ecmds[5]); | |
410 | cmdSTP((unsigned char *)&ecmds[6]); | |
411 | } | |
412 | ||
05740673 | 413 | void renderer_update_caches(int x, int y, int w, int h) |
b094071f | 414 | { |
415 | } | |
416 | ||
417 | void renderer_flush_queues(void) | |
418 | { | |
419 | } | |
914455e6 | 420 | |
5440b88e | 421 | void renderer_set_interlace(int enable, int is_odd) |
422 | { | |
423 | } | |
424 | ||
914455e6 | 425 | #include "../../frontend/plugin_lib.h" |
426 | ||
427 | void renderer_set_config(const struct rearmed_cbs *cbs) | |
428 | { | |
429 | iUseDither = cbs->gpu_peops.iUseDither; | |
430 | dwActFixes = cbs->gpu_peops.dwActFixes; | |
fa56d360 | 431 | if (cbs->pl_set_gpu_caps) |
432 | cbs->pl_set_gpu_caps(0); | |
9ee0fd5b | 433 | set_vram(gpu.vram); |
914455e6 | 434 | } |