Skip to content

Commit

Permalink
[libromdata] CBMDOS::loadFileData: Parse the disk name as ASCII if it…
Browse files Browse the repository at this point in the history
… has a GEOS ID string.

The ID string may indicate "V1.0" or "V1.1", so we're only checking
for the presence of "GEOS".
  • Loading branch information
GerbilSoft committed Feb 26, 2024
1 parent a217ba9 commit fca6a14
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/libromdata/Media/CBMDOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,15 +1090,22 @@ int CBMDOS::loadFieldData(void)
}

// Disk name
const char *const s_disk_name_title = C_("CBMDOS", "Disk Name");
remove_A0_padding(disk_name, disk_name_len);
string s_disk_name = cpN_to_utf8(codepage, disk_name, disk_name_len);
if (s_disk_name.find(uFFFD) != string::npos) {
// Disk name has invalid characters when using Unshifted.
// Try again with Shifted.
codepage = CP_RP_PETSCII_Shifted;
s_disk_name = cpN_to_utf8(codepage, disk_name, disk_name_len);
if (unlikely(!memcmp(c1541_bam.geos.geos_id_string, "GEOS", 4))) {
// GEOS ID is present. Parse the disk name as ASCII. (well, Latin-1)
d->fields.addField_string(s_disk_name_title,
latin1_to_utf8(disk_name, disk_name_len));
} else {
string s_disk_name = cpN_to_utf8(codepage, disk_name, disk_name_len);
if (s_disk_name.find(uFFFD) != string::npos) {
// Disk name has invalid characters when using Unshifted.
// Try again with Shifted.
codepage = CP_RP_PETSCII_Shifted;
s_disk_name = cpN_to_utf8(codepage, disk_name, disk_name_len);
}
d->fields.addField_string(s_disk_name_title, s_disk_name);
}
d->fields.addField_string(C_("CBMDOS", "Disk Name"), s_disk_name);

// Disk ID
d->fields.addField_string(C_("CBMDOS", "Disk ID"),
Expand Down
8 changes: 8 additions & 0 deletions src/libromdata/Media/cbmdos_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ASSERT_STRUCT(cbmdos_TS_ptr_t, 2);
/**
* CBMDOS: C1541 Block Allocation Map (18/0)
*/
#define GEOS_ID_STRING "GEOS format V1.x" // the 'x' may be 0 or 1; the '.' may be missing
typedef struct _cbmdos_C1541_BAM_t {
cbmdos_TS_ptr_t next; // $00: Location of the first directory sector
// NOTE: Ignore this; it should always be 18/1.
Expand Down Expand Up @@ -70,6 +71,13 @@ typedef struct _cbmdos_C1541_BAM_t {
uint8_t unused_C1571_AB[0x32]; // $AB
uint8_t free_sector_count[35]; // $DD: [C1571] Free sector count for tracks 36-70
};
struct {
cbmdos_TS_ptr_t border_sector; // $AB: Border sector location
char geos_id_string[16]; // $AC: GEOS ID string, in ASCII
// (check first 4 char for "GEOS" in ASCII)
uint8_t unused_other_BD[16]; // $BD
uint8_t free_sector_count[35]; // $DD: [C1571] Free sector count for tracks 36-70
} geos;
};
} cbmdos_C1541_BAM_t;
ASSERT_STRUCT(cbmdos_C1541_BAM_t, CBMDOS_SECTOR_SIZE);
Expand Down

0 comments on commit fca6a14

Please sign in to comment.