Skip to content

Commit

Permalink
Updated to current libretro-common (#901)
Browse files Browse the repository at this point in the history
* VFS fix

* Linking errors

* MSVC comoile fix

* Updated to current libretro-common
  • Loading branch information
albertofustinoni authored Jun 28, 2024
1 parent faf0ae3 commit eaa6bc0
Show file tree
Hide file tree
Showing 17 changed files with 957 additions and 468 deletions.
85 changes: 35 additions & 50 deletions libretro-common/cdrom/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,9 +1346,9 @@ struct string_list* cdrom_get_available_drives(void)
if (string_starts_with_size(dir_list->elems[i].data, "/dev/sg",
STRLEN_CONST("/dev/sg")))
{
char drive_string[33];
libretro_vfs_implementation_file *stream;
char drive_model[32] = {0};
char drive_string[33] = {0};
union string_list_elem_attr attr = {0};
int dev_index = 0;
RFILE *file = filestream_open(
Expand Down Expand Up @@ -1380,9 +1380,9 @@ struct string_list* cdrom_get_available_drives(void)
attr.i = dev_index;

if (!string_is_empty(drive_model))
strlcat(drive_string, drive_model, sizeof(drive_string));
strlcpy(drive_string, drive_model, sizeof(drive_string));
else
strlcat(drive_string, "Unknown Drive", sizeof(drive_string));
strlcpy(drive_string, "Unknown Drive", sizeof(drive_string));

string_list_append(list, drive_string, attr);
}
Expand All @@ -1404,7 +1404,7 @@ struct string_list* cdrom_get_available_drives(void)

if (string_split_noalloc(&mods, buf, "\n"))
{
for (i = 0; i < mods.size; i++)
for (i = 0; i < (int)mods.size; i++)
{
if (strcasestr(mods.elems[i].data, "sg "))
{
Expand Down Expand Up @@ -1446,29 +1446,28 @@ struct string_list* cdrom_get_available_drives(void)
DWORD drive_mask = GetLogicalDrives();
int i;

for (i = 0; i < sizeof(DWORD) * 8; i++)
for (i = 0; i < (int)(sizeof(DWORD) * 8); i++)
{
char path[] = {"a:\\"};
char path[] = {"a:\\"};
char cdrom_path[] = {"cdrom://a:/drive-track01.bin"};

path[0] += i;
cdrom_path[8] += i;
path[0] += i;
cdrom_path[8] += i;

/* this drive letter doesn't exist */
if (!(drive_mask & (1 << i)))
continue;

if (GetDriveType(path) != DRIVE_CDROM)
continue;
else

{
char drive_model[32] = {0};
char drive_string[33] = {0};
char drive_string[33];
libretro_vfs_implementation_file *stream;
bool is_cdrom = false;
char drive_model[32] = {0};
union string_list_elem_attr attr = {0};
RFILE *file = filestream_open(cdrom_path, RETRO_VFS_FILE_ACCESS_READ, 0);
libretro_vfs_implementation_file *stream;
bool is_cdrom = false;

if (!file)
continue;

Expand All @@ -1482,9 +1481,9 @@ struct string_list* cdrom_get_available_drives(void)
attr.i = path[0];

if (!string_is_empty(drive_model))
strlcat(drive_string, drive_model, sizeof(drive_string));
strlcpy(drive_string, drive_model, sizeof(drive_string));
else
strlcat(drive_string, "Unknown Drive", sizeof(drive_string));
strlcpy(drive_string, "Unknown Drive", sizeof(drive_string));

string_list_append(list, drive_string, attr);
}
Expand Down Expand Up @@ -1524,9 +1523,7 @@ bool cdrom_drive_has_media(const char drive)
if (file)
{
libretro_vfs_implementation_file *stream = filestream_get_vfs_handle(file);
bool has_media = false;

has_media = cdrom_is_media_inserted(stream);
bool has_media = cdrom_is_media_inserted(stream);

filestream_close(file);

Expand All @@ -1538,14 +1535,14 @@ bool cdrom_drive_has_media(const char drive)

bool cdrom_set_read_cache(libretro_vfs_implementation_file *stream, bool enabled)
{
int i;
/* MMC Command: MODE SENSE (10) and MODE SELECT (10) */
unsigned char cdb_sense_changeable[] = {0x5A, 0, 0x48, 0, 0, 0, 0, 0, 0x14, 0};
unsigned char cdb_sense[] = {0x5A, 0, 0x8, 0, 0, 0, 0, 0, 0x14, 0};
unsigned char cdb_select[] = {0x55, 0x10, 0, 0, 0, 0, 0, 0, 0x14, 0};
unsigned char buf[20] = {0};
int rv, i;

rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb_sense_changeable, sizeof(cdb_sense_changeable), 0);
unsigned char cdb_sense[] = {0x5A, 0, 0x8, 0, 0, 0, 0, 0, 0x14, 0};
unsigned char cdb_select[] = {0x55, 0x10, 0, 0, 0, 0, 0, 0, 0x14, 0};
unsigned char buf[20] = {0};
int rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf),
cdb_sense_changeable, sizeof(cdb_sense_changeable), 0);

#ifdef CDROM_DEBUG
printf("[CDROM] mode sense changeable status code %d\n", rv);
Expand Down Expand Up @@ -1581,9 +1578,7 @@ bool cdrom_set_read_cache(libretro_vfs_implementation_file *stream, bool enabled
printf("Mode sense data for caching mode page: ");

for (i = 0; i < (int)sizeof(buf); i++)
{
printf("%02X ", buf[i]);
}

printf("\n");
fflush(stdout);
Expand All @@ -1596,7 +1591,7 @@ bool cdrom_set_read_cache(libretro_vfs_implementation_file *stream, bool enabled
if (enabled)
buf[10] &= ~1;
else
buf[10] |= 1;
buf[10] |= 1;

rv = cdrom_send_command(stream, DIRECTION_OUT, buf, sizeof(buf), cdb_select, sizeof(cdb_select), 0);

Expand Down Expand Up @@ -1645,9 +1640,7 @@ bool cdrom_get_timeouts(libretro_vfs_implementation_file *stream, cdrom_group_ti
printf("Mode sense data for timeout groups: ");

for (i = 0; i < (int)sizeof(buf); i++)
{
printf("%02X ", buf[i]);
}

printf("\n");

Expand All @@ -1669,8 +1662,8 @@ bool cdrom_get_timeouts(libretro_vfs_implementation_file *stream, cdrom_group_ti
bool cdrom_has_atip(libretro_vfs_implementation_file *stream)
{
/* MMC Command: READ TOC/PMA/ATIP */
unsigned char cdb[] = {0x43, 0x2, 0x4, 0, 0, 0, 0, 0x9, 0x30, 0};
unsigned char buf[32] = {0};
unsigned char cdb[] = {0x43, 0x2, 0x4, 0, 0, 0, 0, 0x9, 0x30, 0};
unsigned char buf[32] = {0};
unsigned short atip_len = 0;
int rv = cdrom_send_command(stream, DIRECTION_IN, buf, sizeof(buf), cdb, sizeof(cdb), 0);

Expand All @@ -1680,7 +1673,10 @@ bool cdrom_has_atip(libretro_vfs_implementation_file *stream)
atip_len = buf[0] << 8 | buf[1];

#ifdef CDROM_DEBUG
printf("ATIP Length %d, Disc Type %d, Disc Sub-Type %d\n", atip_len, (buf[6] >> 6) & 0x1, ((buf[6] >> 5) & 0x1) << 2 | ((buf[6] >> 4) & 0x1) << 1 | ((buf[6] >> 3) & 0x1) << 0);
printf("ATIP Length %d, Disc Type %d, Disc Sub-Type %d\n",
atip_len,
(buf[6] >> 6) & 0x1,
((buf[6] >> 5) & 0x1) << 2 | ((buf[6] >> 4) & 0x1) << 1 | ((buf[6] >> 3) & 0x1) << 0);
#endif

if (atip_len < 5)
Expand All @@ -1691,53 +1687,42 @@ bool cdrom_has_atip(libretro_vfs_implementation_file *stream)

void cdrom_device_fillpath(char *path, size_t len, char drive, unsigned char track, bool is_cue)
{
size_t pos = 0;

if (!path || len == 0)
return;

if (is_cue)
{
#ifdef _WIN32
pos = strlcpy(path, "cdrom://", len);

size_t pos = strlcpy(path, "cdrom://", len);
if (len > pos)
path[pos++] = drive;

pos = strlcat(path, ":/drive.cue", len);
#else
#ifdef __linux__
pos = strlcpy(path, "cdrom://drive", len);

size_t pos = strlcpy(path, "cdrom://drive", len);
if (len > pos + 1)
{
path[pos++] = drive;
path[pos] = '\0';
path[pos] = '\0';
}

pos = strlcat(path, ".cue", len);
#endif
#endif
}
else
{
#ifdef _WIN32
pos = strlcpy(path, "cdrom://", len);

size_t pos = strlcpy(path, "cdrom://", len);
if (len > pos + 1)
{
path[pos++] = drive;
path[pos] = '\0';
path[pos] = '\0';
}

pos += snprintf(path + pos, len - pos, ":/drive-track%02d.bin", track);
#else
#ifdef __linux__
pos = strlcpy(path, "cdrom://drive", len);

size_t pos = strlcpy(path, "cdrom://drive", len);
if (len > pos)
path[pos++] = drive;

pos += snprintf(path + pos, len - pos, "-track%02d.bin", track);
#endif
#endif
Expand Down
7 changes: 0 additions & 7 deletions libretro-common/compat/compat_strl.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,3 @@ size_t strlcat(char *dest, const char *source, size_t size)
return len + strlcpy(dest, source, size);
}
#endif

char *strldup(const char *s, size_t n)
{
char *dst = (char*)malloc(sizeof(char) * (n + 1));
strlcpy(dst, s, n);
return dst;
}
Loading

0 comments on commit eaa6bc0

Please sign in to comment.