-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBus.cpp
More file actions
76 lines (60 loc) · 1.48 KB
/
Copy pathBus.cpp
File metadata and controls
76 lines (60 loc) · 1.48 KB
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
#include "Bus.h"
using namespace std;
Bus::Bus()
{
for (auto &e : ram) e = 0x00; /* clear ram */
cpu.connectBus(this); /* connect cpu to bus */
}
Bus::~Bus()
{
}
void Bus::cpuWrite(uint16_t addr, uint8_t data) /* write to bus */
{
if(cart->cpuWrite(addr, data)) /* if cart is writing */
{
/* cartridge read/write has priority */
}else if(addr >= 0x0000 && adr <= 0x1FFF) /* bit range of bus */
{
ramCPU[addr & 0x07FF] = data;
}else if(addr >= 0x2000 && addr <= 0x3FFF)
{ /* ppu bus range */
ppu.cpuWrite(addr & 0x007, data); /* mirroring */
}
}
uint8_t cpuRead(uint16_t addr, bool bReadOnlyFlag = false) /* read bus */
{
uint8_t data = 0x00;
if(cart->cpuWrite(addr, data)) /* if cart is writing */
{
/* cartridge read/write has priority */
}else if(addr >= 0x0000 && adr <= 0x1FFF) /* bit range of bus */
{
data = ramCPU[addr & 0x07FF];
}else if (addr >= 0x2000 && addr <= 0x3FFF)
{ /* ppu range */
data = ppu.cpuRead(addr & 0x0007, bReadOnly);
}
return data;
}
void Bus::insertCartridge(const shared_ptr<Cartridge>& cartridge)
{
/* connect bus to cartridge */
this->cart = cartridge;
/*connect ppu to cartridge */
ppu.ConnectCartridge(cartridge);
}
void Bus::reset()
{
cpu.reset(); /* reset the cpu */
sysClockCount = 0; /* reset clock count */
}
void Bus::clock()
{
ppu.clock(); /* ppu clock is fastest */
/*cpu clock is 1/3 speed of ppu */
if(sysClockCount % 3 == 0)
{
cpu.clock();
}
sysClockCount++;
}