src/gba.c (view raw)
1#include "gba.h"
2
3#include <sys/mman.h>
4
5void GBAInit(struct GBA* gba) {
6 ARMInit(&gba->cpu);
7 GBAMemoryInit(&gba->memory);
8}
9
10void GBADeinit(struct GBA* gba) {
11 GBAMemoryDeinit(&gba->memory);
12}
13
14void GBAMemoryInit(struct GBAMemory* memory) {
15 memory->d.load32 = GBALoad32;
16 memory->d.load16 = GBALoad16;
17 memory->d.loadU16 = GBALoadU16;
18 memory->d.load8 = GBALoad8;
19 memory->d.loadU8 = GBALoadU8;
20
21 memory->bios = 0;
22 memory->wram = mmap(0, SIZE_WORKING_RAM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
23 memory->iwram = mmap(0, SIZE_WORKING_IRAM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
24 memory->rom = 0;
25}
26
27void GBAMemoryDeinit(struct GBAMemory* memory) {
28 munmap(memory->wram, SIZE_WORKING_RAM);
29 munmap(memory->iwram, SIZE_WORKING_IRAM);
30}
31
32int32_t GBALoad32(struct ARMMemory* memory, uint32_t address) {
33 struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
34
35 switch (address & OFFSET_MASK) {
36 case REGION_BIOS:
37 break;
38 case REGION_WORKING_RAM:
39 break;
40 case REGION_WORKING_IRAM:
41 break;
42 case REGION_IO:
43 break;
44 case REGION_PALETTE_RAM:
45 break;
46 case REGION_VRAM:
47 break;
48 case REGION_OAM:
49 break;
50 case REGION_CART0:
51 case REGION_CART0_EX:
52 case REGION_CART1:
53 case REGION_CART1_EX:
54 case REGION_CART2:
55 case REGION_CART2_EX:
56 break;
57 case REGION_CART_SRAM:
58 break;
59 default:
60 break;
61 }
62
63 return 0;
64}
65
66int16_t GBALoad16(struct ARMMemory* memory, uint32_t address) {
67 struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
68
69 switch (address & OFFSET_MASK) {
70 case REGION_BIOS:
71 break;
72 case REGION_WORKING_RAM:
73 break;
74 case REGION_WORKING_IRAM:
75 break;
76 case REGION_IO:
77 break;
78 case REGION_PALETTE_RAM:
79 break;
80 case REGION_VRAM:
81 break;
82 case REGION_OAM:
83 break;
84 case REGION_CART0:
85 case REGION_CART0_EX:
86 case REGION_CART1:
87 case REGION_CART1_EX:
88 case REGION_CART2:
89 case REGION_CART2_EX:
90 break;
91 case REGION_CART_SRAM:
92 break;
93 default:
94 break;
95 }
96
97 return 0;
98}
99
100uint16_t GBALoadU16(struct ARMMemory* memory, uint32_t address) {
101 struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
102
103 switch (address & OFFSET_MASK) {
104 case REGION_BIOS:
105 break;
106 case REGION_WORKING_RAM:
107 break;
108 case REGION_WORKING_IRAM:
109 break;
110 case REGION_IO:
111 break;
112 case REGION_PALETTE_RAM:
113 break;
114 case REGION_VRAM:
115 break;
116 case REGION_OAM:
117 break;
118 case REGION_CART0:
119 case REGION_CART0_EX:
120 case REGION_CART1:
121 case REGION_CART1_EX:
122 case REGION_CART2:
123 case REGION_CART2_EX:
124 break;
125 case REGION_CART_SRAM:
126 break;
127 default:
128 break;
129 }
130
131 return 0;
132}
133
134int8_t GBALoad8(struct ARMMemory* memory, uint32_t address) {
135 struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
136
137 switch (address & OFFSET_MASK) {
138 case REGION_BIOS:
139 break;
140 case REGION_WORKING_RAM:
141 break;
142 case REGION_WORKING_IRAM:
143 break;
144 case REGION_IO:
145 break;
146 case REGION_PALETTE_RAM:
147 break;
148 case REGION_VRAM:
149 break;
150 case REGION_OAM:
151 break;
152 case REGION_CART0:
153 case REGION_CART0_EX:
154 case REGION_CART1:
155 case REGION_CART1_EX:
156 case REGION_CART2:
157 case REGION_CART2_EX:
158 break;
159 case REGION_CART_SRAM:
160 break;
161 default:
162 break;
163 }
164
165 return 0;
166}
167
168uint8_t GBALoadU8(struct ARMMemory* memory, uint32_t address) {
169 struct GBAMemory* gbaMemory = (struct GBAMemory*) memory;
170
171 switch (address & OFFSET_MASK) {
172 case REGION_BIOS:
173 break;
174 case REGION_WORKING_RAM:
175 break;
176 case REGION_WORKING_IRAM:
177 break;
178 case REGION_IO:
179 break;
180 case REGION_PALETTE_RAM:
181 break;
182 case REGION_VRAM:
183 break;
184 case REGION_OAM:
185 break;
186 case REGION_CART0:
187 case REGION_CART0_EX:
188 case REGION_CART1:
189 case REGION_CART1_EX:
190 case REGION_CART2:
191 case REGION_CART2_EX:
192 break;
193 case REGION_CART_SRAM:
194 break;
195 default:
196 break;
197 }
198
199 return 0;
200}