-
Notifications
You must be signed in to change notification settings - Fork 0
/
mylib.c
79 lines (66 loc) · 1.75 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
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "list.h"
#include "mylib.h"
#include <string.h>
#include <debugging.h>
/*Sets pixel(r,c) to the given color*/
void setPixel(int r, int c, u16 color){
*(videoBuffer + OFFSET(r,c,240)) = color;
}
/*Draws a filled rectangle of the given color with the
given width at (r,c)
*/
void drawRect(int r, int c, int width, int height, u16 color){
int w;
int h;
//draw the rectangle
for(h = 0; h < height; h++){
for(w = 0; w < width; w++){
setPixel(h + r, w + c, color);
}
}
}
/*Draws an outline of a rectangle of the given color
with a given width and height at (r,c)
*/
void drawHollowRect(int r, int c, int width, int height, u16 color){
int w;
int h;
//draw the rectangle
for(h = 0; h < height; h++){
for(w = 0; w < width; w++){
//set the pixel only if the current pixel is on the outer edges
//i.e. on the first or last row, or the first or last column
if((h == 0 || h == (height - 1)) || (w == 0 || w == (width - 1))){
setPixel(h + r, w + c, color);
}
}
}
}
void drawImage3(int r, int c, int width, int height, int image){
int h;
for(h = 0; h < height; h++){
//memmove(videoBuffer + OFFSET(r + h, c, 240), image, width * sizeof(u16));
int color[] = {image};
DMA[3].src = color;
DMA[3].dst = videoBuffer + OFFSET(r + h, c, 240);
DMA[3].cnt = (width) | DMA_SOURCE_FIXED | DMA_ON;
}
/*DMA[3].src = image;
DMA[3].dst = videoBuffer + OFFSET(r,c,240);
DMA[3].cnt = ((width * height) / 4) | DMA_ON;*/
}
void delay(int n){
int i;
volatile int x = 0;
for(i = 0; i < n*10000; i++){x++;}
}
void waitForVblank(){
while(SCANLINECOUNTER > 160);
while(SCANLINECOUNTER < 160);
}
void clearScreen(){
int clear[] = {BLACK};
DMA[3].src = clear;
DMA[3].dst = videoBuffer;
DMA[3].cnt = (240 * 160) | DMA_SOURCE_FIXED | DMA_ON;
}