Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/chip/obc1/obc1.cpp
2 views
1
#include <snes/snes.hpp>
2
3
#define OBC1_CPP
4
namespace SNES {
5
6
#include "serialization.cpp"
7
OBC1 obc1;
8
9
void OBC1::init() {
10
}
11
12
void OBC1::load() {
13
}
14
15
void OBC1::unload() {
16
}
17
18
void OBC1::power() {
19
}
20
21
void OBC1::reset() {
22
status.baseptr = (ram_read(0x1ff5) & 1) ? 0x1800 : 0x1c00;
23
status.address = (ram_read(0x1ff6) & 0x7f);
24
status.shift = (ram_read(0x1ff6) & 3) << 1;
25
}
26
27
uint8 OBC1::read(unsigned addr) {
28
addr &= 0x1fff;
29
30
switch(addr) {
31
case 0x1ff0: return ram_read(status.baseptr + (status.address << 2) + 0);
32
case 0x1ff1: return ram_read(status.baseptr + (status.address << 2) + 1);
33
case 0x1ff2: return ram_read(status.baseptr + (status.address << 2) + 2);
34
case 0x1ff3: return ram_read(status.baseptr + (status.address << 2) + 3);
35
case 0x1ff4: return ram_read(status.baseptr + (status.address >> 2) + 0x200);
36
}
37
38
return ram_read(addr);
39
}
40
41
void OBC1::write(unsigned addr, uint8 data) {
42
addr &= 0x1fff;
43
44
switch(addr) {
45
case 0x1ff0: ram_write(status.baseptr + (status.address << 2) + 0, data); return;
46
case 0x1ff1: ram_write(status.baseptr + (status.address << 2) + 1, data); return;
47
case 0x1ff2: ram_write(status.baseptr + (status.address << 2) + 2, data); return;
48
case 0x1ff3: ram_write(status.baseptr + (status.address << 2) + 3, data); return;
49
case 0x1ff4: {
50
uint8 temp = ram_read(status.baseptr + (status.address >> 2) + 0x200);
51
temp = (temp & ~(3 << status.shift)) | ((data & 3) << status.shift);
52
ram_write(status.baseptr + (status.address >> 2) + 0x200, temp);
53
} return;
54
case 0x1ff5:
55
status.baseptr = (data & 1) ? 0x1800 : 0x1c00;
56
ram_write(addr, data);
57
return;
58
case 0x1ff6:
59
status.address = (data & 0x7f);
60
status.shift = (data & 3) << 1;
61
ram_write(addr, data);
62
return;
63
case 0x1ff7:
64
ram_write(addr, data);
65
return;
66
}
67
68
return ram_write(addr, data);
69
}
70
71
uint8 OBC1::ram_read(unsigned addr) {
72
return cartridge.ram.read(addr & 0x1fff);
73
}
74
75
void OBC1::ram_write(unsigned addr, uint8 data) {
76
cartridge.ram.write(addr & 0x1fff, data);
77
}
78
79
}
80
81