GBDK 2020 Docs API Documentation for GBDK 2020

Macros | Typedefs | Functions
bcd.h File Reference
`#include <asm/types.h>`

Go to the source code of this file.

## Macros
#define | BCD_HEX(v) ((BCD)(v))
#define | MAKE_BCD(v) BCD_HEX(0x ## v)

## Typedefs
typedef unsigned long | BCD

## Functions
void | uint2bcd (unsigned int i, BCD *value)
void | bcd_add (BCD *sour, const BCD *value)
void | bcd_sub (BCD *sour, const BCD *value)
UBYTE | bcd2text (const BCD *bcd, UBYTE tile_offset, unsigned char *buffer)

## Detailed Description

Support for working with BCD (Binary Coded Decimal)

See the example BCD project for additional details.

## Macro Definition Documentation

## ◆ BCD_HEX

#define BCD_HEX | ( |  | v | ) | ((BCD)(v))

## ◆ MAKE_BCD

#define MAKE_BCD | ( |  | v | ) | BCD_HEX(0x ## v)

Converts an integer value into BCD format

A maximum of 8 digits may be used

## Typedef Documentation

## ◆ BCD

typedef unsigned long BCD

## Function Documentation

## ◆ uint2bcd()

void uint2bcd | ( | unsigned int | i,
|  | BCD * | value
| ) |  |

Converts integer i into BCD format (Binary Coded Decimal)

Parameters

  i | Numeric value to convert
  value | Pointer to a BCD variable to store the converted result

## ◆ bcd_add()

void bcd_add | ( | BCD * | sour,
|  | const BCD * | value
| ) |  |

Adds two numbers in BCD format: sour += value

Parameters

  sour | Pointer to a BCD value to add to (and where the result is stored)
  value | Pointer to the BCD value to add to sour

## ◆ bcd_sub()

void bcd_sub | ( | BCD * | sour,
|  | const BCD * | value
| ) |  |

Subtracts two numbers in BCD format: sour -= value

Parameters

  sour | Pointer to a BCD value to subtract from (and where the result is stored)
  value | Pointer to the BCD value to subtract from sour

## ◆ bcd2text()

UBYTE bcd2text | ( | const BCD * | bcd,
|  | UBYTE | tile_offset,
|  | unsigned char * | buffer
| ) |  |

Convert a BCD number into an asciiz (null terminated) string and return the length

Parameters

  bcd | Pointer to BCD value to convert
  tile_offset | Optional per-character offset value to add (use 0 for none)
  buffer | Buffer to store the result in

Returns: Length in characters (always 8)

buffer should be large enough to store the converted string (9 bytes: 8 characters + 1 for terminator)

There are a couple different ways to use tile_offset. For example:

- It can be the Index of the Font Tile '0' in VRAM to allow the buffer to be used directly with set_bkg_tiles.
- It can also be set to the ascii value for character '0' so that the buffer is a normal string that can be passed to printf.