NickMass.com

I am Amazing

I have been working away on my emulator quite a bit lately and have recently made quite a break through. First off I rewrote the PPU completely, it is now probably a bit faster, the code is much much much better organized, and perhaps most importantly it now provides loopy based scrolling which is far more accurate. So now any game that doesn't work is pretty much down to mapper errors / omissions or it requires extremely precise timing (Battletoads), which is just plain awesome. I found and fixed a huge stupid insane typo in my APU code that has been in place since its inception which was completely breaking the APU in 70% of games. Though far from perfect the APU now produces recognizable audio in the majority of games. The pulse sweep units are doing something wrong and just don't sound quite right, the triangle channel does stupid things which I don't understand, and the DMC channel tends to introduce a fair bit of static, but it's good enough for me. I finally added the ability to toggle between PAL and NTSC emulation though my focus will remain on NTSC accuracy.


Adventure Island 3 first world play through


I put a copy of the latest binaries up here if you want to try it out. I'm not really sure what I will be working on next, I would like to add the VRC mappers which would add support for ~20 reasonably high quality games and it would be quite easy. I also of course want to improve the APU quality but I don't really know how to fix it right now and it would mostly be me just changing random parameters and then testing if it is any better. I am tempted to do a cycle accurate PPU but it would be quite finicky and not really add support for many new games. THAT'S ALL FOLKS.

Edit: Whaoaoaooaoaoaoao, so I was just playing around updating my Silverlight emulator to the newest version of my NESCore and I decided to give adding audio a try and somehow... I managed to actually do it. It may have some audio artifacts because I'm doing some very sloppy format conversions to get it playing but it seems to be working pretty freaken good. I have to run it on about a 50ms delay which isn't terrible but also isn't very good. You can scroll down the page to whichever post I made to unveil the damn thing if you want to try it out. I of course take no responsibility if it completely crashes your browser or blows your ear drums out.

Beep Beep Bloop Bloop Beep

I spent the last couple of days pounding out an APU for my glorious Emu-o-Tron and now have something worth posting about. I made use of XAudio2 through Slimdx for the output and that was all pretty straightforward. However actually generating the sound data was intense especially with my limited understanding of how sound works with all its wave lengths and frequencies and mixing channels, but after a lot of trial and error I got some excellent results

Flash Player


Mega Man III Intro

There are still a bunch of bugs in the sound generation channels will sometimes not mute themselves at the right time or their volume or frequency will be completely wrong, but I've noticed almost the entire Mega Man series is emulated perfectly. I also need to figure out how to filter out extremely high pitch notes that shatter my ear drums in a few tracks. Savestates don't currently keep track of the APUs state but I will add that once I have the APU set in stone. Also I fully intend to eventually allow for the playback of .nsf files, which doesn't look TOO hard. And finally to help me keep track of revisions I have started keep an up to date repo for my emu on my Google Code page, so if you have some desire to try out my latest changes you can download it there.

SlimDX is my Mistress

When I first started working on my NES emulator I had set my target at being able to emulate Super Mario Bros. and now I can happily say my emulator can do just that. Running SMB is pretty much glitch free (and audio free, but I'm okay with that) at this point and can be played start to finish without any issues, so I am officially tickled pink. It can also play quite a few other big name titles; in fact I would estimate that around 80% of the games it has the mapper for are playable.

Video Embed

A few games running in Emu-o-Tron

I added the ability to "rewind" games using save states which is really fun and a nifty looking effect and I'm now dependant on it to progress in games I'm testing, it can eat up quite a bit of RAM depending on how long of a rewind buffer you want and how smooth you want the animation to be but I think it is worth it. There are now quite a few new frontend features, it supports Xbox 360 Controllers thanks to GLORIOUS SlimDX, it uses the 7zip library to allow it to play ROMs that are archived, you can finally rebind keys, and it supports using Scale2x and Scale3x display modes which it actually manages to handle while still maintaining 60FPS.


Super Mario Bros. in Scale2x mode

I'm not quite sure what to work on next, I could do audio but I am really scared that it will completely destroy my FPS. I could also add some more mappers like MMC3 which is used by a lot of the best NES games like Super Mario Bros. 3 and Kirby's Adventure but I have my doubts that games that complex will even be able to boot. I also need to massively improve the timing of the CPU which will be an absolute snore fest and take aggggggesss.

Emu All Night Long

After going almost two months without touching my Emulator in the slightest I for some reason decided to pick it up again, and ended up making a ton of changes. I switched from using SdlDotNet to the DirectX framework SlimDx which is just far better suited for the type of things I'm doing. In the process of switching graphics libraries I changed my emulator from being frame based to being scanline based which allows me to do split-screen horizontal scrolling, which almost every game out there uses, so that gave me a massive compatibility boost. Everything now runs at a much higher framerate now so it is really no longer a concern though if I were to add audio support it would probably be slow as ass again. I added the ability to use game genie codes just for fun and it is working pretty well. I did not touch my mappers since I last worked on it so right now it can only run mapper 0, 2, and 3 games, I coded support for mapper 1 but there is something really wrong with it and over half of the mapper 1 games won't even boot. The main reason I'm making this post is to show off what I just whipped up today in about an hour or two of boredom. I decided to give porting my Emu to Silverlight a go and it actually worked really well once I got my head around what Silverlight will and will not let me do, I've embedded it below it's framerate may be messed up and it could even crash but it's still pretty nifty.

Get Microsoft Silverlight

Controls: Q = Change rom, A = Select, S = Start, A = Z, X = B, Up = Up, Down = Down, etc…

I want to try adding the ability for it to run roms straight from my server but didn't feel like doing that right away. Also due to the way I re-did the graphics of the Emulator updating this Silverlight version to match the desktops emulation accuracy is as simple as copying and pasting one file, so I will try to keep it up to date.

Edit
Quickly updated it today to load roms straight from the net, so no need to download any roms to test it.

Strange Attractors

Yesterday I decided to make a fun little program to generate Strange Attractors which are wacky fractal-like images which I'm sure have some complex mathematical explanation behind them but I just think they look pretty. Generating them was extremely trivial I all there is to it is the take x and y cords, perform a simple math operation on them, and draw a pixel at the result, then repeat that a few million times. I chose to use the Peter de Jong formula for generation attractors created with it tend to look really cool and varied and the formula is trivial so less work for me then.

Peter de Jong formula
Peter de Jong formula

It can take quite some time to generate high quality attractors so I have been just dumping out really low quality low resolution images until I find one that may look nifty and start it going at 36megapixels. It takes around 30 minutes for my craptop to dump one out but they end up looking sooo neat. Once generated my program applies a gradient map to it based on the brightness of each pixel, the map is just something I whipped up in a couple minutes in Photoshop to try and get the most detail showing though while keeping it looking good. Also I have made a couple animated ones by generating it then changing one variable by like 1/100 and generating again then stringing them together, it does create a neat effect but there are noticeable flickers and it will dim and brighten so it does not work perfectly.

A Strange Attractor
One of my Strange Attractors

In other news I was able to approximately double my NES emulators FPS, through some crazy window hyjinks and hacks. I can now run it at a respectable resolution and have it still be playable which is nice.

Emu-o-Tron

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".

Video Embed

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!

Srs Business

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.

Edit
I found the silly mistake I was making that broke backgrounds and sprite colors and fixed it up.


OMG so amazing.

6502 XXX-TREME

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.

Mass6502
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.