alcedo/kernel/arch/i386/tty.nim

42 lines
1.2 KiB
Nim

import vga
const
vgaWidth = 80
vgaHeight = 25
terminalBufferBaseAddress = 0xB8000
bufferWidthSkip = vgaWidth * 2
var
terminalRow, terminalColumn = 0
terminalColour: int
proc terminalWriteAtPoint(writeChar: char, colour: int, xPos: int, yPos: int) =
let index = terminalBufferBaseAddress + (yPos * bufferWidthSkip + (xPos * 2))
cast[ptr int16](index)[] = vga.vgaEntry(writeChar, terminalColour) # Write directly to display memory
proc terminalInitialize*() =
terminalColour = vgaEntryColour(VGA_Colour.lightGreen, VGA_Colour.red)
for x in 0..<vgaWidth:
for y in 0..<vgaHeight:
terminalWriteAtPoint(' ', terminalColour, x, y)
proc setTerminalColour(newColour: int) =
terminalColour = newColour
proc terminalWriteChar(writeChar: char) =
if(writeChar == '\L'):
inc(terminalRow)
terminalColumn = 0
if(terminalRow == vgaHeight): terminalRow = 0
return
terminalWriteAtPoint(writeChar, terminalColour, terminalColumn, terminalRow)
inc(terminalColumn)
if(terminalColumn == vgaWidth):
terminalColumn = 0
inc(terminalRow)
if(terminalRow == vgaHeight): terminalRow = 0
proc terminalWrite*(data: string) =
for character in data:
terminalWriteChar(character)