Repository navigation
DS Hardware
Things about the DS's video, 3D, memory and slot hardware found while making games run in Maelle. Everything here is also true of a DSi running DS software, unless noted. See Hardware notes for what Measured, Software and Unverified mean.
-
The DS samples at pixel corners, not centers. A renderer drawing with a GPU has to move vertices by just under
half a pixel to pick the same pixels on edges. Moving them by exactly 1/64 of a pixel took in pixels outside long,
shallow edges. 1/256 is safe up to edges 256 pixels longer one way than the other
(
872014f,8c773c7). -
Texture coordinates are rounded down to a texel, not to the nearest one. A GPU sampling with ordinary rounding
picks the next texel near texel edges, which shows up as an extra row of outline above sprites
(
872014f). -
Spans start and end on whole pixels. The DS works out each row's span ends (x1 to x4) from its edge rules, then
interpolates texture coordinates across the row between those whole-pixel ends. A GPU uses the exact edge positions.
On flat, textured, rotated quads at about one texel per pixel, the GPU's edge pixels then read the next texel. Pokémon
Black 2's intro showed black slits in Professor Juniper's coat
(
eeb7a93). -
T-junctions leave real gaps, and the DS draws them. Measured with
tests/gpu3d, which replays one frame of The Legend of Zelda: Spirit Tracks' first tunnel with its exact clip coordinates. Where one polygon's vertex sits on another's edge, rounding vertices to whole pixels opens a slit up to about 0.6 px wide. With anti-aliasing on, the DS gives the edge pixel to the polygon and blends in only a little of what's behind. The real DS draws a dim line there (about 60-110 of 255 on one row), on the same rows and nearly the same X ranges as NooDS's software renderer. With anti-aliasing off it draws none. A GPU sampling pixel centers sees through the slit at full brightness (7fbda5b,60ee9a7). -
Full spans with anti-aliasing or edge marking hide cracks. Pokémon Pearl's ground has one-pixel gaps between
polygons, from vertices rounded to pixels. The DS only covers them because it draws edge pixels fully when
anti-aliasing or edge marking is on. Pearl uses DISP3DCNT 0x39. Edge marking would otherwise outline each gap in black
(
cba0f94). -
The equal depth test has a margin. Decals drawn with it, like Link's shadow in Phantom Hourglass, are cut and blink
if depths are compared exactly (
a4ed320). -
High-res rendering and texture atlases don't mix. The DS samples native pixel corners, so the last row or column of
a flat polygon stops short of the neighbouring image in an atlas. Rendering at 2x samples halfway into that last
pixel and reaches the neighbour's first texel. Ultimate Mortal Kombat's fight backgrounds then showed long
wrong-coloured lines. A high-res renderer has to clamp texels on flat (equal-W) polygons to the range the DS would read
(
a480645).
-
CLEAR_DEPTHmust start at the farthest depth (0x7FFF). Plants vs. Zombies never writes it, or anything else in 0x4000330-0x40003FF, and its 3D menu text only shows if the reset value is the far plane (882a49e). melonDS also starts the clear polygon ID at 63. Maelle keeps 0 there, which is unverified either way. -
GXSTAT bit 27 (busy) stays set from
SWAP_BUFFERSuntil the swap at V-blank, even once the FIFO is empty, because the engine is halted until then. Dragon Ball Kai Ultimate Butouden and Dragon Ball Origins 2 poll that bit to wait for the swap. If it clears early, they switch POWCNT1, VRAMCNT and DISPCAPCNT mid-frame and show bands at the top of both screens (8b7f79d). -
The GXFIFO interrupt is a level, not an event. Writing GXSTAT or IF has to re-check it. Mario Kart DS waits
forever on its first 3D screen if the interrupt is only sent when a batch of commands drains the FIFO
(
adc8678). -
Geometry commands start as soon as a word completes one. Spirit Tracks paces itself on the geometry engine's
latency. Starting commands 64 cycles later shows its title 40 frames late
(
3700ca5). -
Translucent polygons that write depth also set the depth fog uses. In Mario Kart's Rainbow Road, the road is
translucent (alpha 55-59) with "translucent new depth". If it doesn't update the fog depth, fog uses the sky behind it
and the road vanishes into the fog colour (
c06853e). -
Fog is ANDed for every translucent pixel. A translucent polygon with fog off turns fog off where it draws, even over
a fogged solid pixel. Mario Kart DS's 3D name tags rely on this to show over the sky
(
5889e00). -
Shadow polygons draw once per pixel and ID. The marks shadow masks leave stay until the next group of masks. A
shadow removes them as it draws, so overlapping faces of one shadow volume (Mario Kart DS's karts, several ID 3 faces in
one model) don't darken twice (
d60e811). - Display capture keeps 5 bits per channel. The 3D engine outputs 6-bit colours. A game that alternates showing live 3D with a capture of it shows the captured frames exactly one 6-bit step darker on every channel. Phantom Hourglass's boat intro does this at 30 Hz on each screen, and on a TV over smooth water it reads as a blink. The real DS does it too. That follows from capture storing 15-bit colour, and Maelle's GPU and software renderers agree on every pixel (13,425 water pixels drop one step between two frames), but nobody filmed it on a DS.
Measured on a DS, a DSi in DS mode and a DSi in DSi mode with maelle-rdlines.nds, which gave identical results
on all three (24d3432). Results are in
tests/hardware/rdlines-realds.bin. melonDS's unmerged render timing model (PR #1911) was refitted to it and then
matched all 56 scenes (019422e, since reverted in
d72a2c0 because no tested game reads it):
- The line buffer stalls at 49 lines. RDLINES_COUNT is the fewest lines waiting during the frame, minus 2.
- Bit 12 (underflow) is set 2 lines before the pair of lines that overruns, at H-blank.
- RDLINES_COUNT reads 63 until two swaps after POWCNT1 bit 2 turns the 3D engine on.
- Once behind, each line pair draws only what fits, with a partial pair at the transition. The captures in the results file show the real cut-off.
- The fitted costs are in the model's commit. Only axis-aligned quads were measured. How sloped edges cost is still open.
None of 18 games tested read RDLINES_COUNT, but nearly every game reads DISP3DCNT.
Measured on a DSi in DSi mode with maelle-fifo.nds. A DSi in DS mode matched too
(846ae58, ca5c7dd).
The full write-up is in tests/hardware/README.md. In short:
- DMA timing 4 (main memory display) is requested every 8 pixels, 32 times a line, and only while the FIFO is shown or captured. Only channels that were already running when the frame started answer, and V-blank stops them. NDMA mode 9 is the same, except that V-blank doesn't stop it.
- A repeating DMA sends at most 16 bytes per request, then carries on with the rest of its count at the next request.
- Each halfword written by DMA is a pixel. Halfword writes from the CPU only move the FIFO on with the top half.
- Writes land between the display reading pixels 8n + 2 and 8n + 3.
- A DMA without repeat sends its whole count at the first request, as fast as the bus allows.
- Capture blending rounds to the nearest ((x + 8) / 16), and a source B pixel with bit 15 clear blends as black. This is true for every capture, not only the FIFO.
Still open: source A's alpha in blends, NDMA mode 9 started mid-frame, and whether an original DS or DS Lite does the same.
-
BG2 and BG3 rotation and scaling parameters start as the identity matrix. Bitmap-mode homebrew relies on that and
never writes them (
d5deba9). - On the GBA, transparent sprite pixels can still lower the priority under them, so rows with nothing opaque can't
be skipped as they can on the DS (
ffe09f8).
-
The
DIVCNTdivision-by-zero bit belongs to the current operation. Code that sets up a division and checks the bit before reading the result has to see this division's bit, not the last one's (e87d862). -
The square root has to be exact for 64-bit inputs. Floating point isn't exact for them (and on the Wii U it's done in
software anyway). Use an integer square root (
b1db67c).
From GBATEK, melonDS and DeSmuME where noted, with no game or real hardware check yet
(656ed6a):
- An empty slot reads open bus, the halfword of the address, with ROM access timing.
-
EXMEMCNTbit 7 gives the slot to one CPU. The other CPU reads 0 from it. Its slot bits also show in the ARM7'sEXMEMSTAT. The DSi's ARM7 card driver refuses to read the header ifEXMEMSTATreads a fixed 0x6000 (Software,fdb4691). - 8-bit SRAM reads are repeated across the bus width.
-
Rumble Pak: reads
(addr / 2) & 0xFFFD. Bit 1 flips the motor. - Memory Expansion Pak: 8 MB at 0x9000000, with a lock register at 0x8240000.
- GBA carts with GPIO: rumble is on pin 3 (WarioWare: Twisted, Drill Dozer). The Boktai solar sensor is a counter read through the pins. Both work with the cart in the slot in DS mode and in GBA mode.
-
FLASH size can't be told from commands. Spirit Tracks has a 1 MB chip and keeps a marker at 0xF4E00. Assuming 512 KB
drops that write, and the game refuses to continue with a "could not be written" error. Reads past a chip's end read
0xFF, like erased FLASH (
93cf79a). -
A read with a 1-byte address and 1 data byte can only be EEPROM 0.5 KB. The Simpsons Game starts that way, then writes
with command 0x02, which otherwise looks like 64 KB EEPROM (
e784480). -
Some cards keep their save on the ROM chip (NAND), like WarioWare: D.I.Y. and Jam with the Band. Jam with the Band
only finishes a profile after the whole first song, so a name prompt after an earlier reboot is normal
(
73ce9c1). -
The chip ID has to fit the ROM size. NooDS answered
00001FC2(32 MB) for every card. The DSi menu treats a card whose ID doesn't fit it as no card at all, so Pokémon Black (256 MB) and Black 2 (512 MB) didn't show. Bit 30 marks a DSi title (a4b47f3).
-
Games read the day of the week. Mario Kart DS, Spirit Tracks and Resident Evil run differently once the RTC
reports it (Mario Kart from frame 30), so an emulator test that hashes frames shouldn't compare runs across that change
(
14cb4a3). -
The GBA cart RTC's AM/PM flag is hour bit 7. On the DS's RTC it's bit 6. It's set for 12-23 h in 24-hour mode too.
In GBA mode the date and time can't be written (
cde2f26). - A GBA cart RTC that a game has set stays in 24-hour mode, since its battery keeps it. Goomba Color reads the hours as 24-hour without setting the mode. Pokémon Emerald finds a clock in 12-hour mode wrong and resets it at boot.
-
Gen 3 Pokémon ROM hacks often add a cart RTC without the plain
SIIRTC_Vstring. Goomba Color (game codeGMBC) uses the cart RTC for MBC3 clocks, and detects it by writing 1 to 0x080000C8 and reading it back (0931bd6).
- A test ROM that sets the sound registers itself may be silent on hardware. Without libnds's sound driver, nothing turns the speaker amplifier on beyond its starting state. Maelle doesn't emulate SPI device 0 (power management), which reads 0 there.