diff options
author | Uwe Stuehler <uwe@cvs.openbsd.org> | 2005-04-25 02:52:01 +0000 |
---|---|---|
committer | Uwe Stuehler <uwe@cvs.openbsd.org> | 2005-04-25 02:52:01 +0000 |
commit | 8b8e315f8067d94e2a39729262b146657020d02d (patch) | |
tree | e6d0b71e429d533ca612c74533bed25ebd3a87f3 /usr.sbin | |
parent | 841b49f6a42a7de299eec8fa44979733503e9bce (diff) |
- don't loop infinitely after a missed "mouse up" event
- display bitmaps correctly if width is not divisible by 8
- display another bitmap on error
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ztsscale/message.xbm | 36 | ||||
-rw-r--r-- | usr.sbin/ztsscale/ztsscale.c | 66 |
2 files changed, 74 insertions, 28 deletions
diff --git a/usr.sbin/ztsscale/message.xbm b/usr.sbin/ztsscale/message.xbm index 288bee60974..31214d8ecc7 100644 --- a/usr.sbin/ztsscale/message.xbm +++ b/usr.sbin/ztsscale/message.xbm @@ -36,3 +36,39 @@ static unsigned char message_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + +#define error_width 272 +#define error_height 11 +static unsigned char error_bits[] = { + 0xe3, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x80, 0x6d, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x38, 0x7c, 0x00, + 0x78, 0x60, 0x61, 0x99, 0x31, 0xe3, 0xe0, 0x83, 0x01, 0x80, 0x43, 0x07, + 0xc7, 0x0c, 0x1b, 0x0d, 0x00, 0x80, 0x6d, 0x76, 0xe7, 0x00, 0x3c, 0xd8, + 0x38, 0x38, 0xe8, 0x00, 0x00, 0x00, 0x4a, 0xfc, 0x7c, 0x00, 0xf8, 0xf8, + 0xf1, 0x99, 0xf3, 0xf3, 0xe3, 0xe3, 0x03, 0xc0, 0xc7, 0x87, 0xcf, 0x9c, + 0x1f, 0x1f, 0x00, 0x80, 0x6d, 0x7e, 0xe7, 0x00, 0x7c, 0xfc, 0xfc, 0x38, + 0xf8, 0x00, 0x00, 0x00, 0x5a, 0x86, 0x08, 0x00, 0x80, 0x08, 0x09, 0x11, + 0x63, 0x00, 0x63, 0x20, 0x04, 0x60, 0xc8, 0xc8, 0x98, 0xd8, 0x08, 0x11, + 0x00, 0x00, 0x0c, 0x0c, 0x46, 0x00, 0x40, 0x46, 0xc0, 0x20, 0x18, 0x01, + 0x00, 0x00, 0x52, 0x82, 0x08, 0x00, 0xf8, 0x08, 0x08, 0x10, 0x23, 0xe0, + 0x63, 0xf0, 0x07, 0xe0, 0xcf, 0x48, 0x90, 0x58, 0x08, 0x11, 0x00, 0x00, + 0x0c, 0x04, 0x24, 0x00, 0x7c, 0x42, 0xf8, 0x20, 0x18, 0x01, 0x00, 0x00, + 0x62, 0x86, 0x08, 0x00, 0x8c, 0x08, 0x08, 0x10, 0x23, 0x10, 0x63, 0x30, + 0x00, 0x60, 0xc0, 0xc8, 0x98, 0xd8, 0x08, 0x11, 0x00, 0x00, 0x0c, 0x04, + 0x2c, 0x00, 0x46, 0x46, 0xc4, 0x20, 0x18, 0x01, 0x00, 0x00, 0x67, 0xfc, + 0xf8, 0x00, 0xfc, 0xf9, 0xf9, 0xf1, 0xf3, 0xf1, 0xc3, 0xe7, 0x07, 0xc0, + 0xcf, 0x8c, 0x8f, 0x9f, 0x8f, 0x39, 0x06, 0x00, 0x1e, 0x3e, 0x18, 0x00, + 0xfe, 0x7c, 0xfc, 0xf8, 0x99, 0x61, 0x60, 0xc0, 0x47, 0x38, 0x70, 0x00, + 0xb8, 0xf1, 0xe0, 0xe0, 0xf3, 0xe1, 0x82, 0xc1, 0x03, 0x80, 0xc7, 0x0c, + 0x07, 0x1f, 0x8b, 0x39, 0x04, 0x00, 0x1e, 0x3e, 0x18, 0x00, 0xdc, 0x58, + 0xb8, 0xf8, 0x99, 0x61, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 }; diff --git a/usr.sbin/ztsscale/ztsscale.c b/usr.sbin/ztsscale/ztsscale.c index 4ba13752853..42a073bc440 100644 --- a/usr.sbin/ztsscale/ztsscale.c +++ b/usr.sbin/ztsscale/ztsscale.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ztsscale.c,v 1.5 2005/04/25 00:28:12 uwe Exp $ */ +/* $OpenBSD: ztsscale.c,v 1.6 2005/04/25 02:52:00 uwe Exp $ */ /* * Copyright (c) 2005 Matthieu Herrb @@ -37,6 +37,7 @@ #define WIDTH 640 #define HEIGHT 480 #define BLACK 0x0 +#define RED 0xf000 #define WHITE 0xffff #define ADDR(x,y) (HEIGHT*(x)+(y)) @@ -59,17 +60,20 @@ int main(int, char *[]); __dead void usage(void); void -bitmap(u_short *fb, u_short color, u_char bits[], int width, int height) +bitmap(u_short *fb, u_short pixel, u_char bits[], int width, int height) { int i, j; int x, y; +#define BITADDR(x, y) ((width + 7)/8*(y) + (x)/8) +#define BITMASK(x) (1 << ((x) % 8)) + for (i = 0; i < height; i++) { - x = (WIDTH - width) / 2; - y = HEIGHT + (HEIGHT - height)/2 + 60; + x = (WIDTH - width)/2; + y = (HEIGHT/2 - height)/2; for (j = 0; j < width; j++) - if (bits[((i * width) + j) / 8] & (1 << (j % 8))) - fb[ADDR(x + j, y - i - 1)] = BLACK; + if (bits[BITADDR(j, i)] & BITMASK(j)) + fb[ADDR(x + j, HEIGHT - y - i)] = pixel; } } @@ -93,7 +97,8 @@ wait_event(int mfd, int *x, int *y) struct wscons_event evbuf; down = 0; - while (!down) { + *x = *y = -1; + while (down || *x == -1 || *y == -1) { len = read(mfd, &evbuf, sizeof(evbuf)); if (len != 16) break; @@ -101,15 +106,6 @@ wait_event(int mfd, int *x, int *y) case WSCONS_EVENT_MOUSE_DOWN: down = 1; break; - } - } - - *x = *y = -1; - while (down || *x == -1 || *y == -1) { - len = read(mfd, &evbuf, sizeof(evbuf)); - if (len != 16) - break; - switch (evbuf.type) { case WSCONS_EVENT_MOUSE_UP: down = 0; break; @@ -157,7 +153,6 @@ void sighandler(int sig) { restore_screen(); - close(fd); _exit(2); } @@ -181,24 +176,29 @@ main(int argc, char *argv[]) if (argc != 1) usage(); -again: fd = open("/dev/ttyC0", O_RDWR); if (fd < 0) { err(2, "open /dev/ttyC0"); } + save_screen(); + +again: mfd = open("/dev/wsmouse", O_RDONLY); - if (mfd < 0) + if (mfd < 0) { + restore_screen(); err(2, "open /dev/wsmouse"); + } mib[0] = CTL_MACHDEP; mib[1] = CPU_ZTSRAWMODE; rawmode = 1; oldsize = sizeof(oldval); if (sysctl(mib, 2, &oldval, &oldsize, &rawmode, - sizeof(rawmode)) == -1) + sizeof(rawmode)) == -1) { + restore_screen(); err(1, "sysctl"); + } - save_screen(); signal(SIGINT, sighandler); for (i = 0; i < 5; i++) { memset(mapaddr, WHITE, WIDTH*HEIGHT*sizeof(u_short)); @@ -208,16 +208,16 @@ again: /* printf("waiting for event\n"); */ wait_event(mfd, &x[i], &y[i]); } - restore_screen(); close(mfd); - close(fd); mib[0] = CTL_MACHDEP; mib[1] = CPU_ZTSRAWMODE; rawmode = oldval; oldsize = sizeof(oldval); - if (sysctl(mib, 2, NULL, NULL, &rawmode, sizeof(rawmode)) == -1) + if (sysctl(mib, 2, NULL, NULL, &rawmode, sizeof(rawmode)) == -1) { + restore_screen(); err(1, "sysctl"); + } bzero(&ts, sizeof(ts)); @@ -232,10 +232,11 @@ again: b = (b1+b2)/2.0; errx = a*WIDTH/2+b - x[2]; if (fabs(errx) > (a*WIDTH+b)*.01) { +#ifdef DEBUG fprintf(stderr, "X error (%.2f) too high, try again\n", fabs(errx)); - sleep(2); - goto again; +#endif + goto err; } ts.ts_minx = (int)(b+0.5); @@ -252,20 +253,29 @@ again: b = (b1+b2)/2.0; erry = a*HEIGHT/2+b - y[2]; if (fabs(erry) > (a*HEIGHT+b)*.01) { +#ifdef DEBUG fprintf(stderr, "Y error (%.2f) too high, try again\n", fabs(erry)); - sleep(2); - goto again; +#endif + goto err; } ts.ts_miny = (int)(b+0.5); ts.ts_maxy = (int)(a*HEIGHT+b+0.5); + restore_screen(); + (void)printf("%s.%s=%d,%d,%d,%d\n", topname[CTL_MACHDEP].ctl_name, machdepname[CPU_ZTSSCALE].ctl_name, ts.ts_minx, ts.ts_maxx, ts.ts_miny, ts.ts_maxy); return 0; + +err: + memset(mapaddr, WHITE, WIDTH*HEIGHT*sizeof(u_short)); + bitmap(mapaddr, RED, error_bits, error_width, error_height); + sleep(2); + goto again; } __dead void |