AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vga.c
Go to the documentation of this file.
1
9
10#include <core/system.h>
11#include <cpu/io.h>
12#include <mm/mm.h>
13#include <dev/vt.h>
14
15#define VGA_ROWS 25
16#define VGA_COLS 80
17
18static uint16_t *vga = (uint16_t *) VMA(0xB8000);
19
20static struct ioaddr crtc = {
21 .addr = 0x3D4,
22 .type = IOADDR_PORT,
23};
24
26static void vga_draw(int row, int col, struct vt_cell cell)
27{
28 vga[row * VGA_COLS + col] = vt_vga_attr(cell) << 8 | cell.ch;
29}
30
32static void vga_cursor(int row, int col, int visible)
33{
34 /* a hidden cursor is one past the end of the screen */
35 unsigned pos = visible ? row * VGA_COLS + col : VGA_ROWS * VGA_COLS;
36
37 io_out8(&crtc, 0x00, 0x0F);
38 io_out8(&crtc, 0x01, pos & 0xFF);
39 io_out8(&crtc, 0x00, 0x0E);
40 io_out8(&crtc, 0x01, (pos >> 8) & 0xFF);
41}
42
48int vt_vga_probe(void)
49{
50 return 0;
51}
52
54 .name = "VGA text mode",
55 .rows = VGA_ROWS,
56 .cols = VGA_COLS,
57 .draw = vga_draw,
58 .cursor = vga_cursor,
59};
static void io_out8(struct ioaddr *io, uintptr_t off, uint8_t val)
Writes an 8-, 16- or 32-bit register.
Definition io.h:44
#define VMA(obj)
Definition mm.h:36
#define VGA_ROWS
Definition vga.c:22
static char * vga
Definition vga.c:14
#define VGA_COLS
Definition vga.c:21
#define IOADDR_PORT
Definition io.h:89
static void vga_draw(int row, int col, struct vt_cell cell)
Draws one cell of the screen.
Definition vga.c:26
static struct ioaddr crtc
Definition vga.c:20
static void vga_cursor(int row, int col, int visible)
Moves the cursor, or hides it.
Definition vga.c:32
int vt_vga_probe(void)
Says whether VGA text mode can be used.
Definition vga.c:48
struct vt_display vt_vga_display
Definition vga.c:53
unsigned short int uint16_t
Definition stddef.h:21
Where a device's registers are.
Definition io.h:95
A character cell.
Definition vt.h:35
uint8_t ch
Definition vt.h:36
A display that virtual terminals are shown on.
Definition vt.h:43
uint8_t vt_vga_attr(struct vt_cell cell)
Returns the VGA text mode attribute of a cell (its colours, in VGA's order), for the VGA display and ...
Definition vt.c:122