Skip to content

Commit

Permalink
feat: PS2 master disc sectors with correct submode
Browse files Browse the repository at this point in the history
  • Loading branch information
N4gtan committed Oct 13, 2024
1 parent 63f1bd7 commit 3eec932
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 30 deletions.
5 changes: 2 additions & 3 deletions examples/example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
If xa_edc is not specified, defaults to 'true'.
new_type - For data track only, specifies if the image was created with the old(<2003) Sony's mastering tool.
If new_type is not specified, defaults to 'false'.
source - For audio tracks only, specifies the file name of a wav audio
file as source data for the audio track.
ps2 - Optional, for data track only, specifies if the image is a Playstation 2 one. Defaults to 'false'.
source - For audio tracks only, specifies the file name of a wav audio file as source data for the audio track.
-->
<track type="data" xa_edc="true" new_type="false">

Expand Down
16 changes: 12 additions & 4 deletions src/dumpsxiso/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void prepareRIFFHeader(cd::RIFF_HEADER* header, int dataSize) {
// don't have EDC Form2 data (this can be checked at redump.org) and some games rely on this to do anti-piracy checks like DDR.
const bool CheckEDCXA(cd::IsoReader &reader) {
cd::SECTOR_M2F2 sector;
while (reader.ReadBytesXA(sector.data, 2336)) {
while (reader.ReadBytesXA(sector.data, 2336, true)) {
if (sector.data[2] & 0x20) {
if (sector.data[2332] == 0 && sector.data[2333] == 0 && sector.data[2334] == 0 && sector.data[2335] == 0) {
return false;
Expand All @@ -171,10 +171,14 @@ const bool CheckEDCXA(cd::IsoReader &reader) {

// Games from 2003 and onwards apparenly has built with a newer Sony's mastering tool.
// These has different submode in the descriptor sectors, a correct root year value and files are sorted by LBA instead by name.
const bool CheckISOver(cd::IsoReader &reader) {
const bool CheckISOver(cd::IsoReader &reader, bool& ps2) {
cd::SECTOR_M2F2 sector;
reader.SeekToSector(16);
reader.SeekToSector(15);
reader.ReadBytesXA(sector.data, 2336);
if (sector.data[2] & 0x08) {
ps2 = true;
}
reader.ReadBytesXA(sector.data, 2336, true);
if (sector.data[2] & 0x01) {
return false;
}
Expand Down Expand Up @@ -949,9 +953,10 @@ void WriteXMLByDirectories(const cd::IsoDirEntries* directory, tinyxml2::XMLElem
void ParseISO(cd::IsoReader& reader) {

cd::ISO_DESCRIPTOR descriptor;
bool ps2 = false;
auto license = ReadLicense(reader);
const bool xa_edc = CheckEDCXA(reader);
global::new_type = CheckISOver(reader);
global::new_type = CheckISOver(reader, ps2);

reader.SeekToSector(16);
reader.ReadBytes(&descriptor, 2048);
Expand Down Expand Up @@ -1033,6 +1038,9 @@ void ParseISO(cd::IsoReader& reader) {
trackElement->SetAttribute(xml::attrib::TRACK_TYPE, "data");
trackElement->SetAttribute(xml::attrib::XA_EDC, xa_edc);
trackElement->SetAttribute(xml::attrib::NEW_TYPE, *global::new_type);
if (ps2) {
trackElement->SetAttribute(xml::attrib::PS2, ps2);
}

{
tinyxml2::XMLElement *newElement = trackElement->InsertNewChildElement(xml::elem::IDENTIFIERS);
Expand Down
2 changes: 1 addition & 1 deletion src/mkpsxiso/cdwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IsoWriter

virtual void WriteFile(FILE* file) = 0;
virtual void WriteMemory(const void* memory, size_t size) = 0;
virtual void WriteBlankSectors(unsigned int count, const unsigned char submode = 32, const bool eccAddr = false) = 0;
virtual void WriteBlankSectors(unsigned int count, const unsigned char submode = 0x20, const bool eccAddr = false) = 0;
virtual size_t GetSpaceInCurrentSector() const = 0;
virtual void NextSector() = 0;
virtual void SetSubheader(unsigned int subHead) = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/mkpsxiso/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace global {

extern time_t BuildTime;
extern bool xa_edc;
extern int QuietMode;
extern int trackNum;
extern int noXA;
extern time_t BuildTime;
extern bool xa_edc;
extern bool QuietMode;
extern bool noXA;
extern int trackNum;
};

#endif // _GLOBAL_H
12 changes: 9 additions & 3 deletions src/mkpsxiso/iso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,13 +973,19 @@ int iso::DirTreeClass::GetDirCountTotal() const
return numdirs;
}

void iso::WriteLicenseData(cd::IsoWriter* writer, void* data)
void iso::WriteLicenseData(cd::IsoWriter* writer, void* data, const bool& ps2)
{
auto licenseSectors = writer->GetSectorViewM2F2(0, 12, cd::IsoWriter::EdcEccForm::Form1);
licenseSectors->WriteMemory(data, 2336 * 12);

auto licenseBlankSectors = writer->GetSectorViewM2F1(12, 4, cd::IsoWriter::EdcEccForm::Form2);
licenseBlankSectors->WriteBlankSectors(4);
if (!ps2) {
auto licenseBlankSectors = writer->GetSectorViewM2F1(12, 4, cd::IsoWriter::EdcEccForm::Form2);
licenseBlankSectors->WriteBlankSectors(4);
}
else {
auto licenseBlankSectors = writer->GetSectorViewM2F1(12, 4, cd::IsoWriter::EdcEccForm::Form1);
licenseBlankSectors->WriteBlankSectors(4, 0x08);
}
}

template<size_t N>
Expand Down
2 changes: 1 addition & 1 deletion src/mkpsxiso/iso.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace iso
void OutputLBAlisting(FILE* fp, int level) const;
};

void WriteLicenseData(cd::IsoWriter* writer, void* data);
void WriteLicenseData(cd::IsoWriter* writer, void* data, const bool& ps2);

void WriteDescriptor(cd::IsoWriter* writer, const IDENTIFIERS& id, const DIRENTRY& root, int imageLen);

Expand Down
26 changes: 14 additions & 12 deletions src/mkpsxiso/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,22 @@

namespace global
{
time_t BuildTime;
bool xa_edc;
int QuietMode = false;
int Overwrite = false;

int trackNum = 1;
int noXA = false;
time_t BuildTime;
bool xa_edc = true;
bool ps2 = false;
bool QuietMode = false;
bool Overwrite = false;
bool NoIsoGen = false;
bool noXA = false;
int trackNum = 1;

std::optional<bool> new_type;
std::optional<std::string> volid_override;
std::optional<fs::path> cuefile;
fs::path XMLscript;
fs::path LBAfile;
fs::path LBAheaderFile;
fs::path ImageName;

std::optional<fs::path> cuefile;
int NoIsoGen = false;
fs::path RebuildXMLScript;

tinyxml2::XMLDocument xmlIdFile;
Expand Down Expand Up @@ -414,7 +413,7 @@ int Main(int argc, char* argv[])
printf( "\n" );
}

global::noXA = projectElement->IntAttribute( xml::attrib::NO_XA, 0 );
global::noXA = projectElement->BoolAttribute( xml::attrib::NO_XA );

if ( ( !global::Overwrite ) && ( !global::NoIsoGen ) )
{
Expand Down Expand Up @@ -536,6 +535,9 @@ int Main(int argc, char* argv[])
if ( trackElement->Attribute(xml::attrib::NEW_TYPE) != nullptr ) {
global::new_type = trackElement->BoolAttribute(xml::attrib::NEW_TYPE);
}
if ( global::ps2 = trackElement->BoolAttribute(xml::attrib::PS2) ) {
global::new_type = true; // Force true if it's an PS2 disc
}

if ( global::trackNum != 1 )
{
Expand Down Expand Up @@ -861,7 +863,7 @@ int Main(int argc, char* argv[])
printf( " Writing license data..." );
}

iso::WriteLicenseData( &writer, license->data );
iso::WriteLicenseData( &writer, license->data, global::ps2 );

if ( !global::QuietMode )
{
Expand Down
2 changes: 1 addition & 1 deletion src/shared/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ std::string LongDateToString(const cd::ISO_LONG_DATESTAMP& src)

uint32_t GetSizeInSectors(uint64_t size, uint32_t sectorSize)
{
return size > 0 || *global::new_type ? static_cast<uint32_t>((size + (sectorSize - 1)) / sectorSize) : 1;
return size > 0 ? static_cast<uint32_t>((size + (sectorSize - 1)) / sectorSize) : 1;
}

std::string SectorsToTimecode(const unsigned sectors)
Expand Down
1 change: 1 addition & 0 deletions src/shared/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace attrib
constexpr const char* TRACK_TYPE = "type";
constexpr const char* XA_EDC = "xa_edc";
constexpr const char* NEW_TYPE = "new_type";
constexpr const char* PS2 = "ps2";
constexpr const char* TRACK_SOURCE = "source";
constexpr const char* TRACK_ID = "trackid";
constexpr const char* PREGAP_DURATION = "duration";
Expand Down

0 comments on commit 3eec932

Please sign in to comment.