1 /******************************************************************************
\r
3 * CZ80 ED opcode include source file
\r
4 * CZ80 emulator version 0.9
\r
5 * Copyright 2004-2005 Stéphane Dallongeville
\r
9 *****************************************************************************/
\r
11 #if CZ80_USE_JUMPTABLE
\r
12 goto *JumpTableED[Opcode];
\r
18 /*-----------------------------------------
\r
20 -----------------------------------------*/
\r
216 /*-----------------------------------------
\r
218 -----------------------------------------*/
\r
220 OPED(0x47): // LD I,A
\r
224 OPED(0x4f): // LD R,A
\r
225 #if CZ80_EMULATE_R_EXACTLY
\r
228 zR = zA - ((cycles - CPU->ICount) >> 2);
\r
233 OPED(0x57): // LD A,I
\r
235 zF = (zF & CF) | SZ[zA] | zIFF2;
\r
238 OPED(0x5f): // LD A,R
\r
239 #if CZ80_EMULATE_R_EXACTLY
\r
240 zA = (zR & 0x7f) | zR2;
\r
242 zA = ((zR + ((cycles - CPU->ICount) >> 2)) & 0x7f) | zR2;
\r
244 zF = (zF & CF) | SZ[zA] | zIFF2;
\r
247 /*-----------------------------------------
\r
249 -----------------------------------------*/
\r
251 OPED(0x43): // LD (w),BC
\r
255 OPED(0x53): // LD (w),DE
\r
259 OPED(0x63): // LD (w),HL
\r
263 OPED(0x73): // LD (w),SP
\r
267 OPED(0x4b): // LD BC,(w)
\r
271 OPED(0x5b): // LD DE,(w)
\r
275 OPED(0x6b): // LD HL,(w)
\r
279 OPED(0x7b): // LD SP,(w)
\r
283 /*-----------------------------------------
\r
285 -----------------------------------------*/
\r
299 /*-----------------------------------------
\r
301 -----------------------------------------*/
\r
303 OPED(0x67): // RRD (HL)
\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
311 /*-----------------------------------------
\r
313 -----------------------------------------*/
\r
315 OPED(0x6f): // RLD (HL)
\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
323 /*-----------------------------------------
\r
325 -----------------------------------------*/
\r
327 OPED(0x7a): // ADC HL,SP
\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
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
346 /*-----------------------------------------
\r
348 -----------------------------------------*/
\r
350 OPED(0x72): // SBC HL,SP
\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
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
369 /*-----------------------------------------
\r
371 -----------------------------------------*/
\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
381 zR8((Opcode >> 3) & 7) = res;
\r
382 zF = (zF & CF) | SZP[res];
\r
385 OPED(0x70): // IN 0,(C)
\r
387 zF = (zF & CF) | SZP[res];
\r
390 /*-----------------------------------------
\r
392 -----------------------------------------*/
\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
405 OPED(0x71): // OUT (C),0
\r
409 /*-----------------------------------------
\r
411 -----------------------------------------*/
\r
413 OPED(0x45): // RETN;
\r
414 OPED(0x55): // RETN;
\r
415 OPED(0x65): // RETN;
\r
416 OPED(0x75): // RETN;
\r
419 if (!zIFF1 && zIFF2)
\r
425 goto Cz80_Check_Interrupt;
\r
428 else zIFF1 = zIFF2;
\r
431 /*-----------------------------------------
\r
433 -----------------------------------------*/
\r
435 OPED(0x4d): // RETI
\r
436 OPED(0x5d): // RETI
\r
437 OPED(0x6d): // RETI
\r
438 OPED(0x7d): // RETI
\r
443 /*-----------------------------------------
\r
445 -----------------------------------------*/
\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
454 OPED(0x56): // IM 1
\r
455 OPED(0x76): // IM 1
\r
459 OPED(0x5e): // IM 2
\r
460 OPED(0x7e): // IM 2
\r
469 /*-----------------------------------------
\r
471 -----------------------------------------*/
\r
474 val = READ_MEM8(zHL++);
\r
475 WRITE_MEM8(zDE++, val);
\r
479 val = READ_MEM8(zHL--);
\r
480 WRITE_MEM8(zDE--, val);
\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
490 /*-----------------------------------------
\r
492 -----------------------------------------*/
\r
494 OPED(0xb0): // LDIR
\r
497 val = READ_MEM8(zHL++);
\r
498 WRITE_MEM8(zDE++, val);
\r
501 } while (zBC && (CPU->ICount > 0));
\r
504 OPED(0xb8): // LDDR
\r
507 val = READ_MEM8(zHL--);
\r
508 WRITE_MEM8(zDE--, val);
\r
511 } while (zBC && (CPU->ICount > 0));
\r
514 F = zF & (SF | ZF | CF);
\r
515 if ((zA + val) & 0x02) F |= YF;
\r
516 if ((zA + val) & 0x08) F |= XF;
\r
521 #if CZ80_EMULATE_R_EXACTLY
\r
524 goto Cz80_Exec_End;
\r
530 /*-----------------------------------------
\r
532 -----------------------------------------*/
\r
535 val = READ_MEM8(zHL++);
\r
539 val = READ_MEM8(zHL--);
\r
543 F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;
\r
545 if (res & 0x02) F |= YF;
\r
546 if (res & 0x08) F |= XF;
\r
547 if (--zBC) F |= VF;
\r
551 /*-----------------------------------------
\r
553 -----------------------------------------*/
\r
555 OPED(0xb1): // CPIR
\r
558 val = READ_MEM8(zHL++);
\r
561 F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;
\r
563 if (res & 0x02) F |= YF;
\r
564 if (res & 0x08) F |= XF;
\r
568 } while (zBC && !(F & ZF) && (CPU->ICount > 0));
\r
571 OPED(0xb9): // CPDR
\r
574 val = READ_MEM8(zHL--);
\r
577 F = (zF & CF) | (SZ[res] & ~(YF | XF)) | ((zA ^ val ^ res) & HF) | NF;
\r
579 if (res & 0x02) F |= YF;
\r
580 if (res & 0x08) F |= XF;
\r
584 } while (zBC && !(F & ZF) && (CPU->ICount > 0));
\r
587 if (zBC && !(F & ZF))
\r
590 #if CZ80_EMULATE_R_EXACTLY
\r
593 goto Cz80_Exec_End;
\r
598 /*-----------------------------------------
\r
600 -----------------------------------------*/
\r
605 WRITE_MEM8(zHL++, val);
\r
611 WRITE_MEM8(zHL--, val);
\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
622 /*-----------------------------------------
\r
624 -----------------------------------------*/
\r
626 OPED(0xb2): // INIR
\r
631 WRITE_MEM8(zHL++, val);
\r
633 } while (zB && (CPU->ICount > 0));
\r
636 OPED(0xba): // INDR
\r
641 WRITE_MEM8(zHL--, val);
\r
643 } while (zB && (CPU->ICount > 0));
\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
655 #if CZ80_EMULATE_R_EXACTLY
\r
658 goto Cz80_Exec_End;
\r
663 /*-----------------------------------------
\r
665 -----------------------------------------*/
\r
667 OPED(0xa3): // OUTI
\r
668 val = READ_MEM8(zHL++);
\r
673 OPED(0xab): // OUTD
\r
674 val = READ_MEM8(zHL--);
\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
687 /*-----------------------------------------
\r
689 -----------------------------------------*/
\r
691 OPED(0xb3): // OTIR
\r
694 val = READ_MEM8(zHL++);
\r
698 } while (zB && (CPU->ICount > 0));
\r
701 OPED(0xbb): // OTDR
\r
704 val = READ_MEM8(zHL--);
\r
708 } while (zB && (CPU->ICount > 0));
\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
720 #if CZ80_EMULATE_R_EXACTLY
\r
723 goto Cz80_Exec_End;
\r
729 #if !CZ80_USE_JUMPTABLE
\r