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 |
|
949554 |
inline int snestopc(int addr) |
44 |
|
|
{ |
45 |
2/2
✓ Branch 0 taken 948108 times.
✓ Branch 1 taken 1446 times.
|
949554 |
if (addr<0 || addr>0xFFFFFF) return -1;//not 24bit |
46 |
2/2
✓ Branch 0 taken 936738 times.
✓ Branch 1 taken 11370 times.
|
948108 |
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 936738 times.
✗ Branch 1 not taken.
|
936738 |
if ((addr&0xFE0000)==0x7E0000 ||//wram |
51 |
2/2
✓ Branch 0 taken 936708 times.
✓ Branch 1 taken 30 times.
|
936738 |
(addr&0x408000)==0x000000 ||//hardware regs, ram mirrors, other strange junk |
52 |
1/2
✓ Branch 0 taken 936708 times.
✗ Branch 1 not taken.
|
936708 |
(addr&0x708000)==0x700000)//sram (low parts of banks 70-7D) |
53 |
|
|
return -1; |
54 |
|
936708 |
addr=((addr&0x7F0000)>>1|(addr&0x7FFF)); |
55 |
|
936708 |
return addr; |
56 |
|
|
} |
57 |
|
|
if (mapper==hirom) |
58 |
|
|
{ |
59 |
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
|
2730 |
if ((addr&0xFE0000)==0x7E0000 ||//wram |
60 |
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
|
2730 |
(addr&0x408000)==0x000000)//hardware regs, ram mirrors, other strange junk |
61 |
|
|
return -1; |
62 |
|
2730 |
return addr&0x3FFFFF; |
63 |
|
|
} |
64 |
|
|
if (mapper==exlorom) |
65 |
|
|
{ |
66 |
1/2
✓ Branch 0 taken 2198 times.
✗ Branch 1 not taken.
|
2198 |
if ((addr&0xF00000)==0x700000 ||//wram, sram |
67 |
1/2
✓ Branch 0 taken 2198 times.
✗ Branch 1 not taken.
|
2198 |
(addr&0x408000)==0x000000)//area that shouldn't be used in lorom |
68 |
|
|
return -1; |
69 |
2/2
✓ Branch 0 taken 882 times.
✓ Branch 1 taken 1316 times.
|
2198 |
if (addr&0x800000) |
70 |
|
|
{ |
71 |
|
882 |
addr=((addr&0x7F0000)>>1|(addr&0x7FFF)); |
72 |
|
|
} |
73 |
|
|
else |
74 |
|
|
{ |
75 |
|
1316 |
addr=((addr&0x7F0000)>>1|(addr&0x7FFF))+0x400000; |
76 |
|
|
} |
77 |
|
2198 |
return addr; |
78 |
|
|
} |
79 |
|
|
if (mapper==exhirom) |
80 |
|
|
{ |
81 |
1/2
✓ Branch 0 taken 2354 times.
✗ Branch 1 not taken.
|
2354 |
if ((addr&0xFE0000)==0x7E0000 ||//wram |
82 |
1/2
✓ Branch 0 taken 2354 times.
✗ Branch 1 not taken.
|
2354 |
(addr&0x408000)==0x000000)//hardware regs, ram mirrors, other strange junk |
83 |
|
|
return -1; |
84 |
2/2
✓ Branch 0 taken 1322 times.
✓ Branch 1 taken 1032 times.
|
2354 |
if ((addr&0x800000)==0x000000) return (addr&0x3FFFFF)|0x400000; |
85 |
|
1032 |
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 252 times.
✗ Branch 1 not taken.
|
252 |
if ((addr&0x600000)==0x600000 ||//wram, sram, open bus |
91 |
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
|
252 |
(addr&0x408000)==0x000000 ||//hardware regs, ram mirrors, rom mirrors, other strange junk |
92 |
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
|
252 |
(addr&0x800000)==0x800000)//fastrom isn't valid either in superfx |
93 |
|
|
return -1; |
94 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
|
252 |
if (addr&0x400000) return addr&0x3FFFFF; |
95 |
|
252 |
else return (addr&0x7F0000)>>1|(addr&0x7FFF); |
96 |
|
|
} |
97 |
|
|
if (mapper==sa1rom) |
98 |
|
|
{ |
99 |
1/2
✓ Branch 0 taken 582 times.
✗ Branch 1 not taken.
|
582 |
if ((addr&0x408000)==0x008000) |
100 |
|
|
{ |
101 |
|
582 |
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 576 times.
✓ Branch 1 taken 626 times.
|
1202 |
if ((addr&0xC00000)==0xC00000)//hirom |
112 |
|
|
{ |
113 |
|
576 |
return (addr&0x3FFFFF)|0x400000; |
114 |
|
|
} |
115 |
3/4
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 338 times.
✓ Branch 2 taken 288 times.
✗ Branch 3 not taken.
|
626 |
if ((addr&0xC00000)==0x000000 || (addr&0xC00000)==0x800000)//lorom |
116 |
|
|
{ |
117 |
1/2
✓ Branch 0 taken 626 times.
✗ Branch 1 not taken.
|
626 |
if ((addr&0x008000)==0x000000) return -1; |
118 |
|
626 |
return (addr&0x800000)>>2 | (addr&0x3F0000)>>1 | (addr&0x7FFF); |
119 |
|
|
} |
120 |
|
|
return -1; |
121 |
|
|
} |
122 |
|
|
if (mapper==norom) |
123 |
|
|
{ |
124 |
|
2052 |
return addr; |
125 |
|
|
} |
126 |
|
|
return -1; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
481474 |
inline int pctosnes(int addr) |
130 |
|
|
{ |
131 |
1/2
✓ Branch 0 taken 481474 times.
✗ Branch 1 not taken.
|
481474 |
if (addr<0) return -1; |
132 |
2/2
✓ Branch 0 taken 477430 times.
✓ Branch 1 taken 4044 times.
|
481474 |
if (mapper==lorom) |
133 |
|
|
{ |
134 |
1/2
✓ Branch 0 taken 477430 times.
✗ Branch 1 not taken.
|
477430 |
if (addr>=0x400000) return -1; |
135 |
|
477430 |
addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000; |
136 |
|
477430 |
return addr|0x800000; |
137 |
|
|
} |
138 |
|
|
if (mapper==hirom) |
139 |
|
|
{ |
140 |
1/2
✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
|
901 |
if (addr>=0x400000) return -1; |
141 |
|
901 |
return addr|0xC00000; |
142 |
|
|
} |
143 |
|
|
if (mapper == exlorom) |
144 |
|
|
{ |
145 |
1/2
✓ Branch 0 taken 473 times.
✗ Branch 1 not taken.
|
473 |
if (addr>=0x800000) return -1; |
146 |
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 450 times.
|
473 |
if (addr&0x400000) |
147 |
|
|
{ |
148 |
|
23 |
addr-=0x400000; |
149 |
|
23 |
addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000; |
150 |
|
23 |
return addr; |
151 |
|
|
} |
152 |
|
|
else |
153 |
|
|
{ |
154 |
|
450 |
addr=((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000; |
155 |
|
450 |
return addr|0x800000; |
156 |
|
|
} |
157 |
|
|
} |
158 |
|
|
if (mapper == exhirom) |
159 |
|
|
{ |
160 |
1/2
✓ Branch 0 taken 545 times.
✗ Branch 1 not taken.
|
545 |
if (addr>=0x800000) return -1; |
161 |
2/2
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 23 times.
|
545 |
if (addr&0x400000) return addr; |
162 |
|
522 |
return addr|0xC00000; |
163 |
|
|
} |
164 |
|
|
if (mapper==sa1rom) |
165 |
|
|
{ |
166 |
1/2
✓ Branch 0 taken 813 times.
✗ Branch 1 not taken.
|
813 |
for (int i=0;i<8;i++) |
167 |
|
|
{ |
168 |
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 480 times.
|
813 |
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 601 times.
✗ Branch 1 not taken.
|
601 |
if (addr>=0x800000) return -1; |
175 |
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 313 times.
|
601 |
if ((addr&0x400000)==0x400000) |
176 |
|
|
{ |
177 |
|
288 |
return addr|0xC00000; |
178 |
|
|
} |
179 |
2/2
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 144 times.
|
313 |
if ((addr&0x600000)==0x000000) |
180 |
|
|
{ |
181 |
|
169 |
return ((addr<<1)&0x3F0000)|0x8000|(addr&0x7FFF); |
182 |
|
|
} |
183 |
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144 |
if ((addr&0x600000)==0x200000) |
184 |
|
|
{ |
185 |
|
144 |
return 0x800000|((addr<<1)&0x3F0000)|0x8000|(addr&0x7FFF); |
186 |
|
|
} |
187 |
|
|
return -1; |
188 |
|
|
} |
189 |
|
|
if (mapper==sfxrom) |
190 |
|
|
{ |
191 |
2/2
✓ Branch 0 taken 147 times.
✓ Branch 1 taken 12 times.
|
159 |
if (addr>=0x200000) return -1; |
192 |
|
147 |
return ((addr<<1)&0x7F0000)|(addr&0x7FFF)|0x8000; |
193 |
|
|
} |
194 |
|
|
if (mapper==norom) |
195 |
|
|
{ |
196 |
|
1032 |
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 |
|
|
|