Nick Massey on Tuesday, October 20, 2009
It has been another couple of days and I've made a wee bit of progress on my emulator. It now allows for player 1 controller input which is nice and meant I could actually start playing some games, I could add support for a 2nd player in no time I just didn't feel like bothering with it. Also added turbo buttons for A and B just for funzies took about 2 lines of code and they are neat to play with. I finally got around to supporting hardware scroll which opened up a TON of games, it isn't a perfect implementation but it seems to get the job done. You can pause and soft reset games now, which I really should have added much earlier as it can really help when debugging issues in games. You can now save and load game states which are a pretty key feature of any emulator. And finally there have been all around performance increases though it still isn't what I would call "fast".
Little demo of Emu-o-Tron in action.
With all that done I think I am pretty much finished working on this project, I may come back to it time to time to add minor features (support for UNROM and CNROM games would be lovely) but I won't be spending days in a row working on it. It was an extremely fun project and very educational even though I didn't work on it for very long. I know it sucks that it won't run 80% of NES games but that is just a flaw with my entire approach to the project and I was aware of this limitation from the get go, I am rendering everything frame by frame to get a massive performance increase at the cost of killing game compatibility. I just really did not want to spend weeks pouring over the code of a spare time project looking for speed tweaks. Still I do not regret my choice to make and emulator and would recommend it as something every programmer should make one day. NickMass OUT!
Nick Massey on Friday, October 16, 2009
A couple of days ago me and Capt. Jordo decided to go back to maintaining separate blogs, so I'm back to blogging at good old NickMass.com, and Jordan is at jordanranson.com. Separating the blogs required that I make a new design which was a horribly HORRIBLY painful process but it's over now. I used SIFR for the first time to get the fancy fonts working in the headers, it?s a handy thing to have but an absolute pain in the ass to setup, I will be very happy when everyone can just use CSS fonts without worrying about them not being displayed in some browsers. I also disabled a lot of features that the previous blog had because they were just a pain to deal with, no more leaving comments, logging in, or any of that other junk. All the old posts are still in the database (viewable here) I just moved them off the front page to keep things tidy. My torrent site is still up and running despite the blog stealing its URL, you can find it over here.
I have continued working on my NES emulator, though I haven't been putting as much time in, and have made some progress. All the code was reorganized and is a lot more condensed and easier to read now, memory mirroring is functioning now along with being able to label certain memory addresses as read only. I also worked on the PPU so I can boot legitimate ROMs now without them getting stuck polling the PPU addresses over and over. I also wrote a bit of the SDL renderer to try and get some video output going and I was moderately successful. I can draw all the tiles and all the sprites but the backgrounds and palettes are royally messed, though I didn't spend much time trying to figure out what was going wrong.
Video of awesome sprite action.
Performance is looking to be an issue I'm only getting around 50 - 55 FPS (NTSC is 60FPS) when just straight up drawing the sprites and background without worrying about the palette or attributes, though the code is far from optimized and I am using the CPU to render everything instead of OpenGL. I have been using a game called Balloon Fight as my test ROM, it is apparently one of the easiest mainstream games to emulate properly, I had never heard of it before and it seems like a joust clone. I'm pretty tickled pink with how this whole project is turning out I anticipated myself giving up on it long before now; hopefully I'll finish it someday.
I found the silly mistake I was making that broke backgrounds and sprite colors and fixed it up.
OMG so amazing.
Nick Massey on Wednesday, October 14, 2009
Since the dawn of time I have been interested in making an emulator for some sort of old console, and this week I finally started giving it a shot. The system I picked to work with was the NES, I figured it would be one of the more documented systems with low performance requirements which is pretty important because I hate optimizing my code and am using C# which can be a bit slow compared to lower level languages. Yesterday I finished the first part of this grand project a 6502 CPU emulator. The 6502 was a widely used processor back in the day used in the C64, Atari 2600, Apple I & Apple II, and of course the NES. This meant there was pleennnty of documentation for me to refer to although many systems had slightly different implementations of the CPU with some differing features their docs were still extremely useful. There are around 55 different operations the CPU can perform and like a gazillion addressing types for each one do making this CPU involved a ton of typing though it was quite straight forward for the most part. Actually coding the majority of the opcodes didn't take too long but debugging them to behave with all the subtle nuances and finding out what some obscure NES opcodes actually did seemed to take years. To assist with debugging I found a NES ROM called nestest.nes and a log from a fully function emulator running nestest.nes to compare against. Nestest.nes is an excellent tool that doesn't require video output to work, it runs through most operations the NES needs to support and the edge cases for using them to make sure your CPU can handle everything. But now my 6502 emulator passes nestest.nes so I consider this portion of my grand project pretty much complete, though the CPU cycle counting I'm doing needs a little fine tuning and I wouldn't mind polishing up some code.
My emulator's log in all its glory
It is pretty hard for me to measure the mhz of my emulator at the moment but I think I am crushing the 1.79mhz the NES required. Next I plan to implement the NES PPU so I can get some sort of graphics output from this beast though I am dreading working on it as it seems far more intricate then the CPU. After that I just need controller support and some support for loading the large variety of differing ROM types and hopefully I'll be able to start testing it against actual games instead of test ROMs.