Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Console supports scrolling #20

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rmdir /S /Q ..\bin >nul 2>&1
mkdir ..\bin
cd ..\bin

csc /debug:embedded /noconfig /nostdlib /runtimemetadataversion:v4.0.30319 ../src/PatienceOS.Kernel/kernel.cs ../src/PatienceOS.Kernel/Console.cs ../src/PatienceOS.Kernel/FrameBuffer.cs ../src/PatienceOS.Kernel/zerosharp.cs /out:kernel.ilexe /langversion:latest /unsafe || goto Error
csc /debug:embedded /noconfig /nostdlib /runtimemetadataversion:v4.0.30319 ../src/PatienceOS.Kernel/Color.cs ../src/PatienceOS.Kernel/Console.cs ../src/PatienceOS.Kernel/FrameBuffer.cs ../src/PatienceOS.Kernel/kernel.cs ../src/PatienceOS.Kernel/zerosharp.cs /out:kernel.ilexe /langversion:latest /unsafe || goto Error
ilc --targetos windows --targetarch x86 --instruction-set base --verbose kernel.ilexe -g -o kernel.obj --systemmodule kernel --map kernel.map -O || goto Error
nasm -f win32 -o loader.obj ../src/loader.asm || goto Error

Expand All @@ -23,7 +23,8 @@ nasm -f win32 -o loader.obj ../src/loader.asm || goto Error

ld -m i386pe -T ../src/linker.ld -o kernel.bin loader.obj kernel.obj || goto Error
objcopy -O elf32-i386 kernel.bin kernel.elf || goto Error
qemu-system-i386 -cpu pentium3 -kernel kernel.elf -d int -no-reboot -no-shutdown || goto Error
qemu-system-i386 -cpu pentium3 -kernel kernel.elf -no-reboot -no-shutdown || goto Error
:: qemu-system-i386 -cpu pentium3 -kernel kernel.elf -d int -no-reboot -no-shutdown || goto Error

cd ..\build
exit /B
Expand Down
143 changes: 137 additions & 6 deletions src/PatienceOS.Kernel.Tests/ConsoleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Should_Clear_A_EOL_B()
unsafe public class ThreeXThree
{
[Fact]
public void Should_Write_ABC_EOL_DEF_EOL_GHI()
public void Should_Write_ABC_DEF_GHI()
{
// Given
byte* buffer = stackalloc byte[3 * 3 * 2];
Expand All @@ -94,12 +94,143 @@ public void Should_Write_ABC_EOL_DEF_EOL_GHI()
Assert.Equal((byte)'H', buffer[14]);
Assert.Equal((byte)'I', buffer[16]);
}

[Fact]
public void Should_Clear_ABC_DEF_GHI()
{
// Given
byte* buffer = stackalloc byte[3 * 3 * 2];
var frameBuffer = new FrameBuffer(buffer);
var console = new Console(3, 3, frameBuffer);

// When
console.Print("ABCDEFGHI");
console.Clear();

// Then
Assert.Equal((byte)' ', buffer[0]);
Assert.Equal((byte)' ', buffer[2]);
Assert.Equal((byte)' ', buffer[4]);
Assert.Equal((byte)' ', buffer[6]);
Assert.Equal((byte)' ', buffer[8]);
Assert.Equal((byte)' ', buffer[10]);
Assert.Equal((byte)' ', buffer[12]);
Assert.Equal((byte)' ', buffer[14]);
Assert.Equal((byte)' ', buffer[16]);
}

[Fact]
public void Should_Scroll_One_Line()
{
// Given
byte* buffer = stackalloc byte[3 * 3 * 2];
var frameBuffer = new FrameBuffer(buffer);
var console = new Console(3, 3, frameBuffer);

// When
console.Print("AAA");
console.Print("BBB");
console.Print("CCC");
console.Print("DDD");

// Then
Assert.Equal((byte)'B', buffer[0]);
Assert.Equal((byte)'B', buffer[2]);
Assert.Equal((byte)'B', buffer[4]);
Assert.Equal((byte)'C', buffer[6]);
Assert.Equal((byte)'C', buffer[8]);
Assert.Equal((byte)'C', buffer[10]);
Assert.Equal((byte)'D', buffer[12]);
Assert.Equal((byte)'D', buffer[14]);
Assert.Equal((byte)'D', buffer[16]);
}

[Fact]
public void Should_Scroll_Two_Lines()
{
// Given
byte* buffer = stackalloc byte[3 * 3 * 2];
var frameBuffer = new FrameBuffer(buffer);
var console = new Console(3, 3, frameBuffer);

// When
console.Print("AAA");
console.Print("BBB");
console.Print("CCC");
console.Print("DDD");
console.Print("EEE");

// Then
Assert.Equal((byte)'C', buffer[0]);
Assert.Equal((byte)'C', buffer[2]);
Assert.Equal((byte)'C', buffer[4]);
Assert.Equal((byte)'D', buffer[6]);
Assert.Equal((byte)'D', buffer[8]);
Assert.Equal((byte)'D', buffer[10]);
Assert.Equal((byte)'E', buffer[12]);
Assert.Equal((byte)'E', buffer[14]);
Assert.Equal((byte)'E', buffer[16]);
}

[Fact]
public void Should_Scroll_Three_Lines()
{
// Given
byte* buffer = stackalloc byte[3 * 3 * 2];
var frameBuffer = new FrameBuffer(buffer);
var console = new Console(3, 3, frameBuffer);

// When
console.Print("AAA");
console.Print("BBB");
console.Print("CCC");
console.Print("DDD");
console.Print("EEE");
console.Print("FFF");

// Then
Assert.Equal((byte)'D', buffer[0]);
Assert.Equal((byte)'D', buffer[2]);
Assert.Equal((byte)'D', buffer[4]);
Assert.Equal((byte)'E', buffer[6]);
Assert.Equal((byte)'E', buffer[8]);
Assert.Equal((byte)'E', buffer[10]);
Assert.Equal((byte)'F', buffer[12]);
Assert.Equal((byte)'F', buffer[14]);
Assert.Equal((byte)'F', buffer[16]);
}

[Fact]
public void Should_Scroll_And_Blank_Last_Line()
{
// Given
byte* buffer = stackalloc byte[3 * 3 * 2];
var frameBuffer = new FrameBuffer(buffer);
var console = new Console(3, 3, frameBuffer);

// When
console.Print("AAA");
console.Print("BBB");
console.Print("CCC");
console.Print("D");

// Then
Assert.Equal((byte)'B', buffer[0]);
Assert.Equal((byte)'B', buffer[2]);
Assert.Equal((byte)'B', buffer[4]);
Assert.Equal((byte)'C', buffer[6]);
Assert.Equal((byte)'C', buffer[8]);
Assert.Equal((byte)'C', buffer[10]);
Assert.Equal((byte)'D', buffer[12]);
Assert.Equal((byte)' ', buffer[14]);
Assert.Equal((byte)' ', buffer[16]);
}
}

