Sega CD Mode 1 support functions for SGDK

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

Post Reply
mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Sega CD Mode 1 support functions for SGDK

Post by mikejmoffitt » Sat Sep 26, 2015 9:48 pm

Hi everyone, first post here but it looks like the place to go for Sega development. I've been working on porting Lyle in Cube Sector to Sega Genesis and I thought it would be neat to offer the ability to put in a deluxe soundtrack CD to get the original game audio, so I set about implementing Mode 1 support.

Chilly Willy's example player code was very helpful, but much of it is not broken into neat functions and it relies on a lot of externally defined ASM code as well. My goal was more or less to rewrite it in a way that's a little less integrated into the player example so it can be used in other places. It's not finished yet, but it's finally working enough that it is somewhat presentable and it works in the game. I will probably add some more functions and clean it up a little, and give it a little repo with integration instructions. It relies on a little of the assembly provided with the original demo, but much less than before. I tried to give things clear function names so usage is clear.

You can look at what I have so far here: https://github.com/Mikejmoffitt/LICS/bl ... /cdaudio.c

Here is a video of it working: https://www.youtube.com/watch?v=P20fGWXYXaI

User avatar
Sik
Very interested
Posts: 562
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Sega CD Mode 1 support functions for SGDK

Post by Sik » Mon Sep 28, 2015 4:18 pm

Am I the only one who's tired of it being called mode 1? (mode 1 is the Mega CD firmware booting the game from the cartridge and it doesn't work at all without the Mega CD being connected) I'd rather call this "mode 0" if we insist on giving it a name, but I don't like things that result in misinformation.
Sik is pronounced as "seek", not as "sick".

mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Re: Sega CD Mode 1 support functions for SGDK

Post by mikejmoffitt » Mon Sep 28, 2015 4:34 pm

I'm just calling it what people are already calling it, I don't care what name it's given as long as it's consistent.

Chilly Willy
Very interested
Posts: 2466
Joined: Fri Aug 17, 2007 9:33 pm

Re: Sega CD Mode 1 support functions for SGDK

Post by Chilly Willy » Wed Jul 05, 2017 4:54 pm

Sik wrote:Am I the only one who's tired of it being called mode 1? (mode 1 is the Mega CD firmware booting the game from the cartridge and it doesn't work at all without the Mega CD being connected) I'd rather call this "mode 0" if we insist on giving it a name, but I don't like things that result in misinformation.
Hmm - sorry about the necromancy, but it IS on topic and I didn't see this until recently...

I called it "mode 1" because that's what SEGA called. It's part of the MEGA-CD BIOS Manual, specifically page 30. Mode 1 is when you boot from a cart (it specifically says "Boot from cartridge", not boot CD firmware and look at cart), manually setup the CD BIOS, and init the CD. I think you misunderstood that part of the manual thinking it was referring to the CD BIOS looking for a special signature in the cart area and then loading the sub-cpu program from the cart. That's not what the manual describes at all. It clearly states the MD side is booting from the cart, which means the CD side firmware is not active. The CD side is described as being held in reset until the MD side finishes setting up what the CD needs to run and releasing the reset. The entire sequence described in the manual is exactly what the "mode 1" code I published does.

That's beside the fact that the mode where the MD boots the firmware and looks for a special signature in the cart area is not actually present in all models, and is not described in any form in the BIOS manual.

User avatar
KanedaFr
Administrateur
Posts: 1102
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: Sega CD Mode 1 support functions for SGDK

Post by KanedaFr » Wed Jul 05, 2017 4:59 pm

If I remember, you already answered to Sik on Sega16 back then, when you released your Mode1 demo ;)

