PDA

View Full Version : Initialising the z80 not the same for real cart/SegaCD/EverDrive?



slobu
01-17-2012, 03:04 PM
So, I'm starting to try an add music to my code. I'm using an earlier version of TFM Music Maker as it still has examples for BasiEgaXorz.
I've heard there are issues with initializing the z80 so I inserted this code:


asm
move.w #$0100,$A11100 ;busreq on
move.w #$0100,$A11200 ;stop Z80 and YM2612
move.w #0,$A11100 ;busreq off
move.w #0,$A11200 ;start Z80 and YM2612
end asm

I've also tried including KramLib and starting the sound system:


asm
jsr LoadSoundSystem ; initialize Samplized Music Processing System
end asm

I've heard that either method might not work on a real cartridge. I've also heard that it might not work on a SegaCD. I'd hate to test my code successfully on an EverDrive and then fail completely when it come time to produce a real cart.

What is the proper method to init the z80? Is there any reason the two methods I posted here wouldn't work?

Sik
01-17-2012, 08:44 PM
asm
move.w #$0100,$A11100 ;busreq on
move.w #$0100,$A11200 ;stop Z80 and YM2612
move.w #0,$A11100 ;busreq off
move.w #0,$A11200 ;start Z80 and YM2612
end asm
This isn't going to work. When you reset the Z80 you need to wait some time before letting it start again. I've noticed several games use 16 NOPs for the job, so that seems like a good enough delay (and for our purposes, EverDrive = real cartridge, it's emulators that differ).


I've also heard that it might not work on a SegaCD.
The Z80 can't access the Sega CD hardware at all. Add to this the fact there is no cartridge and that 68000 RAM can't be accessed and you essentially end up with a Z80 that can only access its own RAM. Guess you're better off not using the Z80 for sound in this case =/

(note the above assumes you're booting from CD - if you have a cartridge then the Z80 is still able to access that)

TmEE
01-18-2012, 04:10 AM
I keep no waits between busreq and reset in my MD stuff

Sik
01-18-2012, 04:17 AM
I keep no waits between busreq and reset in my MD stuff
I meant that you need to hold the reset line high for some time, busreq has nothing to do with that. Practically all the games I've seen do the wait, so obviously some wait is needed.

TmEE
01-18-2012, 04:24 AM
reset does not deny you from doing your reads and writes, so while I do those, the chips can reset all they want. And when I release reset I no longer care what goes on the other side, it will start eventually and comes alive.

Sik
01-18-2012, 06:11 AM
Thing being this is the initialization code and the Z80 isn't guaranteed to reset if you don't wait =P (note that writing to Z80 RAM while waiting for it to reset is valid if the bus is requested)

This reminds me, you need to wait until the Z80 gives you the bus when you request it. I know some Z80 init code on SpritesMind didn't work until the wait was added, so don't come tell me it isn't needed =P Also beware that the system won't tell you the bus is requested if you're resetting the Z80... though if the Z80 is being reset I guess it's safe to access its RAM for starters.

Or screw that, just do what Echo does:


Set Z80 reset line
Clear Z80 reset line
Request Z80 bus
Load Z80 program into RAM
Release Z80 bus


(if you bus request right after releasing reset the Z80 won't have enough time to even access RAM, so yes, this is safe)

TmEE
01-18-2012, 07:11 AM
Looks like I do things this way :
*release reset
*grab bus
*do mädzik
*set reset
*release bus
*release reset

slobu
01-18-2012, 01:58 PM
This isn't going to work. When you reset the Z80 you need to wait some time before letting it start again. I've noticed several games use 16 NOPs for the job, so that seems like a good enough delay (and for our purposes, EverDrive = real cartridge, it's emulators that differ).


The Z80 can't access the Sega CD hardware at all. Add to this the fact there is no cartridge and that 68000 RAM can't be accessed and you essentially end up with a Z80 that can only access its own RAM. Guess you're better off not using the Z80 for sound in this case =/

(note the above assumes you're booting from CD - if you have a cartridge then the Z80 is still able to access that)

I see in KramLib he is doing this after his sound driver is loaded:


DriverAlreadyInitialized:
move.w #$0000, $A11200
nop
nop
nop
nop
move.w #$0100, $A11200 ; Z80 start reset
move.w #$0000, $A11100 ; Z80 bus request - Stop
rts

Could I just do this to safely init the z80? Seems to be using those NOP delays (which I could add more as Sik states). My goal is to use the TFM Music Maker engine and not have it break on a real cart. I really don't care about CD audio but I'd like builds to at least run as a SegaCD. I guess the question I have here is does attempting to init the z80 break things when the binary is run on a SegaCD.

Thanks for the help guys. I don't have a very good comprehension of assembly or sound issues on the Genesis. This gives me a good hint of what I need to learn.

Sik
01-18-2012, 03:16 PM
Seems to be using those NOP delays (which I could add more as Sik states).
I have no idea how many NOPs are actually needed, I've just seen games doing 16 and that seems to work.


I guess the question I have here is does attempting to init the z80 break things when the binary is run on a SegaCD.
The problem wouldn't be initializing but getting it to run instead. The player won't be able to access anything at all (68000 RAM is unreadable, accesses to Mega CD hardware are documented as not working), so basically you end up with it unable to play anything.