Game Boy: What constitutes a "half-carry"?

game boy advance
game boy pocket
game boy color
nintendo game boy advance
gameboy advance sp
nintendo game boy color
original gameboy price
game boy color release date

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, subtract, shift, or rotate operation (and maybe others?) set it to bit 4 of the result(?), and the DAA instruction sets/uses this somehow. What I'm not sure is how 16-bit instructions affect it and whether it's affected or not by the use of certain registers.

It's the carry from bit 3 to bit 4, just like the normal carry flag records carry from bit 7. So, e.g. to get the half carry bit in an add:

((a&0xf) + (value&0xf))&0x10

Which gives 0x10 if half carry should be set, 0 otherwise. Getting half carry from the other relevant ops follows naturally - the questions is whether there was carry from the low nibble to the high.

To put things in perspective, the z80 has a 4bit ALU and performs 8bit ops by doing two 4bit ops. So it gets half carry very naturally, as an intermediate result.

DAA is interested in the flag because if half carry is set then two digits that add up to more than 16 were added in the low nibble; that will have correctly produced carry into the upper nibble but will have left the low nibble 6 lower than it should be, since there were six more values between 10, when it should have generated carry, and 16, when it did.

Game Boy, The Game Boy Advance is one of Nintendo's handheld gaming systems that have dominated the market . Find out what made the Game Boy Advance such a � The Game Boy Pocket is a redesigned version of the original Game Boy having the same features released in 1996. Notably, this variation is smaller and lighter. Another notable improvement over the original Game Boy includes a black-and-white display screen, rather than the "pea soup" monochromatic display of the original Game Boy and less sprite blurs. The Game Boy Pocket takes two AAA

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

Game Boy family, The Nintendo Game Boy was released in 1989. It was a handheld video game console that combined aspects of Nintendos successful Nintendo Entertainment � The system looks like an old Game Boy Pocket but packs stereo speakers and a much nicer display, with a 3.5-inch 1,600 x 1,440 pixel LCD with "pro-level color accuracy," according to Analogue.

Gameboy, GB, Game Boy. GB, Good Bye. GB, Gabon (Africa). GB, Gilbert. GB, Gearbox. GB, Ground Ball (baseball). GB, Green Bay (Wisconsin). GB, Gordon Brown (UK). The Game Boy is an 8-bit console that was released by Nintendo in 1989. It's the first console in the Game Boy line, a line of consoles that Nintendo expanded on through different handheld

How Game Boy Advance Works, Gameboy definition: A Gameboy is a small portable computer that is specially designed for people to play | Meaning, pronunciation, translations and examples. Ultra Game Boy brings slim aluminum case, backlight for under $100. Kyle Orland - Jan 10, 2018 3:40 pm UTC Enlarge / Not an actual picture of the Ultra Game Boy.

Game Boy, JAMSWALL Handheld Game Console, 400 Classical FC Games 2.8-Inch Screen 800mAh Rechargeable Battery Portable Retro Video Game Console Support for Connecting TV and Two Players(White) $18.99 $ 18 . 99 $19.99

Game Boy, Game Boy Color. Refurbished. $79.99 Buy Now. QuickView Pokemon Silver Version. Game Boy. Pre-Owned. $17.99 15% off $50+ 25% off $75+ and 50% off $100+ on Pre-Owned

Comments
  • Er, isn't it electronics question?
  • I'm writing an emulator, so I don't think so...
  • I highly recommend that anyone struggling with the half-carry flag read this thread for further details.
  • Read the Z80 reference manual. The effect on every flag of every instruction is documented.
  • Alright, but what about 16-bit operations? Is the half-carry set from the high or low byte?
  • The high byte; it's the most recent half carry. And you've probably found it already, but I find datasheets.chipdb.org/Zilog/Z80/z80-documented-0.90.pdf to have a great description of DAA, plus explanations of where half carry comes from in edge cases like CCF (where it's set to old carry, if memory serves).
  • One thing to add that makes it clear to me: Adding e.g., 0x37 and 0x44 will not cause a half-carry because you only look at the lower 4 bits of each byte, add them together, and see if that overflows. 0x0F + 0x01 does, 0x37 + 0x44 does not.
  • The GBZ80 (a.k.a. the SM83) has an 8-bit ALU.