/[gxemul]/trunk/src/devices/dev_ps2_gif.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_ps2_gif.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations)
Mon Oct 8 16:21:17 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 13022 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1480 2007/02/19 01:34:42 debug Exp $
20061029	Changing usleep(1) calls in the debugger to usleep(10000)
20061107	Adding a new disk image option (-d o...) which sets the ISO9660
		filesystem base offset; also making some other hacks to allow
		NetBSD/dreamcast and homebrew demos/games to boot directly
		from a filesystem image.
		Moving Dreamcast-specific stuff in the documentation to its
		own page (dreamcast.html).
		Adding a border to the Dreamcast PVR framebuffer.
20061108	Adding a -T command line option (again?), for halting the
		emulator on unimplemented memory accesses.
20061109	Continuing on various SH4 and Dreamcast related things.
		The emulator should now halt on more unimplemented device
		accesses, instead of just printing a warning, forcing me to
		actually implement missing stuff :)
20061111	Continuing on SH4 and Dreamcast stuff.
		Adding a bogus Landisk (SH4) machine mode.
20061112	Implementing some parts of the Dreamcast GDROM device. With
		some ugly hacks, NetBSD can (barely) mount an ISO image.
20061113	NetBSD/dreamcast now starts booting from the Live CD image,
		but crashes randomly quite early on in the boot process.
20061122	Beginning on a skeleton interrupt.h and interrupt.c for the
		new interrupt subsystem.
20061124	Continuing on the new interrupt system; taking the first steps
		to attempt to connect CPUs (SuperH and MIPS) and devices
		(dev_cons and SH4 timer interrupts) to it. Many things will
		probably break from now on.
20061125	Converting dev_ns16550, dev_8253 to the new interrupt system.
		Attempting to begin to convert the ISA bus.
20061130	Incorporating a patch from Brian Foley for the configure
		script, which checks for X11 libs in /usr/X11R6/lib64 (which
		is used on some Linux systems).
20061227	Adding a note in the man page about booting from Dreamcast
		CDROM images (i.e. that no external kernel is needed).
20061229	Continuing on the interrupt system rewrite: beginning to
		convert more devices, adding abort() calls for legacy interrupt
		system calls so that everything now _has_ to be rewritten!
		Almost all machine modes are now completely broken.
20061230	More progress on removing old interrupt code, mostly related
		to the ISA bus + devices, the LCA bus (on AlphaBook1), and
		the Footbridge bus (for CATS). And some minor PCI stuff.
		Connecting the ARM cpu to the new interrupt system.
		The CATS, NetWinder, and QEMU_MIPS machine modes now work with
		the new interrupt system :)
20061231	Connecting PowerPC CPUs to the new interrupt system.
		Making PReP machines (IBM 6050) work again.
		Beginning to convert the GT PCI controller (for e.g. Malta
		and Cobalt emulation). Some things work, but not everything.
		Updating Copyright notices for 2007.
20070101	Converting dev_kn02 from legacy style to devinit; the 3max
		machine mode now works with the new interrupt system :-]
20070105	Beginning to convert the SGI O2 machine to the new interrupt
		system; finally converting O2 (IP32) devices to devinit, etc.
20070106	Continuing on the interrupt system redesign/rewrite; KN01
		(PMAX), KN230, and Dreamcast ASIC interrupts should work again,
		moving out stuff from machine.h and devices.h into the
		corresponding devices, beginning the rewrite of i80321
		interrupts, etc.
20070107	Beginning on the rewrite of Eagle interrupt stuff (PReP, etc).
20070117	Beginning the rewrite of Algor (V3) interrupts (finally
		changing dev_v3 into devinit style).
20070118	Removing the "bus" registry concept from machine.h, because
		it was practically meaningless.
		Continuing on the rewrite of Algor V3 ISA interrupts.
20070121	More work on Algor interrupts; they are now working again,
		well enough to run NetBSD/algor. :-)
20070122	Converting VR41xx (HPCmips) interrupts. NetBSD/hpcmips
		can be installed using the new interrupt system :-)
20070123	Making the testmips mode work with the new interrupt system.
20070127	Beginning to convert DEC5800 devices to devinit, and to the
		new interrupt system.
		Converting Playstation 2 devices to devinit, and converting
		the interrupt system. Also fixing a severe bug: the interrupt
		mask register on Playstation 2 is bitwise _toggled_ on writes.
