5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
8 #include "../pico_int.h"
10 int (*PicoScan32xBegin)(unsigned int num);
11 int (*PicoScan32xEnd)(unsigned int num);
14 static void convert_pal555(int invert_prio)
16 unsigned int *ps = (void *)Pico32xMem->pal;
17 unsigned int *pd = (void *)Pico32xMem->pal_native;
18 unsigned int m1 = 0x001f001f;
19 unsigned int m2 = 0x03e003e0;
20 unsigned int m3 = 0xfc00fc00;
27 // place prio to LS green bit
28 for (i = 0x100/2; i > 0; i--, ps++, pd++) {
30 *pd = (((t & m1) << 11) | ((t & m2) << 1) | ((t & m3) >> 10)) ^ inv;
33 Pico32x.dirty_pal = 0;
37 #define do_line_dc(pd, p32x, pmd, inv, pmd_draw_code) \
39 const unsigned int m1 = 0x001f; \
40 const unsigned int m2 = 0x03e0; \
41 const unsigned int m3 = 0x7c00; \
44 for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \
45 unsigned short t = *p32x; \
46 if ((*pmd & 0x3f) != mdbg && !((t ^ inv) & 0x8000)) { \
51 *pd = ((t & m1) << 11) | ((t & m2) << 1) | ((t & m3) >> 10); \
56 #define do_line_pp(pd, p32x, pmd, pmd_draw_code) \
60 for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \
61 t = pal[*(unsigned char *)((long)p32x ^ 1)]; \
62 if ((t & 0x20) || (*pmd & 0x3f) == mdbg) \
70 #define do_line_rl(pd, p32x, pmd, pmd_draw_code) \
72 unsigned short len, t; \
74 for (i = 320; i > 0; p32x++) { \
75 t = pal[*p32x & 0xff]; \
76 for (len = (*p32x >> 8) + 1; len > 0 && i > 0; len--, i--, pd++, pmd++) { \
77 if ((*pmd & 0x3f) == mdbg || (t & 0x20)) \
85 // this is almost never used (Wiz and menu bg gen only)
86 void FinalizeLine32xRGB555(int sh, int line, struct PicoEState *est)
88 unsigned short *pd = est->DrawLineDest;
89 unsigned short *pal = Pico32xMem->pal_native;
90 unsigned char *pmd = est->HighCol + 8;
91 unsigned short *dram, *p32x;
94 FinalizeLine555(sh, line, est);
96 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 0 || // 32x blanking
97 // XXX: how is 32col mode hadled by real hardware?
98 !(Pico.video.reg[12] & 1) || // 32col mode
99 !(PicoDrawMask & PDRAW_32X_ON))
104 dram = (void *)Pico32xMem->dram[Pico32x.vdp_regs[0x0a/2] & P32XV_FS];
105 p32x = dram + dram[line];
106 mdbg = Pico.video.reg[7] & 0x3f;
108 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 2) { // Direct Color Mode
109 int inv_bit = (Pico32x.vdp_regs[0] & P32XV_PRI) ? 0x8000 : 0;
110 do_line_dc(pd, p32x, pmd, inv_bit,);
114 if (Pico32x.dirty_pal)
115 convert_pal555(Pico32x.vdp_regs[0] & P32XV_PRI);
117 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 1) { // Packed Pixel Mode
118 unsigned char *p32xb = (void *)p32x;
119 if (Pico32x.vdp_regs[2 / 2] & P32XV_SFT)
121 do_line_pp(pd, p32xb, pmd,);
123 else { // Run Length Mode
124 do_line_rl(pd, p32x, pmd,);
128 #define MD_LAYER_CODE \
131 #define PICOSCAN_PRE \
132 PicoScan32xBegin(l + (lines_sft_offs & 0xff)); \
133 dst = Pico.est.DrawLineDest; \
135 #define PICOSCAN_POST \
136 PicoScan32xEnd(l + (lines_sft_offs & 0xff)); \
138 #define make_do_loop(name, pre_code, post_code, md_code) \
139 /* Direct Color Mode */ \
140 static void do_loop_dc##name(unsigned short *dst, \
141 unsigned short *dram, int lines_sft_offs, int mdbg) \
143 int inv_bit = (Pico32x.vdp_regs[0] & P32XV_PRI) ? 0x8000 : 0; \
144 unsigned char *pmd = Pico.est.Draw2FB + \
145 328 * (lines_sft_offs & 0xff) + 8; \
146 unsigned short *palmd = Pico.est.HighPal; \
147 unsigned short *p32x; \
148 int lines = lines_sft_offs >> 16; \
151 for (l = 0; l < lines; l++, pmd += 8) { \
153 p32x = dram + dram[l]; \
154 do_line_dc(dst, p32x, pmd, inv_bit, md_code); \
159 /* Packed Pixel Mode */ \
160 static void do_loop_pp##name(unsigned short *dst, \
161 unsigned short *dram, int lines_sft_offs, int mdbg) \
163 unsigned short *pal = Pico32xMem->pal_native; \
164 unsigned char *pmd = Pico.est.Draw2FB + \
165 328 * (lines_sft_offs & 0xff) + 8; \
166 unsigned short *palmd = Pico.est.HighPal; \
167 unsigned char *p32x; \
168 int lines = lines_sft_offs >> 16; \
171 for (l = 0; l < lines; l++, pmd += 8) { \
173 p32x = (void *)(dram + dram[l]); \
174 p32x += (lines_sft_offs >> 8) & 1; \
175 do_line_pp(dst, p32x, pmd, md_code); \
180 /* Run Length Mode */ \
181 static void do_loop_rl##name(unsigned short *dst, \
182 unsigned short *dram, int lines_sft_offs, int mdbg) \
184 unsigned short *pal = Pico32xMem->pal_native; \
185 unsigned char *pmd = Pico.est.Draw2FB + \
186 328 * (lines_sft_offs & 0xff) + 8; \
187 unsigned short *palmd = Pico.est.HighPal; \
188 unsigned short *p32x; \
189 int lines = lines_sft_offs >> 16; \
192 for (l = 0; l < lines; l++, pmd += 8) { \
194 p32x = dram + dram[l]; \
195 do_line_rl(dst, p32x, pmd, md_code); \
202 #define make_do_loop(name, pre_code, post_code, md_code) \
203 extern void do_loop_dc##name(unsigned short *dst, \
204 unsigned short *dram, int lines_offs, int mdbg); \
205 extern void do_loop_pp##name(unsigned short *dst, \
206 unsigned short *dram, int lines_offs, int mdbg); \
207 extern void do_loop_rl##name(unsigned short *dst, \
208 unsigned short *dram, int lines_offs, int mdbg);
212 make_do_loop(_md, , , MD_LAYER_CODE)
213 make_do_loop(_scan, PICOSCAN_PRE, PICOSCAN_POST, )
214 make_do_loop(_scan_md, PICOSCAN_PRE, PICOSCAN_POST, MD_LAYER_CODE)
216 typedef void (*do_loop_func)(unsigned short *dst, unsigned short *dram, int lines, int mdbg);
217 enum { DO_LOOP, DO_LOOP_MD, DO_LOOP_SCAN, DO_LOOP_MD_SCAN };
219 static const do_loop_func do_loop_dc_f[] = { do_loop_dc, do_loop_dc_md, do_loop_dc_scan, do_loop_dc_scan_md };
220 static const do_loop_func do_loop_pp_f[] = { do_loop_pp, do_loop_pp_md, do_loop_pp_scan, do_loop_pp_scan_md };
221 static const do_loop_func do_loop_rl_f[] = { do_loop_rl, do_loop_rl_md, do_loop_rl_scan, do_loop_rl_scan_md };
223 void PicoDraw32xLayer(int offs, int lines, int md_bg)
225 int have_scan = PicoScan32xBegin != NULL && PicoScan32xEnd != NULL;
226 const do_loop_func *do_loop;
227 unsigned short *dram;
231 Pico.est.DrawLineDest = (char *)DrawLineDestBase + offs * DrawLineDestIncrement;
232 dram = Pico32xMem->dram[Pico32x.vdp_regs[0x0a/2] & P32XV_FS];
234 if (Pico32xDrawMode == PDM32X_BOTH) {
236 PicoDrawUpdateHighPal();
239 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 2)
242 do_loop = do_loop_dc_f;
246 if (Pico32x.dirty_pal)
247 convert_pal555(Pico32x.vdp_regs[0] & P32XV_PRI);
249 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 1)
252 do_loop = do_loop_pp_f;
257 do_loop = do_loop_rl_f;
261 if (Pico32xDrawMode == PDM32X_BOTH)
262 which_func = have_scan ? DO_LOOP_MD_SCAN : DO_LOOP_MD;
264 which_func = have_scan ? DO_LOOP_SCAN : DO_LOOP;
265 lines_sft_offs = (lines << 16) | offs;
266 if (Pico32x.vdp_regs[2 / 2] & P32XV_SFT)
267 lines_sft_offs |= 1 << 8;
269 do_loop[which_func](Pico.est.DrawLineDest, dram, lines_sft_offs, md_bg);
272 // mostly unused, games tend to keep 32X layer on
273 void PicoDraw32xLayerMdOnly(int offs, int lines)
275 int have_scan = PicoScan32xBegin != NULL && PicoScan32xEnd != NULL;
276 unsigned short *dst = (void *)((char *)DrawLineDestBase + offs * DrawLineDestIncrement);
277 unsigned char *pmd = Pico.est.Draw2FB + 328 * offs + 8;
278 unsigned short *pal = Pico.est.HighPal;
279 int poffs = 0, plen = 320;
282 if (!(Pico.video.reg[12] & 1)) {
289 PicoDrawUpdateHighPal();
292 for (l = 0; l < lines; l++) {
294 PicoScan32xBegin(l + offs);
295 dst = Pico.est.DrawLineDest + poffs;
297 for (p = 0; p < plen; p += 4) {
298 dst[p + 0] = pal[*pmd++];
299 dst[p + 1] = pal[*pmd++];
300 dst[p + 2] = pal[*pmd++];
301 dst[p + 3] = pal[*pmd++];
303 dst = (void *)((char *)dst + DrawLineDestIncrement);
306 PicoScan32xEnd(l + offs);
310 void PicoDrawSetOutFormat32x(pdso_t which, int use_32x_line_mode)
313 extern void *Pico32xNativePal;
314 Pico32xNativePal = Pico32xMem->pal_native;
317 if (which == PDF_RGB555 && use_32x_line_mode) {
318 // we'll draw via FinalizeLine32xRGB555 (rare)
319 PicoDrawSetInternalBuf(NULL, 0);
320 Pico32xDrawMode = PDM32X_OFF;
324 // use the same layout as alt renderer
325 PicoDrawSetInternalBuf(Pico.est.Draw2FB, 328);
326 Pico32xDrawMode = (which == PDF_RGB555) ? PDM32X_32X_ONLY : PDM32X_BOTH;
329 // vim:shiftwidth=2:ts=2:expandtab