Megacd timing issues and solutions (PCM, HINT, DMA...)

Ask anything your want about Mega/SegaCD programming.

Moderator: Mask of Destiny

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

Megacd timing issues and solutions (PCM, HINT, DMA...)

Post by Fonzie » Sun Mar 11, 2007 5:33 pm

Well, as you may imagine, I start to do silly thing with the hardware ;)
Here is a list of :

:arrow: - Trying to set HINT enable while the vdp is on display period imediately reset the main cpu, even if the HINT code is situated in megadrive ram (if situated in workram, it will hang anyway).
Workaround -> Do not use HINT at all ;P

:arrow: - Reading outside the "autorized" areas imediately reset the maincpu
Workaround -> Clean your code ;P

:arrow: - Trying to enable the play of one pcm channel (different from channel0) work randomely (75% of time, the play command is ignored)
Sample code to reset a pcm channel (to make it play, the channel settings were set before) :
pc=(unsigned char *) 0xFF0011;*pc=0xE2;//Stop Channel1 only
pc=(unsigned char *) 0xFF000F;*pc=0x80+0x40+1;//Select channel1
pc=(unsigned char *) 0xFF000D;*pc=0x80;//Make it START at 0x8000
pc=(unsigned char *) 0xFF0011;*pc=0xE0;//Start all channels

Workaround -> Not found... Maybe i need to add some nops?

If someone have an idea about the pcm channel, it would be great :)

ob1
Very interested
Posts: 463
Joined: Wed Dec 06, 2006 9:01 am
Location: Aix-en-Provence, France

Post by ob1 » Sun Mar 11, 2007 5:54 pm

No idea at all.
But reading, you, and the hardware manual (check "antime sega" on google), I guess SegaCD is my first big leap.
Saturn is too hard to configure and to develop on at work ;)

TascoDLX
Very interested
Posts: 262
Joined: Tue Feb 06, 2007 8:18 pm

Re: Megacd timing issues and solutions (PCM, HINT, DMA...)

Post by TascoDLX » Sun Mar 11, 2007 9:51 pm

Fonzie wrote:Well, as you may imagine, I start to do silly thing with the hardware ;)
Here is a list of :

:arrow: - Trying to set HINT enable while the vdp is on display period imediately reset the main cpu, even if the HINT code is situated in megadrive ram (if situated in workram, it will hang anyway).
Workaround -> Do not use HINT at all ;P
You try the weirdest things!
Fonzie wrote::arrow: - Trying to enable the play of one pcm channel (different from channel0) work randomely (75% of time, the play command is ignored)
Sample code to reset a pcm channel (to make it play, the channel settings were set before) :
pc=(unsigned char *) 0xFF0011;*pc=0xE2;//Stop Channel1 only
pc=(unsigned char *) 0xFF000F;*pc=0x80+0x40+1;//Select channel1
pc=(unsigned char *) 0xFF000D;*pc=0x80;//Make it START at 0x8000
pc=(unsigned char *) 0xFF0011;*pc=0xE0;//Start all channels

Workaround -> Not found... Maybe i need to add some nops?
You probably want to delay after writing the START address since that address needs to be updated in internal memory. 50 clock cycles should be enough.

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

Re: Megacd timing issues and solutions (PCM, HINT, DMA...)

Post by Mask of Destiny » Mon Mar 12, 2007 1:03 pm

Fonzie wrote:Well, as you may imagine, I start to do silly thing with the hardware ;)
Here is a list of :

:arrow: - Trying to set HINT enable while the vdp is on display period imediately reset the main cpu, even if the HINT code is situated in megadrive ram (if situated in workram, it will hang anyway).
Workaround -> Do not use HINT at all ;P
Are you sure you have your interrupt handlers set up properly. I've never had any trouble with HINTs.
:arrow: - Trying to enable the play of one pcm channel (different from channel0) work randomely (75% of time, the play command is ignored)
Sample code to reset a pcm channel (to make it play, the channel settings were set before) :
pc=(unsigned char *) 0xFF0011;*pc=0xE2;//Stop Channel1 only
pc=(unsigned char *) 0xFF000F;*pc=0x80+0x40+1;//Select channel1
pc=(unsigned char *) 0xFF000D;*pc=0x80;//Make it START at 0x8000
pc=(unsigned char *) 0xFF0011;*pc=0xE0;//Start all channels

