summaryrefslogtreecommitdiffstats
path: root/arch/x86/io/VGADisplay.cpp
blob: 0cd0beda78e15aebc11c808e1cbb357314e1ae6a (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
#include "VGADisplay.h"

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;
                   }
    }
};