merge
This commit is contained in:
commit
258a072d95
3 changed files with 64 additions and 2 deletions
|
@ -19,3 +19,5 @@ while(~ $1 -*) {
|
|||
}
|
||||
while(x = `{read -n $nargs})
|
||||
$* $x
|
||||
if(! ~ $#x 0)
|
||||
$* $x
|
||||
|
|
60
sys/src/cmd/aux/icanhasmsi.c
Normal file
60
sys/src/cmd/aux/icanhasmsi.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
|
||||
int
|
||||
pcicfg16r(int fd, ushort *s, vlong offset)
|
||||
{
|
||||
char buf[2];
|
||||
|
||||
if(pread(fd, buf, 2, offset) < 2) return -1;
|
||||
*s = buf[0] | (buf[1] << 8);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
main()
|
||||
{
|
||||
int fd;
|
||||
long n;
|
||||
Dir *dir;
|
||||
char *p, *s;
|
||||
uchar cap, c;
|
||||
ushort sh;
|
||||
|
||||
fd = open("/dev/pci", OREAD);
|
||||
if(fd < 0) sysfatal("open /dev/pci: %r");
|
||||
n = dirreadall(fd, &dir);
|
||||
if(n < 0) sysfatal("dirreadall /dev/pci: %r");
|
||||
close(fd);
|
||||
for(; n--; dir++) {
|
||||
p = dir->name + strlen(dir->name) - 3;
|
||||
if(strcmp(p, "raw") != 0)
|
||||
continue;
|
||||
s = smprint("/dev/pci/%s", dir->name);
|
||||
fd = open(s, OREAD);
|
||||
if(fd < 0) {
|
||||
fprint(2, "open %s: %r", s);
|
||||
free(s);
|
||||
continue;
|
||||
}
|
||||
if(pcicfg16r(fd, &sh, 0) < 0) goto err;
|
||||
if(sh == 0xFFFF) goto end;
|
||||
if(pcicfg16r(fd, &sh, 0x06) < 0) goto err;
|
||||
if((sh & (1<<4)) == 0) goto end;
|
||||
cap = 0x33;
|
||||
for(;;) {
|
||||
if(pread(fd, &cap, 1, cap+1) < 0) goto err;
|
||||
if(cap == 0) goto end;
|
||||
if(pread(fd, &c, 1, cap) < 0) goto err;
|
||||
if(c == 0x05) break;
|
||||
}
|
||||
s[strlen(s) - 3] = 0;
|
||||
print("%s\n", s+9);
|
||||
goto end;
|
||||
err:
|
||||
fprint(2, "read %s: %r", s);
|
||||
end:
|
||||
free(s);
|
||||
close(fd);
|
||||
}
|
||||
}
|
|
@ -848,7 +848,7 @@ threadmain(int argc, char *argv[])
|
|||
snprint(buf, sizeof(buf), "/sys/games/lib/%dscores", N);
|
||||
scores = open(buf, OWRITE);
|
||||
if(scores < 0)
|
||||
sysfatal("can't open %s: %r", buf);
|
||||
print("can't open %s: %r\n", buf);
|
||||
tb = 0;
|
||||
if(screen->depth < 3){
|
||||
tb = allocimage(display, Rect(0,0,16,16), 0, 1, -1);
|
||||
|
@ -881,7 +881,7 @@ threadmain(int argc, char *argv[])
|
|||
points = 0;
|
||||
memset(board, 0, sizeof(board));
|
||||
redraw(0);
|
||||
if(play()){
|
||||
if(play() && scores >= 0){
|
||||
endtime = time(0);
|
||||
fprint(scores, "%ld\t%s\t%lud\t%ld\n",
|
||||
points, getuser(), starttime, endtime-starttime);
|
||||
|
|
Loading…
Reference in a new issue