Booting CD from Cart ?

Ask anything your want about Mega/SegaCD programming.

Moderator: Mask of Destiny

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

Post by Chilly Willy » Sat Jan 11, 2014 3:11 am

No problem. I try to share as much as possible so that others have something to work from. Help as much as possible so we see more homebrew. 8)

User avatar
Orion_
Very interested
Posts: 52
Joined: Mon May 02, 2011 2:26 pm
Location: France
Contact:

Post by Orion_ » Sat Feb 01, 2014 2:14 pm

I will not make another topic just for this but, I'm trying to time my code from the CD CPU, to do so, I send a color in the SUBCPU_DATA -> $FFFF8020 and on the Main CPU I put this data in the VDP Palette 0 in a loop (+ some VBL sync between both CPU so the CD CPU routine starts just after the VBL begins)
I get an almost stable color band on screen ... almost...
because about one or two time per second, I get a screen filled with the color, that's because the CD CPU is taking more time to execute my routine.
I guess this is because of a BIOS interrupt code running something "CPU intensive" from time to time (even when the CD spin is idle)
Is this unavoidable ?
Retro game programming !

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

Post by Chilly Willy » Sat Feb 01, 2014 11:49 pm

There are a number of interrupts the CD CPU must deal with regarding the CD. You also MUST send a level 2 int periodically to keep the CD BIOS working. The "standard" is to assert the level 2 int in the MD vblank, but it doesn't need to be. You can't run the CD with ints off if you want to use the CD. That means that things can be interrupted, so in critical areas, disable ints (set sr to 0x2700), do the critical task, then enable ints (set sr to 0x2000).

User avatar
Orion_
Very interested
Posts: 52
Joined: Mon May 02, 2011 2:26 pm
Location: France
Contact:

Post by Orion_ » Mon Feb 03, 2014 3:47 pm

I'm trying to use the 1M mode of the WordRAM, so I render data in one bank using CD CPU, while I copy data from the second bank using DMA on MD CPU
it works great on emulators, but not on real hardware ... (like always)
so I guess I'm doing something wrong

I have some sync, so on the CD side I first set the wordram in 1M mode, then in a loop I do this:

SubCPU: Render data at $D0000, wait for the Main CPU to finish DMA
MainCPU: do DMA from $230000, then ask for wordram swap using
bset.b #1,$A12003 ; Request WordRAM Swap
SubCPU: do a Wordram swap using:
eor.b #1,$FFFF8003.w ; Swap WordRAM
do some VBL sync and loop again

I'm missing something ?
Retro game programming !

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

Post by Chilly Willy » Mon Feb 03, 2014 6:45 pm

Well, the ram starts at 0xC0000, but 0xD0000 should be okay as long as you don't go past 0xDFFFF.

If you look at my SCD wolfdemo, I use 1M mode to double-buffer a DMA Direct Color display. Here's my assembly code to switch banks:

Code: Select all

| void switch_banks(void);
| Switch 1M Banks
        .global switch_banks
switch_banks:
        bchg    #0,0x8003.w             /* switch banks */
0:
        btst    #1,0x8003.w
        bne.b   0b                      /* bank switch not finished */
        rts
In the demo loop, I wait for a bank switch flag to be cleared, render the level, then set the flag. The flag is checked in the INT2 routine, which calls the switch_banks() function above and clears the flag if it was set. That way I know the bank is switched in the vertical blank, which is where the INT2 is asserted. I COULD switch the banks at any time, but that would cause a tear in the display is it were changed in the middle of displaying a frame.

User avatar
Orion_
Very interested
Posts: 52
Joined: Mon May 02, 2011 2:26 pm
Location: France
Contact:

Post by Orion_ » Mon Feb 03, 2014 8:13 pm

ok, I think I got it, it's because I was testing on hardware while booting from cart, so the wordram is at $600000 instead of $200000 so now it's working :)
Retro game programming !

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

Post by Chilly Willy » Tue Feb 04, 2014 6:08 pm

Orion_ wrote:ok, I think I got it, it's because I was testing on hardware while booting from cart, so the wordram is at $600000 instead of $200000 so now it's working :)
Yes, in mode 1, don't forget that 4MB offset! :lol:

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests