5 * - column scroll (reg 0 bit7)
11 static void (*FinalizeLineM4)(void);
12 static int skip_next_line;
13 static int screen_offset;
15 #define PLANAR_PIXEL(x,p) \
16 t = pack & (0x80808080 >> p); \
18 t = ((t >> (7-p)) | (t >> (14-p)) | (t >> (21-p)) | (t >> (28-p))) & 0x0f; \
22 static int TileNormM4(int sx, int addr, int pal)
24 unsigned char *pd = HighCol + sx;
27 pack = *(unsigned int *)(Pico.vram + addr); /* Get 4 bitplanes / 8 pixels */
41 return 1; /* Tile blank */
44 static int TileFlipM4(int sx,int addr,int pal)
46 unsigned char *pd = HighCol + sx;
49 pack = *(unsigned int *)(Pico.vram + addr); /* Get 4 bitplanes / 8 pixels */
63 return 1; /* Tile blank */
66 static void draw_sprites(int scanline)
68 struct PicoVideo *pv = &Pico.video;
69 unsigned int sprites_addr[8];
70 unsigned int sprites_x[8];
72 int xoff = 8; // relative to HighCol, which is (screen - 8)
73 int sprite_base, addr_mask;
79 sat = (unsigned char *)Pico.vram + ((pv->reg[5] & 0x7e) << 7);
81 addr_mask = 0xfe; h = 16;
83 addr_mask = 0xff; h = 8;
85 sprite_base = (pv->reg[6] & 4) << (13-2-1);
87 for (i = s = 0; i < 64 && s < 8; i++)
93 if (y + h <= scanline || scanline < y)
94 continue; // not on this line
96 sprites_x[s] = xoff + sat[0x80 + i*2];
97 sprites_addr[s] = sprite_base + ((sat[0x80 + i*2 + 1] & addr_mask) << (5-1)) +
98 ((scanline - y) << (2-1));
102 // now draw all sprites backwards
103 for (--s; s >= 0; s--)
104 TileNormM4(sprites_x[s], sprites_addr[s], 0x10);
107 // tilex_ty_prio merged to reduce register pressure
108 static void draw_strip(const unsigned short *nametab, int dx, int cells, int tilex_ty_prio)
110 int oldcode = -1, blank = -1; // The tile we know is blank
111 int addr = 0, pal = 0;
113 // Draw tiles across screen:
114 for (; cells > 0; dx += 8, tilex_ty_prio++, cells--)
118 code = nametab[tilex_ty_prio & 0x1f];
121 if ((code ^ tilex_ty_prio) & 0x1000) // priority differs?
124 if (code != oldcode) {
126 // Get tile address/2:
127 addr = (code & 0x1ff) << 4;
128 addr += tilex_ty_prio >> 16;
130 addr ^= 0xe; // Y-flip
132 pal = (code>>7) & 0x10;
135 if (code&0x0200) zero = TileFlipM4(dx, addr, pal);
136 else zero = TileNormM4(dx, addr, pal);
139 blank = code; // We know this tile is blank now
143 static void DrawDisplayM4(int scanline)
145 struct PicoVideo *pv = &Pico.video;
146 unsigned short *nametab;
147 int line, tilex, dx, ty, cells;
148 int cellskip = 0; // XXX
151 // Find the line in the name table
152 line = pv->reg[9] + scanline; // vscroll + scanline
158 nametab += (pv->reg[2] & 0x0e) << (10-1);
159 nametab += (line>>3) << (6-1);
161 dx = pv->reg[8]; // hscroll
162 if (scanline < 16 && (pv->reg[0] & 0x40))
163 dx = 0; // hscroll disabled for top 2 rows
165 tilex = ((-dx >> 3) + cellskip) & 0x1f;
166 ty = (line & 7) << 1; // Y-Offset into tile
167 cells = maxcells - cellskip;
169 dx = ((dx - 1) & 7) + 1;
171 cells++; // have hscroll, need to draw 1 cell more
174 // low priority tiles
175 if (PicoDrawMask & PDRAW_LAYERB_ON)
176 draw_strip(nametab, dx, cells, tilex | 0x0000 | (ty << 16));
179 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON)
180 draw_sprites(scanline);
182 // high priority tiles (use virtual layer switch just for fun)
183 if (PicoDrawMask & PDRAW_LAYERA_ON)
184 draw_strip(nametab, dx, cells, tilex | 0x1000 | (ty << 16));
186 if (pv->reg[0] & 0x20)
187 // first column masked
188 ((int *)HighCol)[2] = ((int *)HighCol)[3] = 0xe0e0e0e0;
191 void PicoFrameStartMode4(void)
195 rendstatus = PDRAW_192LINES;
196 if ((Pico.video.reg[0] & 6) == 6 && (Pico.video.reg[1] & 0x18)) {
197 rendstatus &= ~PDRAW_192LINES;
198 if (Pico.video.reg[1] & 0x08) {
200 rendstatus |= PDRAW_240LINES;
202 else // it's 224 lines
207 void PicoLineMode4(int line)
209 if (skip_next_line > 0) {
214 if (PicoScanBegin != NULL)
215 skip_next_line = PicoScanBegin(line + screen_offset);
218 BackFill(Pico.video.reg[7] & 0x0f, 0);
219 if (Pico.video.reg[1] & 0x40)
222 if (FinalizeLineM4 != NULL)
225 if (PicoScanEnd != NULL)
226 skip_next_line = PicoScanEnd(line + screen_offset);
229 void PicoDoHighPal555M4(void)
231 unsigned int *spal=(void *)Pico.cram;
232 unsigned int *dpal=(void *)HighPal;
238 /* cram is always stored as shorts, even though real hardware probably uses bytes */
239 for (i = 0x20/2; i > 0; i--, spal++, dpal++) {
242 t = ((t & 0x00030003)<< 3) | ((t & 0x000c000c)<<7) | ((t & 0x00300030)<<10);
244 t = ((t & 0x00030003)<<14) | ((t & 0x000c000c)<<7) | ((t & 0x00300030)>>1);
247 t |= (t >> 4) & 0x08610861;
252 static void FinalizeLineRGB555M4(void)
254 unsigned short *pd=DrawLineDest;
255 unsigned char *ps=HighCol+8;
256 unsigned short *pal=HighPal;
260 PicoDoHighPal555M4();
262 if (!(PicoOpt & POPT_DIS_32C_BORDER))
265 for (i = 256/4; i > 0; i--) {
273 static void FinalizeLine8bitM4(void)
275 memcpy32(DrawLineDest, (int *)(HighCol+8), 256/4);
278 void PicoDrawSetColorFormatMode4(int which)
282 case 2: FinalizeLineM4 = FinalizeLine8bitM4; break;
283 case 1: FinalizeLineM4 = FinalizeLineRGB555M4; break;
284 default:FinalizeLineM4 = NULL; break;