From 3471e9aa3a397fd583e8fc85f3a40e6d890eb2e9 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Mon, 18 Dec 2017 09:53:18 -0800 Subject: [PATCH] Fixed PHP to only modify B flag in byte written, status reg itself is unchanged * line #71: C7E8 68 PLA * see http://visual6502.org/wiki/index.php?title=6502_BRK_and_B_bit --- 6502.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/6502.c b/6502.c index ce276d0..11282f5 100644 --- a/6502.c +++ b/6502.c @@ -322,8 +322,16 @@ static void inst_PHA() static void inst_PHP() { - SR.bits.brk = 1; // this is slightly unexpected, but it's what the real hardware does. - stack_push(SR.byte); + union StatusReg pushed_sr; + + // PHP sets the BRK flag in the byte that is pushed onto the stack, + // but doesn't affect the status register itself. this is slightly + // unexpected, but it's what the real hardware does. + // + // See http://visual6502.org/wiki/index.php?title=6502_BRK_and_B_bit + pushed_sr.byte = SR.byte; + pushed_sr.bits.brk = 1; + stack_push(pushed_sr.byte); } static void inst_PLA()