remove unused/unmaintained code
[picodrive.git] / pico / 32x / draw.c
... / ...
CommitLineData
1#include "../pico_int.h"
2
3int (*PicoScan32xBegin)(unsigned int num);
4int (*PicoScan32xEnd)(unsigned int num);
5int Pico32xDrawMode;
6
7static void convert_pal555(int invert_prio)
8{
9 unsigned int *ps = (void *)Pico32xMem->pal;
10 unsigned int *pd = (void *)Pico32xMem->pal_native;
11 unsigned int m1 = 0x001f001f;
12 unsigned int m2 = 0x03e003e0;
13 unsigned int m3 = 0xfc00fc00;
14 unsigned int inv = 0;
15 int i;
16
17 if (invert_prio)
18 inv = 0x00200020;
19
20 // place prio to LS green bit
21 for (i = 0x100/2; i > 0; i--, ps++, pd++) {
22 unsigned int t = *ps;
23 *pd = (((t & m1) << 11) | ((t & m2) << 1) | ((t & m3) >> 10)) ^ inv;
24 }
25
26 Pico32x.dirty_pal = 0;
27}
28
29// direct color mode
30#define do_line_dc(pd, p32x, pmd, inv, pmd_draw_code) \
31{ \
32 const unsigned int m1 = 0x001f; \
33 const unsigned int m2 = 0x03e0; \
34 const unsigned int m3 = 0x7c00; \
35 int i; \
36 \
37 for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \
38 unsigned short t = *p32x; \
39 if (*pmd != mdbg && !((t ^ inv) & 0x8000)) { \
40 pmd_draw_code; \
41 continue; \
42 } \
43 \
44 *pd = ((t & m1) << 11) | ((t & m2) << 1) | ((t & m3) >> 10); \
45 } \
46}
47
48// packed pixel mode
49#define do_line_pp(pd, p32x, pmd, pmd_draw_code) \
50{ \
51 unsigned short t; \
52 int i; \
53 for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \
54 t = pal[*(unsigned char *)((long)p32x ^ 1)]; \
55 if ((t & 0x20) || *pmd == mdbg) \
56 *pd = t; \
57 else \
58 pmd_draw_code; \
59 } \
60}
61
62// run length mode
63#define do_line_rl(pd, p32x, pmd, pmd_draw_code) \
64{ \
65 unsigned short len, t; \
66 int i; \
67 for (i = 320; i > 0; p32x++) { \
68 t = pal[*p32x & 0xff]; \
69 for (len = (*p32x >> 8) + 1; len > 0 && i > 0; len--, i--, pd++, pmd++) { \
70 if (*pmd == mdbg || (t & 0x20)) \
71 *pd = t; \
72 else \
73 pmd_draw_code; \
74 } \
75 } \
76}
77
78void FinalizeLine32xRGB555(int sh, int line)
79{
80 unsigned short *pd = DrawLineDest;
81 unsigned short *pal = Pico32xMem->pal_native;
82 unsigned char *pmd = HighCol + 8;
83 unsigned short *dram, *p32x;
84 unsigned char mdbg;
85
86 FinalizeLine555(sh, line);
87
88 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 0 || // 32x blanking
89 // XXX: how is 32col mode hadled by real hardware?
90 !(Pico.video.reg[12] & 1) || // 32col mode
91 !(PicoDrawMask & PDRAW_32X_ON))
92 {
93 return;
94 }
95
96 dram = (void *)Pico32xMem->dram[Pico32x.vdp_regs[0x0a/2] & P32XV_FS];
97 p32x = dram + dram[line];
98 mdbg = Pico.video.reg[7] & 0x3f;
99
100 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 2) { // Direct Color Mode
101 int inv_bit = (Pico32x.vdp_regs[0] & P32XV_PRI) ? 0x8000 : 0;
102 do_line_dc(pd, p32x, pmd, inv_bit,);
103 return;
104 }
105
106 if (Pico32x.dirty_pal)
107 convert_pal555(Pico32x.vdp_regs[0] & P32XV_PRI);
108
109 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 1) { // Packed Pixel Mode
110 unsigned char *p32xb = (void *)p32x;
111 if (Pico32x.vdp_regs[2 / 2] & P32XV_SFT)
112 p32xb++;
113 do_line_pp(pd, p32xb, pmd,);
114 }
115 else { // Run Length Mode
116 do_line_rl(pd, p32x, pmd,);
117 }
118}
119
120#define MD_LAYER_CODE \
121 *dst = palmd[*pmd]
122
123#define PICOSCAN_PRE \
124 PicoScan32xBegin(l + (lines_sft_offs & 0xff)); \
125 dst = DrawLineDest; \
126
127#define PICOSCAN_POST \
128 PicoScan32xEnd(l + (lines_sft_offs & 0xff)); \
129
130#define make_do_loop(name, pre_code, post_code, md_code) \
131/* Direct Color Mode */ \
132static void do_loop_dc##name(unsigned short *dst, \
133 unsigned short *dram, int lines_sft_offs, int mdbg) \
134{ \
135 int inv_bit = (Pico32x.vdp_regs[0] & P32XV_PRI) ? 0x8000 : 0; \
136 unsigned char *pmd = PicoDraw2FB + \
137 328 * (lines_sft_offs & 0xff) + 8; \
138 unsigned short *palmd = HighPal; \
139 unsigned short *p32x; \
140 int lines = lines_sft_offs >> 16; \
141 int l; \
142 (void)palmd; \
143 for (l = 0; l < lines; l++, pmd += 8) { \
144 pre_code; \
145 p32x = dram + dram[l]; \
146 do_line_dc(dst, p32x, pmd, inv_bit, md_code); \
147 post_code; \
148 } \
149} \
150 \
151/* Packed Pixel Mode */ \
152static void do_loop_pp##name(unsigned short *dst, \
153 unsigned short *dram, int lines_sft_offs, int mdbg) \
154{ \
155 unsigned short *pal = Pico32xMem->pal_native; \
156 unsigned char *pmd = PicoDraw2FB + \
157 328 * (lines_sft_offs & 0xff) + 8; \
158 unsigned short *palmd = HighPal; \
159 unsigned char *p32x; \
160 int lines = lines_sft_offs >> 16; \
161 int l; \
162 (void)palmd; \
163 for (l = 0; l < lines; l++, pmd += 8) { \
164 pre_code; \
165 p32x = (void *)(dram + dram[l]); \
166 p32x += (lines_sft_offs >> 8) & 1; \
167 do_line_pp(dst, p32x, pmd, md_code); \
168 post_code; \
169 } \
170} \
171 \
172/* Run Length Mode */ \
173static void do_loop_rl##name(unsigned short *dst, \
174 unsigned short *dram, int lines_sft_offs, int mdbg) \
175{ \
176 unsigned short *pal = Pico32xMem->pal_native; \
177 unsigned char *pmd = PicoDraw2FB + \
178 328 * (lines_sft_offs & 0xff) + 8; \
179 unsigned short *palmd = HighPal; \
180 unsigned short *p32x; \
181 int lines = lines_sft_offs >> 16; \
182 int l; \
183 (void)palmd; \
184 for (l = 0; l < lines; l++, pmd += 8) { \
185 pre_code; \
186 p32x = dram + dram[l]; \
187 do_line_rl(dst, p32x, pmd, md_code); \
188 post_code; \
189 } \
190}
191
192#ifdef _ASM_32X_DRAW
193#undef make_do_loop
194#define make_do_loop(name, pre_code, post_code, md_code) \
195extern void do_loop_dc##name(unsigned short *dst, \
196 unsigned short *dram, int lines_offs, int mdbg); \
197extern void do_loop_pp##name(unsigned short *dst, \
198 unsigned short *dram, int lines_offs, int mdbg); \
199extern void do_loop_rl##name(unsigned short *dst, \
200 unsigned short *dram, int lines_offs, int mdbg);
201#endif
202
203make_do_loop(,,,)
204make_do_loop(_md, , , MD_LAYER_CODE)
205make_do_loop(_scan, PICOSCAN_PRE, PICOSCAN_POST, )
206make_do_loop(_scan_md, PICOSCAN_PRE, PICOSCAN_POST, MD_LAYER_CODE)
207
208typedef void (*do_loop_func)(unsigned short *dst, unsigned short *dram, int lines, int mdbg);
209enum { DO_LOOP, DO_LOOP_MD, DO_LOOP_SCAN, DO_LOOP_MD_SCAN };
210
211static const do_loop_func do_loop_dc_f[] = { do_loop_dc, do_loop_dc_md, do_loop_dc_scan, do_loop_dc_scan_md };
212static const do_loop_func do_loop_pp_f[] = { do_loop_pp, do_loop_pp_md, do_loop_pp_scan, do_loop_pp_scan_md };
213static const do_loop_func do_loop_rl_f[] = { do_loop_rl, do_loop_rl_md, do_loop_rl_scan, do_loop_rl_scan_md };
214
215void PicoDraw32xLayer(int offs, int lines, int md_bg)
216{
217 int have_scan = PicoScan32xBegin != NULL && PicoScan32xEnd != NULL;
218 const do_loop_func *do_loop;
219 unsigned short *dram;
220 int lines_sft_offs;
221 int which_func;
222
223 DrawLineDest = (char *)DrawLineDestBase + offs * DrawLineDestIncrement;
224 dram = Pico32xMem->dram[Pico32x.vdp_regs[0x0a/2] & P32XV_FS];
225
226 if (Pico32xDrawMode == PDM32X_BOTH) {
227 if (Pico.m.dirtyPal)
228 PicoDrawUpdateHighPal();
229 }
230
231 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 2)
232 {
233 // Direct Color Mode
234 do_loop = do_loop_dc_f;
235 goto do_it;
236 }
237
238 if (Pico32x.dirty_pal)
239 convert_pal555(Pico32x.vdp_regs[0] & P32XV_PRI);
240
241 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 1)
242 {
243 // Packed Pixel Mode
244 do_loop = do_loop_pp_f;
245 }
246 else
247 {
248 // Run Length Mode
249 do_loop = do_loop_rl_f;
250 }
251
252do_it:
253 if (Pico32xDrawMode == PDM32X_BOTH)
254 which_func = have_scan ? DO_LOOP_MD_SCAN : DO_LOOP_MD;
255 else
256 which_func = have_scan ? DO_LOOP_SCAN : DO_LOOP;
257 lines_sft_offs = (lines << 16) | offs;
258 if (Pico32x.vdp_regs[2 / 2] & P32XV_SFT)
259 lines_sft_offs |= 1 << 8;
260
261 do_loop[which_func](DrawLineDest, dram, lines_sft_offs, md_bg);
262}
263
264// mostly unused, games tend to keep 32X layer on
265void PicoDraw32xLayerMdOnly(int offs, int lines)
266{
267 int have_scan = PicoScan32xBegin != NULL && PicoScan32xEnd != NULL;
268 unsigned short *dst = (void *)((char *)DrawLineDestBase + offs * DrawLineDestIncrement);
269 unsigned char *pmd = PicoDraw2FB + 328 * offs + 8;
270 unsigned short *pal = HighPal;
271 int poffs = 0, plen = 320;
272 int l, p;
273
274 if (!(Pico.video.reg[12] & 1)) {
275 // 32col mode
276 poffs = 32;
277 plen = 256;
278 }
279
280 if (Pico.m.dirtyPal)
281 PicoDrawUpdateHighPal();
282
283 dst += poffs;
284 for (l = 0; l < lines; l++) {
285 if (have_scan) {
286 PicoScan32xBegin(l + offs);
287 dst = DrawLineDest + poffs;
288 }
289 for (p = 0; p < plen; p += 4) {
290 dst[p + 0] = pal[*pmd++];
291 dst[p + 1] = pal[*pmd++];
292 dst[p + 2] = pal[*pmd++];
293 dst[p + 3] = pal[*pmd++];
294 }
295 dst = (void *)((char *)dst + DrawLineDestIncrement);
296 pmd += 328 - plen;
297 if (have_scan)
298 PicoScan32xEnd(l + offs);
299 }
300}
301
302void PicoDraw32xSetFrameMode(int is_on, int only_32x)
303{
304#ifdef _ASM_32X_DRAW
305 extern void *Pico32xNativePal;
306 Pico32xNativePal = Pico32xMem->pal_native;
307#endif
308
309 if (is_on) {
310 // use the same layout as alt renderer
311 PicoDrawSetInternalBuf(PicoDraw2FB, 328);
312 Pico32xDrawMode = only_32x ? PDM32X_32X_ONLY : PDM32X_BOTH;
313 } else {
314 PicoDrawSetInternalBuf(NULL, 0);
315 Pico32xDrawMode = PDM32X_OFF;
316 }
317}
318