tape-kernel 1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
vga.c File Reference
#include "../lib/types.h"
#include "vga.h"
#include "kb.h"
#include "cm.h"
#include "../lib/err.h"
#include "../lib/utils.h"
Include dependency graph for vga.c:

Go to the source code of this file.

Functions

void __scrl (void)
 scrl scrolls the vga text screen up by one row
void __prt (int x, int y, const char *txt, uint8_t col)
 prt prints a string to the vga screen at a given position
void __prtd (int x, int y, int num, uint8_t col)
 prtd prints a decimal integer to the vga screen
void __prth (int x, int y, uint32_t hex, uint8_t col)
 prth prints a 32 bit hex value to the vga screen
void __clscr (void)
 clscr clears the entire vga text screen
void __rdln (char *buffer, int maxlen)
 rdln reads a line of text input from the keyboard
void __drw (int x1, int y1, int x2, int y2, uint8_t col)
 drw draws a line on the vga screen using '#' characters
void __pchr (int x, int y, char chr, uint8_t col)
 pchr prints a single raw character to the vga screen

Variables

uint16_tvga = (uint16_t*)0xB8000
 the vga framebuffer pointer

Function Documentation

◆ __clscr()

void __clscr ( void )

clscr clears the entire vga text screen

clscr is a function that fills all 2000 vga cells with spaces using the default white-on-black color attribute

using clscr is done with

#include "../io/vga.h" //or just vga.h
#define clscr
Definition vga.h:7
See also
scrl(), prt()

Definition at line 193 of file vga.c.

References vga.

◆ __drw()

void __drw ( int x1,
int y1,
int x2,
int y2,
uint8_t col )

drw draws a line on the vga screen using '#' characters

drw is a function that draws horizontal, vertical, or diagonal lines on the vga screen using bresenhams line algorithm for the diagonal case

Parameters
x1,thestarting column (0-79)
y1,thestarting row (0-24)
x2,theending column (0-79)
y2,theending row (0-24)
col,thevga color attribute byte

using drw is done with

#include "../io/vga.h" //or just vga.h
drw(10, 5, 50, 5, 0x0A); //horizontal green line
#define drw
Definition vga.h:10
See also
prt(), pchr()

Definition at line 280 of file vga.c.

References abs(), assert, and prt.

◆ __pchr()

void __pchr ( int x,
int y,
char chr,
uint8_t col )

pchr prints a single raw character to the vga screen

pchr is a function that prints a single character at a given screen position, useful for printing extended ascii characters

Parameters
x,thecolumn to print at
y,therow to print at
chr,theraw character to print (e.g. a char literal)
col,thevga color attribute byte

using pchr is done with

#include "../io/vga.h" //or just vga.h
pchr(40, 12, 0xDB, 0x0F); //solid block char
#define pchr
Definition vga.h:11
See also
prt(), drw()

Definition at line 352 of file vga.c.

References prt.

◆ __prt()

void __prt ( int x,
int y,
const char * txt,
uint8_t col )

prt prints a string to the vga screen at a given position

prt is a function that writes a null-terminated string to the vga text framebuffer handling newlines, line wrapping, and scrolling

Parameters
x,thecolumn to start printing at (0-79)
y,therow to start printing at (0-24)
txt,thenull-terminated string to print
col,thevga color attribute byte (0x00-0xFF)

using prt is done with

#include "../io/vga.h" //or just vga.h
prt(0, 0, "hello, kernel!", 0x0F); //white text on black bg
#define prt
Definition vga.h:6
See also
scrl(), pchr(), prtd(), prth()

Definition at line 62 of file vga.c.

References assert, NULL, scrl, and vga.

◆ __prtd()

void __prtd ( int x,
int y,
int num,
uint8_t col )

prtd prints a decimal integer to the vga screen

prtd is a function that converts an integer to a decimal string using itoa and prints it at the given position

Parameters
x,thecolumn to start printing at
y,therow to start printing at
num,thesigned integer to print
col,thevga color attribute byte

using prtd is done with

#include "../io/vga.h" //or just vga.h
prtd(0, 5, 42, 0x0F);
#define prtd
Definition vga.h:12
See also
prt(), prth(), itoa()

Definition at line 138 of file vga.c.

References itoa(), and prt.

◆ __prth()

void __prth ( int x,
int y,
uint32_t hex,
uint8_t col )

prth prints a 32 bit hex value to the vga screen

prth is a function that converts a uint32_t to an 8 character hexadecimal string and prints it at the given position

Parameters
x,thecolumn to start printing at
y,therow to start printing at
hex,the32 bit unsigned integer to print in hex
col,thevga color attribute byte

using prth is done with

#include "../io/vga.h" //or just vga.h
prth(0, 0, 0x00007C00, 0x0F);
#define prth
Definition vga.h:13
See also
prt(), prtd()

Definition at line 162 of file vga.c.

References prt.

◆ __rdln()

void __rdln ( char * buffer,
int maxlen )

rdln reads a line of text input from the keyboard

rdln is a function that reads keyboard input into a buffer, handling backspace, echoing characters, and returning on enter

Parameters
buffer,thebuffer to store the input string in
maxlen,themaximum length of the input including null

using rdln is done with

#include "../io/vga.h" //or just vga.h
char input[100];
rdln(input, 100);
#define rdln
Definition vga.h:9
See also
gtchr(), prt(), cob()

Definition at line 216 of file vga.c.

References assert, cnb, cob, gtchr, NULL, prt, and scrl.

◆ __scrl()

void __scrl ( void )

scrl scrolls the vga text screen up by one row

scrl is a function that shifts all rows up by one and clears the bottom row, used for when text output fills the screen

scrl is called automatically by prt when y goes past 24

See also
prt(), clscr()

Definition at line 30 of file vga.c.

References vga.

Variable Documentation

◆ vga

uint16_t* vga = (uint16_t*)0xB8000

the vga framebuffer pointer

vga points to the vga text-mode framebuffer at physical address 0xB8000, each cell is a uint16_t with the lower byte as the character and the upper byte as the color attribute

See also
prt(), clscr(), scrl()

Definition at line 18 of file vga.c.

Referenced by __clscr(), __panic(), __prt(), and __scrl().