Line |
Branch |
Exec |
Source |
1 |
|
|
#pragma once |
2 |
|
|
#include <vector> |
3 |
|
|
|
4 |
|
|
#include "errors.h" |
5 |
|
|
#include "autoarray.h" |
6 |
|
|
#include <cstdint> |
7 |
|
|
|
8 |
|
|
extern const unsigned char * romdata; |
9 |
|
|
extern int romlen; |
10 |
|
|
extern asar_error_id openromerror; |
11 |
|
|
bool openrom(const char * filename, bool confirm=true); |
12 |
|
|
uint32_t closerom(bool save = true); |
13 |
|
|
|
14 |
|
|
enum mapper_t { |
15 |
|
|
invalid_mapper, |
16 |
|
|
lorom, |
17 |
|
|
hirom, |
18 |
|
|
sa1rom, |
19 |
|
|
bigsa1rom, |
20 |
|
|
sfxrom, |
21 |
|
|
exlorom, |
22 |
|
|
exhirom, |
23 |
|
|
norom |
24 |
|
|
} extern mapper; |
25 |
|
|
|
26 |
|
|
extern int sa1banks[8];//only 0, 1, 4, 5 are used |
27 |
|
|
|
28 |
|
|
void addromwrite(int pcoffset, int numbytes); |
29 |
|
|
void writeromdata(int pcoffset, const void * indata, int numbytes); |
30 |
|
|
void writeromdata_byte(int pcoffset, unsigned char indata); |
31 |
|
|
void writeromdata_bytes(int pcoffset, unsigned char indata, int numbytes); |
32 |
|
|
|
33 |
|
|
struct writtenblockdata { |
34 |
|
|
int pcoffset; |
35 |
|
|
int snesoffset; |
36 |
|
|
int numbytes; |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
extern autoarray<writtenblockdata> writtenblocks; |
40 |
|
|
extern std::vector<writtenblockdata> found_rats_tags; |
41 |
|
|
extern bool found_rats_tags_initialized; |
42 |
|
|
|
43 |
|
321140 |
inline int snestopc(int addr) |
44 |
|
|
{ |
45 |
2/2
✓ Branch 0 taken 320656 times.
✓ Branch 1 taken 484 times.
|
321140 |
if (addr<0 || addr>0xFFFFFF) return -1;//not 24bit |
46 |
2/2
✓ Branch 0 taken 314120 times.
✓ Branch 1 taken 6536 times.
|
320656 |
if (mapper==lorom) |
47 |
|
|
{ |
48 |
|
|
// randomdude999: The low pages ($0000-$7FFF) of banks 70-7D are used |
49 |
|
|
// for SRAM, the high pages are available for ROM data though |
50 |
1/2
✓ Branch 0 taken 314120 times.
✗ Branch 1 not taken.
|
314120 |
if ((addr&0xFE0000)==0x7E0000 ||//wram |
51 |
2/2
✓ Branch 0 taken 314110 times.
✓ Branch 1 taken 10 times.
|
314120 |
(addr&0x408000)==0x000000 ||//hardware regs, ram mirrors, other strange junk |
52 |
1/2
✓ Branch 0 taken 314110 times.
✗ Branch 1 not taken.
|
314110 |
(addr&0x708000)==0x700000)//sram (low parts of banks 70-7D) |
53 |
|
|
return -1; |
54 |
|
314110 |
addr=((addr&0x7F0000)>>1|(addr&0x7FFF)); |
55 |
|
314110 |
return addr; |
56 |
|
|
} |
57 |
|
|
if (mapper==hirom) |
58 |
|
|
{ |
59 |
1/2
✓ Branch 0 taken 1838 times.
✗ Branch 1 not taken.
|
1838 |
if ((addr&0xFE0000)==0x7E0000 ||//wram |
60 |
1/2
✓ Branch 0 taken 1838 times.
✗ Branch 1 not taken.
|
1838 |
(addr&0x408000)==0x000000)//hardware regs, ram mirrors, other strange junk |
61 |
|
|
return -1; |
62 |
|
1838 |
return addr&0x3FFFFF; |
63 |
|
|
} |
64 |
|
|
if (mapper==exlorom) |
65 |
|
|
{ |
66 |
1/2
✓ Branch 0 taken 1634 times.
✗ Branch 1 not taken.
|
1634 |
if ((addr&0xF00000)==0x700000 ||//wram, sram |
67 |
1/2
✓ Branch 0 taken 1634 times.
✗ Branch 1 not taken.
|
1634 |
(addr&0x408000)==0x000000)//area that shouldn't be used in lorom |
68 |
|
|
return -1; |
69 |
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 1340 times.
|
1634 |
if (addr&0x800000) |
70 |
|
|
{ |
71 |
|
294 |
addr=((addr&0x7F0000)>>1|(addr&0x7FFF)); |
72 |
|
|
} |
73 |
|
|
else |
74 |
|
|
{ |
75 |
|
1340 |
addr=((addr&0x7F0000)>>1|(addr&0x7FFF))+0x400000; |
76 |
|
|
} |
77 |
|
1634 |
return addr; |
78 |
|
|
} |
79 |
|
|
if (mapper==exhirom) |
80 |
|
|
{ |
81 |
1/2
✓ Branch 0 taken 1686 times.
✗ Branch 1 not taken.
|
1686 |
if ((addr&0xFE0000)==0x7E0000 ||//wram |
82 |
1/2
✓ Branch 0 taken 1686 times.
✗ Branch 1 not taken.
|
1686 |
(addr&0x408000)==0x000000)//hardware regs, ram mirrors, other strange junk |
83 |
|
|
return -1; |
84 |
2/2
✓ Branch 0 taken 1342 times.
✓ Branch 1 taken 344 times.
|
1686 |
if ((addr&0x800000)==0x000000) return (addr&0x3FFFFF)|0x400000; |
85 |
|
344 |
return addr&0x3FFFFF; |
86 |
|
|
} |
87 |
|
|
if (mapper==sfxrom) |
88 |
|
|
{ |
89 |
|
|
// Asar emulates GSU1, because apparently emulators don't support the extra ROM data from GSU2 |
90 |
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
|
94 |
if ((addr&0x600000)==0x600000 ||//wram, sram, open bus |
91 |
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
|
94 |
(addr&0x408000)==0x000000 ||//hardware regs, ram mirrors, rom mirrors, other strange junk |
92 |
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
|
94 |
(addr&0x800000)==0x800000)//fastrom isn't valid either in superfx |
93 |
|
|
return -1; |
94 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
|
94 |
if (addr&0x400000) return addr&0x3FFFFF; |
95 |
|
94 |
else return (addr&0x7F0000)>>1|(addr&0x7FFF); |
96 |
|
|
} |
97 |
|
|
if (mapper==sa1rom) |
98 |
|
|
{ |
99 |
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
|
204 |
if ((addr&0x408000)==0x008000) |
100 |
|
|
{ |
101 |
|
204 |
return sa1banks[(addr&0xE00000)>>21]|((addr&0x1F0000)>>1)|(addr&0x007FFF); |
102 |
|
|
} |
103 |
|
✗ |
if ((addr&0xC00000)==0xC00000) |
104 |
|
|
{ |
105 |
|
✗ |
return sa1banks[((addr&0x100000)>>20)|((addr&0x200000)>>19)]|(addr&0x0FFFFF); |
106 |
|
|
} |
107 |
|
|
return -1; |
108 |
|
|
} |
109 |
|
|
if (mapper==bigsa1rom) |
110 |
|
|
{ |
111 |
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 212 times.
|
404 |
if ((addr&0xC00000)==0xC00000)//hirom |
112 |
|
|
{ |
113 |
|
192 |
return (addr&0x3FFFFF)|0x400000; |
114 |
|
|
} |
115 |
3/4
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
|
212 |
if ((addr&0xC00000)==0x000000 || (addr&0xC00000)==0x800000)//lorom |
116 |
|
|
{ |
117 |
1/2
✓ Branch 0 taken 212 times.
✗ Branch 1 not taken.
|
212 |
if ((addr&0x008000)==0x000000) return -1; |
118 |
|
212 |
return (addr&0x800000)>>2 | (addr&0x3F0000)>>1 | (addr&0x7FFF); |
119 |
|
|
} |
120 |
|
|
return -1; |
121 |
|
|
} |
122 |
|
|
if (mapper==norom) |
123 |
|
|
{ |
124 |
|
676 |
return addr; |
125 |
|
|
} |
126 |
|
|
return -1; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
160942 |
inline int pctosnes(int addr) |
130 |
|
|
{ |
131 |
1/2
✓ Branch 0 taken 160942 times.
✗ Branch 1 not taken.
|
160942 |
if (addr<0) return -1; |
132 |
2/2
✓ Branch 0 taken 159578 times.
✓ Branch 1 taken 1364 times.
|
160942 |
if (mapper==lorom) |
133 |
|
|
{ |
134 |
1/2
✓ Branch 0 taken 159578 times.
✗ Branch 1 not taken.
|
159578 |
if (addr>=0x400000) return -1; |
135 |
|
159578 |
addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000; |
136 |
|
159578 |
return addr|0x800000; |
137 |
|
|
} |
138 |
|
|
if (mapper==hirom) |
139 |
|
|
{ |
140 |
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
|
312 |
if (addr>=0x400000) return -1; |
141 |
|
312 |
return addr|0xC00000; |
142 |
|
|
} |
143 |
|
|
if (mapper == exlorom) |
144 |
|
|
{ |
145 |
1/2
✓ Branch 0 taken 156 times.
✗ Branch 1 not taken.
|
156 |
if (addr>=0x800000) return -1; |
146 |
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 150 times.
|
156 |
if (addr&0x400000) |
147 |
|
|
{ |
148 |
|
6 |
addr-=0x400000; |
149 |
|
6 |
addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000; |
150 |
|
6 |
return addr; |
151 |
|
|
} |
152 |
|
|
else |
153 |
|
|
{ |
154 |
|
150 |
addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000; |
155 |
|
150 |
return addr|0x800000; |
156 |
|
|
} |
157 |
|
|
} |
158 |
|
|
if (mapper == exhirom) |
159 |
|
|
{ |
160 |
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
|
180 |
if (addr>=0x800000) return -1; |
161 |
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 6 times.
|
180 |
if (addr&0x400000) return addr; |
162 |
|
174 |
return addr|0xC00000; |
163 |
|
|
} |
164 |
|
|
if (mapper==sa1rom) |
165 |
|
|
{ |
166 |
1/2
✓ Branch 0 taken 276 times.
✗ Branch 1 not taken.
|
276 |
for (int i=0;i<8;i++) |
167 |
|
|
{ |
168 |
2/2
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 160 times.
|
276 |
if (sa1banks[i]==(addr&0x700000)){ return 0x008000|(i<<21)|((addr&0x0F8000)<<1)|(addr&0x7FFF);} |
169 |
|
|
} |
170 |
|
|
return -1; |
171 |
|
|
} |
172 |
|
|
if (mapper==bigsa1rom) |
173 |
|
|
{ |
174 |
1/2
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
|
202 |
if (addr>=0x800000) return -1; |
175 |
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 106 times.
|
202 |
if ((addr&0x400000)==0x400000) |
176 |
|
|
{ |
177 |
|
96 |
return addr|0xC00000; |
178 |
|
|
} |
179 |
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 48 times.
|
106 |
if ((addr&0x600000)==0x000000) |
180 |
|
|
{ |
181 |
|
58 |
return ((addr<<1)&0x3F0000)|0x8000|(addr&0x7FFF); |
182 |
|
|
} |
183 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
if ((addr&0x600000)==0x200000) |
184 |
|
|
{ |
185 |
|
48 |
return 0x800000|((addr<<1)&0x3F0000)|0x8000|(addr&0x7FFF); |
186 |
|
|
} |
187 |
|
|
return -1; |
188 |
|
|
} |
189 |
|
|
if (mapper==sfxrom) |
190 |
|
|
{ |
191 |
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 4 times.
|
58 |
if (addr>=0x200000) return -1; |
192 |
|
54 |
return ((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000; |
193 |
|
|
} |
194 |
|
|
if (mapper==norom) |
195 |
|
|
{ |
196 |
|
340 |
return addr; |
197 |
|
|
} |
198 |
|
|
return -1; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
int getpcfreespace(int size, int target_bank, bool autoexpand=true, bool respectbankborders=true, bool align=false, unsigned char freespacebyte=0x00, bool write_rats=true, int search_start=-1); |
202 |
|
|
int getsnesfreespace(int size, int target_bank, bool autoexpand=true, bool respectbankborders=true, bool align=false, unsigned char freespacebyte=0x00, bool write_rats=true, int search_start=-1); |
203 |
|
|
|
204 |
|
|
void removerats(int snesaddr, unsigned char clean_byte); |
205 |
|
|
void handle_cleared_rats_tags(); |
206 |
|
|
int ratsstart(int pcaddr); |
207 |
|
|
|
208 |
|
|
void fixchecksum(); |
209 |
|
|
|
210 |
|
|
void WalkMetadata(int loc, void(*func)(int loc, char * name, int len, const unsigned char * contents));//This one calls func() for each metadata block in the RATS tag whose contents (metadata) start at loc in the ROM. Do not replace name with an invalid metadata name, and note that name is not null terminated. |
211 |
|
|
|