SEGA CD Mode 1

Ask anything your want about Mega/SegaCD programming.

Moderator: Mask of Destiny

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: SEGA CD Mode 1

Post by KanedaFr » Fri Jul 21, 2017 2:40 pm

From what we know, a CDD access takes almost 1/75s
so every time a BIOS function called need to communicate with the CDD, it takes this time.
Add the process time, you almost have a frame (60hz/50Hz)
:arrow: you lost a frame every bios call ?!

I don't understand how Sega let this happen....
At the first scratch, the game hangs or happy lagging......
Am I too serious about this ?

On the other side, I saw some BIOS call are made in 3 steps : XXXSTART, XXXXREAD, XXXXSTOP
I assume it was to handle this kind of thing ?

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

Re: SEGA CD Mode 1

Post by Chilly Willy » Fri Jul 21, 2017 3:16 pm

Well, most of the time you don't ask for one sector at a time, you either ask for N sectors, or tell the CD to just start streaming data until you tell it to stop, so you're not constantly doing CDD commands. All the bios handling tends to take place inside CDD and CDC interrupts when they're done so that they occur immediately instead of when the chip is busy. Also, it's only the CD system where you have to watch the timing - the comm registers and asic only take a couple clock cycles to rd/wr.

If you want to see how "typical" sega cd code looks, go check out the reverse-engineered SCD Cinepak code. You'll see code like this

Code: Select all

SwapMeg:	
	LINK     A6,#0x0
	;; to get here sub is ready to swap meg
	;; need to wait for main to be ready to swap meg
SwapMegWaitForZeroCommand:	
	MOVEA.L  #0xFF8010,A0
	TST.W    0x2(A0)
	BNE.S    SwapMegWaitForZeroCommand
	;; swap the main/sub control of the two 1Mbit areas in word RAM
	EORI.W   #0x1,(0xFF8002).L
	UNLK     A6
	RTS
This is probably compiled code... I've never seen hand-written assembly use link/unlk. It also sets the address register INSIDE the loop - that's typical of unoptimized compiled code. Notice how they simply wait for one of the comm registers to be cleared and then toggle the memory bit? See any error handling or timeouts or whatnot? That's typical for code from the period.

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Re: SEGA CD Mode 1

Post by Manveru » Sat Jul 29, 2023 4:41 pm

Hello mates, i am working with mode 1 and i am having some issues, so sorry for writting in this old thread but i cant make it work.

I tried from the last version code in this thread, it works well just adding a check command after reading disk. My problem comes when i try to read pads. When i both call the megacd vint code + pad reading, game freezes. No matters if i read pads first or last, or if i put pad read outside vint callback, or if i wait some time between both calls waitting some vints or adding nops, or if i add or remove the bus request for the z80/pad stuff... if i call both pad and megacd, game freezes.

I can remove one of the two calls and all other works nice: all the game stuff and megacd accesses and playing or pad reading work as expected. I also can play a megacd track before first vint and even when the game freezes, the music keeps playing (game freezes if i play music and if i do not play any track). Funny both megacd accesses and pad reading works together if megacd is detected but no disk in the unit.

I am using Kega Fusion, the unique emulator i know how to use with mode 1. I wonder if exist an update version of the mode 1 code in this thread, or a demo or game or some code unsing mode 1 beyond a sound test screen to check it. I need some help, i do not know what i can try anymore...

Thanks
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

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

Re: SEGA CD Mode 1

Post by Chilly Willy » Fri Aug 04, 2023 8:27 am

