Skip to content

Commit 29bbec6

Browse files
committed
GBA: Do not allocate BIOS when using built-in one
Saves 16KB
1 parent 878178e commit 29bbec6

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed
File renamed without changes.

gbsp/components/gbsp-libretro/gba_memory.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "common.h"
2121
#include "streams/file_stream.h"
22+
#include "bios/open_gba_bios.h"
2223

2324
/* Sound */
2425
#define gbc_sound_tone_control_low(channel, regn) \
@@ -336,9 +337,10 @@ const u32 def_seq_cycles[16][2] =
336337
{ 9, 17 }, // Gamepak (wait 2)
337338
};
338339

339-
#ifndef RETRO_GO
340-
u8 bios_rom[1024 * 16];
340+
static u8 *bios_rom_alloc; // [1024 * 16];
341+
const u8 *bios_rom = open_gba_bios_rom; // [1024 * 16];
341342

343+
#ifndef RETRO_GO
342344
// Up to 128kb, store SRAM, flash ROM, or EEPROM here.
343345
u8 gamepak_backup[1024 * 128];
344346
#endif
@@ -2578,13 +2580,21 @@ u32 load_gamepak(const struct retro_game_info* info, const char *name,
25782580
s32 load_bios(char *name)
25792581
{
25802582
FILE *fd = fopen(name, "rb");
2581-
2582-
if(!fd)
2583+
if (!fd)
25832584
return -1;
25842585

2585-
fread(bios_rom, 0x4000, 1, fd);
2586+
if (!bios_rom_alloc)
2587+
bios_rom_alloc = malloc(0x4000);
2588+
2589+
if (bios_rom_alloc && fread(bios_rom_alloc, 0x4000, 1, fd))
2590+
{
2591+
bios_rom = bios_rom_alloc;
2592+
fclose(fd);
2593+
return 0;
2594+
}
2595+
fail:
25862596
fclose(fd);
2587-
return 0;
2597+
return -1;
25882598
}
25892599

25902600

gbsp/components/gbsp-libretro/gba_memory.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ extern u16 oam_ram[512];
271271
extern u16 palette_ram_converted[512];
272272
extern u16 io_registers[512];
273273
extern u8 vram[1024 * 96];
274-
extern u8 bios_rom[1024 * 16];
274+
extern const u8 *bios_rom; // [1024 * 16];
275275
// Double buffer used for SMC detection
276276
extern u8 ewram[(1024 * 256) << SMC_DETECTION];
277277
extern u8 iwram[(1024 * 32) << SMC_DETECTION];
@@ -343,7 +343,6 @@ typedef struct
343343
{
344344
// TODO: Evaluate what is best left in internal memory for performance reasons (for the few that could fit)
345345
u8 vram[1024 * 96];
346-
u8 bios_rom[1024 * 16];
347346
u8 ewram[(1024 * 256) << SMC_DETECTION];
348347
u8 iwram[(1024 * 32) << SMC_DETECTION];
349348
u8 *memory_map_read[8 * 1024];
@@ -356,7 +355,6 @@ typedef struct
356355

357356
extern gbsp_memory_t *gbsp_memory;
358357
#define vram gbsp_memory->vram
359-
#define bios_rom gbsp_memory->bios_rom
360358
#define ewram gbsp_memory->ewram
361359
#define iwram gbsp_memory->iwram
362360
#define memory_map_read gbsp_memory->memory_map_read

gbsp/main/main.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#define AUDIO_SAMPLE_RATE (GBA_SOUND_FREQUENCY)
1212
#define AUDIO_BUFFER_LENGTH (AUDIO_SAMPLE_RATE / 60 + 1)
1313

14-
#include "bios.h"
15-
1614
u32 idle_loop_target_pc = 0xFFFFFFFF;
1715
u32 translation_gate_target_pc[MAX_TRANSLATION_GATES];
1816
u32 translation_gate_targets = 0;
@@ -151,9 +149,7 @@ void app_main(void)
151149
retro_set_input_state(input_cb);
152150
init_gamepak_buffer();
153151
init_sound();
154-
155-
if (load_bios(RG_BASE_PATH_BIOS "/gba_bios.bin") != 0)
156-
memcpy(bios_rom, open_gba_bios_rom, sizeof(bios_rom));
152+
// load_bios(RG_BASE_PATH_BIOS "/gba_bios.bin");
157153

158154
memset(gamepak_backup, 0xff, sizeof(gamepak_backup));
159155
if (load_gamepak(NULL, app->romPath, FEAT_DISABLE, FEAT_DISABLE, SERIAL_MODE_DISABLED) != 0)

0 commit comments

Comments
 (0)