|
Maybe this is obvious, but I'll ask in case I missed something.
I'm writing a chip8 emu to learn how emus work, and I've noticed a weird behavior on one of the games I'm trying (the TETRIS rom).
It sets an 8-bit register to 1F, and then later adds FF to the same register.
V[1] = 1F ... V[1] += FF
Now I'm not sure how I should handle the overflow. Initially I had this: 1. add number to register 2. if register > 255, set to 255 and set the Carry Flag.
But this is cearly wrong since I get into an infinite loop (the rom tests for V[1] being equal to 0, but with the alg. above it will always stay at FF).
So what should I do? I would think that bits are added 1 by 1, and resets to 00 after reaching FF, but then my register would go back to 1F at the end.
Should I add the two values as integers, convert to binary, and then only keep the leftmost 8 bits? Or should I keep the rightmost?
 [download a life]
|