Cocoa Port pt 1 - Setting up the project

I'll go through the steps to build the emulator as a Cocoa Application. These steps are correct as of OS X 10.10 El Capitan and XCode 7.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 with common sense modifications.

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

Here are step by step instructions:

Project

  1. Open XCode choose OS X -> Application -> Cocoa Application, then click "Next"

  2. Fill in information, making sure to uncheck "Create Document-Based Application"

  3. Name your project and click Next

  4. Choose a place to save your project

Cocoa Port New Project

View

Make a NSView to draw the game screen and receive the Cocoa input events.

  1. File->New File...

  2. In the OS X section, select Source, then choose Cocoa Class. Click Next.

  3. Name the class - I called mine "InvadersView". 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 - Invaders" flippy triangle. (Consult the view below for a visual.)

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

  7. Expose the Utilities pane

  8. Click the "Identity Inspector"

  9. Change the Class to InvadersView

  10. Click the Size Inspector

  11. Change the size to Width: 224 Height:256

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

  13. Steps 13 and 14 are in the movie below. Click on the Invaders view, then click on Pin popup menu. Check the checkboxes for width and height which should already be set to 224, 256 from step 11.

  14. Finally, with the Invaders view still selected, control click from the Invaders view to the window's view and choose Center in each direction.

Cocoa Port 1

Cocoa Port 2

Machine

  1. File->New File...

  2. In the OS X section, select Source, then choose Cocoa Class. Click Next.

  3. Name the class - I called mine "SpaceInvadersMachine". Make it a subclass of NSObject.

  4. Click Next, then save the files. They should get automatically added to the project.

Other Files

I put the ROM files into the project so they get copied to the Application's bundle when it gets built.

  1. Drag the invaders.e, .f, .g, and .h files into the project, right into the Supporting Files group

  2. In the Choose options sheet, check Copy items if needed, and make sure Invaders is not checked in Add To Targets

  3. Click on the Invaders project in the project browser

  4. Click on the Invaders target

  5. Click on Build Phases

  6. Disclose Copy Bundle Resources

  7. Drag invaders.e, .f, .g, and .h into the Copy Bundle Resources area

Cocoa Port 3

This completes the setup of your project. We'll make this work in 3 stages:

  1. Machine gets CPU, timer, and framebuffer sharing functions. Platform code will display the machine's framebuffer image on a timer.

  2. Add keyboard handling to machine and platform.

  3. Play sounds from machine.

← Prev: interrupts   Next: cocoa-port-pt-2---machine-object →