CTR-SDK API Guide

Overview

This guide provides the following two types of information to allow developers to understand the features provided by the CTR-SDK.

Table of Contents

Library Overview

Library Name Overview
init Handles processing that precedes a program's main function. By providing functions with particular names, applications can add processing that runs before the main function starts.
os Handles threads, mutexes, timers, clocks, and basic memory management.
fnd Defines common classes used by a number of other libraries, such as allocators, dates and times.
fs Accesses Game Cards, SD Cards, save data, and other memory locations.
ro Controls dynamic modules.
math Defines numeric functions and classes.
nstd Provides customized versions of standard library functions.
util Defines general-purpose classes.
cx Compresses and expands data.
zlib The CTR-SDK ported version of the open-source zlib library.
crypto Handles encryption-related processing.
jpeg Encodes and decodes JPEG and MPO images.
enc Provides conversion back and forth between UTF-16 and UTF-8.
applet Controls the HOME Menu and Sleep Mode.
ptm Gets power status and controls the real-time clock alarm(s).
pl Handles pedometer step counts and shared fonts.
news Posts messages to Notifications.
cfg Gets the settings stored in System Memory.
dbg Handles debug output and abnormal program termination.
hio Communicates with a Windows PC via USB. This can only be used for development purposes.
midi Uses UIC-MIDI to communicate with a MIDI interface. This library can be used only for development purposes.
nngx, nn::gx Controls the GPU.
gl Creates command lists. This uses an OpenGL ES-compatible API, but it increases the CPU load.
gd Creates command lists. This is incompatible with OpenGL ES but it reduces the CPU load.
gr Provides helper functions for creating command lists.
ulcd Generates appropriate camera matrices based on input from the 3D depth slider.
tpl A library for accessing TPL files, which hold texture data.
font A library for rendering characters and strings using font data created by FontConverter.
snd Uses the sound DSP for sound playback.
dsp Controls the sound DSP.
hid Reads input from buttons, the Circle Pad, the Touch Screen, the accelerometer, and the gyro sensor.
camera Controls the cameras.
y2r Converts YUV image data into RGB format.
mic Gets input from the microphone.
uds Handles direct wireless communication between CTR systems.
rdt Establishes reliable communication channels on top of UDS communication channels.
dlp Library that handles Download Play.
cec Controls StreetPass.
boss Controls SpotPass.
ac Connects to access points.
http Used by NEX.
socket Used by NEX.
ir Carries out infrared communication between consoles.
ndm Controls communication-related background processing.
friends Gets information from the friend list. This also controls logins for online services.
ngc Checks strings for profanity.
ubl Manages the user blacklist.
erreula Controls the applet that displays the EULA error message.
swkbd Controls the software keyboard applet.
phtsel Controls the photo selector applet.
voicesel Controls the voice selector applet.

Index by Feature

Graphics

Screen Display Handled by the gx, gl, gd, and gr libraries.
Stereoscopic Output Use the gx and ulcd libraries.
Fonts You can use the font library.
Use FontConverter to create font data for the font library.
Text Rendering Fonts
Shared Fonts Use the pl library.
Texture Files You can use the tpl library.
Use ctr_TexturePackager to create TPL files for the tpl library.
Encoding and Decoding JPEG Images Use the jpeg library.
Encoding and Decoding MPO Images Use the jpeg library.
Encoding and Decoding Stereoscopic Images Encoding and Decoding MPO Images
Converting from YUV to RGB You can use the y2r library.
Brightness Adjustment You cannot change the brightness or get the current brightness value.
Power-Saving Mode You cannot turn power-saving mode on or off, nor can you get the current mode.

Sound

Sound Playback Use the snd library.
Shutter Sound Play it using nn::camera::CTR::PlayShutterSound.
Microphone Get input audio using the mic library.
Using the MIDI Interface (UIC-MIDI) This can only be used for development purposes. It cannot be used in retail products.
Use the midi library.
Sound Output Mode Get this using nn::cfg::CTR::GetSoundOutputMode.
Headphone Connection Status Get this using nn::snd::CTR::GetHeadphoneStatus.
Sound Volume You cannot get a value for this.

