2 #include "../port/lib.h"
7 #include "../port/error.h"
16 * #9 Ticket to Ride IV.
27 enum { /* index registers */
54 CursorMode32x32 = 0x23,
55 CursorMode64x64 = 0x27,
56 CursorMode = CursorMode32x32,
60 t2r4enable(VGAscr* scr)
67 if(p = pcimatch(nil, 0x105D, 0)){
79 mmio = vmap(p->mem[4].bar & ~0x0F, p->mem[4].size);
82 addvgaseg("t2r4mmio", p->mem[4].bar & ~0x0F, p->mem[4].size);
87 addvgaseg("t2r4screen", scr->paddr, scr->apsize);
91 t2r4xi(VGAscr* scr, int index)
96 mmio[IndexLo] = index & 0xFF;
97 mmio[IndexHi] = (index>>8) & 0xFF;
103 t2r4xo(VGAscr* scr, int index, uchar data)
108 mmio[IndexLo] = index & 0xFF;
109 mmio[IndexHi] = (index>>8) & 0xFF;
115 t2r4curdisable(VGAscr* scr)
119 t2r4xo(scr, CursorCtl, 0x00);
123 t2r4curload(VGAscr* scr, Cursor* curs)
126 int size, x, y, zoom;
127 ulong clr, *mmio, pixels, set;
134 * Make sure cursor is off by initialising the cursor
135 * control to defaults.
137 t2r4xo(scr, CursorCtl, 0x00);
140 * Set auto-increment mode for index-register addressing
141 * and initialise the cursor array index.
143 mmio[IndexCtl] = 0x01;
144 mmio[IndexLo] = CursorArray & 0xFF;
145 mmio[IndexHi] = (CursorArray>>8) & 0xFF;
148 * Initialise the cursor RAM array. There are 2 planes,
149 * p0 and p1. Data is written 4 pixels per byte, with p1 the
150 * MS bit of each pixel.
151 * The cursor is set in X-Windows mode which gives the following
154 * 0 0 underlying pixel colour
155 * 0 1 underlying pixel colour
156 * 1 0 cursor colour 1
157 * 1 1 cursor colour 2
158 * Put the cursor into the top-left of the array.
160 * Although this looks a lot like the IBM RGB524 cursor, the
161 * scanlines appear to be twice as long as they should be and
162 * some of the other features are missing.
164 if(mmio[Zoom] & 0x0F)
168 data = (uchar*)&mmio[Data];
169 for(y = 0; y < zoom; y++){
170 clr = (curs->clr[2*y]<<8)|curs->clr[y*2 + 1];
171 set = (curs->set[2*y]<<8)|curs->set[y*2 + 1];
173 for(x = 0; x < 16; x++){
175 pixels |= 0x03<<(x*2);
176 else if(clr & (1<<x))
177 pixels |= 0x02<<(x*2);
190 if(CursorMode == CursorMode32x32 && zoom == 16)
202 if(CursorMode == CursorMode32x32)
207 for(x = 0; x < size/8; x++){
213 mmio[IndexCtl] = 0x00;
216 * Initialise the hotpoint and enable the cursor.
218 t2r4xo(scr, CursorHotX, -curs->offset.x);
219 zoom = (scr->mmio[Zoom] & 0x0F)+1;
220 t2r4xo(scr, CursorHotY, -curs->offset.y*zoom);
222 t2r4xo(scr, CursorCtl, CursorMode);
226 t2r4curmove(VGAscr* scr, Point p)
233 t2r4xo(scr, CursorXLo, p.x & 0xFF);
234 t2r4xo(scr, CursorXHi, (p.x>>8) & 0x0F);
236 zoom = (scr->mmio[Zoom] & 0x0F)+1;
238 t2r4xo(scr, CursorYLo, y & 0xFF);
239 t2r4xo(scr, CursorYHi, (y>>8) & 0x0F);
245 t2r4curenable(VGAscr* scr)
252 * Make sure cursor is off by initialising the cursor
253 * control to defaults.
255 t2r4xo(scr, CursorCtl, 0x00);
258 * Cursor colour 1 (white),
259 * cursor colour 2 (black).
261 t2r4xo(scr, CursorR1, Pwhite);
262 t2r4xo(scr, CursorG1, Pwhite);
263 t2r4xo(scr, CursorB1, Pwhite);
265 t2r4xo(scr, CursorR2, Pblack);
266 t2r4xo(scr, CursorG2, Pblack);
267 t2r4xo(scr, CursorB2, Pblack);
270 * Load, locate and enable the cursor, 64x64, mode 2.
272 t2r4curload(scr, &arrow);
273 t2r4curmove(scr, ZP);
274 t2r4xo(scr, CursorCtl, CursorMode);
310 /* wait until pipeline ready for new command */
312 waitforfifo(VGAscr *scr)
318 d = scr->mmio + RBaseD;
319 while((d[Busy]&1) && x++ < 1000000)
321 if(x >= 1000000) /* shouldn't happen */
322 iprint("busy %8lux\n", d[Busy]);
325 /* wait until command has finished executing */
327 waitforcmd(VGAscr *scr)
333 d = scr->mmio + RBaseD;
334 while((d[Flow]&0x1B) && x++ < 1000000)
336 if(x >= 1000000) /* shouldn't happen */
337 iprint("flow %8lux\n", d[Flow]);
340 /* wait until memory controller not busy (i.e. wait for writes to flush) */
342 waitformem(VGAscr *scr)
348 d = scr->mmio + RBaseD;
349 while((d[Flow]&2)&& x++ < 1000000)
351 if(x >= 1000000) /* shouldn't happen */
352 iprint("mem %8lux\n", d[Busy]);
356 t2r4hwscroll(VGAscr *scr, Rectangle r, Rectangle sr)
363 if(r.min.y == sr.min.y){ /* a purely horizontal scroll */
364 depth = scr->gscreen->depth;
368 * Using the SGI flat panels with the Ticket-to-Ride IV, horizontal
369 * 32-bit scrolls don't work perfectly on rectangles of width <= 24.
370 * we bail on a bigger bound for padding.
377 * Using the SGI flat panels with the Ticket-to-Ride IV, horizontal
378 * 16-bit scrolls don't work perfectly on rectangles of width <= 96.
379 * we bail on a bigger bound for padding.
388 d = scr->mmio + RBaseD;
390 if(r.min.x <= sr.min.x){
399 if(r.min.y < sr.min.y){
408 d[CmdOpc] = 0x1; /* bitblt */
409 d[CmdRop] = 0xC; /* copy source */
415 /* writing XY1 executes cmd */
417 d[XY0] = (sp.x<<16)|sp.y;
418 d[XY2] = (Dx(r)<<16)|Dy(r);
420 d[XY1] = (dp.x<<16)|dp.y;
427 t2r4hwfill(VGAscr *scr, Rectangle r, ulong sval)
431 d = scr->mmio + RBaseD;
435 d[CmdOpc] = 0x1; /* bitblt */
436 d[CmdRop] = 0xC; /* copy source */
437 d[CmdStyle] = 1; /* use source from Fore register */
438 d[CmdPatrn] = 0; /* no stipple */
442 /* writing XY1 executes cmd */
444 d[XY0] = (r.min.x<<16)|r.min.y;
445 d[XY2] = (Dx(r)<<16)|Dy(r);
447 d[XY1] = (r.min.x<<16)|r.min.y;
454 t2r4blank(VGAscr *scr, int blank)
458 x = t2r4xi(scr, CursorSyncCtl);
461 x |= HsyncLo | VsyncLo;
462 t2r4xo(scr, CursorSyncCtl, x);
466 t2r4drawinit(VGAscr *scr)
473 pitch = Dx(scr->gscreen->r);
474 depth = scr->gscreen->depth;
476 switch(scr->gscreen->chan){
492 d = scr->mmio + RBaseD;
497 d[DeSptch] = (pitch*depth)/8;
498 d[DeDptch] = (pitch*depth)/8;
499 d[CmdClp] = 0; /* 2 = inside rectangle */
503 d[Clpbr] = 0xFFF0FFF0;
507 scr->fill = t2r4hwfill;
508 scr->scroll = t2r4hwscroll;
509 scr->blank = t2r4blank;
513 VGAdev vgat2r4dev = {
523 VGAcur vgat2r4cur = {