tparray5.pp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. {$mode macpas}
  2. {$r-}
  3. procedure error(l: longint);
  4. begin
  5. writeln('error near ',l);
  6. halt(1);
  7. end;
  8. procedure test8bit;
  9. type
  10. ta = 0..1;
  11. tb = packed array[0..999] of ta;
  12. tc = array[0..124] of byte;
  13. const
  14. {$ifdef ENDIAN_BIG}
  15. results: array[0..9] of ta = (1,0,1,0,1,0,1,0,1,0);
  16. {$else}
  17. results: array[0..9] of ta = (0,1,0,1,0,1,0,1,0,1);
  18. {$endif}
  19. var
  20. a: ta;
  21. b: tb;
  22. i: longint;
  23. begin
  24. fillchar(b,sizeof(b),$AA);
  25. if (b[0] <> results[0]) then
  26. error(1);
  27. if (b[1] <> results[1]) then
  28. error(2);
  29. if (b[2] <> results[2]) then
  30. error(3);
  31. if (b[3] <> results[3]) then
  32. error(4);
  33. if (b[4] <> results[4]) then
  34. error(5);
  35. // if (b[600] <> 1) then
  36. // error(6);
  37. for i := low(results) to high(results) do
  38. if b[i] <> results[i] then
  39. error(7);
  40. // i := 500;
  41. // if (b[i] <> 1) then
  42. // error(8);
  43. end;
  44. procedure test8to16bit;
  45. type
  46. ta = 0..7;
  47. tb = packed array[0..1000] of ta;
  48. const
  49. {$ifdef ENDIAN_BIG}
  50. { 010 110 100 101 101 001 011 010 010 11010010110100101101001011010 }
  51. results: array[0..5] of ta = (2,6,4,5,5,1);
  52. {$else}
  53. { (memory layout is different but equivalent with starting at end }
  54. { 01011010010110100101101001011 010 010 110 100 101 101 001 011 010 }
  55. results: array[0..5] of ta = (2,3,1,5,5,4);
  56. {$endif}
  57. var
  58. a: ta;
  59. b: tb;
  60. i: longint;
  61. begin
  62. fillchar(b,sizeof(b),$5A);
  63. if (b[0] <> results[0]) then
  64. error(11);
  65. if (b[1] <> results[1]) then
  66. error(12);
  67. if (b[2] <> results[2]) then
  68. error(13);
  69. if (b[3] <> results[3]) then
  70. error(14);
  71. if (b[4] <> results[4]) then
  72. error(15);
  73. if (b[5] <> results[5]) then
  74. error(155);
  75. // if (b[600] <> 2) then
  76. // error(16);
  77. for i := low(results) to high(results) do
  78. if b[i] <> results[i] then
  79. error(17);
  80. // i := 500;
  81. // if (b[i] <> 5) then
  82. // error(18);
  83. end;
  84. procedure test16bit;
  85. type
  86. ta = 0..511;
  87. tb = packed array[0..799] of ta;
  88. tc = array[0..899] of byte;
  89. const
  90. {$ifdef ENDIAN_BIG}
  91. { 010110100 111011001 011010011 101100101 101001110 110010110 100111011 001011010 0111011001011010011101100101101001110110 }
  92. results: array[0..4] of ta = ($5A*2,$76 * 4 + 1,$69 * 2 + 1,$B2 * 2 + 1,$A7 * 2);
  93. {$else}
  94. { algorithm: cut bit string in 16 bit chunks, byteswap, take 9 bits from right to left per chunck, continuing at the right of the next chunck if the previous one is used up }
  95. { 001011010 100111011 110010110 101001110 101100101 011 0101101001110110010110100111011001011010011101100101101001110110 }
  96. results: array[0..4] of ta = ($2D*2,$9D*2+1,$CB*2,$A7*2,$B2*2+1);
  97. {$endif}
  98. var
  99. a: ta;
  100. b: tb;
  101. i: longint;
  102. begin
  103. for i := 0 to high(tc) div 2 do
  104. begin
  105. tc(b)[i*2] := $5A;
  106. tc(b)[i*2+1] := $76;
  107. end;
  108. if (b[0] <> results[0]) then
  109. error(21);
  110. if (b[1] <> results[1]) then
  111. error(22);
  112. if (b[2] <> results[2]) then
  113. error(23);
  114. if (b[3] <> results[3]) then
  115. error(24);
  116. if (b[4] <> results[4]) then
  117. error(25);
  118. // if (b[600] <> $76 * 2) then
  119. // error(26);
  120. for i := low(results) to high(results) do
  121. if b[i] <> results[i] then
  122. error(27);
  123. // i := 500;
  124. // if (b[i] <> $A7 * 2) then
  125. // error(28);
  126. end;
  127. procedure test16to24bit;
  128. type
  129. ta = 0..2047;
  130. tb = packed array[0..799] of ta;
  131. tc = array[0..1099] of byte;
  132. const
  133. {$ifdef ENDIAN_BIG}
  134. results: array[0..4] of ta = ($5A * 8 + 3,$B2 * 8 + 6,$9D * 8 + 4,$B4 * 8 + 7,$65 * 8 + 5);
  135. {$else}
  136. { %11001011010 01101001110 00111011001 01100101101 10110100111 011101100 0111011001011010 0111011001011010 0111011001011010 }
  137. results: array[0..4] of ta = ($0000065A,$0000034E,$000001D9,$0000032D,$000005A7);
  138. {$endif}
  139. var
  140. a: ta;
  141. b: tb;
  142. i: longint;
  143. begin
  144. for i := 0 to high(tc) div 2 do
  145. begin
  146. tc(b)[i*2] := $5A;
  147. tc(b)[i*2+1] := $76;
  148. end;
  149. if (b[0] <> results[0]) then
  150. error(31);
  151. if (b[1] <> results[1]) then
  152. error(32);
  153. if (b[2] <> results[2]) then
  154. error(33);
  155. if (b[3] <> results[3]) then
  156. error(34);
  157. if (b[4] <> results[4]) then
  158. error(35);
  159. // if (b[600] <> $76 * 8 + 2) then
  160. // error(36);
  161. for i := low(results) to high(results) do
  162. if b[i] <> results[i] then
  163. error(37);
  164. // i := 500;
  165. // if (b[i] <> $65 * 8 + 5) then
  166. // error(38);
  167. end;
  168. procedure test32bit;
  169. type
  170. ta = 0..(1 shl 19) - 1;
  171. tb = packed array[0..799] of ta;
  172. tc = array[0..1899] of byte;
  173. const
  174. {$ifdef ENDIAN_BIG}
  175. results: array[0..4] of ta = ($5A76*8+2, $D3B2*8+6,$9D96*8+4,$ECB4*8+7,$65A7*8+3);
  176. {$else}
  177. { 0100111011001011010 0110100111011001011 0010110100111011001 0110010110100111011 1110110010110100111 0 01110110010110100111011001011010 01110110010110100111011001011010 01110110010110100111011001011010 01110110010110100111011001011010 01110110010110100111011001011010 01110110010110100111011001011010}
  178. results: array[0..4] of ta = ($0002765A,$00034ECB,$000169D9,$00032D3B,$000765A7);
  179. {$endif}
  180. var
  181. a: ta;
  182. b: tb;
  183. i: longint;
  184. begin
  185. for i := 0 to high(tc) div 2 do
  186. begin
  187. tc(b)[i*2] := $5A;
  188. tc(b)[i*2+1] := $76;
  189. end;
  190. if (b[0] <> results[0]) then
  191. error(41);
  192. if (b[1] <> results[1]) then
  193. error(42);
  194. if (b[2] <> results[2]) then
  195. error(43);
  196. if (b[3] <> results[3]) then
  197. error(44);
  198. if (b[4] <> results[4]) then
  199. error(45);
  200. // if (b[600] <> $765A*8+3) then
  201. // error(46);
  202. for i := low(results) to high(results) do
  203. if b[i] <> results[i] then
  204. error(47);
  205. // i := 500;
  206. // if (b[i] <> $65a7*8+3) then
  207. // error(48);
  208. end;
  209. {
  210. write(hexstr(%1110110010110100111011001011010 ,8),',$');
  211. write(hexstr(%1101100101101001110110010110100 ,8),',$');
  212. write(hexstr(%1011001011010011101100101101001 ,8),',$');
  213. write(hexstr(%0110010110100111011001011010011 ,8),',$');
  214. writeln(hexstr(%1100101101001110110010110100111 ,8));
  215. }
  216. procedure test32to40bit;
  217. type
  218. ta = 0..$7fffffff;
  219. tb = packed array[0..799] of ta;
  220. tc = array[0..3099] of byte;
  221. const
  222. {$ifdef ENDIAN_BIG}
  223. results: array[0..4] of ta = ($5A765A7*8+3,$2D3B2D3*8+5,$969D969*8+6,$CB4ECB4*8+7,$65A765A*8+3);
  224. {$else}
  225. {
  226. 1110110010110100111011001011010 1101100101101001110110010110100 1011001011010011101100101101001 0110010110100111011001011010011 1100101101001110110010110100111 1001011010011101100101101001110 011101
  227. }
  228. results: array[0..4] of ta = ($765A765A,$6CB4ECB4,$5969D969,$32D3B2D3,$65A765A7);
  229. {$endif}
  230. var
  231. a: ta;
  232. b: tb;
  233. i: longint;
  234. begin
  235. for i := 0 to high(tc) div 2 do
  236. begin
  237. tc(b)[i*2] := $5A;
  238. tc(b)[i*2+1] := $76;
  239. end;
  240. if (b[0] <> results[0]) then
  241. error(51);
  242. if (b[1] <> results[1]) then
  243. error(52);
  244. if (b[2] <> results[2]) then
  245. error(53);
  246. if (b[3] <> results[3]) then
  247. error(54);
  248. if (b[4] <> results[4]) then
  249. error(55);
  250. for i := low(results) to high(results) do
  251. if b[i] <> results[i] then
  252. error(57);
  253. // i := 500;
  254. // if (b[i] <> $65A765A*8+3) then
  255. // error(58);
  256. end;
  257. begin
  258. test8bit;
  259. test8to16bit;
  260. test16bit;
  261. test16to24bit;
  262. test32bit;
  263. test32to40bit;
  264. end.