aboutsummaryrefslogtreecommitdiff
path: root/arm9/source/bang.h
blob: b85e9cd94ee2c9730914902cb975480f4fbbf452 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef BANG_H_
    #define BANG_H_

    #include <nds.h>


    // Read and write individual bytes from a 32-bit value.
    #define SETHH(v,h)     v = h << 24 | (v & 0x00ffffff)
    #define SETHL(v,l)     v = l << 16 | (v & 0xff00ffff)
    #define SETLH(v,h)     v = h <<  8 | (v & 0xffff00ff)
    #define SETLL(v,l)     v = l       | (v & 0xffffff00)
    #define GETHH(v)       (u8)((v) >> 24)
    #define GETHL(v)       (u8)((v) >> 16)
    #define GETLH(v)       (u8)((v) >>  8)
    #define GETLL(v)       (u8)((v)      )
    // Aliases for use on 16-bit values.
    #define SETH(v,h)      SETLH(v,h)
    #define SETL(v,l)      SETLL(v,l)
    #define GETH(v)        GETLH(v)
    #define GETL(v)        GETLL(v)
    // Test if all bits of a mask are set in a value.
    #define TEST(v,m)     ((v & m) == m)
    // Convert a C-style boolean to a Bedrock-style boolean.
    #define BOOL(v)       ((u8)-(v))
    // Merge two bytes together as a double.
    #define DOUBLE(h,l)   ((u16)(h) << 8 | (u16)(l))
    // Extract the high and low bytes of a double.
    #define HIGH(v)       (u8)(v >> 8)
    #define LOW(v)        (u8)(v)
    // Find the highest or lowest value of a pair.
    #define MAX(x,y)      (x>y ? x : y)
    #define MIN(x,y)      (x<y ? x : y)

    // Functions.
    u8 ROL1(u8 v, u8 d);
    u16 ROLD(u16 v, u8 d);
    u8 ROR1(u8 v, u8 d);
    u16 RORD(u16 v, u8 d);
#endif