-
Notifications
You must be signed in to change notification settings - Fork 3
/
mylib.h
97 lines (81 loc) · 2.53 KB
/
mylib.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Patrick Stoica
/* Aliases */
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
/* Images */
/* Buttons */
#define BUTTON_A (1<<0)
#define BUTTON_B (1<<1)
#define BUTTON_SELECT (1<<2)
#define BUTTON_START (1<<3)
#define BUTTON_RIGHT (1<<4)
#define BUTTON_LEFT (1<<5)
#define BUTTON_UP (1<<6)
#define BUTTON_DOWN (1<<7)
#define BUTTON_R (1<<8)
#define BUTTON_L (1<<9)
/* GBA Settings */
#define REG_DISPCTL *(u16 *)0x4000000
#define RGB(r, g, b) ((r) | (g)<<5 | (b)<<10)
#define MODE3 3
#define BG2_ENABLE (1<<10)
#define BUTTONS (*( unsigned int *)0x04000130)
#define BUTTON_MASK 0x03FF
#define KEY_HIT(key) ((__key_curr & ~__key_prev) & key)
#define KEY_HELD(key) ((__key_curr & __key_prev) & key)
#define SCANLINECOUNTER (*(unsigned short *)0x4000006)
#define OFFSET(r, c, rowlen) ((r)*(rowlen)+(c))
/* Colors */
#define RED RGB(31,0,0)
#define GREEN RGB(0,31,0)
#define BLUE RGB(0,0,31)
#define YELLOW RGB(31,31,0)
#define ORANGE RGB(31,20,0)
#define PURPLE RGB(31,0,31)
#define CYAN RGB(0,31,31)
#define BLACK 0
#define WHITE RGB(31,31,31)
#define LTGREY RGB(12, 12, 12)
#define BGCOLOR LTGREY
#define BOARDCOLOR BLACK
/* External Variables */
extern u16 *videoBuffer;
extern u16 __key_curr, __key_prev;
/* DMA */
typedef struct {
const volatile void *src;
volatile void *dst;
volatile u32 cnt;
} DMAREC;
#define DMA ((volatile DMAREC *)0x040000B0)
/* Defines */
#define DMA_CHANNEL_0 0
#define DMA_CHANNEL_1 1
#define DMA_CHANNEL_2 2
#define DMA_CHANNEL_3 3
// Note: The next 4 lines can tell you the default: DMA_DESTINATION_INCREMENT
// as well as which bits are used for this (i.e. 22 and 21)
#define DMA_DESTINATION_INCREMENT (0 << 21)
#define DMA_DESTINATION_DECREMENT (1 << 21)
#define DMA_DESTINATION_FIXED (2 << 21)
#define DMA_DESTINATION_RESET (3 << 21)
#define DMA_SOURCE_INCREMENT (0 << 23)
#define DMA_SOURCE_DECREMENT (1 << 23)
#define DMA_SOURCE_FIXED (2 << 23)
#define DMA_REPEAT (1 << 25) // Used for sound
#define DMA_16 (0 << 26) // Typically use this
#define DMA_32 (1 << 26)
#define DMA_NOW (0 << 28) // Typically use this
#define DMA_AT_VBLANK (1 << 28)
#define DMA_AT_HBLANK (2 << 28)
#define DMA_AT_REFRESH (3 << 28)
#define DMA_IRQ (1 << 30)
#define DMA_ON (1 << 31) // The on switch!!!!
/* mylib.c */
void setPixel(int r, int c, u16 color);
void drawRect(int r, int c, int width, int height, u16 color);
void waitForVblank();
void drawImage3(int r, int c, int width, int height, const u16*
image);
void drawRect3(int r, int c, int width, int height, u16 color);