Make the Processor Status register match a real 6502 at power-on.
When describing the CPU's reset pin, the W65C02S data sheet says: > All Registers are initialized by software except the Decimal and Interrupt > disable mode select bits of the Processor Status Register (P) are initialized > by hardware. It then has a diagram of the power-on state of the processor status register: > 7 6 5 4 3 2 1 0 > * * 1 1 0 1 * * > N V - B D I Z C > > * = software initialized Confusingly the text indicates that only the D and I flags are initialised by hardware, while the diagram indicates that the B flag is initialised too. Meanwhile, https://www.nesdev.org/wiki/CPU_power_up_state says that the power-on state of the NES CPU is $34 (exactly matching the diagram above) but https://www.nesdev.org/wiki/Status_flags#The_B_flag says that the B flag does not physically exist within P register, it's only relevant in the copy of P that gets pushed to the stack by BRK (set), PHP (set), or an interrupt signal (cleared). As a result, the most sensible power-on state for the processor status register is with the "interrupt disable" flag set and everything else cleared.
This commit is contained in:
1 parent
e210a40639
commit
b5a470d3ba
16 files changed
+40
-38
No files matched your search
@@ -44,7 +44,7 @@ public class CpuTest extends TestCase {
|
||||
assertEquals(0x0200, cpu.getProgramCounter());
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertTrue(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
@@ -205,14 +205,12 @@ public class CpuTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testGetProcessorStatus() {
|
||||
// By default, no flags are set. Remember, bit 5
|
||||
// By default, only "interrupt disable" is set. Remember, bit 5
|
||||
// is always '1'.
|
||||
assertEquals(0x20, cpu.getProcessorStatus());
|
||||
assertEquals(0x24, cpu.getProcessorStatus());
|
||||
cpu.setCarryFlag();
|
||||
assertEquals(0x21, cpu.getProcessorStatus());
|
||||
assertEquals(0x25, cpu.getProcessorStatus());
|
||||
cpu.setZeroFlag();
|
||||
assertEquals(0x23, cpu.getProcessorStatus());
|
||||
cpu.setIrqDisableFlag();
|
||||
assertEquals(0x27, cpu.getProcessorStatus());
|
||||
cpu.setDecimalModeFlag();
|
||||
assertEquals(0x2f, cpu.getProcessorStatus());
|
||||
@@ -237,13 +235,16 @@ public class CpuTest extends TestCase {
|
||||
assertEquals(0xa0, cpu.getProcessorStatus());
|
||||
cpu.clearNegativeFlag();
|
||||
assertEquals(0x20, cpu.getProcessorStatus());
|
||||
|
||||
cpu.setIrqDisableFlag();
|
||||
assertEquals(0x24, cpu.getProcessorStatus());
|
||||
}
|
||||
|
||||
public void testSetProcessorStatus() {
|
||||
// Default
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertTrue(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
@@ -669,4 +670,4 @@ public class CpuTest extends TestCase {
|
||||
cpu.step();
|
||||
assertEquals(0x3E, cpu.getAccumulator());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user