blob: 50fd4b75005afbcaab2fbd5492cc5b6cb26a1314 (
plain) (
blame)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/**
* Copyright (c) 2026 Alexey Gavrilov <alexey.gavrilov@mail.com>
*
* This file is part of ObjectiveOS.
*
* ObjectiveOS is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* ObjectiveOS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* ObjectiveOS. If not, see <https://www.gnu.org/licenses/>.
*/
#include "VGADisplay.h"
VGADisplay out::display;
VGADisplay::VGADisplay()
{
isBright = isBlink = shift = 0;
xCurr = yCurr = 0;
color = (char)VGADisplayInfo::colorAttr::gray;
videoMem = (dchar *)VGADisplayInfo::videoMemAddr;
};
VGADisplay::VGADisplay(uint16 x, uint16 y)
{
isBright = isBlink = shift = 0;
xCurr = yCurr = 0;
color = (char)VGADisplayInfo::colorAttr::gray;
videoMem = (dchar *)VGADisplayInfo::videoMemAddr;
};
VGADisplay& VGADisplay::operator<<(const char &c)
{
printChar(c);
return *this;
};
VGADisplay& VGADisplay::operator<<(const uint32 number)
{
IntConverter conv;
(*this) << conv.uintToChar(number);
return *this;
};
VGADisplay& VGADisplay::operator<<(const uint64 number)
{
IntConverter conv;
(*this) << conv.uintToChar(number);
return *this;
};
VGADisplay& VGADisplay::operator++(int)
{
if(++xCurr == VGADisplayInfo::width)
{
yCurr++;
xCurr = 0;
}
if(yCurr == VGADisplayInfo::height)
{
if(shift)
{
this->doShift();
xCurr = 0;
yCurr--;
}
else xCurr = 0, yCurr = 0;
}
videoMem = (dchar *)(VGADisplayInfo::videoMemAddr)
+ yCurr * VGADisplayInfo::width + xCurr;
return *this;
};
VGADisplay& VGADisplay::operator<<(const char *c)
{
for(int i = 0; c[i] != '\0'; i++)
{
(*this) << c[i];
}
return *this;
};
void VGADisplay::doShift()
{
for(uint16 i = 0; i < VGADisplayInfo::height; i++)
{
for(uint16 j = 0; j < VGADisplayInfo::width; j++)
{
*((dchar *)(VGADisplayInfo::videoMemAddr) + (i - 1) * VGADisplayInfo::width + j) = *((dchar *)(VGADisplayInfo::videoMemAddr) + i * VGADisplayInfo::width + j);
*((dchar *)(VGADisplayInfo::videoMemAddr) + i * VGADisplayInfo::width + j) = (*((dchar *)(VGADisplayInfo::videoMemAddr) + i * VGADisplayInfo::width + j) & 0x00) | ' ';
}
}
};
void VGADisplay::setShift(bool status)
{
shift = status;
};
void VGADisplay::setColor(char colorAttr)
{
color = colorAttr;
};
void VGADisplay::setBlink(bool blinkAttr)
{
isBlink = blinkAttr;
};
void VGADisplay::setBright(bool brigthAttr)
{
isBright = brigthAttr;
};
void VGADisplay::goNewLine()
{
uint16 yCurrOld = yCurr;
while(yCurrOld == yCurr) (*this)++;
};
void VGADisplay::goHorizontalTab()
{
while(xCurr % 8 != 0) (*this)++;
};
bool VGADisplay::printChar(const char &c)
{
switch(c)
{
case '\0': return true;
case '\n': this->goNewLine(); return true;
case '\t': this->goHorizontalTab(); return true;
default:
{
char attr = isBlink << 8 | isBright << 4
| color;
*videoMem = c | attr << 8;
(*this)++;
return false;
}
}
};
void VGADisplay::clearScreen()
{
xCurr = yCurr = 0;
videoMem = (dchar *)VGADisplayInfo::videoMemAddr;
uint16 maxPos = VGADisplayInfo::height * VGADisplayInfo::width * 2;
for(uint16 pos = 0; pos < maxPos; pos++) *this << ' ';
};
|