5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
12 * - column scroll (reg 0 bit7)
13 * - 224/240 line modes
18 static void (*FinalizeLineM4)(int line);
19 static int skip_next_line;
20 static int screen_offset;
22 #define PLANAR_PIXEL(x,p) \
23 t = pack & (0x80808080 >> p); \
25 t = ((t >> (7-p)) | (t >> (14-p)) | (t >> (21-p)) | (t >> (28-p))) & 0x0f; \
29 static int TileNormM4(int sx, int addr, int pal)
31 unsigned char *pd = HighCol + sx;
34 pack = *(unsigned int *)(Pico.vram + addr); /* Get 4 bitplanes / 8 pixels */
48 return 1; /* Tile blank */
51 static int TileFlipM4(int sx,int addr,int pal)
53 unsigned char *pd = HighCol + sx;
56 pack = *(unsigned int *)(Pico.vram + addr); /* Get 4 bitplanes / 8 pixels */
70 return 1; /* Tile blank */
73 static void draw_sprites(int scanline)
75 struct PicoVideo *pv = &Pico.video;
76 unsigned int sprites_addr[8];
77 unsigned int sprites_x[8];
79 int xoff = 8; // relative to HighCol, which is (screen - 8)
80 int sprite_base, addr_mask;
86 sat = (unsigned char *)Pico.vram + ((pv->reg[5] & 0x7e) << 7);
88 addr_mask = 0xfe; h = 16;
90 addr_mask = 0xff; h = 8;
92 sprite_base = (pv->reg[6] & 4) << (13-2-1);
94 for (i = s = 0; i < 64 && s < 8; i++)
100 if (y + h <= scanline || scanline < y)
101 continue; // not on this line
103 sprites_x[s] = xoff + sat[0x80 + i*2];
104 sprites_addr[s] = sprite_base + ((sat[0x80 + i*2 + 1] & addr_mask) << (5-1)) +
105 ((scanline - y) << (2-1));
109 // now draw all sprites backwards
110 for (--s; s >= 0; s--)
111 TileNormM4(sprites_x[s], sprites_addr[s], 0x10);
114 // tilex_ty_prio merged to reduce register pressure
115 static void draw_strip(const unsigned short *nametab, int dx, int cells, int tilex_ty_prio)
117 int oldcode = -1, blank = -1; // The tile we know is blank
118 int addr = 0, pal = 0;
120 // Draw tiles across screen:
121 for (; cells > 0; dx += 8, tilex_ty_prio++, cells--)
125 code = nametab[tilex_ty_prio & 0x1f];
128 if ((code ^ tilex_ty_prio) & 0x1000) // priority differs?
131 if (code != oldcode) {
133 // Get tile address/2:
134 addr = (code & 0x1ff) << 4;
135 addr += tilex_ty_prio >> 16;
137 addr ^= 0xe; // Y-flip
139 pal = (code>>7) & 0x10;
142 if (code&0x0200) zero = TileFlipM4(dx, addr, pal);
143 else zero = TileNormM4(dx, addr, pal);
146 blank = code; // We know this tile is blank now
150 static void DrawDisplayM4(int scanline)
152 struct PicoVideo *pv = &Pico.video;
153 unsigned short *nametab;
154 int line, tilex, dx, ty, cells;
155 int cellskip = 0; // XXX
158 // Find the line in the name table
159 line = pv->reg[9] + scanline; // vscroll + scanline
165 nametab += (pv->reg[2] & 0x0e) << (10-1);
166 nametab += (line>>3) << (6-1);
168 dx = pv->reg[8]; // hscroll
169 if (scanline < 16 && (pv->reg[0] & 0x40))
170 dx = 0; // hscroll disabled for top 2 rows
172 tilex = ((-dx >> 3) + cellskip) & 0x1f;
173 ty = (line & 7) << 1; // Y-Offset into tile
174 cells = maxcells - cellskip;
176 dx = ((dx - 1) & 7) + 1;
178 cells++; // have hscroll, need to draw 1 cell more
181 // low priority tiles
182 if (PicoDrawMask & PDRAW_LAYERB_ON)
183 draw_strip(nametab, dx, cells, tilex | 0x0000 | (ty << 16));
186 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON)
187 draw_sprites(scanline);
189 // high priority tiles (use virtual layer switch just for fun)
190 if (PicoDrawMask & PDRAW_LAYERA_ON)
191 draw_strip(nametab, dx, cells, tilex | 0x1000 | (ty << 16));
193 if (pv->reg[0] & 0x20)
194 // first column masked
195 ((int *)HighCol)[2] = ((int *)HighCol)[3] = 0xe0e0e0e0;
198 void PicoFrameStartMode4(void)
203 rendstatus = PDRAW_32_COLS;
205 if ((Pico.video.reg[0] & 6) == 6 && (Pico.video.reg[1] & 0x18)) {
206 if (Pico.video.reg[1] & 0x08) {
216 if (rendstatus != rendstatus_old || lines != rendlines) {
217 emu_video_mode_change(screen_offset, lines, 1);
218 rendstatus_old = rendstatus;
222 DrawLineDest = (char *)DrawLineDestBase + screen_offset * DrawLineDestIncrement;
225 void PicoLineMode4(int line)
227 if (skip_next_line > 0) {
232 if (PicoScanBegin != NULL)
233 skip_next_line = PicoScanBegin(line + screen_offset);
236 BackFill(Pico.video.reg[7] & 0x0f, 0);
237 if (Pico.video.reg[1] & 0x40)
240 if (FinalizeLineM4 != NULL)
241 FinalizeLineM4(line);
243 if (PicoScanEnd != NULL)
244 skip_next_line = PicoScanEnd(line + screen_offset);
246 DrawLineDest = (char *)DrawLineDest + DrawLineDestIncrement;
249 void PicoDoHighPal555M4(void)
251 unsigned int *spal=(void *)Pico.cram;
252 unsigned int *dpal=(void *)HighPal;
258 /* cram is always stored as shorts, even though real hardware probably uses bytes */
259 for (i = 0x20/2; i > 0; i--, spal++, dpal++) {
262 t = ((t & 0x00030003)<< 3) | ((t & 0x000c000c)<<7) | ((t & 0x00300030)<<10);
264 t = ((t & 0x00030003)<<14) | ((t & 0x000c000c)<<7) | ((t & 0x00300030)>>1);
267 t |= (t >> 4) & 0x08610861;
273 static void FinalizeLineRGB555M4(int line)
276 PicoDoHighPal555M4();
278 // standard FinalizeLine can finish it for us,
279 // with features like scaling and such
280 FinalizeLine555(0, line);
283 static void FinalizeLine8bitM4(int line)
285 unsigned char *pd = DrawLineDest;
287 if (!(PicoOpt & POPT_DIS_32C_BORDER))
290 memcpy32((int *)pd, (int *)(HighCol+8), 256/4);
293 void PicoDrawSetOutputMode4(pdso_t which)
297 case PDF_8BIT: FinalizeLineM4 = FinalizeLine8bitM4; break;
298 case PDF_RGB555: FinalizeLineM4 = FinalizeLineRGB555M4; break;
299 default: FinalizeLineM4 = NULL; break;