1 /*
2  * libtilemcore - Graphing calculator emulation library
3  *
4  * Copyright (C) 2009-2011 Benjamin Moody
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 /* Flag magic:
22 
23    S (the Sign flag) is set when the result is negative (i.e., copied
24    from the MS bit.)
25 
26    Z (the Zero flag) is set when the result is zero.
27 
28    Y (undocumented flag) is usually copied from the result.
29 
30    H (the Half-carry flag) is set when a carry occurs from LS to MS
31    nibble.  Since bit 4 of the result is equal to (bit 4 of first arg)
32    xor (bit 4 of second arg) xor H, we can infer that H equals (bit 4
33    of first arg) xor (bit 4 of second arg) xor (bit 4 of result).
34 
35    X (undocumented flag) is copied from the same place as is Y.
36 
37    P (parity flag) is set -- by logic operations -- when the result
38    has even parity; i.e., it's the xor of all the bits of the result
39    and 1.
40 
41    V (overflow flag, which is another name for the parity flag) is set
42    -- by arithmetic operations -- when the result overflows.  This can
43    happen when a positive plus a positive is negative, or a negative
44    plus a negative is positive, or a positive minus a negative is
45    negative, or a negative minus a positive is positive.
46 
47    (In 8 bits, a positive plus a negative is at least 0 + -128 = -128
48    and at most 127 + -1 + 1 = 127.  A positive minus a positive is at
49    least 0 - 127 - 1 = -128 and at most 127 - 0 = 127.  A negative
50    minus a negative is at least -128 - -1 - 1 = -128 and at most -1 -
51    -128 = 127.  Thus these cases can never overflow.)
52 
53    When adding, then, overflow occurs if the args are equal in the
54    MS bit and the result differs in the MS bit.
55 
56    When subtracting, overflow occurs if the args differ in the MS
57    bit and the result differs from the first arg in the MS bit.
58 
59    N (subtract flag) is set or cleared depending on the operation.
60 
61    C (carry flag) is the leftover bit after an addition or
62    subtraction.
63 */
64 
65 #define FLAG_XY (FLAG_X | FLAG_Y)
66 #define FLAG_XYC (FLAG_X | FLAG_Y | FLAG_C)
67 #define FLAG_SXY (FLAG_S | FLAG_X | FLAG_Y)
68 #define FLAG_SXYC (FLAG_S | FLAG_X | FLAG_Y | FLAG_C)
69 #define FLAG_ZP (FLAG_Z | FLAG_P)
70 #define FLAG_SZPC (FLAG_S | FLAG_Z | FLAG_P | FLAG_C)
71 
72 #define lsb(xxx) ((xxx) & 0xff)
73 
74 #define UNDOCUMENTED(clks)						\
75 	if (calc->z80.emuflags & TILEM_Z80_BREAK_UNDOCUMENTED)		\
76 		tilem_z80_stop(calc, TILEM_STOP_UNDOCUMENTED_INST);	\
77 	if (calc->z80.emuflags & TILEM_Z80_SKIP_UNDOCUMENTED) {		\
78 		delay(clks);						\
79 		break;							\
80 	}								\
81 	if (calc->z80.emuflags & TILEM_Z80_RESET_UNDOCUMENTED) {	\
82 		tilem_warning(calc, "Invalid opcode %x", op);		\
83 		tilem_z80_exception(calc, TILEM_EXC_INSTRUCTION);	\
84 		break;							\
85 	}
86 
87 #define add8(dst, src) do {						\
88 		word arg1 = (dst);					\
89 		word arg2 = (src);					\
90 		word res = arg1 + arg2;					\
91 		byte resb = res;					\
92 		F = ((res & FLAG_SXY)			/* S/X/Y */	\
93 		     | (resb ? 0 : FLAG_Z)		/* Z */		\
94 		     | ((arg1 ^ arg2 ^ res) & FLAG_H)	/* H */		\
95 		     | (((arg1 ^ ~arg2) & (arg1 ^ res) & 0x80) >> 5)	\
96 		     | (res >> 8));			/* C */		\
97 		(dst) = resb;						\
98 	} while (0)
99 
100 #define adc8(dst, src) do {						\
101 		word arg1 = (dst);					\
102 		word arg2 = (src);					\
103 		word res = arg1 + arg2 + (F & 1);			\
104 		byte resb = res;					\
105 		F = ((res & FLAG_SXY)			/* S/X/Y */	\
106 		     | (resb ? 0 : FLAG_Z)		/* Z */		\
107 		     | ((arg1 ^ arg2 ^ res) & FLAG_H)	/* H */		\
108 		     | (((arg1 ^ ~arg2) & (arg1 ^ res) & 0x80) >> 5)	\
109 		     | (res >> 8));			/* C */		\
110 		(dst) = resb;						\
111 	} while (0)
112 
113 #define sub8(dst, src) do {						\
114 		word arg1 = (dst);					\
115 		word arg2 = (src);					\
116 		word res = arg1 - arg2;					\
117 		byte resb = res;					\
118 		F = ((res & FLAG_SXY)			/* S/X/Y */	\
119 		     | (resb ? 0 : FLAG_Z)		/* Z */		\
120 		     | ((arg1 ^ arg2 ^ res) & FLAG_H)	/* H */		\
121 		     | (((arg1 ^ arg2) & (arg1 ^ res) & 0x80) >> 5)	\
122 		     | (FLAG_N)				/* N */		\
123 		     | ((res >> 8) & 1));		/* C */		\
124 		(dst) = resb;						\
125 	} while (0)
126 
127 #define sbc8(dst, src) do {						\
128 		word arg1 = (dst);					\
129 		word arg2 = (src);					\
130 		word res = arg1 - arg2 - (F & 1);			\
131 		byte resb = res;					\
132 		F = ((res & FLAG_SXY)			/* S/X/Y */	\
133 		     | (resb ? 0 : FLAG_Z)		/* Z */		\
134 		     | ((arg1 ^ arg2 ^ res) & FLAG_H)	/* H */		\
135 		     | (((arg1 ^ arg2) & (arg1 ^ res) & 0x80) >> 5)	\
136 		     | (FLAG_N)				/* N */		\
137 		     | ((res >> 8) & 1));		/* C */		\
138 		(dst) = resb;						\
139 	} while (0)
140 
141 #define and(dst, src) do {						\
142 		byte arg1 = (dst);					\
143 		byte arg2 = (src);					\
144 		byte res = (arg1 & arg2);				\
145 		F = ((res & FLAG_SXY)			/* S/X/Y */	\
146 		     | (res ? 0 : FLAG_Z)		/* Z */		\
147 		     | (FLAG_H)				/* H */		\
148 		     | parity_table[res]);		/* P */		\
149 		(dst) = res;						\
150 	} while (0)
151 
152 #define xor(dst, src) do {						\
153 		byte arg1 = (dst);					\
154 		byte arg2 = (src);					\
155 		byte res = (arg1 ^ arg2);				\
156 		F = ((res & FLAG_SXY)			/* S/X/Y */	\
157 		     | (res ? 0 : FLAG_Z)		/* Z */		\
158 		     | parity_table[res]);		/* P */		\
159 		(dst) = res;						\
160 	} while (0)
161 
162 #define or(dst, src) do {						\
163 		byte arg1 = (dst);					\
164 		byte arg2 = (src);					\
165 		byte res = (arg1 | arg2);				\
166 		F = ((res & FLAG_SXY)			/* S/X/Y */	\
167 		     | (res ? 0 : FLAG_Z)		/* Z */		\
168 		     | parity_table[res]);		/* P */		\
169 		(dst) = res;						\
170 	} while (0)
171 
172 #define cp(dst, src) do {						\
173 		word arg1 = (dst);					\
174 		word arg2 = (src);					\
175 		word res = arg1 - arg2;					\
176 		byte resb = res;					\
177 		F = ((res & FLAG_SXY)	                /* S/X/Y */	\
178 		     | (resb ? 0 : FLAG_Z)		/* Z */	\
179 		     | ((arg1 ^ arg2 ^ res) & FLAG_H)	/* H */		\
180 		     | (((arg1 ^ arg2) & (arg1 ^ res) & 0x80) >> 5)	\
181 		     | (FLAG_N)		                /* N */		\
182 		     | ((res >> 8) & 1));		/* C */		\
183 	} while (0)
184 
185 
186 #define add16(dst, src) do {						\
187 		dword arg1 = (dst);					\
188 		dword arg2 = (src);					\
189 		dword res = arg1 + arg2;				\
190 		F = ((F & (FLAG_S | FLAG_Z | FLAG_P))			\
191 		     | ((res >> 8) & FLAG_XY)		     /* X/Y */	\
192 		     | (((arg1 ^ arg2 ^ res) >> 8) & FLAG_H) /* H */	\
193 		     | (res >> 16));		   	     /* C */	\
194 		(dst) = res;						\
195 	} while (0)
196 
197 #define adc16(dst, src) do {						\
198 		dword arg1 = (dst);					\
199 		dword arg2 = (src);					\
200 		dword res = arg1 + arg2 + (F & 1);			\
201 		word resw = res;					\
202 		F = (((res >> 8) & FLAG_SXY)		     /* S/X/Y */\
203 		     | (resw ? 0 : FLAG_Z)		     /* Z */	\
204 		     | (((arg1 ^ arg2 ^ res) >> 8) & FLAG_H) /* H */	\
205 		     | (((arg1 ^ ~arg2) & (arg1 ^ res) & 0x8000) >> 11) \
206 		     | (res >> 16));		     	     /* C */	\
207 		(dst) = resw;						\
208 	} while (0)
209 
210 #define sbc16(dst, src) do {						\
211 		dword arg1 = (dst);					\
212 		dword arg2 = (src);					\
213 		dword res = arg1 - arg2 - (F & 1);			\
214 		word resw = res;					\
215 		F = (((res >> 8) & FLAG_SXY)		     /* S/X/Y */\
216 		     | (resw ? 0 : FLAG_Z)		     /* Z */	\
217 		     | (((arg1 ^ arg2 ^ res) >> 8) & FLAG_H) /* H */	\
218 		     | (((arg1 ^ arg2) & (arg1 ^ res) & 0x8000) >> 11)	\
219 		     | (FLAG_N)				     /* N */	\
220 		     | ((res >> 16) & 1));		     /* C */	\
221 		(dst) = resw;						\
222 	} while (0)
223 
224 
225 #define inc(reg) do {						\
226 		byte arg = (reg);				\
227 		byte res = arg + 1;				\
228 		F = ((res & FLAG_SXY)	       	    /* S/X/Y */	\
229 		     | (res ? 0 : FLAG_Z)	    /* Z */	\
230 		     | ((arg ^ res) & FLAG_H)	    /* H */	\
231 		     | (res == 0x80 ? FLAG_V : 0)   /* V */	\
232 		     | (F & FLAG_C));				\
233 		(reg) = res;					\
234 	} while (0)
235 
236 #define dec(reg) do {						\
237 		byte arg = (reg);				\
238 		byte res = arg - 1;				\
239 		F = ((res & FLAG_SXY)	       	    /* S/X/Y */	\
240 		     | (res ? 0 : FLAG_Z)	    /* Z */	\
241 		     | ((arg ^ res) & FLAG_H)	    /* H */	\
242 		     | (res == 0x7f ? FLAG_V : 0)   /* V */	\
243 		     | (FLAG_N)			    /* N */	\
244 		     | (F & FLAG_C));				\
245 		(reg) = res;					\
246 	} while (0)
247 
248 
249 #define cpl(reg) do {						\
250 		byte arg = (reg);				\
251 		byte res = ~arg;				\
252 		F = ((res & FLAG_XY)		/* X/Y */	\
253 		     | FLAG_H | FLAG_N		/* H/N */	\
254 		     | (F & FLAG_SZPC));			\
255 		(reg) = res;					\
256 	} while (0)
257 
258 #define neg(reg) do {						\
259 		byte arg = (reg);				\
260 		byte res = -arg;				\
261 		F = ((res & FLAG_SXY)		    /* S/X/Y */	\
262 		     | (res ? 0 : FLAG_Z)	    /* Z */	\
263 		     | ((arg ^ res) & FLAG_H)	    /* H */	\
264 		     | (arg == 0x80 ? FLAG_V : 0)   /* V */	\
265 		     | (FLAG_N)			    /* N */	\
266 		     | (!!arg));		    /* C */	\
267 		(reg) = res;					\
268 	} while (0)
269 
270 #define daa do {							\
271 		word idx = (((F & 0x10) << 6) | ((F & 0x03) << 8) | A);	\
272 		AF = daa_table[idx];					\
273 	} while (0)
274 
275 
276 #define rlca do {							\
277 		byte arg = A;						\
278 		byte res = ((arg << 1) | (arg >> 7));			\
279 		F = ((F & (FLAG_S | FLAG_Z | FLAG_P))			\
280 		     | (res & FLAG_XYC));	          /* X/Y/C */	\
281 		A = res;						\
282 	} while (0)
283 
284 #define rrca do {						\
285 		byte arg = A;					\
286 		byte res = ((arg >> 1) | (arg << 7));		\
287 		F = ((F & (FLAG_S | FLAG_Z | FLAG_P))		\
288 		     | (res & FLAG_XY)	          /* X/Y */	\
289 		     | (arg & FLAG_C));		  /* C */	\
290 		A = res;					\
291 	} while (0)
292 
293 #define rla do {						\
294 		byte arg = A;					\
295 		byte res = ((arg << 1) | (F & 1));		\
296 		F = ((F & (FLAG_S | FLAG_Z | FLAG_P))		\
297 		     | (res & FLAG_XY)	          /* X/Y */	\
298 		     | (arg >> 7));		  /* C */	\
299 		A = res;					\
300 	} while (0)
301 
302 #define rra do {						\
303 		byte arg = A;					\
304 		byte res = ((arg >> 1) | (F << 7));		\
305 		F = ((F & (FLAG_S | FLAG_Z | FLAG_P))		\
306 		     | (res & FLAG_XY)		  /* X/Y */	\
307 		     | (arg & FLAG_C));		  /* C */	\
308 		A = res;					\
309 	} while (0)
310 
311 #define rlc(reg) do {						\
312 		byte arg = (reg);				\
313 		byte res = ((arg << 1) | (arg >> 7));		\
314 		F = ((res & FLAG_SXYC)	          /* S/X/Y/C */ \
315 		     | (res ? 0 : FLAG_Z)	  /* Z */       \
316 		     | parity_table[res]);	  /* P */	\
317 		(reg) = res;					\
318 	} while (0)
319 
320 #define rrc(reg) do {						\
321 		byte arg = (reg);				\
322 		byte res = ((arg >> 1) | (arg << 7));		\
323 		F = ((res & FLAG_SXY)	          /* S/X/Y */	\
324 		     | (res ? 0 : FLAG_Z)	  /* Z */	\
325 		     | parity_table[res]	  /* P */	\
326 		     | (arg & FLAG_C));		  /* C */	\
327 		(reg) = res;					\
328 	} while (0)
329 
330 #define rl(reg) do {						\
331 		byte arg = (reg);				\
332 		byte res = ((arg << 1) | (F & 1));		\
333 		F = ((res & FLAG_SXY)	          /* S/X/Y */	\
334 		     | (res ? 0 : FLAG_Z)	  /* Z */	\
335 		     | parity_table[res]	  /* P */	\
336 		     | (arg >> 7));		  /* C */	\
337 		(reg) = res;					\
338 	} while (0)
339 
340 #define rr(reg) do {						\
341 		byte arg = (reg);				\
342 		byte res = ((arg >> 1) | (F << 7));		\
343 		F = ((res & FLAG_SXY)	          /* S/X/Y */	\
344 		     | (res ? 0 : FLAG_Z)	  /* Z */	\
345 		     | parity_table[res]	  /* P */	\
346 		     | (arg & FLAG_C));		  /* C */	\
347 		(reg) = res;					\
348 	} while (0)
349 
350 #define sla(reg) do {						\
351 		byte arg = (reg);				\
352 		byte res = (arg << 1);				\
353 		F = ((res & FLAG_SXY)	          /* S/X/Y */	\
354 		     | (res ? 0 : FLAG_Z)	  /* Z */	\
355 		     | parity_table[res]	  /* P */	\
356 		     | (arg >> 7));		  /* C */	\
357 		(reg) = res;					\
358 	} while (0)
359 
360 #define sra(reg) do {						\
361 		byte arg = (reg);				\
362 		byte res = ((signed char) arg >> 1);		\
363 		F = ((res & FLAG_SXY)	          /* S/X/Y */	\
364 		     | (res ? 0 : FLAG_Z)	  /* Z */	\
365 		     | parity_table[res]	  /* P */	\
366 		     | (arg & FLAG_C));		  /* C */	\
367 		(reg) = res;					\
368 	} while (0)
369 
370 #define slia(reg) do {						\
371 		byte arg = (reg);				\
372 		byte res = ((arg << 1) | 1);			\
373 		F = ((res & FLAG_SXY)	          /* S/X/Y */	\
374 		     | (res ? 0 : FLAG_Z)	  /* Z */	\
375 		     | parity_table[res]	  /* P */	\
376 		     | (arg >> 7));		  /* C */	\
377 		(reg) = res;					\
378 	} while (0)
379 
380 #define srl(reg) do {						\
381 		byte arg = (reg);				\
382 		byte res = (arg >> 1);				\
383 		F = ((res & FLAG_SXY)	          /* S/X/Y */	\
384 		     | (res ? 0 : FLAG_Z)	  /* Z */	\
385 		     | parity_table[res]	  /* P */	\
386 		     | (arg & FLAG_C));		  /* C */	\
387 		(reg) = res;					\
388 	} while (0)
389 
390 #define rld do {						\
391 		byte arg1 = readb(HL);				\
392 		byte arg2 = A;					\
393 		byte res = ((arg2 & 0xf0) | (arg1 >> 4));	\
394 		WZ = HL + 1;					\
395 		writeb(HL, (arg1 << 4) | (arg2 & 0xf));		\
396 		F = ((res & FLAG_SXY)		/* S/X/Y */	\
397 		     | (res ? 0 : FLAG_Z)	/* Z */		\
398 		     | parity_table[res]	/* P */		\
399 		     | (F & FLAG_C));				\
400 		A = res;					\
401 	} while (0)
402 
403 #define rrd do {						\
404 		byte arg1 = readb(HL);				\
405 		byte arg2 = A;					\
406 		byte res = ((arg2 & 0xf0) | (arg1 & 0x0f));	\
407 		WZ = HL + 1;					\
408 		writeb(HL, (arg1 >> 4) | (arg2 << 4));		\
409 		F = ((res & FLAG_SXY)		/* S/X/Y */	\
410 		     | (res ? 0 : FLAG_Z)	/* Z */		\
411 		     | parity_table[res]       	/* P */		\
412 		     | (F & FLAG_C));				\
413 		A = res;					\
414 	} while (0)
415 
416 #define push(reg) do {				\
417 		SP -= 2;			\
418 		writew(SP, (reg));		\
419 	} while (0)
420 
421 #define pop(reg) do {				\
422 		(reg) = readw(SP);		\
423 		SP += 2;			\
424 	} while (0)
425 
426 #define ex(aaa, bbb) do {		\
427 		tmp2 = (aaa);		\
428 		(aaa) = (bbb);		\
429 		(bbb) = tmp2;		\
430 	} while (0)
431 
432 #define in(reg) do {						\
433 		byte res = input(WZ);				\
434 		F = ((res & FLAG_SXY)       /* S/X/Y */		\
435 		     | (res ? 0 : FLAG_Z)   /* Z */		\
436 		     | parity_table[res]    /* P */		\
437 		     | (F & FLAG_C));				\
438 		(reg) = res;					\
439 	} while (0)
440 
441 
442 #define ld_a_ir(reg) do {					\
443 		byte res = (reg);				\
444 		A = res;					\
445 		F = ((res & FLAG_SXY)		/* S/X/Y */	\
446 		     | (res ? 0 : FLAG_Z)	/* Z */		\
447 		     | (IFF2 ? FLAG_P : 0)	/* P */		\
448 		     | (F & FLAG_C));				\
449 	} while (0)
450 
451 #define ldi do {						\
452 		byte res = readb(HL++);				\
453 		writeb(DE++, res);				\
454 		BC--;						\
455 		F = ((F & (FLAG_S | FLAG_Z | FLAG_C))		\
456 		     | ((res << 4) & FLAG_Y)	/* Y */		\
457 		     | (res & FLAG_X)		/* X */		\
458 		     | (BCw ? FLAG_P : 0));	/* P */	\
459 	} while (0)
460 
461 #define ldd do {						\
462 		byte res = readb(HL--);				\
463 		writeb(DE--, res);				\
464 		BC--;						\
465 		F = ((F & (FLAG_S | FLAG_Z | FLAG_C))		\
466 		     | ((res << 4) & FLAG_Y) 	/* Y */		\
467 		     | (res & FLAG_X)        	/* X */		\
468 		     | (BCw ? FLAG_P : 0));	/* P */		\
469 	} while (0)
470 
471 /* FIXME: CPI and CPD obviously use WZ, but I haven't yet figured out
472    precisely how. */
473 
474 #define cpi do {						\
475 		word arg1 = A;					\
476 		word arg2 = readb(HL++);			\
477 		word res = arg1 - arg2;				\
478 		byte hc = ((arg1 ^ arg2 ^ res) & 0x10);		\
479 		byte res2 = res - (hc >> 4);			\
480 		BC--;						\
481 		F = ((res & FLAG_S)		   /* S */	\
482 		     | (lsb(res) ? 0 : FLAG_Z)	   /* Z */	\
483 		     | ((res2 << 4) & FLAG_Y)	   /* Y */	\
484 		     | hc			   /* H */	\
485 		     | (res2 & FLAG_X)		   /* X */	\
486 		     | (BCw ? FLAG_P : 0)	   /* P */	\
487 		     | FLAG_N			   /* N */	\
488 		     | (F & FLAG_C));				\
489 	} while (0)
490 
491 #define cpd do {						\
492 		word arg1 = A;					\
493 		word arg2 = readb(HL--);			\
494 		word res = arg1 - arg2;				\
495 		byte hc = ((arg1 ^ arg2 ^ res) & 0x10);		\
496 		byte res2 = res - (hc >> 4);			\
497 		BC--;						\
498 		F = ((res & FLAG_S)		   /* S */	\
499 		     | (lsb(res) ? 0 : FLAG_Z)	   /* Z */	\
500 		     | ((res2 << 4) & FLAG_Y)	   /* Y */	\
501 		     | hc			   /* H */	\
502 		     | (res2 & FLAG_X)		   /* X */	\
503 		     | (BCw ? FLAG_P : 0)	   /* P */	\
504 		     | FLAG_N			   /* N */	\
505 		     | (F & FLAG_C));				\
506 	} while (0)
507 
508 #define ini do {							\
509 		byte value, count;					\
510 		word k;							\
511 		value = input(BC);					\
512 		writeb(HL++, value);					\
513 		WZ = BC + 1;						\
514 		k = Z + value;						\
515 		count = --B;						\
516 		F = ((count & FLAG_SXY)			/* S/X/Y */	\
517 		     | (count ? 0 : FLAG_Z)		/* Z */		\
518 		     | ((k >> 8) ? 0x11 : 0)		/* H/C */	\
519 		     | parity_table[(k & 7) ^ count]	/* P */		\
520 		     | ((value >> 6) & FLAG_N));	/* N */		\
521 	} while (0)
522 
523 #define ind do {							\
524 		byte value, count;					\
525 		word k;							\
526 		value = input(BC);					\
527 		writeb(HL--, value);					\
528 		WZ = BC - 1;						\
529 		k = Z + value;						\
530 		count = --B;						\
531 		F = ((count & FLAG_SXY)	  		/* S/X/Y */	\
532 		     | (count ? 0 : FLAG_Z)		/* Z */		\
533 		     | ((k >> 8) ? 0x11 : 0)    	/* H/C */	\
534 		     | parity_table[(k & 7) ^ count]	/* P */		\
535 		     | ((value >> 6) & FLAG_N)); 	/* N */		\
536 	} while (0)
537 
538 #define outi do {							\
539 		byte value, count;					\
540 		word k;							\
541 		value = readb(HL++);					\
542 		count = --B;						\
543 		output(BC, value);					\
544 		k = L + value;						\
545 		WZ = BC + 1;						\
546 		F = ((count & FLAG_SXY)			/* S/X/Y */	\
547 		     | (count ? 0 : FLAG_Z)		/* Z */		\
548 		     | ((k >> 8) ? 0x11 : 0)	  	/* H/C */	\
549 		     | parity_table[(k & 7) ^ count]	/* P */		\
550 		     | ((value >> 6) & FLAG_N));	/* N */		\
551 	} while (0)
552 
553 #define outd do {							\
554 		byte value, count;					\
555 		word k;							\
556 		value = readb(HL--);					\
557 		count = --B;						\
558 		output(BC, value);					\
559 		k = L + value;						\
560 		WZ = BC - 1;						\
561 		F = ((count & FLAG_SXY)			/* S/X/Y */	\
562 		     | (count ? 0 : FLAG_Z)		/* Z */		\
563 		     | ((k >> 8) ? 0x11 : 0)		/* H/C */	\
564 		     | parity_table[(k & 7) ^ count]	/* P */		\
565 		     | ((value >> 6) & FLAG_N));	/* N */		\
566 	} while (0)
567 
568 /* Table giving parity flag values.  (Also known as the Thue-Morse
569    sequence.) */
570 static const byte parity_table[256] = {
571 	4,0,0,4,0,4,4,0, 0,4,4,0,4,0,0,4, 0,4,4,0,4,0,0,4, 4,0,0,4,0,4,4,0,
572 	0,4,4,0,4,0,0,4, 4,0,0,4,0,4,4,0, 4,0,0,4,0,4,4,0, 0,4,4,0,4,0,0,4,
573 	0,4,4,0,4,0,0,4, 4,0,0,4,0,4,4,0, 4,0,0,4,0,4,4,0, 0,4,4,0,4,0,0,4,
574 	4,0,0,4,0,4,4,0, 0,4,4,0,4,0,0,4, 0,4,4,0,4,0,0,4, 4,0,0,4,0,4,4,0,
575 
576 	0,4,4,0,4,0,0,4, 4,0,0,4,0,4,4,0, 4,0,0,4,0,4,4,0, 0,4,4,0,4,0,0,4,
577 	4,0,0,4,0,4,4,0, 0,4,4,0,4,0,0,4, 0,4,4,0,4,0,0,4, 4,0,0,4,0,4,4,0,
578 	4,0,0,4,0,4,4,0, 0,4,4,0,4,0,0,4, 0,4,4,0,4,0,0,4, 4,0,0,4,0,4,4,0,
579 	0,4,4,0,4,0,0,4, 4,0,0,4,0,4,4,0, 4,0,0,4,0,4,4,0, 0,4,4,0,4,0,0,4,
580 };
581 
582 /* Table giving AF values following DAA */
583 static const word daa_table[2048] = {
584 	0x0044, 0x0100, 0x0200, 0x0304, 0x0400, 0x0504, 0x0604, 0x0700,
585 	0x0808, 0x090c, 0x1010, 0x1114, 0x1214, 0x1310, 0x1414, 0x1510,
586 	0x1000, 0x1104, 0x1204, 0x1300, 0x1404, 0x1500, 0x1600, 0x1704,
587 	0x180c, 0x1908, 0x2030, 0x2134, 0x2234, 0x2330, 0x2434, 0x2530,
588 	0x2020, 0x2124, 0x2224, 0x2320, 0x2424, 0x2520, 0x2620, 0x2724,
589 	0x282c, 0x2928, 0x3034, 0x3130, 0x3230, 0x3334, 0x3430, 0x3534,
590 	0x3024, 0x3120, 0x3220, 0x3324, 0x3420, 0x3524, 0x3624, 0x3720,
591 	0x3828, 0x392c, 0x4010, 0x4114, 0x4214, 0x4310, 0x4414, 0x4510,
592 	0x4000, 0x4104, 0x4204, 0x4300, 0x4404, 0x4500, 0x4600, 0x4704,
593 	0x480c, 0x4908, 0x5014, 0x5110, 0x5210, 0x5314, 0x5410, 0x5514,
594 	0x5004, 0x5100, 0x5200, 0x5304, 0x5400, 0x5504, 0x5604, 0x5700,
595 	0x5808, 0x590c, 0x6034, 0x6130, 0x6230, 0x6334, 0x6430, 0x6534,
596 	0x6024, 0x6120, 0x6220, 0x6324, 0x6420, 0x6524, 0x6624, 0x6720,
597 	0x6828, 0x692c, 0x7030, 0x7134, 0x7234, 0x7330, 0x7434, 0x7530,
598 	0x7020, 0x7124, 0x7224, 0x7320, 0x7424, 0x7520, 0x7620, 0x7724,
599 	0x782c, 0x7928, 0x8090, 0x8194, 0x8294, 0x8390, 0x8494, 0x8590,
600 	0x8080, 0x8184, 0x8284, 0x8380, 0x8484, 0x8580, 0x8680, 0x8784,
601 	0x888c, 0x8988, 0x9094, 0x9190, 0x9290, 0x9394, 0x9490, 0x9594,
602 	0x9084, 0x9180, 0x9280, 0x9384, 0x9480, 0x9584, 0x9684, 0x9780,
603 	0x9888, 0x998c, 0x0055, 0x0111, 0x0211, 0x0315, 0x0411, 0x0515,
604 	0x0045, 0x0101, 0x0201, 0x0305, 0x0401, 0x0505, 0x0605, 0x0701,
605 	0x0809, 0x090d, 0x1011, 0x1115, 0x1215, 0x1311, 0x1415, 0x1511,
606 	0x1001, 0x1105, 0x1205, 0x1301, 0x1405, 0x1501, 0x1601, 0x1705,
607 	0x180d, 0x1909, 0x2031, 0x2135, 0x2235, 0x2331, 0x2435, 0x2531,
608 	0x2021, 0x2125, 0x2225, 0x2321, 0x2425, 0x2521, 0x2621, 0x2725,
609 	0x282d, 0x2929, 0x3035, 0x3131, 0x3231, 0x3335, 0x3431, 0x3535,
610 	0x3025, 0x3121, 0x3221, 0x3325, 0x3421, 0x3525, 0x3625, 0x3721,
611 	0x3829, 0x392d, 0x4011, 0x4115, 0x4215, 0x4311, 0x4415, 0x4511,
612 	0x4001, 0x4105, 0x4205, 0x4301, 0x4405, 0x4501, 0x4601, 0x4705,
613 	0x480d, 0x4909, 0x5015, 0x5111, 0x5211, 0x5315, 0x5411, 0x5515,
614 	0x5005, 0x5101, 0x5201, 0x5305, 0x5401, 0x5505, 0x5605, 0x5701,
615 	0x5809, 0x590d, 0x6035, 0x6131, 0x6231, 0x6335, 0x6431, 0x6535,
616 	0x6025, 0x6121, 0x6221, 0x6325, 0x6421, 0x6525, 0x6625, 0x6721,
617 	0x6829, 0x692d, 0x7031, 0x7135, 0x7235, 0x7331, 0x7435, 0x7531,
618 	0x7021, 0x7125, 0x7225, 0x7321, 0x7425, 0x7521, 0x7621, 0x7725,
619 	0x782d, 0x7929, 0x8091, 0x8195, 0x8295, 0x8391, 0x8495, 0x8591,
620 	0x8081, 0x8185, 0x8285, 0x8381, 0x8485, 0x8581, 0x8681, 0x8785,
621 	0x888d, 0x8989, 0x9095, 0x9191, 0x9291, 0x9395, 0x9491, 0x9595,
622 	0x9085, 0x9181, 0x9281, 0x9385, 0x9481, 0x9585, 0x9685, 0x9781,
623 	0x9889, 0x998d, 0xa0b5, 0xa1b1, 0xa2b1, 0xa3b5, 0xa4b1, 0xa5b5,
624 	0xa0a5, 0xa1a1, 0xa2a1, 0xa3a5, 0xa4a1, 0xa5a5, 0xa6a5, 0xa7a1,
625 	0xa8a9, 0xa9ad, 0xb0b1, 0xb1b5, 0xb2b5, 0xb3b1, 0xb4b5, 0xb5b1,
626 	0xb0a1, 0xb1a5, 0xb2a5, 0xb3a1, 0xb4a5, 0xb5a1, 0xb6a1, 0xb7a5,
627 	0xb8ad, 0xb9a9, 0xc095, 0xc191, 0xc291, 0xc395, 0xc491, 0xc595,
628 	0xc085, 0xc181, 0xc281, 0xc385, 0xc481, 0xc585, 0xc685, 0xc781,
629 	0xc889, 0xc98d, 0xd091, 0xd195, 0xd295, 0xd391, 0xd495, 0xd591,
630 	0xd081, 0xd185, 0xd285, 0xd381, 0xd485, 0xd581, 0xd681, 0xd785,
631 	0xd88d, 0xd989, 0xe0b1, 0xe1b5, 0xe2b5, 0xe3b1, 0xe4b5, 0xe5b1,
632 	0xe0a1, 0xe1a5, 0xe2a5, 0xe3a1, 0xe4a5, 0xe5a1, 0xe6a1, 0xe7a5,
633 	0xe8ad, 0xe9a9, 0xf0b5, 0xf1b1, 0xf2b1, 0xf3b5, 0xf4b1, 0xf5b5,
634 	0xf0a5, 0xf1a1, 0xf2a1, 0xf3a5, 0xf4a1, 0xf5a5, 0xf6a5, 0xf7a1,
635 	0xf8a9, 0xf9ad, 0x0055, 0x0111, 0x0211, 0x0315, 0x0411, 0x0515,
636 	0x0045, 0x0101, 0x0201, 0x0305, 0x0401, 0x0505, 0x0605, 0x0701,
637 	0x0809, 0x090d, 0x1011, 0x1115, 0x1215, 0x1311, 0x1415, 0x1511,
638 	0x1001, 0x1105, 0x1205, 0x1301, 0x1405, 0x1501, 0x1601, 0x1705,
639 	0x180d, 0x1909, 0x2031, 0x2135, 0x2235, 0x2331, 0x2435, 0x2531,
640 	0x2021, 0x2125, 0x2225, 0x2321, 0x2425, 0x2521, 0x2621, 0x2725,
641 	0x282d, 0x2929, 0x3035, 0x3131, 0x3231, 0x3335, 0x3431, 0x3535,
642 	0x3025, 0x3121, 0x3221, 0x3325, 0x3421, 0x3525, 0x3625, 0x3721,
643 	0x3829, 0x392d, 0x4011, 0x4115, 0x4215, 0x4311, 0x4415, 0x4511,
644 	0x4001, 0x4105, 0x4205, 0x4301, 0x4405, 0x4501, 0x4601, 0x4705,
645 	0x480d, 0x4909, 0x5015, 0x5111, 0x5211, 0x5315, 0x5411, 0x5515,
646 	0x5005, 0x5101, 0x5201, 0x5305, 0x5401, 0x5505, 0x5605, 0x5701,
647 	0x5809, 0x590d, 0x6035, 0x6131, 0x6231, 0x6335, 0x6431, 0x6535,
648 	0x0046, 0x0102, 0x0202, 0x0306, 0x0402, 0x0506, 0x0606, 0x0702,
649 	0x080a, 0x090e, 0x0402, 0x0506, 0x0606, 0x0702, 0x080a, 0x090e,
650 	0x1002, 0x1106, 0x1206, 0x1302, 0x1406, 0x1502, 0x1602, 0x1706,
651 	0x180e, 0x190a, 0x1406, 0x1502, 0x1602, 0x1706, 0x180e, 0x190a,
652 	0x2022, 0x2126, 0x2226, 0x2322, 0x2426, 0x2522, 0x2622, 0x2726,
653 	0x282e, 0x292a, 0x2426, 0x2522, 0x2622, 0x2726, 0x282e, 0x292a,
654 	0x3026, 0x3122, 0x3222, 0x3326, 0x3422, 0x3526, 0x3626, 0x3722,
655 	0x382a, 0x392e, 0x3422, 0x3526, 0x3626, 0x3722, 0x382a, 0x392e,
656 	0x4002, 0x4106, 0x4206, 0x4302, 0x4406, 0x4502, 0x4602, 0x4706,
657 	0x480e, 0x490a, 0x4406, 0x4502, 0x4602, 0x4706, 0x480e, 0x490a,
658 	0x5006, 0x5102, 0x5202, 0x5306, 0x5402, 0x5506, 0x5606, 0x5702,
659 	0x580a, 0x590e, 0x5402, 0x5506, 0x5606, 0x5702, 0x580a, 0x590e,
660 	0x6026, 0x6122, 0x6222, 0x6326, 0x6422, 0x6526, 0x6626, 0x6722,
661 	0x682a, 0x692e, 0x6422, 0x6526, 0x6626, 0x6722, 0x682a, 0x692e,
662 	0x7022, 0x7126, 0x7226, 0x7322, 0x7426, 0x7522, 0x7622, 0x7726,
663 	0x782e, 0x792a, 0x7426, 0x7522, 0x7622, 0x7726, 0x782e, 0x792a,
664 	0x8082, 0x8186, 0x8286, 0x8382, 0x8486, 0x8582, 0x8682, 0x8786,
665 	0x888e, 0x898a, 0x8486, 0x8582, 0x8682, 0x8786, 0x888e, 0x898a,
666 	0x9086, 0x9182, 0x9282, 0x9386, 0x9482, 0x9586, 0x9686, 0x9782,
667 	0x988a, 0x998e, 0x3423, 0x3527, 0x3627, 0x3723, 0x382b, 0x392f,
668 	0x4003, 0x4107, 0x4207, 0x4303, 0x4407, 0x4503, 0x4603, 0x4707,
669 	0x480f, 0x490b, 0x4407, 0x4503, 0x4603, 0x4707, 0x480f, 0x490b,
670 	0x5007, 0x5103, 0x5203, 0x5307, 0x5403, 0x5507, 0x5607, 0x5703,
671 	0x580b, 0x590f, 0x5403, 0x5507, 0x5607, 0x5703, 0x580b, 0x590f,
672 	0x6027, 0x6123, 0x6223, 0x6327, 0x6423, 0x6527, 0x6627, 0x6723,
673 	0x682b, 0x692f, 0x6423, 0x6527, 0x6627, 0x6723, 0x682b, 0x692f,
674 	0x7023, 0x7127, 0x7227, 0x7323, 0x7427, 0x7523, 0x7623, 0x7727,
675 	0x782f, 0x792b, 0x7427, 0x7523, 0x7623, 0x7727, 0x782f, 0x792b,
676 	0x8083, 0x8187, 0x8287, 0x8383, 0x8487, 0x8583, 0x8683, 0x8787,
677 	0x888f, 0x898b, 0x8487, 0x8583, 0x8683, 0x8787, 0x888f, 0x898b,
678 	0x9087, 0x9183, 0x9283, 0x9387, 0x9483, 0x9587, 0x9687, 0x9783,
679 	0x988b, 0x998f, 0x9483, 0x9587, 0x9687, 0x9783, 0x988b, 0x998f,
680 	0xa0a7, 0xa1a3, 0xa2a3, 0xa3a7, 0xa4a3, 0xa5a7, 0xa6a7, 0xa7a3,
681 	0xa8ab, 0xa9af, 0xa4a3, 0xa5a7, 0xa6a7, 0xa7a3, 0xa8ab, 0xa9af,
682 	0xb0a3, 0xb1a7, 0xb2a7, 0xb3a3, 0xb4a7, 0xb5a3, 0xb6a3, 0xb7a7,
683 	0xb8af, 0xb9ab, 0xb4a7, 0xb5a3, 0xb6a3, 0xb7a7, 0xb8af, 0xb9ab,
684 	0xc087, 0xc183, 0xc283, 0xc387, 0xc483, 0xc587, 0xc687, 0xc783,
685 	0xc88b, 0xc98f, 0xc483, 0xc587, 0xc687, 0xc783, 0xc88b, 0xc98f,
686 	0xd083, 0xd187, 0xd287, 0xd383, 0xd487, 0xd583, 0xd683, 0xd787,
687 	0xd88f, 0xd98b, 0xd487, 0xd583, 0xd683, 0xd787, 0xd88f, 0xd98b,
688 	0xe0a3, 0xe1a7, 0xe2a7, 0xe3a3, 0xe4a7, 0xe5a3, 0xe6a3, 0xe7a7,
689 	0xe8af, 0xe9ab, 0xe4a7, 0xe5a3, 0xe6a3, 0xe7a7, 0xe8af, 0xe9ab,
690 	0xf0a7, 0xf1a3, 0xf2a3, 0xf3a7, 0xf4a3, 0xf5a7, 0xf6a7, 0xf7a3,
691 	0xf8ab, 0xf9af, 0xf4a3, 0xf5a7, 0xf6a7, 0xf7a3, 0xf8ab, 0xf9af,
692 	0x0047, 0x0103, 0x0203, 0x0307, 0x0403, 0x0507, 0x0607, 0x0703,
693 	0x080b, 0x090f, 0x0403, 0x0507, 0x0607, 0x0703, 0x080b, 0x090f,
694 	0x1003, 0x1107, 0x1207, 0x1303, 0x1407, 0x1503, 0x1603, 0x1707,
695 	0x180f, 0x190b, 0x1407, 0x1503, 0x1603, 0x1707, 0x180f, 0x190b,
696 	0x2023, 0x2127, 0x2227, 0x2323, 0x2427, 0x2523, 0x2623, 0x2727,
697 	0x282f, 0x292b, 0x2427, 0x2523, 0x2623, 0x2727, 0x282f, 0x292b,
698 	0x3027, 0x3123, 0x3223, 0x3327, 0x3423, 0x3527, 0x3627, 0x3723,
699 	0x382b, 0x392f, 0x3423, 0x3527, 0x3627, 0x3723, 0x382b, 0x392f,
700 	0x4003, 0x4107, 0x4207, 0x4303, 0x4407, 0x4503, 0x4603, 0x4707,
701 	0x480f, 0x490b, 0x4407, 0x4503, 0x4603, 0x4707, 0x480f, 0x490b,
702 	0x5007, 0x5103, 0x5203, 0x5307, 0x5403, 0x5507, 0x5607, 0x5703,
703 	0x580b, 0x590f, 0x5403, 0x5507, 0x5607, 0x5703, 0x580b, 0x590f,
704 	0x6027, 0x6123, 0x6223, 0x6327, 0x6423, 0x6527, 0x6627, 0x6723,
705 	0x682b, 0x692f, 0x6423, 0x6527, 0x6627, 0x6723, 0x682b, 0x692f,
706 	0x7023, 0x7127, 0x7227, 0x7323, 0x7427, 0x7523, 0x7623, 0x7727,
707 	0x782f, 0x792b, 0x7427, 0x7523, 0x7623, 0x7727, 0x782f, 0x792b,
708 	0x8083, 0x8187, 0x8287, 0x8383, 0x8487, 0x8583, 0x8683, 0x8787,
709 	0x888f, 0x898b, 0x8487, 0x8583, 0x8683, 0x8787, 0x888f, 0x898b,
710 	0x9087, 0x9183, 0x9283, 0x9387, 0x9483, 0x9587, 0x9687, 0x9783,
711 	0x988b, 0x998f, 0x9483, 0x9587, 0x9687, 0x9783, 0x988b, 0x998f,
712 	0x0604, 0x0700, 0x0808, 0x090c, 0x0a0c, 0x0b08, 0x0c0c, 0x0d08,
713 	0x0e08, 0x0f0c, 0x1010, 0x1114, 0x1214, 0x1310, 0x1414, 0x1510,
714 	0x1600, 0x1704, 0x180c, 0x1908, 0x1a08, 0x1b0c, 0x1c08, 0x1d0c,
715 	0x1e0c, 0x1f08, 0x2030, 0x2134, 0x2234, 0x2330, 0x2434, 0x2530,
716 	0x2620, 0x2724, 0x282c, 0x2928, 0x2a28, 0x2b2c, 0x2c28, 0x2d2c,
717 	0x2e2c, 0x2f28, 0x3034, 0x3130, 0x3230, 0x3334, 0x3430, 0x3534,
718 	0x3624, 0x3720, 0x3828, 0x392c, 0x3a2c, 0x3b28, 0x3c2c, 0x3d28,
719 	0x3e28, 0x3f2c, 0x4010, 0x4114, 0x4214, 0x4310, 0x4414, 0x4510,
720 	0x4600, 0x4704, 0x480c, 0x4908, 0x4a08, 0x4b0c, 0x4c08, 0x4d0c,
721 	0x4e0c, 0x4f08, 0x5014, 0x5110, 0x5210, 0x5314, 0x5410, 0x5514,
722 	0x5604, 0x5700, 0x5808, 0x590c, 0x5a0c, 0x5b08, 0x5c0c, 0x5d08,
723 	0x5e08, 0x5f0c, 0x6034, 0x6130, 0x6230, 0x6334, 0x6430, 0x6534,
724 	0x6624, 0x6720, 0x6828, 0x692c, 0x6a2c, 0x6b28, 0x6c2c, 0x6d28,
725 	0x6e28, 0x6f2c, 0x7030, 0x7134, 0x7234, 0x7330, 0x7434, 0x7530,
726 	0x7620, 0x7724, 0x782c, 0x7928, 0x7a28, 0x7b2c, 0x7c28, 0x7d2c,
727 	0x7e2c, 0x7f28, 0x8090, 0x8194, 0x8294, 0x8390, 0x8494, 0x8590,
728 	0x8680, 0x8784, 0x888c, 0x8988, 0x8a88, 0x8b8c, 0x8c88, 0x8d8c,
729 	0x8e8c, 0x8f88, 0x9094, 0x9190, 0x9290, 0x9394, 0x9490, 0x9594,
730 	0x9684, 0x9780, 0x9888, 0x998c, 0x9a8c, 0x9b88, 0x9c8c, 0x9d88,
731 	0x9e88, 0x9f8c, 0x0055, 0x0111, 0x0211, 0x0315, 0x0411, 0x0515,
732 	0x0605, 0x0701, 0x0809, 0x090d, 0x0a0d, 0x0b09, 0x0c0d, 0x0d09,
733 	0x0e09, 0x0f0d, 0x1011, 0x1115, 0x1215, 0x1311, 0x1415, 0x1511,
734 	0x1601, 0x1705, 0x180d, 0x1909, 0x1a09, 0x1b0d, 0x1c09, 0x1d0d,
735 	0x1e0d, 0x1f09, 0x2031, 0x2135, 0x2235, 0x2331, 0x2435, 0x2531,
736 	0x2621, 0x2725, 0x282d, 0x2929, 0x2a29, 0x2b2d, 0x2c29, 0x2d2d,
737 	0x2e2d, 0x2f29, 0x3035, 0x3131, 0x3231, 0x3335, 0x3431, 0x3535,
738 	0x3625, 0x3721, 0x3829, 0x392d, 0x3a2d, 0x3b29, 0x3c2d, 0x3d29,
739 	0x3e29, 0x3f2d, 0x4011, 0x4115, 0x4215, 0x4311, 0x4415, 0x4511,
740 	0x4601, 0x4705, 0x480d, 0x4909, 0x4a09, 0x4b0d, 0x4c09, 0x4d0d,
741 	0x4e0d, 0x4f09, 0x5015, 0x5111, 0x5211, 0x5315, 0x5411, 0x5515,
742 	0x5605, 0x5701, 0x5809, 0x590d, 0x5a0d, 0x5b09, 0x5c0d, 0x5d09,
743 	0x5e09, 0x5f0d, 0x6035, 0x6131, 0x6231, 0x6335, 0x6431, 0x6535,
744 	0x6625, 0x6721, 0x6829, 0x692d, 0x6a2d, 0x6b29, 0x6c2d, 0x6d29,
745 	0x6e29, 0x6f2d, 0x7031, 0x7135, 0x7235, 0x7331, 0x7435, 0x7531,
746 	0x7621, 0x7725, 0x782d, 0x7929, 0x7a29, 0x7b2d, 0x7c29, 0x7d2d,
747 	0x7e2d, 0x7f29, 0x8091, 0x8195, 0x8295, 0x8391, 0x8495, 0x8591,
748 	0x8681, 0x8785, 0x888d, 0x8989, 0x8a89, 0x8b8d, 0x8c89, 0x8d8d,
749 	0x8e8d, 0x8f89, 0x9095, 0x9191, 0x9291, 0x9395, 0x9491, 0x9595,
750 	0x9685, 0x9781, 0x9889, 0x998d, 0x9a8d, 0x9b89, 0x9c8d, 0x9d89,
751 	0x9e89, 0x9f8d, 0xa0b5, 0xa1b1, 0xa2b1, 0xa3b5, 0xa4b1, 0xa5b5,
752 	0xa6a5, 0xa7a1, 0xa8a9, 0xa9ad, 0xaaad, 0xaba9, 0xacad, 0xada9,
753 	0xaea9, 0xafad, 0xb0b1, 0xb1b5, 0xb2b5, 0xb3b1, 0xb4b5, 0xb5b1,
754 	0xb6a1, 0xb7a5, 0xb8ad, 0xb9a9, 0xbaa9, 0xbbad, 0xbca9, 0xbdad,
755 	0xbead, 0xbfa9, 0xc095, 0xc191, 0xc291, 0xc395, 0xc491, 0xc595,
756 	0xc685, 0xc781, 0xc889, 0xc98d, 0xca8d, 0xcb89, 0xcc8d, 0xcd89,
757 	0xce89, 0xcf8d, 0xd091, 0xd195, 0xd295, 0xd391, 0xd495, 0xd591,
758 	0xd681, 0xd785, 0xd88d, 0xd989, 0xda89, 0xdb8d, 0xdc89, 0xdd8d,
759 	0xde8d, 0xdf89, 0xe0b1, 0xe1b5, 0xe2b5, 0xe3b1, 0xe4b5, 0xe5b1,
760 	0xe6a1, 0xe7a5, 0xe8ad, 0xe9a9, 0xeaa9, 0xebad, 0xeca9, 0xedad,
761 	0xeead, 0xefa9, 0xf0b5, 0xf1b1, 0xf2b1, 0xf3b5, 0xf4b1, 0xf5b5,
762 	0xf6a5, 0xf7a1, 0xf8a9, 0xf9ad, 0xfaad, 0xfba9, 0xfcad, 0xfda9,
763 	0xfea9, 0xffad, 0x0055, 0x0111, 0x0211, 0x0315, 0x0411, 0x0515,
764 	0x0605, 0x0701, 0x0809, 0x090d, 0x0a0d, 0x0b09, 0x0c0d, 0x0d09,
765 	0x0e09, 0x0f0d, 0x1011, 0x1115, 0x1215, 0x1311, 0x1415, 0x1511,
766 	0x1601, 0x1705, 0x180d, 0x1909, 0x1a09, 0x1b0d, 0x1c09, 0x1d0d,
767 	0x1e0d, 0x1f09, 0x2031, 0x2135, 0x2235, 0x2331, 0x2435, 0x2531,
768 	0x2621, 0x2725, 0x282d, 0x2929, 0x2a29, 0x2b2d, 0x2c29, 0x2d2d,
769 	0x2e2d, 0x2f29, 0x3035, 0x3131, 0x3231, 0x3335, 0x3431, 0x3535,
770 	0x3625, 0x3721, 0x3829, 0x392d, 0x3a2d, 0x3b29, 0x3c2d, 0x3d29,
771 	0x3e29, 0x3f2d, 0x4011, 0x4115, 0x4215, 0x4311, 0x4415, 0x4511,
772 	0x4601, 0x4705, 0x480d, 0x4909, 0x4a09, 0x4b0d, 0x4c09, 0x4d0d,
773 	0x4e0d, 0x4f09, 0x5015, 0x5111, 0x5211, 0x5315, 0x5411, 0x5515,
774 	0x5605, 0x5701, 0x5809, 0x590d, 0x5a0d, 0x5b09, 0x5c0d, 0x5d09,
775 	0x5e09, 0x5f0d, 0x6035, 0x6131, 0x6231, 0x6335, 0x6431, 0x6535,
776 	0xfabe, 0xfbba, 0xfcbe, 0xfdba, 0xfeba, 0xffbe, 0x0046, 0x0102,
777 	0x0202, 0x0306, 0x0402, 0x0506, 0x0606, 0x0702, 0x080a, 0x090e,
778 	0x0a1e, 0x0b1a, 0x0c1e, 0x0d1a, 0x0e1a, 0x0f1e, 0x1002, 0x1106,
779 	0x1206, 0x1302, 0x1406, 0x1502, 0x1602, 0x1706, 0x180e, 0x190a,
780 	0x1a1a, 0x1b1e, 0x1c1a, 0x1d1e, 0x1e1e, 0x1f1a, 0x2022, 0x2126,
781 	0x2226, 0x2322, 0x2426, 0x2522, 0x2622, 0x2726, 0x282e, 0x292a,
782 	0x2a3a, 0x2b3e, 0x2c3a, 0x2d3e, 0x2e3e, 0x2f3a, 0x3026, 0x3122,
783 	0x3222, 0x3326, 0x3422, 0x3526, 0x3626, 0x3722, 0x382a, 0x392e,
784 	0x3a3e, 0x3b3a, 0x3c3e, 0x3d3a, 0x3e3a, 0x3f3e, 0x4002, 0x4106,
785 	0x4206, 0x4302, 0x4406, 0x4502, 0x4602, 0x4706, 0x480e, 0x490a,
786 	0x4a1a, 0x4b1e, 0x4c1a, 0x4d1e, 0x4e1e, 0x4f1a, 0x5006, 0x5102,
787 	0x5202, 0x5306, 0x5402, 0x5506, 0x5606, 0x5702, 0x580a, 0x590e,
788 	0x5a1e, 0x5b1a, 0x5c1e, 0x5d1a, 0x5e1a, 0x5f1e, 0x6026, 0x6122,
789 	0x6222, 0x6326, 0x6422, 0x6526, 0x6626, 0x6722, 0x682a, 0x692e,
790 	0x6a3e, 0x6b3a, 0x6c3e, 0x6d3a, 0x6e3a, 0x6f3e, 0x7022, 0x7126,
791 	0x7226, 0x7322, 0x7426, 0x7522, 0x7622, 0x7726, 0x782e, 0x792a,
792 	0x7a3a, 0x7b3e, 0x7c3a, 0x7d3e, 0x7e3e, 0x7f3a, 0x8082, 0x8186,
793 	0x8286, 0x8382, 0x8486, 0x8582, 0x8682, 0x8786, 0x888e, 0x898a,
794 	0x8a9a, 0x8b9e, 0x8c9a, 0x8d9e, 0x8e9e, 0x8f9a, 0x9086, 0x9182,
795 	0x9282, 0x9386, 0x3423, 0x3527, 0x3627, 0x3723, 0x382b, 0x392f,
796 	0x3a3f, 0x3b3b, 0x3c3f, 0x3d3b, 0x3e3b, 0x3f3f, 0x4003, 0x4107,
797 	0x4207, 0x4303, 0x4407, 0x4503, 0x4603, 0x4707, 0x480f, 0x490b,
798 	0x4a1b, 0x4b1f, 0x4c1b, 0x4d1f, 0x4e1f, 0x4f1b, 0x5007, 0x5103,
799 	0x5203, 0x5307, 0x5403, 0x5507, 0x5607, 0x5703, 0x580b, 0x590f,
800 	0x5a1f, 0x5b1b, 0x5c1f, 0x5d1b, 0x5e1b, 0x5f1f, 0x6027, 0x6123,
801 	0x6223, 0x6327, 0x6423, 0x6527, 0x6627, 0x6723, 0x682b, 0x692f,
802 	0x6a3f, 0x6b3b, 0x6c3f, 0x6d3b, 0x6e3b, 0x6f3f, 0x7023, 0x7127,
803 	0x7227, 0x7323, 0x7427, 0x7523, 0x7623, 0x7727, 0x782f, 0x792b,
804 	0x7a3b, 0x7b3f, 0x7c3b, 0x7d3f, 0x7e3f, 0x7f3b, 0x8083, 0x8187,
805 	0x8287, 0x8383, 0x8487, 0x8583, 0x8683, 0x8787, 0x888f, 0x898b,
806 	0x8a9b, 0x8b9f, 0x8c9b, 0x8d9f, 0x8e9f, 0x8f9b, 0x9087, 0x9183,
807 	0x9283, 0x9387, 0x9483, 0x9587, 0x9687, 0x9783, 0x988b, 0x998f,
808 	0x9a9f, 0x9b9b, 0x9c9f, 0x9d9b, 0x9e9b, 0x9f9f, 0xa0a7, 0xa1a3,
809 	0xa2a3, 0xa3a7, 0xa4a3, 0xa5a7, 0xa6a7, 0xa7a3, 0xa8ab, 0xa9af,
810 	0xaabf, 0xabbb, 0xacbf, 0xadbb, 0xaebb, 0xafbf, 0xb0a3, 0xb1a7,
811 	0xb2a7, 0xb3a3, 0xb4a7, 0xb5a3, 0xb6a3, 0xb7a7, 0xb8af, 0xb9ab,
812 	0xbabb, 0xbbbf, 0xbcbb, 0xbdbf, 0xbebf, 0xbfbb, 0xc087, 0xc183,
813 	0xc283, 0xc387, 0xc483, 0xc587, 0xc687, 0xc783, 0xc88b, 0xc98f,
814 	0xca9f, 0xcb9b, 0xcc9f, 0xcd9b, 0xce9b, 0xcf9f, 0xd083, 0xd187,
815 	0xd287, 0xd383, 0xd487, 0xd583, 0xd683, 0xd787, 0xd88f, 0xd98b,
816 	0xda9b, 0xdb9f, 0xdc9b, 0xdd9f, 0xde9f, 0xdf9b, 0xe0a3, 0xe1a7,
817 	0xe2a7, 0xe3a3, 0xe4a7, 0xe5a3, 0xe6a3, 0xe7a7, 0xe8af, 0xe9ab,
818 	0xeabb, 0xebbf, 0xecbb, 0xedbf, 0xeebf, 0xefbb, 0xf0a7, 0xf1a3,
819 	0xf2a3, 0xf3a7, 0xf4a3, 0xf5a7, 0xf6a7, 0xf7a3, 0xf8ab, 0xf9af,
820 	0xfabf, 0xfbbb, 0xfcbf, 0xfdbb, 0xfebb, 0xffbf, 0x0047, 0x0103,
821 	0x0203, 0x0307, 0x0403, 0x0507, 0x0607, 0x0703, 0x080b, 0x090f,
822 	0x0a1f, 0x0b1b, 0x0c1f, 0x0d1b, 0x0e1b, 0x0f1f, 0x1003, 0x1107,
823 	0x1207, 0x1303, 0x1407, 0x1503, 0x1603, 0x1707, 0x180f, 0x190b,
824 	0x1a1b, 0x1b1f, 0x1c1b, 0x1d1f, 0x1e1f, 0x1f1b, 0x2023, 0x2127,
825 	0x2227, 0x2323, 0x2427, 0x2523, 0x2623, 0x2727, 0x282f, 0x292b,
826 	0x2a3b, 0x2b3f, 0x2c3b, 0x2d3f, 0x2e3f, 0x2f3b, 0x3027, 0x3123,
827 	0x3223, 0x3327, 0x3423, 0x3527, 0x3627, 0x3723, 0x382b, 0x392f,
828 	0x3a3f, 0x3b3b, 0x3c3f, 0x3d3b, 0x3e3b, 0x3f3f, 0x4003, 0x4107,
829 	0x4207, 0x4303, 0x4407, 0x4503, 0x4603, 0x4707, 0x480f, 0x490b,
830 	0x4a1b, 0x4b1f, 0x4c1b, 0x4d1f, 0x4e1f, 0x4f1b, 0x5007, 0x5103,
831 	0x5203, 0x5307, 0x5403, 0x5507, 0x5607, 0x5703, 0x580b, 0x590f,
832 	0x5a1f, 0x5b1b, 0x5c1f, 0x5d1b, 0x5e1b, 0x5f1f, 0x6027, 0x6123,
833 	0x6223, 0x6327, 0x6423, 0x6527, 0x6627, 0x6723, 0x682b, 0x692f,
834 	0x6a3f, 0x6b3b, 0x6c3f, 0x6d3b, 0x6e3b, 0x6f3f, 0x7023, 0x7127,
835 	0x7227, 0x7323, 0x7427, 0x7523, 0x7623, 0x7727, 0x782f, 0x792b,
836 	0x7a3b, 0x7b3f, 0x7c3b, 0x7d3f, 0x7e3f, 0x7f3b, 0x8083, 0x8187,
837 	0x8287, 0x8383, 0x8487, 0x8583, 0x8683, 0x8787, 0x888f, 0x898b,
838 	0x8a9b, 0x8b9f, 0x8c9b, 0x8d9f, 0x8e9f, 0x8f9b, 0x9087, 0x9183,
839 	0x9283, 0x9387, 0x9483, 0x9587, 0x9687, 0x9783, 0x988b, 0x998f
840 };
841