Annotation of researchv10no/cmd/pico/framebuffers/pram.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <signal.h>
                      3: #include "pico.h"
                      4: 
                      5: extern short   CURSCRATCH, CUROLD;
                      6: extern struct  SRC src[MANY];
                      7: extern void    onquit();
                      8: extern int     DEF_LL, DEF_NL;
                      9: 
                     10: ramputitall(k)
                     11: {
                     12:        register unsigned char *pr, *pg, *pb;
                     13:        struct SRC *from = &src[k];
                     14:        register int j, ex = from->sx + from->ex;
                     15:        int i, offset, delta, sx = from->sx;
                     16:        int sy = from->sy, ey = from->sy + from->ey;
                     17:        short w[1024];          /* avoid malloc */
                     18: 
                     19:        offset = sy*DEF_LL + sx;
                     20:        delta  = DEF_LL - ex + sx;
                     21: 
                     22:        pr = from->pixred+offset;
                     23:        pg = from->pixgrn+offset;
                     24:        pb = from->pixblu+offset;
                     25:        signal(SIGINT, SIG_IGN);        /* don't mess up the ramtek */
                     26:        switch (from->nchan)
                     27:        {       case 1:
                     28:                        for (i = sy; i < ey; i++, pr += delta)
                     29:                        {       for (j = sx; j < ex; j++)
                     30:                                        w[j] = *pr++;
                     31:                                wi(w, ex-sx, 1, sx, i);
                     32:                        }
                     33:                        break;
                     34:                case 4:
                     35:                case 3:
                     36:                        for (i = sy; i < ey; i++, pr+=delta, pg+=delta, pb+=delta)
                     37:                        {       for (j = sx; j < ex; j++)
                     38:                                w[j] =  ((*pr++ & 224)<<1)|
                     39:                                        ((*pg++ & 224)>>2)|
                     40:                                        ((*pb++ & 224)>>5);
                     41:                                wi(w, ex-sx, 1, sx, i);
                     42:                        }
                     43:                        break;
                     44:                default:
                     45:                        fprintf(stderr, "undefined number of channels\n");
                     46:                        break;
                     47:        }
                     48:        signal(SIGINT, onquit);
                     49: }
                     50: 
                     51: ramlamcl()
                     52: {      int cm[512], a, b, c, i;
                     53: 
                     54:        for (i = 0; i < 512; i++)
                     55:        {       a = (i & (7<<6)) << 3;
                     56:                b = (i & (7<<3)) << 2;
                     57:                c = (i & (7   )) << 1;
                     58:                cm[i] = a | b | c;
                     59:        }
                     60:        signal(SIGINT, SIG_IGN);
                     61:        lam(512, cm);
                     62:        signal(SIGINT, onquit);
                     63:        reloadmaps();
                     64: }
                     65: 
                     66: ramlambwram()
                     67: {      int cm[512], i;
                     68: 
                     69:        for (i = 0; i < 512; i++)
                     70:                cm[i] = i;
                     71:        signal(SIGINT, SIG_IGN);
                     72:        lam(512, cm);
                     73:        signal(SIGINT, onquit);
                     74:        reloadmaps();
                     75: }
                     76: 
                     77: ramgetitall(from)
                     78:        struct SRC *from;
                     79: {
                     80:        register unsigned char *pr, *pg, *pb;
                     81:        register int j, ex = from->sx + from->ex;
                     82:        int i, offset, delta, sx = from->sx;
                     83:        int sy = from->sy, ey = from->sy + from->ey;
                     84:        short w[1024];  /* avoid malloc */
                     85: 
                     86:        if (from == Old)
                     87:                fprintf(stderr, "reading screen...");
                     88: 
                     89:        offset = sy*DEF_LL + sx;
                     90:        delta  = DEF_LL - ex + sx;
                     91: 
                     92:        pr = from->pixred+offset;
                     93:        pg = from->pixgrn+offset;
                     94:        pb = from->pixblu+offset;
                     95: 
                     96:        signal(SIGINT, SIG_IGN);        /* don't mess up the ramtek */
                     97:        switch (from->nchan)
                     98:        {       case 1:
                     99:                        for (i = sy; i < ey; i++, pr+=delta, pg+=delta, pb+=delta)
                    100:                        {       ri(0, i, DEF_LL, w);
                    101:                                for (j = sx; j < ex; j++)
                    102:                                {       *pg = *pb = *pr = w[j];
                    103:                                        pg++; pb++; pr++;
                    104:                                }
                    105:                        }
                    106:                        break;
                    107:                case 4:
                    108:                case 3:
                    109:                        for (i = sy; i < ey; i++, pr+=delta, pg+=delta, pb+=delta)
                    110:                        {       ri(0, i, DEF_LL, w);
                    111:                                for (j = sx; j < ex; j++)
                    112:                                {       *pr++ = ((w[j]>>6)&7)<<5;
                    113:                                        *pg++ = ((w[j]>>3)&7)<<5;
                    114:                                        *pb++ = ((w[j]   )&7)<<5;
                    115:                        }       }
                    116:                        break;
                    117:                default:
                    118:                        fprintf(stderr, "undefined number of channels\n");
                    119:                        break;
                    120:        }
                    121:        signal(SIGINT, onquit);
                    122:        if (from == Old)
                    123:                fprintf(stderr, "\n");
                    124:        RESIDENT;
                    125: }
                    126: 
                    127: /* a few extra builtins:
                    128:  */
                    129: 
                    130: ramlyank(x, y)
                    131: {      register int i;
                    132:        register unsigned char *pr, *pg, *pb;
                    133:        extern char faster;
                    134:        short w[1024];          /* avoid malloc */
                    135:        int from=Old->sx, to=Old->ex;
                    136: 
                    137:        if (y < Old->sy || y >= Old->ey) return 0;
                    138: 
                    139:        if (!faster)
                    140:        {       ramyank(x, y);
                    141:                return 0;
                    142:        } else
                    143:        {       if (x != 0)
                    144:                        return 0;
                    145:        }
                    146:        i = (y < 1 || y >= DEF_LL) ? 0 : DEF_LL*(y-1);
                    147:        pr = scratchred+i;
                    148:        pg = scratchgrn+i;
                    149:        pb = scratchblu+i;
                    150: 
                    151:        if (Old->nchan == 1)
                    152:                for (i = from; i < to; i++)
                    153:                w[i] = *pr++;
                    154:        else
                    155:                for (i = from; i < to; i++)
                    156:                w[i] = ((*pr++ & 224)<<1) | ((*pg++ & 224)>>2) | (*pb++>>5);
                    157: 
                    158:        signal(SIGINT, SIG_IGN);
                    159:        wi(&w[from], to - from, 1, from, y-1);
                    160:        signal(SIGINT, onquit);
                    161: 
                    162:        return 1;
                    163: }
                    164: 
                    165: ramyank(x, y)
                    166: {      register int i = DEF_LL*y+x;
                    167:        unsigned char *pr = scratchred+i;
                    168:        unsigned char *pg = scratchgrn+i;
                    169:        unsigned char *pb = scratchblu+i;
                    170:        short ch;
                    171: 
                    172:        if (Old->nchan == 1)
                    173:                ch = *pr;
                    174:        else
                    175:                ch = ((*pr & 224)<<1)|((*pg & 224)>>2)|(*pb >>5);
                    176:        wii(&ch, x, y);
                    177:        return 1;
                    178: }
                    179: 
                    180: unsigned char Rmap[256], Gmap[256], Bmap[256];
                    181: 
                    182: reloadmaps()
                    183: {      register int i;
                    184:        for (i = 0; i < 256; i++)
                    185:                Rmap[i]=Gmap[i]=Bmap[i]=i;
                    186: }
                    187: 
                    188: ramredcmap(i, z)
                    189: {      int j = i%256;
                    190:        int k = z%256;
                    191: 
                    192:        Rmap[j] = k;
                    193:        if (j == 255) docmap();
                    194:        return k;
                    195: }
                    196: 
                    197: ramgrncmap(i, z)
                    198: {      int j = i%256;
                    199:        int k = z%256;
                    200: 
                    201:        Gmap[j] = k;
                    202:        if (j == 255) docmap();
                    203:        return k;
                    204: }
                    205: 
                    206: ramblucmap(i, z)
                    207: {      int j = i%256;
                    208:        int k = z%256;
                    209: 
                    210:        Bmap[j] = k;
                    211:        if (j == 255) docmap();
                    212:        return k;
                    213: }
                    214: 
                    215: docmap()
                    216: {      int i, cm[512], a, b, c;
                    217: 
                    218:        if (Old->nchan == 1)
                    219:        {       for (i = 0; i < 256; i++)
                    220:                        cm[i] = Rmap[i];
                    221:        } else
                    222:        {       for (i = 0; i < 512; i++)
                    223:                {       a = ((Rmap[(i&(7<<6))>>1])&240)<<4;
                    224:                        b = ((Gmap[(i&(7<<3))<<2])&240);
                    225:                        c = ((Bmap[(i&(7   ))<<5])&240)>>4;
                    226:                        cm[i] = a | b | c;
                    227:                }
                    228:        }
                    229:        signal(SIGINT, SIG_IGN);
                    230:        lam(512, cm);
                    231:        signal(SIGINT, onquit);
                    232: }
                    233: 
                    234: ramzap()
                    235: {
                    236:        fill(0, Old->sx, Old->sy, Old->ex, Old->ey);
                    237: }
                    238: 
                    239: ramgetcmap(i, r,g,b)
                    240: {      int h = 0, k = 0;
                    241: 
                    242:        if (r) { h++; k += Rmap[i]; }
                    243:        if (g) { h++; k += Gmap[i]; }
                    244:        if (b) { h++; k += Bmap[i]; }
                    245:        if (h > 1) k /= h;
                    246: 
                    247:        return k;
                    248: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.