|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <signal.h> ! 3: #include "pico.h" ! 4: #define NMBUF 2048 ! 5: ! 6: #define mlong(a) (mword((a)>>16), mword(a)) ! 7: #define mword(a) (mbyte((a)>>8), mbyte(a)) ! 8: #define mbyte(a) (mbufp==&mbuf[NMBUF] && mflush(), *mbufp++=(a)) ! 9: /* versions of the above allowing moving checks out of the loop */ ! 10: #define mcheck(n) (mbufp>=&mbuf[NMBUF-n] && mflush()) ! 11: #define mulong(a) (muword((a)>>16), muword(a)) ! 12: #define muword(a) (mubyte((a)>>8), mubyte(a)) ! 13: #define mubyte(a) (*mbufp++=a) ! 14: #define mcmd(a) ((mbufp-mbuf)&1 && (*mbufp++=0), mword(a)) ! 15: #define mflush() ((mbufp-mbuf)&1 && (*mbufp++=0),write(om_fd, mbuf, (mbufp-mbuf)*sizeof mbuf[0]),mbufp=mbuf) ! 16: ! 17: #define MOVP1 0x0052 ! 18: #define MOVP2 0x0053 ! 19: #define SETCLL 0x3061 /* l:color */ ! 20: #define WPIXEL 0x006d /* */ ! 21: #define CMAP 0x0051 /* b:index, b:red, b:grn, b:blu */ ! 22: #define WRMSKL 0x3023 /* l:mask */ ! 23: #define CMAPOL 0x301a /* 8b:2 nibble-sized entries */ ! 24: #define CMSEL 0x3015 ! 25: #define CMLDM 0x3013 ! 26: #define CMCOPY 0x3016 ! 27: #define CMACT 0x3000 ! 28: #define RGBA 0xe ! 29: #define RGB 0xd ! 30: #define A 0x1 ! 31: #define R 0x2 ! 32: #define G 0x4 ! 33: #define B 0x8 ! 34: ! 35: extern short CURSCRATCH, CUROLD; ! 36: extern struct SRC src[MANY]; ! 37: extern int DEF_LL, DEF_NL; ! 38: extern void onquit(); ! 39: ! 40: int om_fd; ! 41: ! 42: om_open(dev) ! 43: { char buf[16]; ! 44: unsigned char mbuf[16], *mbufp=mbuf; ! 45: extern char metheus; ! 46: ! 47: sprintf(buf, "/dev/om%d", dev); ! 48: if ((om_fd = open(buf, 2)) == -1) ! 49: { perror("om_open"); ! 50: metheus = 0; ! 51: return 0; ! 52: } ! 53: #if 1 ! 54: signal(SIGINT, SIG_IGN); /* don't mess up the device */ ! 55: metinitcmap(); ! 56: muword(WRMSKL); /* enable all 4 bitplanes */ ! 57: mubyte(255); mubyte(255); ! 58: mubyte(255); mubyte(255); ! 59: muword(CMAPOL); /* clear the overlaymap */ ! 60: muword(0); muword(0); ! 61: muword(0); muword(0); ! 62: write(om_fd, (char *)mbuf, 16); ! 63: signal(SIGINT, onquit); ! 64: #endif ! 65: return 1; ! 66: } ! 67: ! 68: om_close() ! 69: { ! 70: close(om_fd); ! 71: } ! 72: ! 73: metputitall(k) ! 74: { struct SRC *from = &src[k]; ! 75: register unsigned char *pr, *pg, *pb; ! 76: register int i; int offset, delta; ! 77: int sx = from->sx; ! 78: int ex = from->ex; ! 79: int sy = from->sy; ! 80: int ey = from->ey; ! 81: int chunk; if ((ex-sx)&1) ex++; ! 82: ! 83: signal(SIGINT, SIG_IGN); /* don't mess up the device */ ! 84: merect(sx, sy, ex, ey); ! 85: offset = sy*DEF_LL + sx; ! 86: delta = DEF_LL - ex + sx; ! 87: chunk = (ex-sx)+delta; ! 88: ! 89: pr = from->pixred+offset; ! 90: switch (from->nchan) ! 91: { case 1: setbank(RGBA); ! 92: for (i = sy; i < ey; i++, pr += chunk) ! 93: write(om_fd, pr, ex-sx); ! 94: break; ! 95: case 3: setbank(R); ! 96: for (i = sy; i < ey; i++, pr += chunk) ! 97: write(om_fd, pr, ex-sx); ! 98: setbank(G); pg = from->pixgrn+offset; ! 99: for (i = sy; i < ey; i++, pg += chunk) ! 100: write(om_fd, pg, ex-sx); ! 101: setbank(B); pb = from->pixblu+offset; ! 102: for (i = sy; i < ey; i++, pb += chunk) ! 103: write(om_fd, pb, ex-sx); ! 104: break; ! 105: default: ! 106: fprintf(stderr, "undefined number of channels\n"); ! 107: break; ! 108: } ! 109: signal(SIGINT, onquit); ! 110: } ! 111: ! 112: metgetitall(from) ! 113: struct SRC *from; ! 114: { ! 115: register unsigned char *pr, *pg, *pb; ! 116: register int i; int offset, delta; ! 117: int sx = from->sx; ! 118: int ex = from->ex; ! 119: int sy = from->sy; ! 120: int ey = from->ey; ! 121: int chunk; if ((ex-sx)&1) ex++; ! 122: ! 123: signal(SIGINT, SIG_IGN); /* don't mess up the device */ ! 124: merect(sx, sy, ex, ey); ! 125: offset = sy*DEF_LL + sx; ! 126: delta = DEF_LL - ex + sx; ! 127: chunk = (ex-sx)+delta; ! 128: ! 129: if (from == Old) ! 130: fprintf(stderr, "reading screen..."); ! 131: ! 132: pr = from->pixred+offset; ! 133: switch (from->nchan) ! 134: { case 1: setbank(RGBA); ! 135: for (i = sy; i < ey; i++, pr += chunk) ! 136: read(om_fd, pr, ex-sx); ! 137: break; ! 138: case 3: setbank(R); ! 139: for (i = sy; i < ey; i++, pr += chunk) ! 140: read(om_fd, pr, ex-sx); ! 141: setbank(G); pg = from->pixgrn+offset; ! 142: for (i = sy; i < ey; i++, pg += chunk) ! 143: read(om_fd, pg, ex-sx); ! 144: setbank(B); pb = from->pixblu+offset; ! 145: for (i = sy; i < ey; i++, pb += chunk) ! 146: read(om_fd, pb, ex-sx); ! 147: break; ! 148: default: ! 149: fprintf(stderr, "undefined number of channels\n"); ! 150: break; ! 151: } ! 152: signal(SIGINT, onquit); ! 153: RESIDENT; ! 154: } ! 155: ! 156: metlyank(x, y) ! 157: { register int i; ! 158: register unsigned char *pr, *pg, *pb; ! 159: extern char faster; ! 160: int from=Old->sx, to=Old->ex; ! 161: ! 162: if (y <= Old->sy || y > Old->ey) return 1; ! 163: ! 164: if (!faster) ! 165: { metyank(x, y); ! 166: return; ! 167: } else ! 168: { if (x > from) ! 169: return; ! 170: } ! 171: if ((to-from)&1) to++; ! 172: i = x+DEF_LL*(y-1); ! 173: signal(SIGINT, SIG_IGN); /* don't mess up the device */ ! 174: merect(from, y-1, to, y); ! 175: ! 176: pr = scratchred+i; ! 177: switch (Old->nchan) ! 178: { case 1: setbank(RGBA); write(om_fd, pr, to-from); ! 179: break; ! 180: case 3: pg = scratchgrn+i; ! 181: pb = scratchblu+i; ! 182: setbank(R); write(om_fd, pr, to-from); ! 183: setbank(G); write(om_fd, pg, to-from); ! 184: setbank(B); write(om_fd, pb, to-from); ! 185: break; ! 186: } ! 187: signal(SIGINT, onquit); ! 188: return 1; ! 189: } ! 190: ! 191: metyank(x, y) ! 192: { register int i = DEF_LL*y+x; ! 193: unsigned char *pg, *pb; ! 194: unsigned char *pr = scratchred+i; ! 195: ! 196: signal(SIGINT, SIG_IGN); /* don't mess up the device */ ! 197: merect(x, y, x, y); ! 198: switch (Old->nchan) ! 199: { case 1: setbank(RGBA); write(om_fd, pr, 1); ! 200: break; ! 201: case 3: pg = scratchgrn+i; ! 202: pb = scratchblu+i; ! 203: setbank(R); write(om_fd, pr, 1); ! 204: setbank(G); write(om_fd, pg, 1); ! 205: setbank(B); write(om_fd, pb, 1); ! 206: break; ! 207: } ! 208: signal(SIGINT, onquit); ! 209: return 1; ! 210: } ! 211: ! 212: unsigned char Rmap[256], Gmap[256], Bmap[256]; ! 213: ! 214: metinitcmap() ! 215: { int i; ! 216: ! 217: for (i = 0; i < 256; i++) ! 218: Rmap[i] = Gmap[i] = Bmap[i] = (unsigned char) i; ! 219: ! 220: } ! 221: ! 222: metredcmap(i, z) ! 223: { int j = i%256; ! 224: int k = z%256; ! 225: ! 226: Rmap[j] = k; ! 227: if (j == 255) dometcmap(); ! 228: return k; ! 229: } ! 230: ! 231: metgrncmap(i, z) ! 232: { int j = i%256; ! 233: int k = z%256; ! 234: ! 235: Gmap[j] = k; ! 236: if (j == 255) dometcmap(); ! 237: return k; ! 238: } ! 239: ! 240: metblucmap(i, z) ! 241: { int j = i%256; ! 242: int k = z%256; ! 243: ! 244: Bmap[j] = k; ! 245: if (j == 255) dometcmap(); ! 246: return k; ! 247: } ! 248: ! 249: dometcmap() ! 250: { unsigned char mbuf[2048], *mbufp=mbuf; ! 251: unsigned char cmap[256*3], *m; ! 252: int i; ! 253: ! 254: signal(SIGINT, SIG_IGN); /* don't mess up the device */ ! 255: ! 256: for (i = 0; i < 256; i++) ! 257: { cmap[3*i] = Rmap[i]; ! 258: cmap[3*i+1] = Gmap[i]; ! 259: cmap[3*i+2] = Bmap[i]; ! 260: } ! 261: m = cmap; ! 262: mcmd(CMSEL); mbyte(0); /* write in cmap buffer 0 */ ! 263: mcmd(CMLDM);mword(0);mword(256); /* load 256 entries at loc. 0 */ ! 264: for(i=0;i!=256*3;i++) mbyte(*m++); /* data */ ! 265: mcmd(CMCOPY); mbyte(0); mbyte(0); /* copy 256 entries to rest */ ! 266: mword(0); mword(256); mword(256*15); ! 267: mcmd(CMACT); /* make current buffer active */ ! 268: mflush(); ! 269: ! 270: signal(SIGINT, onquit); ! 271: } ! 272: ! 273: metgetcmap(i, r,g,b) ! 274: { int h = 0, k = 0; ! 275: ! 276: if (r) { h++; k += Rmap[i]; } ! 277: if (g) { h++; k += Gmap[i]; } ! 278: if (b) { h++; k += Bmap[i]; } ! 279: if (h > 1) k /= h; ! 280: ! 281: return k; ! 282: } ! 283: ! 284: merect(x0, y0, x1, y1) ! 285: { ! 286: unsigned char mbuf[16], *mbufp=mbuf; ! 287: ! 288: muword(MOVP1); muword(x0); muword(y0); ! 289: muword(MOVP2); muword(x1-1); muword(y1-1); ! 290: write(om_fd, (char *)mbuf, 12); ! 291: } ! 292: ! 293: #define WRBANK 0x003d ! 294: #define WRR 0x006f ! 295: ! 296: setbank(bank) ! 297: unsigned char bank; ! 298: { ! 299: unsigned char mbuf[8], *mbufp=mbuf; ! 300: ! 301: muword(WRBANK); ! 302: mubyte(bank); mubyte(0); ! 303: muword(WRR); /* write 1 byte/pixel rectangle */ ! 304: write(om_fd, (char *)mbuf, 6); ! 305: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.