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