/*************************************************************************
*
* 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 .
*
*************************************************************************/
#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=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