Added x2 multiplication for row placement. Means newlines actually work properly.

This commit is contained in:
neviyn 2017-10-21 18:35:13 +01:00
parent 4d19433c17
commit c3ca04dd5a

View File

@ -27,19 +27,20 @@ const
vgaWidth = 80 vgaWidth = 80
vgaHeight = 25 vgaHeight = 25
terminalBufferBaseAddress = 0xB8000 terminalBufferBaseAddress = 0xB8000
bufferWidthSkip = vgaWidth * 2
var var
terminalRow, terminalColumn = 0 terminalRow, terminalColumn = 0
terminalColour: int terminalColour: int
proc terminalWriteAtPoint(writeChar: char, colour: int, xPos: int, yPos: int) = proc terminalWriteAtPoint(writeChar: char, colour: int, xPos: int, yPos: int) =
let index = terminalBufferBaseAddress + (yPos * vgaWidth + (xPos * 2)) let index = terminalBufferBaseAddress + (yPos * bufferWidthSkip + (xPos * 2))
cast[ptr int16](index)[] = vgaEntry(writeChar, terminalColour) # Write directly to display memory cast[ptr int16](index)[] = vgaEntry(writeChar, terminalColour) # Write directly to display memory
proc terminalInitialize() = proc terminalInitialize() =
terminalColour = vgaEntryColour(VGA_Colour.lightGreen, VGA_Colour.red) terminalColour = vgaEntryColour(VGA_Colour.lightGreen, VGA_Colour.red)
for y in 0..<vgaWidth: for x in 0..<vgaWidth:
for x in 0..<vgaHeight: for y in 0..<vgaHeight:
terminalWriteAtPoint(' ', terminalColour, x, y) terminalWriteAtPoint(' ', terminalColour, x, y)
proc setTerminalColour(newColour: int) = proc setTerminalColour(newColour: int) =
@ -48,6 +49,7 @@ proc setTerminalColour(newColour: int) =
proc terminalWriteChar(writeChar: char) = proc terminalWriteChar(writeChar: char) =
if(writeChar == '\L'): if(writeChar == '\L'):
inc(terminalRow) inc(terminalRow)
terminalColumn = 0
if(terminalRow == vgaHeight): terminalRow = 0 if(terminalRow == vgaHeight): terminalRow = 0
return return
terminalWriteAtPoint(writeChar, terminalColour, terminalColumn, terminalRow) terminalWriteAtPoint(writeChar, terminalColour, terminalColumn, terminalRow)
@ -63,5 +65,5 @@ proc terminalWrite(data: string) =
proc kernelMain() {.exportc: "kernel_main"}= proc kernelMain() {.exportc: "kernel_main"}=
terminalInitialize() terminalInitialize()
terminalWrite("Hello World\LThis is Nim!") terminalWrite("Hello World!\LNim here!")