20070128	Removing the dummy NetGear machine mode and the 8250 device
		(which was only used by the NetGear machine).
		Beginning to convert the MacPPC GC (Grand Central) interrupt
		controller to the new interrupt system.
		Converting Jazz interrupts (PICA61 etc.) to the new interrupt
		system. NetBSD/arc can be installed again :-)
		Fixing the JAZZ timer (hardcoding it at 100 Hz, works with
		NetBSD and it is better than a completely dummy timer as it
		was before).
		Converting dev_mp to the new interrupt system, although I
		haven't had time to actually test it yet.
		Completely removing src/machines/interrupts.c, cpu_interrupt
		and cpu_interrupt_ack in src/cpu.c, and
		src/include/machine_interrupts.h! Adding fatal error messages
		+ abort() in the few places that are left to fix.
		Converting dev_z8530 to the new interrupt system.
		FINALLY removing the md_int struct completely from the
		machine struct.
		SH4 fixes (adding a PADDR invalidation in the ITLB replacement
		code in memory_sh.c); the NetBSD/dreamcast LiveCD now runs
		all the way to the login prompt, and can be interacted with :-)
		Converting the CPC700 controller (PCI and interrupt controller
		for PM/PPC) to the new interrupt system.
20070129	Fixing MACE ISA interrupts (SGI IP32 emulation). Both NetBSD/
		sgimips' and OpenBSD/sgi's ramdisk kernels can now be
		interacted with again.
20070130	Moving out the MIPS multi_lw and _sw instruction combinations
		so that they are auto-generated at compile time instead.
20070131	Adding detection of amd64/x86_64 hosts in the configure script,
		for doing initial experiments (again :-) with native code
		generation.
		Adding a -k command line option to set the size of the dyntrans
		cache, and a -B command line option to disable native code
		generation, even if GXemul was compiled with support for
		native code generation for the specific host CPU architecture.
20070201	Experimenting with a skeleton for native code generation.
		Changing the default behaviour, so that native code generation
		is now disabled by default, and has to be enabled by using
		-b on the command line.
20070202	Continuing the native code generation experiments.
		Making PCI interrupts work for Footbridge again.
20070203	More native code generation experiments.
		Removing most of the native code generation experimental code,
		it does not make sense to include any quick hacks like this.
		Minor cleanup/removal of some more legacy MIPS interrupt code.
20070204	Making i80321 interrupts work again (for NetBSD/evbarm etc.),
		and fixing the timer at 100 Hz.
20070206	Experimenting with removing the wdc interrupt slowness hack.
20070207	Lowering the number of dyntrans TLB entries for MIPS from
		192 to 128, resulting in a minor speed improvement.
		Minor optimization to the code invalidation routine in
		cpu_dyntrans.c.
20070208	Increasing (experimentally) the nr of dyntrans instructions per
		loop from 60 to 120.
20070210	Commenting out (experimentally) the dyntrans_device_danger
		detection in memory_rw.c.
		Changing the testmips and baremips machines to use a revision 2
		MIPS64 CPU by default, instead of revision 1.
		Removing the dummy i960, IA64, x86, AVR32, and HP PA-RISC
		files, the PC bios emulation, and the Olivetti M700 (ARC) and
		db64360 emulation modes.
20070211	Adding an "mp" demo to the demos directory, which tests the
		SMP functionality of the testmips machine.
		Fixing PReP interrupts some more. NetBSD/prep now boots again.
20070216	Adding a "nop workaround" for booting Mach/PMAX to the
		documentation; thanks to Artur Bujdoso for the values.
		Converting more of the MacPPC interrupt stuff to the new
		system.
		Beginning to convert BeBox interrupts to the new system.
		PPC603e should NOT have the PPC_NO_DEC flag! Removing it.
		Correcting BeBox clock speed (it was set to 100 in the NetBSD
		bootinfo block, but should be 33000000/4), allowing NetBSD
		to start without using the (incorrect) PPC_NO_DEC hack.
20070217	Implementing (slow) AltiVec vector loads and stores, allowing
		NetBSD/macppc to finally boot using the GENERIC kernel :-)
		Updating the documentation with install instructions for
		NetBSD/macppc.
20070218-19	Regression testing for the release.

==============  RELEASE 0.4.4  ==============


