ekeeke / Genesis-Plus-GX

An enhanced port of Genesis Plus - accurate & portable Sega 8/16 bit emulator
Other
673 stars 193 forks source link

Looking for clarification on Z80's zstate #508

Closed NicholasBHubbard closed 1 year ago

NicholasBHubbard commented 1 year ago

The zstate variable is defined as so in genesis.c:

uint8 zstate;             /* Z80 bus state (d0 = BUSACK, d1 = /RESET) */

I am a bit confused however on what d0 and d1 actually mean. Based on the comment, I assume that if d0 == 1 then BUSACK is set, otherwise BUSACK is not set. And if d1 == 1 then RESET is not set, otherwise it is set. However throughout system.c, z80 execution is guarded by zstate == 1, for example here:

/* run Z80 until end of line */
if (zstate == 1)
{
  z80_run(mcycles_vdp + MCYCLES_PER_LINE);
}

If I understand correctly then that would mean we only run the z80 when BUSACK and RESET are both set. However it seems quite strange to me that we would run the Z80 only under such conditions.

I would appreciate clarification on what d0 and d1 stand for.

ekeeke commented 1 year ago

There is actually an error in that comment: D0 corresponds to Z80 /RESET state and D1 to Z80 bus request state.

The value 0x1 corresponds to the state where Z80 /RESET is not asserted (it is active low) and Z80 has access to its bus.

See also https://github.com/ekeeke/Genesis-Plus-GX/blob/master/core/genesis.c#L462 https://github.com/ekeeke/Genesis-Plus-GX/blob/master/core/genesis.c#L502