BigEd wrote:
Write, or find, a short 6502 program, and make it your aim to emulate that program
That's how I wrote my emulators for a 16-bit minicomputer and a 32-bit minicomputer. Although I had some quite good documentation there were still undocumented parts (including for some instructions) so it was not entirely straight forward. I had some binary images of programs I wrote way back then which I tried to get running. So I implemented the first minor sets of instructions and worked on getting the setup of the CPU right w.r.t. to the executable image (mapping memory and loading the executable etc). Then I ran it with a disassembly trace until it found an unknown instruction and bailed out (I implemented the tracing disassembler iteratively at the same time). Add the missing instruction and retry. Had lots of fun. For the 32-bit system this was really the only way to see any progress in a reasonable timeframe, as it had more than a thousand instructions and 28 addressing modes (which I also implemented on a need-to-have basis).
So I started with small programs and got those to run, then I moved on to vendor-provided executables like program editors and compilers (I had some backup tapes which I managed to extract files from). I was pretty happy when I had the full-screen programmer's editor running! I spent a couple of vacations sitting all day in a cafeteria with documentation and computer. Could easily get into "the flow" that way. [I can see why so many authors write their books in coffee shops. There's coffee, and lunch, and quiet corners, none of your usual distractions and nobody to interrupt you.]
The good thing about this iterative approach is that the emulator actually does something from the very beginning. Along the way I implemented a debugger and a register trace feature, and improved the disassembler. This was also fun to work with: I had something fully functional which I could improve on when the emulators were still in their infancy.
Now, a 6502 is a much simpler architecture than what I worked on above so it's not directly comparable, still I would follow the same approach - and I will implement a 6502 emulator too one day, even though there are so many in existence already (unlike those I mentioned above. I'm only aware of two other efforts for the 16-bit one and as far as I know mine is the only emulator for the 32-bit one).
-Tor