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
|
/*************************************************************************
*
* AleeOS Screen: This include file is for the terminal features
* Copyright (C) 2018 AleeCorp
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*************************************************************************/
#ifndef SCREEN_H
#define SCREEN_H
#include "types.h"
#include "system.h"
#include "string.h"
int cursorX = 0, cursorY = 0;
const uint8 sw = 80,sh = 25,sd = 2; //We define the screen width, height, and depth.
void clearLine(uint8 from,uint8 to)
{
uint16 i = sw * from * sd;
string vidmem=(string)0xb8000;
for(i;i<(sw*to*sd);i++)
{
vidmem[i] = 0x0;
}
}
void updateCursor()
{
unsigned temp;
temp = cursorY * sw + cursorX; // Position = (y * width) + x
outportb(0x3D4, 14); // CRT Control Register: Select Cursor Location
outportb(0x3D5, temp >> 8); // Send the high byte across the bus
outportb(0x3D4, 15); // CRT Control Register: Select Send Low byte
outportb(0x3D5, temp); // Send the Low byte of the cursor location
}
void clearScreen()
{
clearLine(0,sh-1);
cursorX = 0;
cursorY = 0;
updateCursor();
}
void scrollUp(uint8 lineNumber)
{
string vidmem = (string)0xb8000;
uint16 i = 0;
clearLine(0,lineNumber-1); //updated
for (i;i<sw*(sh-1)*2;i++)
{
vidmem[i] = vidmem[i+sw*2*lineNumber];
}
clearLine(sh-1-lineNumber,sh-1);
if((cursorY - lineNumber) < 0 )
{
cursorY = 0;
cursorX = 0;
}
else
{
cursorY -= lineNumber;
}
updateCursor();
}
void newLineCheck()
{
if(cursorY >=sh-1)
{
scrollUp(1);
}
}
void printch(char c)
{
string vidmem = (string) 0xb8000;
switch(c)
{
case (0x08):
if(cursorX > 0)
{
cursorX--;
vidmem[(cursorY * sw + cursorX)*sd]=0x00;
}
break;
/* case (0x09):
cursorX = (cursorX + 8) & ~(8 - 1);
break;*/
case ('\r'):
cursorX = 0;
break;
case ('\n'):
cursorX = 0;
cursorY++;
break;
default:
vidmem [((cursorY * sw + cursorX))*sd] = c;
vidmem [((cursorY * sw + cursorX))*sd+1] = 0x0F;
cursorX++;
break;
}
if(cursorX >= sw)
{
cursorX = 0;
cursorY++;
}
updateCursor();
newLineCheck();
}
void print (string ch)
{
uint16 i = 0;
uint8 length = strlength(ch)-1; //Updated (Now we store string length on a variable to call the function only once)
for(i;i<length;i++)
{
printch(ch[i]);
}
}
#endif
|