-
Notifications
You must be signed in to change notification settings - Fork 0
/
deepDisplay.c
145 lines (141 loc) · 4.05 KB
/
deepDisplay.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "address_map_nios2.h"
#include "head.h"
void colorArea(int startRow, int endRow, int startCol, int endCol, short color)
{
for (int currentRow=startRow;currentRow<endRow;currentRow++) //for each row
{
for (int currentCol=startCol;currentCol<endCol;currentCol++) //for each column in that row (every pixel)
{
drawPixel(currentRow,currentCol,color); //color that pixel with the given color
}
}
}
void colorLine(int startRow, int endRow, int startCol, int endCol, short color)
{
int slopesUp = (startRow>endRow); //This tells if a line will slope up or down
if (startCol == endCol) //The slope would be infinity, which would not be possible
{
int currentRow = startRow;
int currentCol = startCol;
while (currentRow<=endRow)
{
drawPixel(currentRow,currentCol,color);
currentRow++;
}
}
else if (startRow == endRow) //the slope would be zero, so nothing would ever change
{
int currentRow = startRow;
int currentCol = startCol;
while (currentCol<=endCol)
{
drawPixel(currentRow,currentCol,color);
currentCol++;
}
}
else //The line is sloped
{
int dRow = endRow-startRow; //The change in row
int dCol = endCol-startCol; //The change in column
//if (slopesUp)
//{
// dRow = -dRow;
//}
float invSlope = (float)dRow/(float)dCol; //The slope
int currentRow = startRow;
int currentCol = startCol;
//So, we want to at least one pixel on every row/col
if (invSlope>1)
{
float floatCol = (float)currentCol; //Taking a general approximation of the current column
while (((!slopesUp) & (currentRow<=endRow)) | (slopesUp & (currentRow>=endRow)))
{
drawPixel(currentRow,currentCol,color); //Draws a pixel at the most general column
currentRow++;
floatCol+=1/invSlope;
currentCol = (int)floatCol;
}
}
else
{
float floatRow = (float)currentRow;
while (currentCol<=endCol)
{
drawPixel(currentRow,currentCol,color);
currentCol++;
floatRow+=invSlope;
currentRow = (int)floatRow;
}
}
}
}
void drawPixel(int row,int col,short color) //The very general method for deciding the color of a pixel
{
volatile short * pixel_address = (volatile short *)(0x08000000 + (row<<10)+(col<<1));
*pixel_address = color;
}
short getPixel(int row, int col)
{
volatile short * pixel_address = (volatile short *)(0x08000000 + (row<<10)+(col<<1));
return *pixel_address;
}
void displayDialogue(char * text_ptr)
{
clearDialogue(); //removes dialogue already there
int startRow = 40;//was 30. I think this is unrelated to the pixel thing?
int startCol = 5;
int offset = (startRow << 7) + startCol;
volatile char * character_buffer = (char *) FPGA_CHAR_BASE; // VGA character buffer
int charCounter = 0;
int readyForNewLine = 0;
volatile int pauseTime = 30000;
while ( *(text_ptr) ) //while there is still dialogue left in the array
{
pause(pauseTime);
*(character_buffer + offset) = *(text_ptr); // write to the character buffer
++text_ptr;
++offset;
++charCounter;
//updating all values
if ((charCounter == 50) || (charCounter == 100)) //This tells that the dialogue is almost off-screen
{
readyForNewLine = 1;
}
int charIsSpace = 0;
if ((char)*(text_ptr) == ' ')
{
charIsSpace = 1; //Tells if the current char is just a space
}
if (charIsSpace && readyForNewLine) //If the current char is space and the next line should be used, change rows
{
int rowDiff = (charCounter/50);
offset = ((startRow+rowDiff)<<7)+startCol;
readyForNewLine=0;
/*if (charCounter>100)
{
offset = ((startRow+2)<<7)+startCol;
readyForNewLine = 0;
}
else if (charCounter>50)
{
offset = ((startRow+1)<<7)+startCol;//tbh dunno what I'm doing here
readyForNewLine = 0;
}*/
}
}
}
void clearDialogue() //Removes all current dialogue
{
int startRow = 40;
int startCol = 5;
volatile char * character_buffer = (char *) FPGA_CHAR_BASE; // VGA character buffer
for (int startRow=40;startRow<45;startRow++)
{
int offset = (startRow << 7) + startCol;
for (int i=0;i<100;i++)
{
*(character_buffer + offset) = ' '; // write to the character buffer
++offset;
}
}
}