WeAreRust / Nes

NES Emulator
MIT License
0 stars 1 forks source link

Init program counter to correct value #28

Closed tobyjsullivan closed 6 years ago

tobyjsullivan commented 6 years ago

We're currently initialising the PC to 0x0C00 (possibly correct at power on). This is an address in RAM which is empty so we try to execute instruction 0x00. The following defines what is probably the correct behaviour (possibly due to some CPU-internal process following power on).

As per: http://forum.6502.org/viewtopic.php?t=1708

That is a good question. On reset, the processor will read address $FFFC and $FFFD (called the reset vector) and load the program counter (PC) with their content.

For example, if $FFFC = $00 and $FFFD = $10, then the PC will get loaded with $1000 and execution will start there. However, most 6502 systems contain ROM in the upper address region, say $E000-$FFFF so it's likely that the reset vector will point to a location there.

More technical: https://www.pagetable.com/?p=410