Skip to content

Commit

Permalink
rename globals
Browse files Browse the repository at this point in the history
  • Loading branch information
dszakallas committed May 1, 2024
1 parent 2055766 commit 6fc98e6
Showing 1 changed file with 74 additions and 74 deletions.
148 changes: 74 additions & 74 deletions libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ static char g_ROMS_DIR[PATH_MAX_LENGTH];
// disk swapping
#define M3U_MAX_FILE 4

static char disk_paths[M3U_MAX_FILE][PATH_MAX_LENGTH];
static char disk_labels[M3U_MAX_FILE][PATH_MAX_LENGTH];
static char g_DISK_PATHS[M3U_MAX_FILE][PATH_MAX_LENGTH];
static char g_DISK_LABELS[M3U_MAX_FILE][PATH_MAX_LENGTH];

static unsigned disk_initial_index = 0;
static char disk_initial_path[PATH_MAX];
static unsigned disk_index = 0;
static unsigned disk_total = 0;
static bool disk_tray_open = false;
static unsigned g_DISK_INITIAL_INDEX = 0;
static char g_DISK_INITIAL_PATH[PATH_MAX];
static unsigned g_DISK_INDEX = 0;
static unsigned g_DISK_TOTAL = 0;
static bool g_DISK_TRAY_OPEN = false;

static struct retro_disk_control_callback retro_disk_control_cb;
static struct retro_disk_control_ext_callback retro_disk_control_ext_cb;
static struct retro_disk_control_callback g_DISK_CONTROL_CB;
static struct retro_disk_control_ext_callback g_DISK_CONTROL_EXT_CB;

static
bool
Expand All @@ -69,15 +69,15 @@ read_m3u(const char *file)
char name[PATH_MAX];
FILE *f = fopen(file, "r");

disk_total = 0;
g_DISK_TOTAL = 0;

if (!f)
{
retro_log_printf_cb(RETRO_LOG_ERROR, "Could not read file\n");
return false;
}

while (fgets(line, sizeof(line), f) && disk_total <= M3U_MAX_FILE)
while (fgets(line, sizeof(line), f) && g_DISK_TOTAL <= M3U_MAX_FILE)
{
if (line[0] == '#')
continue;
Expand All @@ -104,14 +104,14 @@ read_m3u(const char *file)

if (line[0] != '\0')
{
snprintf(disk_paths[disk_total], sizeof(disk_paths[disk_total]), "%s%c%s", g_ROMS_DIR, slash, line);
fill_pathname(disk_labels[disk_total], path_basename(disk_paths[disk_total]), "", sizeof(disk_labels[disk_total]));
disk_total++;
snprintf(g_DISK_PATHS[g_DISK_TOTAL], sizeof(g_DISK_PATHS[g_DISK_TOTAL]), "%s%c%s", g_ROMS_DIR, slash, line);
fill_pathname(g_DISK_LABELS[g_DISK_TOTAL], path_basename(g_DISK_PATHS[g_DISK_TOTAL]), "", sizeof(g_DISK_LABELS[g_DISK_TOTAL]));
g_DISK_TOTAL++;
}
}

fclose(f);
return (disk_total != 0);
return (g_DISK_TOTAL != 0);
}

