Skip to content

pbp: fix last track length computation (lead-out) - #951

Merged
notaz merged 1 commit into
libretro:masterfrom
hsyysy:pbp-last-track-length
Nov 26, 2026
Merged

notaz merged 1 commit into
libretro:masterfrom
hsyysy:pbp-last-track-length

Conversation

@hsyysy

@hsyysy hsyysy commented Nov 26, 2026

Copy link
Copy Markdown

handlepbp() computes the last track's length from start_offset, which is
the INDEX 00 (pregap) start:

ti[numtracks].length = cd_length - ti[numtracks].start_offset / 2352;

cd_length is the lead-out from the PBP TOC (a2), and ti[].start is the
track's INDEX 01. trackinfo.length is documented as "readable sectors,
excludes gaps", so the length should be:

ti[numtracks].length = cd_length - ti[numtracks].start;

As written, the last track includes its 2 s pregap, and GetTD(0) reports a
lead-out that is 150 sectors too long.

For example, a multi-track PBP whose TOC lead-out is 30:00:00 currently
returns 30:02:00 from GetTD(0). Games that sanity-check the TOC can hang:
"大富翁之笑笑江湖" (a Chinese bootleg with a fake SLUS-01272 ID) stops on a
black screen right after the intro with the old code, and reaches the title
and character-select screens with this change.

Tested with the libretro core on an RK3566 / Mali-G52; CAPCOM VS SNK still
boots normally. Build-tested with make -f Makefile.libretro platform=unix.

Note: the image used for the test stores its PBP blocks uncompressed
(PSX2PSP with compression off); loading it additionally needs a small local
loader patch that is not part of this PR. The TOC arithmetic is independent
of that.

The last track length is lead-out minus the track INDEX 01 start.
handlepbp() used start_offset, which is the INDEX 00 pregap start, so
the last track (and the reported lead-out) included the pregap and was
two seconds (150 sectors) too long for the usual 2 s pregap.

The trackinfo comment says length excludes gaps, and games that check
the TOC with GetTD can hang when the lead-out is wrong.  With this
change GetTD(0) matches the lead-out from the PBP TOC.
@hsyysy

hsyysy commented Nov 26, 2026

Copy link
Copy Markdown
Author

The uncompressed-block loader patch for the image used in the test: #952.

@notaz
notaz merged commit 830e0d7 into libretro:master Nov 26, 2026
7 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.

2 participants