CDROM reading speed

Ask anything your want about Mega/SegaCD programming.

Moderator: Mask of Destiny

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

CDROM reading speed

Post by Fonzie » Sun Jan 21, 2007 6:20 pm

Hi :)

I have some troubles to reach maximum reading speed on megacd hardware.

It is theoricaly situated around 150KB/second.
However, even if emulators allow a such fast rate, on real hardware, i cannot barely go over 96KB/sec. :'(

Some FMV games are supposed to be 100-150 KB/sec bitrate so I wonder how they do :?

Actualy, i do this:
0-Read 1 Second of GFX frames (while reading, fill 1 second of PCM playback data)
1-Read 1 Second of PCM data (in a buffer, will be copied to pcm ram during next read)
2-Wait PCM synchro
3-Wait MainCPU ready (it is always ready since playing a bit faster)
4-Flip 128KB ram

I don't know where the problem is... I even tried to SEEK cdrom few ms before next read but it randomely hang and dont fix the problem at all.

I don't know what to remove to speedup the thing...
For exemple mcd_wait_cdc_stat(); is used to wait if prepared data is present... however, it appear to slowdown a bit the process...
I can provide source code, just PM me :)

Thx for your answers.

Stef
Very interested
Posts: 3037
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Jan 22, 2007 7:57 am

Something important when you want to "optimise" the CDROM speed is the Seek function. Always try to seek the next sector you plan to read. Maybe you're already doing it...

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie » Mon Jan 22, 2007 4:11 pm

Well, in fact, segacd bios have a seek function... but in my case... i really wonder how i can use it...

Each time i tried to use it , it randomely crashed the thing... :/
You know, I read data in streaming.

Well, i'll try again.

I'm just disapointed that nor Kega or Gens emulate CDROM seek/read times correctly...

Stef
Very interested
Posts: 3037
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Jan 22, 2007 7:43 pm

In fact in Gens i simulate a x1 CDROM speed but i've to admit i just ignore the seek time. Anyway if you're reading sector by sector, as soon you receive data, launch the next sector read then do your data transfert...
I never developed on Mega CD, i don't know exactly how handle it :o
Last edited by Stef on Wed Jan 24, 2007 11:24 am, edited 1 time in total.

Mask of Destiny
Very interested
Posts: 591
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Wed Jan 24, 2007 5:29 am

Are you using DMA for your transfers? The 68K is so slow when it comes to doing memory access I would imagine it could become quite a bottleneck.

I never quite got around to looking at how the various FMV enabled games did their DMA. I would imagine that you would need to get the DMA copy of the first sector going at the same time that the second sector is being read from the disc into the disc buffer. I have no idea how you would go about doing that on the Sega CD though. Ideally you'd set up the hardware to do a read of multiple sectors at once so the drive doesn't have to wait for the disc to rotate back into position again before it can start reading the next sector. Not sure if the Sega CD hardware supports that though.

Unfortunately I stopped my Sega CD reverse engineering efforts before I figured out the proper way to do all this.

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie » Wed Jan 24, 2007 7:30 am

I see... but i load 128KB imediately (no wait, no sector dropping), i think my lag comes from the gap to wait PCM sample to finish (so the cdrom drive pass the next sector and need to go slighty back)...

Since it happen every second, i thought it could be ok.. It is not :/

