/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (hide annotations)
Mon Oct 8 16:22:32 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 15212 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1613 2007/06/15 20:11:26 debug Exp $
20070501	Continuing a little on m88k disassembly (control registers,
		more instructions).
		Adding a dummy mvme88k machine mode.
20070502	Re-adding MIPS load/store alignment exceptions.
20070503	Implementing more of the M88K disassembly code.
20070504	Adding disassembly of some more M88K load/store instructions.
		Implementing some relatively simple M88K instructions (br.n,
		xor[.u] imm, and[.u] imm).
20070505	Implementing M88K three-register and, or, xor, and jmp[.n],
		bsr[.n] including function call trace stuff.
		Applying a patch from Bruce M. Simpson which implements the
		SYSCON_BOARD_CPU_CLOCK_FREQ_ID object of the syscon call in
		the yamon PROM emulation.
20070506	Implementing M88K bb0[.n] and bb1[.n], and skeletons for
		ldcr and stcr (although no control regs are implemented yet).
20070509	Found and fixed the bug which caused Linux for QEMU_MIPS to
		stop working in 0.4.5.1: It was a faulty change to the MIPS
		'sc' and 'scd' instructions I made while going through gcc -W
		warnings on 20070428.
20070510	Updating the Linux/QEMU_MIPS section in guestoses.html to
		use mips-test-0.2.tar.gz instead of 0.1.
		A big thank you to Miod Vallat for sending me M88K manuals.
		Implementing more M88K instructions (addu, subu, div[u], mulu,
		ext[u], clr, set, cmp).
20070511	Fixing bugs in the M88K "and" and "and.u" instructions (found
		by comparing against the manual).
		Implementing more M88K instructions (mask[.u], mak, bcnd (auto-
		generated)) and some more control register details.
		Cleanup: Removing the experimental AVR emulation mode and
		corresponding devices; AVR emulation wasn't really meaningful.
		Implementing autogeneration of most M88K loads/stores. The
		rectangle drawing demo (with -O0) for M88K runs :-)
		Beginning on M88K exception handling.
		More M88K instructions: tb0, tb1, rte, sub, jsr[.n].
		Adding some skeleton MVME PROM ("BUG") emulation.
20070512	Fixing a bug in the M88K cmp instruction.
		Adding the M88K lda (scaled register) instruction.
		Fixing bugs in 64-bit (32-bit pairs) M88K loads/stores.
		Removing the unused tick_hz stuff from the machine struct.
		Implementing the M88K xmem instruction. OpenBSD/mvme88k gets
		far enough to display the Copyright banner :-)
		Implementing subu.co (guess), addu.co, addu.ci, ff0, and ff1.
		Adding a dev_mvme187, for MVME187-specific devices/registers.
		OpenBSD/mvme88k prints more boot messages. :)
20070515	Continuing on MVME187 emulation (adding more devices, beginning
		on the CMMUs, etc).
		Adding the M88K and.c, xor.c, and or.c instructions, and making
		sure that mul, div, etc cause exceptions if executed when SFD1
		is disabled.
20070517	Continuing on M88K and MVME187 emulation in general; moving
		the CMMU registers to the CPU struct, separating dev_pcc2 from
		dev_mvme187, and beginning on memory_m88k.c (BATC and PATC).
		Fixing a bug in 64-bit (32-bit pairs) M88K fast stores.
		Implementing the clock part of dev_mk48txx.
		Implementing the M88K fstcr and xcr instructions.
		Implementing m88k_cpu_tlbdump().
		Beginning on the implementation of a separate address space
		for M88K .usr loads/stores.
20070520	Removing the non-working (skeleton) Sandpoint, SonyNEWS, SHARK
		Dnard, and Zaurus machine modes.
		Experimenting with dyntrans to_be_translated read-ahead. It
		seems to give a very small performance increase for MIPS
		emulation, but a large performance degradation for SuperH. Hm.
20070522	Disabling correct SuperH ITLB emulation; it does not seem to be
		necessary in order to let SH4 guest OSes run, and it slows down
		userspace code.
		Implementing "samepage" branches for SuperH emulation, and some
		other minor speed hacks.
