Added printing of ints to the screen.
This commit is contained in:
parent
4f2c632cf9
commit
e871378f8f
@ -12,30 +12,69 @@ var
|
||||
|
||||
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
|
||||
cast[ptr int16](index)[] = vga.vgaEntry(writeChar, terminalColour)
|
||||
|
||||
proc terminalInitialize*() =
|
||||
terminalColour = vgaEntryColour(VGA_Colour.lightGreen, VGA_Colour.red)
|
||||
proc terminalClear*() =
|
||||
for x in 0..<vgaWidth:
|
||||
for y in 0..<vgaHeight:
|
||||
terminalWriteAtPoint(' ', terminalColour, x, y)
|
||||
terminalRow = 0
|
||||
terminalColumn = 0
|
||||
|
||||
proc terminalInitialize*() =
|
||||
terminalColour = vgaEntryColour(VGA_Colour.lightGreen, VGA_Colour.red)
|
||||
terminalClear()
|
||||
|
||||
proc terminalScroll() =
|
||||
for y in 0..< (vgaHeight - 1):
|
||||
for x in 0..<vgaWidth:
|
||||
let xval = x * 2
|
||||
let index1 = terminalBufferBaseAddress + (y * bufferWidthSkip + xval)
|
||||
let index2 = terminalBufferBaseAddress +
|
||||
((y + 1) * bufferWidthSkip + xval)
|
||||
cast[ptr int16](index1)[] = cast[ptr int16](index2)[]
|
||||
|
||||
proc setTerminalColour(newColour: int) =
|
||||
terminalColour = newColour
|
||||
|
||||
proc terminalWriteChar(writeChar: char) =
|
||||
if(writeChar == '\L'):
|
||||
inc(terminalRow)
|
||||
if(terminalRow < vgaHeight): inc(terminalRow)
|
||||
#else: # If we are at the bottom of the screen then scroll the screen.
|
||||
#terminalScroll()
|
||||
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
|
||||
if(terminalRow < vgaHeight): 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)
|
||||
|
||||
proc terminalWrite*(data: char) =
|
||||
terminalWriteChar(data)
|
||||
|
||||
var parsedData = ['0','0','0','0','0','0','0','0','0','0']
|
||||
|
||||
proc terminalWrite*(data: int) =
|
||||
var input = data
|
||||
var i = 0
|
||||
if(input < 0):
|
||||
terminalWrite('-')
|
||||
if(input == 0):
|
||||
terminalWrite('0')
|
||||
else:
|
||||
while(input > 0):
|
||||
let parsedChar: char = char(48 + (input mod 10))
|
||||
parsedData[i] = parsedChar
|
||||
i = i + 1
|
||||
input = input div 10
|
||||
while i > 0:
|
||||
i = i - 1
|
||||
terminalWrite(parsedData[i])
|
||||
|
||||
|
@ -2,4 +2,6 @@ import tty
|
||||
|
||||
proc kernelMain() {.exportc: "kernel_main"}=
|
||||
terminalInitialize()
|
||||
terminalWrite("Hello World!\LNim here!")
|
||||
terminalWrite("Hello World!\LNim here!\L")
|
||||
for i in 0..10:
|
||||
terminalWrite(i)
|
||||
|
Loading…
Reference in New Issue
Block a user