Hey everyone!
I'm new here, and as many of you, I'm trying to create a NES emulator to learn about its internals. I have implemented all the official instructions and I'll start reading to start the PPU, but first I wanted to test my CPU with `nestest`.
I've added logs in my `.step(...)` method to print something similar to what's expected (http://www.qmtpro.com/~nes/misc/nestest.log). Comparing with meld the output of the first 100 steps, I find some differences:
1)
In nestest, NOP is taking 3 cycles, but http://www.obelisk.me.uk/6502/reference.html#NOP says that NOP uses 2 cycles.
2)
The other problem is here... after a PLA instruction, nestest seems to be setting the bit 4 of the flags register. I thought that bit 4 and 5 were not used by emulators.
Also, there are some things I don't understand yet:
- Why is the cycle counter starting at 7? (instead of 0)
- Why is SP starting in $FD (instead of $FF)?
- How does the "extra cycle if page crossed" behavior works? If I have a `LDA $2040,X`, what would it mean that $2040+X and $2040 are in different "pages"?
- Where can I read about interrupt vectors? I cannot find clear documentation. I think that I should initialize my program counter with the RESET interrupt handler (at 0xFFCC), but after I read the two bytes of 0xFFCC/D and set that as PC, I don't find any valid instruction there. Should I treat this address in my dummy-mapper (mapper 0) as a sentinel value to point to the start of the PRG-ROM (0x8000)?
I'd appreciate some help on this. Thanks for reading!!
I'm new here, and as many of you, I'm trying to create a NES emulator to learn about its internals. I have implemented all the official instructions and I'll start reading to start the PPU, but first I wanted to test my CPU with `nestest`.
I've added logs in my `.step(...)` method to print something similar to what's expected (http://www.qmtpro.com/~nes/misc/nestest.log). Comparing with meld the output of the first 100 steps, I find some differences:
1)
In nestest, NOP is taking 3 cycles, but http://www.obelisk.me.uk/6502/reference.html#NOP says that NOP uses 2 cycles.
2)
The other problem is here... after a PLA instruction, nestest seems to be setting the bit 4 of the flags register. I thought that bit 4 and 5 were not used by emulators.
Also, there are some things I don't understand yet:
- Why is the cycle counter starting at 7? (instead of 0)
- Why is SP starting in $FD (instead of $FF)?
- How does the "extra cycle if page crossed" behavior works? If I have a `LDA $2040,X`, what would it mean that $2040+X and $2040 are in different "pages"?
- Where can I read about interrupt vectors? I cannot find clear documentation. I think that I should initialize my program counter with the RESET interrupt handler (at 0xFFCC), but after I read the two bytes of 0xFFCC/D and set that as PC, I don't find any valid instruction there. Should I treat this address in my dummy-mapper (mapper 0) as a sentinel value to point to the start of the PRG-ROM (0x8000)?
I'd appreciate some help on this. Thanks for reading!!