-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBus.cs
101 lines (83 loc) · 2.88 KB
/
Bus.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Collections.Generic;
namespace M6502.IO
{
public class Bus
{
private readonly M6502Core _core;
private readonly List<IDevice> _devices;
public Bus(M6502Core core)
{
_core = core;
_devices = new List<IDevice>();
}
public void AttachDevice(IDevice device)
{
_devices.Add(device);
}
public byte Read(ushort address, bool? forcedRw = null)
{
_core.Pins.ReadWrite = forcedRw ?? true;
_core.Pins.A = address;
_core.Pins.D = 0;
// ForEach method was quite slower than typical for statement
//_devices.ForEach(p => p.Process());
for (var i = 0; i < _devices.Count; i++)
{
_devices[i].Process();
}
_core.YieldCycle();
return _core.Pins.D;
}
public byte ReadDebug(ushort address)
{
var oldReadWriteState = _core.Pins.ReadWrite;
var oldAddressState = _core.Pins.A;
var oldDataState = _core.Pins.D;
_core.Pins.ReadWrite = true;
_core.Pins.A = address;
_core.Pins.D = 0;
// ForEach method was quite slower than typical for statement
//_devices.ForEach(p => p.Process());
for (var i = 0; i < _devices.Count; i++)
{
_devices[i].Process();
}
var result = _core.Pins.D;
_core.Pins.ReadWrite = oldReadWriteState;
_core.Pins.A = oldAddressState;
_core.Pins.D = oldDataState;
return result;
}
public void Write(ushort address, byte value, bool? forcedRw = null)
{
_core.Pins.ReadWrite = forcedRw ?? false;
_core.Pins.A = address;
_core.Pins.D = value;
_core.YieldCycle();
// ForEach method was quite slower than typical for statement
//_devices.ForEach(p => p.Process());
for (var i = 0; i < _devices.Count; i++)
{
_devices[i].Process();
}
}
public void WriteDebug(ushort address, byte value)
{
var oldReadWriteState = _core.Pins.ReadWrite;
var oldAddressState = _core.Pins.A;
var oldDataState = _core.Pins.D;
_core.Pins.ReadWrite = false;
_core.Pins.A = address;
_core.Pins.D = value;
// ForEach method was quite slower than typical for statement
//_devices.ForEach(p => p.Process());
for (var i = 0; i < _devices.Count; i++)
{
_devices[i].Process();
}
_core.Pins.ReadWrite = oldReadWriteState;
_core.Pins.A = oldAddressState;
_core.Pins.D = oldDataState;
}
}
}