Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

RetroGames
Interested
Posts: 34
Joined: Mon Oct 19, 2015 12:34 pm

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by RetroGames » Thu Nov 05, 2015 1:14 am

Mask of Destiny wrote:That's more or less it.
I really appreciate you taking the time to answer my questions about this!
Mask of Destiny wrote:I think there was a proposal to either start a wiki or start using one of the existing ones to collect documentation. Don't remember what came of that discussion.
Man, that'd be great! Obviously, I don't have much to offer yet, but maybe I can contribute some intro tutorials in the same vein as Big Evil Corp's, a sort of 'follow along with me as I learn the basics' kind of thing. I'm willing to help out, in other words. :D

And thanks for the debugger suggestions. I can't run Exodus since I don't have any available 64-bit machines, but I'll definitely check out BlastEm and Gens KMod.
Last edited by RetroGames on Mon Nov 23, 2015 4:00 am, edited 1 time in total.

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

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by Mask of Destiny » Thu Nov 05, 2015 10:34 pm

Forgot one: Gens r57shell mod. Not sure of the "canonical" home of that one, but there is a current thread about a fork that adds IDA integration.

EDIT: Fixed markup
Last edited by Mask of Destiny on Fri Nov 06, 2015 1:13 am, edited 1 time in total.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by Sik » Fri Nov 06, 2015 1:02 am

Mask of Destiny wrote:I think there was a proposal to either start a wiki or start using one of the existing ones to collect documentation.
The problem with that is that the wikis so far pretty much get spam infested, and also everybody rushes to write about the undocumented VDP bits without bothering to give much attention to, huh, the rest of the hardware (some parts may be explained, but most stuff either isn't or is explained too loosely to be that useful - and you better hope you aren't trying to write sound code...).

If you want to do this then you really need one person who's willing to document all of the existing knowledge, including the boring parts. At least for starters, once that's done we can probably move on as usual.
Sik is pronounced as "seek", not as "sick".

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

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by Mask of Destiny » Sat Nov 21, 2015 8:57 am

I've expanded and cleaned up the test ROM I used to verify this behavior. All the tests now have a PASS/FAIL indication with the exception of the ones testing the delay between asserting !BUSREQ and when the request is acknowledged as the value varies between 1 and 0 on the hardware and I haven't had a chance to figure out how to synchronize things such that it's reliably one or the other. For tests that should result in an "open" bus value, I simply test that it's not the value that was written as this isn't really intended to be a test of how prefetch values get used for open bus reads. For the "unused bits" tests I check for non-zero as at least one buggy game depends on that behavior for the BUSREQ/BUSACK register.

Here's it is:
Assembled ROM
Source Code

RetroGames
Interested
Posts: 34
Joined: Mon Oct 19, 2015 12:34 pm

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by RetroGames » Mon Nov 23, 2015 3:59 am

Probably not useful info, but running your test in different emulators gives different results. Shocking, no? :D

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

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by Mask of Destiny » Tue Nov 24, 2015 6:02 am

Not a huge surprise (ok, not really a surprise at all since I ran it on a few emulators previously). I can confirm that Genesis Plus GX gives more or less perfect results including the exact "open bus" values I see on the hardware I have here. The only real difference is that on real hardware the busack delay is sometimes not zero (just hit start a few times), but it's always zero on Genesis Plus GX. The delay measurement has pretty poor granularity, it's basically how many move.b (aN), dN instructions get a value without the busack bit set appropriately. I didn't have a chance to test on Exodus to see how it fairs (most of my machines run Linux exclusively). BlastEm fails the unused reset bits test and currently makes no attempt at simulating actual open bus values. For others, it seems that the handling of word-wide accesses is the most commonly messed up.

mickagame
Very interested
Posts: 256
Joined: Sat Jun 07, 2008 7:37 am

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by mickagame » Sat Nov 16, 2019 7:59 am

I'm using this thread to ask a question about Reset et BusAck signals from the Z80.
While the Z80 is resetting (RESET Pin in low state) how is the BusAck Signal?
If the BusAck Signal is low that mean the 68k can read/write the Z80 bus (That what i understand from this post).

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

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by Stef » Mon Nov 18, 2019 1:13 pm

The 2 aren't connected but SEGA clearly indicate to always asserting BUSREQ during Z80 reset operation.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by Sik » Mon Nov 18, 2019 7:50 pm

It's… messier than that:
https://plutiedev.com/using-the-z80#loading-z80

