sgdk: tools.h File Reference

sgdk

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

Defines | Typedefs | Functions
tools.h File Reference

Misc tools methods. More...

`#include "bmp.h"`
`#include "vdp_tile.h"`
`#include "vdp_bg.h"`
`#include "map.h"`

Go to the source code of this file.

## Defines

#define | COMPRESSION_NONE 0
| No compression.
#define | COMPRESSION_APLIB 1
| Use aplib (appack or sixpack) compression scheme.
#define | COMPRESSION_LZ4W 2
| Use LZ4W compression scheme.

## Typedefs

typedef s16 | _comparatorCallback (void *o1, void *o2)
| Callback for QSort comparaison.

## Functions

void | setRandomSeed (u16 seed)
| Set the randomizer seed (to allow reproductible value if we are lucky with HV counter :p)
u16 | random ()
| Returns a random u16 integer value.
u32 | getFPS ()
fix32 | getFPS_f ()
void | KLog (char *text)
| KDebug log helper methods.
void | KLog_U1 (char *t1, u32 v1)
void | KLog_U2 (char *t1, u32 v1, char *t2, u32 v2)
void | KLog_U3 (char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3)
void | KLog_U4 (char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3, char *t4, u32 v4)
void | KLog_U1_ (char *t1, u32 v1, char *t2)
void | KLog_U2_ (char *t1, u32 v1, char *t2, u32 v2, char *t3)
void | KLog_U3_ (char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3, char *t4)
void | KLog_U4_ (char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3, char *t4, u32 v4, char *t5)
void | KLog_U1x (u16 minSize, char *t1, u32 v1)
void | KLog_U2x (u16 minSize, char *t1, u32 v1, char *t2, u32 v2)
void | KLog_U3x (u16 minSize, char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3)
void | KLog_U4x (u16 minSize, char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3, char *t4, u32 v4)
void | KLog_U1x_ (u16 minSize, char *t1, u32 v1, char *t2)
void | KLog_U2x_ (u16 minSize, char *t1, u32 v1, char *t2, u32 v2, char *t3)
void | KLog_U3x_ (u16 minSize, char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3, char *t4)
void | KLog_U4x_ (u16 minSize, char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3, char *t4, u32 v4, char *t5)
void | KLog_S1 (char *t1, s32 v1)
void | KLog_S2 (char *t1, s32 v1, char *t2, s32 v2)
void | KLog_S3 (char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3)
void | KLog_S4 (char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3, char *t4, s32 v4)
void | KLog_S1_ (char *t1, s32 v1, char *t2)
void | KLog_S2_ (char *t1, s32 v1, char *t2, s32 v2, char *t3)
void | KLog_S3_ (char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3, char *t4)
void | KLog_S4_ (char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3, char *t4, s32 v4, char *t5)
void | KLog_S1x (u16 minSize, char *t1, s32 v1)
void | KLog_S2x (u16 minSize, char *t1, s32 v1, char *t2, s32 v2)
void | KLog_S3x (u16 minSize, char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3)
void | KLog_S4x (u16 minSize, char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3, char *t4, s32 v4)
void | KLog_f1 (char *t1, fix16 v1)
void | KLog_f2 (char *t1, fix16 v1, char *t2, fix16 v2)
void | KLog_f3 (char *t1, fix16 v1, char *t2, fix16 v2, char *t3, fix16 v3)
void | KLog_f4 (char *t1, fix16 v1, char *t2, fix16 v2, char *t3, fix16 v3, char *t4, fix16 v4)
void | KLog_f1x (s16 numDec, char *t1, fix16 v1)
void | KLog_f2x (s16 numDec, char *t1, fix16 v1, char *t2, fix16 v2)
void | KLog_f3x (s16 numDec, char *t1, fix16 v1, char *t2, fix16 v2, char *t3, fix16 v3)
void | KLog_f4x (s16 numDec, char *t1, fix16 v1, char *t2, fix16 v2, char *t3, fix16 v3, char *t4, fix16 v4)
void | KLog_F1 (char *t1, fix32 v1)
void | KLog_F2 (char *t1, fix32 v1, char *t2, fix32 v2)
void | KLog_F3 (char *t1, fix32 v1, char *t2, fix32 v2, char *t3, fix32 v3)
void | KLog_F4 (char *t1, fix32 v1, char *t2, fix32 v2, char *t3, fix32 v3, char *t4, fix32 v4)
void | KLog_F1x (s16 numDec, char *t1, fix32 v1)
void | KLog_F2x (s16 numDec, char *t1, fix32 v1, char *t2, fix32 v2)
void | KLog_F3x (s16 numDec, char *t1, fix32 v1, char *t2, fix32 v2, char *t3, fix32 v3)
void | KLog_F4x (s16 numDec, char *t1, fix32 v1, char *t2, fix32 v2, char *t3, fix32 v3, char *t4, fix32 v4)
Bitmap * | allocateBitmap (const Bitmap *bitmap)
| Allocate a new Bitmap structure which can receive unpacked bitmap data of the specified Bitmap. There is no memory allocated for the palette data as it assumes to always use a reference for Palette field.
Bitmap * | allocateBitmapEx (u16 width, u16 heigth)
| Allocate a new Bitmap structure which can receive the bitmap data for the specified Bitmap dimension. There is no memory allocated for the palette data as it assumes to always use a reference for Palette field.
TileSet * | allocateTileSet (const TileSet *tileset)
| Allocate TileSet structure which can receive unpacked tiles data of the specified TileSet.
TileSet * | allocateTileSetEx (u16 numTile)
| Allocate a new TileSet structure which can receive the data for the specified number of tile.
TileMap * | allocateTileMap (const TileMap *tilemap)
| Allocate TileMap structure which can receive unpacked tilemap data of the specified TileMap.
TileMap * | allocateTileMapEx (u16 width, u16 heigth)
| Allocate a new TileMap structure which can receive tilemap data for the specified TileMap dimension.
Image * | allocateImage (const Image *image)
| Allocate Image structure which can receive unpacked image data of the specified Image. There is no memory allocated for the palette data as it assumes to always use a reference for Palette field.
Map * | allocateMap (const MapDefinition *mapDef)
| Allocate Map structure which can receive unpacked data of the specified MapDefinition.
Bitmap * | unpackBitmap (const Bitmap *src, Bitmap *dest)
| Unpack the specified source Bitmap and return result in a new allocated Bitmap.
TileSet * | unpackTileSet (const TileSet *src, TileSet *dest)
| Unpack the specified TileSet structure and return result in a new allocated TileSet.
TileMap * | unpackTileMap (const TileMap *src, TileMap *dest)
| Unpack the specified TileMap structure and return result in a new allocated TileMap.
Image * | unpackImage (const Image *src, Image *dest)
| Unpack the specified Image structure and return result in a new allocated Image.
u32 | unpack (u16 compression, u8 *src, u8 *dest)
| Unpack the specified source data buffer in the specified destination buffer. if source is not packed then nothing is done.
u32 | aplib_unpack (u8 *src, u8 *dest)
| Unpack (aplib packer) the specified source data buffer in the specified destination buffer.
u32 | lz4w_unpack (const u8 *src, u8 *dest)
| Unpack (LZ4W) the specified source data buffer in the specified destination buffer.
void | qsort_u8 (u8 *data, u16 left, u16 right)
| Quick sort algo on u8 data array.
void | qsort_s8 (s8 *data, u16 left, u16 right)
| Quick sort algo on s8 data array.
void | qsort_u16 (u16 *data, u16 left, u16 right)
| Quick sort algo on u16 data array.
void | qsort_s16 (s16 *data, u16 left, u16 right)
| Quick sort algo on s16 data array.
void | qsort_u32 (u32 *data, u16 left, u16 right)
| Quick sort algo on u32 data array.
void | qsort_s32 (s32 *data, u16 left, u16 right)
| Quick sort algo on s32 data array.
void | qsort (void **data, u16 len, _comparatorCallback *cb)
| Quick sort algo on array of pointer (object)

