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 void TileNormM4(int sx, unsigned int pack, int pal)
31 unsigned char *pd = Pico.est.HighCol + sx;
44 static void TileFlipM4(int sx, unsigned int pack, int pal)
46 unsigned char *pd = Pico.est.HighCol + sx;
59 static void draw_sprites(int scanline)
61 struct PicoVideo *pv = &Pico.video;
62 unsigned int sprites_addr[8];
63 unsigned int sprites_x[8];
66 int xoff = 8; // relative to HighCol, which is (screen - 8)
67 int sprite_base, addr_mask;
73 sat = (unsigned char *)PicoMem.vram + ((pv->reg[5] & 0x7e) << 7);
75 addr_mask = 0xfe; h = 16;
77 addr_mask = 0xff; h = 8;
79 sprite_base = (pv->reg[6] & 4) << (13-2-1);
81 for (i = s = 0; i < 64; i++)
87 if (y + h <= scanline || scanline < y)
88 continue; // not on this line
90 pv->status |= SR_SOVR;
94 sprites_x[s] = xoff + sat[0x80 + i*2];
95 sprites_addr[s] = sprite_base + ((sat[0x80 + i*2 + 1] & addr_mask) << (5-1)) +
96 ((scanline - y) << (2-1));
100 // really half-assed but better than nothing
104 // now draw all sprites backwards
105 for (--s; s >= 0; s--) {
106 pack = *(unsigned int *)(PicoMem.vram + sprites_addr[s]);
107 TileNormM4(sprites_x[s], pack, 0x10);
111 // tilex_ty_prio merged to reduce register pressure
112 static void draw_strip(const unsigned short *nametab, int dx, int cells, int tilex_ty_prio)
114 int oldcode = -1, blank = -1; // The tile we know is blank
115 int addr = 0, pal = 0;
117 // Draw tiles across screen:
118 for (; cells > 0; dx += 8, tilex_ty_prio++, cells--)
123 code = nametab[tilex_ty_prio & 0x1f];
126 if ((code ^ tilex_ty_prio) & 0x1000) // priority differs?
129 if (code != oldcode) {
131 // Get tile address/2:
132 addr = (code & 0x1ff) << 4;
133 addr += tilex_ty_prio >> 16;
135 addr ^= 0xe; // Y-flip
137 pal = (code>>7) & 0x10;
140 pack = *(unsigned int *)(PicoMem.vram + addr); /* Get 4 bitplanes / 8 pixels */
145 if (code & 0x0200) TileFlipM4(dx, pack, pal);
146 else TileNormM4(dx, pack, pal);
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
164 nametab = PicoMem.vram;
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 (!(pv->debug_p & PVD_KILL_B))
183 draw_strip(nametab, dx, cells, tilex | 0x0000 | (ty << 16));
186 if (!(pv->debug_p & PVD_KILL_S_LO))
187 draw_sprites(scanline);
189 // high priority tiles (use virtual layer switch just for fun)
190 if (!(pv->debug_p & PVD_KILL_A))
191 draw_strip(nametab, dx, cells, tilex | 0x1000 | (ty << 16));
193 if (pv->reg[0] & 0x20)
194 // first column masked
195 ((int *)Pico.est.HighCol)[2] = ((int *)Pico.est.HighCol)[3] = 0xe0e0e0e0;
198 void PicoFrameStartMode4(void)
203 Pico.est.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 (Pico.est.rendstatus != rendstatus_old || lines != rendlines) {
217 emu_video_mode_change(screen_offset, lines, 1);
218 rendstatus_old = Pico.est.rendstatus;
222 Pico.est.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, &Pico.est);
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 Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement;
249 void PicoDoHighPal555M4(void)
251 unsigned int *spal=(void *)PicoMem.cram;
252 unsigned int *dpal=(void *)Pico.est.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;
270 Pico.est.HighPal[0xe0] = 0;
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, &Pico.est);
283 static void FinalizeLine8bitM4(int line)
285 unsigned char *pd = Pico.est.DrawLineDest;
287 if (!(PicoIn.opt & POPT_DIS_32C_BORDER))
290 memcpy(pd, Pico.est.HighCol + 8, 256);
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;
303 // vim:shiftwidth=2:ts=2:expandtab