How to Program Games for a Nokia 3310
In this article
Programming games for the Nokia 3310 is a great way to learn embedded development and create simple, addictive games that run on one of the most iconic phones ever made. This guide covers the two main approaches: using the classic C/embedded route with a compatible compiler, or using an emulator like "Nokia 3310 Snake" in a web browser. By the end, you'll have a working game you can run on an emulator or, with extra hardware, on a real phone.
What You'll Need
- A computer (Windows, macOS, or Linux)
- A text editor or IDE (VS Code, Notepad++, or any plain text editor)
- For C development: a C compiler (GCC or SDCC) and the Nokia 3310 SDK (like the "Nokia 3310 SDK" from the "nokia3310" project on GitHub)
- For emulator development: a web browser and a text editor
- Optional: a real Nokia 3310 and a programmer (like a USB-to-UART adapter) to flash the game
Step-by-Step
- Choose your development path. The easiest way to start is to use an emulator that runs in your browser, such as the "Nokia 3310 Snake" emulator. This lets you write JavaScript and see results instantly. For a more authentic experience, you'll need to set up a C development environment.
- Set up the C environment (if going the C route). Install a C compiler like SDCC (Small Device C Compiler) which supports the 8051 microcontroller used in the 3310. Download the Nokia 3310 SDK (often called "nokia3310" or "Nokia 3310 SDK") from a trusted source like GitHub. Extract it to a folder, e.g.,
C:\nokia3310. - Understand the hardware. The Nokia 3310 has a 84x48 pixel monochrome LCD. The screen is controlled by a PCD8544 controller. You'll be writing to a framebuffer (a 504-byte array) and then sending it to the display.
- Create your first project. In the SDK folder, create a new file called
game.c. Include the SDK's header files, typically#include "nokia3310.h"or similar. This header provides functions likenokia_lcd_init(),nokia_lcd_clear(), andnokia_lcd_set_pixel(). - Write a simple game loop. The core of any game is a loop that updates game state and draws to the screen. For example, a simple "Snake" game would have a loop that checks for button presses, moves the snake, checks for collisions, and redraws the screen. Use the SDK's button functions like
nokia_buttons_get()to read input. - Compile the code. Use the command line to compile your C file with SDCC. For example:
sdcc -c game.cthen link with the SDK's library. The SDK typically provides a Makefile or build script. Follow the instructions in the SDK's README to produce a binary file (e.g.,game.hex). - Test on an emulator. Most SDKs include an emulator (like the "nokia3310" emulator) that can run your compiled .hex file. Run the emulator, load your game, and test it. This is the fastest way to debug without hardware.
- If using the web emulator path: Open the emulator's HTML file in a text editor. You'll find a JavaScript file (often
game.js) where you write your game logic. The emulator provides a canvas element and functions to draw pixels. Write your game loop usingrequestAnimationFrameorsetInterval. - Implement game logic. For a simple game like Snake, keep an array of snake segments, a direction variable, and a food position. In each frame, update the snake's position, check if it hits the wall or itself, and draw the snake and food on the screen.
- Add input handling. In the C SDK, use
nokia_buttons_get()to get the state of the buttons (UP, DOWN, LEFT, RIGHT, FIRE). In the web emulator, listen for keydown events for arrow keys and space. - Optimize for the hardware. The 3310's CPU is slow (about 6 MHz), so avoid heavy calculations in the game loop. Use integer math, avoid floating point, and keep the framebuffer updates efficient. The SDK provides functions like
nokia_lcd_update()to send the framebuffer to the screen. - Build and test iteratively. Compile, run, test, and fix. Use the emulator to debug. Once it works, you can optionally flash it to a real phone using a programmer.
Common Mistakes
- Forgetting to initialize the LCD. Always call
nokia_lcd_init()before drawing anything. - Not clearing the screen between frames. This causes ghosting. Use
nokia_lcd_clear()or clear the framebuffer manually. - Using floating point math. The 8051 has no floating-point unit, so floating point operations are very slow. Use integers.
- Ignoring button debouncing. In the C SDK, buttons may trigger multiple times. Use a small delay or check for state changes.
- Writing out of bounds. The screen is 84x48, so pixel coordinates must be 0-83 for x and 0-47 for y.
- Not reading the SDK documentation. Each SDK has its own API. Read the header files carefully.
Tips
- Start with a simple game. Snake, Pong, or a maze game are perfect for learning.
- Use a framebuffer. Modify the framebuffer array directly and then call
nokia_lcd_update()once per frame to reduce I/O. - Keep the game loop fixed. Use a timer to ensure consistent speed across different machines. In C, use the SDK's delay functions.
- Test on the emulator frequently. It's much faster than flashing a real phone.
- Learn the keypad layout. The 3310 has a 4-way D-pad plus a fire button. Map your game controls accordingly.
- Look at existing open-source games. The SDK often includes examples. Study them to learn best practices.
Troubleshooting
- Game doesn't compile: Check for missing includes, typos, and ensure you're using the correct compiler flags. Look at the SDK's example Makefile.
- Screen is blank: Ensure you called
nokia_lcd_init()andnokia_lcd_clear()before drawing. Also check that you're setting pixels correctly (x and y might be swapped). - Game runs too fast or too slow: Adjust the delay in your game loop. In C, use
delay_ms()or similar. In JavaScript, usesetIntervalwith a specific time. - Buttons don't respond: Verify the button mapping. In the C SDK, buttons are read via
nokia_buttons_get()which returns a bitmask. In the web emulator, check the key codes. - Game crashes: Check for array out-of-bounds access, especially in Snake. Use bounds checking in your code.
- Emulator shows "File not found": Make sure the .hex file is in the correct path and that you're using the right emulator command.
Frequently Asked Questions
Can I use modern C features like structs and pointers?
Yes, SDCC supports standard C, including structs, pointers, and arrays. Just be mindful of the limited RAM (about 1KB).
Do I need a real Nokia 3310 to test?
No. The SDK includes an emulator that runs on your PC. It's recommended to test there first. You only need a real phone if you want to flash the game to hardware.
What language is best for Nokia 3310 games?
C is the traditional choice because it's efficient and the SDK is written in C. However, if you're just learning, the web emulator with JavaScript is easier and requires no setup.
How do I add sound effects?
The Nokia 3310 has a buzzer. In the C SDK, you can use a function like nokia_buzzer_on() and nokia_buzzer_off() with delays to create beeps. In the web emulator, you can use the Web Audio API to generate tones.
Can I make a game with graphics and sprites?
Yes. You can define sprite arrays as 2D arrays of bytes and draw them pixel by pixel. The SDK may have helper functions for drawing bitmaps.
Is it possible to make a multiplayer game?
Not directly, as the 3310 has no network capabilities. You could make a pass-and-play game where players take turns on the same device.