Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/cartridge/cartridge.cpp
2 views
1
#include <snes/snes.hpp>
2
3
#include <nall/crc32.hpp>
4
#include <nall/sha256.hpp>
5
6
#define CARTRIDGE_CPP
7
namespace SNES {
8
9
#include "markup.cpp"
10
#include "serialization.cpp"
11
12
Cartridge cartridge;
13
14
void Cartridge::load(Mode cartridge_mode, const char *markup) {
15
mode = cartridge_mode;
16
region = Region::NTSC;
17
ram_size = 0;
18
19
has_bsx_slot = false;
20
has_nss_dip = false;
21
has_superfx = false;
22
has_sa1 = false;
23
has_necdsp = false;
24
has_hitachidsp = false;
25
has_armdsp = false;
26
has_srtc = false;
27
has_sdd1 = false;
28
has_spc7110 = false;
29
has_spc7110rtc = false;
30
has_obc1 = false;
31
has_msu1 = false;
32
has_link = false;
33
34
nvram.reset();
35
36
parse_markup(markup);
37
//print(markup, "\n\n");
38
39
if(ram_size > 0) {
40
uint8* buf = (uint8*)interface()->allocSharedMemory("CARTRIDGE_RAM",ram_size,0xff);
41
ram.map(buf, ram_size);
42
nvram.append({ "program.ram", ram.data(), ram.size() });
43
}
44
45
rom.write_protect(true);
46
ram.write_protect(false);
47
48
crc32 = crc32_calculate(rom.data(), rom.size());
49
50
switch((Mode)mode) {
51
case Mode::Normal:
52
case Mode::BsxSlotted:
53
sha256 = nall::sha256(rom.data(), rom.size());
54
break;
55
case Mode::Bsx:
56
sha256 = nall::sha256(bsxflash.memory.data(), bsxflash.memory.size());
57
break;
58
case Mode::SufamiTurbo:
59
sha256 = nall::sha256(sufamiturbo.slotA.rom.data(), sufamiturbo.slotA.rom.size());
60
break;
61
case Mode::SuperGameBoy:
62
#if defined(GAMEBOY)
63
sha256 = GameBoy::cartridge.sha256();
64
#else
65
throw "Game Boy support not present";
66
#endif
67
break;
68
}
69
70
system.load();
71
loaded = true;
72
}
73
74
void Cartridge::unload() {
75
if(loaded == false) return;
76
77
system.unload();
78
rom.reset();
79
ram.reset();
80
81
loaded = false;
82
}
83
84
Cartridge::Cartridge()
85
: rom("CARTRIDGE_ROM")
86
, ram("CARTRIDGE_RAM")
87
{
88
loaded = false;
89
unload();
90
}
91
92
Cartridge::~Cartridge() {
93
unload();
94
}
95
96
}
97
98