Jun 29

I’m not particularly happy with the direction the iPhone is going in… so I’m taking a break from WeatherMan.

In it’s place, I’m working on a fun project that I’ve been doing on-and-off called CoCoNES. If you guessed that this is an NES emulator written using Cocoa, you deserve a banana or something. I decided not to quite go whole-hog though… my original thought was to really try and keep things strictly Cocoa, which would have meant the opcode dispatch table would have been an NSArray of NSValues containing selectors for the methods. However, from a processor time standpoint, this is a horrible, horrible idea. Pulling up an object from an NSArray is more expensive than a standard C array, then I have to get the scalar value out of the NSValue object, then send the message to that selector… yeah, you get the point.

Instead, for the actual CPU emulator, I have a nice, elegant, FAST system set up. The opcode is an 8-bit unsigned integer. So, when we read the next byte with the opcode, we plug that into an array (opcodes[read_opcode]) of pointers to functions for each opcode. One step. From a computer time standpoint, this is probably 10x cheaper than sticking with Cocoa. Do modern computers need that time for a NES emulator anymore? I don’t know. I will find out though when I get to speed control.

This is going to be a really good learning experience–I get to learn the ins and outs of NES hardware; I get to learn CoreAudio for creating the audio, and (probably) OpenGL for the video, and Grand Central Dispatch for parallelism; my plan is to have the main thread basically just sending out ticks to the other objects (CPU, PPU, any other chips) which process on their own threads, and then when they’re done wait for the preappointed time (or if that time is past, start the next tick)

In addition, I’m probably going to blow the dust off of StudioMan. That’s one project I would really like to complete, and it shouldn’t be terribly difficult provided I can find the time.

Leave a Reply

Powered by WP Hashcash

preload preload preload