CDC DMA failing on Kega Fusion?

Ask anything your want about Mega/SegaCD programming.

Moderator: Mask of Destiny

Post Reply
CrazyMonkey
Newbie
Posts: 8
Joined: Mon Feb 15, 2016 12:43 pm

CDC DMA failing on Kega Fusion?

Post by CrazyMonkey » Tue Oct 04, 2016 10:21 pm

Hello. We learn a lot thanks to Luke's ProjectCD, and now have been trying to go fancy on the optimizations, such as running the engine from SubCPU and similar. We're currently on the tedious task of adapting the previously edited ReadCD to use DMA and its expanded bandwidth. So far it appear to work just fine on edited Genesis Plus GX, Gens, and many other emulators, all BUT Kega Fusion. Being unable to, or having no strategy to properly debug whatever happen to be going on this emulator, what can we do to find the cause and/or fix this issue?

The freeze appear to on this location as if CDC status were never "ready":

Code: Select all

.waitSTAT:
	BIOS_CDCSTAT			; Check CDC status
	bcs.s	.waitSTAT		; If not ready, branch
Here is the full code for reference; previously it was pretty much the same to SoullessSentinel/Luke's ProjectCD, with a few adds (++) to properly "load" some files' uneven file size:

Code: Select all

	; Set DMA to PRG-RAM
	move.b	#5,(CDC_Mode).w

	; Load Volume VolumeDescriptor
	moveq	#$10,d0					; Start Sector
	move.l	#2*$800,d1				; Read 2 sectors
	move.w	#FileSysBuffer/8,(CDC_DMA_Adr).w	; Destination
	bsr.w	ReadCD					; Read Data


	; (...)


ReadSector:    macro
.waitSTAT:
	BIOS_CDCSTAT			; Check CDC status
	bcs.s	.waitSTAT		; If not ready, branch
.waitREAD:
	BIOS_CDCREAD			; Read data
	bcs.s	.waitREAD		; If not done, branch
	BIOS_CDCACK			; Acknowledge transfer
	endm

ReadCD:
	pushr	d0-d7/a0-a6		; Store all registers
	move.l	d1,d6			; ++
	lsr.l	#8,d1			; ++ '' Bitshift filesize (to get sector count)
	lsr.l	#3,d1			; ++ ''
	andi.l	#$7FF,d6		; ++ D6 will contain the size of "incomplete" sector
	lea	BiosPacket(pc),a5	; Load bios packet
	move.l	d0,(a5)			; Write start sector to packet
	move.l	d1,4(a5)		; Write size to packet
	movea.l	a5,a0			; Put packet to a0 (for BIOS)
	tst.l	d1			; ++ Is there any "complete" sector needing to be read?
	beq.s	RCD_ByteSpecificTransfer ; ++ If not, branch
	BIOS_CDCSTOP			; Stop CDC
	BIOS_ROMREADN			; Begin data read

RCD_SectorReadLoop:
	ReadSector
	addq.l	#1, (a5)		; Increment starting sector
	addi.l	#$0800,8(a5)		; Increment destination address
	subq.l	#1,4(a5)		; Decrement sectors left
	bne.s	RCD_SectorReadLoop	; If not finished, branch
	tst.l	d6			; ++ Is there any "incomplete" sector needing to be read?
	beq.w	RCD_Return		; ++ If not, branch

RCD_ByteSpecificTransfer:		; ++
	move.l	#1,4(a5)
	move.l	8(a5),d7
	move.l	#SectorBuffer,8(a5)

	; For some reason (maybe timing?) we need to
	; re-setup the reader
	movea.l	a5,a0			; Put packet to a0 (for BIOS)
	BIOS_CDCSTOP			; Stop CDC
	BIOS_ROMREADN			; Begin data read

	ReadSector
	clr.l	4(a5)

RCD_Return:
	popr	d0-d7/a0-a6		; Restore all registers
	rts				; Return

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

Re: CDC DMA failing on Kega Fusion?

Post by Mask of Destiny » Tue Oct 04, 2016 11:51 pm

I think the first question you need to answer is whether it actually works on the real hardware or not. It's quite possible you're just hitting a bug in Fusion.

