Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

424 lines
21 KiB

  1. /***************************************************************************
  2. Name : ENCODER.C
  3. Comment : HDLC encoding routines
  4. Functions: (see Prototypes just below)
  5. Copyright (c) Microsoft Corp. 1991 1992 1993
  6. Revision Log
  7. Date Name Description
  8. -------- ----- ---------------------------------------------------------
  9. ***************************************************************************/
  10. #include "prep.h"
  11. #include "encoder.h"
  12. #include "debug.h"
  13. #include "glbproto.h"
  14. #define faxTlog(m) DEBUGMSG(ZONE_SWFRAME, m)
  15. #define FILEID FILEID_ENCODER
  16. extern BYTE CODEBASED EncLen[5][256], CODEBASED EncWidth[5][256];
  17. extern WORD CODEBASED EncOut[5][256];
  18. USHORT SWECMEXP HDLC_Encode(PThrdGlbl pTG, LPBYTE lpbSrc, USHORT cbSrc, LPBYTE lpbDst, LPENCODESTATE lpState)
  19. {
  20. // Processes all cbSrc input bytes
  21. // Returns number of bytes written to lpbDst
  22. USHORT cbDst;
  23. #ifdef PORTABLE_CODE
  24. BYTE StateLen = lpState->len;
  25. BYTE StateCarry = lpState->carry;
  26. BYTE StateWidth = lpState->enc_width;
  27. USHORT SrcSize;
  28. BYTE InByte;
  29. LPBYTE CurrentSrc = lpbSrc;
  30. LPBYTE CurrentDst = lpbDst;
  31. ULONG EncodeWord; //must be ULONG because value can be up to 17 bits
  32. #ifdef CLASS1_TEST_HOOKS
  33. BYTE TstlpbDst[((USHORT)(((4 + 256 + 2) * 1.2) + 10))]; //Size = FRAMEBUFINITIALSIZE from framing.c
  34. ENCODESTATE TstState;
  35. LPENCODESTATE TstlpState = & TstState;
  36. USHORT TstcbDst;
  37. USHORT i;
  38. USHORT BadFlag = FALSE;
  39. CurrentDst = TstlpbDst;
  40. #endif //CLASS1_TEST_HOOKS
  41. for (SrcSize = cbSrc; SrcSize > 0; SrcSize--) {
  42. InByte = *CurrentSrc++;
  43. EncodeWord = (((ULONG)EncOut[StateLen][InByte]) << StateWidth) | StateCarry;
  44. *CurrentDst++ = LOBYTE(EncodeWord);
  45. EncodeWord >>= 8;
  46. StateWidth += EncWidth[StateLen][InByte];
  47. StateLen = EncLen[StateLen][InByte];
  48. if (StateWidth < 8) {
  49. StateCarry = LOBYTE(EncodeWord);
  50. }
  51. else {
  52. *CurrentDst++ = LOBYTE(EncodeWord);
  53. StateCarry = HIBYTE(EncodeWord);
  54. StateWidth -= 8;
  55. }
  56. }
  57. #ifdef CLASS1_TEST_HOOKS
  58. TstlpState->carry = StateCarry;
  59. TstlpState->enc_width = StateWidth;
  60. TstlpState->len = StateLen;
  61. TstcbDst = CurrentDst - TstlpbDst;
  62. #else
  63. lpState->carry = StateCarry;
  64. lpState->enc_width = StateWidth;
  65. lpState->len = StateLen;
  66. cbDst = (USHORT)(CurrentDst - lpbDst);
  67. #endif
  68. #endif //PORTABLE_CODE
  69. #ifdef CLASS1_TEST_HOOKS
  70. for (i = 0;( i < cbDst) && !BadFlag; i++) {
  71. if (lpbDst[i] != TstlpbDst[i]) {
  72. BadFlag = TRUE;
  73. }
  74. }
  75. if (BadFlag || (TstcbDst != cbDst) || (lpState->carry != TstlpState->carry) || (lpState->len != TstlpState->len) ||
  76. (lpState->enc_width != TstlpState->enc_width)){
  77. ERRORMSG(("HDLC_Encode: Assembly Encode != C Encode\n"));
  78. DebugBreak();
  79. }
  80. #endif //CLASS1_TEST_HOOKS
  81. return cbDst;
  82. }
  83. BYTE RotFlag[8] = { 0x7e, 0xfc, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3f };
  84. BYTE LowBits[8] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f };
  85. USHORT SWECMEXP HDLC_AddFlags(PThrdGlbl pTG, LPBYTE lpbDst, USHORT cbFlags, LPENCODESTATE lpState)
  86. {
  87. USHORT i;
  88. // faxTlog((SZMOD "iAddF c=%02x w=%d l=%d\r\n", lpState->carry, lpState->enc_width, lpState->len));
  89. BG_CHK(lpState->enc_width < 8);
  90. *lpbDst = lpState->carry;
  91. *lpbDst++ |= (0x7E << lpState->enc_width);
  92. lpState->len = 0;
  93. lpState->carry = RotFlag[lpState->enc_width];
  94. // lpState->enc_width is unchanged
  95. for(i=0; i<cbFlags-1; i++)
  96. {
  97. *lpbDst++ = lpState->carry;
  98. }
  99. // zap out high (8-width) bits of carry
  100. lpState->carry &= LowBits[lpState->enc_width];
  101. // faxTlog((SZMOD "xAddF c=%02x w=%d l=%d\r\n", lpState->carry, lpState->enc_width, lpState->len));
  102. return cbFlags;
  103. }
  104. BYTE CODEBASED EncLen[5][256] = {
  105. // Input Len = 0
  106. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  111. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  112. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 2,
  195. 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
  196. 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 2, 1, 2, 1, 2, 1, 2 }
  197. }; // W2
  198. WORD CODEBASED EncOut[5][256] = {
  199. // Input Len = 0
  200. {0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
  201. 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
  202. 0x010, 0x011, 0x012, 0x013, 0x014, 0x015, 0x016, 0x017,
  203. 0x018, 0x019, 0x01a, 0x01b, 0x01c, 0x01d, 0x01e, 0x01f,
  204. 0x020, 0x021, 0x022, 0x023, 0x024, 0x025, 0x026, 0x027,
  205. 0x028, 0x029, 0x02a, 0x02b, 0x02c, 0x02d, 0x02e, 0x02f,
  206. 0x030, 0x031, 0x032, 0x033, 0x034, 0x035, 0x036, 0x037,
  207. 0x038, 0x039, 0x03a, 0x03b, 0x03c, 0x03d, 0x03e, 0x05f,
  208. 0x040, 0x041, 0x042, 0x043, 0x044, 0x045, 0x046, 0x047,
  209. 0x048, 0x049, 0x04a, 0x04b, 0x04c, 0x04d, 0x04e, 0x04f,
  210. 0x050, 0x051, 0x052, 0x053, 0x054, 0x055, 0x056, 0x057,
  211. 0x058, 0x059, 0x05a, 0x05b, 0x05c, 0x05d, 0x05e, 0x09f,
  212. 0x060, 0x061, 0x062, 0x063, 0x064, 0x065, 0x066, 0x067,
  213. 0x068, 0x069, 0x06a, 0x06b, 0x06c, 0x06d, 0x06e, 0x06f,
  214. 0x070, 0x071, 0x072, 0x073, 0x074, 0x075, 0x076, 0x077,
  215. 0x078, 0x079, 0x07a, 0x07b, 0x07c, 0x07d, 0x0be, 0x0df,
  216. 0x080, 0x081, 0x082, 0x083, 0x084, 0x085, 0x086, 0x087,
  217. 0x088, 0x089, 0x08a, 0x08b, 0x08c, 0x08d, 0x08e, 0x08f,
  218. 0x090, 0x091, 0x092, 0x093, 0x094, 0x095, 0x096, 0x097,
  219. 0x098, 0x099, 0x09a, 0x09b, 0x09c, 0x09d, 0x09e, 0x11f,
  220. 0x0a0, 0x0a1, 0x0a2, 0x0a3, 0x0a4, 0x0a5, 0x0a6, 0x0a7,
  221. 0x0a8, 0x0a9, 0x0aa, 0x0ab, 0x0ac, 0x0ad, 0x0ae, 0x0af,
  222. 0x0b0, 0x0b1, 0x0b2, 0x0b3, 0x0b4, 0x0b5, 0x0b6, 0x0b7,
  223. 0x0b8, 0x0b9, 0x0ba, 0x0bb, 0x0bc, 0x0bd, 0x13e, 0x15f,
  224. 0x0c0, 0x0c1, 0x0c2, 0x0c3, 0x0c4, 0x0c5, 0x0c6, 0x0c7,
  225. 0x0c8, 0x0c9, 0x0ca, 0x0cb, 0x0cc, 0x0cd, 0x0ce, 0x0cf,
  226. 0x0d0, 0x0d1, 0x0d2, 0x0d3, 0x0d4, 0x0d5, 0x0d6, 0x0d7,
  227. 0x0d8, 0x0d9, 0x0da, 0x0db, 0x0dc, 0x0dd, 0x0de, 0x19f,
  228. 0x0e0, 0x0e1, 0x0e2, 0x0e3, 0x0e4, 0x0e5, 0x0e6, 0x0e7,
  229. 0x0e8, 0x0e9, 0x0ea, 0x0eb, 0x0ec, 0x0ed, 0x0ee, 0x0ef,
  230. 0x0f0, 0x0f1, 0x0f2, 0x0f3, 0x0f4, 0x0f5, 0x0f6, 0x0f7,
  231. 0x0f8, 0x0f9, 0x0fa, 0x0fb, 0x17c, 0x17d, 0x1be, 0x1df },
  232. // Input Len = 1
  233. {0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
  234. 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
  235. 0x010, 0x011, 0x012, 0x013, 0x014, 0x015, 0x016, 0x017,
  236. 0x018, 0x019, 0x01a, 0x01b, 0x01c, 0x01d, 0x01e, 0x02f,
  237. 0x020, 0x021, 0x022, 0x023, 0x024, 0x025, 0x026, 0x027,
  238. 0x028, 0x029, 0x02a, 0x02b, 0x02c, 0x02d, 0x02e, 0x04f,
  239. 0x030, 0x031, 0x032, 0x033, 0x034, 0x035, 0x036, 0x037,
  240. 0x038, 0x039, 0x03a, 0x03b, 0x03c, 0x03d, 0x03e, 0x06f,
  241. 0x040, 0x041, 0x042, 0x043, 0x044, 0x045, 0x046, 0x047,
  242. 0x048, 0x049, 0x04a, 0x04b, 0x04c, 0x04d, 0x04e, 0x08f,
  243. 0x050, 0x051, 0x052, 0x053, 0x054, 0x055, 0x056, 0x057,
  244. 0x058, 0x059, 0x05a, 0x05b, 0x05c, 0x05d, 0x05e, 0x0af,
  245. 0x060, 0x061, 0x062, 0x063, 0x064, 0x065, 0x066, 0x067,
  246. 0x068, 0x069, 0x06a, 0x06b, 0x06c, 0x06d, 0x06e, 0x0cf,
  247. 0x070, 0x071, 0x072, 0x073, 0x074, 0x075, 0x076, 0x077,
  248. 0x078, 0x079, 0x07a, 0x07b, 0x07c, 0x07d, 0x0be, 0x0ef,
  249. 0x080, 0x081, 0x082, 0x083, 0x084, 0x085, 0x086, 0x087,
  250. 0x088, 0x089, 0x08a, 0x08b, 0x08c, 0x08d, 0x08e, 0x10f,
  251. 0x090, 0x091, 0x092, 0x093, 0x094, 0x095, 0x096, 0x097,
  252. 0x098, 0x099, 0x09a, 0x09b, 0x09c, 0x09d, 0x09e, 0x12f,
  253. 0x0a0, 0x0a1, 0x0a2, 0x0a3, 0x0a4, 0x0a5, 0x0a6, 0x0a7,
  254. 0x0a8, 0x0a9, 0x0aa, 0x0ab, 0x0ac, 0x0ad, 0x0ae, 0x14f,
  255. 0x0b0, 0x0b1, 0x0b2, 0x0b3, 0x0b4, 0x0b5, 0x0b6, 0x0b7,
  256. 0x0b8, 0x0b9, 0x0ba, 0x0bb, 0x0bc, 0x0bd, 0x13e, 0x16f,
  257. 0x0c0, 0x0c1, 0x0c2, 0x0c3, 0x0c4, 0x0c5, 0x0c6, 0x0c7,
  258. 0x0c8, 0x0c9, 0x0ca, 0x0cb, 0x0cc, 0x0cd, 0x0ce, 0x18f,
  259. 0x0d0, 0x0d1, 0x0d2, 0x0d3, 0x0d4, 0x0d5, 0x0d6, 0x0d7,
  260. 0x0d8, 0x0d9, 0x0da, 0x0db, 0x0dc, 0x0dd, 0x0de, 0x1af,
  261. 0x0e0, 0x0e1, 0x0e2, 0x0e3, 0x0e4, 0x0e5, 0x0e6, 0x0e7,
  262. 0x0e8, 0x0e9, 0x0ea, 0x0eb, 0x0ec, 0x0ed, 0x0ee, 0x1cf,
  263. 0x0f0, 0x0f1, 0x0f2, 0x0f3, 0x0f4, 0x0f5, 0x0f6, 0x0f7,
  264. 0x0f8, 0x0f9, 0x0fa, 0x0fb, 0x17c, 0x17d, 0x1be, 0x1ef },
  265. // Input Len = 2
  266. {0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
  267. 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x017,
  268. 0x010, 0x011, 0x012, 0x013, 0x014, 0x015, 0x016, 0x027,
  269. 0x018, 0x019, 0x01a, 0x01b, 0x01c, 0x01d, 0x01e, 0x037,
  270. 0x020, 0x021, 0x022, 0x023, 0x024, 0x025, 0x026, 0x047,
  271. 0x028, 0x029, 0x02a, 0x02b, 0x02c, 0x02d, 0x02e, 0x057,
  272. 0x030, 0x031, 0x032, 0x033, 0x034, 0x035, 0x036, 0x067,
  273. 0x038, 0x039, 0x03a, 0x03b, 0x03c, 0x03d, 0x03e, 0x077,
  274. 0x040, 0x041, 0x042, 0x043, 0x044, 0x045, 0x046, 0x087,
  275. 0x048, 0x049, 0x04a, 0x04b, 0x04c, 0x04d, 0x04e, 0x097,
  276. 0x050, 0x051, 0x052, 0x053, 0x054, 0x055, 0x056, 0x0a7,
  277. 0x058, 0x059, 0x05a, 0x05b, 0x05c, 0x05d, 0x05e, 0x0b7,
  278. 0x060, 0x061, 0x062, 0x063, 0x064, 0x065, 0x066, 0x0c7,
  279. 0x068, 0x069, 0x06a, 0x06b, 0x06c, 0x06d, 0x06e, 0x0d7,
  280. 0x070, 0x071, 0x072, 0x073, 0x074, 0x075, 0x076, 0x0e7,
  281. 0x078, 0x079, 0x07a, 0x07b, 0x07c, 0x07d, 0x0be, 0x0f7,
  282. 0x080, 0x081, 0x082, 0x083, 0x084, 0x085, 0x086, 0x107,
  283. 0x088, 0x089, 0x08a, 0x08b, 0x08c, 0x08d, 0x08e, 0x117,
  284. 0x090, 0x091, 0x092, 0x093, 0x094, 0x095, 0x096, 0x127,
  285. 0x098, 0x099, 0x09a, 0x09b, 0x09c, 0x09d, 0x09e, 0x137,
  286. 0x0a0, 0x0a1, 0x0a2, 0x0a3, 0x0a4, 0x0a5, 0x0a6, 0x147,
  287. 0x0a8, 0x0a9, 0x0aa, 0x0ab, 0x0ac, 0x0ad, 0x0ae, 0x157,
  288. 0x0b0, 0x0b1, 0x0b2, 0x0b3, 0x0b4, 0x0b5, 0x0b6, 0x167,
  289. 0x0b8, 0x0b9, 0x0ba, 0x0bb, 0x0bc, 0x0bd, 0x13e, 0x177,
  290. 0x0c0, 0x0c1, 0x0c2, 0x0c3, 0x0c4, 0x0c5, 0x0c6, 0x187,
  291. 0x0c8, 0x0c9, 0x0ca, 0x0cb, 0x0cc, 0x0cd, 0x0ce, 0x197,
  292. 0x0d0, 0x0d1, 0x0d2, 0x0d3, 0x0d4, 0x0d5, 0x0d6, 0x1a7,
  293. 0x0d8, 0x0d9, 0x0da, 0x0db, 0x0dc, 0x0dd, 0x0de, 0x1b7,
  294. 0x0e0, 0x0e1, 0x0e2, 0x0e3, 0x0e4, 0x0e5, 0x0e6, 0x1c7,
  295. 0x0e8, 0x0e9, 0x0ea, 0x0eb, 0x0ec, 0x0ed, 0x0ee, 0x1d7,
  296. 0x0f0, 0x0f1, 0x0f2, 0x0f3, 0x0f4, 0x0f5, 0x0f6, 0x1e7,
  297. 0x0f8, 0x0f9, 0x0fa, 0x0fb, 0x17c, 0x17d, 0x1be, 0x1f7 },
  298. // Input Len = 3
  299. {0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x00b,
  300. 0x008, 0x009, 0x00a, 0x013, 0x00c, 0x00d, 0x00e, 0x01b,
  301. 0x010, 0x011, 0x012, 0x023, 0x014, 0x015, 0x016, 0x02b,
  302. 0x018, 0x019, 0x01a, 0x033, 0x01c, 0x01d, 0x01e, 0x03b,
  303. 0x020, 0x021, 0x022, 0x043, 0x024, 0x025, 0x026, 0x04b,
  304. 0x028, 0x029, 0x02a, 0x053, 0x02c, 0x02d, 0x02e, 0x05b,
  305. 0x030, 0x031, 0x032, 0x063, 0x034, 0x035, 0x036, 0x06b,
  306. 0x038, 0x039, 0x03a, 0x073, 0x03c, 0x03d, 0x03e, 0x07b,
  307. 0x040, 0x041, 0x042, 0x083, 0x044, 0x045, 0x046, 0x08b,
  308. 0x048, 0x049, 0x04a, 0x093, 0x04c, 0x04d, 0x04e, 0x09b,
  309. 0x050, 0x051, 0x052, 0x0a3, 0x054, 0x055, 0x056, 0x0ab,
  310. 0x058, 0x059, 0x05a, 0x0b3, 0x05c, 0x05d, 0x05e, 0x0bb,
  311. 0x060, 0x061, 0x062, 0x0c3, 0x064, 0x065, 0x066, 0x0cb,
  312. 0x068, 0x069, 0x06a, 0x0d3, 0x06c, 0x06d, 0x06e, 0x0db,
  313. 0x070, 0x071, 0x072, 0x0e3, 0x074, 0x075, 0x076, 0x0eb,
  314. 0x078, 0x079, 0x07a, 0x0f3, 0x07c, 0x07d, 0x0be, 0x0fb,
  315. 0x080, 0x081, 0x082, 0x103, 0x084, 0x085, 0x086, 0x10b,
  316. 0x088, 0x089, 0x08a, 0x113, 0x08c, 0x08d, 0x08e, 0x11b,
  317. 0x090, 0x091, 0x092, 0x123, 0x094, 0x095, 0x096, 0x12b,
  318. 0x098, 0x099, 0x09a, 0x133, 0x09c, 0x09d, 0x09e, 0x13b,
  319. 0x0a0, 0x0a1, 0x0a2, 0x143, 0x0a4, 0x0a5, 0x0a6, 0x14b,
  320. 0x0a8, 0x0a9, 0x0aa, 0x153, 0x0ac, 0x0ad, 0x0ae, 0x15b,
  321. 0x0b0, 0x0b1, 0x0b2, 0x163, 0x0b4, 0x0b5, 0x0b6, 0x16b,
  322. 0x0b8, 0x0b9, 0x0ba, 0x173, 0x0bc, 0x0bd, 0x13e, 0x17b,
  323. 0x0c0, 0x0c1, 0x0c2, 0x183, 0x0c4, 0x0c5, 0x0c6, 0x18b,
  324. 0x0c8, 0x0c9, 0x0ca, 0x193, 0x0cc, 0x0cd, 0x0ce, 0x19b,
  325. 0x0d0, 0x0d1, 0x0d2, 0x1a3, 0x0d4, 0x0d5, 0x0d6, 0x1ab,
  326. 0x0d8, 0x0d9, 0x0da, 0x1b3, 0x0dc, 0x0dd, 0x0de, 0x1bb,
  327. 0x0e0, 0x0e1, 0x0e2, 0x1c3, 0x0e4, 0x0e5, 0x0e6, 0x1cb,
  328. 0x0e8, 0x0e9, 0x0ea, 0x1d3, 0x0ec, 0x0ed, 0x0ee, 0x1db,
  329. 0x0f0, 0x0f1, 0x0f2, 0x1e3, 0x0f4, 0x0f5, 0x0f6, 0x1eb,
  330. 0x0f8, 0x0f9, 0x0fa, 0x1f3, 0x17c, 0x17d, 0x1be, 0x2fb },
  331. // Input Len = 4
  332. {0x000, 0x001, 0x002, 0x005, 0x004, 0x009, 0x006, 0x00d,
  333. 0x008, 0x011, 0x00a, 0x015, 0x00c, 0x019, 0x00e, 0x01d,
  334. 0x010, 0x021, 0x012, 0x025, 0x014, 0x029, 0x016, 0x02d,
  335. 0x018, 0x031, 0x01a, 0x035, 0x01c, 0x039, 0x01e, 0x03d,
  336. 0x020, 0x041, 0x022, 0x045, 0x024, 0x049, 0x026, 0x04d,
  337. 0x028, 0x051, 0x02a, 0x055, 0x02c, 0x059, 0x02e, 0x05d,
  338. 0x030, 0x061, 0x032, 0x065, 0x034, 0x069, 0x036, 0x06d,
  339. 0x038, 0x071, 0x03a, 0x075, 0x03c, 0x079, 0x03e, 0x07d,
  340. 0x040, 0x081, 0x042, 0x085, 0x044, 0x089, 0x046, 0x08d,
  341. 0x048, 0x091, 0x04a, 0x095, 0x04c, 0x099, 0x04e, 0x09d,
  342. 0x050, 0x0a1, 0x052, 0x0a5, 0x054, 0x0a9, 0x056, 0x0ad,
  343. 0x058, 0x0b1, 0x05a, 0x0b5, 0x05c, 0x0b9, 0x05e, 0x0bd,
  344. 0x060, 0x0c1, 0x062, 0x0c5, 0x064, 0x0c9, 0x066, 0x0cd,
  345. 0x068, 0x0d1, 0x06a, 0x0d5, 0x06c, 0x0d9, 0x06e, 0x0dd,
  346. 0x070, 0x0e1, 0x072, 0x0e5, 0x074, 0x0e9, 0x076, 0x0ed,
  347. 0x078, 0x0f1, 0x07a, 0x0f5, 0x07c, 0x0f9, 0x0be, 0x17d,
  348. 0x080, 0x101, 0x082, 0x105, 0x084, 0x109, 0x086, 0x10d,
  349. 0x088, 0x111, 0x08a, 0x115, 0x08c, 0x119, 0x08e, 0x11d,
  350. 0x090, 0x121, 0x092, 0x125, 0x094, 0x129, 0x096, 0x12d,
  351. 0x098, 0x131, 0x09a, 0x135, 0x09c, 0x139, 0x09e, 0x13d,
  352. 0x0a0, 0x141, 0x0a2, 0x145, 0x0a4, 0x149, 0x0a6, 0x14d,
  353. 0x0a8, 0x151, 0x0aa, 0x155, 0x0ac, 0x159, 0x0ae, 0x15d,
  354. 0x0b0, 0x161, 0x0b2, 0x165, 0x0b4, 0x169, 0x0b6, 0x16d,
  355. 0x0b8, 0x171, 0x0ba, 0x175, 0x0bc, 0x179, 0x13e, 0x27d,
  356. 0x0c0, 0x181, 0x0c2, 0x185, 0x0c4, 0x189, 0x0c6, 0x18d,
  357. 0x0c8, 0x191, 0x0ca, 0x195, 0x0cc, 0x199, 0x0ce, 0x19d,
  358. 0x0d0, 0x1a1, 0x0d2, 0x1a5, 0x0d4, 0x1a9, 0x0d6, 0x1ad,
  359. 0x0d8, 0x1b1, 0x0da, 0x1b5, 0x0dc, 0x1b9, 0x0de, 0x1bd,
  360. 0x0e0, 0x1c1, 0x0e2, 0x1c5, 0x0e4, 0x1c9, 0x0e6, 0x1cd,
  361. 0x0e8, 0x1d1, 0x0ea, 0x1d5, 0x0ec, 0x1d9, 0x0ee, 0x1dd,
  362. 0x0f0, 0x1e1, 0x0f2, 0x1e5, 0x0f4, 0x1e9, 0x0f6, 0x1ed,
  363. 0x0f8, 0x1f1, 0x0fa, 0x1f5, 0x17c, 0x2f9, 0x1be, 0x37d }
  364. }; // Out