Skip to content

Commit

Permalink
WIP on sound. Got all sounds except channel 3 perfect!
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperDisk committed Mar 28, 2019
1 parent 531b7f6 commit 6b40d82
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 109 deletions.
67 changes: 14 additions & 53 deletions GBEmu.lpi
Expand Up @@ -26,6 +26,7 @@
<RunParams>
<local>
<FormatVersion Value="1"/>
<CommandLineParams Value="C:\Projects\GB-Stuff\sml.gb"/>
</local>
</RunParams>
<RequiredPackages Count="2">
Expand All @@ -36,7 +37,7 @@
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="22">
<Units Count="12">
<Unit0>
<Filename Value="GBEmu.lpr"/>
<IsPartOfProject Value="True"/>
Expand All @@ -53,92 +54,52 @@
<IsPartOfProject Value="True"/>
</Unit2>
<Unit3>
<Filename Value="Directx\directdraw.pas"/>
<Filename Value="Gpu\ddraw_out.pas"/>
<IsPartOfProject Value="True"/>
</Unit3>
<Unit4>
<Filename Value="DirectX\dxcommon.pas"/>
<Filename Value="Gpu\gfx.pas"/>
<IsPartOfProject Value="True"/>
</Unit4>
<Unit5>
<Filename Value="Gpu\ddraw_out.pas"/>
<Filename Value="CPU\machine.pas"/>
<IsPartOfProject Value="True"/>
</Unit5>
<Unit6>
<Filename Value="Gpu\dib_out.pas"/>
<Filename Value="Cpu\z80cpu.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Z80CPU"/>
</Unit6>
<Unit7>
<Filename Value="Gpu\gfx.pas"/>
<Filename Value="Sound\sound.pas"/>
<IsPartOfProject Value="True"/>
</Unit7>
<Unit8>
<Filename Value="CPU\machine.pas"/>
<Filename Value="Global\vars.pas"/>
<IsPartOfProject Value="True"/>
</Unit8>
<Unit9>
<Filename Value="Cpu\z80cpu.pas"/>
<Filename Value="mainloop.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Z80CPU"/>
</Unit9>
<Unit10>
<Filename Value="Sound\sound.pas"/>
<IsPartOfProject Value="True"/>
</Unit10>
<Unit11>
<Filename Value="Global\vars.pas"/>
<IsPartOfProject Value="True"/>
</Unit11>
<Unit12>
<Filename Value="mainloop.pas"/>
<IsPartOfProject Value="True"/>
</Unit12>
<Unit13>
<Filename Value="Debugger\UnitDebug.pas"/>
<IsPartOfProject Value="True"/>
<HasResources Value="True"/>
</Unit13>
<Unit14>
<Filename Value="DirectX\Direct3DRM.pas"/>
<IsPartOfProject Value="True"/>
</Unit14>
<Unit15>
<Filename Value="DirectX\DirectInput.pas"/>
<IsPartOfProject Value="True"/>
</Unit15>
<Unit16>
<Filename Value="DirectX\DirectMusic.pas"/>
<IsPartOfProject Value="True"/>
</Unit16>
<Unit17>
<Filename Value="DirectX\DirectPlay.pas"/>
<IsPartOfProject Value="True"/>
</Unit17>
<Unit18>
<Filename Value="DirectX\DirectSetup.pas"/>
<IsPartOfProject Value="True"/>
</Unit18>
<Unit19>
<Filename Value="DirectX\DirectSound.pas"/>
<IsPartOfProject Value="True"/>
</Unit19>
<Unit20>
<Filename Value="DirectX\Direct3D.pas"/>
<IsPartOfProject Value="True"/>
</Unit20>
<Unit21>
</Unit10>
<Unit11>
<Filename Value="Debugger\UnitMapview.pas"/>
<IsPartOfProject Value="True"/>
<HasResources Value="True"/>
</Unit21>
</Unit11>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="Debugger;Directx;GPU;CPU;Sound;Global;Components;$(ProjOutDir)"/>
<OtherUnitFiles Value="Debugger;Directx;GPU;CPU;Sound;Global"/>
<OtherUnitFiles Value="Debugger;GPU;CPU;Sound;Global"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down
10 changes: 0 additions & 10 deletions GBEmu.lpr
Expand Up @@ -7,24 +7,14 @@
Interfaces,
UnitMain in 'UnitMain.pas' {frmGameboy},
debugger in 'Debugger\debugger.pas',
directdraw in 'Directx\directdraw.pas',
dxcommon in 'DirectX\dxcommon.pas',
ddraw_out in 'GPU\ddraw_out.pas',
dib_out in 'GPU\dib_out.pas',
gfx in 'GPU\gfx.pas',
machine in 'CPU\machine.pas',
Z80CPU in 'CPU\z80cpu.pas',
sound in 'Sound\sound.pas',
vars in 'Global\vars.pas',
mainloop in 'mainloop.pas',
UnitDebug in 'Debugger\UnitDebug.pas' {frmDebug},
Direct3DRM in 'DirectX\Direct3DRM.pas',
DirectInput in 'DirectX\DirectInput.pas',
DirectMusic in 'DirectX\DirectMusic.pas',
DirectPlay in 'DirectX\DirectPlay.pas',
DirectSetup in 'DirectX\DirectSetup.pas',
DirectSound in 'DirectX\DirectSound.pas',
Direct3D in 'DirectX\Direct3D.pas',
UnitMapview in 'Debugger\UnitMapview.pas' {frmMapview};

