[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
vga.c File Reference
#include "devices/vga.h"
#include <round.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "threads/io.h"
#include "threads/interrupt.h"
#include "threads/vaddr.h"
Include dependency graph for vga.c:

Macros

#define COL_CNT   80
 
#define ROW_CNT   25
 
#define GRAY_ON_BLACK   0x07
 

Functions

static void clear_row (size_t y)
 
static void cls (void)
 
static void newline (void)
 
static void move_cursor (void)
 
static void find_cursor (size_t *x, size_t *y)
 
static void init (void)
 
void vga_putc (int c)
 

Variables

static size_t cx
 
static size_t cy
 
static uint8_t(* fb )[COL_CNT][2]
 

Macro Definition Documentation

◆ COL_CNT

#define COL_CNT   80

◆ GRAY_ON_BLACK

#define GRAY_ON_BLACK   0x07

◆ ROW_CNT

#define ROW_CNT   25

Function Documentation

◆ clear_row()

static void clear_row ( size_t  y)
static
108 {
109 size_t x;
110
111 for (x = 0; x < COL_CNT; x++)
112 {
113 fb[y][x][0] = ' ';
114 fb[y][x][1] = GRAY_ON_BLACK;
115 }
116}
#define GRAY_ON_BLACK
Definition: vga.c:21
#define COL_CNT
Definition: vga.c:13
static uint8_t(* fb)[COL_CNT][2]
Definition: vga.c:26
Here is the caller graph for this function:

◆ cls()

static void cls ( void  )
static
96 {
97 size_t y;
98
99 for (y = 0; y < ROW_CNT; y++)
100 clear_row (y);
101
102 cx = cy = 0;
103 move_cursor ();
104}
static size_t cy
Definition: vga.c:18
static void clear_row(size_t y)
Definition: vga.c:108
#define ROW_CNT
Definition: vga.c:14
static void move_cursor(void)
Definition: vga.c:135
static size_t cx
Definition: vga.c:18
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
144 {
145 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
146 uint16_t cp;
147
148 outb (0x3d4, 0x0e);
149 cp = inb (0x3d5) << 8;
150
151 outb (0x3d4, 0x0f);
152 cp |= inb (0x3d5);
153
154 *x = cp % COL_CNT;
155 *y = cp / COL_CNT;
156}
static uint8_t inb(uint16_t port)
Definition: io.h:49
static void outb(uint16_t port, uint8_t data)
Definition: io.h:109
unsigned short int uint16_t
Definition: stdint.h:23
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

static void init ( void  )
static
36 {
37 /* Already initialized? */
38 static bool inited;
39 if (!inited) {
40 fb = ptov (0xb8000);
41 find_cursor (&cx, &cy);
42 inited = true;
43 }
44}
static bool inited
Definition: random.c:21
#define ptov(paddr)
Definition: vaddr.h:49
static void find_cursor(size_t *x, size_t *y)
Definition: vga.c:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ move_cursor()

static void move_cursor ( void  )
static
135 {
136 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
137 uint16_t cp = cx + COL_CNT * cy;
138 outw (0x3d4, 0x0e | (cp & 0xff00));
139 outw (0x3d4, 0x0f | (cp << 8));
140}
static void outw(uint16_t port, uint16_t data)
Definition: io.h:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ newline()

static void newline ( void  )
static
122 {
123 cx = 0;
124 cy++;
125 if (cy >= ROW_CNT)
126 {
127 cy = ROW_CNT - 1;
128 memmove (&fb[0], &fb[1], sizeof fb[0] * (ROW_CNT - 1));
129 clear_row (ROW_CNT - 1);
130 }
131}
void * memmove(void *, const void *, size_t)
Definition: string.c:23
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vga_putc()

void vga_putc ( int  c)
49 {
50 /* Disable interrupts to lock out interrupt handlers
51 that might write to the console. */
52 enum intr_level old_level = intr_disable ();
53
54 init ();
55
56 switch (c) {
57 case '\n':
58 newline ();
59 break;
60
61 case '\f':
62 cls ();
63 break;
64
65 case '\b':
66 if (cx > 0)
67 cx--;
68 break;
69
70 case '\r':
71 cx = 0;
72 break;
73
74 case '\t':
75 cx = ROUND_UP (cx + 1, 8);
76 if (cx >= COL_CNT)
77 newline ();
78 break;
79
80 default:
81 fb[cy][cx][0] = c;
82 fb[cy][cx][1] = GRAY_ON_BLACK;
83 if (++cx >= COL_CNT)
84 newline ();
85 break;
86 }
87
88 /* Update cursor position. */
89 move_cursor ();
90
91 intr_set_level (old_level);
92}
enum intr_level intr_set_level(enum intr_level)
Definition: interrupt.c:130
enum intr_level intr_disable(void)
Definition: interrupt.c:151
intr_level
Definition: interrupt.h:8
#define ROUND_UP(X, STEP)
Definition: round.h:6
static void init(void)
Definition: vga.c:36
static void cls(void)
Definition: vga.c:96
static void newline(void)
Definition: vga.c:122
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cx

size_t cx
static

◆ cy

size_t cy
static

◆ fb

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