1 #include "../pico_int.h"
3 int (*PicoScan32xBegin)(unsigned int num);
4 int (*PicoScan32xEnd)(unsigned int num);
7 static void convert_pal555(int invert_prio)
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;
20 // place prio to LS green bit
21 for (i = 0x100/2; i > 0; i--, ps++, pd++) {
23 *pd = (((t & m1) << 11) | ((t & m2) << 1) | ((t & m3) >> 10)) ^ inv;
26 Pico32x.dirty_pal = 0;
30 #define do_line_dc(pd, p32x, pmd, inv, pmd_draw_code) \
32 const unsigned int m1 = 0x001f; \
33 const unsigned int m2 = 0x03e0; \
34 const unsigned int m3 = 0x7c00; \
37 for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \
38 unsigned short t = *p32x; \
39 if (*pmd != mdbg && !((t ^ inv) & 0x8000)) { \
44 *pd = ((t & m1) << 11) | ((t & m2) << 1) | ((t & m3) >> 10); \
49 #define do_line_pp(pd, p32x, pmd, pmd_draw_code) \
53 for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \
54 t = pal[*(unsigned char *)((long)p32x ^ 1)]; \
55 if ((t & 0x20) || *pmd == mdbg) \
63 #define do_line_rl(pd, p32x, pmd, pmd_draw_code) \
65 unsigned short len, t; \
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)) \
78 void FinalizeLine32xRGB555(int sh, int line)
80 unsigned short *pd = DrawLineDest;
81 unsigned short *pal = Pico32xMem->pal_native;
82 unsigned char *pmd = HighCol + 8;
83 unsigned short *dram, *p32x;
86 FinalizeLine555(sh, line);
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))
96 dram = (void *)Pico32xMem->dram[Pico32x.vdp_regs[0x0a/2] & P32XV_FS];
97 p32x = dram + dram[line];
98 mdbg = Pico.video.reg[7] & 0x3f;
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,);
106 if (Pico32x.dirty_pal)
107 convert_pal555(Pico32x.vdp_regs[0] & P32XV_PRI);
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)
113 do_line_pp(pd, p32xb, pmd,);
115 else { // Run Length Mode
116 do_line_rl(pd, p32x, pmd,);
120 #define MD_LAYER_CODE \
123 #define PICOSCAN_PRE \
124 PicoScan32xBegin(l + (lines_sft_offs & 0xff)); \
125 dst = DrawLineDest; \
127 #define PICOSCAN_POST \
128 PicoScan32xEnd(l + (lines_sft_offs & 0xff)); \
130 #define make_do_loop(name, pre_code, post_code, md_code) \
131 /* Direct Color Mode */ \
132 static void do_loop_dc##name(unsigned short *dst, \
133 unsigned short *dram, int lines_sft_offs, int mdbg) \
135 int inv_bit = (Pico32x.vdp_regs[0] & P32XV_PRI) ? 0x8000 : 0; \
136 unsigned char *pmd = PicoDraw2FB + 328 * 8 + 8; \
137 unsigned short *palmd = HighPal; \
138 unsigned short *p32x; \
139 int lines = lines_sft_offs >> 16; \
142 for (l = 0; l < lines; l++, pmd += 8) { \
144 p32x = dram + dram[l]; \
145 do_line_dc(dst, p32x, pmd, inv_bit, md_code); \
150 /* Packed Pixel Mode */ \
151 static void do_loop_pp##name(unsigned short *dst, \
152 unsigned short *dram, int lines_sft_offs, int mdbg) \
154 unsigned short *pal = Pico32xMem->pal_native; \
155 unsigned char *pmd = PicoDraw2FB + 328 * 8 + 8; \
156 unsigned short *palmd = HighPal; \
157 unsigned char *p32x; \
158 int lines = lines_sft_offs >> 16; \
161 for (l = 0; l < lines; l++, pmd += 8) { \
163 p32x = (void *)(dram + dram[l]); \
164 p32x += (lines_sft_offs >> 8) & 1; \
165 do_line_pp(dst, p32x, pmd, md_code); \
170 /* Run Length Mode */ \
171 static void do_loop_rl##name(unsigned short *dst, \
172 unsigned short *dram, int lines_sft_offs, int mdbg) \
174 unsigned short *pal = Pico32xMem->pal_native; \
175 unsigned char *pmd = PicoDraw2FB + 328 * 8 + 8; \
176 unsigned short *palmd = HighPal; \
177 unsigned short *p32x; \
178 int lines = lines_sft_offs >> 16; \
181 for (l = 0; l < lines; l++, pmd += 8) { \
183 p32x = dram + dram[l]; \
184 do_line_rl(dst, p32x, pmd, md_code); \
191 #define make_do_loop(name, pre_code, post_code, md_code) \
192 extern void do_loop_dc##name(unsigned short *dst, \
193 unsigned short *dram, int lines_offs, int mdbg); \
194 extern void do_loop_pp##name(unsigned short *dst, \
195 unsigned short *dram, int lines_offs, int mdbg); \
196 extern void do_loop_rl##name(unsigned short *dst, \
197 unsigned short *dram, int lines_offs, int mdbg);
201 make_do_loop(_md, , , MD_LAYER_CODE)
202 make_do_loop(_scan, PICOSCAN_PRE, PICOSCAN_POST, )
203 make_do_loop(_scan_md, PICOSCAN_PRE, PICOSCAN_POST, MD_LAYER_CODE)
205 typedef void (*do_loop_func)(unsigned short *dst, unsigned short *dram, int lines, int mdbg);
206 enum { DO_LOOP, DO_LOOP_MD, DO_LOOP_SCAN, DO_LOOP_MD_SCAN };
208 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 };
209 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 };
210 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 };
212 void PicoDraw32xLayer(int offs, int lines, int md_bg)
214 int have_scan = PicoScan32xBegin != NULL && PicoScan32xEnd != NULL;
215 const do_loop_func *do_loop;
216 unsigned short *dram;
220 DrawLineDest = DrawLineDestBase + offs * DrawLineDestIncrement;
221 dram = Pico32xMem->dram[Pico32x.vdp_regs[0x0a/2] & P32XV_FS];
223 if (Pico32xDrawMode == 2) {
225 PicoDrawUpdateHighPal();
228 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 2)
231 do_loop = do_loop_dc_f;
235 if (Pico32x.dirty_pal)
236 convert_pal555(Pico32x.vdp_regs[0] & P32XV_PRI);
238 if ((Pico32x.vdp_regs[0] & P32XV_Mx) == 1)
241 do_loop = do_loop_pp_f;
246 do_loop = do_loop_rl_f;
250 if (Pico32xDrawMode == 2)
251 which_func = have_scan ? DO_LOOP_MD_SCAN : DO_LOOP_MD;
253 which_func = have_scan ? DO_LOOP_SCAN : DO_LOOP;
254 lines_sft_offs = (lines << 16) | offs;
255 if (Pico32x.vdp_regs[2 / 2] & P32XV_SFT)
256 lines_sft_offs |= 1 << 8;
258 do_loop[which_func](DrawLineDest, dram, lines_sft_offs, md_bg);
261 void PicoDraw32xSetFrameMode(int is_on, int only_32x)
264 extern void *Pico32xNativePal;
265 Pico32xNativePal = Pico32xMem->pal_native;
269 // use the same layout as alt renderer
270 PicoDrawSetInternalBuf(PicoDraw2FB + 328*8, 328);
271 Pico32xDrawMode = only_32x ? 1 : 2;
273 PicoDrawSetInternalBuf(NULL, 0);