Skip to content

Dvd improvements#358

Merged
superg merged 6 commits intomainfrom
dvd_improvements
Mar 1, 2026
Merged

Dvd improvements#358
superg merged 6 commits intomainfrom
dvd_improvements

Conversation

@superg
Copy link
Owner

@superg superg commented Feb 28, 2026

Summary by CodeRabbit

  • Refactor

    • Centralized per-sector validation and descrambling; public DVD APIs and constants reorganized for clearer interfaces.
  • New Features

    • Optional Nintendo-key-aware validation and descrambling per sector.
    • Public scrambler access and ECC_FRAMES constant exposed.
    • Drive firmware version utilities and enforced minimum-version checks.
  • Bug Fixes

    • Improved detection/reporting of invalid data frames and safer raw read / ISO/lead-out handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1e6910 and ed90e1e.

📒 Files selected for processing (1)
  • dvd/dvd_dump.ixx

📝 Walkthrough

Walkthrough

Refactors DVD descramble/validation to per-frame APIs: DataFrame gains ID::valid(), valid(optional key) and descramble(optional key); Scrambler exposes a public get()/descramble(span,psn,key); constants and namespace moved under gpsxre::dvd; callers (dvd_dump, dvd_split, xbox, nintendo, drive, redumper) updated to new signatures and flows.

Changes

