#ifndef _JTABLES_H_
#define _JTABLES_H_ 1


// EPROM Space used by distance tables is 46 * 46 * 4 = 8464

// Largest dist = 53.  As long as this is <= 63, these arrays work.

  // junction_distance (actually 'junction distance and direction' but that was a bit
  // verbose to be used in the code too often) takes a pair of junction numbers (extracted
  // from wallmap) and returns the distance in map cells from the first to the second, plus
  // a direction to head from the first junction to the next square on the way to the
  // second junction.  If that square is within a corridor, the corridor is simply followed
  // in the same direction; otherwise if it is a new junction, this table is consulted
  // again for the next direction.

  // 6 bits for distance plus 2 bits for direction.  (Largest distance was 53 so that's safe...)

//const unsigned char junction_distance[4][NUM_JUNCTIONS][NUM_JUNCTIONS] IN_ROM = {

// TO DO: I had hoped that where a junction leads to itself (ie the entry is 0) we could replace 0 with the code for STUCK (4)
// but that will not be possible because we only have 2 bits available for direction (and 6 for distance). So interception of
// that value has to take place at a higher level (which it currently is.)

// Here's a problem... these are triangular matrices, and therefore might be
// cut in half by wrapping access in slightly smarter code (testing j1 < j2)
// ... except that the direction component of A to B is is not simply the
// reverse direction of B to A, because of corners within the corridor.

// An alternative way of compacting the routing tables would be to use left/right symmetry
// - which *would* allow for reversing the X direction component...  It would require a
// table to map junctions in the right hand half of the table to the equivalent junction
// in the left hand half.  Since I'm currently within 1000 bytes of fitting in to a 32K
// rom now, saving half of these tables is worth the effort: the savings would be
// 38*38/2 + 36*36/2 + 46*46/2 + 40*40/2 = 722 + 648 + 1058 + 800 = 3228 bytes! 
// - call it 2.5K with extra lookup tables and new code.

