openMSX
Z80.hh
Go to the documentation of this file.
1#ifndef Z80_HH
2#define Z80_HH
3
4#include "CPUClock.hh"
5
6#include "inline.hh"
7
8#include <cassert>
9
10namespace openmsx {
11
12class CPURegs;
13
14class Z80TYPE : public CPUClock
15{
16protected:
17 template<bool> struct Normalize { static constexpr bool value = false; };
18
19 static constexpr int CLOCK_FREQ = 3579545;
20 static constexpr int WAIT_CYCLES = 1;
21 static constexpr unsigned HALT_STATES = 4 + WAIT_CYCLES; // HALT + M1
22 static constexpr bool IS_R800 = false;
23
24 Z80TYPE(EmuTime::param time, Scheduler& scheduler_)
25 : CPUClock(time, scheduler_)
26 {
27 }
28
29 template<bool, bool> ALWAYS_INLINE void PRE_MEM (unsigned /*address*/) const {}
30 template< bool> ALWAYS_INLINE void POST_MEM (unsigned /*address*/) const {}
31 template<bool, bool> ALWAYS_INLINE void PRE_WORD (unsigned /*address*/) const {}
32 template< bool> ALWAYS_INLINE void POST_WORD(unsigned /*address*/) const {}
33
34 ALWAYS_INLINE void R800Refresh(CPURegs& /*R*/) const {}
36
37 ALWAYS_INLINE void setMemPtr(unsigned x) { memptr = x; }
38 [[nodiscard]] ALWAYS_INLINE unsigned getMemPtr() const { return memptr; }
39
40 static constexpr int
42 CC_LD_A_NN = 5+3+3+3, CC_LD_A_NN_1 = 5+1, CC_LD_A_NN_2 = 5+3+3+1,
43 CC_LD_A_I = 5+6,
45 CC_LD_R_N = 5+3, CC_LD_R_N_1 = 5+1,
47 CC_LD_R_XIX = 5+3+5+3, CC_LD_R_XIX_1 = 5+1, CC_LD_R_XIX_2 = 5+3+5+1, // +5
49 CC_LD_HL_N = 5+3+3, CC_LD_HL_N_1 = 5+1, CC_LD_HL_N_2 = 5+3+1,
51 CC_LD_NN_A = 5+3+3+3, CC_LD_NN_A_1 = 5+1, CC_LD_NN_A_2 = 5+3+3+1,
52 CC_LD_XIX_R = 5+3+5+3, CC_LD_XIX_R_1 = 5+1, CC_LD_XIX_R_2 = 5+3+5+1, // +5
53 CC_LD_XIX_N = 5+3+5+3, CC_LD_XIX_N_1 = 5+1, CC_LD_XIX_N_2 = 5+3+5+1, // +5
54 CC_LD_HL_XX = 5+3+3+3+3, CC_LD_HL_XX_1 = 5+1, CC_LD_HL_XX_2 = 5+3+3+1,
56 CC_LD_SS_NN = 5+3+3, CC_LD_SS_NN_1 = 5+1,
57 CC_LD_XX_HL = 5+3+3+3+3, CC_LD_XX_HL_1 = 5+1, CC_LD_XX_HL_2 = 5+3+3+1,
58
60 CC_CP_N = 5+3, CC_CP_N_1 = 5+1,
61 CC_CP_XHL = 5+3, CC_CP_XHL_1 = 5+1,
62 CC_CP_XIX = 5+3+5+3, CC_CP_XIX_1 = 5+1, CC_CP_XIX_2 = 5+3+5+1, // +5
64 CC_INC_XHL = 5+4+3, CC_INC_XHL_1 = 5+1, CC_INC_XHL_2 = 5+4+1,
65 CC_INC_XIX = 5+3+5+4+3, CC_INC_XIX_1 = 5+1, EE_INC_XIX = 8, // +5
67 CC_ADD_HL_SS = 5+4+3,
68 CC_ADC_HL_SS = 5+5+4+3,
69
70 CC_LDI = 5+5+3+5, CC_LDI_1 = 5+5+1, CC_LDI_2 = 5+5+3+1,
71 CC_LDIR = 5+5+3+5+5,
72 CC_CPI = 5+5+3+5, CC_CPI_1 = 5+5+1,
73 CC_CPIR = 5+5+3+5+5,
74
75 CC_PUSH = 6+3+3, CC_PUSH_1 = 6+1,
76 CC_POP = 5+3+3, CC_POP_1 = 5+1,
77 CC_CALL = 5+3+4+3+3, CC_CALL_1 = 5+1, EE_CALL = 6,
78 CC_CALL_A = 5+3+4+3+3, CC_CALL_B = 5+3+3,
79 CC_RST = 6+3+3,
80 CC_RET_A = 5+3+3, CC_RET_B = 5, EE_RET_C = 1,
81 CC_RETN = 5+5+3+3, EE_RETN = 5,
82 CC_JP_A = 5+3+3, CC_JP_B = 5+3+3, CC_JP_1 = 5+1,
84 CC_JR_A = 5+3+5, CC_JR_B = 5+3, CC_JR_1 = 5+1,
85 CC_DJNZ = 6+3+5, EE_DJNZ = 1,
86
87 CC_EX_SP_HL = 5+3+4+3+5, CC_EX_SP_HL_1 = 5+1, CC_EX_SP_HL_2 = 5+3+4+1,
88
89 CC_BIT_R = 5+5,
90 CC_BIT_XHL = 5+5+4, CC_BIT_XHL_1 = 5+5+1,
91 CC_BIT_XIX = 5+3+5+4, CC_BIT_XIX_1 = 5+3+5+1, // +5
92 CC_SET_R = 5+5,
93 CC_SET_XHL = 5+5+4+3, CC_SET_XHL_1 = 5+5+1, CC_SET_XHL_2 = 5+5+4+1,
94 CC_SET_XIX = 5+3+5+4+3, EE_SET_XIX = 3, // +5
95
96 CC_RLA = 5,
97 CC_RLD = 5+5+3+4+3, CC_RLD_1 = 5+5+1, CC_RLD_2 = 5+5+3+4+1,
98
99 CC_IN_A_N = 5+3+4, CC_IN_A_N_1 = 5+1, CC_IN_A_N_2 = 5+3+1,
100 CC_IN_R_C = 5+5+4, CC_IN_R_C_1 = 5+5+1,
101 CC_INI = 5+6+4+3, CC_INI_1 = 5+6+1, CC_INI_2 = 5+6+4+1,
102 CC_INIR = 5+6+4+3+5,
103 CC_OUT_N_A = 5+3+4, CC_OUT_N_A_1 = 5+1, CC_OUT_N_A_2 = 5+3+1,
104 CC_OUT_C_R = 5+5+4, CC_OUT_C_R_1 = 5+5+1,
105 CC_OUTI = 5+6+3+4, CC_OUTI_1 = 5+6+1, CC_OUTI_2 = 5+6+3+1,
106 CC_OTIR = 5+6+3+4+5,
107
108 CC_EX = 5,
113 CC_NEG = 5+5,
115 CC_DI = 5,
116 CC_EI = 5,
118 CC_IM = 5+5,
119
122
123 CC_NMI = 5+3+3, EE_NMI_1 = -1,
124 CC_IRQ0 = 7+3+3, EE_IRQ0_1 = 1,
125 CC_IRQ1 = 7+3+3, EE_IRQ1_1 = 1,
126 CC_IRQ2 = 7+3+3+3+3, EE_IRQ2_1 = 1, CC_IRQ2_2 = 7+3+3+1,
127
129 CC_DD = 5,
131 CC_DD_CB = 5+1, // +5
132 EE_ED = 5,
135
136 // versions (version number shared with CPUCore<> class)
137 // 1 -> initial version
138 // 2 -> moved memptr from CPUCore to here
139 template<typename Archive>
140 void serialize(Archive& ar, unsigned version)
141 {
142 CPUClock::serialize(ar, version);
143 if (version >= 2) {
144 ar.serialize("memptr", memptr);
145 }
146 }
147
148private:
149 unsigned memptr;
150};
151
152
153} // namespace openmsx
154
155#endif
void serialize(Archive &ar, unsigned version)
Definition CPUClock.cc:20
static constexpr int CC_CP_XIX
Definition Z80.hh:62
static constexpr int CC_JR_B
Definition Z80.hh:84
static constexpr int CC_RLA
Definition Z80.hh:96
static constexpr int CC_LD_HL_R_1
Definition Z80.hh:48
static constexpr int CC_OUTI
Definition Z80.hh:105
static constexpr int CC_RET_A
Definition Z80.hh:80
static constexpr int CC_CP_XIX_2
Definition Z80.hh:62
static constexpr int CC_DJNZ
Definition Z80.hh:85
static constexpr int CC_LD_A_SS
Definition Z80.hh:41
static constexpr int CC_HALT
Definition Z80.hh:117
static constexpr int CC_LDIR
Definition Z80.hh:71
static constexpr int CC_LD_A_NN
Definition Z80.hh:42
static constexpr int CC_MULUB
Definition Z80.hh:120
static constexpr int CC_PUSH
Definition Z80.hh:75
static constexpr int CC_INC_XIX
Definition Z80.hh:65
static constexpr int CC_OUT_N_A
Definition Z80.hh:103
ALWAYS_INLINE void PRE_WORD(unsigned) const
Definition Z80.hh:31
static constexpr int CC_BIT_XHL_1
Definition Z80.hh:90
ALWAYS_INLINE void R800ForcePageBreak() const
Definition Z80.hh:35
static constexpr int CC_PUSH_1
Definition Z80.hh:75
static constexpr int CC_RST
Definition Z80.hh:79
static constexpr int CC_LD_XIX_N_2
Definition Z80.hh:53
static constexpr int CC_ADD_HL_SS
Definition Z80.hh:67
static constexpr int EE_IRQ1_1
Definition Z80.hh:125
static constexpr int CC_WRMEM
Definition Z80.hh:134
static constexpr int CC_OUT_C_R
Definition Z80.hh:104
static constexpr int CC_CP_XHL_1
Definition Z80.hh:61
static constexpr int CC_CP_N_1
Definition Z80.hh:60
static constexpr int EE_SET_XIX
Definition Z80.hh:94
static constexpr int CC_JP_B
Definition Z80.hh:82
static constexpr int CC_JP_1
Definition Z80.hh:82
static constexpr int CC_OUTI_1
Definition Z80.hh:105
static constexpr int CC_EX_SP_HL
Definition Z80.hh:87
static constexpr int EE_CALL
Definition Z80.hh:77
static constexpr int CC_MAIN
Definition Z80.hh:128
static constexpr int CC_LD_SS_A_1
Definition Z80.hh:50
static constexpr int CC_RLD
Definition Z80.hh:97
static constexpr int CC_SET_XHL
Definition Z80.hh:93
static constexpr int CC_LD_HL_XX_1
Definition Z80.hh:54
static constexpr int EE_IRQ0_1
Definition Z80.hh:124
static constexpr int CC_IM
Definition Z80.hh:118
static constexpr int CC_SET_XHL_1
Definition Z80.hh:93
static constexpr int CC_LD_SS_NN
Definition Z80.hh:56
static constexpr int CC_LDI_1
Definition Z80.hh:70
ALWAYS_INLINE unsigned getMemPtr() const
Definition Z80.hh:38
static constexpr int CC_CALL
Definition Z80.hh:77
static constexpr bool IS_R800
Definition Z80.hh:22
static constexpr int CC_INI
Definition Z80.hh:101
static constexpr int CC_LD_XX_HL_2
Definition Z80.hh:57
static constexpr int CC_INIR
Definition Z80.hh:102
static constexpr int CC_LD_XIX_N
Definition Z80.hh:53
static constexpr int CC_OUT_N_A_2
Definition Z80.hh:103
static constexpr int CC_INC_SS
Definition Z80.hh:66
static constexpr int CC_LD_R_XIX
Definition Z80.hh:47
static constexpr int CC_RDMEM
Definition Z80.hh:133
static constexpr int CC_LD_A_I
Definition Z80.hh:43
static constexpr int CC_MULUW
Definition Z80.hh:121
static constexpr int CC_INC_R
Definition Z80.hh:63
void serialize(Archive &ar, unsigned version)
Definition Z80.hh:140
static constexpr int CC_LDI
Definition Z80.hh:70
static constexpr int CC_INI_1
Definition Z80.hh:101
static constexpr int CC_LD_HL_N_2
Definition Z80.hh:49
static constexpr int CC_JR_A
Definition Z80.hh:84
static constexpr int CC_POP
Definition Z80.hh:76
static constexpr int CC_LD_XIX_R
Definition Z80.hh:52
static constexpr int CC_IRQ2_2
Definition Z80.hh:126
static constexpr int CC_OTIR
Definition Z80.hh:106
static constexpr int CLOCK_FREQ
Definition Z80.hh:19
static constexpr int CC_RLD_1
Definition Z80.hh:97
static constexpr int CC_EI
Definition Z80.hh:116
static constexpr int CC_CP_N
Definition Z80.hh:60
static constexpr int CC_LD_HL_XX
Definition Z80.hh:54
static constexpr int CC_LD_NN_A
Definition Z80.hh:51
static constexpr int CC_INC_XHL
Definition Z80.hh:64
static constexpr int CC_LD_SP_HL
Definition Z80.hh:55
static constexpr int CC_INC_XHL_1
Definition Z80.hh:64
Z80TYPE(EmuTime::param time, Scheduler &scheduler_)
Definition Z80.hh:24
static constexpr int EE_IRQ2_1
Definition Z80.hh:126
static constexpr int CC_RETN
Definition Z80.hh:81
static constexpr int EE_DJNZ
Definition Z80.hh:85
static constexpr int CC_INC_XHL_2
Definition Z80.hh:64
static constexpr int CC_CPL
Definition Z80.hh:114
static constexpr int EE_INC_XIX
Definition Z80.hh:65
static constexpr int CC_CP_XHL
Definition Z80.hh:61
static constexpr int CC_CALL_A
Definition Z80.hh:78
static constexpr int WAIT_CYCLES
Definition Z80.hh:20
static constexpr int CC_LD_HL_XX_2
Definition Z80.hh:54
static constexpr int CC_LD_XIX_N_1
Definition Z80.hh:53
static constexpr int CC_CPI_1
Definition Z80.hh:72
static constexpr int CC_DD_CB
Definition Z80.hh:131
static constexpr int CC_ADC_HL_SS
Definition Z80.hh:68
static constexpr int CC_LD_XIX_R_1
Definition Z80.hh:52
static constexpr int CC_SET_XHL_2
Definition Z80.hh:93
static constexpr int CC_PREFIX
Definition Z80.hh:130
ALWAYS_INLINE void POST_MEM(unsigned) const
Definition Z80.hh:30
static constexpr int CC_DAA
Definition Z80.hh:112
static constexpr int CC_BIT_XHL
Definition Z80.hh:90
static constexpr int CC_SCF
Definition Z80.hh:111
static constexpr int CC_IN_A_N
Definition Z80.hh:99
static constexpr int CC_LD_A_NN_1
Definition Z80.hh:42
static constexpr int EE_RETN
Definition Z80.hh:81
static constexpr int CC_LD_HL_N
Definition Z80.hh:49
static constexpr int CC_OUT_C_R_1
Definition Z80.hh:104
static constexpr int CC_DI
Definition Z80.hh:115
ALWAYS_INLINE void R800Refresh(CPURegs &) const
Definition Z80.hh:34
static constexpr int CC_IN_A_N_2
Definition Z80.hh:99
static constexpr int CC_LD_A_NN_2
Definition Z80.hh:42
ALWAYS_INLINE void POST_WORD(unsigned) const
Definition Z80.hh:32
static constexpr int CC_NOP
Definition Z80.hh:109
static constexpr int CC_LD_A_SS_1
Definition Z80.hh:41
static constexpr int CC_LD_R_N
Definition Z80.hh:45
static constexpr int CC_CALL_1
Definition Z80.hh:77
static constexpr int CC_LD_XX_HL
Definition Z80.hh:57
static constexpr int CC_JR_1
Definition Z80.hh:84
static constexpr int CC_BIT_XIX_1
Definition Z80.hh:91
static constexpr int CC_NMI
Definition Z80.hh:123
static constexpr int CC_LD_R_R
Definition Z80.hh:44
static constexpr int CC_LD_HL_R
Definition Z80.hh:48
static constexpr int CC_CCF
Definition Z80.hh:110
static constexpr int CC_LD_SS_A
Definition Z80.hh:50
static constexpr int CC_LD_NN_A_1
Definition Z80.hh:51
static constexpr int CC_CP_XIX_1
Definition Z80.hh:62
static constexpr int CC_LD_XIX_R_2
Definition Z80.hh:52
static constexpr int CC_SET_R
Definition Z80.hh:92
static constexpr int CC_LD_R_HL
Definition Z80.hh:46
static constexpr int CC_IN_A_N_1
Definition Z80.hh:99
static constexpr int EE_ED
Definition Z80.hh:132
static constexpr int CC_LDI_2
Definition Z80.hh:70
static constexpr int CC_CALL_B
Definition Z80.hh:78
static constexpr int CC_INC_XIX_1
Definition Z80.hh:65
static constexpr int CC_OUT_N_A_1
Definition Z80.hh:103
static constexpr int CC_OUTI_2
Definition Z80.hh:105
static constexpr int CC_DD
Definition Z80.hh:129
static constexpr int CC_JP_HL
Definition Z80.hh:83
static constexpr int CC_EX_SP_HL_2
Definition Z80.hh:87
static constexpr int CC_EX_SP_HL_1
Definition Z80.hh:87
static constexpr int CC_POP_1
Definition Z80.hh:76
static constexpr int CC_LD_SS_NN_1
Definition Z80.hh:56
static constexpr int CC_IRQ1
Definition Z80.hh:125
static constexpr unsigned HALT_STATES
Definition Z80.hh:21
static constexpr int CC_RET_B
Definition Z80.hh:80
static constexpr int CC_SET_XIX
Definition Z80.hh:94
static constexpr int CC_RLD_2
Definition Z80.hh:97
static constexpr int CC_LD_XX_HL_1
Definition Z80.hh:57
static constexpr int CC_LD_R_XIX_2
Definition Z80.hh:47
static constexpr int CC_CPI
Definition Z80.hh:72
static constexpr int CC_LD_NN_A_2
Definition Z80.hh:51
static constexpr int CC_NEG
Definition Z80.hh:113
static constexpr int CC_LD_R_XIX_1
Definition Z80.hh:47
static constexpr int CC_LD_HL_N_1
Definition Z80.hh:49
static constexpr int CC_EX
Definition Z80.hh:108
static constexpr int CC_IRQ0
Definition Z80.hh:124
ALWAYS_INLINE void PRE_MEM(unsigned) const
Definition Z80.hh:29
static constexpr int EE_RET_C
Definition Z80.hh:80
static constexpr int EE_NMI_1
Definition Z80.hh:123
static constexpr int CC_IRQ2
Definition Z80.hh:126
ALWAYS_INLINE void setMemPtr(unsigned x)
Definition Z80.hh:37
static constexpr int CC_JP_A
Definition Z80.hh:82
static constexpr int CC_LD_R_HL_1
Definition Z80.hh:46
static constexpr int CC_IN_R_C
Definition Z80.hh:100
static constexpr int CC_BIT_R
Definition Z80.hh:89
static constexpr int CC_LD_R_N_1
Definition Z80.hh:45
static constexpr int CC_CPIR
Definition Z80.hh:73
static constexpr int CC_IN_R_C_1
Definition Z80.hh:100
static constexpr int CC_CP_R
Definition Z80.hh:59
static constexpr int CC_BIT_XIX
Definition Z80.hh:91
static constexpr int CC_INI_2
Definition Z80.hh:101
#define ALWAYS_INLINE
Definition inline.hh:16
This file implemented 3 utility functions:
Definition Autofire.cc:11
static constexpr bool value
Definition Z80.hh:17