libctr9
Nintendo 3DS ARM9 library
ctr_cart_interface.h File Reference
#include <ctr9/ctr_headers.h>
#include <ctr9/io/ctr_io_interface.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  ctr_cart_interface
 io interface object for accessing 3DSS game carts. More...
 

Functions

bool ctr_cart_interface_initialize (ctr_cart_interface *cart)
 Initialize the given 3DS cart io interface object. More...
 
bool ctr_cart_inserted (void)
 Returns whether a cart is inserted or not. More...
 
int ctr_cart_interface_read_sector (void *io, void *buffer, size_t buffer_size, size_t sector, size_t count)
 Reads sectors from the given io interface. More...
 
int ctr_cart_interface_read (void *io, void *buffer, size_t buffer_size, uint64_t position, size_t count)
 Reads bytes from the given io interface. More...
 
int ctr_cart_interface_noop_write (void *io, const void *buffer, size_t buffer_size, uint64_t position)
 Writes bytes to the given io interface. Not possible for carts. More...
 
int ctr_cart_interface_noop_write_sector (void *io, const void *buffer, size_t buffer_size, size_t sector)
 Writes sectors from the given io interface. Not possible for carts. More...
 
uint64_t ctr_cart_interface_disk_size (void *io)
 Returns the size of the underlying disk for the given io interface. More...
 
size_t ctr_cart_interface_sector_size (void *io)
 Returns the size of the sectors used by the io interface. This is cart dependent, althoug to date most, if not all carts report 512 bytes. More...
 
int ctr_cart_raw_interface_read (void *io, void *buffer, size_t buffer_size, uint64_t position, size_t count)
 Reads bytes from the given io interface. More...
 
int ctr_cart_raw_interface_read_sector (void *io, void *buffer, size_t buffer_size, size_t sector, size_t count)
 Reads sectors from the given io interface. More...
 

Function Documentation

bool ctr_cart_inserted ( void  )

Returns whether a cart is inserted or not.

Returns
True if a cart is inserted, false otherwise.
uint64_t ctr_cart_interface_disk_size ( void *  io)

Returns the size of the underlying disk for the given io interface.

Returns
The size of the 3DS ROM as reported by it.
bool ctr_cart_interface_initialize ( ctr_cart_interface cart)

Initialize the given 3DS cart io interface object.

Parameters
[out]io3DS cart io interface to initialize.
Returns
True on success, false on failure. This will fail if no cart is inserted.
int ctr_cart_interface_noop_write ( void *  io,
const void *  buffer,
size_t  buffer_size,
uint64_t  position 
)

Writes bytes to the given io interface. Not possible for carts.

It is not possible to write to a 3DS cart, so this function will always return an error.

Parameters
[in,out]ioThe io interface to use for writing.
[in]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer, and the number of bytes to write.
[in]positionPosition/address in the io interface to write to.
Returns
Non-zero, error always.
int ctr_cart_interface_noop_write_sector ( void *  io,
const void *  buffer,
size_t  buffer_size,
size_t  sector 
)

Writes sectors from the given io interface. Not possible for carts.

It is not possible to write to a 3DS cart, so this function will always return an error.

Parameters
[in,out]ioThe io interface to use for writing.
[in]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer, and the number of bytes to write. If the number is not a multiple of the sector size, this function will only write all the full sectors it can, ignoring the end of the buffer that doesn't fit a sector.
[in]sectorSector Position in the io interface to write to.
Returns
Non-zero, error always.
int ctr_cart_interface_read ( void *  io,
void *  buffer,
size_t  buffer_size,
uint64_t  position,
size_t  count 
)

Reads bytes from the given io interface.

This implementation automatically returns the NCCH header when reading carts at 0x1000, and from 0x1200 to 0x2000 it returns 0xFF bytes.

Parameters
[in,out]ioThe io interface to use for reading.
[out]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer in bytes.
[in]positionPosition/address in the io interface to read from.
[in]countThe number of bytes to read.
Returns
0 upon success, anything else means an error.
int ctr_cart_interface_read_sector ( void *  io,
void *  buffer,
size_t  buffer_size,
size_t  sector,
size_t  count 
)

Reads sectors from the given io interface.

3DS carts define their own sector size. They refer to these as the unit media size. Most, if not all carts seem to use 512 bytes.

This implementation automatically returns the NCCH header when reading carts at 0x1000, and from 0x1200 to 0x2000 it returns 0xFF bytes.

Parameters
[in,out]ioThe io interface to use for reading.
[out]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer in bytes.
[in]sectorSector position in the io interface to read from.
[in]countThe number of sectors to read.
Returns
0 upon success, anything else means an error.
size_t ctr_cart_interface_sector_size ( void *  io)

Returns the size of the sectors used by the io interface. This is cart dependent, althoug to date most, if not all carts report 512 bytes.

Returns
The unit media size as reported by the 3DS cart, tends to be 512 bytes.
int ctr_cart_raw_interface_read ( void *  io,
void *  buffer,
size_t  buffer_size,
uint64_t  position,
size_t  count 
)

Reads bytes from the given io interface.

This implementation returns the raw data returned by the cart reading system for data between 0x1000 to 0x4000, which tends to be incomprehensible.

Parameters
[in,out]ioThe io interface to use for reading.
[out]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer in bytes.
[in]positionPosition/address in the io interface to read from.
[in]countThe number of bytes to read.
Returns
0 upon success, anything else means an error.
int ctr_cart_raw_interface_read_sector ( void *  io,
void *  buffer,
size_t  buffer_size,
size_t  sector,
size_t  count 
)

Reads sectors from the given io interface.

3DS carts define their own sector size. They refer to these as the unit media size. Most, if not all carts seem to use 512 bytes.

This implementation returns the raw data returned by the cart reading system for data between 0x1000 to 0x4000, which tends to be incomprehensible.

Parameters
[in,out]ioThe io interface to use for reading.
[out]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer in bytes.
[in]sectorSector position in the io interface to read from.
[in]countThe number of sectors to read.
Returns
0 upon success, anything else means an error.