@@ -9,22 +9,24 @@ uses |
| 9 |
cthreads, |
9 |
cthreads, |
| 10 |
cmem, // the c memory manager is on some systems much faster for multi-threading |
10 |
cmem, // the c memory manager is on some systems much faster for multi-threading |
| 11 |
{$endif} |
11 |
{$endif} |
| 12 |
Classes, SysUtils; |
12 |
Classes, SysUtils, epiktimer; |
| 13 |
|
13 |
|
| 14 |
type |
14 |
type |
|
|
15 |
{ TEmulationThread } |
|
|
16 |
|
| 15 |
TEmulationThread = class(TThread) |
17 |
TEmulationThread = class(TThread) |
| 16 |
private |
18 |
private |
| 17 |
//stuff |
19 |
ET: TEpikTimer; |
| 18 |
protected |
20 |
protected |
| 19 |
procedure Execute; override; |
21 |
procedure Execute; override; |
| 20 |
public |
22 |
public |
| 21 |
Constructor Create(ROM: String); |
23 |
Constructor Create(ROM: String); |
|
|
24 |
destructor Destroy; override; |
| 22 |
end; |
25 |
end; |
| 23 |
|
26 |
|
| 24 |
implementation |
27 |
implementation |
| 25 |
|
28 |
|
| 26 |
uses sound, mainloop, vars, machine, |
29 |
uses sound, mainloop, vars, machine; |
| 27 |
windows; |
|
|
| 28 |
|
30 |
|
| 29 |
const |
31 |
const |
| 30 |
CyclesPerFrame : Integer = 70224; |
32 |
CyclesPerFrame : Integer = 70224; |
@@ -32,22 +34,21 @@ const |
| 32 |
|
34 |
|
| 33 |
procedure TEmulationThread.Execute; |
35 |
procedure TEmulationThread.Execute; |
| 34 |
var |
36 |
var |
| 35 |
li: Large_Integer; |
37 |
tickFreq, cycles: Extended; |
| 36 |
tickFreq, cycles: Integer; |
38 |
frameStart, frameEnd: Extended; |
| 37 |
frameStart, frameEnd: Integer; |
|
|
| 38 |
frameElapsedInSec: Double; |
39 |
frameElapsedInSec: Double; |
| 39 |
function GetCounter: Integer; |
40 |
function GetCounter: Integer; |
| 40 |
begin |
41 |
begin |
| 41 |
QueryPerformanceCounter(@li); |
42 |
Result := Trunc(ET.Elapsed*1000000); // Convert to microseconds |
| 42 |
Result := li.QuadPart |
|
|
| 43 |
end; |
43 |
end; |
| 44 |
begin |
44 |
begin |
|
|
45 |
ET.Start; |
|
|
46 |
|
| 45 |
lastTime := 0; |
47 |
lastTime := 0; |
| 46 |
|
48 |
|
| 47 |
cycles := 0; |
49 |
cycles := 0; |
| 48 |
|
50 |
|
| 49 |
QueryPerformanceFrequency(@li); |
51 |
tickFreq := 1000000; // Convert to microseconds |
| 50 |
tickFreq := li.QuadPart; |
|
|
| 51 |
FrameStart := GetCounter; |
52 |
FrameStart := GetCounter; |
| 52 |
|
53 |
|
| 53 |
repeat |
54 |
repeat |
@@ -73,8 +74,17 @@ begin |
| 73 |
ResetSound; |
74 |
ResetSound; |
| 74 |
enablesound; |
75 |
enablesound; |
| 75 |
|
76 |
|
|
|
77 |
ET := TEpikTimer.Create(nil); |
|
|
78 |
|
| 76 |
load(ROM); |
79 |
load(ROM); |
| 77 |
end; |
80 |
end; |
| 78 |
|
81 |
|
|
|
82 |
destructor TEmulationThread.Destroy; |
|
|
83 |
begin |
|
|
84 |
inherited Destroy; |
|
|
85 |
|
|
|
86 |
ET.Free; |
|
|
87 |
end; |
|
|
88 |
|
| 79 |
end. |
89 |
end. |
| 80 |
|
90 |
|