#include #include typedef struct Ent Ent; struct Ent { ulong off; int dx; int dy; int yy; }; int modes[] = { 320, 200, 320, 240, 512, 384, 640, 350, 640, 400, 640, 480, 720, 400, 768, 480, 800, 600, 1024, 768, 1152, 864, 1280, 800, 1280, 1024, 1400, 1050, 1440, 900, 1600, 1200, 1680, 1050, 1920, 1080, 1920, 1200, 2048, 1536, 0, }; int entcmp(void *p1, void *p2) { Ent *e1 = p1; Ent *e2 = p2; int n; if((n = e1->off - e2->off) == 0) n = e1->yy - e2->yy; return n; } void main(int argc, char *argv[]) { uchar buf[4*64*1024], *p, *e; ulong oo, off, start; int fd, i, j; ARGBEGIN { } ARGEND; if(*argv == 0){ fprint(2, "Usage: %s file [ off[+disp] val ... ]\n", argv0); exits("usage"); } fd = open(*argv, ORDWR); if(fd < 0) sysfatal("open: %r"); argv++; start = 0xC0000; if(*argv == 0){ Ent ent[1024]; int nent; nent = 0; off = start; if(seek(fd, off, 0) == -1) sysfatal("seek: %r"); if(readn(fd, buf, sizeof(buf)) != sizeof(buf)) sysfatal("read: %r"); for(i=0; modes[i]; i += 2){ for(p = buf, e = buf + sizeof(buf); p+32 < e; p++){ if(p[0] != (modes[i] & 0xFF)) continue; if(p[1] != (modes[i] >> 8)) continue; for(j=2; j<30; j++){ if(p[j] != (modes[i+1] & 0xFF)) continue; if(p[j+1] != (modes[i+1] >> 8)) continue; if(nent >= nelem(ent)) break; ent[nent].off = off + (p - buf); ent[nent].dx = modes[i]; ent[nent].dy = modes[i+1]; ent[nent].yy = j; nent++; } } } qsort(ent, nent, sizeof(ent[0]), entcmp); for(j=2; j<30; j++){ print("# y=x+%d\n", j); oo = 0; for(i=0; i> 8; if(seek(fd, off, 0) == -1) sysfatal("seek: %r"); if(write(fd, buf, 2) != 2) sysfatal("write: %r"); argv += 2; } exits(0); }