-
Notifications
You must be signed in to change notification settings - Fork 0
/
Emulator.cs
79 lines (69 loc) · 1.92 KB
/
Emulator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Drawing;
namespace ZarthGB
{
class Emulator
{
private Cartridge cartridge = new Cartridge();
private Memory memory = new Memory();
private Cpu cpu;
private Video video;
#region Buttons
public bool KeyUp
{
set { memory.KeyUp = value; cpu.KeyPressed(); }
}
public bool KeyDown
{
set { memory.KeyDown = value; cpu.KeyPressed(); }
}
public bool KeyLeft
{
set { memory.KeyLeft = value; cpu.KeyPressed(); }
}
public bool KeyRight
{
set { memory.KeyRight = value; cpu.KeyPressed(); }
}
public bool KeyA
{
set { memory.KeyA = value; cpu.KeyPressed(); }
}
public bool KeyB
{
set { memory.KeyB = value; cpu.KeyPressed(); }
}
public bool KeyStart
{
set { memory.KeyStart = value; cpu.KeyPressed(); }
}
public bool KeySelect
{
set { memory.KeySelect = value; cpu.KeyPressed(); }
}
#endregion
public Color[] Framebuffer { get; } = new Color[160 * 144];
public bool IsFrameReady => video.IsFrameReady;
public Emulator()
{
cartridge = new Cartridge();
memory = new Memory();
cpu = new Cpu(memory);
video = new Video(memory, Framebuffer);
}
public void LoadCartridge(string filename)
{
cartridge.Load(filename);
memory.SetCartridge(cartridge.Rom, cartridge.CartType);
}
public void RunStep()
{
cpu.Step();
video.Step();
}
public void Reset()
{
cpu.Reset();
memory.Reset();
}
}
}