simbase.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {
  2. $Id$
  3. This file is part of the Free Pascal simulator environment
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. This unit implemements some helper routines
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  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.
  11. **********************************************************************}
  12. {$N+}
  13. {$H-}
  14. unit simbase;
  15. interface
  16. {$ifdef Delphi}
  17. uses
  18. dmisc;
  19. {$else Delphi}
  20. uses
  21. dos;
  22. {$endif Delphi}
  23. { global types }
  24. type
  25. { tindex must be at least of type integer }
  26. tindex = integer;
  27. {$ifndef FPC}
  28. int64 = comp;
  29. qword = comp;
  30. {$endif FPC}
  31. dword = longint;
  32. tdword = array[0..3] of byte;
  33. pbyte = ^byte;
  34. pword = ^word;
  35. pdword = ^dword;
  36. pqword = ^qword;
  37. tqwordrec = record
  38. case tindex of
  39. 1 : (low32,high32 : dword);
  40. 2 : (bytes : array[0..7] of byte);
  41. 3 : (words : array[0..3] of word);
  42. end;
  43. oword = array[0..7] of word;
  44. towordrec = record
  45. case tindex of
  46. 1 : (bytes : array[0..15] of byte);
  47. 2 : (words : array[0..7] of word);
  48. 3 : (low64,high64 : qword);
  49. end;
  50. function hexstr(val : longint;cnt : byte) : string;
  51. function qword2str(q : qword) : string;
  52. function realtime : double;
  53. var
  54. stopsim : procedure;
  55. implementation
  56. function hexstr(val : longint;cnt : byte) : string;
  57. const
  58. HexTbl : array[0..15] of char='0123456789ABCDEF';
  59. var
  60. i : tindex;
  61. begin
  62. hexstr[0]:=char(cnt);
  63. for i:=cnt downto 1 do
  64. begin
  65. hexstr[i]:=hextbl[val and $f];
  66. val:=val shr 4;
  67. end;
  68. end;
  69. function qword2str(q : qword) : string;
  70. begin
  71. qword2str:=hexstr(tqwordrec(q).high32,8)+hexstr(tqwordrec(q).low32,8);
  72. end;
  73. function realtime : double;
  74. var
  75. h,m,s,s100 : word;
  76. begin
  77. gettime(h,m,s,s100);
  78. realtime:=h*3600+m*60+s+s100/100.0;
  79. end;
  80. procedure _stopsim;{$ifdef TP}far;{$endif TP}
  81. begin
  82. writeln('Simulation stopped');
  83. halt(1);
  84. end;
  85. begin
  86. {$ifdef FPC}
  87. stopsim:=@_stopsim;
  88. {$else FPC}
  89. stopsim:=_stopsim;
  90. {$endif FPC}
  91. end.
  92. {
  93. $Log$
  94. Revision 1.2 2002-09-07 15:40:37 peter
  95. * old logs removed and tabs fixed
  96. }