## Detailed Description

Misc tools methods.

Author:
  Stephane Dallongeville

Date:
  08/2011

This unit provides some misc tools methods as getFPS(), unpack()...

## Typedef Documentation

typedef s16 _comparatorCallback(void *o1, void *o2)

Callback for QSort comparaison.

This callback is used to compare 2 objects.
Return value should be:
< 0 if o1 is below o2
= 0 if o1 is equal to o2
> 0 if o1 is above o2

## Function Documentation

Bitmap* allocateBitmap | ( | const Bitmap * | bitmap | ) |

Allocate a new Bitmap structure which can receive unpacked bitmap data of the specified Bitmap.
There is no memory allocated for the palette data as it assumes to always use a reference for Palette field.

Parameters:

  bitmap | Source Bitmap we want to allocate the unpacked Bitmap object.

Returns:
  The new allocated Bitmap object which can receive the unpacked Bitmap, note that returned bitmap is allocated in a single bloc and can be released with Mem_Free(bitmap).
  NULL is returned if there is not enough memory to store the unpacked bitmap.

Bitmap* allocateBitmapEx | ( | u16 | width,
|  | u16 | heigth
| ) |  |

Allocate a new Bitmap structure which can receive the bitmap data for the specified Bitmap dimension.
There is no memory allocated for the palette data as it assumes to always use a reference for Palette field.

