CHIP-8 Cocoa Port part 1

I’ll go through the steps to build the emulator as a Cocoa Application. These steps are correct as of OS X 10.7 Lion and XCode 4.2. I’m not doing anything exotic, and I think most of these instructions will work fine back to OS X 10.5 or even before.

I’m going to build the Cocoa application with 3 pieces.

Here are step by step instructions:

Project

  1. Open XCode and create a new project - choose Mac OS X, Application, then Cocoa Application. Click Next.

  2. Use "Chip8" (or whatever you want) for the Product name.

  3. Uncheck “Create Document-Based Application”. Click Next.

  4. Choose a location, then click "Create".

Make an NSView and edit the XIB

  1. File->New File...

  2. In the Mac OS X section, select Cocoa, then choose Objective-C class. Click Next.

  3. Name the class - I called mine “Chip8View”. Make it a subclass of NSView. Save the file.

  4. In the project window, click on the “MainMenu.xib” file.

  5. In the “Objects” area, click the “Window - Chip8” flippy triangle. (Consult the view below for a visual.)

  6. In the Catalog View, find a CustomView and drag it into the Window.

  7. Expose the Utilities pane

  8. Click the “Identity Inspector”

  9. Change the Class to Chip8View

  10. Click the Size Inspector. Change the size to Width: 640 Height:320

  11. In the windows area, drag the view around until the blue alignment lines show you that the view is centered.

  12. Adjust the Autosizing area so the view will stay pinned to the sides of the window. (You could also ajust the window’s settings so it can’t be resized.)

Chip-8 setup 1

Chip-8 setup 2

Machine object

Make a new file to put the machine code in

  1. File->New File...

  2. In the Mac OS X section, select Cocoa, then choose Objective-C class. Click Next.

  3. Name the class - I called mine “Chip8Machine”. Make it a subclass of NSObject.

  4. Save the new class.

Add the OpenGL Framework

Since the Cocoa Port will use OpenGL for the display, we have to add the OpenGL framework.

  1. Click the Chip8 project

  2. Choose the Chip 8 target

  3. Click on Build Phases

  4. Expand the Link Binary With Libraries section

  5. Click on the + and choose OpenGL.framework from the list

Chip-8 setup 3

Other files

I'm going to add a couple of CHIP-8 programs into the project. You can get these from several places on the internet including http://chip8.com/. These seem to be public domain so I'm going to include them in the download. (Please contact me if you know differently.)

I'll add Fishie, CHIP-8 Picture, and Maze. Simply drag them into the "Supporting Files" folder in your project. XCode will know these are resources and will put them in your app's bundle. You shouldn't have to do anything to the project settings to make that happen.

Also add in your chip8emu.c and .h files. (If you haven't made a .h file yet, create it now. You'll want to move the Chip8State structure definition there, as well as define the APIs.) I also made a .c and .h file for my font definition, although you could put that in the emulator's .c file.

← Prev: chip-8-sprites   Next: chip-8-port-pt-2---machine-object →


Post questions or comments on Twitter @realemulator101, or if you find issues in the code, file them on the github repository.