Annotation of researchv9/jerq/src/mux/term/user.c, revision 1.1

1.1     ! root        1: #include <jerq.h>
        !             2: #include <layer.h>
        !             3: #include <jerqproc.h>
        !             4: #include <font.h>
        !             5: static inhibited;
        !             6: Texture *Ucursswitch();
        !             7: #define        DB              ((Word *)0x700000)
        !             8: #define        ONSCREEN(b)     (b->base>=DB && b->base<DB+XMAX/WORDSIZE*YMAX)
        !             9: 
        !            10: char *
        !            11: Ualloc(n)
        !            12:        unsigned n;
        !            13: {
        !            14:        extern char *realalloc();
        !            15:        return realalloc(n, (char *)P);
        !            16: }
        !            17: Bitmap *
        !            18: Uballoc(r)
        !            19:        Rectangle r;
        !            20: {
        !            21:        extern Bitmap *realballoc();
        !            22:        return realballoc(r, (char *)P);
        !            23: }
        !            24: Uexit(){
        !            25:        extern windowproc();
        !            26:        shutdown(P);
        !            27:        exec(windowproc);
        !            28: }
        !            29: Urequest(r)
        !            30: {
        !            31:        extern struct Proc *kbdproc;
        !            32:        register struct Proc *p=P;
        !            33:        if(r&KBD)
        !            34:                p->state|=KBDLOCAL;
        !            35:        else
        !            36:                p->state&=~KBDLOCAL;
        !            37:        if(r&MOUSE){
        !            38:                p->state|=MOUSELOCAL;
        !            39:                if(kbdproc==p){
        !            40:                        p->state|=GOTMOUSE;
        !            41:                        if(p->state&GOTMOUSE)   /* if not, it's windowproc */
        !            42:                                givemouse(p);
        !            43:                }
        !            44:                sleep(1);       /* Let control() update the mouse */
        !            45:        }else{
        !            46:                Ucursallow();
        !            47:                Ucursswitch((Texture *) 0);
        !            48:                p->state&=~(GOTMOUSE|MOUSELOCAL);
        !            49:        }
        !            50:        if(r&ALARM)
        !            51:                p->state|=ALARMREQD;
        !            52:        else
        !            53:                p->state&=~ALARMREQD;
        !            54: }
        !            55: Urcvchar(){
        !            56:        if(P->nchars==0)
        !            57:                return -1;
        !            58:        return(getchar());
        !            59: }
        !            60: Ukbdchar(){
        !            61:        if((P->state&KBDLOCAL)==0)
        !            62:                return -1;
        !            63:        return(qgetc(&P->kbdqueue));
        !            64: }
        !            65: Uown()
        !            66: {
        !            67:        register got=CPU|cansend(P-proctab);
        !            68:        if(P->state&GOTMOUSE)
        !            69:                got|=MOUSE;
        !            70:        if(P->kbdqueue.c_cc>0)
        !            71:                got|=KBD;
        !            72:        if(P->nchars>0)
        !            73:                got|=RCV;
        !            74:        if(P->state&ALARMREQD && P->nticks== 0)
        !            75:                got|=ALARM;
        !            76:        return got;
        !            77: }
        !            78: Uwait(r)
        !            79:        register r;
        !            80: {
        !            81:        register u;
        !            82: 
        !            83:        if((r&RCV) && P->nchars==0)
        !            84:                muxublk(P);
        !            85:        sw(1);
        !            86:        if(r==0)
        !            87:                return; /* dumb person */
        !            88:        spl1();
        !            89:        while((u=Uown()&r)==0 && (r&CPU)==0){
        !            90:                spl0();
        !            91:                sw(0);
        !            92:                spl1();
        !            93:        }
        !            94:        spl0();
        !            95:        return u;
        !            96: }
        !            97: Ucursallow(){
        !            98:        if(P->state&MOUSELOCAL){
        !            99:                if(ptinrect(mouse.xy, P->layer->rect) && (P->state&GOTMOUSE))
        !           100:                        cursallow();
        !           101:                P->inhibited=0;
        !           102:        }
        !           103: }
        !           104: Ucursset(p)
        !           105:        Point p;
        !           106: {
        !           107:        if(P->state&GOTMOUSE){
        !           108:                cursset(p);
        !           109:                givemouse(P);
        !           110:        }
        !           111: }
        !           112: Ucursinhibit(){
        !           113:        if(P->state&MOUSELOCAL){
        !           114:                if(ptinrect(mouse.xy, P->layer->rect) && (P->state&GOTMOUSE))
        !           115:                        cursinhibit();
        !           116:                P->inhibited=1;
        !           117:        }
        !           118: }
        !           119: Texture *
        !           120: Ucursswitch(t)
        !           121:        register Texture *t;
        !           122: {
        !           123:        Texture *ot;
        !           124:        ot=0;
        !           125:        if(P->state&MOUSELOCAL){
        !           126:                ot=P->cursor;
        !           127:                if(ptinrect(mouse.xy, P->layer->rect) && (P->state&GOTMOUSE))
        !           128:                        cursswitch(t);
        !           129:                P->cursor=t;
        !           130:        }
        !           131:        sleep(1);
        !           132:        return ot;
        !           133: }
        !           134: Point
        !           135: ostring(f,s,b,p,fc)
        !           136:        register Font *f;
        !           137:        unsigned char *s;
        !           138:        register Layer *b;
        !           139:        Point p;
        !           140:        int fc;
        !           141: {
        !           142:        register c;
        !           143:        int full = (fc == F_STORE);
        !           144:        Point q;
        !           145:        Rectangle r;
        !           146:        register Fontchar *i;
        !           147:        inhibited=0;
        !           148:        if(fc!=F_XOR && ONSCREEN(b)){
        !           149:                cursinhibit();
        !           150:                inhibited=1;
        !           151:        }
        !           152:        if (full) {
        !           153:                r.origin.y = 0;
        !           154:                r.corner.y = f->height;
        !           155:        }
        !           156:        for (; c = *s++; p.x += i->width) {
        !           157:                i = f->info + c;
        !           158:                if (!full) {
        !           159:                        r.origin.y = i->top;
        !           160:                        r.corner.y = i->bottom;
        !           161:                }
        !           162:                r.origin.x = i->x;
        !           163:                r.corner.x = (i+1)->x;
        !           164:                q.x = p.x+((i->left&0x80)? (i->left|0xffffff00):i->left);
        !           165:                q.y = p.y+r.origin.y;
        !           166:                if (b->someobs == b->nonevis)
        !           167:                        bitblt(f->bits,r,b->nonevis?b->obs:(Bitmap *)b,q,fc);
        !           168:                else
        !           169:                        lblt(f->bits,r,b,q,fc);
        !           170:        }
        !           171:        if(inhibited)
        !           172:                cursallow();
        !           173:        return(p);
        !           174: }
        !           175: Point
        !           176: string(f,s,b,p,fc)     /* highly 5620 dependent! */
        !           177:        Font *f;
        !           178:        unsigned char *s;
        !           179:        register Layer *b;
        !           180:        Point p;
        !           181:        int fc;
        !           182: {
        !           183:        register Word *src,*dst;        /* %r7, %r6 */
        !           184:        register m,shift,i;             /* %r5, %r4, %r3 */
        !           185:        static Bitmap *mrfont;  /* local font, guaranteed to not straddle source */
        !           186:        unsigned char *cp,mrbuf[2];
        !           187:        int dw;
        !           188:        short cwid,edge;
        !           189:        Fontchar *infop;
        !           190:        if (b->someobs != 0 || f != &defont || fc != F_XOR 
        !           191:                || p.x < b->rect.origin.x || p.y < b->rect.origin.y
        !           192:                || p.y+f->height > b->rect.corner.y)
        !           193:                        return(ostring(f,s,b,p,fc));
        !           194:        if (mrfont == 0) {      /* create Mr Font */
        !           195:                mrbuf[1] = 0;
        !           196:                mrfont = balloc(Rect(0,0,32,f->height*defont.n));
        !           197:                rectf(mrfont,mrfont->rect,F_CLR);
        !           198:                for (i = 0; i < defont.n; i++) {
        !           199:                        mrbuf[0] = i;
        !           200:                        ostring(f,mrbuf,mrfont,Pt(0,i*f->height),F_XOR);
        !           201:                }
        !           202:        }
        !           203:        edge = b->rect.corner.x;
        !           204:        dw = 4*b->width;
        !           205:        for (; m = *s; s++) {
        !           206:                if(m >= defont.n)
        !           207:                        continue;
        !           208:                infop = &f->info[m];
        !           209:                i = infop->top;
        !           210:                dst = addr(b,Pt(p.x,p.y+i));
        !           211:                src = mrfont->base + f->height*m + i;
        !           212:                shift = p.x & 31;
        !           213:                i = infop->bottom - i;
        !           214:                cwid = infop->width;
        !           215:                if(p.x+cwid > edge)
        !           216:                        return(ostring(f,s,b,p,fc));
        !           217:                if (shift + cwid <= 32) {
        !           218:                        do {
        !           219: asm("                          ROTW    %r4,(%r7),%r5   ");
        !           220:                                src++;
        !           221:                                *dst ^= m;
        !           222:                                (char *) dst += dw;
        !           223:                        } while (--i > 0);
        !           224:                }
        !           225:                else {
        !           226:                        ((short *) dst)++;
        !           227:                        do {
        !           228: asm("                          ROTW    %r4,(%r7),%r5   ");
        !           229:                                src++;
        !           230: asm("                          XORH2   %r5,(%r6)       ");
        !           231: asm("                          ROTW    &16,%r5,%r5     ");
        !           232: asm("                          XORH2   %r5,2(%r6)      ");
        !           233:                                (char *) dst += dw;
        !           234:                        } while (--i > 0);
        !           235:                }
        !           236:                p.x += cwid;
        !           237:        }
        !           238:        return(p);
        !           239: }
        !           240: Usendchar(c)
        !           241:        char c;
        !           242: {
        !           243:        while(muxsendchar(c, P) == -1)
        !           244:                sw(1);
        !           245: }
        !           246: Upoint(l, p, f)
        !           247:        register Layer *l;
        !           248:        Point p;
        !           249: {
        !           250:        inhibited=0;
        !           251:        if(f!=F_XOR && ONSCREEN(l)){
        !           252:                cursinhibit();
        !           253:                inhibited=1;
        !           254:        }
        !           255:        lpoint(l, p, f);
        !           256:        if(inhibited)
        !           257:                cursallow();
        !           258: }
        !           259: Ubitblt(s, r, d, p, f)
        !           260:        Layer *s, *d;
        !           261:        Rectangle r;
        !           262:        Point p;
        !           263: {
        !           264:        inhibited=0;
        !           265:        if((f!=F_XOR && ONSCREEN(d)) || ONSCREEN(s)){
        !           266:                cursinhibit();
        !           267:                inhibited=1;
        !           268:        }
        !           269:        lbitblt(s, r, d, p, f);
        !           270:        if(inhibited)
        !           271:                cursallow();
        !           272: }
        !           273: Urectf(l, r, f)
        !           274:        Layer *l;
        !           275:        Rectangle r;
        !           276: {
        !           277:        inhibited=0;
        !           278:        if(f!=F_XOR && ONSCREEN(l)){
        !           279:                cursinhibit();
        !           280:                inhibited=1;
        !           281:        }
        !           282:        /* speed hack: rectf clips */
        !           283:        if(l->someobs != l->nonevis)
        !           284:                lrectf(l, r, f);
        !           285:        else
        !           286:                rectf(l->nonevis?l->obs:(Bitmap *)l, r, f);
        !           287:        if(inhibited)
        !           288:                cursallow();
        !           289: }
        !           290: Usegment(l, p, q, f)
        !           291:        Layer *l;
        !           292:        Point p, q;
        !           293: {
        !           294:        inhibited=0;
        !           295:        if(f!=F_XOR && ONSCREEN(l)){
        !           296:                cursinhibit();
        !           297:                inhibited=1;
        !           298:        }
        !           299:        lsegment(l, p, q, f);
        !           300:        if(inhibited)
        !           301:                cursallow();
        !           302: }
        !           303: Utexture(l, r, t, f)
        !           304:        Layer *l;
        !           305:        Rectangle r;
        !           306:        Texture *t;
        !           307: {
        !           308:        inhibited=0;
        !           309:        if(f!=F_XOR && ONSCREEN(l)){
        !           310:                cursinhibit();
        !           311:                inhibited=1;
        !           312:        }
        !           313:        /* speed hack; texture clips anyway */
        !           314:        if(l->someobs != l->nonevis)
        !           315:                ltexture(l, r, t, f);
        !           316:        else
        !           317:                texture(l->nonevis?l->obs:(Bitmap *)l, r, t, f);
        !           318:        if(inhibited)
        !           319:                cursallow();
        !           320: }
        !           321: Uscreenswap(b, r, s)
        !           322:        Bitmap *b;
        !           323:        Rectangle r, s;
        !           324: {
        !           325:        cursinhibit();
        !           326:        screenswap(b, r, s);
        !           327:        cursallow();
        !           328: }
        !           329: struct Proc *
        !           330: Unewproc(f)
        !           331:        int (*f)();
        !           332: {
        !           333:        extern windowproc();
        !           334:        if(f==0)
        !           335:                f=windowproc;
        !           336:        return newproc(f);
        !           337: }
        !           338: struct Proc *
        !           339: Unewwindow(f)
        !           340:        int (*f)();
        !           341: {
        !           342:        extern windowproc();
        !           343:        if(f==0)
        !           344:                f=windowproc;
        !           345:        return newwindow(f);
        !           346: }
        !           347: Word *
        !           348: Uaddr(l, pt)
        !           349:        register Layer *l;
        !           350:        Point pt;
        !           351: {
        !           352:        register bit;
        !           353:        register Word *p;
        !           354:        register Obscured *o;
        !           355:        register Bitmap *b;
        !           356:        b=(Bitmap *)l;
        !           357:        if(ptinrect(pt, l->rect)){
        !           358:                if (l->someobs == l->nonevis)
        !           359:                        b = (l->nonevis?l->obs:(Bitmap *)l);
        !           360:                else
        !           361:                        for(o=lfront; o; o=o->back)
        !           362:                                if(ptinrect(p, o->rect)){
        !           363:                                        b=((o!=l)?l->obs:(Bitmap *)l);
        !           364:                                        break;
        !           365:                        }
        !           366:                return addr(b, pt);
        !           367:        }
        !           368:        return addr(b, pt);
        !           369: }
        !           370: Rectangle      /* pure history */
        !           371: Uogetrect()
        !           372: {
        !           373:        return getrect3();
        !           374: }
        !           375: 
        !           376: #define Nalloc(n)      (struct Nqueue *)realalloc(sizeof(struct Nqueue)+(n)-3, (char *)0)
        !           377: 
        !           378: static struct Nqueue *nlist;
        !           379: 
        !           380: struct Nqueue *
        !           381: getname(name)
        !           382: register char *name;
        !           383: {
        !           384:        register struct Nqueue *p = nlist;
        !           385:        while (p && strcmp(name, p->name))
        !           386:                p = p->next;
        !           387:        if (p == 0) {
        !           388:                if ((p = Nalloc(strlen(name))) == 0)
        !           389:                        return 0;
        !           390:                p->next = nlist;
        !           391:                nlist = p;
        !           392:                strcpy(p->name, name);
        !           393:        }
        !           394:        return p;
        !           395: }
        !           396: 
        !           397: putname(name, data)
        !           398: char *name; long data;
        !           399: {
        !           400:        register struct Nqueue *p = getname(name);
        !           401:        if (p == 0)
        !           402:                return 1;
        !           403:        p->proc = P;
        !           404:        p->data = data;
        !           405:        return 0;
        !           406: }
        !           407: 
        !           408: clearname(proc)
        !           409: register struct Proc *proc;
        !           410: {
        !           411:        register struct Nqueue *p;
        !           412:        for (p=nlist; p; p = p->next)
        !           413:                if (p->proc == proc)
        !           414:                        p->proc = 0;
        !           415: }

unix.superglobalmegacorp.com

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