Commit 6b40d82

Nick committed on
WIP on sound. Got all sounds except channel 3 perfect!
commit 6b40d822bac795bbbcbdfb2ee700451b84444ca1 parent 531b7f6
7 changed files +45−109
ModifiedGBEmu.lpi +14−53
@@ -26,6 +26,7 @@
26 <RunParams> 26 <RunParams>
27 <local> 27 <local>
28 <FormatVersion Value="1"/> 28 <FormatVersion Value="1"/>
29 <CommandLineParams Value="C:\Projects\GB-Stuff\sml.gb"/>
29 </local> 30 </local>
30 </RunParams> 31 </RunParams>
31 <RequiredPackages Count="2"> 32 <RequiredPackages Count="2">
@@ -36,7 +37,7 @@
36 <PackageName Value="LCL"/> 37 <PackageName Value="LCL"/>
37 </Item2> 38 </Item2>
38 </RequiredPackages> 39 </RequiredPackages>
39 <Units Count="22"> 40 <Units Count="12">
40 <Unit0> 41 <Unit0>
41 <Filename Value="GBEmu.lpr"/> 42 <Filename Value="GBEmu.lpr"/>
42 <IsPartOfProject Value="True"/> 43 <IsPartOfProject Value="True"/>
@@ -53,84 +54,44 @@
53 <IsPartOfProject Value="True"/> 54 <IsPartOfProject Value="True"/>
54 </Unit2> 55 </Unit2>
55 <Unit3> 56 <Unit3>
56 <Filename Value="Directx\directdraw.pas"/> 57 <Filename Value="Gpu\ddraw_out.pas"/>
57 <IsPartOfProject Value="True"/> 58 <IsPartOfProject Value="True"/>
58 </Unit3> 59 </Unit3>
59 <Unit4> 60 <Unit4>
60 <Filename Value="DirectX\dxcommon.pas"/> 61 <Filename Value="Gpu\gfx.pas"/>
61 <IsPartOfProject Value="True"/> 62 <IsPartOfProject Value="True"/>
62 </Unit4> 63 </Unit4>
63 <Unit5> 64 <Unit5>
64 <Filename Value="Gpu\ddraw_out.pas"/> 65 <Filename Value="CPU\machine.pas"/>
65 <IsPartOfProject Value="True"/> 66 <IsPartOfProject Value="True"/>
66 </Unit5> 67 </Unit5>
67 <Unit6> 68 <Unit6>
68 <Filename Value="Gpu\dib_out.pas"/> 69 <Filename Value="Cpu\z80cpu.pas"/>
69 <IsPartOfProject Value="True"/> 70 <IsPartOfProject Value="True"/>
71 <UnitName Value="Z80CPU"/>
70 </Unit6> 72 </Unit6>
71 <Unit7> 73 <Unit7>
72 <Filename Value="Gpu\gfx.pas"/> 74 <Filename Value="Sound\sound.pas"/>
73 <IsPartOfProject Value="True"/> 75 <IsPartOfProject Value="True"/>
74 </Unit7> 76 </Unit7>
75 <Unit8> 77 <Unit8>
76 <Filename Value="CPU\machine.pas"/> 78 <Filename Value="Global\vars.pas"/>
77 <IsPartOfProject Value="True"/> 79 <IsPartOfProject Value="True"/>
78 </Unit8> 80 </Unit8>
79 <Unit9> 81 <Unit9>
80 <Filename Value="Cpu\z80cpu.pas"/> 82 <Filename Value="mainloop.pas"/>
81 <IsPartOfProject Value="True"/> 83 <IsPartOfProject Value="True"/>
82 <UnitName Value="Z80CPU"/>
83 </Unit9> 84 </Unit9>
84 <Unit10> 85 <Unit10>
85 <Filename Value="Sound\sound.pas"/>
86 <IsPartOfProject Value="True"/>
87 </Unit10>
88 <Unit11>
89 <Filename Value="Global\vars.pas"/>
90 <IsPartOfProject Value="True"/>
91 </Unit11>
92 <Unit12>
93 <Filename Value="mainloop.pas"/>
94 <IsPartOfProject Value="True"/>
95 </Unit12>
96 <Unit13>
97 <Filename Value="Debugger\UnitDebug.pas"/> 86 <Filename Value="Debugger\UnitDebug.pas"/>
98 <IsPartOfProject Value="True"/> 87 <IsPartOfProject Value="True"/>
99 <HasResources Value="True"/> 88 <HasResources Value="True"/>
100 </Unit13> 89 </Unit10>
101 <Unit14> 90 <Unit11>
102 <Filename Value="DirectX\Direct3DRM.pas"/>
103 <IsPartOfProject Value="True"/>
104 </Unit14>
105 <Unit15>
106 <Filename Value="DirectX\DirectInput.pas"/>
107 <IsPartOfProject Value="True"/>
108 </Unit15>
109 <Unit16>
110 <Filename Value="DirectX\DirectMusic.pas"/>
111 <IsPartOfProject Value="True"/>
112 </Unit16>
113 <Unit17>
114 <Filename Value="DirectX\DirectPlay.pas"/>
115 <IsPartOfProject Value="True"/>
116 </Unit17>
117 <Unit18>
118 <Filename Value="DirectX\DirectSetup.pas"/>
119 <IsPartOfProject Value="True"/>
120 </Unit18>
121 <Unit19>
122 <Filename Value="DirectX\DirectSound.pas"/>
123 <IsPartOfProject Value="True"/>
124 </Unit19>
125 <Unit20>
126 <Filename Value="DirectX\Direct3D.pas"/>
127 <IsPartOfProject Value="True"/>
128 </Unit20>
129 <Unit21>
130 <Filename Value="Debugger\UnitMapview.pas"/> 91 <Filename Value="Debugger\UnitMapview.pas"/>
131 <IsPartOfProject Value="True"/> 92 <IsPartOfProject Value="True"/>
132 <HasResources Value="True"/> 93 <HasResources Value="True"/>
133 </Unit21> 94 </Unit11>
134 </Units> 95 </Units>
135 </ProjectOptions> 96 </ProjectOptions>
136 <CompilerOptions> 97 <CompilerOptions>
@@ -138,7 +99,7 @@
138 <PathDelim Value="\"/> 99 <PathDelim Value="\"/>
139 <SearchPaths> 100 <SearchPaths>
140 <IncludeFiles Value="Debugger;Directx;GPU;CPU;Sound;Global;Components;$(ProjOutDir)"/> 101 <IncludeFiles Value="Debugger;Directx;GPU;CPU;Sound;Global;Components;$(ProjOutDir)"/>
141 <OtherUnitFiles Value="Debugger;Directx;GPU;CPU;Sound;Global"/> 102 <OtherUnitFiles Value="Debugger;GPU;CPU;Sound;Global"/>
142 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 103 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
143 </SearchPaths> 104 </SearchPaths>
144 <Parsing> 105 <Parsing>
ModifiedGBEmu.lpr +0−10
@@ -7,10 +7,7 @@ uses
7 Interfaces, 7 Interfaces,
8 UnitMain in 'UnitMain.pas' {frmGameboy}, 8 UnitMain in 'UnitMain.pas' {frmGameboy},
9 debugger in 'Debugger\debugger.pas', 9 debugger in 'Debugger\debugger.pas',
10 directdraw in 'Directx\directdraw.pas',
11 dxcommon in 'DirectX\dxcommon.pas',
12 ddraw_out in 'GPU\ddraw_out.pas', 10 ddraw_out in 'GPU\ddraw_out.pas',
13 dib_out in 'GPU\dib_out.pas',
14 gfx in 'GPU\gfx.pas', 11 gfx in 'GPU\gfx.pas',
15 machine in 'CPU\machine.pas', 12 machine in 'CPU\machine.pas',
16 Z80CPU in 'CPU\z80cpu.pas', 13 Z80CPU in 'CPU\z80cpu.pas',
@@ -18,13 +15,6 @@ uses
18 vars in 'Global\vars.pas', 15 vars in 'Global\vars.pas',
19 mainloop in 'mainloop.pas', 16 mainloop in 'mainloop.pas',
20 UnitDebug in 'Debugger\UnitDebug.pas' {frmDebug}, 17 UnitDebug in 'Debugger\UnitDebug.pas' {frmDebug},
21 Direct3DRM in 'DirectX\Direct3DRM.pas',
22 DirectInput in 'DirectX\DirectInput.pas',
23 DirectMusic in 'DirectX\DirectMusic.pas',
24 DirectPlay in 'DirectX\DirectPlay.pas',
25 DirectSetup in 'DirectX\DirectSetup.pas',
26 DirectSound in 'DirectX\DirectSound.pas',
27 Direct3D in 'DirectX\Direct3D.pas',
28 UnitMapview in 'Debugger\UnitMapview.pas' {frmMapview}; 18 UnitMapview in 'Debugger\UnitMapview.pas' {frmMapview};
29 19
30 {.$R *.RES} 20 {.$R *.RES}
ModifiedGlobal/vars.pas +0−2
@@ -7,8 +7,6 @@ unit vars;
7 7
8 interface 8 interface
9 9
10 uses Windows, DirectDraw;
11
12 const 10 const
13 thr_f: integer = 1; 11 thr_f: integer = 1;
14 cart: pointer = nil; // Cartdridge 12 cart: pointer = nil; // Cartdridge
ModifiedSound/sound.pas +2−3
@@ -253,7 +253,7 @@ begin
253 snd[1].Freq := m_iram[$FF13] or ((m_iram[$FF14] and 7) shl 8); 253 snd[1].Freq := m_iram[$FF13] or ((m_iram[$FF14] and 7) shl 8);
254 snd[2].Freq := m_iram[$FF18] or ((m_iram[$FF19] and 7) shl 8); 254 snd[2].Freq := m_iram[$FF18] or ((m_iram[$FF19] and 7) shl 8);
255 snd[3].Freq := m_iram[$FF1d] or ((m_iram[$FF1e] and 7) shl 8); 255 snd[3].Freq := m_iram[$FF1d] or ((m_iram[$FF1e] and 7) shl 8);
256 case m_iram[$FF22] and 7 of //NICK (7 -> 15)... wrong number of bits! 256 case m_iram[$FF22] and 7 of
257 0: snd[4].Freq := (512 * 1024 * 2) shr ((m_iram[$FF22] shr 4) + 1); 257 0: snd[4].Freq := (512 * 1024 * 2) shr ((m_iram[$FF22] shr 4) + 1);
258 1: snd[4].Freq := (512 * 1024) shr ((m_iram[$FF22] shr 4) + 1); 258 1: snd[4].Freq := (512 * 1024) shr ((m_iram[$FF22] shr 4) + 1);
259 2: snd[4].Freq := ((512 * 1024) div 2) shr ((m_iram[$FF22] shr 4) + 1); 259 2: snd[4].Freq := ((512 * 1024) div 2) shr ((m_iram[$FF22] shr 4) + 1);
@@ -561,8 +561,7 @@ begin
561 561
562 l := shortint(l shr 2) + 128; 562 l := shortint(l shr 2) + 128;
563 r := shortint(r shr 2) + 128; 563 r := shortint(r shr 2) + 128;
564 if (l <> 170) and (r <> 170) then 564 SoundOutBits(l, r, cycles)
565 SoundOutBits(l, r, cycles);
566 end; 565 end;
567 566
568 procedure SoundSetCycles(n: integer); 567 procedure SoundSetCycles(n: integer);
ModifiedUnitMain.lfm +6−7
@@ -1,14 +1,13 @@
1 object frmGameboy: TfrmGameboy 1 object frmGameboy: TfrmGameboy
2 Left = 1262 2 Left = 572
3 Height = 354 3 Height = 354
4 Top = 525 4 Top = 127
5 Width = 318 5 Width = 318
6 Caption = 'Gameboy' 6 Caption = 'Gameboy'
7 ClientHeight = 320 7 ClientHeight = 334
8 ClientWidth = 318 8 ClientWidth = 318
9 Color = clYellow 9 Color = clYellow
10 DefaultMonitor = dmMainForm 10 DefaultMonitor = dmMainForm
11 DesignTimePPI = 168
12 Font.CharSet = ANSI_CHARSET 11 Font.CharSet = ANSI_CHARSET
13 Font.Color = clWindowText 12 Font.Color = clWindowText
14 Font.Height = -12 13 Font.Height = -12
@@ -25,8 +24,8 @@ object frmGameboy: TfrmGameboy
25 LCLVersion = '1.8.4.0' 24 LCLVersion = '1.8.4.0'
26 object StatusBar: TStatusBar 25 object StatusBar: TStatusBar
27 Left = 0 26 Left = 0
28 Height = 43 27 Height = 23
29 Top = 277 28 Top = 311
30 Width = 318 29 Width = 318
31 Panels = < 30 Panels = <
32 item 31 item
@@ -46,7 +45,7 @@ object frmGameboy: TfrmGameboy
46 end 45 end
47 object PaintBox1: TPaintBox 46 object PaintBox1: TPaintBox
48 Left = 0 47 Left = 0
49 Height = 277 48 Height = 311
50 Top = 0 49 Top = 0
51 Width = 318 50 Width = 318
52 Align = alClient 51 Align = alClient
ModifiedUnitMain.pas +22−26
@@ -133,6 +133,7 @@ type
133 FDiff: integer; // Caption Height 133 FDiff: integer; // Caption Height
134 procedure Emulation(var msg: TMessage); message wm_user; 134 procedure Emulation(var msg: TMessage); message wm_user;
135 procedure SetWindow; 135 procedure SetWindow;
136 procedure LoadRom(Rom: String);
136 137
137 procedure ShowCaption; 138 procedure ShowCaption;
138 procedure RemoveCaption; 139 procedure RemoveCaption;
@@ -169,8 +170,6 @@ begin
169 end; 170 end;
170 171
171 procedure TfrmGameboy.FormCreate(Sender: TObject); 172 procedure TfrmGameboy.FormCreate(Sender: TObject);
172 var
173 li: Large_Integer;
174 begin 173 begin
175 loadstat.Enabled := False; 174 loadstat.Enabled := False;
176 savestat.Enabled := False; 175 savestat.Enabled := False;
@@ -188,10 +187,7 @@ begin
188 if assigned(cart) then 187 if assigned(cart) then
189 freemem(cart, cartsize); 188 freemem(cart, cartsize);
190 z80_reset; 189 z80_reset;
191 // initialize PerfFreq
192 190
193 QueryPerformanceFrequency(li.quadpart);
194 perfFreq := li.LowPart div 32;// shr 5;
195 SetAudioChannel(Self); 191 SetAudioChannel(Self);
196 enablesound; 192 enablesound;
197 end; 193 end;
@@ -243,19 +239,32 @@ begin
243 239
244 cycles -= CyclesPerFrame; 240 cycles -= CyclesPerFrame;
245 241
246 while True do begin 242 repeat
247 QueryPerformanceCounter(@li); 243 QueryPerformanceCounter(@li);
248 frameEnd := li.QuadPart; 244 frameEnd := li.QuadPart;
249 245
250 frameElapsedInSec := (frameEnd - frameStart) / tickFreq; 246 frameElapsedInSec := (frameEnd - frameStart) / tickFreq;
251 if frameElapsedInSec > TimePerFrame then 247 until frameElapsedInSec > TimePerFrame;
252 Break;
253 end;
254 248
255 frameStart := frameEnd; 249 frameStart := frameEnd;
256 until application.Terminated; 250 until application.Terminated;
257 end; 251 end;
258 252
253 procedure TfrmGameboy.LoadRom(Rom: String);
254 begin
255 f_stopped := True;
256 load(Rom);
257 statusbar.Panels[2].Text := getcompany;
258 statusbar.Panels[1].Text := speicher;
259 statusbar.panels[0].Text := romname;
260 z80_reset;
261 z80_reset;
262 f_stopped := False;
263 gb_speed := 1;
264 loadstat.Enabled := True;
265 savestat.Enabled := True;
266 end;
267
259 procedure TfrmGameboy.FileOpenClick(Sender: TObject); 268 procedure TfrmGameboy.FileOpenClick(Sender: TObject);
260 var 269 var
261 i: integer; 270 i: integer;
@@ -267,22 +276,7 @@ begin
267 opendialog.Filter := 276 opendialog.Filter :=
268 'All Roms [*.gb;*.gbc;*.rom]|*.gb;*.gbc;*.rom|Gameboy [*.gb]|*.gb|Gameboy Color [*.gbc]|*.gbc|All Files [*.*]|*.*'; 277 'All Roms [*.gb;*.gbc;*.rom]|*.gb;*.gbc;*.rom|Gameboy [*.gb]|*.gb|Gameboy Color [*.gbc]|*.gbc|All Files [*.*]|*.*';
269 278
270 if opendialog.Execute then 279 if opendialog.Execute then LoadRom(opendialog.filename);
271 begin
272 f_stopped := True;
273 load(opendialog.filename);
274 i := 0;
275 statusbar.Panels[2].Text := getcompany;
276 statusbar.Panels[1].Text := speicher;
277 statusbar.panels[0].Text := romname;
278 z80_reset;
279 z80_reset;
280 f_stopped := False;
281 gb_speed := 1;
282 setzewindow(handle);
283 loadstat.Enabled := True;
284 savestat.Enabled := True;
285 end;
286 end; 280 end;
287 281
288 procedure TfrmGameboy.KillClick(Sender: TObject); 282 procedure TfrmGameboy.KillClick(Sender: TObject);
@@ -307,11 +301,13 @@ begin
307 z80_reset; 301 z80_reset;
308 f_stopped := True; 302 f_stopped := True;
309 gb_speed := 1; 303 gb_speed := 1;
310 setzewindow(handle);
311 304
312 frmGameboy.DoubleBuffered := True; 305 frmGameboy.DoubleBuffered := True;
313 SetPaintBox(PaintBox1); 306 SetPaintBox(PaintBox1);
314 postmessage(handle, wm_user, 0, 0); 307 postmessage(handle, wm_user, 0, 0);
308
309 if ParamCount >= 1 then
310 LoadRom(ParamStr(1));
315 end; 311 end;
316 312
317 procedure TfrmGameboy.Exit1Click(Sender: TObject); 313 procedure TfrmGameboy.Exit1Click(Sender: TObject);
Modifiedmainloop.pas +1−8
@@ -13,28 +13,21 @@ unit mainloop;
13 13
14 interface 14 interface
15 15
16 uses Windows, ExtCtrls; 16 uses ExtCtrls;
17 17
18 function main_loop(a: DWord): DWORD; 18 function main_loop(a: DWord): DWORD;
19 procedure setzewindow(h_wnd: HWND);
20 procedure SetPaintBox(pb: TPaintBox); 19 procedure SetPaintBox(pb: TPaintBox);
21 20
22 function z80_decode: byte; pascal; 21 function z80_decode: byte; pascal;
23 procedure z80_reset; 22 procedure z80_reset;
24 23
25 var 24 var
26 window: Hwnd; // is the DirectDraw window
27 PaintBox: TPaintBox; 25 PaintBox: TPaintBox;
28 26
29 implementation 27 implementation
30 28
31 uses vars, gfx, machine, z80cpu, sound; 29 uses vars, gfx, machine, z80cpu, sound;
32 30
33 procedure setzewindow(h_wnd: HWND);
34 begin
35 window := h_wnd;
36 end;
37
38 procedure SetPaintBox(pb: TPaintBox); 31 procedure SetPaintBox(pb: TPaintBox);
39 begin 32 begin
40 PaintBox := pb; 33 PaintBox := pb;