-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcga.cc
66 lines (54 loc) · 1.27 KB
/
cga.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "types.h"
#include "kernel.hh"
#include "amd64.h"
#include "cmdline.hh"
#include <string.h>
#define BACKSPACE 0x100
#define CRTPORT 0x3d4
static volatile u16 *crt = (u16*)(KBASE + 0xb8000); // CGA memory
// Black background, (high intensity) white foreground
static int color = ((0 << 4) | 15) << 8;
void
cgaputc(int c)
{
if (!cmdline_params.use_cga)
return;
int pos;
// Cursor position: col + 80*row.
outb(CRTPORT, 14);
pos = inb(CRTPORT+1) << 8;
outb(CRTPORT, 15);
pos |= inb(CRTPORT+1);
if(c == '\n')
pos += 80 - pos%80;
else if(c == BACKSPACE){
if(pos > 0) --pos;
} else
crt[pos++] = (c&0xff) | color;
if((pos/80) >= 24){ // Scroll up.
memmove((void *)crt, (void*)(crt+80), sizeof(crt[0])*23*80);
pos -= 80;
memset((void *)(crt+pos), 0, sizeof(crt[0])*(24*80 - pos));
}
outb(CRTPORT, 14);
outb(CRTPORT+1, pos>>8);
outb(CRTPORT, 15);
outb(CRTPORT+1, pos);
crt[pos] = ' ' | 0x0700;
}
void
initcga(void)
{
if (!cmdline_params.use_cga)
return;
int i;
for (i = 0; i < 80*25; i++)
crt[i] = 0x0f20;
outb(CRTPORT, 14);
outb(CRTPORT+1, 0);
outb(CRTPORT, 15);
outb(CRTPORT+1, 0);
// Announce that we're here.
for (const char *p=DEBUG?"xv6 DEBUG CGA\n":"xv6 CGA\n"; *p; p++)
cgaputc(*p);
}