static const void badusage(const char *what) {
fprintf(stderr,"bad usage: %s\n"
- "usage: train-pic-prog-select [-p/dev/parport] picno|range...\n"
- "ranges are picno-picno (inclusive)\n",
+ "usage: train-pic-prog-select -i0|-i1"
+ " [-p/dev/parport] picno|range...\n"
+ "ranges are picno-picno (inclusive)\n"
+ "-i0 means PPWDATA bit is 0 for selected pics; -i1 means 1\n"
+ " (default: value of TRAIN_PPWDATA_SEL_BIT env. var)\n"
+ "-pstdin means use fd 0; -pstdin-noclaim uses fd 0 and"
+ " doesn't PPCLAIM\n",
what);
exit(126);
}
const char *parport= "/dev/parport0";
+static int yesfor1bit= -1; /* same as bit needed for `yes' :-) */
+
static union {
yesno rect[COLUMNS][ROWS];
yesno lin[COLUMNS*ROWS];
argv++;
if (arg[1]=='p') {
parport= arg+2;
+ } else if (arg[1]=='i') {
+ yesfor1bit= atoi(arg+2);
} else {
badusage("unknown option");
}
}
+ if (!(yesfor1bit==0 || yesfor1bit==1)) badusage("need proper -i value");
+
if (!*argv) badusage("need to specify pics");
+
while ((arg= *argv++)) {
first= last= strtol(arg,&ep,10);
if (ep==arg) badusage("syntactically incorrect pic number");
yesses.lin[first]= 1;
}
}
- if (!strcmp(parport,"stdin")) {
+ if (!strcmp(parport,"stdin") || !strcmp(parport,"stdin-noclaim")) {
fd= 0;
} else {
fd= open(parport, O_RDWR);
for (col=0; col<COLUMNS; col++)
if (yesses.rect[col][row])
nselected++;
- printf("Selecting %d/%d; bytes:", nselected, ROWS*COLUMNS);
- doioctl(PPCLAIM,0,0);
+ if (!strcmp(parport,"stdin-noclaim")) {
+ printf("Not claiming.\n");
+ } else {
+ printf("Claiming %s...\n", parport);
+ doioctl(PPCLAIM,0,0);
+ }
+
+ printf("Selecting %d/%d; bytes:", nselected, ROWS*COLUMNS);
wpause(PPWCONTROL, 0x02 /* !ENGAGE_VPP, !PC, !PDW */);
for (row=0; row<ROWS; row++) {
v= 0;
for (col=0; col<COLUMNS; col++)
- v |= yesses.rect[col][row] ? 0 : (1<<col);
+ v |= yesses.rect[col][row]==yesfor1bit ? 0 : (1<<col);
wpause(PPWDATA, v | 0x80);
wpause(PPWDATA, v); /* SEL_CLK ~|_ shifts */
}