ppu.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Routines to read/write ppu files
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ppu;
  19. {$i defines.inc}
  20. interface
  21. { Also write the ppu if only crc if done, this can be used with ppudump to
  22. see the differences between the intf and implementation }
  23. { define INTFPPU}
  24. {$ifdef Test_Double_checksum}
  25. var
  26. CRCFile : text;
  27. const
  28. CRC_array_Size = 200000;
  29. type
  30. tcrc_array = array[0..crc_array_size] of longint;
  31. pcrc_array = ^tcrc_array;
  32. {$endif Test_Double_checksum}
  33. const
  34. CurrentPPUVersion=22;
  35. { buffer sizes }
  36. maxentrysize = 1024;
  37. ppubufsize = 16384;
  38. {ppu entries}
  39. mainentryid = 1;
  40. subentryid = 2;
  41. {special}
  42. iberror = 0;
  43. ibstartdefs = 248;
  44. ibenddefs = 249;
  45. ibstartsyms = 250;
  46. ibendsyms = 251;
  47. ibendinterface = 252;
  48. ibendimplementation = 253;
  49. ibendbrowser = 254;
  50. ibend = 255;
  51. {general}
  52. ibmodulename = 1;
  53. ibsourcefiles = 2;
  54. ibloadunit = 3;
  55. ibinitunit = 4;
  56. iblinkunitofiles = 5;
  57. iblinkunitstaticlibs = 6;
  58. iblinkunitsharedlibs = 7;
  59. iblinkotherofiles = 8;
  60. iblinkotherstaticlibs = 9;
  61. iblinkothersharedlibs = 10;
  62. ibdbxcount = 11;
  63. ibsymref = 12;
  64. ibdefref = 13;
  65. ibendsymtablebrowser = 14;
  66. ibbeginsymtablebrowser = 15;
  67. ibusedmacros = 16;
  68. {syms}
  69. ibtypesym = 20;
  70. ibprocsym = 21;
  71. ibvarsym = 22;
  72. ibconstsym = 23;
  73. ibenumsym = 24;
  74. ibtypedconstsym = 25;
  75. ibabsolutesym = 26;
  76. ibpropertysym = 27;
  77. ibvarsym_C = 28;
  78. ibunitsym = 29; { needed for browser }
  79. iblabelsym = 30;
  80. ibfuncretsym = 31;
  81. ibsyssym = 32;
  82. {definitions}
  83. iborddef = 40;
  84. ibpointerdef = 41;
  85. ibarraydef = 42;
  86. ibprocdef = 43;
  87. ibshortstringdef = 44;
  88. ibrecorddef = 45;
  89. ibfiledef = 46;
  90. ibformaldef = 47;
  91. ibobjectdef = 48;
  92. ibenumdef = 49;
  93. ibsetdef = 50;
  94. ibprocvardef = 51;
  95. ibfloatdef = 52;
  96. ibclassrefdef = 53;
  97. iblongstringdef = 54;
  98. ibansistringdef = 55;
  99. ibwidestringdef = 56;
  100. ibvariantdef = 57;
  101. { unit flags }
  102. uf_init = $1;
  103. uf_finalize = $2;
  104. uf_big_endian = $4;
  105. uf_has_dbx = $8;
  106. uf_has_browser = $10;
  107. uf_in_library = $20; { is the file in another file than <ppufile>.* ? }
  108. uf_smart_linked = $40; { the ppu can be smartlinked }
  109. uf_static_linked = $80; { the ppu can be linked static }
  110. uf_shared_linked = $100; { the ppu can be linked shared }
  111. uf_local_browser = $200;
  112. uf_no_link = $400; { unit has no .o generated, but can still have
  113. external linking! }
  114. uf_has_resources = $800; { unit has resource section }
  115. uf_little_endian = $1000;
  116. uf_release = $2000;{ unit was compiled with -Ur option }
  117. type
  118. ppureal=extended;
  119. tppuerror=(ppuentrytoobig,ppuentryerror);
  120. tppuheader=packed record { 40 bytes }
  121. id : array[1..3] of char; { = 'PPU' }
  122. ver : array[1..3] of char;
  123. compiler : word;
  124. cpu : word;
  125. target : word;
  126. flags : longint;
  127. size : longint; { size of the ppufile without header }
  128. checksum : cardinal; { checksum for this ppufile }
  129. interface_checksum : cardinal;
  130. future : array[0..2] of longint;
  131. end;
  132. tppuentry=packed record
  133. id : byte;
  134. nr : byte;
  135. size : longint;
  136. end;
  137. tppufile=class
  138. private
  139. f : file;
  140. mode : byte; {0 - Closed, 1 - Reading, 2 - Writing}
  141. fname : string;
  142. fsize : integer;
  143. {$ifdef Test_Double_checksum}
  144. crcindex,
  145. crc_index,
  146. crcindex2,
  147. crc_index2 : cardinal;
  148. crc_test,
  149. crc_test2 : pcrc_array;
  150. {$endif def Test_Double_checksum}
  151. change_endian : boolean;
  152. buf : pchar;
  153. bufstart,
  154. bufsize,
  155. bufidx : integer;
  156. entrybufstart,
  157. entrystart,
  158. entryidx : integer;
  159. entry : tppuentry;
  160. closed,
  161. tempclosed : boolean;
  162. closepos : integer;
  163. public
  164. entrytyp : byte;
  165. header : tppuheader;
  166. size : integer;
  167. crc,
  168. interface_crc : cardinal;
  169. error,
  170. do_crc,
  171. do_interface_crc : boolean;
  172. crc_only : boolean; { used to calculate interface_crc before implementation }
  173. constructor Create(const fn:string);
  174. destructor Destroy;override;
  175. procedure flush;
  176. procedure closefile;
  177. function CheckPPUId:boolean;
  178. function GetPPUVersion:integer;
  179. procedure NewHeader;
  180. procedure NewEntry;
  181. {read}
  182. function openfile:boolean;
  183. procedure reloadbuf;
  184. procedure readdata(var b;len:integer);
  185. procedure skipdata(len:integer);
  186. function readentry:byte;
  187. function EndOfEntry:boolean;
  188. procedure getdatabuf(var b;len:integer;var res:integer);
  189. procedure getdata(var b;len:integer);
  190. function getbyte:byte;
  191. function getword:word;
  192. function getlongint:longint;
  193. function getreal:ppureal;
  194. function getstring:string;
  195. procedure getnormalset(var b);
  196. procedure getsmallset(var b);
  197. function skipuntilentry(untilb:byte):boolean;
  198. {write}
  199. function createfile:boolean;
  200. procedure writeheader;
  201. procedure writebuf;
  202. procedure writedata(const b;len:integer);
  203. procedure writeentry(ibnr:byte);
  204. procedure putdata(const b;len:integer);
  205. procedure putbyte(b:byte);
  206. procedure putword(w:word);
  207. procedure putlongint(l:longint);
  208. procedure putreal(d:ppureal);
  209. procedure putstring(s:string);
  210. procedure putnormalset(const b);
  211. procedure putsmallset(const b);
  212. procedure tempclose;
  213. function tempopen:boolean;
  214. end;
  215. implementation
  216. uses
  217. {$ifdef Test_Double_checksum}
  218. comphook,
  219. {$endif def Test_Double_checksum}
  220. crc;
  221. {*****************************************************************************
  222. Endian Handling
  223. *****************************************************************************}
  224. Function SwapLong(var x : longint): longint;
  225. var
  226. y : word;
  227. z : word;
  228. Begin
  229. y := (x shr 16) and $FFFF;
  230. y := (y shl 8) or ((y shr 8) and $ff);
  231. z := x and $FFFF;
  232. z := (z shl 8) or ((z shr 8) and $ff);
  233. SwapLong := (longint(z) shl 16) or longint(y);
  234. End;
  235. Function SwapWord(var x : word): word;
  236. var
  237. z : byte;
  238. Begin
  239. z := (x shr 8) and $ff;
  240. x := x and $ff;
  241. x := (x shl 8);
  242. SwapWord := x or z;
  243. End;
  244. {*****************************************************************************
  245. TPPUFile
  246. *****************************************************************************}
  247. constructor tppufile.Create(const fn:string);
  248. begin
  249. fname:=fn;
  250. change_endian:=false;
  251. crc_only:=false;
  252. Mode:=0;
  253. NewHeader;
  254. Error:=false;
  255. closed:=true;
  256. tempclosed:=false;
  257. getmem(buf,ppubufsize);
  258. end;
  259. destructor tppufile.destroy;
  260. begin
  261. closefile;
  262. if assigned(buf) then
  263. freemem(buf,ppubufsize);
  264. end;
  265. procedure tppufile.flush;
  266. begin
  267. if Mode=2 then
  268. writebuf;
  269. end;
  270. procedure tppufile.closefile;
  271. begin
  272. {$ifdef Test_Double_checksum}
  273. if mode=2 then
  274. begin
  275. if assigned(crc_test) then
  276. dispose(crc_test);
  277. if assigned(crc_test2) then
  278. dispose(crc_test2);
  279. end;
  280. {$endif Test_Double_checksum}
  281. if Mode<>0 then
  282. begin
  283. Flush;
  284. {$I-}
  285. system.close(f);
  286. {$I+}
  287. if ioresult<>0 then;
  288. Mode:=0;
  289. closed:=true;
  290. end;
  291. end;
  292. function tppufile.CheckPPUId:boolean;
  293. begin
  294. CheckPPUId:=((Header.Id[1]='P') and (Header.Id[2]='P') and (Header.Id[3]='U'));
  295. end;
  296. function tppufile.GetPPUVersion:integer;
  297. var
  298. l : integer;
  299. code : integer;
  300. begin
  301. Val(header.ver[1]+header.ver[2]+header.ver[3],l,code);
  302. if code=0 then
  303. GetPPUVersion:=l
  304. else
  305. GetPPUVersion:=0;
  306. end;
  307. procedure tppufile.NewHeader;
  308. var
  309. s : string;
  310. begin
  311. fillchar(header,sizeof(tppuheader),0);
  312. str(currentppuversion,s);
  313. while length(s)<3 do
  314. s:='0'+s;
  315. with header do
  316. begin
  317. Id[1]:='P';
  318. Id[2]:='P';
  319. Id[3]:='U';
  320. Ver[1]:=s[1];
  321. Ver[2]:=s[2];
  322. Ver[3]:=s[3];
  323. end;
  324. end;
  325. {*****************************************************************************
  326. TPPUFile Reading
  327. *****************************************************************************}
  328. function tppufile.openfile:boolean;
  329. var
  330. ofmode : byte;
  331. i : integer;
  332. begin
  333. openfile:=false;
  334. assign(f,fname);
  335. ofmode:=filemode;
  336. filemode:=$0;
  337. {$I-}
  338. reset(f,1);
  339. {$I+}
  340. filemode:=ofmode;
  341. if ioresult<>0 then
  342. exit;
  343. closed:=false;
  344. {read ppuheader}
  345. fsize:=filesize(f);
  346. if fsize<sizeof(tppuheader) then
  347. exit;
  348. blockread(f,header,sizeof(tppuheader),i);
  349. { The header is always stored in little endian order }
  350. { therefore swap if on a big endian machine }
  351. {$IFDEF ENDIAN_BIG}
  352. header.compiler := SwapWord(header.compiler);
  353. header.cpu := SwapWord(header.cpu);
  354. header.target := SwapWord(header.target);
  355. header.flags := SwapLong(header.flags);
  356. header.size := SwapLong(header.size);
  357. header.checksum := SwapLong(header.checksum);
  358. header.interface_checksum := SwapLong(header.interface_checksum);
  359. {$ENDIF}
  360. { the PPU DATA is stored in native order }
  361. if (header.flags and uf_big_endian) = uf_big_endian then
  362. Begin
  363. {$IFDEF ENDIAN_LITTLE}
  364. change_endian := TRUE;
  365. {$ELSE}
  366. change_endian := FALSE;
  367. {$ENDIF}
  368. End
  369. else if (header.flags and uf_little_endian) = uf_little_endian then
  370. Begin
  371. {$IFDEF ENDIAN_BIG}
  372. change_endian := TRUE;
  373. {$ELSE}
  374. change_endian := FALSE;
  375. {$ENDIF}
  376. End;
  377. {reset buffer}
  378. bufstart:=i;
  379. bufsize:=0;
  380. bufidx:=0;
  381. Mode:=1;
  382. FillChar(entry,sizeof(tppuentry),0);
  383. entryidx:=0;
  384. entrystart:=0;
  385. entrybufstart:=0;
  386. Error:=false;
  387. openfile:=true;
  388. end;
  389. procedure tppufile.reloadbuf;
  390. begin
  391. inc(bufstart,bufsize);
  392. blockread(f,buf^,ppubufsize,bufsize);
  393. bufidx:=0;
  394. end;
  395. procedure tppufile.readdata(var b;len:integer);
  396. var
  397. p : pchar;
  398. left,
  399. idx : integer;
  400. begin
  401. p:=pchar(@b);
  402. idx:=0;
  403. while len>0 do
  404. begin
  405. left:=bufsize-bufidx;
  406. if len>left then
  407. begin
  408. move(buf[bufidx],p[idx],left);
  409. dec(len,left);
  410. inc(idx,left);
  411. reloadbuf;
  412. if bufsize=0 then
  413. exit;
  414. end
  415. else
  416. begin
  417. move(buf[bufidx],p[idx],len);
  418. inc(bufidx,len);
  419. exit;
  420. end;
  421. end;
  422. end;
  423. procedure tppufile.skipdata(len:integer);
  424. var
  425. left : integer;
  426. begin
  427. while len>0 do
  428. begin
  429. left:=bufsize-bufidx;
  430. if len>left then
  431. begin
  432. dec(len,left);
  433. reloadbuf;
  434. if bufsize=0 then
  435. exit;
  436. end
  437. else
  438. begin
  439. inc(bufidx,len);
  440. exit;
  441. end;
  442. end;
  443. end;
  444. function tppufile.readentry:byte;
  445. begin
  446. if entryidx<entry.size then
  447. skipdata(entry.size-entryidx);
  448. readdata(entry,sizeof(tppuentry));
  449. entrystart:=bufstart+bufidx;
  450. entryidx:=0;
  451. if not(entry.id in [mainentryid,subentryid]) then
  452. begin
  453. readentry:=iberror;
  454. error:=true;
  455. exit;
  456. end;
  457. readentry:=entry.nr;
  458. end;
  459. function tppufile.endofentry:boolean;
  460. begin
  461. endofentry:=(entryidx>=entry.size);
  462. end;
  463. procedure tppufile.getdatabuf(var b;len:integer;var res:integer);
  464. begin
  465. if entryidx+len>entry.size then
  466. res:=entry.size-entryidx
  467. else
  468. res:=len;
  469. readdata(b,res);
  470. inc(entryidx,res);
  471. end;
  472. procedure tppufile.getdata(var b;len:integer);
  473. begin
  474. if entryidx+len>entry.size then
  475. begin
  476. error:=true;
  477. exit;
  478. end;
  479. readdata(b,len);
  480. inc(entryidx,len);
  481. end;
  482. function tppufile.getbyte:byte;
  483. var
  484. b : byte;
  485. begin
  486. if entryidx+1>entry.size then
  487. begin
  488. error:=true;
  489. getbyte:=0;
  490. exit;
  491. end;
  492. readdata(b,1);
  493. getbyte:=b;
  494. inc(entryidx);
  495. end;
  496. function tppufile.getword:word;
  497. type
  498. pword = ^word;
  499. var
  500. w : word;
  501. begin
  502. if entryidx+2>entry.size then
  503. begin
  504. error:=true;
  505. getword:=0;
  506. exit;
  507. end;
  508. readdata(w,2);
  509. if change_endian then
  510. getword:=swapword(w)
  511. else
  512. getword:=w;
  513. inc(entryidx,2);
  514. end;
  515. function tppufile.getlongint:longint;
  516. type
  517. plongint = ^longint;
  518. var
  519. l : longint;
  520. begin
  521. if entryidx+4>entry.size then
  522. begin
  523. error:=true;
  524. getlongint:=0;
  525. exit;
  526. end;
  527. readdata(l,4);
  528. if change_endian then
  529. getlongint:=swaplong(l)
  530. else
  531. getlongint:=l;
  532. inc(entryidx,4);
  533. end;
  534. function tppufile.getreal:ppureal;
  535. type
  536. pppureal = ^ppureal;
  537. var
  538. d : ppureal;
  539. begin
  540. if entryidx+sizeof(ppureal)>entry.size then
  541. begin
  542. error:=true;
  543. getreal:=0;
  544. exit;
  545. end;
  546. readdata(d,sizeof(ppureal));
  547. getreal:=d;
  548. inc(entryidx,sizeof(ppureal));
  549. end;
  550. function tppufile.getstring:string;
  551. var
  552. s : string;
  553. begin
  554. s[0]:=chr(getbyte);
  555. if entryidx+length(s)>entry.size then
  556. begin
  557. error:=true;
  558. exit;
  559. end;
  560. ReadData(s[1],length(s));
  561. getstring:=s;
  562. inc(entryidx,length(s));
  563. end;
  564. procedure tppufile.getsmallset(var b);
  565. begin
  566. getdata(b,4);
  567. end;
  568. procedure tppufile.getnormalset(var b);
  569. begin
  570. getdata(b,32);
  571. end;
  572. function tppufile.skipuntilentry(untilb:byte):boolean;
  573. var
  574. b : byte;
  575. begin
  576. repeat
  577. b:=readentry;
  578. until (b in [ibend,iberror]) or ((b=untilb) and (entry.id=mainentryid));
  579. skipuntilentry:=(b=untilb);
  580. end;
  581. {*****************************************************************************
  582. TPPUFile Writing
  583. *****************************************************************************}
  584. function tppufile.createfile:boolean;
  585. begin
  586. createfile:=false;
  587. {$ifdef INTFPPU}
  588. if crc_only then
  589. begin
  590. fname:=fname+'.intf';
  591. crc_only:=false;
  592. end;
  593. {$endif}
  594. if not crc_only then
  595. begin
  596. assign(f,fname);
  597. {$I-}
  598. rewrite(f,1);
  599. {$I+}
  600. if ioresult<>0 then
  601. exit;
  602. Mode:=2;
  603. {write header for sure}
  604. blockwrite(f,header,sizeof(tppuheader));
  605. end;
  606. bufsize:=ppubufsize;
  607. bufstart:=sizeof(tppuheader);
  608. bufidx:=0;
  609. {reset}
  610. crc:=cardinal($ffffffff);
  611. interface_crc:=cardinal($ffffffff);
  612. do_interface_crc:=true;
  613. Error:=false;
  614. do_crc:=true;
  615. size:=0;
  616. entrytyp:=mainentryid;
  617. {start}
  618. NewEntry;
  619. createfile:=true;
  620. end;
  621. procedure tppufile.writeheader;
  622. var
  623. opos : integer;
  624. begin
  625. { flush buffer }
  626. writebuf;
  627. { update size (w/o header!) in the header }
  628. header.size:=bufstart-sizeof(tppuheader);
  629. { set the endian flag }
  630. {$IFDEF SOURCE_BIG_ENDIAN}
  631. header.flags := header.flags or uf_big_endian;
  632. {$ENDIF}
  633. {$IFDEF SOURCE_LITTLE_ENDIAN}
  634. header.flags := header.flags or uf_little_endian;
  635. {$ENDIF}
  636. { Now swap the header in the correct endian (always little endian) }
  637. {$IFDEF SOURCE_BIG_ENDIAN}
  638. header.compiler := SwapWord(header.compiler);
  639. header.cpu := SwapWord(header.cpu);
  640. header.target := SwapWord(header.target);
  641. header.flags := SwapLong(header.flags);
  642. header.size := SwapLong(header.size);
  643. header.checksum := SwapLong(header.checksum);
  644. header.interface_checksum := SwapLong(header.interface_checksum);
  645. {$ENDIF}
  646. { write header and restore filepos after it }
  647. opos:=filepos(f);
  648. seek(f,0);
  649. blockwrite(f,header,sizeof(tppuheader));
  650. seek(f,opos);
  651. end;
  652. procedure tppufile.writebuf;
  653. begin
  654. if not crc_only then
  655. blockwrite(f,buf^,bufidx);
  656. inc(bufstart,bufidx);
  657. bufidx:=0;
  658. end;
  659. procedure tppufile.writedata(const b;len:integer);
  660. var
  661. p : pchar;
  662. left,
  663. idx : integer;
  664. begin
  665. if crc_only then
  666. exit;
  667. p:=pchar(@b);
  668. idx:=0;
  669. while len>0 do
  670. begin
  671. left:=bufsize-bufidx;
  672. if len>left then
  673. begin
  674. move(p[idx],buf[bufidx],left);
  675. dec(len,left);
  676. inc(idx,left);
  677. inc(bufidx,left);
  678. writebuf;
  679. end
  680. else
  681. begin
  682. move(p[idx],buf[bufidx],len);
  683. inc(bufidx,len);
  684. exit;
  685. end;
  686. end;
  687. end;
  688. procedure tppufile.NewEntry;
  689. begin
  690. with entry do
  691. begin
  692. id:=entrytyp;
  693. nr:=ibend;
  694. size:=0;
  695. end;
  696. {Reset Entry State}
  697. entryidx:=0;
  698. entrybufstart:=bufstart;
  699. entrystart:=bufstart+bufidx;
  700. {Alloc in buffer}
  701. writedata(entry,sizeof(tppuentry));
  702. end;
  703. procedure tppufile.writeentry(ibnr:byte);
  704. var
  705. opos : integer;
  706. begin
  707. {create entry}
  708. entry.id:=entrytyp;
  709. entry.nr:=ibnr;
  710. entry.size:=entryidx;
  711. {it's already been sent to disk ?}
  712. if entrybufstart<>bufstart then
  713. begin
  714. if not crc_only then
  715. begin
  716. {flush to be sure}
  717. WriteBuf;
  718. {write entry}
  719. opos:=filepos(f);
  720. seek(f,entrystart);
  721. blockwrite(f,entry,sizeof(tppuentry));
  722. seek(f,opos);
  723. end;
  724. entrybufstart:=bufstart;
  725. end
  726. else
  727. move(entry,buf[entrystart-bufstart],sizeof(entry));
  728. {Add New Entry, which is ibend by default}
  729. entrystart:=bufstart+bufidx; {next entry position}
  730. NewEntry;
  731. end;
  732. procedure tppufile.putdata(const b;len:integer);
  733. begin
  734. if do_crc then
  735. begin
  736. crc:=UpdateCrc32(crc,b,len);
  737. {$ifdef Test_Double_checksum}
  738. if crc_only then
  739. begin
  740. crc_test2^[crc_index2]:=crc;
  741. {$ifdef Test_Double_checksum_write}
  742. Writeln(CRCFile,crc);
  743. {$endif Test_Double_checksum_write}
  744. if crc_index2<crc_array_size then
  745. inc(crc_index2);
  746. end
  747. else
  748. begin
  749. if (crcindex2<crc_array_size) and (crcindex2<crc_index2) and
  750. (crc_test2^[crcindex2]<>crc) then
  751. Do_comment(V_Warning,'impl CRC changed');
  752. {$ifdef Test_Double_checksum_write}
  753. Writeln(CRCFile,crc);
  754. {$endif Test_Double_checksum_write}
  755. inc(crcindex2);
  756. end;
  757. {$endif def Test_Double_checksum}
  758. if do_interface_crc then
  759. begin
  760. interface_crc:=UpdateCrc32(interface_crc,b,len);
  761. {$ifdef Test_Double_checksum}
  762. if crc_only then
  763. begin
  764. crc_test^[crc_index]:=interface_crc;
  765. {$ifdef Test_Double_checksum_write}
  766. Writeln(CRCFile,interface_crc);
  767. {$endif Test_Double_checksum_write}
  768. if crc_index<crc_array_size then
  769. inc(crc_index);
  770. end
  771. else
  772. begin
  773. if (crcindex<crc_array_size) and (crcindex<crc_index) and
  774. (crc_test^[crcindex]<>interface_crc) then
  775. Do_comment(V_Warning,'CRC changed');
  776. {$ifdef Test_Double_checksum_write}
  777. Writeln(CRCFile,interface_crc);
  778. {$endif Test_Double_checksum_write}
  779. inc(crcindex);
  780. end;
  781. {$endif def Test_Double_checksum}
  782. end;
  783. end;
  784. if not crc_only then
  785. writedata(b,len);
  786. inc(entryidx,len);
  787. end;
  788. procedure tppufile.putbyte(b:byte);
  789. begin
  790. putdata(b,1);
  791. end;
  792. procedure tppufile.putword(w:word);
  793. begin
  794. putdata(w,2);
  795. end;
  796. procedure tppufile.putlongint(l:longint);
  797. begin
  798. putdata(l,4);
  799. end;
  800. procedure tppufile.putreal(d:ppureal);
  801. begin
  802. putdata(d,sizeof(ppureal));
  803. end;
  804. procedure tppufile.putstring(s:string);
  805. begin
  806. putdata(s,length(s)+1);
  807. end;
  808. procedure tppufile.putsmallset(const b);
  809. begin
  810. putdata(b,4);
  811. end;
  812. procedure tppufile.putnormalset(const b);
  813. begin
  814. putdata(b,32);
  815. end;
  816. procedure tppufile.tempclose;
  817. begin
  818. if not closed then
  819. begin
  820. closepos:=filepos(f);
  821. {$I-}
  822. system.close(f);
  823. {$I+}
  824. if ioresult<>0 then;
  825. closed:=true;
  826. tempclosed:=true;
  827. end;
  828. end;
  829. function tppufile.tempopen:boolean;
  830. var
  831. ofm : byte;
  832. begin
  833. tempopen:=false;
  834. if not closed or not tempclosed then
  835. exit;
  836. ofm:=filemode;
  837. filemode:=0;
  838. {$I-}
  839. reset(f,1);
  840. {$I+}
  841. filemode:=ofm;
  842. if ioresult<>0 then
  843. exit;
  844. closed:=false;
  845. tempclosed:=false;
  846. { restore state }
  847. seek(f,closepos);
  848. tempopen:=true;
  849. end;
  850. end.
  851. {
  852. $Log$
  853. Revision 1.10 2001-06-18 20:36:25 peter
  854. * -Ur switch (merged)
  855. * masm fixes (merged)
  856. * quoted filenames for go32v2 and win32
  857. Revision 1.9 2001/05/18 22:28:59 peter
  858. * endian define
  859. Revision 1.8 2001/05/06 14:49:17 peter
  860. * ppu object to class rewrite
  861. * move ppu read and write stuff to fppu
  862. Revision 1.7 2001/03/22 00:10:58 florian
  863. + basic variant type support in the compiler
  864. Revision 1.6 2000/12/07 17:19:43 jonas
  865. * new constant handling: from now on, hex constants >$7fffffff are
  866. parsed as unsigned constants (otherwise, $80000000 got sign extended
  867. and became $ffffffff80000000), all constants in the longint range
  868. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  869. are cardinals and the rest are int64's.
  870. * added lots of longint typecast to prevent range check errors in the
  871. compiler and rtl
  872. * type casts of symbolic ordinal constants are now preserved
  873. * fixed bug where the original resulttype wasn't restored correctly
  874. after doing a 64bit rangecheck
  875. Revision 1.5 2000/10/31 22:02:50 peter
  876. * symtable splitted, no real code changes
  877. Revision 1.4 2000/09/24 15:06:24 peter
  878. * use defines.inc
  879. Revision 1.3 2000/08/13 13:04:38 peter
  880. * new ppu version
  881. Revision 1.2 2000/07/13 11:32:45 michael
  882. + removed logs
  883. }