5 Starting somewhere

 

This chapter covers

  • NES code structure and memory configuration
  • Initializing the NES hardware
  • Loading tile and sprite shape data
  • Displaying some text on the screen
  • Displaying a bat and a ball using sprites
  • Moving the ball and bat around the screen

We are going to create a simple space shooting game throughout the rest of this book, but before we get too carried away, we should start with a simpler demo NES project that provides the basic template for making a game. This demo does all the required setup to get the console up and running, placing some text on the screen along with two objects, a ball that bounces around the screen and a bat that is moved via the game controller.

We will work our way through this sample template code step by step, explaining each section of code as we go. You can type each section of code we will cover or follow the complete sample code from the supporting download site. The files for this chapter can be downloaded from the following GIT repository: https://github.com/tony-cruise/ProgrammingGamesForTheNES/tree/main/CH05.

In this chapter, we will put together the following physical files:

  • example.cfg—NES configuration
  • example.s—Contains the 6502 source code
  • example.bat (or example.sh)—The script to compile the source code into an NES ROM
  • example.chr—The patterns to use for the characters and sprites (download the sample from the previously cited repository for this chapter)

5.1 NES cartridge code structure

5.2 NES memory configuration

5.2.1 Memory

5.2.2 Segments

5.3 Defined values

5.4 NES header

5.5 Vectors

5.6 Zero page

5.7 Sprite data

5.8 Code

5.9 Chars

5.10 RAM

5.11 IRQ interrupt

5.12 Initializing the NES hardware

5.13 NMI routine