/[gxemul]/trunk/src/devices/dev_bt459.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/src/devices/dev_bt459.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30 - (show annotations)
Mon Oct 8 16:20:40 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 15417 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1325 2006/08/15 15:38:37 debug Exp $
20060723	More Transputer instructions (pfix, nfix, opr, mint, ldl, ldlp,
		eqc, rev, ajw, stl, stlf, sthf, sub, ldnl, ldnlp, ldpi, move,
		wcnt, add, bcnt).
		Adding more SPARC instructions (andcc, addcc, bl, rdpr).
		Progress on the igsfb framebuffer used by NetBSD/netwinder.
		Enabling 8-bit fills in dev_fb.
		NetBSD/netwinder 3.0.1 can now run from a disk image :-)
20060724	Cleanup/performance fix for 64-bit virtual translation table
		updates (by removing the "timestamp" stuff). A full NetBSD/pmax
		3.0.1 install for R4400 has dropped from 667 seconds to 584 :)
		Fixing the igsfb "almost vga" color (it is 24-bit, not 18-bit).
		Adding some MIPS instruction combinations (3*lw, and 3*addu).
		The 8048 keyboard now turns off interrupt enable between the
		KBR_ACK and the KBR_RSTDONE, to work better with Linux 2.6.
		Not causing PPC DEC interrupts if PPC_NO_DEC is set for a
		specific CPU; NetBSD/bebox gets slightly further than before.
		Adding some more SPARC instructions: branches, udiv.
20060725	Refreshing dev_pckbc.c a little.
		Cleanups for the SH emulation mode, and adding the first
		"compact" (16-bit) instructions: various simple movs, nop,
		shll, stc, or, ldc.
20060726	Adding dummy "pcn" (AMD PCnet NIC) PCI glue.
20060727	Various cleanups; removing stuff from cpu.h, such as
		running_translated (not really meaningful anymore), and
		page flags (breaking into the debugger clears all translations
		anyway).
		Minor MIPS instruction combination updates.
20060807	Expanding the 3*sw and 3*lw MIPS instruction combinations to
		work with 2* and 4* too, resulting in a minor performance gain.
		Implementing a usleep hack for the RM52xx/MIPS32/MIPS64 "wait"
		instruction (when emulating 1 cpu).
20060808	Experimenting with some more MIPS instruction combinations.
		Implementing support for showing a (hardcoded 12x22) text
		cursor in igsfb.
20060809	Simplifying the NetBSD/evbmips (Malta) install instructions
		somewhat (by using a NetBSD/pmax ramdisk install kernel).
20060812	Experimenting more with the MIPS 'wait' instruction.
		PCI configuration register writes can now be handled, which
		allow PCI IDE controllers to work with NetBSD/Malta 3.0.1 and
		NetBSD/cobalt 3.0.1. (Previously only NetBSD 2.1 worked.)
20060813	Updating dev_gt.c based on numbers from Alec Voropay, to enable
		Linux 2.6 to use PCI on Malta.
		Continuing on Algor interrupt stuff.
20060814	Adding support for routing ISA interrupts to two different
		interrupts, making it possible to run NetBSD/algor :-)
20060814-15	Testing for the release.

==============  RELEASE 0.4.2  ==============