You might try ARES. It has better mode 1 support (it's the emulator Vic uses for testing mode 1 support in D32XR). The main problem with ares is that it takes a pretty beefy computer.

If it acts the same, then the problem is likely in the code rather than the emulator.

Vic posted his Genesis+CD pcm mode 1 player example:
https://github.com/viciious/SegaCDMode1PCM

You can look at that to get an idea of how we do things. It makes much more use of the CD side, and shows how you can use C for programming the CD side in mode 1.

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Re: SEGA CD Mode 1

Post by Manveru » Fri Aug 04, 2023 6:08 pm

Chilly Willy wrote:
Fri Aug 04, 2023 8:27 am
You might try ARES. It has better mode 1 support (it's the emulator Vic uses for testing mode 1 support in D32XR). The main problem with ares is that it takes a pretty beefy computer.

If it acts the same, then the problem is likely in the code rather than the emulator.

Vic posted his Genesis+CD pcm mode 1 player example:
https://github.com/viciious/SegaCDMode1PCM

You can look at that to get an idea of how we do things. It makes much more use of the CD side, and shows how you can use C for programming the CD side in mode 1.
Thanks mate, i will try both things. I checked and rechecked the old code hundreds of times but no way i can use mega cd and pads at the same time. I will try those things this weekend, i hope i can make it work
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

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

Re: SEGA CD Mode 1

Post by Mask of Destiny » Fri Aug 04, 2023 10:55 pm

FWIW, BlastEm nightly builds also have Mode 1 support these days and might run on a slightly less beefy machine. My CD compatibility is currently a fair bit worse at the moment, though I do much better on mcd-verficator. I think Genesis Plus GX also supports Mode 1 boot these days, but I've personally had trouble figuring out how to get it running.

This is kind of an odd thing to fail though. Reading pads and interacting with the MCD hardware shouldn't have any impact on either other whatsoever. If it also fails the same way in other emulators I suggest posting some of your pad reading and MCD access code.

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Re: SEGA CD Mode 1

Post by Manveru » Sat Aug 05, 2023 6:48 am

Mask of Destiny wrote:
Fri Aug 04, 2023 10:55 pm
FWIW, BlastEm nightly builds also have Mode 1 support these days and might run on a slightly less beefy machine. My CD compatibility is currently a fair bit worse at the moment, though I do much better on mcd-verficator. I think Genesis Plus GX also supports Mode 1 boot these days, but I've personally had trouble figuring out how to get it running.

This is kind of an odd thing to fail though. Reading pads and interacting with the MCD hardware shouldn't have any impact on either other whatsoever. If it also fails the same way in other emulators I suggest posting some of your pad reading and MCD access code.
Someone told me BlastEm have some mode 1 support but i have no idea how to load both MD rom and CD. In kega fusion i have some demos that works so it is probably some fail in my code i cant find. I have to test what Chilly Willy told me and i wish i can use BlastEm because of the KLog debugging feature and for using DMA with Mode 1 because Fusion bugs with that

EDIT: i found how to load md rom and cd, i needed a .cue because a .iso did not load the tracks

EDIT2: i can make Mode 1 work in Blastem. In Fusion when i try: music plays but game frezzes and pads do not work. In Blastem music plays, game works but pads dont... At least BlastEm working for mode 1 is a big deal, although it prints a lot of output in Klog and i cant use it for debugging :P

EDIT3: i copied what i can from the new driver (i cant find some stuff and other is mixed with the pcm code) but i have the same issue. Every code i see is a demo of a sound test, with the code run every frame with no gameplay update code. I see a delay(2) and then pad reading, but i cant do the same in a game rom. Anyway i tried to wait 2 frames before reading pads but the same problem.

FINAL EDIT: finally it seems some undefinded behavior with memory allocation, structs, maybe padding... i really do not know why but it freezes when i read the Disc Unit Info and try to copy the last byte to a struct. I am happy is just that i guess... Thanks for the help
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Re: SEGA CD Mode 1

Post by Eke » Sun Aug 06, 2023 8:56 pm

Mask of Destiny wrote:
Fri Aug 04, 2023 10:55 pm
I think Genesis Plus GX also supports Mode 1 boot these days, but I've personally had trouble figuring out how to get it running.
Hi,

You only need to have a .cue file with same basename as the ROM file you load, in same directory, and Sega CD Mode 1 should automatically be enabled.

Alternatively, if you just want to use Mega CD hardware without necessarely using a disc, having the 'C' value in ROM header peripherals field will also enable Sega CD hardware emulation and Mode 1.

In both cases, you need valid Sega CD BIOS file corresponding to ROM region configured in system path otherwise Sega CD hardware emulation won't be enabled.

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Re: SEGA CD Mode 1

Post by Manveru » Tue Aug 08, 2023 1:50 pm

Eke wrote:
Sun Aug 06, 2023 8:56 pm
Mask of Destiny wrote:
Fri Aug 04, 2023 10:55 pm
I think Genesis Plus GX also supports Mode 1 boot these days, but I've personally had trouble figuring out how to get it running.
Hi,

You only need to have a .cue file with same basename as the ROM file you load, in same directory, and Sega CD Mode 1 should automatically be enabled.

Alternatively, if you just want to use Mega CD hardware without necessarely using a disc, having the 'C' value in ROM header peripherals field will also enable Sega CD hardware emulation and Mode 1.

In both cases, you need valid Sega CD BIOS file corresponding to ROM region configured in system path otherwise Sega CD hardware emulation won't be enabled.
I am trying to use GX with BizHawk but it does not activate the Mode 1. I have both same filenames and 'C' added to boot. Both MD rom and CD cue run the alone MD/CD game right, but together MD rom does not detect the MegaCD. I read Sik saying different emulators detect it in different ways, so maybe blastem and fusion work with my rom code but not gx
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Re: SEGA CD Mode 1

Post by Eke » Tue Aug 08, 2023 8:52 pm

Unfortunately, Bizhawk is using a quite old version of Genesis Plus GX so it's probably missing a lot of bugfixes and added features, including automatic Mode 1 support.

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Re: SEGA CD Mode 1

Post by Manveru » Wed Aug 09, 2023 12:23 pm

Eke wrote:
Tue Aug 08, 2023 8:52 pm
Unfortunately, Bizhawk is using a quite old version of Genesis Plus GX so it's probably missing a lot of bugfixes and added features, including automatic Mode 1 support.
In Retroarch it works perfectly, thanks
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

Nemesis
Very interested
Posts: 791
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Re: SEGA CD Mode 1

Post by Nemesis » Thu Nov 16, 2023 5:53 am

Hey guys, yes, I'm still alive, but life is very very busy, and all this stuff is very much on the backburner for me. I'm dropping in because someone contacted me on Discord recently asking about my work on MegaLD hardware, and I thought I'd put more stuff out there publicly than I had, so I'm going to rectify that now. I'm about to dump a lot of stuff in this thread which could help anyone who's interested in emulating MegaLD hardware. I'm dumping it in here, because it happens to come with a Mode 1 bootable ROM I wrote to help me rip MegaLD digital data tracks. Here's a raw drop from my development folder in whatever the hell state it's in:
https://nemesis.exodusemulator.com/Mega ... MegaLD.zip

Inside this archive you'll find an LDBIOS.INC file, which I've also uploaded separately here: https://nemesis.exodusemulator.com/MegaLD/MEGALD.INC
This file is one I put together to complement the MEGACD.INC file from the Sega CD SDK, with changes for the MegaLD hardware which has differences in its BIOS routines. At the start of this file is a sizable block of comments which contain incomplete, but still fairly comprehensive notes from all my testing on the hardware interface of the Pioneer PD6103A IC inside the PAC-S1/S10 and PAC-N1/N10 modules. These hardware notes are the results of extensive hardware testing and reverse-engineering of the MegaLD subcpu BIOS program. Each register is described with all my observations on behaviour and interactions. All the other ICs are the same as a regular MegaCD, it's just this chip, with the custom BIOS programs, which make this hardware any different than a MegaCD, so it should be easy to "bolt on" to any emulator with MegaCD support.

As for the DumpMegaLD.zip file, it'll be a mess in who knows what state, but there are several ROM files you can build from it of interest:
Mode1DumperCD.bin - Bootable cartridge ROM to dump CD images via the MegaCD hardware streamed over the second control port
Mode1DumperLD.bin - Bootable cartridge ROM to dump digital LD tracks via the MegaCD hardware streamed over the second control port
MegaLDRegEditor.bin - Interactive program to view/edit the Pioneer PD6103A register block live on the LaserActive hardware. Very useful for hardware testing.

I haven't touched any of these files in years. No idea what state the code or the built binaries are in, but feel free to take them and do whatever you want with them.

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

Re: SEGA CD Mode 1

Post by Chilly Willy » Sun Dec 03, 2023 6:19 pm

Very cool. Thanks. :D

Post Reply