User Input

+Control Pad, A/B/X/Y/L/R Buttons, START Get input values using nn::hid::CTR::PadReader.
SELECT This option can be used only for development purposes.
It cannot be used in retail products.
Enable Debug Mode using the Config tool and call nn::hid::CTR::EnableSelectButton to get input via nn::hid::CTR::PadReader.
Circle Pad Use nn::hid::CTR::PadReader to get input values.
Circle Pad Pro Get input values using nn::hid::CTR::ExtraPadReader.
ZL/ZR Buttons Use nn::hid::CTR::ExtraPadReader to get input values.
Analog Stick Circle Pad
Touch Panel Get input values using nn::hid::CTR::TouchPanelReader.
Touch Screen Touch Panel
Accelerometer Get input values using nn::hid::CTR::AccelerometerReader.
Gyro Sensor Get input values using nn::hid::CTR::GyroscopeReader.
Pedometer Use the pl library.
Camera Get camera images using the camera library.
Microphone Use the mic library to get input audio.
Debug Controller This option can be used only for development purposes.
It cannot be used in retail products.
Use nn::hid::CTR::DebugPadReader to get input values.
3D depth slider You can indirectly use this through the ulcd library.
Sound Volume You cannot get a value for this function.
POWER Button You cannot get the POWER Button input directly.
→ You must handle Application Close instead.
Wireless Switch You cannot get the wireless switch input.
→ However, turning the wireless switch OFF has an impact during communication.
HOME You cannot get the HOME Button input directly.
→ You must handle switching to the HOME Menu.

Getting Information Other Than User Input

Remaining Battery Life Get this using nn::ptm::CTR::GetBatteryLevel.
AC Adapter Connection State Get this using nn::ptm::CTR::GetAdapterState.
Charging Status Get this using nn::ptm::CTR::GetBatteryChargeState.
Getting System Settings You can get some System Settings using the cfg library.
Date and time You can get the current date and time using nn::fnd::DateTime.
Use nn::cfg::CTR::GetUserTimeOffset to discover whether and how the time has been changed by the user.
Get CPU cycle counts using nn::os::Tick.
Username Get this using nn::cfg::CTR::GetUserName.
Birthday Get this using nn::cfg::CTR::GetBirthday.
Regions Get the country using nn::cfg::CTR::GetCountry and the local area using nn::cfg::CTR::GetSimpleAddress.
Headphone Connection Status Use nn::snd::CTR::GetHeadphoneStatus to get the connection status of headphones.
User Information Username
Birthday
Area
Language Get this using nn::cfg::CTR::GetLanguage.
Region Get this using nn::cfg::CTR::GetRegion.
Sound Output Mode Use nn::cfg::CTR::GetSoundOutputMode to get the sound output mode.
Variable RTC Offset Get this using nn::cfg::CTR::GetUserTimeOffset.
System-Specific ID Get this using nn::cfg::CTR::GetTransferableId.
Pedometer Use the pl library.
Notification LED You cannot manipulate the notification LED directly, or get its state.
See below for the conditions under which it illuminates or blinks, and related information.
  • When a notification is received
    Illuminates when a notification is received via SpotPass. You can make a notification be sent from the server and the LED to illuminate by registering an application-specific SpotPass task.
  • When a StreetPass communication is received
    Illuminates when StreetPass is engaged.
    You cannot control this from the application.
  • When a friend comes online
    Illuminates when a Friend comes online.
    You cannot control this option from the application.
  • When the battery level is very low
    Illuminates when the battery level reaches nn::ptm::CTR::BATTERYLEVEL_1.
    You cannot control this option from the application.
