~kris/9p

9hist

ref: bf48946ab64f5efb633b696dc17f70880b3a2f71 9hist/pc/cga.c -rw-r--r-- 3.1 KiB
bf48946a — David du Colombier Plan 9 from Bell Labs 1992-05-14 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include	"u.h"
#include	"../port/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)
{
	void vgadump(void);

	memset(SCREEN+pos, 0, WIDTH*HEIGHT-pos);
	vgadump();
}

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;
}


#include	<libg.h>
#include	<gnot.h>
#include	"screen.h"

/*
 *  screen dimensions
 */
#define MAXX	640
#define MAXY	480

#define SCREENMEM	(0xA0000 | KZERO)
GBitmap	gscreen =
{
	(ulong*)SCREENMEM,
	0,
	640/32,
	0,
	0, 0, MAXX, MAXY,
	0
};

typedef struct VGAmode	VGAmode;
struct VGAmode
{
	uchar	general[4];
	uchar	sequencer[5];
	uchar	crt[0x19];
	uchar	graphics[9];
	uchar	attribute[0x15];
};

enum
{
	EMISCR=		0x3CC,		/* control sync polarity */
	EMISCW=		0x3C2,
	EFCW=		0x3DA,		/* feature control */
	EFCR=		0x3CA,
	GRX=		0x3CE,		/* index to graphics registers */
	GR=		0x3CF,		/* graphics registers */
	 Grms=		 0x04,		/*  read map select register */
	SRX=		0x3C4,		/* index to sequence registers */
	SR=		0x3C5,		/* sequence registers */
	 Smmask=	 0x02,		/*  map mask */
	CRX=		0x3D4,		/* index to crt registers */
	CR=		0x3D5,		/* crt registers */
	 Cvre=		 0x11,		/*  vertical retrace end */
	ARX=		0x3C0,		/* index to attribute registers */
	AR=		0x3C1,		/* attribute registers */
};

uchar
genin(int reg)
{
	if(reg == 0)
		return inb(EMISCR);
	else if (reg == 1)
		return inb(EFCR);
}
uchar
srin(int reg)
{
	outb(SRX, reg);
	return inb(SR);
}
uchar
grin(int reg)
{
	outb(GRX, reg);
	return inb(GR);
}
uchar
arin(int reg)
{
	inb(0x3DA);
	outb(ARX, reg | 0x20);
	return inb(AR);
}
uchar
crin(int reg)
{
	outb(CRX, reg);
	return inb(CR);
}

void
vgadump(void)
{
	int i;
	VGAmode *v;

	print("GEN ");
	for(i = 0; i < sizeof(v->general); i++)
		print("%d-%ux ", i, genin(i));
	print("\nSR ");
	for(i = 0; i < sizeof(v->sequencer); i++)
		print("%d-%ux ", i, srin(i));
	print("\nCR ");
	for(i = 0; i < sizeof(v->crt); i++)
		print("%d-%ux ", i, crin(i));
	print("\nGR ");
	for(i = 0; i < sizeof(v->graphics); i++)
		print("%d-%ux ", i, grin(i));
	print("\nAR ");
	for(i = 0; i < sizeof(v->attribute); i++)
		print("%d-%ux ", i, arin(i));
	print("\n ");
}

void
bigcursor(void)
{}

void
getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
{
	ulong ans;

	/*
	 * The safari monochrome says 0 is black (zero intensity)
	 */
	if(p == 0)
		ans = 0;
	else
		ans = ~0;
	*pr = *pg = *pb = ans;
}


int
setcolor(ulong p, ulong r, ulong g, ulong b)
{
	return 0;	/* can't change mono screen colormap */
}

void
mouseclock(void)
{
	mouseupdate(1);
}