mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-07 08:41:45 +00:00
This commit is contained in:
parent
956ddbada8
commit
1cd1a251b3
2 changed files with 178 additions and 201 deletions
|
|
@ -2,40 +2,32 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Cosmos.Hardware
|
namespace Cosmos.Hardware {
|
||||||
{
|
public class TextScreen {
|
||||||
public class TextScreen
|
|
||||||
{
|
|
||||||
protected const int VideoAddr = 0xB8000;
|
protected const int VideoAddr = 0xB8000;
|
||||||
protected const byte DefaultColor = 15; //White
|
protected const byte DefaultColor = 15; //White
|
||||||
protected static bool mInitialized = false;
|
protected static bool mInitialized = false;
|
||||||
protected static byte Color;
|
protected static byte Color;
|
||||||
protected static void CheckInit()
|
protected static void CheckInit() {
|
||||||
{
|
if (!mInitialized) {
|
||||||
if (!mInitialized)
|
|
||||||
{
|
|
||||||
Color = DefaultColor;
|
Color = DefaultColor;
|
||||||
mInitialized = true;
|
mInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Rows
|
public static int Rows {
|
||||||
{
|
|
||||||
// for now 24 lines, as it's one line for the Heap Debug Display
|
// for now 24 lines, as it's one line for the Heap Debug Display
|
||||||
get { return 24; }
|
get { return 24; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Columns
|
public static int Columns {
|
||||||
{
|
|
||||||
get { return 80; }
|
get { return 80; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void NewLine()
|
public static void NewLine() {
|
||||||
{
|
|
||||||
CurrentRow += 1;
|
CurrentRow += 1;
|
||||||
CurrentChar = 0;
|
CurrentChar = 0;
|
||||||
if (CurrentRow > Rows)
|
if (CurrentRow > Rows) {
|
||||||
{
|
|
||||||
ScrollUp();
|
ScrollUp();
|
||||||
CurrentRow -= 1;
|
CurrentRow -= 1;
|
||||||
CurrentChar = 0;
|
CurrentChar = 0;
|
||||||
|
|
@ -44,15 +36,15 @@ namespace Cosmos.Hardware
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe void Clear()
|
public static unsafe void Clear() {
|
||||||
{
|
|
||||||
CheckInit();
|
CheckInit();
|
||||||
|
|
||||||
byte* xScreenPtr = (byte*)(VideoAddr + (2 * Columns));
|
byte* xScreenPtr = (byte*)(VideoAddr + (2 * Columns));
|
||||||
for (int i = 0; i < Columns * (Rows); i++)
|
for (int i = 0; i < Columns * (Rows); i++) {
|
||||||
{
|
|
||||||
*xScreenPtr = 0;
|
*xScreenPtr = 0;
|
||||||
xScreenPtr++;
|
xScreenPtr++;
|
||||||
|
//TODO: This and prob bg color too are a bug. We cant put straight in
|
||||||
|
// because it causes blink etc. We need to translate/reduce the color.
|
||||||
*xScreenPtr = Color;
|
*xScreenPtr = Color;
|
||||||
xScreenPtr++;
|
xScreenPtr++;
|
||||||
}
|
}
|
||||||
|
|
@ -62,13 +54,11 @@ namespace Cosmos.Hardware
|
||||||
|
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
public static unsafe void ReallyClearScreen()
|
public static unsafe void ReallyClearScreen() {
|
||||||
{
|
|
||||||
CheckInit();
|
CheckInit();
|
||||||
|
|
||||||
byte* xScreenPtr = (byte*)(VideoAddr);
|
byte* xScreenPtr = (byte*)(VideoAddr);
|
||||||
for (int i = 0; i < Columns * Rows; i++)
|
for (int i = 0; i < Columns * Rows; i++) {
|
||||||
{
|
|
||||||
*xScreenPtr = 0;
|
*xScreenPtr = 0;
|
||||||
xScreenPtr++;
|
xScreenPtr++;
|
||||||
*xScreenPtr = Color;
|
*xScreenPtr = Color;
|
||||||
|
|
@ -80,25 +70,21 @@ namespace Cosmos.Hardware
|
||||||
|
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
public static void WriteChar(char aChar)
|
public static void WriteChar(char aChar) {
|
||||||
{
|
|
||||||
PutChar(CurrentRow, CurrentChar, aChar);
|
PutChar(CurrentRow, CurrentChar, aChar);
|
||||||
CurrentChar += 1;
|
CurrentChar += 1;
|
||||||
if (CurrentChar == Columns)
|
if (CurrentChar == Columns) {
|
||||||
{
|
|
||||||
NewLine();
|
NewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static unsafe void ScrollUp()
|
protected static unsafe void ScrollUp() {
|
||||||
{
|
|
||||||
CheckInit();
|
CheckInit();
|
||||||
int Columns2 = Columns * 2;
|
int Columns2 = Columns * 2;
|
||||||
byte* xScreenPtr = (byte*)(VideoAddr + Columns2);
|
byte* xScreenPtr = (byte*)(VideoAddr + Columns2);
|
||||||
for (int i = 0; i < Columns * Rows; i++)
|
for (int i = 0; i < Columns * Rows; i++) {
|
||||||
{
|
|
||||||
*xScreenPtr = *(xScreenPtr + Columns2);
|
*xScreenPtr = *(xScreenPtr + Columns2);
|
||||||
xScreenPtr++;
|
xScreenPtr++;
|
||||||
*xScreenPtr = *(xScreenPtr + Columns2);
|
*xScreenPtr = *(xScreenPtr + Columns2);
|
||||||
|
|
@ -106,8 +92,7 @@ namespace Cosmos.Hardware
|
||||||
}
|
}
|
||||||
|
|
||||||
xScreenPtr = (byte*)(VideoAddr + Rows * Columns * 2);
|
xScreenPtr = (byte*)(VideoAddr + Rows * Columns * 2);
|
||||||
for (int i = 0; i < Columns; i++)
|
for (int i = 0; i < Columns; i++) {
|
||||||
{
|
|
||||||
*xScreenPtr = 0;
|
*xScreenPtr = 0;
|
||||||
xScreenPtr++;
|
xScreenPtr++;
|
||||||
*xScreenPtr = Color;
|
*xScreenPtr = Color;
|
||||||
|
|
@ -117,8 +102,7 @@ namespace Cosmos.Hardware
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe static void RemoveChar(int aLine, int aRow)
|
public unsafe static void RemoveChar(int aLine, int aRow) {
|
||||||
{
|
|
||||||
CheckInit();
|
CheckInit();
|
||||||
int xScreenOffset = ((aRow + (aLine * Columns)) * 2);
|
int xScreenOffset = ((aRow + (aLine * Columns)) * 2);
|
||||||
byte* xScreenPtr = (byte*)(VideoAddr + xScreenOffset);
|
byte* xScreenPtr = (byte*)(VideoAddr + xScreenOffset);
|
||||||
|
|
@ -129,8 +113,7 @@ namespace Cosmos.Hardware
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe static void PutChar(int aLine, int aRow, char aChar)
|
public unsafe static void PutChar(int aLine, int aRow, char aChar) {
|
||||||
{
|
|
||||||
CheckInit();
|
CheckInit();
|
||||||
int xScreenOffset = ((aRow + (aLine * Columns)) * 2);
|
int xScreenOffset = ((aRow + (aLine * Columns)) * 2);
|
||||||
byte* xScreenPtr = (byte*)(VideoAddr + xScreenOffset);
|
byte* xScreenPtr = (byte*)(VideoAddr + xScreenOffset);
|
||||||
|
|
@ -141,14 +124,12 @@ namespace Cosmos.Hardware
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetColors(ConsoleColor aForeground, ConsoleColor aBackground)
|
public static void SetColors(ConsoleColor aForeground, ConsoleColor aBackground) {
|
||||||
{
|
|
||||||
CheckInit();
|
CheckInit();
|
||||||
Color = (byte)((byte)(aForeground) | ((byte)(aBackground) << 4));
|
Color = (byte)((byte)(aForeground) | ((byte)(aBackground) << 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetCursor()
|
private static void SetCursor() {
|
||||||
{
|
|
||||||
CheckInit();
|
CheckInit();
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
@ -176,28 +157,22 @@ namespace Cosmos.Hardware
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int mCurrentRow = 1;
|
private static int mCurrentRow = 1;
|
||||||
public static int CurrentRow
|
public static int CurrentRow {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
return mCurrentRow;
|
return mCurrentRow;
|
||||||
}
|
}
|
||||||
set
|
set {
|
||||||
{
|
|
||||||
mCurrentRow = value;
|
mCurrentRow = value;
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int mCurrentChar = 0;
|
private static int mCurrentChar = 0;
|
||||||
public static int CurrentChar
|
public static int CurrentChar {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
return mCurrentChar;
|
return mCurrentChar;
|
||||||
}
|
}
|
||||||
set
|
set {
|
||||||
{
|
|
||||||
mCurrentChar = value;
|
mCurrentChar = value;
|
||||||
SetCursor();
|
SetCursor();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,15 @@ namespace CosmosBoot {
|
||||||
public static void Init() {
|
public static void Init() {
|
||||||
var xBoot = new Cosmos.Sys.Boot();
|
var xBoot = new Cosmos.Sys.Boot();
|
||||||
xBoot.Execute();
|
xBoot.Execute();
|
||||||
Console.BackgroundColor = ConsoleColor.Green;
|
|
||||||
|
//Console.BackgroundColor = ConsoleColor.Blue;
|
||||||
//TODO: What is this next line for?
|
//TODO: What is this next line for?
|
||||||
S.ReallyClearScreen();
|
S.ReallyClearScreen();
|
||||||
Console.WriteLine("Congratulations! You just booted C# code.");
|
Console.WriteLine("Congratulations! You just booted C# code.");
|
||||||
Console.WriteLine("Edit Program.cs to create your own Operating System.");
|
Console.WriteLine("Edit Program.cs to create your own Operating System.");
|
||||||
Console.WriteLine("Press a key to shutdown...");
|
Console.WriteLine("Press a key to shutdown...");
|
||||||
Console.Read();
|
Console.Read();
|
||||||
|
|
||||||
Cosmos.Sys.Deboot.ShutDown();
|
Cosmos.Sys.Deboot.ShutDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue