blob: 179b821f9d6972527a1e148634657135e46acc7c (
plain)
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
|
#include "./memPrint.hpp"
//Constructor
memPrint::memPrint(){
//Initialise position
this->m_cursorX=0;
this->m_cursorY=0;
//Initialise color
this->setBackground(BLACK);
this->setForeground(WHITE);
}
//Destructor
memPrint::~memPrint(){
}
//Move cursor
void memPrint::updateCursor(){
//Update X axis
this->m_cursorX++;
//Check X value
if(this->m_cursorX >= MAXCURSORX){
//If X is out of the screen
this->m_cursorX=0;
//Update Y
this->m_cursorY++;
//Check Y value
if(this->m_cursorY >= MAXCURSORY){
//If Y is out of the screen
this->scrollUp(1);
//Decrease Y value
this->m_cursorY--;
}
}
}
//Change character background color
void memPrint::setBackground(colorBios color){
u8 newColor= (color << 4);
this->m_colors= newColor | ((this->m_colors << 4) >> 4);
}
//Change character color
void memPrint::setForeground(colorBios color){
u8 newColor= color;
this->m_colors= newColor | ((this->m_colors >> 4) << 4);
}
//Print a char
void memPrint::putChar(u8 character){
//Get the adresse with the cursor position
char *adress= ((char *) MEMPRINTSTARTADR) + (this->m_cursorX * 2) + (this->m_cursorY * MAXCURSORX * 2);
//Copy the character
*adress=character;
//Copy his attribute
adress++;
*adress=this->m_colors;
//Update cursor position
this->updateCursor();
}
//Print a char*
void memPrint::print(char *str){
while(*str!=0x0){
this->putChar(*str);
str++;
}
}
//Clear the screen
void memPrint::clear(){
this->scrollUp(MAXCURSORY);
}
//Scroll up "number" times
void memPrint::scrollUp(u8 number){
//Get number of adress (char & his attribute) to scroll
int nbAdrToScroll=number*MAXCURSORX*2;
//Scroll all of the characters and attributes
for(int i=0;i!=MAXCURSORX*2*MAXCURSORY;i++){
//Get source character or attribute
char* source=(((char *)MEMPRINTSTARTADR) + i);
//Get destination character or attribute
char* dest=source-nbAdrToScroll;
//Check if destination is out of the screen
if(dest >= (char *)MEMPRINTSTARTADR)
*dest=*source;
//Remove data from source
*source=0x0;
}
}
|