Skip to content

Commit 4e439f0

Browse files
committed
Add z80_wait, improve Doxygen documentation and update history.
1 parent a5720e7 commit 4e439f0

File tree

3 files changed

+105
-87
lines changed

3 files changed

+105
-87
lines changed

API/Z80.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ Z80_API void z80_int(Z80 *self, zbool state);
825825
Z80_API void z80_nmi(Z80 *self);
826826

827827
/** @brief Runs a <tt>@ref Z80</tt> for a given number of clock @p cycles,
828-
* executing only instructions without responding to signals.
828+
* executing only instructions without responding to interrupts requests or
829+
* special RESET signals.
829830
*
830831
* @param self Pointer to the object on which the function is called.
831832
* @param cycles Number of clock cycles to be emulated.
@@ -915,6 +916,19 @@ static Z_ALWAYS_INLINE zuint8 z80_out_cycle(Z80 const *self)
915916
}
916917

917918

919+
/** @brief Sends a WAIT signal to a <tt>@ref Z80</tt>.
920+
*
921+
* This function should only be used inside callback functions. It adds the
922+
* given number of clock @p cycles to <tt>@ref Z80::cycles</tt>, thus
923+
* lengthening the ongoing emulation step.
924+
*
925+
* @param self Pointer to the object on which the function is called.
926+
* @param cycles Duration of the WAIT signal, in clock cycles. */
927+
928+
static Z_ALWAYS_INLINE void z80_wait(Z80 *self, zusize cycles)
929+
{self->cycles += cycles;}
930+
931+
918932
Z_EXTERN_C_END
919933

920934
#endif /* Z80_H */

