whscullin / apple1js

An Apple 1 Emulator in Javascript
MIT License
35 stars 8 forks source link

Strange implementation of BRK and JSR #33

Closed ldm0 closed 1 year ago

ldm0 commented 1 year ago

https://www.masswerk.at/6502/6502_instruction_set.html#BRK https://www.masswerk.at/6502/6502_instruction_set.html#JSR

According to the documentation, BRK and JSR pushes PC + 2 to stack.

But:

It seems that BRK pushes PC, and JSR pushes PC + 1 to stack.

whscullin commented 1 year ago

I'm not sure what they mean by PC + 2, readBytePC() at the beginning increments the PC once more in addition to the initial increment after reading the opcode. This is in line with what is described in Table 4.1 in Jim Sather's Understanding the Apple II - and although admittedly BRK/RTI might not get exercised a whole lot, JSR/RTS simply wouldn't work any other way.

The 6502 code from sister project apple2js has been tested against the Tom Harte test suite that validates cycle and memory accuracy against a real CPU, the logic there, although re-written in Typescript, is unchanged.