const uint8_t junction_distance0[] = { // 6 bits for distance plus 2 bits for direction.  38x38
//  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   a   b   c   d   e   f   g   h   i   j   k   l
    0, 67, 70, 73, 76, 79, 82,207,196, 74, 83,203,199, 77,212,206, 80,215,205, 86, 89,212,208,214,221,215,211,214,217,220,223,224,221,218,220,223,230,227, // A
    3,  0, 67, 70, 73, 76, 79, 18,  7,199, 80, 14, 10,202, 83, 17,205, 86, 16,211,214, 23, 19,217,220, 26, 22, 25,220,223,226,223, 32, 29, 31, 34, 41, 38, // B
    6,  3,  0, 67, 70, 73, 76, 21, 10, 10, 77, 17, 13, 13, 80, 20, 16, 83, 19, 22, 89, 26, 22, 28, 95, 29, 25, 28, 31, 34, 37, 98, 35, 32, 34, 37, 44, 41, // C
    9,  6,  3,  0, 67, 70, 73, 86, 13,199, 74, 20, 16,202, 77, 83,205, 80, 22,211, 86, 89, 25,217, 92, 92, 28, 31,220,223,226, 95, 98, 95, 37,232,235,104, // D
   12,  9,  6,  3,  0, 67, 70, 83, 16, 10,199,211, 19, 13,202,208, 16,205, 25, 22,211,214, 28, 28,217,217, 31, 34, 31, 34,223,220,223,220, 40, 43,232,229, // E
   15, 12,  9,  6,  3,  0, 67, 80, 19, 13, 10, 84, 22, 16, 13, 19, 19, 16, 28, 25, 22, 25, 31, 31, 28, 28, 34, 37, 34, 37, 34, 31, 34, 31, 43, 46, 43, 40, // F
   18, 15, 12,  9,  6,  3,  0,141, 22, 16,199,145, 25, 19,202,208, 22,205,221,214,211,214,224,220,217,217,227,226,223,226,223,220,223,220,232,235,232,229, // G
  207, 18, 15, 12,  9,  6,  3,  0,203, 19, 10,196,206,212, 13,199,215, 16,212, 25, 22,205,215,221,214,208,218,221,224,223,220,217,214,211,227,230,223,220, // H
  132,135,138,141,144, 17, 14, 11,  0,204, 19,  7,195,201, 16, 10,204, 19,201,210,213, 16,204,210, 25, 19,207,210,213,216,219, 28, 25, 22,216,219, 34, 31, // I
   10,  7, 10, 71, 74, 77, 80,215,204,  0,207,211,201,195,204,210,198,207,207,204,207,214,210,210,213,217,213,216,213,216,219,216,219,220,222,225,228,225, // J
   19, 16, 13, 10,  7, 10, 71,208,211,207,  0,204,210,204,195,201,207,198,214,207,204,207,217,213,210,210,220,219,216,219,216,213,216,213,225,228,225,222, // K
   75, 78, 81,144,141,138,135,132, 71, 83,204,  0, 74, 80,201,195, 83,204, 80,213,210,201, 83, 89,210,204, 86, 89, 92,219,216,213,210,207, 95, 98,219,216, // L
  135,138,141,144,147,148,145,142,131, 73, 82,138,  0, 70, 79,141, 73, 82,198, 79, 82,205,201,207,214,208,204,207,210,213,216,217,214,211,213,216,223,220, // M
  141,138,141,138,141,144,147, 20,  9,131, 76, 16,  6,  0, 73, 79,195, 76, 12,201,204, 19, 15,207,210, 22, 18, 21,210,213,216,213,216, 25, 27,222,225,222, // N
   84,147,144,141,138,141,138, 77, 80, 12,131, 73, 15,  9,  0, 70, 12,195, 83,204,201, 76, 86,210,207, 79, 89,216,213,216,213,210,213, 82,222,225,222,219, // O
  142,145,148,147,144,141,138,135,138, 18,  9,131,141, 15,  6,  0, 18,  9,205, 18, 15,198,208,214,207,201,211,214,217,216,213,210,207,204,220,223,216,213, // P
  144,141,144,141,144,147,150,151,140,134,143,147,137,131,140,146,  0,143,  9,198,201, 16, 12,204,207, 19, 15, 18,207,210,213,210,213, 22, 24,219,222,219, // Q
  151,150,147,144,141,144,141,144,147,143,134,140,146,140,131,137,143,  0, 80,201,198, 73, 83,207,204, 76, 86,213,210,213,210,207,210, 79,219,222,219,216, // R
  141,144,147,150,153,154,151,148,137,143, 22,144,134,140, 19, 13, 73, 16,  0, 79, 82,  7,195,201, 16, 10,198,201,204,207,210, 19, 16, 13,207,210, 25, 22, // S
   22, 19, 22, 19, 22, 25, 86, 89, 18, 12, 79, 85, 15,  9, 76, 82,  6, 73, 15,  0, 67, 82,204,198, 73, 79,207,204,201,204,207, 76, 79, 82,210,213,216, 85, // T
   25, 22, 89, 86, 83, 86, 83, 86, 21, 15, 76, 82, 18, 12, 73, 79,  9, 70, 18,  3,  0, 79, 15,  9,198,204, 18, 15, 12, 15,204,201,204,207, 21, 24,213,210, // U
  148,151,154,153,150,147,144,141,144, 86,143,137, 77, 83,140,134, 80,  9, 71, 18, 15,  0, 74, 80,201,195, 77, 80, 83,210,207,204,201,198, 86, 89,210,207, // V
  144,147,150,153,156,157,154,151,140,146,153,147,137,143,150,144,140,147,131, 76, 79,138,  0, 70,147,141,195,198, 73, 76, 79, 82,147,144,204,207, 88,153, // W
   22, 89, 92, 89, 92, 95, 92, 29, 18, 82, 85, 25, 15, 79, 82, 22, 76, 79,  9, 70, 73, 16,  6,  0, 79, 19,  9,198,195,198,201,204,207,210,204,207,210,213, // X
   93, 28, 31, 28, 25, 28, 25, 86, 89, 21, 18, 82, 86, 18, 15, 79, 15, 12, 80,  9,  6, 73, 83, 15,  0, 70,210,207,204,201,198,195,198, 73,213,210,207,204, // Y
  151,154,157,156,153,150,147,144,147,153,146,140,144,150,143,137,147,140,138, 15, 12,131,141,147,  6,  0,144,147, 18, 15, 12,  9,198,195,153, 24,207,204, // Z
  147,150,153,156,159,160,157,154,143,149,156,150,140,146,153,147,143,150,134,143,146,141,131,137, 82,144,  0, 67, 70, 73, 76, 79, 82,147, 73, 76, 85, 88, // a
   22, 25, 28, 31, 34, 35, 32, 29, 18, 24, 91, 25, 15, 21, 88, 22, 18, 85,  9, 76, 79, 16,  6, 70, 79, 19,  3,  0, 67, 70, 73, 76, 79, 82,198,201, 82, 85, // b
  153,156,159,156,159,162,159,160,149,149,152,156,146,146,149,153,143,146,140,137,140,147,137,131, 76, 82,  6,  3,  0, 67, 70, 73, 76, 79,  9, 76, 79, 82, // c
   28, 31, 34, 31, 34, 37, 34, 95, 24, 24, 27, 91, 21, 21, 24, 88, 18, 21, 15, 12, 15, 82, 12,  6, 73, 79,  9,  6,  3,  0, 67, 70, 73, 76, 12,201, 76, 79, // d
   31, 34, 37, 34, 95, 98, 95, 92, 27, 27, 88, 88, 24, 24, 85, 85, 21, 82, 18, 15, 76, 79, 15,  9, 70, 76, 12,  9,  6,  3,  0, 67, 70, 73, 15, 12,201, 76, // e
  160,159,162,159,156,159,156,153,156,152,149,149,153,149,146,146,146,143,147,140,137,140, 18, 12,131,137, 15, 12,  9,  6,  3,  0, 67, 70, 18, 15, 12, 73, // f
   93, 96, 99, 34, 31, 92, 89, 86, 89, 27, 24, 82, 86, 24, 21, 79, 21, 18, 80, 15, 12, 73, 83, 15,  6, 70, 18, 15, 12,  9,  6,  3,  0, 67, 21, 18,201,198, // g
  154,157,160,159,156,153,150,147,150,156,149,143,147,153,146,140,150,143,141,146,143,134,144, 18,137,131,147, 18, 15, 12,  9,  6,  3,  0, 24, 21, 12,  9, // h
  156,159,162,165,168,169,166,163,152,158,161,159,149,155,158,156,152,155,143,146,149,150,140,140,149,153,137,134,137,140,143,146,149,152,  0, 67, 76, 79, // i
   31, 34, 37,168,171, 44, 41, 38, 27,161,164, 34, 24,158,161, 31,155,158, 18,149,152, 25, 15,143,146,152, 12,  9,140,137,140,143,146,149,  3,  0, 73, 76, // j
  102,105,108,171,168,101, 98, 95, 98,164,161, 91, 95,161,158, 88,158,155, 89,152,149, 82,152,146,143, 79,149,146,143,140,137,140, 73, 76, 12,  9,  0, 67, // k
  163,166,169,168,165,162,159,156,159,161,158,152,156,158,155,149,155,152,150,149,146,143,153,149,140,140,152,149,146,143,140,137,134,137, 15, 12,  3,  0, // l
//  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   a   b   c   d   e   f   g   h   i   j   k   l
};

