@@ -34,7 +34,8 @@ void LoadingBar_showBar(float percent, const char* string);
3434
3535static char ROMTooBig ;
3636static char ROMCompressed ;
37- static char * ROMBase = ROMCACHE_LO ;
37+ static char * ROMCache = ROMCACHE_LO ;
38+ static int ROMCacheSize = ROMCACHE_SIZE ;
3839
3940void 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
57101void ROMCache_deinit ()
58102{
59103 if (ROMTooBig ) {
60- ROMBase = ROMCACHE_LO ;
104+ ROMCache = NULL ;
61105 VM_Deinit ();
62106 }
63107}
64108
65109void * ROMCache_pointer (u32 rom_offset )
66110{
67- return ROMBase + rom_offset ;
111+ return ROMCache + rom_offset ;
68112}
69113
70114void 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
75119void 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
80124int 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