alcedo/kernel/arch/i386/tty.nim

87 lines
2.2 KiB
Nim
Raw Normal View History

import vga
2017-10-20 14:47:56 +01:00
const
vgaWidth = 80
vgaHeight = 25
type
VGAMemory = ptr array[0..(vgaWidth * vgaHeight - 1), VGADoubleByte]
const
2017-10-20 18:00:17 +01:00
terminalBufferBaseAddress = 0xB8000
vgaMem = cast[VGAMemory](terminalBufferBaseAddress)
2017-10-20 18:00:17 +01:00
var
terminalRow, terminalColumn = 0
terminalColour: int
2017-10-20 18:00:17 +01:00
proc terminalWriteAtPoint(writeChar: char, colour: int, xPos: int, yPos: int) =
let index = yPos * vgaWidth + xPos
vgaMem[index] = vga.vgaEntry(writeChar, terminalColour)
2017-10-22 00:22:32 +01:00
proc terminalClear*() =
for x in 0..<vgaWidth:
for y in 0..<vgaHeight:
terminalWriteAtPoint(' ', terminalColour, x, y)
2017-10-22 00:22:32 +01:00
terminalRow = 0
terminalColumn = 0
proc terminalInitialize*() =
terminalColour = vgaEntryColour(VGA_Colour.lightGreen, VGA_Colour.red)
terminalClear()
proc terminalScroll() =
for y in 0..< (vgaHeight - 1):
let base1 = y * vgaWidth
let base2 = (y + 1) * vgaWidth
2017-10-22 00:22:32 +01:00
for x in 0..<vgaWidth:
vgaMem[base1 + x] = vgaMem[base2 + x]
for x in 0..<vgaWidth: # Blank the "new" bottom line
terminalWriteAtPoint(' ', terminalColour, x, vgaHeight - 1)
proc setTerminalColour(newColour: int) =
terminalColour = newColour
proc terminalWriteChar(writeChar: char) =
if(writeChar == '\L'):
if(terminalRow < vgaHeight - 1): inc(terminalRow)
else: # If we are at the bottom of the screen then scroll the screen.
terminalScroll()
terminalColumn = 0
return
terminalWriteAtPoint(writeChar, terminalColour, terminalColumn, terminalRow)
inc(terminalColumn)
if(terminalColumn == vgaWidth):
terminalColumn = 0
if(terminalRow < vgaHeight - 1): inc(terminalRow)
else: # If we are at the bottom of the screen then scroll the screen.
terminalScroll()
proc terminalWrite*(data: string) =
for character in data:
terminalWriteChar(character)
2017-10-22 00:22:32 +01:00
proc terminalWrite*(data: char) =
terminalWriteChar(data)
var parsedData = ['0','0','0','0','0','0','0','0','0','0']
proc terminalWrite*(data: int) =
if(data == 0):
2017-10-22 00:22:32 +01:00
terminalWrite('0')
return
var input = data
var i = 0
if(input < 0):
terminalWrite('-')
input = input * -1
while(input != 0):
let parsedChar: char = char(48 + (input mod 10))
parsedData[i] = parsedChar
i = i + 1
input = input div 10
2017-10-22 00:22:32 +01:00
while i > 0:
i = i - 1
terminalWrite(parsedData[i])