| plan 9 kernel history: overview | file list | diff list |
1991/0706/port/devbit.c (diff list | history)
| 1991/0701/sys/src/9/port/devbit.c:6,12 – 1991/0706/sys/src/9/port/devbit.c:6,11 (short | long | prev | next) | ||
|
Created.
rsc Fri Mar 4 12:44:25 2005 | ||
| 1990/0324 | #include "errno.h" #include "devtab.h" | |
| 1991/0423 |
| |
| 1990/0324 | ||
| 1990/0912 | #include <libg.h> | |
| 1990/0902 | #include <gnot.h> | |
| 1991/0701/sys/src/9/port/devbit.c:14,19 – 1991/0706/sys/src/9/port/devbit.c:13,37 | ||
| 1990/0902 | extern GFont *defont; | |
| 1990/0329 | ||
| 1990/0327 | /* | |
| 1991/0706 | * Some monochrome screens are reversed from what we like: * We want 0's bright and 1s dark. * Indexed by an Fcode, these compensate for the source bitmap being wrong * (exchange S rows) and destination (exchange D columns and invert result) */ int flipS[] = { 0x0, 0x4, 0x8, 0xC, 0x1, 0x5, 0x9, 0xD, 0x2, 0x6, 0xA, 0xE, 0x3, 0x7, 0xB, 0xF }; int flipD[] = { 0xF, 0xD, 0xE, 0xC, 0x7, 0x5, 0x6, 0x4, 0xB, 0x9, 0xA, 0x8, 0x3, 0x1, 0x2, 0x0, }; int flipping; /* are flip tables being used to transform Fcodes? */ int hwcursor; /* is there a hardware cursor? */ /* | |
| 1990/0329 | * Device (#b/bitblt) is exclusive use on open, so no locks are necessary * for i/o */ | |
| 1991/0701/sys/src/9/port/devbit.c:41,66 – 1991/0706/sys/src/9/port/devbit.c:59,83 | ||
| 1990/0613 | int rid; /* read bitmap id */ int rminy; /* read miny */ int rmaxy; /* read maxy */ | |
| 1991/0706 | int mid; /* colormap read bitmap id */ | |
| 1990/0324 | }bit; | |
| 1990/0327 | #define FREE 0x80000000 void bitcompact(void); | |
| 1990/0902 | void bitfree(GBitmap*); | |
| 1991/0423 |
| |
| 1990/0912 | extern GBitmap gscreen; | |
| 1990/0327 | ||
| 1990/0504 | struct{ /* | |
| 1991/0706 | * First four fields are known in screen.c | |
| 1990/0504 | */ int dx; /* interrupt-time delta */ int dy; int track; /* update cursor on screen */ | |
| 1991/0423 |
| |
| 1990/0504 | Mouse; int changed; /* mouse structure changed since last read */ | |
| 1990/0505 |
| |
| 1990/0504 | Rendez r; | |
| 1991/0706 | int newbuttons; /* interrupt time access only */ | |
| 1990/0504 | }mouse; | |
| 1990/05313 | Cursor arrow = | |
| 1991/0701/sys/src/9/port/devbit.c:105,111 – 1991/0706/sys/src/9/port/devbit.c:122,128 | ||
| 1990/0504 | {0, 0, 16, 16} }; | |
| 1991/0706 | ulong cursorbackbits[16*4]; | |
| 1990/0902 | GBitmap cursorback = | |
| 1990/0504 | { cursorbackbits, | |
| 1991/0701/sys/src/9/port/devbit.c:141,146 – 1991/0706/sys/src/9/port/devbit.c:158,164 | ||
| 1990/0324 | { | |
| 1990/0327 | int i; | |
| 1990/0902 | GBitmap *bp; | |
| 1991/0706 | ulong r; | |
| 1990/0327 | ||
| 1990/0902 | bit.map = ialloc(conf.nbitmap * sizeof(GBitmap), 0); | |
| 1990/0327 | for(i=0,bp=bit.map; i<conf.nbitmap; i++,bp++){ | |
| 1991/0701/sys/src/9/port/devbit.c:150,155 – 1991/0706/sys/src/9/port/devbit.c:168,176 | ||
| 1990/0327 | bp--; bp->base = 0; | |
| 1990/0912 | bit.map[0] = gscreen; /* bitmap 0 is screen */ | |
| 1991/0706 | getcolor(0, &r, &r, &r); if(r == 0) flipping = 1; | |
| 1990/0327 | bit.free = bit.map+1; bit.lastid = -1; | |
| 1990/0623 | bit.lastfid = -1; | |
| 1991/0701/sys/src/9/port/devbit.c:168,176 – 1991/0706/sys/src/9/port/devbit.c:189,200 | ||
| 1990/0324 | { lock(&bit); unlock(&bit); | |
| 1990/0912 |
| |
| 1990/05313 |
| |
| 1990/0912 |
| |
| 1991/0706 | if(gscreen.ldepth > 3) cursorback.ldepth = 0; else { cursorback.ldepth = gscreen.ldepth; cursorback.width = ((16 << gscreen.ldepth) + 31) >> 5; } | |
| 1990/0504 | cursoron(1); | |
| 1990/0324 | } | |
| 1991/0701/sys/src/9/port/devbit.c:186,191 – 1991/0706/sys/src/9/port/devbit.c:210,216 | ||
| 1990/0324 | nc = devclone(c, nc); | |
| 1990/11211 | if(c->qid.path != CHDIR) | |
| 1990/0324 | incref(&bit); | |
| 1991/0706 | return nc; | |
| 1990/0324 | } int | |
| 1991/0701/sys/src/9/port/devbit.c:215,220 – 1991/0706/sys/src/9/port/devbit.c:240,246 | ||
| 1990/0327 | bit.lastid = -1; | |
| 1990/0623 | bit.lastfid = -1; | |
| 1990/0613 | bit.rid = -1; | |
| 1991/0706 | bit.mid = -1; | |
| 1990/0604 | bit.init = 0; | |
| 1990/05151 | bit.ref = 1; | |
| 1990/05313 | Cursortocursor(&arrow); | |
| 1991/0701/sys/src/9/port/devbit.c:272,278 – 1991/0706/sys/src/9/port/devbit.c:298,305 | ||
| 1990/0327 | ||
| 1990/0329 | /* * These macros turn user-level (high bit at left) into internal (whatever) | |
| 1991/0706 | * bit order. So far all machines have the same (good) order; when * that changes, these should switch on a variable set at init time. | |
| 1990/0329 | */ #define U2K(x) (x) #define K2U(x) (x) | |
| 1991/0701/sys/src/9/port/devbit.c:282,288 – 1991/0706/sys/src/9/port/devbit.c:309,315 | ||
| 1990/0324 | { | |
| 1990/0613 | uchar *p, *q; long miny, maxy, t, x, y; | |
| 1991/0706 | ulong l, nw, ws, rv, gv, bv; | |
| 1990/06231 | int off, j; Fontchar *i; | |
| 1990/0902 | GBitmap *src; | |
| 1991/0701/sys/src/9/port/devbit.c:387,395 – 1991/0706/sys/src/9/port/devbit.c:414,449 | ||
| 1990/0623 | n = 3; break; } | |
| 1991/0706 | if(bit.mid >= 0){ /* * read colormap: * data 12*(2**bitmapdepth) */ l = (1<<bit.map[bit.mid].ldepth); nw = 1 << l; if(n < 12*nw) error(Ebadblt); for(j = 0; j < nw; j++){ if(bit.mid == 0){ getcolor(flipping? ~j : j, &rv, &gv, &bv); }else{ rv = j; for(off = 32-l; off > 0; off -= l) rv = (rv << l) | j; gv = bv = rv; } PLONG(p, rv); PLONG(p+4, gv); PLONG(p+8, bv); p += 12; } bit.mid = -1; n = 12*nw; break; } | |
| 1990/0613 | if(bit.rid >= 0){ /* | |
| 1991/0706 | * read bitmap: | |
| 1990/0613 | * data bytewidth*(maxy-miny) */ src = &bit.map[bit.rid]; | |
| 1991/0701/sys/src/9/port/devbit.c:420,427 – 1991/0706/sys/src/9/port/devbit.c:474,485 | ||
| 1990/0613 | for(y=miny; y<maxy; y++){ | |
| 1990/0912 | q = (uchar*)gaddr(src, Pt(src->r.min.x, y)); | |
| 1990/0911 | q += (src->r.min.x&((sizeof(ulong))*ws-1))/ws; | |
| 1990/0613 |
| |
| 1991/0706 | if(bit.rid == 0 && flipping) /* flip bits */ for(x=0; x<l; x++) *p++ = ~K2U(*q++); else for(x=0; x<l; x++) *p++ = K2U(*q++); | |
| 1990/0613 | n += l; } if(off) | |
| 1991/0701/sys/src/9/port/devbit.c:473,484 – 1991/0706/sys/src/9/port/devbit.c:531,543 | ||
| 1991/0411 | bitwrite(Chan *c, void *va, long n, ulong offset) | |
| 1990/0324 | { | |
| 1990/0329 | uchar *p, *q; | |
| 1990/1011 |
| |
| 1990/0327 |
| |
| 1990/0721 |
| |
| 1991/0706 | long m, v, miny, maxy, minx, maxx, t, x, y; ulong l, nw, ws, rv; int off, isoff, i, ok; | |
| 1990/06111 | Point pt, pt1, pt2; | |
| 1990/0324 | Rectangle rect; | |
| 1990/05313 | Cursor curs; | |
| 1991/0706 | Fcode fc; | |
| 1990/0623 | Fontchar *fcp; | |
| 1990/0902 | GBitmap *bp, *src, *dst; GFont *f; | |
| 1991/0701/sys/src/9/port/devbit.c:514,520 – 1991/0706/sys/src/9/port/devbit.c:573,579 | ||
| 1990/0327 | if(m < 18) | |
| 1990/11211 | error(Ebadblt); | |
| 1990/0327 | v = *(p+1); | |
| 1990/05313 |
| |
| 1991/0706 | if(v>3) /* BUG */ | |
| 1990/11211 | error(Ebadblt); | |
| 1990/0327 | ws = 1<<(5-v); /* pixels per word */ if(bit.free == 0) | |
| 1991/0701/sys/src/9/port/devbit.c:572,602 – 1991/0706/sys/src/9/port/devbit.c:631,667 | ||
| 1990/0327 | */ if(m < 31) | |
| 1990/11211 | error(Ebadblt); | |
| 1991/0706 | fc = GSHORT(p+29) & 0xF; v = GSHORT(p+11); src = &bit.map[v]; if(v<0 || v>=conf.nbitmap || src->ldepth < 0) error(Ebadbitmap); off = 0; if(v == 0){ if(flipping) fc = flipS[fc]; off = 1; } | |
| 1990/0327 | v = GSHORT(p+1); dst = &bit.map[v]; if(v<0 || v>=conf.nbitmap || dst->ldepth < 0) | |
| 1990/11211 | error(Ebadbitmap); | |
| 1990/0504 |
| |
| 1991/0706 | if(v == 0){ if(flipping) fc = flipD[fc]; | |
| 1990/0504 | off = 1; | |
| 1991/0706 | } | |
| 1990/0327 | pt.x = GLONG(p+3); pt.y = GLONG(p+7); | |
| 1990/11211 |
| |
| 1990/0504 |
| |
| 1990/0327 | rect.min.x = GLONG(p+13); rect.min.y = GLONG(p+17); rect.max.x = GLONG(p+21); rect.max.y = GLONG(p+25); | |
| 1990/0721 | if(off && !isoff){ | |
| 1990/0504 | cursoroff(1); | |
| 1990/0721 | isoff = 1; } | |
| 1990/1219 |
| |
| 1991/0706 | gbitblt(dst, pt, src, rect, fc); | |
| 1990/0327 | m -= 31; p += 31; break; | |
| 1991/0701/sys/src/9/port/devbit.c:744,766 – 1991/0706/sys/src/9/port/devbit.c:809,852 | ||
| 1990/0623 | if(v<0 || v>=conf.nbitmap || dst->ldepth<0) | |
| 1990/11211 | error(Ebadbitmap); | |
| 1990/06111 | off = 0; | |
| 1991/0706 | fc = GSHORT(p+20) & 0xF; if(v == 0){ if(flipping) fc = flipD[fc]; | |
| 1990/06111 | off = 1; | |
| 1991/0706 | } | |
| 1990/06111 | pt1.x = GLONG(p+3); pt1.y = GLONG(p+7); pt2.x = GLONG(p+11); pt2.y = GLONG(p+15); t = p[19]; | |
| 1990/0721 | if(off && !isoff){ | |
| 1990/06111 | cursoroff(1); | |
| 1990/0721 | isoff = 1; } | |
| 1990/0902 |
| |
| 1991/0706 | gsegment(dst, pt1, pt2, t, fc); | |
| 1990/06111 | m -= 22; p += 22; | |
| 1990/0613 | break; | |
| 1991/0706 | case 'm': /* * read colormap * * 'm' 1 * id 2 */ if(m < 3) error(Ebadblt); v = GSHORT(p+1); dst = &bit.map[v]; if(v<0 || v>=conf.nbitmap || dst->ldepth<0) error(Ebadbitmap); bit.mid = v; m -= 3; p += 3; break; | |
| 1990/0722 | case 'p': /* * point | |
| 1991/0701/sys/src/9/port/devbit.c:778,794 – 1991/0706/sys/src/9/port/devbit.c:864,883 | ||
| 1990/0722 | if(v<0 || v>=conf.nbitmap || dst->ldepth<0) | |
| 1990/11211 | error(Ebadbitmap); | |
| 1990/0722 | off = 0; | |
| 1991/0706 | fc = GSHORT(p+12) & 0xF; if(v == 0){ if(flipping) fc = flipD[fc]; | |
| 1990/0722 | off = 1; | |
| 1991/0706 | } | |
| 1990/0722 | pt1.x = GLONG(p+3); pt1.y = GLONG(p+7); t = p[11]; | |
| 1990/0902 |
| |
| 1991/0706 | gpoint(dst, pt1, t, fc); | |
| 1990/0722 | m -= 14; p += 14; break; | |
| 1991/0701/sys/src/9/port/devbit.c:835,842 – 1991/0706/sys/src/9/port/devbit.c:924,935 | ||
| 1990/0623 | if(v<0 || v>=conf.nbitmap || dst->ldepth<0) | |
| 1990/11211 | error(Ebadbitmap); | |
| 1990/0504 | off = 0; | |
| 1991/0706 | fc = GSHORT(p+13) & 0xF; if(v == 0){ if(flipping) fc = flipD[fc]; | |
| 1990/0504 | off = 1; | |
| 1991/0706 | } | |
| 1990/0329 | pt.x = GLONG(p+3); pt.y = GLONG(p+7); v = GSHORT(p+11); | |
| 1991/0701/sys/src/9/port/devbit.c:843,849 – 1991/0706/sys/src/9/port/devbit.c:936,941 | ||
| 1990/0623 | f = &bit.font[v]; if(v<0 || v>=conf.nfont || f->bits==0 || f->bits->ldepth<0) | |
| 1990/11211 | error(Ebadblt); | |
| 1990/0329 |
| |
| 1991/0701/sys/src/9/port/devbit.c:853,859 – 1991/0706/sys/src/9/port/devbit.c:945,951 | ||
| 1990/0504 | cursoroff(1); | |
| 1990/0721 | isoff = 1; } | |
| 1990/0902 |
| |
| 1991/0706 | gstring(dst, pt, f, (char*)p, fc); | |
| 1990/0329 | q++; m -= q-p; p = q; | |
| 1991/0701/sys/src/9/port/devbit.c:875,882 – 1991/0706/sys/src/9/port/devbit.c:967,978 | ||
| 1990/0623 | if(v<0 || v>=conf.nbitmap || dst->ldepth<0) | |
| 1990/11211 | error(Ebadbitmap); | |
| 1990/0504 | off = 0; | |
| 1991/0706 | fc = GSHORT(p+21) & 0xF; if(v == 0){ if(flipping) fc = flipD[fc]; | |
| 1990/0504 | off = 1; | |
| 1991/0706 | } | |
| 1990/0329 | rect.min.x = GLONG(p+3); rect.min.y = GLONG(p+7); rect.max.x = GLONG(p+11); | |
| 1991/0701/sys/src/9/port/devbit.c:885,896 – 1991/0706/sys/src/9/port/devbit.c:981,991 | ||
| 1990/0329 | src = &bit.map[v]; | |
| 1990/0623 | if(v<0 || v>=conf.nbitmap || src->ldepth<0) | |
| 1990/11211 | error(Ebadbitmap); | |
| 1990/0329 |
| |
| 1991/0701 | if(off && !isoff){ cursoroff(1); isoff = 1; | |
| 1990/0329 | } | |
| 1991/0701 |
| |
| 1991/0706 | gtexture(dst, rect, src, fc); | |
| 1990/0329 | m -= 23; p += 23; break; | |
| 1991/0701/sys/src/9/port/devbit.c:937,944 – 1991/0706/sys/src/9/port/devbit.c:1032,1043 | ||
| 1990/0329 | for(y=miny; y<maxy; y++){ | |
| 1990/0912 | q = (uchar*)gaddr(dst, Pt(dst->r.min.x, y)); | |
| 1990/0911 | q += (dst->r.min.x&((sizeof(ulong))*ws-1))/ws; | |
| 1990/0329 |
| |
| 1991/0706 | if(v == 0 && flipping) /* flip bits */ for(x=0; x<l; x++) *q++ = ~U2K(*p++); else for(x=0; x<l; x++) *q++ = U2K(*p++); | |
| 1990/0329 | m -= l; } break; | |
| 1991/0701/sys/src/9/port/devbit.c:954,960 – 1991/0706/sys/src/9/port/devbit.c:1053,1059 | ||
| 1990/11211 | error(Ebadblt); | |
| 1990/0826 | pt1.x = GLONG(p+1); pt1.y = GLONG(p+5); | |
| 1991/0619 |
| |
| 1991/0706 | /* if(!eqpt(mouse.xy, pt1))*/{ | |
| 1991/0619 | mouse.xy = pt1; mouse.track = 1; mouseclock(); | |
| 1991/0701/sys/src/9/port/devbit.c:962,967 – 1991/0706/sys/src/9/port/devbit.c:1061,1098 | ||
| 1990/0826 | m -= 9; p += 9; break; | |
| 1991/0706 | case 'z': /* * write the colormap * * 'z' 1 * id 2 * map 12*(2**bitmapdepth) */ if(m < 3) error(Ebadblt); v = GSHORT(p+1); if(v != 0) error(Ebadbitmap); m -= 3; p += 3; nw = 1 << (1 << bit.map[v].ldepth); if(m < 12*nw) error(Ebadblt); ok = 1; for(i = 0; i < nw; i++){ ok &= setcolor(i, GLONG(p), GLONG(p+4), GLONG(p+8)); p += 12; m -= 12; } if(!ok){ /* assume monochrome: possibly change flipping */ l = GLONG(p-12); getcolor(nw-1, &rv, &rv, &rv); flipping = (l != rv); } break; | |
| 1990/0327 | } | |
| 1991/0614 | poperror(); | |
| 1991/0701/sys/src/9/port/devbit.c:1011,1018 – 1991/0706/sys/src/9/port/devbit.c:1142,1147 | ||
| 1990/0327 | p1 += 2 + p1[0]; } bit.wfree = p1; | |
| 1991/0329 |
| |
| 1990/08101 | qunlock(&bitlock); | |
| 1990/0329 | } | |
| 1991/0701/sys/src/9/port/devbit.c:1041,1049 – 1991/0706/sys/src/9/port/devbit.c:1170,1178 | ||
| 1990/0504 | cursor.r = raddp(cursor.r, cursor.offset); | |
| 1990/0912 | gbitblt(&cursorback, Pt(0, 0), &gscreen, cursor.r, S); gbitblt(&gscreen, add(mouse.xy, cursor.offset), | |
| 1990/0504 |
| |
| 1991/0706 | &clr, Rect(0, 0, 16, 16), flipping? flipD[D&~S] : D&~S); | |
| 1990/0912 | gbitblt(&gscreen, add(mouse.xy, cursor.offset), | |
| 1990/0504 |
| |
| 1991/0706 | &set, Rect(0, 0, 16, 16), flipping? flipD[S|D] : S|D); | |
| 1990/0504 | } if(dolock) unlock(&cursor); | |
| 1991/0701/sys/src/9/port/devbit.c:1061,1068 – 1991/0706/sys/src/9/port/devbit.c:1190,1206 | ||
| 1990/0504 | } void | |
| 1990/0505 |
| |
| 1991/0706 | mousedelta(int b, int dx, int dy) /* called at higher priority */ | |
| 1990/0504 | { | |
| 1991/0706 | mouse.dx += dx; mouse.dy += dy; mouse.newbuttons = b; mouse.track = 1; } void mousebuttons(int b) /* called at higher priority */ { | |
| 1990/0505 | /* * It is possible if you click very fast and get bad luck * you could miss a button click (down up). Doesn't seem | |
| 1991/0701/sys/src/9/port/devbit.c:1074,1093 – 1991/0706/sys/src/9/port/devbit.c:1212,1239 | ||
| 1990/0504 | } void | |
| 1990/0505 |
| |
| 1991/0706 | mouseclock(void) /* called splhi */ | |
| 1990/0504 | { | |
| 1991/0423 |
| |
| 1991/0706 | int x, y; if(mouse.track && canlock(&cursor)){ x = mouse.xy.x + mouse.dx; if(x < gscreen.r.min.x) x = gscreen.r.min.x; if(x >= gscreen.r.max.x) x = gscreen.r.max.x; y = mouse.xy.y + mouse.dy; if(y < gscreen.r.min.y) y = gscreen.r.min.y; if(y >= gscreen.r.max.y) y = gscreen.r.max.y; cursoroff(0); mouse.xy = Pt(x, y); cursoron(0); mouse.dx = 0; mouse.dy = 0; mouse.track = 0; mouse.buttons = mouse.newbuttons; mouse.changed = 1; | |
| 1991/0423 | unlock(&cursor); wakeup(&mouse.r); } | |
| 1991/0701/sys/src/9/port/devbit.c:1096,1137 – 1991/0706/sys/src/9/port/devbit.c:1242,1263 | ||
| 1991/0605 | int mouseputc(IOQ *q, int c) { | |
| 1991/0706 | static short msg[5]; static int nb; static uchar b[] = {0, 4, 2, 6, 1, 5, 3, 7}; | |
| 1991/0605 | ||
| 1991/0423 |
| |
| 1990/0504 |
| |
| 1991/0423 |
| |
| 1990/0504 |
| |
| 1991/0706 | if((c&0xF0) == 0x80) nb=0; msg[nb] = c; if(c & 0x80) msg[nb] |= 0xFF00; /* sign extend */ if(++nb == 5){ mouse.newbuttons = b[(msg[0]&7)^7]; mouse.dx = msg[1]+msg[3]; mouse.dy = -(msg[2]+msg[4]); mouse.track = 1; mouseclock(); nb = 0; | |
| 1990/0329 | } | |
| 1990/0505 | } | |