-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.c
162 lines (144 loc) · 4.89 KB
/
output.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "globals.h"
void outb(unsigned short port, unsigned char value) {
__asm__ (
"mov AL, [EBP+12]\n"
"mov DX, [EBP+8]\n"
"outb DX, AL\n"
);
}
void Delay()
{
unsigned int i = 0x400000;
while(i-- > 0) {}
}
void DisplayColourArea(unsigned char BackgroundColour, unsigned char ForegroundColour, unsigned int start, unsigned int length)
{
unsigned char Colour;
Colour = ((BackgroundColour << 4) & 0xF0) | (ForegroundColour & 0x0F);
unsigned short* DisplayMemoryPtr = (unsigned short*)0xB8000;
unsigned int i = start;
while(i < DISPLAY_SIZE && i < start + length)
{
DisplayMemoryPtr[i++] = (((unsigned short)Colour) << 8) | 0x00;
}
}
void DisplayColour(unsigned char BackgroundColour, unsigned char ForegroundColour)
{
DisplayColourArea(BackgroundColour, ForegroundColour, 0, DISPLAY_SIZE);
Delay();
}
// unsigned short* displayMemoryPointer = (unsigned short*) 0xB8000;
// int i;
// for(i = 0; i < DISPLAY_SIZE - 80; i++) {
// displayMemoryPointer[i] = displayMemoryPointer[i + 80];
// }
// for(i = DISPLAY_SIZE - 1; i > DISPLAY_SIZE - 80; i--) {
// displayMemoryPointer[i] = 0x0000;
// }
//}
//void print(char text[]) {
// static unsigned int currentLocation = 0;
//
// unsigned short* displayMemoryPtr = (unsigned short*)0xB8000;
//
// int i;
// for(i = 0; text[i] != 0; i++) {
// if(currentLocation == DISPLAY_SIZE) {
// shiftTextUpOneLine();
// currentLocation -= 80;
// }
//
// if(text[i] == '\n') {
// currentLocation += (80 - (currentLocation % 80));
// } else if(text[i] == '\t') {
// int spaces;
// for(spaces = 0; spaces < 4; spaces++) {
// if(currentLocation == DISPLAY_SIZE) {
// shiftTextUpOneLine();
// currentLocation -= 80;
// }
// displayMemoryPtr[currentLocation++] = (unsigned short)(0x0200 | ' ');
// }
// }
// else if(text[i] == '\b') {
// if(currentLocation > 0) {
// displayMemoryPtr[--currentLocation] = (unsigned short)(0x0200 | ' ');
// }
// } else {
// displayMemoryPtr[currentLocation++] = (unsigned short)(0x0200 | text[i]);
// }
//
// outb(0x3D4, 14);
// outb(0x3D5, (unsigned char)(currentLocation >> 8));
// outb(0x3D4, 15);
// outb(0x3D5, (unsigned char)(currentLocation));
// }
//}
//void println(char text[]) {
// print(text);
// print("\n");
//}
void ShiftDisplayUpOneLine()
{
unsigned short* DisplayMemoryPtr = (unsigned short*)0xB8000;
unsigned int i;
for(i = 0; i < DISPLAY_SIZE - 80; i++)
{
DisplayMemoryPtr[i] = DisplayMemoryPtr[i + 80];
}
for(i = DISPLAY_SIZE - 1; i > DISPLAY_SIZE - 80; i--)
{
DisplayMemoryPtr[i] = 0x0000;
}
}
void Print(char text[])
{
static unsigned int CurrentLocation = 0;
unsigned short* DisplayMemoryPtr = (unsigned short*)0xB8000;
int i;
for(i = 0; text[i] != 0; i++)
{
if(CurrentLocation == DISPLAY_SIZE)
{
ShiftDisplayUpOneLine();
CurrentLocation -= 80;
}
if(text[i] == '\n')
{
CurrentLocation += (80 - (CurrentLocation % 80));
}
else if(text[i] == '\t')
{
int spaces;
for(spaces = 0; spaces < 4; spaces++)
{
if(CurrentLocation == DISPLAY_SIZE)
{
ShiftDisplayUpOneLine();
CurrentLocation -= 80;
}
DisplayMemoryPtr[CurrentLocation++] = (unsigned short)(0x0200 | ' ');
}
}
else if(text[i] == '\b')
{
if(CurrentLocation > 0)
{
DisplayMemoryPtr[--CurrentLocation] = (unsigned short)(0x0200 | ' ');
}
}
else
{
DisplayMemoryPtr[CurrentLocation++] = (unsigned short)(0x0200 | text[i]);
}
outb(0x3D4, 14);
outb(0x3D5, (unsigned char)(CurrentLocation >> 8));
outb(0x3D4, 15);
outb(0x3D5, (unsigned char)(CurrentLocation));
}
}
void PrintLine(char text[])
{
Print(text);
Print("\n");
}