
/* Column Binary to ASCII conversion */

/* Assume row 12 is the high-order bit and row 9 is the low-order bit */

#define P0  001000  /* row 0  */
#define P1  000400  /* row 1  */
#define P2  000200  /* row 2  */
#define P3  000100  /* row 3  */
#define P4  000040  /* row 4  */
#define P5  000020  /* row 5  */
#define P6  000010  /* row 6  */
#define P7  000004  /* row 7  */
#define P8  000002  /* row 8  */
#define P9  000001  /* row 9  */
#define P11 000002  /* row 11 */
#define P12 000001  /* row 12 */
#define P13 010000  /* space = no punch */
#define P14 020000  /* line feed = new card */
#define NONE 017777 /* no ASCII <-> punch correspondence */

/*
  SIMH 1401 BCD encoding:

  Numeric     b 1 2 3 4 5 6 7 8 9 0 3 4 5 6 7
  Rows        b                     8 8 8 8 8
  ===========================================
  No zone       1 2 3 4 5 6 7 8 9 0 # @ : > (  000-017 = 00-0F
  0  zone A   ^ / S T U V W X Y Z ' , % = \ +  020-037 = 10-1F
  11 zone B   - J K L M N O P Q R ! $ * ] ; _  040-057 = 20-2F
  12 zone BA  & A B C D E F G H I ? . ) [ < "  060-077 = 30-3F

  ' is 0-2-8, and ^ has no input punch
  (it may punch as zero on output).
*/

const char ascii_to_cb_simh[128] = {
        /* 0000 - 0037: Control chars */
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   P14,    NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  

        000,       P11+P0,    P12+P7+P8, P3+P8,     /* 0040-0043:  !"# */
        P11+P3+P8, P0+P4+P8,  P12,       P0+P2+P8,  /* 0044-0047: $%&' */
        P7+P8,     P12+P4+P8, P11+P4+P8, P0+P7+P8,  /* 0050-0053: ()*+ */
        P0+P3+P8,  P11,       P12+P3+P8, P0+P1,     /* 0054-0057: ,-./ */
        P0,        P1,        P2,        P3,        /* 0060-0063: 0123 */
        P4,        P5,        P6,        P7,        /* 0064-0067: 4567 */
        P8,        P9,        P5+P8,     P11+P6+P8, /* 0070-0073: 89:; */
        P12+P6+P8, P0+P5+P8,  P6+P8,     P12+P0,    /* 0074-0077: <=>? */

        P4+P8,     P12+P1,    P12+P2,    P12+P3,    /* 0100-0103: @ABC */
        P12+P4,    P12+P5,    P12+P6,    P12+P7,    /* 0104-0107: DEFG */
        P12+P8,    P12+P9,    P11+P1,    P11+P2,    /* 0110-0113: HIJK */
        P11+P3,    P11+P4,    P11+P5,    P11+P6     /* 0114-0117: LMNO */
        P11+P7,    P11+P8,    P11+P9,    P0+P2,     /* 0120-0123: PQRS */
        P0+P3,     P0+P4,     P0+P5,     P0+P6,     /* 0124-0127: TUVW */
        P0+P7,     P0+P8,     P0+P9,     P12+P5+P8, /* 0130-0133: XYZ[ */
        P0+P6+P8,  P11+P5+P8, NONE,      P11+P7+P8, /* 0134-0137: \]^_ */

        NONE,      P12+P1,    P12+P2,    P12+P3,    /* 0140-0143: @abc */
        P12+P4,    P12+P5,    P12+P6,    P12+P7,    /* 0144-0147: defg */
        P12+P8,    P12+P9,    P11+P1,    P11+P2,    /* 0150-0153: hijk */
        P11+P3,    P11+P4,    P11+P5,    P11+P6     /* 0154-0157: lmno */
        P11+P7,    P11+P8,    P11+P9,    P0+P2,     /* 0160-0163: pqrs */
        P0+P3,     P0+P4,     P0+P5,     P0+P6,     /* 0164-0167: tuvw */
        P0+P7,     P0+P8,     P0+P9,     NONE,      /* 0170-0137: xyz{ */
        NONE,      NONE,      NONE,      NONE   ]   /* 0174-0177: |}~DEL */
