word RunZ80(Z80 *R) { register byte I; register pair J; for(;;) { #ifdef DEBUG /* Turn tracing on when reached trap address */ if(R->PC.W==R->Trap) R->Trace=1; /* Call single-step debugger, exit if requested */ if(R->Trace) if(!DebugZ80(R)) return(R->PC.W); #endif I=RdZ80(R->PC.W++); R->ICount-=Cycles[I]; switch(I) { #include "Codes.h" case PFX_CB: CodesCB(R);break; case PFX_ED: CodesED(R);break; case PFX_FD: CodesFD(R);break; case PFX_DD: CodesDD(R);break; } /* If cycle counter expired... */ if(R->ICount<=0) { /* If we have come after EI, get address from IRequest */ /* Otherwise, get it from the loop handler */ if(R->IFF&IFF_EI) { R->IFF=(R->IFF&~IFF_EI)|IFF_1; /* Done with AfterEI state */ R->ICount+=R->IBackup-1; /* Restore the ICount */ /* Call periodic handler or set pending IRQ */ if(R->ICount>0) J.W=R->IRequest; else { J.W=LoopZ80(R); /* Call periodic handler */ R->ICount+=R->IPeriod; /* Reset the cycle counter */ if(J.W==INT_NONE) J.W=R->IRequest; /* Pending IRQ */ } } else { J.W=LoopZ80(R); /* Call periodic handler */ R->ICount+=R->IPeriod; /* Reset the cycle counter */ if(J.W==INT_NONE) J.W=R->IRequest; /* Pending IRQ */ } if(J.W==INT_QUIT) return(R->PC.W); /* Exit if INT_QUIT */ if(J.W!=INT_NONE) IntZ80(R,J.W); /* Int-pt if needed */ } } /* Execution stopped */ return(R->PC.W); }
// MAIN EMULATION LOOP (RAZE CORE) -------------------------------------------- void CPU_Loop (void) { for (;;) { z80_emulate (opt.Cur_IPeriod); switch (LoopZ80 ()) { case INT_IRQ: z80_raise_IRQ (0xff); z80_lower_IRQ(); break; case INT_NMI: z80_cause_NMI(); break; case INT_QUIT: return; } } }
// MAIN EMULATION LOOP (MAME CORE) -------------------------------------------- void CPU_Loop (void) { for (;;) { z80_execute (opt.Cur_IPeriod); switch (LoopZ80 ()) { case INT_IRQ: break; case INT_NMI: z80_set_nmi_line (ASSERT_LINE); z80_set_nmi_line (CLEAR_LINE); break; case INT_QUIT: return; } } /* z80_stop_emulating(); */ }
word RunZ80(Z80 *R) { register byte I; register pair J; for(;;) { #ifdef DEBUG /* Turn tracing on when reached trap address */ if(R->PC.W==R->Trap) R->Trace=1; /* Call single-step debugger, exit if requested */ if(R->Trace) if(!DebugZ80(R)) return(R->PC.W); #endif I=OpZ80(R->PC.W++); R->ICount-=Cycles[I]; switch(I) { #include "Codes.h" case PFX_CB: CodesCB(R);break; case PFX_ED: CodesED(R);break; case PFX_FD: CodesFD(R);break; case PFX_DD: CodesDD(R);break; } /* Nascom Single Step ; activate nmi push af ld a,8 out (0),a pop af ; execute one step of program retn after out skip pop,retn and one user program opcode before forcing NMI */ byte skip; if (R->Trap) { if (skip++==3) { skip=0; R->Trap=0; IntZ80(R,INT_NMI); } } /* If cycle counter expired... */ if(R->ICount<=0) { /* If we have come after EI, get address from IRequest */ /* Otherwise, get it from the loop handler */ if(R->IFF&IFF_EI) { R->IFF=(R->IFF&~IFF_EI)|IFF_1; /* Done with AfterEI state */ R->ICount+=R->IBackup-1; /* Restore the ICount */ /* Call periodic handler or set pending IRQ */ if(R->ICount>0) J.W=R->IRequest; else { J.W=LoopZ80(R); /* Call periodic handler */ R->ICount+=R->IPeriod; /* Reset the cycle counter */ if(J.W==INT_NONE) J.W=R->IRequest; /* Pending IRQ */ } } else { J.W=LoopZ80(R); /* Call periodic handler */ R->ICount+=R->IPeriod; /* Reset the cycle counter */ if(J.W==INT_NONE) J.W=R->IRequest; /* Pending IRQ */ } if(J.W==INT_QUIT) return(R->PC.W); /* Exit if INT_QUIT */ if(J.W!=INT_NONE) IntZ80(R,J.W); /* Int-pt if needed */ } } /* Execution stopped */ return(R->PC.W); }