Parameters:

  width | Width in pixel of the bitmap structure we want to allocate.
  heigth | heigth in pixel of the bitmap structure we want to allocate.

Returns:
  The new allocated Bitmap object which can receive an unpacked Bitmap for the specified dimension.
  Note that returned bitmap is allocated in a single bloc and can be released with Mem_Free(bitmap).
  NULL is returned if there is not enough memory to allocate the bitmap.

Image* allocateImage | ( | const Image * | image | ) |

Allocate Image structure which can receive unpacked image data of the specified Image. There is no memory allocated for the palette data as it assumes to always use a reference for Palette field.

Parameters:

  image | Source Image we want to allocate the unpacked Image object.

Returns:
  The new allocated Image object which can receive the unpacked Image, note that returned image is allocated in a single bloc and can be released with Mem_Free(image).
  NULL is returned if there is not enough memory to store the unpacked image.

Map* allocateMap | ( | const MapDefinition * | mapDef | ) |

Allocate Map structure which can receive unpacked data of the specified MapDefinition.

Parameters:

  mapDef | Source MapDefinition we want to allocate Map object for.

Returns:
  The new allocated Map object which can receive the (unpacked) MapDefinition data, note that returned map is allocated in a single bloc and can be released with Mem_Free(image).
  NULL is returned if there is not enough memory to store the data for given MapDefinition.

TileMap* allocateTileMap | ( | const TileMap * | tilemap | ) |

Allocate TileMap structure which can receive unpacked tilemap data of the specified TileMap.

Parameters:

  tilemap | Source TileMap we want to allocate the unpacked TileMap object.

Returns:
  The new allocated TileMap object which can receive the unpacked TileMap, note that returned tilemap is allocated in a single bloc and can be released with Mem_Free(tilemap).
  NULL is returned if there is not enough memory to store the unpacked tilemap.

TileMap* allocateTileMapEx | ( | u16 | width,
|  | u16 | heigth
| ) |  |

Allocate a new TileMap structure which can receive tilemap data for the specified TileMap dimension.

Parameters:

  width | Width in tile of the TileMap structure we want to allocate.
  heigth | heigth in tile of the TileMap structure we want to allocate.

Returns:
  The new allocated TileMap object which can receive data for the specified TileMap dimension.
  Note that returned tilemap is allocated in a single bloc and can be released with Mem_Free(tilemap).
  NULL is returned if there is not enough memory to allocate the tilemap.

TileSet* allocateTileSet | ( | const TileSet * | tileset | ) |

Allocate TileSet structure which can receive unpacked tiles data of the specified TileSet.

Parameters:

  tileset | Source TileSet we want to allocate the unpacked TileSet object.

Returns:
  The new allocated TileSet object which can receive the unpacked TileSet, note that returned tile set is allocated in a single bloc and can be released with Mem_Free(tb).
  NULL is returned if there is not enough memory to store the unpacked tiles.

TileSet* allocateTileSetEx | ( | u16 | numTile | ) |

Allocate a new TileSet structure which can receive the data for the specified number of tile.

Parameters:

  numTile | Number of tile this tileset can contain

Returns:
  The new allocated TileSet object which can receive the specified number of tile.
  Note that returned tileset is allocated in a single bloc and can be released with Mem_Free(tileset).
  NULL is returned if there is not enough memory to allocatee the tileset.

u32 aplib_unpack | ( | u8 * | src,
|  | u8 * | dest
| ) |  |

Unpack (aplib packer) the specified source data buffer in the specified destination buffer.

Parameters:

  src | Source data buffer containing the packed data (aplib packer) to unpack.
  dest | Destination buffer where to store unpacked data, be sure to allocate enough space.

Returns:
  Unpacked size.

u32 getFPS | ( |  | ) |

Deprecated:
  Uses SYS_getFPS() instead

fix32 getFPS_f | ( |  | ) |

Deprecated:
  Uses SYS_getFPSAsFloat() instead

u32 lz4w_unpack | ( | const u8 * | src,
|  | u8 * | dest
| ) |  |

Unpack (LZ4W) the specified source data buffer in the specified destination buffer.

Parameters:

  src | Source data buffer containing the packed data (LZ4W packed) to unpack.
  dest | Destination buffer where to store unpacked data, be sure to allocate enough space. The size of unpacked data is contained in the first 4 bytes of 'src'.

Returns:
  Unpacked size.

void qsort | ( | void ** | data,
|  | u16 | len,
|  | _comparatorCallback * | cb
| ) |  |

