8 u16int vdpstat = 0x3400;
9 int vdpx, vdpy, vdpyy, frame, intla;
11 static int xmax, xdisp;
12 static int sx, snx, col, pri, lum;
13 enum { DARK, NORM, BRIGHT };
14 enum { ymax = 262, yvbl = 234 };
19 if((reg[MODE4] & WIDE) != 0){
26 intla = (reg[MODE4] & 6) == 6;
30 pixeldraw(int x, int y, int v)
33 union { u32int l; u8int b[4]; } u;
35 p = (u32int *)pic + (x + y * 320) * scale;
55 case 2: *p++ = u.l; /* intla ignored */
61 shade(u32int v, int l)
66 return v << 1 & 0xefefef;
67 return v >> 1 & 0xf7f7f7;
95 default: a = (reg[PANT] & 0x38) << 9; break;
96 case 1: a = (reg[PBNT] & 7) << 12; break;
97 case 2: a = (reg[PWNT] & 0x3e) << 9; break;
104 if((p->t & 0x1000) != 0)
106 a = (p->t & 0x7ff) << 5 | y << 1;
108 if((p->t & 0x1000) != 0)
110 a = (p->t & 0x7ff) << 4 | y << 1;
112 p->c = vram[a] << 16 | vram[a+1];
118 static int szs[] = {5, 6, 6, 7};
122 pctxt[0].hs = pctxt[1].hs = szs[reg[PLSIZ] >> 4 & 3];
123 pctxt[0].ws = pctxt[1].ws = szs[reg[PLSIZ] & 3];
124 pctxt[2].ws = (reg[MODE4] & WIDE) != 0 ? 6 : 5;
126 for(i = 0; i <= 2; i++){
127 pctxt[i].h = 1<<pctxt[i].hs;
128 pctxt[i].w = 1<<pctxt[i].ws;
130 a = reg[HORSCR] << 9 & 0x7fff;
131 switch(reg[MODE3] & 3){
132 case 1: a += vdpy << 1 & 0xe; break;
133 case 2: a += vdpy << 1 & 0xff0; break;
134 case 3: a += vdpy << 1 & 0xffe; break;
136 for(i = 0; i < 2; i++){
138 v = -(vram[a + i] & 0x3ff);
140 p->tx = v >> 3 & pctxt[i].w - 1;
142 v = vsram[i] + vdpyy;
144 p->ty = v >> 4 & pctxt[i].h - 1;
148 p->ty = v >> 3 & pctxt[i].h - 1;
152 if((p->t & 0x800) != 0)
153 p->c >>= p->tnx << 2;
155 p->c <<= p->tnx << 2;
159 v = reg[WINV] << 3 & 0xf8;
160 if((reg[WINV] & 0x80) != 0 ? vdpy < v : vdpy >= v){
162 rwin = reg[WINH] << 4 & 0x1f0;
163 if((reg[WINH] & 0x80) != 0){
173 p->tx = lwin >> 3 & pctxt[2].w - 1;
176 p->ty = vdpy >> 3 & pctxt[2].h - 1;
182 plane(int n, int vis)
188 if((p->t & 0x800) != 0){
198 pr = 2 - (n & 1) + (p->t >> 13 & 4);
217 if((reg[MODE3] & 4) != 0 && ++snx == 16){
220 for(i = 0; i < 2; i++){
221 v = vsram[sx + i] + vdpy;
222 pctxt[i].tny = v & 7;
223 pctxt[i].ty = v >> 3 & pctxt[i].h - 1;
226 w = vdpx < rwin && vdpx >= lwin;
233 static struct sprite {
248 t = (reg[SPRTAB] << 8 & 0x7f00);
251 ns = (reg[MODE4] & WIDE) != 0 ? 20 : 16;
256 q->y = (p[0] & 0x3ff) - 256;
257 q->h = (p[1] >> 8 & 3) + 1 << 4;
260 q->y = (p[0] & 0x3ff) - 128;
261 q->h = (p[1] >> 8 & 3) + 1 << 3;
267 if((q->t & 0x1000) != 0)
269 q->x = (p[3] & 0x3ff) - 128;
272 q->w = (p[1] >> 10 & 3) + 1 << 3;
273 c = ((q->t & 0x7ff) << 4+intla) + (dy << 1);
274 for(i = 0; i < q->w >> 3 && np < xdisp; i++){
275 v = vram[c] << 16 | vram[(u16int)(c+1)];
277 if((q->t & 0x800) != 0)
278 q->c[(q->w >> 3) - 1 - i] = v;
283 if((u16int)-q->x < q->w){
285 if((q->t & 0x800) != 0)
286 q->c[i>>3] >>= (i & 7) << 2;
288 q->c[i>>3] <<= (i & 7) << 2;
290 if(++q == spr + ns || np >= xdisp){
294 }while(p = vram + (u16int)(t + ((p[1] & 0x7f) << 2)), p - vram != t && ++nt < 80);
308 for(p = spr; p < lsp; p++){
312 c = p->c + (dx >> 3);
313 if((p->t & 0x800) != 0){
324 set = 1 | p->t & 0x8000;
325 col = p->t >> 9 & 48 | v;
329 if((reg[MODE4] & SHI) != 0)
330 if((col & 0xfe) == 0x3e)
333 pixel(col, set >> 13 | 2);
334 if((col & 0xf) == 0xe)
340 pixel(col, set >> 13 | 2);
352 if(vdpx < 320 && vdpy < 224)
354 col = reg[BGCOL] & 0x3f;
359 if((reg[MODE2] & 0x40) != 0 && (vdpx >= 8 || (reg[MODE1] & 0x20) == 0)){
361 if((reg[MODE4] & SHI) != 0)
363 pixeldraw(vdpx, vdpy, v);
365 pixeldraw(vdpx, vdpy, 0);
367 pixeldraw(vdpx, vdpy, 0xcccccc);
375 vdpstat &= ~(STATINT | STATVBL | STATOVR | STATCOLL);
379 vdpyy = vdpy << 1 | frame;
380 if(vdpy == 0 || vdpy >= 225)
384 if((reg[MODE1] & IE1) != 0)
389 vdpstat |= STATVBL | STATINT;
392 if((reg[MODE2] & IE0) != 0)