AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
fb.c
Go to the documentation of this file.
1
9
10
#include <
core/system.h
>
11
#include <
core/string.h
>
12
#include <
dev/fbdev.h
>
13
#include <
dev/vt.h
>
14
15
#define FONT_W 8
16
#define FONT_H 16
17
18
/* the font: code page 437, from the early console */
19
extern
const
unsigned
char
font_8x16
[];
20
21
/* the framebuffer device, if the kernel has a framebuffer driver */
22
extern
struct
fbdev
*
fbdev_primary
(
void
) __attribute__((weak));
23
24
static
uint8_t
*
fb
;
25
static
uint32_t
pitch
,
bytes_pp
;
26
29
static
inline
void
put_pixel
(
uint8_t
*p,
uint32_t
rgb)
30
{
31
switch
(
bytes_pp
) {
32
case
4:
33
*(
uint32_t
*) p = rgb;
34
break
;
35
case
3:
36
p[0] = rgb;
37
p[1] = rgb >> 8;
38
p[2] = rgb >> 16;
39
break
;
40
case
2:
41
*(
uint16_t
*) p = ((rgb >> 8) & 0xf800) | ((rgb >> 5) & 0x07e0) | ((rgb >> 3) & 0x001f);
42
break
;
43
}
44
}
45
48
static
void
fb_draw
(
int
row,
int
col,
struct
vt_cell
cell)
49
{
50
uint8_t
fg = cell.
fg
, bg = cell.
bg
;
51
52
if
((cell.
attr
&
VT_BOLD
) && fg < 8)
53
fg += 8;
54
55
if
(cell.
attr
&
VT_REVERSE
) {
56
uint8_t
t = fg;
57
fg = bg;
58
bg = t;
59
}
60
61
uint32_t
fg_rgb =
vt_palette
(fg), bg_rgb =
vt_palette
(bg);
62
63
if
(cell.
attr
&
VT_DIM
)
64
fg_rgb = (fg_rgb >> 1) & 0x7f7f7f;
65
66
if
(cell.
attr
&
VT_INVISIBLE
)
67
fg_rgb = bg_rgb;
68
69
const
uint8_t
*glyph = &
font_8x16
[cell.
ch
*
FONT_H
];
70
uint8_t
*line =
fb
+ row *
FONT_H
*
pitch
+ col *
FONT_W
*
bytes_pp
;
71
72
for
(
int
y = 0; y <
FONT_H
; ++y, line +=
pitch
) {
73
uint8_t
bits = glyph[y];
74
75
if
((cell.
attr
&
VT_UNDERLINE
) && y ==
FONT_H
- 2)
76
bits = 0xff;
77
78
/* an underline cursor, like the Linux console's */
79
if
((cell.
attr
&
VT_CURSOR
) && y >=
FONT_H
- 2)
80
bits = 0xff;
81
82
if
(
bytes_pp
== 4) {
83
uint32_t
*p = (
uint32_t
*) line;
84
for
(
int
x = 0; x <
FONT_W
; ++x)
85
p[x] = bits & (0x80 >> x) ? fg_rgb : bg_rgb;
86
}
else
{
87
for
(
int
x = 0; x <
FONT_W
; ++x)
88
put_pixel
(line + x *
bytes_pp
, bits & (0x80 >> x) ? fg_rgb : bg_rgb);
89
}
90
}
91
}
92
100
int
vt_fb_probe
(
void
)
101
{
102
struct
fbdev
*
dev
=
fbdev_primary
?
fbdev_primary
() :
NULL
;
103
104
if
(!
dev
|| !
dev
->fix_screeninfo || !
dev
->var_screeninfo)
105
return
-ENODEV;
106
107
struct
fb_fix_screeninfo *fix =
dev
->fix_screeninfo;
108
struct
fb_var_screeninfo *var =
dev
->var_screeninfo;
109
110
if
(var->bits_per_pixel != 32 && var->bits_per_pixel != 24 && var->bits_per_pixel != 16)
111
return
-ENODEV;
112
113
fb
= (
uint8_t
*) fix->smem_start;
114
pitch
= fix->line_length;
115
bytes_pp
= var->bits_per_pixel / 8;
116
117
vt_fb_display
.
rows
= var->yres /
FONT_H
;
118
vt_fb_display
.
cols
= var->xres /
FONT_W
;
119
120
if
(!
vt_fb_display
.
rows
|| !
vt_fb_display
.
cols
)
121
return
-ENODEV;
122
123
/* clear the whole screen: the terminals don't draw on the margins,
124
* and the early console may have */
125
memset
(
fb
, 0, var->yres *
pitch
);
126
127
return
0;
128
}
129
130
struct
vt_display
vt_fb_display
= {
131
.name =
"framebuffer"
,
132
.draw =
fb_draw
,
133
};
FONT_H
#define FONT_H
Definition
fb.c:16
pitch
static uint32_t pitch
Definition
fb.c:25
FONT_W
#define FONT_W
Definition
fb.c:15
fb_draw
static void fb_draw(int row, int col, struct vt_cell cell)
Draws one cell of the terminal: its character's glyph, in its colours and attributes (bold,...
Definition
fb.c:48
bytes_pp
static uint32_t bytes_pp
Definition
fb.c:25
put_pixel
static void put_pixel(uint8_t *p, uint32_t rgb)
Writes one pixel of colour rgb (0xRRGGBB) at p, in the framebuffer's pixel format.
Definition
fb.c:29
vt_fb_probe
int vt_fb_probe(void)
Sets up the virtual terminals on the framebuffer, if there is one the terminals can draw on,...
Definition
fb.c:100
vt_fb_display
struct vt_display vt_fb_display
Definition
fb.c:130
fb
static uint8_t * fb
Definition
fb.c:24
fbdev_primary
struct fbdev * fbdev_primary(void)
Returns the first framebuffer, once it is set up, for the virtual terminals.
Definition
fbdev.c:63
fbdev.h
font_8x16
const unsigned char font_8x16[256 *16]
Definition
font.h:7
system.h
memset
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
Definition
libc.c:23
NULL
#define NULL
Definition
stddef.h:27
uint32_t
unsigned int uint32_t
Definition
stddef.h:22
uint8_t
unsigned char uint8_t
Definition
stddef.h:20
uint16_t
unsigned short int uint16_t
Definition
stddef.h:21
string.h
dev
A device driver: its operations, any of which may be NULL.
Definition
dev.h:28
fbdev
A framebuffer: its driver, its screen's information, its operations.
Definition
fbdev.h:23
vt_cell
A character cell.
Definition
vt.h:35
vt_cell::fg
uint8_t fg
Definition
vt.h:38
vt_cell::ch
uint8_t ch
Definition
vt.h:36
vt_cell::bg
uint8_t bg
Definition
vt.h:39
vt_cell::attr
uint8_t attr
Definition
vt.h:37
vt_display
A display that virtual terminals are shown on.
Definition
vt.h:43
vt_display::rows
int rows
Definition
vt.h:45
vt_display::cols
int cols
Definition
vt.h:45
vt_palette
uint32_t vt_palette(uint8_t color)
Returns one of the 256 colours of xterm's palette: the 16 colours, a 6 x 6 x 6 cube,...
Definition
vt.c:73
vt.h
VT_CURSOR
#define VT_CURSOR
Definition
vt.h:32
VT_UNDERLINE
#define VT_UNDERLINE
Definition
vt.h:27
VT_REVERSE
#define VT_REVERSE
Definition
vt.h:29
VT_DIM
#define VT_DIM
Definition
vt.h:26
VT_INVISIBLE
#define VT_INVISIBLE
Definition
vt.h:30
VT_BOLD
#define VT_BOLD
Definition
vt.h:25
kernel
dev
tty
vt
fb.c
Generated by
1.18.0