I think DMA is just to get more 68K cpu time between each sector read (sector read from 68K don't halt the CDROM read as far as i know).


----------
There is also a buffer thing... Segacd functions are quite obscure.
Because if i miss one sector, the CDC buffer (up to 5 sectors) is full.. To get effectively the good sector very fast, i just wonder if the CDC need to be fully flushed or if it requires something else.

Well, i'm sure it is not emulated properly in both gens and kega (the cdc buffer thing).

I tried to do HALT an UNHALT to halt reading during my PCM synch... It hang almost all the time.
I also tried to use SEEK, but it slowdowned even more the thing.

I think i need to bypass the segacd bios and get in touch directly with hardware :/

----------

I have a full thing ready, even artworks... too bad i hang there!

Thx

Stef
Very interested
Posts: 3037
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Jan 24, 2007 11:40 am

Fonzie wrote:I see... but i load 128KB imediately (no wait, no sector dropping), i think my lag comes from the gap to wait PCM sample to finish (so the cdrom drive pass the next sector and need to go slighty back)...

Since it happen every second, i thought it could be ok.. It is not :/

I think DMA is just to get more 68K cpu time between each sector read (sector read from 68K don't halt the CDROM read as far as i know).


----------
There is also a buffer thing... Segacd functions are quite obscure.
Because if i miss one sector, the CDC buffer (up to 5 sectors) is full.. To get effectively the good sector very fast, i just wonder if the CDC need to be fully flushed or if it requires something else.

Well, i'm sure it is not emulated properly in both gens and kega (the cdc buffer thing).

I tried to do HALT an UNHALT to halt reading during my PCM synch... It hang almost all the time.
I also tried to use SEEK, but it slowdowned even more the thing.

I think i need to bypass the segacd bios and get in touch directly with hardware :/

----------

I have a full thing ready, even artworks... too bad i hang there!

Thx
Bypassing the BIOS and getting hands directly in the hardware would be very diffcult IMO. There are so much things to know and take care about...
I did many reverse engineerning in Gens for the CDC as no good documents exist about it. As said Mask of Destiny you should continue to read sector during your data transfert. If you want to reach the 150 KB/s, the CD should read data in continu.

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie » Wed Jan 24, 2007 2:02 pm

"should continue to read sector during your data transfert. "
Yeah, of course, i'm already doing this...
I don't stop reading (exept if i loose a sector).

So... i don't know where is the real problem :/

Stef
Very interested
Posts: 3037
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Jan 24, 2007 2:23 pm

Fonzie wrote:"should continue to read sector during your data transfert. "
Yeah, of course, i'm already doing this...
I don't stop reading (exept if i loose a sector).

So... i don't know where is the real problem :/
Err strange, i can help you if you want to do some low level access but i warn you that would be a hard piece !

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie » Wed Jan 24, 2007 3:22 pm

Maybe i should show you my C code...
In fact, it is very hard to know what is wrong...

Here is my "loading code"... for each sector.
This code was tested and validated, it works... But is it fast when we miss sectors?

It can be three possibilities:
-"sector in ze slot"
-"Curently loading sectors (still not good one)"
-"Fok, we missed one sector, need to retry"

I just wanted to know if the
-"Fok, we missed one sector, need to retry"
section appeared ok to you?
Do i need to flush? Do i need to flush more? Do i need to stop CDC?

Code: Select all

                  for(j=0;j<togo;)//Dl one frame
                    {
                      //Read 1st sector and determine togo :P
                      mcd_wait_cdc_stat();
                      mcd_cdc_read();


if(stats2sectors(biosrts[1])==currentsector+j)//Sector is in ZE SLOT!
                          { 
                            //ReadDATA (one sector)!
                              mcd_cdc_ctrn(destaddress); //Validated
                              mcd_cdc_ack();
                            
                            //Tell CDC that one frame is read, plz show next frame?
                            pcm_progress();
                              destaddress+=2048;j++;
                           }
else if (stats2sectors(biosrts[1])<currentsector+j)//Curently loading sectors (still not good one)
                          {
                            
                            mcd_cdc_ctrn(0x10000);
                            mcd_cdc_ack();
                          }
else if (stats2sectors(biosrts[1])>currentsector+j)//Fok, we missed one sector, need to retry
                          {
                            mcd_cdc_ctrn(0x10000);
                            mcd_cdc_ack();
                            mcd_cd_rom_read(currentsector);
                          }
                    }

Gerrie
Interested
Posts: 16
Joined: Tue Dec 12, 2006 9:33 pm
Contact:

Post by Gerrie » Wed Jan 24, 2007 9:58 pm

I recently uploaded a datasheet of an IC which is compatible with the CDC used in the SegaCD to Eidolon's Inn. This document might be usefull to get better understanding of the CDC.

http://www.eidolons-inn.net/tiki-downlo ... fileId=271

Stef
Very interested
Posts: 3037
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Jan 25, 2007 10:22 am

Hi Gerrie !

Glad to see you here :)
Do you plan to do some genny dev :p ?

I think your document is even more complete the one i used for megaCD CDC/CDD emulation development (i got something similar but not as clean and complete)

Gerrie
Interested
Posts: 16
Joined: Tue Dec 12, 2006 9:33 pm
Contact:

Post by Gerrie » Fri Jan 26, 2007 12:54 am

Hi Stef :D

Hehe no.. I will stick to emulation dev for now, but I'm very interested to see how the homebrew genny scene is coming along. It's good to see that a lot of people still are making things for those good old consoles, that motivates me .

I had that datasheet floating around for a few years on my harddisc until I rediscovered again, and wanted to share it. It's very difficult to find good documentation about the SegaCD's cdrom unit. So I thought it might be usefull to you guys.

Stef
Very interested
Posts: 3037
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri Jan 26, 2007 3:12 pm

Gerrie wrote:Hi Stef :D

Hehe no.. I will stick to emulation dev for now, but I'm very interested to see how the homebrew genny scene is coming along. It's good to see that a lot of people still are making things for those good old consoles, that motivates me .

I had that datasheet floating around for a few years on my harddisc until I rediscovered again, and wanted to share it. It's very difficult to find good documentation about the SegaCD's cdrom unit. So I thought it might be usefull to you guys.
I would love to do something really nice for the genesis.
I'm working on a library to help genny dever but aside that i also want to do my own programs :)

Thanks for your document, it's is the must have SegaCD doc, very hard to find !

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie » Wed Jan 31, 2007 11:33 am

With the help of steve, i tried the fallowing things:


rom_pause_on ... rom_pause_off
:arrow: Slowdown even more and hang randomely

rom_pause_on ... rom_read
:arrow: hang imediately

rom_seek ... rom_pause_off
:arrow: Slowdown even more (like 24KB/sec)

Well, i'm a bit disapointed... Most fmv games certainely do something to avoid slowdown... I'm extremely surprised that pause_on...pause_off sux.

Steve told me to put dummy data to reach maximum bitrate and avoid any seeking problem between each chunk of 1second fmv... That would work but it is extremely "sad" method.

Thx for your help.

Post Reply