static
Expand Down Expand Up @@ -411,7 +411,7 @@ static
bool
disk_set_eject_state(bool ejected)
{
disk_tray_open = ejected;
g_DISK_TRAY_OPEN = ejected;
if (ejected)
return true;

Expand All @@ -427,7 +427,7 @@ disk_set_eject_state(bool ejected)
opera_lr_opts_reset();

// load
rv = open_cdimage(disk_paths[disk_index]);
rv = open_cdimage(g_DISK_PATHS[g_DISK_INDEX]);
if (rv == -1)
return false;

Expand All @@ -450,16 +450,16 @@ static
bool
disk_get_eject_state()
{
return disk_tray_open;
return g_DISK_TRAY_OPEN;
}

static
bool
disk_set_image_index(unsigned index)
{
if (disk_tray_open && index < disk_total)
if (g_DISK_TRAY_OPEN && index < g_DISK_TOTAL)
{
disk_index = index;
g_DISK_INDEX = index;
return true;
}
return false;
Expand All @@ -469,25 +469,25 @@ static
unsigned
disk_get_image_index()
{
return disk_index;
return g_DISK_INDEX;
}

static
unsigned
disk_get_num_images(void)
{
return disk_total;
return g_DISK_TOTAL;
}

static
bool
disk_add_image_index(void)
{
if (disk_total >= M3U_MAX_FILE)
if (g_DISK_TOTAL >= M3U_MAX_FILE)
return false;
disk_total++;
disk_paths[disk_total - 1][0] = '\0';
disk_labels[disk_total - 1][0] = '\0';
g_DISK_TOTAL++;
g_DISK_PATHS[g_DISK_TOTAL - 1][0] = '\0';
g_DISK_LABELS[g_DISK_TOTAL - 1][0] = '\0';
return true;
}

Expand All @@ -496,23 +496,23 @@ bool
disk_replace_image_index(unsigned index,
const struct retro_game_info *info)
{
if ((index >= disk_total))
if ((index >= g_DISK_TOTAL))
return false;

if (!info)
{
disk_paths[index][0] = '\0';
disk_labels[index][0] = '\0';
disk_total--;
g_DISK_PATHS[index][0] = '\0';
g_DISK_LABELS[index][0] = '\0';
g_DISK_TOTAL--;

if ((disk_index >= index) && (disk_index > 0))
disk_index--;
if ((g_DISK_INDEX >= index) && (g_DISK_INDEX > 0))
g_DISK_INDEX--;
}
else
{
snprintf(disk_paths[index], sizeof(disk_paths[index]), "%s", info->path);
fill_pathname(disk_labels[index], path_basename(disk_paths[index]), "",
sizeof(disk_labels[index]));
snprintf(g_DISK_PATHS[index], sizeof(g_DISK_PATHS[index]), "%s", info->path);
fill_pathname(g_DISK_LABELS[index], path_basename(g_DISK_PATHS[index]), "",
sizeof(g_DISK_LABELS[index]));
}
return true;
}
Expand All @@ -521,8 +521,8 @@ static bool disk_set_initial_image(unsigned index, const char *path) {
if (!path || (*path == '\0'))
return false;

disk_initial_index = index;
snprintf(disk_initial_path, sizeof(disk_initial_path), "%s", path);
g_DISK_INITIAL_INDEX = index;
snprintf(g_DISK_INITIAL_PATH, sizeof(g_DISK_INITIAL_PATH), "%s", path);

return true;
}
Expand All @@ -534,13 +534,13 @@ disk_get_image_path(unsigned index, char *path, size_t len)
if (len < 1)
return false;

if (index >= disk_total)
if (index >= g_DISK_TOTAL)
return false;

if (disk_paths[index][0] == '\0')
if (g_DISK_PATHS[index][0] == '\0')
return false;

strncpy(path, disk_paths[index], len - 1);
strncpy(path, g_DISK_PATHS[index], len - 1);
path[len - 1] = '\0';

return true;
Expand All @@ -553,13 +553,13 @@ disk_get_image_label(unsigned index, char *label, size_t len)
if (len < 1)
return false;

if (index >= disk_total)
if (index >= g_DISK_TOTAL)
return false;

if (disk_labels[index][0] == '\0')
if (g_DISK_LABELS[index][0] == '\0')
return false;

strncpy(label, disk_labels[index], len - 1);
strncpy(label, g_DISK_LABELS[index], len - 1);
label[len - 1] = '\0';

return true;
Expand All @@ -571,31 +571,31 @@ init_disk_control_interface(void)
{
unsigned dci_version = 0;

retro_disk_control_cb.set_eject_state = disk_set_eject_state;
retro_disk_control_cb.get_eject_state = disk_get_eject_state;
retro_disk_control_cb.set_image_index = disk_set_image_index;
retro_disk_control_cb.get_image_index = disk_get_image_index;
retro_disk_control_cb.get_num_images = disk_get_num_images;
retro_disk_control_cb.add_image_index = disk_add_image_index;
retro_disk_control_cb.replace_image_index = disk_replace_image_index;

retro_disk_control_ext_cb.set_eject_state = disk_set_eject_state;
retro_disk_control_ext_cb.get_eject_state = disk_get_eject_state;
retro_disk_control_ext_cb.set_image_index = disk_set_image_index;
retro_disk_control_ext_cb.get_image_index = disk_get_image_index;
retro_disk_control_ext_cb.get_num_images = disk_get_num_images;
retro_disk_control_ext_cb.add_image_index = disk_add_image_index;
retro_disk_control_ext_cb.replace_image_index = disk_replace_image_index;
retro_disk_control_ext_cb.set_initial_image = disk_set_initial_image;
retro_disk_control_ext_cb.get_image_path = disk_get_image_path;
retro_disk_control_ext_cb.get_image_label = disk_get_image_label;

disk_initial_index = 0;
disk_initial_path[0] = '\0';
g_DISK_CONTROL_CB.set_eject_state = disk_set_eject_state;
g_DISK_CONTROL_CB.get_eject_state = disk_get_eject_state;
g_DISK_CONTROL_CB.set_image_index = disk_set_image_index;
g_DISK_CONTROL_CB.get_image_index = disk_get_image_index;
g_DISK_CONTROL_CB.get_num_images = disk_get_num_images;
g_DISK_CONTROL_CB.add_image_index = disk_add_image_index;
g_DISK_CONTROL_CB.replace_image_index = disk_replace_image_index;

g_DISK_CONTROL_EXT_CB.set_eject_state = disk_set_eject_state;
g_DISK_CONTROL_EXT_CB.get_eject_state = disk_get_eject_state;
g_DISK_CONTROL_EXT_CB.set_image_index = disk_set_image_index;
g_DISK_CONTROL_EXT_CB.get_image_index = disk_get_image_index;
g_DISK_CONTROL_EXT_CB.get_num_images = disk_get_num_images;
g_DISK_CONTROL_EXT_CB.add_image_index = disk_add_image_index;
g_DISK_CONTROL_EXT_CB.replace_image_index = disk_replace_image_index;
g_DISK_CONTROL_EXT_CB.set_initial_image = disk_set_initial_image;
g_DISK_CONTROL_EXT_CB.get_image_path = disk_get_image_path;
g_DISK_CONTROL_EXT_CB.get_image_label = disk_get_image_label;

g_DISK_INITIAL_INDEX = 0;
g_DISK_INITIAL_PATH[0] = '\0';
if (retro_environment_cb(RETRO_ENVIRONMENT_GET_DISK_CONTROL_INTERFACE_VERSION, &dci_version) && (dci_version >= 1))
retro_environment_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE, &retro_disk_control_ext_cb);
retro_environment_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE, &g_DISK_CONTROL_EXT_CB);
else
retro_environment_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &retro_disk_control_cb);
retro_environment_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &g_DISK_CONTROL_CB);
}

