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