Coder Social home page Coder Social logo

nes-bootstrap's Introduction

NES Bootstrap logo skeleton

NES Programming Bootstrap Project

Everything to start coding NES games with C

This is a "batteries included" bootstrap project so you can start coding NES in C. Just read the README and start hacking!

Getting started

You need to install CC65 compiler to your machine. This compiler is used to compile the C code into NES game.

After you have CC65 installed, just run:

./compile

This will compile all the source files into game.nes file that you can open in your favorite emulator.

Developing

This project has quite handy development tools that make developing NES games a lot easier:

  • Automatic building via Nodemon file watcher
  • JavaScript-based JSNES emulator that runs in browser

Installing developer tools

You need Node.js installed, because some developer tools (like file watching, and the web server) are running on top of Node. To install the dev tools, just run:

npm install

This will download and install all needed development tools for this project.

Running developer tools

To run the developer tools, just run:

npm run start

This will start the file watcher, web server (that serves the JSNES-based emulator) and compiles the project automatically.

Features

Using this project you will be able to:

  • Start developing NES games with (close to) zero knowledge of NES
  • Have working code for moving sprites, drawing backgrounds and handling user input from the first minute
  • See updates in seconds via the browser-based emulator
  • Use words instead of hex-codes (NO magic numbers!)
  • Converts .png files automatically to .chr sprites via img2chr

This project has been constructed from different how-to's and sample codes.

The "heart" of the project is file called nes.h, which is originally converted from the CC65 project's nes.inc assembly file to C, but it has been filled and modified to include all necessary magic number definitions from the NES architecture.

Nice helpers and globals

When you start crafting your own game, just open main.c and start hacking. There are a few convenience functions/macros/variables available for you when you start hacking more:

Sprites

Type: Sprite[]
Import from: nes/sprite.h

This is a global array of Sprite structs that holds the information of all 64 sprites you can have at your screen at the same time.

Each sprite can be modified at any point (even outside vblank), and they are copied to Picture Processing Unit automatically once per frame.

Example:

Sprites[0].xPos = 0x80; // Moves sprite in index 0 horizontally to center

Input

Type: { struct ControllerInput player1, struct ControllerInput player2 }
Import from: nes/controller.c

This reads input from the controllers automatically. You can check the struct for if the player's controller was pressed during that frame.

Example:

if (Input.player1.A) {
  jump();
}

SET_16BIT_VALUE_TO_POINTER ( pointer, value )

Type: macro
Import from: nes.h

With this helper macro you can set one 16-bit value to a register that only accepts 8-bit values (like Picture Processing Unit Address).

Example:

SET_16BIT_VALUE_TO_POINTER(PPU_ADDR, 0x1234)

/**
 * Outputs:
 *  lda     #$12
 *  sta     $4016
 *  lda     #$34
 *  sta     $4016
 */

SET_PPU_SCROLL ( x, y )

Type: macro
Import from: nes.h

Sets Picture Processing Unit's scroll in one function.

Example:

SET_PPU_SCROLL(0,0)

/**
 * Outputs:
 *  lda     #$00
 *  sta     $2006
 *  sta     $2006
 *
 * (omits the unnecessary extra LDA)
 */

PALETTE_COLOR_ [color]

Type: constant
Import from: nes.h

All available colors of the standard palette are available as constants.

Example:

// Sets universal background to black
SET_PPU_ADDR_VALUE(PPU_ADDR_PALETTE_UNIVERSAL_BACKGROUND_COLOR, PALETTE_COLOR_BLACK);

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

This project was initially created for Global Game Jam 2018. It might not be updated a lot after the jam is over, but I hope some others will also find it useful in the future!

Licensing

The code in this project is licensed under MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.