From afb222f18f8bf30c49e79706c70831b49d2422c7 Mon Sep 17 00:00:00 2001 From: Brad Grantham Date: Sun, 27 Dec 2020 20:50:32 -0800 Subject: [PATCH] initialize CPU correctly, never set bit 4 or 5 of P --- cpu6502.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cpu6502.h b/cpu6502.h index 9e09691..680c641 100644 --- a/cpu6502.h +++ b/cpu6502.h @@ -147,15 +147,15 @@ struct CPU6502 a(0), x(0), y(0), - s(0), - p(0x20), + s(0xFF), + p(I), exception(RESET) { } void reset() { - s = 0xFD; + s = 0xFF; uint8_t low = bus.read(0xFFFC); uint8_t high = bus.read(0xFFFD); pc = low + high * 256; @@ -1272,7 +1272,7 @@ struct CPU6502 } case 0x28: { // PLP - p = stack_pull(); + p = stack_pull() & ~ (B2 | B); break; } @@ -1547,7 +1547,7 @@ struct CPU6502 } case 0x40: { // RTI - p = stack_pull(); + p = stack_pull() & ~ (B2 | B); uint8_t pcl = stack_pull(); uint8_t pch = stack_pull(); pc = pcl + pch * 256;