Commit 26623c4

Nick committed on
Cleanup + removed EmulationThread
commit 26623c443d369fcf474e627e5a5f59570609aadd parent 59cde70
5 changed files +10−89
ModifiedGBEmu.lpr +2−2
@@ -53,7 +53,7 @@ begin
53 DeleteFile('heap.trc'); 53 DeleteFile('heap.trc');
54 SetHeapTraceOutput('heap.trc'); 54 SetHeapTraceOutput('heap.trc');
55 55
56 Writeln(StdErr, 'Using heaptrc...'); 56 Writeln(StdErr, '[DEBUG] Using heaptrc...');
57 {$endIf} 57 {$endIf}
58 58
59 { Before the LCL starts, embed Pixelite so users dont have to install it. 59 { Before the LCL starts, embed Pixelite so users dont have to install it.
@@ -62,7 +62,7 @@ begin
62 62
63 {$ifdef MSWINDOWS} 63 {$ifdef MSWINDOWS}
64 if AddFontResource('PixeliteTTF.ttf') = 0 then 64 if AddFontResource('PixeliteTTF.ttf') = 0 then
65 Writeln(StdErr, 'Couldn''t load Pixelite!!!'); 65 Writeln(StdErr, '[ERROR] Couldn''t load Pixelite!!!');
66 66
67 ExitProc := @WindowsExitProc; 67 ExitProc := @WindowsExitProc;
68 {$endif} 68 {$endif}
ModifiedSound/sound.pas +6−4
@@ -161,8 +161,6 @@ procedure EndWritingSoundToStream;
161 var 161 var
162 soundEnable: boolean; 162 soundEnable: boolean;
163 sndRegChange: boolean; 163 sndRegChange: boolean;
164 sndBuffer: ^Single;
165 sndBytesWritten: Integer;
166 snd: array[1..4] of record 164 snd: array[1..4] of record
167 // public: 165 // public:
168 ChannelOFF: boolean; // (un)mute Channel 166 ChannelOFF: boolean; // (un)mute Channel
@@ -191,6 +189,10 @@ const
191 var 189 var
192 PlayStream: TSDL_AudioDeviceID; 190 PlayStream: TSDL_AudioDeviceID;
193 bufCycles, bufLVal, bufRVal: integer; 191 bufCycles, bufLVal, bufRVal: integer;
192
193 sndBuffer: ^Single;
194 sndBytesWritten: Integer;
195
194 lfsr: Cardinal = 0; 196 lfsr: Cardinal = 0;
195 197
196 WritingSoundToStream: Boolean; 198 WritingSoundToStream: Boolean;
@@ -269,6 +271,7 @@ begin
269 sndBuffer := PSingle(Stream); 271 sndBuffer := PSingle(Stream);
270 while sndBytesWritten < len do 272 while sndBytesWritten < len do
271 z80_decode; 273 z80_decode;
274 if sndBytesWritten > len then Writeln(StdErr, '[WARNING] Audio callback wrote into uninitialized ram!');
272 sndBytesWritten := 0; 275 sndBytesWritten := 0;
273 end; 276 end;
274 277
@@ -287,7 +290,7 @@ begin
287 Want.freq := playbackFrequency; 290 Want.freq := playbackFrequency;
288 Want.format := AUDIO_F32; 291 Want.format := AUDIO_F32;
289 Want.channels := 2; 292 Want.channels := 2;
290 Want.samples := 1024; //512; 293 Want.samples := 512;
291 Want.callback := @AudioCallback; 294 Want.callback := @AudioCallback;
292 295
293 PlayStream := SDL_OpenAudioDevice(nil, 0, @Want, @Have, 0); 296 PlayStream := SDL_OpenAudioDevice(nil, 0, @Want, @Have, 0);
@@ -336,7 +339,6 @@ begin
336 sndBuffer^ := buf[1]; 339 sndBuffer^ := buf[1];
337 Inc(sndBuffer); 340 Inc(sndBuffer);
338 Inc(sndBytesWritten, SampleSize); 341 Inc(sndBytesWritten, SampleSize);
339 //SDL_QueueAudio(PlayStream, @buf, SampleSize);
340 end; 342 end;
341 end; 343 end;
342 end; 344 end;
Deletedemulationthread.pas +0−81
@@ -1,81 +0,0 @@
1 unit EmulationThread;
2
3 {$mode delphi}
4
5 interface
6
7 uses
8 Classes, SysUtils, epiktimer;
9
10 type
11 { TEmulationThread }
12
13 TEmulationThread = class(TThread)
14 protected
15 procedure Execute; override;
16 procedure OnFD;
17 public
18 Constructor Create(ROM: String);
19 end;
20
21 implementation
22
23 uses sound, mainloop, vars, machine, LCLIntf, constants, Tracker;
24
25 var
26 ET: TEpikTimer;
27
28 const
29 CyclesPerFrame : Integer = 70224;
30 TimePerFrame: Double = 1.0 / 60.0;
31
32 procedure TEmulationThread.Execute;
33 var
34 cycles: Extended;
35 frameStart, frameEnd: Extended;
36 frameElapsedInSec: Extended;
37 begin
38 LastTime := 0;
39
40 Cycles := 0;
41
42 FrameStart := ET.Elapsed;
43
44 repeat
45 while (Cycles < CyclesPerFrame) do
46 Cycles += z80_decode;
47
48 Cycles -= CyclesPerFrame;
49
50 repeat
51 FrameEnd := ET.Elapsed;
52 FrameElapsedInSec := (FrameEnd - frameStart);
53
54 until ((FrameElapsedInSec > TimePerFrame) and (not SoundBufferTooFull));
55
56 FrameStart := FrameEnd;
57 until Terminated;
58 end;
59
60 procedure TEmulationThread.OnFD;
61 begin
62 PostMessage(frmTracker.Handle, LM_FD, 0, 0);
63 end;
64
65 constructor TEmulationThread.Create(ROM: String);
66 begin
67 inherited Create(True);
68 z80_reset;
69 ResetSound;
70 enablesound;
71
72 FDCallback := OnFD;
73
74 load(ROM);
75 end;
76
77 begin
78 ET := TEpikTimer.Create(nil);
79 ET.Start;
80 end.
81
Modifiedrendertowave.pas +1−1
@@ -153,7 +153,7 @@ begin
153 153
154 z80_reset; 154 z80_reset;
155 ResetSound; 155 ResetSound;
156 //enablesound; 156 enablesound;
157 157
158 FDCallback := nil; 158 FDCallback := nil;
159 load('hUGEDriver/preview.gb'); 159 load('hUGEDriver/preview.gb');
Modifiedtrackergrid.pas +1−1
@@ -399,7 +399,7 @@ begin
399 Other.SelectedPart := High(TCellPart); 399 Other.SelectedPart := High(TCellPart);
400 except 400 except
401 on E: Exception do 401 on E: Exception do
402 WriteLn(StdErr, 'Clipboard did not contain valid note data!'); 402 WriteLn(StdErr, '[DEBUG] Clipboard did not contain valid note data!');
403 end; 403 end;
404 end; 404 end;
405 405