-
Notifications
You must be signed in to change notification settings - Fork 3
/
mylib.c
56 lines (49 loc) · 1.47 KB
/
mylib.c
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
// Patrick Stoica
#include "mylib.h"
u16 *videoBuffer = (u16 *) 0x6000000; // start of the video buffer
// Key state globals
u16 __key_curr = 0, __key_prev = 0;
// A function to set pixel (r, c) to the color passed in
void setPixel(int r, int c, u16 color) {
videoBuffer[OFFSET(r, c, 240)] = color;
}
// A function to draw a FILLED rectangle starting at (r, c)
void drawRect(int r, int c, int width, int height, u16 color) {
// we're basically looping through pixel by pixel
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
setPixel(r + i, c + j, color);
}
}
}
void waitForVblank() {
while(SCANLINECOUNTER > 160);
while(SCANLINECOUNTER < 160);
}
/* drawImage3
* A function that will draw an arbitrary sized image
* onto the screen (with DMA).
* @param r row to draw the image
* @param c column to draw the image
* @param width width of the image
* @param height height of the image
* @param image Pointer to the first element of the image.
*/
void drawImage3(int r, int c, int width, int height, const u16*
image) {
for (int x = 0; x < height; x++) {
DMA[3].src = &image[OFFSET(x, 0, width)];
DMA[3].dst = &videoBuffer[OFFSET(r + x, c, 240)];
DMA[3].cnt = (width) | DMA_ON;
}
}
/* drawRect3
* A DMA Implementation of drawRect
*/
void drawRect3(int r, int c, int width, int height, u16 color) {
for (int x = 0; x < height; x++) {
DMA[3].src = &color;
DMA[3].dst = &videoBuffer[OFFSET(r + x, c, 240)];
DMA[3].cnt = (width) | DMA_SOURCE_FIXED | DMA_ON;
}
}