Quick sort algo on array of pointer (object)

Parameters:

  data | array of pointer (pointer of object to sort).
  len | number of element in the data array
  cb | comparator callback used to compare 2 objects.

void qsort_s16 | ( | s16 * | data,
|  | u16 | left,
|  | u16 | right
| ) |  |

Quick sort algo on s16 data array.

Parameters:

  data | s16 data pointer.
  left | left index (should be 0).
  right | right index (should be table size - 1).

void qsort_s32 | ( | s32 * | data,
|  | u16 | left,
|  | u16 | right
| ) |  |

Quick sort algo on s32 data array.

Parameters:

  data | s32 data pointer.
  left | left index (should be 0).
  right | right index (should be table size - 1).

void qsort_s8 | ( | s8 * | data,
|  | u16 | left,
|  | u16 | right
| ) |  |

Quick sort algo on s8 data array.

Parameters:

  data | s8 data pointer.
  left | left index (should be 0).
  right | right index (should be table size - 1).

void qsort_u16 | ( | u16 * | data,
|  | u16 | left,
|  | u16 | right
| ) |  |

Quick sort algo on u16 data array.

Parameters:

  data | u16 data pointer.
  left | left index (should be 0).
  right | right index (should be table size - 1).

void qsort_u32 | ( | u32 * | data,
|  | u16 | left,
|  | u16 | right
| ) |  |

Quick sort algo on u32 data array.

Parameters:

  data | u32 data pointer.
  left | left index (should be 0).
  right | right index (should be table size - 1).

void qsort_u8 | ( | u8 * | data,
|  | u16 | left,
|  | u16 | right
| ) |  |

Quick sort algo on u8 data array.

Parameters:

  data | u8 data pointer.
  left | left index (should be 0).
  right | right index (should be table size - 1).

u32 unpack | ( | u16 | compression,
|  | u8 * | src,
|  | u8 * | dest
| ) |  |

Unpack the specified source data buffer in the specified destination buffer.
if source is not packed then nothing is done.

Parameters:

  compression | compression type, accepted values: COMPRESSION_APLIB COMPRESSION_LZ4W
  src | Source data buffer containing the packed data to unpack.
  dest | Destination buffer where to store unpacked data, be sure to allocate enough space.

Returns:
  Unpacked size.

Bitmap* unpackBitmap | ( | const Bitmap * | src,
|  | Bitmap * | dest
| ) |  |

Unpack the specified source Bitmap and return result in a new allocated Bitmap.

Parameters:

  src | bitmap to unpack.
  dest | Destination bitmap where to store unpacked data, be sure to allocate enough space in image buffer. If set to NULL then a dynamic allocated Bitmap is returned.

Returns:
  The unpacked Bitmap.
  If dest was set to NULL then the returned bitmap is allocated in a single bloc and can be released with Mem_Free(bitmap).
  NULL is returned if there is not enough memory to store the unpacked bitmap.

Image* unpackImage | ( | const Image * | src,
|  | Image * | dest
| ) |  |

Unpack the specified Image structure and return result in a new allocated Image.

Parameters:

  src | image to unpack.
  dest | Destination Image where to store unpacked data. If set to NULL then a dynamic allocated Image is returned.

Returns:
  The unpacked Image.
  If dest was set to NULL then the returned image is allocated in a single bloc and can be released with Mem_Free(image).
  NULL is returned if there is not enough memory to store the unpacked image.

TileMap* unpackTileMap | ( | const TileMap * | src,
|  | TileMap * | dest
| ) |  |

Unpack the specified TileMap structure and return result in a new allocated TileMap.

Parameters:

  src | tilemap to unpack.
  dest | Destination tilemap where to store unpacked data, be sure to allocate enough space in tiles and tilemap buffer. If set to NULL then a dynamic allocated TileMap is returned.

Returns:
  The unpacked TileMap.
  If dest was set to NULL then the returned tilemap is allocated in a single bloc and can be released with Mem_Free(tilemap).
  NULL is returned if there is not enough memory to store the unpacked tilemap.

TileSet* unpackTileSet | ( | const TileSet * | src,
|  | TileSet * | dest
| ) |  |

Unpack the specified TileSet structure and return result in a new allocated TileSet.

Parameters:

  src | tiles to unpack.
  dest | Destination TileSet structure where to store unpacked data, be sure to allocate enough space in tiles and tilemap buffer. If set to NULL then a dynamic allocated TileSet is returned.

Returns:
  The unpacked TileSet.
  If dest was set to NULL then the returned tiles base is allocated in a single bloc and can be released with Mem_Free(tb).
  NULL is returned if there is not enough memory to store the unpacked tiles.

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines