Skip to content

Commit

Permalink
implement some quirks...
Browse files Browse the repository at this point in the history
  • Loading branch information
breqdev committed Nov 17, 2023
1 parent 3669596 commit 2369b68
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/cpu/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl Execute for Mos6502 {
// ASL
let (address, cycles) = self.fetch_operand_address(opcode);
let value = self.read(address);
self.write(address, value); // QUIRK

Check warning on line 136 in src/cpu/execute.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/execute.rs#L136

Added line #L136 was not covered by tests
let result = value << 1;

self.registers.sr.write(flags::CARRY, value & 0x80 != 0);
Expand All @@ -154,6 +155,7 @@ impl Execute for Mos6502 {
// LSR
let (address, cycles) = self.fetch_operand_address(opcode);
let value = self.read(address);
self.write(address, value); // QUIRK

Check warning on line 158 in src/cpu/execute.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/execute.rs#L158

Added line #L158 was not covered by tests
let result = value >> 1;

self.registers.sr.write(flags::CARRY, value & 0x01 != 0);
Expand All @@ -176,6 +178,7 @@ impl Execute for Mos6502 {
// ROL
let (address, cycles) = self.fetch_operand_address(opcode);
let value = self.read(address);
self.write(address, value); // QUIRK

Check warning on line 181 in src/cpu/execute.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/execute.rs#L181

Added line #L181 was not covered by tests
let result = (value << 1) | (self.registers.sr.read(flags::CARRY) as u8);

self.registers.sr.write(flags::CARRY, value & 0x80 != 0);
Expand All @@ -198,6 +201,7 @@ impl Execute for Mos6502 {
// ROR
let (address, cycles) = self.fetch_operand_address(opcode);
let value = self.read(address);
self.write(address, value); // QUIRK

Check warning on line 204 in src/cpu/execute.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/execute.rs#L204

Added line #L204 was not covered by tests
let result = value >> 1 | (self.registers.sr.read(flags::CARRY) as u8) << 7;

self.registers.sr.write(flags::CARRY, value & 0x01 != 0);
Expand Down Expand Up @@ -341,7 +345,16 @@ impl Execute for Mos6502 {
0x4C => (self.fetch_word(), 3),
0x6C => {
let indirect = self.fetch_word();
(self.read_word(indirect), 5)

// QUIRK
if indirect & 0xFF == 0xFF {
let lo = self.read(indirect);
let hi = self.read(indirect & 0xFF00);
((hi as u16) << 8 | lo as u16, 5)

Check warning on line 353 in src/cpu/execute.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/execute.rs#L348-L353

Added lines #L348 - L353 were not covered by tests
} else {
// normal behavior
(self.read_word(indirect), 5)

Check warning on line 356 in src/cpu/execute.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/execute.rs#L356

Added line #L356 was not covered by tests
}
}
_ => unreachable!(),
};
Expand Down
24 changes: 20 additions & 4 deletions src/cpu/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,31 @@ impl Fetch for Mos6502 {
0x1C | 0x1D => {
// Absolute,X
let base = self.fetch_word();
(base + self.registers.x as u16, 4)
let indexed = base + self.registers.x as u16;

// QUIRK
if base & 0xFF00 != indexed & 0xFF00 {
self.read(base & 0xFF00 | indexed & 0x00FF);
(indexed, 5)

Check warning on line 96 in src/cpu/fetch.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/fetch.rs#L91-L96

Added lines #L91 - L96 were not covered by tests
} else {
(indexed, 4)

Check warning on line 98 in src/cpu/fetch.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/fetch.rs#L98

Added line #L98 was not covered by tests
}
}
0x1E | 0x1F => {
// Absolute,X or Absolute,Y
let base = self.fetch_word();
if opcode & 0xC0 == 0x80 {
(base + self.registers.y as u16, 4)
let indexed = if opcode & 0xC0 == 0x80 {
base + self.registers.y as u16

Check warning on line 105 in src/cpu/fetch.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/fetch.rs#L104-L105

Added lines #L104 - L105 were not covered by tests
} else {
base + self.registers.x as u16

Check warning on line 107 in src/cpu/fetch.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/fetch.rs#L107

Added line #L107 was not covered by tests
};

// QUIRK
if base & 0xFF00 != indexed & 0xFF00 {
self.read(base & 0xFF00 | indexed & 0x00FF);
(indexed, 5)

Check warning on line 113 in src/cpu/fetch.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/fetch.rs#L111-L113

Added lines #L111 - L113 were not covered by tests
} else {
(base + self.registers.x as u16, 4)
(indexed, 4)

Check warning on line 115 in src/cpu/fetch.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/fetch.rs#L115

Added line #L115 was not covered by tests
}
}
_ => unreachable!(),
Expand Down

0 comments on commit 2369b68

Please sign in to comment.