NDS Programming (Part 2)
1. Hardware Introduction
First, here’s a widely circulated NDS hardware spec list:
Console Name: Nintendo DS [NTR-001(JPN)]
Dimensions & Weight (closed):
- Length: 148.7mm, Width: 84.7mm, Thickness: 28.9mm
- Weight: approx. 275g (including battery, touch pen)
Display: Dual LCD screens for simultaneous display and gameplay. The bottom screen can be operated with touch pen or fingers.
- Top Screen: 3-inch (diagonal) semi-transmissive TFT color LCD, backlit, 256x192 pixels, 0.24mm dot pitch, 260K colors
- Bottom Screen: 3-inch (diagonal) semi-transmissive TFT color LCD, backlit, 256x192 pixels, 0.24mm dot pitch, 260K colors, with high-strength transparent analog touch screen
Main Controls: D-pad, A/B/X/Y/L/R buttons, START/SELECT button, touch screen (pen, strap, fingers), built-in MIC
I/O Ports: DS card slot, GBA card slot, headphone/mic jack
Wireless: IEEE802.11 and Nintendo proprietary protocol, range 10-30m, supports multi-card multiplayer, built-in MIC for internet voice chat
CPU: ARM9 and ARM7 dual CPU
Sound: Built-in stereo speakers (surround effect achievable via software)
Other: Built-in real-time clock (date/time/alarm), touch screen calibration, built-in pictochat (up to 16 NDS units wireless), customizable boot mode, language support (Japanese, English, German, French, Spanish, Italian), user profiles, battery power management, sleep mode
Power: Rechargeable lithium battery, 6-10 hours continuous use, 4 hours full charge, includes AC adapter (110V)
Compatible Software: DS专用卡带, GBA专用卡带
From a programming perspective, some key points need emphasis:
1. CPU
The NDS has two CPUs: an ARM7 and an ARM9 — a heterogeneous dual-CPU setup. The manufacturers aren’t clear — probably not the commonly used Samsung 2410, 4510; Intel XScale; or Freescale Dragonball. I suspect Nintendo licensed ARM’s IP and manufactured them themselves. The ARM7 is ARM7TDMI; the ARM9 is ARM946E-S. The ARM946E-S details can be found on ARM’s website at http://www.arm.com/products/CPUs/ARM946E-S.html. Two things to note about the ARM9: First, it has no MMU, only an MPU. Second, it has enhanced DSP instruction support.
What? You don’t know what MMU and MPU are? Well, MMU stands for Memory Management Unit. You know about virtual memory on Windows — that’s the “trick” accomplished jointly by the OS and hardware. The “hardware” part is the MMU. It has two main functions: virtual-to-physical address mapping (giving each process 4GB of virtual address space) and memory protection (giving you a stable OS — you’ve seen the “illegal operation” dialog box, right? That’s MMU memory protection at work). So what’s MPU? It’s MMU without the virtual-to-physical mapping, keeping only memory protection. What does no MMU mean? For those hoping to port Windows CE, Pocket PC, Smartphone, Symbian, etc. to the NDS — think again. The hardware support isn’t there. What? You say there’s already Linux running on the NDS? Yes, there’s DSLinux, but it’s uCLinux, which is specifically designed for CPUs without MMU.
What? You don’t know what DSP is? Honestly, I’m not very familiar either. Generally, DSP enables快速 processing of multimedia data — audio, graphics, especially 3D. These are crucial for gaming.
Nintendo sure knows how to pick CPUs. Among the ARM9 series, only a few models lack MMU; almost all others have it. Nintendo deliberately chose the one without MMU — probably afraid that BT programmers would port operating systems to the NDS and use it as a PDA. (Despite the lack of MMU, some BT programmers are already thinking about this…)
What does dual CPU mean? When the NDS is working, both CPUs run programs simultaneously. Writing programs for NDS means传说中的 “parallel/concurrent programming.” If you’ve sat through lectures on this topic in school and still felt confused, the NDS is a great platform to practice on. Concurrency means the two CPUs need to coordinate and synchronize data. On the NDS, many peripherals can only be accessed by one CPU, which then passes data to the other — quite challenging.
2. Peripherals
The NDS’s peripherals主要包括:
- Output devices (two screens, speakers)
- Input devices (keyboard, touch screen, microphone)
- Interactive devices (WiFi wireless)
- Expansion slots (DS and GBA game card slots)
Compared to a PC, it’s missing quite a bit, but for a game console, these are already plenty. A few more things worth mentioning:
The NDS’s dual-screen design is unique — that’s where “DS” comes from (Dual Screen). The bottom screen is a touch screen; the top is a regular screen. Touch screens are common in embedded systems, especially phones and PDAs, but this is the first time on a dedicated game console. Many touch screen games are very creative — like Nintendogs’ petting, Resident Evil’s knife-stabbing zombies…
The NDS keyboard layout is basically the same as the SFC: up/down/left/right, A/B/X/Y, L/R, plus Select and Start. Sufficient and easy to program with.
The microphone is another major NDS innovation, giving rise to many voice games. Imagine Phoenix Wright shouting “Objection!” at the console, Bomberman shouting “Boom!” to detonate bombs, Nintendogs shouting “Jump!” to make your dog jump… This type of game is a first in history and a revolutionary innovation.
Another major innovation is WiFi (IEEE802.11, aka wireless networking). The console has a built-in wireless module. As long as there’s wireless coverage, you can play online with others or locally with nearby players. Every night, I play Bomberman with my roommate from under the covers.
For coding, these things aren’t directly important. What matters is how to control them with code — which we’ll cover later.
// TODO: Add block chart of peripheral
OK, enough废话. Let’s start writing code. Below, we’ll write the familiar Hello World on the game console.