summaryrefslogtreecommitdiff
path: root/arm9/source/bang.h
blob: 110e2430af6e7cdc1a73cad09910a3402386dc16 (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
#ifndef BANG_H_
    #define BANG_H_

    #define SET_HIGH(v,high)   v = high << 8 | (v & 0x00ff)
    #define SET_LOW(v,low)     v = (v & 0xff00) | low
    #define HIGH(v)            (u8)((v) >> 8)
    #define LOW(v)             (u8)((v)     )

    #define SET_H_HIGH(v,high) v = high << 24 | (v & 0x00ffffff)
    #define SET_H_LOW(v,low)   v = low  << 16 | (v & 0xff00ffff)
    #define SET_L_HIGH(v,high) v = high <<  8 | (v & 0xffff00ff)
    #define SET_L_LOW(v,low)   v = low        | (v & 0xffffff00)
    #define H_HIGH(v)          (u8)((v) >> 24)
    #define H_LOW(v)           (u8)((v) >> 16)
    #define L_HIGH(v)          (u8)((v) >>  8)
    #define L_LOW(v)           (u8)((v)      )

    #define LEFT(x)       ((x) >> 4)
    #define RIGHT(x)      ((x) & 0xf)

    #define SHF(x,y)      (x >> RIGHT(y) << LEFT(y))
    #define TAL(x)        __builtin_popcount(x)

    #define TEST(x,m)     ((x & m) == m)
    #define BOOL(v)       ((u8)-(v))
    #define DOUBLE(h,l)   ((u16)(h) << 8 | (u16)(l))

    u8 rev(u8 x);
    u8 shc(u8 x, u8 y);
    u16 shcd(u16 x, u8 y);
#endif