Skip to content

Instantly share code, notes, and snippets.

@Palmr
Last active December 11, 2015 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Palmr/4520944 to your computer and use it in GitHub Desktop.
Save Palmr/4520944 to your computer and use it in GitHub Desktop.
Return instruction for the gameboy cpu emulator I'm writing
void Instructions::doReturn(CPU* cpu, BYTE pOpcode) {
if (pOpcode == 0xc9
|| (pOpcode == 0xc0 && cpu->reg->getFlagZ() == 0)
|| (pOpcode == 0xc8 && cpu->reg->getFlagZ() == 1)
|| (pOpcode == 0xd0 && cpu->reg->getFlagC() == 0)
|| (pOpcode == 0xd8 && cpu->reg->getFlagC() == 1)) {
cpu->reg->setPC((WORD)((cpu->mem.readByte(cpu->reg->getSP() + 1) << 8) | cpu->mem.readByte(cpu->reg->getSP())));
cpu->reg->incSP(2);
cpu->clock.m += 5;
cpu->clock.t += 20;
}
else {
cpu->clock.m += 2;
cpu->clock.t += 8;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment