Dreambox C/C++ SDK v1.0.0
C/C++ SDK for creating Dreambox games
Loading...
Searching...
No Matches
db_io.h File Reference
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  IODIRENT
 Directory entry detailing information about a file or directory. More...
 

Macros

#define IO_WHENCE_BEGIN   0
 
#define IO_WHENCE_CURRENT   1
 
#define IO_WHENCE_END   2
 
#define IO_FILEMODE_READ   0
 
#define IO_FILEMODE_WRITE   1
 

Typedefs

typedef void IODIR
 Opaque handle to an open directory. More...
 
typedef void IOFILE
 Opaque handle to an open file descriptor. More...
 

Functions

uint8_t fs_deviceExists (const char *device)
 Check if the given storage device is present. More...
 
void fs_deviceEject (const char *device)
 Eject the given storage device, if it supports it. More...
 
uint8_t fs_fileExists (const char *filepath)
 Check if the file exists. More...
 
IOFILEfs_open (const char *filepath, uint32_t mode)
 Open a file for reading. More...
 
IOFILEfs_allocMemoryCard (const char *filename, const void *icon, const uint16_t *iconPalette, uint32_t numBlocks)
 Allocate a new file on the memory card. More...
 
uint32_t fs_read (IOFILE *filehandle, void *buffer, uint32_t readLen)
 Read data from an open file stream. More...
 
uint32_t fs_write (IOFILE *filehandle, const void *buffer, uint32_t readLen)
 Write to an open file stream. More...
 
uint32_t fs_seek (IOFILE *filehandle, int32_t position, uint32_t whence)
 Seek to a position within the open file stream. More...
 
uint32_t fs_tell (IOFILE *filehandle)
 Retrieve the current position within the open file stream. More...
 
uint8_t fs_eof (IOFILE *filehandle)
 Retrieve whether the given file stream's position is at its end. More...
 
void fs_close (IOFILE *filehandle)
 Close a previously opened file stream. More...
 
IODIRfs_openDir (const char *path)
 Open a directory. More...
 
IODIRENTfs_readDir (IODIR *dirHandle)
 Reads the next directory entry from the open directory. More...
 
void fs_rewindDir (IODIR *dirHandle)
 Rewind open directory to the beginning of the listing. More...
 
void fs_closeDir (IODIR *dirHandle)
 Close open directory. More...
 

Macro Definition Documentation

◆ IO_FILEMODE_READ

#define IO_FILEMODE_READ   0

Definition at line 14 of file db_io.h.

◆ IO_FILEMODE_WRITE

#define IO_FILEMODE_WRITE   1

Definition at line 15 of file db_io.h.

◆ IO_WHENCE_BEGIN

#define IO_WHENCE_BEGIN   0

Definition at line 10 of file db_io.h.

◆ IO_WHENCE_CURRENT

#define IO_WHENCE_CURRENT   1

Definition at line 11 of file db_io.h.

◆ IO_WHENCE_END

#define IO_WHENCE_END   2

Definition at line 12 of file db_io.h.

Typedef Documentation

◆ IODIR

typedef void IODIR

Opaque handle to an open directory.

Definition at line 37 of file db_io.h.

◆ IOFILE

typedef void IOFILE

Opaque handle to an open file descriptor.

Definition at line 40 of file db_io.h.

Function Documentation

◆ fs_allocMemoryCard()

IOFILE * fs_allocMemoryCard ( const char *  filename,
const void *  icon,
const uint16_t *  iconPalette,
uint32_t  numBlocks 
)

Allocate a new file on the memory card.

Parameters
filenameThe name of the file to create (must not exceed 28 characters)
iconPointer to a 16x16 4bpp icon to associate with the file
iconPalettePointer to an array of RGB565 palette colors to use for the icon
numBlocksThe number of 512-byte blocks to reserve for the file
Returns
A handle to the open file or NULL if the file could not be created

◆ fs_close()

void fs_close ( IOFILE filehandle)

Close a previously opened file stream.

Parameters
filehandleA handle previously returned from fs_open

◆ fs_closeDir()

void fs_closeDir ( IODIR dirHandle)

Close open directory.

Parameters
dirHandleA handle previously returned from fs_opendir

◆ fs_deviceEject()

void fs_deviceEject ( const char *  device)

Eject the given storage device, if it supports it.

Parameters
deviceThe storage device (valid values are "cd", "ma", and "mb")

◆ fs_deviceExists()

uint8_t fs_deviceExists ( const char *  device)

Check if the given storage device is present.

Parameters
deviceThe storage device (valid values are "cd", "ma", and "mb")
Returns

◆ fs_eof()

uint8_t fs_eof ( IOFILE filehandle)

Retrieve whether the given file stream's position is at its end.

Parameters
filehandleA handle previously returned from fs_open
Returns
True if the stream has reached its end, false otherwise

◆ fs_fileExists()

uint8_t fs_fileExists ( const char *  filepath)

Check if the file exists.

Parameters
filepathPath to the file
Returns
1 if the file exists, 0 otherwise

◆ fs_open()

IOFILE * fs_open ( const char *  filepath,
uint32_t  mode 
)

Open a file for reading.

Parameters
filepathPath to the file to open
modeMode to open the file in (valid values are IO_FILEMODE_READ, IO_FILEMODE_WRITE, and IO_FILEMODE_APPEND)
Returns
A handle to the open file or NULL if the file could not be opened

◆ fs_openDir()

IODIR * fs_openDir ( const char *  path)

Open a directory.

Parameters
pathPath to a directory to open
Returns
A handle to the open directory, or NULL if an error occurred

◆ fs_read()

uint32_t fs_read ( IOFILE filehandle,
void *  buffer,
uint32_t  readLen 
)

Read data from an open file stream.

Parameters
filehandleA handle previously returned from fs_open
bufferBuffer to read data into
readLenMaximum number of bytes to read
Returns
Number of bytes read, or -1 if an error occurred

◆ fs_readDir()

IODIRENT * fs_readDir ( IODIR dirHandle)

Reads the next directory entry from the open directory.

Parameters
dirHandleA handle previously returned from fs_opendir
Returns
A pointer to a struct with information about the directory entry, or NULL if an error occurred or reached end of directory listing

◆ fs_rewindDir()

void fs_rewindDir ( IODIR dirHandle)

Rewind open directory to the beginning of the listing.

Parameters
dirHandleA handle previously returned from fs_opendir

◆ fs_seek()

uint32_t fs_seek ( IOFILE filehandle,
int32_t  position,
uint32_t  whence 
)

Seek to a position within the open file stream.

Parameters
filehandleA handle previously returned from fs_open
positionSeek position
whenceOrigin to seek relative to
Returns
New absolute position within the stream

◆ fs_tell()

uint32_t fs_tell ( IOFILE filehandle)

Retrieve the current position within the open file stream.

Parameters
filehandleA handle previously returned from fs_open
Returns
The absolute position within the stream

◆ fs_write()

uint32_t fs_write ( IOFILE filehandle,
const void *  buffer,
uint32_t  readLen 
)

Write to an open file stream.

Parameters
filehandleA handle previously returned from fs_open
bufferBuffer to write from
readLenNumber of bytes to write
Returns
Number of bytes written, or -1 if an error occurred