Running emulator tests

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
DaNES
Posts: 20
Joined: Mon May 16, 2016 7:41 am

Running emulator tests

Post by DaNES » Mon May 16, 2016 8:13 am

I've decided I'm going to try and build a NES emulator! :) It's something I've always wanted to do (just for fun/learning) but never gotten around to. I've never done anything like this at all; I am a complete noob. All of my programming experience is in fairly high-level languages like C# (which is what I'm doing this in, for now...).

I've made a quick start and implemented a few basic LDA instructions and created some tests:

http://imgur.com/EKDXmZv

These seem to work, though I don't know if I'm doing this in a good way.. Since I'm a noob, there's a danger I'll implement both my code and tests wrong, but everything will look good. I figured maybe I should try and use someones existing test suite instead.

I came across the Emulator Tests page which has a lot of links on it, including:
nestest fairly thoroughly tests CPU operation. This is the best test to start with when getting a CPU emulator working for the first time. Start execution at $C000 and compare execution with a log from Nintendulator, whose CPU works (apart from some details of the power-up state).
This sounds quite promising, but it's just a binary file. It leaves me with some questions!
  1. Is it as simple as reading the bytes from this file to replace my hard-coded bytes, or is there more to this format? (I'm guess it's not this simple, as the page says "Start execution at $C000", which my maths says is 49152 bytes in, yet the fie is only 25k?)
  2. Will this thing work at all without an already-complete set of opcode implementations?
  3. Is there any info on that log file format anywhere? Some of it looks obvious, but some of it less so!
Any pointers would be greatly appreciated :-)

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

Re: Running emulator tests

Post by tepples » Mon May 16, 2016 8:45 am

DaNES wrote:
nestest fairly thoroughly tests CPU operation. This is the best test to start with when getting a CPU emulator working for the first time. Start execution at $C000 and compare execution with a log from Nintendulator, whose CPU works (apart from some details of the power-up state).
This sounds quite promising, but it's just a binary file.
nestest.nes is a binary file in iNES format, and nestest.log is a text file.
  1. Is it as simple as reading the bytes from this file to replace my hard-coded bytes, or is there more to this format? (I'm guess it's not this simple, as the page says "Start execution at $C000", which my maths says is 49152 bytes in, yet the fie is only 25k?)
You'll eventually need to understand the iNES file format. For now, you can load 0x4000 bytes starting at offset 0x0010, and map that as ROM into both $8000-$BFFF and $C000-$FFFF of the emulated 6502's memory map. You can make an iNES parser once you start trying to actually run Concentration Room or Donkey Kong.
  1. Will this thing work at all without an already-complete set of opcode implementations?
The more opcodes you implement, the farther it'll get into the test before diverging.
  1. Is there any info on that log file format anywhere? Some of it looks obvious, but some of it less so!
For now, you only need to parse the program counter from the first 4 hex digits on each line, and make sure the sequence of PC values from the file matches the sequence of PC values from your emulator. When they diverge, your emulator did something wrong probably within the last dozen instructions. Later, you can parse A:, X:, and Y: columns to find the cause of a divergence. The CYC: and SL: columns will become useful once you start making the 6502 core's timing cycle-accurate.

DaNES
Posts: 20
Joined: Mon May 16, 2016 7:41 am

Re: Running emulator tests

Post by DaNES » Mon May 16, 2016 9:01 am

You'll eventually need to understand the iNES file format. For now, you can load 0x4000 bytes starting at offset 0x0010, and map that as ROM into both $8000-$BFFF and $C000-$FFFF of the emulated 6502's memory map.
I guess I've missed something out here... I don't have any memory mapping :roll: .. My memory is just a byte array with 0x4000 elements and my program lives in its own disconnected byte array! I guess I should've realised a program would need to read its own data and this wouldn't fly!

I'll work on fixing my memory and then see where I get.

Thanks for all the info; helps loads! :)

DaNES
Posts: 20
Joined: Mon May 16, 2016 7:41 am

Re: Running emulator tests

Post by DaNES » Mon May 16, 2016 9:52 am

Awesome; up and running now :)
Attachments
ntest.png
ntest.png (7.55 KiB) Viewed 3055 times

Post Reply