/*
  Pierce's primary (A) BCD encoding:

  Numeric     b 1 2 3 4 5 6 7 8 9 0 3 4 5 6 7
  Rows        b                     8 8 8 8 8
  ===========================================
  No zone       1 2 3 4 5 6 7 8 9 0 # @ : > {  000-017 = 00-0F
  0  zone A   ^ / S T U V W X Y Z | , % ~ \ "  020-037 = 10-1F
  11 zone B   - J K L M N O P Q R ! $ * ] ; _  040-057 = 20-2F
  12 zone BA  & A B C D E F G H I ? . ) [ < }  060-077 = 30-3F

  | is 0-2-8, and ^ has no input punch
  (it may punch as zero on output).
*/

const char ascii_to_cb_Pierce_A[128] = {
        /* 0000 - 0037: Control chars */
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   P14,    NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  

        000,       P11+P0,    P0+P7+P8,  P3+P8,     /* 0040-0043:  !"# */
        P11+P3+P8, P0+P4+P8,  P12,       NONE,      /* 0044-0047: $%&' */
        NONE,      P12+P4+P8, P11+P4+P8, NONE,      /* 0050-0053: ()*+ */
        P0+P3+P8,  P11,       P12+P3+P8, P0+P1,     /* 0054-0057: ,-./ */
        P0,        P1,        P2,        P3,        /* 0060-0063: 0123 */
        P4,        P5,        P6,        P7,        /* 0064-0067: 4567 */
        P8,        P9,        P5+P8,     P11+P6+P8, /* 0070-0073: 89:; */
        P12+P6+P8, NONE,      P6+P8,     P12+P0,    /* 0074-0077: <=>? */

        P4+P8,     P12+P1,    P12+P2,    P12+P3,    /* 0100-0103: @ABC */
        P12+P4,    P12+P5,    P12+P6,    P12+P7,    /* 0104-0107: DEFG */
        P12+P8,    P12+P9,    P11+P1,    P11+P2,    /* 0110-0113: HIJK */
        P11+P3,    P11+P4,    P11+P5,    P11+P6     /* 0114-0117: LMNO */
        P11+P7,    P11+P8,    P11+P9,    P0+P2,     /* 0120-0123: PQRS */
        P0+P3,     P0+P4,     P0+P5,     P0+P6,     /* 0124-0127: TUVW */
        P0+P7,     P0+P8,     P0+P9,     P12+P5+P8, /* 0130-0133: XYZ[ */
        P0+P6+P8,  P11+P5+P8, NONE,      P11+P7+P8, /* 0134-0137: \]^_ */

        NONE,      P12+P1,    P12+P2,    P12+P3,    /* 0140-0143: @abc */
        P12+P4,    P12+P5,    P12+P6,    P12+P7,    /* 0144-0147: defg */
        P12+P8,    P12+P9,    P11+P1,    P11+P2,    /* 0150-0153: hijk */
        P11+P3,    P11+P4,    P11+P5,    P11+P6     /* 0154-0157: lmno */
        P11+P7,    P11+P8,    P11+P9,    P0+P2,     /* 0160-0163: pqrs */
        P0+P3,     P0+P4,     P0+P5,     P0+P6,     /* 0164-0167: tuvw */
        P0+P7,     P0+P8,     P0+P9,     P7+P8,     /* 0170-0137: xyz{ */
        P0+P2+P8,  P12+P7+P8, P0+P5+P8,  NONE   ]   /* 0174-0177: |}~DEL */
/*
  Pierce's alternate (H) BCD encoding:

  Numeric     b 1 2 3 4 5 6 7 8 9 0 3 4 5 6 7
  Rows        b                     8 8 8 8 8
  ===========================================
  No zone       1 2 3 4 5 6 7 8 9 0 = ' : > {  000-017 = 00-0F
  0  zone A   ^ / S T U V W X Y Z | , ( ~ \ "  020-037 = 10-1F
  11 zone B   - J K L M N O P Q R ! $ * ] ; _  040-057 = 20-2F
  12 zone BA  + A B C D E F G H I ? . ) [ < }  060-077 = 30-3F

  | is 0-2-8, and ^ has no input punch
  (it may punch as zero on output).
*/

