Skip to content

Commit ed610be

Browse files
committed
Increased ROM cache size on Wii with dual-rank MEM2 to 48 MiB.
Increased ROM cache size on Wii U to 192 MiB.
1 parent deff3be commit ed610be

2 files changed

Lines changed: 78 additions & 13 deletions

File tree

gc_memory/MEM2.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,24 @@
105105
#error Too much MEM2 used!
106106
#endif
107107

108+
#define ROMCACHE_128MB_SIZE (64*MB)
109+
#define ROMCACHE_128MB_LO (UNCLAIMED_LO)
110+
#define ROMCACHE_128MB_HI (ROMCACHE_128MB_LO + ROMCACHE_128MB_SIZE)
111+
112+
#define ROMCACHE_64_128MB_SIZE (48*MB)
113+
#define ROMCACHE_64_128MB_LO ((char*)0x94000000)
114+
#define ROMCACHE_64_128MB_HI (ROMCACHE_64_128MB_LO + ROMCACHE_64_128MB_SIZE)
115+
116+
#define ROMCACHE_256MB_SIZE (192*MB)
117+
#define ROMCACHE_256MB_LO (UNCLAIMED_LO)
118+
#define ROMCACHE_256MB_HI (ROMCACHE_256MB_LO + ROMCACHE_256MB_SIZE)
119+
120+
#define ROMCACHE_128_256MB_SIZE (128*MB)
121+
#define ROMCACHE_128_256MB_LO ((char*)0x98000000)
122+
#define ROMCACHE_128_256MB_HI (ROMCACHE_128_256MB_LO + ROMCACHE_128_256MB_SIZE)
123+
124+
#define ROMCACHE_64_256MB_SIZE (192*MB)
125+
#define ROMCACHE_64_256MB_LO ((char*)0x94000000)
126+
#define ROMCACHE_64_256MB_HI (ROMCACHE_64_256MB_LO + ROMCACHE_64_256MB_SIZE)
127+
108128
#endif

main/ROM-Cache-MEM2.c

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ void LoadingBar_showBar(float percent, const char* string);
3434

3535
static char ROMTooBig;
3636
static char ROMCompressed;
37-
static char* ROMBase = ROMCACHE_LO;
37+
static char* ROMCache = ROMCACHE_LO;
38+
static int ROMCacheSize = ROMCACHE_SIZE;
3839

3940
void ROMCache_init(fileBrowser_file* file)
4041
{
@@ -51,30 +52,73 @@ void ROMCache_init(fileBrowser_file* file)
5152
ROMCompressed = 0;
5253
}
5354

54-
ROMTooBig = rom_length > ROMCACHE_SIZE;
55+
switch (SYS_GetPhysicalMem2Size()) {
56+
default:
57+
ROMCache = ROMCACHE_LO;
58+
ROMCacheSize = ROMCACHE_SIZE;
59+
break;
60+
case 128*MB:
61+
switch (SYS_GetSimulatedMem2Size()) {
62+
case 128*MB:
63+
ROMCache = ROMCACHE_128MB_LO;
64+
ROMCacheSize = ROMCACHE_128MB_SIZE;
65+
break;
66+
case 64*MB:
67+
ROMCache = ROMCACHE_64_128MB_LO;
68+
ROMCacheSize = ROMCACHE_64_128MB_SIZE;
69+
break;
70+
default:
71+
ROMCache = ROMCACHE_LO;
72+
ROMCacheSize = ROMCACHE_SIZE;
73+
break;
74+
}
75+
break;
76+
case 256*MB:
77+
switch (SYS_GetSimulatedMem2Size()) {
78+
case 256*MB:
79+
ROMCache = ROMCACHE_256MB_LO;
80+
ROMCacheSize = ROMCACHE_256MB_SIZE;
81+
break;
82+
case 128*MB:
83+
ROMCache = ROMCACHE_128_256MB_LO;
84+
ROMCacheSize = ROMCACHE_128_256MB_SIZE;
85+
break;
86+
case 64*MB:
87+
ROMCache = ROMCACHE_64_256MB_LO;
88+
ROMCacheSize = ROMCACHE_64_256MB_SIZE;
89+
break;
90+
default:
91+
ROMCache = ROMCACHE_LO;
92+
ROMCacheSize = ROMCACHE_SIZE;
93+
break;
94+
}
95+
break;
96+
}
97+
98+
ROMTooBig = rom_length > ROMCacheSize;
5599
}
56100

