Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
z180ex.c
Go to the documentation of this file.
1 /* Xep128: Minimalistic Enterprise-128 emulator with focus on "exotic" hardware
2  Copyright (C)2015,2016 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3  http://xep128.lgb.hu/
4 
5  Additional quirky Z180 emulation for Z80Ex. You should read
6  file README about the (lack of ...) features.
7 
8  FIXME: This must be integrated into opcodes_ed.c!
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
23 
24 #ifdef Z80EX_Z180_SUPPORT
25 
26 #warning "LGB: Z180 support is _very_ limited, please read file z80ex/README."
27 
28 #define MULT_OP_T_STATES 13
29 #define TST_OP_T_STATES 4
30 
31 #define ITC_B3 0xC0
32 #define ITC_B2 0x80
33 
34 
35 
36 #define TST(value)\
37 {\
38  F = FLAG_H | sz53p_table[A & (value)];\
39 }
40 
41 
42 
43 static void z180_trap ( void ) {
44  opcodes_base[0xC7](); /* = RST 0 */
45 }
46 
47 static const z80ex_opcode_fn trapping ( Z80EX_BYTE prefix, Z80EX_BYTE series, Z80EX_BYTE opcode, Z80EX_BYTE itc76 ) {
48 
49  PC--; /* back to the byte caused the invalid opcode trap */
50  if (prefix && series == 0xCB) PC--; /* odd enough, but it seems real Z180 stacks PC on the disp. byte in prefixed CB op!!! */
51  /* call user handler stuff */
52  z80ex_z180_cb(PC, prefix, series, opcode, itc76);
53  return z180_trap; /* respond with trap handler, heh! */
54 }
55 
56 
57 
58 
59 static const int opcodes_ddfd_bad_for_z180[0x100] = {
60 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
61 
62  1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1, /* 0. */
63  1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1, /* 1. */
64  1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1, /* 2. */
65  1,1,1,1,0,0,0,1,1,0,1,1,1,1,1,1, /* 3. */
66  1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1, /* 4. */
67  1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1, /* 5. */
68  1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1, /* 6. */
69  0,0,0,0,0,0,1,0,1,1,1,1,1,1,0,1, /* 7. */
70  1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1, /* 8. */
71  1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1, /* 9. */
72  1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1, /* A. */
73  1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1, /* B. */
74  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* C. */
75  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* D. */
76  1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,1, /* E. */
77  1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1 /* F. */
78 };
79 
80 
81 static void zop_ED_0x00(void) { /* 0xED 0x00 : IN0 B,(n) */
82 }
83 static void zop_ED_0x01(void) { /* 0xED 0x01 : OUT0 (n),B */
84 }
85 static void zop_ED_0x04(void) { /* 0xED 0x04 : TST B */
86  TST(B);
87  T_WAIT_UNTIL(TST_OP_T_STATES);
88 }
89 static void zop_ED_0x08(void) { /* 0xED 0x08 : IN0 C,(n) */
90 }
91 static void zop_ED_0x09(void) { /* 0xED 0x09 : OUT0 (n),C */
92 }
93 static void zop_ED_0x0C(void) { /* 0xED 0x0C : TST C */
94  TST(C);
95  T_WAIT_UNTIL(TST_OP_T_STATES);
96 }
97 static void zop_ED_0x10(void) { /* 0xED 0x10 : IN0 D,(n) */
98 }
99 static void zop_ED_0x11(void) { /* 0xED 0x11 : OUT0 (n),D */
100 }
101 static void zop_ED_0x14(void) { /* 0xED 0x14 : TST D */
102  TST(D);
103  T_WAIT_UNTIL(TST_OP_T_STATES);
104 }
105 static void zop_ED_0x18(void) { /* 0xED 0x18 : IN0 E,(n) */
106 }
107 static void zop_ED_0x19(void) { /* 0xED 0x19 : OUT0 (n),E */
108 }
109 static void zop_ED_0x1C(void) { /* 0xED 0x1C : TST E */
110  TST(E);
111  T_WAIT_UNTIL(TST_OP_T_STATES);
112 }
113 static void zop_ED_0x20(void) { /* 0xED 0x20 : IN0 H,(n) */
114 }
115 static void zop_ED_0x21(void) { /* 0xED 0x21 : OUT0 (n),H */
116 }
117 static void zop_ED_0x24(void) { /* 0xED 0x24 : TST H */
118  TST(H);
119  T_WAIT_UNTIL(TST_OP_T_STATES);
120 }
121 static void zop_ED_0x28(void) { /* 0xED 0x28 : IN0 L,(n) */
122 }
123 static void zop_ED_0x29(void) { /* 0xED 0x29 : OUT0 (n),L */
124 }
125 static void zop_ED_0x2C(void) { /* 0xED 0x2C : TST L */
126  TST(L);
127  T_WAIT_UNTIL(TST_OP_T_STATES);
128 }
129 static void zop_ED_0x30(void) { /* 0xED 0x30 : IN0 F,(n) */
130 }
131 static void zop_ED_0x34(void) { /* 0xED 0x34 : TST (HL) */
132  READ_MEM(temp_byte, (HL), 4);
133  TST(temp_byte);
134  T_WAIT_UNTIL(7);
135 }
136 static void zop_ED_0x38(void) { /* 0xED 0x38 : IN0 A,(n) */
137 }
138 static void zop_ED_0x39(void) { /* 0xED 0x39 : OUT0 (n),A */
139 }
140 static void zop_ED_0x3C(void) { /* 0xED 0x3C : TST A */
141  TST(A);
142  T_WAIT_UNTIL(TST_OP_T_STATES);
143 }
144 static void zop_ED_0x4C(void) { /* 0xED 0x4C : MULT BC */
145  BC = B * C;
146  T_WAIT_UNTIL(MULT_OP_T_STATES);
147 }
148 static void zop_ED_0x5C(void) { /* 0xED 0x5C : MULT DE */
149  DE = D * E;
150  T_WAIT_UNTIL(MULT_OP_T_STATES);
151 }
152 static void zop_ED_0x64(void) { /* 0xED 0x64 : TST n */
153 }
154 static void zop_ED_0x6C(void) { /* 0xED 0x6C : MULT HL */
155  HL = H * L;
156  T_WAIT_UNTIL(MULT_OP_T_STATES);
157 }
158 static void zop_ED_0x74(void) { /* 0xED 0x74 : TST (C),n [TESTIO] */
159 }
160 static void zop_ED_0x76(void) { /* 0xED 0x76 : SLP */
161  HALT(); /* really, not sure what SLP does, since it's opcode 0xED 0x76, we try
162  to execute 0x76 as it would be normal HALT opcode. The difference maybe only
163  the "depth" CPU is powered down, so for the emulation it does not make too much
164  different - I think - LGB */
165  T_WAIT_UNTIL(4);
166 }
167 static void zop_ED_0x7C(void) { /* 0xED 0x7C : MULT SP */
168  SP = SPH * SPL;
169  T_WAIT_UNTIL(MULT_OP_T_STATES);
170 }
171 static void zop_ED_0x83(void) { /* 0xED 0x83 : OTIM */
172 }
173 static void zop_ED_0x8B(void) { /* 0xED 0x8B : OTDM */
174 }
175 static void zop_ED_0x93(void) { /* 0xED 0x93 : OTIMR */
176 }
177 static void zop_ED_0x9B(void) { /* 0xED 0x9B : OTDMR */
178 }
179 
180 
181 
182 static const z80ex_opcode_fn opcodes_ed_z180[0x100] = {
183  zop_ED_0x00 , zop_ED_0x01 , NULL , NULL , /* 0x00 */
184  zop_ED_0x04 , NULL , NULL , NULL , /* 0x04 */
185  zop_ED_0x08 , zop_ED_0x09 , NULL , NULL , /* 0x08 */
186  zop_ED_0x0C , NULL , NULL , NULL , /* 0x0C */
187  zop_ED_0x10 , zop_ED_0x11 , NULL , NULL , /* 0x10 */
188  zop_ED_0x14 , NULL , NULL , NULL , /* 0x14 */
189  zop_ED_0x18 , zop_ED_0x19 , NULL , NULL , /* 0x18 */
190  zop_ED_0x1C , NULL , NULL , NULL , /* 0x1C */
191  zop_ED_0x20 , zop_ED_0x21 , NULL , NULL , /* 0x20 */
192  zop_ED_0x24 , NULL , NULL , NULL , /* 0x24 */
193  zop_ED_0x28 , zop_ED_0x29 , NULL , NULL , /* 0x28 */
194  zop_ED_0x2C , NULL , NULL , NULL , /* 0x2C */
195  zop_ED_0x30 , NULL , NULL , NULL , /* 0x30 */
196  zop_ED_0x34 , NULL , NULL , NULL , /* 0x34 */
197  zop_ED_0x38 , zop_ED_0x39 , NULL , NULL , /* 0x38 */
198  zop_ED_0x3C , NULL , NULL , NULL , /* 0x3C */
199  op_ED_0x40 , op_ED_0x41 , op_ED_0x42 , op_ED_0x43 , /* 0x40 */
200  op_ED_0x44 , op_ED_0x45 , op_ED_0x46 , op_ED_0x47 , /* 0x44 */
201  op_ED_0x48 , op_ED_0x49 , op_ED_0x4a , op_ED_0x4b , /* 0x48 */
202  zop_ED_0x4C , op_ED_0x4d , NULL , op_ED_0x4f , /* 0x4C */
203  op_ED_0x50 , op_ED_0x51 , op_ED_0x52 , op_ED_0x53 , /* 0x50 */
204  NULL , NULL , op_ED_0x56 , op_ED_0x57 , /* 0x54 */
205  op_ED_0x58 , op_ED_0x59 , op_ED_0x5a , op_ED_0x5b , /* 0x58 */
206  zop_ED_0x5C , NULL , op_ED_0x5e , op_ED_0x5f , /* 0x5C */
207  op_ED_0x60 , op_ED_0x61 , op_ED_0x62 , op_ED_0x63 , /* 0x60 */
208  zop_ED_0x64 , NULL , NULL , op_ED_0x67 , /* 0x64 */
209  op_ED_0x68 , op_ED_0x69 , op_ED_0x6a , op_ED_0x6b , /* 0x68 */
210  zop_ED_0x6C , NULL , NULL , op_ED_0x6f , /* 0x6C */
211  op_ED_0x70 , NULL , op_ED_0x72 , op_ED_0x73 , /* 0x70 */
212  zop_ED_0x74 , NULL , zop_ED_0x76 , NULL , /* 0x74 */
213  op_ED_0x78 , op_ED_0x79 , op_ED_0x7a , op_ED_0x7b , /* 0x78 */
214  zop_ED_0x7C , NULL , NULL , NULL , /* 0x7C */
215  NULL , NULL , NULL , zop_ED_0x83 , /* 0x80 */
216  NULL , NULL , NULL , NULL , /* 0x84 */
217  NULL , NULL , NULL , zop_ED_0x8B , /* 0x88 */
218  NULL , NULL , NULL , NULL , /* 0x8C */
219  NULL , NULL , NULL , zop_ED_0x93 , /* 0x90 */
220  NULL , NULL , NULL , NULL , /* 0x94 */
221  NULL , NULL , NULL , zop_ED_0x9B , /* 0x98 */
222  NULL , NULL , NULL , NULL , /* 0x9C */
223  op_ED_0xa0 , op_ED_0xa1 , op_ED_0xa2 , op_ED_0xa3 , /* 0xA0 */
224  NULL , NULL , NULL , NULL , /* 0xA4 */
225  op_ED_0xa8 , op_ED_0xa9 , op_ED_0xaa , op_ED_0xab , /* 0xA8 */
226  NULL , NULL , NULL , NULL , /* 0xAC */
227  op_ED_0xb0 , op_ED_0xb1 , op_ED_0xb2 , op_ED_0xb3 , /* 0xB0 */
228  NULL , NULL , NULL , NULL , /* 0xB4 */
229  op_ED_0xb8 , op_ED_0xb9 , op_ED_0xba , op_ED_0xbb , /* 0xB8 */
230  NULL , NULL , NULL , NULL , /* 0xBC */
231  NULL , NULL , NULL , NULL , /* 0xC0 */
232  NULL , NULL , NULL , NULL , /* 0xC4 */
233  NULL , NULL , NULL , NULL , /* 0xC8 */
234  NULL , NULL , NULL , NULL , /* 0xCC */
235  NULL , NULL , NULL , NULL , /* 0xD0 */
236  NULL , NULL , NULL , NULL , /* 0xD4 */
237  NULL , NULL , NULL , NULL , /* 0xD8 */
238  NULL , NULL , NULL , NULL , /* 0xDC */
239  NULL , NULL , NULL , NULL , /* 0xE0 */
240  NULL , NULL , NULL , NULL , /* 0xE4 */
241  NULL , NULL , NULL , NULL , /* 0xE8 */
242  NULL , NULL , NULL , NULL , /* 0xEC */
243  NULL , NULL , NULL , NULL , /* 0xF0 */
244  NULL , NULL , NULL , NULL , /* 0xF4 */
245  NULL , NULL , NULL , NULL , /* 0xF8 */
246  NULL , NULL , NULL , NULL /* 0xFC */
247 };
248 
249 #endif
250 
SPL
#define SPL
Definition: macros.h:58
SPH
#define SPH
Definition: macros.h:57
BC
#define BC
Definition: macros.h:23
B
#define B
Definition: macros.h:21
T_WAIT_UNTIL
#define T_WAIT_UNTIL(t_state)
Definition: macros.h:119
temp_byte
#define temp_byte
Definition: z80ex.c:23
HL
#define HL
Definition: macros.h:31
E
#define E
Definition: macros.h:26
SP
#define SP
Definition: macros.h:59
z80ex_opcode_fn
void(* z80ex_opcode_fn)(void)
Definition: z80ex.c:28
Z80EX_BYTE
unsigned char Z80EX_BYTE
Definition: z80ex.h:49
D
#define D
Definition: macros.h:25
H
#define H
Definition: macros.h:29
C
#define C
Definition: macros.h:22
DE
#define DE
Definition: macros.h:27
L
#define L
Definition: macros.h:30
HALT
#define HALT()
Definition: macros.h:1009
A
#define A
Definition: macros.h:17
PC
#define PC
Definition: macros.h:63
READ_MEM
#define READ_MEM(result, addr, t_state)
Definition: macros.h:147