{.$R *.RES}
Expand Down
2 changes: 0 additions & 2 deletions Global/vars.pas
Expand Up @@ -7,8 +7,6 @@

interface

uses Windows, DirectDraw;

const
thr_f: integer = 1;
cart: pointer = nil; // Cartdridge
Expand Down
5 changes: 2 additions & 3 deletions Sound/sound.pas
Expand Up @@ -253,7 +253,7 @@ procedure SoundUpdate(cycles: integer);
snd[1].Freq := m_iram[$FF13] or ((m_iram[$FF14] and 7) shl 8);
snd[2].Freq := m_iram[$FF18] or ((m_iram[$FF19] and 7) shl 8);
snd[3].Freq := m_iram[$FF1d] or ((m_iram[$FF1e] and 7) shl 8);
case m_iram[$FF22] and 7 of //NICK (7 -> 15)... wrong number of bits!
case m_iram[$FF22] and 7 of
0: snd[4].Freq := (512 * 1024 * 2) shr ((m_iram[$FF22] shr 4) + 1);
1: snd[4].Freq := (512 * 1024) shr ((m_iram[$FF22] shr 4) + 1);
2: snd[4].Freq := ((512 * 1024) div 2) shr ((m_iram[$FF22] shr 4) + 1);
Expand Down Expand Up @@ -561,8 +561,7 @@ procedure SoundUpdate(cycles: integer);

l := shortint(l shr 2) + 128;
r := shortint(r shr 2) + 128;
if (l <> 170) and (r <> 170) then
SoundOutBits(l, r, cycles);
SoundOutBits(l, r, cycles)
end;

procedure SoundSetCycles(n: integer);
Expand Down
13 changes: 6 additions & 7 deletions UnitMain.lfm
@@ -1,14 +1,13 @@
object frmGameboy: TfrmGameboy
Left = 1262
Left = 572
Height = 354
Top = 525
Top = 127
Width = 318
Caption = 'Gameboy'
ClientHeight = 320
ClientHeight = 334
ClientWidth = 318
Color = clYellow
DefaultMonitor = dmMainForm
DesignTimePPI = 168
Font.CharSet = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -12
Expand All @@ -25,8 +24,8 @@ object frmGameboy: TfrmGameboy
LCLVersion = '1.8.4.0'
object StatusBar: TStatusBar
Left = 0
Height = 43
Top = 277
Height = 23
Top = 311
Width = 318
Panels = <
item
Expand All @@ -46,7 +45,7 @@ object frmGameboy: TfrmGameboy
end
object PaintBox1: TPaintBox
Left = 0
Height = 277
Height = 311
Top = 0
Width = 318
Align = alClient
Expand Down
48 changes: 22 additions & 26 deletions UnitMain.pas
Expand Up @@ -133,6 +133,7 @@ TfrmGameboy = class(TForm)
FDiff: integer; // Caption Height
procedure Emulation(var msg: TMessage); message wm_user;
procedure SetWindow;
procedure LoadRom(Rom: String);