1 /*
2 * Copyright (C) 2003-2007 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_ps2_gif.c,v 1.34 2006/12/30 13:30:58 debug Exp $
29 *
30 * Playstation 2 "gif" graphics device.
31 *
32 * TODO: Convert dev_fb_access() accesses into direct framebuffer reads and
33 * writes, to improve performance.
34 *
35 * TODO 2: The way things are now, rgb bytes are copied from emulated
36 * space to the framebuffer as rgb, but on X Windows servers on
37 * big-endian machines that should be bgr. (?) Hm...
38 */
39
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43
44 #include "cpu.h"
45 #include "device.h"
46 #include "devices.h"
47 #include "machine.h"
48 #include "memory.h"
49 #include "misc.h"
50
51
52 #define DEV_PS2_GIF_LENGTH 0x10000
53
54 #define PS2_FB_ADDR 0x60000000ULL /* hopefully nothing else here */
55
56
57 struct gif_data {
58 struct cpu *cpu;
59 int xsize, ysize;
60 int bytes_per_pixel;
61 int transparent_text;
62 struct vfb_data *vfb_data;
63 };
64
65
66 /*
67 * test_triangle():
68 *
69 * Draw a triangle:
70 */
71 void test_triangle(struct gif_data *d,
72 int x1, int y1, int r1, int g1, int b1,
73 int x2, int y2, int r2, int g2, int b2,
74 int x3, int y3, int r3, int g3, int b3)
75 {
76 unsigned char *line = malloc(d->xsize * d->bytes_per_pixel);
77 int y, tmp, scale = 32768;
78 int xofs, xlen, savedxlen, xdir, x;
79 int r, g, b; /* scaled */
80 int xstart, xstop; /* scaled */
81 int rstart, rstop; /* scaled */
82 int gstart, gstop; /* scaled */
83 int bstart, bstop; /* scaled */
84 int rpx, gpx, bpx; /* scaled */
85 int xpy12, xpy13, xpy23;
86 int rpy12, rpy13, rpy23;
87 int gpy12, gpy13, gpy23;
88 int bpy12, bpy13, bpy23;
89
90 if (y2 > y3) {
91 tmp = x2; x2 = x3; x3 = tmp;
92 tmp = y2; y2 = y3; y3 = tmp;
93 tmp = r2; r2 = r3; r3 = tmp;
94 tmp = g2; g2 = g3; g3 = tmp;
95 tmp = b2; b2 = b3; b3 = tmp;
96 }
97
98 if (y1 > y2) {
99 tmp = x1; x1 = x2; x2 = tmp;
100 tmp = y1; y1 = y2; y2 = tmp;
101 tmp = r1; r1 = r2; r2 = tmp;
102 tmp = g1; g1 = g2; g2 = tmp;
103 tmp = b1; b1 = b2; b2 = tmp;
104 }
105
106 if (y1 > y3) {
107 tmp = x1; x1 = x3; x3 = tmp;
108 tmp = y1; y1 = y3; y3 = tmp;
109 tmp = r1; r1 = r3; r3 = tmp;
110 tmp = g1; g1 = g3; g3 = tmp;
111 tmp = b1; b1 = b3; b3 = tmp;
112 }
113
114 /* X change per line: */
115 xpy12 = (y2-y1)? scale*(x2-x1)/(y2-y1) : 0;
116 xpy13 = (y3-y1)? scale*(x3-x1)/(y3-y1) : 0;
117 xpy23 = (y3-y2)? scale*(x3-x2)/(y3-y2) : 0;
118
119 /* Color change per line: */
120 rpy12 = (y2-y1)? scale*(r2-r1)/(y2-y1) : 0;
121 rpy13 = (y3-y1)? scale*(r3-r1)/(y3-y1) : 0;
122 rpy23 = (y3-y2)? scale*(r3-r2)/(y3-y2) : 0;
123
124 gpy12 = (y2-y1)? scale*(g2-g1)/(y2-y1) : 0;
125 gpy13 = (y3-y1)? scale*(g3-g1)/(y3-y1) : 0;
126 gpy23 = (y3-y2)? scale*(g3-g2)/(y3-y2) : 0;
127
128 bpy12 = (y2-y1)? scale*(b2-b1)/(y2-y1) : 0;
129 bpy13 = (y3-y1)? scale*(b3-b1)/(y3-y1) : 0;
130 bpy23 = (y3-y2)? scale*(b3-b2)/(y3-y2) : 0;
131
132 xstart = xstop = x1 * scale;
133 rstart = rstop = r1 * scale;
134 gstart = gstop = g1 * scale;
135 bstart = bstop = b1 * scale;
136
137 for (y=y1; y<=y3; y++) {
138 if (xstart < xstop)
139 xofs = xstart/scale, xlen = (xstop-xstart)/scale + 1;
140 else
141 xofs = xstop/scale, xlen = (xstart-xstop)/scale + 1;
142
143 savedxlen = xlen;
144 xdir = (xstart < xstop)? 1 : -1;
145 r = rstart; g = gstart; b = bstart;
146
147 rpx = (xstop-xstart)? (rstop-rstart) / ((xstop-xstart)
148 / scale) : 0;
149 gpx = (xstop-xstart)? (gstop-gstart) / ((xstop-xstart)
150 / scale) : 0;
151 bpx = (xstop-xstart)? (bstop-bstart) / ((xstop-xstart)
152 / scale): 0;
153
154 x = xstart / scale;
155 while (xlen > 0) {
156 if (x>=0 && x<d->xsize) {
157 int c;
158 c = r/scale;
159 line[x * d->bytes_per_pixel + 0] = c<0?
160 0 : (c > 255? 255 : c);
161 c = g/scale;
162 line[x * d->bytes_per_pixel + 1] = c<0?
163 0 : (c > 255? 255 : c);
164 c = b/scale;
165 line[x * d->bytes_per_pixel + 2] = c<0?
166 0 : (c > 255? 255 : c);
167 }
168 r += rpx;
169 g += gpx;
170 b += bpx;
171 x += xdir;
172 xlen --;
173 }
174
175 dev_fb_access(d->cpu, d->cpu->mem,
176 (y*d->xsize + xofs) * d->bytes_per_pixel,
177 line + xofs * d->bytes_per_pixel,
178 savedxlen * d->bytes_per_pixel,
179 MEM_WRITE, d->vfb_data);
180
181 if (y<y2) {
182 xstart += xpy12;
183 rstart += rpy12;
184 gstart += gpy12;
185 bstart += bpy12;
186 } else {
187 xstart += xpy23;
188 rstart += rpy23;
189 gstart += gpy23;
190 bstart += bpy23;
191 }
192 xstop += xpy13;
193 rstop += rpy13;
194 gstop += gpy13;
195 bstop += bpy13;
196
197 if (y==y2) {
198 xstart = x2 * scale;
199 rstart = r2 * scale;
200 gstart = g2 * scale;
201 bstart = b2 * scale;
202 }
203 }
204 }
205
206
207 /*
208 * dev_ps2_gif_access():
209 */
210 DEVICE_ACCESS(ps2_gif)
211 {
212 unsigned int i;
213 struct gif_data *d = extra;
214
215 if (relative_addr + len > DEV_PS2_GIF_LENGTH)
216 return 0;
217
218 if (writeflag==MEM_READ) {
219 debug("[ gif read from addr 0x%x, len=%i ]\n",
220 (int)relative_addr, (int)len);
221 } else {
222 if (data[0] == 0x08 && data[1] == 0x80) {
223 /* Possibly "initialize 640x480 mode": */
224 debug("[ gif: initialize video mode (?) ]\n");
225 } else if (data[0] == 0x04 && data[1] == 0x00 && len > 300) {
226 /* Possibly "output 8x16 character": */
227 int xbase, ybase, xsize, ysize, x, y;
228
229 xbase = data[9*4 + 0] + (data[9*4 + 1] << 8);
230 ybase = data[9*4 + 2] + (data[9*4 + 3] << 8);
231
232 xsize = data[12*4 + 0] + (data[12*4 + 1] << 8);
233 ysize = data[13*4 + 0] + (data[13*4 + 1] << 8);
234 ysize &= ~0xf; /* multple of 16 */
235
236 /* debug("[ gif: putchar at (%i,%i), size (%i,%i) "
237 "]\n", xbase, ybase, xsize, ysize); */
238
239 /*
240 * NetBSD and Linux:
241 *
242 * [ gif write to addr 0x0 (len=608):
243 * 04 00 00 00 00 00 00 10, 0e 00 00 00 00 00 00 00,
244 * 00 00 00 00 00 00 0a 00, 50 00 00 00 00 00 00 00,
245 * 00 00 00 00 00 00 00 00, 51 00 00 00 00 00 00 00,
246 * 08 00 00 00 16 00 00 00, 52 00 00 00 00 00 00 00,
247 * 00 00 00 00 00 00 00 00, 53 00 00 00 00 00 00 00,
248 * 20 80 00 00 00 00 00 08, 00 00 00 00 00 00 00 00,
249 * 00 00 aa 80 00 00 aa 80, 00 00 aa 80 00 00 aa 80,
250 * 00 00 aa 80 00 00 aa 80, 00 00 aa 80 00 00 aa 80,
251 * aa aa 00 80 aa aa 00 80, 00 00 aa 80 00 00 aa 80,
252 * 00 00 aa 80 00 00 aa 80, 00 00 aa 80 00 00 aa 80,
253 */
254
255 /*
256 fatal("[ gif write to addr 0x%x (len=%i):",
257 (int)relative_addr, (int)len);
258 for (i=0; i<len; i++) {
259 fatal(" %02x", data[i]);
260 if ((i & 7) == 7)
261 fatal(",");
262 if ((i & 31) == 31)
263 fatal("\n");
264 }
265 fatal(" ]\n");
266 */
267
268 for (y=0; y<ysize; y++) {
269 int fb_addr = (xbase + (ybase+y) * d->xsize)
270 * d->bytes_per_pixel;
271 int addr = (24 + y*xsize) * 4;
272 for (x=0; x<xsize; x++) {
273 /* There are three bytes (r,g,b) at
274 data[addr + 0] .. [addr + 2].
275 TODO: This should be translated to a
276 direct update of the framebuffer. */
277
278 dev_fb_access(d->cpu, d->cpu->mem,
279 fb_addr, data + addr, 3, MEM_WRITE,
280 d->vfb_data);
281
282 fb_addr += d->bytes_per_pixel;
283 addr += 4;
284 }
285 }
286 } else if (data[0] == 0x04 && data[1] == 0x80 && len == 0x50) {
287 /* blockcopy */
288 int y_source, y_dest, x_source, x_dest, x_size, y_size;
289 x_source = data[8*4 + 0] + ((data[8*4 + 1]) << 8);
290 y_source = data[8*4 + 2] + ((data[8*4 + 3]) << 8);
291 x_dest = data[9*4 + 0] + ((data[9*4 + 1]) << 8);
292 y_dest = data[9*4 + 2] + ((data[9*4 + 3]) << 8);
293 x_size = data[12*4 + 0] + ((data[12*4 + 1]) << 8);
294 y_size = data[13*4 + 0] + ((data[13*4 + 1]) << 8);
295
296 /* debug("[ gif: blockcopy (%i,%i) -> (%i,%i), size="
297 "(%i,%i) ]\n", x_source,y_source, x_dest,y_dest,
298 x_size,y_size); */
299
300 framebuffer_blockcopyfill(d->vfb_data, 0, 0,0,0,
301 x_dest, y_dest, x_dest + x_size - 1, y_dest +
302 y_size - 1, x_source, y_source);
303 } else if (data[8] == 0x10 && data[9] == 0x55 && len == 48) {
304 /* Linux "clear": This is used by linux to clear the
305 lowest 16 pixels of the framebuffer. */
306 int xbase, ybase, xend, yend;
307
308 xbase = (data[8*4 + 0] + (data[8*4 + 1] << 8)) / 16;
309 ybase = (data[8*4 + 2] + (data[8*4 + 3] << 8)) / 16;
310 xend = (data[8*5 + 0] + (data[8*5 + 1] << 8)) / 16;
311 yend = (data[8*5 + 2] + (data[8*5 + 3] << 8)) / 16;
312
313 /* debug("[ gif: linux \"clear\" (%i,%i)-(%i,%i) ]\n",
314 xbase, ybase, xend, yend); */
315
316 framebuffer_blockcopyfill(d->vfb_data, 1, 0,0,0,
317 xbase, ybase, xend - 1, yend - 1, 0,0);
318 } else if (data[0] == 0x07 && data[1] == 0x80 && len == 128) {
319 /* NetBSD "output cursor": */
320 int xbase, ybase, xend, yend, x, y;
321
322 xbase = (data[20*4 + 0] + (data[20*4 + 1] << 8)) / 16;
323 ybase = (data[20*4 + 2] + (data[20*4 + 3] << 8)) / 16;
324 xend = (data[28*4 + 0] + (data[28*4 + 1] << 8)) / 16;
325 yend = (data[28*4 + 2] + (data[28*4 + 3] << 8)) / 16;
326
327 /* debug("[ gif: NETBSD cursor at (%i,%i)-(%i,%i) ]\n",
328 xbase, ybase, xend, yend); */
329
330 /* Output the cursor to framebuffer memory: */
331
332 for (y=ybase; y<=yend; y++)
333 for (x=xbase; x<=xend; x++) {
334 int fb_addr = (x + y * d->xsize) *
335 d->bytes_per_pixel;
336 unsigned char pixels[3];
337
338 dev_fb_access(d->cpu, d->cpu->mem,
339 fb_addr, pixels, sizeof(pixels),
340 MEM_READ, d->vfb_data);
341
342 pixels[0] = 0xff - pixels[0];
343 pixels[1] = 0xff - pixels[1];
344 pixels[2] = 0xff - pixels[2];
345
346 dev_fb_access(d->cpu, d->cpu->mem,
347 fb_addr, pixels, sizeof(pixels),
348 MEM_WRITE, d->vfb_data);
349 }
350 } else if (data[0] == 0x01 && data[1] == 0x00 && len == 80) {
351 /* Linux "output cursor": */
352 int xbase, ybase, xend, yend, x, y;
353
354 xbase = (data[7*8 + 0] + (data[7*8 + 1] << 8)) / 16;
355 ybase = (data[7*8 + 2] + (data[7*8 + 3] << 8)) / 16;
356 xend = (data[8*8 + 0] + (data[8*8 + 1] << 8)) / 16;
357 yend = (data[8*8 + 2] + (data[8*8 + 3] << 8)) / 16;
358
359 debug("[ gif: LINUX cursor at (%i,%i)-(%i,%i) ]\n",
360 xbase, ybase, xend, yend);
361
362 /* Output the cursor to framebuffer memory: */
363
364 for (y=ybase; y<=yend; y++)
365 for (x=xbase; x<=xend; x++) {
366 int fb_addr = (x + y * d->xsize) *
367 d->bytes_per_pixel;
368 unsigned char pixels[3];
369
370 dev_fb_access(d->cpu, d->cpu->mem,
371 fb_addr, pixels, sizeof(pixels),
372 MEM_READ, d->vfb_data);
373
374 pixels[0] = 0xff - pixels[0];
375 pixels[1] = 0xff - pixels[1];
376 pixels[2] = 0xff - pixels[2];
377
378 dev_fb_access(d->cpu, d->cpu->mem,
379 fb_addr, pixels, sizeof(pixels),
380 MEM_WRITE, d->vfb_data);
381 }
382 } else { /* Unknown command: */
383 fatal("[ gif write to addr 0x%x (len=%i):",
384 (int)relative_addr, len);
385 for (i=0; i<len; i++)
386 fatal(" %02x", data[i]);
387 fatal(" ]\n");
388 /* fatal("Unknown gif command.\n");
389 cpu->running = 0;
390 */ }
391 }
392
393 return 1;
394 }
395
396
397 /*
398 * devinit_ps2_gif():
399 *
400 * Attached to separate memory by devinit_ps2_gs().
401 */
402 DEVINIT(ps2_gif)
403 {
404 struct gif_data *d;
405
406 d = malloc(sizeof(struct gif_data));
407 if (d == NULL) {
408 fprintf(stderr, "out of memory\n");
409 exit(1);
410 }
411 memset(d, 0, sizeof(struct gif_data));
412
413 d->transparent_text = 0;
414 d->cpu = devinit->machine->cpus[0]; /* TODO */
415 d->xsize = 640; d->ysize = 480;
416 d->bytes_per_pixel = 3;
417
418 d->vfb_data = dev_fb_init(devinit->machine, devinit->machine->memory,
419 PS2_FB_ADDR, VFB_PLAYSTATION2,
420 d->xsize, d->ysize, d->xsize, d->ysize, 24, "Playstation 2");
421 if (d->vfb_data == NULL) {
422 fprintf(stderr, "could not initialize fb, out of memory\n");
423 exit(1);
424 }
425
426 #if 0
427 test_triangle(d, 300,50, 255,0,0, 50,150, 0,255,0, 600,400, 0,0,255);
428 test_triangle(d, 310,210, 128,32,0, 175,410, 0,32,0,
429 500,470, 125,255,125);
430 test_triangle(d, 100,450, 255,255,0, 250,370, 0,255,255,
431 400,470, 255,0,255);
432 #endif
433
434 memory_device_register(devinit->machine->memory, devinit->name,
435 devinit->addr, DEV_PS2_GIF_LENGTH, dev_ps2_gif_access, d,
436 DM_DEFAULT, NULL);
437
438 return 1;
439 }
440

  ViewVC Help
Powered by ViewVC 1.1.26