Import Debian changes 1.23-11
[debian-dgen.git] / zz80.c
blob169a268981cdc0e3a162890f7fbcd61898d40066
1 /* Multi-Z80 32 Bit emulator */
3 /* Copyright 1996-2000 Neil Bradley, All rights reserved
5 * License agreement:
7 * (MZ80 Refers to both the assembly code emitted by makeZ80.c and makeZ80.c
8 * itself)
10 * MZ80 May be distributed in unmodified form to any medium.
12 * MZ80 May not be sold, or sold as a part of a commercial package without
13 * the express written permission of Neil Bradley (neil@synthcom.com). This
14 * includes shareware.
16 * Modified versions of MZ80 may not be publicly redistributed without author
17 * approval (neil@synthcom.com). This includes distributing via a publicly
18 * accessible LAN. You may make your own source modifications and distribute
19 * MZ80 in source or object form, but if you make modifications to MZ80
20 * then it should be noted in the top as a comment in makeZ80.c.
22 * MZ80 Licensing for commercial applications is available. Please email
23 * neil@synthcom.com for details.
25 * Synthcom Systems, Inc, and Neil Bradley will not be held responsible for
26 * any damage done by the use of MZ80. It is purely "as-is".
28 * If you use MZ80 in a freeware application, credit in the following text:
30 * "Multi-Z80 CPU emulator by Neil Bradley (neil@synthcom.com)"
32 * must accompany the freeware application within the application itself or
33 * in the documentation.
35 * Legal stuff aside:
37 * If you find problems with MZ80, please email the author so they can get
38 * resolved. If you find a bug and fix it, please also email the author so
39 * that those bug fixes can be propogated to the installed base of MZ80
40 * users. If you find performance improvements or problems with MZ80, please
41 * email the author with your changes/suggestions and they will be rolled in
42 * with subsequent releases of MZ80.
44 * The whole idea of this emulator is to have the fastest available 32 bit
45 * Multi-Z80 emulator for the PC, giving maximum performance.
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <string.h>
51 #include "mz80.h"
52 UINT32 z80intAddr;
53 UINT32 z80pc;
56 /* Modular global variables go here*/
58 static CONTEXTMZ80 cpu; /* CPU Context */
59 static UINT8 *pbPC; /* Program counter normalized */
60 static UINT8 *pbSP; /* Stack pointer normalized */
61 static struct MemoryReadByte *psMemRead; /* Read memory structure */
62 static struct MemoryWriteByte *psMemWrite; /* Write memory structure */
63 static struct z80PortRead *psIoRead; /* Read I/O structure */
64 static struct z80PortWrite *psIoWrite; /* Write memory structure */
65 static INT32 sdwCyclesRemaining; /* Used as a countdown */
66 static UINT32 dwReturnCode; /* Return code from exec() */
67 static UINT32 dwOriginalCycles; /* How many cycles did we start with? */
68 static UINT32 dwElapsedTicks; /* How many ticks did we elapse? */
69 static INT32 sdwAddr; /* Temporary address storage */
70 static UINT32 dwAddr; /* Temporary stack address */
71 static UINT8 *pbAddAdcTable; /* Pointer to add/adc flag table */
72 static UINT8 *pbSubSbcTable; /* Pointer to sub/sbc flag table */
73 static UINT32 dwTemp; /* Temporary value */
75 static UINT8 bTemp; /* Temporary value */
77 static UINT8 bTemp2; /* Temporary value */
79 /* Precomputed flag tables */
81 static UINT8 bPostIncFlags[0x100] =
83 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
84 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
85 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
86 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
87 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
88 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
89 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
90 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x94,
91 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,
92 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,
93 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,
94 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,
95 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,
96 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,
97 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,
98 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x50
101 static UINT8 bPostDecFlags[0x100] =
103 0x92,0x42,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
104 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
105 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
106 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
107 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
108 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
109 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
110 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
111 0x16,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
112 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
113 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
114 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
115 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
116 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
117 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
118 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82
121 static UINT8 bPostORFlags[0x100] =
123 0x44,0x00,0x00,0x04,0x00,0x04,0x04,0x00,0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,
124 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,
125 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,
126 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,
127 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,
128 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,
129 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,
130 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,
131 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,
132 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,
133 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,
134 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,
135 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,
136 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,
137 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,
138 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84
141 static UINT8 bPostANDFlags[0x100] =
143 0x54,0x10,0x10,0x14,0x10,0x14,0x14,0x10,0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,
144 0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,
145 0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,
146 0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,
147 0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,
148 0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,
149 0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,
150 0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,
151 0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,
152 0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,
153 0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,
154 0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,
155 0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,
156 0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,
157 0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,
158 0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94
161 static UINT16 wDAATable[0x800] =
163 0x5400,0x1001,0x1002,0x1403,0x1004,0x1405,0x1406,0x1007,
164 0x1008,0x1409,0x1010,0x1411,0x1412,0x1013,0x1414,0x1015,
165 0x1010,0x1411,0x1412,0x1013,0x1414,0x1015,0x1016,0x1417,
166 0x1418,0x1019,0x1020,0x1421,0x1422,0x1023,0x1424,0x1025,
167 0x1020,0x1421,0x1422,0x1023,0x1424,0x1025,0x1026,0x1427,
168 0x1428,0x1029,0x1430,0x1031,0x1032,0x1433,0x1034,0x1435,
169 0x1430,0x1031,0x1032,0x1433,0x1034,0x1435,0x1436,0x1037,
170 0x1038,0x1439,0x1040,0x1441,0x1442,0x1043,0x1444,0x1045,
171 0x1040,0x1441,0x1442,0x1043,0x1444,0x1045,0x1046,0x1447,
172 0x1448,0x1049,0x1450,0x1051,0x1052,0x1453,0x1054,0x1455,
173 0x1450,0x1051,0x1052,0x1453,0x1054,0x1455,0x1456,0x1057,
174 0x1058,0x1459,0x1460,0x1061,0x1062,0x1463,0x1064,0x1465,
175 0x1460,0x1061,0x1062,0x1463,0x1064,0x1465,0x1466,0x1067,
176 0x1068,0x1469,0x1070,0x1471,0x1472,0x1073,0x1474,0x1075,
177 0x1070,0x1471,0x1472,0x1073,0x1474,0x1075,0x1076,0x1477,
178 0x1478,0x1079,0x9080,0x9481,0x9482,0x9083,0x9484,0x9085,
179 0x9080,0x9481,0x9482,0x9083,0x9484,0x9085,0x9086,0x9487,
180 0x9488,0x9089,0x9490,0x9091,0x9092,0x9493,0x9094,0x9495,
181 0x9490,0x9091,0x9092,0x9493,0x9094,0x9495,0x9496,0x9097,
182 0x9098,0x9499,0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,
183 0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,0x1506,0x1107,
184 0x1108,0x1509,0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,
185 0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,0x1116,0x1517,
186 0x1518,0x1119,0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,
187 0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,0x1126,0x1527,
188 0x1528,0x1129,0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,
189 0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,0x1536,0x1137,
190 0x1138,0x1539,0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,
191 0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,0x1146,0x1547,
192 0x1548,0x1149,0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,
193 0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,0x1556,0x1157,
194 0x1158,0x1559,0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,
195 0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,0x1566,0x1167,
196 0x1168,0x1569,0x1170,0x1571,0x1572,0x1173,0x1574,0x1175,
197 0x1170,0x1571,0x1572,0x1173,0x1574,0x1175,0x1176,0x1577,
198 0x1578,0x1179,0x9180,0x9581,0x9582,0x9183,0x9584,0x9185,
199 0x9180,0x9581,0x9582,0x9183,0x9584,0x9185,0x9186,0x9587,
200 0x9588,0x9189,0x9590,0x9191,0x9192,0x9593,0x9194,0x9595,
201 0x9590,0x9191,0x9192,0x9593,0x9194,0x9595,0x9596,0x9197,
202 0x9198,0x9599,0x95a0,0x91a1,0x91a2,0x95a3,0x91a4,0x95a5,
203 0x95a0,0x91a1,0x91a2,0x95a3,0x91a4,0x95a5,0x95a6,0x91a7,
204 0x91a8,0x95a9,0x91b0,0x95b1,0x95b2,0x91b3,0x95b4,0x91b5,
205 0x91b0,0x95b1,0x95b2,0x91b3,0x95b4,0x91b5,0x91b6,0x95b7,
206 0x95b8,0x91b9,0x95c0,0x91c1,0x91c2,0x95c3,0x91c4,0x95c5,
207 0x95c0,0x91c1,0x91c2,0x95c3,0x91c4,0x95c5,0x95c6,0x91c7,
208 0x91c8,0x95c9,0x91d0,0x95d1,0x95d2,0x91d3,0x95d4,0x91d5,
209 0x91d0,0x95d1,0x95d2,0x91d3,0x95d4,0x91d5,0x91d6,0x95d7,
210 0x95d8,0x91d9,0x91e0,0x95e1,0x95e2,0x91e3,0x95e4,0x91e5,
211 0x91e0,0x95e1,0x95e2,0x91e3,0x95e4,0x91e5,0x91e6,0x95e7,
212 0x95e8,0x91e9,0x95f0,0x91f1,0x91f2,0x95f3,0x91f4,0x95f5,
213 0x95f0,0x91f1,0x91f2,0x95f3,0x91f4,0x95f5,0x95f6,0x91f7,
214 0x91f8,0x95f9,0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,
215 0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,0x1506,0x1107,
216 0x1108,0x1509,0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,
217 0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,0x1116,0x1517,
218 0x1518,0x1119,0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,
219 0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,0x1126,0x1527,
220 0x1528,0x1129,0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,
221 0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,0x1536,0x1137,
222 0x1138,0x1539,0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,
223 0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,0x1146,0x1547,
224 0x1548,0x1149,0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,
225 0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,0x1556,0x1157,
226 0x1158,0x1559,0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,
227 0x1406,0x1007,0x1008,0x1409,0x140a,0x100b,0x140c,0x100d,
228 0x100e,0x140f,0x1010,0x1411,0x1412,0x1013,0x1414,0x1015,
229 0x1016,0x1417,0x1418,0x1019,0x101a,0x141b,0x101c,0x141d,
230 0x141e,0x101f,0x1020,0x1421,0x1422,0x1023,0x1424,0x1025,
231 0x1026,0x1427,0x1428,0x1029,0x102a,0x142b,0x102c,0x142d,
232 0x142e,0x102f,0x1430,0x1031,0x1032,0x1433,0x1034,0x1435,
233 0x1436,0x1037,0x1038,0x1439,0x143a,0x103b,0x143c,0x103d,
234 0x103e,0x143f,0x1040,0x1441,0x1442,0x1043,0x1444,0x1045,
235 0x1046,0x1447,0x1448,0x1049,0x104a,0x144b,0x104c,0x144d,
236 0x144e,0x104f,0x1450,0x1051,0x1052,0x1453,0x1054,0x1455,
237 0x1456,0x1057,0x1058,0x1459,0x145a,0x105b,0x145c,0x105d,
238 0x105e,0x145f,0x1460,0x1061,0x1062,0x1463,0x1064,0x1465,
239 0x1466,0x1067,0x1068,0x1469,0x146a,0x106b,0x146c,0x106d,
240 0x106e,0x146f,0x1070,0x1471,0x1472,0x1073,0x1474,0x1075,
241 0x1076,0x1477,0x1478,0x1079,0x107a,0x147b,0x107c,0x147d,
242 0x147e,0x107f,0x9080,0x9481,0x9482,0x9083,0x9484,0x9085,
243 0x9086,0x9487,0x9488,0x9089,0x908a,0x948b,0x908c,0x948d,
244 0x948e,0x908f,0x9490,0x9091,0x9092,0x9493,0x9094,0x9495,
245 0x9496,0x9097,0x9098,0x9499,0x949a,0x909b,0x949c,0x909d,
246 0x909e,0x949f,0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,
247 0x1506,0x1107,0x1108,0x1509,0x150a,0x110b,0x150c,0x110d,
248 0x110e,0x150f,0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,
249 0x1116,0x1517,0x1518,0x1119,0x111a,0x151b,0x111c,0x151d,
250 0x151e,0x111f,0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,
251 0x1126,0x1527,0x1528,0x1129,0x112a,0x152b,0x112c,0x152d,
252 0x152e,0x112f,0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,
253 0x1536,0x1137,0x1138,0x1539,0x153a,0x113b,0x153c,0x113d,
254 0x113e,0x153f,0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,
255 0x1146,0x1547,0x1548,0x1149,0x114a,0x154b,0x114c,0x154d,
256 0x154e,0x114f,0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,
257 0x1556,0x1157,0x1158,0x1559,0x155a,0x115b,0x155c,0x115d,
258 0x115e,0x155f,0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,
259 0x1566,0x1167,0x1168,0x1569,0x156a,0x116b,0x156c,0x116d,
260 0x116e,0x156f,0x1170,0x1571,0x1572,0x1173,0x1574,0x1175,
261 0x1176,0x1577,0x1578,0x1179,0x117a,0x157b,0x117c,0x157d,
262 0x157e,0x117f,0x9180,0x9581,0x9582,0x9183,0x9584,0x9185,
263 0x9186,0x9587,0x9588,0x9189,0x918a,0x958b,0x918c,0x958d,
264 0x958e,0x918f,0x9590,0x9191,0x9192,0x9593,0x9194,0x9595,
265 0x9596,0x9197,0x9198,0x9599,0x959a,0x919b,0x959c,0x919d,
266 0x919e,0x959f,0x95a0,0x91a1,0x91a2,0x95a3,0x91a4,0x95a5,
267 0x95a6,0x91a7,0x91a8,0x95a9,0x95aa,0x91ab,0x95ac,0x91ad,
268 0x91ae,0x95af,0x91b0,0x95b1,0x95b2,0x91b3,0x95b4,0x91b5,
269 0x91b6,0x95b7,0x95b8,0x91b9,0x91ba,0x95bb,0x91bc,0x95bd,
270 0x95be,0x91bf,0x95c0,0x91c1,0x91c2,0x95c3,0x91c4,0x95c5,
271 0x95c6,0x91c7,0x91c8,0x95c9,0x95ca,0x91cb,0x95cc,0x91cd,
272 0x91ce,0x95cf,0x91d0,0x95d1,0x95d2,0x91d3,0x95d4,0x91d5,
273 0x91d6,0x95d7,0x95d8,0x91d9,0x91da,0x95db,0x91dc,0x95dd,
274 0x95de,0x91df,0x91e0,0x95e1,0x95e2,0x91e3,0x95e4,0x91e5,
275 0x91e6,0x95e7,0x95e8,0x91e9,0x91ea,0x95eb,0x91ec,0x95ed,
276 0x95ee,0x91ef,0x95f0,0x91f1,0x91f2,0x95f3,0x91f4,0x95f5,
277 0x95f6,0x91f7,0x91f8,0x95f9,0x95fa,0x91fb,0x95fc,0x91fd,
278 0x91fe,0x95ff,0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,
279 0x1506,0x1107,0x1108,0x1509,0x150a,0x110b,0x150c,0x110d,
280 0x110e,0x150f,0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,
281 0x1116,0x1517,0x1518,0x1119,0x111a,0x151b,0x111c,0x151d,
282 0x151e,0x111f,0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,
283 0x1126,0x1527,0x1528,0x1129,0x112a,0x152b,0x112c,0x152d,
284 0x152e,0x112f,0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,
285 0x1536,0x1137,0x1138,0x1539,0x153a,0x113b,0x153c,0x113d,
286 0x113e,0x153f,0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,
287 0x1146,0x1547,0x1548,0x1149,0x114a,0x154b,0x114c,0x154d,
288 0x154e,0x114f,0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,
289 0x1556,0x1157,0x1158,0x1559,0x155a,0x115b,0x155c,0x115d,
290 0x115e,0x155f,0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,
291 0x5600,0x1201,0x1202,0x1603,0x1204,0x1605,0x1606,0x1207,
292 0x1208,0x1609,0x1204,0x1605,0x1606,0x1207,0x1208,0x1609,
293 0x1210,0x1611,0x1612,0x1213,0x1614,0x1215,0x1216,0x1617,
294 0x1618,0x1219,0x1614,0x1215,0x1216,0x1617,0x1618,0x1219,
295 0x1220,0x1621,0x1622,0x1223,0x1624,0x1225,0x1226,0x1627,
296 0x1628,0x1229,0x1624,0x1225,0x1226,0x1627,0x1628,0x1229,
297 0x1630,0x1231,0x1232,0x1633,0x1234,0x1635,0x1636,0x1237,
298 0x1238,0x1639,0x1234,0x1635,0x1636,0x1237,0x1238,0x1639,
299 0x1240,0x1641,0x1642,0x1243,0x1644,0x1245,0x1246,0x1647,
300 0x1648,0x1249,0x1644,0x1245,0x1246,0x1647,0x1648,0x1249,
301 0x1650,0x1251,0x1252,0x1653,0x1254,0x1655,0x1656,0x1257,
302 0x1258,0x1659,0x1254,0x1655,0x1656,0x1257,0x1258,0x1659,
303 0x1660,0x1261,0x1262,0x1663,0x1264,0x1665,0x1666,0x1267,
304 0x1268,0x1669,0x1264,0x1665,0x1666,0x1267,0x1268,0x1669,
305 0x1270,0x1671,0x1672,0x1273,0x1674,0x1275,0x1276,0x1677,
306 0x1678,0x1279,0x1674,0x1275,0x1276,0x1677,0x1678,0x1279,
307 0x9280,0x9681,0x9682,0x9283,0x9684,0x9285,0x9286,0x9687,
308 0x9688,0x9289,0x9684,0x9285,0x9286,0x9687,0x9688,0x9289,
309 0x9690,0x9291,0x9292,0x9693,0x9294,0x9695,0x9696,0x9297,
310 0x9298,0x9699,0x1334,0x1735,0x1736,0x1337,0x1338,0x1739,
311 0x1340,0x1741,0x1742,0x1343,0x1744,0x1345,0x1346,0x1747,
312 0x1748,0x1349,0x1744,0x1345,0x1346,0x1747,0x1748,0x1349,
313 0x1750,0x1351,0x1352,0x1753,0x1354,0x1755,0x1756,0x1357,
314 0x1358,0x1759,0x1354,0x1755,0x1756,0x1357,0x1358,0x1759,
315 0x1760,0x1361,0x1362,0x1763,0x1364,0x1765,0x1766,0x1367,
316 0x1368,0x1769,0x1364,0x1765,0x1766,0x1367,0x1368,0x1769,
317 0x1370,0x1771,0x1772,0x1373,0x1774,0x1375,0x1376,0x1777,
318 0x1778,0x1379,0x1774,0x1375,0x1376,0x1777,0x1778,0x1379,
319 0x9380,0x9781,0x9782,0x9383,0x9784,0x9385,0x9386,0x9787,
320 0x9788,0x9389,0x9784,0x9385,0x9386,0x9787,0x9788,0x9389,
321 0x9790,0x9391,0x9392,0x9793,0x9394,0x9795,0x9796,0x9397,
322 0x9398,0x9799,0x9394,0x9795,0x9796,0x9397,0x9398,0x9799,
323 0x97a0,0x93a1,0x93a2,0x97a3,0x93a4,0x97a5,0x97a6,0x93a7,
324 0x93a8,0x97a9,0x93a4,0x97a5,0x97a6,0x93a7,0x93a8,0x97a9,
325 0x93b0,0x97b1,0x97b2,0x93b3,0x97b4,0x93b5,0x93b6,0x97b7,
326 0x97b8,0x93b9,0x97b4,0x93b5,0x93b6,0x97b7,0x97b8,0x93b9,
327 0x97c0,0x93c1,0x93c2,0x97c3,0x93c4,0x97c5,0x97c6,0x93c7,
328 0x93c8,0x97c9,0x93c4,0x97c5,0x97c6,0x93c7,0x93c8,0x97c9,
329 0x93d0,0x97d1,0x97d2,0x93d3,0x97d4,0x93d5,0x93d6,0x97d7,
330 0x97d8,0x93d9,0x97d4,0x93d5,0x93d6,0x97d7,0x97d8,0x93d9,
331 0x93e0,0x97e1,0x97e2,0x93e3,0x97e4,0x93e5,0x93e6,0x97e7,
332 0x97e8,0x93e9,0x97e4,0x93e5,0x93e6,0x97e7,0x97e8,0x93e9,
333 0x97f0,0x93f1,0x93f2,0x97f3,0x93f4,0x97f5,0x97f6,0x93f7,
334 0x93f8,0x97f9,0x93f4,0x97f5,0x97f6,0x93f7,0x93f8,0x97f9,
335 0x5700,0x1301,0x1302,0x1703,0x1304,0x1705,0x1706,0x1307,
336 0x1308,0x1709,0x1304,0x1705,0x1706,0x1307,0x1308,0x1709,
337 0x1310,0x1711,0x1712,0x1313,0x1714,0x1315,0x1316,0x1717,
338 0x1718,0x1319,0x1714,0x1315,0x1316,0x1717,0x1718,0x1319,
339 0x1320,0x1721,0x1722,0x1323,0x1724,0x1325,0x1326,0x1727,
340 0x1728,0x1329,0x1724,0x1325,0x1326,0x1727,0x1728,0x1329,
341 0x1730,0x1331,0x1332,0x1733,0x1334,0x1735,0x1736,0x1337,
342 0x1338,0x1739,0x1334,0x1735,0x1736,0x1337,0x1338,0x1739,
343 0x1340,0x1741,0x1742,0x1343,0x1744,0x1345,0x1346,0x1747,
344 0x1748,0x1349,0x1744,0x1345,0x1346,0x1747,0x1748,0x1349,
345 0x1750,0x1351,0x1352,0x1753,0x1354,0x1755,0x1756,0x1357,
346 0x1358,0x1759,0x1354,0x1755,0x1756,0x1357,0x1358,0x1759,
347 0x1760,0x1361,0x1362,0x1763,0x1364,0x1765,0x1766,0x1367,
348 0x1368,0x1769,0x1364,0x1765,0x1766,0x1367,0x1368,0x1769,
349 0x1370,0x1771,0x1772,0x1373,0x1774,0x1375,0x1376,0x1777,
350 0x1778,0x1379,0x1774,0x1375,0x1376,0x1777,0x1778,0x1379,
351 0x9380,0x9781,0x9782,0x9383,0x9784,0x9385,0x9386,0x9787,
352 0x9788,0x9389,0x9784,0x9385,0x9386,0x9787,0x9788,0x9389,
353 0x9790,0x9391,0x9392,0x9793,0x9394,0x9795,0x9796,0x9397,
354 0x9398,0x9799,0x9394,0x9795,0x9796,0x9397,0x9398,0x9799,
355 0x97fa,0x93fb,0x97fc,0x93fd,0x93fe,0x97ff,0x5600,0x1201,
356 0x1202,0x1603,0x1204,0x1605,0x1606,0x1207,0x1208,0x1609,
357 0x160a,0x120b,0x160c,0x120d,0x120e,0x160f,0x1210,0x1611,
358 0x1612,0x1213,0x1614,0x1215,0x1216,0x1617,0x1618,0x1219,
359 0x121a,0x161b,0x121c,0x161d,0x161e,0x121f,0x1220,0x1621,
360 0x1622,0x1223,0x1624,0x1225,0x1226,0x1627,0x1628,0x1229,
361 0x122a,0x162b,0x122c,0x162d,0x162e,0x122f,0x1630,0x1231,
362 0x1232,0x1633,0x1234,0x1635,0x1636,0x1237,0x1238,0x1639,
363 0x163a,0x123b,0x163c,0x123d,0x123e,0x163f,0x1240,0x1641,
364 0x1642,0x1243,0x1644,0x1245,0x1246,0x1647,0x1648,0x1249,
365 0x124a,0x164b,0x124c,0x164d,0x164e,0x124f,0x1650,0x1251,
366 0x1252,0x1653,0x1254,0x1655,0x1656,0x1257,0x1258,0x1659,
367 0x165a,0x125b,0x165c,0x125d,0x125e,0x165f,0x1660,0x1261,
368 0x1262,0x1663,0x1264,0x1665,0x1666,0x1267,0x1268,0x1669,
369 0x166a,0x126b,0x166c,0x126d,0x126e,0x166f,0x1270,0x1671,
370 0x1672,0x1273,0x1674,0x1275,0x1276,0x1677,0x1678,0x1279,
371 0x127a,0x167b,0x127c,0x167d,0x167e,0x127f,0x9280,0x9681,
372 0x9682,0x9283,0x9684,0x9285,0x9286,0x9687,0x9688,0x9289,
373 0x928a,0x968b,0x928c,0x968d,0x968e,0x928f,0x9690,0x9291,
374 0x9292,0x9693,0x1334,0x1735,0x1736,0x1337,0x1338,0x1739,
375 0x173a,0x133b,0x173c,0x133d,0x133e,0x173f,0x1340,0x1741,
376 0x1742,0x1343,0x1744,0x1345,0x1346,0x1747,0x1748,0x1349,
377 0x134a,0x174b,0x134c,0x174d,0x174e,0x134f,0x1750,0x1351,
378 0x1352,0x1753,0x1354,0x1755,0x1756,0x1357,0x1358,0x1759,
379 0x175a,0x135b,0x175c,0x135d,0x135e,0x175f,0x1760,0x1361,
380 0x1362,0x1763,0x1364,0x1765,0x1766,0x1367,0x1368,0x1769,
381 0x176a,0x136b,0x176c,0x136d,0x136e,0x176f,0x1370,0x1771,
382 0x1772,0x1373,0x1774,0x1375,0x1376,0x1777,0x1778,0x1379,
383 0x137a,0x177b,0x137c,0x177d,0x177e,0x137f,0x9380,0x9781,
384 0x9782,0x9383,0x9784,0x9385,0x9386,0x9787,0x9788,0x9389,
385 0x938a,0x978b,0x938c,0x978d,0x978e,0x938f,0x9790,0x9391,
386 0x9392,0x9793,0x9394,0x9795,0x9796,0x9397,0x9398,0x9799,
387 0x979a,0x939b,0x979c,0x939d,0x939e,0x979f,0x97a0,0x93a1,
388 0x93a2,0x97a3,0x93a4,0x97a5,0x97a6,0x93a7,0x93a8,0x97a9,
389 0x97aa,0x93ab,0x97ac,0x93ad,0x93ae,0x97af,0x93b0,0x97b1,
390 0x97b2,0x93b3,0x97b4,0x93b5,0x93b6,0x97b7,0x97b8,0x93b9,
391 0x93ba,0x97bb,0x93bc,0x97bd,0x97be,0x93bf,0x97c0,0x93c1,
392 0x93c2,0x97c3,0x93c4,0x97c5,0x97c6,0x93c7,0x93c8,0x97c9,
393 0x97ca,0x93cb,0x97cc,0x93cd,0x93ce,0x97cf,0x93d0,0x97d1,
394 0x97d2,0x93d3,0x97d4,0x93d5,0x93d6,0x97d7,0x97d8,0x93d9,
395 0x93da,0x97db,0x93dc,0x97dd,0x97de,0x93df,0x93e0,0x97e1,
396 0x97e2,0x93e3,0x97e4,0x93e5,0x93e6,0x97e7,0x97e8,0x93e9,
397 0x93ea,0x97eb,0x93ec,0x97ed,0x97ee,0x93ef,0x97f0,0x93f1,
398 0x93f2,0x97f3,0x93f4,0x97f5,0x97f6,0x93f7,0x93f8,0x97f9,
399 0x97fa,0x93fb,0x97fc,0x93fd,0x93fe,0x97ff,0x5700,0x1301,
400 0x1302,0x1703,0x1304,0x1705,0x1706,0x1307,0x1308,0x1709,
401 0x170a,0x130b,0x170c,0x130d,0x130e,0x170f,0x1310,0x1711,
402 0x1712,0x1313,0x1714,0x1315,0x1316,0x1717,0x1718,0x1319,
403 0x131a,0x171b,0x131c,0x171d,0x171e,0x131f,0x1320,0x1721,
404 0x1722,0x1323,0x1724,0x1325,0x1326,0x1727,0x1728,0x1329,
405 0x132a,0x172b,0x132c,0x172d,0x172e,0x132f,0x1730,0x1331,
406 0x1332,0x1733,0x1334,0x1735,0x1736,0x1337,0x1338,0x1739,
407 0x173a,0x133b,0x173c,0x133d,0x133e,0x173f,0x1340,0x1741,
408 0x1742,0x1343,0x1744,0x1345,0x1346,0x1747,0x1748,0x1349,
409 0x134a,0x174b,0x134c,0x174d,0x174e,0x134f,0x1750,0x1351,
410 0x1352,0x1753,0x1354,0x1755,0x1756,0x1357,0x1358,0x1759,
411 0x175a,0x135b,0x175c,0x135d,0x135e,0x175f,0x1760,0x1361,
412 0x1362,0x1763,0x1364,0x1765,0x1766,0x1367,0x1368,0x1769,
413 0x176a,0x136b,0x176c,0x136d,0x136e,0x176f,0x1370,0x1771,
414 0x1772,0x1373,0x1774,0x1375,0x1376,0x1777,0x1778,0x1379,
415 0x137a,0x177b,0x137c,0x177d,0x177e,0x137f,0x9380,0x9781,
416 0x9782,0x9383,0x9784,0x9385,0x9386,0x9787,0x9788,0x9389,
417 0x938a,0x978b,0x938c,0x978d,0x978e,0x938f,0x9790,0x9391,
418 0x9392,0x9793,0x9394,0x9795,0x9796,0x9397,0x9398,0x9799
421 void DDFDCBHandler(UINT32 dwWhich);
424 static void InvalidInstruction(UINT32 dwCount)
426 pbPC -= dwCount; /* Invalid instruction - back up */
427 dwReturnCode = (UINT32) pbPC - (UINT32) cpu.z80Base;
428 dwOriginalCycles -= sdwCyclesRemaining;
429 sdwCyclesRemaining = 0;
432 void CBHandler(void)
434 switch (*pbPC++)
436 case 0x00:
438 sdwCyclesRemaining -= 8;
439 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
440 bTemp2 = (cpu.z80B >> 7);
441 cpu.z80B = (cpu.z80B << 1) | bTemp2;
442 cpu.z80F |= bTemp2 | bPostORFlags[cpu.z80B];
443 break;
445 case 0x01:
447 sdwCyclesRemaining -= 8;
448 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
449 bTemp2 = (cpu.z80C >> 7);
450 cpu.z80C = (cpu.z80C << 1) | bTemp2;
451 cpu.z80F |= bTemp2 | bPostORFlags[cpu.z80C];
452 break;
454 case 0x02:
456 sdwCyclesRemaining -= 8;
457 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
458 bTemp2 = (cpu.z80D >> 7);
459 cpu.z80D = (cpu.z80D << 1) | bTemp2;
460 cpu.z80F |= bTemp2 | bPostORFlags[cpu.z80D];
461 break;
463 case 0x03:
465 sdwCyclesRemaining -= 8;
466 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
467 bTemp2 = (cpu.z80E >> 7);
468 cpu.z80E = (cpu.z80E << 1) | bTemp2;
469 cpu.z80F |= bTemp2 | bPostORFlags[cpu.z80E];
470 break;
472 case 0x04:
474 sdwCyclesRemaining -= 8;
475 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
476 bTemp2 = (cpu.z80H >> 7);
477 cpu.z80H = (cpu.z80H << 1) | bTemp2;
478 cpu.z80F |= bTemp2 | bPostORFlags[cpu.z80H];
479 break;
481 case 0x05:
483 sdwCyclesRemaining -= 8;
484 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
485 bTemp2 = (cpu.z80L >> 7);
486 cpu.z80L = (cpu.z80L << 1) | bTemp2;
487 cpu.z80F |= bTemp2 | bPostORFlags[cpu.z80L];
488 break;
490 case 0x06:
492 sdwCyclesRemaining -= 15;
493 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
494 while (psMemRead->lowAddr != 0xffffffff)
496 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
498 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
499 if (psMemRead->memoryCall)
501 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
503 else
505 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
507 psMemRead = NULL;
508 break;
510 ++psMemRead;
513 if (psMemRead)
515 bTemp = cpu.z80Base[cpu.z80HL];
518 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
519 bTemp2 = (bTemp >> 7);
520 bTemp = (bTemp << 1) | bTemp2;
521 cpu.z80F |= bTemp2 | bPostORFlags[bTemp];
522 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
523 while (psMemWrite->lowAddr != 0xffffffff)
525 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
527 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
528 if (psMemWrite->memoryCall)
530 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
532 else
534 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
536 psMemWrite = NULL;
537 break;
539 ++psMemWrite;
542 if (psMemWrite)
544 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
547 break;
549 case 0x07:
551 sdwCyclesRemaining -= 8;
552 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
553 bTemp2 = (cpu.z80A >> 7);
554 cpu.z80A = (cpu.z80A << 1) | bTemp2;
555 cpu.z80F |= bTemp2 | bPostORFlags[cpu.z80A];
556 break;
558 case 0x08:
560 sdwCyclesRemaining -= 8;
561 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
562 cpu.z80F |= (cpu.z80B & Z80_FLAG_CARRY);
563 cpu.z80B = (cpu.z80B >> 1) | (cpu.z80B << 7);
564 cpu.z80F |= bPostORFlags[cpu.z80B];
565 break;
567 case 0x09:
569 sdwCyclesRemaining -= 8;
570 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
571 cpu.z80F |= (cpu.z80C & Z80_FLAG_CARRY);
572 cpu.z80C = (cpu.z80C >> 1) | (cpu.z80C << 7);
573 cpu.z80F |= bPostORFlags[cpu.z80C];
574 break;
576 case 0x0a:
578 sdwCyclesRemaining -= 8;
579 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
580 cpu.z80F |= (cpu.z80D & Z80_FLAG_CARRY);
581 cpu.z80D = (cpu.z80D >> 1) | (cpu.z80D << 7);
582 cpu.z80F |= bPostORFlags[cpu.z80D];
583 break;
585 case 0x0b:
587 sdwCyclesRemaining -= 8;
588 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
589 cpu.z80F |= (cpu.z80E & Z80_FLAG_CARRY);
590 cpu.z80E = (cpu.z80E >> 1) | (cpu.z80E << 7);
591 cpu.z80F |= bPostORFlags[cpu.z80E];
592 break;
594 case 0x0c:
596 sdwCyclesRemaining -= 8;
597 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
598 cpu.z80F |= (cpu.z80H & Z80_FLAG_CARRY);
599 cpu.z80H = (cpu.z80H >> 1) | (cpu.z80H << 7);
600 cpu.z80F |= bPostORFlags[cpu.z80H];
601 break;
603 case 0x0d:
605 sdwCyclesRemaining -= 8;
606 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
607 cpu.z80F |= (cpu.z80L & Z80_FLAG_CARRY);
608 cpu.z80L = (cpu.z80L >> 1) | (cpu.z80L << 7);
609 cpu.z80F |= bPostORFlags[cpu.z80L];
610 break;
612 case 0x0e:
614 sdwCyclesRemaining -= 15;
615 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
616 while (psMemRead->lowAddr != 0xffffffff)
618 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
620 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
621 if (psMemRead->memoryCall)
623 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
625 else
627 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
629 psMemRead = NULL;
630 break;
632 ++psMemRead;
635 if (psMemRead)
637 bTemp = cpu.z80Base[cpu.z80HL];
640 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
641 cpu.z80F |= (bTemp & Z80_FLAG_CARRY);
642 bTemp = (bTemp >> 1) | (bTemp << 7);
643 cpu.z80F |= bPostORFlags[bTemp];
644 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
645 while (psMemWrite->lowAddr != 0xffffffff)
647 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
649 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
650 if (psMemWrite->memoryCall)
652 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
654 else
656 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
658 psMemWrite = NULL;
659 break;
661 ++psMemWrite;
664 if (psMemWrite)
666 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
669 break;
671 case 0x0f:
673 sdwCyclesRemaining -= 8;
674 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
675 cpu.z80F |= (cpu.z80A & Z80_FLAG_CARRY);
676 cpu.z80A = (cpu.z80A >> 1) | (cpu.z80A << 7);
677 cpu.z80F |= bPostORFlags[cpu.z80A];
678 break;
680 case 0x10:
682 sdwCyclesRemaining -= 8;
683 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
684 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
685 cpu.z80F |= (cpu.z80B >> 7);
686 cpu.z80B = (cpu.z80B << 1) | bTemp2;
687 cpu.z80F |= bPostORFlags[cpu.z80B];
688 break;
690 case 0x11:
692 sdwCyclesRemaining -= 8;
693 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
694 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
695 cpu.z80F |= (cpu.z80C >> 7);
696 cpu.z80C = (cpu.z80C << 1) | bTemp2;
697 cpu.z80F |= bPostORFlags[cpu.z80C];
698 break;
700 case 0x12:
702 sdwCyclesRemaining -= 8;
703 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
704 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
705 cpu.z80F |= (cpu.z80D >> 7);
706 cpu.z80D = (cpu.z80D << 1) | bTemp2;
707 cpu.z80F |= bPostORFlags[cpu.z80D];
708 break;
710 case 0x13:
712 sdwCyclesRemaining -= 8;
713 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
714 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
715 cpu.z80F |= (cpu.z80E >> 7);
716 cpu.z80E = (cpu.z80E << 1) | bTemp2;
717 cpu.z80F |= bPostORFlags[cpu.z80E];
718 break;
720 case 0x14:
722 sdwCyclesRemaining -= 8;
723 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
724 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
725 cpu.z80F |= (cpu.z80H >> 7);
726 cpu.z80H = (cpu.z80H << 1) | bTemp2;
727 cpu.z80F |= bPostORFlags[cpu.z80H];
728 break;
730 case 0x15:
732 sdwCyclesRemaining -= 8;
733 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
734 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
735 cpu.z80F |= (cpu.z80L >> 7);
736 cpu.z80L = (cpu.z80L << 1) | bTemp2;
737 cpu.z80F |= bPostORFlags[cpu.z80L];
738 break;
740 case 0x16:
742 sdwCyclesRemaining -= 15;
743 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
744 while (psMemRead->lowAddr != 0xffffffff)
746 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
748 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
749 if (psMemRead->memoryCall)
751 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
753 else
755 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
757 psMemRead = NULL;
758 break;
760 ++psMemRead;
763 if (psMemRead)
765 bTemp = cpu.z80Base[cpu.z80HL];
768 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
769 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
770 cpu.z80F |= (bTemp >> 7);
771 bTemp = (bTemp << 1) | bTemp2;
772 cpu.z80F |= bPostORFlags[bTemp];
773 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
774 while (psMemWrite->lowAddr != 0xffffffff)
776 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
778 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
779 if (psMemWrite->memoryCall)
781 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
783 else
785 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
787 psMemWrite = NULL;
788 break;
790 ++psMemWrite;
793 if (psMemWrite)
795 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
798 break;
800 case 0x17:
802 sdwCyclesRemaining -= 8;
803 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
804 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
805 cpu.z80F |= (cpu.z80A >> 7);
806 cpu.z80A = (cpu.z80A << 1) | bTemp2;
807 cpu.z80F |= bPostORFlags[cpu.z80A];
808 break;
810 case 0x18:
812 sdwCyclesRemaining -= 8;
813 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
814 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
815 cpu.z80F |= (cpu.z80B & Z80_FLAG_CARRY);
816 cpu.z80B = (cpu.z80B >> 1) | bTemp2;
817 cpu.z80F |= bPostORFlags[cpu.z80B];
818 break;
820 case 0x19:
822 sdwCyclesRemaining -= 8;
823 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
824 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
825 cpu.z80F |= (cpu.z80C & Z80_FLAG_CARRY);
826 cpu.z80C = (cpu.z80C >> 1) | bTemp2;
827 cpu.z80F |= bPostORFlags[cpu.z80C];
828 break;
830 case 0x1a:
832 sdwCyclesRemaining -= 8;
833 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
834 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
835 cpu.z80F |= (cpu.z80D & Z80_FLAG_CARRY);
836 cpu.z80D = (cpu.z80D >> 1) | bTemp2;
837 cpu.z80F |= bPostORFlags[cpu.z80D];
838 break;
840 case 0x1b:
842 sdwCyclesRemaining -= 8;
843 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
844 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
845 cpu.z80F |= (cpu.z80E & Z80_FLAG_CARRY);
846 cpu.z80E = (cpu.z80E >> 1) | bTemp2;
847 cpu.z80F |= bPostORFlags[cpu.z80E];
848 break;
850 case 0x1c:
852 sdwCyclesRemaining -= 8;
853 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
854 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
855 cpu.z80F |= (cpu.z80H & Z80_FLAG_CARRY);
856 cpu.z80H = (cpu.z80H >> 1) | bTemp2;
857 cpu.z80F |= bPostORFlags[cpu.z80H];
858 break;
860 case 0x1d:
862 sdwCyclesRemaining -= 8;
863 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
864 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
865 cpu.z80F |= (cpu.z80L & Z80_FLAG_CARRY);
866 cpu.z80L = (cpu.z80L >> 1) | bTemp2;
867 cpu.z80F |= bPostORFlags[cpu.z80L];
868 break;
870 case 0x1e:
872 sdwCyclesRemaining -= 15;
873 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
874 while (psMemRead->lowAddr != 0xffffffff)
876 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
878 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
879 if (psMemRead->memoryCall)
881 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
883 else
885 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
887 psMemRead = NULL;
888 break;
890 ++psMemRead;
893 if (psMemRead)
895 bTemp = cpu.z80Base[cpu.z80HL];
898 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
899 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
900 cpu.z80F |= (bTemp & Z80_FLAG_CARRY);
901 bTemp = (bTemp >> 1) | bTemp2;
902 cpu.z80F |= bPostORFlags[bTemp];
903 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
904 while (psMemWrite->lowAddr != 0xffffffff)
906 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
908 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
909 if (psMemWrite->memoryCall)
911 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
913 else
915 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
917 psMemWrite = NULL;
918 break;
920 ++psMemWrite;
923 if (psMemWrite)
925 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
928 break;
930 case 0x1f:
932 sdwCyclesRemaining -= 8;
933 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
934 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
935 cpu.z80F |= (cpu.z80A & Z80_FLAG_CARRY);
936 cpu.z80A = (cpu.z80A >> 1) | bTemp2;
937 cpu.z80F |= bPostORFlags[cpu.z80A];
938 break;
940 case 0x20:
942 sdwCyclesRemaining -= 8;
943 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
944 cpu.z80F |= (cpu.z80B >> 7);
945 cpu.z80B = (cpu.z80B << 1);
946 cpu.z80F |= bPostORFlags[cpu.z80B];
947 break;
949 case 0x21:
951 sdwCyclesRemaining -= 8;
952 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
953 cpu.z80F |= (cpu.z80C >> 7);
954 cpu.z80C = (cpu.z80C << 1);
955 cpu.z80F |= bPostORFlags[cpu.z80C];
956 break;
958 case 0x22:
960 sdwCyclesRemaining -= 8;
961 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
962 cpu.z80F |= (cpu.z80D >> 7);
963 cpu.z80D = (cpu.z80D << 1);
964 cpu.z80F |= bPostORFlags[cpu.z80D];
965 break;
967 case 0x23:
969 sdwCyclesRemaining -= 8;
970 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
971 cpu.z80F |= (cpu.z80E >> 7);
972 cpu.z80E = (cpu.z80E << 1);
973 cpu.z80F |= bPostORFlags[cpu.z80E];
974 break;
976 case 0x24:
978 sdwCyclesRemaining -= 8;
979 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
980 cpu.z80F |= (cpu.z80H >> 7);
981 cpu.z80H = (cpu.z80H << 1);
982 cpu.z80F |= bPostORFlags[cpu.z80H];
983 break;
985 case 0x25:
987 sdwCyclesRemaining -= 8;
988 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
989 cpu.z80F |= (cpu.z80L >> 7);
990 cpu.z80L = (cpu.z80L << 1);
991 cpu.z80F |= bPostORFlags[cpu.z80L];
992 break;
994 case 0x26:
996 sdwCyclesRemaining -= 15;
997 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
998 while (psMemRead->lowAddr != 0xffffffff)
1000 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1002 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1003 if (psMemRead->memoryCall)
1005 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1007 else
1009 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1011 psMemRead = NULL;
1012 break;
1014 ++psMemRead;
1017 if (psMemRead)
1019 bTemp = cpu.z80Base[cpu.z80HL];
1022 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1023 cpu.z80F |= (bTemp >> 7);
1024 bTemp = (bTemp << 1);
1025 cpu.z80F |= bPostORFlags[bTemp];
1026 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
1027 while (psMemWrite->lowAddr != 0xffffffff)
1029 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
1031 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1032 if (psMemWrite->memoryCall)
1034 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
1036 else
1038 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
1040 psMemWrite = NULL;
1041 break;
1043 ++psMemWrite;
1046 if (psMemWrite)
1048 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
1051 break;
1053 case 0x27:
1055 sdwCyclesRemaining -= 8;
1056 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1057 cpu.z80F |= (cpu.z80A >> 7);
1058 cpu.z80A = (cpu.z80A << 1);
1059 cpu.z80F |= bPostORFlags[cpu.z80A];
1060 break;
1062 case 0x28:
1064 sdwCyclesRemaining -= 8;
1065 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1066 cpu.z80F |= (cpu.z80B & Z80_FLAG_CARRY);
1067 cpu.z80B = (cpu.z80B >> 1) | (cpu.z80B & 0x80);
1068 cpu.z80F |= bPostORFlags[cpu.z80B];
1069 break;
1071 case 0x29:
1073 sdwCyclesRemaining -= 8;
1074 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1075 cpu.z80F |= (cpu.z80C & Z80_FLAG_CARRY);
1076 cpu.z80C = (cpu.z80C >> 1) | (cpu.z80C & 0x80);
1077 cpu.z80F |= bPostORFlags[cpu.z80C];
1078 break;
1080 case 0x2a:
1082 sdwCyclesRemaining -= 8;
1083 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1084 cpu.z80F |= (cpu.z80D & Z80_FLAG_CARRY);
1085 cpu.z80D = (cpu.z80D >> 1) | (cpu.z80D & 0x80);
1086 cpu.z80F |= bPostORFlags[cpu.z80D];
1087 break;
1089 case 0x2b:
1091 sdwCyclesRemaining -= 8;
1092 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1093 cpu.z80F |= (cpu.z80E & Z80_FLAG_CARRY);
1094 cpu.z80E = (cpu.z80E >> 1) | (cpu.z80E & 0x80);
1095 cpu.z80F |= bPostORFlags[cpu.z80E];
1096 break;
1098 case 0x2c:
1100 sdwCyclesRemaining -= 8;
1101 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1102 cpu.z80F |= (cpu.z80H & Z80_FLAG_CARRY);
1103 cpu.z80H = (cpu.z80H >> 1) | (cpu.z80H & 0x80);
1104 cpu.z80F |= bPostORFlags[cpu.z80H];
1105 break;
1107 case 0x2d:
1109 sdwCyclesRemaining -= 8;
1110 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1111 cpu.z80F |= (cpu.z80L & Z80_FLAG_CARRY);
1112 cpu.z80L = (cpu.z80L >> 1) | (cpu.z80L & 0x80);
1113 cpu.z80F |= bPostORFlags[cpu.z80L];
1114 break;
1116 case 0x2e:
1118 sdwCyclesRemaining -= 15;
1119 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
1120 while (psMemRead->lowAddr != 0xffffffff)
1122 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1124 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1125 if (psMemRead->memoryCall)
1127 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1129 else
1131 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1133 psMemRead = NULL;
1134 break;
1136 ++psMemRead;
1139 if (psMemRead)
1141 bTemp = cpu.z80Base[cpu.z80HL];
1144 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1145 cpu.z80F |= (bTemp & Z80_FLAG_CARRY);
1146 bTemp = (bTemp >> 1) | (bTemp & 0x80);
1147 cpu.z80F |= bPostORFlags[bTemp];
1148 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
1149 while (psMemWrite->lowAddr != 0xffffffff)
1151 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
1153 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1154 if (psMemWrite->memoryCall)
1156 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
1158 else
1160 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
1162 psMemWrite = NULL;
1163 break;
1165 ++psMemWrite;
1168 if (psMemWrite)
1170 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
1173 break;
1175 case 0x2f:
1177 sdwCyclesRemaining -= 8;
1178 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1179 cpu.z80F |= (cpu.z80A & Z80_FLAG_CARRY);
1180 cpu.z80A = (cpu.z80A >> 1) | (cpu.z80A & 0x80);
1181 cpu.z80F |= bPostORFlags[cpu.z80A];
1182 break;
1184 case 0x30:
1186 sdwCyclesRemaining -= 8;
1187 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1188 cpu.z80F |= (cpu.z80B >> 7);
1189 cpu.z80B = (cpu.z80B << 1);
1190 cpu.z80F |= bPostORFlags[cpu.z80B];
1191 break;
1193 case 0x31:
1195 sdwCyclesRemaining -= 8;
1196 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1197 cpu.z80F |= (cpu.z80C >> 7);
1198 cpu.z80C = (cpu.z80C << 1);
1199 cpu.z80F |= bPostORFlags[cpu.z80C];
1200 break;
1202 case 0x32:
1204 sdwCyclesRemaining -= 8;
1205 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1206 cpu.z80F |= (cpu.z80D >> 7);
1207 cpu.z80D = (cpu.z80D << 1);
1208 cpu.z80F |= bPostORFlags[cpu.z80D];
1209 break;
1211 case 0x33:
1213 sdwCyclesRemaining -= 8;
1214 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1215 cpu.z80F |= (cpu.z80E >> 7);
1216 cpu.z80E = (cpu.z80E << 1);
1217 cpu.z80F |= bPostORFlags[cpu.z80E];
1218 break;
1220 case 0x34:
1222 sdwCyclesRemaining -= 8;
1223 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1224 cpu.z80F |= (cpu.z80H >> 7);
1225 cpu.z80H = (cpu.z80H << 1);
1226 cpu.z80F |= bPostORFlags[cpu.z80H];
1227 break;
1229 case 0x35:
1231 sdwCyclesRemaining -= 8;
1232 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1233 cpu.z80F |= (cpu.z80L >> 7);
1234 cpu.z80L = (cpu.z80L << 1);
1235 cpu.z80F |= bPostORFlags[cpu.z80L];
1236 break;
1238 case 0x36:
1240 sdwCyclesRemaining -= 15;
1241 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
1242 while (psMemRead->lowAddr != 0xffffffff)
1244 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1246 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1247 if (psMemRead->memoryCall)
1249 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1251 else
1253 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1255 psMemRead = NULL;
1256 break;
1258 ++psMemRead;
1261 if (psMemRead)
1263 bTemp = cpu.z80Base[cpu.z80HL];
1266 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1267 cpu.z80F |= (bTemp >> 7);
1268 bTemp = (bTemp << 1);
1269 cpu.z80F |= bPostORFlags[bTemp];
1270 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
1271 while (psMemWrite->lowAddr != 0xffffffff)
1273 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
1275 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1276 if (psMemWrite->memoryCall)
1278 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
1280 else
1282 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
1284 psMemWrite = NULL;
1285 break;
1287 ++psMemWrite;
1290 if (psMemWrite)
1292 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
1295 break;
1297 case 0x37:
1299 sdwCyclesRemaining -= 8;
1300 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1301 cpu.z80F |= (cpu.z80A >> 7);
1302 cpu.z80A = (cpu.z80A << 1);
1303 cpu.z80F |= bPostORFlags[cpu.z80A];
1304 break;
1306 case 0x38:
1308 sdwCyclesRemaining -= 8;
1309 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1310 cpu.z80F |= (cpu.z80B & Z80_FLAG_CARRY);
1311 cpu.z80B = (cpu.z80B >> 1);
1312 cpu.z80F |= bPostORFlags[cpu.z80B];
1313 break;
1315 case 0x39:
1317 sdwCyclesRemaining -= 8;
1318 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1319 cpu.z80F |= (cpu.z80C & Z80_FLAG_CARRY);
1320 cpu.z80C = (cpu.z80C >> 1);
1321 cpu.z80F |= bPostORFlags[cpu.z80C];
1322 break;
1324 case 0x3a:
1326 sdwCyclesRemaining -= 8;
1327 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1328 cpu.z80F |= (cpu.z80D & Z80_FLAG_CARRY);
1329 cpu.z80D = (cpu.z80D >> 1);
1330 cpu.z80F |= bPostORFlags[cpu.z80D];
1331 break;
1333 case 0x3b:
1335 sdwCyclesRemaining -= 8;
1336 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1337 cpu.z80F |= (cpu.z80E & Z80_FLAG_CARRY);
1338 cpu.z80E = (cpu.z80E >> 1);
1339 cpu.z80F |= bPostORFlags[cpu.z80E];
1340 break;
1342 case 0x3c:
1344 sdwCyclesRemaining -= 8;
1345 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1346 cpu.z80F |= (cpu.z80H & Z80_FLAG_CARRY);
1347 cpu.z80H = (cpu.z80H >> 1);
1348 cpu.z80F |= bPostORFlags[cpu.z80H];
1349 break;
1351 case 0x3d:
1353 sdwCyclesRemaining -= 8;
1354 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1355 cpu.z80F |= (cpu.z80L & Z80_FLAG_CARRY);
1356 cpu.z80L = (cpu.z80L >> 1);
1357 cpu.z80F |= bPostORFlags[cpu.z80L];
1358 break;
1360 case 0x3e:
1362 sdwCyclesRemaining -= 15;
1363 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
1364 while (psMemRead->lowAddr != 0xffffffff)
1366 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1368 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1369 if (psMemRead->memoryCall)
1371 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1373 else
1375 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1377 psMemRead = NULL;
1378 break;
1380 ++psMemRead;
1383 if (psMemRead)
1385 bTemp = cpu.z80Base[cpu.z80HL];
1388 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1389 cpu.z80F |= (bTemp & Z80_FLAG_CARRY);
1390 bTemp = (bTemp >> 1);
1391 cpu.z80F |= bPostORFlags[bTemp];
1392 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
1393 while (psMemWrite->lowAddr != 0xffffffff)
1395 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
1397 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1398 if (psMemWrite->memoryCall)
1400 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
1402 else
1404 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
1406 psMemWrite = NULL;
1407 break;
1409 ++psMemWrite;
1412 if (psMemWrite)
1414 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
1417 break;
1419 case 0x3f:
1421 sdwCyclesRemaining -= 8;
1422 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
1423 cpu.z80F |= (cpu.z80A & Z80_FLAG_CARRY);
1424 cpu.z80A = (cpu.z80A >> 1);
1425 cpu.z80F |= bPostORFlags[cpu.z80A];
1426 break;
1428 case 0x40:
1430 sdwCyclesRemaining -= 8;
1431 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1432 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1433 if (!(cpu.z80B & 0x01))
1435 cpu.z80F |= Z80_FLAG_ZERO;
1437 break;
1439 case 0x41:
1441 sdwCyclesRemaining -= 8;
1442 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1443 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1444 if (!(cpu.z80C & 0x01))
1446 cpu.z80F |= Z80_FLAG_ZERO;
1448 break;
1450 case 0x42:
1452 sdwCyclesRemaining -= 8;
1453 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1454 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1455 if (!(cpu.z80D & 0x01))
1457 cpu.z80F |= Z80_FLAG_ZERO;
1459 break;
1461 case 0x43:
1463 sdwCyclesRemaining -= 8;
1464 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1465 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1466 if (!(cpu.z80E & 0x01))
1468 cpu.z80F |= Z80_FLAG_ZERO;
1470 break;
1472 case 0x44:
1474 sdwCyclesRemaining -= 8;
1475 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1476 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1477 if (!(cpu.z80H & 0x01))
1479 cpu.z80F |= Z80_FLAG_ZERO;
1481 break;
1483 case 0x45:
1485 sdwCyclesRemaining -= 8;
1486 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1487 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1488 if (!(cpu.z80L & 0x01))
1490 cpu.z80F |= Z80_FLAG_ZERO;
1492 break;
1494 case 0x46:
1496 sdwCyclesRemaining -= 12;
1497 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
1498 while (psMemRead->lowAddr != 0xffffffff)
1500 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1502 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1503 if (psMemRead->memoryCall)
1505 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1507 else
1509 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1511 psMemRead = NULL;
1512 break;
1514 ++psMemRead;
1517 if (psMemRead)
1519 bTemp = cpu.z80Base[cpu.z80HL];
1522 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1523 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1524 if (!(bTemp & 0x01))
1526 cpu.z80F |= Z80_FLAG_ZERO;
1528 break;
1530 case 0x47:
1532 sdwCyclesRemaining -= 8;
1533 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1534 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1535 if (!(cpu.z80A & 0x01))
1537 cpu.z80F |= Z80_FLAG_ZERO;
1539 break;
1541 case 0x48:
1543 sdwCyclesRemaining -= 8;
1544 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1545 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1546 if (!(cpu.z80B & 0x02))
1548 cpu.z80F |= Z80_FLAG_ZERO;
1550 break;
1552 case 0x49:
1554 sdwCyclesRemaining -= 8;
1555 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1556 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1557 if (!(cpu.z80C & 0x02))
1559 cpu.z80F |= Z80_FLAG_ZERO;
1561 break;
1563 case 0x4a:
1565 sdwCyclesRemaining -= 8;
1566 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1567 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1568 if (!(cpu.z80D & 0x02))
1570 cpu.z80F |= Z80_FLAG_ZERO;
1572 break;
1574 case 0x4b:
1576 sdwCyclesRemaining -= 8;
1577 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1578 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1579 if (!(cpu.z80E & 0x02))
1581 cpu.z80F |= Z80_FLAG_ZERO;
1583 break;
1585 case 0x4c:
1587 sdwCyclesRemaining -= 8;
1588 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1589 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1590 if (!(cpu.z80H & 0x02))
1592 cpu.z80F |= Z80_FLAG_ZERO;
1594 break;
1596 case 0x4d:
1598 sdwCyclesRemaining -= 8;
1599 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1600 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1601 if (!(cpu.z80L & 0x02))
1603 cpu.z80F |= Z80_FLAG_ZERO;
1605 break;
1607 case 0x4e:
1609 sdwCyclesRemaining -= 12;
1610 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
1611 while (psMemRead->lowAddr != 0xffffffff)
1613 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1615 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1616 if (psMemRead->memoryCall)
1618 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1620 else
1622 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1624 psMemRead = NULL;
1625 break;
1627 ++psMemRead;
1630 if (psMemRead)
1632 bTemp = cpu.z80Base[cpu.z80HL];
1635 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1636 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1637 if (!(bTemp & 0x02))
1639 cpu.z80F |= Z80_FLAG_ZERO;
1641 break;
1643 case 0x4f:
1645 sdwCyclesRemaining -= 8;
1646 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1647 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1648 if (!(cpu.z80A & 0x02))
1650 cpu.z80F |= Z80_FLAG_ZERO;
1652 break;
1654 case 0x50:
1656 sdwCyclesRemaining -= 8;
1657 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1658 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1659 if (!(cpu.z80B & 0x04))
1661 cpu.z80F |= Z80_FLAG_ZERO;
1663 break;
1665 case 0x51:
1667 sdwCyclesRemaining -= 8;
1668 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1669 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1670 if (!(cpu.z80C & 0x04))
1672 cpu.z80F |= Z80_FLAG_ZERO;
1674 break;
1676 case 0x52:
1678 sdwCyclesRemaining -= 8;
1679 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1680 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1681 if (!(cpu.z80D & 0x04))
1683 cpu.z80F |= Z80_FLAG_ZERO;
1685 break;
1687 case 0x53:
1689 sdwCyclesRemaining -= 8;
1690 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1691 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1692 if (!(cpu.z80E & 0x04))
1694 cpu.z80F |= Z80_FLAG_ZERO;
1696 break;
1698 case 0x54:
1700 sdwCyclesRemaining -= 8;
1701 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1702 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1703 if (!(cpu.z80H & 0x04))
1705 cpu.z80F |= Z80_FLAG_ZERO;
1707 break;
1709 case 0x55:
1711 sdwCyclesRemaining -= 8;
1712 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1713 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1714 if (!(cpu.z80L & 0x04))
1716 cpu.z80F |= Z80_FLAG_ZERO;
1718 break;
1720 case 0x56:
1722 sdwCyclesRemaining -= 12;
1723 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
1724 while (psMemRead->lowAddr != 0xffffffff)
1726 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1728 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1729 if (psMemRead->memoryCall)
1731 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1733 else
1735 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1737 psMemRead = NULL;
1738 break;
1740 ++psMemRead;
1743 if (psMemRead)
1745 bTemp = cpu.z80Base[cpu.z80HL];
1748 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1749 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1750 if (!(bTemp & 0x04))
1752 cpu.z80F |= Z80_FLAG_ZERO;
1754 break;
1756 case 0x57:
1758 sdwCyclesRemaining -= 8;
1759 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1760 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1761 if (!(cpu.z80A & 0x04))
1763 cpu.z80F |= Z80_FLAG_ZERO;
1765 break;
1767 case 0x58:
1769 sdwCyclesRemaining -= 8;
1770 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1771 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1772 if (!(cpu.z80B & 0x08))
1774 cpu.z80F |= Z80_FLAG_ZERO;
1776 break;
1778 case 0x59:
1780 sdwCyclesRemaining -= 8;
1781 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1782 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1783 if (!(cpu.z80C & 0x08))
1785 cpu.z80F |= Z80_FLAG_ZERO;
1787 break;
1789 case 0x5a:
1791 sdwCyclesRemaining -= 8;
1792 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1793 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1794 if (!(cpu.z80D & 0x08))
1796 cpu.z80F |= Z80_FLAG_ZERO;
1798 break;
1800 case 0x5b:
1802 sdwCyclesRemaining -= 8;
1803 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1804 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1805 if (!(cpu.z80E & 0x08))
1807 cpu.z80F |= Z80_FLAG_ZERO;
1809 break;
1811 case 0x5c:
1813 sdwCyclesRemaining -= 8;
1814 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1815 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1816 if (!(cpu.z80H & 0x08))
1818 cpu.z80F |= Z80_FLAG_ZERO;
1820 break;
1822 case 0x5d:
1824 sdwCyclesRemaining -= 8;
1825 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1826 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1827 if (!(cpu.z80L & 0x08))
1829 cpu.z80F |= Z80_FLAG_ZERO;
1831 break;
1833 case 0x5e:
1835 sdwCyclesRemaining -= 12;
1836 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
1837 while (psMemRead->lowAddr != 0xffffffff)
1839 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1841 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1842 if (psMemRead->memoryCall)
1844 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1846 else
1848 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1850 psMemRead = NULL;
1851 break;
1853 ++psMemRead;
1856 if (psMemRead)
1858 bTemp = cpu.z80Base[cpu.z80HL];
1861 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1862 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1863 if (!(bTemp & 0x08))
1865 cpu.z80F |= Z80_FLAG_ZERO;
1867 break;
1869 case 0x5f:
1871 sdwCyclesRemaining -= 8;
1872 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1873 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1874 if (!(cpu.z80A & 0x08))
1876 cpu.z80F |= Z80_FLAG_ZERO;
1878 break;
1880 case 0x60:
1882 sdwCyclesRemaining -= 8;
1883 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1884 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1885 if (!(cpu.z80B & 0x10))
1887 cpu.z80F |= Z80_FLAG_ZERO;
1889 break;
1891 case 0x61:
1893 sdwCyclesRemaining -= 8;
1894 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1895 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1896 if (!(cpu.z80C & 0x10))
1898 cpu.z80F |= Z80_FLAG_ZERO;
1900 break;
1902 case 0x62:
1904 sdwCyclesRemaining -= 8;
1905 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1906 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1907 if (!(cpu.z80D & 0x10))
1909 cpu.z80F |= Z80_FLAG_ZERO;
1911 break;
1913 case 0x63:
1915 sdwCyclesRemaining -= 8;
1916 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1917 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1918 if (!(cpu.z80E & 0x10))
1920 cpu.z80F |= Z80_FLAG_ZERO;
1922 break;
1924 case 0x64:
1926 sdwCyclesRemaining -= 8;
1927 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1928 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1929 if (!(cpu.z80H & 0x10))
1931 cpu.z80F |= Z80_FLAG_ZERO;
1933 break;
1935 case 0x65:
1937 sdwCyclesRemaining -= 8;
1938 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1939 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1940 if (!(cpu.z80L & 0x10))
1942 cpu.z80F |= Z80_FLAG_ZERO;
1944 break;
1946 case 0x66:
1948 sdwCyclesRemaining -= 12;
1949 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
1950 while (psMemRead->lowAddr != 0xffffffff)
1952 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
1954 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
1955 if (psMemRead->memoryCall)
1957 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
1959 else
1961 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
1963 psMemRead = NULL;
1964 break;
1966 ++psMemRead;
1969 if (psMemRead)
1971 bTemp = cpu.z80Base[cpu.z80HL];
1974 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1975 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1976 if (!(bTemp & 0x10))
1978 cpu.z80F |= Z80_FLAG_ZERO;
1980 break;
1982 case 0x67:
1984 sdwCyclesRemaining -= 8;
1985 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1986 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1987 if (!(cpu.z80A & 0x10))
1989 cpu.z80F |= Z80_FLAG_ZERO;
1991 break;
1993 case 0x68:
1995 sdwCyclesRemaining -= 8;
1996 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
1997 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
1998 if (!(cpu.z80B & 0x20))
2000 cpu.z80F |= Z80_FLAG_ZERO;
2002 break;
2004 case 0x69:
2006 sdwCyclesRemaining -= 8;
2007 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2008 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2009 if (!(cpu.z80C & 0x20))
2011 cpu.z80F |= Z80_FLAG_ZERO;
2013 break;
2015 case 0x6a:
2017 sdwCyclesRemaining -= 8;
2018 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2019 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2020 if (!(cpu.z80D & 0x20))
2022 cpu.z80F |= Z80_FLAG_ZERO;
2024 break;
2026 case 0x6b:
2028 sdwCyclesRemaining -= 8;
2029 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2030 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2031 if (!(cpu.z80E & 0x20))
2033 cpu.z80F |= Z80_FLAG_ZERO;
2035 break;
2037 case 0x6c:
2039 sdwCyclesRemaining -= 8;
2040 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2041 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2042 if (!(cpu.z80H & 0x20))
2044 cpu.z80F |= Z80_FLAG_ZERO;
2046 break;
2048 case 0x6d:
2050 sdwCyclesRemaining -= 8;
2051 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2052 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2053 if (!(cpu.z80L & 0x20))
2055 cpu.z80F |= Z80_FLAG_ZERO;
2057 break;
2059 case 0x6e:
2061 sdwCyclesRemaining -= 12;
2062 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2063 while (psMemRead->lowAddr != 0xffffffff)
2065 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2067 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2068 if (psMemRead->memoryCall)
2070 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2072 else
2074 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2076 psMemRead = NULL;
2077 break;
2079 ++psMemRead;
2082 if (psMemRead)
2084 bTemp = cpu.z80Base[cpu.z80HL];
2087 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2088 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2089 if (!(bTemp & 0x20))
2091 cpu.z80F |= Z80_FLAG_ZERO;
2093 break;
2095 case 0x6f:
2097 sdwCyclesRemaining -= 8;
2098 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2099 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2100 if (!(cpu.z80A & 0x20))
2102 cpu.z80F |= Z80_FLAG_ZERO;
2104 break;
2106 case 0x70:
2108 sdwCyclesRemaining -= 8;
2109 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2110 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2111 if (!(cpu.z80B & 0x40))
2113 cpu.z80F |= Z80_FLAG_ZERO;
2115 break;
2117 case 0x71:
2119 sdwCyclesRemaining -= 8;
2120 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2121 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2122 if (!(cpu.z80C & 0x40))
2124 cpu.z80F |= Z80_FLAG_ZERO;
2126 break;
2128 case 0x72:
2130 sdwCyclesRemaining -= 8;
2131 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2132 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2133 if (!(cpu.z80D & 0x40))
2135 cpu.z80F |= Z80_FLAG_ZERO;
2137 break;
2139 case 0x73:
2141 sdwCyclesRemaining -= 8;
2142 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2143 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2144 if (!(cpu.z80E & 0x40))
2146 cpu.z80F |= Z80_FLAG_ZERO;
2148 break;
2150 case 0x74:
2152 sdwCyclesRemaining -= 8;
2153 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2154 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2155 if (!(cpu.z80H & 0x40))
2157 cpu.z80F |= Z80_FLAG_ZERO;
2159 break;
2161 case 0x75:
2163 sdwCyclesRemaining -= 8;
2164 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2165 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2166 if (!(cpu.z80L & 0x40))
2168 cpu.z80F |= Z80_FLAG_ZERO;
2170 break;
2172 case 0x76:
2174 sdwCyclesRemaining -= 12;
2175 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2176 while (psMemRead->lowAddr != 0xffffffff)
2178 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2180 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2181 if (psMemRead->memoryCall)
2183 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2185 else
2187 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2189 psMemRead = NULL;
2190 break;
2192 ++psMemRead;
2195 if (psMemRead)
2197 bTemp = cpu.z80Base[cpu.z80HL];
2200 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2201 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2202 if (!(bTemp & 0x40))
2204 cpu.z80F |= Z80_FLAG_ZERO;
2206 break;
2208 case 0x77:
2210 sdwCyclesRemaining -= 8;
2211 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2212 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2213 if (!(cpu.z80A & 0x40))
2215 cpu.z80F |= Z80_FLAG_ZERO;
2217 break;
2219 case 0x78:
2221 sdwCyclesRemaining -= 8;
2222 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2223 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2224 if (!(cpu.z80B & 0x80))
2226 cpu.z80F |= Z80_FLAG_ZERO;
2228 break;
2230 case 0x79:
2232 sdwCyclesRemaining -= 8;
2233 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2234 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2235 if (!(cpu.z80C & 0x80))
2237 cpu.z80F |= Z80_FLAG_ZERO;
2239 break;
2241 case 0x7a:
2243 sdwCyclesRemaining -= 8;
2244 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2245 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2246 if (!(cpu.z80D & 0x80))
2248 cpu.z80F |= Z80_FLAG_ZERO;
2250 break;
2252 case 0x7b:
2254 sdwCyclesRemaining -= 8;
2255 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2256 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2257 if (!(cpu.z80E & 0x80))
2259 cpu.z80F |= Z80_FLAG_ZERO;
2261 break;
2263 case 0x7c:
2265 sdwCyclesRemaining -= 8;
2266 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2267 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2268 if (!(cpu.z80H & 0x80))
2270 cpu.z80F |= Z80_FLAG_ZERO;
2272 break;
2274 case 0x7d:
2276 sdwCyclesRemaining -= 8;
2277 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2278 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2279 if (!(cpu.z80L & 0x80))
2281 cpu.z80F |= Z80_FLAG_ZERO;
2283 break;
2285 case 0x7e:
2287 sdwCyclesRemaining -= 12;
2288 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2289 while (psMemRead->lowAddr != 0xffffffff)
2291 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2293 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2294 if (psMemRead->memoryCall)
2296 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2298 else
2300 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2302 psMemRead = NULL;
2303 break;
2305 ++psMemRead;
2308 if (psMemRead)
2310 bTemp = cpu.z80Base[cpu.z80HL];
2313 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2314 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2315 if (!(bTemp & 0x80))
2317 cpu.z80F |= Z80_FLAG_ZERO;
2319 break;
2321 case 0x7f:
2323 sdwCyclesRemaining -= 8;
2324 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);
2325 cpu.z80F |= (Z80_FLAG_HALF_CARRY);
2326 if (!(cpu.z80A & 0x80))
2328 cpu.z80F |= Z80_FLAG_ZERO;
2330 break;
2332 case 0x80:
2334 sdwCyclesRemaining -= 8;
2335 cpu.z80B &= 0xfe;
2336 break;
2338 case 0x81:
2340 sdwCyclesRemaining -= 8;
2341 cpu.z80C &= 0xfe;
2342 break;
2344 case 0x82:
2346 sdwCyclesRemaining -= 8;
2347 cpu.z80D &= 0xfe;
2348 break;
2350 case 0x83:
2352 sdwCyclesRemaining -= 8;
2353 cpu.z80E &= 0xfe;
2354 break;
2356 case 0x84:
2358 sdwCyclesRemaining -= 8;
2359 cpu.z80H &= 0xfe;
2360 break;
2362 case 0x85:
2364 sdwCyclesRemaining -= 8;
2365 cpu.z80L &= 0xfe;
2366 break;
2368 case 0x86:
2370 sdwCyclesRemaining -= 15;
2371 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2372 while (psMemRead->lowAddr != 0xffffffff)
2374 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2376 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2377 if (psMemRead->memoryCall)
2379 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2381 else
2383 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2385 psMemRead = NULL;
2386 break;
2388 ++psMemRead;
2391 if (psMemRead)
2393 bTemp = cpu.z80Base[cpu.z80HL];
2396 bTemp &= 0xfe;
2397 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
2398 while (psMemWrite->lowAddr != 0xffffffff)
2400 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
2402 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2403 if (psMemWrite->memoryCall)
2405 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
2407 else
2409 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
2411 psMemWrite = NULL;
2412 break;
2414 ++psMemWrite;
2417 if (psMemWrite)
2419 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
2422 break;
2424 case 0x87:
2426 sdwCyclesRemaining -= 8;
2427 cpu.z80A &= 0xfe;
2428 break;
2430 case 0x88:
2432 sdwCyclesRemaining -= 8;
2433 cpu.z80B &= 0xfd;
2434 break;
2436 case 0x89:
2438 sdwCyclesRemaining -= 8;
2439 cpu.z80C &= 0xfd;
2440 break;
2442 case 0x8a:
2444 sdwCyclesRemaining -= 8;
2445 cpu.z80D &= 0xfd;
2446 break;
2448 case 0x8b:
2450 sdwCyclesRemaining -= 8;
2451 cpu.z80E &= 0xfd;
2452 break;
2454 case 0x8c:
2456 sdwCyclesRemaining -= 8;
2457 cpu.z80H &= 0xfd;
2458 break;
2460 case 0x8d:
2462 sdwCyclesRemaining -= 8;
2463 cpu.z80L &= 0xfd;
2464 break;
2466 case 0x8e:
2468 sdwCyclesRemaining -= 15;
2469 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2470 while (psMemRead->lowAddr != 0xffffffff)
2472 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2474 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2475 if (psMemRead->memoryCall)
2477 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2479 else
2481 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2483 psMemRead = NULL;
2484 break;
2486 ++psMemRead;
2489 if (psMemRead)
2491 bTemp = cpu.z80Base[cpu.z80HL];
2494 bTemp &= 0xfd;
2495 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
2496 while (psMemWrite->lowAddr != 0xffffffff)
2498 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
2500 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2501 if (psMemWrite->memoryCall)
2503 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
2505 else
2507 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
2509 psMemWrite = NULL;
2510 break;
2512 ++psMemWrite;
2515 if (psMemWrite)
2517 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
2520 break;
2522 case 0x8f:
2524 sdwCyclesRemaining -= 8;
2525 cpu.z80A &= 0xfd;
2526 break;
2528 case 0x90:
2530 sdwCyclesRemaining -= 8;
2531 cpu.z80B &= 0xfb;
2532 break;
2534 case 0x91:
2536 sdwCyclesRemaining -= 8;
2537 cpu.z80C &= 0xfb;
2538 break;
2540 case 0x92:
2542 sdwCyclesRemaining -= 8;
2543 cpu.z80D &= 0xfb;
2544 break;
2546 case 0x93:
2548 sdwCyclesRemaining -= 8;
2549 cpu.z80E &= 0xfb;
2550 break;
2552 case 0x94:
2554 sdwCyclesRemaining -= 8;
2555 cpu.z80H &= 0xfb;
2556 break;
2558 case 0x95:
2560 sdwCyclesRemaining -= 8;
2561 cpu.z80L &= 0xfb;
2562 break;
2564 case 0x96:
2566 sdwCyclesRemaining -= 15;
2567 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2568 while (psMemRead->lowAddr != 0xffffffff)
2570 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2572 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2573 if (psMemRead->memoryCall)
2575 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2577 else
2579 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2581 psMemRead = NULL;
2582 break;
2584 ++psMemRead;
2587 if (psMemRead)
2589 bTemp = cpu.z80Base[cpu.z80HL];
2592 bTemp &= 0xfb;
2593 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
2594 while (psMemWrite->lowAddr != 0xffffffff)
2596 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
2598 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2599 if (psMemWrite->memoryCall)
2601 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
2603 else
2605 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
2607 psMemWrite = NULL;
2608 break;
2610 ++psMemWrite;
2613 if (psMemWrite)
2615 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
2618 break;
2620 case 0x97:
2622 sdwCyclesRemaining -= 8;
2623 cpu.z80A &= 0xfb;
2624 break;
2626 case 0x98:
2628 sdwCyclesRemaining -= 8;
2629 cpu.z80B &= 0xf7;
2630 break;
2632 case 0x99:
2634 sdwCyclesRemaining -= 8;
2635 cpu.z80C &= 0xf7;
2636 break;
2638 case 0x9a:
2640 sdwCyclesRemaining -= 8;
2641 cpu.z80D &= 0xf7;
2642 break;
2644 case 0x9b:
2646 sdwCyclesRemaining -= 8;
2647 cpu.z80E &= 0xf7;
2648 break;
2650 case 0x9c:
2652 sdwCyclesRemaining -= 8;
2653 cpu.z80H &= 0xf7;
2654 break;
2656 case 0x9d:
2658 sdwCyclesRemaining -= 8;
2659 cpu.z80L &= 0xf7;
2660 break;
2662 case 0x9e:
2664 sdwCyclesRemaining -= 15;
2665 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2666 while (psMemRead->lowAddr != 0xffffffff)
2668 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2670 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2671 if (psMemRead->memoryCall)
2673 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2675 else
2677 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2679 psMemRead = NULL;
2680 break;
2682 ++psMemRead;
2685 if (psMemRead)
2687 bTemp = cpu.z80Base[cpu.z80HL];
2690 bTemp &= 0xf7;
2691 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
2692 while (psMemWrite->lowAddr != 0xffffffff)
2694 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
2696 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2697 if (psMemWrite->memoryCall)
2699 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
2701 else
2703 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
2705 psMemWrite = NULL;
2706 break;
2708 ++psMemWrite;
2711 if (psMemWrite)
2713 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
2716 break;
2718 case 0x9f:
2720 sdwCyclesRemaining -= 8;
2721 cpu.z80A &= 0xf7;
2722 break;
2724 case 0xa0:
2726 sdwCyclesRemaining -= 8;
2727 cpu.z80B &= 0xef;
2728 break;
2730 case 0xa1:
2732 sdwCyclesRemaining -= 8;
2733 cpu.z80C &= 0xef;
2734 break;
2736 case 0xa2:
2738 sdwCyclesRemaining -= 8;
2739 cpu.z80D &= 0xef;
2740 break;
2742 case 0xa3:
2744 sdwCyclesRemaining -= 8;
2745 cpu.z80E &= 0xef;
2746 break;
2748 case 0xa4:
2750 sdwCyclesRemaining -= 8;
2751 cpu.z80H &= 0xef;
2752 break;
2754 case 0xa5:
2756 sdwCyclesRemaining -= 8;
2757 cpu.z80L &= 0xef;
2758 break;
2760 case 0xa6:
2762 sdwCyclesRemaining -= 15;
2763 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2764 while (psMemRead->lowAddr != 0xffffffff)
2766 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2768 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2769 if (psMemRead->memoryCall)
2771 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2773 else
2775 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2777 psMemRead = NULL;
2778 break;
2780 ++psMemRead;
2783 if (psMemRead)
2785 bTemp = cpu.z80Base[cpu.z80HL];
2788 bTemp &= 0xef;
2789 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
2790 while (psMemWrite->lowAddr != 0xffffffff)
2792 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
2794 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2795 if (psMemWrite->memoryCall)
2797 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
2799 else
2801 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
2803 psMemWrite = NULL;
2804 break;
2806 ++psMemWrite;
2809 if (psMemWrite)
2811 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
2814 break;
2816 case 0xa7:
2818 sdwCyclesRemaining -= 8;
2819 cpu.z80A &= 0xef;
2820 break;
2822 case 0xa8:
2824 sdwCyclesRemaining -= 8;
2825 cpu.z80B &= 0xdf;
2826 break;
2828 case 0xa9:
2830 sdwCyclesRemaining -= 8;
2831 cpu.z80C &= 0xdf;
2832 break;
2834 case 0xaa:
2836 sdwCyclesRemaining -= 8;
2837 cpu.z80D &= 0xdf;
2838 break;
2840 case 0xab:
2842 sdwCyclesRemaining -= 8;
2843 cpu.z80E &= 0xdf;
2844 break;
2846 case 0xac:
2848 sdwCyclesRemaining -= 8;
2849 cpu.z80H &= 0xdf;
2850 break;
2852 case 0xad:
2854 sdwCyclesRemaining -= 8;
2855 cpu.z80L &= 0xdf;
2856 break;
2858 case 0xae:
2860 sdwCyclesRemaining -= 15;
2861 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2862 while (psMemRead->lowAddr != 0xffffffff)
2864 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2866 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2867 if (psMemRead->memoryCall)
2869 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2871 else
2873 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2875 psMemRead = NULL;
2876 break;
2878 ++psMemRead;
2881 if (psMemRead)
2883 bTemp = cpu.z80Base[cpu.z80HL];
2886 bTemp &= 0xdf;
2887 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
2888 while (psMemWrite->lowAddr != 0xffffffff)
2890 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
2892 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2893 if (psMemWrite->memoryCall)
2895 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
2897 else
2899 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
2901 psMemWrite = NULL;
2902 break;
2904 ++psMemWrite;
2907 if (psMemWrite)
2909 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
2912 break;
2914 case 0xaf:
2916 sdwCyclesRemaining -= 8;
2917 cpu.z80A &= 0xdf;
2918 break;
2920 case 0xb0:
2922 sdwCyclesRemaining -= 8;
2923 cpu.z80B &= 0xbf;
2924 break;
2926 case 0xb1:
2928 sdwCyclesRemaining -= 8;
2929 cpu.z80C &= 0xbf;
2930 break;
2932 case 0xb2:
2934 sdwCyclesRemaining -= 8;
2935 cpu.z80D &= 0xbf;
2936 break;
2938 case 0xb3:
2940 sdwCyclesRemaining -= 8;
2941 cpu.z80E &= 0xbf;
2942 break;
2944 case 0xb4:
2946 sdwCyclesRemaining -= 8;
2947 cpu.z80H &= 0xbf;
2948 break;
2950 case 0xb5:
2952 sdwCyclesRemaining -= 8;
2953 cpu.z80L &= 0xbf;
2954 break;
2956 case 0xb6:
2958 sdwCyclesRemaining -= 15;
2959 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
2960 while (psMemRead->lowAddr != 0xffffffff)
2962 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
2964 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2965 if (psMemRead->memoryCall)
2967 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
2969 else
2971 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
2973 psMemRead = NULL;
2974 break;
2976 ++psMemRead;
2979 if (psMemRead)
2981 bTemp = cpu.z80Base[cpu.z80HL];
2984 bTemp &= 0xbf;
2985 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
2986 while (psMemWrite->lowAddr != 0xffffffff)
2988 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
2990 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
2991 if (psMemWrite->memoryCall)
2993 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
2995 else
2997 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
2999 psMemWrite = NULL;
3000 break;
3002 ++psMemWrite;
3005 if (psMemWrite)
3007 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3010 break;
3012 case 0xb7:
3014 sdwCyclesRemaining -= 8;
3015 cpu.z80A &= 0xbf;
3016 break;
3018 case 0xb8:
3020 sdwCyclesRemaining -= 8;
3021 cpu.z80B &= 0x7f;
3022 break;
3024 case 0xb9:
3026 sdwCyclesRemaining -= 8;
3027 cpu.z80C &= 0x7f;
3028 break;
3030 case 0xba:
3032 sdwCyclesRemaining -= 8;
3033 cpu.z80D &= 0x7f;
3034 break;
3036 case 0xbb:
3038 sdwCyclesRemaining -= 8;
3039 cpu.z80E &= 0x7f;
3040 break;
3042 case 0xbc:
3044 sdwCyclesRemaining -= 8;
3045 cpu.z80H &= 0x7f;
3046 break;
3048 case 0xbd:
3050 sdwCyclesRemaining -= 8;
3051 cpu.z80L &= 0x7f;
3052 break;
3054 case 0xbe:
3056 sdwCyclesRemaining -= 15;
3057 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3058 while (psMemRead->lowAddr != 0xffffffff)
3060 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3062 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3063 if (psMemRead->memoryCall)
3065 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3067 else
3069 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3071 psMemRead = NULL;
3072 break;
3074 ++psMemRead;
3077 if (psMemRead)
3079 bTemp = cpu.z80Base[cpu.z80HL];
3082 bTemp &= 0x7f;
3083 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3084 while (psMemWrite->lowAddr != 0xffffffff)
3086 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3088 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3089 if (psMemWrite->memoryCall)
3091 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3093 else
3095 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3097 psMemWrite = NULL;
3098 break;
3100 ++psMemWrite;
3103 if (psMemWrite)
3105 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3108 break;
3110 case 0xbf:
3112 sdwCyclesRemaining -= 8;
3113 cpu.z80A &= 0x7f;
3114 break;
3116 case 0xc0:
3118 sdwCyclesRemaining -= 8;
3119 cpu.z80B |= 0x01;
3120 break;
3122 case 0xc1:
3124 sdwCyclesRemaining -= 8;
3125 cpu.z80C |= 0x01;
3126 break;
3128 case 0xc2:
3130 sdwCyclesRemaining -= 8;
3131 cpu.z80D |= 0x01;
3132 break;
3134 case 0xc3:
3136 sdwCyclesRemaining -= 8;
3137 cpu.z80E |= 0x01;
3138 break;
3140 case 0xc4:
3142 sdwCyclesRemaining -= 8;
3143 cpu.z80H |= 0x01;
3144 break;
3146 case 0xc5:
3148 sdwCyclesRemaining -= 8;
3149 cpu.z80L |= 0x01;
3150 break;
3152 case 0xc6:
3154 sdwCyclesRemaining -= 15;
3155 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3156 while (psMemRead->lowAddr != 0xffffffff)
3158 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3160 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3161 if (psMemRead->memoryCall)
3163 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3165 else
3167 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3169 psMemRead = NULL;
3170 break;
3172 ++psMemRead;
3175 if (psMemRead)
3177 bTemp = cpu.z80Base[cpu.z80HL];
3180 bTemp |= 0x01;
3181 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3182 while (psMemWrite->lowAddr != 0xffffffff)
3184 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3186 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3187 if (psMemWrite->memoryCall)
3189 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3191 else
3193 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3195 psMemWrite = NULL;
3196 break;
3198 ++psMemWrite;
3201 if (psMemWrite)
3203 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3206 break;
3208 case 0xc7:
3210 sdwCyclesRemaining -= 8;
3211 cpu.z80A |= 0x01;
3212 break;
3214 case 0xc8:
3216 sdwCyclesRemaining -= 8;
3217 cpu.z80B |= 0x02;
3218 break;
3220 case 0xc9:
3222 sdwCyclesRemaining -= 8;
3223 cpu.z80C |= 0x02;
3224 break;
3226 case 0xca:
3228 sdwCyclesRemaining -= 8;
3229 cpu.z80D |= 0x02;
3230 break;
3232 case 0xcb:
3234 sdwCyclesRemaining -= 8;
3235 cpu.z80E |= 0x02;
3236 break;
3238 case 0xcc:
3240 sdwCyclesRemaining -= 8;
3241 cpu.z80H |= 0x02;
3242 break;
3244 case 0xcd:
3246 sdwCyclesRemaining -= 8;
3247 cpu.z80L |= 0x02;
3248 break;
3250 case 0xce:
3252 sdwCyclesRemaining -= 15;
3253 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3254 while (psMemRead->lowAddr != 0xffffffff)
3256 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3258 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3259 if (psMemRead->memoryCall)
3261 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3263 else
3265 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3267 psMemRead = NULL;
3268 break;
3270 ++psMemRead;
3273 if (psMemRead)
3275 bTemp = cpu.z80Base[cpu.z80HL];
3278 bTemp |= 0x02;
3279 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3280 while (psMemWrite->lowAddr != 0xffffffff)
3282 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3284 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3285 if (psMemWrite->memoryCall)
3287 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3289 else
3291 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3293 psMemWrite = NULL;
3294 break;
3296 ++psMemWrite;
3299 if (psMemWrite)
3301 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3304 break;
3306 case 0xcf:
3308 sdwCyclesRemaining -= 8;
3309 cpu.z80A |= 0x02;
3310 break;
3312 case 0xd0:
3314 sdwCyclesRemaining -= 8;
3315 cpu.z80B |= 0x04;
3316 break;
3318 case 0xd1:
3320 sdwCyclesRemaining -= 8;
3321 cpu.z80C |= 0x04;
3322 break;
3324 case 0xd2:
3326 sdwCyclesRemaining -= 8;
3327 cpu.z80D |= 0x04;
3328 break;
3330 case 0xd3:
3332 sdwCyclesRemaining -= 8;
3333 cpu.z80E |= 0x04;
3334 break;
3336 case 0xd4:
3338 sdwCyclesRemaining -= 8;
3339 cpu.z80H |= 0x04;
3340 break;
3342 case 0xd5:
3344 sdwCyclesRemaining -= 8;
3345 cpu.z80L |= 0x04;
3346 break;
3348 case 0xd6:
3350 sdwCyclesRemaining -= 15;
3351 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3352 while (psMemRead->lowAddr != 0xffffffff)
3354 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3356 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3357 if (psMemRead->memoryCall)
3359 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3361 else
3363 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3365 psMemRead = NULL;
3366 break;
3368 ++psMemRead;
3371 if (psMemRead)
3373 bTemp = cpu.z80Base[cpu.z80HL];
3376 bTemp |= 0x04;
3377 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3378 while (psMemWrite->lowAddr != 0xffffffff)
3380 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3382 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3383 if (psMemWrite->memoryCall)
3385 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3387 else
3389 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3391 psMemWrite = NULL;
3392 break;
3394 ++psMemWrite;
3397 if (psMemWrite)
3399 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3402 break;
3404 case 0xd7:
3406 sdwCyclesRemaining -= 8;
3407 cpu.z80A |= 0x04;
3408 break;
3410 case 0xd8:
3412 sdwCyclesRemaining -= 8;
3413 cpu.z80B |= 0x08;
3414 break;
3416 case 0xd9:
3418 sdwCyclesRemaining -= 8;
3419 cpu.z80C |= 0x08;
3420 break;
3422 case 0xda:
3424 sdwCyclesRemaining -= 8;
3425 cpu.z80D |= 0x08;
3426 break;
3428 case 0xdb:
3430 sdwCyclesRemaining -= 8;
3431 cpu.z80E |= 0x08;
3432 break;
3434 case 0xdc:
3436 sdwCyclesRemaining -= 8;
3437 cpu.z80H |= 0x08;
3438 break;
3440 case 0xdd:
3442 sdwCyclesRemaining -= 8;
3443 cpu.z80L |= 0x08;
3444 break;
3446 case 0xde:
3448 sdwCyclesRemaining -= 15;
3449 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3450 while (psMemRead->lowAddr != 0xffffffff)
3452 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3454 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3455 if (psMemRead->memoryCall)
3457 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3459 else
3461 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3463 psMemRead = NULL;
3464 break;
3466 ++psMemRead;
3469 if (psMemRead)
3471 bTemp = cpu.z80Base[cpu.z80HL];
3474 bTemp |= 0x08;
3475 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3476 while (psMemWrite->lowAddr != 0xffffffff)
3478 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3480 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3481 if (psMemWrite->memoryCall)
3483 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3485 else
3487 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3489 psMemWrite = NULL;
3490 break;
3492 ++psMemWrite;
3495 if (psMemWrite)
3497 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3500 break;
3502 case 0xdf:
3504 sdwCyclesRemaining -= 8;
3505 cpu.z80A |= 0x08;
3506 break;
3508 case 0xe0:
3510 sdwCyclesRemaining -= 8;
3511 cpu.z80B |= 0x10;
3512 break;
3514 case 0xe1:
3516 sdwCyclesRemaining -= 8;
3517 cpu.z80C |= 0x10;
3518 break;
3520 case 0xe2:
3522 sdwCyclesRemaining -= 8;
3523 cpu.z80D |= 0x10;
3524 break;
3526 case 0xe3:
3528 sdwCyclesRemaining -= 8;
3529 cpu.z80E |= 0x10;
3530 break;
3532 case 0xe4:
3534 sdwCyclesRemaining -= 8;
3535 cpu.z80H |= 0x10;
3536 break;
3538 case 0xe5:
3540 sdwCyclesRemaining -= 8;
3541 cpu.z80L |= 0x10;
3542 break;
3544 case 0xe6:
3546 sdwCyclesRemaining -= 15;
3547 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3548 while (psMemRead->lowAddr != 0xffffffff)
3550 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3552 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3553 if (psMemRead->memoryCall)
3555 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3557 else
3559 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3561 psMemRead = NULL;
3562 break;
3564 ++psMemRead;
3567 if (psMemRead)
3569 bTemp = cpu.z80Base[cpu.z80HL];
3572 bTemp |= 0x10;
3573 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3574 while (psMemWrite->lowAddr != 0xffffffff)
3576 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3578 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3579 if (psMemWrite->memoryCall)
3581 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3583 else
3585 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3587 psMemWrite = NULL;
3588 break;
3590 ++psMemWrite;
3593 if (psMemWrite)
3595 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3598 break;
3600 case 0xe7:
3602 sdwCyclesRemaining -= 8;
3603 cpu.z80A |= 0x10;
3604 break;
3606 case 0xe8:
3608 sdwCyclesRemaining -= 8;
3609 cpu.z80B |= 0x20;
3610 break;
3612 case 0xe9:
3614 sdwCyclesRemaining -= 8;
3615 cpu.z80C |= 0x20;
3616 break;
3618 case 0xea:
3620 sdwCyclesRemaining -= 8;
3621 cpu.z80D |= 0x20;
3622 break;
3624 case 0xeb:
3626 sdwCyclesRemaining -= 8;
3627 cpu.z80E |= 0x20;
3628 break;
3630 case 0xec:
3632 sdwCyclesRemaining -= 8;
3633 cpu.z80H |= 0x20;
3634 break;
3636 case 0xed:
3638 sdwCyclesRemaining -= 8;
3639 cpu.z80L |= 0x20;
3640 break;
3642 case 0xee:
3644 sdwCyclesRemaining -= 15;
3645 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3646 while (psMemRead->lowAddr != 0xffffffff)
3648 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3650 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3651 if (psMemRead->memoryCall)
3653 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3655 else
3657 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3659 psMemRead = NULL;
3660 break;
3662 ++psMemRead;
3665 if (psMemRead)
3667 bTemp = cpu.z80Base[cpu.z80HL];
3670 bTemp |= 0x20;
3671 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3672 while (psMemWrite->lowAddr != 0xffffffff)
3674 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3676 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3677 if (psMemWrite->memoryCall)
3679 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3681 else
3683 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3685 psMemWrite = NULL;
3686 break;
3688 ++psMemWrite;
3691 if (psMemWrite)
3693 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3696 break;
3698 case 0xef:
3700 sdwCyclesRemaining -= 8;
3701 cpu.z80A |= 0x20;
3702 break;
3704 case 0xf0:
3706 sdwCyclesRemaining -= 8;
3707 cpu.z80B |= 0x40;
3708 break;
3710 case 0xf1:
3712 sdwCyclesRemaining -= 8;
3713 cpu.z80C |= 0x40;
3714 break;
3716 case 0xf2:
3718 sdwCyclesRemaining -= 8;
3719 cpu.z80D |= 0x40;
3720 break;
3722 case 0xf3:
3724 sdwCyclesRemaining -= 8;
3725 cpu.z80E |= 0x40;
3726 break;
3728 case 0xf4:
3730 sdwCyclesRemaining -= 8;
3731 cpu.z80H |= 0x40;
3732 break;
3734 case 0xf5:
3736 sdwCyclesRemaining -= 8;
3737 cpu.z80L |= 0x40;
3738 break;
3740 case 0xf6:
3742 sdwCyclesRemaining -= 15;
3743 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3744 while (psMemRead->lowAddr != 0xffffffff)
3746 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3748 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3749 if (psMemRead->memoryCall)
3751 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3753 else
3755 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3757 psMemRead = NULL;
3758 break;
3760 ++psMemRead;
3763 if (psMemRead)
3765 bTemp = cpu.z80Base[cpu.z80HL];
3768 bTemp |= 0x40;
3769 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3770 while (psMemWrite->lowAddr != 0xffffffff)
3772 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3774 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3775 if (psMemWrite->memoryCall)
3777 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3779 else
3781 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3783 psMemWrite = NULL;
3784 break;
3786 ++psMemWrite;
3789 if (psMemWrite)
3791 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3794 break;
3796 case 0xf7:
3798 sdwCyclesRemaining -= 8;
3799 cpu.z80A |= 0x40;
3800 break;
3802 case 0xf8:
3804 sdwCyclesRemaining -= 8;
3805 cpu.z80B |= 0x80;
3806 break;
3808 case 0xf9:
3810 sdwCyclesRemaining -= 8;
3811 cpu.z80C |= 0x80;
3812 break;
3814 case 0xfa:
3816 sdwCyclesRemaining -= 8;
3817 cpu.z80D |= 0x80;
3818 break;
3820 case 0xfb:
3822 sdwCyclesRemaining -= 8;
3823 cpu.z80E |= 0x80;
3824 break;
3826 case 0xfc:
3828 sdwCyclesRemaining -= 8;
3829 cpu.z80H |= 0x80;
3830 break;
3832 case 0xfd:
3834 sdwCyclesRemaining -= 8;
3835 cpu.z80L |= 0x80;
3836 break;
3838 case 0xfe:
3840 sdwCyclesRemaining -= 15;
3841 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
3842 while (psMemRead->lowAddr != 0xffffffff)
3844 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
3846 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3847 if (psMemRead->memoryCall)
3849 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
3851 else
3853 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
3855 psMemRead = NULL;
3856 break;
3858 ++psMemRead;
3861 if (psMemRead)
3863 bTemp = cpu.z80Base[cpu.z80HL];
3866 bTemp |= 0x80;
3867 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
3868 while (psMemWrite->lowAddr != 0xffffffff)
3870 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
3872 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
3873 if (psMemWrite->memoryCall)
3875 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
3877 else
3879 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
3881 psMemWrite = NULL;
3882 break;
3884 ++psMemWrite;
3887 if (psMemWrite)
3889 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
3892 break;
3894 case 0xff:
3896 sdwCyclesRemaining -= 8;
3897 cpu.z80A |= 0x80;
3898 break;
3902 void EDHandler(void)
3904 switch (*pbPC++)
3906 case 0x00:
3908 InvalidInstruction(2);
3909 break;
3911 case 0x01:
3913 InvalidInstruction(2);
3914 break;
3916 case 0x02:
3918 InvalidInstruction(2);
3919 break;
3921 case 0x03:
3923 InvalidInstruction(2);
3924 break;
3926 case 0x04:
3928 InvalidInstruction(2);
3929 break;
3931 case 0x05:
3933 InvalidInstruction(2);
3934 break;
3936 case 0x06:
3938 InvalidInstruction(2);
3939 break;
3941 case 0x07:
3943 InvalidInstruction(2);
3944 break;
3946 case 0x08:
3948 InvalidInstruction(2);
3949 break;
3951 case 0x09:
3953 InvalidInstruction(2);
3954 break;
3956 case 0x0a:
3958 InvalidInstruction(2);
3959 break;
3961 case 0x0b:
3963 InvalidInstruction(2);
3964 break;
3966 case 0x0c:
3968 InvalidInstruction(2);
3969 break;
3971 case 0x0d:
3973 InvalidInstruction(2);
3974 break;
3976 case 0x0e:
3978 InvalidInstruction(2);
3979 break;
3981 case 0x0f:
3983 InvalidInstruction(2);
3984 break;
3986 case 0x10:
3988 InvalidInstruction(2);
3989 break;
3991 case 0x11:
3993 InvalidInstruction(2);
3994 break;
3996 case 0x12:
3998 InvalidInstruction(2);
3999 break;
4001 case 0x13:
4003 InvalidInstruction(2);
4004 break;
4006 case 0x14:
4008 InvalidInstruction(2);
4009 break;
4011 case 0x15:
4013 InvalidInstruction(2);
4014 break;
4016 case 0x16:
4018 InvalidInstruction(2);
4019 break;
4021 case 0x17:
4023 InvalidInstruction(2);
4024 break;
4026 case 0x18:
4028 InvalidInstruction(2);
4029 break;
4031 case 0x19:
4033 InvalidInstruction(2);
4034 break;
4036 case 0x1a:
4038 InvalidInstruction(2);
4039 break;
4041 case 0x1b:
4043 InvalidInstruction(2);
4044 break;
4046 case 0x1c:
4048 InvalidInstruction(2);
4049 break;
4051 case 0x1d:
4053 InvalidInstruction(2);
4054 break;
4056 case 0x1e:
4058 InvalidInstruction(2);
4059 break;
4061 case 0x1f:
4063 InvalidInstruction(2);
4064 break;
4066 case 0x20:
4068 InvalidInstruction(2);
4069 break;
4071 case 0x21:
4073 InvalidInstruction(2);
4074 break;
4076 case 0x22:
4078 InvalidInstruction(2);
4079 break;
4081 case 0x23:
4083 InvalidInstruction(2);
4084 break;
4086 case 0x24:
4088 InvalidInstruction(2);
4089 break;
4091 case 0x25:
4093 InvalidInstruction(2);
4094 break;
4096 case 0x26:
4098 InvalidInstruction(2);
4099 break;
4101 case 0x27:
4103 InvalidInstruction(2);
4104 break;
4106 case 0x28:
4108 InvalidInstruction(2);
4109 break;
4111 case 0x29:
4113 InvalidInstruction(2);
4114 break;
4116 case 0x2a:
4118 InvalidInstruction(2);
4119 break;
4121 case 0x2b:
4123 InvalidInstruction(2);
4124 break;
4126 case 0x2c:
4128 InvalidInstruction(2);
4129 break;
4131 case 0x2d:
4133 InvalidInstruction(2);
4134 break;
4136 case 0x2e:
4138 InvalidInstruction(2);
4139 break;
4141 case 0x2f:
4143 InvalidInstruction(2);
4144 break;
4146 case 0x30:
4148 InvalidInstruction(2);
4149 break;
4151 case 0x31:
4153 InvalidInstruction(2);
4154 break;
4156 case 0x32:
4158 InvalidInstruction(2);
4159 break;
4161 case 0x33:
4163 InvalidInstruction(2);
4164 break;
4166 case 0x34:
4168 InvalidInstruction(2);
4169 break;
4171 case 0x35:
4173 InvalidInstruction(2);
4174 break;
4176 case 0x36:
4178 InvalidInstruction(2);
4179 break;
4181 case 0x37:
4183 InvalidInstruction(2);
4184 break;
4186 case 0x38:
4188 InvalidInstruction(2);
4189 break;
4191 case 0x39:
4193 InvalidInstruction(2);
4194 break;
4196 case 0x3a:
4198 InvalidInstruction(2);
4199 break;
4201 case 0x3b:
4203 InvalidInstruction(2);
4204 break;
4206 case 0x3c:
4208 InvalidInstruction(2);
4209 break;
4211 case 0x3d:
4213 InvalidInstruction(2);
4214 break;
4216 case 0x3e:
4218 InvalidInstruction(2);
4219 break;
4221 case 0x3f:
4223 InvalidInstruction(2);
4224 break;
4226 case 0x40:
4228 sdwCyclesRemaining -= 12;
4229 dwAddr = cpu.z80C;
4230 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
4231 while (psIoRead->lowIoAddr != 0xffff)
4233 if ((dwAddr >= psIoRead->lowIoAddr) && (dwAddr <= psIoRead->highIoAddr))
4235 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4236 cpu.z80B = psIoRead->IOCall(dwAddr, psIoRead);
4237 psIoRead = NULL;
4238 break;
4240 ++psIoRead;
4243 if (psIoRead)
4245 cpu.z80B = 0xff; /* Unclaimed I/O read */
4248 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
4249 cpu.z80F |= bPostORFlags[cpu.z80B];
4250 break;
4252 case 0x41:
4254 sdwCyclesRemaining -= 12;
4255 dwAddr = cpu.z80C;
4256 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
4257 while (psIoWrite->lowIoAddr != 0xffff)
4259 if ((dwAddr >= psIoWrite->lowIoAddr) && (dwAddr <= psIoWrite->highIoAddr))
4261 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4262 psIoWrite->IOCall(dwAddr, cpu.z80B, psIoWrite);
4263 psIoWrite = NULL;
4264 break;
4266 ++psIoWrite;
4269 break;
4271 case 0x42:
4273 sdwCyclesRemaining -= 15;
4274 dwTemp = cpu.z80HL - cpu.z80BC - (cpu.z80F & Z80_FLAG_CARRY);
4275 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
4276 cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);
4277 if (0 == (dwTemp & 0xffff))
4279 cpu.z80F |= Z80_FLAG_ZERO;
4281 cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ cpu.z80BC) >> 8) & Z80_FLAG_HALF_CARRY);
4282 cpu.z80F |= ((((cpu.z80BC ^ cpu.z80HL) & (cpu.z80BC ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);
4283 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);
4284 cpu.z80HL = dwTemp & 0xffff;
4285 break;
4287 case 0x43:
4289 sdwCyclesRemaining -= 20;
4290 dwTemp = *pbPC++;
4291 dwTemp |= ((UINT32) *pbPC++ << 8);
4292 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
4293 while (psMemWrite->lowAddr != 0xffffffff)
4295 if ((dwTemp >= psMemWrite->lowAddr) && (dwTemp <= psMemWrite->highAddr))
4297 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4298 if (psMemWrite->memoryCall)
4300 psMemWrite->memoryCall(dwTemp, (cpu.z80BC & 0xff), psMemWrite);
4301 psMemWrite->memoryCall(dwTemp + 1, (cpu.z80BC >> 8), psMemWrite);
4303 else
4305 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr)) = cpu.z80BC;
4306 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr) + 1) = cpu.z80BC >> 8;
4308 psMemWrite = NULL;
4309 break;
4311 ++psMemWrite;
4314 if (psMemWrite)
4316 cpu.z80Base[dwTemp] = (UINT8) cpu.z80BC;
4317 cpu.z80Base[dwTemp + 1] = (UINT8) ((UINT32) cpu.z80BC >> 8);
4320 break;
4322 case 0x44:
4324 sdwCyclesRemaining -= 8;
4325 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
4326 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
4327 pbSubSbcTable[((UINT32) 0 << 8) | cpu.z80A];
4328 cpu.z80A = 0 - cpu.z80A;
4329 break;
4331 case 0x45:
4333 sdwCyclesRemaining -= 14;
4334 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
4335 dwAddr = *pbSP++; /* Pop LSB */
4336 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
4337 cpu.z80sp += 2; /* Pop the word off */
4338 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
4339 cpu.z80iff &= ~(IFF1); /* Keep IFF2 around */
4340 cpu.z80iff |= ((cpu.z80iff >> 1) & IFF1); /* IFF2->IFF1 */
4341 break;
4343 case 0x46:
4345 sdwCyclesRemaining -= 8;
4346 cpu.z80interruptMode = 0;
4347 break;
4349 case 0x47:
4351 sdwCyclesRemaining -= 9;
4352 cpu.z80i = cpu.z80A;
4353 break;
4355 case 0x48:
4357 sdwCyclesRemaining -= 12;
4358 dwAddr = cpu.z80C;
4359 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
4360 while (psIoRead->lowIoAddr != 0xffff)
4362 if ((dwAddr >= psIoRead->lowIoAddr) && (dwAddr <= psIoRead->highIoAddr))
4364 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4365 cpu.z80C = psIoRead->IOCall(dwAddr, psIoRead);
4366 psIoRead = NULL;
4367 break;
4369 ++psIoRead;
4372 if (psIoRead)
4374 cpu.z80C = 0xff; /* Unclaimed I/O read */
4377 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
4378 cpu.z80F |= bPostORFlags[cpu.z80C];
4379 break;
4381 case 0x49:
4383 sdwCyclesRemaining -= 12;
4384 dwAddr = cpu.z80C;
4385 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
4386 while (psIoWrite->lowIoAddr != 0xffff)
4388 if ((dwAddr >= psIoWrite->lowIoAddr) && (dwAddr <= psIoWrite->highIoAddr))
4390 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4391 psIoWrite->IOCall(dwAddr, cpu.z80C, psIoWrite);
4392 psIoWrite = NULL;
4393 break;
4395 ++psIoWrite;
4398 break;
4400 case 0x4a:
4402 sdwCyclesRemaining -= 15;
4403 dwTemp = cpu.z80HL + cpu.z80BC + (cpu.z80F & Z80_FLAG_CARRY);
4404 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
4405 cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);
4406 if (0 == (dwTemp & 0xffff))
4408 cpu.z80F |= Z80_FLAG_ZERO;
4410 cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ cpu.z80BC) >> 8) & Z80_FLAG_HALF_CARRY);
4411 cpu.z80F |= ((((cpu.z80BC ^ cpu.z80HL ^ 0x8000) & (cpu.z80BC ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);
4412 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);
4413 cpu.z80HL = dwTemp & 0xffff;
4414 break;
4416 case 0x4b:
4418 sdwCyclesRemaining -= 20;
4419 dwTemp = *pbPC++;
4420 dwTemp |= ((UINT32) *pbPC++ << 8);
4421 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
4422 while (psMemRead->lowAddr != 0xffffffff)
4424 if ((dwTemp >= psMemRead->lowAddr) && (dwTemp <= psMemRead->highAddr))
4426 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4427 if (psMemRead->memoryCall)
4429 cpu.z80BC = psMemRead->memoryCall(dwTemp, psMemRead);
4430 cpu.z80BC |= (UINT32) ((UINT32) psMemRead->memoryCall(dwTemp + 1, psMemRead) << 8);
4432 else
4434 cpu.z80BC = *((UINT8 *) psMemRead->pUserArea + (dwTemp - psMemRead->lowAddr));
4435 cpu.z80BC |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (dwTemp - psMemRead->lowAddr + 1)) << 8);
4437 psMemRead = NULL;
4438 break;
4440 ++psMemRead;
4443 if (psMemRead)
4445 cpu.z80BC = cpu.z80Base[dwTemp];
4446 cpu.z80BC |= (UINT32) ((UINT32) cpu.z80Base[dwTemp + 1] << 8);
4449 break;
4451 case 0x4c:
4453 sdwCyclesRemaining -= 8;
4454 InvalidInstruction(2);
4455 break;
4457 case 0x4d:
4459 sdwCyclesRemaining -= 14;
4460 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
4461 dwAddr = *pbSP++; /* Pop LSB */
4462 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
4463 cpu.z80sp += 2; /* Pop the word off */
4464 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
4465 break;
4467 case 0x4e:
4469 sdwCyclesRemaining -= 8;
4470 InvalidInstruction(2);
4471 break;
4473 case 0x4f:
4475 sdwCyclesRemaining -= 9;
4476 cpu.z80r = cpu.z80A;
4477 break;
4479 case 0x50:
4481 sdwCyclesRemaining -= 12;
4482 dwAddr = cpu.z80C;
4483 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
4484 while (psIoRead->lowIoAddr != 0xffff)
4486 if ((dwAddr >= psIoRead->lowIoAddr) && (dwAddr <= psIoRead->highIoAddr))
4488 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4489 cpu.z80D = psIoRead->IOCall(dwAddr, psIoRead);
4490 psIoRead = NULL;
4491 break;
4493 ++psIoRead;
4496 if (psIoRead)
4498 cpu.z80D = 0xff; /* Unclaimed I/O read */
4501 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
4502 cpu.z80F |= bPostORFlags[cpu.z80D];
4503 break;
4505 case 0x51:
4507 sdwCyclesRemaining -= 12;
4508 dwAddr = cpu.z80C;
4509 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
4510 while (psIoWrite->lowIoAddr != 0xffff)
4512 if ((dwAddr >= psIoWrite->lowIoAddr) && (dwAddr <= psIoWrite->highIoAddr))
4514 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4515 psIoWrite->IOCall(dwAddr, cpu.z80D, psIoWrite);
4516 psIoWrite = NULL;
4517 break;
4519 ++psIoWrite;
4522 break;
4524 case 0x52:
4526 sdwCyclesRemaining -= 15;
4527 dwTemp = cpu.z80HL - cpu.z80DE - (cpu.z80F & Z80_FLAG_CARRY);
4528 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
4529 cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);
4530 if (0 == (dwTemp & 0xffff))
4532 cpu.z80F |= Z80_FLAG_ZERO;
4534 cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ cpu.z80DE) >> 8) & Z80_FLAG_HALF_CARRY);
4535 cpu.z80F |= ((((cpu.z80DE ^ cpu.z80HL) & (cpu.z80DE ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);
4536 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);
4537 cpu.z80HL = dwTemp & 0xffff;
4538 break;
4540 case 0x53:
4542 sdwCyclesRemaining -= 20;
4543 dwTemp = *pbPC++;
4544 dwTemp |= ((UINT32) *pbPC++ << 8);
4545 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
4546 while (psMemWrite->lowAddr != 0xffffffff)
4548 if ((dwTemp >= psMemWrite->lowAddr) && (dwTemp <= psMemWrite->highAddr))
4550 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4551 if (psMemWrite->memoryCall)
4553 psMemWrite->memoryCall(dwTemp, (cpu.z80DE & 0xff), psMemWrite);
4554 psMemWrite->memoryCall(dwTemp + 1, (cpu.z80DE >> 8), psMemWrite);
4556 else
4558 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr)) = cpu.z80DE;
4559 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr) + 1) = cpu.z80DE >> 8;
4561 psMemWrite = NULL;
4562 break;
4564 ++psMemWrite;
4567 if (psMemWrite)
4569 cpu.z80Base[dwTemp] = (UINT8) cpu.z80DE;
4570 cpu.z80Base[dwTemp + 1] = (UINT8) ((UINT32) cpu.z80DE >> 8);
4573 break;
4575 case 0x54:
4577 sdwCyclesRemaining -= 8;
4578 InvalidInstruction(2);
4579 break;
4581 case 0x55:
4583 sdwCyclesRemaining -= 8;
4584 InvalidInstruction(2);
4585 break;
4587 case 0x56:
4589 sdwCyclesRemaining -= 8;
4590 cpu.z80interruptMode = 1;
4591 cpu.z80intAddr = 0x38;
4592 break;
4594 case 0x57:
4596 sdwCyclesRemaining -= 9;
4597 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
4598 cpu.z80F |= ((cpu.z80iff & IFF2) << 1);
4599 cpu.z80A = cpu.z80i;
4600 cpu.z80F |= bPostORFlags[cpu.z80A];
4601 break;
4603 case 0x58:
4605 sdwCyclesRemaining -= 12;
4606 dwAddr = cpu.z80C;
4607 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
4608 while (psIoRead->lowIoAddr != 0xffff)
4610 if ((dwAddr >= psIoRead->lowIoAddr) && (dwAddr <= psIoRead->highIoAddr))
4612 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4613 cpu.z80E = psIoRead->IOCall(dwAddr, psIoRead);
4614 psIoRead = NULL;
4615 break;
4617 ++psIoRead;
4620 if (psIoRead)
4622 cpu.z80E = 0xff; /* Unclaimed I/O read */
4625 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
4626 cpu.z80F |= bPostORFlags[cpu.z80E];
4627 break;
4629 case 0x59:
4631 sdwCyclesRemaining -= 12;
4632 dwAddr = cpu.z80C;
4633 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
4634 while (psIoWrite->lowIoAddr != 0xffff)
4636 if ((dwAddr >= psIoWrite->lowIoAddr) && (dwAddr <= psIoWrite->highIoAddr))
4638 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4639 psIoWrite->IOCall(dwAddr, cpu.z80E, psIoWrite);
4640 psIoWrite = NULL;
4641 break;
4643 ++psIoWrite;
4646 break;
4648 case 0x5a:
4650 sdwCyclesRemaining -= 15;
4651 dwTemp = cpu.z80HL + cpu.z80DE + (cpu.z80F & Z80_FLAG_CARRY);
4652 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
4653 cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);
4654 if (0 == (dwTemp & 0xffff))
4656 cpu.z80F |= Z80_FLAG_ZERO;
4658 cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ cpu.z80DE) >> 8) & Z80_FLAG_HALF_CARRY);
4659 cpu.z80F |= ((((cpu.z80DE ^ cpu.z80HL ^ 0x8000) & (cpu.z80DE ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);
4660 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);
4661 cpu.z80HL = dwTemp & 0xffff;
4662 break;
4664 case 0x5b:
4666 sdwCyclesRemaining -= 20;
4667 dwTemp = *pbPC++;
4668 dwTemp |= ((UINT32) *pbPC++ << 8);
4669 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
4670 while (psMemRead->lowAddr != 0xffffffff)
4672 if ((dwTemp >= psMemRead->lowAddr) && (dwTemp <= psMemRead->highAddr))
4674 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4675 if (psMemRead->memoryCall)
4677 cpu.z80DE = psMemRead->memoryCall(dwTemp, psMemRead);
4678 cpu.z80DE |= (UINT32) ((UINT32) psMemRead->memoryCall(dwTemp + 1, psMemRead) << 8);
4680 else
4682 cpu.z80DE = *((UINT8 *) psMemRead->pUserArea + (dwTemp - psMemRead->lowAddr));
4683 cpu.z80DE |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (dwTemp - psMemRead->lowAddr + 1)) << 8);
4685 psMemRead = NULL;
4686 break;
4688 ++psMemRead;
4691 if (psMemRead)
4693 cpu.z80DE = cpu.z80Base[dwTemp];
4694 cpu.z80DE |= (UINT32) ((UINT32) cpu.z80Base[dwTemp + 1] << 8);
4697 break;
4699 case 0x5c:
4701 sdwCyclesRemaining -= 8;
4702 InvalidInstruction(2);
4703 break;
4705 case 0x5d:
4707 sdwCyclesRemaining -= 8;
4708 InvalidInstruction(2);
4709 break;
4711 case 0x5e:
4713 sdwCyclesRemaining -= 8;
4714 cpu.z80interruptMode = 2;
4715 break;
4717 case 0x5f:
4719 sdwCyclesRemaining -= 9;
4720 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
4721 cpu.z80F |= bPostORFlags[cpu.z80r];
4722 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_OVERFLOW_PARITY)) | ((cpu.z80iff & IFF2) << 1);
4723 cpu.z80A = cpu.z80r;
4724 bTemp = (cpu.z80r + (cpu.z80B + sdwCyclesRemaining + 1 + cpu.z80H)) ^ cpu.z80A;
4725 cpu.z80r = (cpu.z80r & 0x80) | (bTemp & 0x7f);
4726 break;
4728 case 0x60:
4730 sdwCyclesRemaining -= 12;
4731 dwAddr = cpu.z80C;
4732 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
4733 while (psIoRead->lowIoAddr != 0xffff)
4735 if ((dwAddr >= psIoRead->lowIoAddr) && (dwAddr <= psIoRead->highIoAddr))
4737 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4738 cpu.z80H = psIoRead->IOCall(dwAddr, psIoRead);
4739 psIoRead = NULL;
4740 break;
4742 ++psIoRead;
4745 if (psIoRead)
4747 cpu.z80H = 0xff; /* Unclaimed I/O read */
4750 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
4751 cpu.z80F |= bPostORFlags[cpu.z80H];
4752 break;
4754 case 0x61:
4756 sdwCyclesRemaining -= 12;
4757 dwAddr = cpu.z80C;
4758 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
4759 while (psIoWrite->lowIoAddr != 0xffff)
4761 if ((dwAddr >= psIoWrite->lowIoAddr) && (dwAddr <= psIoWrite->highIoAddr))
4763 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4764 psIoWrite->IOCall(dwAddr, cpu.z80H, psIoWrite);
4765 psIoWrite = NULL;
4766 break;
4768 ++psIoWrite;
4771 break;
4773 case 0x62:
4775 sdwCyclesRemaining -= 15;
4776 dwTemp = cpu.z80HL - cpu.z80HL - (cpu.z80F & Z80_FLAG_CARRY);
4777 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
4778 cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);
4779 if (0 == (dwTemp & 0xffff))
4781 cpu.z80F |= Z80_FLAG_ZERO;
4783 cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ cpu.z80HL) >> 8) & Z80_FLAG_HALF_CARRY);
4784 cpu.z80F |= ((((cpu.z80HL ^ cpu.z80HL) & (cpu.z80HL ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);
4785 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);
4786 cpu.z80HL = dwTemp & 0xffff;
4787 break;
4789 case 0x63:
4791 sdwCyclesRemaining -= 20;
4792 dwTemp = *pbPC++;
4793 dwTemp |= ((UINT32) *pbPC++ << 8);
4794 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
4795 while (psMemWrite->lowAddr != 0xffffffff)
4797 if ((dwTemp >= psMemWrite->lowAddr) && (dwTemp <= psMemWrite->highAddr))
4799 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4800 if (psMemWrite->memoryCall)
4802 psMemWrite->memoryCall(dwTemp, (cpu.z80HL & 0xff), psMemWrite);
4803 psMemWrite->memoryCall(dwTemp + 1, (cpu.z80HL >> 8), psMemWrite);
4805 else
4807 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr)) = cpu.z80HL;
4808 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr) + 1) = cpu.z80HL >> 8;
4810 psMemWrite = NULL;
4811 break;
4813 ++psMemWrite;
4816 if (psMemWrite)
4818 cpu.z80Base[dwTemp] = (UINT8) cpu.z80HL;
4819 cpu.z80Base[dwTemp + 1] = (UINT8) ((UINT32) cpu.z80HL >> 8);
4822 break;
4824 case 0x64:
4826 sdwCyclesRemaining -= 8;
4827 InvalidInstruction(2);
4828 break;
4830 case 0x65:
4832 sdwCyclesRemaining -= 8;
4833 InvalidInstruction(2);
4834 break;
4836 case 0x66:
4838 sdwCyclesRemaining -= 8;
4839 InvalidInstruction(2);
4840 break;
4842 case 0x67:
4844 sdwCyclesRemaining -= 18;
4845 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
4846 while (psMemRead->lowAddr != 0xffffffff)
4848 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
4850 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4851 if (psMemRead->memoryCall)
4853 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
4855 else
4857 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
4859 psMemRead = NULL;
4860 break;
4862 ++psMemRead;
4865 if (psMemRead)
4867 bTemp = cpu.z80Base[cpu.z80HL];
4870 bTemp2 = (cpu.z80A & 0x0f) << 4;
4871 cpu.z80A = (cpu.z80A & 0xf0) | (bTemp & 0x0f);
4872 bTemp = (bTemp >> 4) | bTemp2;
4873 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
4874 while (psMemWrite->lowAddr != 0xffffffff)
4876 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
4878 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4879 if (psMemWrite->memoryCall)
4881 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
4883 else
4885 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
4887 psMemWrite = NULL;
4888 break;
4890 ++psMemWrite;
4893 if (psMemWrite)
4895 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
4898 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
4899 cpu.z80F |= bPostORFlags[cpu.z80A];
4900 break;
4902 case 0x68:
4904 sdwCyclesRemaining -= 12;
4905 dwAddr = cpu.z80C;
4906 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
4907 while (psIoRead->lowIoAddr != 0xffff)
4909 if ((dwAddr >= psIoRead->lowIoAddr) && (dwAddr <= psIoRead->highIoAddr))
4911 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4912 cpu.z80L = psIoRead->IOCall(dwAddr, psIoRead);
4913 psIoRead = NULL;
4914 break;
4916 ++psIoRead;
4919 if (psIoRead)
4921 cpu.z80L = 0xff; /* Unclaimed I/O read */
4924 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
4925 cpu.z80F |= bPostORFlags[cpu.z80L];
4926 break;
4928 case 0x69:
4930 sdwCyclesRemaining -= 12;
4931 dwAddr = cpu.z80C;
4932 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
4933 while (psIoWrite->lowIoAddr != 0xffff)
4935 if ((dwAddr >= psIoWrite->lowIoAddr) && (dwAddr <= psIoWrite->highIoAddr))
4937 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4938 psIoWrite->IOCall(dwAddr, cpu.z80L, psIoWrite);
4939 psIoWrite = NULL;
4940 break;
4942 ++psIoWrite;
4945 break;
4947 case 0x6a:
4949 sdwCyclesRemaining -= 15;
4950 dwTemp = cpu.z80HL + cpu.z80HL + (cpu.z80F & Z80_FLAG_CARRY);
4951 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
4952 cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);
4953 if (0 == (dwTemp & 0xffff))
4955 cpu.z80F |= Z80_FLAG_ZERO;
4957 cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ cpu.z80HL) >> 8) & Z80_FLAG_HALF_CARRY);
4958 cpu.z80F |= ((((cpu.z80HL ^ cpu.z80HL ^ 0x8000) & (cpu.z80HL ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);
4959 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);
4960 cpu.z80HL = dwTemp & 0xffff;
4961 break;
4963 case 0x6b:
4965 sdwCyclesRemaining -= 20;
4966 InvalidInstruction(2);
4967 break;
4969 case 0x6c:
4971 sdwCyclesRemaining -= 8;
4972 InvalidInstruction(2);
4973 break;
4975 case 0x6d:
4977 sdwCyclesRemaining -= 8;
4978 InvalidInstruction(2);
4979 break;
4981 case 0x6e:
4983 sdwCyclesRemaining -= 8;
4984 InvalidInstruction(2);
4985 break;
4987 case 0x6f:
4989 sdwCyclesRemaining -= 18;
4990 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
4991 while (psMemRead->lowAddr != 0xffffffff)
4993 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
4995 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
4996 if (psMemRead->memoryCall)
4998 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5000 else
5002 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5004 psMemRead = NULL;
5005 break;
5007 ++psMemRead;
5010 if (psMemRead)
5012 bTemp = cpu.z80Base[cpu.z80HL];
5015 bTemp2 = (cpu.z80A & 0x0f);
5016 cpu.z80A = (cpu.z80A & 0xf0) | (bTemp >> 4);
5017 bTemp = (bTemp << 4) | bTemp2;
5018 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
5019 while (psMemWrite->lowAddr != 0xffffffff)
5021 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
5023 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5024 if (psMemWrite->memoryCall)
5026 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
5028 else
5030 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
5032 psMemWrite = NULL;
5033 break;
5035 ++psMemWrite;
5038 if (psMemWrite)
5040 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
5043 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
5044 cpu.z80F |= bPostORFlags[cpu.z80A];
5045 break;
5047 case 0x70:
5049 sdwCyclesRemaining -= 12;
5050 InvalidInstruction(2);
5051 break;
5053 case 0x71:
5055 sdwCyclesRemaining -= 12;
5056 InvalidInstruction(2);
5057 break;
5059 case 0x72:
5061 sdwCyclesRemaining -= 15;
5062 dwTemp = cpu.z80HL - cpu.z80sp - (cpu.z80F & Z80_FLAG_CARRY);
5063 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
5064 cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);
5065 if (0 == (dwTemp & 0xffff))
5067 cpu.z80F |= Z80_FLAG_ZERO;
5069 cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ cpu.z80sp) >> 8) & Z80_FLAG_HALF_CARRY);
5070 cpu.z80F |= ((((cpu.z80sp ^ cpu.z80HL) & (cpu.z80sp ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);
5071 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);
5072 cpu.z80HL = dwTemp & 0xffff;
5073 break;
5075 case 0x73:
5077 sdwCyclesRemaining -= 20;
5078 dwTemp = *pbPC++;
5079 dwTemp |= ((UINT32) *pbPC++ << 8);
5080 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
5081 while (psMemWrite->lowAddr != 0xffffffff)
5083 if ((dwTemp >= psMemWrite->lowAddr) && (dwTemp <= psMemWrite->highAddr))
5085 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5086 if (psMemWrite->memoryCall)
5088 psMemWrite->memoryCall(dwTemp, (cpu.z80sp & 0xff), psMemWrite);
5089 psMemWrite->memoryCall(dwTemp + 1, (cpu.z80sp >> 8), psMemWrite);
5091 else
5093 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr)) = cpu.z80sp;
5094 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr) + 1) = cpu.z80sp >> 8;
5096 psMemWrite = NULL;
5097 break;
5099 ++psMemWrite;
5102 if (psMemWrite)
5104 cpu.z80Base[dwTemp] = (UINT8) cpu.z80sp;
5105 cpu.z80Base[dwTemp + 1] = (UINT8) ((UINT32) cpu.z80sp >> 8);
5108 break;
5110 case 0x74:
5112 sdwCyclesRemaining -= 8;
5113 InvalidInstruction(2);
5114 break;
5116 case 0x75:
5118 sdwCyclesRemaining -= 8;
5119 InvalidInstruction(2);
5120 break;
5122 case 0x76:
5124 sdwCyclesRemaining -= 8;
5125 InvalidInstruction(2);
5126 break;
5128 case 0x77:
5130 InvalidInstruction(2);
5131 break;
5133 case 0x78:
5135 sdwCyclesRemaining -= 12;
5136 dwAddr = cpu.z80C;
5137 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
5138 while (psIoRead->lowIoAddr != 0xffff)
5140 if ((dwAddr >= psIoRead->lowIoAddr) && (dwAddr <= psIoRead->highIoAddr))
5142 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5143 cpu.z80A = psIoRead->IOCall(dwAddr, psIoRead);
5144 psIoRead = NULL;
5145 break;
5147 ++psIoRead;
5150 if (psIoRead)
5152 cpu.z80A = 0xff; /* Unclaimed I/O read */
5155 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
5156 cpu.z80F |= bPostORFlags[cpu.z80A];
5157 break;
5159 case 0x79:
5161 sdwCyclesRemaining -= 12;
5162 dwAddr = cpu.z80C;
5163 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
5164 while (psIoWrite->lowIoAddr != 0xffff)
5166 if ((dwAddr >= psIoWrite->lowIoAddr) && (dwAddr <= psIoWrite->highIoAddr))
5168 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5169 psIoWrite->IOCall(dwAddr, cpu.z80A, psIoWrite);
5170 psIoWrite = NULL;
5171 break;
5173 ++psIoWrite;
5176 break;
5178 case 0x7a:
5180 sdwCyclesRemaining -= 15;
5181 dwTemp = cpu.z80HL + cpu.z80sp + (cpu.z80F & Z80_FLAG_CARRY);
5182 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
5183 cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);
5184 if (0 == (dwTemp & 0xffff))
5186 cpu.z80F |= Z80_FLAG_ZERO;
5188 cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ cpu.z80sp) >> 8) & Z80_FLAG_HALF_CARRY);
5189 cpu.z80F |= ((((cpu.z80sp ^ cpu.z80HL ^ 0x8000) & (cpu.z80sp ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);
5190 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);
5191 cpu.z80HL = dwTemp & 0xffff;
5192 break;
5194 case 0x7b:
5196 sdwCyclesRemaining -= 20;
5197 dwTemp = *pbPC++;
5198 dwTemp |= ((UINT32) *pbPC++ << 8);
5199 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5200 while (psMemRead->lowAddr != 0xffffffff)
5202 if ((dwTemp >= psMemRead->lowAddr) && (dwTemp <= psMemRead->highAddr))
5204 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5205 if (psMemRead->memoryCall)
5207 cpu.z80sp = psMemRead->memoryCall(dwTemp, psMemRead);
5208 cpu.z80sp |= (UINT32) ((UINT32) psMemRead->memoryCall(dwTemp + 1, psMemRead) << 8);
5210 else
5212 cpu.z80sp = *((UINT8 *) psMemRead->pUserArea + (dwTemp - psMemRead->lowAddr));
5213 cpu.z80sp |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (dwTemp - psMemRead->lowAddr + 1)) << 8);
5215 psMemRead = NULL;
5216 break;
5218 ++psMemRead;
5221 if (psMemRead)
5223 cpu.z80sp = cpu.z80Base[dwTemp];
5224 cpu.z80sp |= (UINT32) ((UINT32) cpu.z80Base[dwTemp + 1] << 8);
5227 break;
5229 case 0x7c:
5231 sdwCyclesRemaining -= 8;
5232 InvalidInstruction(2);
5233 break;
5235 case 0x7d:
5237 sdwCyclesRemaining -= 8;
5238 InvalidInstruction(2);
5239 break;
5241 case 0x7e:
5243 sdwCyclesRemaining -= 8;
5244 InvalidInstruction(2);
5245 break;
5247 case 0x7f:
5249 InvalidInstruction(2);
5250 break;
5252 case 0x80:
5254 InvalidInstruction(2);
5255 break;
5257 case 0x81:
5259 InvalidInstruction(2);
5260 break;
5262 case 0x82:
5264 InvalidInstruction(2);
5265 break;
5267 case 0x83:
5269 InvalidInstruction(2);
5270 break;
5272 case 0x84:
5274 InvalidInstruction(2);
5275 break;
5277 case 0x85:
5279 InvalidInstruction(2);
5280 break;
5282 case 0x86:
5284 InvalidInstruction(2);
5285 break;
5287 case 0x87:
5289 InvalidInstruction(2);
5290 break;
5292 case 0x88:
5294 InvalidInstruction(2);
5295 break;
5297 case 0x89:
5299 InvalidInstruction(2);
5300 break;
5302 case 0x8a:
5304 InvalidInstruction(2);
5305 break;
5307 case 0x8b:
5309 InvalidInstruction(2);
5310 break;
5312 case 0x8c:
5314 InvalidInstruction(2);
5315 break;
5317 case 0x8d:
5319 InvalidInstruction(2);
5320 break;
5322 case 0x8e:
5324 InvalidInstruction(2);
5325 break;
5327 case 0x8f:
5329 InvalidInstruction(2);
5330 break;
5332 case 0x90:
5334 InvalidInstruction(2);
5335 break;
5337 case 0x91:
5339 InvalidInstruction(2);
5340 break;
5342 case 0x92:
5344 InvalidInstruction(2);
5345 break;
5347 case 0x93:
5349 InvalidInstruction(2);
5350 break;
5352 case 0x94:
5354 InvalidInstruction(2);
5355 break;
5357 case 0x95:
5359 InvalidInstruction(2);
5360 break;
5362 case 0x96:
5364 InvalidInstruction(2);
5365 break;
5367 case 0x97:
5369 InvalidInstruction(2);
5370 break;
5372 case 0x98:
5374 InvalidInstruction(2);
5375 break;
5377 case 0x99:
5379 InvalidInstruction(2);
5380 break;
5382 case 0x9a:
5384 InvalidInstruction(2);
5385 break;
5387 case 0x9b:
5389 InvalidInstruction(2);
5390 break;
5392 case 0x9c:
5394 InvalidInstruction(2);
5395 break;
5397 case 0x9d:
5399 InvalidInstruction(2);
5400 break;
5402 case 0x9e:
5404 InvalidInstruction(2);
5405 break;
5407 case 0x9f:
5409 InvalidInstruction(2);
5410 break;
5412 case 0xa0:
5414 sdwCyclesRemaining -= 16;
5415 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5416 while (psMemRead->lowAddr != 0xffffffff)
5418 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
5420 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5421 if (psMemRead->memoryCall)
5423 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5425 else
5427 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5429 psMemRead = NULL;
5430 break;
5432 ++psMemRead;
5435 if (psMemRead)
5437 bTemp = cpu.z80Base[cpu.z80HL];
5440 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
5441 while (psMemWrite->lowAddr != 0xffffffff)
5443 if ((cpu.z80DE >= psMemWrite->lowAddr) && (cpu.z80DE <= psMemWrite->highAddr))
5445 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5446 if (psMemWrite->memoryCall)
5448 psMemWrite->memoryCall(cpu.z80DE, bTemp, psMemWrite);
5450 else
5452 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80DE - psMemWrite->lowAddr)) = bTemp;
5454 psMemWrite = NULL;
5455 break;
5457 ++psMemWrite;
5460 if (psMemWrite)
5462 cpu.z80Base[cpu.z80DE] = (UINT8) bTemp;
5465 ++cpu.z80HL;
5466 ++cpu.z80DE;
5467 --cpu.z80BC;
5468 cpu.z80HL &= 0xffff;
5469 cpu.z80DE &= 0xffff;
5470 cpu.z80BC &= 0xffff;
5471 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY);
5472 if (cpu.z80BC)
5474 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5476 break;
5478 case 0xa1:
5480 sdwCyclesRemaining -= 16;
5482 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5483 while (psMemRead->lowAddr != 0xffffffff)
5485 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
5487 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5488 if (psMemRead->memoryCall)
5490 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5492 else
5494 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5496 psMemRead = NULL;
5497 break;
5499 ++psMemRead;
5502 if (psMemRead)
5504 bTemp = cpu.z80Base[cpu.z80HL];
5507 cpu.z80HL++;
5508 cpu.z80HL &= 0xffff;
5509 cpu.z80BC--;
5510 cpu.z80BC &= 0xffff;
5512 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
5513 cpu.z80F |= (pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO));
5514 if (cpu.z80BC)
5516 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5518 break;
5520 case 0xa2:
5522 sdwCyclesRemaining -= 16;
5524 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
5525 while (psIoRead->lowIoAddr != 0xffff)
5527 if ((cpu.z80B >= psIoRead->lowIoAddr) && (cpu.z80B <= psIoRead->highIoAddr))
5529 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5530 bTemp = psIoRead->IOCall(cpu.z80B, psIoRead);
5531 psIoRead = NULL;
5532 break;
5534 ++psIoRead;
5537 if (psIoRead)
5539 bTemp = 0xff; /* Unclaimed I/O read */
5542 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
5543 while (psMemWrite->lowAddr != 0xffffffff)
5545 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
5547 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5548 if (psMemWrite->memoryCall)
5550 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
5552 else
5554 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
5556 psMemWrite = NULL;
5557 break;
5559 ++psMemWrite;
5562 if (psMemWrite)
5564 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
5567 cpu.z80HL++;
5568 cpu.z80HL &= 0xffff;
5569 sdwCyclesRemaining -= 16;
5570 cpu.z80B--;
5572 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
5573 cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));
5574 if (cpu.z80B)
5576 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5577 pbPC -= 2;
5579 break;
5581 case 0xa3:
5583 sdwCyclesRemaining -= 16;
5585 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5586 while (psMemRead->lowAddr != 0xffffffff)
5588 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
5590 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5591 if (psMemRead->memoryCall)
5593 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5595 else
5597 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5599 psMemRead = NULL;
5600 break;
5602 ++psMemRead;
5605 if (psMemRead)
5607 bTemp = cpu.z80Base[cpu.z80HL];
5610 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
5611 while (psIoWrite->lowIoAddr != 0xffff)
5613 if ((cpu.z80BC >= psIoWrite->lowIoAddr) && (cpu.z80BC <= psIoWrite->highIoAddr))
5615 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5616 psIoWrite->IOCall(cpu.z80BC, bTemp, psIoWrite);
5617 psIoWrite = NULL;
5618 break;
5620 ++psIoWrite;
5623 cpu.z80HL++;
5624 cpu.z80HL &= 0xffff;
5625 sdwCyclesRemaining -= 16;
5626 cpu.z80B--;
5628 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
5629 cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));
5630 if (cpu.z80B)
5632 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5634 break;
5636 case 0xa4:
5638 InvalidInstruction(2);
5639 break;
5641 case 0xa5:
5643 InvalidInstruction(2);
5644 break;
5646 case 0xa6:
5648 InvalidInstruction(2);
5649 break;
5651 case 0xa7:
5653 InvalidInstruction(2);
5654 break;
5656 case 0xa8:
5658 sdwCyclesRemaining -= 16;
5659 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5660 while (psMemRead->lowAddr != 0xffffffff)
5662 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
5664 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5665 if (psMemRead->memoryCall)
5667 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5669 else
5671 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5673 psMemRead = NULL;
5674 break;
5676 ++psMemRead;
5679 if (psMemRead)
5681 bTemp = cpu.z80Base[cpu.z80HL];
5684 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
5685 while (psMemWrite->lowAddr != 0xffffffff)
5687 if ((cpu.z80DE >= psMemWrite->lowAddr) && (cpu.z80DE <= psMemWrite->highAddr))
5689 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5690 if (psMemWrite->memoryCall)
5692 psMemWrite->memoryCall(cpu.z80DE, bTemp, psMemWrite);
5694 else
5696 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80DE - psMemWrite->lowAddr)) = bTemp;
5698 psMemWrite = NULL;
5699 break;
5701 ++psMemWrite;
5704 if (psMemWrite)
5706 cpu.z80Base[cpu.z80DE] = (UINT8) bTemp;
5709 --cpu.z80HL;
5710 --cpu.z80DE;
5711 --cpu.z80BC;
5712 cpu.z80HL &= 0xffff;
5713 cpu.z80DE &= 0xffff;
5714 cpu.z80BC &= 0xffff;
5715 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY);
5716 if (cpu.z80BC)
5718 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5720 break;
5722 case 0xa9:
5724 sdwCyclesRemaining -= 16;
5726 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5727 while (psMemRead->lowAddr != 0xffffffff)
5729 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
5731 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5732 if (psMemRead->memoryCall)
5734 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5736 else
5738 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5740 psMemRead = NULL;
5741 break;
5743 ++psMemRead;
5746 if (psMemRead)
5748 bTemp = cpu.z80Base[cpu.z80HL];
5751 cpu.z80HL--;
5752 cpu.z80HL &= 0xffff;
5753 cpu.z80BC--;
5754 cpu.z80BC &= 0xffff;
5756 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
5757 cpu.z80F |= (pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO));
5758 if (cpu.z80BC)
5760 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5762 break;
5764 case 0xaa:
5766 sdwCyclesRemaining -= 16;
5768 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
5769 while (psIoRead->lowIoAddr != 0xffff)
5771 if ((cpu.z80B >= psIoRead->lowIoAddr) && (cpu.z80B <= psIoRead->highIoAddr))
5773 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5774 bTemp = psIoRead->IOCall(cpu.z80B, psIoRead);
5775 psIoRead = NULL;
5776 break;
5778 ++psIoRead;
5781 if (psIoRead)
5783 bTemp = 0xff; /* Unclaimed I/O read */
5786 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
5787 while (psMemWrite->lowAddr != 0xffffffff)
5789 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
5791 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5792 if (psMemWrite->memoryCall)
5794 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
5796 else
5798 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
5800 psMemWrite = NULL;
5801 break;
5803 ++psMemWrite;
5806 if (psMemWrite)
5808 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
5811 cpu.z80HL--;
5812 cpu.z80HL &= 0xffff;
5813 sdwCyclesRemaining -= 16;
5814 cpu.z80B--;
5816 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
5817 cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));
5818 if (cpu.z80B)
5820 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5821 pbPC -= 2;
5823 break;
5825 case 0xab:
5827 sdwCyclesRemaining -= 16;
5829 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5830 while (psMemRead->lowAddr != 0xffffffff)
5832 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
5834 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5835 if (psMemRead->memoryCall)
5837 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5839 else
5841 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5843 psMemRead = NULL;
5844 break;
5846 ++psMemRead;
5849 if (psMemRead)
5851 bTemp = cpu.z80Base[cpu.z80HL];
5854 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
5855 while (psIoWrite->lowIoAddr != 0xffff)
5857 if ((cpu.z80BC >= psIoWrite->lowIoAddr) && (cpu.z80BC <= psIoWrite->highIoAddr))
5859 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5860 psIoWrite->IOCall(cpu.z80BC, bTemp, psIoWrite);
5861 psIoWrite = NULL;
5862 break;
5864 ++psIoWrite;
5867 cpu.z80HL--;
5868 cpu.z80HL &= 0xffff;
5869 sdwCyclesRemaining -= 16;
5870 cpu.z80B--;
5872 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
5873 cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));
5874 if (cpu.z80B)
5876 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5878 break;
5880 case 0xac:
5882 InvalidInstruction(2);
5883 break;
5885 case 0xad:
5887 InvalidInstruction(2);
5888 break;
5890 case 0xae:
5892 InvalidInstruction(2);
5893 break;
5895 case 0xaf:
5897 InvalidInstruction(2);
5898 break;
5900 case 0xb0:
5902 sdwCyclesRemaining -= 16;
5903 while ((sdwCyclesRemaining > 0) && (cpu.z80BC))
5905 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5906 while (psMemRead->lowAddr != 0xffffffff)
5908 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
5910 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5911 if (psMemRead->memoryCall)
5913 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5915 else
5917 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5919 psMemRead = NULL;
5920 break;
5922 ++psMemRead;
5925 if (psMemRead)
5927 bTemp = cpu.z80Base[cpu.z80HL];
5930 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
5931 while (psMemWrite->lowAddr != 0xffffffff)
5933 if ((cpu.z80DE >= psMemWrite->lowAddr) && (cpu.z80DE <= psMemWrite->highAddr))
5935 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5936 if (psMemWrite->memoryCall)
5938 psMemWrite->memoryCall(cpu.z80DE, bTemp, psMemWrite);
5940 else
5942 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80DE - psMemWrite->lowAddr)) = bTemp;
5944 psMemWrite = NULL;
5945 break;
5947 ++psMemWrite;
5950 if (psMemWrite)
5952 cpu.z80Base[cpu.z80DE] = (UINT8) bTemp;
5955 ++cpu.z80HL;
5956 ++cpu.z80DE;
5957 --cpu.z80BC;
5958 cpu.z80HL &= 0xffff;
5959 cpu.z80DE &= 0xffff;
5960 cpu.z80BC &= 0xffff;
5961 sdwCyclesRemaining -= 21;
5963 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY);
5964 if (cpu.z80BC)
5966 pbPC -= 2; /* Back up so we hit this instruction again */
5967 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
5969 sdwCyclesRemaining -= 16;
5970 break;
5972 case 0xb1:
5974 sdwCyclesRemaining -= 16;
5975 while ((sdwCyclesRemaining >= 0) && (cpu.z80BC))
5977 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
5978 while (psMemRead->lowAddr != 0xffffffff)
5980 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
5982 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
5983 if (psMemRead->memoryCall)
5985 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
5987 else
5989 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
5991 psMemRead = NULL;
5992 break;
5994 ++psMemRead;
5997 if (psMemRead)
5999 bTemp = cpu.z80Base[cpu.z80HL];
6002 cpu.z80HL++;
6003 cpu.z80HL &= 0xffff;
6004 cpu.z80BC--;
6005 cpu.z80BC &= 0xffff;
6006 sdwCyclesRemaining -= 16;
6007 if (cpu.z80A == bTemp)
6009 break;
6012 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
6013 cpu.z80F |= (pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO));
6014 if (cpu.z80BC)
6016 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
6018 break;
6020 case 0xb2:
6022 sdwCyclesRemaining -= 16;
6023 while ((sdwCyclesRemaining > 0) && (cpu.z80B))
6025 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
6026 while (psIoRead->lowIoAddr != 0xffff)
6028 if ((cpu.z80B >= psIoRead->lowIoAddr) && (cpu.z80B <= psIoRead->highIoAddr))
6030 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6031 bTemp = psIoRead->IOCall(cpu.z80B, psIoRead);
6032 psIoRead = NULL;
6033 break;
6035 ++psIoRead;
6038 if (psIoRead)
6040 bTemp = 0xff; /* Unclaimed I/O read */
6043 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
6044 while (psMemWrite->lowAddr != 0xffffffff)
6046 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
6048 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6049 if (psMemWrite->memoryCall)
6051 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
6053 else
6055 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
6057 psMemWrite = NULL;
6058 break;
6060 ++psMemWrite;
6063 if (psMemWrite)
6065 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
6068 cpu.z80HL++;
6069 cpu.z80HL &= 0xffff;
6070 sdwCyclesRemaining -= 16;
6071 cpu.z80B--;
6073 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
6074 cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));
6075 if (cpu.z80B)
6077 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
6078 pbPC -= 2;
6080 break;
6082 case 0xb3:
6084 sdwCyclesRemaining -= 16;
6085 while ((sdwCyclesRemaining > 0) && (cpu.z80B))
6087 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
6088 while (psMemRead->lowAddr != 0xffffffff)
6090 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
6092 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6093 if (psMemRead->memoryCall)
6095 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
6097 else
6099 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
6101 psMemRead = NULL;
6102 break;
6104 ++psMemRead;
6107 if (psMemRead)
6109 bTemp = cpu.z80Base[cpu.z80HL];
6112 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
6113 while (psIoWrite->lowIoAddr != 0xffff)
6115 if ((cpu.z80BC >= psIoWrite->lowIoAddr) && (cpu.z80BC <= psIoWrite->highIoAddr))
6117 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6118 psIoWrite->IOCall(cpu.z80BC, bTemp, psIoWrite);
6119 psIoWrite = NULL;
6120 break;
6122 ++psIoWrite;
6125 cpu.z80HL++;
6126 cpu.z80HL &= 0xffff;
6127 sdwCyclesRemaining -= 16;
6128 cpu.z80B--;
6130 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
6131 cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));
6132 if (cpu.z80B)
6134 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
6136 break;
6138 case 0xb4:
6140 InvalidInstruction(2);
6141 break;
6143 case 0xb5:
6145 InvalidInstruction(2);
6146 break;
6148 case 0xb6:
6150 InvalidInstruction(2);
6151 break;
6153 case 0xb7:
6155 InvalidInstruction(2);
6156 break;
6158 case 0xb8:
6160 sdwCyclesRemaining -= 16;
6161 while ((sdwCyclesRemaining > 0) && (cpu.z80BC))
6163 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
6164 while (psMemRead->lowAddr != 0xffffffff)
6166 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
6168 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6169 if (psMemRead->memoryCall)
6171 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
6173 else
6175 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
6177 psMemRead = NULL;
6178 break;
6180 ++psMemRead;
6183 if (psMemRead)
6185 bTemp = cpu.z80Base[cpu.z80HL];
6188 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
6189 while (psMemWrite->lowAddr != 0xffffffff)
6191 if ((cpu.z80DE >= psMemWrite->lowAddr) && (cpu.z80DE <= psMemWrite->highAddr))
6193 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6194 if (psMemWrite->memoryCall)
6196 psMemWrite->memoryCall(cpu.z80DE, bTemp, psMemWrite);
6198 else
6200 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80DE - psMemWrite->lowAddr)) = bTemp;
6202 psMemWrite = NULL;
6203 break;
6205 ++psMemWrite;
6208 if (psMemWrite)
6210 cpu.z80Base[cpu.z80DE] = (UINT8) bTemp;
6213 --cpu.z80HL;
6214 --cpu.z80DE;
6215 --cpu.z80BC;
6216 cpu.z80HL &= 0xffff;
6217 cpu.z80DE &= 0xffff;
6218 cpu.z80BC &= 0xffff;
6219 sdwCyclesRemaining -= 21;
6221 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY);
6222 if (cpu.z80BC)
6224 pbPC -= 2; /* Back up so we hit this instruction again */
6225 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
6227 sdwCyclesRemaining -= 16;
6228 break;
6230 case 0xb9:
6232 sdwCyclesRemaining -= 16;
6233 while ((sdwCyclesRemaining >= 0) && (cpu.z80BC))
6235 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
6236 while (psMemRead->lowAddr != 0xffffffff)
6238 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
6240 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6241 if (psMemRead->memoryCall)
6243 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
6245 else
6247 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
6249 psMemRead = NULL;
6250 break;
6252 ++psMemRead;
6255 if (psMemRead)
6257 bTemp = cpu.z80Base[cpu.z80HL];
6260 cpu.z80HL--;
6261 cpu.z80HL &= 0xffff;
6262 cpu.z80BC--;
6263 cpu.z80BC &= 0xffff;
6264 sdwCyclesRemaining -= 16;
6265 if (cpu.z80A == bTemp)
6267 break;
6270 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
6271 cpu.z80F |= (pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO));
6272 if (cpu.z80BC)
6274 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
6276 break;
6278 case 0xba:
6280 sdwCyclesRemaining -= 16;
6281 while ((sdwCyclesRemaining > 0) && (cpu.z80B))
6283 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
6284 while (psIoRead->lowIoAddr != 0xffff)
6286 if ((cpu.z80B >= psIoRead->lowIoAddr) && (cpu.z80B <= psIoRead->highIoAddr))
6288 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6289 bTemp = psIoRead->IOCall(cpu.z80B, psIoRead);
6290 psIoRead = NULL;
6291 break;
6293 ++psIoRead;
6296 if (psIoRead)
6298 bTemp = 0xff; /* Unclaimed I/O read */
6301 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
6302 while (psMemWrite->lowAddr != 0xffffffff)
6304 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
6306 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6307 if (psMemWrite->memoryCall)
6309 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
6311 else
6313 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
6315 psMemWrite = NULL;
6316 break;
6318 ++psMemWrite;
6321 if (psMemWrite)
6323 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
6326 cpu.z80HL--;
6327 cpu.z80HL &= 0xffff;
6328 sdwCyclesRemaining -= 16;
6329 cpu.z80B--;
6331 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
6332 cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));
6333 if (cpu.z80B)
6335 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
6336 pbPC -= 2;
6338 break;
6340 case 0xbb:
6342 sdwCyclesRemaining -= 16;
6343 while ((sdwCyclesRemaining > 0) && (cpu.z80B))
6345 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
6346 while (psMemRead->lowAddr != 0xffffffff)
6348 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
6350 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6351 if (psMemRead->memoryCall)
6353 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
6355 else
6357 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
6359 psMemRead = NULL;
6360 break;
6362 ++psMemRead;
6365 if (psMemRead)
6367 bTemp = cpu.z80Base[cpu.z80HL];
6370 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
6371 while (psIoWrite->lowIoAddr != 0xffff)
6373 if ((cpu.z80BC >= psIoWrite->lowIoAddr) && (cpu.z80BC <= psIoWrite->highIoAddr))
6375 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6376 psIoWrite->IOCall(cpu.z80BC, bTemp, psIoWrite);
6377 psIoWrite = NULL;
6378 break;
6380 ++psIoWrite;
6383 cpu.z80HL--;
6384 cpu.z80HL &= 0xffff;
6385 sdwCyclesRemaining -= 16;
6386 cpu.z80B--;
6388 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
6389 cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));
6390 if (cpu.z80B)
6392 cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;
6394 break;
6396 case 0xbc:
6398 InvalidInstruction(2);
6399 break;
6401 case 0xbd:
6403 InvalidInstruction(2);
6404 break;
6406 case 0xbe:
6408 InvalidInstruction(2);
6409 break;
6411 case 0xbf:
6413 InvalidInstruction(2);
6414 break;
6416 case 0xc0:
6418 InvalidInstruction(2);
6419 break;
6421 case 0xc1:
6423 InvalidInstruction(2);
6424 break;
6426 case 0xc2:
6428 InvalidInstruction(2);
6429 break;
6431 case 0xc3:
6433 InvalidInstruction(2);
6434 break;
6436 case 0xc4:
6438 InvalidInstruction(2);
6439 break;
6441 case 0xc5:
6443 InvalidInstruction(2);
6444 break;
6446 case 0xc6:
6448 InvalidInstruction(2);
6449 break;
6451 case 0xc7:
6453 InvalidInstruction(2);
6454 break;
6456 case 0xc8:
6458 InvalidInstruction(2);
6459 break;
6461 case 0xc9:
6463 InvalidInstruction(2);
6464 break;
6466 case 0xca:
6468 InvalidInstruction(2);
6469 break;
6471 case 0xcb:
6473 InvalidInstruction(2);
6474 break;
6476 case 0xcc:
6478 InvalidInstruction(2);
6479 break;
6481 case 0xcd:
6483 InvalidInstruction(2);
6484 break;
6486 case 0xce:
6488 InvalidInstruction(2);
6489 break;
6491 case 0xcf:
6493 InvalidInstruction(2);
6494 break;
6496 case 0xd0:
6498 InvalidInstruction(2);
6499 break;
6501 case 0xd1:
6503 InvalidInstruction(2);
6504 break;
6506 case 0xd2:
6508 InvalidInstruction(2);
6509 break;
6511 case 0xd3:
6513 InvalidInstruction(2);
6514 break;
6516 case 0xd4:
6518 InvalidInstruction(2);
6519 break;
6521 case 0xd5:
6523 InvalidInstruction(2);
6524 break;
6526 case 0xd6:
6528 InvalidInstruction(2);
6529 break;
6531 case 0xd7:
6533 InvalidInstruction(2);
6534 break;
6536 case 0xd8:
6538 InvalidInstruction(2);
6539 break;
6541 case 0xd9:
6543 InvalidInstruction(2);
6544 break;
6546 case 0xda:
6548 InvalidInstruction(2);
6549 break;
6551 case 0xdb:
6553 InvalidInstruction(2);
6554 break;
6556 case 0xdc:
6558 InvalidInstruction(2);
6559 break;
6561 case 0xdd:
6563 InvalidInstruction(2);
6564 break;
6566 case 0xde:
6568 InvalidInstruction(2);
6569 break;
6571 case 0xdf:
6573 InvalidInstruction(2);
6574 break;
6576 case 0xe0:
6578 InvalidInstruction(2);
6579 break;
6581 case 0xe1:
6583 InvalidInstruction(2);
6584 break;
6586 case 0xe2:
6588 InvalidInstruction(2);
6589 break;
6591 case 0xe3:
6593 InvalidInstruction(2);
6594 break;
6596 case 0xe4:
6598 InvalidInstruction(2);
6599 break;
6601 case 0xe5:
6603 InvalidInstruction(2);
6604 break;
6606 case 0xe6:
6608 InvalidInstruction(2);
6609 break;
6611 case 0xe7:
6613 InvalidInstruction(2);
6614 break;
6616 case 0xe8:
6618 InvalidInstruction(2);
6619 break;
6621 case 0xe9:
6623 InvalidInstruction(2);
6624 break;
6626 case 0xea:
6628 InvalidInstruction(2);
6629 break;
6631 case 0xeb:
6633 InvalidInstruction(2);
6634 break;
6636 case 0xec:
6638 InvalidInstruction(2);
6639 break;
6641 case 0xed:
6643 InvalidInstruction(2);
6644 break;
6646 case 0xee:
6648 InvalidInstruction(2);
6649 break;
6651 case 0xef:
6653 InvalidInstruction(2);
6654 break;
6656 case 0xf0:
6658 InvalidInstruction(2);
6659 break;
6661 case 0xf1:
6663 InvalidInstruction(2);
6664 break;
6666 case 0xf2:
6668 InvalidInstruction(2);
6669 break;
6671 case 0xf3:
6673 InvalidInstruction(2);
6674 break;
6676 case 0xf4:
6678 InvalidInstruction(2);
6679 break;
6681 case 0xf5:
6683 InvalidInstruction(2);
6684 break;
6686 case 0xf6:
6688 InvalidInstruction(2);
6689 break;
6691 case 0xf7:
6693 InvalidInstruction(2);
6694 break;
6696 case 0xf8:
6698 InvalidInstruction(2);
6699 break;
6701 case 0xf9:
6703 InvalidInstruction(2);
6704 break;
6706 case 0xfa:
6708 InvalidInstruction(2);
6709 break;
6711 case 0xfb:
6713 InvalidInstruction(2);
6714 break;
6716 case 0xfc:
6718 InvalidInstruction(2);
6719 break;
6721 case 0xfd:
6723 InvalidInstruction(2);
6724 break;
6726 case 0xfe:
6728 InvalidInstruction(2);
6729 break;
6731 case 0xff:
6733 InvalidInstruction(2);
6734 break;
6739 void DDHandler(void)
6741 switch (*pbPC++)
6743 case 0x00:
6745 InvalidInstruction(2);
6746 break;
6748 case 0x01:
6750 InvalidInstruction(2);
6751 break;
6753 case 0x02:
6755 InvalidInstruction(2);
6756 break;
6758 case 0x03:
6760 InvalidInstruction(2);
6761 break;
6763 case 0x04:
6765 InvalidInstruction(2);
6766 break;
6768 case 0x05:
6770 InvalidInstruction(2);
6771 break;
6773 case 0x06:
6775 InvalidInstruction(2);
6776 break;
6778 case 0x07:
6780 InvalidInstruction(2);
6781 break;
6783 case 0x08:
6785 InvalidInstruction(2);
6786 break;
6788 case 0x09:
6790 sdwCyclesRemaining -= 15;
6791 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
6792 dwTemp = cpu.z80IX + cpu.z80BC;
6793 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80IX ^ dwTemp ^ cpu.z80BC) >> 8) & Z80_FLAG_HALF_CARRY);
6794 cpu.z80IX = dwTemp & 0xffff;
6795 break;
6797 case 0x0a:
6799 InvalidInstruction(2);
6800 break;
6802 case 0x0b:
6804 InvalidInstruction(2);
6805 break;
6807 case 0x0c:
6809 InvalidInstruction(2);
6810 break;
6812 case 0x0d:
6814 InvalidInstruction(2);
6815 break;
6817 case 0x0e:
6819 InvalidInstruction(2);
6820 break;
6822 case 0x0f:
6824 InvalidInstruction(2);
6825 break;
6827 case 0x10:
6829 InvalidInstruction(2);
6830 break;
6832 case 0x11:
6834 InvalidInstruction(2);
6835 break;
6837 case 0x12:
6839 InvalidInstruction(2);
6840 break;
6842 case 0x13:
6844 InvalidInstruction(2);
6845 break;
6847 case 0x14:
6849 InvalidInstruction(2);
6850 break;
6852 case 0x15:
6854 InvalidInstruction(2);
6855 break;
6857 case 0x16:
6859 InvalidInstruction(2);
6860 break;
6862 case 0x17:
6864 InvalidInstruction(2);
6865 break;
6867 case 0x18:
6869 InvalidInstruction(2);
6870 break;
6872 case 0x19:
6874 sdwCyclesRemaining -= 15;
6875 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
6876 dwTemp = cpu.z80IX + cpu.z80DE;
6877 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80IX ^ dwTemp ^ cpu.z80DE) >> 8) & Z80_FLAG_HALF_CARRY);
6878 cpu.z80IX = dwTemp & 0xffff;
6879 break;
6881 case 0x1a:
6883 InvalidInstruction(2);
6884 break;
6886 case 0x1b:
6888 InvalidInstruction(2);
6889 break;
6891 case 0x1c:
6893 InvalidInstruction(2);
6894 break;
6896 case 0x1d:
6898 InvalidInstruction(2);
6899 break;
6901 case 0x1e:
6903 InvalidInstruction(2);
6904 break;
6906 case 0x1f:
6908 InvalidInstruction(2);
6909 break;
6911 case 0x20:
6913 InvalidInstruction(2);
6914 break;
6916 case 0x21:
6918 sdwCyclesRemaining -= 14;
6919 cpu.z80IX = *pbPC++;
6920 cpu.z80IX |= ((UINT32) *pbPC++ << 8);
6921 break;
6923 case 0x22:
6925 sdwCyclesRemaining -= 20;
6926 dwAddr = *pbPC++;
6927 dwAddr |= ((UINT32) *pbPC++ << 8);
6928 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
6929 while (psMemWrite->lowAddr != 0xffffffff)
6931 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
6933 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
6934 if (psMemWrite->memoryCall)
6936 psMemWrite->memoryCall(dwAddr, (cpu.z80IX & 0xff), psMemWrite);
6937 psMemWrite->memoryCall(dwAddr + 1, (cpu.z80IX >> 8), psMemWrite);
6939 else
6941 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = cpu.z80IX;
6942 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr) + 1) = cpu.z80IX >> 8;
6944 psMemWrite = NULL;
6945 break;
6947 ++psMemWrite;
6950 if (psMemWrite)
6952 cpu.z80Base[dwAddr] = (UINT8) cpu.z80IX;
6953 cpu.z80Base[dwAddr + 1] = (UINT8) ((UINT32) cpu.z80IX >> 8);
6956 break;
6958 case 0x23:
6960 sdwCyclesRemaining -= 10;
6961 cpu.z80IX++;
6962 cpu.z80IX &= 0xffff;
6963 break;
6965 case 0x24:
6967 sdwCyclesRemaining -= 9;
6968 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
6969 cpu.z80F |= bPostIncFlags[cpu.z80XH++];
6970 break;
6972 case 0x25:
6974 sdwCyclesRemaining -= 9;
6975 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
6976 cpu.z80F |= bPostDecFlags[cpu.z80XH--];
6977 break;
6979 case 0x26:
6981 sdwCyclesRemaining -= 9;
6982 cpu.z80XH = *pbPC++;
6983 break;
6985 case 0x27:
6987 InvalidInstruction(2);
6988 break;
6990 case 0x28:
6992 InvalidInstruction(2);
6993 break;
6995 case 0x29:
6997 sdwCyclesRemaining -= 15;
6998 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
6999 dwTemp = cpu.z80IX + cpu.z80IX;
7000 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80IX ^ dwTemp ^ cpu.z80HL) >> 8) & Z80_FLAG_HALF_CARRY);
7001 cpu.z80IX = dwTemp & 0xffff;
7002 break;
7004 case 0x2a:
7006 sdwCyclesRemaining -= 20;
7007 dwAddr = *pbPC++;
7008 dwAddr |= ((UINT32) *pbPC++ << 8);
7009 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7010 while (psMemRead->lowAddr != 0xffffffff)
7012 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
7014 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7015 if (psMemRead->memoryCall)
7017 cpu.z80IX = psMemRead->memoryCall(dwAddr, psMemRead);
7018 cpu.z80IX |= (UINT32) ((UINT32) psMemRead->memoryCall(dwAddr + 1, psMemRead) << 8);
7020 else
7022 cpu.z80IX = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
7023 cpu.z80IX |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr + 1)) << 8);
7025 psMemRead = NULL;
7026 break;
7028 ++psMemRead;
7031 if (psMemRead)
7033 cpu.z80IX = cpu.z80Base[dwAddr];
7034 cpu.z80IX |= (UINT32) ((UINT32) cpu.z80Base[dwAddr + 1] << 8);
7037 break;
7039 case 0x2b:
7041 sdwCyclesRemaining -= 10;
7042 cpu.z80IX--;
7043 cpu.z80IX &= 0xffff;
7044 break;
7046 case 0x2c:
7048 sdwCyclesRemaining -= 9;
7049 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
7050 cpu.z80F |= bPostIncFlags[cpu.z80XL++];
7051 break;
7053 case 0x2d:
7055 sdwCyclesRemaining -= 9;
7056 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
7057 cpu.z80F |= bPostDecFlags[cpu.z80XL--];
7058 break;
7060 case 0x2e:
7062 sdwCyclesRemaining -= 9;
7063 cpu.z80XL = *pbPC++;
7064 break;
7066 case 0x2f:
7068 InvalidInstruction(2);
7069 break;
7071 case 0x30:
7073 InvalidInstruction(2);
7074 break;
7076 case 0x31:
7078 InvalidInstruction(2);
7079 break;
7081 case 0x32:
7083 InvalidInstruction(2);
7084 break;
7086 case 0x33:
7088 InvalidInstruction(2);
7089 break;
7091 case 0x34:
7093 sdwCyclesRemaining -= 23;
7094 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
7095 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
7096 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7097 while (psMemRead->lowAddr != 0xffffffff)
7099 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
7101 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7102 if (psMemRead->memoryCall)
7104 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
7106 else
7108 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
7110 psMemRead = NULL;
7111 break;
7113 ++psMemRead;
7116 if (psMemRead)
7118 bTemp = cpu.z80Base[dwAddr];
7121 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
7122 cpu.z80F |= bPostIncFlags[bTemp++];
7123 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7124 while (psMemWrite->lowAddr != 0xffffffff)
7126 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
7128 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7129 if (psMemWrite->memoryCall)
7131 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
7133 else
7135 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
7137 psMemWrite = NULL;
7138 break;
7140 ++psMemWrite;
7143 if (psMemWrite)
7145 cpu.z80Base[dwAddr] = (UINT8) bTemp;
7148 break;
7150 case 0x35:
7152 sdwCyclesRemaining -= 23;
7153 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
7154 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
7155 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7156 while (psMemRead->lowAddr != 0xffffffff)
7158 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
7160 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7161 if (psMemRead->memoryCall)
7163 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
7165 else
7167 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
7169 psMemRead = NULL;
7170 break;
7172 ++psMemRead;
7175 if (psMemRead)
7177 bTemp = cpu.z80Base[dwAddr];
7180 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
7181 cpu.z80F |= bPostDecFlags[bTemp--];
7182 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7183 while (psMemWrite->lowAddr != 0xffffffff)
7185 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
7187 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7188 if (psMemWrite->memoryCall)
7190 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
7192 else
7194 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
7196 psMemWrite = NULL;
7197 break;
7199 ++psMemWrite;
7202 if (psMemWrite)
7204 cpu.z80Base[dwAddr] = (UINT8) bTemp;
7207 break;
7209 case 0x36:
7211 sdwCyclesRemaining -= 19;
7212 sdwAddr = (INT8) *pbPC++; // Get the offset
7213 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7214 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7215 while (psMemWrite->lowAddr != 0xffffffff)
7217 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
7219 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7220 if (psMemWrite->memoryCall)
7222 psMemWrite->memoryCall(sdwAddr, *pbPC++, psMemWrite);
7224 else
7226 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = *pbPC++;
7228 psMemWrite = NULL;
7229 break;
7231 ++psMemWrite;
7234 if (psMemWrite)
7236 cpu.z80Base[sdwAddr] = (UINT8) *pbPC++;
7239 break;
7241 case 0x37:
7243 InvalidInstruction(2);
7244 break;
7246 case 0x38:
7248 InvalidInstruction(2);
7249 break;
7251 case 0x39:
7253 sdwCyclesRemaining -= 15;
7254 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
7255 dwTemp = cpu.z80IX + cpu.z80sp;
7256 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80IX ^ dwTemp ^ cpu.z80sp) >> 8) & Z80_FLAG_HALF_CARRY);
7257 cpu.z80IX = dwTemp & 0xffff;
7258 break;
7260 case 0x3a:
7262 InvalidInstruction(2);
7263 break;
7265 case 0x3b:
7267 InvalidInstruction(2);
7268 break;
7270 case 0x3c:
7272 InvalidInstruction(2);
7273 break;
7275 case 0x3d:
7277 InvalidInstruction(2);
7278 break;
7280 case 0x3e:
7282 InvalidInstruction(2);
7283 break;
7285 case 0x3f:
7287 InvalidInstruction(2);
7288 break;
7290 case 0x40:
7292 InvalidInstruction(2);
7293 break;
7295 case 0x41:
7297 InvalidInstruction(2);
7298 break;
7300 case 0x42:
7302 InvalidInstruction(2);
7303 break;
7305 case 0x43:
7307 InvalidInstruction(2);
7308 break;
7310 case 0x44:
7312 sdwCyclesRemaining -= 9;
7313 cpu.z80B = cpu.z80XH;
7314 break;
7316 case 0x45:
7318 sdwCyclesRemaining -= 9;
7319 cpu.z80B = cpu.z80XL;
7320 break;
7322 case 0x46:
7324 sdwCyclesRemaining -= 19;
7325 sdwAddr = (INT8) *pbPC++; // Get the offset
7326 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7327 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7328 while (psMemRead->lowAddr != 0xffffffff)
7330 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
7332 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7333 if (psMemRead->memoryCall)
7335 cpu.z80B = psMemRead->memoryCall(sdwAddr, psMemRead);
7337 else
7339 cpu.z80B = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
7341 psMemRead = NULL;
7342 break;
7344 ++psMemRead;
7347 if (psMemRead)
7349 cpu.z80B = cpu.z80Base[sdwAddr];
7352 break;
7354 case 0x47:
7356 InvalidInstruction(2);
7357 break;
7359 case 0x48:
7361 InvalidInstruction(2);
7362 break;
7364 case 0x49:
7366 InvalidInstruction(2);
7367 break;
7369 case 0x4a:
7371 InvalidInstruction(2);
7372 break;
7374 case 0x4b:
7376 InvalidInstruction(2);
7377 break;
7379 case 0x4c:
7381 sdwCyclesRemaining -= 9;
7382 cpu.z80C = cpu.z80XH;
7383 break;
7385 case 0x4d:
7387 sdwCyclesRemaining -= 9;
7388 cpu.z80C = cpu.z80XL;
7389 break;
7391 case 0x4e:
7393 sdwCyclesRemaining -= 19;
7394 sdwAddr = (INT8) *pbPC++; // Get the offset
7395 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7396 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7397 while (psMemRead->lowAddr != 0xffffffff)
7399 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
7401 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7402 if (psMemRead->memoryCall)
7404 cpu.z80C = psMemRead->memoryCall(sdwAddr, psMemRead);
7406 else
7408 cpu.z80C = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
7410 psMemRead = NULL;
7411 break;
7413 ++psMemRead;
7416 if (psMemRead)
7418 cpu.z80C = cpu.z80Base[sdwAddr];
7421 break;
7423 case 0x4f:
7425 InvalidInstruction(2);
7426 break;
7428 case 0x50:
7430 InvalidInstruction(2);
7431 break;
7433 case 0x51:
7435 InvalidInstruction(2);
7436 break;
7438 case 0x52:
7440 InvalidInstruction(2);
7441 break;
7443 case 0x53:
7445 InvalidInstruction(2);
7446 break;
7448 case 0x54:
7450 sdwCyclesRemaining -= 9;
7451 cpu.z80D = cpu.z80XH;
7452 break;
7454 case 0x55:
7456 sdwCyclesRemaining -= 9;
7457 cpu.z80D = cpu.z80XL;
7458 break;
7460 case 0x56:
7462 sdwCyclesRemaining -= 19;
7463 sdwAddr = (INT8) *pbPC++; // Get the offset
7464 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7465 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7466 while (psMemRead->lowAddr != 0xffffffff)
7468 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
7470 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7471 if (psMemRead->memoryCall)
7473 cpu.z80D = psMemRead->memoryCall(sdwAddr, psMemRead);
7475 else
7477 cpu.z80D = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
7479 psMemRead = NULL;
7480 break;
7482 ++psMemRead;
7485 if (psMemRead)
7487 cpu.z80D = cpu.z80Base[sdwAddr];
7490 break;
7492 case 0x57:
7494 InvalidInstruction(2);
7495 break;
7497 case 0x58:
7499 InvalidInstruction(2);
7500 break;
7502 case 0x59:
7504 InvalidInstruction(2);
7505 break;
7507 case 0x5a:
7509 InvalidInstruction(2);
7510 break;
7512 case 0x5b:
7514 InvalidInstruction(2);
7515 break;
7517 case 0x5c:
7519 sdwCyclesRemaining -= 9;
7520 cpu.z80E = cpu.z80XH;
7521 break;
7523 case 0x5d:
7525 sdwCyclesRemaining -= 9;
7526 cpu.z80E = cpu.z80XL;
7527 break;
7529 case 0x5e:
7531 sdwCyclesRemaining -= 19;
7532 sdwAddr = (INT8) *pbPC++; // Get the offset
7533 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7534 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7535 while (psMemRead->lowAddr != 0xffffffff)
7537 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
7539 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7540 if (psMemRead->memoryCall)
7542 cpu.z80E = psMemRead->memoryCall(sdwAddr, psMemRead);
7544 else
7546 cpu.z80E = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
7548 psMemRead = NULL;
7549 break;
7551 ++psMemRead;
7554 if (psMemRead)
7556 cpu.z80E = cpu.z80Base[sdwAddr];
7559 break;
7561 case 0x5f:
7563 InvalidInstruction(2);
7564 break;
7566 case 0x60:
7568 sdwCyclesRemaining -= 9;
7569 cpu.z80XH = cpu.z80B;
7570 break;
7572 case 0x61:
7574 sdwCyclesRemaining -= 9;
7575 cpu.z80XH = cpu.z80C;
7576 break;
7578 case 0x62:
7580 sdwCyclesRemaining -= 9;
7581 cpu.z80XH = cpu.z80D;
7582 break;
7584 case 0x63:
7586 sdwCyclesRemaining -= 9;
7587 cpu.z80XH = cpu.z80E;
7588 break;
7590 case 0x64:
7592 sdwCyclesRemaining -= 9;
7593 break;
7595 case 0x65:
7597 sdwCyclesRemaining -= 9;
7598 cpu.z80XH = cpu.z80XL;
7599 break;
7601 case 0x66:
7603 sdwCyclesRemaining -= 19;
7604 sdwAddr = (INT8) *pbPC++; // Get the offset
7605 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7606 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7607 while (psMemRead->lowAddr != 0xffffffff)
7609 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
7611 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7612 if (psMemRead->memoryCall)
7614 cpu.z80H = psMemRead->memoryCall(sdwAddr, psMemRead);
7616 else
7618 cpu.z80H = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
7620 psMemRead = NULL;
7621 break;
7623 ++psMemRead;
7626 if (psMemRead)
7628 cpu.z80H = cpu.z80Base[sdwAddr];
7631 break;
7633 case 0x67:
7635 sdwCyclesRemaining -= 9;
7636 cpu.z80XH = cpu.z80A;
7637 break;
7639 case 0x68:
7641 sdwCyclesRemaining -= 9;
7642 cpu.z80XL = cpu.z80B;
7643 break;
7645 case 0x69:
7647 sdwCyclesRemaining -= 9;
7648 cpu.z80XL = cpu.z80C;
7649 break;
7651 case 0x6a:
7653 sdwCyclesRemaining -= 9;
7654 cpu.z80XL = cpu.z80D;
7655 break;
7657 case 0x6b:
7659 sdwCyclesRemaining -= 9;
7660 cpu.z80XL = cpu.z80E;
7661 break;
7663 case 0x6c:
7665 sdwCyclesRemaining -= 9;
7666 cpu.z80XL = cpu.z80XH;
7667 break;
7669 case 0x6d:
7671 sdwCyclesRemaining -= 9;
7672 break;
7674 case 0x6e:
7676 sdwCyclesRemaining -= 19;
7677 sdwAddr = (INT8) *pbPC++; // Get the offset
7678 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7679 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7680 while (psMemRead->lowAddr != 0xffffffff)
7682 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
7684 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7685 if (psMemRead->memoryCall)
7687 cpu.z80L = psMemRead->memoryCall(sdwAddr, psMemRead);
7689 else
7691 cpu.z80L = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
7693 psMemRead = NULL;
7694 break;
7696 ++psMemRead;
7699 if (psMemRead)
7701 cpu.z80L = cpu.z80Base[sdwAddr];
7704 break;
7706 case 0x6f:
7708 sdwCyclesRemaining -= 9;
7709 cpu.z80XL = cpu.z80A;
7710 break;
7712 case 0x70:
7714 sdwCyclesRemaining -= 19;
7715 sdwAddr = (INT8) *pbPC++; // Get the offset
7716 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7717 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7718 while (psMemWrite->lowAddr != 0xffffffff)
7720 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
7722 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7723 if (psMemWrite->memoryCall)
7725 psMemWrite->memoryCall(sdwAddr, cpu.z80B, psMemWrite);
7727 else
7729 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80B;
7731 psMemWrite = NULL;
7732 break;
7734 ++psMemWrite;
7737 if (psMemWrite)
7739 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80B;
7742 break;
7744 case 0x71:
7746 sdwCyclesRemaining -= 19;
7747 sdwAddr = (INT8) *pbPC++; // Get the offset
7748 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7749 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7750 while (psMemWrite->lowAddr != 0xffffffff)
7752 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
7754 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7755 if (psMemWrite->memoryCall)
7757 psMemWrite->memoryCall(sdwAddr, cpu.z80C, psMemWrite);
7759 else
7761 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80C;
7763 psMemWrite = NULL;
7764 break;
7766 ++psMemWrite;
7769 if (psMemWrite)
7771 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80C;
7774 break;
7776 case 0x72:
7778 sdwCyclesRemaining -= 19;
7779 sdwAddr = (INT8) *pbPC++; // Get the offset
7780 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7781 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7782 while (psMemWrite->lowAddr != 0xffffffff)
7784 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
7786 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7787 if (psMemWrite->memoryCall)
7789 psMemWrite->memoryCall(sdwAddr, cpu.z80D, psMemWrite);
7791 else
7793 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80D;
7795 psMemWrite = NULL;
7796 break;
7798 ++psMemWrite;
7801 if (psMemWrite)
7803 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80D;
7806 break;
7808 case 0x73:
7810 sdwCyclesRemaining -= 19;
7811 sdwAddr = (INT8) *pbPC++; // Get the offset
7812 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7813 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7814 while (psMemWrite->lowAddr != 0xffffffff)
7816 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
7818 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7819 if (psMemWrite->memoryCall)
7821 psMemWrite->memoryCall(sdwAddr, cpu.z80E, psMemWrite);
7823 else
7825 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80E;
7827 psMemWrite = NULL;
7828 break;
7830 ++psMemWrite;
7833 if (psMemWrite)
7835 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80E;
7838 break;
7840 case 0x74:
7842 sdwCyclesRemaining -= 19;
7843 sdwAddr = (INT8) *pbPC++; // Get the offset
7844 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7845 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7846 while (psMemWrite->lowAddr != 0xffffffff)
7848 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
7850 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7851 if (psMemWrite->memoryCall)
7853 psMemWrite->memoryCall(sdwAddr, cpu.z80H, psMemWrite);
7855 else
7857 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80H;
7859 psMemWrite = NULL;
7860 break;
7862 ++psMemWrite;
7865 if (psMemWrite)
7867 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80H;
7870 break;
7872 case 0x75:
7874 sdwCyclesRemaining -= 19;
7875 sdwAddr = (INT8) *pbPC++; // Get the offset
7876 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7877 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7878 while (psMemWrite->lowAddr != 0xffffffff)
7880 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
7882 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7883 if (psMemWrite->memoryCall)
7885 psMemWrite->memoryCall(sdwAddr, cpu.z80L, psMemWrite);
7887 else
7889 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80L;
7891 psMemWrite = NULL;
7892 break;
7894 ++psMemWrite;
7897 if (psMemWrite)
7899 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80L;
7902 break;
7904 case 0x76:
7906 sdwCyclesRemaining -= 19;
7907 InvalidInstruction(2);
7908 break;
7910 case 0x77:
7912 sdwCyclesRemaining -= 19;
7913 sdwAddr = (INT8) *pbPC++; // Get the offset
7914 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7915 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
7916 while (psMemWrite->lowAddr != 0xffffffff)
7918 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
7920 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7921 if (psMemWrite->memoryCall)
7923 psMemWrite->memoryCall(sdwAddr, cpu.z80A, psMemWrite);
7925 else
7927 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80A;
7929 psMemWrite = NULL;
7930 break;
7932 ++psMemWrite;
7935 if (psMemWrite)
7937 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80A;
7940 break;
7942 case 0x78:
7944 InvalidInstruction(2);
7945 break;
7947 case 0x79:
7949 InvalidInstruction(2);
7950 break;
7952 case 0x7a:
7954 InvalidInstruction(2);
7955 break;
7957 case 0x7b:
7959 InvalidInstruction(2);
7960 break;
7962 case 0x7c:
7964 sdwCyclesRemaining -= 9;
7965 cpu.z80A = cpu.z80XH;
7966 break;
7968 case 0x7d:
7970 sdwCyclesRemaining -= 9;
7971 cpu.z80A = cpu.z80XL;
7972 break;
7974 case 0x7e:
7976 sdwCyclesRemaining -= 19;
7977 sdwAddr = (INT8) *pbPC++; // Get the offset
7978 sdwAddr = ((INT32) cpu.z80IX + sdwAddr) & 0xffff;
7979 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
7980 while (psMemRead->lowAddr != 0xffffffff)
7982 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
7984 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
7985 if (psMemRead->memoryCall)
7987 cpu.z80A = psMemRead->memoryCall(sdwAddr, psMemRead);
7989 else
7991 cpu.z80A = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
7993 psMemRead = NULL;
7994 break;
7996 ++psMemRead;
7999 if (psMemRead)
8001 cpu.z80A = cpu.z80Base[sdwAddr];
8004 break;
8006 case 0x7f:
8008 InvalidInstruction(2);
8009 break;
8011 case 0x80:
8013 InvalidInstruction(2);
8014 break;
8016 case 0x81:
8018 InvalidInstruction(2);
8019 break;
8021 case 0x82:
8023 InvalidInstruction(2);
8024 break;
8026 case 0x83:
8028 InvalidInstruction(2);
8029 break;
8031 case 0x84:
8033 sdwCyclesRemaining -= 9;
8034 bTemp2 = cpu.z80A + cpu.z80XH;
8035 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8036 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8037 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80XH];
8038 InvalidInstruction(2);
8039 break;
8041 case 0x85:
8043 sdwCyclesRemaining -= 9;
8044 bTemp2 = cpu.z80A + cpu.z80XL;
8045 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8046 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8047 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80XL];
8048 InvalidInstruction(2);
8049 break;
8051 case 0x86:
8053 sdwCyclesRemaining -= 19;
8054 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
8055 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
8056 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8057 while (psMemRead->lowAddr != 0xffffffff)
8059 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
8061 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8062 if (psMemRead->memoryCall)
8064 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
8066 else
8068 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
8070 psMemRead = NULL;
8071 break;
8073 ++psMemRead;
8076 if (psMemRead)
8078 bTemp = cpu.z80Base[dwAddr];
8081 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8082 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8083 pbAddAdcTable[((UINT32) cpu.z80A << 8) | bTemp];
8084 cpu.z80A += bTemp;
8085 break;
8087 case 0x87:
8089 InvalidInstruction(2);
8090 break;
8092 case 0x88:
8094 InvalidInstruction(2);
8095 break;
8097 case 0x89:
8099 InvalidInstruction(2);
8100 break;
8102 case 0x8a:
8104 InvalidInstruction(2);
8105 break;
8107 case 0x8b:
8109 InvalidInstruction(2);
8110 break;
8112 case 0x8c:
8114 sdwCyclesRemaining -= 9;
8115 bTemp2 = cpu.z80A + cpu.z80XH + (cpu.z80F & Z80_FLAG_CARRY);
8116 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8117 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8118 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80XH | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
8119 InvalidInstruction(2);
8120 break;
8122 case 0x8d:
8124 sdwCyclesRemaining -= 9;
8125 bTemp2 = cpu.z80A + cpu.z80XL + (cpu.z80F & Z80_FLAG_CARRY);
8126 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8127 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8128 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80XL | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
8129 InvalidInstruction(2);
8130 break;
8132 case 0x8e:
8134 sdwCyclesRemaining -= 19;
8135 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
8136 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
8137 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8138 while (psMemRead->lowAddr != 0xffffffff)
8140 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
8142 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8143 if (psMemRead->memoryCall)
8145 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
8147 else
8149 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
8151 psMemRead = NULL;
8152 break;
8154 ++psMemRead;
8157 if (psMemRead)
8159 bTemp = cpu.z80Base[dwAddr];
8162 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY);
8163 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8164 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8165 pbAddAdcTable[((UINT32) cpu.z80A << 8) | bTemp | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
8166 cpu.z80A += bTemp + bTemp2;
8167 break;
8169 case 0x8f:
8171 InvalidInstruction(2);
8172 break;
8174 case 0x90:
8176 InvalidInstruction(2);
8177 break;
8179 case 0x91:
8181 InvalidInstruction(2);
8182 break;
8184 case 0x92:
8186 InvalidInstruction(2);
8187 break;
8189 case 0x93:
8191 InvalidInstruction(2);
8192 break;
8194 case 0x94:
8196 sdwCyclesRemaining -= 9;
8197 bTemp2 = cpu.z80A - cpu.z80XH;
8198 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8199 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8200 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80XH];
8201 InvalidInstruction(2);
8202 break;
8204 case 0x95:
8206 sdwCyclesRemaining -= 9;
8207 bTemp2 = cpu.z80A - cpu.z80XL;
8208 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8209 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8210 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80XL];
8211 InvalidInstruction(2);
8212 break;
8214 case 0x96:
8216 sdwCyclesRemaining -= 19;
8217 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
8218 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
8219 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8220 while (psMemRead->lowAddr != 0xffffffff)
8222 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
8224 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8225 if (psMemRead->memoryCall)
8227 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
8229 else
8231 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
8233 psMemRead = NULL;
8234 break;
8236 ++psMemRead;
8239 if (psMemRead)
8241 bTemp = cpu.z80Base[dwAddr];
8244 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8245 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8246 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp];
8247 cpu.z80A -= bTemp;
8248 break;
8250 case 0x97:
8252 InvalidInstruction(2);
8253 break;
8255 case 0x98:
8257 InvalidInstruction(2);
8258 break;
8260 case 0x99:
8262 InvalidInstruction(2);
8263 break;
8265 case 0x9a:
8267 InvalidInstruction(2);
8268 break;
8270 case 0x9b:
8272 InvalidInstruction(2);
8273 break;
8275 case 0x9c:
8277 sdwCyclesRemaining -= 9;
8278 bTemp2 = cpu.z80A - cpu.z80XH - (cpu.z80F & Z80_FLAG_CARRY);
8279 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8280 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8281 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80XH | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
8282 InvalidInstruction(2);
8283 break;
8285 case 0x9d:
8287 sdwCyclesRemaining -= 9;
8288 bTemp2 = cpu.z80A - cpu.z80XL - (cpu.z80F & Z80_FLAG_CARRY);
8289 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8290 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8291 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80XL | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
8292 InvalidInstruction(2);
8293 break;
8295 case 0x9e:
8297 sdwCyclesRemaining -= 19;
8298 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
8299 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
8300 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8301 while (psMemRead->lowAddr != 0xffffffff)
8303 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
8305 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8306 if (psMemRead->memoryCall)
8308 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
8310 else
8312 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
8314 psMemRead = NULL;
8315 break;
8317 ++psMemRead;
8320 if (psMemRead)
8322 bTemp = cpu.z80Base[dwAddr];
8325 bTemp2 = cpu.z80A;
8326 cpu.z80A = cpu.z80A - bTemp - (cpu.z80F & Z80_FLAG_CARRY);
8327 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8328 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8329 pbSubSbcTable[((UINT32) bTemp2 << 8) | bTemp | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
8330 break;
8332 case 0x9f:
8334 InvalidInstruction(2);
8335 break;
8337 case 0xa0:
8339 InvalidInstruction(2);
8340 break;
8342 case 0xa1:
8344 InvalidInstruction(2);
8345 break;
8347 case 0xa2:
8349 InvalidInstruction(2);
8350 break;
8352 case 0xa3:
8354 InvalidInstruction(2);
8355 break;
8357 case 0xa4:
8359 sdwCyclesRemaining -= 9;
8360 cpu.z80A &= cpu.z80XH;
8361 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8362 cpu.z80F |= bPostANDFlags[cpu.z80A];
8364 InvalidInstruction(2);
8365 break;
8367 case 0xa5:
8369 sdwCyclesRemaining -= 9;
8370 cpu.z80A &= cpu.z80XL;
8371 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8372 cpu.z80F |= bPostANDFlags[cpu.z80A];
8374 InvalidInstruction(2);
8375 break;
8377 case 0xa6:
8379 sdwCyclesRemaining -= 19;
8380 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
8381 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
8382 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8383 while (psMemRead->lowAddr != 0xffffffff)
8385 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
8387 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8388 if (psMemRead->memoryCall)
8390 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
8392 else
8394 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
8396 psMemRead = NULL;
8397 break;
8399 ++psMemRead;
8402 if (psMemRead)
8404 bTemp = cpu.z80Base[dwAddr];
8407 cpu.z80A &= bTemp;
8408 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8409 cpu.z80F |= bPostANDFlags[cpu.z80A];
8411 break;
8413 case 0xa7:
8415 InvalidInstruction(2);
8416 break;
8418 case 0xa8:
8420 InvalidInstruction(2);
8421 break;
8423 case 0xa9:
8425 InvalidInstruction(2);
8426 break;
8428 case 0xaa:
8430 InvalidInstruction(2);
8431 break;
8433 case 0xab:
8435 InvalidInstruction(2);
8436 break;
8438 case 0xac:
8440 sdwCyclesRemaining -= 9;
8441 cpu.z80A ^= cpu.z80XH;
8442 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8443 cpu.z80F |= bPostORFlags[cpu.z80A];
8445 InvalidInstruction(2);
8446 break;
8448 case 0xad:
8450 sdwCyclesRemaining -= 9;
8451 cpu.z80A ^= cpu.z80XL;
8452 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8453 cpu.z80F |= bPostORFlags[cpu.z80A];
8455 InvalidInstruction(2);
8456 break;
8458 case 0xae:
8460 sdwCyclesRemaining -= 19;
8461 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
8462 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
8463 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8464 while (psMemRead->lowAddr != 0xffffffff)
8466 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
8468 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8469 if (psMemRead->memoryCall)
8471 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
8473 else
8475 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
8477 psMemRead = NULL;
8478 break;
8480 ++psMemRead;
8483 if (psMemRead)
8485 bTemp = cpu.z80Base[dwAddr];
8488 cpu.z80A ^= bTemp;
8489 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8490 cpu.z80F |= bPostORFlags[cpu.z80A];
8492 break;
8494 case 0xaf:
8496 InvalidInstruction(2);
8497 break;
8499 case 0xb0:
8501 InvalidInstruction(2);
8502 break;
8504 case 0xb1:
8506 InvalidInstruction(2);
8507 break;
8509 case 0xb2:
8511 InvalidInstruction(2);
8512 break;
8514 case 0xb3:
8516 InvalidInstruction(2);
8517 break;
8519 case 0xb4:
8521 sdwCyclesRemaining -= 9;
8522 cpu.z80A |= cpu.z80XH;
8523 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8524 cpu.z80F |= bPostORFlags[cpu.z80A];
8526 InvalidInstruction(2);
8527 break;
8529 case 0xb5:
8531 sdwCyclesRemaining -= 9;
8532 cpu.z80A |= cpu.z80XL;
8533 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8534 cpu.z80F |= bPostORFlags[cpu.z80A];
8536 InvalidInstruction(2);
8537 break;
8539 case 0xb6:
8541 sdwCyclesRemaining -= 19;
8542 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
8543 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
8544 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8545 while (psMemRead->lowAddr != 0xffffffff)
8547 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
8549 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8550 if (psMemRead->memoryCall)
8552 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
8554 else
8556 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
8558 psMemRead = NULL;
8559 break;
8561 ++psMemRead;
8564 if (psMemRead)
8566 bTemp = cpu.z80Base[dwAddr];
8569 cpu.z80A |= bTemp;
8570 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8571 cpu.z80F |= bPostORFlags[cpu.z80A];
8573 break;
8575 case 0xb7:
8577 InvalidInstruction(2);
8578 break;
8580 case 0xb8:
8582 InvalidInstruction(2);
8583 break;
8585 case 0xb9:
8587 InvalidInstruction(2);
8588 break;
8590 case 0xba:
8592 InvalidInstruction(2);
8593 break;
8595 case 0xbb:
8597 InvalidInstruction(2);
8598 break;
8600 case 0xbc:
8602 sdwCyclesRemaining -= 9;
8603 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8604 cpu.z80F |= bPostORFlags[cpu.z80A];
8606 InvalidInstruction(2);
8607 break;
8609 case 0xbd:
8611 sdwCyclesRemaining -= 9;
8612 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
8613 cpu.z80F |= bPostORFlags[cpu.z80A];
8615 InvalidInstruction(2);
8616 break;
8618 case 0xbe:
8620 sdwCyclesRemaining -= 19;
8621 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
8622 dwAddr = (sdwAddr + (INT32) cpu.z80IX) & 0xffff;
8623 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8624 while (psMemRead->lowAddr != 0xffffffff)
8626 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
8628 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8629 if (psMemRead->memoryCall)
8631 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
8633 else
8635 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
8637 psMemRead = NULL;
8638 break;
8640 ++psMemRead;
8643 if (psMemRead)
8645 bTemp = cpu.z80Base[dwAddr];
8648 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
8649 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
8650 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp];
8651 break;
8653 case 0xbf:
8655 InvalidInstruction(2);
8656 break;
8658 case 0xc0:
8660 InvalidInstruction(2);
8661 break;
8663 case 0xc1:
8665 InvalidInstruction(2);
8666 break;
8668 case 0xc2:
8670 InvalidInstruction(2);
8671 break;
8673 case 0xc3:
8675 InvalidInstruction(2);
8676 break;
8678 case 0xc4:
8680 InvalidInstruction(2);
8681 break;
8683 case 0xc5:
8685 InvalidInstruction(2);
8686 break;
8688 case 0xc6:
8690 InvalidInstruction(2);
8691 break;
8693 case 0xc7:
8695 InvalidInstruction(2);
8696 break;
8698 case 0xc8:
8700 InvalidInstruction(2);
8701 break;
8703 case 0xc9:
8705 InvalidInstruction(2);
8706 break;
8708 case 0xca:
8710 InvalidInstruction(2);
8711 break;
8713 case 0xcb:
8715 DDFDCBHandler(0);
8716 break;
8718 case 0xcc:
8720 InvalidInstruction(2);
8721 break;
8723 case 0xcd:
8725 InvalidInstruction(2);
8726 break;
8728 case 0xce:
8730 InvalidInstruction(2);
8731 break;
8733 case 0xcf:
8735 InvalidInstruction(2);
8736 break;
8738 case 0xd0:
8740 InvalidInstruction(2);
8741 break;
8743 case 0xd1:
8745 InvalidInstruction(2);
8746 break;
8748 case 0xd2:
8750 InvalidInstruction(2);
8751 break;
8753 case 0xd3:
8755 InvalidInstruction(2);
8756 break;
8758 case 0xd4:
8760 InvalidInstruction(2);
8761 break;
8763 case 0xd5:
8765 InvalidInstruction(2);
8766 break;
8768 case 0xd6:
8770 InvalidInstruction(2);
8771 break;
8773 case 0xd7:
8775 InvalidInstruction(2);
8776 break;
8778 case 0xd8:
8780 InvalidInstruction(2);
8781 break;
8783 case 0xd9:
8785 InvalidInstruction(2);
8786 break;
8788 case 0xda:
8790 InvalidInstruction(2);
8791 break;
8793 case 0xdb:
8795 InvalidInstruction(2);
8796 break;
8798 case 0xdc:
8800 InvalidInstruction(2);
8801 break;
8803 case 0xdd:
8805 InvalidInstruction(2);
8806 break;
8808 case 0xde:
8810 InvalidInstruction(2);
8811 break;
8813 case 0xdf:
8815 InvalidInstruction(2);
8816 break;
8818 case 0xe0:
8820 InvalidInstruction(2);
8821 break;
8823 case 0xe1:
8825 sdwCyclesRemaining -= 14;
8826 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8827 while (psMemRead->lowAddr != 0xffffffff)
8829 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
8831 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8832 if (psMemRead->memoryCall)
8834 cpu.z80IX = psMemRead->memoryCall(cpu.z80sp, psMemRead);
8835 cpu.z80IX |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
8837 else
8839 cpu.z80IX = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
8840 cpu.z80IX |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
8842 psMemRead = NULL;
8843 break;
8845 ++psMemRead;
8848 if (psMemRead)
8850 cpu.z80IX = cpu.z80Base[cpu.z80sp];
8851 cpu.z80IX |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
8854 cpu.z80sp += 2;
8855 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
8856 break;
8858 case 0xe2:
8860 InvalidInstruction(2);
8861 break;
8863 case 0xe3:
8865 sdwCyclesRemaining -= 23;
8866 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
8867 while (psMemRead->lowAddr != 0xffffffff)
8869 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
8871 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8872 if (psMemRead->memoryCall)
8874 dwAddr = psMemRead->memoryCall(cpu.z80sp, psMemRead);
8875 dwAddr |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
8877 else
8879 dwAddr = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
8880 dwAddr |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
8882 psMemRead = NULL;
8883 break;
8885 ++psMemRead;
8888 if (psMemRead)
8890 dwAddr = cpu.z80Base[cpu.z80sp];
8891 dwAddr |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
8894 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
8895 while (psMemWrite->lowAddr != 0xffffffff)
8897 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
8899 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8900 if (psMemWrite->memoryCall)
8902 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80IX & 0xff), psMemWrite);
8903 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80IX >> 8), psMemWrite);
8905 else
8907 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80IX;
8908 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80IX >> 8;
8910 psMemWrite = NULL;
8911 break;
8913 ++psMemWrite;
8916 if (psMemWrite)
8918 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80IX;
8919 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80IX >> 8);
8922 cpu.z80IX = dwAddr;
8923 break;
8925 case 0xe4:
8927 InvalidInstruction(2);
8928 break;
8930 case 0xe5:
8932 sdwCyclesRemaining -= 15;
8933 cpu.z80sp -= 2;
8934 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
8935 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
8936 while (psMemWrite->lowAddr != 0xffffffff)
8938 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
8940 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
8941 if (psMemWrite->memoryCall)
8943 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80IX & 0xff), psMemWrite);
8944 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80IX >> 8), psMemWrite);
8946 else
8948 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80IX;
8949 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80IX >> 8;
8951 psMemWrite = NULL;
8952 break;
8954 ++psMemWrite;
8957 if (psMemWrite)
8959 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80IX;
8960 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80IX >> 8);
8963 break;
8965 case 0xe6:
8967 InvalidInstruction(2);
8968 break;
8970 case 0xe7:
8972 InvalidInstruction(2);
8973 break;
8975 case 0xe8:
8977 InvalidInstruction(2);
8978 break;
8980 case 0xe9:
8982 sdwCyclesRemaining -= 8;
8983 pbPC = cpu.z80Base + cpu.z80IX;
8984 break;
8986 case 0xea:
8988 InvalidInstruction(2);
8989 break;
8991 case 0xeb:
8993 InvalidInstruction(2);
8994 break;
8996 case 0xec:
8998 InvalidInstruction(2);
8999 break;
9001 case 0xed:
9003 InvalidInstruction(2);
9004 break;
9006 case 0xee:
9008 InvalidInstruction(2);
9009 break;
9011 case 0xef:
9013 InvalidInstruction(2);
9014 break;
9016 case 0xf0:
9018 InvalidInstruction(2);
9019 break;
9021 case 0xf1:
9023 InvalidInstruction(2);
9024 break;
9026 case 0xf2:
9028 InvalidInstruction(2);
9029 break;
9031 case 0xf3:
9033 InvalidInstruction(2);
9034 break;
9036 case 0xf4:
9038 InvalidInstruction(2);
9039 break;
9041 case 0xf5:
9043 InvalidInstruction(2);
9044 break;
9046 case 0xf6:
9048 InvalidInstruction(2);
9049 break;
9051 case 0xf7:
9053 InvalidInstruction(2);
9054 break;
9056 case 0xf8:
9058 InvalidInstruction(2);
9059 break;
9061 case 0xf9:
9063 sdwCyclesRemaining -= 10;
9064 cpu.z80sp = cpu.z80IX;
9065 break;
9067 case 0xfa:
9069 InvalidInstruction(2);
9070 break;
9072 case 0xfb:
9074 InvalidInstruction(2);
9075 break;
9077 case 0xfc:
9079 InvalidInstruction(2);
9080 break;
9082 case 0xfd:
9084 InvalidInstruction(2);
9085 break;
9087 case 0xfe:
9089 InvalidInstruction(2);
9090 break;
9092 case 0xff:
9094 InvalidInstruction(2);
9095 break;
9099 void DDFDCBHandler(UINT32 dwWhich)
9101 if (dwWhich)
9103 dwAddr = (UINT32) ((INT32) cpu.z80IY + ((INT32) *pbPC++)) & 0xffff;
9105 else
9107 dwAddr = (UINT32) ((INT32) cpu.z80IX + ((INT32) *pbPC++)) & 0xffff;
9110 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
9111 while (psMemRead->lowAddr != 0xffffffff)
9113 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
9115 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
9116 if (psMemRead->memoryCall)
9118 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
9120 else
9122 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
9124 psMemRead = NULL;
9125 break;
9127 ++psMemRead;
9130 if (psMemRead)
9132 bTemp = cpu.z80Base[dwAddr];
9135 switch (*pbPC++)
9137 case 0x00:
9139 InvalidInstruction(4);
9140 break;
9142 case 0x01:
9144 InvalidInstruction(4);
9145 break;
9147 case 0x02:
9149 InvalidInstruction(4);
9150 break;
9152 case 0x03:
9154 InvalidInstruction(4);
9155 break;
9157 case 0x04:
9159 InvalidInstruction(4);
9160 break;
9162 case 0x05:
9164 InvalidInstruction(4);
9165 break;
9167 case 0x06:
9169 sdwCyclesRemaining -= 23;
9170 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
9171 bTemp2 = (bTemp >> 7);
9172 bTemp = (bTemp << 1) | bTemp2;
9173 cpu.z80F |= bTemp2 | bPostORFlags[bTemp];
9174 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
9175 while (psMemWrite->lowAddr != 0xffffffff)
9177 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
9179 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
9180 if (psMemWrite->memoryCall)
9182 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
9184 else
9186 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
9188 psMemWrite = NULL;
9189 break;
9191 ++psMemWrite;
9194 if (psMemWrite)
9196 cpu.z80Base[dwAddr] = (UINT8) bTemp;
9199 break;
9201 case 0x07:
9203 InvalidInstruction(4);
9204 break;
9206 case 0x08:
9208 InvalidInstruction(4);
9209 break;
9211 case 0x09:
9213 InvalidInstruction(4);
9214 break;
9216 case 0x0a:
9218 InvalidInstruction(4);
9219 break;
9221 case 0x0b:
9223 InvalidInstruction(4);
9224 break;
9226 case 0x0c:
9228 InvalidInstruction(4);
9229 break;
9231 case 0x0d:
9233 InvalidInstruction(4);
9234 break;
9236 case 0x0e:
9238 sdwCyclesRemaining -= 23;
9239 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
9240 cpu.z80F |= (bTemp & Z80_FLAG_CARRY);
9241 bTemp = (bTemp >> 1) | (bTemp << 7);
9242 cpu.z80F |= bPostORFlags[bTemp];
9243 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
9244 while (psMemWrite->lowAddr != 0xffffffff)
9246 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
9248 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
9249 if (psMemWrite->memoryCall)
9251 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
9253 else
9255 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
9257 psMemWrite = NULL;
9258 break;
9260 ++psMemWrite;
9263 if (psMemWrite)
9265 cpu.z80Base[dwAddr] = (UINT8) bTemp;
9268 break;
9270 case 0x0f:
9272 InvalidInstruction(4);
9273 break;
9275 case 0x10:
9277 InvalidInstruction(4);
9278 break;
9280 case 0x11:
9282 InvalidInstruction(4);
9283 break;
9285 case 0x12:
9287 InvalidInstruction(4);
9288 break;
9290 case 0x13:
9292 InvalidInstruction(4);
9293 break;
9295 case 0x14:
9297 InvalidInstruction(4);
9298 break;
9300 case 0x15:
9302 InvalidInstruction(4);
9303 break;
9305 case 0x16:
9307 sdwCyclesRemaining -= 23;
9308 bTemp2 = cpu.z80F & Z80_FLAG_CARRY;
9309 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
9310 cpu.z80F |= (bTemp >> 7);
9311 bTemp = (bTemp << 1) | bTemp2;
9312 cpu.z80F |= bPostORFlags[bTemp];
9313 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
9314 while (psMemWrite->lowAddr != 0xffffffff)
9316 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
9318 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
9319 if (psMemWrite->memoryCall)
9321 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
9323 else
9325 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
9327 psMemWrite = NULL;
9328 break;
9330 ++psMemWrite;
9333 if (psMemWrite)
9335 cpu.z80Base[dwAddr] = (UINT8) bTemp;
9338 break;
9340 case 0x17:
9342 InvalidInstruction(4);
9343 break;
9345 case 0x18:
9347 InvalidInstruction(4);
9348 break;
9350 case 0x19:
9352 InvalidInstruction(4);
9353 break;
9355 case 0x1a:
9357 InvalidInstruction(4);
9358 break;
9360 case 0x1b:
9362 InvalidInstruction(4);
9363 break;
9365 case 0x1c:
9367 InvalidInstruction(4);
9368 break;
9370 case 0x1d:
9372 InvalidInstruction(4);
9373 break;
9375 case 0x1e:
9377 sdwCyclesRemaining -= 23;
9378 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;
9379 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
9380 cpu.z80F |= (bTemp & Z80_FLAG_CARRY);
9381 bTemp = (bTemp >> 1) | bTemp2;
9382 cpu.z80F |= bPostORFlags[bTemp];
9383 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
9384 while (psMemWrite->lowAddr != 0xffffffff)
9386 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
9388 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
9389 if (psMemWrite->memoryCall)
9391 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
9393 else
9395 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
9397 psMemWrite = NULL;
9398 break;
9400 ++psMemWrite;
9403 if (psMemWrite)
9405 cpu.z80Base[dwAddr] = (UINT8) bTemp;
9408 break;
9410 case 0x1f:
9412 InvalidInstruction(4);
9413 break;
9415 case 0x20:
9417 InvalidInstruction(4);
9418 break;
9420 case 0x21:
9422 InvalidInstruction(4);
9423 break;
9425 case 0x22:
9427 InvalidInstruction(4);
9428 break;
9430 case 0x23:
9432 InvalidInstruction(4);
9433 break;
9435 case 0x24:
9437 InvalidInstruction(4);
9438 break;
9440 case 0x25:
9442 InvalidInstruction(4);
9443 break;
9445 case 0x26:
9447 sdwCyclesRemaining -= 23;
9448 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
9449 cpu.z80F |= (bTemp >> 7);
9450 bTemp = (bTemp << 1);
9451 cpu.z80F |= bPostORFlags[bTemp];
9452 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
9453 while (psMemWrite->lowAddr != 0xffffffff)
9455 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
9457 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
9458 if (psMemWrite->memoryCall)
9460 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
9462 else
9464 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
9466 psMemWrite = NULL;
9467 break;
9469 ++psMemWrite;
9472 if (psMemWrite)
9474 cpu.z80Base[dwAddr] = (UINT8) bTemp;
9477 break;
9479 case 0x27:
9481 InvalidInstruction(4);
9482 break;
9484 case 0x28:
9486 InvalidInstruction(4);
9487 break;
9489 case 0x29:
9491 InvalidInstruction(4);
9492 break;
9494 case 0x2a:
9496 InvalidInstruction(4);
9497 break;
9499 case 0x2b:
9501 InvalidInstruction(4);
9502 break;
9504 case 0x2c:
9506 InvalidInstruction(4);
9507 break;
9509 case 0x2d:
9511 InvalidInstruction(4);
9512 break;
9514 case 0x2e:
9516 sdwCyclesRemaining -= 23;
9517 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
9518 cpu.z80F |= (bTemp & Z80_FLAG_CARRY);
9519 bTemp = (bTemp >> 1) | (bTemp & 0x80);
9520 cpu.z80F |= bPostORFlags[bTemp];
9521 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
9522 while (psMemWrite->lowAddr != 0xffffffff)
9524 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
9526 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
9527 if (psMemWrite->memoryCall)
9529 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
9531 else
9533 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
9535 psMemWrite = NULL;
9536 break;
9538 ++psMemWrite;
9541 if (psMemWrite)
9543 cpu.z80Base[dwAddr] = (UINT8) bTemp;
9546 break;
9548 case 0x2f:
9550 InvalidInstruction(4);
9551 break;
9553 case 0x30:
9555 InvalidInstruction(4);
9556 break;
9558 case 0x31:
9560 InvalidInstruction(4);
9561 break;
9563 case 0x32:
9565 InvalidInstruction(4);
9566 break;
9568 case 0x33:
9570 InvalidInstruction(4);
9571 break;
9573 case 0x34:
9575 InvalidInstruction(4);
9576 break;
9578 case 0x35:
9580 InvalidInstruction(4);
9581 break;
9583 case 0x36:
9585 sdwCyclesRemaining -= 23;
9586 InvalidInstruction(4);
9587 break;
9589 case 0x37:
9591 InvalidInstruction(4);
9592 break;
9594 case 0x38:
9596 InvalidInstruction(4);
9597 break;
9599 case 0x39:
9601 InvalidInstruction(4);
9602 break;
9604 case 0x3a:
9606 InvalidInstruction(4);
9607 break;
9609 case 0x3b:
9611 InvalidInstruction(4);
9612 break;
9614 case 0x3c:
9616 InvalidInstruction(4);
9617 break;
9619 case 0x3d:
9621 InvalidInstruction(4);
9622 break;
9624 case 0x3e:
9626 sdwCyclesRemaining -= 23;
9627 cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);
9628 cpu.z80F |= (bTemp & Z80_FLAG_CARRY);
9629 bTemp = (bTemp >> 1);
9630 cpu.z80F |= bPostORFlags[bTemp];
9631 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
9632 while (psMemWrite->lowAddr != 0xffffffff)
9634 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
9636 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
9637 if (psMemWrite->memoryCall)
9639 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
9641 else
9643 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
9645 psMemWrite = NULL;
9646 break;
9648 ++psMemWrite;
9651 if (psMemWrite)
9653 cpu.z80Base[dwAddr] = (UINT8) bTemp;
9656 break;
9658 case 0x3f:
9660 InvalidInstruction(4);
9661 break;
9663 case 0x40:
9665 sdwCyclesRemaining -= 20;
9666 InvalidInstruction(4);
9667 break;
9669 case 0x41:
9671 sdwCyclesRemaining -= 20;
9672 InvalidInstruction(4);
9673 break;
9675 case 0x42:
9677 sdwCyclesRemaining -= 20;
9678 InvalidInstruction(4);
9679 break;
9681 case 0x43:
9683 sdwCyclesRemaining -= 20;
9684 InvalidInstruction(4);
9685 break;
9687 case 0x44:
9689 sdwCyclesRemaining -= 20;
9690 InvalidInstruction(4);
9691 break;
9693 case 0x45:
9695 sdwCyclesRemaining -= 20;
9696 InvalidInstruction(4);
9697 break;
9699 case 0x46:
9701 sdwCyclesRemaining -= 20;
9702 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;
9703 if (!(bTemp & 0x01))
9705 cpu.z80F |= Z80_FLAG_ZERO;
9707 break;
9709 case 0x47:
9711 sdwCyclesRemaining -= 20;
9712 InvalidInstruction(4);
9713 break;
9715 case 0x48:
9717 sdwCyclesRemaining -= 20;
9718 InvalidInstruction(4);
9719 break;
9721 case 0x49:
9723 sdwCyclesRemaining -= 20;
9724 InvalidInstruction(4);
9725 break;
9727 case 0x4a:
9729 sdwCyclesRemaining -= 20;
9730 InvalidInstruction(4);
9731 break;
9733 case 0x4b:
9735 sdwCyclesRemaining -= 20;
9736 InvalidInstruction(4);
9737 break;
9739 case 0x4c:
9741 sdwCyclesRemaining -= 20;
9742 InvalidInstruction(4);
9743 break;
9745 case 0x4d:
9747 sdwCyclesRemaining -= 20;
9748 InvalidInstruction(4);
9749 break;
9751 case 0x4e:
9753 sdwCyclesRemaining -= 20;
9754 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;
9755 if (!(bTemp & 0x02))
9757 cpu.z80F |= Z80_FLAG_ZERO;
9759 break;
9761 case 0x4f:
9763 sdwCyclesRemaining -= 20;
9764 InvalidInstruction(4);
9765 break;
9767 case 0x50:
9769 sdwCyclesRemaining -= 20;
9770 InvalidInstruction(4);
9771 break;
9773 case 0x51:
9775 sdwCyclesRemaining -= 20;
9776 InvalidInstruction(4);
9777 break;
9779 case 0x52:
9781 sdwCyclesRemaining -= 20;
9782 InvalidInstruction(4);
9783 break;
9785 case 0x53:
9787 sdwCyclesRemaining -= 20;
9788 InvalidInstruction(4);
9789 break;
9791 case 0x54:
9793 sdwCyclesRemaining -= 20;
9794 InvalidInstruction(4);
9795 break;
9797 case 0x55:
9799 sdwCyclesRemaining -= 20;
9800 InvalidInstruction(4);
9801 break;
9803 case 0x56:
9805 sdwCyclesRemaining -= 20;
9806 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;
9807 if (!(bTemp & 0x04))
9809 cpu.z80F |= Z80_FLAG_ZERO;
9811 break;
9813 case 0x57:
9815 sdwCyclesRemaining -= 20;
9816 InvalidInstruction(4);
9817 break;
9819 case 0x58:
9821 sdwCyclesRemaining -= 20;
9822 InvalidInstruction(4);
9823 break;
9825 case 0x59:
9827 sdwCyclesRemaining -= 20;
9828 InvalidInstruction(4);
9829 break;
9831 case 0x5a:
9833 sdwCyclesRemaining -= 20;
9834 InvalidInstruction(4);
9835 break;
9837 case 0x5b:
9839 sdwCyclesRemaining -= 20;
9840 InvalidInstruction(4);
9841 break;
9843 case 0x5c:
9845 sdwCyclesRemaining -= 20;
9846 InvalidInstruction(4);
9847 break;
9849 case 0x5d:
9851 sdwCyclesRemaining -= 20;
9852 InvalidInstruction(4);
9853 break;
9855 case 0x5e:
9857 sdwCyclesRemaining -= 20;
9858 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;
9859 if (!(bTemp & 0x08))
9861 cpu.z80F |= Z80_FLAG_ZERO;
9863 break;
9865 case 0x5f:
9867 sdwCyclesRemaining -= 20;
9868 InvalidInstruction(4);
9869 break;
9871 case 0x60:
9873 sdwCyclesRemaining -= 20;
9874 InvalidInstruction(4);
9875 break;
9877 case 0x61:
9879 sdwCyclesRemaining -= 20;
9880 InvalidInstruction(4);
9881 break;
9883 case 0x62:
9885 sdwCyclesRemaining -= 20;
9886 InvalidInstruction(4);
9887 break;
9889 case 0x63:
9891 sdwCyclesRemaining -= 20;
9892 InvalidInstruction(4);
9893 break;
9895 case 0x64:
9897 sdwCyclesRemaining -= 20;
9898 InvalidInstruction(4);
9899 break;
9901 case 0x65:
9903 sdwCyclesRemaining -= 20;
9904 InvalidInstruction(4);
9905 break;
9907 case 0x66:
9909 sdwCyclesRemaining -= 20;
9910 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;
9911 if (!(bTemp & 0x10))
9913 cpu.z80F |= Z80_FLAG_ZERO;
9915 break;
9917 case 0x67:
9919 sdwCyclesRemaining -= 20;
9920 InvalidInstruction(4);
9921 break;
9923 case 0x68:
9925 sdwCyclesRemaining -= 20;
9926 InvalidInstruction(4);
9927 break;
9929 case 0x69:
9931 sdwCyclesRemaining -= 20;
9932 InvalidInstruction(4);
9933 break;
9935 case 0x6a:
9937 sdwCyclesRemaining -= 20;
9938 InvalidInstruction(4);
9939 break;
9941 case 0x6b:
9943 sdwCyclesRemaining -= 20;
9944 InvalidInstruction(4);
9945 break;
9947 case 0x6c:
9949 sdwCyclesRemaining -= 20;
9950 InvalidInstruction(4);
9951 break;
9953 case 0x6d:
9955 sdwCyclesRemaining -= 20;
9956 InvalidInstruction(4);
9957 break;
9959 case 0x6e:
9961 sdwCyclesRemaining -= 20;
9962 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;
9963 if (!(bTemp & 0x20))
9965 cpu.z80F |= Z80_FLAG_ZERO;
9967 break;
9969 case 0x6f:
9971 sdwCyclesRemaining -= 20;
9972 InvalidInstruction(4);
9973 break;
9975 case 0x70:
9977 sdwCyclesRemaining -= 20;
9978 InvalidInstruction(4);
9979 break;
9981 case 0x71:
9983 sdwCyclesRemaining -= 20;
9984 InvalidInstruction(4);
9985 break;
9987 case 0x72:
9989 sdwCyclesRemaining -= 20;
9990 InvalidInstruction(4);
9991 break;
9993 case 0x73:
9995 sdwCyclesRemaining -= 20;
9996 InvalidInstruction(4);
9997 break;
9999 case 0x74:
10001 sdwCyclesRemaining -= 20;
10002 InvalidInstruction(4);
10003 break;
10005 case 0x75:
10007 sdwCyclesRemaining -= 20;
10008 InvalidInstruction(4);
10009 break;
10011 case 0x76:
10013 sdwCyclesRemaining -= 20;
10014 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;
10015 if (!(bTemp & 0x40))
10017 cpu.z80F |= Z80_FLAG_ZERO;
10019 break;
10021 case 0x77:
10023 sdwCyclesRemaining -= 20;
10024 InvalidInstruction(4);
10025 break;
10027 case 0x78:
10029 sdwCyclesRemaining -= 20;
10030 InvalidInstruction(4);
10031 break;
10033 case 0x79:
10035 sdwCyclesRemaining -= 20;
10036 InvalidInstruction(4);
10037 break;
10039 case 0x7a:
10041 sdwCyclesRemaining -= 20;
10042 InvalidInstruction(4);
10043 break;
10045 case 0x7b:
10047 sdwCyclesRemaining -= 20;
10048 InvalidInstruction(4);
10049 break;
10051 case 0x7c:
10053 sdwCyclesRemaining -= 20;
10054 InvalidInstruction(4);
10055 break;
10057 case 0x7d:
10059 sdwCyclesRemaining -= 20;
10060 InvalidInstruction(4);
10061 break;
10063 case 0x7e:
10065 sdwCyclesRemaining -= 20;
10066 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;
10067 if (!(bTemp & 0x80))
10069 cpu.z80F |= Z80_FLAG_ZERO;
10071 break;
10073 case 0x7f:
10075 sdwCyclesRemaining -= 20;
10076 InvalidInstruction(4);
10077 break;
10079 case 0x80:
10081 InvalidInstruction(4);
10082 break;
10084 case 0x81:
10086 InvalidInstruction(4);
10087 break;
10089 case 0x82:
10091 InvalidInstruction(4);
10092 break;
10094 case 0x83:
10096 InvalidInstruction(4);
10097 break;
10099 case 0x84:
10101 InvalidInstruction(4);
10102 break;
10104 case 0x85:
10106 InvalidInstruction(4);
10107 break;
10109 case 0x86:
10111 sdwCyclesRemaining -= 23;
10112 bTemp &= 0xfe;
10113 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10114 while (psMemWrite->lowAddr != 0xffffffff)
10116 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10118 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10119 if (psMemWrite->memoryCall)
10121 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10123 else
10125 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10127 psMemWrite = NULL;
10128 break;
10130 ++psMemWrite;
10133 if (psMemWrite)
10135 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10138 break;
10140 case 0x87:
10142 InvalidInstruction(4);
10143 break;
10145 case 0x88:
10147 InvalidInstruction(4);
10148 break;
10150 case 0x89:
10152 InvalidInstruction(4);
10153 break;
10155 case 0x8a:
10157 InvalidInstruction(4);
10158 break;
10160 case 0x8b:
10162 InvalidInstruction(4);
10163 break;
10165 case 0x8c:
10167 InvalidInstruction(4);
10168 break;
10170 case 0x8d:
10172 InvalidInstruction(4);
10173 break;
10175 case 0x8e:
10177 sdwCyclesRemaining -= 23;
10178 bTemp &= 0xfd;
10179 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10180 while (psMemWrite->lowAddr != 0xffffffff)
10182 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10184 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10185 if (psMemWrite->memoryCall)
10187 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10189 else
10191 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10193 psMemWrite = NULL;
10194 break;
10196 ++psMemWrite;
10199 if (psMemWrite)
10201 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10204 break;
10206 case 0x8f:
10208 InvalidInstruction(4);
10209 break;
10211 case 0x90:
10213 InvalidInstruction(4);
10214 break;
10216 case 0x91:
10218 InvalidInstruction(4);
10219 break;
10221 case 0x92:
10223 InvalidInstruction(4);
10224 break;
10226 case 0x93:
10228 InvalidInstruction(4);
10229 break;
10231 case 0x94:
10233 InvalidInstruction(4);
10234 break;
10236 case 0x95:
10238 InvalidInstruction(4);
10239 break;
10241 case 0x96:
10243 sdwCyclesRemaining -= 23;
10244 bTemp &= 0xfb;
10245 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10246 while (psMemWrite->lowAddr != 0xffffffff)
10248 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10250 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10251 if (psMemWrite->memoryCall)
10253 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10255 else
10257 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10259 psMemWrite = NULL;
10260 break;
10262 ++psMemWrite;
10265 if (psMemWrite)
10267 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10270 break;
10272 case 0x97:
10274 InvalidInstruction(4);
10275 break;
10277 case 0x98:
10279 InvalidInstruction(4);
10280 break;
10282 case 0x99:
10284 InvalidInstruction(4);
10285 break;
10287 case 0x9a:
10289 InvalidInstruction(4);
10290 break;
10292 case 0x9b:
10294 InvalidInstruction(4);
10295 break;
10297 case 0x9c:
10299 InvalidInstruction(4);
10300 break;
10302 case 0x9d:
10304 InvalidInstruction(4);
10305 break;
10307 case 0x9e:
10309 sdwCyclesRemaining -= 23;
10310 bTemp &= 0xf7;
10311 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10312 while (psMemWrite->lowAddr != 0xffffffff)
10314 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10316 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10317 if (psMemWrite->memoryCall)
10319 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10321 else
10323 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10325 psMemWrite = NULL;
10326 break;
10328 ++psMemWrite;
10331 if (psMemWrite)
10333 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10336 break;
10338 case 0x9f:
10340 InvalidInstruction(4);
10341 break;
10343 case 0xa0:
10345 InvalidInstruction(4);
10346 break;
10348 case 0xa1:
10350 InvalidInstruction(4);
10351 break;
10353 case 0xa2:
10355 InvalidInstruction(4);
10356 break;
10358 case 0xa3:
10360 InvalidInstruction(4);
10361 break;
10363 case 0xa4:
10365 InvalidInstruction(4);
10366 break;
10368 case 0xa5:
10370 InvalidInstruction(4);
10371 break;
10373 case 0xa6:
10375 sdwCyclesRemaining -= 23;
10376 bTemp &= 0xef;
10377 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10378 while (psMemWrite->lowAddr != 0xffffffff)
10380 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10382 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10383 if (psMemWrite->memoryCall)
10385 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10387 else
10389 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10391 psMemWrite = NULL;
10392 break;
10394 ++psMemWrite;
10397 if (psMemWrite)
10399 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10402 break;
10404 case 0xa7:
10406 InvalidInstruction(4);
10407 break;
10409 case 0xa8:
10411 InvalidInstruction(4);
10412 break;
10414 case 0xa9:
10416 InvalidInstruction(4);
10417 break;
10419 case 0xaa:
10421 InvalidInstruction(4);
10422 break;
10424 case 0xab:
10426 InvalidInstruction(4);
10427 break;
10429 case 0xac:
10431 InvalidInstruction(4);
10432 break;
10434 case 0xad:
10436 InvalidInstruction(4);
10437 break;
10439 case 0xae:
10441 sdwCyclesRemaining -= 23;
10442 bTemp &= 0xdf;
10443 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10444 while (psMemWrite->lowAddr != 0xffffffff)
10446 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10448 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10449 if (psMemWrite->memoryCall)
10451 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10453 else
10455 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10457 psMemWrite = NULL;
10458 break;
10460 ++psMemWrite;
10463 if (psMemWrite)
10465 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10468 break;
10470 case 0xaf:
10472 InvalidInstruction(4);
10473 break;
10475 case 0xb0:
10477 InvalidInstruction(4);
10478 break;
10480 case 0xb1:
10482 InvalidInstruction(4);
10483 break;
10485 case 0xb2:
10487 InvalidInstruction(4);
10488 break;
10490 case 0xb3:
10492 InvalidInstruction(4);
10493 break;
10495 case 0xb4:
10497 InvalidInstruction(4);
10498 break;
10500 case 0xb5:
10502 InvalidInstruction(4);
10503 break;
10505 case 0xb6:
10507 sdwCyclesRemaining -= 23;
10508 bTemp &= 0xbf;
10509 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10510 while (psMemWrite->lowAddr != 0xffffffff)
10512 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10514 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10515 if (psMemWrite->memoryCall)
10517 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10519 else
10521 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10523 psMemWrite = NULL;
10524 break;
10526 ++psMemWrite;
10529 if (psMemWrite)
10531 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10534 break;
10536 case 0xb7:
10538 InvalidInstruction(4);
10539 break;
10541 case 0xb8:
10543 InvalidInstruction(4);
10544 break;
10546 case 0xb9:
10548 InvalidInstruction(4);
10549 break;
10551 case 0xba:
10553 InvalidInstruction(4);
10554 break;
10556 case 0xbb:
10558 InvalidInstruction(4);
10559 break;
10561 case 0xbc:
10563 InvalidInstruction(4);
10564 break;
10566 case 0xbd:
10568 InvalidInstruction(4);
10569 break;
10571 case 0xbe:
10573 sdwCyclesRemaining -= 23;
10574 bTemp &= 0x7f;
10575 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10576 while (psMemWrite->lowAddr != 0xffffffff)
10578 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10580 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10581 if (psMemWrite->memoryCall)
10583 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10585 else
10587 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10589 psMemWrite = NULL;
10590 break;
10592 ++psMemWrite;
10595 if (psMemWrite)
10597 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10600 break;
10602 case 0xbf:
10604 InvalidInstruction(4);
10605 break;
10607 case 0xc0:
10609 InvalidInstruction(4);
10610 break;
10612 case 0xc1:
10614 InvalidInstruction(4);
10615 break;
10617 case 0xc2:
10619 InvalidInstruction(4);
10620 break;
10622 case 0xc3:
10624 InvalidInstruction(4);
10625 break;
10627 case 0xc4:
10629 InvalidInstruction(4);
10630 break;
10632 case 0xc5:
10634 InvalidInstruction(4);
10635 break;
10637 case 0xc6:
10639 sdwCyclesRemaining -= 23;
10640 bTemp |= 0x01;
10641 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10642 while (psMemWrite->lowAddr != 0xffffffff)
10644 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10646 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10647 if (psMemWrite->memoryCall)
10649 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10651 else
10653 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10655 psMemWrite = NULL;
10656 break;
10658 ++psMemWrite;
10661 if (psMemWrite)
10663 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10666 break;
10668 case 0xc7:
10670 InvalidInstruction(4);
10671 break;
10673 case 0xc8:
10675 InvalidInstruction(4);
10676 break;
10678 case 0xc9:
10680 InvalidInstruction(4);
10681 break;
10683 case 0xca:
10685 InvalidInstruction(4);
10686 break;
10688 case 0xcb:
10690 InvalidInstruction(4);
10691 break;
10693 case 0xcc:
10695 InvalidInstruction(4);
10696 break;
10698 case 0xcd:
10700 InvalidInstruction(4);
10701 break;
10703 case 0xce:
10705 sdwCyclesRemaining -= 23;
10706 bTemp |= 0x02;
10707 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10708 while (psMemWrite->lowAddr != 0xffffffff)
10710 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10712 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10713 if (psMemWrite->memoryCall)
10715 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10717 else
10719 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10721 psMemWrite = NULL;
10722 break;
10724 ++psMemWrite;
10727 if (psMemWrite)
10729 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10732 break;
10734 case 0xcf:
10736 InvalidInstruction(4);
10737 break;
10739 case 0xd0:
10741 InvalidInstruction(4);
10742 break;
10744 case 0xd1:
10746 InvalidInstruction(4);
10747 break;
10749 case 0xd2:
10751 InvalidInstruction(4);
10752 break;
10754 case 0xd3:
10756 InvalidInstruction(4);
10757 break;
10759 case 0xd4:
10761 InvalidInstruction(4);
10762 break;
10764 case 0xd5:
10766 InvalidInstruction(4);
10767 break;
10769 case 0xd6:
10771 sdwCyclesRemaining -= 23;
10772 bTemp |= 0x04;
10773 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10774 while (psMemWrite->lowAddr != 0xffffffff)
10776 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10778 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10779 if (psMemWrite->memoryCall)
10781 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10783 else
10785 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10787 psMemWrite = NULL;
10788 break;
10790 ++psMemWrite;
10793 if (psMemWrite)
10795 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10798 break;
10800 case 0xd7:
10802 InvalidInstruction(4);
10803 break;
10805 case 0xd8:
10807 InvalidInstruction(4);
10808 break;
10810 case 0xd9:
10812 InvalidInstruction(4);
10813 break;
10815 case 0xda:
10817 InvalidInstruction(4);
10818 break;
10820 case 0xdb:
10822 InvalidInstruction(4);
10823 break;
10825 case 0xdc:
10827 InvalidInstruction(4);
10828 break;
10830 case 0xdd:
10832 InvalidInstruction(4);
10833 break;
10835 case 0xde:
10837 sdwCyclesRemaining -= 23;
10838 bTemp |= 0x08;
10839 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10840 while (psMemWrite->lowAddr != 0xffffffff)
10842 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10844 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10845 if (psMemWrite->memoryCall)
10847 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10849 else
10851 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10853 psMemWrite = NULL;
10854 break;
10856 ++psMemWrite;
10859 if (psMemWrite)
10861 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10864 break;
10866 case 0xdf:
10868 InvalidInstruction(4);
10869 break;
10871 case 0xe0:
10873 InvalidInstruction(4);
10874 break;
10876 case 0xe1:
10878 InvalidInstruction(4);
10879 break;
10881 case 0xe2:
10883 InvalidInstruction(4);
10884 break;
10886 case 0xe3:
10888 InvalidInstruction(4);
10889 break;
10891 case 0xe4:
10893 InvalidInstruction(4);
10894 break;
10896 case 0xe5:
10898 InvalidInstruction(4);
10899 break;
10901 case 0xe6:
10903 sdwCyclesRemaining -= 23;
10904 bTemp |= 0x10;
10905 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10906 while (psMemWrite->lowAddr != 0xffffffff)
10908 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10910 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10911 if (psMemWrite->memoryCall)
10913 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10915 else
10917 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10919 psMemWrite = NULL;
10920 break;
10922 ++psMemWrite;
10925 if (psMemWrite)
10927 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10930 break;
10932 case 0xe7:
10934 InvalidInstruction(4);
10935 break;
10937 case 0xe8:
10939 InvalidInstruction(4);
10940 break;
10942 case 0xe9:
10944 InvalidInstruction(4);
10945 break;
10947 case 0xea:
10949 InvalidInstruction(4);
10950 break;
10952 case 0xeb:
10954 InvalidInstruction(4);
10955 break;
10957 case 0xec:
10959 InvalidInstruction(4);
10960 break;
10962 case 0xed:
10964 InvalidInstruction(4);
10965 break;
10967 case 0xee:
10969 sdwCyclesRemaining -= 23;
10970 bTemp |= 0x20;
10971 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
10972 while (psMemWrite->lowAddr != 0xffffffff)
10974 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
10976 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
10977 if (psMemWrite->memoryCall)
10979 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
10981 else
10983 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
10985 psMemWrite = NULL;
10986 break;
10988 ++psMemWrite;
10991 if (psMemWrite)
10993 cpu.z80Base[dwAddr] = (UINT8) bTemp;
10996 break;
10998 case 0xef:
11000 InvalidInstruction(4);
11001 break;
11003 case 0xf0:
11005 InvalidInstruction(4);
11006 break;
11008 case 0xf1:
11010 InvalidInstruction(4);
11011 break;
11013 case 0xf2:
11015 InvalidInstruction(4);
11016 break;
11018 case 0xf3:
11020 InvalidInstruction(4);
11021 break;
11023 case 0xf4:
11025 InvalidInstruction(4);
11026 break;
11028 case 0xf5:
11030 InvalidInstruction(4);
11031 break;
11033 case 0xf6:
11035 sdwCyclesRemaining -= 23;
11036 bTemp |= 0x40;
11037 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
11038 while (psMemWrite->lowAddr != 0xffffffff)
11040 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
11042 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11043 if (psMemWrite->memoryCall)
11045 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
11047 else
11049 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
11051 psMemWrite = NULL;
11052 break;
11054 ++psMemWrite;
11057 if (psMemWrite)
11059 cpu.z80Base[dwAddr] = (UINT8) bTemp;
11062 break;
11064 case 0xf7:
11066 InvalidInstruction(4);
11067 break;
11069 case 0xf8:
11071 InvalidInstruction(4);
11072 break;
11074 case 0xf9:
11076 InvalidInstruction(4);
11077 break;
11079 case 0xfa:
11081 InvalidInstruction(4);
11082 break;
11084 case 0xfb:
11086 InvalidInstruction(4);
11087 break;
11089 case 0xfc:
11091 InvalidInstruction(4);
11092 break;
11094 case 0xfd:
11096 InvalidInstruction(4);
11097 break;
11099 case 0xfe:
11101 sdwCyclesRemaining -= 23;
11102 bTemp |= 0x80;
11103 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
11104 while (psMemWrite->lowAddr != 0xffffffff)
11106 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
11108 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11109 if (psMemWrite->memoryCall)
11111 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
11113 else
11115 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
11117 psMemWrite = NULL;
11118 break;
11120 ++psMemWrite;
11123 if (psMemWrite)
11125 cpu.z80Base[dwAddr] = (UINT8) bTemp;
11128 break;
11130 case 0xff:
11132 InvalidInstruction(4);
11133 break;
11137 void FDHandler(void)
11139 switch (*pbPC++)
11141 case 0x00:
11143 InvalidInstruction(2);
11144 break;
11146 case 0x01:
11148 InvalidInstruction(2);
11149 break;
11151 case 0x02:
11153 InvalidInstruction(2);
11154 break;
11156 case 0x03:
11158 InvalidInstruction(2);
11159 break;
11161 case 0x04:
11163 InvalidInstruction(2);
11164 break;
11166 case 0x05:
11168 InvalidInstruction(2);
11169 break;
11171 case 0x06:
11173 InvalidInstruction(2);
11174 break;
11176 case 0x07:
11178 InvalidInstruction(2);
11179 break;
11181 case 0x08:
11183 InvalidInstruction(2);
11184 break;
11186 case 0x09:
11188 sdwCyclesRemaining -= 15;
11189 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
11190 dwTemp = cpu.z80IY + cpu.z80BC;
11191 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80IY ^ dwTemp ^ cpu.z80BC) >> 8) & Z80_FLAG_HALF_CARRY);
11192 cpu.z80IY = dwTemp & 0xffff;
11193 break;
11195 case 0x0a:
11197 InvalidInstruction(2);
11198 break;
11200 case 0x0b:
11202 InvalidInstruction(2);
11203 break;
11205 case 0x0c:
11207 InvalidInstruction(2);
11208 break;
11210 case 0x0d:
11212 InvalidInstruction(2);
11213 break;
11215 case 0x0e:
11217 InvalidInstruction(2);
11218 break;
11220 case 0x0f:
11222 InvalidInstruction(2);
11223 break;
11225 case 0x10:
11227 InvalidInstruction(2);
11228 break;
11230 case 0x11:
11232 InvalidInstruction(2);
11233 break;
11235 case 0x12:
11237 InvalidInstruction(2);
11238 break;
11240 case 0x13:
11242 InvalidInstruction(2);
11243 break;
11245 case 0x14:
11247 InvalidInstruction(2);
11248 break;
11250 case 0x15:
11252 InvalidInstruction(2);
11253 break;
11255 case 0x16:
11257 InvalidInstruction(2);
11258 break;
11260 case 0x17:
11262 InvalidInstruction(2);
11263 break;
11265 case 0x18:
11267 InvalidInstruction(2);
11268 break;
11270 case 0x19:
11272 sdwCyclesRemaining -= 15;
11273 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
11274 dwTemp = cpu.z80IY + cpu.z80DE;
11275 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80IY ^ dwTemp ^ cpu.z80DE) >> 8) & Z80_FLAG_HALF_CARRY);
11276 cpu.z80IY = dwTemp & 0xffff;
11277 break;
11279 case 0x1a:
11281 InvalidInstruction(2);
11282 break;
11284 case 0x1b:
11286 InvalidInstruction(2);
11287 break;
11289 case 0x1c:
11291 InvalidInstruction(2);
11292 break;
11294 case 0x1d:
11296 InvalidInstruction(2);
11297 break;
11299 case 0x1e:
11301 InvalidInstruction(2);
11302 break;
11304 case 0x1f:
11306 InvalidInstruction(2);
11307 break;
11309 case 0x20:
11311 InvalidInstruction(2);
11312 break;
11314 case 0x21:
11316 sdwCyclesRemaining -= 14;
11317 cpu.z80IY = *pbPC++;
11318 cpu.z80IY |= ((UINT32) *pbPC++ << 8);
11319 break;
11321 case 0x22:
11323 sdwCyclesRemaining -= 20;
11324 dwAddr = *pbPC++;
11325 dwAddr |= ((UINT32) *pbPC++ << 8);
11326 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
11327 while (psMemWrite->lowAddr != 0xffffffff)
11329 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
11331 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11332 if (psMemWrite->memoryCall)
11334 psMemWrite->memoryCall(dwAddr, (cpu.z80IY & 0xff), psMemWrite);
11335 psMemWrite->memoryCall(dwAddr + 1, (cpu.z80IY >> 8), psMemWrite);
11337 else
11339 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = cpu.z80IY;
11340 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr) + 1) = cpu.z80IY >> 8;
11342 psMemWrite = NULL;
11343 break;
11345 ++psMemWrite;
11348 if (psMemWrite)
11350 cpu.z80Base[dwAddr] = (UINT8) cpu.z80IY;
11351 cpu.z80Base[dwAddr + 1] = (UINT8) ((UINT32) cpu.z80IY >> 8);
11354 break;
11356 case 0x23:
11358 sdwCyclesRemaining -= 10;
11359 cpu.z80IY++;
11360 cpu.z80IY &= 0xffff;
11361 break;
11363 case 0x24:
11365 sdwCyclesRemaining -= 9;
11366 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
11367 cpu.z80F |= bPostIncFlags[cpu.z80YH++];
11368 break;
11370 case 0x25:
11372 sdwCyclesRemaining -= 9;
11373 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
11374 cpu.z80F |= bPostDecFlags[cpu.z80YH--];
11375 break;
11377 case 0x26:
11379 sdwCyclesRemaining -= 9;
11380 cpu.z80YH = *pbPC++;
11381 break;
11383 case 0x27:
11385 InvalidInstruction(2);
11386 break;
11388 case 0x28:
11390 InvalidInstruction(2);
11391 break;
11393 case 0x29:
11395 sdwCyclesRemaining -= 15;
11396 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
11397 dwTemp = cpu.z80IY + cpu.z80IY;
11398 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80IY ^ dwTemp ^ cpu.z80HL) >> 8) & Z80_FLAG_HALF_CARRY);
11399 cpu.z80IY = dwTemp & 0xffff;
11400 break;
11402 case 0x2a:
11404 sdwCyclesRemaining -= 20;
11405 dwAddr = *pbPC++;
11406 dwAddr |= ((UINT32) *pbPC++ << 8);
11407 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
11408 while (psMemRead->lowAddr != 0xffffffff)
11410 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
11412 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11413 if (psMemRead->memoryCall)
11415 cpu.z80IY = psMemRead->memoryCall(dwAddr, psMemRead);
11416 cpu.z80IY |= (UINT32) ((UINT32) psMemRead->memoryCall(dwAddr + 1, psMemRead) << 8);
11418 else
11420 cpu.z80IY = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
11421 cpu.z80IY |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr + 1)) << 8);
11423 psMemRead = NULL;
11424 break;
11426 ++psMemRead;
11429 if (psMemRead)
11431 cpu.z80IY = cpu.z80Base[dwAddr];
11432 cpu.z80IY |= (UINT32) ((UINT32) cpu.z80Base[dwAddr + 1] << 8);
11435 break;
11437 case 0x2b:
11439 sdwCyclesRemaining -= 10;
11440 cpu.z80IY--;
11441 cpu.z80IY &= 0xffff;
11442 break;
11444 case 0x2c:
11446 sdwCyclesRemaining -= 9;
11447 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
11448 cpu.z80F |= bPostIncFlags[cpu.z80YL++];
11449 break;
11451 case 0x2d:
11453 sdwCyclesRemaining -= 9;
11454 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
11455 cpu.z80F |= bPostDecFlags[cpu.z80YL--];
11456 break;
11458 case 0x2e:
11460 sdwCyclesRemaining -= 9;
11461 cpu.z80YL = *pbPC++;
11462 break;
11464 case 0x2f:
11466 InvalidInstruction(2);
11467 break;
11469 case 0x30:
11471 InvalidInstruction(2);
11472 break;
11474 case 0x31:
11476 InvalidInstruction(2);
11477 break;
11479 case 0x32:
11481 InvalidInstruction(2);
11482 break;
11484 case 0x33:
11486 InvalidInstruction(2);
11487 break;
11489 case 0x34:
11491 sdwCyclesRemaining -= 23;
11492 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
11493 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
11494 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
11495 while (psMemRead->lowAddr != 0xffffffff)
11497 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
11499 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11500 if (psMemRead->memoryCall)
11502 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
11504 else
11506 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
11508 psMemRead = NULL;
11509 break;
11511 ++psMemRead;
11514 if (psMemRead)
11516 bTemp = cpu.z80Base[dwAddr];
11519 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
11520 cpu.z80F |= bPostIncFlags[bTemp++];
11521 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
11522 while (psMemWrite->lowAddr != 0xffffffff)
11524 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
11526 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11527 if (psMemWrite->memoryCall)
11529 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
11531 else
11533 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
11535 psMemWrite = NULL;
11536 break;
11538 ++psMemWrite;
11541 if (psMemWrite)
11543 cpu.z80Base[dwAddr] = (UINT8) bTemp;
11546 break;
11548 case 0x35:
11550 sdwCyclesRemaining -= 23;
11551 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
11552 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
11553 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
11554 while (psMemRead->lowAddr != 0xffffffff)
11556 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
11558 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11559 if (psMemRead->memoryCall)
11561 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
11563 else
11565 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
11567 psMemRead = NULL;
11568 break;
11570 ++psMemRead;
11573 if (psMemRead)
11575 bTemp = cpu.z80Base[dwAddr];
11578 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
11579 cpu.z80F |= bPostDecFlags[bTemp--];
11580 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
11581 while (psMemWrite->lowAddr != 0xffffffff)
11583 if ((dwAddr >= psMemWrite->lowAddr) && (dwAddr <= psMemWrite->highAddr))
11585 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11586 if (psMemWrite->memoryCall)
11588 psMemWrite->memoryCall(dwAddr, bTemp, psMemWrite);
11590 else
11592 *((UINT8 *) psMemWrite->pUserArea + (dwAddr - psMemWrite->lowAddr)) = bTemp;
11594 psMemWrite = NULL;
11595 break;
11597 ++psMemWrite;
11600 if (psMemWrite)
11602 cpu.z80Base[dwAddr] = (UINT8) bTemp;
11605 break;
11607 case 0x36:
11609 sdwCyclesRemaining -= 19;
11610 sdwAddr = (INT8) *pbPC++; // Get the offset
11611 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
11612 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
11613 while (psMemWrite->lowAddr != 0xffffffff)
11615 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
11617 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11618 if (psMemWrite->memoryCall)
11620 psMemWrite->memoryCall(sdwAddr, *pbPC++, psMemWrite);
11622 else
11624 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = *pbPC++;
11626 psMemWrite = NULL;
11627 break;
11629 ++psMemWrite;
11632 if (psMemWrite)
11634 cpu.z80Base[sdwAddr] = (UINT8) *pbPC++;
11637 break;
11639 case 0x37:
11641 InvalidInstruction(2);
11642 break;
11644 case 0x38:
11646 InvalidInstruction(2);
11647 break;
11649 case 0x39:
11651 sdwCyclesRemaining -= 15;
11652 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
11653 dwTemp = cpu.z80IY + cpu.z80sp;
11654 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80IY ^ dwTemp ^ cpu.z80sp) >> 8) & Z80_FLAG_HALF_CARRY);
11655 cpu.z80IY = dwTemp & 0xffff;
11656 break;
11658 case 0x3a:
11660 InvalidInstruction(2);
11661 break;
11663 case 0x3b:
11665 InvalidInstruction(2);
11666 break;
11668 case 0x3c:
11670 InvalidInstruction(2);
11671 break;
11673 case 0x3d:
11675 InvalidInstruction(2);
11676 break;
11678 case 0x3e:
11680 InvalidInstruction(2);
11681 break;
11683 case 0x3f:
11685 InvalidInstruction(2);
11686 break;
11688 case 0x40:
11690 InvalidInstruction(2);
11691 break;
11693 case 0x41:
11695 InvalidInstruction(2);
11696 break;
11698 case 0x42:
11700 InvalidInstruction(2);
11701 break;
11703 case 0x43:
11705 InvalidInstruction(2);
11706 break;
11708 case 0x44:
11710 sdwCyclesRemaining -= 9;
11711 cpu.z80B = cpu.z80YH;
11712 break;
11714 case 0x45:
11716 sdwCyclesRemaining -= 9;
11717 cpu.z80B = cpu.z80YL;
11718 break;
11720 case 0x46:
11722 sdwCyclesRemaining -= 19;
11723 sdwAddr = (INT8) *pbPC++; // Get the offset
11724 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
11725 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
11726 while (psMemRead->lowAddr != 0xffffffff)
11728 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
11730 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11731 if (psMemRead->memoryCall)
11733 cpu.z80B = psMemRead->memoryCall(sdwAddr, psMemRead);
11735 else
11737 cpu.z80B = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
11739 psMemRead = NULL;
11740 break;
11742 ++psMemRead;
11745 if (psMemRead)
11747 cpu.z80B = cpu.z80Base[sdwAddr];
11750 break;
11752 case 0x47:
11754 InvalidInstruction(2);
11755 break;
11757 case 0x48:
11759 InvalidInstruction(2);
11760 break;
11762 case 0x49:
11764 InvalidInstruction(2);
11765 break;
11767 case 0x4a:
11769 InvalidInstruction(2);
11770 break;
11772 case 0x4b:
11774 InvalidInstruction(2);
11775 break;
11777 case 0x4c:
11779 sdwCyclesRemaining -= 9;
11780 cpu.z80C = cpu.z80YH;
11781 break;
11783 case 0x4d:
11785 sdwCyclesRemaining -= 9;
11786 cpu.z80C = cpu.z80YL;
11787 break;
11789 case 0x4e:
11791 sdwCyclesRemaining -= 19;
11792 sdwAddr = (INT8) *pbPC++; // Get the offset
11793 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
11794 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
11795 while (psMemRead->lowAddr != 0xffffffff)
11797 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
11799 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11800 if (psMemRead->memoryCall)
11802 cpu.z80C = psMemRead->memoryCall(sdwAddr, psMemRead);
11804 else
11806 cpu.z80C = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
11808 psMemRead = NULL;
11809 break;
11811 ++psMemRead;
11814 if (psMemRead)
11816 cpu.z80C = cpu.z80Base[sdwAddr];
11819 break;
11821 case 0x4f:
11823 InvalidInstruction(2);
11824 break;
11826 case 0x50:
11828 InvalidInstruction(2);
11829 break;
11831 case 0x51:
11833 InvalidInstruction(2);
11834 break;
11836 case 0x52:
11838 InvalidInstruction(2);
11839 break;
11841 case 0x53:
11843 InvalidInstruction(2);
11844 break;
11846 case 0x54:
11848 sdwCyclesRemaining -= 9;
11849 cpu.z80D = cpu.z80YH;
11850 break;
11852 case 0x55:
11854 sdwCyclesRemaining -= 9;
11855 cpu.z80D = cpu.z80YL;
11856 break;
11858 case 0x56:
11860 sdwCyclesRemaining -= 19;
11861 sdwAddr = (INT8) *pbPC++; // Get the offset
11862 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
11863 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
11864 while (psMemRead->lowAddr != 0xffffffff)
11866 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
11868 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11869 if (psMemRead->memoryCall)
11871 cpu.z80D = psMemRead->memoryCall(sdwAddr, psMemRead);
11873 else
11875 cpu.z80D = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
11877 psMemRead = NULL;
11878 break;
11880 ++psMemRead;
11883 if (psMemRead)
11885 cpu.z80D = cpu.z80Base[sdwAddr];
11888 break;
11890 case 0x57:
11892 InvalidInstruction(2);
11893 break;
11895 case 0x58:
11897 InvalidInstruction(2);
11898 break;
11900 case 0x59:
11902 InvalidInstruction(2);
11903 break;
11905 case 0x5a:
11907 InvalidInstruction(2);
11908 break;
11910 case 0x5b:
11912 InvalidInstruction(2);
11913 break;
11915 case 0x5c:
11917 sdwCyclesRemaining -= 9;
11918 cpu.z80E = cpu.z80YH;
11919 break;
11921 case 0x5d:
11923 sdwCyclesRemaining -= 9;
11924 cpu.z80E = cpu.z80YL;
11925 break;
11927 case 0x5e:
11929 sdwCyclesRemaining -= 19;
11930 sdwAddr = (INT8) *pbPC++; // Get the offset
11931 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
11932 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
11933 while (psMemRead->lowAddr != 0xffffffff)
11935 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
11937 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
11938 if (psMemRead->memoryCall)
11940 cpu.z80E = psMemRead->memoryCall(sdwAddr, psMemRead);
11942 else
11944 cpu.z80E = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
11946 psMemRead = NULL;
11947 break;
11949 ++psMemRead;
11952 if (psMemRead)
11954 cpu.z80E = cpu.z80Base[sdwAddr];
11957 break;
11959 case 0x5f:
11961 InvalidInstruction(2);
11962 break;
11964 case 0x60:
11966 sdwCyclesRemaining -= 9;
11967 cpu.z80YH = cpu.z80B;
11968 break;
11970 case 0x61:
11972 sdwCyclesRemaining -= 9;
11973 cpu.z80YH = cpu.z80C;
11974 break;
11976 case 0x62:
11978 sdwCyclesRemaining -= 9;
11979 cpu.z80YH = cpu.z80D;
11980 break;
11982 case 0x63:
11984 sdwCyclesRemaining -= 9;
11985 cpu.z80YH = cpu.z80E;
11986 break;
11988 case 0x64:
11990 sdwCyclesRemaining -= 9;
11991 break;
11993 case 0x65:
11995 sdwCyclesRemaining -= 9;
11996 cpu.z80YH = cpu.z80YL;
11997 break;
11999 case 0x66:
12001 sdwCyclesRemaining -= 19;
12002 sdwAddr = (INT8) *pbPC++; // Get the offset
12003 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12004 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12005 while (psMemRead->lowAddr != 0xffffffff)
12007 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
12009 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12010 if (psMemRead->memoryCall)
12012 cpu.z80H = psMemRead->memoryCall(sdwAddr, psMemRead);
12014 else
12016 cpu.z80H = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
12018 psMemRead = NULL;
12019 break;
12021 ++psMemRead;
12024 if (psMemRead)
12026 cpu.z80H = cpu.z80Base[sdwAddr];
12029 break;
12031 case 0x67:
12033 sdwCyclesRemaining -= 9;
12034 cpu.z80YH = cpu.z80A;
12035 break;
12037 case 0x68:
12039 sdwCyclesRemaining -= 9;
12040 cpu.z80YL = cpu.z80B;
12041 break;
12043 case 0x69:
12045 sdwCyclesRemaining -= 9;
12046 cpu.z80YL = cpu.z80C;
12047 break;
12049 case 0x6a:
12051 sdwCyclesRemaining -= 9;
12052 cpu.z80YL = cpu.z80D;
12053 break;
12055 case 0x6b:
12057 sdwCyclesRemaining -= 9;
12058 cpu.z80YL = cpu.z80E;
12059 break;
12061 case 0x6c:
12063 sdwCyclesRemaining -= 9;
12064 cpu.z80YL = cpu.z80YH;
12065 break;
12067 case 0x6d:
12069 sdwCyclesRemaining -= 9;
12070 break;
12072 case 0x6e:
12074 sdwCyclesRemaining -= 19;
12075 sdwAddr = (INT8) *pbPC++; // Get the offset
12076 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12077 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12078 while (psMemRead->lowAddr != 0xffffffff)
12080 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
12082 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12083 if (psMemRead->memoryCall)
12085 cpu.z80L = psMemRead->memoryCall(sdwAddr, psMemRead);
12087 else
12089 cpu.z80L = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
12091 psMemRead = NULL;
12092 break;
12094 ++psMemRead;
12097 if (psMemRead)
12099 cpu.z80L = cpu.z80Base[sdwAddr];
12102 break;
12104 case 0x6f:
12106 sdwCyclesRemaining -= 9;
12107 cpu.z80YL = cpu.z80A;
12108 break;
12110 case 0x70:
12112 sdwCyclesRemaining -= 19;
12113 sdwAddr = (INT8) *pbPC++; // Get the offset
12114 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12115 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
12116 while (psMemWrite->lowAddr != 0xffffffff)
12118 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
12120 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12121 if (psMemWrite->memoryCall)
12123 psMemWrite->memoryCall(sdwAddr, cpu.z80B, psMemWrite);
12125 else
12127 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80B;
12129 psMemWrite = NULL;
12130 break;
12132 ++psMemWrite;
12135 if (psMemWrite)
12137 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80B;
12140 break;
12142 case 0x71:
12144 sdwCyclesRemaining -= 19;
12145 sdwAddr = (INT8) *pbPC++; // Get the offset
12146 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12147 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
12148 while (psMemWrite->lowAddr != 0xffffffff)
12150 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
12152 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12153 if (psMemWrite->memoryCall)
12155 psMemWrite->memoryCall(sdwAddr, cpu.z80C, psMemWrite);
12157 else
12159 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80C;
12161 psMemWrite = NULL;
12162 break;
12164 ++psMemWrite;
12167 if (psMemWrite)
12169 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80C;
12172 break;
12174 case 0x72:
12176 sdwCyclesRemaining -= 19;
12177 sdwAddr = (INT8) *pbPC++; // Get the offset
12178 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12179 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
12180 while (psMemWrite->lowAddr != 0xffffffff)
12182 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
12184 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12185 if (psMemWrite->memoryCall)
12187 psMemWrite->memoryCall(sdwAddr, cpu.z80D, psMemWrite);
12189 else
12191 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80D;
12193 psMemWrite = NULL;
12194 break;
12196 ++psMemWrite;
12199 if (psMemWrite)
12201 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80D;
12204 break;
12206 case 0x73:
12208 sdwCyclesRemaining -= 19;
12209 sdwAddr = (INT8) *pbPC++; // Get the offset
12210 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12211 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
12212 while (psMemWrite->lowAddr != 0xffffffff)
12214 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
12216 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12217 if (psMemWrite->memoryCall)
12219 psMemWrite->memoryCall(sdwAddr, cpu.z80E, psMemWrite);
12221 else
12223 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80E;
12225 psMemWrite = NULL;
12226 break;
12228 ++psMemWrite;
12231 if (psMemWrite)
12233 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80E;
12236 break;
12238 case 0x74:
12240 sdwCyclesRemaining -= 19;
12241 sdwAddr = (INT8) *pbPC++; // Get the offset
12242 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12243 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
12244 while (psMemWrite->lowAddr != 0xffffffff)
12246 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
12248 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12249 if (psMemWrite->memoryCall)
12251 psMemWrite->memoryCall(sdwAddr, cpu.z80H, psMemWrite);
12253 else
12255 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80H;
12257 psMemWrite = NULL;
12258 break;
12260 ++psMemWrite;
12263 if (psMemWrite)
12265 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80H;
12268 break;
12270 case 0x75:
12272 sdwCyclesRemaining -= 19;
12273 sdwAddr = (INT8) *pbPC++; // Get the offset
12274 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12275 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
12276 while (psMemWrite->lowAddr != 0xffffffff)
12278 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
12280 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12281 if (psMemWrite->memoryCall)
12283 psMemWrite->memoryCall(sdwAddr, cpu.z80L, psMemWrite);
12285 else
12287 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80L;
12289 psMemWrite = NULL;
12290 break;
12292 ++psMemWrite;
12295 if (psMemWrite)
12297 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80L;
12300 break;
12302 case 0x76:
12304 sdwCyclesRemaining -= 19;
12305 InvalidInstruction(2);
12306 break;
12308 case 0x77:
12310 sdwCyclesRemaining -= 19;
12311 sdwAddr = (INT8) *pbPC++; // Get the offset
12312 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12313 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
12314 while (psMemWrite->lowAddr != 0xffffffff)
12316 if ((sdwAddr >= psMemWrite->lowAddr) && (sdwAddr <= psMemWrite->highAddr))
12318 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12319 if (psMemWrite->memoryCall)
12321 psMemWrite->memoryCall(sdwAddr, cpu.z80A, psMemWrite);
12323 else
12325 *((UINT8 *) psMemWrite->pUserArea + (sdwAddr - psMemWrite->lowAddr)) = cpu.z80A;
12327 psMemWrite = NULL;
12328 break;
12330 ++psMemWrite;
12333 if (psMemWrite)
12335 cpu.z80Base[sdwAddr] = (UINT8) cpu.z80A;
12338 break;
12340 case 0x78:
12342 InvalidInstruction(2);
12343 break;
12345 case 0x79:
12347 InvalidInstruction(2);
12348 break;
12350 case 0x7a:
12352 InvalidInstruction(2);
12353 break;
12355 case 0x7b:
12357 InvalidInstruction(2);
12358 break;
12360 case 0x7c:
12362 sdwCyclesRemaining -= 9;
12363 cpu.z80A = cpu.z80YH;
12364 break;
12366 case 0x7d:
12368 sdwCyclesRemaining -= 9;
12369 cpu.z80A = cpu.z80YL;
12370 break;
12372 case 0x7e:
12374 sdwCyclesRemaining -= 19;
12375 sdwAddr = (INT8) *pbPC++; // Get the offset
12376 sdwAddr = ((INT32) cpu.z80IY + sdwAddr) & 0xffff;
12377 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12378 while (psMemRead->lowAddr != 0xffffffff)
12380 if ((sdwAddr >= psMemRead->lowAddr) && (sdwAddr <= psMemRead->highAddr))
12382 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12383 if (psMemRead->memoryCall)
12385 cpu.z80A = psMemRead->memoryCall(sdwAddr, psMemRead);
12387 else
12389 cpu.z80A = *((UINT8 *) psMemRead->pUserArea + (sdwAddr - psMemRead->lowAddr));
12391 psMemRead = NULL;
12392 break;
12394 ++psMemRead;
12397 if (psMemRead)
12399 cpu.z80A = cpu.z80Base[sdwAddr];
12402 break;
12404 case 0x7f:
12406 InvalidInstruction(2);
12407 break;
12409 case 0x80:
12411 InvalidInstruction(2);
12412 break;
12414 case 0x81:
12416 InvalidInstruction(2);
12417 break;
12419 case 0x82:
12421 InvalidInstruction(2);
12422 break;
12424 case 0x83:
12426 InvalidInstruction(2);
12427 break;
12429 case 0x84:
12431 sdwCyclesRemaining -= 9;
12432 bTemp2 = cpu.z80A + cpu.z80YH;
12433 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12434 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12435 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80YH];
12436 InvalidInstruction(2);
12437 break;
12439 case 0x85:
12441 sdwCyclesRemaining -= 9;
12442 bTemp2 = cpu.z80A + cpu.z80YL;
12443 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12444 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12445 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80YL];
12446 InvalidInstruction(2);
12447 break;
12449 case 0x86:
12451 sdwCyclesRemaining -= 19;
12452 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
12453 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
12454 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12455 while (psMemRead->lowAddr != 0xffffffff)
12457 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
12459 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12460 if (psMemRead->memoryCall)
12462 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
12464 else
12466 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
12468 psMemRead = NULL;
12469 break;
12471 ++psMemRead;
12474 if (psMemRead)
12476 bTemp = cpu.z80Base[dwAddr];
12479 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12480 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12481 pbAddAdcTable[((UINT32) cpu.z80A << 8) | bTemp];
12482 cpu.z80A += bTemp;
12483 break;
12485 case 0x87:
12487 InvalidInstruction(2);
12488 break;
12490 case 0x88:
12492 InvalidInstruction(2);
12493 break;
12495 case 0x89:
12497 InvalidInstruction(2);
12498 break;
12500 case 0x8a:
12502 InvalidInstruction(2);
12503 break;
12505 case 0x8b:
12507 InvalidInstruction(2);
12508 break;
12510 case 0x8c:
12512 sdwCyclesRemaining -= 9;
12513 bTemp2 = cpu.z80A + cpu.z80YH + (cpu.z80F & Z80_FLAG_CARRY);
12514 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12515 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12516 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80YH | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
12517 InvalidInstruction(2);
12518 break;
12520 case 0x8d:
12522 sdwCyclesRemaining -= 9;
12523 bTemp2 = cpu.z80A + cpu.z80YL + (cpu.z80F & Z80_FLAG_CARRY);
12524 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12525 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12526 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80YL | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
12527 InvalidInstruction(2);
12528 break;
12530 case 0x8e:
12532 sdwCyclesRemaining -= 19;
12533 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
12534 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
12535 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12536 while (psMemRead->lowAddr != 0xffffffff)
12538 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
12540 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12541 if (psMemRead->memoryCall)
12543 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
12545 else
12547 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
12549 psMemRead = NULL;
12550 break;
12552 ++psMemRead;
12555 if (psMemRead)
12557 bTemp = cpu.z80Base[dwAddr];
12560 bTemp2 = (cpu.z80F & Z80_FLAG_CARRY);
12561 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12562 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12563 pbAddAdcTable[((UINT32) cpu.z80A << 8) | bTemp | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
12564 cpu.z80A += bTemp + bTemp2;
12565 break;
12567 case 0x8f:
12569 InvalidInstruction(2);
12570 break;
12572 case 0x90:
12574 InvalidInstruction(2);
12575 break;
12577 case 0x91:
12579 InvalidInstruction(2);
12580 break;
12582 case 0x92:
12584 InvalidInstruction(2);
12585 break;
12587 case 0x93:
12589 InvalidInstruction(2);
12590 break;
12592 case 0x94:
12594 sdwCyclesRemaining -= 9;
12595 bTemp2 = cpu.z80A - cpu.z80YH;
12596 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12597 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12598 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80YH];
12599 InvalidInstruction(2);
12600 break;
12602 case 0x95:
12604 sdwCyclesRemaining -= 9;
12605 bTemp2 = cpu.z80A - cpu.z80YL;
12606 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12607 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12608 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80YL];
12609 InvalidInstruction(2);
12610 break;
12612 case 0x96:
12614 sdwCyclesRemaining -= 19;
12615 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
12616 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
12617 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12618 while (psMemRead->lowAddr != 0xffffffff)
12620 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
12622 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12623 if (psMemRead->memoryCall)
12625 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
12627 else
12629 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
12631 psMemRead = NULL;
12632 break;
12634 ++psMemRead;
12637 if (psMemRead)
12639 bTemp = cpu.z80Base[dwAddr];
12642 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12643 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12644 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp];
12645 cpu.z80A -= bTemp;
12646 break;
12648 case 0x97:
12650 InvalidInstruction(2);
12651 break;
12653 case 0x98:
12655 InvalidInstruction(2);
12656 break;
12658 case 0x99:
12660 InvalidInstruction(2);
12661 break;
12663 case 0x9a:
12665 InvalidInstruction(2);
12666 break;
12668 case 0x9b:
12670 InvalidInstruction(2);
12671 break;
12673 case 0x9c:
12675 sdwCyclesRemaining -= 9;
12676 bTemp2 = cpu.z80A - cpu.z80YH - (cpu.z80F & Z80_FLAG_CARRY);
12677 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12678 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12679 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80YH | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
12680 InvalidInstruction(2);
12681 break;
12683 case 0x9d:
12685 sdwCyclesRemaining -= 9;
12686 bTemp2 = cpu.z80A - cpu.z80YL - (cpu.z80F & Z80_FLAG_CARRY);
12687 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12688 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12689 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80YL | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
12690 InvalidInstruction(2);
12691 break;
12693 case 0x9e:
12695 sdwCyclesRemaining -= 19;
12696 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
12697 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
12698 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12699 while (psMemRead->lowAddr != 0xffffffff)
12701 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
12703 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12704 if (psMemRead->memoryCall)
12706 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
12708 else
12710 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
12712 psMemRead = NULL;
12713 break;
12715 ++psMemRead;
12718 if (psMemRead)
12720 bTemp = cpu.z80Base[dwAddr];
12723 bTemp2 = cpu.z80A;
12724 cpu.z80A = cpu.z80A - bTemp - (cpu.z80F & Z80_FLAG_CARRY);
12725 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
12726 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
12727 pbSubSbcTable[((UINT32) bTemp2 << 8) | bTemp | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
12728 break;
12730 case 0x9f:
12732 InvalidInstruction(2);
12733 break;
12735 case 0xa0:
12737 InvalidInstruction(2);
12738 break;
12740 case 0xa1:
12742 InvalidInstruction(2);
12743 break;
12745 case 0xa2:
12747 InvalidInstruction(2);
12748 break;
12750 case 0xa3:
12752 InvalidInstruction(2);
12753 break;
12755 case 0xa4:
12757 sdwCyclesRemaining -= 9;
12758 cpu.z80A &= cpu.z80YH;
12759 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12760 cpu.z80F |= bPostANDFlags[cpu.z80A];
12762 InvalidInstruction(2);
12763 break;
12765 case 0xa5:
12767 sdwCyclesRemaining -= 9;
12768 cpu.z80A &= cpu.z80YL;
12769 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12770 cpu.z80F |= bPostANDFlags[cpu.z80A];
12772 InvalidInstruction(2);
12773 break;
12775 case 0xa6:
12777 sdwCyclesRemaining -= 19;
12778 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
12779 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
12780 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12781 while (psMemRead->lowAddr != 0xffffffff)
12783 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
12785 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12786 if (psMemRead->memoryCall)
12788 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
12790 else
12792 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
12794 psMemRead = NULL;
12795 break;
12797 ++psMemRead;
12800 if (psMemRead)
12802 bTemp = cpu.z80Base[dwAddr];
12805 cpu.z80A &= bTemp;
12806 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12807 cpu.z80F |= bPostANDFlags[cpu.z80A];
12809 break;
12811 case 0xa7:
12813 InvalidInstruction(2);
12814 break;
12816 case 0xa8:
12818 InvalidInstruction(2);
12819 break;
12821 case 0xa9:
12823 InvalidInstruction(2);
12824 break;
12826 case 0xaa:
12828 InvalidInstruction(2);
12829 break;
12831 case 0xab:
12833 InvalidInstruction(2);
12834 break;
12836 case 0xac:
12838 sdwCyclesRemaining -= 9;
12839 cpu.z80A ^= cpu.z80YH;
12840 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12841 cpu.z80F |= bPostORFlags[cpu.z80A];
12843 InvalidInstruction(2);
12844 break;
12846 case 0xad:
12848 sdwCyclesRemaining -= 9;
12849 cpu.z80A ^= cpu.z80YL;
12850 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12851 cpu.z80F |= bPostORFlags[cpu.z80A];
12853 InvalidInstruction(2);
12854 break;
12856 case 0xae:
12858 sdwCyclesRemaining -= 19;
12859 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
12860 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
12861 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12862 while (psMemRead->lowAddr != 0xffffffff)
12864 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
12866 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12867 if (psMemRead->memoryCall)
12869 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
12871 else
12873 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
12875 psMemRead = NULL;
12876 break;
12878 ++psMemRead;
12881 if (psMemRead)
12883 bTemp = cpu.z80Base[dwAddr];
12886 cpu.z80A ^= bTemp;
12887 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12888 cpu.z80F |= bPostORFlags[cpu.z80A];
12890 break;
12892 case 0xaf:
12894 InvalidInstruction(2);
12895 break;
12897 case 0xb0:
12899 InvalidInstruction(2);
12900 break;
12902 case 0xb1:
12904 InvalidInstruction(2);
12905 break;
12907 case 0xb2:
12909 InvalidInstruction(2);
12910 break;
12912 case 0xb3:
12914 InvalidInstruction(2);
12915 break;
12917 case 0xb4:
12919 sdwCyclesRemaining -= 9;
12920 cpu.z80A |= cpu.z80YH;
12921 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12922 cpu.z80F |= bPostORFlags[cpu.z80A];
12924 InvalidInstruction(2);
12925 break;
12927 case 0xb5:
12929 sdwCyclesRemaining -= 9;
12930 cpu.z80A |= cpu.z80YL;
12931 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12932 cpu.z80F |= bPostORFlags[cpu.z80A];
12934 InvalidInstruction(2);
12935 break;
12937 case 0xb6:
12939 sdwCyclesRemaining -= 19;
12940 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
12941 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
12942 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
12943 while (psMemRead->lowAddr != 0xffffffff)
12945 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
12947 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
12948 if (psMemRead->memoryCall)
12950 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
12952 else
12954 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
12956 psMemRead = NULL;
12957 break;
12959 ++psMemRead;
12962 if (psMemRead)
12964 bTemp = cpu.z80Base[dwAddr];
12967 cpu.z80A |= bTemp;
12968 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
12969 cpu.z80F |= bPostORFlags[cpu.z80A];
12971 break;
12973 case 0xb7:
12975 InvalidInstruction(2);
12976 break;
12978 case 0xb8:
12980 InvalidInstruction(2);
12981 break;
12983 case 0xb9:
12985 InvalidInstruction(2);
12986 break;
12988 case 0xba:
12990 InvalidInstruction(2);
12991 break;
12993 case 0xbb:
12995 InvalidInstruction(2);
12996 break;
12998 case 0xbc:
13000 sdwCyclesRemaining -= 9;
13001 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
13002 cpu.z80F |= bPostORFlags[cpu.z80A];
13004 InvalidInstruction(2);
13005 break;
13007 case 0xbd:
13009 sdwCyclesRemaining -= 9;
13010 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
13011 cpu.z80F |= bPostORFlags[cpu.z80A];
13013 InvalidInstruction(2);
13014 break;
13016 case 0xbe:
13018 sdwCyclesRemaining -= 19;
13019 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
13020 dwAddr = (sdwAddr + (INT32) cpu.z80IY) & 0xffff;
13021 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
13022 while (psMemRead->lowAddr != 0xffffffff)
13024 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
13026 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13027 if (psMemRead->memoryCall)
13029 bTemp = psMemRead->memoryCall(dwAddr, psMemRead);
13031 else
13033 bTemp = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
13035 psMemRead = NULL;
13036 break;
13038 ++psMemRead;
13041 if (psMemRead)
13043 bTemp = cpu.z80Base[dwAddr];
13046 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
13047 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
13048 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp];
13049 break;
13051 case 0xbf:
13053 InvalidInstruction(2);
13054 break;
13056 case 0xc0:
13058 InvalidInstruction(2);
13059 break;
13061 case 0xc1:
13063 InvalidInstruction(2);
13064 break;
13066 case 0xc2:
13068 InvalidInstruction(2);
13069 break;
13071 case 0xc3:
13073 InvalidInstruction(2);
13074 break;
13076 case 0xc4:
13078 InvalidInstruction(2);
13079 break;
13081 case 0xc5:
13083 InvalidInstruction(2);
13084 break;
13086 case 0xc6:
13088 InvalidInstruction(2);
13089 break;
13091 case 0xc7:
13093 InvalidInstruction(2);
13094 break;
13096 case 0xc8:
13098 InvalidInstruction(2);
13099 break;
13101 case 0xc9:
13103 InvalidInstruction(2);
13104 break;
13106 case 0xca:
13108 InvalidInstruction(2);
13109 break;
13111 case 0xcb:
13113 DDFDCBHandler(1);
13114 break;
13116 case 0xcc:
13118 InvalidInstruction(2);
13119 break;
13121 case 0xcd:
13123 InvalidInstruction(2);
13124 break;
13126 case 0xce:
13128 InvalidInstruction(2);
13129 break;
13131 case 0xcf:
13133 InvalidInstruction(2);
13134 break;
13136 case 0xd0:
13138 InvalidInstruction(2);
13139 break;
13141 case 0xd1:
13143 InvalidInstruction(2);
13144 break;
13146 case 0xd2:
13148 InvalidInstruction(2);
13149 break;
13151 case 0xd3:
13153 InvalidInstruction(2);
13154 break;
13156 case 0xd4:
13158 InvalidInstruction(2);
13159 break;
13161 case 0xd5:
13163 InvalidInstruction(2);
13164 break;
13166 case 0xd6:
13168 InvalidInstruction(2);
13169 break;
13171 case 0xd7:
13173 InvalidInstruction(2);
13174 break;
13176 case 0xd8:
13178 InvalidInstruction(2);
13179 break;
13181 case 0xd9:
13183 InvalidInstruction(2);
13184 break;
13186 case 0xda:
13188 InvalidInstruction(2);
13189 break;
13191 case 0xdb:
13193 InvalidInstruction(2);
13194 break;
13196 case 0xdc:
13198 InvalidInstruction(2);
13199 break;
13201 case 0xdd:
13203 InvalidInstruction(2);
13204 break;
13206 case 0xde:
13208 InvalidInstruction(2);
13209 break;
13211 case 0xdf:
13213 InvalidInstruction(2);
13214 break;
13216 case 0xe0:
13218 InvalidInstruction(2);
13219 break;
13221 case 0xe1:
13223 sdwCyclesRemaining -= 14;
13224 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
13225 while (psMemRead->lowAddr != 0xffffffff)
13227 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
13229 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13230 if (psMemRead->memoryCall)
13232 cpu.z80IY = psMemRead->memoryCall(cpu.z80sp, psMemRead);
13233 cpu.z80IY |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
13235 else
13237 cpu.z80IY = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
13238 cpu.z80IY |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
13240 psMemRead = NULL;
13241 break;
13243 ++psMemRead;
13246 if (psMemRead)
13248 cpu.z80IY = cpu.z80Base[cpu.z80sp];
13249 cpu.z80IY |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
13252 cpu.z80sp += 2;
13253 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
13254 break;
13256 case 0xe2:
13258 InvalidInstruction(2);
13259 break;
13261 case 0xe3:
13263 sdwCyclesRemaining -= 23;
13264 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
13265 while (psMemRead->lowAddr != 0xffffffff)
13267 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
13269 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13270 if (psMemRead->memoryCall)
13272 dwAddr = psMemRead->memoryCall(cpu.z80sp, psMemRead);
13273 dwAddr |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
13275 else
13277 dwAddr = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
13278 dwAddr |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
13280 psMemRead = NULL;
13281 break;
13283 ++psMemRead;
13286 if (psMemRead)
13288 dwAddr = cpu.z80Base[cpu.z80sp];
13289 dwAddr |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
13292 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
13293 while (psMemWrite->lowAddr != 0xffffffff)
13295 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
13297 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13298 if (psMemWrite->memoryCall)
13300 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80IY & 0xff), psMemWrite);
13301 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80IY >> 8), psMemWrite);
13303 else
13305 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80IY;
13306 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80IY >> 8;
13308 psMemWrite = NULL;
13309 break;
13311 ++psMemWrite;
13314 if (psMemWrite)
13316 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80IY;
13317 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80IY >> 8);
13320 cpu.z80IY = dwAddr;
13321 break;
13323 case 0xe4:
13325 InvalidInstruction(2);
13326 break;
13328 case 0xe5:
13330 sdwCyclesRemaining -= 15;
13331 cpu.z80sp -= 2;
13332 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
13333 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
13334 while (psMemWrite->lowAddr != 0xffffffff)
13336 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
13338 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13339 if (psMemWrite->memoryCall)
13341 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80IY & 0xff), psMemWrite);
13342 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80IY >> 8), psMemWrite);
13344 else
13346 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80IY;
13347 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80IY >> 8;
13349 psMemWrite = NULL;
13350 break;
13352 ++psMemWrite;
13355 if (psMemWrite)
13357 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80IY;
13358 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80IY >> 8);
13361 break;
13363 case 0xe6:
13365 InvalidInstruction(2);
13366 break;
13368 case 0xe7:
13370 InvalidInstruction(2);
13371 break;
13373 case 0xe8:
13375 InvalidInstruction(2);
13376 break;
13378 case 0xe9:
13380 sdwCyclesRemaining -= 8;
13381 pbPC = cpu.z80Base + cpu.z80IY;
13382 break;
13384 case 0xea:
13386 InvalidInstruction(2);
13387 break;
13389 case 0xeb:
13391 InvalidInstruction(2);
13392 break;
13394 case 0xec:
13396 InvalidInstruction(2);
13397 break;
13399 case 0xed:
13401 InvalidInstruction(2);
13402 break;
13404 case 0xee:
13406 InvalidInstruction(2);
13407 break;
13409 case 0xef:
13411 InvalidInstruction(2);
13412 break;
13414 case 0xf0:
13416 InvalidInstruction(2);
13417 break;
13419 case 0xf1:
13421 InvalidInstruction(2);
13422 break;
13424 case 0xf2:
13426 InvalidInstruction(2);
13427 break;
13429 case 0xf3:
13431 InvalidInstruction(2);
13432 break;
13434 case 0xf4:
13436 InvalidInstruction(2);
13437 break;
13439 case 0xf5:
13441 InvalidInstruction(2);
13442 break;
13444 case 0xf6:
13446 InvalidInstruction(2);
13447 break;
13449 case 0xf7:
13451 InvalidInstruction(2);
13452 break;
13454 case 0xf8:
13456 InvalidInstruction(2);
13457 break;
13459 case 0xf9:
13461 sdwCyclesRemaining -= 10;
13462 cpu.z80sp = cpu.z80IY;
13463 break;
13465 case 0xfa:
13467 InvalidInstruction(2);
13468 break;
13470 case 0xfb:
13472 InvalidInstruction(2);
13473 break;
13475 case 0xfc:
13477 InvalidInstruction(2);
13478 break;
13480 case 0xfd:
13482 InvalidInstruction(2);
13483 break;
13485 case 0xfe:
13487 InvalidInstruction(2);
13488 break;
13490 case 0xff:
13492 InvalidInstruction(2);
13493 break;
13497 /* Main execution entry point */
13499 UINT32 mz80exec(UINT32 dwCycles)
13501 UINT8 bOpcode;
13503 dwReturnCode = 0x80000000; /* Assume it'll work */
13504 sdwCyclesRemaining = dwCycles;
13505 dwOriginalCycles = dwCycles;
13506 if (cpu.z80halted)
13508 dwElapsedTicks += dwCycles;
13509 return(0x80000000);
13512 pbPC = cpu.z80Base + cpu.z80pc;
13514 while (sdwCyclesRemaining > 0)
13516 bOpcode = *pbPC++;
13517 switch (bOpcode)
13519 case 0x00:
13521 sdwCyclesRemaining -= 4;
13522 /* Intentionally not doing anything - NOP! */
13523 break;
13525 case 0x01:
13527 sdwCyclesRemaining -= 10;
13528 cpu.z80BC = *pbPC++; /* LSB First */
13529 cpu.z80BC |= (((UINT32) *pbPC++ << 8)); /* Now the MSB */
13530 break;
13532 case 0x02:
13534 sdwCyclesRemaining -= 7;
13535 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
13536 while (psMemWrite->lowAddr != 0xffffffff)
13538 if ((cpu.z80BC >= psMemWrite->lowAddr) && (cpu.z80BC <= psMemWrite->highAddr))
13540 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13541 if (psMemWrite->memoryCall)
13543 psMemWrite->memoryCall(cpu.z80BC, cpu.z80A, psMemWrite);
13545 else
13547 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80BC - psMemWrite->lowAddr)) = cpu.z80A;
13549 psMemWrite = NULL;
13550 break;
13552 ++psMemWrite;
13555 if (psMemWrite)
13557 cpu.z80Base[cpu.z80BC] = (UINT8) cpu.z80A;
13560 break;
13562 case 0x03:
13564 sdwCyclesRemaining -= 6;
13565 cpu.z80BC++;
13566 cpu.z80BC &= 0xffff;
13567 break;
13569 case 0x04:
13571 sdwCyclesRemaining -= 4;
13572 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
13573 cpu.z80F |= bPostIncFlags[cpu.z80B++];
13574 break;
13576 case 0x05:
13578 sdwCyclesRemaining -= 4;
13579 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY);
13580 cpu.z80F |= bPostDecFlags[cpu.z80B--];
13581 break;
13583 case 0x06:
13585 sdwCyclesRemaining -= 7;
13586 cpu.z80B = *pbPC++; /* Get immediate byte into register */
13587 break;
13589 case 0x07:
13591 sdwCyclesRemaining -= 4;
13592 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
13593 cpu.z80F |= (cpu.z80A >> 7);
13594 cpu.z80A = (cpu.z80A << 1) | (cpu.z80A >> 7);
13595 break;
13597 case 0x08:
13599 sdwCyclesRemaining -= 4;
13600 dwAddr = (UINT32) cpu.z80AF;
13601 cpu.z80AF = cpu.z80afprime;
13602 cpu.z80afprime = dwAddr;
13603 break;
13605 case 0x09:
13607 sdwCyclesRemaining -= 11;
13608 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
13609 dwTemp = cpu.z80HL + cpu.z80BC;
13610 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80HL ^ dwTemp ^ cpu.z80BC) >> 8) & Z80_FLAG_HALF_CARRY);
13611 cpu.z80HL = dwTemp & 0xffff;
13612 break;
13614 case 0x0a:
13616 sdwCyclesRemaining -= 7;
13617 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
13618 while (psMemRead->lowAddr != 0xffffffff)
13620 if ((cpu.z80BC >= psMemRead->lowAddr) && (cpu.z80BC <= psMemRead->highAddr))
13622 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13623 if (psMemRead->memoryCall)
13625 cpu.z80A = psMemRead->memoryCall(cpu.z80BC, psMemRead);
13627 else
13629 cpu.z80A = *((UINT8 *) psMemRead->pUserArea + (cpu.z80BC - psMemRead->lowAddr));
13631 psMemRead = NULL;
13632 break;
13634 ++psMemRead;
13637 if (psMemRead)
13639 cpu.z80A = cpu.z80Base[cpu.z80BC];
13642 break;
13644 case 0x0b:
13646 sdwCyclesRemaining -= 6;
13647 cpu.z80BC--;
13648 cpu.z80BC &= 0xffff;
13649 break;
13651 case 0x0c:
13653 sdwCyclesRemaining -= 4;
13654 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
13655 cpu.z80F |= bPostIncFlags[cpu.z80C++];
13656 break;
13658 case 0x0d:
13660 sdwCyclesRemaining -= 4;
13661 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY);
13662 cpu.z80F |= bPostDecFlags[cpu.z80C--];
13663 break;
13665 case 0x0e:
13667 sdwCyclesRemaining -= 7;
13668 cpu.z80C = *pbPC++; /* Get immediate byte into register */
13669 break;
13671 case 0x0f:
13673 sdwCyclesRemaining -= 4;
13674 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
13675 cpu.z80F |= (cpu.z80A & Z80_FLAG_CARRY);
13676 cpu.z80A = (cpu.z80A >> 1) | (cpu.z80A << 7);
13677 break;
13679 case 0x10:
13681 sdwCyclesRemaining -= 8;
13682 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
13683 if (--cpu.z80B)
13685 dwElapsedTicks += 5; /* 5 More for jump taken */
13686 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13687 sdwAddr = (sdwAddr + (INT32) cpu.z80pc) & 0xffff;
13688 pbPC = cpu.z80Base + sdwAddr; /* Normalize the address */
13690 break;
13692 case 0x11:
13694 sdwCyclesRemaining -= 10;
13695 cpu.z80DE = *pbPC++; /* LSB First */
13696 cpu.z80DE |= (((UINT32) *pbPC++ << 8)); /* Now the MSB */
13697 break;
13699 case 0x12:
13701 sdwCyclesRemaining -= 7;
13702 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
13703 while (psMemWrite->lowAddr != 0xffffffff)
13705 if ((cpu.z80DE >= psMemWrite->lowAddr) && (cpu.z80DE <= psMemWrite->highAddr))
13707 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13708 if (psMemWrite->memoryCall)
13710 psMemWrite->memoryCall(cpu.z80DE, cpu.z80A, psMemWrite);
13712 else
13714 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80DE - psMemWrite->lowAddr)) = cpu.z80A;
13716 psMemWrite = NULL;
13717 break;
13719 ++psMemWrite;
13722 if (psMemWrite)
13724 cpu.z80Base[cpu.z80DE] = (UINT8) cpu.z80A;
13727 break;
13729 case 0x13:
13731 sdwCyclesRemaining -= 6;
13732 cpu.z80DE++;
13733 cpu.z80DE &= 0xffff;
13734 break;
13736 case 0x14:
13738 sdwCyclesRemaining -= 4;
13739 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
13740 cpu.z80F |= bPostIncFlags[cpu.z80D++];
13741 break;
13743 case 0x15:
13745 sdwCyclesRemaining -= 4;
13746 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY);
13747 cpu.z80F |= bPostDecFlags[cpu.z80D--];
13748 break;
13750 case 0x16:
13752 sdwCyclesRemaining -= 7;
13753 cpu.z80D = *pbPC++; /* Get immediate byte into register */
13754 break;
13756 case 0x17:
13758 sdwCyclesRemaining -= 4;
13759 bTemp = cpu.z80A >> 7;
13760 cpu.z80A = (cpu.z80A << 1) | (cpu.z80F & Z80_FLAG_CARRY);
13761 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY)) | bTemp;
13762 break;
13764 case 0x18:
13766 sdwCyclesRemaining -= 12;
13767 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
13768 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13769 sdwAddr = (sdwAddr + (INT32) cpu.z80pc) & 0xffff;
13771 sdwCyclesRemaining -= 5;
13772 pbPC = cpu.z80Base + sdwAddr; /* Normalize the address */
13774 break;
13776 case 0x19:
13778 sdwCyclesRemaining -= 11;
13779 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
13780 dwTemp = cpu.z80HL + cpu.z80DE;
13781 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80HL ^ dwTemp ^ cpu.z80DE) >> 8) & Z80_FLAG_HALF_CARRY);
13782 cpu.z80HL = dwTemp & 0xffff;
13783 break;
13785 case 0x1a:
13787 sdwCyclesRemaining -= 7;
13788 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
13789 while (psMemRead->lowAddr != 0xffffffff)
13791 if ((cpu.z80DE >= psMemRead->lowAddr) && (cpu.z80DE <= psMemRead->highAddr))
13793 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13794 if (psMemRead->memoryCall)
13796 cpu.z80A = psMemRead->memoryCall(cpu.z80DE, psMemRead);
13798 else
13800 cpu.z80A = *((UINT8 *) psMemRead->pUserArea + (cpu.z80DE - psMemRead->lowAddr));
13802 psMemRead = NULL;
13803 break;
13805 ++psMemRead;
13808 if (psMemRead)
13810 cpu.z80A = cpu.z80Base[cpu.z80DE];
13813 break;
13815 case 0x1b:
13817 sdwCyclesRemaining -= 6;
13818 cpu.z80DE--;
13819 cpu.z80DE &= 0xffff;
13820 break;
13822 case 0x1c:
13824 sdwCyclesRemaining -= 4;
13825 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
13826 cpu.z80F |= bPostIncFlags[cpu.z80E++];
13827 break;
13829 case 0x1d:
13831 sdwCyclesRemaining -= 4;
13832 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY);
13833 cpu.z80F |= bPostDecFlags[cpu.z80E--];
13834 break;
13836 case 0x1e:
13838 sdwCyclesRemaining -= 7;
13839 cpu.z80E = *pbPC++; /* Get immediate byte into register */
13840 break;
13842 case 0x1f:
13844 sdwCyclesRemaining -= 4;
13845 bTemp = (cpu.z80F & Z80_FLAG_CARRY) << 7;
13846 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY)) | (cpu.z80A & Z80_FLAG_CARRY);
13847 cpu.z80A = ((cpu.z80A >> 1) | bTemp);
13848 break;
13850 case 0x20:
13852 sdwCyclesRemaining -= 7;
13853 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
13854 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13855 sdwAddr = (sdwAddr + (INT32) cpu.z80pc) & 0xffff;
13856 if (!(cpu.z80F & Z80_FLAG_ZERO))
13858 sdwCyclesRemaining -= 5;
13859 pbPC = cpu.z80Base + sdwAddr; /* Normalize the address */
13861 break;
13863 case 0x21:
13865 sdwCyclesRemaining -= 10;
13866 cpu.z80HL = *pbPC++; /* LSB First */
13867 cpu.z80HL |= (((UINT32) *pbPC++ << 8)); /* Now the MSB */
13868 break;
13870 case 0x22:
13872 sdwCyclesRemaining -= 16;
13873 dwTemp = *pbPC++;
13874 dwTemp |= ((UINT32) *pbPC++ << 8);
13875 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
13876 while (psMemWrite->lowAddr != 0xffffffff)
13878 if ((dwTemp >= psMemWrite->lowAddr) && (dwTemp <= psMemWrite->highAddr))
13880 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13881 if (psMemWrite->memoryCall)
13883 psMemWrite->memoryCall(dwTemp, (cpu.z80HL & 0xff), psMemWrite);
13884 psMemWrite->memoryCall(dwTemp + 1, (cpu.z80HL >> 8), psMemWrite);
13886 else
13888 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr)) = cpu.z80HL;
13889 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr) + 1) = cpu.z80HL >> 8;
13891 psMemWrite = NULL;
13892 break;
13894 ++psMemWrite;
13897 if (psMemWrite)
13899 cpu.z80Base[dwTemp] = (UINT8) cpu.z80HL;
13900 cpu.z80Base[dwTemp + 1] = (UINT8) ((UINT32) cpu.z80HL >> 8);
13903 break;
13905 case 0x23:
13907 sdwCyclesRemaining -= 6;
13908 cpu.z80HL++;
13909 cpu.z80HL &= 0xffff;
13910 break;
13912 case 0x24:
13914 sdwCyclesRemaining -= 4;
13915 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
13916 cpu.z80F |= bPostIncFlags[cpu.z80H++];
13917 break;
13919 case 0x25:
13921 sdwCyclesRemaining -= 4;
13922 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY);
13923 cpu.z80F |= bPostDecFlags[cpu.z80H--];
13924 break;
13926 case 0x26:
13928 sdwCyclesRemaining -= 7;
13929 cpu.z80H = *pbPC++; /* Get immediate byte into register */
13930 break;
13932 case 0x27:
13934 sdwCyclesRemaining -= 4;
13935 dwAddr = (((cpu.z80F & Z80_FLAG_CARRY) |
13936 ((cpu.z80F & Z80_FLAG_HALF_CARRY) >> 3) |
13937 ((cpu.z80F & Z80_FLAG_NEGATIVE) << 1)) << 8) | cpu.z80A;
13938 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
13939 cpu.z80F |= (wDAATable[dwAddr] >> 8);
13940 cpu.z80A = wDAATable[dwAddr] & 0xff;
13941 break;
13943 case 0x28:
13945 sdwCyclesRemaining -= 7;
13946 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
13947 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13948 sdwAddr = (sdwAddr + (INT32) cpu.z80pc) & 0xffff;
13949 if (cpu.z80F & Z80_FLAG_ZERO)
13951 sdwCyclesRemaining -= 5;
13952 pbPC = cpu.z80Base + sdwAddr; /* Normalize the address */
13954 break;
13956 case 0x29:
13958 sdwCyclesRemaining -= 11;
13959 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
13960 dwTemp = cpu.z80HL + cpu.z80HL;
13961 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80HL ^ dwTemp ^ cpu.z80HL) >> 8) & Z80_FLAG_HALF_CARRY);
13962 cpu.z80HL = dwTemp & 0xffff;
13963 break;
13965 case 0x2a:
13967 sdwCyclesRemaining -= 16;
13968 dwAddr = *pbPC++;
13969 dwAddr |= ((UINT32) *pbPC++ << 8);
13970 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
13971 while (psMemRead->lowAddr != 0xffffffff)
13973 if ((dwAddr >= psMemRead->lowAddr) && (dwAddr <= psMemRead->highAddr))
13975 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
13976 if (psMemRead->memoryCall)
13978 cpu.z80HL = psMemRead->memoryCall(dwAddr, psMemRead);
13979 cpu.z80HL |= (UINT32) ((UINT32) psMemRead->memoryCall(dwAddr + 1, psMemRead) << 8);
13981 else
13983 cpu.z80HL = *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr));
13984 cpu.z80HL |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (dwAddr - psMemRead->lowAddr + 1)) << 8);
13986 psMemRead = NULL;
13987 break;
13989 ++psMemRead;
13992 if (psMemRead)
13994 cpu.z80HL = cpu.z80Base[dwAddr];
13995 cpu.z80HL |= (UINT32) ((UINT32) cpu.z80Base[dwAddr + 1] << 8);
13998 break;
14000 case 0x2b:
14002 sdwCyclesRemaining -= 6;
14003 cpu.z80HL--;
14004 cpu.z80HL &= 0xffff;
14005 break;
14007 case 0x2c:
14009 sdwCyclesRemaining -= 4;
14010 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
14011 cpu.z80F |= bPostIncFlags[cpu.z80L++];
14012 break;
14014 case 0x2d:
14016 sdwCyclesRemaining -= 4;
14017 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY);
14018 cpu.z80F |= bPostDecFlags[cpu.z80L--];
14019 break;
14021 case 0x2e:
14023 sdwCyclesRemaining -= 7;
14024 cpu.z80L = *pbPC++; /* Get immediate byte into register */
14025 break;
14027 case 0x2f:
14029 sdwCyclesRemaining -= 4;
14030 cpu.z80A ^= 0xff;
14031 cpu.z80F |= (Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
14032 break;
14034 case 0x30:
14036 sdwCyclesRemaining -= 7;
14037 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
14038 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14039 sdwAddr = (sdwAddr + (INT32) cpu.z80pc) & 0xffff;
14040 if (!(cpu.z80F & Z80_FLAG_CARRY))
14042 sdwCyclesRemaining -= 5;
14043 pbPC = cpu.z80Base + sdwAddr; /* Normalize the address */
14045 break;
14047 case 0x31:
14049 sdwCyclesRemaining -= 10;
14050 cpu.z80sp = *pbPC++; /* LSB First */
14051 cpu.z80sp |= (((UINT32) *pbPC++ << 8)); /* Now the MSB */
14052 break;
14054 case 0x32:
14056 sdwCyclesRemaining -= 13;
14057 dwTemp = *pbPC++;
14058 dwTemp |= ((UINT32) *pbPC++ << 8);
14059 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14060 while (psMemWrite->lowAddr != 0xffffffff)
14062 if ((dwTemp >= psMemWrite->lowAddr) && (dwTemp <= psMemWrite->highAddr))
14064 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14065 if (psMemWrite->memoryCall)
14067 psMemWrite->memoryCall(dwTemp, cpu.z80A, psMemWrite);
14069 else
14071 *((UINT8 *) psMemWrite->pUserArea + (dwTemp - psMemWrite->lowAddr)) = cpu.z80A;
14073 psMemWrite = NULL;
14074 break;
14076 ++psMemWrite;
14079 if (psMemWrite)
14081 cpu.z80Base[dwTemp] = (UINT8) cpu.z80A;
14084 break;
14086 case 0x33:
14088 sdwCyclesRemaining -= 6;
14089 cpu.z80sp++;
14090 cpu.z80sp &= 0xffff;
14091 break;
14093 case 0x34:
14095 sdwCyclesRemaining -= 11;
14096 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14097 while (psMemRead->lowAddr != 0xffffffff)
14099 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
14101 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14102 if (psMemRead->memoryCall)
14104 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
14106 else
14108 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
14110 psMemRead = NULL;
14111 break;
14113 ++psMemRead;
14116 if (psMemRead)
14118 bTemp = cpu.z80Base[cpu.z80HL];
14121 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
14122 cpu.z80F |= bPostIncFlags[bTemp];
14123 bTemp++;
14124 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14125 while (psMemWrite->lowAddr != 0xffffffff)
14127 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14129 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14130 if (psMemWrite->memoryCall)
14132 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
14134 else
14136 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
14138 psMemWrite = NULL;
14139 break;
14141 ++psMemWrite;
14144 if (psMemWrite)
14146 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
14149 break;
14151 case 0x35:
14153 sdwCyclesRemaining -= 11;
14154 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14155 while (psMemRead->lowAddr != 0xffffffff)
14157 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
14159 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14160 if (psMemRead->memoryCall)
14162 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
14164 else
14166 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
14168 psMemRead = NULL;
14169 break;
14171 ++psMemRead;
14174 if (psMemRead)
14176 bTemp = cpu.z80Base[cpu.z80HL];
14179 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
14180 cpu.z80F |= bPostDecFlags[bTemp];
14181 bTemp--;
14182 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14183 while (psMemWrite->lowAddr != 0xffffffff)
14185 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14187 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14188 if (psMemWrite->memoryCall)
14190 psMemWrite->memoryCall(cpu.z80HL, bTemp, psMemWrite);
14192 else
14194 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = bTemp;
14196 psMemWrite = NULL;
14197 break;
14199 ++psMemWrite;
14202 if (psMemWrite)
14204 cpu.z80Base[cpu.z80HL] = (UINT8) bTemp;
14207 break;
14209 case 0x36:
14211 sdwCyclesRemaining -= 10;
14212 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14213 while (psMemWrite->lowAddr != 0xffffffff)
14215 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14217 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14218 if (psMemWrite->memoryCall)
14220 psMemWrite->memoryCall(cpu.z80HL, *pbPC++, psMemWrite);
14222 else
14224 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = *pbPC++;
14226 psMemWrite = NULL;
14227 break;
14229 ++psMemWrite;
14232 if (psMemWrite)
14234 cpu.z80Base[cpu.z80HL] = (UINT8) *pbPC++;
14237 break;
14239 case 0x37:
14241 sdwCyclesRemaining -= 4;
14242 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE);
14243 cpu.z80F |= Z80_FLAG_CARRY;
14244 break;
14246 case 0x38:
14248 sdwCyclesRemaining -= 7;
14249 sdwAddr = (INT8) *pbPC++; /* Get LSB first */
14250 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14251 sdwAddr = (sdwAddr + (INT32) cpu.z80pc) & 0xffff;
14252 if (cpu.z80F & Z80_FLAG_CARRY)
14254 sdwCyclesRemaining -= 5;
14255 pbPC = cpu.z80Base + sdwAddr; /* Normalize the address */
14257 break;
14259 case 0x39:
14261 sdwCyclesRemaining -= 11;
14262 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);
14263 dwTemp = cpu.z80HL + cpu.z80sp;
14264 cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80HL ^ dwTemp ^ cpu.z80sp) >> 8) & Z80_FLAG_HALF_CARRY);
14265 cpu.z80HL = dwTemp & 0xffff;
14266 break;
14268 case 0x3a:
14270 sdwCyclesRemaining -= 13;
14271 dwTemp = *pbPC++;
14272 dwTemp |= (((UINT32) *pbPC++) << 8);
14273 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14274 while (psMemRead->lowAddr != 0xffffffff)
14276 if ((dwTemp >= psMemRead->lowAddr) && (dwTemp <= psMemRead->highAddr))
14278 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14279 if (psMemRead->memoryCall)
14281 cpu.z80A = psMemRead->memoryCall(dwTemp, psMemRead);
14283 else
14285 cpu.z80A = *((UINT8 *) psMemRead->pUserArea + (dwTemp - psMemRead->lowAddr));
14287 psMemRead = NULL;
14288 break;
14290 ++psMemRead;
14293 if (psMemRead)
14295 cpu.z80A = cpu.z80Base[dwTemp];
14298 break;
14300 case 0x3b:
14302 sdwCyclesRemaining -= 6;
14303 cpu.z80sp--;
14304 cpu.z80sp &= 0xffff;
14305 break;
14307 case 0x3c:
14309 sdwCyclesRemaining -= 4;
14310 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);
14311 cpu.z80F |= bPostIncFlags[cpu.z80A++];
14312 break;
14314 case 0x3d:
14316 sdwCyclesRemaining -= 4;
14317 cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY);
14318 cpu.z80F |= bPostDecFlags[cpu.z80A--];
14319 break;
14321 case 0x3e:
14323 sdwCyclesRemaining -= 7;
14324 cpu.z80A = *pbPC++; /* Get immediate byte into register */
14325 break;
14327 case 0x3f:
14329 sdwCyclesRemaining -= 4;
14330 bTemp = (cpu.z80F & Z80_FLAG_CARRY) << 4;
14331 cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE);
14332 cpu.z80F ^= Z80_FLAG_CARRY;
14333 break;
14335 case 0x40:
14337 sdwCyclesRemaining -= 4;
14338 break;
14340 case 0x41:
14342 sdwCyclesRemaining -= 4;
14343 cpu.z80B = cpu.z80C;
14344 break;
14346 case 0x42:
14348 sdwCyclesRemaining -= 4;
14349 cpu.z80B = cpu.z80D;
14350 break;
14352 case 0x43:
14354 sdwCyclesRemaining -= 4;
14355 cpu.z80B = cpu.z80E;
14356 break;
14358 case 0x44:
14360 sdwCyclesRemaining -= 4;
14361 cpu.z80B = cpu.z80H;
14362 break;
14364 case 0x45:
14366 sdwCyclesRemaining -= 4;
14367 cpu.z80B = cpu.z80L;
14368 break;
14370 case 0x46:
14372 sdwCyclesRemaining -= 7;
14373 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14374 while (psMemRead->lowAddr != 0xffffffff)
14376 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
14378 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14379 if (psMemRead->memoryCall)
14381 cpu.z80B = psMemRead->memoryCall(cpu.z80HL, psMemRead);
14383 else
14385 cpu.z80B = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
14387 psMemRead = NULL;
14388 break;
14390 ++psMemRead;
14393 if (psMemRead)
14395 cpu.z80B = cpu.z80Base[cpu.z80HL];
14398 break;
14400 case 0x47:
14402 sdwCyclesRemaining -= 4;
14403 cpu.z80B = cpu.z80A;
14404 break;
14406 case 0x48:
14408 sdwCyclesRemaining -= 4;
14409 cpu.z80C = cpu.z80B;
14410 break;
14412 case 0x49:
14414 sdwCyclesRemaining -= 4;
14415 break;
14417 case 0x4a:
14419 sdwCyclesRemaining -= 4;
14420 cpu.z80C = cpu.z80D;
14421 break;
14423 case 0x4b:
14425 sdwCyclesRemaining -= 4;
14426 cpu.z80C = cpu.z80E;
14427 break;
14429 case 0x4c:
14431 sdwCyclesRemaining -= 4;
14432 cpu.z80C = cpu.z80H;
14433 break;
14435 case 0x4d:
14437 sdwCyclesRemaining -= 4;
14438 cpu.z80C = cpu.z80L;
14439 break;
14441 case 0x4e:
14443 sdwCyclesRemaining -= 7;
14444 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14445 while (psMemRead->lowAddr != 0xffffffff)
14447 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
14449 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14450 if (psMemRead->memoryCall)
14452 cpu.z80C = psMemRead->memoryCall(cpu.z80HL, psMemRead);
14454 else
14456 cpu.z80C = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
14458 psMemRead = NULL;
14459 break;
14461 ++psMemRead;
14464 if (psMemRead)
14466 cpu.z80C = cpu.z80Base[cpu.z80HL];
14469 break;
14471 case 0x4f:
14473 sdwCyclesRemaining -= 4;
14474 cpu.z80C = cpu.z80A;
14475 break;
14477 case 0x50:
14479 sdwCyclesRemaining -= 4;
14480 cpu.z80D = cpu.z80B;
14481 break;
14483 case 0x51:
14485 sdwCyclesRemaining -= 4;
14486 cpu.z80D = cpu.z80C;
14487 break;
14489 case 0x52:
14491 sdwCyclesRemaining -= 4;
14492 break;
14494 case 0x53:
14496 sdwCyclesRemaining -= 4;
14497 cpu.z80D = cpu.z80E;
14498 break;
14500 case 0x54:
14502 sdwCyclesRemaining -= 4;
14503 cpu.z80D = cpu.z80H;
14504 break;
14506 case 0x55:
14508 sdwCyclesRemaining -= 4;
14509 cpu.z80D = cpu.z80L;
14510 break;
14512 case 0x56:
14514 sdwCyclesRemaining -= 7;
14515 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14516 while (psMemRead->lowAddr != 0xffffffff)
14518 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
14520 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14521 if (psMemRead->memoryCall)
14523 cpu.z80D = psMemRead->memoryCall(cpu.z80HL, psMemRead);
14525 else
14527 cpu.z80D = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
14529 psMemRead = NULL;
14530 break;
14532 ++psMemRead;
14535 if (psMemRead)
14537 cpu.z80D = cpu.z80Base[cpu.z80HL];
14540 break;
14542 case 0x57:
14544 sdwCyclesRemaining -= 4;
14545 cpu.z80D = cpu.z80A;
14546 break;
14548 case 0x58:
14550 sdwCyclesRemaining -= 4;
14551 cpu.z80E = cpu.z80B;
14552 break;
14554 case 0x59:
14556 sdwCyclesRemaining -= 4;
14557 cpu.z80E = cpu.z80C;
14558 break;
14560 case 0x5a:
14562 sdwCyclesRemaining -= 4;
14563 cpu.z80E = cpu.z80D;
14564 break;
14566 case 0x5b:
14568 sdwCyclesRemaining -= 4;
14569 break;
14571 case 0x5c:
14573 sdwCyclesRemaining -= 4;
14574 cpu.z80E = cpu.z80H;
14575 break;
14577 case 0x5d:
14579 sdwCyclesRemaining -= 4;
14580 cpu.z80E = cpu.z80L;
14581 break;
14583 case 0x5e:
14585 sdwCyclesRemaining -= 7;
14586 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14587 while (psMemRead->lowAddr != 0xffffffff)
14589 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
14591 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14592 if (psMemRead->memoryCall)
14594 cpu.z80E = psMemRead->memoryCall(cpu.z80HL, psMemRead);
14596 else
14598 cpu.z80E = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
14600 psMemRead = NULL;
14601 break;
14603 ++psMemRead;
14606 if (psMemRead)
14608 cpu.z80E = cpu.z80Base[cpu.z80HL];
14611 break;
14613 case 0x5f:
14615 sdwCyclesRemaining -= 4;
14616 cpu.z80E = cpu.z80A;
14617 break;
14619 case 0x60:
14621 sdwCyclesRemaining -= 4;
14622 cpu.z80H = cpu.z80B;
14623 break;
14625 case 0x61:
14627 sdwCyclesRemaining -= 4;
14628 cpu.z80H = cpu.z80C;
14629 break;
14631 case 0x62:
14633 sdwCyclesRemaining -= 4;
14634 cpu.z80H = cpu.z80D;
14635 break;
14637 case 0x63:
14639 sdwCyclesRemaining -= 4;
14640 cpu.z80H = cpu.z80E;
14641 break;
14643 case 0x64:
14645 sdwCyclesRemaining -= 4;
14646 break;
14648 case 0x65:
14650 sdwCyclesRemaining -= 4;
14651 cpu.z80H = cpu.z80L;
14652 break;
14654 case 0x66:
14656 sdwCyclesRemaining -= 7;
14657 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14658 while (psMemRead->lowAddr != 0xffffffff)
14660 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
14662 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14663 if (psMemRead->memoryCall)
14665 cpu.z80H = psMemRead->memoryCall(cpu.z80HL, psMemRead);
14667 else
14669 cpu.z80H = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
14671 psMemRead = NULL;
14672 break;
14674 ++psMemRead;
14677 if (psMemRead)
14679 cpu.z80H = cpu.z80Base[cpu.z80HL];
14682 break;
14684 case 0x67:
14686 sdwCyclesRemaining -= 4;
14687 cpu.z80H = cpu.z80A;
14688 break;
14690 case 0x68:
14692 sdwCyclesRemaining -= 4;
14693 cpu.z80L = cpu.z80B;
14694 break;
14696 case 0x69:
14698 sdwCyclesRemaining -= 4;
14699 cpu.z80L = cpu.z80C;
14700 break;
14702 case 0x6a:
14704 sdwCyclesRemaining -= 4;
14705 cpu.z80L = cpu.z80D;
14706 break;
14708 case 0x6b:
14710 sdwCyclesRemaining -= 4;
14711 cpu.z80L = cpu.z80E;
14712 break;
14714 case 0x6c:
14716 sdwCyclesRemaining -= 4;
14717 cpu.z80L = cpu.z80H;
14718 break;
14720 case 0x6d:
14722 sdwCyclesRemaining -= 4;
14723 break;
14725 case 0x6e:
14727 sdwCyclesRemaining -= 7;
14728 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
14729 while (psMemRead->lowAddr != 0xffffffff)
14731 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
14733 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14734 if (psMemRead->memoryCall)
14736 cpu.z80L = psMemRead->memoryCall(cpu.z80HL, psMemRead);
14738 else
14740 cpu.z80L = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
14742 psMemRead = NULL;
14743 break;
14745 ++psMemRead;
14748 if (psMemRead)
14750 cpu.z80L = cpu.z80Base[cpu.z80HL];
14753 break;
14755 case 0x6f:
14757 sdwCyclesRemaining -= 4;
14758 cpu.z80L = cpu.z80A;
14759 break;
14761 case 0x70:
14763 sdwCyclesRemaining -= 7;
14764 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14765 while (psMemWrite->lowAddr != 0xffffffff)
14767 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14769 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14770 if (psMemWrite->memoryCall)
14772 psMemWrite->memoryCall(cpu.z80HL, cpu.z80B, psMemWrite);
14774 else
14776 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = cpu.z80B;
14778 psMemWrite = NULL;
14779 break;
14781 ++psMemWrite;
14784 if (psMemWrite)
14786 cpu.z80Base[cpu.z80HL] = (UINT8) cpu.z80B;
14789 break;
14791 case 0x71:
14793 sdwCyclesRemaining -= 7;
14794 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14795 while (psMemWrite->lowAddr != 0xffffffff)
14797 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14799 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14800 if (psMemWrite->memoryCall)
14802 psMemWrite->memoryCall(cpu.z80HL, cpu.z80C, psMemWrite);
14804 else
14806 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = cpu.z80C;
14808 psMemWrite = NULL;
14809 break;
14811 ++psMemWrite;
14814 if (psMemWrite)
14816 cpu.z80Base[cpu.z80HL] = (UINT8) cpu.z80C;
14819 break;
14821 case 0x72:
14823 sdwCyclesRemaining -= 7;
14824 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14825 while (psMemWrite->lowAddr != 0xffffffff)
14827 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14829 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14830 if (psMemWrite->memoryCall)
14832 psMemWrite->memoryCall(cpu.z80HL, cpu.z80D, psMemWrite);
14834 else
14836 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = cpu.z80D;
14838 psMemWrite = NULL;
14839 break;
14841 ++psMemWrite;
14844 if (psMemWrite)
14846 cpu.z80Base[cpu.z80HL] = (UINT8) cpu.z80D;
14849 break;
14851 case 0x73:
14853 sdwCyclesRemaining -= 7;
14854 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14855 while (psMemWrite->lowAddr != 0xffffffff)
14857 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14859 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14860 if (psMemWrite->memoryCall)
14862 psMemWrite->memoryCall(cpu.z80HL, cpu.z80E, psMemWrite);
14864 else
14866 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = cpu.z80E;
14868 psMemWrite = NULL;
14869 break;
14871 ++psMemWrite;
14874 if (psMemWrite)
14876 cpu.z80Base[cpu.z80HL] = (UINT8) cpu.z80E;
14879 break;
14881 case 0x74:
14883 sdwCyclesRemaining -= 7;
14884 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14885 while (psMemWrite->lowAddr != 0xffffffff)
14887 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14889 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14890 if (psMemWrite->memoryCall)
14892 psMemWrite->memoryCall(cpu.z80HL, cpu.z80H, psMemWrite);
14894 else
14896 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = cpu.z80H;
14898 psMemWrite = NULL;
14899 break;
14901 ++psMemWrite;
14904 if (psMemWrite)
14906 cpu.z80Base[cpu.z80HL] = (UINT8) cpu.z80H;
14909 break;
14911 case 0x75:
14913 sdwCyclesRemaining -= 7;
14914 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14915 while (psMemWrite->lowAddr != 0xffffffff)
14917 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14919 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14920 if (psMemWrite->memoryCall)
14922 psMemWrite->memoryCall(cpu.z80HL, cpu.z80L, psMemWrite);
14924 else
14926 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = cpu.z80L;
14928 psMemWrite = NULL;
14929 break;
14931 ++psMemWrite;
14934 if (psMemWrite)
14936 cpu.z80Base[cpu.z80HL] = (UINT8) cpu.z80L;
14939 break;
14941 case 0x76:
14943 sdwCyclesRemaining -= 4;
14944 cpu.z80halted = 1;
14945 dwElapsedTicks += sdwCyclesRemaining;
14946 sdwCyclesRemaining = 0;
14947 break;
14949 case 0x77:
14951 sdwCyclesRemaining -= 7;
14952 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
14953 while (psMemWrite->lowAddr != 0xffffffff)
14955 if ((cpu.z80HL >= psMemWrite->lowAddr) && (cpu.z80HL <= psMemWrite->highAddr))
14957 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
14958 if (psMemWrite->memoryCall)
14960 psMemWrite->memoryCall(cpu.z80HL, cpu.z80A, psMemWrite);
14962 else
14964 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80HL - psMemWrite->lowAddr)) = cpu.z80A;
14966 psMemWrite = NULL;
14967 break;
14969 ++psMemWrite;
14972 if (psMemWrite)
14974 cpu.z80Base[cpu.z80HL] = (UINT8) cpu.z80A;
14977 break;
14979 case 0x78:
14981 sdwCyclesRemaining -= 4;
14982 cpu.z80A = cpu.z80B;
14983 break;
14985 case 0x79:
14987 sdwCyclesRemaining -= 4;
14988 cpu.z80A = cpu.z80C;
14989 break;
14991 case 0x7a:
14993 sdwCyclesRemaining -= 4;
14994 cpu.z80A = cpu.z80D;
14995 break;
14997 case 0x7b:
14999 sdwCyclesRemaining -= 4;
15000 cpu.z80A = cpu.z80E;
15001 break;
15003 case 0x7c:
15005 sdwCyclesRemaining -= 4;
15006 cpu.z80A = cpu.z80H;
15007 break;
15009 case 0x7d:
15011 sdwCyclesRemaining -= 4;
15012 cpu.z80A = cpu.z80L;
15013 break;
15015 case 0x7e:
15017 sdwCyclesRemaining -= 7;
15018 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15019 while (psMemRead->lowAddr != 0xffffffff)
15021 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15023 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15024 if (psMemRead->memoryCall)
15026 cpu.z80A = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15028 else
15030 cpu.z80A = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15032 psMemRead = NULL;
15033 break;
15035 ++psMemRead;
15038 if (psMemRead)
15040 cpu.z80A = cpu.z80Base[cpu.z80HL];
15043 break;
15045 case 0x7f:
15047 sdwCyclesRemaining -= 4;
15048 break;
15050 case 0x80:
15052 sdwCyclesRemaining -= 4;
15053 bTemp2 = cpu.z80A + cpu.z80B;
15054 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15055 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15056 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80B];
15057 cpu.z80A = bTemp2;
15058 break;
15060 case 0x81:
15062 sdwCyclesRemaining -= 4;
15063 bTemp2 = cpu.z80A + cpu.z80C;
15064 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15065 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15066 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80C];
15067 cpu.z80A = bTemp2;
15068 break;
15070 case 0x82:
15072 sdwCyclesRemaining -= 4;
15073 bTemp2 = cpu.z80A + cpu.z80D;
15074 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15075 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15076 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80D];
15077 cpu.z80A = bTemp2;
15078 break;
15080 case 0x83:
15082 sdwCyclesRemaining -= 4;
15083 bTemp2 = cpu.z80A + cpu.z80E;
15084 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15085 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15086 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80E];
15087 cpu.z80A = bTemp2;
15088 break;
15090 case 0x84:
15092 sdwCyclesRemaining -= 4;
15093 bTemp2 = cpu.z80A + cpu.z80H;
15094 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15095 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15096 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80H];
15097 cpu.z80A = bTemp2;
15098 break;
15100 case 0x85:
15102 sdwCyclesRemaining -= 4;
15103 bTemp2 = cpu.z80A + cpu.z80L;
15104 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15105 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15106 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80L];
15107 cpu.z80A = bTemp2;
15108 break;
15110 case 0x86:
15112 sdwCyclesRemaining -= 7;
15113 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15114 while (psMemRead->lowAddr != 0xffffffff)
15116 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15118 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15119 if (psMemRead->memoryCall)
15121 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15123 else
15125 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15127 psMemRead = NULL;
15128 break;
15130 ++psMemRead;
15133 if (psMemRead)
15135 bTemp = cpu.z80Base[cpu.z80HL];
15138 bTemp2 = cpu.z80A + bTemp;
15139 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15140 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15141 pbAddAdcTable[((UINT32) cpu.z80A << 8) | bTemp];
15142 cpu.z80A = bTemp2;
15143 break;
15145 case 0x87:
15147 sdwCyclesRemaining -= 4;
15148 bTemp2 = cpu.z80A + cpu.z80A;
15149 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15150 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15151 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80A];
15152 cpu.z80A = bTemp2;
15153 break;
15155 case 0x88:
15157 sdwCyclesRemaining -= 4;
15158 bTemp2 = cpu.z80A + cpu.z80B + (cpu.z80F & Z80_FLAG_CARRY);
15159 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15160 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15161 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80B | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15162 cpu.z80A = bTemp2;
15163 break;
15165 case 0x89:
15167 sdwCyclesRemaining -= 4;
15168 bTemp2 = cpu.z80A + cpu.z80C + (cpu.z80F & Z80_FLAG_CARRY);
15169 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15170 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15171 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80C | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15172 cpu.z80A = bTemp2;
15173 break;
15175 case 0x8a:
15177 sdwCyclesRemaining -= 4;
15178 bTemp2 = cpu.z80A + cpu.z80D + (cpu.z80F & Z80_FLAG_CARRY);
15179 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15180 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15181 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80D | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15182 cpu.z80A = bTemp2;
15183 break;
15185 case 0x8b:
15187 sdwCyclesRemaining -= 4;
15188 bTemp2 = cpu.z80A + cpu.z80E + (cpu.z80F & Z80_FLAG_CARRY);
15189 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15190 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15191 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80E | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15192 cpu.z80A = bTemp2;
15193 break;
15195 case 0x8c:
15197 sdwCyclesRemaining -= 4;
15198 bTemp2 = cpu.z80A + cpu.z80H + (cpu.z80F & Z80_FLAG_CARRY);
15199 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15200 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15201 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80H | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15202 cpu.z80A = bTemp2;
15203 break;
15205 case 0x8d:
15207 sdwCyclesRemaining -= 4;
15208 bTemp2 = cpu.z80A + cpu.z80L + (cpu.z80F & Z80_FLAG_CARRY);
15209 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15210 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15211 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80L | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15212 cpu.z80A = bTemp2;
15213 break;
15215 case 0x8e:
15217 sdwCyclesRemaining -= 7;
15218 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15219 while (psMemRead->lowAddr != 0xffffffff)
15221 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15223 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15224 if (psMemRead->memoryCall)
15226 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15228 else
15230 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15232 psMemRead = NULL;
15233 break;
15235 ++psMemRead;
15238 if (psMemRead)
15240 bTemp = cpu.z80Base[cpu.z80HL];
15243 bTemp2 = cpu.z80A + bTemp + (cpu.z80F & Z80_FLAG_CARRY);
15244 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15245 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15246 pbAddAdcTable[((UINT32) cpu.z80A << 8) | bTemp | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15247 cpu.z80A = bTemp2;
15248 break;
15250 case 0x8f:
15252 sdwCyclesRemaining -= 4;
15253 bTemp2 = cpu.z80A + cpu.z80A + (cpu.z80F & Z80_FLAG_CARRY);
15254 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15255 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15256 pbAddAdcTable[((UINT32) cpu.z80A << 8) | cpu.z80A | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15257 cpu.z80A = bTemp2;
15258 break;
15260 case 0x90:
15262 sdwCyclesRemaining -= 4;
15263 bTemp2 = cpu.z80A - cpu.z80B;
15264 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15265 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15266 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80B];
15267 cpu.z80A = bTemp2;
15268 break;
15270 case 0x91:
15272 sdwCyclesRemaining -= 4;
15273 bTemp2 = cpu.z80A - cpu.z80C;
15274 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15275 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15276 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80C];
15277 cpu.z80A = bTemp2;
15278 break;
15280 case 0x92:
15282 sdwCyclesRemaining -= 4;
15283 bTemp2 = cpu.z80A - cpu.z80D;
15284 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15285 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15286 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80D];
15287 cpu.z80A = bTemp2;
15288 break;
15290 case 0x93:
15292 sdwCyclesRemaining -= 4;
15293 bTemp2 = cpu.z80A - cpu.z80E;
15294 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15295 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15296 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80E];
15297 cpu.z80A = bTemp2;
15298 break;
15300 case 0x94:
15302 sdwCyclesRemaining -= 4;
15303 bTemp2 = cpu.z80A - cpu.z80H;
15304 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15305 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15306 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80H];
15307 cpu.z80A = bTemp2;
15308 break;
15310 case 0x95:
15312 sdwCyclesRemaining -= 4;
15313 bTemp2 = cpu.z80A - cpu.z80L;
15314 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15315 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15316 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80L];
15317 cpu.z80A = bTemp2;
15318 break;
15320 case 0x96:
15322 sdwCyclesRemaining -= 7;
15323 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15324 while (psMemRead->lowAddr != 0xffffffff)
15326 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15328 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15329 if (psMemRead->memoryCall)
15331 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15333 else
15335 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15337 psMemRead = NULL;
15338 break;
15340 ++psMemRead;
15343 if (psMemRead)
15345 bTemp = cpu.z80Base[cpu.z80HL];
15348 bTemp2 = cpu.z80A - bTemp;
15349 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15350 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15351 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp];
15352 cpu.z80A = bTemp2;
15353 break;
15355 case 0x97:
15357 sdwCyclesRemaining -= 4;
15358 bTemp2 = cpu.z80A - cpu.z80A;
15359 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15360 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15361 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80A];
15362 cpu.z80A = bTemp2;
15363 break;
15365 case 0x98:
15367 sdwCyclesRemaining -= 4;
15368 bTemp2 = cpu.z80A - cpu.z80B - (cpu.z80F & Z80_FLAG_CARRY);
15369 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15370 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15371 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80B | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15372 cpu.z80A = bTemp2;
15373 break;
15375 case 0x99:
15377 sdwCyclesRemaining -= 4;
15378 bTemp2 = cpu.z80A - cpu.z80C - (cpu.z80F & Z80_FLAG_CARRY);
15379 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15380 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15381 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80C | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15382 cpu.z80A = bTemp2;
15383 break;
15385 case 0x9a:
15387 sdwCyclesRemaining -= 4;
15388 bTemp2 = cpu.z80A - cpu.z80D - (cpu.z80F & Z80_FLAG_CARRY);
15389 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15390 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15391 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80D | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15392 cpu.z80A = bTemp2;
15393 break;
15395 case 0x9b:
15397 sdwCyclesRemaining -= 4;
15398 bTemp2 = cpu.z80A - cpu.z80E - (cpu.z80F & Z80_FLAG_CARRY);
15399 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15400 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15401 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80E | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15402 cpu.z80A = bTemp2;
15403 break;
15405 case 0x9c:
15407 sdwCyclesRemaining -= 4;
15408 bTemp2 = cpu.z80A - cpu.z80H - (cpu.z80F & Z80_FLAG_CARRY);
15409 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15410 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15411 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80H | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15412 cpu.z80A = bTemp2;
15413 break;
15415 case 0x9d:
15417 sdwCyclesRemaining -= 4;
15418 bTemp2 = cpu.z80A - cpu.z80L - (cpu.z80F & Z80_FLAG_CARRY);
15419 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15420 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15421 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80L | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15422 cpu.z80A = bTemp2;
15423 break;
15425 case 0x9e:
15427 sdwCyclesRemaining -= 7;
15428 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15429 while (psMemRead->lowAddr != 0xffffffff)
15431 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15433 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15434 if (psMemRead->memoryCall)
15436 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15438 else
15440 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15442 psMemRead = NULL;
15443 break;
15445 ++psMemRead;
15448 if (psMemRead)
15450 bTemp = cpu.z80Base[cpu.z80HL];
15453 bTemp2 = cpu.z80A - bTemp - (cpu.z80F & Z80_FLAG_CARRY);
15454 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15455 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15456 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15457 cpu.z80A = bTemp2;
15458 break;
15460 case 0x9f:
15462 sdwCyclesRemaining -= 4;
15463 bTemp2 = cpu.z80A - cpu.z80A - (cpu.z80F & Z80_FLAG_CARRY);
15464 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15465 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15466 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80A | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
15467 cpu.z80A = bTemp2;
15468 break;
15470 case 0xa0:
15472 sdwCyclesRemaining -= 4;
15473 cpu.z80A &= cpu.z80B;
15474 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15475 cpu.z80F |= bPostANDFlags[cpu.z80A];
15477 break;
15479 case 0xa1:
15481 sdwCyclesRemaining -= 4;
15482 cpu.z80A &= cpu.z80C;
15483 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15484 cpu.z80F |= bPostANDFlags[cpu.z80A];
15486 break;
15488 case 0xa2:
15490 sdwCyclesRemaining -= 4;
15491 cpu.z80A &= cpu.z80D;
15492 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15493 cpu.z80F |= bPostANDFlags[cpu.z80A];
15495 break;
15497 case 0xa3:
15499 sdwCyclesRemaining -= 4;
15500 cpu.z80A &= cpu.z80E;
15501 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15502 cpu.z80F |= bPostANDFlags[cpu.z80A];
15504 break;
15506 case 0xa4:
15508 sdwCyclesRemaining -= 4;
15509 cpu.z80A &= cpu.z80H;
15510 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15511 cpu.z80F |= bPostANDFlags[cpu.z80A];
15513 break;
15515 case 0xa5:
15517 sdwCyclesRemaining -= 4;
15518 cpu.z80A &= cpu.z80L;
15519 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15520 cpu.z80F |= bPostANDFlags[cpu.z80A];
15522 break;
15524 case 0xa6:
15526 sdwCyclesRemaining -= 7;
15527 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15528 while (psMemRead->lowAddr != 0xffffffff)
15530 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15532 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15533 if (psMemRead->memoryCall)
15535 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15537 else
15539 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15541 psMemRead = NULL;
15542 break;
15544 ++psMemRead;
15547 if (psMemRead)
15549 bTemp = cpu.z80Base[cpu.z80HL];
15552 cpu.z80A &= bTemp;
15553 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15554 cpu.z80F |= bPostANDFlags[cpu.z80A];
15556 break;
15558 case 0xa7:
15560 sdwCyclesRemaining -= 4;
15561 cpu.z80A &= cpu.z80A;
15562 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15563 cpu.z80F |= bPostANDFlags[cpu.z80A];
15565 break;
15567 case 0xa8:
15569 sdwCyclesRemaining -= 4;
15570 cpu.z80A ^= cpu.z80B;
15571 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15572 cpu.z80F |= bPostORFlags[cpu.z80A];
15574 break;
15576 case 0xa9:
15578 sdwCyclesRemaining -= 4;
15579 cpu.z80A ^= cpu.z80C;
15580 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15581 cpu.z80F |= bPostORFlags[cpu.z80A];
15583 break;
15585 case 0xaa:
15587 sdwCyclesRemaining -= 4;
15588 cpu.z80A ^= cpu.z80D;
15589 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15590 cpu.z80F |= bPostORFlags[cpu.z80A];
15592 break;
15594 case 0xab:
15596 sdwCyclesRemaining -= 4;
15597 cpu.z80A ^= cpu.z80E;
15598 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15599 cpu.z80F |= bPostORFlags[cpu.z80A];
15601 break;
15603 case 0xac:
15605 sdwCyclesRemaining -= 4;
15606 cpu.z80A ^= cpu.z80H;
15607 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15608 cpu.z80F |= bPostORFlags[cpu.z80A];
15610 break;
15612 case 0xad:
15614 sdwCyclesRemaining -= 4;
15615 cpu.z80A ^= cpu.z80L;
15616 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15617 cpu.z80F |= bPostORFlags[cpu.z80A];
15619 break;
15621 case 0xae:
15623 sdwCyclesRemaining -= 7;
15624 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15625 while (psMemRead->lowAddr != 0xffffffff)
15627 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15629 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15630 if (psMemRead->memoryCall)
15632 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15634 else
15636 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15638 psMemRead = NULL;
15639 break;
15641 ++psMemRead;
15644 if (psMemRead)
15646 bTemp = cpu.z80Base[cpu.z80HL];
15649 cpu.z80A ^= bTemp;
15650 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15651 cpu.z80F |= bPostORFlags[cpu.z80A];
15653 break;
15655 case 0xaf:
15657 sdwCyclesRemaining -= 4;
15658 cpu.z80A ^= cpu.z80A;
15659 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15660 cpu.z80F |= bPostORFlags[cpu.z80A];
15662 break;
15664 case 0xb0:
15666 sdwCyclesRemaining -= 4;
15667 cpu.z80A |= cpu.z80B;
15668 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15669 cpu.z80F |= bPostORFlags[cpu.z80A];
15671 break;
15673 case 0xb1:
15675 sdwCyclesRemaining -= 4;
15676 cpu.z80A |= cpu.z80C;
15677 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15678 cpu.z80F |= bPostORFlags[cpu.z80A];
15680 break;
15682 case 0xb2:
15684 sdwCyclesRemaining -= 4;
15685 cpu.z80A |= cpu.z80D;
15686 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15687 cpu.z80F |= bPostORFlags[cpu.z80A];
15689 break;
15691 case 0xb3:
15693 sdwCyclesRemaining -= 4;
15694 cpu.z80A |= cpu.z80E;
15695 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15696 cpu.z80F |= bPostORFlags[cpu.z80A];
15698 break;
15700 case 0xb4:
15702 sdwCyclesRemaining -= 4;
15703 cpu.z80A |= cpu.z80H;
15704 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15705 cpu.z80F |= bPostORFlags[cpu.z80A];
15707 break;
15709 case 0xb5:
15711 sdwCyclesRemaining -= 4;
15712 cpu.z80A |= cpu.z80L;
15713 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15714 cpu.z80F |= bPostORFlags[cpu.z80A];
15716 break;
15718 case 0xb6:
15720 sdwCyclesRemaining -= 7;
15721 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15722 while (psMemRead->lowAddr != 0xffffffff)
15724 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15726 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15727 if (psMemRead->memoryCall)
15729 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15731 else
15733 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15735 psMemRead = NULL;
15736 break;
15738 ++psMemRead;
15741 if (psMemRead)
15743 bTemp = cpu.z80Base[cpu.z80HL];
15746 cpu.z80A |= bTemp;
15747 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15748 cpu.z80F |= bPostORFlags[cpu.z80A];
15750 break;
15752 case 0xb7:
15754 sdwCyclesRemaining -= 4;
15755 cpu.z80A |= cpu.z80A;
15756 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
15757 cpu.z80F |= bPostORFlags[cpu.z80A];
15759 break;
15761 case 0xb8:
15763 sdwCyclesRemaining -= 4;
15764 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15765 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15766 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80B];
15767 break;
15769 case 0xb9:
15771 sdwCyclesRemaining -= 4;
15772 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15773 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15774 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80C];
15775 break;
15777 case 0xba:
15779 sdwCyclesRemaining -= 4;
15780 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15781 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15782 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80D];
15783 break;
15785 case 0xbb:
15787 sdwCyclesRemaining -= 4;
15788 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15789 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15790 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80E];
15791 break;
15793 case 0xbc:
15795 sdwCyclesRemaining -= 4;
15796 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15797 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15798 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80H];
15799 break;
15801 case 0xbd:
15803 sdwCyclesRemaining -= 4;
15804 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15805 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15806 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80L];
15807 break;
15809 case 0xbe:
15811 sdwCyclesRemaining -= 7;
15812 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15813 while (psMemRead->lowAddr != 0xffffffff)
15815 if ((cpu.z80HL >= psMemRead->lowAddr) && (cpu.z80HL <= psMemRead->highAddr))
15817 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15818 if (psMemRead->memoryCall)
15820 bTemp = psMemRead->memoryCall(cpu.z80HL, psMemRead);
15822 else
15824 bTemp = *((UINT8 *) psMemRead->pUserArea + (cpu.z80HL - psMemRead->lowAddr));
15826 psMemRead = NULL;
15827 break;
15829 ++psMemRead;
15832 if (psMemRead)
15834 bTemp = cpu.z80Base[cpu.z80HL];
15837 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15838 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15839 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp];
15840 break;
15842 case 0xbf:
15844 sdwCyclesRemaining -= 4;
15845 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15846 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15847 pbSubSbcTable[((UINT32) cpu.z80A << 8) | cpu.z80A];
15848 break;
15850 case 0xc0:
15852 sdwCyclesRemaining -= 5;
15853 if (!(cpu.z80F & Z80_FLAG_ZERO))
15855 dwElapsedTicks += 6;
15856 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
15857 dwAddr = *pbSP++; /* Pop LSB */
15858 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
15859 cpu.z80sp += 2; /* Pop the word off */
15860 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
15862 break;
15864 case 0xc1:
15866 sdwCyclesRemaining -= 10;
15867 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
15868 while (psMemRead->lowAddr != 0xffffffff)
15870 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
15872 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15873 if (psMemRead->memoryCall)
15875 cpu.z80BC = psMemRead->memoryCall(cpu.z80sp, psMemRead);
15876 cpu.z80BC |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
15878 else
15880 cpu.z80BC = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
15881 cpu.z80BC |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
15883 psMemRead = NULL;
15884 break;
15886 ++psMemRead;
15889 if (psMemRead)
15891 cpu.z80BC = cpu.z80Base[cpu.z80sp];
15892 cpu.z80BC |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
15895 cpu.z80sp += 2;
15896 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
15897 break;
15899 case 0xc2:
15901 sdwCyclesRemaining -= 10;
15902 dwAddr = *pbPC++; /* Get LSB first */
15903 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
15904 if (!(cpu.z80F & Z80_FLAG_ZERO))
15906 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
15908 break;
15910 case 0xc3:
15912 sdwCyclesRemaining -= 10;
15913 dwAddr = *pbPC++; /* Get LSB first */
15914 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
15915 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
15916 break;
15918 case 0xc4:
15920 sdwCyclesRemaining -= 10;
15921 dwAddr = *pbPC++; /* Get LSB first */
15922 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
15923 if (!(cpu.z80F & Z80_FLAG_ZERO))
15925 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15926 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
15927 *pbSP-- = cpu.z80pc >> 8; /* MSB */
15928 *pbSP = (UINT8) cpu.z80pc; /* LSB */
15929 cpu.z80sp -= 2; /* Back our stack up */
15930 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
15932 break;
15934 case 0xc5:
15936 sdwCyclesRemaining -= 11;
15937 cpu.z80sp -= 2;
15938 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
15939 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
15940 while (psMemWrite->lowAddr != 0xffffffff)
15942 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
15944 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15945 if (psMemWrite->memoryCall)
15947 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80BC & 0xff), psMemWrite);
15948 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80BC >> 8), psMemWrite);
15950 else
15952 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80BC;
15953 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80BC >> 8;
15955 psMemWrite = NULL;
15956 break;
15958 ++psMemWrite;
15961 if (psMemWrite)
15963 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80BC;
15964 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80BC >> 8);
15967 break;
15969 case 0xc6:
15971 sdwCyclesRemaining -= 7;
15972 bTemp = *pbPC++;
15973 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
15974 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
15975 pbAddAdcTable[((UINT32) cpu.z80A << 8) | bTemp];
15976 cpu.z80A += bTemp;
15977 break;
15979 case 0xc7:
15981 sdwCyclesRemaining -= 11;
15982 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
15983 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
15984 *pbSP-- = cpu.z80pc >> 8; /* LSB */
15985 *pbSP = (UINT8) cpu.z80pc; /* MSB */
15986 cpu.z80sp -= 2; /* Back our stack up */
15987 pbPC = cpu.z80Base + 0x00; /* Normalize the address */
15988 break;
15990 case 0xc8:
15992 sdwCyclesRemaining -= 5;
15993 if (cpu.z80F & Z80_FLAG_ZERO)
15995 dwElapsedTicks += 6;
15996 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
15997 dwAddr = *pbSP++; /* Pop LSB */
15998 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
15999 cpu.z80sp += 2; /* Pop the word off */
16000 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
16002 break;
16004 case 0xc9:
16006 sdwCyclesRemaining -= 10;
16007 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
16008 dwAddr = *pbSP++; /* Pop LSB */
16009 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
16010 cpu.z80sp += 2; /* Pop the word off */
16011 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
16012 break;
16014 case 0xca:
16016 sdwCyclesRemaining -= 10;
16017 dwAddr = *pbPC++; /* Get LSB first */
16018 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16019 if (cpu.z80F & Z80_FLAG_ZERO)
16021 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16023 break;
16025 case 0xcb:
16027 CBHandler();
16028 break;
16030 case 0xcc:
16032 sdwCyclesRemaining -= 10;
16033 dwAddr = *pbPC++; /* Get LSB first */
16034 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16035 if (cpu.z80F & Z80_FLAG_ZERO)
16037 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16038 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16039 *pbSP-- = cpu.z80pc >> 8; /* MSB */
16040 *pbSP = (UINT8) cpu.z80pc; /* LSB */
16041 cpu.z80sp -= 2; /* Back our stack up */
16042 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16044 break;
16046 case 0xcd:
16048 sdwCyclesRemaining -= 17;
16049 dwAddr = *pbPC++; /* Get LSB first */
16050 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16051 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16052 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16053 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16054 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16055 cpu.z80sp -= 2; /* Back our stack up */
16056 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16057 break;
16059 case 0xce:
16061 sdwCyclesRemaining -= 7;
16062 bTemp = *pbPC++ + (cpu.z80F & Z80_FLAG_CARRY);
16063 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
16064 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
16065 pbAddAdcTable[((UINT32) cpu.z80A << 8) | bTemp | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
16066 cpu.z80A += bTemp;
16067 break;
16069 case 0xcf:
16071 sdwCyclesRemaining -= 11;
16072 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16073 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16074 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16075 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16076 cpu.z80sp -= 2; /* Back our stack up */
16077 pbPC = cpu.z80Base + 0x08; /* Normalize the address */
16078 break;
16080 case 0xd0:
16082 sdwCyclesRemaining -= 5;
16083 if (!(cpu.z80F & Z80_FLAG_CARRY))
16085 dwElapsedTicks += 6;
16086 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
16087 dwAddr = *pbSP++; /* Pop LSB */
16088 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
16089 cpu.z80sp += 2; /* Pop the word off */
16090 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
16092 break;
16094 case 0xd1:
16096 sdwCyclesRemaining -= 10;
16097 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
16098 while (psMemRead->lowAddr != 0xffffffff)
16100 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
16102 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16103 if (psMemRead->memoryCall)
16105 cpu.z80DE = psMemRead->memoryCall(cpu.z80sp, psMemRead);
16106 cpu.z80DE |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
16108 else
16110 cpu.z80DE = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
16111 cpu.z80DE |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
16113 psMemRead = NULL;
16114 break;
16116 ++psMemRead;
16119 if (psMemRead)
16121 cpu.z80DE = cpu.z80Base[cpu.z80sp];
16122 cpu.z80DE |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
16125 cpu.z80sp += 2;
16126 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
16127 break;
16129 case 0xd2:
16131 sdwCyclesRemaining -= 10;
16132 dwAddr = *pbPC++; /* Get LSB first */
16133 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16134 if (!(cpu.z80F & Z80_FLAG_CARRY))
16136 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16138 break;
16140 case 0xd3:
16142 sdwCyclesRemaining -= 11;
16143 dwTemp = *pbPC++;
16144 psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */
16145 while (psIoWrite->lowIoAddr != 0xffff)
16147 if ((dwTemp >= psIoWrite->lowIoAddr) && (dwTemp <= psIoWrite->highIoAddr))
16149 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16150 psIoWrite->IOCall(dwTemp, cpu.z80A, psIoWrite);
16151 psIoWrite = NULL;
16152 break;
16154 ++psIoWrite;
16157 break;
16159 case 0xd4:
16161 sdwCyclesRemaining -= 10;
16162 dwAddr = *pbPC++; /* Get LSB first */
16163 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16164 if (!(cpu.z80F & Z80_FLAG_CARRY))
16166 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16167 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16168 *pbSP-- = cpu.z80pc >> 8; /* MSB */
16169 *pbSP = (UINT8) cpu.z80pc; /* LSB */
16170 cpu.z80sp -= 2; /* Back our stack up */
16171 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16173 break;
16175 case 0xd5:
16177 sdwCyclesRemaining -= 11;
16178 cpu.z80sp -= 2;
16179 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
16180 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
16181 while (psMemWrite->lowAddr != 0xffffffff)
16183 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
16185 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16186 if (psMemWrite->memoryCall)
16188 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80DE & 0xff), psMemWrite);
16189 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80DE >> 8), psMemWrite);
16191 else
16193 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80DE;
16194 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80DE >> 8;
16196 psMemWrite = NULL;
16197 break;
16199 ++psMemWrite;
16202 if (psMemWrite)
16204 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80DE;
16205 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80DE >> 8);
16208 break;
16210 case 0xd6:
16212 sdwCyclesRemaining -= 7;
16213 bTemp = *pbPC++;
16214 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
16215 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
16216 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp];
16217 cpu.z80A -= bTemp;
16218 break;
16220 case 0xd7:
16222 sdwCyclesRemaining -= 11;
16223 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16224 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16225 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16226 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16227 cpu.z80sp -= 2; /* Back our stack up */
16228 pbPC = cpu.z80Base + 0x10; /* Normalize the address */
16229 break;
16231 case 0xd8:
16233 sdwCyclesRemaining -= 5;
16234 if (cpu.z80F & Z80_FLAG_CARRY)
16236 dwElapsedTicks += 6;
16237 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
16238 dwAddr = *pbSP++; /* Pop LSB */
16239 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
16240 cpu.z80sp += 2; /* Pop the word off */
16241 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
16243 break;
16245 case 0xd9:
16247 sdwCyclesRemaining -= 4;
16248 dwTemp = cpu.z80DE;
16249 cpu.z80DE = cpu.z80deprime;
16250 cpu.z80deprime = dwTemp;
16251 dwTemp = cpu.z80BC;
16252 cpu.z80BC = cpu.z80bcprime;
16253 cpu.z80bcprime = dwTemp;
16254 dwTemp = cpu.z80HL;
16255 cpu.z80HL = cpu.z80hlprime;
16256 cpu.z80hlprime = dwTemp;
16257 break;
16259 case 0xda:
16261 sdwCyclesRemaining -= 10;
16262 dwAddr = *pbPC++; /* Get LSB first */
16263 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16264 if (cpu.z80F & Z80_FLAG_CARRY)
16266 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16268 break;
16270 case 0xdb:
16272 sdwCyclesRemaining -= 11;
16273 dwTemp = *pbPC++;
16274 psIoRead = cpu.z80IoRead; /* Beginning of our handler */
16275 while (psIoRead->lowIoAddr != 0xffff)
16277 if ((dwTemp >= psIoRead->lowIoAddr) && (dwTemp <= psIoRead->highIoAddr))
16279 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16280 cpu.z80A = psIoRead->IOCall(dwTemp, psIoRead);
16281 psIoRead = NULL;
16282 break;
16284 ++psIoRead;
16287 if (psIoRead)
16289 cpu.z80A = 0xff; /* Unclaimed I/O read */
16292 break;
16294 case 0xdc:
16296 sdwCyclesRemaining -= 10;
16297 dwAddr = *pbPC++; /* Get LSB first */
16298 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16299 if (cpu.z80F & Z80_FLAG_CARRY)
16301 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16302 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16303 *pbSP-- = cpu.z80pc >> 8; /* MSB */
16304 *pbSP = (UINT8) cpu.z80pc; /* LSB */
16305 cpu.z80sp -= 2; /* Back our stack up */
16306 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16308 break;
16310 case 0xdd:
16312 DDHandler();
16313 break;
16315 case 0xde:
16317 sdwCyclesRemaining -= 7;
16318 bTemp = *pbPC++ + (cpu.z80F & Z80_FLAG_CARRY);
16319 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
16320 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
16321 pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];
16322 cpu.z80A = cpu.z80A - bTemp;
16323 break;
16325 case 0xdf:
16327 sdwCyclesRemaining -= 11;
16328 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16329 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16330 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16331 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16332 cpu.z80sp -= 2; /* Back our stack up */
16333 pbPC = cpu.z80Base + 0x18; /* Normalize the address */
16334 break;
16336 case 0xe0:
16338 sdwCyclesRemaining -= 5;
16339 if (!(cpu.z80F & Z80_FLAG_OVERFLOW_PARITY))
16341 dwElapsedTicks += 6;
16342 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
16343 dwAddr = *pbSP++; /* Pop LSB */
16344 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
16345 cpu.z80sp += 2; /* Pop the word off */
16346 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
16348 break;
16350 case 0xe1:
16352 sdwCyclesRemaining -= 10;
16353 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
16354 while (psMemRead->lowAddr != 0xffffffff)
16356 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
16358 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16359 if (psMemRead->memoryCall)
16361 cpu.z80HL = psMemRead->memoryCall(cpu.z80sp, psMemRead);
16362 cpu.z80HL |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
16364 else
16366 cpu.z80HL = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
16367 cpu.z80HL |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
16369 psMemRead = NULL;
16370 break;
16372 ++psMemRead;
16375 if (psMemRead)
16377 cpu.z80HL = cpu.z80Base[cpu.z80sp];
16378 cpu.z80HL |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
16381 cpu.z80sp += 2;
16382 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
16383 break;
16385 case 0xe2:
16387 sdwCyclesRemaining -= 10;
16388 dwAddr = *pbPC++; /* Get LSB first */
16389 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16390 if (!(cpu.z80F & Z80_FLAG_OVERFLOW_PARITY))
16392 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16394 break;
16396 case 0xe3:
16398 sdwCyclesRemaining -= 19;
16399 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
16400 while (psMemRead->lowAddr != 0xffffffff)
16402 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
16404 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16405 if (psMemRead->memoryCall)
16407 dwAddr = psMemRead->memoryCall(cpu.z80sp, psMemRead);
16408 dwAddr |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
16410 else
16412 dwAddr = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
16413 dwAddr |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
16415 psMemRead = NULL;
16416 break;
16418 ++psMemRead;
16421 if (psMemRead)
16423 dwAddr = cpu.z80Base[cpu.z80sp];
16424 dwAddr |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
16427 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
16428 while (psMemWrite->lowAddr != 0xffffffff)
16430 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
16432 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16433 if (psMemWrite->memoryCall)
16435 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80HL & 0xff), psMemWrite);
16436 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80HL >> 8), psMemWrite);
16438 else
16440 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80HL;
16441 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80HL >> 8;
16443 psMemWrite = NULL;
16444 break;
16446 ++psMemWrite;
16449 if (psMemWrite)
16451 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80HL;
16452 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80HL >> 8);
16455 cpu.z80HL = dwAddr;
16456 break;
16458 case 0xe4:
16460 sdwCyclesRemaining -= 10;
16461 dwAddr = *pbPC++; /* Get LSB first */
16462 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16463 if (!(cpu.z80F & Z80_FLAG_OVERFLOW_PARITY))
16465 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16466 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16467 *pbSP-- = cpu.z80pc >> 8; /* MSB */
16468 *pbSP = (UINT8) cpu.z80pc; /* LSB */
16469 cpu.z80sp -= 2; /* Back our stack up */
16470 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16472 break;
16474 case 0xe5:
16476 sdwCyclesRemaining -= 11;
16477 cpu.z80sp -= 2;
16478 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
16479 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
16480 while (psMemWrite->lowAddr != 0xffffffff)
16482 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
16484 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16485 if (psMemWrite->memoryCall)
16487 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80HL & 0xff), psMemWrite);
16488 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80HL >> 8), psMemWrite);
16490 else
16492 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80HL;
16493 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80HL >> 8;
16495 psMemWrite = NULL;
16496 break;
16498 ++psMemWrite;
16501 if (psMemWrite)
16503 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80HL;
16504 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80HL >> 8);
16507 break;
16509 case 0xe6:
16511 sdwCyclesRemaining -= 7;
16512 cpu.z80A &= *pbPC++;
16513 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
16514 cpu.z80F |= bPostANDFlags[cpu.z80A];
16516 break;
16518 case 0xe7:
16520 sdwCyclesRemaining -= 11;
16521 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16522 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16523 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16524 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16525 cpu.z80sp -= 2; /* Back our stack up */
16526 pbPC = cpu.z80Base + 0x20; /* Normalize the address */
16527 break;
16529 case 0xe8:
16531 sdwCyclesRemaining -= 5;
16532 if (cpu.z80F & Z80_FLAG_OVERFLOW_PARITY)
16534 dwElapsedTicks += 6;
16535 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
16536 dwAddr = *pbSP++; /* Pop LSB */
16537 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
16538 cpu.z80sp += 2; /* Pop the word off */
16539 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
16541 break;
16543 case 0xe9:
16545 sdwCyclesRemaining -= 4;
16546 pbPC = cpu.z80Base + cpu.z80HL;
16547 break;
16549 case 0xea:
16551 sdwCyclesRemaining -= 10;
16552 dwAddr = *pbPC++; /* Get LSB first */
16553 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16554 if (cpu.z80F & Z80_FLAG_OVERFLOW_PARITY)
16556 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16558 break;
16560 case 0xeb:
16562 sdwCyclesRemaining -= 4;
16563 dwAddr = cpu.z80DE;
16564 cpu.z80DE = cpu.z80HL;
16565 cpu.z80HL = dwAddr;
16566 break;
16568 case 0xec:
16570 sdwCyclesRemaining -= 10;
16571 dwAddr = *pbPC++; /* Get LSB first */
16572 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16573 if (cpu.z80F & Z80_FLAG_OVERFLOW_PARITY)
16575 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16576 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16577 *pbSP-- = cpu.z80pc >> 8; /* MSB */
16578 *pbSP = (UINT8) cpu.z80pc; /* LSB */
16579 cpu.z80sp -= 2; /* Back our stack up */
16580 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16582 break;
16584 case 0xed:
16586 EDHandler();
16587 break;
16589 case 0xee:
16591 sdwCyclesRemaining -= 7;
16592 cpu.z80A ^= *pbPC++;
16593 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
16594 cpu.z80F |= bPostORFlags[cpu.z80A];
16596 break;
16598 case 0xef:
16600 sdwCyclesRemaining -= 11;
16601 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16602 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16603 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16604 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16605 cpu.z80sp -= 2; /* Back our stack up */
16606 pbPC = cpu.z80Base + 0x28; /* Normalize the address */
16607 break;
16609 case 0xf0:
16611 sdwCyclesRemaining -= 5;
16612 if (!(cpu.z80F & Z80_FLAG_SIGN))
16614 dwElapsedTicks += 6;
16615 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
16616 dwAddr = *pbSP++; /* Pop LSB */
16617 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
16618 cpu.z80sp += 2; /* Pop the word off */
16619 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
16621 break;
16623 case 0xf1:
16625 sdwCyclesRemaining -= 10;
16626 psMemRead = cpu.z80MemRead; /* Beginning of our handler */
16627 while (psMemRead->lowAddr != 0xffffffff)
16629 if ((cpu.z80sp >= psMemRead->lowAddr) && (cpu.z80sp <= psMemRead->highAddr))
16631 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16632 if (psMemRead->memoryCall)
16634 cpu.z80AF = psMemRead->memoryCall(cpu.z80sp, psMemRead);
16635 cpu.z80AF |= (UINT32) ((UINT32) psMemRead->memoryCall(cpu.z80sp + 1, psMemRead) << 8);
16637 else
16639 cpu.z80AF = *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr));
16640 cpu.z80AF |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (cpu.z80sp - psMemRead->lowAddr + 1)) << 8);
16642 psMemRead = NULL;
16643 break;
16645 ++psMemRead;
16648 if (psMemRead)
16650 cpu.z80AF = cpu.z80Base[cpu.z80sp];
16651 cpu.z80AF |= (UINT32) ((UINT32) cpu.z80Base[cpu.z80sp + 1] << 8);
16654 cpu.z80sp += 2;
16655 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
16656 break;
16658 case 0xf2:
16660 sdwCyclesRemaining -= 10;
16661 dwAddr = *pbPC++; /* Get LSB first */
16662 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16663 if (!(cpu.z80F & Z80_FLAG_SIGN))
16665 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16667 break;
16669 case 0xf3:
16671 sdwCyclesRemaining -= 4;
16672 cpu.z80iff &= (~IFF1);
16673 break;
16675 case 0xf4:
16677 sdwCyclesRemaining -= 10;
16678 dwAddr = *pbPC++; /* Get LSB first */
16679 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16680 if (!(cpu.z80F & Z80_FLAG_SIGN))
16682 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16683 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16684 *pbSP-- = cpu.z80pc >> 8; /* MSB */
16685 *pbSP = (UINT8) cpu.z80pc; /* LSB */
16686 cpu.z80sp -= 2; /* Back our stack up */
16687 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16689 break;
16691 case 0xf5:
16693 sdwCyclesRemaining -= 11;
16694 cpu.z80sp -= 2;
16695 pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */
16696 psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */
16697 while (psMemWrite->lowAddr != 0xffffffff)
16699 if ((cpu.z80sp >= psMemWrite->lowAddr) && (cpu.z80sp <= psMemWrite->highAddr))
16701 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16702 if (psMemWrite->memoryCall)
16704 psMemWrite->memoryCall(cpu.z80sp, (cpu.z80AF & 0xff), psMemWrite);
16705 psMemWrite->memoryCall(cpu.z80sp + 1, (cpu.z80AF >> 8), psMemWrite);
16707 else
16709 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr)) = cpu.z80AF;
16710 *((UINT8 *) psMemWrite->pUserArea + (cpu.z80sp - psMemWrite->lowAddr) + 1) = cpu.z80AF >> 8;
16712 psMemWrite = NULL;
16713 break;
16715 ++psMemWrite;
16718 if (psMemWrite)
16720 cpu.z80Base[cpu.z80sp] = (UINT8) cpu.z80AF;
16721 cpu.z80Base[cpu.z80sp + 1] = (UINT8) ((UINT32) cpu.z80AF >> 8);
16724 break;
16726 case 0xf6:
16728 sdwCyclesRemaining -= 7;
16729 cpu.z80A |= *pbPC++;
16730 cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);
16731 cpu.z80F |= bPostORFlags[cpu.z80A];
16733 break;
16735 case 0xf7:
16737 sdwCyclesRemaining -= 11;
16738 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16739 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16740 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16741 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16742 cpu.z80sp -= 2; /* Back our stack up */
16743 pbPC = cpu.z80Base + 0x30; /* Normalize the address */
16744 break;
16746 case 0xf8:
16748 sdwCyclesRemaining -= 5;
16749 if (cpu.z80F & Z80_FLAG_SIGN)
16751 dwElapsedTicks += 6;
16752 pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */
16753 dwAddr = *pbSP++; /* Pop LSB */
16754 dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */
16755 cpu.z80sp += 2; /* Pop the word off */
16756 pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */
16758 break;
16760 case 0xf9:
16762 sdwCyclesRemaining -= 6;
16763 cpu.z80sp = cpu.z80HL;
16764 break;
16766 case 0xfa:
16768 sdwCyclesRemaining -= 10;
16769 dwAddr = *pbPC++; /* Get LSB first */
16770 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16771 if (cpu.z80F & Z80_FLAG_SIGN)
16773 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16775 break;
16777 case 0xfb:
16779 sdwCyclesRemaining -= 4;
16780 cpu.z80iff |= IFF1;
16781 break;
16783 case 0xfc:
16785 sdwCyclesRemaining -= 10;
16786 dwAddr = *pbPC++; /* Get LSB first */
16787 dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */
16788 if (cpu.z80F & Z80_FLAG_SIGN)
16790 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16791 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16792 *pbSP-- = cpu.z80pc >> 8; /* MSB */
16793 *pbSP = (UINT8) cpu.z80pc; /* LSB */
16794 cpu.z80sp -= 2; /* Back our stack up */
16795 pbPC = cpu.z80Base + dwAddr; /* Normalize the address */
16797 break;
16799 case 0xfd:
16801 FDHandler();
16802 break;
16804 case 0xfe:
16806 sdwCyclesRemaining -= 7;
16807 cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY |
16808 Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |
16809 pbSubSbcTable[((UINT32) cpu.z80A << 8) | *pbPC++];
16810 break;
16812 case 0xff:
16814 sdwCyclesRemaining -= 11;
16815 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16816 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16817 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16818 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16819 cpu.z80sp -= 2; /* Back our stack up */
16820 pbPC = cpu.z80Base + 0x38; /* Normalize the address */
16821 break;
16826 dwElapsedTicks += (dwOriginalCycles - sdwCyclesRemaining);
16828 cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;
16829 return(dwReturnCode); /* Indicate success */
16832 /* Get mz80's context */
16834 void mz80GetContext(void *pData)
16836 memcpy(pData, &cpu, sizeof(CONTEXTMZ80));
16839 /* Set mz80's context */
16841 void mz80SetContext(void *pData)
16843 memcpy(&cpu, pData, sizeof(CONTEXTMZ80));
16846 /* Get mz80's context size */
16848 UINT32 mz80GetContextSize(void)
16850 return(sizeof(CONTEXTMZ80));
16853 /* This will return the elapsed ticks */
16855 UINT32 mz80GetElapsedTicks(UINT32 dwClear)
16857 UINT32 dwTemp = dwElapsedTicks;
16859 if (dwClear)
16861 dwElapsedTicks = 0;
16864 return(dwTemp);
16867 /* Releases mz80 from its current timeslice */
16869 void mz80ReleaseTimeslice(void)
16871 dwOriginalCycles -= sdwCyclesRemaining;
16872 sdwCyclesRemaining = 0;
16875 /* This routine is mz80's reset handler */
16877 void mz80reset(void)
16879 cpu.z80halted = 0;
16880 cpu.z80AF = 0;
16881 cpu.z80F = Z80_FLAG_ZERO;
16882 cpu.z80BC = 0;
16883 cpu.z80DE = 0;
16884 cpu.z80HL = 0;
16885 cpu.z80afprime = 0;
16886 cpu.z80bcprime = 0;
16887 cpu.z80deprime = 0;
16888 cpu.z80hlprime = 0;
16889 cpu.z80i = 0;
16890 cpu.z80r = 0;
16891 cpu.z80IX = 0xffff; /* Yes, this is intentional */
16892 cpu.z80IY = 0xffff; /* Yes, this is intentional */
16893 cpu.z80pc = 0;
16894 cpu.z80sp = 0;
16895 cpu.z80interruptMode = 0;
16896 cpu.z80intAddr = 0x38;
16897 cpu.z80nmiAddr = 0x66;
16900 /* Interrupt handler */
16902 UINT32 mz80int(UINT32 dwLowAddr)
16904 cpu.z80halted = 0;
16905 if (0 == (cpu.z80iff & IFF1))
16906 return(0xffffffff);
16907 cpu.z80iff &= ~(IFF1 | IFF2);
16908 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16909 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16910 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16911 cpu.z80sp -= 2; /* Back our stack up */
16912 if (2 == cpu.z80interruptMode)
16914 cpu.z80pc = ((UINT16) cpu.z80i << 8) | (dwLowAddr & 0xff);
16915 cpu.z80pc = ((UINT16) cpu.z80Base[cpu.z80pc + 1] << 8) | (cpu.z80Base[cpu.z80pc]);
16917 else
16919 cpu.z80pc = cpu.z80intAddr;
16921 pbPC = cpu.z80Base + cpu.z80pc; /* Normalize the address */
16922 return(0);
16925 /* NMI Handler */
16927 UINT32 mz80nmi(void)
16929 cpu.z80halted = 0;
16930 pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */
16931 *pbSP-- = cpu.z80pc >> 8; /* LSB */
16932 *pbSP = (UINT8) cpu.z80pc; /* MSB */
16933 cpu.z80sp -= 2; /* Back our stack up */
16934 cpu.z80pc = cpu.z80nmiAddr; /* Our NMI */
16935 return(0);
16938 /* Initialize MZ80 for action */
16940 void mz80init(void)
16942 UINT32 dwLoop;
16943 UINT8 *pbTempPtr;
16944 UINT8 *pbTempPtr2;
16945 UINT8 bNewAdd;
16946 UINT8 bNewSub;
16947 UINT8 bFlag;
16948 UINT8 bLow;
16949 UINT8 bHigh;
16950 UINT8 bCarry;
16952 if (NULL == pbAddAdcTable)
16954 pbAddAdcTable = malloc(256*256*2);
16956 if (NULL == pbAddAdcTable)
16958 return;
16961 pbTempPtr = pbAddAdcTable;
16963 pbSubSbcTable = malloc(256*256*2);
16965 if (NULL == pbSubSbcTable)
16967 return;
16970 pbTempPtr2 = pbSubSbcTable;
16972 for (dwLoop = 0; dwLoop < (256*256*2); dwLoop++)
16974 bLow = dwLoop & 0xff;
16975 bHigh = (dwLoop >> 8) & 0xff;
16976 bCarry = (dwLoop >> 16);
16978 bFlag = 0;
16979 bNewAdd = bHigh + bLow + bCarry;
16981 if (0 == bNewAdd)
16983 bFlag |= Z80_FLAG_ZERO;
16985 else
16987 bFlag = bNewAdd & 0x80; /* Sign flag */
16990 if (((UINT32) bLow + (UINT32) bHigh + (UINT32) bCarry) >= 0x100)
16992 bFlag |= Z80_FLAG_CARRY;
16995 if ( ((bLow ^ bHigh ^ 0x80) & (bLow ^ (bNewAdd & 0x80))) & 0x80)
16997 bFlag |= Z80_FLAG_OVERFLOW_PARITY;
17000 if (((bLow & 0x0f) + (bHigh & 0x0f) + bCarry) >= 0x10)
17002 bFlag |= Z80_FLAG_HALF_CARRY;
17005 *pbTempPtr++ = bFlag; /* Store our new flag */
17007 // Now do subtract - Zero
17009 bFlag = Z80_FLAG_NEGATIVE;
17010 bNewSub = bHigh - bLow - bCarry;
17012 if (0 == bNewSub)
17014 bFlag |= Z80_FLAG_ZERO;
17016 else
17018 bFlag |= bNewSub & 0x80; /* Sign flag */
17021 if ( ((INT32) bHigh - (INT32) bLow - (INT32) bCarry) < 0)
17023 bFlag |= Z80_FLAG_CARRY;
17026 if ( ((INT32) (bHigh & 0xf) - (INT32) (bLow & 0x0f) - (INT32) bCarry) < 0)
17028 bFlag |= Z80_FLAG_HALF_CARRY;
17031 if ( ((bLow ^ bHigh) & (bHigh ^ bNewSub) & 0x80) )
17033 bFlag |= Z80_FLAG_OVERFLOW_PARITY;
17036 *pbTempPtr2++ = bFlag; /* Store our sub flag */
17041 /* Shut down MZ80 */
17043 void mz80shutdown(void)