Skip to content

Commit

Permalink
asus 2Mb cache config and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
superg committed Dec 6, 2022
1 parent b1bb4c6 commit b13cefd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
33 changes: 25 additions & 8 deletions drive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ static const std::map<DriveConfig::Type, std::string> TYPE_STRING =
{DriveConfig::Type::GENERIC, "GENERIC"},
{DriveConfig::Type::PLEXTOR, "PLEXTOR"},
{DriveConfig::Type::LG_ASU8, "LG_ASU8"},
{DriveConfig::Type::LG_ASU3, "LG_ASU3"}
{DriveConfig::Type::LG_ASU3, "LG_ASU3"},
{DriveConfig::Type::LG_ASU2, "LG_ASU2"}
};


Expand Down Expand Up @@ -106,6 +107,7 @@ static const std::vector<DriveConfig> KNOWN_DRIVES =
{"ATAPI" , "iHBS112 2" , "PL06", "2012/09/17 10:50" , +6, 0, -135, DriveConfig::ReadMethod::BE_CDDA, DriveConfig::SectorOrder::DATA_C2_SUB, DriveConfig::Type::LG_ASU8}, // CHECKED: LITE-ON
{"ASUS" , "BW-16D1HT" , "3.02", "W000800KL8J9NJ3134" , +6, 0, -135, DriveConfig::ReadMethod::BE_CDDA, DriveConfig::SectorOrder::DATA_C2_SUB, DriveConfig::Type::LG_ASU3}, // CHECKED
{"HL-DT-ST", "BD-RE BP50NB40" , "1.00", "N005505MD8F8BD0700" , +6, 0, -135, DriveConfig::ReadMethod::BE_CDDA, DriveConfig::SectorOrder::DATA_C2_SUB, DriveConfig::Type::LG_ASU3}, // olofolleola4
{"Slimtype", "BD E DS4E1S" , "EA2B", "2009/11/13 15:21" , +6, 0, -135, DriveConfig::ReadMethod::BE_CDDA, DriveConfig::SectorOrder::DATA_C2_SUB, DriveConfig::Type::LG_ASU2}, // olofolleola4

// OTHER
{"ASUS" , "SDRW-08D2S-U" , "B901", "2015/03/03 15:29" , +6, 0, -135, DriveConfig::ReadMethod::BE , DriveConfig::SectorOrder::DATA_SUB_C2, DriveConfig::Type::GENERIC}, // internal model: DU-8A6NH11B
Expand Down Expand Up @@ -156,10 +158,13 @@ static const std::pair<int32_t, int32_t> PLEXTOR_TOC_RANGE = {-20150, -1150};
// 0x0ACA unknown
// 0x0B00 end
constexpr uint32_t ASUS_CACHE_ENTRY_SIZE = 0xB00;
constexpr uint32_t ASU8_CACHE_SIZE_MB = 8;
constexpr uint32_t ASU3_CACHE_SIZE_MB = 3;
constexpr uint32_t ASU8_CACHE_ENTRIES_COUNT = 2806;
constexpr uint32_t ASU3_CACHE_ENTRIES_COUNT = 1070;

static const std::map<DriveConfig::Type, AsusConfig> ASUS_CACHE_CONFIG =
{
{DriveConfig::Type::LG_ASU8, {8, 2806}},
{DriveConfig::Type::LG_ASU3, {3, 1070}},
{DriveConfig::Type::LG_ASU2, {2, 586}}
};


DriveConfig drive_get_config(const DriveQuery &drive_query)
Expand Down Expand Up @@ -191,6 +196,18 @@ DriveConfig drive_get_config(const DriveQuery &drive_query)
}


AsusConfig asus_get_config(DriveConfig::Type type)
{
AsusConfig asus_config = {0, 0};

auto it = ASUS_CACHE_CONFIG.find(type);
if(it != ASUS_CACHE_CONFIG.end())
asus_config = it->second;

return asus_config;
}


