summaryrefslogtreecommitdiff
path: root/libretro.c
diff options
context:
space:
mode:
Diffstat (limited to 'libretro.c')
-rw-r--r--libretro.c177
1 files changed, 105 insertions, 72 deletions
diff --git a/libretro.c b/libretro.c
index 7191f2e..f240b21 100644
--- a/libretro.c
+++ b/libretro.c
@@ -23,10 +23,10 @@ static cothread_t cpu_thread;
/* to be removed */
u32 savestate_slot = 0;
-void get_savestate_filename_noshot(u32 slot, char *name_buffer)
+void get_savestate_filename_noshot(u32 slot, char* name_buffer)
{
- (void) slot;
- sprintf(name_buffer, "dummy.svs");
+ (void) slot;
+ sprintf(name_buffer, "dummy.svs");
}
/* ------------ */
@@ -77,7 +77,7 @@ extern struct retro_perf_callback perf_cb;
#endif
-void retro_get_system_info(struct retro_system_info *info)
+void retro_get_system_info(struct retro_system_info* info)
{
info->library_name = "TempGBA";
info->library_version = "v0.0.1";
@@ -87,28 +87,45 @@ void retro_get_system_info(struct retro_system_info *info)
}
-void retro_get_system_av_info(struct retro_system_av_info *info)
+void retro_get_system_av_info(struct retro_system_av_info* info)
{
info->geometry.base_width = GBA_SCREEN_WIDTH;
info->geometry.base_height = GBA_SCREEN_HEIGHT;
info->geometry.max_width = GBA_SCREEN_WIDTH;
info->geometry.max_height = GBA_SCREEN_HEIGHT;
info->geometry.aspect_ratio = 0;
- info->timing.fps = ((float) (16* 1024 * 1024)) / (308 * 228 * 4); // 59.72750057 hz
+ // 59.72750057 hz
+ info->timing.fps = ((float)(16 * 1024 * 1024)) / (308 * 228 * 4);
info->timing.sample_rate = GBA_SOUND_FREQUENCY;
}
+#include <sys/mman.h>
void retro_init()
{
init_gamepak_buffer();
init_sound(1);
+
+ rom_translation_cache = mmap(NULL, ROM_TRANSLATION_CACHE_SIZE,
+ PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
+ ram_translation_cache = mmap(NULL, RAM_TRANSLATION_CACHE_SIZE,
+ PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
+ bios_translation_cache = mmap(NULL, BIOS_TRANSLATION_CACHE_SIZE,
+ PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
+
+ rom_translation_ptr = rom_translation_cache;
+ ram_translation_ptr = ram_translation_cache;
+ bios_translation_ptr = bios_translation_cache;
}
void retro_deinit()
{
perf_cb.perf_log();
memory_term();
+
+ munmap(rom_translation_cache, ROM_TRANSLATION_CACHE_SIZE);
+ munmap(ram_translation_cache, RAM_TRANSLATION_CACHE_SIZE);
+ munmap(bios_translation_cache, BIOS_TRANSLATION_CACHE_SIZE);
}
void retro_set_environment(retro_environment_t cb)
@@ -126,8 +143,14 @@ void retro_set_environment(retro_environment_t cb)
}
-void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
-void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
+void retro_set_video_refresh(retro_video_refresh_t cb)
+{
+ video_cb = cb;
+}
+void retro_set_input_poll(retro_input_poll_t cb)
+{
+ input_poll_cb = cb;
+}
void retro_set_controller_port_device(unsigned port, unsigned device) {}
@@ -144,51 +167,51 @@ void retro_reset()
size_t retro_serialize_size()
{
-// return SAVESTATE_SIZE;
+ // return SAVESTATE_SIZE;
return 0;
}
-bool retro_serialize(void *data, size_t size)
+bool retro_serialize(void* data, size_t size)
{
-// if (size < SAVESTATE_SIZE)
- return false;
+ // if (size < SAVESTATE_SIZE)
+ return false;
-// gba_save_state(data);
+ // gba_save_state(data);
-// return true;
+ // return true;
}
-bool retro_unserialize(const void *data, size_t size)
+bool retro_unserialize(const void* data, size_t size)
{
-// if (size < SAVESTATE_SIZE)
- return false;
+ // if (size < SAVESTATE_SIZE)
+ return false;
-// gba_load_state(data);
+ // gba_load_state(data);
-// return true;
+ // return true;
}
void retro_cheat_reset() {}
-void retro_cheat_set(unsigned index, bool enabled, const char *code) {}
+void retro_cheat_set(unsigned index, bool enabled, const char* code) {}
-void error_msg(const char *text)
+void error_msg(const char* text)
{
if (log_cb)
log_cb(RETRO_LOG_ERROR, text);
}
-void info_msg(const char *text)
+void info_msg(const char* text)
{
if (log_cb)
log_cb(RETRO_LOG_INFO, text);
}
-static void extract_directory(char *buf, const char *path, size_t size)
+static void extract_directory(char* buf, const char* path, size_t size)
{
strncpy(buf, path, size - 1);
buf[size - 1] = '\0';
- char *base = strrchr(buf, '/');
+ char* base = strrchr(buf, '/');
if (base)
*base = '\0';
@@ -196,10 +219,10 @@ static void extract_directory(char *buf, const char *path, size_t size)
strncpy(buf, ".", size);
}
-bool retro_load_game(const struct retro_game_info *info)
+bool retro_load_game(const struct retro_game_info* info)
{
char filename_bios[MAX_PATH];
- const char *dir = NULL;
+ const char* dir = NULL;
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
@@ -209,45 +232,45 @@ bool retro_load_game(const struct retro_game_info *info)
return false;
}
- extract_directory(main_path,info->path,sizeof(main_path));
+ extract_directory(main_path, info->path, sizeof(main_path));
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
strncpy(filename_bios, dir, sizeof(filename_bios));
else
strncpy(filename_bios, main_path, sizeof(filename_bios));
- strncat(filename_bios, "/gba_bios.bin",sizeof(filename_bios));
+ strncat(filename_bios, "/gba_bios.bin", sizeof(filename_bios));
-// if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir)
-// strncpy(dir_save, dir, sizeof(dir_save));
-// else
-// strncpy(dir_save, main_path, sizeof(dir_save));
+ // if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir)
+ // strncpy(dir_save, dir, sizeof(dir_save));
+ // else
+ // strncpy(dir_save, main_path, sizeof(dir_save));
-// strncat(dir_save, "/",sizeof(dir_save));
+ // strncat(dir_save, "/",sizeof(dir_save));
-// strncat(main_path, "/",sizeof(main_path));
+ // strncat(main_path, "/",sizeof(main_path));
if (load_bios(filename_bios) != 0)
{
- error_msg("Could not load BIOS image file.\n");
- return false;
+ error_msg("Could not load BIOS image file.\n");
+ return false;
}
- if(bios_rom[0] != 0x18)
+ if (bios_rom[0] != 0x18)
{
- info_msg("You have an incorrect BIOS image.\n");
- info_msg("While many games will work fine, some will not. It\n");
- info_msg("is strongly recommended that you obtain the\n");
- info_msg("correct BIOS file.\n");
+ info_msg("You have an incorrect BIOS image.\n");
+ info_msg("While many games will work fine, some will not. It\n");
+ info_msg("is strongly recommended that you obtain the\n");
+ info_msg("correct BIOS file.\n");
}
gamepak_filename[0] = 0;
if (load_gamepak(info->path) != 0)
{
- error_msg("Could not load the game file.\n");
- return false;
+ error_msg("Could not load the game file.\n");
+ return false;
}
reset_gba();
@@ -258,8 +281,11 @@ bool retro_load_game(const struct retro_game_info *info)
}
-bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
-{ return false; }
+bool retro_load_game_special(unsigned game_type,
+ const struct retro_game_info* info, size_t num_info)
+{
+ return false;
+}
void retro_unload_game()
{
@@ -267,42 +293,45 @@ void retro_unload_game()
update_backup();
}
-unsigned retro_get_region() { return RETRO_REGION_NTSC; }
+unsigned retro_get_region()
+{
+ return RETRO_REGION_NTSC;
+}
-void *retro_get_memory_data(unsigned id)
+void* retro_get_memory_data(unsigned id)
{
-// switch (id)
-// {
-// case RETRO_MEMORY_SAVE_RAM:
-// return gamepak_backup;
-// }
+ // switch (id)
+ // {
+ // case RETRO_MEMORY_SAVE_RAM:
+ // return gamepak_backup;
+ // }
return 0;
}
size_t retro_get_memory_size(unsigned id)
{
-// switch (id)
-// {
-// case RETRO_MEMORY_SAVE_RAM:
-// switch(backup_type)
-// {
-// case BACKUP_SRAM:
-// return sram_size;
+ // switch (id)
+ // {
+ // case RETRO_MEMORY_SAVE_RAM:
+ // switch(backup_type)
+ // {
+ // case BACKUP_SRAM:
+ // return sram_size;
-// case BACKUP_FLASH:
-// return flash_size;
+ // case BACKUP_FLASH:
+ // return flash_size;
-// case BACKUP_EEPROM:
-// return eeprom_size;
+ // case BACKUP_EEPROM:
+ // return eeprom_size;
-// case BACKUP_NONE:
-// return 0x0;
+ // case BACKUP_NONE:
+ // return 0x0;
-// default:
-// return 0x8000;
-// }
-// }
+ // default:
+ // return 0x8000;
+ // }
+ // }
return 0;
}
@@ -324,11 +353,15 @@ void retro_run()
render_audio();
- video_cb(gba_screen_pixels, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT, GBA_SCREEN_PITCH * 2);
+ video_cb(gba_screen_pixels, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT,
+ GBA_SCREEN_PITCH * 2);
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
- check_variables();
+ check_variables();
}
-unsigned retro_api_version() { return RETRO_API_VERSION; }
+unsigned retro_api_version()
+{
+ return RETRO_API_VERSION;
+}