Skip to content

BCA support#356

Merged
superg merged 14 commits intosuperg:mainfrom
Didrole:feat_bca-support
Feb 28, 2026
Merged

BCA support#356
superg merged 14 commits intosuperg:mainfrom
Didrole:feat_bca-support

Conversation

@Didrole
Copy link
Contributor

@Didrole Didrole commented Feb 24, 2026

This PR adds bca dumping on supported discs and logs the relevant part of it for GC and Wii platforms.

Example of produced log:

redumper (build: LOCAL)

arguments: --drive=/dev/sr0 --retries=5 --overwrite --image-name=test

drive information
  path: /dev/sr0
  inquiry: HL-DT-ST - BD-RE BU40N (revision level: 1.00, vendor specific: N003103651CN044957)
  configuration: MTK8B (read offset: +6, C2 shift: 0, pre-gap start: -135, read method: BE, sector order: DATA_C2_SUB)
  profile: DVD-ROM
  read speed: <optimal>
  firmware: OmniDrive v1.0.2

image path: .
image name: test

*** DUMP

disc structure:
  layer 0 { embossed }
    data { PSN: [196608 .. 2491519], length: 2294912, hPSN: [0x030000 .. 0x26047F] }
    book type: RESERVED5
    part version: 15
    disc size: 120mm
    maximum rate: 10.08 mbps
    layers count: 1
    track path: parallel
    linear density: 0.267 um/bit
    track density: 0.74 um/track
    BCA: yes

sectors count (READ_CAPACITY): 2294912
sectors count (PHYSICAL): 2294912
warning: setting dump read size to 31 for raw dumping
                                                  

media errors: 
  SCSI: 0

*** DUMP::EXTRA (time check: 653s)


*** PROTECTION


*** REFINE


*** DVDKEY

copyright: 
  protection system type: <none>
  region management information: 1 2 3 4 5 6 7 8

*** SPLIT


*** HASH (time check: 87s)

                

dat:
<rom name="test.iso" size="4699979776" crc="6538bbd9" md5="e9710660538d07454d069dd3d99a1a4c" sha1="fbece33c107b50a3b810097c2519f2fb08a3d897" />

*** INFO (time check: 95s)

WII [test.iso]:
  version: 0
  serial: RYWP01
  title: Big Brain Academy: Wii Degree
  BCA:
