simbase.pas 2.5 KB

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