SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
tools.h File Reference

Misc tools methods. More...

#include "bmp.h"
#include "vdp.h"
#include "vdp_tile.h"
#include "vdp_bg.h"
#include "map.h"
Include dependency graph for tools.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#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.
 
#define BLASTEM_PROFIL_START   VDP_setReg(0x9F, 0xC0);
 Simple cycle counter tool from BlastEm - start cycle count (see BLASTEM_PROFIL_END)
 
#define BLASTEM_PROFIL_END   VDP_setReg(0x9F, 0x00);
 Simple cycle counter tool from BlastEm - stop cycle count and display result in console.
 

Typedefs

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

Functions

void setRandomSeed (u16 seed)
 Set the randomizer seed (to allow different reproductible series)
 
u16 random (void)
 Returns a random u16 integer value.
 
int kprintf (const char *fmt,...) __attribute__((format(printf
 Composes a string with the same text that would be printed if format was used on printf, but instead of being printed to screen, the content is printed in KMod console.
 
int 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)
 
BitmapallocateBitmap (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.
 
BitmapallocateBitmapEx (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.
 
TileSetallocateTileSet (const TileSet *tileset)
 Allocate TileSet structure which can receive unpacked tiles data of the specified TileSet.
 
TileSetallocateTileSetEx (u16 numTile)
 Allocate a new TileSet structure which can receive the data for the specified number of tile.
 
TileMapallocateTileMap (const TileMap *tilemap)
 Allocate TileMap structure which can receive unpacked tilemap data of the specified TileMap.
 
TileMapallocateTileMapEx (u16 width, u16 heigth)
 Allocate a new TileMap structure which can receive tilemap data for the specified TileMap dimension.
 
ImageallocateImage (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.
 
MapallocateMap (const MapDefinition *mapDef)
 Allocate Map structure which can receive unpacked data of the specified MapDefinition.
 
BitmapunpackBitmap (const Bitmap *src, Bitmap *dest)
 Unpack the specified source Bitmap and return result in a new allocated Bitmap.
 
TileSetunpackTileSet (const TileSet *src, TileSet *dest)
 Unpack the specified TileSet structure and return result in a new allocated TileSet.
 
TileMapunpackTileMap (const TileMap *src, TileMap *dest)
 Unpack the specified TileMap structure and return result in a new allocated TileMap.
 
ImageunpackImage (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

◆ _comparatorCallback

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

◆ allocateBitmap()

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
bitmapSource 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.

◆ allocateBitmapEx()

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
widthWidth in pixel of the bitmap structure we want to allocate.
heigthheigth 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.

◆ allocateImage()

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
imageSource 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.

◆ allocateMap()

Map * allocateMap ( const MapDefinition * mapDef)

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

Parameters
mapDefSource 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.

◆ allocateTileMap()

TileMap * allocateTileMap ( const TileMap * tilemap)

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

Parameters
tilemapSource 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.

◆ allocateTileMapEx()

TileMap * allocateTileMapEx ( u16 width,
u16 heigth )

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

Parameters
widthWidth in tile of the TileMap structure we want to allocate.
heigthheigth 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.

◆ allocateTileSet()

TileSet * allocateTileSet ( const TileSet * tileset)

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

Parameters
tilesetSource 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.

◆ allocateTileSetEx()

TileSet * allocateTileSetEx ( u16 numTile)

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

Parameters
numTileNumber 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.

◆ aplib_unpack()

u32 aplib_unpack ( u8 * src,
u8 * dest )

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

Parameters
srcSource data buffer containing the packed data (aplib packer) to unpack.
destDestination buffer where to store unpacked data, be sure to allocate enough space.
Returns
Unpacked size.
Here is the call graph for this function:

◆ KLog()

int void KLog ( char * text)

KDebug log helper methods.

◆ kprintf()

int kprintf ( const char * fmt,
... )

Composes a string with the same text that would be printed if format was used on printf, but instead of being printed to screen, the content is printed in KMod console.

Parameters
fmtC string that contains the text to be written to destination string.
It can optionally contain embedded format specifiers.
...(additional arguments) Depending on the format string, the function may expect a sequence of additional arguments,
each containing a value to be used to replace a format specifier in the format string.

There should be at least as many of these arguments as the number of values specified in the format specifiers.
Additional arguments are ignored by the function.

Returns
On success, the total number of characters written (limited to 255 max)

Copy the string pointed by 'fmt' param to KMod console.
If 'fmt' includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.
Note that internally a buffer of 255 characters is allocated so consider this limitation !

◆ lz4w_unpack()

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

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

Parameters
srcSource data buffer containing the packed data (LZ4W packed) to unpack.
destDestination 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.
Here is the call graph for this function:

◆ qsort()

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

Quick sort algo on array of pointer (object)

Parameters
dataarray of pointer (pointer of object to sort).
lennumber of element in the data array
cbcomparator callback used to compare 2 objects.
Here is the call graph for this function:

◆ qsort_s16()

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

Quick sort algo on s16 data array.

Parameters
datas16 data pointer.
leftleft index (should be 0).
rightright index (should be table size - 1).
Here is the call graph for this function:

◆ qsort_s32()

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

Quick sort algo on s32 data array.

Parameters
datas32 data pointer.
leftleft index (should be 0).
rightright index (should be table size - 1).
Here is the call graph for this function:

◆ qsort_s8()

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

Quick sort algo on s8 data array.

Parameters
datas8 data pointer.
leftleft index (should be 0).
rightright index (should be table size - 1).
Here is the call graph for this function:

◆ qsort_u16()

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

Quick sort algo on u16 data array.

Parameters
datau16 data pointer.
leftleft index (should be 0).
rightright index (should be table size - 1).
Here is the call graph for this function:

◆ qsort_u32()

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

Quick sort algo on u32 data array.

Parameters
datau32 data pointer.
leftleft index (should be 0).
rightright index (should be table size - 1).
Here is the call graph for this function:

◆ qsort_u8()

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

Quick sort algo on u8 data array.

Parameters
datau8 data pointer.
leftleft index (should be 0).
rightright index (should be table size - 1).
Here is the call graph for this function:

◆ unpack()

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
compressioncompression type, accepted values:
COMPRESSION_APLIB
COMPRESSION_LZ4W
srcSource data buffer containing the packed data to unpack.
destDestination buffer where to store unpacked data, be sure to allocate enough space.
Returns
Unpacked size.
Here is the call graph for this function:

◆ unpackBitmap()

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

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

Parameters
srcbitmap to unpack.
destDestination 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.
Here is the call graph for this function:

◆ unpackImage()

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

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

Parameters
srcimage to unpack.
destDestination 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.

◆ unpackTileMap()

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

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

Parameters
srctilemap to unpack.
destDestination 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.
Here is the call graph for this function:

◆ unpackTileSet()

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

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

Parameters
srctiles to unpack.
destDestination 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.
Here is the call graph for this function: