2 * (C) GraÅžvydas "notaz" Ignotas, 2011
4 * This work is licensed under the terms of any of these licenses
6 * - GNU GPL, version 2 or later.
7 * - GNU LGPL, version 2.1 or later.
8 * See the COPYING file in the top-level directory.
14 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
17 uint16_t vram[1024 * 512];
18 uint16_t guard[1024 * 512]; // overdraw guard
23 uint32_t tx:4; // 0 texture page
26 uint32_t tp:2; // 7 t.p. mode (4,8,15bpp)
27 uint32_t dtd:1; // 9 dither
29 uint32_t md:1; // 11 set mask bit when drawing
30 uint32_t me:1; // 12 no draw on mask
32 uint32_t width1:1;// 16
35 uint32_t video:1; // 20 NTSC,PAL
37 uint32_t inter:1; // 22 interlace on
38 uint32_t den:1; // 23 display not enabled
40 uint32_t busy:1; // 26 !busy drawing
41 uint32_t img:1; // 27 ready to DMA
42 uint32_t com:1; // 28 ready for commands
43 uint32_t dma:2; // 29 off, ?, to vram, from vram
44 uint32_t lcf:1; // 21 odd frame/blanking?
59 long GPUshutdown(void)
64 uint32_t GPUreadStatus(void)
66 return gpu.status.reg | (gpu.blanking << 31);
69 void GPUwriteStatus(uint32_t data)
71 static const short hres[8] = { 256, 368, 320, 384, 512, 512, 640, 640 };
72 static const short vres[4] = { 240, 480, 256, 480 };
73 uint32_t cmd = data >> 24;
79 gpu.status.den = data & 1;
82 gpu.status.dma = data & 3;
85 gpu.screen.x = data & 0x3ff;
86 gpu.screen.y = (data >> 10) & 0x3ff;
89 gpu.screen.y1 = data & 0x3ff;
90 gpu.screen.y2 = (data >> 10) & 0x3ff;
93 gpu.status.reg = (gpu.status.reg & ~0x7f0000) | ((data & 0x3F) << 17) | ((data & 0x40) << 10);
94 gpu.screen.w = hres[(gpu.status.reg >> 16) & 7];
95 gpu.screen.h = vres[(gpu.status.reg >> 19) & 3];
99 if (cmd < ARRAY_SIZE(gpu.regs))
100 gpu.regs[cmd] = data;
103 void GPUreadDataMem(uint32_t *mem, int count)
107 uint32_t GPUreadData(void)
112 void GPUwriteDataMem(uint32_t *mem, int count)
116 void GPUwriteData(uint32_t gdata)
120 long GPUdmaChain(uint32_t *base, uint32_t addr)
125 typedef struct GPUFREEZETAG
127 uint32_t ulFreezeVersion; // should be always 1 for now (set by main emu)
128 uint32_t ulStatus; // current gpu status
129 uint32_t ulControl[256]; // latest control register values
130 unsigned char psxVRam[1024*1024*2]; // current VRam image (full 2 MB for ZN)
133 long GPUfreeze(uint32_t type, GPUFreeze_t *freeze)
137 memcpy(freeze->psxVRam, gpu.vram, sizeof(gpu.vram));
138 memcpy(freeze->ulControl, gpu.regs, sizeof(gpu.regs));
139 freeze->ulStatus = gpu.status.reg;
140 freeze->ulControl[255] = gpu.blanking; // abuse free space
143 memcpy(gpu.vram, freeze->psxVRam, sizeof(gpu.vram));
144 memcpy(gpu.regs, freeze->ulControl, sizeof(gpu.regs));
145 gpu.status.reg = freeze->ulStatus;
146 gpu.blanking = freeze->ulControl[255];
147 GPUwriteStatus((5 << 24) | gpu.regs[5]);
148 GPUwriteStatus((7 << 24) | gpu.regs[7]);
149 GPUwriteStatus((8 << 24) | gpu.regs[8]);
156 void GPUvBlank(int val)
158 gpu.blanking = !!val;
163 #include "../../frontend/plugin_lib.h"
164 #include "../../frontend/arm_utils.h"
166 static const struct rearmed_cbs *cbs;
167 static void *screen_buf;
169 static void blit(void)
171 static uint32_t old_status, old_h;
172 int x = gpu.screen.x & ~3; // alignment needed by blitter
173 int y = gpu.screen.y;
174 int w = gpu.screen.w;
179 srcs = &gpu.vram[y * 1024 + x];
181 h = gpu.screen.y2 - gpu.screen.y1;
186 if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || h != old_h) // width|rgb24 change?
188 old_status = gpu.status.reg;
190 screen_buf = cbs->pl_fbdev_set_mode(w, h, gpu.status.rgb24 ? 24 : 16);
194 if (gpu.status.rgb24)
197 for (; h-- > 0; dest += w * 3, srcs += 1024)
199 bgr888_to_rgb888(dest, srcs, w * 3);
202 for (; h-- > 0; dest += w * 2, srcs += 1024)
204 bgr888_to_rgb565(dest, srcs, w * 3);
210 for (; h-- > 0; dest += w * 2, srcs += 1024)
212 bgr555_to_rgb565(dest, srcs, w * 2);
216 screen_buf = cbs->pl_fbdev_flip();
219 void GPUupdateLace(void)
226 cbs->pl_fbdev_open();
227 screen_buf = cbs->pl_fbdev_flip();
233 cbs->pl_fbdev_close();
237 void GPUrearmedCallbacks(const struct rearmed_cbs *cbs_)
242 // vim:shiftwidth=2:expandtab