mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-25 20:10:29 +00:00
Add basic character output for VGA graphics mode console (#649)
* Test output of colors for VGA graphics modes in examples/vga.c * [metal] Character output in VGA graphics modes is mostly working * [metal] Mention magic key to switch video mode, at bootup
This commit is contained in:
parent
b75a4654cf
commit
edb8fef06c
8 changed files with 2059 additions and 324 deletions
|
@ -52,185 +52,6 @@ ssize_t sys_writev_vga(struct Fd *fd, const struct iovec *iov, int iovlen) {
|
|||
return wrote;
|
||||
}
|
||||
|
||||
static void _vga_init_test(void *vid_buf, unsigned char vid_type,
|
||||
size_t stride) {
|
||||
switch (vid_type) {
|
||||
case PC_VIDEO_TEXT:
|
||||
break;
|
||||
case PC_VIDEO_BGR565:
|
||||
{
|
||||
char *row_buf = (char *)vid_buf + stride * 100;
|
||||
uint16_t *row_pix = (uint16_t *)row_buf;
|
||||
unsigned i;
|
||||
row_pix[0] = 0x0000;
|
||||
row_pix[1] = 0x0000;
|
||||
row_pix[2] = 0x07fc;
|
||||
row_pix[3] = 0x07fc;
|
||||
row_pix[4] = 0x07fc;
|
||||
row_pix[5] = 0x0000;
|
||||
row_pix[6] = 0x0000;
|
||||
row_pix[7] = 0x0000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint16_t *)row_buf;
|
||||
row_pix[0] = 0x0000;
|
||||
row_pix[1] = 0x07fc;
|
||||
row_pix[2] = 0x07fc;
|
||||
row_pix[3] = 0x07fc;
|
||||
row_pix[4] = 0x07fc;
|
||||
row_pix[5] = 0x07fc;
|
||||
row_pix[6] = 0x0000;
|
||||
row_pix[7] = 0x0000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint16_t *)row_buf;
|
||||
row_pix[0] = 0x07fc;
|
||||
row_pix[1] = 0x07fc;
|
||||
row_pix[2] = 0x0000;
|
||||
row_pix[3] = 0x0000;
|
||||
row_pix[4] = 0x0000;
|
||||
row_pix[5] = 0x07fc;
|
||||
row_pix[6] = 0x07fc;
|
||||
row_pix[7] = 0x0000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint16_t *)row_buf;
|
||||
row_pix[0] = 0x07fc;
|
||||
row_pix[1] = 0x07fc;
|
||||
row_pix[2] = 0x07fc;
|
||||
row_pix[3] = 0x07fc;
|
||||
row_pix[4] = 0x07fc;
|
||||
row_pix[5] = 0x07fc;
|
||||
row_pix[6] = 0x07fc;
|
||||
row_pix[7] = 0x0000;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
row_buf += stride;
|
||||
row_pix = (uint16_t *)row_buf;
|
||||
row_pix[0] = 0xf81f;
|
||||
row_pix[1] = 0xf81f;
|
||||
row_pix[2] = 0x0000;
|
||||
row_pix[3] = 0x0000;
|
||||
row_pix[4] = 0x0000;
|
||||
row_pix[5] = 0xf81f;
|
||||
row_pix[6] = 0xf81f;
|
||||
row_pix[7] = 0x0000;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PC_VIDEO_BGR555:
|
||||
{
|
||||
char *row_buf = (char *)vid_buf + stride * 100;
|
||||
uint16_t *row_pix = (uint16_t *)row_buf;
|
||||
unsigned i;
|
||||
row_pix[0] = 0x8000;
|
||||
row_pix[1] = 0x8000;
|
||||
row_pix[2] = 0x83fc;
|
||||
row_pix[3] = 0x83fc;
|
||||
row_pix[4] = 0x83fc;
|
||||
row_pix[5] = 0x8000;
|
||||
row_pix[6] = 0x8000;
|
||||
row_pix[7] = 0x8000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint16_t *)row_buf;
|
||||
row_pix[0] = 0x8000;
|
||||
row_pix[1] = 0x83fc;
|
||||
row_pix[2] = 0x83fc;
|
||||
row_pix[3] = 0x83fc;
|
||||
row_pix[4] = 0x83fc;
|
||||
row_pix[5] = 0x83fc;
|
||||
row_pix[6] = 0x8000;
|
||||
row_pix[7] = 0x8000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint16_t *)row_buf;
|
||||
row_pix[0] = 0x83fc;
|
||||
row_pix[1] = 0x83fc;
|
||||
row_pix[2] = 0x8000;
|
||||
row_pix[3] = 0x8000;
|
||||
row_pix[4] = 0x8000;
|
||||
row_pix[5] = 0x83fc;
|
||||
row_pix[6] = 0x83fc;
|
||||
row_pix[7] = 0x8000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint16_t *)row_buf;
|
||||
row_pix[0] = 0x83fc;
|
||||
row_pix[1] = 0x83fc;
|
||||
row_pix[2] = 0x83fc;
|
||||
row_pix[3] = 0x83fc;
|
||||
row_pix[4] = 0x83fc;
|
||||
row_pix[5] = 0x83fc;
|
||||
row_pix[6] = 0x83fc;
|
||||
row_pix[7] = 0x8000;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
row_buf += stride;
|
||||
row_pix = (uint16_t *)row_buf;
|
||||
row_pix[0] = 0xfc1f;
|
||||
row_pix[1] = 0xfc1f;
|
||||
row_pix[2] = 0x8000;
|
||||
row_pix[3] = 0x8000;
|
||||
row_pix[4] = 0x8000;
|
||||
row_pix[5] = 0xfc1f;
|
||||
row_pix[6] = 0xfc1f;
|
||||
row_pix[7] = 0x8000;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
char *row_buf = (char *)vid_buf + stride * 100;
|
||||
uint32_t *row_pix = (uint32_t *)row_buf;
|
||||
unsigned i;
|
||||
row_pix[0] = 0xff000000;
|
||||
row_pix[1] = 0xff000000;
|
||||
row_pix[2] = 0xff00ffe0;
|
||||
row_pix[3] = 0xff00ffe0;
|
||||
row_pix[4] = 0xff00ffe0;
|
||||
row_pix[5] = 0xff000000;
|
||||
row_pix[6] = 0xff000000;
|
||||
row_pix[7] = 0xff000000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint32_t *)row_buf;
|
||||
row_pix[0] = 0xff000000;
|
||||
row_pix[1] = 0xff00ffe0;
|
||||
row_pix[2] = 0xff00ffe0;
|
||||
row_pix[3] = 0xff00ffe0;
|
||||
row_pix[4] = 0xff00ffe0;
|
||||
row_pix[5] = 0xff00ffe0;
|
||||
row_pix[6] = 0xff000000;
|
||||
row_pix[7] = 0xff000000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint32_t *)row_buf;
|
||||
row_pix[0] = 0xff00ffe0;
|
||||
row_pix[1] = 0xff00ffe0;
|
||||
row_pix[2] = 0xff000000;
|
||||
row_pix[3] = 0xff000000;
|
||||
row_pix[4] = 0xff000000;
|
||||
row_pix[5] = 0xff00ffe0;
|
||||
row_pix[6] = 0xff00ffe0;
|
||||
row_pix[7] = 0xff000000;
|
||||
row_buf += stride;
|
||||
row_pix = (uint32_t *)row_buf;
|
||||
row_pix[0] = 0xff00ffe0;
|
||||
row_pix[1] = 0xff00ffe0;
|
||||
row_pix[2] = 0xff00ffe0;
|
||||
row_pix[3] = 0xff00ffe0;
|
||||
row_pix[4] = 0xff00ffe0;
|
||||
row_pix[5] = 0xff00ffe0;
|
||||
row_pix[6] = 0xff00ffe0;
|
||||
row_pix[7] = 0xff000000;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
row_buf += stride;
|
||||
row_pix = (uint32_t *)row_buf;
|
||||
row_pix[0] = 0xffff00ff;
|
||||
row_pix[1] = 0xffff00ff;
|
||||
row_pix[2] = 0xff000000;
|
||||
row_pix[3] = 0xff000000;
|
||||
row_pix[4] = 0xff000000;
|
||||
row_pix[5] = 0xffff00ff;
|
||||
row_pix[6] = 0xffff00ff;
|
||||
row_pix[7] = 0xff000000;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((__constructor__)) static textstartup void _vga_init(void) {
|
||||
if (IsMetal()) {
|
||||
struct mman *mm = (struct mman *)(BANE + 0x0500);
|
||||
|
@ -249,21 +70,22 @@ __attribute__((__constructor__)) static textstartup void _vga_init(void) {
|
|||
unsigned char col, row;
|
||||
} bios_curs_pos_t;
|
||||
bios_curs_pos_t pos = *(bios_curs_pos_t *)(BANE + 0x0450ull);
|
||||
uint8_t chr_ht = *(uint8_t *)(BANE + 0x0485ull),
|
||||
chr_ht_hi = *(uint8_t *)(BANE + 0x0486ull);
|
||||
if (chr_ht_hi != 0 || chr_ht > 32)
|
||||
chr_ht = 32;
|
||||
uint8_t chr_ht, chr_ht_hi, chr_wid;
|
||||
if (vid_type == PC_VIDEO_TEXT) {
|
||||
chr_ht = *(uint8_t *)(BANE + 0x0485ull),
|
||||
chr_ht_hi = *(uint8_t *)(BANE + 0x0486ull);
|
||||
if (chr_ht_hi != 0 || chr_ht > 32 || chr_ht < 2)
|
||||
chr_ht = VGA_ASSUME_CHAR_HEIGHT_PX;
|
||||
} else
|
||||
chr_ht = VGA_ASSUME_CHAR_HEIGHT_PX;
|
||||
chr_wid = VGA_ASSUME_CHAR_WIDTH_PX;
|
||||
/* Make sure the video buffer is mapped into virtual memory. */
|
||||
__invert_memory_area(mm, __get_pml4t(), vid_buf_phy, vid_buf_sz, PAGE_RW);
|
||||
#if 1
|
||||
/* Test video frame buffer output. */
|
||||
_vga_init_test(vid_buf, vid_type, stride);
|
||||
#endif
|
||||
/*
|
||||
* Initialize our tty structure from the current screen geometry,
|
||||
* screen contents, cursor position, & character height.
|
||||
* screen contents, cursor position, & character dimensions.
|
||||
*/
|
||||
_StartTty(&_vga_tty, height, width, pos.row, pos.col, chr_ht,
|
||||
vid_buf, NULL);
|
||||
_StartTty(&_vga_tty, vid_type, height, width, stride, pos.row, pos.col,
|
||||
chr_ht, chr_wid, vid_buf, false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue