Annotation of lucent/sys/src/9/gnot/screen.c, revision 1.1.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: 
                     20: struct{
                     21:        Point   pos;
                     22:        int     bwid;
                     23: }out;
                     24: 
                     25: Lock   screenlock;
                     26: 
                     27: GBitmap        gscreen =
                     28: {
                     29:        (ulong*)((1*1024*1024)|KZERO),  /* bootrom puts it here; changed by mmuinit */
                     30:        0,
                     31:        64,
                     32:        0,
                     33:        { 0, 0, 1024, 1024, },
                     34:        { 0, 0, 1024, 1024, },
                     35:        0
                     36: };
                     37: 
                     38: void
                     39: screeninit(void)
                     40: {
                     41:        /*
                     42:         * Read HEX switch to set ldepth
                     43:         */
                     44:        if(*(uchar*)MOUSE & (1<<4))
                     45:                gscreen.ldepth = 1;
                     46:        defont = &defont0;      /* save space; let bitblt do the conversion work */
                     47:        gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, 0);
                     48:        out.pos.x = MINX;
                     49:        out.pos.y = 0;
                     50:        out.bwid = defont0.info[' '].width;
                     51: }
                     52: 
                     53: void
                     54: screenputnl(void)
                     55: {
                     56:        out.pos.x = MINX;
                     57:        out.pos.y += defont0.height;
                     58:        if(out.pos.y > gscreen.r.max.y-defont0.height)
                     59:                out.pos.y = gscreen.r.min.y;
                     60:        gbitblt(&gscreen, Pt(0, out.pos.y), &gscreen,
                     61:            Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height), 0);
                     62: }
                     63: 
                     64: void
                     65: screenputs(char *s, int n)
                     66: {
                     67:        Rune r;
                     68:        int i;
                     69:        char buf[4];
                     70: 
                     71:        if(getsr() & 0x0700){
                     72:                if(!canlock(&screenlock))
                     73:                        return; /* don't deadlock trying to print in interrupt */
                     74:        }else
                     75:                lock(&screenlock);
                     76:        while(n > 0){
                     77:                i = chartorune(&r, s);
                     78:                if(i == 0){
                     79:                        s++;
                     80:                        --n;
                     81:                        continue;
                     82:                }
                     83:                memmove(buf, s, i);
                     84:                buf[i] = 0;
                     85:                n -= i;
                     86:                s += i;
                     87:                if(r == '\n')
                     88:                        screenputnl();
                     89:                else if(r == '\t'){
                     90:                        out.pos.x += (8-((out.pos.x-MINX)/out.bwid&7))*out.bwid;
                     91:                        if(out.pos.x >= gscreen.r.max.x)
                     92:                                screenputnl();
                     93:                }else if(r == '\b'){
                     94:                        if(out.pos.x >= out.bwid+MINX){
                     95:                                out.pos.x -= out.bwid;
                     96:                                gsubfstring(&gscreen, out.pos, defont, " ", S);
                     97:                        }
                     98:                }else{
                     99:                        if(out.pos.x >= gscreen.r.max.x-out.bwid)
                    100:                                screenputnl();
                    101:                        out.pos = gsubfstring(&gscreen, out.pos, defont, buf, S);
                    102:                }
                    103:        }
                    104:        unlock(&screenlock);
                    105: }
                    106: 
                    107: int
                    108: screenbits(void)
                    109: {
                    110:        if(*(uchar*)MOUSE & (1<<4))
                    111:                return 2;
                    112:        else
                    113:                return 1;
                    114: }
                    115: 
                    116: void
                    117: getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
                    118: {
                    119:        ulong ans;
                    120: 
                    121:        /*
                    122:         * The gnot says 0 is white (max intensity)
                    123:         */
                    124:        if(gscreen.ldepth == 0){
                    125:                if(p == 0)
                    126:                                ans = ~0;
                    127:                else
                    128:                                ans = 0;
                    129:        }else{
                    130:                switch(p){
                    131:                case 0:         ans = ~0;               break;
                    132:                case 1:         ans = 0xAAAAAAAA;       break;
                    133:                case 2:         ans = 0x55555555;       break;
                    134:                default:        ans = 0;                break;
                    135:                }
                    136:        }
                    137:        *pr = *pg = *pb = ans;
                    138: }
                    139: 
                    140: int
                    141: setcolor(ulong p, ulong r, ulong g, ulong b)
                    142: {
                    143:        USED(p, r, g, b);
                    144:        return 0;       /* can't change mono screen colormap */
                    145: }
                    146: 
                    147: int
                    148: hwgcmove(Point p)
                    149: {
                    150:        USED(p);
                    151:        return 0;
                    152: }
                    153: 
                    154: void
                    155: setcursor(Cursor *curs)
                    156: {
                    157:        uchar *p;
                    158:        int i;
                    159:        extern GBitmap set, clr;
                    160: 
                    161:        for(i = 0; i < 16; i++){
                    162:                p = (uchar*)&set.base[i];
                    163:                *p = curs->set[2*i];
                    164:                *(p+1) = curs->set[2*i+1];
                    165:                p = (uchar*)&clr.base[i];
                    166:                *p = curs->clr[2*i];
                    167:                *(p+1) = curs->clr[2*i+1];
                    168:        }
                    169: }
                    170: 
                    171: /* only 1 flavor mouse */
                    172: void
                    173: mousectl(char *x)
                    174: {
                    175:        USED(x);
                    176: }

unix.superglobalmegacorp.com

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