20070525	Continuing on M88K memory-related stuff: exceptions, memory
		transaction register contents, etc.
		Implementing the M88K subu.ci instruction.
		Removing the non-working (skeleton) Iyonix machine mode.
		OpenBSD/mvme88k reaches userland :-), starts executing
		/sbin/init's instructions, and issues a few syscalls, before
		crashing.
20070526	Fixing bugs in dev_mk48txx, so that OpenBSD/mvme88k detects
		the correct time-of-day.
		Implementing a generic IRQ controller for the test machines
		(dev_irqc), similar to a proposed patch from Petr Stepan.
		Experimenting some more with translation read-ahead.
		Adding an "expect" script for automated OpenBSD/landisk
		install regression/performance tests.
20070527	Adding a dummy mmEye (SH3) machine mode skeleton.
		FINALLY found the strange M88K bug I have been hunting: I had
		not emulated the SNIP value for exceptions occurring in
		branch delay slots correctly.
		Implementing correct exceptions for 64-bit M88K loads/stores.
		Address to symbol lookups are now disabled when M88K is
		running in usermode (because usermode addresses don't have
		anything to do with supervisor addresses).
20070531	Removing the mmEye machine mode skeleton.
20070604	Some minor code cleanup.
20070605	Moving src/useremul.c into a subdir (src/useremul/), and
		cleaning up some more legacy constructs.
		Adding -Wstrict-aliasing and -fstrict-aliasing detection to
		the configure script.
20070606	Adding a check for broken GCC on Solaris to the configure
		script. (GCC 3.4.3 on Solaris cannot handle static variables
		which are initialized to 0 or NULL. :-/)
		Removing the old (non-working) ARC emulation modes: NEC RD94,
		R94, R96, and R98, and the last traces of Olivetti M700 and
		Deskstation Tyne.
		Removing the non-working skeleton WDSC device (dev_wdsc).
20070607	Thinking about how to use the host's cc + ld at runtime to
		generate native code. (See experiments/native_cc_ld_test.i
		for an example.)
20070608	Adding a program counter sampling timer, which could be useful
		for native code generation experiments.
		The KN02_CSR_NRMMOD bit in the DECstation 5000/200 (KN02) CSR
		should always be set, to allow a 5000/200 PROM to boot.
20070609	Moving out breakpoint details from the machine struct into
		a helper struct, and removing the limit on max nr of
		breakpoints.
20070610	Moving out tick functions into a helper struct as well (which
		also gets rid of the max limit).
20070612	FINALLY figured out why Debian/DECstation stopped working when
		translation read-ahead was enabled: in src/memory_rw.c, the
		call to invalidate_code_translation was made also if the
		memory access was an instruction load (if the page was mapped
		as writable); it shouldn't be called in that case.
20070613	Implementing some more MIPS32/64 revision 2 instructions: di,
		ei, ext, dext, dextm, dextu, and ins.
20070614	Implementing an instruction combination for the NetBSD/arm
		idle loop (making the host not use any cpu if NetBSD/arm
		inside the emulator is not using any cpu).
		Increasing the nr of ARM VPH entries from 128 to 384.
20070615	Removing the ENABLE_arch stuff from the configure script, so
		that all included architectures are included in both release
		and development builds.
		Moving memory related helper functions from misc.c to memory.c.
		Adding preliminary instructions for netbooting NetBSD/pmppc to
		guestoses.html; it doesn't work yet, there are weird timeouts.
		Beginning a total rewrite of the userland emulation modes
		(removing all emulation modes, beginning from scratch with
		NetBSD/MIPS and FreeBSD/Alpha only).
20070616	After fixing a bug in the DEC21143 NIC (the TDSTAT_OWN bit was
		only cleared for the last segment when transmitting, not all
		segments), NetBSD/pmppc boots with root-on-nfs without the
		timeouts. Updating guestoses.html.
		Removing the skeleton PSP (Playstation Portable) mode.
		Moving X11-related stuff in the machine struct into a helper
		struct.
		Cleanup of out-of-memory checks, to use a new CHECK_ALLOCATION
		macro (which prints a meaningful error message).
		Adding a COMMENT to each machine and device (for automagic
		.index comment generation).
		Doing regression testing for the next release.

==============  RELEASE 0.4.6  ==============


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

  ViewVC Help
Powered by ViewVC 1.1.26