]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/vgatvp3026.c
kernel: cleanup makefile for $CONF.$O target
[plan9front.git] / sys / src / 9 / pc / vgatvp3026.c
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 #include "io.h"
7 #include "../port/error.h"
8
9 #define Image   IMAGE
10 #include <draw.h>
11 #include <memdraw.h>
12 #include <cursor.h>
13 #include "screen.h"
14
15 /*
16  * TVP3026 Viewpoint Video Interface Pallette.
17  * Assumes hooked up to an S3 Vision968.
18  */
19 enum {
20         Index           = 0x00,         /* Index */
21         Data            = 0x0A,         /* Data */
22
23         CaddrW          = 0x04,         /* Colour Write Address */
24         Cdata           = 0x05,         /* Colour Data */
25
26         Cctl            = 0x09,         /* Direct Cursor Control */
27         Cram            = 0x0B,         /* Cursor Ram Data */
28         Cxlsb           = 0x0C,         /* Cursor X LSB */
29         Cxmsb           = 0x0D,         /* Cursor X MSB */
30         Cylsb           = 0x0E,         /* Cursor Y LSB */
31         Cymsb           = 0x0F,         /* Cursor Y MSB */
32
33         Icctl           = 0x06,         /* Indirect Cursor Control */
34 };
35
36 /*
37  * Lower 2-bits of indirect DAC register
38  * addressing.
39  */
40 static ushort dacxreg[4] = {
41         PaddrW, Pdata, Pixmask, PaddrR
42 };
43
44 static uchar
45 tvp3026io(uchar reg, uchar data)
46 {
47         uchar crt55;
48
49         crt55 = vgaxi(Crtx, 0x55) & 0xFC;
50         vgaxo(Crtx, 0x55, crt55|((reg>>2) & 0x03));
51         vgao(dacxreg[reg & 0x03], data);
52
53         return crt55;
54 }
55
56 static void
57 tvp3026o(uchar reg, uchar data)
58 {
59         uchar crt55;
60
61         crt55 = tvp3026io(reg, data);
62         vgaxo(Crtx, 0x55, crt55);
63 }
64
65 void
66 tvp3026xo(uchar index, uchar data)
67 {
68         uchar crt55;
69
70         crt55 = tvp3026io(Index, index);
71         vgaxo(Crtx, 0x55, crt55|((Data>>2) & 0x03));
72         vgao(dacxreg[Data & 0x03], data);
73         vgaxo(Crtx, 0x55, crt55);
74 }
75
76 static void
77 tvp3026disable(VGAscr*)
78 {
79         tvp3026xo(Icctl, 0x90);
80         tvp3026o(Cctl, 0x00);
81 }
82
83 static void
84 tvp3026enable(VGAscr*)
85 {
86         /*
87          * Make sure cursor is off and direct control enabled.
88          */
89         tvp3026xo(Icctl, 0x90);
90         tvp3026o(Cctl, 0x00);
91
92         /*
93          * Overscan colour,
94          * cursor colour 1 (white),
95          * cursor colour 2, 3 (black).
96          */
97         tvp3026o(CaddrW, 0x00);
98         tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite);
99         tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite);
100         tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack);
101         tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack);
102
103         /*
104          * Enable the cursor in 3-colour mode.
105          */
106         tvp3026o(Cctl, 0x01);
107 }
108
109 static void
110 tvp3026load(VGAscr* scr, Cursor* curs)
111 {
112         int x, y;
113
114         /*
115          * Make sure cursor is off by initialising the cursor
116          * control to defaults.
117          * Write to the indirect control register to make sure
118          * direct register is enabled and upper 2 bits of cursor
119          * RAM address are 0.
120          * The LSBs of the cursor RAM address are in PaddrW.
121          */
122         tvp3026xo(Icctl, 0x90);
123         tvp3026o(Cctl, 0x00);
124         vgao(PaddrW, 0x00);
125
126         /*
127          * Initialise the 64x64 cursor RAM array. There are 2 planes,
128          * p0 and p1. Data is written 8 pixels per byte, with p0 in the
129          * first 512 bytes of the array and p1 in the second.
130          * The cursor is set in 3-colour mode which gives the following
131          * truth table:
132          *      p1 p0   colour
133          *       0  0   transparent
134          *       0  1   cursor colour 0
135          *       1  0   cursor colour 1
136          *       1  1   cursor colour 2
137          * Put the cursor into the top-left of the 64x64 array.
138          * The 0,0 cursor point is bottom-right, so positioning will
139          * have to take that into account.
140          */
141         for(y = 0; y < 64; y++){
142                 for(x = 0; x < 64/8; x++){
143                         if(x < 16/8 && y < 16)
144                                 tvp3026o(Cram, curs->clr[x+y*2]);
145                         else
146                                 tvp3026o(Cram, 0x00);
147                 }
148         }
149         for(y = 0; y < 64; y++){
150                 for(x = 0; x < 64/8; x++){
151                         if(x < 16/8 && y < 16)
152                                 tvp3026o(Cram, curs->set[x+y*2]);
153                         else
154                                 tvp3026o(Cram, 0x00);
155                 }
156         }
157
158         /*
159          * Initialise the cursor hotpoint
160          * and enable the cursor in 3-colour mode.
161          */
162         scr->offset.x = 64+curs->offset.x;
163         scr->offset.y = 64+curs->offset.y;
164         tvp3026o(Cctl, 0x01);
165 }
166
167 static int
168 tvp3026move(VGAscr* scr, Point p)
169 {
170         int x, y;
171
172         x = p.x+scr->offset.x;
173         y = p.y+scr->offset.y;
174
175         tvp3026o(Cxlsb, x & 0xFF);
176         tvp3026o(Cxmsb, (x>>8) & 0x0F);
177         tvp3026o(Cylsb, y & 0xFF);
178         tvp3026o(Cymsb, (y>>8) & 0x0F);
179
180         return 0;
181 }
182
183 VGAcur vgatvp3026cur = {
184         "tvp3026hwgc",
185
186         tvp3026enable,
187         tvp3026disable,
188         tvp3026load,
189         tvp3026move,
190 };