PKUOS - Pintos
Pintos source browser for PKU Operating System course
Macros | Functions | Variables
vga.c File Reference
#include "devices/vga.h"
#include <round.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "devices/speaker.h"
#include "threads/io.h"
#include "threads/interrupt.h"
#include "threads/vaddr.h"
Include dependency graph for vga.c:

Go to the source code of this file.

Macros

#define COL_CNT   80
 VGA text screen support. More...
 
#define ROW_CNT   25
 
#define GRAY_ON_BLACK   0x07
 Attribute value for gray text on a black background. More...
 

Functions

static void clear_row (size_t y)
 Clears row Y to spaces. More...
 
static void cls (void)
 Clears the screen and moves the cursor to the upper left. More...
 
static void newline (void)
 Advances the cursor to the first column in the next line on the screen. More...
 
static void move_cursor (void)
 Moves the hardware cursor to (cx,cy). More...
 
static void find_cursor (size_t *x, size_t *y)
 Reads the current hardware cursor position into (*X,*Y). More...
 
static void init (void)
 Initializes the VGA text display. More...
 
void vga_putc (int c)
 Writes C to the VGA text display, interpreting control characters in the conventional ways. More...
 

Variables

static size_t cx
 Current cursor position. More...
 
static size_t cy
 
static uint8_t(* fb )[COL_CNT][2]
 Framebuffer. More...
 

Macro Definition Documentation

◆ COL_CNT

#define COL_CNT   80

VGA text screen support.

See [FREEVGA] for more information. Number of columns and rows on the text display.

Definition at line 14 of file vga.c.

◆ GRAY_ON_BLACK

#define GRAY_ON_BLACK   0x07

Attribute value for gray text on a black background.

Definition at line 22 of file vga.c.

◆ ROW_CNT

#define ROW_CNT   25

Definition at line 15 of file vga.c.

Function Documentation

◆ clear_row()

static void clear_row ( size_t  y)
static

Clears row Y to spaces.

Definition at line 120 of file vga.c.

References COL_CNT, fb, GRAY_ON_BLACK, and x.

Referenced by cls(), and newline().

Here is the caller graph for this function:

◆ cls()

static void cls ( void  )
static

Clears the screen and moves the cursor to the upper left.

Definition at line 107 of file vga.c.

References clear_row(), cx, cy, move_cursor(), and ROW_CNT.

Referenced by vga_putc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_cursor()

static void find_cursor ( size_t x,
size_t y 
)
static

Reads the current hardware cursor position into (*X,*Y).

Definition at line 159 of file vga.c.

References COL_CNT, inb(), outb(), and x.

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

static void init ( void  )
static

Initializes the VGA text display.

Definition at line 37 of file vga.c.

References cx, cy, fb, find_cursor(), inited, and ptov().

Referenced by vga_putc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ move_cursor()

static void move_cursor ( void  )
static

Moves the hardware cursor to (cx,cy).

Definition at line 149 of file vga.c.

References COL_CNT, cx, cy, and outw().

Referenced by cls(), and vga_putc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ newline()

static void newline ( void  )
static

Advances the cursor to the first column in the next line on the screen.

If the cursor is already on the last line on the screen, scrolls the screen upward one line.

Definition at line 135 of file vga.c.

References clear_row(), cx, cy, fb, memmove(), and ROW_CNT.

Referenced by vga_putc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vga_putc()

void vga_putc ( int  c)

Writes C to the VGA text display, interpreting control characters in the conventional ways.

devices/vga.h


Definition at line 52 of file vga.c.

References cls(), COL_CNT, cx, cy, fb, GRAY_ON_BLACK, init(), intr_disable(), intr_set_level(), move_cursor(), newline(), ROUND_UP, and speaker_beep().

Referenced by putchar_have_lock().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cx

size_t cx
static

Current cursor position.

(0,0) is in the upper left corner of the display.

Definition at line 19 of file vga.c.

Referenced by cls(), init(), move_cursor(), newline(), and vga_putc().

◆ cy

size_t cy
static

Definition at line 19 of file vga.c.

Referenced by cls(), init(), move_cursor(), newline(), and vga_putc().

◆ fb

uint8_t(* fb)[COL_CNT][2]
static

Framebuffer.

See [FREEVGA] under "VGA Text Mode Operation". The character at (x,y) is fb[y][x][0]. The attribute at (x,y) is fb[y][x][1].

Definition at line 27 of file vga.c.

Referenced by clear_row(), init(), newline(), and vga_putc().