@@ -31,35 +31,29 @@ const |
| 31 |
|
31 |
|
| 32 |
procedure TEmulationThread.Execute; |
32 |
procedure TEmulationThread.Execute; |
| 33 |
var |
33 |
var |
| 34 |
tickFreq, cycles: Extended; |
34 |
cycles: Extended; |
| 35 |
frameStart, frameEnd: Extended; |
35 |
frameStart, frameEnd: Extended; |
| 36 |
frameElapsedInSec: Extended; |
36 |
frameElapsedInSec: Extended; |
| 37 |
function GetCounter: Extended; |
|
|
| 38 |
begin |
37 |
begin |
| 39 |
Result := ET.Elapsed*1000000; // Convert to microseconds |
38 |
LastTime := 0; |
| 40 |
end; |
|
|
| 41 |
begin |
|
|
| 42 |
lastTime := 0; |
|
|
| 43 |
|
39 |
|
| 44 |
cycles := 0; |
40 |
Cycles := 0; |
| 45 |
|
41 |
|
| 46 |
tickFreq := 1000000; // Convert to microseconds |
42 |
FrameStart := ET.Elapsed; |
| 47 |
FrameStart := GetCounter; |
|
|
| 48 |
|
43 |
|
| 49 |
repeat |
44 |
repeat |
| 50 |
while (cycles < CyclesPerFrame) do |
45 |
while (Cycles < CyclesPerFrame) do |
| 51 |
cycles += z80_decode; |
46 |
Cycles += z80_decode; |
| 52 |
|
47 |
|
| 53 |
cycles -= CyclesPerFrame; |
48 |
Cycles -= CyclesPerFrame; |
| 54 |
|
49 |
|
| 55 |
// TODO: Replace this with an actual timing mechanism. This devours CPU. |
|
|
| 56 |
repeat |
50 |
repeat |
| 57 |
FrameEnd := GetCounter; |
51 |
FrameEnd := ET.Elapsed; |
|
|
52 |
FrameElapsedInSec := (FrameEnd - frameStart); |
| 58 |
|
53 |
|
| 59 |
frameElapsedInSec := (frameEnd - frameStart) / tickFreq; |
54 |
until ((FrameElapsedInSec > TimePerFrame) and (not SoundBufferTooFull)); |
| 60 |
until ((frameElapsedInSec > TimePerFrame) and (not SoundBufferTooFull)); |
|
|
| 61 |
|
55 |
|
| 62 |
frameStart := frameEnd; |
56 |
FrameStart := FrameEnd; |
| 63 |
until Terminated; |
57 |
until Terminated; |
| 64 |
end; |
58 |
end; |
| 65 |
|
59 |
|