Welcome to Emulationworld

Forum Index | FAQ | New User | Login | Search

Make a New PostPrevious ThreadView All ThreadsNext ThreadShow in Flat Mode*

Subjectemulating register overflow? Reply to this message
Posted bynewsdee
Posted on01/23/05 10:13 PM

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]

Entire Thread
Subject  Posted byPosted On
.emulating register overflow?  newsdee01/23/05 10:13 PM
.*thanks guys, very interesting insights  newsdee01/28/05 00:02 AM
..*Re: thanks guys, very interesting insights  Bart T.01/28/05 06:55 PM
.*Re: emulating register overflow?  Bart T.01/24/05 08:43 PM
.*got it (king of answering my own questions)  newsdee01/23/05 10:23 PM
..*Re: got it (king of answering my own questions)  finaldave01/25/05 11:56 AM