/[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 12 - (show annotations)
Mon Oct 8 16:18:38 2007 UTC (12 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 13019 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.905 2005/08/16 09:16:24 debug Exp $
20050628	Continuing the work on the ARM translation engine. end_of_page
		works. Experimenting with load/store translation caches
		(virtual -> physical -> host).
20050629	More ARM stuff (memory access translation cache, mostly). This
		might break a lot of stuff elsewhere, probably some MIPS-
		related translation things.
20050630	Many load/stores are now automatically generated and included
		into cpu_arm_instr.c; 1024 functions in total (!).
		Fixes based on feedback from Alec Voropay: only print 8 hex
		digits instead of 16 in some cases when emulating 32-bit
		machines; similar 8 vs 16 digit fix for breakpoint addresses;
		4Kc has 16 TLB entries, not 48; the MIPS config select1
		register is now printed with "reg ,0".
		Also changing many other occurances of 16 vs 8 digit output.
		Adding cache associativity fields to mips_cpu_types.h; updating
		some other cache fields; making the output of
		mips_cpu_dumpinfo() look nicer.
		Generalizing the bintrans stuff for device accesses to also
		work with the new translation system. (This might also break
		some MIPS things.)
		Adding multi-load/store instructions to the ARM disassembler
		and the translator, and some optimizations of various kinds.
20050701	Adding a simple dev_disk (it can read/write sectors from
		disk images).
20050712	Adding dev_ether (a simple ethernet send/receive device).
		Debugger command "ninstrs" for toggling show_nr_of_instructions
		during runtime.
		Removing the framebuffer logo.
20050713	Continuing on dev_ether.
		Adding a dummy cpu_alpha (again).
20050714	More work on cpu_alpha.
20050715	More work on cpu_alpha. Many instructions work, enough to run
		a simple framebuffer fill test (similar to the ARM test).
20050716	More Alpha stuff.
20050717	Minor updates (Alpha stuff).
20050718	Minor updates (Alpha stuff).
20050719	Generalizing some Alpha instructions.
20050720	More Alpha-related updates.
20050721	Continuing on cpu_alpha. Importing rpb.h from NetBSD/alpha.
20050722	Alpha-related updates: userland stuff (Hello World using
		write() compiled statically for FreeBSD/Alpha runs fine), and
		more instructions are now implemented.
20050723	Fixing ldq_u and stq_u.
		Adding more instructions (conditional moves, masks, extracts,
		shifts).
20050724	More FreeBSD/Alpha userland stuff, and adding some more
		instructions (inserts).
20050725	Continuing on the Alpha stuff. (Adding dummy ldt/stt.)
		Adding a -A command line option to turn off alignment checks
		in some cases (for translated code).
		Trying to remove the old bintrans code which updated the pc
		and nr_of_executed_instructions for every instruction.
20050726	Making another attempt att removing the pc/nr of instructions
		code. This time it worked, huge performance increase for
		artificial test code, but performance loss for real-world
		code :-( so I'm scrapping that code for now.
		Tiny performance increase on Alpha (by using ret instead of
		jmp, to play nice with the Alpha's branch prediction) for the
		old MIPS bintrans backend.
20050727	Various minor fixes and cleanups.
20050728	Switching from a 2-level virtual to host/physical translation
		system for ARM emulation, to a 1-level translation.
		Trying to switch from 2-level to 1-level for the MIPS bintrans
		system as well (Alpha only, so far), but there is at least one
		problem: caches and/or how they work with device mappings.
20050730	Doing the 2-level to 1-level conversion for the i386 backend.
		The cache/device bug is still there for R2K/3K :(
		Various other minor updates (Malta etc).
		The mc146818 clock now updates the UIP bit in a way which works
		better with Linux for at least sgimips and Malta emulation.
		Beginning the work on refactoring the dyntrans system.
20050731	Continuing the dyntrans refactoring.
		Fixing a small but serious host alignment bug in memory_rw.
		Adding support for big-endian load/stores to the i386 bintrans
		backend.
		Another minor i386 bintrans backend update: stores from the
		zero register are now one (or two) loads shorter.
		The slt and sltu instructions were incorrectly implemented for
		the i386 backend; only using them for 32-bit mode for now.
20050801	Continuing the dyntrans refactoring.
		Cleanup of the ns16550 serial controller (removing unnecessary
		code).
		Bugfix (memory corruption bug) in dev_gt, and a patch/hack from
		Alec Voropay for Linux/Malta.
20050802	More cleanup/refactoring of the dyntrans subsystem: adding
		phys_page pointers to the lookup tables, for quick jumps
		between translated pages.
		Better fix for the ns16550 device (but still no real FIFO
		functionality).
		Converting cpu_ppc to the new dyntrans system. This means that
		I will have to start from scratch with implementing each
		instruction, and figure out how to implement dual 64/32-bit
		modes etc.
		Removing the URISC CPU family, because it was useless.
20050803	When selecting a machine type, the main type can now be omitted
		if the subtype name is unique. (I.e. -E can be omitted.)
		Fixing a dyntrans/device update bug. (Writes to offset 0 of
		a device could sometimes go unnoticed.)
		Adding an experimental "instruction combination" hack for
		ARM for memset-like byte fill loops.
20050804	Minor progress on cpu_alpha and related things.
		Finally fixing the MIPS dmult/dmultu bugs.
		Fixing some minor TODOs.
20050805	Generalizing the 8259 PIC. It now also works with Cobalt
		and evbmips emulation, in addition to the x86 hack.
		Finally converting the ns16550 device to use devinit.
		Continuing the work on the dyntrans system. Thinking about
		how to add breakpoints.
20050806	More dyntrans updates. Breakpoints seem to work now.
20050807	Minor updates: cpu_alpha and related things; removing
		dev_malta (as it isn't used any more).
		Dyntrans: working on general "show trace tree" support.
		The trace tree stuff now works with both the old MIPS code and
		with newer dyntrans modes. :)
		Continuing on Alpha-related stuff (trying to get *BSD to boot
		a bit further, adding more instructions, etc).
20050808	Adding a dummy IA64 cpu family, and continuing the refactoring
		of the dyntrans system.
		Removing the regression test stuff, because it was more or
		less useless.
		Adding loadlinked/storeconditional type instructions to the
		Alpha emulation. (Needed for Linux/alpha. Not very well tested
		yet.)
20050809	The function call trace tree now prints a per-function nr of
		arguments. (Semi-meaningless, since that data isn't read yet
		from the ELFs; some hardcoded symbols such as memcpy() and
		strlen() work fine, though.)
		More dyntrans refactoring; taking out more of the things that
		are common to all cpu families.
20050810	Working on adding support for "dual mode" for PPC dyntrans
		(i.e. both 64-bit and 32-bit modes).
		(Re)adding some simple PPC instructions.
20050811	Adding a dummy M68K cpu family. The dyntrans system isn't ready
		for variable-length ISAs yet, so it's completely bogus so far.
		Re-adding more PPC instructions.
		Adding a hack to src/file.c which allows OpenBSD/mac68k a.out
		kernels to be loaded.
		Beginning to add PPC loads/stores. So far they only work in
		32-bit mode.
20050812	The configure file option "add_remote" now accepts symbolic
		host names, in addition to numeric IPv4 addresses.
		Re-adding more PPC instructions.
20050814	Continuing to port back more PPC instructions.
		Found and fixed the cache/device write-update bug for 32-bit
		MIPS bintrans. :-)
		Triggered a really weird and annoying bug in Compaq's C
		compiler; ccc sometimes outputs code which loads from an
		address _before_ checking whether the pointer was NULL or not.
		(I'm not sure how to handle this problem.)
20050815	Removing all of the old x86 instruction execution code; adding
		a new (dummy) dyntrans module for x86.
		Taking the first steps to extend the dyntrans system to support
		variable-length instructions.
		Slowly preparing for the next release.
20050816	Adding a dummy SPARC cpu module.
		Minor updates (documentation etc) for the release.

==============  RELEASE 0.3.5  ==============


1 /*
2 * Copyright (C) 2003-2005 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.29 2005/07/12 08:49:13 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 int dev_ps2_gif_access(struct cpu *cpu, struct memory *mem,
211 uint64_t relative_addr, unsigned char *data, size_t len,
212 int writeflag, void *extra)
213 {
214 int i;
215 struct gif_data *d = extra;
216
217 if (relative_addr + len > DEV_PS2_GIF_LENGTH)
218 return 0;
219
220 if (writeflag==MEM_READ) {
221 debug("[ gif read from addr 0x%x, len=%i ]\n",
222 (int)relative_addr, (int)len);
223 } else {
224 if (data[0] == 0x08 && data[1] == 0x80) {
225 /* Possibly "initialize 640x480 mode": */
226 debug("[ gif: initialize video mode (?) ]\n");
227 } else if (data[0] == 0x04 && data[1] == 0x00 && len > 300) {
228 /* Possibly "output 8x16 character": */
229 int xbase, ybase, xsize, ysize, x, y;
230
231 xbase = data[9*4 + 0] + (data[9*4 + 1] << 8);
232 ybase = data[9*4 + 2] + (data[9*4 + 3] << 8);
233
234 xsize = data[12*4 + 0] + (data[12*4 + 1] << 8);
235 ysize = data[13*4 + 0] + (data[13*4 + 1] << 8);
236 ysize &= ~0xf; /* multple of 16 */
237
238 /* debug("[ gif: putchar at (%i,%i), size (%i,%i) "
239 "]\n", xbase, ybase, xsize, ysize); */
240
241 /*
242 * NetBSD and Linux:
243 *
244 * [ gif write to addr 0x0 (len=608):
245 * 04 00 00 00 00 00 00 10, 0e 00 00 00 00 00 00 00, 00 00 00 00 00 00 0a 00, 50 00 00 00 00 00 00 00,
246 * 00 00 00 00 00 00 00 00, 51 00 00 00 00 00 00 00, 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, 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, 00 00 aa 80 00 00 aa 80, 00 00 aa 80 00 00 aa 80,
249 * aa aa 00 80 aa aa 00 80, 00 00 aa 80 00 00 aa 80, 00 00 aa 80 00 00 aa 80, 00 00 aa 80 00 00 aa 80,
250 */
251
252 /*
253 fatal("[ gif write to addr 0x%x (len=%i):",
254 (int)relative_addr, (int)len);
255 for (i=0; i<len; i++) {
256 fatal(" %02x", data[i]);
257 if ((i & 7) == 7)
258 fatal(",");
259 if ((i & 31) == 31)
260 fatal("\n");
261 }
262 fatal(" ]\n");
263 */
264
265 for (y=0; y<ysize; y++) {
266 int fb_addr = (xbase + (ybase+y) * d->xsize)
267 * d->bytes_per_pixel;
268 int addr = (24 + y*xsize) * 4;
269 for (x=0; x<xsize; x++) {
270 /* There are three bytes (r,g,b) at data[addr + 0] .. [addr + 2].
271 TODO: This should be translated to a direct update of the framebuffer. */
272
273 dev_fb_access(d->cpu, d->cpu->mem,
274 fb_addr, data + addr, 3, MEM_WRITE, d->vfb_data);
275
276 fb_addr += d->bytes_per_pixel;
277 addr += 4;
278 }
279 }
280 } else if (data[0] == 0x04 && data[1] == 0x80 && len == 0x50) { /* blockcopy */
281 int y_source, y_dest, x_source, x_dest, x_size, y_size;
282 x_source = data[8*4 + 0] + ((data[8*4 + 1]) << 8);
283 y_source = data[8*4 + 2] + ((data[8*4 + 3]) << 8);
284 x_dest = data[9*4 + 0] + ((data[9*4 + 1]) << 8);
285 y_dest = data[9*4 + 2] + ((data[9*4 + 3]) << 8);
286 x_size = data[12*4 + 0] + ((data[12*4 + 1]) << 8);
287 y_size = data[13*4 + 0] + ((data[13*4 + 1]) << 8);
288
289 /* debug("[ gif: blockcopy (%i,%i) -> (%i,%i), size=(%i,%i) ]\n",
290 x_source,y_source, x_dest,y_dest, x_size,y_size); */
291
292 framebuffer_blockcopyfill(d->vfb_data, 0, 0,0,0, x_dest,y_dest,
293 x_dest + x_size - 1, y_dest + y_size - 1, x_source, y_source);
294 } else if (data[8] == 0x10 && data[9] == 0x55 && len == 48) { /* Linux "clear": */
295 /* This is used by linux to clear the lowest 16 pixels of the framebuffer. */
296 int xbase, ybase, xend, yend;
297
298 xbase = (data[8*4 + 0] + (data[8*4 + 1] << 8)) / 16;
299 ybase = (data[8*4 + 2] + (data[8*4 + 3] << 8)) / 16;
300 xend = (data[8*5 + 0] + (data[8*5 + 1] << 8)) / 16;
301 yend = (data[8*5 + 2] + (data[8*5 + 3] << 8)) / 16;
302
303 /* debug("[ gif: linux \"clear\" (%i,%i)-(%i,%i) ]\n", xbase,ybase, xend,yend); */
304
305 framebuffer_blockcopyfill(d->vfb_data, 1, 0,0,0, xbase,ybase, xend-1,yend-1, 0,0);
306 } else if (data[0] == 0x07 && data[1] == 0x80 && len == 128) { /* NetBSD "output cursor": */
307 int xbase, ybase, xend, yend, x, y;
308
309 xbase = (data[20*4 + 0] + (data[20*4 + 1] << 8)) / 16;
310 ybase = (data[20*4 + 2] + (data[20*4 + 3] << 8)) / 16;
311 xend = (data[28*4 + 0] + (data[28*4 + 1] << 8)) / 16;
312 yend = (data[28*4 + 2] + (data[28*4 + 3] << 8)) / 16;
313
314 /* debug("[ gif: NETBSD cursor at (%i,%i)-(%i,%i) ]\n", xbase, ybase, xend, yend); */
315
316 /* Output the cursor to framebuffer memory: */
317
318 for (y=ybase; y<=yend; y++)
319 for (x=xbase; x<=xend; x++) {
320 int fb_addr = (x + y * d->xsize) * d->bytes_per_pixel;
321 unsigned char pixels[3];
322
323 dev_fb_access(d->cpu, d->cpu->mem,
324 fb_addr, pixels, sizeof(pixels),
325 MEM_READ, d->vfb_data);
326
327 pixels[0] = 0xff - pixels[0];
328 pixels[1] = 0xff - pixels[1];
329 pixels[2] = 0xff - pixels[2];
330
331 dev_fb_access(d->cpu, d->cpu->mem,
332 fb_addr, pixels, sizeof(pixels),
333 MEM_WRITE, d->vfb_data);
334 }
335 } else if (data[0] == 0x01 && data[1] == 0x00 && len == 80) { /* Linux "output cursor": */
336 int xbase, ybase, xend, yend, x, y;
337
338 xbase = (data[7*8 + 0] + (data[7*8 + 1] << 8)) / 16;
339 ybase = (data[7*8 + 2] + (data[7*8 + 3] << 8)) / 16;
340 xend = (data[8*8 + 0] + (data[8*8 + 1] << 8)) / 16;
341 yend = (data[8*8 + 2] + (data[8*8 + 3] << 8)) / 16;
342
343 debug("[ gif: LINUX cursor at (%i,%i)-(%i,%i) ]\n", xbase, ybase, xend, yend);
344
345 /* Output the cursor to framebuffer memory: */
346
347 for (y=ybase; y<=yend; y++)
348 for (x=xbase; x<=xend; x++) {
349 int fb_addr = (x + y * d->xsize) * d->bytes_per_pixel;
350 unsigned char pixels[3];
351
352 dev_fb_access(d->cpu, d->cpu->mem,
353 fb_addr, pixels, sizeof(pixels),
354 MEM_READ, d->vfb_data);
355
356 pixels[0] = 0xff - pixels[0];
357 pixels[1] = 0xff - pixels[1];
358 pixels[2] = 0xff - pixels[2];
359
360 dev_fb_access(d->cpu, d->cpu->mem,
361 fb_addr, pixels, sizeof(pixels),
362 MEM_WRITE, d->vfb_data);
363 }
364 } else { /* Unknown command: */
365 fatal("[ gif write to addr 0x%x (len=%i):", (int)relative_addr, len);
366 for (i=0; i<len; i++)
367 fatal(" %02x", data[i]);
368 fatal(" ]\n");
369 /* fatal("Unknown gif command.\n");
370 cpu->running = 0;
371 */ }
372 }
373
374 return 1;
375 }
376
377
378 /*
379 * devinit_ps2_gif():
380 *
381 * Attached to separate memory by devinit_ps2_gs().
382 */
383 int devinit_ps2_gif(struct devinit *devinit)
384 {
385 struct gif_data *d;
386
387 d = malloc(sizeof(struct gif_data));
388 if (d == NULL) {
389 fprintf(stderr, "out of memory\n");
390 exit(1);
391 }
392 memset(d, 0, sizeof(struct gif_data));
393
394 d->transparent_text = 0;
395 d->cpu = devinit->machine->cpus[0]; /* TODO */
396 d->xsize = 640; d->ysize = 480;
397 d->bytes_per_pixel = 3;
398
399 d->vfb_data = dev_fb_init(devinit->machine, devinit->machine->memory,
400 PS2_FB_ADDR, VFB_PLAYSTATION2,
401 d->xsize, d->ysize, d->xsize, d->ysize, 24, "Playstation 2");
402 if (d->vfb_data == NULL) {
403 fprintf(stderr, "could not initialize fb, out of memory\n");
404 exit(1);
405 }
406
407 #if 0
408 test_triangle(d, 300,50, 255,0,0, 50,150, 0,255,0, 600,400, 0,0,255);
409 test_triangle(d, 310,210, 128,32,0, 175,410, 0,32,0, 500,470, 125,255,125);
410 test_triangle(d, 100,450, 255,255,0, 250,370, 0,255,255, 400,470, 255,0,255);
411 #endif
412
413 memory_device_register(devinit->machine->memory, devinit->name,
414 devinit->addr, DEV_PS2_GIF_LENGTH, dev_ps2_gif_access, d,
415 MEM_DEFAULT, NULL);
416
417 return 1;
418 }
419

  ViewVC Help
Powered by ViewVC 1.1.26