From 093dd92752e2630106ae4489e5f39f5cc438d1ee Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 13 Apr 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-04-13 --- carrera/main.c | 2 +- carrera/screen.c | 82 +++++++++++----------------- pc/bbmalloc.c | 81 ---------------------------- pc/devconfig.c | 1 - pc/devhard.c | 16 +++--- pc/devvga.c | 56 ++++++++++--------- pc/kbd.c | 1 - port/devcons.c | 13 +++++ port/devmouse.c | 137 +++++++++++++++++++++++++++++++---------------- 9 files changed, 173 insertions(+), 216 deletions(-) delete mode 100644 pc/bbmalloc.c diff --git a/carrera/main.c b/carrera/main.c index fe74314ffb6d4ef880ea3e7a990ac5a02b42378b..ef2d4c89ddbb5b6f0dfb4e93414e79a02d6f3653 100644 --- a/carrera/main.c +++ b/carrera/main.c @@ -503,7 +503,7 @@ rdbginit(void) { uchar *vec; ulong jba; -/*return;/**/ +return;/**/ /* Only interested in the PC */ Mipsjmpbuf.pc = 0x8001C020; diff --git a/carrera/screen.c b/carrera/screen.c index dbe6439d8f3ddcac4ea5928b639a9f16925c9758..79ef3add43e12b35239230f74d6201b47907b4ec 100644 --- a/carrera/screen.c +++ b/carrera/screen.c @@ -8,7 +8,6 @@ #include "../port/error.h" #include -#include #include "screen.h" #define MINX 8 @@ -29,8 +28,7 @@ struct Dac char s1[] = { 0x00, 0x00, 0xC0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - GSubfont* defont; -extern GSubfont defont0; +extern Subfont defont0; static ulong rep(ulong, int); struct{ @@ -40,25 +38,26 @@ struct{ Lock screenlock; -GBitmap gscreen = +Bitmap gscreen = { + { 0, 0, 1600, 1240 }, + { 0, 0, 1600, 1240 }, + 3, Screenvirt+0x00017924, 0, 512, - 3, - { 0, 0, 1600, 1240 }, - { 0, 0, 1600, 1240 }, 0 }; -static GBitmap hwcursor= +static Bitmap hwcursor= { + {0, 0, 64, 64}, + {0, 0, 64, 64}, + 1, 0, /* base filled in by malloc when needed */ 0, 4, - 1, - {0, 0, 64, 64}, - {0, 0, 64, 64} + 0, }; uchar bdata[] = @@ -66,14 +65,14 @@ uchar bdata[] = 0xC0, }; -GBitmap bgrnd = +Bitmap bgrnd = { + { 0, 0, 1, 1 }, + { 0, 0, 1, 1 }, + 3, (ulong*)bdata, 0, 4, - 3, - { 0, 0, 1, 1 }, - { 0, 0, 1, 1 }, 0 }; @@ -98,22 +97,6 @@ static Point cursor; static int h, w; extern Cursor arrow; -void -gborder(GBitmap *l, Rectangle r, int i, Fcode c) -{ - if(i < 0){ - r = inset(r, i); - i = -i; - } - gbitblt(l, r.min, l, Rect(r.min.x, r.min.y, r.max.x, r.min.y+i), c); - gbitblt(l, Pt(r.min.x, r.max.y-i), - l, Rect(r.min.x, r.max.y-i, r.max.x, r.max.y), c); - gbitblt(l, Pt(r.min.x, r.min.y+i), - l, Rect(r.min.x, r.min.y+i, r.min.x+i, r.max.y-i), c); - gbitblt(l, Pt(r.max.x-i, r.min.y+i), - l, Rect(r.max.x-i, r.min.y+i, r.max.x, r.max.y-i), c); -} - void screenwin(void) { @@ -124,23 +107,24 @@ screenwin(void) memset((void*)Screenvirt, 0xff, 3*1024*1024); - gtexture(&gscreen, gscreen.r, &bgrnd, S); + texture(&gscreen, gscreen.r, &bgrnd, S); w = defont0.info[' '].width; h = defont0.height; window.min = Pt(100, 100); window.max = add(window.min, Pt(10+w*120, 10+h*60)); - gbitblt(&gscreen, add(window.min, Pt(5, 5)), &gscreen, window, F); - gbitblt(&gscreen, window.min, &gscreen, window, Zero); - gborder(&gscreen, window, 4, F); + bitblt(&gscreen, add(window.min, Pt(5, 5)), &gscreen, window, F); + bitblt(&gscreen, window.min, &gscreen, window, Zero); + border(&gscreen, window, 4, F); window = inset(window, 5); for(i = 0; i < h+6; i += 2) { y = window.min.y+i; - gsegment(&gscreen, Pt(window.min.x, y), Pt(window.max.x, y), ~0, F); + bitblt(&gscreen, Pt(window.min.x, y), + &gscreen, Rect(window.min.x, y, window.max.x, y+1), F); } p = add(window.min, Pt(10, 2)); - gsubfstring(&gscreen, p, &defont0, "Brazil Console ", S); + subfstring(&gscreen, p, &defont0, "Brazil Console ", S); window.min.y += h+6; cursor = window.min; window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h; @@ -240,8 +224,7 @@ screeninit(void) memmove(&arrow, &fatarrow, sizeof(fatarrow)); - defont = &defont0; - gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, 0); + bitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, 0); out.pos.x = MINX; out.pos.y = 0; out.bwid = defont0.info[' '].width; @@ -266,9 +249,9 @@ scroll(void) o = 5*h; r = Rpt(Pt(window.min.x, window.min.y+o), window.max); - gbitblt(&gscreen, window.min, &gscreen, r, S); + bitblt(&gscreen, window.min, &gscreen, r, S); r = Rpt(Pt(window.min.x, window.max.y-o), window.max); - gbitblt(&gscreen, r.min, &gscreen, r, Zero); + bitblt(&gscreen, r.min, &gscreen, r, Zero); cursor.y -= o; } @@ -299,14 +282,14 @@ screenputc(char *buf) r.max.x = cursor.x; r.min.y = cursor.y; r.max.y = cursor.y+defont0.height; - gbitblt(&gscreen, r.min, &gscreen, r, Zero); + bitblt(&gscreen, r.min, &gscreen, r, Zero); cursor.x -= w; } break; default: if(cursor.x >= window.max.x-w) screenputc("\n"); - cursor = gsubfstring(&gscreen, cursor, &defont0, buf, S); + cursor = subfstring(&gscreen, cursor, &defont0, buf, S); } } @@ -443,7 +426,7 @@ hwcursset(ulong *s, ulong *c, int offx, int offy) spix = (s[y]>>(31-(x&0x1F)))&1; cpix = (c[y]>>(31-(x&0x1F)))&1; dpix = (spix<<1) | cpix; - gpoint(&hwcursor, add(Pt(x,y), org), dpix, S); + point(&hwcursor, add(Pt(x,y), org), dpix, S); } d = DAC; @@ -514,7 +497,7 @@ screenload(Rectangle r, uchar *data, int tl, int l, int dolock) return; lock(&screenlock); - q = gbaddr(&gscreen, r.min); + q = byteaddr(&gscreen, r.min); for(y=r.min.y; y= 3 + * gscreen.ldepth is known to be >= 3. + * screenunload() doesn't clip, so must be + * called correctly. */ void screenunload(Rectangle r, uchar *data, int tl, int l, int dolock) @@ -538,11 +523,8 @@ screenunload(Rectangle r, uchar *data, int tl, int l, int dolock) USED(dolock); - if(!rectclip(&r, gscreen.r) || tl<=0) - return; - lock(&screenlock); - q = gbaddr(&gscreen, r.min); + q = byteaddr(&gscreen, r.min); for(y=r.min.y; y3 bitblt can take 900 words */ -enum { - narena=2, /* put interrupt time stuff in separate arena */ - nbbarena=4096 /* number of words in an arena */ -}; - -static ulong bbarena[narena][nbbarena+LINEWORDS]; -static ulong *bbcur[narena] = {&bbarena[0][0], &bbarena[1][0]}; -static ulong *bblast[narena] = {0, 0}; - -#define INTLEVEL(v) (((v)&(1<<9)) == 0) -void * -bbmalloc(int nbytes) -{ - int nw, a; - int s; - ulong *ans; - - nw = nbytes/sizeof(long); - s = splhi(); - a = INTLEVEL(s)? 1 : 0; - if(bbcur[a] + nw > &bbarena[a][nbbarena]) - ans = bbarena[a]; - else - ans = bbcur[a]; - bbcur[a] = ans + nw + (LINEWORDS); - splx(s); - - bblast[a] = ans; - return ans; -} - -void -bbfree(void *p, int n) -{ - int a, s; - - s = splhi(); - a = INTLEVEL(s)? 1 : 0; - if(p == bblast[a]) - bbcur[a] = (ulong *)(((char *)bblast[a]) + n + LINEWORDS*sizeof(long)); - splx(s); -} - -int -bbonstack(void) -{ - /*if(u) - return 1;*/ - return 0; -} - -void -bbexec(void (*memstart)(void), int len, int onstack) -{ - memstart(); - if(onstack) - return; - bbfree(memstart, len); -} diff --git a/pc/devconfig.c b/pc/devconfig.c index 77c61d50c1d7142e6f4994ace1870d76e81a09ac..4bad0f7f71d42ef341801cff41975b4121e034c6 100644 --- a/pc/devconfig.c +++ b/pc/devconfig.c @@ -7,7 +7,6 @@ #include "../port/error.h" #include -#include #include "devtab.h" #include "vga.h" diff --git a/pc/devhard.c b/pc/devhard.c index 193474ccf6052503f7b716ce884f9ebc2d756628..6eb88003abe90f286a2e309366adbc54b3a63abd 100644 --- a/pc/devhard.c +++ b/pc/devhard.c @@ -993,6 +993,15 @@ hardintr(Ureg *ur, void *arg) break; case Cread: case Cident: + loop = 0; + while((cp->status & (Serr|Sdrq)) == 0){ + if(++loop > 10000) { + DPRINT("cmd=%lux status=%lux\n", + cp->cmd, inb(cp->pbase+Pstatus)); + panic("hardintr: read/ident"); + } + cp->status = inb(cp->pbase+Pstatus); + } if(cp->status & Serr){ cp->lastcmd = cp->cmd; cp->cmd = 0; @@ -1000,13 +1009,6 @@ hardintr(Ureg *ur, void *arg) wakeup(&cp->r); return; } - loop = 0; - while((inb(cp->pbase+Pstatus) & Sdrq) == 0) - if(++loop > 10000) { - DPRINT("cmd=%lux status=%lux\n", - cp->cmd, inb(cp->pbase+Pstatus)); - panic("hardintr: read/ident"); - } addr = cp->buf; if(addr){ addr += cp->sofar*dp->bytes; diff --git a/pc/devvga.c b/pc/devvga.c index 97e6cce1498cb73a355c363a2f1e55b445ed61f5..98fb23f7b6ec194bc84eff5a9133eb9477d68b02 100644 --- a/pc/devvga.c +++ b/pc/devvga.c @@ -7,7 +7,6 @@ #include "../port/error.h" #include -#include enum { @@ -38,12 +37,12 @@ enum }; /* imported */ -extern GSubfont defont0; +extern Subfont defont0; extern Cursor arrow; /* exported */ -GSubfont *defont; -GBitmap gscreen; +Subfont *defont; +Bitmap gscreen; /* vga screen */ static Lock screenlock; @@ -55,7 +54,7 @@ static int cga = 1; /* true if in cga mode */ /* system window */ static Rectangle window; static int h, w; -static Point cursor; +static Point curpos; /* * screen dimensions @@ -184,6 +183,9 @@ static void scroll(void); static ulong x3to32(uchar); static ulong x6to32(uchar); +extern void cursorlock(Rectangle); +extern void cursorunlock(void); + /* * vga device */ @@ -392,9 +394,8 @@ screeninit(void) /* * swizzle the font longs. */ - defont = &defont0; - l = defont->bits->base; - for(i = defont->bits->width*Dy(defont->bits->r); i > 0; i--, l++) + l = defont0.bits->base; + for(i = defont0.bits->width*Dy(defont0.bits->r); i > 0; i--, l++) *l = (*l<<24) | ((*l>>8)&0x0000ff00) | ((*l<<8)&0x00ff0000) | (*l>>24); /* @@ -498,9 +499,9 @@ setscreen(int maxx, int maxy, int ldepth) window.max = add(window.min, Pt(10+w*64, Footprint/(BY2WD*gscreen.width))); vgacard->setpage(0); - gbitblt(&gscreen, window.min, &gscreen, window, Zero); + bitblt(&gscreen, window.min, &gscreen, window, Zero); window = inset(window, 5); - cursor = window.min; + curpos = window.min; window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h; hwcurs = 0; } @@ -570,8 +571,6 @@ screenload(Rectangle r, uchar *data, int tl, int l, int dolock) int y, lpart, rpart, mx, m, mr, page, sw; ulong off; uchar *q, *e; - extern void cursorlock(Rectangle); - extern void cursorunlock(void); if(!rectclip(&r, gscreen.r) || tl<=0) return; @@ -580,7 +579,7 @@ screenload(Rectangle r, uchar *data, int tl, int l, int dolock) cursorlock(r); lock(&screenlock); - q = gbaddr(&gscreen, r.min); + q = byteaddr(&gscreen, r.min); mx = 7>>gscreen.ldepth; lpart = (r.min.x & mx) << gscreen.ldepth; rpart = (r.max.x & mx) << gscreen.ldepth; @@ -728,8 +727,6 @@ screenunload(Rectangle r, uchar *data, int tl, int l, int dolock) int y, lpart, rpart, mx, m, mr, page, sw; ulong off; uchar *q, *e; - extern void cursorlock(Rectangle); - extern void cursorunlock(void); if(!rectclip(&r, gscreen.r) || tl<=0) return; @@ -738,7 +735,7 @@ screenunload(Rectangle r, uchar *data, int tl, int l, int dolock) cursorlock(r); lock(&screenlock); - q = gbaddr(&gscreen, r.min); + q = byteaddr(&gscreen, r.min); mx = 7>>gscreen.ldepth; lpart = (r.min.x & mx) << gscreen.ldepth; rpart = (r.max.x & mx) << gscreen.ldepth; @@ -1072,12 +1069,13 @@ scroll(void) int o; Rectangle r; + o = 2*h; vgacard->setpage(0); - r = Rpt(Pt(window.min.x, window.max.y+h), window.max); - gbitblt(&gscreen, window.min, &gscreen, r, S); + r = Rpt(Pt(window.min.x, window.min.y+o), window.max); + bitblt(&gscreen, window.min, &gscreen, r, S); r = Rpt(Pt(window.min.x, window.max.y-o), window.max); - gbitblt(&gscreen, r.min, &gscreen, r, Zero); - cursor.y -= o; + bitblt(&gscreen, r.min, &gscreen, r, Zero); + curpos.y -= o; } static void @@ -1087,28 +1085,28 @@ screenputc(char *buf) switch(buf[0]) { case '\n': - if(cursor.y+h >= window.max.y) + if(curpos.y+h >= window.max.y) scroll(); - cursor.y += h; + curpos.y += h; screenputc("\r"); break; case '\r': - cursor.x = window.min.x; + curpos.x = window.min.x; break; case '\t': - pos = (cursor.x-window.min.x)/w; + pos = (curpos.x-window.min.x)/w; pos = 8-(pos%8); - cursor.x += pos*w; + curpos.x += pos*w; break; case '\b': - if(cursor.x-w >= window.min.x) - cursor.x -= w; + if(curpos.x-w >= window.min.x) + curpos.x -= w; break; default: - if(cursor.x >= window.max.x-w) + if(curpos.x >= window.max.x-w) screenputc("\n"); - cursor = gsubfstring(&gscreen, cursor, &defont0, buf, S); + curpos = subfstring(&gscreen, curpos, &defont0, buf, S); } } diff --git a/pc/kbd.c b/pc/kbd.c index 21f24166f7921b64d8ab352eed7ddc985462b1b5..65d5bc5410af362d0e01a0c3acb4e37dea7dde47 100644 --- a/pc/kbd.c +++ b/pc/kbd.c @@ -7,7 +7,6 @@ #include "../port/error.h" #include -#include enum { Data= 0x60, /* data port */ diff --git a/port/devcons.c b/port/devcons.c index 6ac6931176b20647bdc5f056abeb8f4d680d760d..32b0ad2562e0eaff4b1f439464f5b23ce09f4d9b 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -119,6 +119,19 @@ print(char *fmt, ...) return n; } +int +fprint(int fd, char *fmt, ...) /* needed so we can use user-level libg */ +{ + char buf[PRINTSIZE]; + int n; + + USED(fd); + n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf; + putstrn(buf, n); + + return n; +} + int kprint(char *fmt, ...) { diff --git a/port/devmouse.c b/port/devmouse.c index 98cb514defee7915939ecb970ce24d3a1570e9d3..4e0b2bcb0f81aa27483f86b754ae4b6c8dd768b2 100644 --- a/port/devmouse.c +++ b/port/devmouse.c @@ -1,7 +1,6 @@ #include "u.h" #include "../port/lib.h" #include -#include #include "mem.h" #include "dat.h" #include "fns.h" @@ -57,6 +56,12 @@ struct Cursorinfo int disable; /* from being used */ int frozen; /* from being used */ Rectangle r; /* location */ + + int l; + int tl; + int setop; + int clrop; + Rectangle clipr; }; Mouseinfo mouse; @@ -83,47 +88,37 @@ Cursor arrow = }; ulong setbits[16]; -GBitmap set = +Bitmap set = { - setbits, + {0, 0, 16, 16}, + {0, 0, 16, 16}, 0, + setbits, 1, 0, - {0, 0, 16, 16}, - {0, 0, 16, 16} }; ulong clrbits[16]; -GBitmap clr = +Bitmap clr = { - clrbits, - 0, - 1, - 0, {0, 0, 16, 16}, - {0, 0, 16, 16} -}; - -ulong cursorbackbits[16*4]; -GBitmap cursorback = -{ - cursorbackbits, + {0, 0, 16, 16}, 0, + clrbits, 1, 0, - {0, 0, 16, 16}, - {0, 0, 16, 16} }; -ulong cursorworkbits[16*4]; -GBitmap cursorwork = +ulong backbits[16*5]; +ulong workbits[16*5]; +Bitmap cursorwork = { - cursorworkbits, + {0, 0, 16+8, 16}, + {0, 0, 16+8, 16}, 0, + workbits, 1, 0, - {0, 0, 16, 16}, - {0, 0, 16, 16} }; void Cursortocursor(Cursor*); @@ -147,7 +142,7 @@ Dirtab mousedir[]={ #define NMOUSE (sizeof(mousedir)/sizeof(Dirtab)) -extern GBitmap gscreen; +extern Bitmap gscreen; void mousereset(void) @@ -165,20 +160,36 @@ mousereset(void) Cursortocursor(&arrow); } +void +cursorinit(void) +{ + cursorwork.ldepth = gscreen.ldepth; + cursorwork.width = ((cursorwork.r.max.x << gscreen.ldepth) + 31) >> 5; + + cursor.l = cursorwork.width*BY2WD; + + if(flipping){ + cursor.setop = flipD[S|D]; + cursor.clrop = flipD[D&~S]; + } else { + cursor.setop = S|D; + cursor.clrop = D&~S; + } +} + void mouseinit(void) { if(!conf.monitor) return; + if(gscreen.ldepth > 3){ - cursorback.ldepth = 0; - cursorwork.ldepth = 0; - }else{ - cursorback.ldepth = gscreen.ldepth; - cursorback.width = ((16 << gscreen.ldepth) + 31) >> 5; - cursorwork.ldepth = gscreen.ldepth; - cursorwork.width = ((16 << gscreen.ldepth) + 31) >> 5; + print("mouse can't work ldepth > 3"); + cursor.disable = 1; } + + cursorinit(); + cursoron(1); } @@ -187,6 +198,7 @@ mouseattach(char *spec) { if(!conf.monitor) error(Egreg); + cursorinit(); return devattach('m', spec); } @@ -437,9 +449,24 @@ cursorunlock(void) unlock(&cursor); } +typedef struct +{ + Bitmap *dm; + Point p; + Bitmap *sm; + Rectangle r; + Fcode f; +} XXX; + void cursoron(int dolock) { + int off; + Rectangle r; + uchar *a; + XXX x; + extern int graphicssubtile(uchar*, int, int, Rectangle, Rectangle, uchar**); + if(cursor.disable) return; if(dolock) @@ -451,15 +478,36 @@ cursoron(int dolock) cursor.r.min = mouse.xy; cursor.r.max = add(mouse.xy, Pt(16, 16)); cursor.r = raddp(cursor.r, cursor.offset); - screenunload(cursor.r, (uchar*)cursorworkbits, - (16>>3) << gscreen.ldepth, cursorwork.width*BY2WD, 0); - memmove(cursorbackbits, cursorworkbits, 16*cursorback.width*BY2WD); - gbitblt(&cursorwork, cursorwork.r.min, - &clr, Rect(0, 0, 16, 16), flipping? flipD[D&~S] : D&~S); - gbitblt(&cursorwork, cursorwork.r.min, - &set, Rect(0, 0, 16, 16), flipping? flipD[S|D] : S|D); - screenload(cursor.r, (uchar*)cursorworkbits, - (16>>3) << gscreen.ldepth, cursorwork.width*BY2WD, 0); + + /* bit offset into backup area */ + off = ((1< 0){ + /* get tile */ + screenunload(x.r, (uchar*)workbits, cursor.tl, cursor.l, 0); + + /* save for cursoroff */ + memmove(backbits, workbits, cursor.l*16); + + /* add mouse into work area */ + r = Rect(0, 0, Dx(x.r), Dy(x.r)); + bitblt(&cursorwork, x.p, &clr, r, cursor.clrop); + bitblt(&cursorwork, x.p, &set, r, cursor.setop); + + /* put back tile */ + cursor.clipr = x.r; + screenload(x.r, (uchar*)workbits, cursor.tl, cursor.l, 0); + } } } if(dolock) @@ -473,11 +521,8 @@ cursoroff(int dolock) return; if(dolock) lock(&cursor); - if(--cursor.visible == 0) { - if(!hwcurs) - screenload(cursor.r, (uchar*)cursorbackbits, - (16>>3) << gscreen.ldepth, cursorback.width*BY2WD, 0); - } + if(--cursor.visible == 0 && !hwcurs && cursor.tl > 0) + screenload(cursor.clipr, (uchar*)backbits, cursor.tl, cursor.l, 0); if(dolock) unlock(&cursor); }