CPU cycle count

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Skypher
Posts: 2
Joined: Thu Jun 20, 2013 3:54 pm

CPU cycle count

Post by Skypher » Thu Jun 20, 2013 6:50 pm

Hi! I've started working on a NES emulator and I'm now testing the CPU.

I've run through nestest.nes and all instructions execute correctly. My problem is, the cycle count is way off right from the start.

These are the first 10 cycle counts from the start:

Code: Select all

+------+-------------+-------------+
| Mine | Nestest.nes | Instruction |
+------+-------------+-------------+
|    0 |           0 | JMP $C5F5   |
|    5 |           9 | LDX #$00    |
|    7 |          15 | STX $00     |
|   10 |          24 | STX $10     |
|   13 |          33 | STX $11     |
|   16 |          42 | JSR $C72D   |
|   22 |          42 | NOP         |
|   24 |          60 | SEC         |
|   26 |          66 | BCS $C735   |
|   28 |          72 | NOP         |
+------+-------------+-------------+
I must be missing something fundamental, since it isn't even close to matching. I only increment the cycle counter after an instruction has been carried out.
Am I supposed to count cycles somewhere else? Right now only the CPU is implemented, nothing else.

tepples
Posts: 22278
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: CPU cycle count

Post by tepples » Thu Jun 20, 2013 6:58 pm

Nintendulator, the emulator used to record the golden log you're probably looking at, counts PPU cycles. Three PPU cycles equal one CPU cycle (on NTSC and RGB systems). And why is JMP taking five cycles anyway?

Skypher
Posts: 2
Joined: Thu Jun 20, 2013 3:54 pm

Re: CPU cycle count

Post by Skypher » Thu Jun 20, 2013 7:27 pm

Ah I see, thanks.

I mixed up the addressing modes on the JMP opcodes that's why it took five instead of three cycles.
One step closer to something now!

Post Reply