chiark / gitweb /
fixed for actual programming circuit on table
authorian <ian>
Fri, 29 Apr 2005 23:29:56 +0000 (23:29 +0000)
committerian <ian>
Fri, 29 Apr 2005 23:29:56 +0000 (23:29 +0000)
parport/odyssey-train
parport/train-pic-prog-select.c

index 077a8922b5a9e8ec0f24af07d514b93ad78193ae..a945b6fdf7045833deafa9d74a1df6d464363126 100755 (executable)
@@ -10,14 +10,16 @@ badusage () {
 
 which=$1
 
+tpps='train-pic-prog-select -i1'
+
 case "$which" in
 all)
-       train-pic-prog-select 0-55
+       $tpps 0-55
        whichconfig=all
        echo "Selected $which"
        ;;
 [0-9]|[0-9][0-9])
-       train-pic-prog-select $which
+       $tpps $which
        whichconfig=single
        echo "Selected #$which"
        ;;
index d1a8315f4b357b32399b66742ac6aa5581c765cc..7dc12b521a5da06a1ee09b2d537be647d97eb354 100644 (file)
 
 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);
 }
@@ -29,6 +34,8 @@ typedef unsigned char yesno;
 
 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];
@@ -54,11 +61,16 @@ int main(int argc, const char *const *argv) {
     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");
@@ -74,7 +86,7 @@ int main(int argc, const char *const *argv) {
       yesses.lin[first]= 1;
     }
   }
-  if (!strcmp(parport,"stdin")) {
+  if (!strcmp(parport,"stdin") || !strcmp(parport,"stdin-noclaim")) {
     fd= 0;
   } else {
     fd= open(parport, O_RDWR);
@@ -87,15 +99,21 @@ int main(int argc, const char *const *argv) {
     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 */
   }