Skip to content

Commit

Permalink
Implement some Chip8 quirks
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDoom committed Dec 18, 2024
1 parent dafcff7 commit 1b1aa23
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/emulator/Cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,24 @@ void Cpu::runInstruction(const uint16_t opcode) {
case 0x0:
this->registers[x] = this->registers[y];
break;
case 0x1:
this->registers[x] |= this->registers[y];
case 0x1: {
const uint8_t vY = this->registers[y];
this->registers[0xF] = 0;
this->registers[x] |= vY;
break;
case 0x2:
this->registers[x] &= this->registers[y];
}
case 0x2: {
const uint8_t vY = this->registers[y];
this->registers[0xF] = 0;
this->registers[x] &= vY;
break;
case 0x3:
this->registers[x] ^= this->registers[y];
}
case 0x3: {
const uint8_t vY = this->registers[y];
this->registers[0xF] = 0;
this->registers[x] ^= vY;
break;
}
case 0x4: {
const uint16_t sum = this->registers[x] + this->registers[y];

Expand All @@ -162,6 +171,7 @@ void Cpu::runInstruction(const uint16_t opcode) {
break;
}
case 0x6: {
this->registers[x] = this->registers[y]; // TODO: Optional quirk? https://tobiasvl.github.io/blog/write-a-chip-8-emulator/#8xy6-and-8xye-shift
const uint8_t value = (this->registers[x] & 0x1);
this->registers[x] >>= 1;
this->registers[0xF] = value;
Expand All @@ -179,6 +189,7 @@ void Cpu::runInstruction(const uint16_t opcode) {

break;
case 0xE: {
this->registers[x] = this->registers[y];
const uint8_t value = (this->registers[x] & 0x80) >> 7;
this->registers[x] <<= 1;
this->registers[0xF] = value;
Expand Down Expand Up @@ -281,16 +292,20 @@ void Cpu::runInstruction(const uint16_t opcode) {
this->memory[this->address] = value % 10;
break;
}
case 0x55:
case 0x55: {
for (uint8_t registerIndex = 0; registerIndex <= x; ++registerIndex) {
this->memory[this->address + registerIndex] = this->registers[registerIndex];
}
this->address += x + 1;
break;
case 0x65:
}
case 0x65: {
for (uint8_t registerIndex = 0; registerIndex <= x; ++registerIndex) {
this->registers[registerIndex] = this->memory[this->address + registerIndex];
}
this->address += x + 1;
break;
}
default:
break;
}
Expand Down

0 comments on commit 1b1aa23

Please sign in to comment.