void drive_override_config(DriveConfig &drive_config, const std::string *type, const int *read_offset, const int *c2_shift, const int *pregap_start, const std::string *read_method, const std::string *sector_order)
{
if(type != nullptr)
Expand Down Expand Up @@ -326,7 +343,7 @@ std::vector<uint8_t> asus_cache_read(SPTD &sptd, DriveConfig::Type drive_type)
{
constexpr uint32_t read_size = 1024 * 64; // 64Kb

std::vector<uint8_t> cache(1024 * 1024 * (drive_type == DriveConfig::Type::LG_ASU8 ? ASU8_CACHE_SIZE_MB : ASU3_CACHE_SIZE_MB));
std::vector<uint8_t> cache(1024 * 1024 * asus_get_config(drive_type).size_mb);

for(uint32_t offset = 0, n = (uint32_t)cache.size(); offset < n; offset += read_size)
{
Expand All @@ -341,7 +358,7 @@ std::vector<uint8_t> asus_cache_read(SPTD &sptd, DriveConfig::Type drive_type)

std::vector<uint8_t> asus_cache_extract(const std::vector<uint8_t> &cache, int32_t lba_start, uint32_t entries_count, DriveConfig::Type drive_type)
{
uint32_t cache_entries_count = drive_type == DriveConfig::Type::LG_ASU8 ? ASU8_CACHE_ENTRIES_COUNT : ASU3_CACHE_ENTRIES_COUNT;
uint32_t cache_entries_count = asus_get_config(drive_type).entries_count;

int32_t index_start = cache_entries_count;
std::pair<int32_t, int32_t> index_range = {cache_entries_count, cache_entries_count};
Expand Down Expand Up @@ -451,7 +468,7 @@ std::vector<uint8_t> asus_cache_extract(const std::vector<uint8_t> &cache, int32

void asus_cache_print_subq(const std::vector<uint8_t> &cache, DriveConfig::Type drive_type)
{
uint32_t cache_entries_count = drive_type == DriveConfig::Type::LG_ASU8 ? ASU8_CACHE_ENTRIES_COUNT : ASU3_CACHE_ENTRIES_COUNT;
uint32_t cache_entries_count = asus_get_config(drive_type).entries_count;

for(uint32_t i = 0; i < cache_entries_count; ++i)
{
Expand Down
9 changes: 8 additions & 1 deletion drive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ struct DriveConfig
GENERIC,
PLEXTOR,
LG_ASU8,
LG_ASU3
LG_ASU3,
LG_ASU2
} type;
};

Expand All @@ -56,6 +57,12 @@ struct SectorLayout
uint32_t size;
};

struct AsusConfig
{
uint32_t size_mb;
uint32_t entries_count;
};

inline constexpr uint32_t PLEXTOR_LEADIN_ENTRY_SIZE = sizeof(SPTD::Status) + CD_DATA_SIZE + CD_SUBCODE_SIZE;

DriveConfig drive_get_config(const DriveQuery &drive_query);
Expand Down
4 changes: 2 additions & 2 deletions redumper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,11 @@ void redumper_debug(const Options &options)
{
std::vector<uint8_t> cache = read_vector(cache_path);

asus_cache_print_subq(cache, DriveConfig::Type::LG_ASU3);
asus_cache_print_subq(cache, DriveConfig::Type::LG_ASU2);

// auto asd = asus_cache_unroll(cache);
// auto asd = asus_cache_extract(cache, 128224, 0);
auto asus_leadout_buffer = asus_cache_extract(cache, 55745, 100, DriveConfig::Type::LG_ASU3);
auto asus_leadout_buffer = asus_cache_extract(cache, 55745, 100, DriveConfig::Type::LG_ASU2);
uint32_t entries_count = (uint32_t)asus_leadout_buffer.size() / CD_RAW_DATA_SIZE;

LOG("entries count: {}", entries_count);
Expand Down

0 comments on commit b13cefd

Please sign in to comment.