0080 : 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
0090 : 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
00A0 : 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
00B0 : 00 00 00 00 4D 42 55 54  0B 0C 5B 03 22 01 28 50   ....MBUT..[.".(P

*** END

I haven't tested it much yet though, that's why it's WIP.

Summary by CodeRabbit

  • New Features
    • BCA data is now saved to .bca files during disc dumps when present and readable; failures are skipped.
    • GameCube and Wii info views show a validated BCA hexdump when available.
    • Added a raw hex-dump utility for consistent, formatted binary output.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 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
📝 Walkthrough

Walkthrough

Adds BCA read/write in the DVD redump path and BCA file hexdump display for GC/Wii printInfo; introduces a rawhexdump utility used to format BCA output.

Changes

Cohort / File(s) Summary
DVD dump
dvd/dvd_dump.ixx
On DumpMode::DUMP, detect supported BCA, call SCSI READ_DISC_STRUCTURE for BCA, and write <image_prefix>.bca if read succeeds; minor whitespace cleanup.
System printInfo (GC / Wii)
systems/gc.ixx, systems/wii.ixx
Import file I/O and hex utilities; read <track_basename>.bca, validate 192-byte structure, and print a "BCA:" header plus a hexdump of offset 0x80 length 0x40; return early on missing/invalid files.
Hex dump utility
utils/hex_bin.ixx
Add exported rawhexdump(const uint8_t*, uint32_t, uint32_t group_size=2, uint32_t groups_per_line=8) that produces grouped, uppercase hex output with line breaks for use in printouts.

Sequence Diagram(s)

sequenceDiagram
    participant Dumper as Dumper
    participant PhysParser as PhysParser
    participant SCSI as SCSI
    participant FS as Filesystem
    participant PrintInfo as PrintInfo
    participant HexUtil as HexUtil

    Dumper->>PhysParser: parse disc physical / per-layer structure
    PhysParser-->>Dumper: has_bca flag
    alt has_bca == true
        Dumper->>SCSI: READ_DISC_STRUCTURE (Format: BCA)
        SCSI-->>Dumper: BCA bytes or error
        alt success
            Dumper->>FS: write "<image_prefix>.bca"
        end
    end
    Note over PrintInfo,FS: Later, printInfo may read the .bca file
    PrintInfo->>FS: open "<track_basename>.bca"
    FS-->>PrintInfo: BCA bytes
    PrintInfo->>HexUtil: rawhexdump(BCA[0x80..0xBF])
    HexUtil-->>PrintInfo: formatted hexdump
    PrintInfo-->>User: display BCA header + hexdump
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • superg

Poem

🐇
I hopped through sectors, found a clue,
Saved tiny marks of silver and blue,
I lined the bytes in tidy rows,
Hex carrots gleam where data grows,
A rabbit cheers the BCA view 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'BCA support' accurately and concisely summarizes the main feature added: BCA (Burst Cutting Area) dumping support across multiple platforms and modules.
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

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.

@Deterous
Copy link
Contributor

Deterous commented Feb 24, 2026

For redump submission, BCA should be formatted in raw hexdump style, not ISO buster style.
Byte groups of two are also a common way of displaying BCA (for whatever reason), like so:
0000 0000 4B5B 3D98 ....

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: 2

🧹 Nitpick comments (1)
systems/gc.ixx (1)

53-69: Consider extracting shared Nintendo BCA formatting into a common helper.

The GC/WII implementations are nearly identical; centralizing this avoids drift in offsets/size handling and output behavior.

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

In `@systems/gc.ixx` around lines 53 - 69, The GC-specific BCA handling (bca_path
creation, existence check, read_vector, size compare against
_GC_BCA_STRUCTURE_SIZE, and hexdump output using
_GC_REPORTED_BCA_OFFSET/_GC_REPORTED_BCA_SIZE) should be extracted into a shared
helper (e.g., format_nintendo_bca or print_nintendo_bca) used by both GC and WII
modules; implement a single function that accepts the track path and an output
stream, encapsulates the path construction (track_extract_basename + ".bca"),
existence check, read_vector call, size validation, and hexdump formatting using
the shared constants (or move constants to a shared header), then replace the
duplicated block in the GC implementation with a call to that helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@systems/gc.ixx`:
- Around line 53-59: The code currently returns silently when the .bca sidecar
vector size is invalid; update the block around bca_path/read_vector so that
when bca.size() != _GC_BCA_STRUCTURE_SIZE you emit a clear INFO-level message
(including bca_path and the actual bca.size()) before returning, rather than
silently returning; locate the check using the symbols bca_path, read_vector,
and _GC_BCA_STRUCTURE_SIZE and add a logging call (e.g., logger.info(...) or
std::cerr if no logger exists) that distinguishes "missing" (prior exists()
check) from "malformed .bca" and then return.

In `@systems/wii.ixx`:
- Around line 54-60: Replace the silent early return when a .bca sidecar has the
wrong size with an informational log that includes the bca_path, the actual
bca.size(), and the expected _WII_BCA_STRUCTURE_SIZE before returning; locate
the check around bca_path, read_vector(bca_path) and the if (bca.size() !=
_WII_BCA_STRUCTURE_SIZE) and add a single log/warn/info call describing the
malformed sidecar and its sizes, then keep the existing return behavior.

---

Nitpick comments:
In `@systems/gc.ixx`:
- Around line 53-69: The GC-specific BCA handling (bca_path creation, existence
check, read_vector, size compare against _GC_BCA_STRUCTURE_SIZE, and hexdump
output using _GC_REPORTED_BCA_OFFSET/_GC_REPORTED_BCA_SIZE) should be extracted
into a shared helper (e.g., format_nintendo_bca or print_nintendo_bca) used by
both GC and WII modules; implement a single function that accepts the track path
and an output stream, encapsulates the path construction (track_extract_basename
+ ".bca"), existence check, read_vector call, size validation, and hexdump
formatting using the shared constants (or move constants to a shared header),
then replace the duplicated block in the GC implementation with a call to that
helper.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d8f993 and f6222d8.

📒 Files selected for processing (3)
  • dvd/dvd_dump.ixx
  • systems/gc.ixx
  • systems/wii.ixx

@superg
Copy link
Owner

superg commented Feb 26, 2026

Before I review this PR, do you plan to finish it and address all open threads?

@Didrole
Copy link
Contributor Author

Didrole commented Feb 26, 2026

Yes, I hope to get back to it this weekend.

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.

♻️ Duplicate comments (1)
systems/gc.ixx (1)

57-59: ⚠️ Potential issue | 🟡 Minor

Log malformed .bca before returning.

At Line 59, size mismatch exits silently, so malformed sidecars are indistinguishable from “no BCA output.” Please emit a clear INFO line (path + actual size) before returning.

Suggested patch
         auto bca = read_vector(bca_path);
-        if(bca.size() != _GC_BCA_STRUCTURE_SIZE)
-            return;
+        if(bca.size() != _GC_BCA_STRUCTURE_SIZE)
+        {
+            os << std::format("  BCA: unavailable (unexpected size: {} bytes in {}, expected: {})",
+                              bca.size(), bca_path.string(), _GC_BCA_STRUCTURE_SIZE)
+               << std::endl;
+            return;
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@systems/gc.ixx` around lines 57 - 59, The size-check on the BCA vector
silently returns when bca.size() != _GC_BCA_STRUCTURE_SIZE; before returning,
emit a clear INFO-level log containing the bca_path and the actual bca.size() so
malformed .bca files are distinguishable from missing output. Locate the check
around the read_vector(bca_path) call and replace the silent return with: log an
INFO message (using the project’s logging facility) that includes the bca_path
and bca.size(), then return; keep the same early-return control flow and
reference _GC_BCA_STRUCTURE_SIZE in the message for clarity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@systems/gc.ixx`:
- Around line 57-59: The size-check on the BCA vector silently returns when
bca.size() != _GC_BCA_STRUCTURE_SIZE; before returning, emit a clear INFO-level
log containing the bca_path and the actual bca.size() so malformed .bca files
are distinguishable from missing output. Locate the check around the
read_vector(bca_path) call and replace the silent return with: log an INFO
message (using the project’s logging facility) that includes the bca_path and
bca.size(), then return; keep the same early-return control flow and reference
_GC_BCA_STRUCTURE_SIZE in the message for clarity.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6222d8 and 93a5065.

📒 Files selected for processing (4)
  • dvd/dvd_dump.ixx
  • systems/gc.ixx
  • systems/wii.ixx
  • utils/hex_bin.ixx
🚧 Files skipped from review as they are similar to previous changes (2)
  • systems/wii.ixx
  • dvd/dvd_dump.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.

Actionable comments posted: 1

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

687-688: For multi-layer DVDs, has_bca reflects only the last layer's BCA flag.

The has_bca assignment inside the loop means it gets overwritten for each layer, and only the last layer's value is retained. While BCA presence is typically consistent across layers, consider assigning from the first layer (layer 0) which is authoritative, or using a logical OR to capture if any layer reports BCA.

♻️ Proposed fix to use first layer's BCA flag
                     // nintendo discs have first byte 0xFF
                     if(structure[sizeof(CMD_ParameterListHeader)] == 0xFF)
                         nintendo_key = 0;
 
-                    has_bca = layer_descriptor.bca;
+                    if(i == 0)
+                        has_bca = layer_descriptor.bca;
                 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dvd/dvd_dump.ixx` around lines 687 - 688, The current loop overwrites has_bca
with layer_descriptor.bca for each layer so only the last layer's value is kept;
change the assignment so has_bca reflects the authoritative BCA state by either
setting has_bca once from the first layer (e.g., when layer index == 0) or by
computing has_bca |= layer_descriptor.bca inside the loop to capture any layer
reporting BCA; update the code around the loop where has_bca and
layer_descriptor are used to follow one of these two approaches.
systems/wii.ixx (1)

68-70: Consider sharing BCA constants between GC and WII.

The BCA constants (_WII_BCA_STRUCTURE_SIZE, _WII_REPORTED_BCA_OFFSET, _WII_REPORTED_BCA_SIZE) are identical to those in gc.ixx. Since both GameCube and Wii discs share the same BCA structure format, consider extracting these to a shared location (e.g., a common Nintendo disc header or constants module) to reduce duplication and ensure consistency.

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

In `@systems/wii.ixx` around lines 68 - 70, The three BCA constants
(_WII_BCA_STRUCTURE_SIZE, _WII_REPORTED_BCA_OFFSET, _WII_REPORTED_BCA_SIZE) are
duplicated in systems/wii.ixx and gc.ixx; extract them into a shared constants
header/module (e.g., nintendo_disc_constants or disc_bca) and replace the local
definitions in systems/wii.ixx and gc.ixx with references to the shared symbols
(import/include the new module and use its symbol names), update any namespaces
as needed so callers (e.g., code that used _WII_BCA_STRUCTURE_SIZE) now
reference the single shared constant to remove duplication and ensure
consistency.
utils/hex_bin.ixx (1)

109-131: Consider adding a trailing newline for consistent output formatting.

The function does not append a trailing newline after the last line of output. When used in gc.ixx and wii.ixx (e.g., os << std::format("{}", rawhexdump(...))), this means the BCA hex dump won't end with a newline, which may cause the next output to appear on the same line or result in inconsistent formatting.

♻️ Proposed fix to add trailing newline
         ss << std::setw(2) << (uint32_t)data[i];
     }
 