3D LED You cannot control or get the state of the 3D LED directly.
The 3D LED lights up when NN_GX_DISPLAY_MODE_STEREO is specified to nngxSetDisplayMode, as long as "Display of 3D Images" is not restricted by Parental Controls.
Power LED You cannot control or get the state of the power LED.
→ You can use the remaining battery life instead.
Recharge LED You cannot control or get the state of the recharge LED.
→ You can use the charging status instead.
Wireless LED You cannot manipulate the wireless LED or get its state.
The LED illuminates when wireless communication is activated, and blinks during wireless communication.
Getting the Execution Environment Use nn::os::CTR::GetRunningTargetHardware to get the type of hardware on which an application is running.

Communication

StreetPass Use the cec library.
SpotPass Use the boss library.
Direct, Low-Latency Communication Between CTR Systems Use the uds library.
Direct Data Transfers Between CTR Systems Use the rdt library.
Download Play Use the dlp library.
Infrared Communication Use the ir library.
Getting Friend Information Use the friends library.
Friend List Getting Friend Information
Registering Friends Applications cannot register friends.
NEX → NEX is distributed with the CTR-NEX package, which is separate from the CTR-SDK. Refer to the CTR-NEX package.
Online Matchmaking NEX
Online Ranking NEX
Network Data Storage NEX
Connecting to an Access Point Use the ac library.
Nintendo Zone Use the ac library to automatically connect to a Nintendo Zone just like an ordinary access point.
USB Communication with a Windows PC This option can be used only for development purposes.
It cannot be used in retail products.
Use the hio library.
Posting Messages Applications can post messages directly using nn::news::CTR::user::PostNews.
You can also post messages through SpotPass.
Internet Communication Connecting to an Access Point
SpotPass
NEX
Local Communication Direct, Low-Latency Wireless Communication Between CTR Systems
Direct Wireless Data Transfers Between CTR Systems
Download Play
Infrared Communication
Nintendo 3DS Service User Agreement EULA
EULA The EULA must be accepted before it is possible to use Internet communication, run StreetPass, or get friend information. Acceptance of EULA can use the System Settings or be performed with Config.
An application can use nn::cfg::CTR::IsAgreedEula to find if the user has accepted the EULA.
Wireless LED You cannot manipulate the wireless LED or get its state.
The LED illuminates when wireless communication is activated, and blinks during wireless communication.
Wireless Switch You cannot get the wireless switch input.
→ However, turning the wireless switch OFF has an effect during communication.
Disabled If wireless communication is disabled when you initialize a library that uses wireless, then you get an error with an error value to indicate that wireless communication is disabled.
If wireless communication is disabled via the wireless switch when wireless communication is in use, the sequence transitions to one for disconnecting a connection by a library.

Calculation

Matrix / Vector Use the math library.
Quaternions Use the math library.
Floating-Point Functions Use the math library.
Integer Functions Use the math library.
Bit Operations Use the math library.
Random Number Generation Normally the math library can be used for the generation of pseudo-random numbers.
You can use the nn::crypto::GenerateRandomBytes function to generate random numbers that are not repeated.
CRC Calculations Use the util library.
SHA Calculations Use the crypto library.
AES Encryption Use the crypto library.
Compression / Decompression The cx library or zlib can be used.
Encoding and Decoding JPEG Images Use the jpeg library.
Encoding and Decoding MPO Images Use the jpeg library.
Encoding and Decoding Stereoscopic Images Encoding and Decoding MPO Images

Power / Application Controls

POWER Button You cannot get input directly from the POWER Button.
→ You must handle Application Close instead.
HOME You cannot get input directly from the HOME Button.
→ You must handle switching to the HOME Menu.
Power Off Applications cannot turn the system off.
Sleep Applications cannot go into Sleep Mode autonomously. Applications go into sleep mode according to instructions from the system.
See the applet library.
Sleep Mode Sleep
Application Shutdown Applications cannot exit autonomously.
Applications close according to instructions from the system.
For more information, see the applet library.
Application Reset Use nn::applet::CTR::RestartApplication.
Remaining Battery Life Use nn::ptm::CTR::GetBatteryLevel to get the remaining battery life.
AC Adapter Connection State Use nn::ptm::CTR::GetAdapterState to get the AC adapter connection state.
Charging Status Use nn::ptm::CTR::GetBatteryChargeState to get the charging status.