57101
void ROMCache_deinit()
58102
{
59103
if (ROMTooBig) {
60-
ROMBase = ROMCACHE_LO;
104+
ROMCache = NULL;
61105
VM_Deinit();
62106
}
63107
}
64108

65109
void* ROMCache_pointer(u32 rom_offset)
66110
{
67-
return ROMBase + rom_offset;
111+
return ROMCache + rom_offset;
68112
}
69113

70114
void ROMCache_read(u8* ram_dest, u32 rom_offset, u32 length)
71115
{
72-
memcpy(ram_dest, ROMBase + rom_offset, length);
116+
memcpy(ram_dest, ROMCache + rom_offset, length);
73117
}
74118

75119
void ROMCache_write(u8* ram_src, u32 rom_offset, u32 length)
76120
{
77-
memcpy(ROMBase + rom_offset, ram_src, length);
121+
memcpy(ROMCache + rom_offset, ram_src, length);
78122
}
79123

80124
int ROMCache_load(fileBrowser_file* file)
@@ -88,7 +132,8 @@ int ROMCache_load(fileBrowser_file* file)
88132
if (VMBase == NULL)
89133
return ROM_CACHE_ERROR_READ;
90134

91-
ROMBase = VMBase;
135+
ROMCache = VMBase;
136+
ROMCacheSize = rom_length;
92137
}
93138

94139
sprintf(txt, "Loading ROM %s into MEM2", ROMTooBig ? "partially" : "fully");
@@ -100,16 +145,16 @@ int ROMCache_load(fileBrowser_file* file)
100145
if (bytes_read < 0)
101146
return ROM_CACHE_ERROR_READ;
102147

103-
bytes_read = inflate_chunk(ROMBase + i, buf, bytes_read);
148+
bytes_read = inflate_chunk(ROMCache + i, buf, bytes_read);
104149
if (bytes_read < 0)
105150
return ROM_CACHE_ERROR_READ;
106151

107-
if (i == 0 && init_byte_swap(*(u32*)ROMBase) == BYTE_SWAP_BAD) {
152+
if (i == 0 && init_byte_swap(*(u32*)ROMCache) == BYTE_SWAP_BAD) {
108153
romFile_deinit(file);
109154
return ROM_CACHE_INVALID_ROM;
110155
}
111156

112-
byte_swap(ROMBase + (i & ~3), bytes_read + (i & 3));
157+
byte_swap(ROMCache + (i & ~3), bytes_read + (i & 3));
113158
i += bytes_read;
114159

115160
if (VIDEO_GetRetraceCount() - count > 2) {
@@ -119,16 +164,16 @@ int ROMCache_load(fileBrowser_file* file)
119164
} while (i < rom_length);
120165
} else {
121166
do {
122-
bytes_read = romFile_readFile(file, ROMBase + i, 32*KB);
167+
bytes_read = romFile_readFile(file, ROMCache + i, 32*KB);
123168
if (bytes_read < 0)
124169
return ROM_CACHE_ERROR_READ;
125170

126-
if (i == 0 && init_byte_swap(*(u32*)ROMBase) == BYTE_SWAP_BAD) {
171+
if (i == 0 && init_byte_swap(*(u32*)ROMCache) == BYTE_SWAP_BAD) {
127172
romFile_deinit(file);
128173
return ROM_CACHE_INVALID_ROM;
129174
}
130175

131-
byte_swap(ROMBase + (i & ~3), bytes_read + (i & 3));
176+
byte_swap(ROMCache + (i & ~3), bytes_read + (i & 3));
132177
i += bytes_read;
133178

134179
if (VIDEO_GetRetraceCount() - count > 2) {

0 commit comments

Comments
 (0)