2017-10-21 19:23:17 +01:00
|
|
|
import vga
|
2017-10-20 14:47:56 +01:00
|
|
|
|
|
|
|
const
|
|
|
|
vgaWidth = 80
|
|
|
|
vgaHeight = 25
|
2017-10-20 18:00:17 +01:00
|
|
|
terminalBufferBaseAddress = 0xB8000
|
2017-10-21 18:35:13 +01:00
|
|
|
bufferWidthSkip = vgaWidth * 2
|
2017-10-20 18:00:17 +01:00
|
|
|
|
|
|
|
var
|
|
|
|
terminalRow, terminalColumn = 0
|
2017-10-21 16:24:06 +01:00
|
|
|
terminalColour: int
|
2017-10-20 18:00:17 +01:00
|
|
|
|
2017-10-21 16:24:06 +01:00
|
|
|
proc terminalWriteAtPoint(writeChar: char, colour: int, xPos: int, yPos: int) =
|
2017-10-21 18:35:13 +01:00
|
|
|
let index = terminalBufferBaseAddress + (yPos * bufferWidthSkip + (xPos * 2))
|
2017-10-22 00:22:32 +01:00
|
|
|
cast[ptr int16](index)[] = vga.vgaEntry(writeChar, terminalColour)
|
2017-10-20 18:12:00 +01:00
|
|
|
|
2017-10-22 00:22:32 +01:00
|
|
|
proc terminalClear*() =
|
2017-10-21 18:35:13 +01:00
|
|
|
for x in 0..<vgaWidth:
|
|
|
|
for y in 0..<vgaHeight:
|
2017-10-21 16:24:06 +01:00
|
|
|
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):
|
|
|
|
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)[]
|
2017-10-20 18:12:00 +01:00
|
|
|
|
2017-10-21 16:24:06 +01:00
|
|
|
proc setTerminalColour(newColour: int) =
|
2017-10-20 18:12:00 +01:00
|
|
|
terminalColour = newColour
|
|
|
|
|
|
|
|
proc terminalWriteChar(writeChar: char) =
|
2017-10-21 16:24:06 +01:00
|
|
|
if(writeChar == '\L'):
|
2017-10-22 00:22:32 +01:00
|
|
|
if(terminalRow < vgaHeight): inc(terminalRow)
|
|
|
|
#else: # If we are at the bottom of the screen then scroll the screen.
|
|
|
|
#terminalScroll()
|
2017-10-21 18:35:13 +01:00
|
|
|
terminalColumn = 0
|
2017-10-20 22:04:09 +01:00
|
|
|
return
|
2017-10-20 18:12:00 +01:00
|
|
|
terminalWriteAtPoint(writeChar, terminalColour, terminalColumn, terminalRow)
|
|
|
|
inc(terminalColumn)
|
2017-10-20 22:04:09 +01:00
|
|
|
if(terminalColumn == vgaWidth):
|
|
|
|
terminalColumn = 0
|
2017-10-22 00:22:32 +01:00
|
|
|
if(terminalRow < vgaHeight): inc(terminalRow)
|
|
|
|
#else: # If we are at the bottom of the screen then scroll the screen.
|
|
|
|
#terminalScroll()
|
2017-10-20 18:20:42 +01:00
|
|
|
|
2017-10-21 19:23:17 +01:00
|
|
|
proc terminalWrite*(data: string) =
|
2017-10-20 18:20:42 +01:00
|
|
|
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) =
|
|
|
|
var input = data
|
|
|
|
var i = 0
|
|
|
|
if(input == 0):
|
|
|
|
terminalWrite('0')
|
2017-10-22 00:44:01 +01:00
|
|
|
return
|
|
|
|
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])
|
|
|
|
|