Replaced libretro specific code with a generic API

This commit is contained in:
Lior Halphon 2017-10-12 22:06:01 +03:00
parent 6b71d1d477
commit 40e4f93637
4 changed files with 22 additions and 29 deletions

View File

@ -153,25 +153,6 @@ void GB_free(GB_gameboy_t *gb)
memset(gb, 0, sizeof(*gb));
}
#ifdef __LIBRETRO__
extern const char dmg_boot[], cgb_boot[];
extern const unsigned dmg_boot_length, cgb_boot_length;
int GB_load_boot_rom_dmg(GB_gameboy_t *gb)
{
memset(gb->boot_rom, 0xFF, sizeof(gb->boot_rom));
memcpy(gb->boot_rom, dmg_boot, dmg_boot_length);
return 0;
}
int GB_load_boot_rom_cgb(GB_gameboy_t *gb)
{
memset(gb->boot_rom, 0xFF, sizeof(gb->boot_rom));
memcpy(gb->boot_rom, cgb_boot, cgb_boot_length);
return 0;
}
#endif
int GB_load_boot_rom(GB_gameboy_t *gb, const char *path)
{
FILE *f = fopen(path, "rb");
@ -184,6 +165,15 @@ int GB_load_boot_rom(GB_gameboy_t *gb, const char *path)
return 0;
}
void GB_load_boot_rom_from_buffer(GB_gameboy_t *gb, const unsigned char *buffer, size_t size)
{
if (size > sizeof(gb->boot_rom)) {
size = sizeof(gb->boot_rom);
}
memset(gb->boot_rom, 0xFF, sizeof(gb->boot_rom));
memcpy(gb->boot_rom, buffer, size);
}
int GB_load_rom(GB_gameboy_t *gb, const char *path)
{
FILE *f = fopen(path, "rb");

View File

@ -530,12 +530,10 @@ void *GB_get_direct_access(GB_gameboy_t *gb, GB_direct_access_t access, size_t *
void *GB_get_user_data(GB_gameboy_t *gb);
void GB_set_user_data(GB_gameboy_t *gb, void *data);
#ifdef __LIBRETRO__
int GB_load_boot_rom_dmg(GB_gameboy_t *gb);
int GB_load_boot_rom_cgb(GB_gameboy_t *gb);
#endif
int GB_load_boot_rom(GB_gameboy_t *gb, const char *path);
void GB_load_boot_rom_from_buffer(GB_gameboy_t *gb, const unsigned char *buffer, size_t size);
int GB_load_rom(GB_gameboy_t *gb, const char *path);
int GB_save_battery(GB_gameboy_t *gb, const char *path);

View File

@ -135,7 +135,7 @@ all: $(TARGET)
$(CORE_DIR)/libretro/%_boot.c: $(CORE_DIR)/build/bin/BootROMs/%_boot.bin
echo "/* AUTO-GENERATED */" > $@
echo "const char $(notdir $(@:%.c=%))[] = {" >> $@
echo "const unsigned char $(notdir $(@:%.c=%))[] = {" >> $@
cat $< | xxd -i >> $@
echo "};" >> $@
echo "const unsigned $(notdir $(@:%.c=%))_length = sizeof($(notdir $(@:%.c=%)));" >> $@

View File

@ -49,6 +49,8 @@ char retro_game_path[4096];
int RLOOP=1;
GB_gameboy_t gb;
extern const unsigned char dmg_boot[], cgb_boot[];
extern const unsigned dmg_boot_length, cgb_boot_length;
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
{
@ -289,8 +291,10 @@ bool retro_load_game(const struct retro_game_info *info)
log_cb(RETRO_LOG_INFO, "Loading boot image: %s\n", buf);
err = GB_load_boot_rom(&gb, buf);
if (err)
err = GB_load_boot_rom_dmg(&gb);
if (err) {
GB_load_boot_rom_from_buffer(&gb, dmg_boot, dmg_boot_length);
err = 0;
}
}
else
{
@ -299,10 +303,11 @@ bool retro_load_game(const struct retro_game_info *info)
log_cb(RETRO_LOG_INFO, "Loading boot image: %s\n", buf);
err = GB_load_boot_rom(&gb, buf);
if (err)
err = GB_load_boot_rom_cgb(&gb);
if (err) {
GB_load_boot_rom_from_buffer(&gb, cgb_boot, cgb_boot_length);
err = 0;
}
}
if (err)
log_cb(RETRO_LOG_INFO, "Failed to load boot ROM %s %d\n", buf, err);
(void)info;