MicroCoreLabs / Projects

Ted Fried's MicroCore Labs Projects which include microsequencer-based FPGA cores and emulators for the 8088, 8086, 8051, 6502, 68000, Z80, Risc-V, and also Typewriter and EPROM Emulator projects. MCL51, MCL64, MCL65, MCL65+, MCL68, MCL86, MCL86+, MCL86jr, MCLR5, MCLZ8, MCL6809
390 stars 79 forks source link

MCLZ8 - Fetch_opcode() is wrongly used to retrieve immediate values, displacements or offsets in an instruction. #10

Open hlide opened 1 year ago

hlide commented 1 year ago

This function is called too often wrongly to retrieve immediate values, displacements or offsets in an instruction. You should use a MEM_READ_BYTE (3 T-states) and not an OPCODE_READ_M1 (4 T-states) for them! https://github.com/MicroCoreLabs/Projects/blob/26b2c2701e403da5991a13c1879093d4e3dbf226/MCLZ8/Code/Standard_Z80/MCLZ8.ino#L629

There is no M1 = 0 and no refresh when retrieving immediate values, displacements or offsets in an instruction!

See here a complex example here: https://floooh.github.io/2021/12/06/z80-instruction-timing.html#dd-and-fd-prefixes. Be aware the table are showing steps per half-cycle (half T-state) so a MEM_READ_BYTE would be 6 rows for 3 T-states.

MicroCoreLabs commented 1 year ago

Thank you for finding this bug! Code updated.