const uint8_t junction_distance1[] = { // 6 bits for distance plus 2 bits for direction.  36x36
//  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   a   b   c   d   e   f   g   h   i   j
    0, 67, 82,147, 70, 85, 14, 93, 74, 83, 81, 90, 80, 77, 86, 89, 82, 87, 89, 86, 85, 90, 95, 98, 92, 88, 93, 99, 96, 93, 98,101, 99, 99,102,104, // A
    3,  0,143,146,195,146,203,154,199,208,206,215,205,202,211,214,207,212,214,211,210,215,220,223,217,213,218,224,221,218,223,226,224,224,227,229, // B
  146,143,  0, 67,146,195,154,203,208,199,215,206,214,211,202,205,212,207,223,220,215,210,211,214,224,218,213,217,226,223,218,221,229,227,224,224, // C
  147, 18,  3,  0, 21,  6, 29, 78, 19, 10, 26, 17, 25, 22, 13, 16, 23, 18, 34, 31, 26, 21, 22, 25, 35, 29, 24, 28, 37, 34, 29, 32, 40, 38, 35, 35, // D
  134,131,146,149,  0,209,  8,217,196,205,203,212,202,199,208,211,204,209,211,208,207,212,217,220,214,210,215,221,218,215,220,223,221,221,224,226, // E
  149,146,131,134,209,  0,217, 72,205,196,212,203,211,208,199,202,209,204,220,217,212,207,208,211,221,215,210,214,223,220,215,218,226,224,221,221, // F
   14,139,154,157,136,153,  0,161,140,149, 69,156, 70, 73,152,155, 78, 83, 79, 76, 81, 86, 91, 92, 82, 84, 89, 89, 88, 89, 94, 95, 91, 95, 98, 98, // G
  157,154,139, 78,153,136,161,  0,149,140,156,  5,155,152,  9,  6, 19, 14, 28, 27, 22, 17, 12, 15, 25, 25, 20, 18, 31, 30, 25, 24, 34, 34, 31, 27, // H
  138,135, 80, 83,132, 77,140, 85,  0, 73,199, 80,198,195, 76, 79,200,205,207,204,203,208, 85, 88,210,206,211,217,214,211,216,219,217,217,220,222, // I
   19, 16,135,138, 13,132, 21,140,  9,  0, 16,199, 15, 12,195,198,205,200, 24, 21,208,203,204,207,217,211,206,210,219,216,211,214,222,220,217,217, // J
  209,206,215,218,203,212,133,220,199,208,  0,215,193,196,211,214,201,206,202,199,204,209,214,215,205,207,212,212,211,212,217,218,214,218,221,221, // K
  218,215,206,209,212,203,220,133,208,199,215,  0,214,211,196,193,206,201,215,214,209,204,199,202,212,212,207,205,218,217,212,211,221,221,218,214, // L
   80, 77, 86, 89, 74, 83,134, 91, 70, 79,129, 86,  0, 67, 82, 85, 72, 77,201,198, 75, 80, 85,214,204, 78, 83,211,210, 83, 88,217,213, 89, 92,220, // M
  141,138,147,150,135,144,  9,152,131,140,  4,147,  3,  0,143,146,197,202, 12,  9,200,205,210,213, 15,203,208, 22,211,208,213,216,214,214,217,219, // N
  150,147,138,141,144,135,152, 73,140,131,147, 68,146,143,  0, 67,202,197,213,210,205,200, 73, 76, 86,208,203, 79,216,213,208,211,219,217,214,214, // O
   25, 22, 13, 16, 19, 10, 27,134, 15,  6, 22,129, 21, 18,  3,  0, 13,  8,214, 21, 16, 11,198,201,211, 19, 14,204,217, 24, 19,210,220, 28, 25,213, // P
   18, 15, 84, 87, 12, 81, 14, 83,  8, 77,  9, 78,  8,  5, 74, 77,  0, 69,203,200,195, 72, 77, 80,206,198, 75, 83,206,203, 80, 83,209,209,212, 86, // Q
   23, 20, 79, 82, 17, 76, 19, 78, 13, 72, 14, 73, 13, 10, 69, 72,  5,  0, 16, 13,  8,195,200,203, 19, 11,198,206, 19, 16,203,206, 22,212,209,209, // R
   89, 86, 95, 98, 83, 92, 79,220, 79, 88, 74,215, 73, 76, 85,214, 75, 80,  0, 67, 72, 83,208,205,195, 75, 80,202,201,204,211,208,204,210,213,211, // S
  150,147,156,159,144,153,140, 91,140,149,135, 86,134,137, 82, 85, 72, 77,  3,  0, 69, 80, 19, 16,  6, 72, 77, 13, 12, 77, 82, 19, 15, 83, 86, 22, // T
  149,146,151,154,143,148,145,150,139,144,140,145,139,136,141,144,131,136,  8,  5,  0,139,144,147, 11,195,200, 18,203,200,205,208,206,206,209,211, // U
  154,151,146,149,148,143,150,145,144,139,145,140,144,141,136,139,136,131,147,144,139,  0, 69, 72, 82,200,195, 75,208,205,200,203,211,209,206,206, // V
  159,156,147,150,153,144, 27,140,149,140, 22,135, 21, 18,137,134, 13,  8, 80, 83, 16,  5,  0, 67, 77, 13,  8, 70, 83, 18, 13, 76, 86, 22, 19, 79, // W
   34, 31, 22, 25, 28, 19,220, 15, 24, 15,215, 10,214, 21, 12,  9, 16, 11,205,208, 19,  8,  3,  0,202, 16, 11,195,208,211,204,201,211,213,210,204, // X
  156,153, 32, 35,150, 29,146, 25,146, 25,141, 20,140,143, 22, 19,142,147,131,134,139, 18, 13, 10,  0,142,147,  7, 70, 73, 16, 13, 73, 79, 82, 16, // Y
  152,149,154,157,146,151,148,153,142,147,143,148,142,139,144,147,134,139,139,136,131, 72, 77, 80,142,  0, 69, 83,  8,  5, 74, 77, 11, 11, 14, 80, // Z
  157,154,149,152,151,146,153,148,147,142,148,143,147,144,139,142,139,134, 16, 13,  8,131,136,139, 19,  5,  0,142, 13, 10, 69, 72, 16, 78, 75, 75, // a
   99, 96,153,156, 93,150, 89,146, 89,146, 84,141, 83, 86,143,140,147,142, 74, 77, 82,139,134,131, 71,147,142,  0, 77, 80,  9,  6, 80, 18, 15,  9, // b
   96, 93, 98,101, 90, 95,152,159, 86, 91,147,154,146, 83, 88,153, 78, 83,137,140, 75, 80,147,144,134, 72, 77,141,  0, 67, 82,147,195, 73, 76, 82, // c
  157,154,159,162,151,156,153,158,147,152,148,153,147,144,149,152,139,144, 12,141,136,141,146, 19,  9,133,138, 16,  3,  0,143,146,  6, 70, 73, 79, // d
  162,159,154,157,156,151,158,153,152,147,153,148,152,149,144,147,144,139, 83,146,141,136,141, 76, 80,138,133, 73,146,143,  0, 67, 15,  9,  6, 70, // e
   37, 34, 29, 32, 31, 26,159,152, 27, 22,154,147,153, 24, 19,146, 19, 14,144,147, 16, 11,140,137,141, 13,  8,134,147, 18,  3,  0, 18, 12,  9,195, // f
  163,160,165,168,157,162,155,162,153,158,150,157,149,150,155,156,145,150,140,143,142,147,150,147,137,139,144,144,131,134, 79, 82,  0, 70, 73, 79, // g
  163,160, 99,102,157, 96,159, 98,153, 92,154, 93,153,150, 89, 92,145, 84,146,147,142, 81, 86, 85,143,139, 78, 82,137,134, 73, 76,  6,  0, 67, 73, // h
   38, 35,160,163, 32,157, 34,159, 28,153, 29,154, 28, 25,150,153, 20,145, 21, 22, 17,142,147,146, 18, 14,139,143, 12,  9,134,137,  9,  3,  0, 70, // i
  168,165,160,163,162,157,162,155,158,153,157,150,156,155,150,149,150,145,147,150,147,142,143,140,144,144,139,137, 18, 15,134,131, 15,  9,  6,  0, // j
//  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   a   b   c   d   e   f   g   h   i   j
};

