-
Notifications
You must be signed in to change notification settings - Fork 0
/
itext.c
182 lines (140 loc) · 3.41 KB
/
itext.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Inspiration Textmode Library
// Updates the hardware cursor
void update_cursor(int pos)
{
unsigned short position = pos;
// cursor LOW port to vga INDEX register
out(0x3D4, 0x0F);
out(0x3D5, (unsigned char)(position&0xFF));
// cursor HIGH port to vga INDEX register
out(0x3D4, 0x0E);
out(0x3D5, (unsigned char)((position>>8)&0xFF));
}
int tpointer = 0 ; // Text Pointer - Position of Cursor
unsigned char tattr = 0x00 ; // Text Attributes - Color of characters
// Sets the color for kputf
void setccol(unsigned char col)
{
tattr = col;
}
// Sets the textponter
void settptr(int tptr)
{
tpointer=tptr;
}
// Sets the background and forground color of every character on the screen
void setbgfg(unsigned char col)
{
unsigned char *tvidmem= (unsigned char *)0xB8000;
int i;
for(i=0;i<80*25;i++)
{
tvidmem++;
*tvidmem=col;
tvidmem++;
}
}
// Puts a string onto the screen
void kputs(unsigned char *cha)
{
int i;
for(i=0; cha[i]!='\0' ;i++)
{
kputf(cha[i]);
}
}
// Puts a character without changings it's attribute on the screen
void kput(unsigned char ch)
{
unsigned char *tvidmem= (unsigned char *)0xB8000;
int caddr=tpointer*2;
tvidmem+=caddr;
*tvidmem=ch;
tpointer++;
return;
}
// Puts a character with the value set by setcol() on the screen
void kputf(unsigned char ch)
{
if(tpointer>=80*25)
{
scroll();
tpointer-=80;
}
unsigned char *tvidmem= (unsigned char *)0xB8000;
int caddr=tpointer*2;
unsigned char txt_attr=tattr;
tvidmem+=caddr;
if(ch=='\n')
{
tpointer+=(80-(tpointer%80))-1;
}
else if(ch=='\b')
{
tpointer-=1;
kput(' ');
tpointer-=2;
}
else if(ch=='\t')
{
kput(' ');
kput(' ');
kput(' ');
kput(' ');
kput(' ');
kput(' ');
kput(' ');
kput(' ');
tpointer--;
}
else
{
*tvidmem=ch;
}
tvidmem++;
*tvidmem=0x00;
*tvidmem+=txt_attr;
tpointer++;
update_cursor(tpointer);
return;
}
// Scrolls the screen up by one line non-undoable
void scroll()
{
int tvids = 0xB8000+160;
int tvidc = (0x0B8000+(80*25*2))-tvids;
memcopy((unsigned char *)tvids,(unsigned char *)0x0B8000,tvidc);
memset((unsigned char *)((0x0B8000+(80*25*2))-80*2),0,80*2);
}
// Prints Inspiration Version on the screen with Inline Assembly
void prASM()
{
unsigned char ch[]="v.1";
__asm__("movb %%al,0xB8000\n"::"al"(ch[0]));
__asm__("movb %%al,0xB8002\n"::"al"(ch[1]));
__asm__("movb %%al,0xB8004\n"::"al"(ch[2]));
}
// Clears the screen
void clrscr()
{
unsigned char *tvidmem= (unsigned char *)0xB8000;
int i;
for(i=0;i<80*25;i++)
{
*tvidmem=0;
tvidmem++;
*tvidmem=0;
tvidmem++;
settptr(0);
update_cursor(0);
}
}
// Test for video mode 0x03
void videomodetst()
{
unsigned char *vmode= (unsigned char *)0x0449;
if(*vmode==0x03)
kputs("8. Mode 0x03 : Yes\n");
else
kputs("8. Mode 0x03 : No\n");
}