On Gameboy Z80, exactly how does the LD HL,(SP+e) operation affect H and C flags? (Half-carry + carry)
Reference: http://www.devrs.com/gb/files/opcodes.html
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I realise this is an old question but I had a similar problem a while ago and would just like to add my solution as there is absolutely no documentation or open-source emulator that does it correctly to my knowledge. Took me some actual debugging on a real gameboy to find the solution.
For both 16bit SP + s8 (signed immediate) operations:
the carry flag is set if there’s an overflow from the 7th to 8th bit.
the half carry flag is set if there’s an overflow from the 3rd into the 4th bit.
I found it easier to do the behaviour separately for both a positive and negative signed immediate (Lua):