ppu.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Routines to read/write ppu files
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ppu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,constexp,entfile;
  22. { Also write the ppu if only crc if done, this can be used with ppudump to
  23. see the differences between the intf and implementation }
  24. { define DEBUG_GENERATE_INTERFACE_PPU}
  25. {$ifdef Test_Double_checksum}
  26. const
  27. CRC_array_Size = 200000;
  28. type
  29. tcrc_array = array[0..crc_array_size] of dword;
  30. pcrc_array = ^tcrc_array;
  31. {$endif Test_Double_checksum}
  32. const
  33. { only update this version if something change in the tppuheader:
  34. * the unit flags listed below
  35. * the format of the header itself
  36. This number cannot become bigger than 255 (it's stored in a byte) }
  37. CurrentPPUVersion = 208;
  38. { for any other changes to the ppu format, increase this version number
  39. (it's a cardinal) }
  40. CurrentPPULongVersion = 28;
  41. { unit flags }
  42. uf_big_endian = $000004;
  43. uf_in_library = $000020; { is the file in another file than <ppufile>.* ? }
  44. uf_smart_linked = $000040; { the ppu can be smartlinked }
  45. uf_static_linked = $000080; { the ppu can be linked static }
  46. uf_shared_linked = $000100; { the ppu can be linked shared }
  47. uf_lto_linked = $000200; { the ppu can be used with LTO }
  48. uf_no_link = $000400; { unit has no .o generated, but can still have external linking! }
  49. uf_little_endian = $001000;
  50. uf_fpu_emulation = $008000; { this unit was compiled with fpu emulation on }
  51. type
  52. { bestreal is defined based on the target architecture }
  53. ppureal=bestreal;
  54. { set type aliases. We cast all sets to a corresponding array type so
  55. that if the set changes size, compilation will fail and we know that
  56. we have have to increase the ppu version }
  57. tppuset1 = array[0..0] of byte;
  58. tppuset2 = array[0..1] of byte;
  59. { tppuset3 = array[0..2] of byte; (sets of 3 bytes are rounded up to 4 bytes) }
  60. tppuset4 = array[0..3] of byte;
  61. tppuset5 = array[0..4] of byte;
  62. tppuset6 = array[0..5] of byte;
  63. tppuset7 = array[0..6] of byte;
  64. tppuset8 = array[0..7] of byte;
  65. tppuset9 = array[0..8] of byte;
  66. tppuset10 = array[0..9] of byte;
  67. tppuset11 = array[0..10] of byte;
  68. tppuset12 = array[0..11] of byte;
  69. tppuset13 = array[0..12] of byte;
  70. tppuset14 = array[0..13] of byte;
  71. tppuset15 = array[0..14] of byte;
  72. tppuset16 = array[0..15] of byte;
  73. tppuset17 = array[0..16] of byte;
  74. tppuset18 = array[0..17] of byte;
  75. tppuset19 = array[0..18] of byte;
  76. tppuset20 = array[0..19] of byte;
  77. tppuset21 = array[0..20] of byte;
  78. tppuset22 = array[0..21] of byte;
  79. tppuset23 = array[0..22] of byte;
  80. tppuset24 = array[0..23] of byte;
  81. tppuset25 = array[0..24] of byte;
  82. tppuset26 = array[0..25] of byte;
  83. tppuset27 = array[0..26] of byte;
  84. tppuset28 = array[0..27] of byte;
  85. tppuset29 = array[0..28] of byte;
  86. tppuset30 = array[0..29] of byte;
  87. tppuset31 = array[0..30] of byte;
  88. tppuset32 = array[0..31] of byte;
  89. tppuerror=(ppuentrytoobig,ppuentryerror);
  90. tppuheader=record
  91. common : tentryheader;
  92. checksum : cardinal; { checksum for this ppufile }
  93. interface_checksum : cardinal;
  94. deflistsize,
  95. symlistsize : longint;
  96. indirect_checksum: cardinal;
  97. end;
  98. tppuentry=tentry;
  99. tunitasmlisttype=(ualt_public,ualt_extern);
  100. { tppufile }
  101. tppufile=class(tentryfile)
  102. {$ifdef Test_Double_checksum}
  103. public
  104. interface_read_crc_index,
  105. interface_write_crc_index,
  106. indirect_read_crc_index,
  107. indirect_write_crc_index,
  108. implementation_read_crc_index,
  109. implementation_write_crc_index : cardinal;
  110. interface_crc_array,
  111. indirect_crc_array,
  112. implementation_crc_array : pcrc_array;
  113. CRCFile : text;
  114. private
  115. {$endif def Test_Double_checksum}
  116. protected
  117. procedure newheader;override;
  118. function readheader: longint;override;
  119. function outputallowed: boolean;override;
  120. //procedure doputdata(const b;len:integer);override;
  121. function getheadersize:longint;override;
  122. function getheaderaddr:pentryheader;override;
  123. procedure resetfile;override;
  124. {$ifdef DEBUG_PPU}
  125. procedure ppu_log(st :string);override;
  126. {$endif}
  127. {$ifdef DEBUG_GENERATE_INTERFACE_PPU}
  128. public
  129. writing_interface_ppu : boolean;
  130. {$endif DEBUG_GENERATE_INTERFACE_PPU}
  131. public
  132. header : tppuheader;
  133. { crc for the entire unit }
  134. crc,
  135. { crc for the interface definitions in this unit }
  136. interface_crc,
  137. { crc of all object/class definitions in the interface of this unit, xor'ed
  138. by the crc's of all object/class definitions in the interfaces of units
  139. used by this unit. Reason: see mantis #13840 }
  140. indirect_crc : cardinal;
  141. do_crc,
  142. do_interface_crc,
  143. do_indirect_crc : boolean;
  144. crc_only : boolean; { used to calculate interface_crc before implementation }
  145. constructor Create(const fn:string);
  146. destructor destroy;override;
  147. function CheckPPUId:boolean;
  148. {read}
  149. { nothing special currently }
  150. {write}
  151. function createfile:boolean;override;
  152. procedure writeheader;override;
  153. procedure putdata(const b;len:integer);override;
  154. procedure putdata(b : tbytedynarray);
  155. procedure putdata(b : tansichardynarray);
  156. end;
  157. implementation
  158. uses
  159. comphook,
  160. globals,
  161. fpchash;
  162. {$ifdef Test_Double_checksum}
  163. {$ifdef TEST_CRC_ERROR}
  164. const
  165. CRC_Interface_Change_Message_Level=V_Error;
  166. CRC_Implementation_Change_Message_Level=V_Error;
  167. CRC_Indirect_Change_Message_Level=V_Error;
  168. {$else : not TEST_CRC_ERROR}
  169. const
  170. CRC_Interface_Change_Message_Level=V_Warning;
  171. CRC_Implementation_Change_Message_Level=V_Note;
  172. CRC_Indirect_Change_Message_Level=V_Note;
  173. {$endif : not TEST_CRC_ERROR}
  174. {$endif Test_Double_checksum}
  175. function swapendian_ppureal(d:ppureal):ppureal;
  176. type ppureal_bytes=array[0..sizeof(d)-1] of byte;
  177. var i:0..sizeof(d)-1;
  178. begin
  179. for i:=low(ppureal_bytes) to high(ppureal_bytes) do
  180. ppureal_bytes(swapendian_ppureal)[i]:=ppureal_bytes(d)[high(ppureal_bytes)-i];
  181. end;
  182. {*****************************************************************************
  183. TPPUFile
  184. *****************************************************************************}
  185. constructor tppufile.Create(const fn:string);
  186. begin
  187. inherited Create(fn);
  188. crc_only:=false;
  189. {$ifdef DEBUG_GENERATE_INTERFACE_PPU}
  190. writing_interface_ppu:=false;
  191. {$endif}
  192. {$ifdef Test_Double_checksum}
  193. if not assigned(interface_crc_array) then
  194. begin
  195. new(interface_crc_array);
  196. fillchar(interface_crc_array^,sizeof(tcrc_array),#$ff);
  197. end;
  198. if not assigned(indirect_crc_array) then
  199. begin
  200. new(indirect_crc_array);
  201. fillchar(indirect_crc_array^,sizeof(tcrc_array),#$ff);
  202. end;
  203. if not assigned(implementation_crc_array) then
  204. begin
  205. new(implementation_crc_array);
  206. fillchar(implementation_crc_array^,sizeof(tcrc_array),#$ff);
  207. end;
  208. {$endif Test_Double_checksum}
  209. end;
  210. destructor tppufile.destroy;
  211. begin
  212. {$ifdef Test_Double_checksum}
  213. if assigned(interface_crc_array) then
  214. dispose(interface_crc_array);
  215. interface_crc_array:=nil;
  216. if assigned(indirect_crc_array) then
  217. dispose(indirect_crc_array);
  218. indirect_crc_array:=nil;
  219. if assigned(implementation_crc_array) then
  220. dispose(implementation_crc_array);
  221. implementation_crc_array:=nil;
  222. {$endif Test_Double_checksum}
  223. inherited destroy;
  224. end;
  225. function tppufile.CheckPPUId:boolean;
  226. begin
  227. CheckPPUId:=((Header.common.Id[1]='P') and
  228. (Header.common.Id[2]='P') and
  229. (Header.common.Id[3]='U'));
  230. end;
  231. procedure tppufile.newheader;
  232. var
  233. s : string;
  234. begin
  235. fillchar(header,sizeof(tppuheader),0);
  236. str(currentppuversion,s);
  237. while length(s)<3 do
  238. s:='0'+s;
  239. with header.common do
  240. begin
  241. Id[1]:='P';
  242. Id[2]:='P';
  243. Id[3]:='U';
  244. Ver[1]:=s[1];
  245. Ver[2]:=s[2];
  246. Ver[3]:=s[3];
  247. end;
  248. end;
  249. function tppufile.readheader: longint;
  250. var
  251. is_valid : boolean;
  252. begin
  253. is_valid:=true;
  254. result:=fsize;
  255. if result<sizeof(tppuheader) then
  256. is_valid:=false;
  257. result:=f.Read(header,sizeof(tppuheader));
  258. if (result<>sizeof(tppuheader)) then
  259. is_valid:=false;
  260. if not is_valid then
  261. begin
  262. fillchar(header,sizeof(tppuheader),#0);
  263. do_comment(V_Error,' Invalid header size '+tostr(result)+' (expecting '+tostr(sizeof(tppuheader))+')');
  264. exit(-1);
  265. end;
  266. { The header is always stored in little endian order }
  267. { therefore swap if on a big endian machine }
  268. {$IFDEF ENDIAN_BIG}
  269. header.common.compiler := swapendian(header.common.compiler);
  270. header.common.cpu := swapendian(header.common.cpu);
  271. header.common.target := swapendian(header.common.target);
  272. header.common.flags := swapendian(header.common.flags);
  273. header.common.size := swapendian(header.common.size);
  274. header.checksum := swapendian(header.checksum);
  275. header.interface_checksum := swapendian(header.interface_checksum);
  276. header.indirect_checksum := swapendian(header.indirect_checksum);
  277. header.deflistsize:=swapendian(header.deflistsize);
  278. header.symlistsize:=swapendian(header.symlistsize);
  279. { the PPU DATA is stored in native order }
  280. change_endian := (header.common.flags and uf_little_endian) = uf_little_endian;
  281. {$ELSE not ENDIAN_BIG}
  282. change_endian := (header.common.flags and uf_big_endian) = uf_big_endian;
  283. {$ENDIF}
  284. end;
  285. function tppufile.outputallowed: boolean;
  286. begin
  287. result:=not crc_only;
  288. end;
  289. {$ifdef DEBUG_PPU}
  290. procedure tppufile.ppu_log(st :string);
  291. begin
  292. inherited ppu_log(st);
  293. if flog_open then
  294. begin
  295. if do_crc and (ppu_log_idx < bufstart+bufidx) then
  296. begin
  297. write(flog,'New crc : ',hexstr(dword(crc),8));
  298. {$ifdef Test_Double_checksum}
  299. if implementation_read_crc_index>0 then
  300. write(flog,' read_index=',implementation_read_crc_index)
  301. else if implementation_write_crc_index>0 then
  302. write(flog,' write_index=',implementation_write_crc_index);
  303. {$endif def Test_Double_checksum}
  304. writeln(flog);
  305. write(flog,'New interface crc : ',hexstr(dword(interface_crc),8));
  306. {$ifdef Test_Double_checksum}
  307. if interface_read_crc_index>0 then
  308. write(flog,' read_index=',interface_read_crc_index)
  309. else if interface_write_crc_index>0 then
  310. write(flog,' write_index=',interface_write_crc_index);
  311. {$endif def Test_Double_checksum}
  312. writeln(flog);
  313. write(flog,'New indirect crc : ',hexstr(dword(indirect_crc),8));
  314. {$ifdef Test_Double_checksum}
  315. if indirect_read_crc_index>0 then
  316. write(flog,' read_index=',indirect_read_crc_index)
  317. else if indirect_write_crc_index>0 then
  318. write(flog,' write_index=',indirect_write_crc_index);
  319. {$endif def Test_Double_checksum}
  320. writeln(flog);
  321. end;
  322. end;
  323. {$ifdef IN_PPUDUMP}
  324. if update_crc then
  325. begin
  326. writeln('New crc : ',hexstr(dword(crc),8));
  327. writeln('New interface crc : ',hexstr(dword(interface_crc),8));
  328. writeln('New indirect crc : ',hexstr(dword(indirect_crc),8));
  329. end;
  330. {$endif}
  331. end;
  332. {$endif}
  333. {*****************************************************************************
  334. TPPUFile Reading
  335. *****************************************************************************}
  336. { nothing special currently }
  337. {*****************************************************************************
  338. TPPUFile Writing
  339. *****************************************************************************}
  340. function tppufile.createfile:boolean;
  341. begin
  342. {$ifdef DEBUG_GENERATE_INTERFACE_PPU}
  343. if crc_only then
  344. begin
  345. fname:=fname+'.intf';
  346. crc_only:=false;
  347. writing_interface_ppu:=true;
  348. end;
  349. {$endif}
  350. result:=inherited createfile;
  351. end;
  352. procedure tppufile.writeheader;
  353. var
  354. opos : integer;
  355. begin
  356. if crc_only then
  357. exit;
  358. { flush buffer }
  359. writebuf;
  360. { update size (w/o header!) in the header }
  361. header.common.size:=bufstart-sizeof(tppuheader);
  362. { set the endian flag }
  363. {$ifndef FPC_BIG_ENDIAN}
  364. header.common.flags := header.common.flags or uf_little_endian;
  365. {$else not FPC_BIG_ENDIAN}
  366. header.common.flags := header.common.flags or uf_big_endian;
  367. { Now swap the header.common in the correct endian (always little endian) }
  368. header.common.compiler := swapendian(header.common.compiler);
  369. header.common.cpu := swapendian(header.common.cpu);
  370. header.common.target := swapendian(header.common.target);
  371. header.common.flags := swapendian(header.common.flags);
  372. header.common.size := swapendian(header.common.size);
  373. header.checksum := swapendian(header.checksum);
  374. header.interface_checksum := swapendian(header.interface_checksum);
  375. header.indirect_checksum := swapendian(header.indirect_checksum);
  376. header.deflistsize:=swapendian(header.deflistsize);
  377. header.symlistsize:=swapendian(header.symlistsize);
  378. {$endif not FPC_BIG_ENDIAN}
  379. { write header and restore filepos after it }
  380. opos:=f.Position;
  381. f.Position:=0;
  382. f.Write(header,sizeof(tppuheader));
  383. f.Position:=opos;
  384. end;
  385. procedure tppufile.putdata(const b;len:integer);
  386. {$ifdef Test_Double_checksum}
  387. var
  388. pb : pbyte;
  389. ind : integer;
  390. {$endif Test_Double_checksum}
  391. begin
  392. if do_crc then
  393. begin
  394. crc:=UpdateCrc32(crc,b,len);
  395. {$ifdef Test_Double_checksum}
  396. if crc_only
  397. {$ifdef DEBUG_GENERATE_INTERFACE_PPU}
  398. or writing_interface_ppu
  399. {$endif DEBUG_GENERATE_INTERFACE_PPU}
  400. then
  401. begin
  402. implementation_crc_array^[implementation_write_crc_index]:=crc;
  403. {$ifdef Test_Double_checksum_write}
  404. Write(CRCFile,'imp_crc ',implementation_write_crc_index:5,' $',hexstr(crc,8),' ',len);
  405. pb:=@b;
  406. for ind:=0 to len-1 do
  407. Write(CRCFile,' ',hexstr(pb[ind],2));
  408. Writeln(CRCFile);
  409. {$endif Test_Double_checksum_write}
  410. if implementation_write_crc_index<crc_array_size then
  411. inc(implementation_write_crc_index);
  412. end
  413. else
  414. begin
  415. if (implementation_read_crc_index<crc_array_size) and
  416. (implementation_read_crc_index<implementation_write_crc_index) and
  417. (implementation_crc_array^[implementation_read_crc_index]<>crc) then
  418. begin
  419. do_comment(CRC_implementation_Change_Message_Level,'implementation CRC changed at index '+tostr(implementation_read_crc_index));
  420. {$IFDEF TEST_CRC_ERROR}
  421. if CRC_implementation_Change_Message_Level=V_Error then
  422. do_internalerror(2020113001);
  423. {$ENDIF}
  424. {$ifdef Test_Double_checksum_write}
  425. Write(CRCFile,'!!!imp_crc ',implementation_read_crc_index:5,' $',hexstr(crc,8),'<>$',hexstr(implementation_crc_array^[implementation_read_crc_index],8),' ',len);
  426. pb:=@b;
  427. for ind:=0 to len-1 do
  428. Write(CRCFile,' ',hexstr(pb[ind],2));
  429. Writeln(CRCFile);
  430. end
  431. else
  432. begin
  433. Write(CRCFile,'imp_crc ',implementation_read_crc_index:5,' $',hexstr(crc,8),' ',len);
  434. pb:=@b;
  435. for ind:=0 to len-1 do
  436. Write(CRCFile,' ',hexstr(pb[ind],2));
  437. Writeln(CRCFile);
  438. {$endif Test_Double_checksum_write}
  439. end;
  440. inc(implementation_read_crc_index);
  441. end;
  442. {$endif def Test_Double_checksum}
  443. if do_interface_crc then
  444. begin
  445. interface_crc:=UpdateCrc32(interface_crc,b,len);
  446. {$ifdef Test_Double_checksum}
  447. if crc_only
  448. {$ifdef DEBUG_GENERATE_INTERFACE_PPU}
  449. or writing_interface_ppu
  450. {$endif DEBUG_GENERATE_INTERFACE_PPU}
  451. then
  452. begin
  453. interface_crc_array^[interface_write_crc_index]:=interface_crc;
  454. {$ifdef Test_Double_checksum_write}
  455. Write(CRCFile,'int_crc ',interface_write_crc_index:5,' $',hexstr(interface_crc,8),' ',len);
  456. pb:=@b;
  457. for ind:=0 to len-1 do
  458. Write(CRCFile,' ',hexstr(pb[ind],2));
  459. Writeln(CRCFile);
  460. {$endif Test_Double_checksum_write}
  461. if interface_write_crc_index<crc_array_size then
  462. inc(interface_write_crc_index);
  463. end
  464. else
  465. begin
  466. if (interface_read_crc_index<crc_array_size) and
  467. (interface_read_crc_index<interface_write_crc_index) and
  468. (interface_crc_array^[interface_read_crc_index]<>interface_crc) then
  469. begin
  470. do_comment(CRC_Interface_Change_Message_Level,'interface CRC changed at index '+tostr(interface_read_crc_index));
  471. {$IFDEF TEST_CRC_ERROR}
  472. if CRC_interface_Change_Message_Level=V_Error then
  473. do_internalerror(2020113002);
  474. {$ENDIF}
  475. {$ifdef Test_Double_checksum_write}
  476. Write(CRCFile,'!!!int_crc ',interface_read_crc_index:5,' $',hexstr(interface_crc,8),'<>$',hexstr(interface_crc_array^[interface_read_crc_index],8),' ',len);
  477. pb:=@b;
  478. for ind:=0 to len-1 do
  479. Write(CRCFile,' ',hexstr(pb[ind],2));
  480. Writeln(CRCFile);
  481. end
  482. else
  483. begin
  484. Write(CRCFile,'int_crc ',interface_read_crc_index:5,' $',hexstr(interface_crc,8),' ',len);
  485. pb:=@b;
  486. for ind:=0 to len-1 do
  487. Write(CRCFile,' ',hexstr(pb[ind],2));
  488. Writeln(CRCFile);
  489. {$endif Test_Double_checksum_write}
  490. end;
  491. inc(interface_read_crc_index);
  492. end;
  493. {$endif def Test_Double_checksum}
  494. { indirect crc must only be calculated for the interface; changes
  495. to a class in the implementation cannot require another unit to
  496. be recompiled }
  497. if do_indirect_crc then
  498. begin
  499. indirect_crc:=UpdateCrc32(indirect_crc,b,len);
  500. {$ifdef Test_Double_checksum}
  501. if crc_only
  502. {$ifdef DEBUG_GENERATE_INTERFACE_PPU}
  503. or writing_interface_ppu
  504. {$endif DEBUG_GENERATE_INTERFACE_PPU}
  505. then
  506. begin
  507. indirect_crc_array^[indirect_write_crc_index]:=indirect_crc;
  508. {$ifdef Test_Double_checksum_write}
  509. Write(CRCFile,'ind_crc ',indirect_write_crc_index:5,' $',hexstr(indirect_crc,8),' ',len);
  510. pb:=@b;
  511. for ind:=0 to len-1 do
  512. Write(CRCFile,' ',hexstr(pb[ind],2));
  513. Writeln(CRCFile);
  514. {$endif Test_Double_checksum_write}
  515. if indirect_write_crc_index<crc_array_size then
  516. inc(indirect_write_crc_index);
  517. end
  518. else
  519. begin
  520. if (indirect_read_crc_index<crc_array_size) and
  521. (indirect_read_crc_index<indirect_write_crc_index) and
  522. (indirect_crc_array^[indirect_read_crc_index]<>indirect_crc) then
  523. begin
  524. do_comment(CRC_Indirect_Change_Message_Level,'Indirect CRC changed at index '+tostr(indirect_read_crc_index));
  525. {$IFDEF TEST_CRC_ERROR}
  526. if CRC_indirect_Change_Message_Level=V_Error then
  527. do_internalerror(2020113003);
  528. {$ENDIF}
  529. {$ifdef Test_Double_checksum_write}
  530. Write(CRCFile,'!!!ind_crc ',indirect_read_crc_index:5,' $',hexstr(indirect_crc,8),'<>$',hexstr(indirect_crc_array^[indirect_read_crc_index],8),' ',len);
  531. pb:=@b;
  532. for ind:=0 to len-1 do
  533. Write(CRCFile,' ',hexstr(pb[ind],2));
  534. Writeln(CRCFile);
  535. end
  536. else
  537. begin
  538. Write(CRCFile,'ind_crc ',indirect_read_crc_index:5,' $',hexstr(indirect_crc,8),' ',len);
  539. pb:=@b;
  540. for ind:=0 to len-1 do
  541. Write(CRCFile,' ',hexstr(pb[ind],2));
  542. Writeln(CRCFile);
  543. {$endif Test_Double_checksum_write}
  544. end;
  545. inc(indirect_read_crc_index);
  546. end;
  547. {$endif def Test_Double_checksum}
  548. end;
  549. end;
  550. end;
  551. inherited putdata(b,len);
  552. (*if not crc_only then
  553. writedata(b,len);
  554. inc(entryidx,len);*)
  555. end;
  556. procedure tppufile.putdata(b: tbytedynarray);
  557. begin
  558. putdata(b[0],length(b));
  559. end;
  560. procedure tppufile.putdata(b: tansichardynarray);
  561. begin
  562. putdata(b[0],length(b));
  563. end;
  564. function tppufile.getheadersize: longint;
  565. begin
  566. result:=sizeof(header);
  567. end;
  568. function tppufile.getheaderaddr: pentryheader;
  569. begin
  570. result:=@header;
  571. end;
  572. procedure tppufile.resetfile;
  573. begin
  574. {$ifdef Test_Double_checksum_write}
  575. if (crc<>0) or (interface_crc<>0) or (indirect_crc<>0) then
  576. Writeln(CRCFile,'!!! tppufile.reset called',
  577. ' implementation_crc=$',hexstr(crc,8),
  578. ' interface_crc=$',hexstr(interface_crc,8),
  579. ' indirect_crc=$',hexstr(indirect_crc,8),
  580. ' implementation_crc_size=',implementation_write_crc_index,
  581. ' interface_crc_size=',interface_write_crc_index,
  582. ' indirect_crc_size=',indirect_write_crc_index);
  583. {$endif Test_Double_checksum_write}
  584. crc:=0;
  585. interface_crc:=0;
  586. indirect_crc:=0;
  587. do_interface_crc:=true;
  588. do_indirect_crc:=false;
  589. do_crc:=true;
  590. end;
  591. end.