Skip to content

Commit

Permalink
CD-TEXT pack type correction
Browse files Browse the repository at this point in the history
  • Loading branch information
superg committed Dec 13, 2022
1 parent b13cefd commit 9424d09
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
34 changes: 25 additions & 9 deletions redumper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1031,26 +1031,42 @@ void redumper_subchannel(const Options &options)

void redumper_debug(const Options &options)
{
/*
std::string image_prefix = (std::filesystem::path(options.image_path) / options.image_name).string();
std::filesystem::path state_path(image_prefix + ".state");
std::filesystem::path cache_path(image_prefix + ".asus");
std::filesystem::path toc_path(image_prefix + ".toc");
std::filesystem::path cdtext_path(image_prefix + ".cdtext");

// CD-TEXT debug
if(1)
{
std::vector<uint8_t> toc_buffer = read_vector(toc_path);
TOC toc(toc_buffer, false);

std::vector<uint8_t> cdtext_buffer = read_vector(cdtext_path);
toc.UpdateCDTEXT(cdtext_buffer);

LOG("");
}

// LG/ASUS cache read
if(0)
{
SPTD sptd(options.drive);
drive_init(sptd, options);

DriveConfig drive_config = drive_get_config(cmd_drive_query(sptd));
drive_override_config(drive_config, options.drive_type.get(),
options.drive_read_offset.get(), options.drive_c2_shift.get(), options.drive_pregap_start.get(), options.drive_read_method.get(), options.drive_sector_order.get());
drive_override_config(drive_config, options.drive_type.get(), options.drive_read_offset.get(),
options.drive_c2_shift.get(), options.drive_pregap_start.get(), options.drive_read_method.get(), options.drive_sector_order.get());
LOG("drive path: {}", options.drive);
LOG("drive: {}", drive_info_string(drive_config));
LOG("drive configuration: {}", drive_config_string(drive_config));

auto cache = asus_cache_read(sptd, drive_config.type);
}
*/
std::string image_prefix = (std::filesystem::path(options.image_path) / options.image_name).string();
std::filesystem::path state_path(image_prefix + ".state");
std::filesystem::path cache_path(image_prefix + ".asus");

//DEBUG: LG/ASUS cache dump read
// LG/ASUS cache dump extract
if(0)
{
std::vector<uint8_t> cache = read_vector(cache_path);

Expand All @@ -1065,7 +1081,7 @@ void redumper_debug(const Options &options)
}


//DEBUG: convert old state file to new state file
// convert old state file to new state file
if(0)
{
std::fstream fs_state(state_path, std::fstream::out | std::fstream::in | std::fstream::binary);
Expand Down
29 changes: 22 additions & 7 deletions toc.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <fmt/format.h>
#include <map>
#include <set>
#include <cctype>
#include "cd.hh"
#include "common.hh"
#include "crc16_gsm.hh"
#include "endian.hh"
#include "logger.hh"
#include "mmc.hh"
#include "toc.hh"


Expand Down Expand Up @@ -336,10 +336,9 @@ bool TOC::UpdateCDTEXT(const std::vector<uint8_t> &cdtext_buffer)
auto &pack_data = descriptors[i];

//DEBUG
// LOG("{:02X} {:02} {:b} {:02} {:02} {:01} {:b} {}{}{}{}{}{}{}{}{}{}{}{}",
// pack_data.PackType, pack_data.TrackNumber, pack_data.ExtensionFlag, pack_data.SequenceNumber, pack_data.CharacterPosition, pack_data.BlockNumber, pack_data.Unicode,
// (char)pack_data.Text[0], (char)pack_data.Text[1], (char)pack_data.Text[2], (char)pack_data.Text[3], (char)pack_data.Text[4], (char)pack_data.Text[5],
// (char)pack_data.Text[6], (char)pack_data.Text[7], (char)pack_data.Text[8], (char)pack_data.Text[9], (char)pack_data.Text[10], (char)pack_data.Text[11]);
LOG("{:02X} {:02} {:b} {:02} {:02} {:01} {:b} {}",
pack_data.pack_type, pack_data.track_number, pack_data.extension_flag, pack_data.sequence_number, pack_data.character_position, pack_data.block_number, pack_data.unicode,
DescriptorText(pack_data));

auto crc = crc16_gsm((uint8_t *)&pack_data, sizeof(pack_data) - sizeof(uint16_t));
// PLEXTOR PX-W5224TA: crc of last pack is always zeroed
Expand Down Expand Up @@ -406,9 +405,8 @@ bool TOC::UpdateCDTEXT(const std::vector<uint8_t> &cdtext_buffer)
if(IsTextPack(pack_type))
{
std::vector<char> text;
for(; i < descriptors_count; ++i)
for(; i < descriptors_count && (PackType)descriptors[i].pack_type == pack_type; ++i)
text.insert(text.end(), descriptors[i].text, descriptors[i].text + sizeof(descriptors[i].text));

std::vector<char *> track_texts;

if(pack_data.unicode)
Expand Down Expand Up @@ -930,4 +928,21 @@ uint32_t TOC::TrackNumberWidth() const
return (track_number ? log10(track_number) : 0) + 1;
}


std::string TOC::DescriptorText(const CD_TEXT_Descriptor &descriptor)
{
std::string text;

for(uint32_t i = 0; i < sizeof(descriptor.text); ++i)
{
if(isprint(descriptor.text[i]))
text += (char)descriptor.text[i];
else
text += descriptor.text[i] ? fmt::format("\\x{:02X}", descriptor.text[i]) : "|";
}

return text;
}


}
2 changes: 2 additions & 0 deletions toc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ostream>
#include <string>
#include <vector>
#include "mmc.hh"
#include "subcode.hh"


Expand Down Expand Up @@ -127,6 +128,7 @@ private:
static bool IsTextPack(PackType pack_type);
CDText *GetCDText(uint8_t index, uint8_t track_number);
uint32_t TrackNumberWidth() const;
std::string DescriptorText(const CD_TEXT_Descriptor &descriptor);
};

}

0 comments on commit 9424d09

Please sign in to comment.