OS Foundation

Thread Use os::Thread.
Mutex Use the os library.
Ticks Use os::Tick.
Cycle Counts Ticks
Timers Use os::Timer.
Memory Management Use the os library for basic allocation of memory to your application. You can use the fnd library to build an allocator in allocated memory.
Device Memory Memory Management
Exception Handling This option can be used only for development purposes.
It cannot be used in retail products.
You can register exception handlers with the os library (nn::os::ARM).
Date and Time Get the current date and time using fnd::DateTime.

Get CPU cycle counts using os::Tick.
Dynamic Modules Use the ro library.
DLL Dynamic Modules

File System

Game Cards Use the fs library.
See nn::fs::MountRom.
Save Data Use the fs library.
See nn::fs::MountSaveData.
Expanded Save Data Use the fs library.
See nn::fs::MountExtSaveData.
SD Card This option can be used only for development purposes.
It cannot be used in retail products.
Use the fs library.
See nn::fs::MountSdmc.

Debug

Debug Output This option can be used only for development purposes.
It cannot be used in retail products.
Use macros for debug string output.
ASSERT Uses the ASSERT Macro.
Enables you to set the handler that is called with nn::dbg::SetBreakHandler when the ASSERT macro fails.
USB Communication with a Windows PC This option can be used only for development purposes.
It cannot be used in retail products.
Use the hio library.
Using the MIDI Interface (UIC-MIDI) This option can be used only for development purposes.
It cannot be used in retail products.
Use the midi library.
Debug Controller This option can be used only for development purposes.
It cannot be used in retail products.
Use nn::hid::CTR::DebugPadReader to get input values.
Exception Handling This option can be used only for development purposes.
It cannot be used in retail products.
You can register exception handlers with the os library (nn::os::ARM).
Getting the Execution Environment Use nn::os::CTR::GetRunningTargetHardware to get the type of hardware on which an application is running.
Accessing SD Cards This option can be used only for development purposes.
It cannot be used in retail products.
Use the fs library.
For more information, see nn::fs::MountSdmc.
SELECT This option can be used only for development purposes.
It cannot be used in retail products.
Enable Debug Mode by using the Config tool, and call nn::hid::CTR::EnableSelectButton to get input from nn::hid::CTR::PadReader.

HOME Menu

Brightness Adjustment You cannot change the brightness or get the current brightness value.
Power-Saving Mode You cannot turn power-saving mode on or off, nor can you get the current mode.
Banners See the ctr_makebanner reference for details about creating icons. See Build Rules or the Guide to Developing a Build System for instructions on adding them to your application.
Icons For more information about creating icons, see the ctr_makebanner reference.
For more information about adding icons to your application, see Build Rules or the Guide to Developing a Build System.
Software Icons Icons
SpotPass Notifications These are notifications received via SpotPass. You can receive notifications sent from the server by registering an application-specific SpotPass task.
StreetPass Notifications This is a notification indicating that StreetPass has occurred.
You cannot control this option from the application.
Notifications Distributed Directly from Games Applications can use nn::news::CTR::user::PostNews to distribute notifications directly.
Pedometer Use the pl library.
Play Coins → The library used for Play Coins is distributed with the CTR-SDK Applet package, which is separate from the CTR-SDK itself.
Switching to the HOME Menu Use the applet library.

Applets

Error Dialogs Use the erreula library.
Software Keyboard Use the swkbd library.
Photo Selector Dialog Use the phtsel library.
Voice Selector Dialog Use the voicesel library.