Workaround -> Not found... Maybe i need to add some nops?

If someone have an idea about the pcm channel, it would be great :)
I'll have to check my PCM code when I get home. I don't think I ever worked with it enough to mess with anything other than channel 0 though.

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

Post by Fonzie » Mon Mar 12, 2007 5:21 pm

I added approx 50 68K nops before activating again the channel and it worked.. thank you very much :D
Are you sure you have your interrupt handlers set up properly. I've never had any trouble with HINTs.
I guess I got the problem... Since I run multiple code segments, I oftenly clear the stack... this must break the HINT jumping :) ... I don't use Hint anymore , I prefer a lot H & V flags now ^^

Now seems my top secret engine is almost ready ^^
I added a fast seeking function in my FMV routine (to seek anywhere in the file without *major* slowdown) while playing.

8bitwizard
Very interested
Posts: 159
Joined: Sat Feb 24, 2007 11:35 pm
Location: San Antonio, TX

Re: Megacd timing issues and solutions (PCM, HINT, DMA...)

Post by 8bitwizard » Wed Mar 14, 2007 11:55 am

Fonzie wrote:pc=(unsigned char *) 0xFF0011;*pc=0xE2;//Stop Channel1 only
pc=(unsigned char *) 0xFF000F;*pc=0x80+0x40+1;//Select channel1
pc=(unsigned char *) 0xFF000D;*pc=0x80;//Make it START at 0x8000
pc=(unsigned char *) 0xFF0011;*pc=0xE0;//Start all channels
What optimization level (-O) are you using with the compiler? Maybe pc should be a "volatile char*" to ensure everything is written in the right order and not optimized to nothing?

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

Post by Mask of Destiny » Wed Mar 14, 2007 4:13 pm

Fonzie wrote: I guess I got the problem... Since I run multiple code segments, I oftenly clear the stack... this must break the HINT jumping :) ...
I don't see how clearing the stack would break HINTs unless you tried to clear the stack in your HINT handler. If your HINT is in Work RAM, it works like a normal Genesis interrupt (i.e. no funny jumping). The 68K pushes the status register (or is it just the condition code register? I don't remember) and the current value of PC on the stack and jumps to the location pointed to by the vector table. So it doesn't care what's currently in the stack as long as the stack pointer points to RAM that you're not using for something else. Even when your HINT handler is in Word RAM it does mostly the same thing except that the vector table entry points to a long absolute jump instruction in high Work RAM ($FFDXXX IIRC). No additional stack usage is required. Of course if you overwrite this section of Genesis Work RAM your interrupts will get borked, but the same is true for VINTs.
I don't use Hint anymore , I prefer a lot H & V flags now ^^
Depends on what you're doing I suppose. Using the H flag instead of HINT can gain you a few precious HBLANK cycles, but it's awfully wasteful of CPU cycles. For VBLANK I've always found it easier to do all of my rendering and animation code in the VINT handler itself. When I was actually working on game code, my VINT handler looked something like:
DMA new spritelist from Work RAM to VRAM
DMA tiles if necessary
scroll background
poll controller pad
calculate new scroll values, update sprite list for next frame and figure out which tiles I'll need to DMA if any
set up color cycle DMA for HBLANK

Then my main loop just polled the H/V counter and DMAed new colors in each HBLANK. HINTs added too much of a delay to get the max number of colors transferred without any screen artifacts.
Now seems my top secret engine is almost ready ^^
I added a fast seeking function in my FMV routine (to seek anywhere in the file without *major* slowdown) while playing.
Can't wait to see it.

Post Reply