summaryrefslogtreecommitdiff
path: root/sys/src/9/pc/vgahiqvideo.c
blob: 6314e783282d012a444b101e081fb8be308e4918 (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "../port/error.h"

#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
#include <cursor.h>
#include "screen.h"

enum {
	Xrx		= 0x3D6,	/* Configuration Extensions Index */
};

static uchar
hiqvideoxi(long port, uchar index)
{
	uchar data;

	outb(port, index);
	data = inb(port+1);

	return data;
}

static void
hiqvideoxo(long port, uchar index, uchar data)
{
	outb(port, index);
	outb(port+1, data);
}

static void
hiqvideolinear(VGAscr*, int, int)
{
}

static void
hiqvideoenable(VGAscr* scr)
{
	Pcidev *p;
	int vmsize;

	/*
	 * Only once, can't be disabled for now.
	 */
	if(scr->mmio)
		return;
	if(p = pcimatch(nil, 0x102C, 0)){
		switch(p->did){
		case 0x00C0:		/* 69000 HiQVideo */
			vmsize = 2*1024*1024;
			break;
		case 0x00E0:		/* 65550 HiQV32 */
		case 0x00E4:		/* 65554 HiQV32 */
		case 0x00E5:		/* 65555 HiQV32 */
			switch((hiqvideoxi(Xrx, 0x43)>>1) & 0x03){
			default:
			case 0:
				vmsize = 1*1024*1024;
				break;
			case 1:
				vmsize = 2*1024*1024;
				break;
			}
			break;
		default:
			return;
		}
	}
	else
		return;

	scr->pci = p;
	vgalinearpci(scr);
	
	if(scr->paddr) {
		addvgaseg("hiqvideoscreen", scr->paddr, scr->apsize);
	}

	/*
	 * Find a place for the cursor data in display memory.
	 * Must be on a 4096-byte boundary.
	 * scr->mmio holds the virtual address of the cursor
	 * storage area in the framebuffer region.
	 */
	scr->storage = vmsize-4096;
	scr->mmio = (ulong*)((uchar*)scr->vaddr+scr->storage);
}

static void
hiqvideocurdisable(VGAscr*)
{
	hiqvideoxo(Xrx, 0xA0, 0x10);
}

static void
hiqvideocurload(VGAscr* scr, Cursor* curs)
{
	uchar *p;
	int x, y;

	/*
	 * Disable the cursor.
	 */
	hiqvideocurdisable(scr);

	if(scr->mmio == 0)
		return;
	p = (uchar*)scr->mmio;

	for(y = 0; y < 16; y += 2){
		*p++ = ~(curs->clr[2*y]|curs->set[2*y]);
		*p++ = ~(curs->clr[2*y+1]|curs->set[2*y+1]);
		*p++ = 0xFF;
		*p++ = 0xFF;
		*p++ = ~(curs->clr[2*y+2]|curs->set[2*y+2]);
		*p++ = ~(curs->clr[2*y+3]|curs->set[2*y+3]);
		*p++ = 0xFF;
		*p++ = 0xFF;
		*p++ = curs->set[2*y];
		*p++ = curs->set[2*y+1];
		*p++ = 0x00;
		*p++ = 0x00;
		*p++ = curs->set[2*y+2];
		*p++ = curs->set[2*y+3];
		*p++ = 0x00;
		*p++ = 0x00;
	}
	while(y < 32){
		for(x = 0; x < 64; x += 8)
			*p++ = 0xFF;
		for(x = 0; x < 64; x += 8)
			*p++ = 0x00;
		y += 2;
	}

	/*
	 * Save the cursor hotpoint and enable the cursor.
	 */
	scr->offset = curs->offset;
	hiqvideoxo(Xrx, 0xA0, 0x11);
}

static int
hiqvideocurmove(VGAscr* scr, Point p)
{
	int x, y;

	if(scr->mmio == 0)
		return 1;

	if((x = p.x+scr->offset.x) < 0)
		x = 0x8000|(-x & 0x07FF);
	if((y = p.y+scr->offset.y) < 0)
		y = 0x8000|(-y & 0x07FF);

	hiqvideoxo(Xrx, 0xA4, x & 0xFF);
	hiqvideoxo(Xrx, 0xA5, (x>>8) & 0xFF);
	hiqvideoxo(Xrx, 0xA6, y & 0xFF);
	hiqvideoxo(Xrx, 0xA7, (y>>8) & 0xFF);

	return 0;
}

static void
hiqvideocurenable(VGAscr* scr)
{
	uchar xr80;

	hiqvideoenable(scr);
	if(scr->mmio == 0)
		return;

	/*
	 * Disable the cursor.
	 */
	hiqvideocurdisable(scr);

	/*
	 * Cursor colours.
	 * Can't call setcolor here as cursor is already locked.
	 * When done make sure the cursor enable in Xr80 is set.
	 */
	xr80 = hiqvideoxi(Xrx, 0x80);
	hiqvideoxo(Xrx, 0x80, xr80|0x01);
	vgao(PaddrW, 0x04);
	vgao(Pdata, Pwhite);
	vgao(Pdata, Pwhite);
	vgao(Pdata, Pwhite);
	vgao(Pdata, Pblack);
	vgao(Pdata, Pblack);
	vgao(Pdata, Pblack);
	hiqvideoxo(Xrx, 0x80, xr80|0x10);

	hiqvideoxo(Xrx, 0xA2, (scr->storage>>12)<<4);
	hiqvideoxo(Xrx, 0xA3, (scr->storage>>16) & 0x3F);

	/*
	 * Load, locate and enable the 32x32 cursor.
	 * Cursor enable in Xr80 better be set already.
	 */
	hiqvideocurload(scr, &arrow);
	hiqvideocurmove(scr, ZP);
	hiqvideoxo(Xrx, 0xA0, 0x11);
}

VGAdev vgahiqvideodev = {
	"hiqvideo",

	hiqvideoenable,			/* enable */
	nil,				/* disable */
	nil,				/* page */
	hiqvideolinear,			/* linear */
};

VGAcur vgahiqvideocur = {
	"hiqvideohwgc",

	hiqvideocurenable,		/* enable */
	hiqvideocurdisable,		/* disable */
	hiqvideocurload,		/* load */
	hiqvideocurmove,		/* move */
};