Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pintos_forked_resit
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s2-alsaloumi
Pintos_forked_resit
Commits
ba2b4e15
Commit
ba2b4e15
authored
1 year ago
by
h2-addad
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
e5deb57b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/devices/vga.c
+172
-0
172 additions, 0 deletions
src/devices/vga.c
with
172 additions
and
0 deletions
src/devices/vga.c
0 → 100644
+
172
−
0
View file @
ba2b4e15
#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"
/* VGA text screen support. See [FREEVGA] for more information. */
/* Number of columns and rows on the text display. */
#define COL_CNT 80
#define ROW_CNT 25
/* Current cursor position. (0,0) is in the upper left corner of
the display. */
static
size_t
cx
,
cy
;
/* Attribute value for gray text on a black background. */
#define GRAY_ON_BLACK 0x07
/* 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]. */
static
uint8_t
(
*
fb
)[
COL_CNT
][
2
];
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
);
/* Initializes the VGA text display. */
static
void
init
(
void
)
{
/* Already initialized? */
static
bool
inited
;
if
(
!
inited
)
{
fb
=
ptov
(
0xb8000
);
find_cursor
(
&
cx
,
&
cy
);
inited
=
true
;
}
}
/* Writes C to the VGA text display, interpreting control
characters in the conventional ways. */
void
vga_putc
(
int
c
)
{
/* Disable interrupts to lock out interrupt handlers
that might write to the console. */
enum
intr_level
old_level
=
intr_disable
();
init
();
switch
(
c
)
{
case
'\n'
:
newline
();
break
;
case
'\f'
:
cls
();
break
;
case
'\b'
:
if
(
cx
>
0
)
cx
--
;
break
;
case
'\r'
:
cx
=
0
;
break
;
case
'\t'
:
cx
=
ROUND_UP
(
cx
+
1
,
8
);
if
(
cx
>=
COL_CNT
)
newline
();
break
;
case
'\a'
:
intr_set_level
(
old_level
);
speaker_beep
();
intr_disable
();
break
;
default:
fb
[
cy
][
cx
][
0
]
=
c
;
fb
[
cy
][
cx
][
1
]
=
GRAY_ON_BLACK
;
if
(
++
cx
>=
COL_CNT
)
newline
();
break
;
}
/* Update cursor position. */
move_cursor
();
intr_set_level
(
old_level
);
}
/* Clears the screen and moves the cursor to the upper left. */
static
void
cls
(
void
)
{
size_t
y
;
for
(
y
=
0
;
y
<
ROW_CNT
;
y
++
)
clear_row
(
y
);
cx
=
cy
=
0
;
move_cursor
();
}
/* Clears row Y to spaces. */
static
void
clear_row
(
size_t
y
)
{
size_t
x
;
for
(
x
=
0
;
x
<
COL_CNT
;
x
++
)
{
fb
[
y
][
x
][
0
]
=
' '
;
fb
[
y
][
x
][
1
]
=
GRAY_ON_BLACK
;
}
}
/* 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. */
static
void
newline
(
void
)
{
cx
=
0
;
cy
++
;
if
(
cy
>=
ROW_CNT
)
{
cy
=
ROW_CNT
-
1
;
memmove
(
&
fb
[
0
],
&
fb
[
1
],
sizeof
fb
[
0
]
*
(
ROW_CNT
-
1
));
clear_row
(
ROW_CNT
-
1
);
}
}
/* Moves the hardware cursor to (cx,cy). */
static
void
move_cursor
(
void
)
{
/* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
uint16_t
cp
=
cx
+
COL_CNT
*
cy
;
outw
(
0x3d4
,
0x0e
|
(
cp
&
0xff00
));
outw
(
0x3d4
,
0x0f
|
(
cp
<<
8
));
}
/* Reads the current hardware cursor position into (*X,*Y). */
static
void
find_cursor
(
size_t
*
x
,
size_t
*
y
)
{
/* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
uint16_t
cp
;
outb
(
0x3d4
,
0x0e
);
cp
=
inb
(
0x3d5
)
<<
8
;
outb
(
0x3d4
,
0x0f
);
cp
|=
inb
(
0x3d5
);
*
x
=
cp
%
COL_CNT
;
*
y
=
cp
/
COL_CNT
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment