ppu.pas 21 KB

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