Skip to content

Commit

Permalink
#32: theaded Skeleton loop for game cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
saku-kaarakainen committed Aug 30, 2016
1 parent 83e8bdd commit 1a944f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
15 changes: 4 additions & 11 deletions WinBoyEmulator/GameBoy/CPU/LR35902.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class LR35902 : Flags, IRegisters
private static readonly object _syncRoot = new object();
private static volatile LR35902 _instance;

private bool _isCpuRunning = false;

// store registers values to these bytes.
private byte _a, _b, _c, _d, _e, _f, _h, _l;
private ushort _sp, _pc;
Expand Down Expand Up @@ -233,18 +235,9 @@ public static LR35902 Instance
}
}

public void Start()
public void EmulateCycle()
{
var cpuIsRunning = true;
/*while(cpuIsRunning)
{
// Issue #32
//
// Fetch instruction
// Dispatch
// Mask PC to 16 bits
// Add time to CPU clock
}*/

}

public void Reset()
Expand Down
24 changes: 23 additions & 1 deletion WinBoyEmulator/GameBoy/Emulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using WinBoyEmulator.GameBoy.CPU;
Expand All @@ -33,6 +34,7 @@ public class Emulator : IEmulator
private static volatile Emulator _instance;

private byte[] _game;
private bool _isGameBoyOn = false;

public static Emulator Instance
{
Expand Down Expand Up @@ -64,6 +66,19 @@ private void _readGameFile(string filename)
{
var length = (int)reader.BaseStream.Length;
_game = reader.ReadBytes(length);
// Issue #29
}
}

private void _gameCycle()
{
while(_isGameBoyOn)
{
// Emulate one cycle
LR35902.Instance.EmulateCycle();

// If the draw flag is set, update the screen
// Store key press state (Press and Release)
}
}

Expand All @@ -79,7 +94,14 @@ public void StartEmulation(string gamePath)
// Load game.
_readGameFile(gamePath);
MMU.Instance.Load(_game);
LR35902.Instance.Start();

var thread = new Thread(_gameCycle)
{
IsBackground = true,
Name = "WinBoyEmulator",
};
thread.Start();

}
}
}

0 comments on commit 1a944f0

Please sign in to comment.