-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.cpp
More file actions
181 lines (154 loc) · 3.3 KB
/
Copy pathscreen.cpp
File metadata and controls
181 lines (154 loc) · 3.3 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <types.h>
#include <screen.h>
Screen::Screen(char * position, int x_size, int y_size)
{
video = position;
size_x = x_size;
size_y = y_size;
}
void Screen::clear()
{
int i;
y = (size_y - 1);
for(i = 0; i < size_y; i++)
{
newline();
}
y = 0;
x = 0;
}
void Screen::setcolor(unsigned char color_to_set)
{
color = color_to_set;
}
void Screen::newline()
{
//Cursor an den Anfang der nächsten Zeile setzen
x = 0;
y++;
//Wir sind am Ende des Bildschirms angekommen, Inhalt eine Zeile nach oben schieben.
if(y == size_y)
{
char * source = video + (2 * (size_x));
char * target = video;
int i;
for(i = 0; i < (2 * ((size_x * 24))); i++)
{
*target++ = *source++;
}
y--;
//Die letzte Zeile wird geleert.
target = video + (2 * size_x * (size_y - 1));
for(i = 0; i < size_x; i++)
{
*target++ = ' ';
*target++ = color;
}
}
}
void Screen::putcharxy(char char_to_put, int x, int y)
{
char * tmpvideo = video + (2 * ((y * size_x) + x));
*tmpvideo = char_to_put;
}
void Screen::print_char(char char_to_put)
{
char * tmpvideo = video + (2 * ((y * size_x) + x));
switch(char_to_put)
{
case 0x0a:
newline();
break;
default:
*tmpvideo++ = char_to_put;
*tmpvideo = color;
x++;
if(x == size_x)
{
newline();
}
break;
}
}
void Screen::print_string(char *string)
{
//Putchar until the null-byte is reached.
while(*string)
{
print_char(*string++);
}
}
void Screen::print_string(const char *string)
{
Screen::print_string((char *)string);
}
void Screen::print_number(unsigned long int number, unsigned int base)
{
const char *digits = "0123456789ABCDEFGHIJKLMNOP";
char buffer[33];
char *pos = ((char *) &buffer) + 32;
*pos-- = '\0';
//while(number || pos == ((char *) &buffer) + 31)
while(number)
{
*pos-- = *(digits + (number % base));
number = number / base;
}
print_string(++pos);
}
void Screen::print_number(signed long int number, unsigned int base)
{
print_char(number < 0 ? '-' : '+');
if(number < 0)
{
print_char('-');
print_number((unsigned long int) (0 - number), base);
}
else
{
print_number((unsigned long int) number, base);
}
}
void Screen::printf(const char *format, ...)
{
unsigned long int *parameter = (unsigned long int *)&format;
while(*format)
{
switch(*format)
{
case '%':
switch(*(++format))
{
case '\0':
format--;
break;
case '%':
print_char('%');
break;
case 'b':
print_number(*(parameter = (unsigned long *)((unsigned long)parameter + sizeof(unsigned long *))), 2);
break;
case 'o':
print_number(*(parameter = (unsigned long *)((unsigned long)parameter + sizeof(unsigned long *))), 8);
break;
case 'd':
print_number(*(parameter = (unsigned long *)((unsigned long)parameter + sizeof(unsigned long *))), 10);
break;
case 'h':
case 'x':
print_number(*(parameter = (unsigned long *)((unsigned long)parameter + sizeof(unsigned long *))), 16);
break;
case 's':
print_string(*(const char **)(parameter = (unsigned long *)((unsigned long)parameter + sizeof(unsigned long *))));
break;
default:
print_char('%');
print_char(*format);
}
break;
default:
print_char(*format);
}
format++;
}
}