Hello world now operational. Separate insertion of colour codes was required.

This commit is contained in:
neviyn 2017-10-21 16:24:06 +01:00
parent 1718c66001
commit 90eba82c39

View File

@ -17,8 +17,8 @@ type
lightBrown = 14,
white = 15
proc vgaEntryColour(fg: VGA_Colour, bg: VGA_Colour): uint8 =
result = uint8(ord(fg)) or (uint8(ord(bg)) shl 4)
proc vgaEntryColour(fg: VGA_Colour, bg: VGA_Colour): int =
result = ord(fg) or (ord(bg) shl 4)
proc vgaEntry(c: char, colour: uint8): uint16 =
result = uint16(c) or (uint16(colour) shl 8)
@ -30,22 +30,24 @@ const
var
terminalRow, terminalColumn = 0
terminalColour = vgaEntryColour(VGA_Colour.lightGrey, VGA_Colour.black)
terminalColour: int
proc terminalWriteAtPoint(writeChar: char, colour: uint8, xPos: int, yPos: int) =
let index = terminalBufferBaseAddress + (yPos * vgaWidth + xPos)
cast[ptr uint16](index)[] = vgaEntry(writeChar, colour) # Write directly to display memory
proc terminalWriteAtPoint(writeChar: char, colour: int, xPos: int, yPos: int) =
let index = terminalBufferBaseAddress + (yPos * vgaWidth + (xPos * 2))
cast[ptr int](index)[] = int(writeChar) # Write directly to display memory
cast[ptr int](index+1)[] = terminalColour
proc terminalInitialize() =
terminalColour = vgaEntryColour(VGA_Colour.white, VGA_Colour.black)
for y in 0..<vgaWidth:
for x in 0..<vgaHeight:
terminalWriteAtPoint(' ', 0, x, y)
terminalWriteAtPoint(' ', terminalColour, x, y)
proc setTerminalColour(newColour: uint8) =
proc setTerminalColour(newColour: int) =
terminalColour = newColour
proc terminalWriteChar(writeChar: char) =
if(writeChar == '\r'):
if(writeChar == '\L'):
inc(terminalRow)
if(terminalRow == vgaHeight): terminalRow = 0
return
@ -62,5 +64,5 @@ proc terminalWrite(data: string) =
proc kernelMain() {.exportc: "kernel_main"}=
terminalInitialize()
terminalWrite("Hello World\rThis is Nim!")
terminalWrite("Hello World This is Nim!")