HISTORY

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,88 +29,90 @@ Changes:
2929
16. Added the `z80_in_cycle` and `z80_out_cycle` functions for obtaining the
3030
clock cycle at which the I/O M-cycle begins, relative to the start of the
3131
instruction.
32-
17. Added the `z80_refresh_address` function for getting the refresh address of
32+
17. Added the `z80_r` function for getting the current value of the R register.
33+
18. Added the `z80_refresh_address` function for getting the refresh address of
3334
the current M1 cycle.
34-
18. Renamed the `z80_reset` function to `z80_instant_reset`.
35-
19. Added optional emulation of the special RESET, and the `z80_special_reset`
35+
19. Added the `z80_wait` function for inserting wait states.
36+
20. Renamed the `z80_reset` function to `z80_instant_reset`.
37+
21. Added optional emulation of the special RESET, and the `z80_special_reset`
3638
function.
37-
20. Added the `Z80::fetch_opcode` and `Z80::fetch` callbacks for performing,
39+
22. Added the `Z80::fetch_opcode` and `Z80::fetch` callbacks for performing,
3840
respectively, opcode fetch operations and memory read operations on
3941
instruction data.
40-
21. Added the `Z80::nop` callback for performing disregarded opcode fetch
42+
23. Added the `Z80::nop` callback for performing disregarded opcode fetch
4143
operations during internal NOP M-cycles.
42-
22. Added emulation of the NMI acknowledge M-cycle through the new `Z80::nmia`
44+
24. Added emulation of the NMI acknowledge M-cycle through the new `Z80::nmia`
4345
callback.
44-
23. Added emulation of the INT acknowledge M-cycle through the new `Z80::inta`
46+
25. Added emulation of the INT acknowledge M-cycle through the new `Z80::inta`
4547
callback, which replaces `Z80::int_data`.
46-
24. Added optional full emulation of the interrupt mode 0, along with the new
48+
26. Added optional full emulation of the interrupt mode 0, along with the new
4749
`Z80::int_fetch` callback for performing bus read operations on instruction
4850
data. If not enabled at compile-time, the old simplified emulation is built,
4951
which supports only the most typical instructions.
50-
25. Added four callbacks for notifying the execution of important instructions:
52+
27. Added four callbacks for notifying the execution of important instructions:
5153
`Z80::ld_i_a`, `Z80::ld_r_a`, `Z80::reti` and `Z80::retn`.
52-
26. Added hooking functionality through the `ld h,h` instruction and the new
54+
28. Added hooking functionality through the `ld h,h` instruction and the new
5355
`Z80::hook` callback.
54-
27. Added the `Z80::illegal` callback for delegating the emulation of illegal
56+
29. Added the `Z80::illegal` callback for delegating the emulation of illegal
5557
instructions.
56-
28. Added emulation options that can be configured at runtime.
57-
29. Removed `Z80::state`. Replaced with individual members for the registers,
58+
30. Added emulation options that can be configured at runtime.
59+
31. Removed `Z80::state`. Replaced with individual members for the registers,
5860
the interrupt enable flip-flops and the interrupt mode.
59-
30. Removed the superfluous EI flag. The previous opcode is checked instead,
61+
32. Removed the superfluous EI flag. The previous opcode is checked instead,
6062
which is faster and makes the `Z80` object smaller.
61-
31. Removed all module-related stuff.
62-
32. Added emulation of the additional flag changes performed during the extra 5
63+
33. Removed all module-related stuff.
64+
34. Added emulation of the additional flag changes performed during the extra 5
6365
clock cycles of the following instructions: `ldir`, `lddr`, `cpir`, `cpdr`,
6466
`inir`, `indr`, `otir` and `otdr`.
65-
33. Added emulation of the interrupt acceptance deferral that occurs during the
67+
35. Added emulation of the interrupt acceptance deferral that occurs during the
6668
`reti` and `retn` instructions.
67-
34. Added MEMPTR emulation. The `bit N,(hl)` instruction now produces a correct
69+
36. Added MEMPTR emulation. The `bit N,(hl)` instruction now produces a correct
6870
value of F.
69-
35. Added optional emulation of Q. If enabled at compile-time, the `ccf` and
71+
37. Added optional emulation of Q. If enabled at compile-time, the `ccf` and
7072
`scf` instructions will produce a correct value of F.
71-
36. Added emulation of the `out (c),255` instruction (Zilog Z80 CMOS).
72-
37. Added optional emulation of the bug affecting the `ld a,{i|r}` instructions
73+
38. Added emulation of the `out (c),255` instruction (Zilog Z80 CMOS).
74+
39. Added optional emulation of the bug affecting the `ld a,{i|r}` instructions
7375
(Zilog Z80 NMOS). If enabled at compile-time and configured at runtime, the
7476
P/V flag will be reset if an INT is accepted during the execution of these
7577
instructions.
76-
38. Added an optional implementation of the parity calculation for the P/V flag
78+
40. Added an optional implementation of the parity calculation for the P/V flag
7779
that performs the actual computation instead of using a table of precomputed
7880
values.
79-
39. Added an optional implementation of the `daa` instruction that uses a table
81+
41. Added an optional implementation of the `daa` instruction that uses a table
8082
of precomputed values.
81-
40. Increased granularity. The emulator can now stop directly after fetching a
83+
42. Increased granularity. The emulator can now stop directly after fetching a
8284
prefix DDh or FDh if it runs out of clock cycles. This also works during the
8385
INT response in mode 0.
84-
41. Reimplemented the HALT state. The emulation should now be fully accurate.
86+
43. Reimplemented the HALT state. The emulation should now be fully accurate.
8587
HALTskip optimization is also supported.
86-
42. Fixed a bug in the `sll` instruction.
87-
43. Fixed a bug in the `INX` and `OUTX` macros affecting the S and N flags.
88-
44. Fixed a bug in the `OUTX` macro affecting the MSByte of the port number.
89-
45. Fixed the clock cycles of the `dec XY` and `in (c)` instructions.
90-
46. Fixed the `read_16` function so that the order of the memory read operations
88+
44. Fixed a bug in the `sll` instruction.
89+
45. Fixed a bug in the `INX` and `OUTX` macros affecting the S and N flags.
90+
46. Fixed a bug in the `OUTX` macro affecting the MSByte of the port number.
91+
47. Fixed the clock cycles of the `dec XY` and `in (c)` instructions.
92+
48. Fixed the `read_16` function so that the order of the memory read operations
9193
is not determined by the order in which the compiler evaluates expressions.
92-
47. Fixed the order in which the memory write operations are performed when the
94+
49. Fixed the order in which the memory write operations are performed when the
9395
SP register is involved. This affects the NMI response, the INT response in
9496
modes 1 and 2, and the following instructions: `ex (sp),{hl|XY}`, `push TT`,
9597
`push XY`, `call WORD`, `call Z,WORD` and `rst N`.
96-
48. Fixed the handling of illegal instructions to avoid stack overflows in long
98+
50. Fixed the handling of illegal instructions to avoid stack overflows in long
9799
sequences of DDh/FDh prefixes.
98-
49. Fixed several implicit conversions to avoid warnings about loss of sign and
100+
51. Fixed several implicit conversions to avoid warnings about loss of sign and
99101
precision.
100-
50. Fixed some bitwise operations to avoid undefined behavior and arithmetic
102+
52. Fixed some bitwise operations to avoid undefined behavior and arithmetic
101103
right shifts on signed integers.
102-
51. Fixed violations of the C standard in several identifiers.
103-
52. Renamed the 8-bit register lists: X/Y to J/K; J/K and P/Q to O/P.
104-
53. Replaced all P/V overflow computation functions with a single, faster macro.
105-
54. Replaced all register resolution functions with macros.
106-
55. Replaced all `ld {J,K|O,P}` instructions that have the same destination and
104+
53. Fixed violations of the C standard in several identifiers.
105+
54. Renamed the 8-bit register lists: X/Y to J/K; J/K and P/Q to O/P.
106+
55. Replaced all P/V overflow computation functions with a single, faster macro.
107+
56. Replaced all register resolution functions with macros.
108+
57. Replaced all `ld {J,K|O,P}` instructions that have the same destination and
107109
source register with NOPs. In addition, the "illegal" forms of the following
108110
instructions are now executed without using the illegal instruction handler:
109111
`ld O,P`, `ld O,BYTE`, `U [a,]P` and `V O`.
110-
56. Optimizations in flag computation and condition evaluation.
111-
57. New source code comments and improvements to existing ones.
112-
58. Improved code aesthetics.
113-
59. Other improvements, optimizations and minor changes.
112+
58. Optimizations in flag computation and condition evaluation.
113+
59. New source code comments and improvements to existing ones.
114+
60. Improved code aesthetics.
115+
61. Other improvements, optimizations and minor changes.
114116

115117

116118
Z80 v0.1 (2018-11-10)

0 commit comments

Comments
 (0)