I'm not sure if there's been any homebrew using CDC DMA before. You might be in relatively uncharted territory here.

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

Re: CDC DMA failing on Kega Fusion?

Post by Sik » Fri Oct 07, 2016 10:37 am

Yeah, try real hardware first of all. Especially since Fusion actually doesn't have good Sega CD compatibility (a lot of games hang). This has never been an area that worked well in any emulator.

Also make sure the firmware you use matches the CDC being emulated =P Some firmware hangs horribly simply because it wants a different CDC.
Sik is pronounced as "seek", not as "sick".

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

Re: CDC DMA failing on Kega Fusion?

Post by Stef » Fri Oct 07, 2016 6:22 pm

Different CDC ?? You have BIOS by region and SCD model but games work both on SCD1 or SCD2 (and i think they both use the same CDC :p) as soon region is compatible.
About Kega (or Gens) SCD compatibility, be sure to enable the "perfect synchro" mode (at least it exists in Gens and was here for performance reason back in time), normally compatibility should be pretty high in both emulators (at least 90% of games working).

CrazyMonkey
Newbie
Posts: 8
Joined: Mon Feb 15, 2016 12:43 pm

Re: CDC DMA failing on Kega Fusion?

Post by CrazyMonkey » Sun Oct 09, 2016 6:45 am

Got the opportunity to get to try, it is left stuck on the BIOS' Sega screen.

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

Re: CDC DMA failing on Kega Fusion?

Post by Sik » Tue Oct 11, 2016 2:09 pm

Stef wrote:Different CDC ?? You have BIOS by region and SCD model but games work both on SCD1 or SCD2 (and i think they both use the same CDC :p) as soon region is compatible.
Wondermega is an obvious broken one (it hangs for a minute before reacting to the disc), but again that one wasn't even provided by Sega. Still, with all those revisions around it's hard to believe there's a single CDC out there.

But yeah in practice you're not going to be sure until you try on real hardware. The CD is not a trivial thing to use.
Sik is pronounced as "seek", not as "sick".

l_oliveira
Interested
Posts: 46
Joined: Mon Mar 07, 2011 12:58 am

Re: CDC DMA failing on Kega Fusion?

Post by l_oliveira » Thu Dec 08, 2016 1:37 am

Certain motherboards from the SEGA/MEGA-CD2 have a different CDC, based on a NEC MCU. Even SEGA/MEGA-CD1 units with a JVC mechanism do have a different CDC and that cause problems with at least one game.

KEGA Fusion emulates a CD-ROM drive with the SONY CDC.

So some CD BIOSes don't work in it (They're meant to run on units with the NEC CDC). For example, one revision of the USA SEGA-CD2 BIOS, X'Eye and Wondermega2, and all of the CDX regional variations have BIOSes which fail on KEGA Fusion and it's not fault of the emulator. They're meant for different hardware. Running them on a real unit (with the wrong CDC) would cause the exact same problems.

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

Re: CDC DMA failing on Kega Fusion?

Post by Stef » Thu Dec 08, 2016 2:31 pm

Never saw that behavior... So i guess these BIOS does fail on Gens as well ? I emulated CDC from my Reverse engineering on MCD1 bios and real hardware tests i made (on a PAL MCD2 this time).

l_oliveira
Interested
Posts: 46
Joined: Mon Mar 07, 2011 12:58 am

Re: CDC DMA failing on Kega Fusion?

Post by l_oliveira » Mon Dec 12, 2016 1:14 pm

That behavior is mentioned in one of the service manuals that got released a couple months ago...

They refer to the affected units as "FUNAI units". FUNAI is the company SEGA contracted to build some of their production of MEGA/SEGA CD2 units.

FUNAI units are more common in the US, equipped with either a SONY KSS-210 or the SAMSUNG SOH-OT3 laser pickup. If you're in Europe you will see more units using SONY KSS-240 (same pickup as CD1 units using SONY mechanism) or JVC OPTIMA-5 (same pickup as the SEGA Saturn). I have no experience with Japan/Asia MEGA-CD2 units so I can't tell how they vary internally.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests