       shaft_status[shaft].shaft_position = SHAFT_CENTER; }
    do_steps(); }
 
+// If this file uses the FILE_TABBY "alternate with tabby" option, we assume
+// none of the treadles in the treadle sequence are either 0 or 1.
+// These routines go forward and backward in the treadle seqeunce by
+// updating tr_seq_pos and/or tr_treadle.
+
+void next_treadle(void) {
+   if (file_hdr.flags & FILE_TABBY && config_hdr.tr_treadle < 2) {
+      // we just did the tabby alternation, so now do the real treadle
+      config_hdr.tr_treadle = treadle_sequence[config_hdr.tr_seq_pos]; }
+   else { // advance to the next in the treadle sequence
+      if (++config_hdr.tr_seq_pos >= sequence_size) config_hdr.tr_seq_pos = 0;
+      if (file_hdr.flags & FILE_TABBY) // first do tabby alternation
+         config_hdr.tr_treadle = config_hdr.tr_seq_pos & 1 ? 1 : 0;
+      else // go right to the real treadle
+         config_hdr.tr_treadle = treadle_sequence[config_hdr.tr_seq_pos]; } }
+
+void previous_treadle(void) {
+   if (file_hdr.flags & FILE_TABBY && config_hdr.tr_treadle >= 2) {
+      // we just did the real treadle, so simply back up to the tabby alternative
+      config_hdr.tr_treadle = config_hdr.tr_seq_pos & 1 ? 1 : 0; }
+   else { // go to the previous in the treadle sequence
+      config_hdr.tr_seq_pos = config_hdr.tr_seq_pos == 0 ? sequence_size - 1
+                              : config_hdr.tr_seq_pos - 1;
+      // and go right to the real treadle, even if we're alternating with tabby
+      config_hdr.tr_treadle = treadle_sequence[config_hdr.tr_seq_pos]; } }
+
 void weave (void) {  // enter weaving mode
    int shuttle_count = 0;
    enum events event;

            if (save) {
               if (charnum == 0) {
                  row_select = true;
                  lcd.noBlink();
                  lcd.cursor(); }
               else --charnum; }
            break;
         case eHrotR:   // move right
            if (save) {
               if (row_select) {
                  row_select = false;
                  lcd.noCursor();
                  lcd.blink(); }
               else if (charnum < MAX_FILENAME) {
                  ++charnum;
                  if (file_hdr.filename[charnum] == '\0') { // if we're going beyond the end

                                  - temporarily disable motors during weaving if there is no activity for a few minutes.
   27 Mar 2017, L. Shustek, V1.6  - display filename on top-level screen, or "unsaved" if pgmg changes are made
                                  - default to current file in load/save menu
                                  - exit from program mode if any other button is pushed
   15 Jun 2017, L. Shustek, V1.7  - fix bug: exiting weaving mode after motors had timed out didn't return
                                    the shafts to the neutral position
    8 Jan 2018, L. Shustek, V1.8  - change "zero" button to "backup" button in weave mode
                                  - display frame numbers instead of X in tieup screen
                                  - display treadle numbers instead of X in treadle sequence screen
                                  - fix bug: backing up weave at the first treadle position failed
   28 Oct 2018, L. Shustek, V1.9  - add the option to do "Tabby" between each step of a treadle sequence
    3 Jan 2019, L. Shustek, V1.10 - during calibration, show the distance the frame moves

*/
#define VERSION "1.10"

/***** Enhancement ideas:

    - Invent a more programmatic way to configure treadle sequences with repeat loops.
      Since weaving is limited to one treadle at a time we can use decimal rather than unary
      notation on the narrow display. It doesn't match weaving books, though, so weavers would
      consider that sacrilegious!

      Idea #1: a programming mode for "treadle loops", in addition to the traditional sequence.
      The notation might be like this, using "Irish Meadows blanket" as an example:
          4x: 5 6
          6x: 6 5
          8x: 5 6
          ?x: 1 2 3 4
          8x: 5 6
          6x: 6 5
          4x: 5 6
      When weaving, the "?x" line would be repeated indefinitely until a button is pushed to advance.
      Either this "treadle loop" notation or a reconstructed "treadle sequence" notation could be displayed.
      The 3rd and 4th numbers on the big-digit display could show how far along in a repeat sequence we are.
      The file format would have to be elaborated to save and load these looped treadle sequences.

    - Save space by making the tieup[][] matrix be a true bitmap. That would allow more files in the EEPROM.
      Or instead: use an SD card for files, and to hell with optimizing the size to fit in the 4K EEPROM!
*/

#define DEBUG true
