mirror of
https://github.com/visualboyadvance-m/visualboyadvance-m
synced 2025-10-05 23:52:49 +02:00
Check file size for GBA ROM and reduce memory footprint
This commit is contained in:
@@ -1675,16 +1675,31 @@ void GBAMatrixWrite16(GBAMatrix_t *matrix, uint32_t address, uint16_t value)
|
||||
}
|
||||
}
|
||||
|
||||
static size_t get_gba_rom_size(const char* szFile)
|
||||
{
|
||||
size_t size = 0;
|
||||
FILE *f = fopen(szFile, "rb");
|
||||
|
||||
if (f == NULL)
|
||||
return 0;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fclose(f);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int CPULoadRom(const char* szFile)
|
||||
{
|
||||
romSize = SIZE_ROM * 4;
|
||||
romSize = get_gba_rom_size(szFile);
|
||||
if (g_rom != NULL) {
|
||||
CPUCleanUp();
|
||||
}
|
||||
|
||||
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
|
||||
|
||||
g_rom = (uint8_t*)malloc(SIZE_ROM * 4);
|
||||
g_rom = (uint8_t*)malloc(romSize);
|
||||
if (g_rom == NULL) {
|
||||
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
|
||||
"ROM");
|
||||
@@ -1829,14 +1844,14 @@ int CPULoadRom(const char* szFile)
|
||||
|
||||
int CPULoadRomData(const char* data, int size)
|
||||
{
|
||||
romSize = SIZE_ROM * 4;
|
||||
romSize = size % 2 == 0 ? size : size + 1;
|
||||
if (g_rom != NULL) {
|
||||
CPUCleanUp();
|
||||
}
|
||||
|
||||
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
|
||||
|
||||
g_rom = (uint8_t*)malloc(SIZE_ROM * 4);
|
||||
g_rom = (uint8_t*)malloc(romSize);
|
||||
if (g_rom == NULL) {
|
||||
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
|
||||
"ROM");
|
||||
@@ -1869,7 +1884,7 @@ int CPULoadRomData(const char* data, int size)
|
||||
memcpy(&ident, &g_rom[0xAC], 1);
|
||||
|
||||
if (ident == 'M') {
|
||||
g_rom2 = (uint8_t *)malloc(SIZE_ROM * 4);
|
||||
g_rom2 = (uint8_t *)malloc(romSize);
|
||||
memcpy(g_rom2, data, size);
|
||||
romSize = 0x01000000;
|
||||
|
||||
|
@@ -1756,9 +1756,9 @@ bool retro_load_game(const struct retro_game_info *game)
|
||||
return emulating;
|
||||
}
|
||||
|
||||
bool retro_load_game_special(unsigned, const struct retro_game_info *, size_t)
|
||||
bool retro_load_game_special(unsigned, const struct retro_game_info *game, size_t)
|
||||
{
|
||||
return false;
|
||||
return retro_load_game(game);
|
||||
}
|
||||
|
||||
void retro_unload_game(void)
|
||||
|
@@ -1,23 +0,0 @@
|
||||
display_name = "Nintendo - Game Boy Advance (VBA-M)"
|
||||
authors = "Forgotten|VBA-M Team"
|
||||
supported_extensions = "gb|gbc|gba"
|
||||
corename = "VBA-M"
|
||||
manufacturer = "Nintendo"
|
||||
categories = "Emulator"
|
||||
systemname = "Game Boy/Game Boy Color/Game Boy Advance"
|
||||
database = "Nintendo - Game Boy|Nintendo - Game Boy Color|Nintendo - Game Boy Advance|Nintendo - Game Boy Advance (e-Cards)"
|
||||
license = "GPLv2"
|
||||
permissions = ""
|
||||
display_version = "2.1.0"
|
||||
supports_no_game = "false"
|
||||
firmware_count = 3
|
||||
firmware0_desc = "gba_bios.bin (Game Boy Advance BIOS)"
|
||||
firmware0_path = "gba_bios.bin"
|
||||
firmware0_opt = "true"
|
||||
firmware1_desc = "gb_bios.bin (Game Boy BIOS)"
|
||||
firmware1_path = "gb_bios.bin"
|
||||
firmware1_opt = "true"
|
||||
firmware2_desc = "gbc_bios.bin (Game Boy Color BIOS)"
|
||||
firmware2_path = "gbc_bios.bin"
|
||||
firmware2_opt = "true"
|
||||
notes = "(!) gba_bios.bin (md5): a860e8c0b6d573d191e4ec7db1b1e4f6|(!) gb_bios.bin (md5): 32fbbd84168d3482956eb3c5051637f5|(!) gbc_bios.bin (md5): dbfce9db9deaa2567f6a84fde55f9680"
|
Reference in New Issue
Block a user