gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/include/gb/bcd.h
1 #ifndef __BCD_H_INCLUDE
2 #define __BCD_H_INCLUDE
3
4 #include <types.h>
5 #include <stdint.h>
6
7 /** @file bcd.h
8 Support for working with BCD (Binary Coded Decimal)
9
10 See the example BCD project for additional details.
11 */
12
13 // macro for creating BCD constants
14 #define BCD_HEX(v) ((BCD)(v))
15
16 /** Converts an integer value into BCD format
17
18 A maximum of 8 digits may be used
19 */
20 #define MAKE_BCD(v) BCD_HEX(0x ## v)
21
22 typedef uint32_t BCD;
23
24 /** Converts integer __i__ into BCD format (Binary Coded Decimal)
25 @param i Numeric value to convert
26 @param value Pointer to a BCD variable to store the converted result
27 */
28 void uint2bcd(uint16_t i, BCD * value) OLDCALL;
29
30 /** Adds two numbers in BCD format: __sour__ += __value__
31 @param sour Pointer to a BCD value to add to (and where the result is stored)
32 @param value Pointer to the BCD value to add to __sour__
33 */
34 void bcd_add(BCD * sour, const BCD * value) OLDCALL;
35
36 /** Subtracts two numbers in BCD format: __sour__ -= __value__
37 @param sour Pointer to a BCD value to subtract from (and where the result is stored)
38 @param value Pointer to the BCD value to subtract from __sour__
39 */
40 void bcd_sub(BCD * sour, const BCD * value) OLDCALL;
41
42 /** Convert a BCD number into an asciiz (null terminated) string and return the length
43 @param bcd Pointer to BCD value to convert
44 @param tile_offset Optional per-character offset value to add (use 0 for none)
45 @param buffer Buffer to store the result in
46
47 Returns: Length in characters (always 8)
48
49 __buffer__ should be large enough to store the converted string
50 (9 bytes: 8 characters + 1 for terminator)
51
52 There are a couple different ways to use __tile_offset__.
53 For example:
54 \li It can be the Index of the Font Tile '0' in VRAM to
55 allow the buffer to be used directly with @ref set_bkg_tiles.
56 \li It can also be set to the ascii value for character '0'
57 so that the buffer is a normal string that can be passed to @ref printf.
58 */
59 uint8_t bcd2text(const BCD * bcd, uint8_t tile_offset, uint8_t * buffer) OLDCALL;
60
61 #endif
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.