+    if(size > 0)
+        ss << std::endl;
+
     return ss.str();
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@utils/hex_bin.ixx` around lines 109 - 131, The rawhexdump function currently
builds hex lines into std::stringstream ss but does not append a trailing
newline, causing subsequent output to appear on the same line; update rawhexdump
(the function signature rawhexdump(const uint8_t *data, uint32_t size, uint32_t
group_size = 2, uint32_t groups_per_line = 8)) to ensure a trailing newline is
added to ss before return (e.g., append '\n' or use ss << std::endl) so output
always ends with a newline when using ss.str().
🤖 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 829-834: The BCA data returned by cmd_read_disc_structure includes
a CMD_ParameterListHeader and must be stripped before further processing; call
strip_response_header(bca) immediately after the cmd_read_disc_structure call
(before any size checks or the write_vector call) so the vector contains the raw
192-byte BCA expected by systems/gc.ixx and systems/wii.ixx; keep the existing
branches around status and use the same image_prefix/WRITE logic (i.e., replace
direct use of bca with the header-stripped bca before writing or validating
against _GC_BCA_STRUCTURE_SIZE).

---

Nitpick comments:
In `@dvd/dvd_dump.ixx`:
- Around line 687-688: The current loop overwrites has_bca with
layer_descriptor.bca for each layer so only the last layer's value is kept;
change the assignment so has_bca reflects the authoritative BCA state by either
setting has_bca once from the first layer (e.g., when layer index == 0) or by
computing has_bca |= layer_descriptor.bca inside the loop to capture any layer
reporting BCA; update the code around the loop where has_bca and
layer_descriptor are used to follow one of these two approaches.

In `@systems/wii.ixx`:
- Around line 68-70: The three BCA constants (_WII_BCA_STRUCTURE_SIZE,
_WII_REPORTED_BCA_OFFSET, _WII_REPORTED_BCA_SIZE) are duplicated in
systems/wii.ixx and gc.ixx; extract them into a shared constants header/module
(e.g., nintendo_disc_constants or disc_bca) and replace the local definitions in
systems/wii.ixx and gc.ixx with references to the shared symbols (import/include
the new module and use its symbol names), update any namespaces as needed so
callers (e.g., code that used _WII_BCA_STRUCTURE_SIZE) now reference the single
shared constant to remove duplication and ensure consistency.

In `@utils/hex_bin.ixx`:
- Around line 109-131: The rawhexdump function currently builds hex lines into
std::stringstream ss but does not append a trailing newline, causing subsequent
output to appear on the same line; update rawhexdump (the function signature
rawhexdump(const uint8_t *data, uint32_t size, uint32_t group_size = 2, uint32_t
groups_per_line = 8)) to ensure a trailing newline is added to ss before return
(e.g., append '\n' or use ss << std::endl) so output always ends with a newline
when using ss.str().

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93a5065 and 2d08456.

📒 Files selected for processing (4)
  • dvd/dvd_dump.ixx
  • systems/gc.ixx
  • systems/wii.ixx
  • utils/hex_bin.ixx

@Didrole
Copy link
Contributor Author

Didrole commented Feb 26, 2026

@Deterous
I've changed the way the BCA is formatted to match your description, is it better now ?

WII [test.iso]:
  version: 0
  serial: RYWP01
  title: Big Brain Academy: Wii Degree
  BCA:
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 4D42 5554 0B0C 5B03 2201 2850
*** END

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)

820-835: Consider using consistent std::set lookup pattern.

The BCA handling logic is correct. However, line 824 uses readable_formats.contains() while the rest of the file consistently uses the find(...) != end() pattern (e.g., lines 646, 736, 853). Consider aligning with the existing style for consistency.

♻️ Optional: Align with existing lookup pattern
-            if(!readable_formats.contains(READ_DISC_STRUCTURE_Format::BCA))
+            if(readable_formats.find(READ_DISC_STRUCTURE_Format::BCA) == readable_formats.end())

Alternatively, modernizing all lookups to use contains() would also be valid.

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

In `@dvd/dvd_dump.ixx` around lines 820 - 835, The BCA branch uses
readable_formats.contains(...) which is inconsistent with the rest of the file;
change the lookup to the existing pattern using
readable_formats.find(READ_DISC_STRUCTURE_Format::BCA) != readable_formats.end()
(refer to has_bca, readable_formats, and READ_DISC_STRUCTURE_Format::BCA used in
this block) so the set lookup style matches other checks in this file.
🤖 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 820-835: The BCA branch uses readable_formats.contains(...) which
is inconsistent with the rest of the file; change the lookup to the existing
pattern using readable_formats.find(READ_DISC_STRUCTURE_Format::BCA) !=
readable_formats.end() (refer to has_bca, readable_formats, and
READ_DISC_STRUCTURE_Format::BCA used in this block) so the set lookup style
matches other checks in this file.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d08456 and b116995.

📒 Files selected for processing (2)
  • dvd/dvd_dump.ixx
  • utils/hex_bin.ixx

@Didrole Didrole changed the title WIP: BCA support BCA support Feb 26, 2026
@Didrole
Copy link
Contributor Author

Didrole commented Feb 26, 2026

It's ready for review now.

Copy link
Owner

@superg superg left a comment

Choose a reason for hiding this comment

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

Fundamentally OK, left some comments.

@Didrole Didrole requested a review from superg February 27, 2026 19:30
Copy link
Owner

@superg superg left a comment

Choose a reason for hiding this comment

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

LGTM.

@superg superg merged commit 1ccff3f into superg:main Feb 28, 2026
11 checks passed
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.

3 participants