mirror of https://github.com/bsnes-emu/bsnes.git
Replaced libretro specific code with a generic API
This commit is contained in:
parent
6b71d1d477
commit
40e4f93637
28
Core/gb.c
28
Core/gb.c
|
@ -153,25 +153,6 @@ void GB_free(GB_gameboy_t *gb)
|
||||||
memset(gb, 0, sizeof(*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)
|
int GB_load_boot_rom(GB_gameboy_t *gb, const char *path)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(path, "rb");
|
FILE *f = fopen(path, "rb");
|
||||||
|
@ -184,6 +165,15 @@ int GB_load_boot_rom(GB_gameboy_t *gb, const char *path)
|
||||||
return 0;
|
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)
|
int GB_load_rom(GB_gameboy_t *gb, const char *path)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(path, "rb");
|
FILE *f = fopen(path, "rb");
|
||||||
|
|
|
@ -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_get_user_data(GB_gameboy_t *gb);
|
||||||
void GB_set_user_data(GB_gameboy_t *gb, void *data);
|
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);
|
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_load_rom(GB_gameboy_t *gb, const char *path);
|
||||||
|
|
||||||
int GB_save_battery(GB_gameboy_t *gb, const char *path);
|
int GB_save_battery(GB_gameboy_t *gb, const char *path);
|
||||||
|
|
|
@ -135,7 +135,7 @@ all: $(TARGET)
|
||||||
|
|
||||||
$(CORE_DIR)/libretro/%_boot.c: $(CORE_DIR)/build/bin/BootROMs/%_boot.bin
|
$(CORE_DIR)/libretro/%_boot.c: $(CORE_DIR)/build/bin/BootROMs/%_boot.bin
|
||||||
echo "/* AUTO-GENERATED */" > $@
|
echo "/* AUTO-GENERATED */" > $@
|
||||||
echo "const char $(notdir $(@:%.c=%))[] = {" >> $@
|
echo "const unsigned char $(notdir $(@:%.c=%))[] = {" >> $@
|
||||||
cat $< | xxd -i >> $@
|
cat $< | xxd -i >> $@
|
||||||
echo "};" >> $@
|
echo "};" >> $@
|
||||||
echo "const unsigned $(notdir $(@:%.c=%))_length = sizeof($(notdir $(@:%.c=%)));" >> $@
|
echo "const unsigned $(notdir $(@:%.c=%))_length = sizeof($(notdir $(@:%.c=%)));" >> $@
|
||||||
|
|
|
@ -49,6 +49,8 @@ char retro_game_path[4096];
|
||||||
int RLOOP=1;
|
int RLOOP=1;
|
||||||
|
|
||||||
GB_gameboy_t gb;
|
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, ...)
|
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);
|
log_cb(RETRO_LOG_INFO, "Loading boot image: %s\n", buf);
|
||||||
err = GB_load_boot_rom(&gb, buf);
|
err = GB_load_boot_rom(&gb, buf);
|
||||||
|
|
||||||
if (err)
|
if (err) {
|
||||||
err = GB_load_boot_rom_dmg(&gb);
|
GB_load_boot_rom_from_buffer(&gb, dmg_boot, dmg_boot_length);
|
||||||
|
err = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
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);
|
log_cb(RETRO_LOG_INFO, "Loading boot image: %s\n", buf);
|
||||||
err = GB_load_boot_rom(&gb, buf);
|
err = GB_load_boot_rom(&gb, buf);
|
||||||
|
|
||||||
if (err)
|
if (err) {
|
||||||
err = GB_load_boot_rom_cgb(&gb);
|
GB_load_boot_rom_from_buffer(&gb, cgb_boot, cgb_boot_length);
|
||||||
|
err = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
log_cb(RETRO_LOG_INFO, "Failed to load boot ROM %s %d\n", buf, err);
|
log_cb(RETRO_LOG_INFO, "Failed to load boot ROM %s %d\n", buf, err);
|
||||||
(void)info;
|
(void)info;
|
||||||
|
|
Loading…
Reference in New Issue