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

后端 未结 3 514
南笙
南笙 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:34

    For 16-bit operations, the carry from bit 3 to bit 4 in the register's high byte sets the flag. In other words, bit 11 to bit 12.

    (Note the above bits are labeled 0-15, from least to most significant)

    See here: http://www.z80.info/z80code.htm

    16 bit arithmetic
    
    If  you want to add numbers that are more than the 0-255 that can
    be stored in the A register,  then the HL, IX or IY registers can
    be used. Thus LD HL,1000H:LD BC,2000H:ADD HL,BC will give
    
    A  CZPSNH  BC   DE   HL   IX   IY  A' CZPSNH' BC'  DE'  HL'  SP
    00 000000 2000 0000 3000 0000 0000 00 000000 0000 0000 0000 0000
    
    The flags are set as follows.
    
    C or carry flag          1 if answer >65535 else 0
    Z or zero flag           not changed
    P flag                   not changed
    S or sign flag           not changed
    N flag                   0
    H or half carry flag     1 if carry from bit 11 to bit 12 else 0
    

提交回复
热议问题