~kris/9p

9hist

ref: 46b0c67fbbcbc663a834fd325958a1fd4e425bc2 9hist/pc/cga.c -rw-r--r-- 839 bytes
46b0c67f — David du Colombier Plan 9 from Bell Labs 1991-11-25 34 years ago
                                                                                
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
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"

#define	WIDTH	160
#define	HEIGHT	24
#define SCREEN	((char *)(0xB8000|KZERO))
int pos;

void
screeninit(void)
{
	memset(SCREEN+pos, 0, WIDTH*HEIGHT-pos);
}

void
screenputc(int c)
{
	int i;
	static int color;

	if(c == '\n'){
		pos = pos/WIDTH;
		pos = (pos+1)*WIDTH;
	} else if(c == '\t'){
		i = 8 - ((pos/2)&7);
		while(i-->0)
			screenputc(' ');
	} else if(c == '\b'){
		if(pos >= 2)
			pos -= 2;
		screenputc(' ');
		pos -= 2;
	} else {
		SCREEN[pos++] = c;
		SCREEN[pos++] = 0x1d;
	}
	if(pos >= WIDTH*HEIGHT){
		memmove(SCREEN, &SCREEN[WIDTH], WIDTH*(HEIGHT-1));
		memset(&SCREEN[WIDTH*(HEIGHT-1)], 0, WIDTH);
		pos = WIDTH*(HEIGHT-1);
	}
}

void
screenputs(char *s, int n)
{
	while(n-- > 0)
		screenputc(*s++);
}

int
screenbits(void)
{
	return 4;
}