1 /*
2 * Copyright (C) 2003-2006 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: dev_bt459.c,v 1.65 2006/07/23 14:37:34 debug Exp $
29 *
30 * Brooktree 459 vdac, used by TURBOchannel graphics cards.
31 */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #include "cpu.h"
38 #include "devices.h"
39 #include "machine.h"
40 #include "memory.h"
41 #include "misc.h"
42 #include "x11.h"
43
44 #include "bt459.h"
45
46
47 #ifdef WITH_X11
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #endif
51
52 extern int quiet_mode;
53
54
55 /* #define BT459_DEBUG */
56 /* #define WITH_CURSOR_DEBUG */
57 #define BT459_TICK_SHIFT 14
58
59 struct bt459_data {
60 uint32_t bt459_reg[DEV_BT459_NREGS];
61
62 unsigned char cur_addr_hi;
63 unsigned char cur_addr_lo;
64
65 int planes;
66 int type;
67
68 int irq_nr;
69 int interrupts_enable;
70 int interrupt_time;
71 int interrupt_time_reset_value;
72
73 int cursor_x_add;
74 int cursor_y_add;
75
76 int need_to_redraw_whole_screen;
77
78 int need_to_update_cursor_shape;
79 int cursor_on;
80 int cursor_x;
81 int cursor_y;
82 int cursor_xsize;
83 int cursor_ysize;
84
85 int palette_sub_offset; /* 0, 1, or 2 */
86
87 struct vfb_data *vfb_data;
88
89 /*
90 * There is one pointer to the framebuffer's RGB palette,
91 * and then a local copy of the palette. 256 * 3 bytes (r,g,b).
92 * The reason for this is that when we need to blank the screen
93 * (ie video_on = 0), we can set the framebuffer's palette to all
94 * zeroes, but keep our own copy intact, to be reused later again
95 * when the screen is unblanked.
96 */
97 int video_on;
98 unsigned char *rgb_palette; /* 256 * 3 (r,g,b) */
99 unsigned char local_rgb_palette[256 * 3];
100 };
101
102
103 /*
104 * bt459_update_X_cursor():
105 *
106 * This routine takes the color values in the cursor RAM area, and put them
107 * in the framebuffer window's cursor_pixels.
108 *
109 * d->cursor_xsize and ysize are also updated.
110 */
111 static void bt459_update_X_cursor(struct cpu *cpu, struct bt459_data *d)
112 {
113 int i, x,y, xmax=0, ymax=0;
114 int bw_only = 1;
115
116 /* First, let's calculate the size of the cursor: */
117 for (y=0; y<64; y++)
118 for (x=0; x<64; x+=4) {
119 int reg = BT459_REG_CRAM_BASE + y*16 + x/4;
120 unsigned char data = d->bt459_reg[reg];
121
122 if (data)
123 ymax = y;
124
125 for (i=0; i<4; i++) {
126 int color = (data >> (6-2*i)) & 3;
127 if (color != 0)
128 xmax = x + i;
129 if (color != 0 && color != 3)
130 bw_only = 0;
131 }
132 }
133
134 d->cursor_xsize = xmax + 1;
135 d->cursor_ysize = ymax + 1;
136
137 /*
138 * The 'bw_only' hack is because it is nicer to have the b/w
139 * text cursor invert whatever it is standing on, not just overwrite
140 * it with a big white box.
141 *
142 * The following seems to work with NetBSD/OpenBSD/Ultrix/Sprite:
143 * 0 = transparent, 1 and 2 = use the color specified by
144 * BT459_REG_CCOLOR_2, 3 = reverse of color 1/2.
145 */
146
147 #ifdef WITH_X11
148 if (cpu->machine->use_x11 && d->vfb_data->fb_window != NULL) {
149 for (y=0; y<=ymax; y++) {
150 for (x=0; x<=xmax; x+=4) {
151 struct fb_window *win = d->vfb_data->fb_window;
152 int reg = BT459_REG_CRAM_BASE + y*16 + x/4;
153 unsigned char data = d->bt459_reg[reg];
154
155 for (i=0; i<4; i++) {
156 int color = (data >> (6-2*i)) & 3;
157 int pixelvalue;
158
159 if (bw_only) {
160 if (color)
161 pixelvalue =
162 CURSOR_COLOR_INVERT;
163 else
164 pixelvalue = 0;
165 } else {
166 pixelvalue =
167 CURSOR_COLOR_TRANSPARENT;
168 switch (color) {
169 case 1:
170 case 2: pixelvalue = (d->
171 bt459_reg[
172 BT459_REG_CCOLOR_2]
173 >> 4) & 0xf;
174 break;
175 case 3: pixelvalue = 15 -
176 ((d->bt459_reg[
177 BT459_REG_CCOLOR_2]
178 >> 4) & 0xf);
179 break;
180 }
181 }
182
183 win->cursor_pixels[y][x+i] =
184 pixelvalue;
185 #ifdef WITH_CURSOR_DEBUG
186 printf("%i", color);
187 #endif
188 }
189 }
190 #ifdef WITH_CURSOR_DEBUG
191 printf("\n");
192 #endif
193 }
194 #ifdef WITH_CURSOR_DEBUG
195 printf("color 1,2,3 = 0x%02x, 0x%02x, 0x%02x\n",
196 d->bt459_reg[BT459_REG_CCOLOR_1],
197 d->bt459_reg[BT459_REG_CCOLOR_2],
198 d->bt459_reg[BT459_REG_CCOLOR_3]);
199 printf("\n");
200 #endif
201 /*
202 * Make sure the cursor is redrawn, if it is on:
203 *
204 * How does this work? Well, 0 is off, and non-zero is on,
205 * but if the old and new differ, the cursor is redrawn.
206 * (Hopefully this will "never" overflow.)
207 */
208 if (d->cursor_on)
209 d->cursor_on ++;
210 }
211 #endif
212 }
213
214
215 /*
216 * bt459_update_cursor_position():
217 */
218 static void bt459_update_cursor_position(struct bt459_data *d,
219 int old_cursor_on)
220 {
221 int new_cursor_x = (d->bt459_reg[BT459_REG_CXLO] & 255) +
222 ((d->bt459_reg[BT459_REG_CXHI] & 255) << 8) - d->cursor_x_add;
223 int new_cursor_y = (d->bt459_reg[BT459_REG_CYLO] & 255) +
224 ((d->bt459_reg[BT459_REG_CYHI] & 255) << 8) - d->cursor_y_add;
225
226 if (new_cursor_x != d->cursor_x || new_cursor_y != d->cursor_y ||
227 d->cursor_on != old_cursor_on) {
228 int on;
229
230 d->cursor_x = new_cursor_x;
231 d->cursor_y = new_cursor_y;
232
233 if (!quiet_mode)
234 debug("[ bt459: cursor = %03i,%03i ]\n",
235 d->cursor_x, d->cursor_y);
236
237 on = d->cursor_on;
238 if (d->cursor_xsize == 0 || d->cursor_ysize == 0)
239 on = 0;
240
241 dev_fb_setcursor(d->vfb_data, d->cursor_x, d->cursor_y,
242 on, d->cursor_xsize, d->cursor_ysize);
243 }
244 }
245
246
247 DEVICE_TICK(bt459)
248 {
249 struct bt459_data *d = extra;
250 int old_cursor_on = d->cursor_on;
251
252 if (d->need_to_update_cursor_shape) {
253 d->need_to_update_cursor_shape = 0;
254 bt459_update_X_cursor(cpu, d);
255 bt459_update_cursor_position(d, old_cursor_on);
256 }
257
258 if (d->need_to_redraw_whole_screen) {
259 d->vfb_data->update_x1 = 0;
260 d->vfb_data->update_x2 = d->vfb_data->xsize - 1;
261 d->vfb_data->update_y1 = 0;
262 d->vfb_data->update_y2 = d->vfb_data->ysize - 1;
263 d->need_to_redraw_whole_screen = 0;
264 }
265
266 /*
267 * Vertical retrace interrupts. (This hack is kind of ugly.)
268 * Once every 'interrupt_time_reset_value', the interrupt is
269 * asserted. It is acked either manually (by someone reading
270 * a normal BT459 register or the Interrupt ack register),
271 * or after another tick has passed. (This is to prevent
272 * lockups from unhandled interrupts.)
273 */
274 if (d->type != BT459_PX && d->interrupts_enable && d->irq_nr > 0) {
275 d->interrupt_time --;
276 if (d->interrupt_time < 0) {
277 d->interrupt_time = d->interrupt_time_reset_value;
278 cpu_interrupt(cpu, d->irq_nr);
279 } else
280 cpu_interrupt_ack(cpu, d->irq_nr);
281 }
282 }
283
284
285 /*
286 * dev_bt459_irq_access():
287 */
288 DEVICE_ACCESS(bt459_irq)
289 {
290 struct bt459_data *d = (struct bt459_data *) extra;
291 uint64_t idata = 0, odata = 0;
292
293 if (writeflag == MEM_WRITE)
294 idata = memory_readmax64(cpu, data, len);
295
296 #ifdef BT459_DEBUG
297 fatal("[ bt459: IRQ ack ]\n");
298 #endif
299
300 d->interrupts_enable = 1;
301 if (d->irq_nr > 0)
302 cpu_interrupt_ack(cpu, d->irq_nr);
303
304 if (writeflag == MEM_READ)
305 memory_writemax64(cpu, data, len, odata);
306
307 return 1;
308 }
309
310
311 /*
312 * dev_bt459_access():
313 */
314 DEVICE_ACCESS(bt459)
315 {
316 struct bt459_data *d = (struct bt459_data *) extra;
317 uint64_t idata = 0, odata = 0;
318 int btaddr, old_cursor_on = d->cursor_on, modified;
319
320 idata = memory_readmax64(cpu, data, len);
321
322 #ifdef BT459_DEBUG
323 if (writeflag == MEM_WRITE)
324 fatal("[ bt459: write to addr 0x%02x: %08x ]\n",
325 (int)relative_addr, (int)idata);
326 #endif
327
328 /*
329 * Vertical retrace interrupts are acked either by
330 * accessing a normal BT459 register, or the irq register,
331 * or by simply "missing" it.
332 */
333 if (d->irq_nr > 0)
334 cpu_interrupt_ack(cpu, d->irq_nr);
335
336 /* ID register is read-only, should always be 0x4a or 0x4a4a4a: */
337 if (d->planes == 24)
338 d->bt459_reg[BT459_REG_ID] = 0x4a4a4a;
339 else {
340 /*
341 * TODO: Is it really 0x4a, or 0x4a0000?
342 * Ultrix panics with a "bad VDAC ID" message if 0x4a
343 * is returned.
344 */
345 d->bt459_reg[BT459_REG_ID] = 0x4a0000;
346 }
347
348 btaddr = ((d->cur_addr_hi << 8) + d->cur_addr_lo) % DEV_BT459_NREGS;
349
350 /* Read from/write to the bt459: */
351 switch (relative_addr) {
352 case 0x00: /* Low byte of address: */
353 if (writeflag == MEM_WRITE) {
354 if (!quiet_mode)
355 debug("[ bt459: write to Low Address Byte, "
356 "0x%02x ]\n", (int)idata);
357 d->cur_addr_lo = idata;
358 d->palette_sub_offset = 0;
359 } else {
360 odata = d->cur_addr_lo;
361 if (!quiet_mode)
362 debug("[ bt459: read from Low Address Byte: "
363 "0x%0x ]\n", (int)odata);
364 }
365 break;
366 case 0x04: /* High byte of address: */
367 if (writeflag == MEM_WRITE) {
368 if (!quiet_mode)
369 debug("[ bt459: write to High Address Byte, "
370 "0x%02x ]\n", (int)idata);
371 d->cur_addr_hi = idata;
372 d->palette_sub_offset = 0;
373 } else {
374 odata = d->cur_addr_hi;
375 if (!quiet_mode)
376 debug("[ bt459: read from High Address Byte: "
377 "0x%0x ]\n", (int)odata);
378 }
379 break;
380 case 0x08: /* Register access: */
381 if (writeflag == MEM_WRITE) {
382 if (!quiet_mode)
383 debug("[ bt459: write to BT459 register "
384 "0x%04x, value 0x%02x ]\n", btaddr,
385 (int)idata);
386 modified = (d->bt459_reg[btaddr] != idata);
387 d->bt459_reg[btaddr] = idata;
388
389 switch (btaddr) {
390 case BT459_REG_CCOLOR_1:
391 case BT459_REG_CCOLOR_2:
392 case BT459_REG_CCOLOR_3:
393 if (modified)
394 d->need_to_update_cursor_shape = 1;
395 break;
396 case BT459_REG_PRM:
397 /*
398 * NetBSD writes 0x00 to this register to
399 * blank the screen (video off), and 0xff
400 * to turn the screen on.
401 */
402 switch (idata & 0xff) {
403 case 0: d->video_on = 0;
404 memset(d->rgb_palette, 0, 256*3);
405 d->need_to_redraw_whole_screen = 1;
406 debug("[ bt459: video OFF ]\n");
407 break;
408 default:d->video_on = 1;
409 memcpy(d->rgb_palette,
410 d->local_rgb_palette, 256*3);
411 d->need_to_redraw_whole_screen = 1;
412 debug("[ bt459: video ON ]\n");
413 }
414 break;
415 case BT459_REG_CCR:
416 /* Cursor control register: */
417 switch (idata & 0xff) {
418 case 0x00: d->cursor_on = 0; break;
419 case 0xc0:
420 case 0xc1: d->cursor_on = 1; break;
421 default:
422 fatal("[ bt459: unimplemented CCR "
423 "value 0x%08x ]\n", (int)idata);
424 }
425 if (modified)
426 d->need_to_update_cursor_shape = 1;
427 break;
428 default:
429 if (btaddr < 0x100)
430 fatal("[ bt459: write to BT459 "
431 "register 0x%04x, value 0x%02x ]\n",
432 btaddr, (int)idata);
433 }
434
435 /* Write to cursor bitmap: */
436 if (btaddr >= BT459_REG_CRAM_BASE && modified)
437 d->need_to_update_cursor_shape = 1;
438 } else {
439 odata = d->bt459_reg[btaddr];
440
441 /* Perhaps this hack is not necessary: */
442 if (btaddr == BT459_REG_ID && len==1)
443 odata = (odata >> 16) & 255;
444
445 if (!quiet_mode)
446 debug("[ bt459: read from BT459 register "
447 "0x%04x, value 0x%02x ]\n", btaddr,
448 (int)odata);
449 }
450
451 /* Go to next register: */
452 d->cur_addr_lo ++;
453 if (d->cur_addr_lo == 0)
454 d->cur_addr_hi ++;
455 break;
456 case 0xc: /* Color map: */
457 if (writeflag == MEM_WRITE) {
458 idata &= 255;
459 if (!quiet_mode)
460 debug("[ bt459: write to BT459 colormap "
461 "0x%04x subaddr %i, value 0x%02x ]\n",
462 btaddr, d->palette_sub_offset, (int)idata);
463
464 if (btaddr < 0x100) {
465 if (d->video_on &&
466 d->local_rgb_palette[(btaddr & 0xff) * 3
467 + d->palette_sub_offset] != idata)
468 d->need_to_redraw_whole_screen = 1;
469
470 /*
471 * Actually, the palette should only be
472 * updated after the third write,
473 * but this should probably work fine too:
474 */
475 d->local_rgb_palette[(btaddr & 0xff) * 3
476 + d->palette_sub_offset] = idata;
477
478 if (d->video_on)
479 d->rgb_palette[(btaddr & 0xff) * 3
480 + d->palette_sub_offset] = idata;
481 }
482 } else {
483 if (btaddr < 0x100)
484 odata = d->local_rgb_palette[(btaddr & 0xff)
485 * 3 + d->palette_sub_offset];
486 if (!quiet_mode)
487 debug("[ bt459: read from BT459 colormap "
488 "0x%04x subaddr %i, value 0x%02x ]\n",
489 btaddr, d->palette_sub_offset, (int)odata);
490 }
491
492 d->palette_sub_offset ++;
493 if (d->palette_sub_offset >= 3) {
494 d->palette_sub_offset = 0;
495
496 d->cur_addr_lo ++;
497 if (d->cur_addr_lo == 0)
498 d->cur_addr_hi ++;
499 }
500
501 break;
502 default:
503 if (writeflag == MEM_WRITE) {
504 debug("[ bt459: unimplemented write to address 0x%x, "
505 "data=0x%02x ]\n", (int)relative_addr, (int)idata);
506 } else {
507 debug("[ bt459: unimplemented read from address "
508 "0x%x ]\n", (int)relative_addr);
509 }
510 }
511
512
513 bt459_update_cursor_position(d, old_cursor_on);
514
515 if (writeflag == MEM_READ)
516 memory_writemax64(cpu, data, len, odata);
517
518 #ifdef BT459_DEBUG
519 if (writeflag == MEM_READ)
520 fatal("[ bt459: read from addr 0x%02x: %08x ]\n",
521 (int)relative_addr, (int)idata);
522 #endif
523
524 return 1;
525 }
526
527
528 /*
529 * dev_bt459_init():
530 */
531 void dev_bt459_init(struct machine *machine, struct memory *mem,
532 uint64_t baseaddr, uint64_t baseaddr_irq, struct vfb_data *vfb_data,
533 int planes, int irq_nr, int type)
534 {
535 struct bt459_data *d = malloc(sizeof(struct bt459_data));
536 if (d == NULL) {
537 fprintf(stderr, "out of memory\n");
538 exit(1);
539 }
540
541 memset(d, 0, sizeof(struct bt459_data));
542
543 d->vfb_data = vfb_data;
544 d->rgb_palette = vfb_data->rgb_palette;
545 d->planes = planes;
546 d->irq_nr = irq_nr;
547 d->type = type;
548 d->cursor_x = -1;
549 d->cursor_y = -1;
550 d->cursor_xsize = d->cursor_ysize = 0; /* anything */
551 d->video_on = 1;
552
553 /*
554 * These offsets are based on those mentioned in NetBSD,
555 * and then adjusted to look good with both NetBSD and
556 * Ultrix:
557 */
558 switch (d->type) {
559 case BT459_PX:
560 d->cursor_x_add = 370;
561 d->cursor_y_add = 37;
562 break;
563 case BT459_BA:
564 d->cursor_x_add = 220;
565 d->cursor_y_add = 35;
566 break;
567 case BT459_BBA:
568 if (vfb_data->xsize == 1280) {
569 /* 1280x1024: */
570 d->cursor_x_add = 368;
571 d->cursor_y_add = 38;
572 } else {
573 /* 1024x864: */
574 d->cursor_x_add = 220;
575 d->cursor_y_add = 35;
576 }
577 break;
578 }
579
580 d->interrupt_time_reset_value = 500;
581
582 memory_device_register(mem, "bt459", baseaddr, DEV_BT459_LENGTH,
583 dev_bt459_access, (void *)d, DM_DEFAULT, NULL);
584
585 if (baseaddr_irq != 0)
586 memory_device_register(mem, "bt459_irq", baseaddr_irq, 0x10000,
587 dev_bt459_irq_access, (void *)d, DM_DEFAULT, NULL);
588
589 machine_add_tickfunction(machine, dev_bt459_tick, d,
590 BT459_TICK_SHIFT, 0.0);
591 }
592

  ViewVC Help
Powered by ViewVC 1.1.26