Game Boy: What constitutes a “half-carry”?

后端 未结 3 524
南笙
南笙 2020-12-13 13:21

The Game Boy Z80 CPU has a half-carry flag, and I can\'t seem to find much information about when to set/clear it.

What I understand so far is that any 8-bit add, su

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 13:21

    Since the half-carry flag is one of the most common stumbling blocks for Game Boy emulator makers, I'll take the liberty to post a link to a recent question of mine regarding the subject as an answer:

    Game Boy: Half-carry flag and 16-bit instructions (especially opcode 0xE8)


    A summary of the above thread (answer by @gekkio):

    It depends on the instruction, but the flags are always updated based on the same bit positions if you think in terms of 8-bit values...it just varies whether we're talking about the high or low byte of the 16-bit value. Bit 11 is just bit 3 of the high byte.

    • ADD SP, e: H from bit 3, C from bit 7 (flags from low byte op)
    • LD HL, SP+e: H from bit 3, C from bit 7 (flags from low byte op)
    • ADD HL, rr: H from bit 11, C from bit 15 (flags from high byte op)
    • INC rr: no flag updates (executed by the 16-bit inc/dec unit)
    • DEC rr: no flag updates (executed by the 16-bit inc/dec unit)

提交回复
热议问题