-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.c
46 lines (38 loc) · 1.29 KB
/
graphics.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
#include "myLib.h"
#include "graphics.h"
#include "colors.h"
#include "text.h"
volatile unsigned short *videoBuffer = (unsigned short *) 0x6000000;
unsigned int vBlankCounter = 0;
void waitForVblank() {
while (*SCANLINECOUNTER > 160);
while (*SCANLINECOUNTER < 160);
vBlankCounter++;
}
void drawRectangle(int row, int col, int width, int height, volatile unsigned int color) {
for (int r = 0; r < height; r++) {
DMA[3].src = &color;
DMA[3].dst = &videoBuffer[OFFSET(row + r, col, SCREEN_WIDTH)];
DMA[3].cnt = width | DMA_SOURCE_FIXED | DMA_ON;
}
}
void drawFullScreenRectangle(volatile unsigned int color) {
DMA[3].src = &color;
DMA[3].dst = &videoBuffer[0];
DMA[3].cnt = SCREEN_WIDTH * SCREEN_HEIGHT | DMA_SOURCE_FIXED | DMA_ON;
}
void drawImage(int row, int col, int width, int height, const unsigned short* image) {
for (int r = 0; r < height; r++) {
DMA[3].src = &image[OFFSET(r, 0, width)];
DMA[3].dst = &videoBuffer[OFFSET(row + r, col, SCREEN_WIDTH)];
DMA[3].cnt = width | DMA_ON;
}
}
void drawFullScreenImage(const unsigned short* image) {
DMA[3].src = image;
DMA[3].dst = videoBuffer;
DMA[3].cnt = SCREEN_WIDTH * SCREEN_HEIGHT | DMA_ON;
}
void setPixel(int row, int col, unsigned short color) {
videoBuffer[OFFSET(row, col, SCREEN_WIDTH)] = color;
}