Skip to content

fix(vromtool): keep ADPCM-A samples within 1 MiB pages - #178

Closed
imshah-id wants to merge 4 commits into
dciabrin:masterfrom
imshah-id:fix/adpcm-a-page-boundaries
Closed

imshah-id wants to merge 4 commits into
dciabrin:masterfrom
imshah-id:fix/adpcm-a-page-boundaries

Conversation

@imshah-id

@imshah-id imshah-id commented Nov 1, 2026 •

Copy link
Copy Markdown

Closes #174.

Depends on #176, which is still open. This branch includes its existing commit 52e14de5 so page placement builds on identical-sample sharing; that commit retains its original authorship.

Move each new ADPCM-A sample to the next 1 MiB page when its inclusive end would cross the page containing its start. Duplicate samples reuse the already aligned location. An explicit capacity condition advances to the next V-ROM when page padding no longer fits. Reject samples larger than a V-ROM or ADPCM-A samples larger than a page.

Six focused ADPCM-A regressions pass with Python 3.14 and PyYAML (python -m unittest discover -s tests -v). They cover the reported earthquake offsets together with duplicate sharing, exact page endings, ROM rollover, impossible allocations, generated padding/sample bytes, and ASM addresses. The boundary and ROM-padding cases verify that the placement change neither discards nor misplaces sample data.

The platform cross-compiler/example build and hardware or emulator playback were not run locally.

Comment thread tools/vromtool.py
f = None
for s in smp:
if vrom_pos+len(s.data) > vrom_size:
if len(s.data) > vrom_size:

@dogruis dogruis Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of leaving all that logic in the for loop you could put this in a method and name it accordingly.

Comment thread tools/vromtool.py Outdated
if isinstance(s, adpcm_a) and len(s.data) > 0x100000:
error("ADPCM-A sample '%s' is larger than one 1 MiB page" % s.name)
while True:
# ADPCM-A start and inclusive end addresses must share a 1 MiB page.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment comes from the fact that the code is not self contained and named properly

Comment thread tests/test_vromtool.py Outdated
@@ -0,0 +1,80 @@
"""Regression tests for ADPCM sample placement and generated V-ROM data."""

@dogruis dogruis Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks AI generated. vromtool doesn't have tests but good to have

Comment thread tests/test_vromtool.py Outdated
vromtool.allocate_samples(samples, 2 * PAGE, "sampleX.rom")
self.assertEqual([s.start for s in samples], [0, PAGE - 0x100, PAGE])

def test_adpcm_b_can_cross_page(self):

@dogruis dogruis Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not needed! The pagination issue only concerns ADPCM-A.

Comment thread tests/test_vromtool.py


class SampleAllocationTests(unittest.TestCase):
def test_adpcm_a_crossing_page_moves_to_next_page(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That should be the only test in this test class if the owner of the library wants it. The rest is testing random vromtool features and out of scope for this ticket. They should land in a separate ticket.

Comment thread tests/test_vromtool.py Outdated
sample(vromtool.adpcm_a, "next", 0x100)]
vromtool.allocate_samples(samples, 2 * PAGE, "sampleX.rom")
self.assertEqual([s.start for s in samples], [0, PAGE, PAGE + 0x2300])
for s in samples:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This for loop is not needed it is redundant with the line above

@dogruis dogruis left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I left enough comments before reviewing this mr again

Comment thread tools/vromtool.py Outdated
if vrom_pos+len(s.data) > vrom_size:
if len(s.data) > vrom_size:
error("Sample '%s' is larger than one VROM" % s.name)
while True:

@dogruis dogruis Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Besides event driven work I never had to write a while true.

@dogruis

dogruis commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

I am dubious of your solution! It should be built on top of the work that will go in the main branch here

@dciabrin

dciabrin commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Closed via #180

@dciabrin dciabrin closed this Nov 4, 2026
@imshah-id
imshah-id deleted the fix/adpcm-a-page-boundaries branch November 4, 2026 21:23
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.

vromtool places ADPCM-A samples across a 1 MiB page

3 participants