unsafe public class HelloWorld
{
[Fact]
public void Should_Write_Hello_Space_World_With_Print_Statement()
public void Should_Write_Hello_World_With_Print_Statement()
{
// Given
byte* buffer = stackalloc byte[80 * 25 * 2];
Expand All @@ -124,7 +255,7 @@ public void Should_Write_Hello_Space_World_With_Print_Statement()
}

[Fact]
public void Should_Write_Hello_Space_World_With_Print_Statements()
public void Should_Write_Hello_World_With_Print_Statements()
{
// Given
byte* buffer = stackalloc byte[80 * 25 * 2];
Expand All @@ -151,7 +282,7 @@ public void Should_Write_Hello_Space_World_With_Print_Statements()
}

[Fact]
public void Should_Write_Hello_EOL_World_EOL_With_Print_Statement()
public void Should_Write_Hello_CRLF_World_With_Print_Statement()
{
// Given
byte* buffer = stackalloc byte[80 * 25 * 2];
Expand All @@ -175,7 +306,7 @@ public void Should_Write_Hello_EOL_World_EOL_With_Print_Statement()
}

[Fact]
public void Should_Write_Hello_EOL_World_EOL_With_Print_Statements()
public void Should_Write_Hello_CRLF_World_With_Print_Statements()
{
// Given
byte* buffer = stackalloc byte[80 * 25 * 2];
Expand All @@ -200,7 +331,7 @@ public void Should_Write_Hello_EOL_World_EOL_With_Print_Statements()
}

[Fact]
public void Should_Write_Hello_EOL_World_EOL_With_PrintLine_Statements()
public void Should_Write_Hello_CRLF_World_With_PrintLine_Statements()
{
// Given
byte* buffer = stackalloc byte[80 * 25 * 2];
Expand Down
24 changes: 24 additions & 0 deletions src/PatienceOS.Kernel.Tests/FrameBufferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,29 @@ public void FrameBuffer_Should_Contain_Hello()
Assert.Equal((byte)'l', buffer[3]);
Assert.Equal((byte)'o', buffer[4]);
}

[Fact]
public void FrameBuffer_Should_Copy()
{
// Given
byte* buffer = stackalloc byte[5];
var frameBuffer = new FrameBuffer(buffer);

frameBuffer.Write(0, (byte)'H');
frameBuffer.Write(1, (byte)'e');
frameBuffer.Write(2, (byte)'l');
frameBuffer.Write(3, (byte)'l');
frameBuffer.Write(4, (byte)'o');

// When
frameBuffer.Copy(3, 0, 2);

// Then
Assert.Equal((byte)'l', buffer[0]);
Assert.Equal((byte)'o', buffer[1]);
Assert.Equal((byte)'l', buffer[2]);
Assert.Equal((byte)'l', buffer[3]);
Assert.Equal((byte)'o', buffer[4]);
}
}
}
28 changes: 28 additions & 0 deletions src/PatienceOS.Kernel/Color.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace PatienceOS.Kernel
{
/// <summary>
/// Allowable terminal colors
/// </summary>
/// <remarks>
/// List of colours sourced from here: <see cref="https://doc.ecoscentric.com/ref/framebuf-colour.html"/>
/// </remarks>
public enum Color
{
Black = 0x00,
Blue = 0x01,
Green = 0x02,
Cyan = 0x03,
Red = 0x04,
Magenta = 0x05,
Brown = 0x06,
LightGrey = 0x07,
DarkGrey = 0x08,
LightBlue = 0x09,
LightGreen = 0x0A,
LightCyan = 0x0B,
LightRed = 0x0C,
LightMagenta = 0x0D,
Yellow = 0x0E,
White = 0x0F,
}
}
Loading