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

  ViewVC Help
Powered by ViewVC 1.1.26