const uint8_t junction_distance2[] = { // 6 bits for distance plus 2 bits for direction.  46x46
//  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t  
    0, 66, 69, 78, 81, 83,  5, 20,197, 73, 76, 80, 11,  8, 17, 14,202,200,201,210, 83, 21, 16,207, 22, 19,210,207,210,213,216, 27, 24,213, 30, 27,216,219,222,225,222, 33, 32,219, 36, 35, // A
    2,  0, 67, 76, 79, 81,  7, 86,  7, 71, 74, 78, 13, 10, 19, 16, 12, 10, 11, 82, 81, 83, 18, 17, 88, 21, 20, 17, 20, 23, 88, 91, 26, 23, 94, 29, 26, 29, 32, 35, 32, 97, 34, 29,100, 37, // B
    5,  3,  0,137,140,142, 10,147,200,196,199,203, 16, 13,212, 19,205,203,204,207,206,208, 21,210,213, 24,213,210,213,216,213,216,219,216,219,222,219,222,225,228,225,222,227,222,225,230, // C
  142,140,137,  0, 67, 69,147, 74,203,199,196,200, 83,212, 77, 80,208,206,207,204,203,205, 88,213,210, 85,216,213,216,213,210,213,222,219,216,219,222,225,228,225,222,219,230,225,222,227, // D
   17, 15, 12,  3,  0, 66, 22, 71, 14, 10,  7, 71, 80, 83, 74, 77, 19, 17, 18, 75, 74, 76, 85, 24, 81, 82, 27, 24, 87, 84, 81, 84, 93, 30, 87, 90, 33, 96, 99, 96, 93, 90,101, 36, 93, 98, // E
   19, 17, 14,  5,  2,  0, 84, 69, 16, 12,  9,197, 78, 81, 72, 75, 85, 19,210,201,200,202, 83, 86,207, 80, 91,216,213,210,207,210, 91, 94,213, 88, 97,222,225,222,219,216, 99,100,219, 96, // F
  133,135,138,147,150,212,  0,207,138,142,145,149,198,195,204,201,199,201,202,211,210,208,203,204,209,206,209,208,211,214,217,214,211,212,217,214,215,218,221,226,223,220,219,218,223,222, // G
  212,150,147,138,135,133,207,  0,149,145,142,138,201,204,195,198,208,210,211,202,201,199,206,209,204,203,214,217,214,211,208,209,214,217,212,211,220,223,224,221,218,215,222,223,218,219, // H
    5,  7, 72, 75, 78, 80, 10, 85,  0, 68, 71, 75,204,201,210,207,197,195,196,205, 78, 80,205,202, 85,212,205,202,205,208,211,214,211,208,217,220,211,214,217,220,217,220,219,214,223,228, // I
  137,135,132, 71, 74, 76,142, 81,  4,  0, 67, 71, 16, 13, 80, 19,  9,  7,  8, 75, 74, 76, 17, 14, 81, 84, 17, 14, 17, 20, 81, 84, 23, 20, 87, 90, 23, 26, 29, 32, 29, 90, 31, 26, 93, 98, // J
   12, 10,  7,132,135,137, 17,142,  7,  3,  0, 68, 19, 16, 77, 80, 12, 10, 11, 72, 71, 73, 20, 17, 78, 81, 20, 17, 20, 81, 78, 81, 26, 23, 84, 87, 26, 29, 32, 93, 90, 87, 34, 29, 90, 95, // K
   16, 14, 11,  8, 71, 69, 21, 74, 11,  7,  4,  0,207,210,201,204, 16, 14,205,196,195,197,212, 21,202,205,214,211,208,205,202,205,220,217,208,211,220,217,220,217,214,211,228,223,214,219, // L
   75, 77, 80, 19, 16, 14, 70,  9, 76, 80, 83, 15,  0, 67,  6,  3, 71, 73, 74, 13, 12, 10,197,200, 11,  8,205, 80, 83, 86, 19, 16,205,208, 19, 16,211,214,217, 28, 25, 22,213,214, 25, 24, // M
  136,138,141,212, 19, 17,131, 12,201,205,208, 18,  3,  0,  9,  6,196,198,199,208, 15, 13,  8,201, 14, 11,206,205,208,211,214, 19, 16,209, 22, 19,212,215,218,223,220, 25, 24,215, 28, 27, // N
   81, 83,212,141,138,136, 76,131, 82,208,205,201, 70, 73,  0, 67, 77, 79, 80,199,198,196, 75, 78,201, 72, 83, 86,211,208,205,206, 83, 86,209, 80, 89,220,221,218,215,212, 91, 92,215, 88, // O
   78, 80, 83, 16, 13, 11, 73,  6, 79, 83, 16, 12, 67, 70,  3,  0, 74, 76, 77, 10,  9,  7, 72, 75,200,197, 80, 83, 86, 19, 16,205, 80, 83,208,205, 86, 89, 92,217,214,211, 88, 89,214,213, // P
   74, 76, 77, 80, 83, 21,  7, 16, 69, 73, 76, 80,  7,  4, 13, 10,  0, 66, 67, 76, 77, 79,200,197, 18, 15,202, 73, 76, 79, 82, 85,208,205, 88, 23,208,211,214, 91, 88, 91,216,211, 94, 31, // Q
  136,138,139,142,145,147,  9, 18,131,135,138,142,  9,  6, 15, 12,  2,  0, 65, 74, 75, 77, 10,  7, 82, 17, 74, 71, 74, 77, 80, 83, 80, 77, 86, 25, 80, 83, 86, 89, 86, 89, 88, 83, 92, 33, // R
    9, 11, 12, 15, 18, 82, 10, 19,  4,  8, 11, 77, 10,  7, 16, 13,  3,  1,  0, 73, 74, 76, 11,  8, 81, 18,201,198,201,204, 79, 82,207,204, 85, 88,207,210,213,216,213, 88,215,210, 91, 96, // S
   18, 82, 79, 76, 75, 73, 19, 74, 13, 75, 72, 68, 77, 16, 71, 74, 12, 10,  9,  0, 65, 67, 82, 17, 72, 75, 18, 15,204,201,198,201, 24, 21,204,207, 24,213,216,213,210,207, 32, 27,210,215, // T
  147,145,142,139,138,136, 82, 73,142,138,135,131, 76, 79, 70, 73, 13, 11, 10,  1,  0, 66, 81, 18, 71, 74, 19, 16, 13, 10,  7, 10, 89, 22, 13, 16, 25, 22, 25, 22, 19, 16, 97, 28, 19, 24, // U
   85, 19, 16, 13, 12, 10, 80, 71, 16, 12,  9,  5, 74, 77, 68, 71, 15, 13, 12,  3,  2,  0, 79, 82,197,200, 21, 18, 15, 12,  9,202, 87, 24,205,208, 27, 24,217,214,211,208, 95, 30,211,216, // V
  144,146,149,152,149,147,139,142, 77, 81, 84,148,133,136,139,136, 72, 74, 75,146,145,143,  0, 67,144,141, 72, 75, 78, 81, 84,149,200, 75,152,149, 78, 81, 84, 93, 90,155,208, 81,158,157, // W
   79, 81, 82, 85, 88, 22, 76, 17, 74, 78, 81, 85,  8, 73, 14, 11, 69, 71, 72, 81, 82, 18,  3,  0, 19, 16,197,200,203,206,209,212, 11,200,215, 24,203,206,209,218,215,218, 19,206,221, 32, // X
   86, 24, 21, 18, 17, 15, 81, 12, 21, 17, 14, 10, 75, 78,  9, 72, 82, 18, 17,  8,  7,  5, 80, 83,  0, 67,212,209,206,203,200,197, 88,215,200, 75,218,215,212,209,206,203, 96,221,206, 83, // Y
  147,149,152,149,146,144,142,139,148, 20, 17, 13,136,139,136,133,143,145,146, 11, 10,  8,141,144,  3,  0,149, 20, 17, 14, 11,  8,149,152, 11,200,155, 26, 23, 20, 17, 14,157,158, 17,208, // Z
   82, 84, 85, 88, 91, 27, 17, 22, 77, 81, 84, 86, 13, 14, 19, 16, 10, 74, 73, 82, 83, 85,  8,  5, 84, 21,  0, 67, 70, 73, 76, 79,198,195, 82, 85,198,201,204, 85, 82, 85,206,201, 88, 93, // a
  143,145,146,149,152,152,144,153,138,142,145,147,144,141,150,147,137,135,134,143,144,146, 11,  8, 81, 84,  3,  0, 67, 70, 73, 76,  9,  6, 79, 82,  9, 76, 79, 82, 79, 82, 17, 12, 85, 90, // b
   18, 20, 21, 24, 87, 85, 19, 86, 13, 17, 20, 80, 19, 16, 83, 22, 12, 10,  9, 76, 77, 79, 14, 11, 78, 81,  6,  3,  0, 67, 70, 73, 12,  9, 76, 79, 12,201,204, 79, 76, 79, 20, 15, 82, 87, // c
   21, 23, 24, 85, 84, 82, 22, 83, 16, 20, 81, 77, 22, 19, 80, 83, 15, 13, 12, 73, 74, 76, 17, 14, 75, 78,  9,  6,  3,  0, 67, 70, 15, 12, 73, 76, 15, 12, 15,204,201, 76, 23, 18, 79, 84, // d
  152,152,149,146,145,143,153,144,147,145,142,138,147,150,141,144,146,144,143,134,135,137, 20, 17, 72, 75, 12,  9,  6,  3,  0, 67, 18, 15, 70, 73, 18, 15, 18, 15, 12, 73, 26, 21, 76, 81, // e
   91, 27, 24, 21, 20, 18, 86, 81, 22, 20, 17, 13, 80, 83, 78, 77, 21, 19, 18,  9, 10, 74, 85, 20, 69, 72, 15, 12,  9,  6,  3,  0, 21, 18,195,198, 21, 18,207,204,201,198, 29, 24,201,206, // f
   24, 26, 91, 94, 29, 27, 19, 22, 83, 87, 90, 28, 13, 16, 19, 16, 16, 80, 79, 88, 25, 23,  8, 11, 24, 21, 70, 73, 76, 79, 82, 85,  0, 67, 88, 91, 70, 73, 76, 91, 88, 91,200, 73, 94, 99, // g
  149,151,152,155,158,158,148,153,144,148,151,153,144,145,150,147,141,141,140,149,150,152,139,136,151,152,131,134,137,140,143,146,  3,  0,149,152,195,198,201,152,149,152, 11,198,155,160, // h
  158,158,155,152,151,149,153,148,153,151,148,144,147,150,145,144,152,150,149,140,141,141,152,151,136,139,146,143,140,137,134,131,152,149,  0, 67,210,207,204,201,198,195,218,213,198, 75, // i
   91, 93, 30, 27, 90, 88, 86, 83, 92, 26, 23, 19, 80, 83, 80, 77, 87, 89, 24, 15, 16, 80, 85, 88, 75, 72, 21, 18, 15, 12,  9,  6, 27, 24,  3,  0, 21, 18, 15, 12,  9,  6, 29, 24,  9,200, // j
  152,154,155,158,161,161,151,156,147,151,154,156,147,148,153,150,144,144,143,152,153,155,142,139,154,155,134,137,140,143,146,149,134,131,152,155,  0, 67, 70,155,152,155,200,195,158,163, // k
  155,157,158,161,160,158, 26,159,150,154,157,153, 22, 23,156, 25, 19,147,146,149,150,152, 17, 14,151,154,  9,140,137,140,143,146,  9,  6,149,152,  3,  0, 67,152,149,152, 11,  6,155,160, // l
   30, 32, 33, 36, 35, 33, 29, 34, 25, 29, 32, 28, 25, 26, 31, 28, 22, 22, 21, 24, 25, 27, 20, 17, 26, 29, 12, 15, 12, 15, 18, 21, 12,  9, 24, 27,  6,  3,  0,219, 24, 27, 14,  9, 30, 35, // m
   33, 35, 36, 97, 96, 94, 32, 93, 28, 32, 93, 89, 28, 29, 90, 89, 25, 25, 24, 85, 86, 86, 23, 20, 81, 84, 15, 18, 15, 76, 79, 76, 15, 12, 73, 76,  9,  6,  3,  0, 67, 70, 17, 12, 73, 84, // n
  158,160,161,158,157,155,159, 90,153,157,154,150, 89,156, 87, 86,152,150,149,146,147, 83,154,151, 78, 81,146,143,140,137,140, 73, 18, 15, 70, 73, 12,  9,  6,  3,  0, 67, 20, 15, 70, 81, // o
  161,161,158,155,154,152,156,151,156,154,151,147,150,153,148,147,155,153,152,143,144,144,155,154,139,142,149,146,143,140,137,134, 21, 18,131,134, 15, 12,  9,  6,  3,  0, 23, 18,195,142, // p
  160,162,163,166,165,163,155,158,155,159,162,164,149,152,155,152,152,152,151,160,161,159,144,147,160,157,142,145,148,151,154,157,136,139,160,163,142,145,148,163,160,163,  0,203,166,171, // q
  155,157,158,161,164,164,154,159,150,154,157,159,150,151,156,153,147,147,146,155,156,158,145,142,157,158,137,140,143,146,149,152,137,134,155,158,131,134,137,158,155,158,  5,  0,161,166, // r
  164,164,161,158,157,155,159,154,159,157,154,150,153,156,151,150,158,156,155,146,147,147,158,157,142,145,152,149,146,143,140,137,152,149,134,137,146,143,140,137,134,131,154,149,  0,203, // s
  163,165,166,163,162,160,158,155,164,162,159,155,152,155,152,149,159,161,160,151,152,152,157,160,147,144,157,154,151,148,145,142, 29, 26,139,136, 23, 20, 17, 14, 11,  8, 31, 26,  5,  0, // t
//  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t  
};

