-
Notifications
You must be signed in to change notification settings - Fork 0
/
myLib.c
65 lines (55 loc) · 1.84 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
57
58
59
60
61
62
63
#include "myLib.h"
#include "text.h"
unsigned short *videoBuffer = (unsigned short *)0x6000000;
// 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;
}
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;
}
}
// 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 draw_image_portion(int destination_row, int destination_col, int source_row, int source_col, int source_width, int source_height, const u16* image, int image_width)
{
for (int x = 0; x < source_height; x++) {
DMA[3].src = &image[OFFSET(x + source_row, source_col, image_width)];
DMA[3].dst = &videoBuffer[OFFSET(destination_row + x, destination_col, 240)];
DMA[3].cnt = (source_width) | DMA_ON;
}
}