VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

I know that the CD-ROM(ATAPI using sff8020i) reads use either LBA or MSF addressing. One thing I don't understand is the physical disk(in this case an iso file or cue-sheet) and it's effect on that addressing(the tracks and absolute disk addresses including pregap, postgap, audio and mode 1/2 data.

How is the LBA/MSF converted to the absolute (cue-based) address?

- What happens during the read (10/12) commands? How does pregap, postgap, track type affect this(besides only allowing mode 1/2 tracks)? How is the LBA address converted to the physical MSF address of the sector? How does pregap/postgap affect this? Does pregap add to the LBA/MSF address(move it after the pregap, essentially adding the pregap/INDEX 00 entry for the sector address)?
- What happens during the audio commands with pregap/postgap? Does it play those as zeroed blocks of audio?
- How do the track numbers affect all of it? Are they in effect at all during reads or playback(other than reporting them to software through the read TOC command)?

So, for example, what happens with a data track with pre and/or postgap?
And what happens during reading (by software) the pregap/postgap areas of an audio track?

Also, there's one command I can't quite identify the purpose of: the SEEK command. Is that purely for audio playback? Afaik it won't affect data track reads, as they are either locked to track 1 only or being seeked accross all tracks? Or does tracks say nothing except when reporting them in the TOC?
What happens with data tracks not at track 01? Or multiple data tracks? Or multiple data tracks with audio tracks(1 or more) between them?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 2 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

Yeah, I figured that out long ago.

But the main issue is: how is MSF and LBA during the read(10/12) and other data transfer and play audio commands applied to the disc? How do pregaps(also index 0), postgaps and track types(audio, data) applied to it? What happens when a data track has pregap/index0 or postgap?

And, which seems badly documented, what does the seek command do? The read(10/12) commands etc. have LBA or MSF in their parameters. So what purpose is the seek command even for?

And finally, what effect do tracks have on all of them? Are LBA and MSF addressing parameters always accross the entire disk? What happens if you interleave data and audio tracks(e.g. track 1 audio, track 2 data, track 3 audio, track 4 data) or any other random way(with multiple data tracks, or a data track not at track 1)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 3 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

So, looking at https://github.com/joncampbell123/dosbox-x/bl … cdrom_image.cpp :
- Pregap/Index 00 adds to the start MSF address, but is unreadable(returns zeroes for audio tracks) and fails reading with OOR(Out of Range) for data reads only(audio reads actually allow to read this for audio tracks only)? Also, Index 00 adds it's length to the file position, while pregap doesn't?
- Postgap does the same as pregap, but it's after the track instead?

Is that correct?

What happens to when the CD-ROM drive gets an instruction to read data? Does it detect the pregap/postgap and add 1 frame to the address to read as well as the current MSF address until it's not a pregap/postgap address anymore that it's checking? So what happens when you issue a MSF address inside the pregap/postgap area? Or past such an area? What about LBA addressing(the other addressing mode the ATAPI/sff8020i specification says exists)? Or does only LBA do the adding to both the requested and physical disc frame numbers?

So the read in MSF format actually reads that literal location(and reports if it's a PreGap/PostGap that's requested)?

But what happens when LBA is requested with multiple data tracks and audio tracks in between? How to convert the LBA to an actual MSF format when the pregap and postgap is variable(with multiple audio/data tracks in the cue file)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 4 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've just improved detection of pregap and postgap. They now both add to the physical(virtualized) address in cue images(meaning the physical medium reports a special result for them instead of reading said addresses) and moving the indexes further ahead on the medium(thus the software needs to skip past them and cannot address them), but doesn't affect them like index entries do(they don't add to the backend file position).

So, with them following cue:

FILE "somefile" BINARY
TRACK 01 MODE1/2048
PREGAP 00:02:00
INDEX 01 00:00:00
POSTGAP 00:02:00
TRACK 02
INDEX 01 00:02:00

That will make the physical disk layout like this:
TRACK 01:
00:00:00 - 00:01:74: pregap
00:02:00 - 00:03:74: data from file somefile at the 00:00:00 - 00:01:74
00:04:00 - 00:05:74: postgap
TRACK 02:
00:06:00 - EOF: data from 00:02:00 - EOF from file somefile

Is that correct?

Now the question, what happens when LBA or MSF addressing is used during playback and during reading? Is anything added to either of them? Using addesses into the ATAPI device: LBA 10 and MSF 00:00:10? What are the resulting addresses on the physical disk layout?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 5 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've just improved the cue image handling as follows:
- The cue parser now handles pregap/postgap as a special case. When pregap exists, it increases the physical location on the disk, but not the file backend.
- The pregap/postgap can be addressed using the cue's normal MSF format. When an attempt to access such an address, it reports a special value(-2 minus the amount of frames the gap has left until the start of the audio or data frame).
- Of course, reads at the pregap/postgap addresses won't read any data from anything, but will report it to the caller.

Then, on the IDE/ATAPI side:
When it detects until the track it's supposed to read, it takes the -2 or lower results and adds them to the LBA address to use instead when not reading and requesting audio tracks. Then, it will cause it to read zeroes for the pregaps for audio tracks(with the audio data following it) when reading audio. When reading data, it will instead skip the track addresses for both audio and data, but add any gaps to the LBA address until it can read the LBA address from any track. When that's detected, the track loop is aborted and the normal read and conversion(between different sector formats) is done on the last sector it found(or out of range).
Thus, any out of range exceptions still happen, but audio tracks include the silent track on reading, while data tracks instead skip them.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 6 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've been fixing some of the bugs with the cue image reads. It should work fine now(at least reporting the proper start of the track in the used cases). Postgap might still be unhandled, but shouldn't pose much of a problem, unless postgap is added for multitrack data CD-ROMs(where tracks contain data after the first data track with postgap).

Edit: After testing a bit, the pregap seems to work without problems now. Didn't manage to test the postgap yet, though. It might need a little bit more code to be fully supported for data reads(multiple data tracks or data track not at track 01).

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 7 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

Just added the postgap area reporting modifications to the cue image handling itself. Then I added the postgap area detection and skipping to the tracks after the tracks that had postgaps. Thus properly shifting audio and adding silence when the postgap is used, as well as properly handle data reads for that case as well now.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 8 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

Now that the whole cue image is working properly(afaik), it's time for the next step: audio CD-ROM playback support. I've already modified and prepared the values in the mode status pages to report it's supported(but the cd-rom configuration(volume etc.) is still unconfigurable as of now, all that's left for that is the actual CD-ROM commands for playback(commands 4B PAUSE/RESUME, 45 PLAY AUDIO (10), 47 PLAY AUDIO MSF and of course 4E STOP PLAY/SCAN for stopping playback). And of course, after that the volume support(and enabling the code).

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 9 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

Just ran my new code for the first time. Earthworm Jim 1 tries to first execute the pause/resume command a few times(nothing is playing yet), then executes PLAY AUDIO MSF.

That somehow ended up with an invalid track type being detected, thus aborting?
Now added the 2 seconds 'Pregap' as the sff8020i documentation says...

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 10 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

Hmmm... It still fails...

Just found a little 'bug': the MSF address was getting converted to and from LBA using BCD to binary and binary to BCD conversions, messing up the translations made for checking the requested addresses and performing calculations on them(adding sectors to skip stuff etc., pre/postgap calculations) 😖

Now having fixed that, it's once again running the application again(which takes a while to get to the correct point due to Earthworm Jim taking a long time to get to the main menu screen(the loading phases take pretty long due to needing to do a lot of processing and data it seems)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 11 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

Just found some more bugs in the cue image reporting of tracks and pregap/postgap. It wasn't correctly registering the end of a pregap/postgap/track when requested to give said information(taking into account the request for pregap/postgap only modes).
As well as the reporting of the end of the last disk track instead of the specified track end 😖

Edit: Then I've found some more problems with the scanning (with pregap/subgap) and track information retrieval for audio playback.
And I also found the bug of forgetting to clear the track/subtrack filter when actually reading the audio data from the disc(it was left at the final track of the disk from the track information retrieval routine).

Edit: Whoops. Another little bug found in the rendering code itself this time. It was fetching new frames from the CD-ROM disc when it was rendering each sample 😖

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 12 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

Hmmm... Strange... Playback is working, but the commands that are executed say that the Pause/Resume command are executed with byte 8 bit 0=0, meaning to pause the audio? Thus no more music is rendered with Earthworm Jim 1?

Last edited by superfury on 2019-07-26, 19:55. Edited 1 time in total.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 13 of 13, by superfury

User metadata
Rank l33t++
Rank
l33t++

Just been adding more functionality. It now supports the full read subchannel format 1(with all fields properly filled). 😁

Just tried some old MS-DOS app named "CDPlayer v2.25e" from http://dosprograms.info.tt/sound.htm . It seems to play the first audio track(when using an audio disk) correctly, but three strange things occur:
- Changing to the next track somehow doesn't have any effect? It will still play track 1.
- The time properly increases(relative track time), but the track number is fixed at 0(even though the hardware reports it as track 1)?
- It keeps saying some seek error(6) due to trying to seek to an invalid location(which errors out)?

Edit: Fixed the track number display. It seems that the read sub-channel command wasn't filling the ADR/Control and Track number bytes(instead giving them for format 3, which is the ISRC data block instead 😖

The next track feature still doesn't seem to properly work?

Just tried another player, the one called "SJGPlay v1.29". It seems to play the CD-ROM without issues?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io