6502 Instruction Timing Tests

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

6502 Instruction Timing Tests

Post by blargg »

This iNES file tests 6502 instruction timing for all documented instructions except branches, both with and without a page crossing. It also tests some of the undocumented NOP instructions, but no others. If it finds a problem, it prints the opcode and the number of clocks it timed along with the correct timing. It's a bit complex so post if you encounter any odd problems. No source code yet.

cpu_timing_test.zip
User avatar
Quietust
Posts: 1786
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Post by Quietust »

Just how long does this take to run? I get the text "6502 TIMING TEST (12 SECONDS)" for a split second followed by a solid black screen for about 12 seconds, then the screen flashes white and turns blue-violet (and then flashes white every so often).
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

I'm not sure what's happening on your end. I made a few changes to the text console initialization in the version below, but I'm not seeing what could be happening. What kind of hardware are you running it on?

cpu_timing_test2.nes
mattmatteh
Posts: 345
Joined: Fri Jul 29, 2005 3:40 pm
Location: near chicago

Post by mattmatteh »

first run i got fail op :$f8
then uncommented flag_d = 1;
then i got passed

i could search the forums if the search worked, how does the nes handle the d flag ?

both test (cpu_timing_test.nes and cpu_timing_test2.nes) ran the same except the second one removes '6502 timing test (12 seconds).

matt
mattmatteh
Posts: 345
Joined: Fri Jul 29, 2005 3:40 pm
Location: near chicago

Post by mattmatteh »

i just tested nestest and nestress again.

with my d flag code commented out i get:

nestest: fail code 13 flag test
nestress: cpu all ok

with my d flag code enabled i get:

nestest: all ok
nestress: cpu sbc error in d-flag

i am stumped

matt
User avatar
Quietust
Posts: 1786
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Post by Quietust »

Evidently, that ROM does something screwy that my emulator doesn't like; exactly what is going on, I have no idea. Naturally, it works fine on my CopyNES's RAM cart.

If anybody's interested, a partial CPU log can be found at http://qmt.ath.cx/~nes/cputiming.zip
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
mattmatteh
Posts: 345
Joined: Fri Jul 29, 2005 3:40 pm
Location: near chicago

Post by mattmatteh »

i tried to unzip your file Quietust and it failed:
skipping: cpu_timing_test2-1.20060915_005436.debug need PK compat. v4.6 (can do v2.1)
how are you zipping that ?
matt
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Here's the (somewhat unpolished) main source, in case it helps: cpu_timing_test.asm The main obscure thing I'm doing is filling the stack with the value $02 to allow thousands of repeated RTS and RTI in those tests, without having to keep refilling the stack. The test loop is copied to $200-$210 or so. RTS should return to $203, and RTI to $202 (the loops are adjusted accordingly). This will require proper stack wrap-around, for one.

mattmatteh, not sure why your emulator is failing. The SED instruction should add two clocks to execution time and set the D flag. The D flag has no effect other than it being remembered; the NES 6502 does not have a decimal mode. I can't imagine why not setting that flag would affect anything timing related. I've found Nestress to be useless as a test since it reports errors for some things when they are working correctly. I recommend Kevtris' NESTEST for a thorough CPU test.
mattmatteh
Posts: 345
Joined: Fri Jul 29, 2005 3:40 pm
Location: near chicago

Post by mattmatteh »

i just noticed that your first version gives failed op f8 unknown error, and the second gives unknown error f8.

i looked at your source and if i read that right, there are 4 locations that jump to error. is that the code where it would cause fail ? perhaps you could separate those errors ?

thanks

matt
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

mattmatteh, try this and post the 16-bit hex value it prints at the end of the unknown error report:

cpu_timing_test3.asm
mattmatteh
Posts: 345
Joined: Fri Jul 29, 2005 3:40 pm
Location: near chicago

Post by mattmatteh »

blargg, $0456

thanks
matt

(g'night)
CaH4e3
Posts: 72
Joined: Thu Oct 13, 2005 10:39 am

Post by CaH4e3 »

Fixed $E2 timing, test is passed now. :)
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

mattmatteh, looks like a CPU error that NESTEST isn't catching. The timing for $F8 is correct, but it's failing in the comparison routine that has a bunch of SBCs in it. Hmmm, could it be that you're supporting 6502's decimal mode?!? The NES does not have that mode; it ignores the D flag. That would explain why it worked when you disabled the flag_d = 1 code! Sounds like your problem. Argh, I guess NESTEST isn't bulletproof after all. :)
User avatar
Quietust
Posts: 1786
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Post by Quietust »

mattmatteh wrote:i tried to unzip your file Quietust and it failed:
skipping: cpu_timing_test2-1.20060915_005436.debug need PK compat. v4.6 (can do v2.1)
how are you zipping that ?
matt
The file is BZIP2-compressed - 7-ZIP should be able to extract it properly, and I'd be surprised if WinRAR or WinZip were unable to do the same.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
Muchaserres
Posts: 96
Joined: Sat Nov 13, 2004 6:25 am

Post by Muchaserres »

I get "fail op :$04 UNKNOWN ERROR". May it be that I'm not implementing 2-byte NOPs? Which are those ops? Are those "official" (I mean, are those in the real thing)?

Thx.
Post Reply