Cohort / File(s) Summary
Module surface & DataFrame
dvd/dvd.ixx
Moved exports under gpsxre::dvd; renamed/re-exported LBA constants (DVD_LBA_STARTLBA_START, DVD_LBA_RCZLBA_RCZ); added DataFrame::ID::valid(), DataFrame::valid(std::optional<uint8_t>), DataFrame::descramble(std::optional<uint8_t>); removed standalone validate_id.
Scrambler
dvd/dvd_scrambler.ixx
Made Scrambler exportable with static const Scrambler &get() and public descramble(std::span<uint8_t>, uint32_t psn, std::optional<uint8_t>); added export constexpr uint32_t ECC_FRAMES; removed prior per-DataFrame private descramble helper.
Raw dump & read paths
dvd/dvd_dump.ixx, dvd/dvd_split.ixx
Switched read/loop types to dvd::RecordingFrame/dvd::DataFrame; renamed lba parameter, removed scrambler and optional key params from read_dvd_sectors; per-LBA key via nintendo::get_key, validate with df.valid(key), call df.descramble(key); track invalid_data_frames and write main_data spans.
Nintendo key management
dvd/nintendo.ixx
Made derive_key non-exported; added exported get_key(std::optional<uint8_t>&, int32_t, const dvd::DataFrame&) that may update key_lba0 and returns optional per-LBA key.
Xbox integration
dvd/xbox.ixx
Removed dvd::Scrambler parameter from initialize(...); omnidrive read now uses dvd::DataFrame, validates via df.valid() and calls df.descramble(), logs invalid sectors and continues.
Drive / OmniDrive & redumper
drive.ixx, redumper.ixx
OmniDrive detection now returns std::optional<uint32_t> (numeric version); added omnidrive_version_string(uint32_t) and omnidrive_minimum_version(); redumper now guards against unsupported firmware and may abort.
Callsite updates
dvd/*
Propagated type/signature/name changes across callers: use dvd::DataFrame/dvd::RecordingFrame, update sizeof checks, remove scrambler args, rename lba_baselba.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Drive as SPTD/Drive
  participant Dump as dvd_dump
  participant RF as RecordingFrame
  participant DF as dvd::DataFrame
  participant Nin as nintendo::get_key
  participant Scr as dvd::Scrambler::get()

  Note over Drive,Dump: Raw sector read and per-LBA validation/descramble
  Dump->>Drive: cmd_read_omnidrive(lba)
  Drive-->>Dump: sector bytes
  Dump->>RF: parse bytes -> RecordingFrame
  RF-->>Dump: RecordingFrame
  Dump->>DF: RecordingFrame_to_DataFrame(RF)
  DF-->>Dump: DataFrame
  Dump->>Nin: get_key(key_lba0, lba, DF)
  Nin-->>Dump: optional<nintendo_key>
  Dump->>DF: DF.ID::valid()
  alt ID valid
    Dump->>DF: DF.valid(optional_key)
    alt DF valid
      Dump->>DF: DF.descramble(optional_key)
      DF-->>Dump: main_data (descrambled)
      Dump->>Scr: Scr.descramble(span, psn, optional_key)
      Scr-->>Dump: span modified (if applicable)
      Dump->>Dump: write main_data span to ISO
    else DF invalid
      Dump-->>Dump: record invalid_data_frames / continue
    end
  else ID invalid
    Dump-->>Dump: record invalid_data_frames / continue
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~55 minutes

Possibly related PRs

Poem

🐰 I nibble LBA and spin the key,
I hop through frames till bytes agree.
IDs checked, descrambled with glee,
I skip the bad and stash what's free.
Carrot cheers for every working byte! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Dvd improvements' is vague and generic, using non-descriptive language that does not convey meaningful information about the specific changes in this comprehensive refactoring. Replace with a more specific title that highlights the primary change, such as 'Refactor DVD validation and descrambling to use frame-level APIs' or 'Restructure DVD module with per-frame validation methods'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dvd_improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
dvd/dvd.ixx (1)

186-220: Remove stale commented implementation block.

The large commented-out descramble code path (Line [186] onward) is obsolete noise now that DataFrame::valid/DataFrame::descramble are the active API.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/dvd.ixx` around lines 186 - 220, Remove the stale commented-out
implementation of descramble by deleting the entire commented block that
contains the old bool descramble(DataFrame &df, std::optional<uint8_t>
nintendo_key) implementation; keep the file focused on the active API
(DataFrame::valid / DataFrame::descramble) and ensure no remaining references to
the old free-function descramble or its helper logic remain in the file so the
codebase only uses the current DataFrame methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dvd/dvd_dump.ixx`:
- Around line 1056-1057: The current condition calls
df.valid(nintendo::get_key(nintendo_key, l, df)) unconditionally, causing
expensive per-sector validation even when options.verbose is false; change the
branch to check options.verbose first (e.g., if (options.verbose &&
!df.valid(nintendo::get_key(nintendo_key, l, df))) ...) so df.valid and
nintendo::get_key are only invoked when verbose logging is enabled, preserving
existing LOG_R behavior.

In `@dvd/dvd_split.ixx`:
- Around line 191-199: The code calls df.descramble(key) before checking
validity, so invalid frames get altered even when options.leave_unchanged is
true; move the descramble call to occur only after validating the frame (i.e.,
call nintendo::get_key(...), then bool valid = df.valid(key) and if valid then
call df.descramble(key), otherwise honor options.leave_unchanged and possibly
zero the buffer), updating the logic around get_key, df.valid, df.descramble and
options.leave_unchanged to ensure descramble is conditional on valid.

In `@dvd/nintendo.ixx`:
- Around line 34-37: The current std::span(std::span(df.cpr_mai, df.cpr_mai +
8)) in the Nintendo key derivation is invoking pointer arithmetic past the
6-element array df.cpr_mai; change derive_key usage to build a safe 8-byte
buffer explicitly after df.descramble: allocate a local 8-byte temporary (e.g.,
uint8_t tmp[8]), copy the 6 bytes from df.cpr_mai into tmp[0..5] and then copy
the remaining 2 bytes from the adjacent df.main_data start into tmp[6..7], and
then call derive_key(std::span(tmp, 8)) (references: data_frame, df.descramble,
df.cpr_mai, df.main_data, derive_key, key_lba0).

---

Nitpick comments:
In `@dvd/dvd.ixx`:
- Around line 186-220: Remove the stale commented-out implementation of
descramble by deleting the entire commented block that contains the old bool
descramble(DataFrame &df, std::optional<uint8_t> nintendo_key) implementation;
keep the file focused on the active API (DataFrame::valid /
DataFrame::descramble) and ensure no remaining references to the old
free-function descramble or its helper logic remain in the file so the codebase
only uses the current DataFrame methods.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ccff3f and 45128e5.

📒 Files selected for processing (6)
  • dvd/dvd.ixx
  • dvd/dvd_dump.ixx
  • dvd/dvd_scrambler.ixx
  • dvd/dvd_split.ixx
  • dvd/nintendo.ixx
  • dvd/xbox.ixx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
dvd/dvd_dump.ixx (1)

1047-1060: Remove redundant verbose check inside verbose-only block.

options.verbose is already guaranteed true in the outer scope, so the inner && options.verbose is unnecessary noise.

♻️ Proposed cleanup
-                                if(!df.valid(nintendo::get_key(nintendo_key, l, df)) && options.verbose)
+                                if(!df.valid(nintendo::get_key(nintendo_key, l, df)))
                                     LOG_R("[LBA: {}] invalid data frame", l);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/dvd_dump.ixx` around lines 1047 - 1060, Inside the verbose-only block
(guarded by options.verbose) remove the redundant inner check by deleting the
"&& options.verbose" from the if that logs invalid frames; specifically update
the inner loop that checks if(!df.valid(nintendo::get_key(nintendo_key, l, df))
&& options.verbose) to simply if(!df.valid(nintendo::get_key(nintendo_key, l,
df))) so the logging via LOG_R("[LBA: {}] invalid data frame", l) still occurs
when ctx.disc_type == DiscType::DVD, raw is true, and the data frame is invalid.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@dvd/dvd_dump.ixx`:
- Around line 1047-1060: Inside the verbose-only block (guarded by
options.verbose) remove the redundant inner check by deleting the "&&
options.verbose" from the if that logs invalid frames; specifically update the
inner loop that checks if(!df.valid(nintendo::get_key(nintendo_key, l, df)) &&
options.verbose) to simply if(!df.valid(nintendo::get_key(nintendo_key, l, df)))
so the logging via LOG_R("[LBA: {}] invalid data frame", l) still occurs when
ctx.disc_type == DiscType::DVD, raw is true, and the data frame is invalid.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ece5c3 and a1e6910.

📒 Files selected for processing (1)
  • dvd/dvd_dump.ixx

@superg
Copy link
Owner Author

superg commented Mar 1, 2026

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@superg superg merged commit f03b29f into main Mar 1, 2026
11 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant