Scrolling now works. Simplified access to VGA memory.
This commit is contained in:
parent
0da0bc40dd
commit
65a4b94be1
@ -1,18 +1,21 @@
|
||||
import vga
|
||||
|
||||
type
|
||||
VGAMemory = ptr array[0..2000, VGADoubleByte]
|
||||
|
||||
const
|
||||
vgaWidth = 80
|
||||
vgaHeight = 25
|
||||
terminalBufferBaseAddress = 0xB8000
|
||||
bufferWidthSkip = vgaWidth * 2
|
||||
vgaMem = cast[VGAMemory](terminalBufferBaseAddress)
|
||||
|
||||
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)
|
||||
let index = yPos * vgaWidth + xPos
|
||||
vgaMem[index] = vga.vgaEntry(writeChar, terminalColour)
|
||||
|
||||
proc terminalClear*() =
|
||||
for x in 0..<vgaWidth:
|
||||
@ -29,28 +32,29 @@ 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)[]
|
||||
let index1 = y * vgaWidth + x
|
||||
let index2 = (y + 1) * vgaWidth + x
|
||||
vgaMem[index1] = vgaMem[index2]
|
||||
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): inc(terminalRow)
|
||||
#else: # If we are at the bottom of the screen then scroll the screen.
|
||||
#terminalScroll()
|
||||
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): inc(terminalRow)
|
||||
#else: # If we are at the bottom of the screen then scroll the screen.
|
||||
#terminalScroll()
|
||||
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:
|
||||
@ -62,11 +66,11 @@ proc terminalWrite*(data: char) =
|
||||
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):
|
||||
if(data == 0):
|
||||
terminalWrite('0')
|
||||
return
|
||||
var input = data
|
||||
var i = 0
|
||||
if(input < 0):
|
||||
terminalWrite('-')
|
||||
input = input * -1
|
||||
|
@ -17,8 +17,10 @@ type
|
||||
lightBrown = 14,
|
||||
white = 15
|
||||
|
||||
VGADoubleByte* = distinct uint16
|
||||
|
||||
proc vgaEntryColour*(fg: VGA_Colour, bg: VGA_Colour): int =
|
||||
result = ord(fg) or (ord(bg) shl 4)
|
||||
|
||||
proc vgaEntry*(c: char, colour: int): int16 =
|
||||
result = int16(int(c) or (colour shl 8))
|
||||
proc vgaEntry*(c: char, colour: int): VGADoubleByte =
|
||||
result = (uint16(int(c) or (colour shl 8))).VGADoubleByte
|
||||
|
@ -7,3 +7,6 @@ proc kernelMain() {.exportc: "kernel_main"}=
|
||||
terminalWrite(high(int))
|
||||
terminalWrite("\LMIN_INT:")
|
||||
terminalWrite(low(int32)+1)
|
||||
for i in 0..22:
|
||||
terminalWrite(i)
|
||||
terminalWrite('\L')
|
||||
|
Loading…
Reference in New Issue
Block a user