Scrolling now works. Simplified access to VGA memory.

This commit is contained in:
neviyn 2017-10-22 01:54:51 +01:00
parent 0da0bc40dd
commit 65a4b94be1
3 changed files with 27 additions and 18 deletions

View File

@ -1,18 +1,21 @@
import vga import vga
type
VGAMemory = ptr array[0..2000, VGADoubleByte]
const const
vgaWidth = 80 vgaWidth = 80
vgaHeight = 25 vgaHeight = 25
terminalBufferBaseAddress = 0xB8000 terminalBufferBaseAddress = 0xB8000
bufferWidthSkip = vgaWidth * 2 vgaMem = cast[VGAMemory](terminalBufferBaseAddress)
var var
terminalRow, terminalColumn = 0 terminalRow, terminalColumn = 0
terminalColour: int terminalColour: int
proc terminalWriteAtPoint(writeChar: char, colour: int, xPos: int, yPos: int) = proc terminalWriteAtPoint(writeChar: char, colour: int, xPos: int, yPos: int) =
let index = terminalBufferBaseAddress + (yPos * bufferWidthSkip + (xPos * 2)) let index = yPos * vgaWidth + xPos
cast[ptr int16](index)[] = vga.vgaEntry(writeChar, terminalColour) vgaMem[index] = vga.vgaEntry(writeChar, terminalColour)
proc terminalClear*() = proc terminalClear*() =
for x in 0..<vgaWidth: for x in 0..<vgaWidth:
@ -29,28 +32,29 @@ proc terminalScroll() =
for y in 0..< (vgaHeight - 1): for y in 0..< (vgaHeight - 1):
for x in 0..<vgaWidth: for x in 0..<vgaWidth:
let xval = x * 2 let xval = x * 2
let index1 = terminalBufferBaseAddress + (y * bufferWidthSkip + xval) let index1 = y * vgaWidth + x
let index2 = terminalBufferBaseAddress + let index2 = (y + 1) * vgaWidth + x
((y + 1) * bufferWidthSkip + xval) vgaMem[index1] = vgaMem[index2]
cast[ptr int16](index1)[] = cast[ptr int16](index2)[] for x in 0..<vgaWidth: # Blank the "new" bottom line
terminalWriteAtPoint(' ', terminalColour, x, vgaHeight - 1)
proc setTerminalColour(newColour: int) = proc setTerminalColour(newColour: int) =
terminalColour = newColour terminalColour = newColour
proc terminalWriteChar(writeChar: char) = proc terminalWriteChar(writeChar: char) =
if(writeChar == '\L'): if(writeChar == '\L'):
if(terminalRow < vgaHeight): inc(terminalRow) if(terminalRow < vgaHeight - 1): inc(terminalRow)
#else: # If we are at the bottom of the screen then scroll the screen. else: # If we are at the bottom of the screen then scroll the screen.
#terminalScroll() terminalScroll()
terminalColumn = 0 terminalColumn = 0
return return
terminalWriteAtPoint(writeChar, terminalColour, terminalColumn, terminalRow) terminalWriteAtPoint(writeChar, terminalColour, terminalColumn, terminalRow)
inc(terminalColumn) inc(terminalColumn)
if(terminalColumn == vgaWidth): if(terminalColumn == vgaWidth):
terminalColumn = 0 terminalColumn = 0
if(terminalRow < vgaHeight): inc(terminalRow) if(terminalRow < vgaHeight - 1): inc(terminalRow)
#else: # If we are at the bottom of the screen then scroll the screen. else: # If we are at the bottom of the screen then scroll the screen.
#terminalScroll() terminalScroll()
proc terminalWrite*(data: string) = proc terminalWrite*(data: string) =
for character in data: for character in data:
@ -62,11 +66,11 @@ proc terminalWrite*(data: char) =
var parsedData = ['0','0','0','0','0','0','0','0','0','0'] var parsedData = ['0','0','0','0','0','0','0','0','0','0']
proc terminalWrite*(data: int) = proc terminalWrite*(data: int) =
var input = data if(data == 0):
var i = 0
if(input == 0):
terminalWrite('0') terminalWrite('0')
return return
var input = data
var i = 0
if(input < 0): if(input < 0):
terminalWrite('-') terminalWrite('-')
input = input * -1 input = input * -1

View File

@ -17,8 +17,10 @@ type
lightBrown = 14, lightBrown = 14,
white = 15 white = 15
VGADoubleByte* = distinct uint16
proc vgaEntryColour*(fg: VGA_Colour, bg: VGA_Colour): int = proc vgaEntryColour*(fg: VGA_Colour, bg: VGA_Colour): int =
result = ord(fg) or (ord(bg) shl 4) result = ord(fg) or (ord(bg) shl 4)
proc vgaEntry*(c: char, colour: int): int16 = proc vgaEntry*(c: char, colour: int): VGADoubleByte =
result = int16(int(c) or (colour shl 8)) result = (uint16(int(c) or (colour shl 8))).VGADoubleByte

View File

@ -7,3 +7,6 @@ proc kernelMain() {.exportc: "kernel_main"}=
terminalWrite(high(int)) terminalWrite(high(int))
terminalWrite("\LMIN_INT:") terminalWrite("\LMIN_INT:")
terminalWrite(low(int32)+1) terminalWrite(low(int32)+1)
for i in 0..22:
terminalWrite(i)
terminalWrite('\L')