/[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 24 - (show annotations)
Mon Oct 8 16:19:56 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 15477 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1256 2006/06/23 20:43:44 debug Exp $
20060219	Various minor updates. Removing the old MIPS16 skeleton code,
		because it will need to be rewritten for dyntrans anyway.
20060220-22	Removing the non-working dyntrans backend support.
		Continuing on the 64-bit dyntrans virtual memory generalization.
20060223	More work on the 64-bit vm generalization.
20060225	Beginning on MIPS dyntrans load/store instructions.
		Minor PPC updates (64-bit load/store, etc).
		Fixes for the variable-instruction-length framework, some
		minor AVR updates (a simple Hello World program works!).
		Beginning on a skeleton for automatically generating documen-
		tation (for devices etc.).
20060226	PPC updates (adding some more 64-bit instructions, etc).
		AVR updates (more instructions).
		FINALLY found and fixed the zs bug, making NetBSD/macppc
		accept the serial console.
20060301	Adding more AVR instructions.
20060304	Continuing on AVR-related stuff. Beginning on a framework for
		cycle-accurate device emulation. Adding an experimental "PAL
		TV" device (just a dummy so far).
20060305	Adding more AVR instructions.
		Adding a dummy epcom serial controller (for TS7200 emulation).
20060310	Removing the emul() command from configuration files, so only
		net() and machine() are supported.
		Minor progress on the MIPS dyntrans rewrite.
20060311	Continuing on the MIPS dyntrans rewrite (adding more
		instructions, etc).
20060315	Adding more instructions (sllv, srav, srlv, bgtz[l], blez[l],
		beql, bnel, slti[u], various loads and stores).
20060316	Removing the ALWAYS_SIGNEXTEND_32 option, since it was rarely
		used.
		Adding more MIPS dyntrans instructions, and fixing bugs.
20060318	Implementing fast loads/stores for MIPS dyntrans (big/little
		endian, 32-bit and 64-bit modes).
20060320	Making MIPS dyntrans the default configure option; use
		"--enable-oldmips" to use the old bintrans system.
		Adding MIPS dyntrans dmult[u]; minor updates.
20060322	Continuing... adding some more instructions.
		Adding a simple skeleton for demangling C++ "_ZN" symbols.
20060323	Moving src/debugger.c into a new directory (src/debugger/).
20060324	Fixing the hack used to load PPC ELFs (useful for relocated
		Linux/ppc kernels), and adding a dummy G3 machine mode.
20060325-26	Beginning to experiment with GDB remote serial protocol
		connections; adding a -G command line option for selecting
		which TCP port to listen to.
20060330	Beginning a major cleanup to replace things like "0x%016llx"
		with more correct "0x%016"PRIx64, etc.
		Continuing on the GDB remote serial protocol support.
20060331	More cleanup, and some minor GDB remote progress.
20060402	Adding a hack to the configure script, to allow compilation
		on systems that lack PRIx64 etc.
20060406	Removing the temporary FreeBSD/arm hack in dev_ns16550.c and
		replacing it with a better fix from Olivier Houchard.
20060407	A remote debugger (gdb or ddd) can now start and stop the
		emulator using the GDB remote serial protocol, and registers
		and memory can be read. MIPS only for now.
20060408	More GDB progress: single-stepping also works, and also adding
		support for ARM, PowerPC, and Alpha targets.
		Continuing on the delay-slot-across-page-boundary issue.
20060412	Minor update: beginning to add support for the SPARC target
		to the remote GDB functionality.
20060414	Various MIPS updates: adding more instructions for dyntrans
		(eret, add), and making some exceptions work. Fixing a bug
		in dmult[u].
		Implementing the first SPARC instructions (sethi, or).
20060415	Adding "magic trap" instructions so that PROM calls can be
		software emulated in MIPS dyntrans.
		Adding more MIPS dyntrans instructions (ddiv, dadd) and
		fixing another bug in dmult.
20060416	More MIPS dyntrans progress: adding [d]addi, movn, movz, dsllv,
		rfi, an ugly hack for supporting R2000/R3000 style faked caches,
		preliminary interrupt support, and various other updates and
		bugfixes.
20060417	Adding more SPARC instructions (add, sub, sll[x], sra[x],
		srl[x]), and useful SPARC header definitions.
		Adding the first (trivial) x86/AMD64 dyntrans instructions (nop,
		cli/sti, stc/clc, std/cld, simple mov, inc ax). Various other
		x86 updates related to variable instruction length stuff.
		Adding unaligned loads/stores to the MIPS dyntrans mode (but
		still using the pre-dyntrans (slow) imlementation).
20060419	Fixing a MIPS dyntrans exception-in-delay-slot bug.
		Removing the old "show opcode statistics" functionality, since
		it wasn't really useful and isn't implemented for dyntrans.
		Single-stepping (or running with instruction trace) now looks
		ok with dyntrans with delay-slot architectures.
20060420	Minor hacks (removing the -B command line option when compiled
		for non-bintrans, and some other very minor updates).
		Adding (slow) MIPS dyntrans load-linked/store-conditional.
20060422	Applying fixes for bugs discovered by Nils Weller's nwcc
		(static DEC memmap => now per machine, and adding an extern
		keyword in cpu_arm_instr.c).
		Finally found one of the MIPS dyntrans bugs that I've been
		looking for (copy/paste spelling error BIG vs LITTLE endian in
		cpu_mips_instr_loadstore.c for 16-bit fast stores).
		FINALLY found the major MIPS dyntrans bug: slti vs sltiu
		signed/unsigned code in cpu_mips_instr.c. :-)
		Adding more MIPS dyntrans instructions (lwc1, swc1, bgezal[l],
		ctc1, tlt[u], tge[u], tne, beginning on rdhwr).
		NetBSD/hpcmips can now reach userland when using dyntrans :-)
		Adding some more x86 dyntrans instructions.
		Finally removed the old Alpha-specific virtual memory code,
		and replaced it with the generic 64-bit version.
		Beginning to add disassembly support for SPECIAL3 MIPS opcodes.