bool
Expand All @@ -615,21 +615,21 @@ retro_load_game(const struct retro_game_info *info_)
}
else
{
disk_index = 0;
g_DISK_INDEX = 0;

if ((disk_total > 1) && (disk_initial_index > 0) && (disk_initial_index < disk_total))
if (strcmp(disk_paths[disk_initial_index], disk_initial_path) == 0)
disk_index = disk_initial_index;
if ((g_DISK_TOTAL > 1) && (g_DISK_INITIAL_INDEX > 0) && (g_DISK_INITIAL_INDEX < g_DISK_TOTAL))
if (strcmp(g_DISK_PATHS[g_DISK_INITIAL_INDEX], g_DISK_INITIAL_PATH) == 0)
g_DISK_INDEX = g_DISK_INITIAL_INDEX;
}
}
else
{
snprintf(disk_paths[disk_total], sizeof(disk_paths[disk_total]), "%s", info_->path);
fill_pathname(disk_labels[disk_total], path_basename(disk_paths[disk_total]), "", sizeof(disk_labels[disk_total]));
disk_total++;
snprintf(g_DISK_PATHS[g_DISK_TOTAL], sizeof(g_DISK_PATHS[g_DISK_TOTAL]), "%s", info_->path);
fill_pathname(g_DISK_LABELS[g_DISK_TOTAL], path_basename(g_DISK_PATHS[g_DISK_TOTAL]), "", sizeof(g_DISK_LABELS[g_DISK_TOTAL]));
g_DISK_TOTAL++;
}

rv = open_cdimage(disk_paths[disk_index]);
rv = open_cdimage(g_DISK_PATHS[g_DISK_INDEX]);
if(rv == -1)
return false;

Expand Down

0 comments on commit 6fc98e6

Please sign in to comment.