Skip to content

Commit

Permalink
"Space Flight 2019!" emulation bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ferris committed May 18, 2013
1 parent 7c6541a commit 50b221d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Chip8/Chip8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ void Chip8::Update()
{
// ADD Vx, Vy
int result = regs[x] + regs[y];
regs[15] = (result > 255) ? 1 : 0;
regs[15] = result > 255 ? 1 : 0;
regs[x] = result;
}
break;

case 5:
// SUB Vx, Vy
regs[15] = (regs[x] < regs[y]) ? 0 : 1;
regs[15] = regs[x] < regs[y] ? 0 : 1;
regs[x] -= regs[y];
break;

Expand All @@ -205,7 +205,7 @@ void Chip8::Update()

case 7:
// SUBN Vx, Vy
regs[15] = (regs[y] < regs[x]) ? 0 : 1;
regs[15] = regs[y] < regs[x] ? 0 : 1;
regs[x] = regs[y] - regs[x];
break;

Expand Down Expand Up @@ -287,8 +287,12 @@ void Chip8::Update()
break;

case 0x1e:
// ADD I, Vx
iReg += regs[x];
{
// ADD I, Vx
auto result = iReg + regs[x];
regs[15] = result > 0xfff ? 1 : 0;
iReg = result & 0xfff;
}
break;

case 0x29:
Expand All @@ -310,15 +314,15 @@ void Chip8::Update()
{
// LD [I], Vx
for (int i = 0; i <= x; i++) ram[iReg + i] = regs[i];
iReg += x + 1;
iReg = (iReg + x + 1) & 0xfff;
}
break;

case 0x65:
{
// LD Vx, [I]
for (int i = 0; i <= x; i++) regs[i] = ram[iReg + i];
iReg += x + 1;
iReg = (iReg + x + 1) & 0xfff;
}
break;

Expand Down

0 comments on commit 50b221d

Please sign in to comment.