title: Game Boy: Half-carry flag and 16-bit instructions (especially opcode 0xE8)
body: <p>Like so many others, I am writing a Game Boy emulator and I have a couple of questions regarding the instruction 0xE8 (<code>ADD SP, n</code> with an 8-bit immediate).</p>
  
  <p>It is claimed <a href="http://www.codeslinger.co.uk/pages/projects/gameboy/hardware.html" rel="noreferrer">here</a> that in 16-bit instructions the half-carry flag is set if a carry occurs from bit 7 to bit 8, whereas <a href="https://stackoverflow.com/questions/8868396/gbz80-what-constitutes-a-half-carry">here</a> it is said that the half-carry flag indicates carry from bit 11 to bit 12. In <a href="https://www.reddit.com/r/EmuDev/comments/4ycoix/a_guide_to_the_gameboys_halfcarry_flag/" rel="noreferrer">this Reddit thread</a> there seems to be a bit of confusion regarding the issue, and the (notoriously flawed, I hear) <a href="http://marc.rawer.de/Gameboy/Docs/GBCPUman.pdf" rel="noreferrer">Game Boy CPU manual</a> doesn't seem to have anything useful to say either.</p>
  
  <p>My questions are the following:</p>
  
  <ol>
  <li>How does the half-carry flag behave in opcode 0xE8?</li>
  <li>How is the opcode 0xE8 implemented in the physical hardware?</li>
  <li>Which is right, that half-carry occurs from bit 7 to bit 8 or that half-carry occurs from bit 11 to bit 12 (in the case of 16-bit instructions)?</li>
  </ol>