Or also from the Sega docs (though it's essentially describing the same thing):
Z80 Start-Up
Z-80 Operation Sequence:
  1. BUS REQ ON
  2. BUS RESET OFF
  3. 68k copies program into Z-80 S-RAM
  4. BUS RESET ON
  5. BUS REQ OFF
  6. BUS RESET OFF
The biggest gotchas are that:
  • You absolutely need to wait at least 192 68k cycles after you assert reset (note: waiting longer is OK). The YM2612 needs that to go to a stable state.
  • You can't access Z80 RAM during Z80 reset, hence why you need to bus request then end reset (that gives you access to Z80 RAM, but the Z80 still won't run until bus request is also deasserted).
  • The bus request signal will be invalid during reset, so do not wait for the Z80 to return the bus in this case.
Considering how it works, you probably don't need to reset again after loading the Z80 program if the reset before had been long enough (and it probably was if you're coming from reset as you were likely spending time on other stuff), but it doesn't hurt either, hence why it's the recommended method.
Sik is pronounced as "seek", not as "sick".

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by TmEE co.(TM) » Mon Nov 18, 2019 9:42 pm

I haven't had any issues by doing a shorter than 192 cycle reset, but I always explicitly zero out all the YM registers and it seems internal state is also fine.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by Sik » Tue Nov 19, 2019 3:16 am

I've had it break (inconsistently… it starts making weird noises) when doing less than 192 cycles, so yeah. To be fair it's possible that the actual amount needed is less, but doing more doesn't hurt. From what I recall, I got the 192 cycles amount by looking at docs.

Considering how some problems seem to show up only on specific consoles (or for extra pain, specific cartridges too), I'd say to play it safe.
Sik is pronounced as "seek", not as "sick".

mickagame
Very interested
Posts: 256
Joined: Sat Jun 07, 2008 7:37 am

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by mickagame » Tue Nov 19, 2019 6:32 am

Sik wrote:
Mon Nov 18, 2019 7:50 pm
It's… messier than that:
https://plutiedev.com/using-the-z80#loading-z80

Or also from the Sega docs (though it's essentially describing the same thing):
Z80 Start-Up
Z-80 Operation Sequence:
  1. BUS REQ ON
  2. BUS RESET OFF
  3. 68k copies program into Z-80 S-RAM
  4. BUS RESET ON
  5. BUS REQ OFF
  6. BUS RESET OFF
The biggest gotchas are that:
  • You absolutely need to wait at least 192 68k cycles after you assert reset (note: waiting longer is OK). The YM2612 needs that to go to a stable state.
  • You can't access Z80 RAM during Z80 reset, hence why you need to bus request then end reset (that gives you access to Z80 RAM, but the Z80 still won't run until bus request is also deasserted).
  • The bus request signal will be invalid during reset, so do not wait for the Z80 to return the bus in this case.
Considering how it works, you probably don't need to reset again after loading the Z80 program if the reset before had been long enough (and it probably was if you're coming from reset as you were likely spending time on other stuff), but it doesn't hurt either, hence why it's the recommended method.
Thanks Sik for your informations.

When you say :
The bus request signal will be invalid during reset
=> The bus request is set by 68K, so why you say is invalid during Z80 reset? What consequences?
so do not wait for the Z80 to return the bus in this case
In my opinion the 68K does not read the bus through the Z80?
The Z80 bus is connected to the 68K no? I dont understand why you said the Z80 return the bus.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by Sik » Tue Nov 19, 2019 4:22 pm

When you assert bus request, what you're doing is asking the Z80 to let its bus alone — which may take a bit of time, since it needs to finish any ongoing access first. You're supposed to read back from $A11100 to know when the Z80 has done that. The problem is that while the Z80 is reset it will never tell you that it has given the bus (even though by definition it has done it already), so waiting for the Z80 to give you the bus while it's reset will result in a hang up (you waiting forever).
Sik is pronounced as "seek", not as "sick".

mickagame
Very interested
Posts: 256
Joined: Sat Jun 07, 2008 7:37 am

Re: Noob questions: DEFINITIVE info about Z80 BUSREQ, RESET?

Post by mickagame » Tue Nov 19, 2019 8:14 pm

Sik wrote:
Tue Nov 19, 2019 4:22 pm
When you assert bus request, what you're doing is asking the Z80 to let its bus alone — which may take a bit of time, since it needs to finish any ongoing access first. You're supposed to read back from $A11100 to know when the Z80 has done that. The problem is that while the Z80 is reset it will never tell you that it has given the bus (even though by definition it has done it already), so waiting for the Z80 to give you the bus while it's reset will result in a hang up (you waiting forever).
... and this reset can finish only when you will set the reset flag to 1, so you will wait forever :-)
All is clear ;-)

Post Reply