Built-In Software

Notifications SpotPass Notifications
StreetPass Notifications
Notifications Distributed Directly from Games
Software Library Icon information is registered here. No other operations are possible.
Activity Log Icon information is used here. No other operations are possible.
AR Cards → The AR library is used to recognize AR Cards. It is distributed separately from the CTR-SDK.
Mii → The CTR Face Library allows you to use Mii characters. It is distributed separately from the CTR-SDK.

System Settings

Username Use nn::cfg::CTR::GetUserName to get the user name.
Birthday Use nn::cfg::CTR::GetBirthday to get the birthday.
Regions Use nn::cfg::CTR::GetCountry to get the country, and use nn::cfg::CTR::GetSimpleAddress to get the local area.
Language Use nn::cfg::CTR::GetLanguage to get the language.
Sound Output Mode Use nn::cfg::CTR::GetSoundOutputMode to get the sound output mode.
Variable RTC Offset Use nn::cfg::CTR::GetUserTimeOffset to get the variable RTC offset.
Touch Screen Calibration Applications do not need to calibrate the Touch Screen because this is automatically done by the nn::hid::CTR::TouchPanelReader.
External Camera Calibration Applications do not need to calibrate the cameras to take 3D photos because the cameras are calibrated automatically.

You can use nn::camera::CTR::GetStereoCameraCalibrationData to get calibration data and nn::camera::CTR::GetStereoCameraCalibrationMatrixEx to generate a calibration matrix from the calibration data.
Circle Pad Calibration Applications do not need to calibrate the Circle Pad because this is automatically done by the nn::hid::CTR::PadReader.
Parental Controls Parental Controls
Blocked-User Settings Initialization The ubl library clears the registered blocked-user settings.
Internet Connections These are used by Connecting to an Access Point.

Parental Controls

Software Rating Based on the rating information set in Icon, applications with a setting greater than the target age are prohibited from running.
This restriction is applied automatically, and prevents the application from being started from the HOME Menu.
It is not possible to obtain whether this restriction is enabled.
Internet Browser When enabled, this restriction prevents the Internet browser from starting.
It is not possible to get whether this restriction is enabled.
Nintendo 3DS Shopping Services When enabled, this restriction prevents the user from purchasing paid content.
It is not possible to get whether this restriction is enabled.
Display of 3D Images When enabled, this restriction prevents the system from displaying stereoscopic images. This restriction is applied automatically. It prevents stereoscopic display even if you set nngxSetDisplayMode to NN_GX_DISPLAYMODE_STEREO.
You can detect whether this restriction or the 3D depth slider has prohibited stereoscopic images by calling nn::gx::CTR::IsStereoVisionAllowed.
Sharing Images / Audio / Video When enabled, this restriction prevents the sending and receiving of user-generated content (UGC).
This restriction is not applied automatically. Applications must get a value from nn::cfg::CTR::IsRestrictPhotoExchange and then enforce this restriction.
Online Interaction When enabled, this restriction prevents communication via access points. This restriction is applied automatically. When enabled, it causes connection to an AP to fail.
You can obtain whether this restriction is enabled using nn::cfg::CTR::IsRestrictP2pInternet.
StreetPass When enabled, this restriction blocks StreetPass.
This restriction is applied automatically. When enabled, writing a message to a StreetPass box fails. It also blocks the StreetPass feature itself.
You can determine whether this restriction is enabled using nn::cfg::CTR::IsRestrictP2pCec.
Friend Registration It is prohibited to register friends when this restriction is enabled.

You can determine whether this restriction is enabled using nn::cfg::CTR::IsRestrictAddFriend.
DS Download Play DS Download Play is prohibited when this restriction is enabled.
It is not possible to get whether this restriction is enabled.

Revision History

2012/06/22
Added the item about the ASSERT macro.
2011/12/12
Updated information.
2011/07/19
Initial version.

CONFIDENTIAL