don't click here

SEGA CD Mode 1 Player

Discussion in 'Technical Discussion' started by Chilly Willy, Dec 17, 2011.

  1. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    There's been a lot of talk since the release of Sonic 1 with Redbook Audio, mainly people asking for code. I can see why they might not want to post their code since it's probably hacked into Sonic 1 pretty bad. However, there still exists a need to show how to use Mode 1. To that end, I did a small demo - this is a tiny CD player done using Mode 1 of the SEGA CD, and includes full source. From this, you should get a good idea of how Mode 1 works. If not, ask questions in the thread here and I'll answer them. THIS is the place for Mode 1 questions, not the Sonic1Mode1 thread.

    The project was compiled with my gcc toolchain, but it wouldn't take much work to convert the code to whatever you normally use. The player goes beyond what you would use in a game, but it's an example.

    Controls:
    A - play from current track to end of disc
    B - play current track once
    C - stop playing
    X - show current track info
    Y - play current track repeatedly
    Z - pause/resume
    START - check disc

    Notes: The TOC is invalid until you check the disc. The CDBIOS doesn't initialize its TOC until you call DRVINIT (which is what my check disc routine does). So when you first start the player, the status may show wildly wrong disc info (first and last tracks being over 99, e.g.). If the tray/lid is open, it will show that. Insert a disc and press START - you should get proper disc info after the status is done showing "Reading TOC" and goes to "PAUSED". The current track may not be the same as the playing track - you can start a track playing and then change the "current" track to something else. Pressing X to see the track info shows the info for the current track displayed on the screen, not the track playing. The track info consists of the track time and track type; the track type is pretty straightforward - it's either a DATA track (track 1 of mixed mode discs), or a CDDA track for audio tracks. The track time shows the BCD minutes/seconds/frames/track number as MMSSFFTN. It shows where the track starts, while the track number is the same as the track number you asked for info on, or 00 is an error occured.

    While this example is a CD audio player, I could have easily also read data discs, showing sector data. I did the audio player since that's mainly what people wanted - to see how to play CDDA from a game in rom. The Sub-CPU program is really simple - wait for commands from the Main-CPU, then do them. The commands all pertain to handling the CD audio, but they could as easily use the ASIC, use the PCM chip, read data from sectors, etc. When I start doing some ASIC tests, this will be the test bed to start from as it's easier for me to write the test file to SD card and run in Mode 1 than to keep burning CDRs.

    I've tested this on a Model 2 Genesis + Model 2 CD and on a CDX. Let me know if you have any trouble on other models, but it SHOULD work on anything.

    mode1player.zip

    Update - 20111219: Should work WonderMega and X'Eye and might work on LaserActive; also inits drive on startup if a disc is in place from the start.
    mode1player2.zip

    Update - 20111228: It's been tried on the LaserActive and doesn't work. Still looking into the issue there, but it's currently the only system known not to work.

    Update - 20120105: Now works with LaserActive.

    Mode1Example-20120104.zip
     
  2. Aerosol

    Aerosol

    Not here. Moderator
    11,163
    573
    93
    Not where I want to be.
    Sonic (?): Coming summer of 2055...?
    I don't know anything about sega cd emulation. How do I get this running with Kega Fusion 3.63?
     
  3. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    You don't. This is so new, nobody supports it. Maybe with an example out, emulation authors might add it to their next update.
     
  4. theocas

    theocas

    Tech Member
    346
    0
    16
    ...of course it works on emulators.

    It works on Kega Fusion. It just involves some secret code. Only works on Fusion though, since all other emulator authors that support Sega CD are too lazy to implement this.

    Hint hint.

    [​IMG] :V
     
  5. Aerosol

    Aerosol

    Not here. Moderator
    11,163
    573
    93
    Not where I want to be.
    Sonic (?): Coming summer of 2055...?
    Thanks theocas.

    This is pretty neat. When I'm back on my own computer I'll take a closer look at it. Not that I'll figure it out on my own :P
     
  6. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    Thanks for the info on Kega - good to see at least ONE emulator supports it. Of COURSE it would be Snake's. :)

    EDIT: Just set up 3.63x for linux - my demo works great! Well, now I have an emu I can test stuff like this on besides real hardware. I normally use Gens_GS, but it doesn't seem to support Mode 1.
     
  7. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    1
    0
    Writing my own MD/Genesis sound driver :D
    MCD emulator authors aren't lazy; the Mega CD isn't something that has been well-explored, though we do have some niche discussions (like that Mega LD discussion going on now on SpritesMind). Though given how much you two know about the Mega CD, why don't you two step up to the plate? :) I'm not a hardware engineer so I really can't help that much; the only thing I can do is analyze the Mega CD BIOS given what we know and I have too much on my plate as it is so sorry :/

    (though IDK but I think getting the VDP decapped and analyzed so might be something more important first)
     
  8. Flygon

    Flygon

    Member
    Doesn't work on my Sega CD drive. Given the Sonic 1 Mode 1 demonstration works perfectly, something's gone on your end.
     
  9. Aerosol

    Aerosol

    Not here. Moderator
    11,163
    573
    93
    Not where I want to be.
    Sonic (?): Coming summer of 2055...?
    Sonic 1 mode 1 doesn't work for me though, so you can't be so sure. Or maybe you can I dunno :v:
     
  10. Flygon

    Flygon

    Member
    And this, ladies and gentlemen, is why homebrewers generally don't bother with the Sega CD's bitchiness. :v:
     
  11. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    What model/region is it? Need a little more info to go on. :)

    Does it give an error message? How is it not working?
     
  12. Flygon

    Flygon

    Member
    No error messgae. European Sega Mega CD II, revision 2.0.0. European Sega Mega Drive II, modified but set to default settings. And I doubt CCAM is breaking the mod. :v:

    If you were testing with a Model I CD drive, this'd explain so much.

    Basically, it sure as heck detects the tracks, even tells me how the CD drive goes. Only failure? No audio plays. I'll check if the drive actually revs and spins for audio playback when I'm not about to be a personal taxi driver.
     
  13. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    I've tested with a US Model 2 and a CDX. If it does everything but play audio, it's finding everything it needs and initializing okay. You did push START before trying to play tracks, right? As I mentioned in the OP, when the CD first starts up, it usually has a bad TOC, and checking the disc reads the TOC so it can actually play the tracks. Also, don't try playing data tracks (track 1 on mixed mode discs) - I'm not sure what it would do.

    EDIT: When you try to play a track, it should briefly (sometimes too brief to see) say "NOT READY", then it should say "SEEKING" and then finally say "PLAYING".
     
  14. sasuke

    sasuke

    Member
    66
    0
    0
    Good. I was actually going to try to make one of these myself, but I had no time because of finals. Good to see a working demo, though.
     
  15. Flygon

    Flygon

    Member
    Sorry about the delay, managed to get it working with rereading the TOC. I cannot believe I missed such an obvious step. Sorry.
     
  16. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    No problem - did it myself the first time or two. :)

    In any case, I've experimented and found that this is a problem when you start with a disc in the CD. If you start without a disc, open the tray, and insert a disc, it automatically reads the TOC. You only have to do the check the first time if you started with a disc in place. So I can improve the code by making the CD init look if the tray is open or there's no disc. If there IS a disc to start, do the check automatically, and not worry about it when you change the CD.

    But this is part of why I posted this app the way it is - it gives us a look inside how the CD operates at a level we don't normally see, and we learn a few things as a result. So thank you for checking this out the way you did. Thanks to anyone else who has tried this, too. :)
     
  17. Aerosol

    Aerosol

    Not here. Moderator
    11,163
    573
    93
    Not where I want to be.
    Sonic (?): Coming summer of 2055...?
    Also sorry for the delay, but I've got a bug!

    So let's say I've loaded the rom, and the audio image. I'm playing the first song and decide to play another one...

    It'll play the first song anyway! Until I press start to "check disk", this will continue to happen. After I've done this, I can change the tracks like normal.
     
  18. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    We just talked about that - it's from the fact that when you start the CD with a disc in place, the TOC is not valid. You have to do a DRVINIT to make it read the TOC. That's ONLY when you start the CD with a disc in place. Press START to make my code do the DRVINIT. Note that you don't have to do that later if you SWITCH discs as the CD will automatically read the TOC when you switch. It's just not automatic on startup. It's not a bug in my example, it's a "bug" in the CD BIOS. Now, knowing this bug, you can work around it by adding DRVINIT to the startup IF there is a disc already in place. You can't ALWAYS do the DRVINIT because doing so without a disc in place would cause the BIOS to go into the wrong state.

    This is example code designed for probing the inner workings of the CD, so there's many safeties not observed that I would add if I were to use this in a game. For example, I'd check if the disc was still in before playing/pausing/etc. I'd do the automatic DRVINIT on startup if the disc were already inserted. I would check that the track is CDDA before playing. Things like that.
     
  19. Aerosol

    Aerosol

    Not here. Moderator
    11,163
    573
    93
    Not where I want to be.
    Sonic (?): Coming summer of 2055...?
    Oh I didn't realize we were talking about the same thing. My bad.
     
  20. Maxd

    Maxd

    Member
    661
    0
    0
    Alabama
    Mixin'
    Just curious - I noticed that your init code is very similar to S1M1's in some instances. What were the major corrections you saw in your design over the original?