I'm making some tests using several 6502 impl, then I took yours and manage to run the tests that I have on it. It's all on branch https://github.com/gutomaia/wedNESday/tree/torlus_6502_js
The problem that I notice must be related to the CPU status byte. Since most of the instructions that have the problem, relies on them.
Example PHP instruction:
yours, get the status inside the instruction as:
CPU6502.prototype.php = function() {
var v = this.N << 7;
v |= this.V << 6;
v |= 3 << 4;
v |= this.D << 3;
v |= this.I << 2;
v |= this.Z << 1;
v |= this.C;
this.write(this.S + 0x100, v);
this.S = (this.S - 1) & 0xFF;
this.cycles++;
}
Take a look on James Tauber (@jtauber) approach, he extrated the status function, on his code we got:
def status_as_byte(self):
return (self.carry_flag |
self.zero_flag << 1 |
self.interrupt_disable_flag << 2 |
self.decimal_mode_flag << 3 |
self.break_flag << 4 |
1 << 5 |
self.overflow_flag << 6 |
self.sign_flag << 7)
def push_byte(self, byte):
self.write_byte(self.STACK_PAGE + self.stack_pointer, byte)
self.stack_pointer = (self.stack_pointer - 1) % 0x100
def PHP(self):
self.cycles += 1
self.push_byte(self.status_as_byte())
The behavior itself, it's the same, only difference seems to be related to the status byte.
On tests on wedNESday, tests that were falling was:
def test_php(self):
self.cpu_set_register('P', 0xff)
self.cpu_pc(0x0100)
self.memory_set(0x0100, 0x08)
self.execute()
self.assertEqual(self.cpu_pull_byte(), 0xff)
BTW, if the proper config, both James Tauber's 6502 and py65 works quite fine! If I got time, I will send a PR about this!
Thanks