mnaberez / py65

Emulate 6502-based microcomputer systems in Python
BSD 3-Clause "New" or "Revised" License
234 stars 68 forks source link

Break pushes correct pc #75

Closed sifferman closed 1 year ago

sifferman commented 1 year ago

Break used to grab the PC 1 higher than expected. However, the PC was already incremented (as denoted by the comment.)

mnaberez commented 1 year ago

It looks like the original code pushes PC+2:

https://github.com/mnaberez/py65/blob/b710c742acf37030c8d99d16b931cb3673372566/py65/devices/mpu6502.py#L528-L532

According to the links below, PC+2 is correct:

http://www.6502.org/tutorials/6502opcodes.html#BRK

BRK causes a non-maskable interrupt and increments the program counter by one. Therefore an RTI will go to the address of the BRK +2 so that BRK may be used to replace a two-byte instruction for debugging and the subsequent RTI will be correct.

http://forum.6502.org/viewtopic.php?t=1917#p15821

BRK is a two byte instruction in the sense that when the PC is pushed it is double-incremented.

sifferman commented 1 year ago

I see! I misinterpreted brk's functionality. Thanks for the help