Skip to content

CPU and peripherals

The DS has two processors, and they do different jobs.

ARM9 ARM7
Model ARM946E-S ARM7TDMI
Speed about 67 MHz about 33 MHz
Job the game: logic, graphics, loading the hardware around it: sound, touch, clock, Wi-Fi, power
Extras small caches, fast on-chip memory, a divider and a square-root unit 64 KB of its own memory

The ARM9 runs the game. It has no floating-point unit, so fractional numbers are done in fixed point, and dividing is slow enough that it has a separate divider the program hands numbers to. It can run two instruction sets: ARM (32-bit instructions) and Thumb (16-bit instructions), which does a little less per instruction but makes code much smaller. With 4 MB of memory, smaller code matters.

The ARM7 is the processor of the original Game Boy Advance, kept on as a helper. It drives the sound hardware, reads the touch screen and the clock, runs the wireless, and watches the power button and the lid. The two processors talk through a small message queue: the ARM9 says “play this sound”, the ARM7 does it.

In PokeLoom all game code runs on the ARM9 and is compiled as Thumb to keep it small (code and static data have a 1.5 MB budget; see Memory). The ARM7 runs the DS SDK’s ready-made program, with the Maxmod sound library. Nothing in a game’s own content runs on the ARM7.

Because the DS has no fractional hardware, PokeLoom does all its maths in one fixed-point type, Fx, on every platform. The same inputs then give the same result on the DS and on every desktop. See Determinism.

The DS has 16 sound channels. Each plays one sound at a time, at its own pitch, volume and position from left to right, and the hardware mixes them. A channel plays a sample from memory, stored as:

  • 8-bit or 16-bit samples, or
  • IMA-ADPCM, a compressed form at 4 bits a sample.

Six channels can also make square waves and two can make noise, the old way of making tones without samples. The mixed sound comes out at about 32 kHz.

Recorded music would be far too big for 4 MB. So DS games play sequenced music: a list of notes, played by the channels using short instrument samples. A whole song is a few kilobytes of notes plus its instruments.

In PokeLoom music is tracker modules (XM, IT, S3M or MOD files), made in free trackers such as OpenMPT or MilkyTracker. A module is exactly that: notes and short samples. Maxmod plays them on the DS’s channels, using the hardware’s own mixing.

The 16 channels are divided so music and effects never steal from each other:

Channels For
11 the music module (the build refuses a module that uses more)
4 sound effects and creature cries
1 a test tone

Sound has a budget of 512 KB of main memory: the playing module with its samples (at most 320 KB), the effects marked to stay loaded, and a cache for the rest. Every other effect and every cry is read from the cartridge when it is played and stays until the cache needs the room, so a game can have thousands. Long effects are stored as ADPCM.

On desktop the same module files are played by a Rust module player and mixed at the DS’s rate, 32,768 samples a second, with samples stepped through without smoothing, as the DS’s channels do. The two do not match sample for sample, but they sound alike. What a creator sets is on Music and sound.

The DS has a real-time clock with its own battery: a calendar date and a time of day that keep going when the console is off. The owner sets it in the system settings. Games read it for time-of-day light, daily events and day-of-the-week events.

Because the owner can set it, a player can also turn it back or forward. Games guard against this: one that sees the clock go backwards may hold back daily events for a while.

In PokeLoom the engine reads the platform’s clock (the DS’s real-time clock, or the computer’s) once when the game starts, then counts ticks from there, so a recorded session replays at the same hours. It looks at the platform’s clock again every so often to stay in step. The rules are in game.toml:

[time]
clock_changed = "penalty" # a clock turned back holds new days back
penalty_hours = 24
resync_minutes = 1 # how often the game looks at the platform's clock

Keys are in the game.toml reference. How the light follows the hour is on How light follows the hour.

A commercial DS cartridge holds a small save chip beside the game data: a few kilobytes to a few megabytes of memory that keeps its contents with no power. The game writes its save there.

A homebrew game on a flash cartridge has no save chip of its own. It saves as a file on the SD card instead, through the card’s file system.

In PokeLoom saves are files on the SD card (ploom-slot<N>.sav, one a slot), read and written through the platform. melonDS provides an SD card only when its DLDI setting is on, which it is not by default; the game checks at start and tells the player how to turn it on rather than failing at the first save. On desktop a save is a file in the user’s data folder, written to a temporary file and renamed so an interrupted save does not break the old one. The save is in sections with a version number. See Game systems.

A DS cartridge is read-only memory, far larger than main memory. Games keep a file system inside it: named files the game opens and reads in pieces, the way a PC reads a disk, but slower.

In PokeLoom a built game is the engine plus its pack: every map, picture, script and sound converted to the forms the engine reads. On the DS the pack is a set of files in the cartridge’s file system; on desktop, files in a folder. Either way the engine opens a file, reads the part it needs, and closes it. Nothing is loaded whole. See Building and shipping.

The DS has Wi-Fi that can join an access point or talk directly to nearby consoles. PokeLoom’s online play uses it to reach a server over the internet; in melonDS through the emulator’s own access point. See Multiplayer.