53 lines
1.4 KiB
Nim
53 lines
1.4 KiB
Nim
type
|
|
VGA_Colour {.pure.} = enum
|
|
black = 0,
|
|
blue = 1,
|
|
green = 2,
|
|
cyan = 3,
|
|
red = 4,
|
|
magenta = 5,
|
|
brown = 6,
|
|
lightGrey = 7,
|
|
darkGrey = 8,
|
|
lightBlue = 9,
|
|
lightGreen = 10,
|
|
lightCyan = 11,
|
|
lightRed = 12,
|
|
lightMagenta = 13,
|
|
lightBrown = 14,
|
|
white = 15
|
|
|
|
proc vgaEntryColour(fg: VGA_Colour, bg: VGA_Colour): uint8 =
|
|
result = uint8(ord(fg) or (ord(bg) shl 4))
|
|
|
|
proc vgaEntry(c: char, colour: uint8): uint16 =
|
|
result = uint16(uint8(c) or (colour shl 8))
|
|
|
|
const
|
|
vgaWidth = 80
|
|
vgaHeight = 25
|
|
terminalBufferBaseAddress = 0xB8000
|
|
|
|
var
|
|
terminalRow, terminalColumn = 0
|
|
terminalColour = vgaEntryColour(VGA_Colour.lightGrey, VGA_Colour.black)
|
|
|
|
proc terminalWriteAtPoint(writeChar: char, colour: uint8, xPos: int, yPos: int) =
|
|
let index = terminalBufferBaseAddress + (yPos * vgaWidth + xPos)
|
|
cast[ptr uint16](index)[] = vgaEntry(' ', terminalColour) # Write directly to display memory
|
|
|
|
proc terminalInitialize() =
|
|
for y in 0..<vgaWidth:
|
|
for x in 0..<vgaHeight:
|
|
terminalWriteAtPoint(' ', terminalColour, x, y)
|
|
|
|
proc setTerminalColour(newColour: uint8) =
|
|
terminalColour = newColour
|
|
|
|
proc terminalWriteChar(writeChar: char) =
|
|
terminalWriteAtPoint(writeChar, terminalColour, terminalColumn, terminalRow)
|
|
inc(terminalColumn)
|
|
inc(terminalRow)
|
|
if(terminalColumn == vgaWidth): terminalColumn = 0
|
|
if(terminalRow == vgaHeight): terminalRow = 0
|