const char ascii_to_cb_Pierce_H[128] = {
        /* 0000 - 0037: Control chars */
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   P14,    NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  
	NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,   NONE,  

        000,       P11+P0,    P0+P7+P8,  NONE,      /* 0040-0043:  !"# */
        P11+P3+P8, NONE,      NONE,      P4+P8,     /* 0044-0047: $%&' */
        P0+P4+P8,  P12+P4+P8, P11+P4+P8, P12,       /* 0050-0053: ()*+ */
        P0+P3+P8,  P11,       P12+P3+P8, P0+P1,     /* 0054-0057: ,-./ */
        P0,        P1,        P2,        P3,        /* 0060-0063: 0123 */
        P4,        P5,        P6,        P7,        /* 0064-0067: 4567 */
        P8,        P9,        P5+P8,     P11+P6+P8, /* 0070-0073: 89:; */
        P12+P6+P8, P3+P8,     P6+P8,     P12+P0,    /* 0074-0077: <=>? */

        NONE,      P12+P1,    P12+P2,    P12+P3,    /* 0100-0103: @ABC */
        P12+P4,    P12+P5,    P12+P6,    P12+P7,    /* 0104-0107: DEFG */
        P12+P8,    P12+P9,    P11+P1,    P11+P2,    /* 0110-0113: HIJK */
        P11+P3,    P11+P4,    P11+P5,    P11+P6     /* 0114-0117: LMNO */
        P11+P7,    P11+P8,    P11+P9,    P0+P2,     /* 0120-0123: PQRS */
        P0+P3,     P0+P4,     P0+P5,     P0+P6,     /* 0124-0127: TUVW */
        P0+P7,     P0+P8,     P0+P9,     P12+P5+P8, /* 0130-0133: XYZ[ */
        P0+P6+P8,  P11+P5+P8, NONE,      P11+P7+P8, /* 0134-0137: \]^_ */

        NONE,      P12+P1,    P12+P2,    P12+P3,    /* 0140-0143: @abc */
        P12+P4,    P12+P5,    P12+P6,    P12+P7,    /* 0144-0147: defg */
        P12+P8,    P12+P9,    P11+P1,    P11+P2,    /* 0150-0153: hijk */
        P11+P3,    P11+P4,    P11+P5,    P11+P6     /* 0154-0157: lmno */
        P11+P7,    P11+P8,    P11+P9,    P0+P2,     /* 0160-0163: pqrs */
        P0+P3,     P0+P4,     P0+P5,     P0+P6,     /* 0164-0167: tuvw */
        P0+P7,     P0+P8,     P0+P9,     P7+P8,     /* 0170-0137: xyz{ */
        P0+P2+P8,  P12+P7+P8, P0+P5+P8,  NONE   ]   /* 0174-0177: |}~DEL */
/*
  Differences:     12  0        0  0     0 12
                       2  3  4  4  5  7  7  7
                       8  8  8  8  8  8  8  8
  ===========================================
              SIMH  &  '  #  @  %  =  (  +  "
    Pierce Primary  &  |  #  @  %  ~  {  "  }
  Pierce Alternate  +  |  =  '  (  ~  {  "  }

 In BCD order, blank to GM:
 IBM A: 1234567890#@:>{^/STUVWXYZ|,%~\"-JKLMNOPQR!$*];_&ABCDEFGHI?.)[<}
 IBM H: 1234567890=':>{^/STUVWXYZ|,(~\"-JKLMNOPQR!$*];_+ABCDEFGHI?.)[<}
  SimH: 1234567890#@:>(^/STUVWXYZ',%=\+-JKLMNOPQR!$*];_&ABCDEFGHI?.)[<"

*/
