cue/bin finally implemented
[picodrive.git] / cpu / cz80 / cz80_opED.c
1 /******************************************************************************\r
2  *\r
3  * CZ80 ED opcode include source file\r
4  * CZ80 emulator version 0.9\r
5  * Copyright 2004-2005 Stéphane Dallongeville\r
6  *\r
7  * (Modified by NJ)\r
8  *\r
9  *****************************************************************************/\r
10 \r
11 #if CZ80_USE_JUMPTABLE\r
12         goto *JumpTableED[Opcode];\r
13 #else\r
14 switch (Opcode)\r
15 {\r
16 #endif\r
17 \r
18 /*-----------------------------------------\r
19  ILLEGAL\r
20 -----------------------------------------*/\r
21 \r
22         OPED(0x00):\r
23         OPED(0x01):\r
24         OPED(0x02):\r
25         OPED(0x03):\r
26         OPED(0x04):\r
27         OPED(0x05):\r
28         OPED(0x06):\r
29         OPED(0x07):\r
30         OPED(0x08):\r
31         OPED(0x09):\r
32         OPED(0x0a):\r
33         OPED(0x0b):\r
34         OPED(0x0c):\r
35         OPED(0x0d):\r
36         OPED(0x0e):\r
37         OPED(0x0f):\r
38 \r
39         OPED(0x10):\r
40         OPED(0x11):\r
41         OPED(0x12):\r
42         OPED(0x13):\r
43         OPED(0x14):\r
44         OPED(0x15):\r
45         OPED(0x16):\r
46         OPED(0x17):\r
47         OPED(0x18):\r
48         OPED(0x19):\r
49         OPED(0x1a):\r
50         OPED(0x1b):\r
51         OPED(0x1c):\r
52         OPED(0x1d):\r
53         OPED(0x1e):\r
54         OPED(0x1f):\r
55 \r
56         OPED(0x20):\r
57         OPED(0x21):\r
58         OPED(0x22):\r
59         OPED(0x23):\r
60         OPED(0x24):\r
61         OPED(0x25):\r
62         OPED(0x26):\r
63         OPED(0x27):\r
64         OPED(0x28):\r
65         OPED(0x29):\r
66         OPED(0x2a):\r
67         OPED(0x2b):\r
68         OPED(0x2c):\r
69         OPED(0x2d):\r
70         OPED(0x2e):\r
71         OPED(0x2f):\r
72 \r
73         OPED(0x30):\r
74         OPED(0x31):\r
75         OPED(0x32):\r
76         OPED(0x33):\r
77         OPED(0x34):\r
78         OPED(0x35):\r
79         OPED(0x36):\r
80         OPED(0x37):\r
81         OPED(0x38):\r
82         OPED(0x39):\r
83         OPED(0x3a):\r
84         OPED(0x3b):\r
85         OPED(0x3c):\r
86         OPED(0x3d):\r
87         OPED(0x3e):\r
88         OPED(0x3f):\r
89 \r
90         OPED(0x77):\r
91         OPED(0x7f):\r
92 \r
93         OPED(0x80):\r
94         OPED(0x81):\r
95         OPED(0x82):\r
96         OPED(0x83):\r
97         OPED(0x84):\r
98         OPED(0x85):\r
99         OPED(0x86):\r
100         OPED(0x87):\r
101         OPED(0x88):\r
102         OPED(0x89):\r
103         OPED(0x8a):\r
104         OPED(0x8b):\r
105         OPED(0x8c):\r
106         OPED(0x8d):\r
107         OPED(0x8e):\r
108         OPED(0x8f):\r
109 \r
110         OPED(0x90):\r
111         OPED(0x91):\r
112         OPED(0x92):\r
113         OPED(0x93):\r
114         OPED(0x94):\r
115         OPED(0x95):\r
116         OPED(0x96):\r
117         OPED(0x97):\r
118         OPED(0x98):\r
119         OPED(0x99):\r
120         OPED(0x9a):\r
121         OPED(0x9b):\r
122         OPED(0x9c):\r
123         OPED(0x9d):\r
124         OPED(0x9e):\r
125         OPED(0x9f):\r
126 \r
127         OPED(0xa4):\r
128         OPED(0xa5):\r
129         OPED(0xa6):\r
130         OPED(0xa7):\r
131 \r
132         OPED(0xac):\r
133         OPED(0xad):\r
134         OPED(0xae):\r
135         OPED(0xaf):\r
136 \r
137         OPED(0xb4):\r
138         OPED(0xb5):\r
139         OPED(0xb6):\r
140         OPED(0xb7):\r
141 \r
142         OPED(0xbc):\r
143         OPED(0xbd):\r
144         OPED(0xbe):\r
145         OPED(0xbf):\r
146 \r
147         OPED(0xc0):\r
148         OPED(0xc1):\r
149         OPED(0xc2):\r
150         OPED(0xc3):\r
151         OPED(0xc4):\r
152         OPED(0xc5):\r
153         OPED(0xc6):\r
154         OPED(0xc7):\r
155         OPED(0xc8):\r
156         OPED(0xc9):\r
157         OPED(0xca):\r
158         OPED(0xcb):\r
159         OPED(0xcc):\r
160         OPED(0xcd):\r
161         OPED(0xce):\r
162         OPED(0xcf):\r
163 \r
164         OPED(0xd0):\r
165         OPED(0xd1):\r
166         OPED(0xd2):\r
167         OPED(0xd3):\r
168         OPED(0xd4):\r
169         OPED(0xd5):\r
170         OPED(0xd6):\r
171         OPED(0xd7):\r
172         OPED(0xd8):\r
173         OPED(0xd9):\r
174         OPED(0xda):\r
175         OPED(0xdb):\r
176         OPED(0xdc):\r
177         OPED(0xdd):\r
178         OPED(0xde):\r
179         OPED(0xdf):\r
180 \r
181         OPED(0xe0):\r
182         OPED(0xe1):\r
183         OPED(0xe2):\r
184         OPED(0xe3):\r
185         OPED(0xe4):\r
186         OPED(0xe5):\r
187         OPED(0xe6):\r
188         OPED(0xe7):\r
189         OPED(0xe8):\r
190         OPED(0xe9):\r
191         OPED(0xea):\r
192         OPED(0xeb):\r
193         OPED(0xec):\r
194         OPED(0xed):\r
195         OPED(0xee):\r
196         OPED(0xef):\r
197 \r
198         OPED(0xf0):\r
199         OPED(0xf1):\r
200         OPED(0xf2):\r
201         OPED(0xf3):\r
202         OPED(0xf4):\r
203         OPED(0xf5):\r
204         OPED(0xf6):\r
205         OPED(0xf7):\r
206         OPED(0xf8):\r
207         OPED(0xf9):\r
208         OPED(0xfa):\r
209         OPED(0xfb):\r
210         OPED(0xfc):\r
211         OPED(0xfd):\r
212         OPED(0xfe):\r
213         OPED(0xff):\r
214                 RET(4)\r
215 \r
216 /*-----------------------------------------\r
217  LD r8\r
218 -----------------------------------------*/\r
219 \r
220         OPED(0x47): // LD   I,A\r
221                 zI = zA;\r
222                 RET(5)\r
223 \r
224         OPED(0x4f): // LD   R,A\r
225 #if CZ80_EMULATE_R_EXACTLY\r
226                 zR = zA;\r
227 #else\r
228                 zR = zA - ((cycles - CPU->ICount) >> 2);\r
229 #endif\r
230                 zR2 = zA & 0x80;\r
231                 RET(5)\r
232 \r
233         OPED(0x57): // LD   A,I\r
234                 zA = zI;\r
235                 zF = (zF & CF) | SZ[zA] | zIFF2;\r
236                 RET(5)\r
237 \r
238         OPED(0x5f): // LD   A,R\r
239 #if CZ80_EMULATE_R_EXACTLY\r
240                 zA = (zR & 0x7f) | zR2;\r
241 #else\r
242                 zA = ((zR + ((cycles - CPU->ICount) >> 2)) & 0x7f) | zR2;\r
243 #endif\r
244                 zF = (zF & CF) | SZ[zA] | zIFF2;\r
245                 RET(5)\r
246 \r
247 /*-----------------------------------------\r
248  LD r16\r
249 -----------------------------------------*/\r
250 \r
251         OPED(0x43): // LD   (w),BC\r
252                 data = pzBC;\r
253                 goto OP_LD_mNN_xx;\r
254 \r
255         OPED(0x53): // LD   (w),DE\r
256                 data = pzDE;\r
257                 goto OP_LD_mNN_xx;\r
258 \r
259         OPED(0x63): // LD   (w),HL\r
260                 data = pzHL;\r
261                 goto OP_LD_mNN_xx;\r
262 \r
263         OPED(0x73): // LD   (w),SP\r
264                 data = pzSP;\r
265                 goto OP_LD_mNN_xx;\r
266 \r
267         OPED(0x4b): // LD   BC,(w)\r
268                 data = pzBC;\r
269                 goto OP_LD_xx_mNN;\r
270 \r
271         OPED(0x5b): // LD   DE,(w)\r
272                 data = pzDE;\r
273                 goto OP_LD_xx_mNN;\r
274 \r
275         OPED(0x6b): // LD   HL,(w)\r
276                 data = pzHL;\r
277                 goto OP_LD_xx_mNN;\r
278 \r
279         OPED(0x7b): // LD   SP,(w)\r
280                 data = pzSP;\r
281                 goto OP_LD_xx_mNN;\r
282 \r
283 /*-----------------------------------------\r
284  NEG\r
285 -----------------------------------------*/\r
286 \r
287         OPED(0x44): // NEG\r
288         OPED(0x4c): // NEG\r
289         OPED(0x54): // NEG\r
290         OPED(0x5c): // NEG\r
291         OPED(0x64): // NEG\r
292         OPED(0x6c): // NEG\r
293         OPED(0x74): // NEG\r
294         OPED(0x7c): // NEG\r
295                 val = zA;\r
296                 zA = 0;\r
297                 goto OP_SUB;\r
298 \r
299 /*-----------------------------------------\r
300  RRD\r
301 -----------------------------------------*/\r
302 \r
303         OPED(0x67): // RRD  (HL)\r
304                 adr = zHL;\r
305                 val = READ_MEM8(adr);\r
306                 WRITE_MEM8(adr, (val >> 4) | (zA << 4));\r
307                 zA = (zA & 0xf0) | (val & 0x0f);\r
308                 zF = (zF & CF) | SZP[zA];\r
309                 RET(14)\r
310 \r
311 /*-----------------------------------------\r
312  RLD\r
313 -----------------------------------------*/\r
314 \r
315         OPED(0x6f): // RLD  (HL)\r
316                 adr = zHL;\r
317                 val = READ_MEM8(adr);\r
318                 WRITE_MEM8(adr, (val << 4) | (zA & 0x0f));\r
319                 zA = (zA & 0xf0) | (val >> 4);\r
320                 zF = (zF & CF) | SZP[zA];\r
321                 RET(14)\r
322 \r
323 /*-----------------------------------------\r
324  ADC 16\r
325 -----------------------------------------*/\r
326 \r
327         OPED(0x7a): // ADC  HL,SP\r
328                 val = zSP;\r
329                 goto OP_ADC16;\r
330 \r
331         OPED(0x4a): // ADC  HL,BC\r
332         OPED(0x5a): // ADC  HL,DE\r
333         OPED(0x6a): // ADC  HL,HL\r
334                 val = zR16((Opcode >> 4) & 3);\r
335 \r
336 OP_ADC16:\r
337                 res = zHL + val + (zF & CF);\r
338                 zF = (((zHL ^ res ^ val) >> 8) & HF) |\r
339                         ((res >> 16) & CF) |\r
340                         ((res >> 8) & (SF | YF | XF)) |\r
341                         ((res & 0xffff) ? 0 : ZF) |\r
342                         (((val ^ zHL ^ 0x8000) & (val ^ res) & 0x8000) >> 13);\r
343                 zHL = (UINT16)res;\r
344                 RET(11)\r
345 \r
346 /*-----------------------------------------\r
347  SBC 16\r
348 -----------------------------------------*/\r
349 \r
350         OPED(0x72): // SBC  HL,SP\r
351                 val = zSP;\r
352                 goto OP_SBC16;\r
353 \r
354         OPED(0x42): // SBC  HL,BC\r
355         OPED(0x52): // SBC  HL,DE\r
356         OPED(0x62): // SBC  HL,HL\r
357                 val = zR16((Opcode >> 4) & 3);\r
358 \r
359 OP_SBC16:\r
360                 res = zHL - val - (zF & CF);\r
361                 zF = (((zHL ^ res ^ val) >> 8) & HF) | NF |\r
362                         ((res >> 16) & CF) |\r
363                         ((res >> 8) & (SF | YF | XF)) |\r
364                         ((res & 0xffff) ? 0 : ZF) |\r
365                         (((val ^ zHL) & (zHL ^ res) & 0x8000) >> 13);\r
366                 zHL = (UINT16)res;\r
367                 RET(11)\r
368 \r
369 /*-----------------------------------------\r
370  IN\r
371 -----------------------------------------*/\r
372 \r
373         OPED(0x40): // IN   B,(C)\r
374         OPED(0x48): // IN   C,(C)\r
375         OPED(0x50): // IN   D,(C)\r
376         OPED(0x58): // IN   E,(C)\r
377         OPED(0x60): // IN   H,(C)\r
378         OPED(0x68): // IN   L,(C)\r
379         OPED(0x78): // IN   E,(C)\r
380                 res = IN(zBC);\r
381                 zR8((Opcode >> 3) & 7) = res;\r
382                 zF = (zF & CF) | SZP[res];\r
383                 RET(8)\r
384 \r
385         OPED(0x70): // IN   0,(C)\r
386                 res = IN(zBC);\r
387                 zF = (zF & CF) | SZP[res];\r
388                 RET(8)\r
389 \r
390 /*-----------------------------------------\r
391  OUT\r
392 -----------------------------------------*/\r
393 \r
394         OPED(0x51): // OUT  (C),D\r
395         OPED(0x41): // OUT  (C),B\r
396         OPED(0x49): // OUT  (C),C\r
397         OPED(0x59): // OUT  (C),E\r
398         OPED(0x61): // OUT  (C),H\r
399         OPED(0x69): // OUT  (C),L\r
400         OPED(0x79): // OUT  (C),E\r
401                 res = zR8((Opcode >> 3) & 7);\r
402                 OUT(zBC, res);\r
403                 RET(8)\r
404 \r
405         OPED(0x71): // OUT  (C),0\r
406                 OUT(zBC, 0);\r
407                 RET(8)\r
408 \r
409 /*-----------------------------------------\r
410  RETN\r
411 -----------------------------------------*/\r
412 \r
413         OPED(0x45): // RETN;\r
414         OPED(0x55): // RETN;\r
415         OPED(0x65): // RETN;\r
416         OPED(0x75): // RETN;\r
417                 POP_16(res);\r
418                 SET_PC(res);\r
419                 if (!zIFF1 && zIFF2)\r
420                 {\r
421                         zIFF1 = (1 << 2);\r
422                         if (CPU->IRQState)\r
423                         {\r
424                                 USE_CYCLES(10)\r
425                                 goto Cz80_Check_Interrupt;\r
426                         }\r
427                 }\r
428                 else zIFF1 = zIFF2;\r
429                 RET(10)\r
430 \r
431 /*-----------------------------------------\r
432  RETI\r
433 -----------------------------------------*/\r
434 \r
435         OPED(0x4d): // RETI\r
436         OPED(0x5d): // RETI\r
437         OPED(0x6d): // RETI\r
438         OPED(0x7d): // RETI\r
439                 POP_16(res);\r
440                 SET_PC(res);\r
441                 RET(10)\r
442 \r
443 /*-----------------------------------------\r
444  IM\r
445 -----------------------------------------*/\r
446 \r
447         OPED(0x46): // IM   0\r
448         OPED(0x4e): // IM   0\r
449         OPED(0x66): // IM   0\r
450         OPED(0x6e): // IM   0\r
451                 zIM = 0;\r
452                 RET(4)\r
453 \r
454         OPED(0x56): // IM   1\r
455         OPED(0x76): // IM   1\r
456                 zIM = 1;\r
457                 RET(4)\r
458 \r
459         OPED(0x5e): // IM   2\r
460         OPED(0x7e): // IM   2\r
461                 zIM = 2;\r
462                 RET(4)\r
463 \r
464         {\r
465                 UINT8 val;\r
466                 UINT8 res;\r
467                 UINT8 F;\r
468 \r
469 /*-----------------------------------------\r
470  LDI/LDD\r
471 -----------------------------------------*/\r
472 \r
473         OPED(0xa0): // LDI\r
474                 val = READ_MEM8(zHL++);\r
475                 WRITE_MEM8(zDE++, val);\r
476                 goto OP_LDX;\r
477 \r
478         OPED(0xa8): // LDD\r
479                 val = READ_MEM8(zHL--);\r
480                 WRITE_MEM8(zDE--, val);\r
481 \r
482 OP_LDX:\r
483                 F = zF & (SF | ZF | CF);\r
484                 if ((zA + val) & 0x02) F |= YF;\r
485                 if ((zA + val) & 0x08) F |= XF;\r
486                 if (--zBC) F |= VF;\r
487                 zF = F;\r
488                 RET(12)\r
489 \r
490 /*-----------------------------------------\r
491  LDIR/LDDR\r
492 -----------------------------------------*/\r
493 \r
494         OPED(0xb0): // LDIR\r
495                 do\r
496                 {\r
497                         val = READ_MEM8(zHL++);\r
498                         WRITE_MEM8(zDE++, val);\r
499                         zBC--;\r
500                         USE_CYCLES(17)\r
501                 } while (zBC && (CPU->ICount > 0));\r
502                 goto OP_LDXR;\r
503 \r
504         OPED(0xb8): // LDDR\r
505                 do\r
506                 {\r
507                         val = READ_MEM8(zHL--);\r
508                         WRITE_MEM8(zDE--, val);\r
509                         zBC--;\r
510                         USE_CYCLES(17)\r
511                 } while (zBC && (CPU->ICount > 0));\r
512 \r
513 OP_LDXR:\r
514                 F = zF & (SF | ZF | CF);\r
515                 if ((zA + val) & 0x02) F |= YF;\r
516                 if ((zA + val) & 0x08) F |= XF;\r
517                 if (zBC)\r
518                 {\r
519                         zF = F | VF;\r
520                         PC -= 2;\r
521 #if CZ80_EMULATE_R_EXACTLY\r
522                         zR--;\r
523 #endif\r
524                         goto Cz80_Exec_End;\r
525                 }\r
526                 zF = F;\r
527                 ADD_CYCLES(5)\r
528                 goto Cz80_Exec;\r
529 \r
530 /*-----------------------------------------\r
531  CPI/CPD\r
532 -----------------------------------------*/\r
533 \r
534         OPED(0xa1): // CPI\r
535                 val = READ_MEM8(zHL++);\r
536                 goto OP_CPX;\r
537 \r
538         OPED(0xa9): // CPD\r
539                 val = READ_MEM8(zHL--);\r
540 \r
541 OP_CPX:\r
542                 res = zA - val;\r
543                 F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;\r
544                 if (F & HF) res--;\r
545                 if (res & 0x02) F |= YF;\r
546                 if (res & 0x08) F |= XF;\r
547                 if (--zBC) F |= VF;\r
548                 zF = F;\r
549                 RET(12)\r
550 \r
551 /*-----------------------------------------\r
552  CPIR/CPDR\r
553 -----------------------------------------*/\r
554 \r
555         OPED(0xb1): // CPIR\r
556                 do\r
557                 {\r
558                         val = READ_MEM8(zHL++);\r
559                         res = zA - val;\r
560                         zBC--;\r
561                         F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;\r
562                         if (F & HF) res--;\r
563                         if (res & 0x02) F |= YF;\r
564                         if (res & 0x08) F |= XF;\r
565                         if (zBC) F |= VF;\r
566                         zF = F;\r
567                         USE_CYCLES(17)\r
568                 } while (zBC && !(F & ZF) && (CPU->ICount > 0));\r
569                 goto OP_CPXR;\r
570 \r
571         OPED(0xb9): // CPDR\r
572                 do\r
573                 {\r
574                         val = READ_MEM8(zHL--);\r
575                         res = zA - val;\r
576                         zBC--;\r
577                         F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;\r
578                         if (F & HF) res--;\r
579                         if (res & 0x02) F |= YF;\r
580                         if (res & 0x08) F |= XF;\r
581                         if (zBC) F |= VF;\r
582                         zF = F;\r
583                         USE_CYCLES(17)\r
584                 } while (zBC && !(F & ZF) && (CPU->ICount > 0));\r
585 \r
586 OP_CPXR:\r
587                 if (zBC && !(F & ZF))\r
588                 {\r
589                         PC -= 2;\r
590 #if CZ80_EMULATE_R_EXACTLY\r
591                         zR--;\r
592 #endif\r
593                         goto Cz80_Exec_End;\r
594                 }\r
595                 ADD_CYCLES(5)\r
596                 goto Cz80_Exec;\r
597 \r
598 /*-----------------------------------------\r
599  INI/IND\r
600 -----------------------------------------*/\r
601 \r
602         OPED(0xa2): // INI\r
603                 val = IN(zBC);\r
604                 zB--;\r
605                 WRITE_MEM8(zHL++, val);\r
606                 goto OP_INX;\r
607 \r
608         OPED(0xaa): // IND\r
609                 val = IN(zBC);\r
610                 zB--;\r
611                 WRITE_MEM8(zHL--, val);\r
612 \r
613 OP_INX:\r
614                 F = SZ[zB];\r
615                 res = ((UINT32)(zC - 1) & 0xff) + (UINT32)val;\r
616                 if (val & SF) F |= NF;\r
617                 if (res & 0x100) F |= HF | CF;\r
618                 F |= SZP[(UINT8)(res & 0x07) ^ zB] & PF;\r
619                 zF = F;\r
620                 RET(12)\r
621 \r
622 /*-----------------------------------------\r
623  INIR/INDR\r
624 -----------------------------------------*/\r
625 \r
626         OPED(0xb2): // INIR\r
627                 do\r
628                 {\r
629                         val = IN(zBC);\r
630                         zB--;\r
631                         WRITE_MEM8(zHL++, val);\r
632                         USE_CYCLES(17)\r
633                 } while (zB && (CPU->ICount > 0));\r
634                 goto OP_INXR;\r
635 \r
636         OPED(0xba): // INDR\r
637                 do\r
638                 {\r
639                         val = IN(zBC);\r
640                         zB--;\r
641                         WRITE_MEM8(zHL--, val);\r
642                         USE_CYCLES(17)\r
643                 } while (zB && (CPU->ICount > 0));\r
644 \r
645 OP_INXR:\r
646                 F = SZ[zB];\r
647                 res = ((UINT32)(zC - 1) & 0xff) + (UINT32)val;\r
648                 if (val & SF) F |= NF;\r
649                 if (res & 0x100) F |= HF | CF;\r
650                 F |= SZP[(UINT8)(res & 0x07) ^ zB] & PF;\r
651                 zF = F;\r
652                 if (zB)\r
653                 {\r
654                         PC -= 2;\r
655 #if CZ80_EMULATE_R_EXACTLY\r
656                         zR--;\r
657 #endif\r
658                         goto Cz80_Exec_End;\r
659                 }\r
660                 ADD_CYCLES(5);\r
661                 goto Cz80_Exec;\r
662 \r
663 /*-----------------------------------------\r
664  OUTI/OUTD\r
665 -----------------------------------------*/\r
666 \r
667         OPED(0xa3): // OUTI\r
668                 val = READ_MEM8(zHL++);\r
669                 zB--;\r
670                 OUT(zBC, val);\r
671                 goto OP_OUTX;\r
672 \r
673         OPED(0xab): // OUTD\r
674                 val = READ_MEM8(zHL--);\r
675                 zB--;\r
676                 OUT(zBC, val);\r
677 \r
678 OP_OUTX:\r
679                 F = SZ[zB];\r
680                 res = (UINT32)zL + (UINT32)val;\r
681                 if (val & SF) F |= NF;\r
682                 if (res & 0x100) F |= HF | CF;\r
683                 F |= SZP[(UINT8)(res & 0x07) - zB] & PF;\r
684                 zF = F;\r
685                 RET(12)\r
686 \r
687 /*-----------------------------------------\r
688  OTIR/OTDR\r
689 -----------------------------------------*/\r
690 \r
691         OPED(0xb3): // OTIR\r
692                 do\r
693                 {\r
694                         val = READ_MEM8(zHL++);\r
695                         zB--;\r
696                         OUT(zBC, val);\r
697                         USE_CYCLES(17)\r
698                 } while (zB && (CPU->ICount > 0));\r
699                 goto OP_OTXR;\r
700 \r
701         OPED(0xbb): // OTDR\r
702                 do\r
703                 {\r
704                         val = READ_MEM8(zHL--);\r
705                         zB--;\r
706                         OUT(zBC, val);\r
707                         USE_CYCLES(17)\r
708                 } while (zB && (CPU->ICount > 0));\r
709 \r
710 OP_OTXR:\r
711                 F = SZ[zB];\r
712                 res = (UINT32)zL + (UINT32)val;\r
713                 if (val & SF) F |= NF;\r
714                 if (res & 0x100) F |= HF | CF;\r
715                 F |= SZP[(UINT8)(res & 0x07) - zB] & PF;\r
716                 zF = F;\r
717                 if (zB)\r
718                 {\r
719                         PC -= 2;\r
720 #if CZ80_EMULATE_R_EXACTLY\r
721                         zR--;\r
722 #endif\r
723                         goto Cz80_Exec_End;\r
724                 }\r
725                 ADD_CYCLES(5)\r
726                 goto Cz80_Exec;\r
727         }\r
728 \r
729 #if !CZ80_USE_JUMPTABLE\r
730 }\r
731 #endif\r