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