Debian Codegraph @

gba/interface/interface.cpp

raw
1 #include <gba/gba.hpp>
2
3 namespace GameBoyAdvance {
4
5 Interface* interface = nullptr;
6
7 string Interface::title() {
8 return cartridge.title();
9 }
10
11 double Interface::videoFrequency() {
12 return 16777216.0 / (228.0 * 1232.0);
13 }
14
15 double Interface::audioFrequency() {
16 return 16777216.0 / 512.0;
17 }
18
19 bool Interface::loaded() {
20 return cartridge.loaded();
21 }
22
23 unsigned Interface::group(unsigned id) {
24 switch(id) {
25 case ID::BIOS:
26 return ID::System;
27 case ID::Manifest:
28 case ID::ROM:
29 case ID::RAM:
30 case ID::EEPROM:
31 case ID::FlashROM:
32 return ID::GameBoyAdvance;
33 }
34
35 throw;
36 }
37
38 void Interface::load(unsigned id) {
39 cartridge.load();
40 }
41
42 void Interface::save() {
43 for(auto& memory : cartridge.memory) {
44 interface->saveRequest(memory.id, memory.name);
45 }
46 }
47
48 void Interface::load(unsigned id, const stream& stream) {
49 if(id == ID::BIOS) {
50 stream.read(bios.data, min(bios.size, stream.size()));
51 }
52
53 if(id == ID::Manifest) cartridge.information.markup = stream.text();
54
55 if(id == ID::ROM) {
56 stream.read(cartridge.rom.data, min(cartridge.rom.size, stream.size()));
57 }
58
59 if(id == ID::RAM) {
60 stream.read(cartridge.ram.data, min(cartridge.ram.size, stream.size()));
61 }
62
63 if(id == ID::EEPROM) {
64 stream.read(cartridge.eeprom.data, min(cartridge.eeprom.size, stream.size()));
65 }
66
67 if(id == ID::FlashROM) {
68 stream.read(cartridge.flashrom.data, min(cartridge.flashrom.size, stream.size()));
69 }
70 }
71
72 void Interface::save(unsigned id, const stream& stream) {
73 if(id == ID::RAM) {
74 stream.write(cartridge.ram.data, cartridge.ram.size);
75 }
76
77 if(id == ID::EEPROM) {
78 stream.write(cartridge.eeprom.data, cartridge.eeprom.size);
79 }
80
81 if(id == ID::FlashROM) {
82 stream.write(cartridge.flashrom.data, cartridge.flashrom.size);
83 }
84 }
85
86 void Interface::unload() {
87 save();
88 cartridge.unload();
89 }
90
91 void Interface::power() {
92 system.power();
93 }
94
95 void Interface::reset() {
96 system.power();
97 }
98
99 void Interface::run() {
100 system.run();
101 }
102
103 serializer Interface::serialize() {
104 system.runtosave();
105 return system.serialize();
106 }
107
108 bool Interface::unserialize(serializer& s) {
109 return system.unserialize(s);
110 }
111
112 void Interface::paletteUpdate(PaletteMode mode) {
113 video.generate_palette(mode);
114 }
115
116 Interface::Interface() {
117 interface = this;
118
119 information.name = "Game Boy Advance";
120 information.width = 240;
121 information.height = 160;
122 information.overscan = false;
123 information.aspectRatio = 1.0;
124 information.resettable = false;
125 information.capability.states = true;
126 information.capability.cheats = false;
127
128 media.append({ID::GameBoyAdvance, "Game Boy Advance", "gba", true});
129
130 {
131 Device device{0, ID::Device, "Controller"};
132 device.input.append({ 0, 0, "A" });
133 device.input.append({ 1, 0, "B" });
134 device.input.append({ 2, 0, "Select"});
135 device.input.append({ 3, 0, "Start" });
136 device.input.append({ 4, 0, "Right" });
137 device.input.append({ 5, 0, "Left" });
138 device.input.append({ 6, 0, "Up" });
139 device.input.append({ 7, 0, "Down" });
140 device.input.append({ 8, 0, "R" });
141 device.input.append({ 9, 0, "L" });
142 device.input.append({10, 2, "Rumble"});
143 device.order = {6, 7, 5, 4, 1, 0, 9, 8, 2, 3, 10};
144 this->device.append(device);
145 }
146
147 port.append({0, "Device", {device[0]}});
148 }
149
150 }