simbase.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. unit simbase;
  14. interface
  15. uses
  16. dos;
  17. { global types }
  18. type
  19. { tindex must be at least of type integer }
  20. tindex = integer;
  21. int64 = comp;
  22. qword = comp;
  23. dword = longint;
  24. tdword = array[0..3] of byte;
  25. pbyte = ^byte;
  26. pword = ^word;
  27. pdword = ^dword;
  28. pqword = ^qword;
  29. tqwordrec = record
  30. case tindex of
  31. 1 : (low32,high32 : dword);
  32. 2 : (bytes : array[0..7] of byte);
  33. 3 : (words : array[0..3] of word);
  34. end;
  35. oword = array[0..7] of word;
  36. towordrec = record
  37. case tindex of
  38. 1 : (bytes : array[0..15] of byte);
  39. 2 : (words : array[0..7] of word);
  40. 3 : (low64,high64 : qword);
  41. end;
  42. function hexstr(val : longint;cnt : byte) : string;
  43. function qword2str(q : qword) : string;
  44. function realtime : double;
  45. var
  46. stopsim : procedure;
  47. implementation
  48. function hexstr(val : longint;cnt : byte) : string;
  49. const
  50. HexTbl : array[0..15] of char='0123456789ABCDEF';
  51. var
  52. i : tindex;
  53. begin
  54. hexstr[0]:=char(cnt);
  55. for i:=cnt downto 1 do
  56. begin
  57. hexstr[i]:=hextbl[val and $f];
  58. val:=val shr 4;
  59. end;
  60. end;
  61. function qword2str(q : qword) : string;
  62. begin
  63. qword2str:=hexstr(tqwordrec(q).high32,8)+hexstr(tqwordrec(q).low32,8);
  64. end;
  65. function realtime : double;
  66. var
  67. h,m,s,s100 : word;
  68. begin
  69. gettime(h,m,s,s100);
  70. realtime:=h*3600+m*60+s+s100/100.0;
  71. end;
  72. procedure _stopsim;{$ifdef TP}far;{$endif TP}
  73. begin
  74. writeln('Simulation stopped');
  75. halt(1);
  76. end;
  77. begin
  78. {$ifdef FPC}
  79. stopsim:=@_stopsim;
  80. {$else FPC}
  81. stopsim:=_stopsim;
  82. {$endif FPC}
  83. end.
  84. {
  85. $Log$
  86. Revision 1.2 2000-01-07 16:46:07 daniel
  87. * copyright 2000
  88. Revision 1.1 1999/06/14 11:49:48 florian
  89. + initial revision, it runs simple Alpha Linux ELF executables
  90. - integer operations are nearly completed (non with overflow checking)
  91. - floating point operations aren't implemented (except loading and
  92. storing)
  93. - only the really necessary system calls are implemented by dummys
  94. write syscalls are redirected to the console
  95. }