ekeeke / Genesis-Plus-GX

An enhanced port of Genesis Plus - accurate & portable Sega 8/16 bit emulator
Other
673 stars 193 forks source link

What does MD+ command 18h do exactly? #504

Closed ArcadeTV closed 1 year ago

ArcadeTV commented 1 year ago

I was wondering what MD+ command 18h does. https://github.com/ekeeke/Genesis-Plus-GX/blob/1db51e2c5fb29fb1305683705e8f007a18341d97/core/cart_hw/megasd.c#L689

Does it transfer any data within a given sector or can I use it to get the current time of a track that is playing? While thinking about porting my MSU-MD hack of SONIC to MD+ I came across this and was hoping I could get the current sector of a music track that is playing and then use 1Bh to play a different track that is the same music but faster. I would calculate the sector to seek to by the ratio of both tracks and the value I was hoping to get from command 18h.

Thanks for clarifying!

ekeeke commented 1 year ago

Afaik, it is to be used with command 0x17 (request read of specific sector) and command 0x19 (request read of next sector): once the sector is read into internal CD memory, you can request a direct transfer to Mega SD buffer RAM (accessible directly from overlay interface). On real Mega CD, you have to use specific BIOS commands to do this, the goal is I guess to make access to CD data easier.

In my implementation, this is limited to the data track though (not sure about MegaSD flashcart implementation) as I do not see any interest in reading audio track samples this way in software.

I am not sure to understand 100% what you want to do but I don't see how this command could help for audio playback, it is for reading data from disk in software and do something with it for your game processing. I might be wrong but I think its main purpose is for video playback (like SNES MSU).

ArcadeTV commented 1 year ago

I was looking for an option to get the currently read sector/position of a track and then use that to calculate a value to seek to a position of another song. See, when Sonic gets the sneakers, the music speeds up. To do this with CDDA I would need to know what's the current position in the BGM and then play another track seemlessly (which is the same music, but with higher speed), so I'd need to calculate the ratio between both tracks and jump to the correct position/sector in the higher-speed-music.

I thought the Transfer last read sector would give me the value of the last read sector instead of the data, so I'm out of luck I guess.

Thanks for taking the time to explain this!