const uint8_t junction_distance3[] = { // 6 bits for distance plus 2 bits for direction.  40x40
//  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   a   b   c   d   e   f   g   h   i   j   k   l   m   n
    0, 69, 78, 83,198, 73, 82, 85, 12, 79, 88, 91, 15, 82, 85, 26, 21, 88, 91, 94, 94, 97, 28, 25, 98,101, 30, 97,100,103, 33, 36, 33,106,109,106, 39, 42, 44,117, // A
    5,  0, 73, 78,199,196, 77, 80,205,202, 83, 86,208,205,208, 89,214,211,214,217,217,220,221,218,221,224,223,220,223,226,226,229,226,229,232,229,232,235,237,240, // B
   14,  9,  0, 69, 16, 13,196,199, 22, 19,202,205, 25,208,205,208,217,214,211,214,220,217,224,221,218,221,226,223,220,223,229,232,229,226,229,226,235,232,240,237, // C
   19, 14,  5,  0, 21, 18,  9,198, 27, 24, 15, 76, 90, 21, 18, 79, 30, 27, 24, 85, 33, 30, 37, 34, 89, 92, 39, 36, 33, 94, 42, 45, 42, 97,100, 97,106,103, 53,108, // D
    6, 71, 80, 85,  0, 67, 84, 87,198, 73, 82,215,201, 76, 79,212,207, 82, 85, 88, 88, 91,214,211, 92, 95,216, 91, 94, 97,219,222,219,100,103,100,225,228,230,111, // E
  137,132,141,146,  3,  0,145,148,  9,198,207,154, 12,201,204, 23, 18,207,210,213,213,216, 25, 22,217,220, 27,216,219,222, 30, 33, 30,225,228,225, 36,231, 41,236, // F
  146,141,132,137,148,145,  0, 67,154,207,198, 73, 87,204,201, 76,213,210,207, 82,216,213,220,217, 86, 89,222,219,216, 91,225,228,225, 94, 97, 94,231,100,236,105, // G
   21, 16,  7, 70, 23, 20,  3,  0,215, 18,  9,198,212, 15, 12,201, 24, 21, 18,207, 27, 24, 31, 28,211,214, 33, 30, 27,216, 36, 39, 36,219,222,219,228,225, 47,230, // H
   12, 77, 86, 91, 70, 73, 90,215,  0, 79, 88,209,195, 82, 85,206,201,204,215,212,210,213,208,205,216,219,210,213,216,219,213,216,213,222,225,224,219,222,224,233, // I
   15, 10, 19, 24,  9,  6,207,210, 15,  0,201,216, 18,195,198,213,204,201,204,207,207,210,211,208,211,214,213,210,213,216,216,219,216,219,222,219,222,225,227,230, // J
   88, 83, 74, 79,210,207, 70, 73,216,201,  0, 79,213,198,195, 82,207,204,201,204,210,207,214,211,208,211,216,213,210,213,219,222,219,216,219,216,225,222,230,227, // K
   27, 22, 13, 76,215, 26,  9,  6,209, 24, 15,  0,206, 21, 18,195,212,215,204,201,213,210,219,216,205,208,219,216,213,210,224,225,222,213,216,213,222,219,233,224, // L
  143,144,153,218,137,140,215,212,131,146, 85,206,  0, 79, 82,203, 70, 73,212,209, 79, 82, 77, 74,213, 88, 79, 82, 85, 88, 82, 85, 82, 91, 94, 93, 88, 91, 93,102, // M
  146,141, 80, 85,140,137, 76, 79,146,131, 70, 85, 15,  0, 67, 82,  9,  6, 73, 76, 12, 79, 16, 13, 80, 83, 18, 15, 82, 85, 21, 24, 21, 88, 91, 88, 27, 94, 32, 99, // N
   21, 16,141,146, 15, 12,137,140, 21,  6,131,146, 18,  3,  0, 79, 12,  9, 70, 73, 15, 76, 19, 16, 77, 80, 21, 18, 79, 82, 24, 27, 24, 85, 88, 85, 30, 91, 35, 96, // O
  218,153,144,143,212,215,140,137,206, 21,146,131,203, 18, 15,  0,209,212,  9,  6, 18, 15,216,213, 10, 13, 24, 21, 18, 15,221, 30, 27, 18, 21, 18, 27, 24, 38, 29, // P
  149,150, 89, 94,143,146, 85, 88,137, 76, 79,148,134, 73, 76,145,  0, 67, 82, 85, 73, 76,199,196,213,210,201, 76, 79, 82,204,207,204, 85, 88,215,210,213,215, 96, // Q
  152,147,150,155,146,143,146,149, 12,137,140, 23,  9,134,137, 20,  3,  0,143,146,198,201, 10,  7,212, 21, 12,201,204,207, 15, 18, 15,210,213,216, 21,216, 26,221, // R
  155,150,147,152,149,146,143,146, 87,140,137, 76, 84,137,134, 73,146,143,  0, 67,201,198, 85,212, 71, 74,207,204,201, 76,216,213,210, 79, 82, 79,216, 85,221, 90, // S
   30, 25,150,149, 24, 21,146,143,148, 15, 12,137,145, 12,  9,134, 21, 18,  3,  0, 12,  9,210,213,196,199, 18, 15, 12,201,215, 24, 21,204,207,204,213,210, 32,215, // T
   30, 25, 28, 33, 24, 21, 24, 27, 18, 15, 18, 85, 15, 12, 15, 82,  9,  6, 73, 76,  0, 67,206,203, 78, 81,198,195, 70, 73,207,204,201, 76, 79, 82,207, 82,212, 87, // U
   97, 92, 89, 94, 91, 88, 85, 88, 21, 82, 79, 82, 18, 79, 76, 79, 12,  9, 70, 73,  3,  0, 17, 14,203,206,  9,  6,195,198, 18, 15, 12,201,204,207, 18,207, 23,212, // V
   92, 93, 96,101, 86, 89, 92, 95, 80, 83, 86, 91, 77, 80, 83, 88, 71, 74,149,146, 78, 81,  0, 67,142,139, 72, 75, 84,147,197,200, 75,150,147,144, 81, 84,208,155, // W
  153,154,157,162,147,150,153,156,141,144,147,152,138,141,144,149,132,135,212, 21,203,206,  3,  0, 17, 14,197,200,209,212,  8, 11,200,215, 22, 19,206,209, 19,220, // X
  162,157,154,153,156,153,150,147,152,147,144,141,149,144,141,138, 85,212,135,132,206,203, 78, 81,  0, 67,212,209,200,197, 83, 86,215,200,203, 72,209,206,220,211, // Y
   37, 32, 29, 28, 31, 28, 25, 22,155, 22, 19, 16,152, 19, 16, 13,146,149, 10,  7, 17, 14,139,142,  3,  0,147, 20, 11,  8,144,147,150, 11,200,197, 20, 17,155,208, // Z
   30, 31, 34, 39, 24, 27, 30, 33, 18, 21, 24, 91, 15, 18, 21, 88,  9, 12, 79, 82, 70, 73,  8,  5, 84, 19,  0, 67, 76, 79,201,198,195, 82, 85, 24,201,204,206,215, // a
  161,156,159,164,155,152,155,158,149,146,149,152,146,143,146,149,140,137,140,143,131,134, 11,  8,209,212,  3,  0,201,204, 12,  9,  6,207,210,213, 12, 15, 17,218, // b
  164,159,156,161,158,155,152,155,152,149,146,149,149,146,143,146,143,140,137,140,134,131,212,209, 72, 75,204,201,  0, 67,213,210,207, 70, 73, 76, 79, 76,218, 81, // c
  103, 98, 95, 94, 97, 94, 91, 88, 27, 88, 85, 82, 24, 85, 82, 79, 18, 15, 76, 73,  9,  6, 83, 20, 69, 72, 15, 12,  3,  0, 88, 21, 18,195,198,201,204,201,215,206, // d
  161,162,165,170,155,158,161,164,149,152,155,160,146,149,152,157,140,143, 88,151, 79, 82,133,136,147,144, 73, 76, 85,152,  0, 67, 70, 85,152,149, 76, 79, 11, 90, // e
   36, 37, 40, 45, 30, 33, 36, 39, 24, 27, 30, 97, 21, 24, 27, 94, 15, 18, 85, 88, 76, 79,  8, 11, 22, 19, 70, 73, 82, 85,  3,  0, 67, 82, 85, 24, 73, 76,200, 87, // f
  161,162,165,170,155,158,161,164,149,152,155,158,146,149,152,155,140,143,146,149,137,140,139,136,151,150,131,134,143,146,  6,  3,  0,207,210,213,198,201, 11,212, // g
  170,165,162,161,164,161,158,155,158,155,152,149,155,152,149,146,149,146,143,140,140,137,150,151,136,139,146,143,134,131,213,210,207,  0, 67, 70,201,198,212, 75, // h
   45, 40, 37, 36, 39, 36, 33, 30, 33, 30, 27, 24, 30, 27, 24, 21, 24, 21, 18, 15, 15, 12, 83, 86, 11, 72, 21, 18,  9,  6, 88, 21, 18,  3,  0, 67, 12,  9, 23,200, // i
  170,165,162,161,164,161,158,155,160,155,152,149,157,152,149,146,151, 24,143,140, 18, 15,144,147,136,133,152, 21, 12,  9,149,152, 21,  6,  3,  0, 15, 12, 26, 75, // j
   39, 40, 43,106, 33, 36, 39,100, 27, 30, 33, 94, 24, 27, 30, 91, 18, 21, 24, 85, 15, 18, 17, 14, 81, 84,  9, 12, 79, 76, 12,  9,  6, 73, 76, 79,  0, 67,203, 78, // k
   42,107,104,103, 36,103,100, 97, 30, 97, 94, 91, 27, 94, 91, 88, 21, 88, 85, 82, 82, 79, 20, 17, 78, 81, 12, 15, 76, 73, 15, 12,  9, 70, 73, 76,  3,  0, 14,203, // l
   44, 45, 48, 53, 38, 41, 44, 47, 32, 35, 38,169, 29, 32, 35,166, 23, 26,157,160,148,151, 16, 19, 92, 27,142,145,154, 87, 11,136,139, 84, 87, 90, 75, 78,  0, 89, // m
  181,176,173,172,175,172,169,166,169,166,163,160,166,163,160,157,160,157,154,151,151,148, 91, 28,147, 80, 23,154,145,142, 26, 23, 20,139,136, 75, 14, 11, 25,  0, // n
//  A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z   a   b   c   d   e   f   g   h   i   j   k   l   m   n
};

const uint8_t * const junction_distance[4] IN_ROM = {junction_distance0, junction_distance1, junction_distance2, junction_distance3};

const uint8_t jsize[4] IN_ROM = {38, 36, 46, 40};
  

#endif // _JTABLES_H_