20060423	Continuing on the delay-slot-across-page-boundary issue;
		adding an end_of_page2 ic slot (like I had planned before, but
		had removed for some reason).
		Adding a quick-and-dirty fallback to legacy coprocessor 1
		code (i.e. skipping dyntrans implementation for now).
		NetBSD/hpcmips and NetBSD/pmax (when running on an emulated
		R4400) can now be installed and run. :-)  (Many bugs left
		to fix, though.)
		Adding more MIPS dyntrans instructions: madd[u], msub[u].
		Cleaning up the SPECIAL2 vs R5900/TX79/C790 "MMI" opcode
		maps somewhat (disassembly and dyntrans instruction decoding).
20060424	Adding an isa_revision field to mips_cpu_types.h, and making
		sure that SPECIAL3 opcodes cause Reserved Instruction
		exceptions on MIPS32/64 revisions lower than 2.
		Adding the SPARC 'ba', 'call', 'jmpl/retl', 'and', and 'xor'
		instructions.
20060425	Removing the -m command line option ("run at most x 
		instructions") and -T ("single_step_on_bad_addr"), because
		they never worked correctly with dyntrans anyway.
		Freshening up the man page.
20060428	Adding more MIPS dyntrans instructions: bltzal[l], idle.
		Enabling MIPS dyntrans compare interrupts.
20060429	FINALLY found the weird dyntrans bug, causing NetBSD etc. to
		behave strangely: some floating point code (conditional
		coprocessor branches) could not be reused from the old
		non-dyntrans code. The "quick-and-dirty fallback" only appeared
		to work. Fixing by implementing bc1* for MIPS dyntrans.
		More MIPS instructions: [d]sub, sdc1, ldc1, dmtc1, dmfc1, cfc0.
		Freshening up MIPS floating point disassembly appearance.
20060430	Continuing on C790/R5900/TX79 disassembly; implementing 128-bit
		"por" and "pextlw".
20060504	Disabling -u (userland emulation) unless compiled as unstable
		development version.
		Beginning on freshening up the testmachine include files,
		to make it easier to reuse those files (placing them in
		src/include/testmachine/), and beginning on a set of "demos"
		or "tutorials" for the testmachine functionality.
		Minor updates to the MIPS GDB remote protocol stub.
		Refreshing doc/experiments.html and gdb_remote.html.
		Enabling Alpha emulation in the stable release configuration,
		even though no guest OSes for Alpha can run yet.
20060505	Adding a generic 'settings' object, which will contain
		references to settable variables (which will later be possible
		to access using the debugger).
20060506	Updating dev_disk and corresponding demo/documentation (and
		switching from SCSI to IDE disk types, so it actually works
		with current test machines :-).
20060510	Adding a -D_LARGEFILE_SOURCE hack for 64-bit Linux hosts,
		so that fseeko() doesn't give a warning.
		Updating the section about how dyntrans works (the "runnable
		IR") in doc/intro.html.
		Instruction updates (some x64=1 checks, some more R5900
		dyntrans stuff: better mul/mult separation from MIPS32/64,
		adding ei and di).
		Updating MIPS cpuregs.h to a newer one (from NetBSD).
		Adding more MIPS dyntrans instructions: deret, ehb.
20060514	Adding disassembly and beginning implementation of SPARC wr
		and wrpr instructions.
20060515	Adding a SUN SPARC machine mode, with dummy SS20 and Ultra1
		machines. Adding the 32-bit "rd psr" instruction.
20060517	Disassembly support for the general SPARC rd instruction.
		Partial implementation of the cmp (subcc) instruction.
		Some other minor updates (making sure that R5900 processors
		start up with the EIE bit enabled, otherwise Linux/playstation2
		receives no interrupts).
20060519	Minor MIPS updates/cleanups.
20060521	Moving the MeshCube machine into evbmips; this seems to work
		reasonably well with a snapshot of a NetBSD MeshCube kernel.
		Cleanup/fix of MIPS config0 register initialization.
20060529	Minor MIPS fixes, including a sign-extension fix to the
		unaligned load/store code, which makes NetBSD/pmax on R3000
		work better with dyntrans. (Ultrix and Linux/DECstation still
		don't work, though.)
20060530	Minor updates to the Alpha machine mode: adding an AlphaBook
		mode, an LCA bus (forwarding accesses to an ISA bus), etc.
20060531	Applying a bugfix for the MIPS dyntrans sc[d] instruction from
		Ondrej Palkovsky. (Many thanks.)
20060601	Minifix to allow ARM immediate msr instruction to not give
		an error for some valid values.
		More Alpha updates.
20060602	Some minor Alpha updates.
20060603	Adding the Alpha cmpbge instruction. NetBSD/alpha prints its
		first boot messages :-) on an emulated Alphabook 1.
20060612	Minor updates; adding a dev_ether.h include file for the
		testmachine ether device. Continuing the hunt for the dyntrans
		bug which makes Linux and Ultrix on DECstation behave
		strangely... FINALLY found it! It seems to be related to
		invalidation of the translation cache, on tlbw{r,i}. There
		also seems to be some remaining interrupt-related problems.
20060614	Correcting the implementation of ldc1/sdc1 for MIPS dyntrans
		(so that it uses 16 32-bit registers if the FR bit in the
		status register is not set).
20060616	REMOVING BINTRANS COMPLETELY!
		Removing the old MIPS interpretation mode.
		Removing the MFHILO_DELAY and instruction delay stuff, because
		they wouldn't work with dyntrans anyway.
20060617	Some documentation updates (adding "NetBSD-archive" to some
		URLs, and new Debian/DECstation installation screenshots).
		Removing the "tracenull" and "enable-caches" configure options.
		Improving MIPS dyntrans performance somewhat (only invalidate
		translations if necessary, on writes to the entryhi register,
		instead of doing it for all cop0 writes).
20060618	More cleanup after the removal of the old MIPS emulation.
		Trying to fix the MIPS dyntrans performance bugs/bottlenecks;
		only semi-successful so far (for R3000).
20060620	Minor update to allow clean compilation again on Tru64/Alpha.
20060622	MIPS cleanup and fixes (removing the pc_last stuff, which
		doesn't make sense with dyntrans anyway, and fixing a cross-
		page-delay-slot-with-exception case in end_of_page).
		Removing the old max_random_cycles_per_chunk stuff, and the
		concept of cycles vs instructions for MIPS emulation.
		FINALLY found and fixed the bug which caused NetBSD/pmax
		clocks to behave strangely (it was a load to the zero register,
		which was treated as a NOP; now it is treated as a load to a
		dummy scratch register).
20060623	Increasing the dyntrans chunk size back to
		N_SAFE_DYNTRANS_LIMIT, instead of N_SAFE_DYNTRANS_LIMIT/2.
		Preparing for a quick release, even though there are known
		bugs, and performance for non-R3000 MIPS emulation is very
		poor. :-/
		Reverting to half the dyntrans chunk size again, because
		NetBSD/cats seemed less stable with full size chunks. :(
		NetBSD/sgimips 3.0 can now run :-)  (With release 0.3.8, only
		NetBSD/sgimips 2.1 worked, not 3.0.)

==============  RELEASE 0.4.0  ==============


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.64 2006/03/04 12:38:47 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 /*
248 * dev_bt459_tick():
249 */
250 void dev_bt459_tick(struct cpu *cpu, void *extra)
251 {
252 struct bt459_data *d = extra;
253 int old_cursor_on = d->cursor_on;
254
255 if (d->need_to_update_cursor_shape) {
256 d->need_to_update_cursor_shape = 0;
257 bt459_update_X_cursor(cpu, d);
258 bt459_update_cursor_position(d, old_cursor_on);
259 }
260
261 if (d->need_to_redraw_whole_screen) {
262 d->vfb_data->update_x1 = 0;
263 d->vfb_data->update_x2 = d->vfb_data->xsize - 1;
264 d->vfb_data->update_y1 = 0;
265 d->vfb_data->update_y2 = d->vfb_data->ysize - 1;
266 d->need_to_redraw_whole_screen = 0;
267 }
268
269 /*
270 * Vertical retrace interrupts. (This hack is kind of ugly.)
271 * Once every 'interrupt_time_reset_value', the interrupt is
272 * asserted. It is acked either manually (by someone reading
273 * a normal BT459 register or the Interrupt ack register),
274 * or after another tick has passed. (This is to prevent
275 * lockups from unhandled interrupts.)
276 */
277 if (d->type != BT459_PX && d->interrupts_enable && d->irq_nr > 0) {
278 d->interrupt_time --;
279 if (d->interrupt_time < 0) {
280 d->interrupt_time = d->interrupt_time_reset_value;
281 cpu_interrupt(cpu, d->irq_nr);
282 } else
283 cpu_interrupt_ack(cpu, d->irq_nr);
284 }
285 }
286
287
288 /*
289 * dev_bt459_irq_access():
290 */
291 DEVICE_ACCESS(bt459_irq)
292 {
293 struct bt459_data *d = (struct bt459_data *) extra;
294 uint64_t idata = 0, odata = 0;
295
296 if (writeflag == MEM_WRITE)
297 idata = memory_readmax64(cpu, data, len);
298
299 #ifdef BT459_DEBUG
300 fatal("[ bt459: IRQ ack ]\n");
301 #endif
302
303 d->interrupts_enable = 1;
304 if (d->irq_nr > 0)
305 cpu_interrupt_ack(cpu, d->irq_nr);
306
307 if (writeflag == MEM_READ)
308 memory_writemax64(cpu, data, len, odata);
309
310 return 1;
311 }
312
313
314 /*
315 * dev_bt459_access():
316 */
317 DEVICE_ACCESS(bt459)
318 {
319 struct bt459_data *d = (struct bt459_data *) extra;
320 uint64_t idata = 0, odata = 0;
321 int btaddr, old_cursor_on = d->cursor_on, modified;
322
323 idata = memory_readmax64(cpu, data, len);
324
325 #ifdef BT459_DEBUG
326 if (writeflag == MEM_WRITE)
327 fatal("[ bt459: write to addr 0x%02x: %08x ]\n",
328 (int)relative_addr, (int)idata);
329 #endif
330
331 /*
332 * Vertical retrace interrupts are acked either by
333 * accessing a normal BT459 register, or the irq register,
334 * or by simply "missing" it.
335 */
336 if (d->irq_nr > 0)
337 cpu_interrupt_ack(cpu, d->irq_nr);
338
339 /* ID register is read-only, should always be 0x4a or 0x4a4a4a: */
340 if (d->planes == 24)
341 d->bt459_reg[BT459_REG_ID] = 0x4a4a4a;
342 else {
343 /*
344 * TODO: Is it really 0x4a, or 0x4a0000?
345 * Ultrix panics with a "bad VDAC ID" message if 0x4a
346 * is returned.
347 */
348 d->bt459_reg[BT459_REG_ID] = 0x4a0000;
349 }
350
351 btaddr = ((d->cur_addr_hi << 8) + d->cur_addr_lo) % DEV_BT459_NREGS;
352
353 /* Read from/write to the bt459: */
354 switch (relative_addr) {
355 case 0x00: /* Low byte of address: */
356 if (writeflag == MEM_WRITE) {
357 if (!quiet_mode)
358 debug("[ bt459: write to Low Address Byte, "
359 "0x%02x ]\n", (int)idata);
360 d->cur_addr_lo = idata;
361 d->palette_sub_offset = 0;
362 } else {
363 odata = d->cur_addr_lo;
364 if (!quiet_mode)
365 debug("[ bt459: read from Low Address Byte: "
366 "0x%0x ]\n", (int)odata);
367 }
368 break;
369 case 0x04: /* High byte of address: */
370 if (writeflag == MEM_WRITE) {
371 if (!quiet_mode)
372 debug("[ bt459: write to High Address Byte, "
373 "0x%02x ]\n", (int)idata);
374 d->cur_addr_hi = idata;
375 d->palette_sub_offset = 0;
376 } else {
377 odata = d->cur_addr_hi;
378 if (!quiet_mode)
379 debug("[ bt459: read from High Address Byte: "
380 "0x%0x ]\n", (int)odata);
381 }
382 break;
383 case 0x08: /* Register access: */
384 if (writeflag == MEM_WRITE) {
385 if (!quiet_mode)
386 debug("[ bt459: write to BT459 register "
387 "0x%04x, value 0x%02x ]\n", btaddr,
388 (int)idata);
389 modified = (d->bt459_reg[btaddr] != idata);
390 d->bt459_reg[btaddr] = idata;
391
392 switch (btaddr) {
393 case BT459_REG_CCOLOR_1:
394 case BT459_REG_CCOLOR_2:
395 case BT459_REG_CCOLOR_3:
396 if (modified)
397 d->need_to_update_cursor_shape = 1;
398 break;
399 case BT459_REG_PRM:
400 /*
401 * NetBSD writes 0x00 to this register to
402 * blank the screen (video off), and 0xff
403 * to turn the screen on.
404 */
405 switch (idata & 0xff) {
406 case 0: d->video_on = 0;
407 memset(d->rgb_palette, 0, 256*3);
408 d->need_to_redraw_whole_screen = 1;
409 debug("[ bt459: video OFF ]\n");
410 break;
411 default:d->video_on = 1;
412 memcpy(d->rgb_palette,
413 d->local_rgb_palette, 256*3);
414 d->need_to_redraw_whole_screen = 1;
415 debug("[ bt459: video ON ]\n");
416 }
417 break;
418 case BT459_REG_CCR:
419 /* Cursor control register: */
420 switch (idata & 0xff) {
421 case 0x00: d->cursor_on = 0; break;
422 case 0xc0:
423 case 0xc1: d->cursor_on = 1; break;
424 default:
425 fatal("[ bt459: unimplemented CCR "
426 "value 0x%08x ]\n", (int)idata);
427 }
428 if (modified)
429 d->need_to_update_cursor_shape = 1;
430 break;
431 default:
432 if (btaddr < 0x100)
433 fatal("[ bt459: write to BT459 "
434 "register 0x%04x, value 0x%02x ]\n",
435 btaddr, (int)idata);
436 }
437
438 /* Write to cursor bitmap: */
439 if (btaddr >= BT459_REG_CRAM_BASE && modified)
440 d->need_to_update_cursor_shape = 1;
441 } else {
442 odata = d->bt459_reg[btaddr];
443
444 /* Perhaps this hack is not necessary: */
445 if (btaddr == BT459_REG_ID && len==1)
446 odata = (odata >> 16) & 255;
447
448 if (!quiet_mode)
449 debug("[ bt459: read from BT459 register "
450 "0x%04x, value 0x%02x ]\n", btaddr,
451 (int)odata);
452 }
453
454 /* Go to next register: */
455 d->cur_addr_lo ++;
456 if (d->cur_addr_lo == 0)
457 d->cur_addr_hi ++;
458 break;
459 case 0xc: /* Color map: */
460 if (writeflag == MEM_WRITE) {
461 idata &= 255;
462 if (!quiet_mode)
463 debug("[ bt459: write to BT459 colormap "
464 "0x%04x subaddr %i, value 0x%02x ]\n",
465 btaddr, d->palette_sub_offset, (int)idata);
466
467 if (btaddr < 0x100) {
468 if (d->video_on &&
469 d->local_rgb_palette[(btaddr & 0xff) * 3
470 + d->palette_sub_offset] != idata)
471 d->need_to_redraw_whole_screen = 1;
472
473 /*
474 * Actually, the palette should only be
475 * updated after the third write,
476 * but this should probably work fine too:
477 */
478 d->local_rgb_palette[(btaddr & 0xff) * 3
479 + d->palette_sub_offset] = idata;
480
481 if (d->video_on)
482 d->rgb_palette[(btaddr & 0xff) * 3
483 + d->palette_sub_offset] = idata;
484 }
485 } else {
486 if (btaddr < 0x100)
487 odata = d->local_rgb_palette[(btaddr & 0xff)
488 * 3 + d->palette_sub_offset];
489 if (!quiet_mode)
490 debug("[ bt459: read from BT459 colormap "
491 "0x%04x subaddr %i, value 0x%02x ]\n",
492 btaddr, d->palette_sub_offset, (int)odata);
493 }
494
495 d->palette_sub_offset ++;
496 if (d->palette_sub_offset >= 3) {
497 d->palette_sub_offset = 0;
498
499 d->cur_addr_lo ++;
500 if (d->cur_addr_lo == 0)
501 d->cur_addr_hi ++;
502 }
503
504 break;
505 default:
506 if (writeflag == MEM_WRITE) {
507 debug("[ bt459: unimplemented write to address 0x%x, "
508 "data=0x%02x ]\n", (int)relative_addr, (int)idata);
509 } else {
510 debug("[ bt459: unimplemented read from address "
511 "0x%x ]\n", (int)relative_addr);
512 }
513 }
514
515
516 bt459_update_cursor_position(d, old_cursor_on);
517
518 if (writeflag == MEM_READ)
519 memory_writemax64(cpu, data, len, odata);
520
521 #ifdef BT459_DEBUG
522 if (writeflag == MEM_READ)
523 fatal("[ bt459: read from addr 0x%02x: %08x ]\n",
524 (int)relative_addr, (int)idata);
525 #endif
526
527 return 1;
528 }
529
530
531 /*
532 * dev_bt459_init():
533 */
534 void dev_bt459_init(struct machine *machine, struct memory *mem,
535 uint64_t baseaddr, uint64_t baseaddr_irq, struct vfb_data *vfb_data,
536 int planes, int irq_nr, int type)
537 {
538 struct bt459_data *d = malloc(sizeof(struct bt459_data));
539 if (d == NULL) {
540 fprintf(stderr, "out of memory\n");
541 exit(1);
542 }
543
544 memset(d, 0, sizeof(struct bt459_data));
545
546 d->vfb_data = vfb_data;
547 d->rgb_palette = vfb_data->rgb_palette;
548 d->planes = planes;
549 d->irq_nr = irq_nr;
550 d->type = type;
551 d->cursor_x = -1;
552 d->cursor_y = -1;
553 d->cursor_xsize = d->cursor_ysize = 0; /* anything */
554 d->video_on = 1;
555
556 /*
557 * These offsets are based on those mentioned in NetBSD,
558 * and then adjusted to look good with both NetBSD and
559 * Ultrix:
560 */
561 switch (d->type) {
562 case BT459_PX:
563 d->cursor_x_add = 370;
564 d->cursor_y_add = 37;
565 break;
566 case BT459_BA:
567 d->cursor_x_add = 220;
568 d->cursor_y_add = 35;
569 break;
570 case BT459_BBA:
571 if (vfb_data->xsize == 1280) {
572 /* 1280x1024: */
573 d->cursor_x_add = 368;
574 d->cursor_y_add = 38;
575 } else {
576 /* 1024x864: */
577 d->cursor_x_add = 220;
578 d->cursor_y_add = 35;
579 }
580 break;
581 }
582
583 d->interrupt_time_reset_value = 500;
584
585 memory_device_register(mem, "bt459", baseaddr, DEV_BT459_LENGTH,
586 dev_bt459_access, (void *)d, DM_DEFAULT, NULL);
587
588 if (baseaddr_irq != 0)
589 memory_device_register(mem, "bt459_irq", baseaddr_irq, 0x10000,
590 dev_bt459_irq_access, (void *)d, DM_DEFAULT, NULL);
591
592 machine_add_tickfunction(machine, dev_bt459_tick, d,
593 BT459_TICK_SHIFT, 0.0);
594 }
595

  ViewVC Help
Powered by ViewVC 1.1.26