Commit 026a871

Nick committed on
Clean up code slightly
commit 026a871b54110602029dbbc228eeaf6a32c3fc5e parent 21bcc29
2 changed files +11−24
ModifiedSound/sound.pas +0−7
@@ -143,7 +143,6 @@ procedure EnableSound;
143 procedure DisableSound; 143 procedure DisableSound;
144 procedure ResetSound; 144 procedure ResetSound;
145 procedure SoundUpdate(cycles: integer); 145 procedure SoundUpdate(cycles: integer);
146 procedure SoundSetCycles(n: integer);
147 146
148 function SoundBufferTooFull: Boolean; 147 function SoundBufferTooFull: Boolean;
149 function SoundBufferSize: Integer; 148 function SoundBufferSize: Integer;
@@ -327,7 +326,6 @@ var
327 326
328 327
329 // Yanked from SameBoy: https://github.com/LIJI32/SameBoy/blob/master/Core/apu.c#L489 328 // Yanked from SameBoy: https://github.com/LIJI32/SameBoy/blob/master/Core/apu.c#L489
330 // carrying on the tradition of translating existing C audio code
331 function NextLFSRBit(Narrow: Boolean): Byte; 329 function NextLFSRBit(Narrow: Boolean): Byte;
332 var 330 var
333 HighBitMask: Cardinal; 331 HighBitMask: Cardinal;
@@ -688,11 +686,6 @@ begin
688 SoundOutBits(l, r, cycles); 686 SoundOutBits(l, r, cycles);
689 end; 687 end;
690 688
691 procedure SoundSetCycles(n: integer);
692 begin
693 sampleCycles := n;
694 end;
695
696 begin 689 begin
697 ResetSound 690 ResetSound
698 end. 691 end.
Modifiedemulationthread.pas +11−17
@@ -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