(I read a lot on this topic lately, it's how I know!)


And, to the topic, it's exactly what's I'm doing this week ;)
RAW port was done, I'm trying to make it clear and easier to use before release

User avatar
Sik
Very interested
Posts: 562
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Sega CD Mode 1 support functions for SGDK

Post by Sik » Wed Jul 05, 2017 5:30 pm

Chilly Willy wrote:That's beside the fact that the mode where the MD boots the firmware and looks for a special signature in the cart area is not actually present in all models,
Only the LaserActive lacks it, which happens to be also the one firmware modified to have two BIOSes, and the only one where the CD BIOS data isn't aligned to a 32KB boundary at that. The other firmwares were cosmetic changes and adapting the BIOS to different CDCs, the LaserActive one seems to have had bigger changes internally so it's no wonder they decided to remove a feature that ended up going unused.
Chilly Willy wrote:and is not described in any form in the BIOS manual.
This is another problem. The Mega CD docs feel like a trainwreck compared to the Mega Drive docs, information is either spread all over the place (often in irrelevant locations) or outright missing making it a freaking pain in the ass to figure out how anything works at all. I still can't remember how much memory is there or how it's arranged =/ (and probably never will until I actively program for it and learn it the hard way)

Also I wonder why did they ever mention its existence seeing as it was apparently never meant to be used in the released add-on anyway (the few licensed cartridges that do it resort to hunting down for the BIOS in the firmware which also makes them prone to not work on different revisions).
Sik is pronounced as "seek", not as "sick".

Chilly Willy
Very interested
Posts: 2466
Joined: Fri Aug 17, 2007 9:33 pm

Re: Sega CD Mode 1 support functions for SGDK

Post by Chilly Willy » Wed Jul 05, 2017 8:14 pm

Sik wrote:
Chilly Willy wrote:That's beside the fact that the mode where the MD boots the firmware and looks for a special signature in the cart area is not actually present in all models,
Only the LaserActive lacks it, which happens to be also the one firmware modified to have two BIOSes, and the only one where the CD BIOS data isn't aligned to a 32KB boundary at that. The other firmwares were cosmetic changes and adapting the BIOS to different CDCs, the LaserActive one seems to have had bigger changes internally so it's no wonder they decided to remove a feature that ended up going unused.
You would think that if any system used that particular mode, it would be the LaserActive. :lol:
This is another problem. The Mega CD docs feel like a trainwreck compared to the Mega Drive docs, information is either spread all over the place (often in irrelevant locations) or outright missing making it a freaking pain in the ass to figure out how anything works at all. I still can't remember how much memory is there or how it's arranged =/ (and probably never will until I actively program for it and learn it the hard way)
Yeah, a lot of the SEGA CD stuff you have to learn by looking at the examples... ALL of them as no one example gives you all the info you need. The Genesis manual was nice... virtually everything you need in a single manual.
Also I wonder why did they ever mention its existence seeing as it was apparently never meant to be used in the released add-on anyway (the few licensed cartridges that do it resort to hunting down for the BIOS in the firmware which also makes them prone to not work on different revisions).
That is weird... they devote a half a page to pseudo-code on how to do this kind of boot, and then never speak of it again! We at least have the fortune of working on this decades later when all hardware is now known, and don't need to worry about any new systems. If they REALLY wanted it used, they should have set aside a vector at a set location in the firmware that the MD side could call that would setup the CD BIOS.

User avatar
KanedaFr
Administrateur
Posts: 1102
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: Sega CD Mode 1 support functions for SGDK

Post by KanedaFr » Wed Jul 05, 2017 9:15 pm

Chilly Willy wrote:
This is another problem. The Mega CD docs feel like a trainwreck compared to the Mega Drive docs, information is either spread all over the place (often in irrelevant locations) or outright missing making it a freaking pain in the ass to figure out how anything works at all. I still can't remember how much memory is there or how it's arranged =/ (and probably never will until I actively program for it and learn it the hard way)
Yeah, a lot of the SEGA CD stuff you have to learn by looking at the examples... ALL of them as no one example gives you all the info you need. The Genesis manual was nice... virtually everything you need in a single manual.
I approve totally.
1/ the main vs sub via communication flag and share (or not) data is "easy" to understand
2/ I finally start to understand what can ONLY be done on sub part, after several read of the manual, when I learnt a point on every try.
3/ the way you should write your sub program was a real mystery too me, and unable to write it from scratch w/o Chilly and LukeCDProject
4/ I didn't start the image processing but the manual seems good on this part
5/ I didn't try to play PCM yet, because I still don't understand if I need to load a PCM driver or if the main bios does it for me (on cart boot vs on cd boot)

Chilly Willy
Very interested
Posts: 2466
Joined: Fri Aug 17, 2007 9:33 pm

Re: Sega CD Mode 1 support functions for SGDK

Post by Chilly Willy » Wed Jul 05, 2017 10:45 pm

You need to read the software manual and BOTH hardware manuals to get ALL the info on the ASIC with regards to graphics. Weirdly, they put some info in ALL or them, and some other info in only ONE of them. :shock:

Look at my CD mod player code to see how you play music on the PCM chip. I made a small helper library for using the PCM chip itself, and then the mod player shows how easy it is to play 4 to 8 channel mods on the SEGA CD.

User avatar
Sik
Very interested
Posts: 562
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Sega CD Mode 1 support functions for SGDK

Post by Sik » Thu Jul 06, 2017 1:32 am

Chilly Willy wrote:You would think that if any system used that particular mode, it would be the LaserActive. :lol:
Dunno, its main gimmick is booting from laserdiscs instead =P
Chilly Willy wrote:That is weird... they devote a half a page to pseudo-code on how to do this kind of boot, and then never speak of it again! We at least have the fortune of working on this decades later when all hardware is now known, and don't need to worry about any new systems. If they REALLY wanted it used, they should have set aside a vector at a set location in the firmware that the MD side could call that would setup the CD BIOS.
The mode 1 in the firmware renders the need for a vector useless: the firmware itself loads the BIOS for you before jumping to the code in the cartridge. This is also the part that doesn't work on the LaserActive (it boots to the cartridge, but the SUB-CPU program isn't loaded)

...actually, now I wonder if this is precisely why the LaserActive is the one where it's broken? The data for the BIOS is aligned to a 32KB boundary in every other firmware, the LaserActive is the exception to the rule. Maybe when they were customizing the firmware something broke in the build and they decided to dummy out that piece of code instead of trying to fix it? (I still don't get why the BIOS is aligned to a 32KB boundary when it's compressed and can't be used as-is anyway)
Sik is pronounced as "seek", not as "sick".

Chilly Willy
Very interested
Posts: 2466
Joined: Fri Aug 17, 2007 9:33 pm

Re: Sega CD Mode 1 support functions for SGDK

Post by Chilly Willy » Thu Jul 06, 2017 3:48 pm

Sounds to me like maybe the engineers at Pioneer worked on the BIOS rather than Sony engineers. They didn't quite understand the nuances of the CD BIOS and wound up doing things in a way SEGA engineers didn't expect. Given the state of the CD manuals and examples, that would be easy to imagine.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest