Annotation of lucent/sys/src/9/next/screen.c, revision 1.1

1.1     ! root        1: #include       "u.h"
        !             2: #include       "../port/lib.h"
        !             3: #include       "mem.h"
        !             4: #include       "dat.h"
        !             5: #include       "fns.h"
        !             6: #include       "io.h"
        !             7: #include       "ureg.h"
        !             8: #include       "../port/error.h"
        !             9: 
        !            10: #include       <libg.h>
        !            11: #include       <gnot.h>
        !            12: #include       "screen.h"
        !            13: 
        !            14: #define        MINX    8
        !            15: 
        !            16: extern GSubfont        defont0;
        !            17: GSubfont               *defont;
        !            18: 
        !            19: struct{
        !            20:        Point   pos;
        !            21:        int     bwid;
        !            22: }out;
        !            23: 
        !            24: Lock   screenlock;
        !            25: 
        !            26: void   duartinit(void);
        !            27: int    duartacr;
        !            28: int    duartimr;
        !            29: 
        !            30: void   (*kprofp)(ulong);
        !            31: 
        !            32: GBitmap        gscreen =
        !            33: {
        !            34:        (ulong*)DISPLAYRAM,     /* BUG */
        !            35:        0,
        !            36:        2*1152/32,
        !            37:        1,
        !            38:        { 0, 0, 1120, 832, },
        !            39:        { 0, 0, 1120, 832, },
        !            40:        0
        !            41: };
        !            42: 
        !            43: void
        !            44: screeninit(void)
        !            45: {
        !            46:        void bigcursor(void);
        !            47:        bigcursor();
        !            48: 
        !            49:        defont = &defont0;      /* save space; let bitblt do the conversion work */
        !            50:        gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, 0); /**/
        !            51:        out.pos.x = MINX;
        !            52:        out.pos.y = 0;
        !            53:        out.bwid = defont0.info[' '].width;
        !            54: }
        !            55: 
        !            56: void
        !            57: screenputs(char *s, int n)
        !            58: {
        !            59:        Rune r;
        !            60:        int i;
        !            61:        char buf[4];
        !            62: 
        !            63:        if(getsr() & 0x0700){
        !            64:                if(!canlock(&screenlock))
        !            65:                        return; /* don't deadlock trying to print in interrupt */
        !            66:        }else
        !            67:                lock(&screenlock);
        !            68:        while(n > 0){
        !            69:                i = chartorune(&r, s);
        !            70:                if(i == 0){
        !            71:                        s++;
        !            72:                        --n;
        !            73:                        continue;
        !            74:                }
        !            75:                memmove(buf, s, i);
        !            76:                buf[i] = 0;
        !            77:                n -= i;
        !            78:                s += i;
        !            79:                if(r == '\n'){
        !            80:                        out.pos.x = MINX;
        !            81:                        out.pos.y += defont0.height;
        !            82:                        if(out.pos.y > gscreen.r.max.y-defont0.height)
        !            83:                                out.pos.y = gscreen.r.min.y;
        !            84:                        gbitblt(&gscreen, Pt(0, out.pos.y), &gscreen,
        !            85:                            Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height), 0);
        !            86:                }else if(r == '\t'){
        !            87:                        out.pos.x += (8-((out.pos.x-MINX)/out.bwid&7))*out.bwid;
        !            88:                        if(out.pos.x >= gscreen.r.max.x)
        !            89:                                screenputs("\n", 1);
        !            90:                }else if(r == '\b'){
        !            91:                        if(out.pos.x >= out.bwid+MINX){
        !            92:                                out.pos.x -= out.bwid;
        !            93:                                gsubfstring(&gscreen, out.pos, defont, " ", S);
        !            94:                        }
        !            95:                }else{
        !            96:                        if(out.pos.x >= gscreen.r.max.x-out.bwid)
        !            97:                                screenputs("\n", 1);
        !            98:                        out.pos = gsubfstring(&gscreen, out.pos, defont, buf, S);
        !            99:                }
        !           100:        }
        !           101:        unlock(&screenlock);
        !           102: }
        !           103: 
        !           104: #include       "keys.h"
        !           105: 
        !           106: void
        !           107: kbdstate(int ch)
        !           108: {
        !           109:        static int collecting, nk;
        !           110:        static uchar kc[5];
        !           111:        int c, i;
        !           112: 
        !           113:        if(ch == 0xff){
        !           114:                collecting = 0;
        !           115:                return;
        !           116:        }
        !           117:        if(ch == -1){
        !           118:                collecting = 1;
        !           119:                nk = 0;
        !           120:                return;
        !           121:        }
        !           122:        if(!collecting){
        !           123:                kbdrepeat(1);
        !           124:                kbdputc(&kbdq, ch);
        !           125:                return;
        !           126:        }
        !           127:        kc[nk++] = ch;
        !           128:        c = latin1(kc, nk);
        !           129:        if(c < -1)      /* need more keystrokes */
        !           130:                return;
        !           131:        if(c != -1)     /* valid sequence */
        !           132:                kbdputc(&kbdq, c);
        !           133:        else    /* dump characters */
        !           134:                for(i=0; i<nk; i++)
        !           135:                        kbdputc(&kbdq, kc[i]);
        !           136:        nk = 0;
        !           137:        collecting = 0;
        !           138: }
        !           139: 
        !           140: int altcmd;    /* state of left alt and command keys */
        !           141: 
        !           142: void
        !           143: kbdmouseintr(void)
        !           144: {
        !           145:        int c;
        !           146:        ulong d;
        !           147:        int dx, dy;
        !           148:        static int b;
        !           149: 
        !           150:        if(*(ulong*)MONCSR & (1<<23)){
        !           151:                if(*(ulong*)MONCSR & (1<<22)){
        !           152:                        d = *(ulong*)KBDDATA;
        !           153:                        if(d & (0xF<<24)){
        !           154:                                if((d&0x01) == 0)
        !           155:                                        b |= 1;
        !           156:                                else
        !           157:                                        b &= ~1;
        !           158:                                if((d&0x100) == 0)
        !           159:                                        b |= mouseshifted ? 2 : 4;
        !           160:                                else
        !           161:                                        b &= ~6;
        !           162:                                dx = (d>>1) & 0x7F;
        !           163:                                dy = (d>>9) & 0x7F;
        !           164:                                if(dx & 0x40)
        !           165:                                        dx |= ~0x7F;
        !           166:                                if(dy & 0x40)
        !           167:                                        dy |= ~0x7F;
        !           168:                                mousetrack(b, 3*-dx, 3*-dy);
        !           169:                        }else{
        !           170:                                /* alt key + right mouse button == middle mouse button */
        !           171:                                if((d&0x2000))
        !           172:                                        altcmd |= 1;
        !           173:                                else if(!(d&0x2000))
        !           174:                                        altcmd &= ~1;
        !           175:                                mouseshifted = altcmd & 1;
        !           176:                                if((d&0x800))           /* left command */
        !           177:                                        altcmd |= 2;
        !           178:                                else if(!(d&0x800))
        !           179:                                        altcmd &= ~2;
        !           180:                                if(d & 0x4000){ /* right alt */
        !           181:                                        kbdstate(-1);
        !           182:                                        goto out;
        !           183:                                }
        !           184:                                if(d & 0x8000){ /* valid data */
        !           185:                                        if(d & 0x80){   /* up */
        !           186:                                                kbdrepeat(0);
        !           187:                                                goto out;
        !           188:                                        }
        !           189:                                        if(d & 0x100)
        !           190:                                                c = keyc[d&0x7f];
        !           191:                                        else if(d & 0x600)
        !           192:                                                c = keys[d&0x7f];
        !           193:                                        else
        !           194:                                                c = key0[d&0x7F];
        !           195:                                        kbdstate(c);
        !           196:                                }
        !           197:                        }
        !           198:                }
        !           199:     out:
        !           200:                if(*(ulong*)MONCSR & (1<<21)){
        !           201:                        /* keyboard overrun */
        !           202:                        *(ulong*)MONCSR |= (1<<21);
        !           203:                }
        !           204:        }
        !           205:        if(*(ulong*)MONCSR & (1<<19)){
        !           206:                print("kms interrupt\n");
        !           207:                if(*(ulong*)MONCSR & (1<<17)){
        !           208:                        print("kms overrun\n");
        !           209:                        *(ulong*)MONCSR |= (1<<17);
        !           210:                }
        !           211:                if(*(ulong*)MONCSR & (1<<18))
        !           212:                        print("kmsdata %lux\n", *(ulong*)KMSDATA);
        !           213:        }
        !           214: }
        !           215: 
        !           216: 
        !           217: void
        !           218: buzz(int freq, int dur)
        !           219: {
        !           220:        USED(freq, dur);
        !           221: }
        !           222: 
        !           223: void
        !           224: lights(int mask)
        !           225: {
        !           226:        USED(mask);
        !           227: }
        !           228: 
        !           229: int
        !           230: screenbits(void)
        !           231: {
        !           232:        return 2;       /* bits per pixel */
        !           233: }
        !           234: 
        !           235: void
        !           236: getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
        !           237: {
        !           238:        ulong ans;
        !           239: 
        !           240:        /*
        !           241:         * The next says 0 is white (max intensity)
        !           242:         */
        !           243:        switch(p){
        !           244:        case 0:         ans = ~0;               break;
        !           245:        case 1:         ans = 0xAAAAAAAA;       break;
        !           246:        case 2:         ans = 0x55555555;       break;
        !           247:        default:        ans = 0;                break;
        !           248:        }
        !           249:        *pr = *pg = *pb = ans;
        !           250: }
        !           251: 
        !           252: int
        !           253: setcolor(ulong p, ulong r, ulong g, ulong b)
        !           254: {
        !           255:        USED(p, r, g, b);
        !           256:        return 0;       /* can't change mono screen colormap */
        !           257: }
        !           258: 
        !           259: 
        !           260: /*
        !           261:  *  a fatter than usual cursor for the safari
        !           262:  */
        !           263: Cursor fatarrow = {
        !           264:        { -1, -1 },
        !           265:        {
        !           266:                0xff, 0xff, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0c, 
        !           267:                0x80, 0x10, 0x80, 0x10, 0x80, 0x08, 0x80, 0x04, 
        !           268:                0x80, 0x02, 0x80, 0x01, 0x80, 0x02, 0x8c, 0x04, 
        !           269:                0x92, 0x08, 0x91, 0x10, 0xa0, 0xa0, 0xc0, 0x40, 
        !           270:        },
        !           271:        {
        !           272:                0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfc, 0x7f, 0xf0, 
        !           273:                0x7f, 0xe0, 0x7f, 0xe0, 0x7f, 0xf0, 0x7f, 0xf8, 
        !           274:                0x7f, 0xfc, 0x7f, 0xfe, 0x7f, 0xfc, 0x73, 0xf8, 
        !           275:                0x61, 0xf0, 0x60, 0xe0, 0x40, 0x40, 0x00, 0x00, 
        !           276:        },
        !           277: };
        !           278: void
        !           279: bigcursor(void)
        !           280: {
        !           281:        extern Cursor arrow;
        !           282: 
        !           283:        memmove(&arrow, &fatarrow, sizeof(fatarrow));
        !           284: }
        !           285: 
        !           286: int
        !           287: hwgcmove(Point p)
        !           288: {
        !           289:        USED(p);
        !           290:        return 0;
        !           291: }
        !           292: 
        !           293: void
        !           294: setcursor(Cursor *curs)
        !           295: {
        !           296:        uchar *p;
        !           297:        int i;
        !           298:        extern GBitmap set, clr;
        !           299: 
        !           300:        for(i = 0; i < 16; i++){
        !           301:                p = (uchar*)&set.base[i];
        !           302:                *p = curs->set[2*i];
        !           303:                *(p+1) = curs->set[2*i+1];
        !           304:                p = (uchar*)&clr.base[i];
        !           305:                *p = curs->clr[2*i];
        !           306:                *(p+1) = curs->clr[2*i+1];
        !           307:        }
        !           308: }
        !           309: 
        !           310: /*
        !           311:  *  setup a serial mouse
        !           312:  */
        !           313: static void
        !           314: serialmouse(int port, char *type, int setspeed)
        !           315: {
        !           316:        if(mousetype)
        !           317:                error(Emouseset);
        !           318: 
        !           319:        if(port >= 2 || port < 0)
        !           320:                error(Ebadarg);
        !           321: 
        !           322:        /* set up /dev/eia0 as the mouse */
        !           323:        sccspecial(port, 0, &mouseq, setspeed ? 1200 : 0);
        !           324:        if(type && *type == 'M')
        !           325:                mouseq.putc = m3mouseputc;
        !           326:        mousetype = Mouseserial;
        !           327: }
        !           328: 
        !           329: /*
        !           330:  *  set/change mouse configuration
        !           331:  */
        !           332: void
        !           333: mousectl(char *arg)
        !           334: {
        !           335:        int n;
        !           336:        char *field[3];
        !           337: 
        !           338:        n = getfields(arg, field, 3, " ");
        !           339:        if(strncmp(field[0], "serial", 6) == 0){
        !           340:                switch(n){
        !           341:                case 1:
        !           342:                        serialmouse(atoi(field[0]+6), 0, 1);
        !           343:                        break;
        !           344:                case 2:
        !           345:                        serialmouse(atoi(field[1]), 0, 0);
        !           346:                        break;
        !           347:                case 3:
        !           348:                default:
        !           349:                        serialmouse(atoi(field[1]), field[2], 0);
        !           350:                        break;
        !           351:                }
        !           352:        }
        !           353:        else
        !           354:                error(Ebadctl);
        !           355: }

unix.superglobalmegacorp.com

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