procedure ShowCaption;
procedure RemoveCaption;
Expand Down Expand Up @@ -169,8 +170,6 @@ procedure TfrmGameboy.ShowCaption;
end;

procedure TfrmGameboy.FormCreate(Sender: TObject);
var
li: Large_Integer;
begin
loadstat.Enabled := False;
savestat.Enabled := False;
Expand All @@ -188,10 +187,7 @@ procedure TfrmGameboy.FormCreate(Sender: TObject);
if assigned(cart) then
freemem(cart, cartsize);
z80_reset;
// initialize PerfFreq

QueryPerformanceFrequency(li.quadpart);
perfFreq := li.LowPart div 32;// shr 5;
SetAudioChannel(Self);
enablesound;
end;
Expand Down Expand Up @@ -243,19 +239,32 @@ procedure TfrmGameboy.Emulation(var Msg: TMessage);

cycles -= CyclesPerFrame;

while True do begin
repeat
QueryPerformanceCounter(@li);
frameEnd := li.QuadPart;

frameElapsedInSec := (frameEnd - frameStart) / tickFreq;
if frameElapsedInSec > TimePerFrame then
Break;
end;
until frameElapsedInSec > TimePerFrame;

frameStart := frameEnd;
until application.Terminated;
end;

procedure TfrmGameboy.LoadRom(Rom: String);
begin
f_stopped := True;
load(Rom);
statusbar.Panels[2].Text := getcompany;
statusbar.Panels[1].Text := speicher;
statusbar.panels[0].Text := romname;
z80_reset;
z80_reset;
f_stopped := False;
gb_speed := 1;
loadstat.Enabled := True;
savestat.Enabled := True;
end;

procedure TfrmGameboy.FileOpenClick(Sender: TObject);
var
i: integer;
Expand All @@ -267,22 +276,7 @@ procedure TfrmGameboy.FileOpenClick(Sender: TObject);
opendialog.Filter :=
'All Roms [*.gb;*.gbc;*.rom]|*.gb;*.gbc;*.rom|Gameboy [*.gb]|*.gb|Gameboy Color [*.gbc]|*.gbc|All Files [*.*]|*.*';

if opendialog.Execute then
begin
f_stopped := True;
load(opendialog.filename);
i := 0;
statusbar.Panels[2].Text := getcompany;
statusbar.Panels[1].Text := speicher;
statusbar.panels[0].Text := romname;
z80_reset;
z80_reset;
f_stopped := False;
gb_speed := 1;
setzewindow(handle);
loadstat.Enabled := True;
savestat.Enabled := True;
end;
if opendialog.Execute then LoadRom(opendialog.filename);
end;

procedure TfrmGameboy.KillClick(Sender: TObject);
Expand All @@ -307,11 +301,13 @@ procedure TfrmGameboy.FormActivate(Sender: TObject);
z80_reset;
f_stopped := True;
gb_speed := 1;
setzewindow(handle);

frmGameboy.DoubleBuffered := True;
SetPaintBox(PaintBox1);
postmessage(handle, wm_user, 0, 0);

if ParamCount >= 1 then
LoadRom(ParamStr(1));
end;

procedure TfrmGameboy.Exit1Click(Sender: TObject);
Expand Down
9 changes: 1 addition & 8 deletions mainloop.pas
Expand Up @@ -13,28 +13,21 @@

interface

uses Windows, ExtCtrls;
uses ExtCtrls;

function main_loop(a: DWord): DWORD;
procedure setzewindow(h_wnd: HWND);
procedure SetPaintBox(pb: TPaintBox);

function z80_decode: byte; pascal;
procedure z80_reset;

var
window: Hwnd; // is the DirectDraw window
PaintBox: TPaintBox;

implementation

uses vars, gfx, machine, z80cpu, sound;

procedure setzewindow(h_wnd: HWND);
begin
window := h_wnd;
end;

procedure SetPaintBox(pb: TPaintBox);
begin
PaintBox := pb;
Expand Down

0 comments on commit 6b40d82

Please sign in to comment.