/** * mdp_host_reg_set_all_z80(): Set all Z80 registers. * @param reg_struct Pointer to mdp_reg_psg_t struct to get the registers from. * @return MDP error code. */ static int mdp_host_reg_set_all_z80(void *reg_struct) { mdp_reg_z80_t *reg_z80 = (mdp_reg_z80_t*)reg_struct; /* Main registers. */ mdZ80_set_AF(&M_Z80, reg_z80->AF); M_Z80.BC.w.BC = reg_z80->BC; M_Z80.DE.w.DE = reg_z80->DE; M_Z80.HL.w.HL = reg_z80->HL; M_Z80.IX.w.IX = reg_z80->IX; M_Z80.IY.w.IY = reg_z80->IY; /* Shadow registers. */ mdZ80_set_AF2(&M_Z80, reg_z80->AF2); M_Z80.BC2.w.BC2 = reg_z80->BC2; M_Z80.DE2.w.DE2 = reg_z80->DE2; M_Z80.HL2.w.HL2 = reg_z80->HL2; /* Other registers. */ mdZ80_set_PC(&M_Z80, reg_z80->PC); M_Z80.I = reg_z80->I; M_Z80.R.b.R1 = reg_z80->R; M_Z80.IM = reg_z80->IM & 3; M_Z80.IFF.b.IFF1 = (reg_z80->IFF & 1); M_Z80.IFF.b.IFF2 = ((reg_z80->IFF & 2) >> 1); return MDP_ERR_OK; }
/** * Reset the Z80 CPU. * This is equivalent to asserting the !RESET line. * @param z80 Pointer to Z80 context. */ void mdZ80_soft_reset(mdZ80_context *z80) { /** * References: * [1] "The Undocumented Z80 Docuemnted" by Sean Young, v0.91 (2005/09/18) * [2] http://gs_server.gerbilsoft.ddns.info/bugs/show_bug.cgi?id=47 */ // NOTE: Both [1] and [2] say that other registers are *not* touched // when !RESET is asserted, so they're left as-is. // TODO: Write a test program for MD, then test it on actual hardware. // Z80 program starts at 0x0000. mdZ80_set_PC(z80, 0); // old Gens; [1] // TODO: Are IX and IY actually reset on !RESET? z80->IX.w = 0xFFFF; // old Gens; also genplus-gx z80->IY.w = 0xFFFF; // old Gens; also genplus-gx // TODO: Initialize AF2 to 0xFFFF? mdZ80_set_AF(z80, 0xFFFF); // [1]; Gens originally used 0x4000 (ZF only). z80->SP.w = 0xFFFF; // [1] z80->IFF = 0; // [1] z80->R = 0; // [2] z80->I = 0; // [2] z80->IM = 0; // [1] }