1 |
/* |
/* |
2 |
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_ps2_gif.c,v 1.28 2005/04/09 13:33:36 debug Exp $ |
* $Id: dev_ps2_gif.c,v 1.35 2007/06/15 19:57:33 debug Exp $ |
29 |
* |
* |
30 |
* Playstation 2 "gif" graphics device. |
* COMMENT: PlayStation 2 "gif" graphics device |
31 |
* |
* |
32 |
* TODO: Convert dev_fb_access() accesses into direct framebuffer reads and |
* TODO: Convert dev_fb_access() accesses into direct framebuffer reads and |
33 |
* writes, to improve performance. |
* writes, to improve performance. |
73 |
int x2, int y2, int r2, int g2, int b2, |
int x2, int y2, int r2, int g2, int b2, |
74 |
int x3, int y3, int r3, int g3, int b3) |
int x3, int y3, int r3, int g3, int b3) |
75 |
{ |
{ |
76 |
unsigned char *line = malloc(d->xsize * d->bytes_per_pixel); |
unsigned char *line; |
77 |
int y, tmp, scale = 32768; |
int y, tmp, scale = 32768; |
78 |
int xofs, xlen, savedxlen, xdir, x; |
int xofs, xlen, savedxlen, xdir, x; |
79 |
int r, g, b; /* scaled */ |
int r, g, b; /* scaled */ |
87 |
int gpy12, gpy13, gpy23; |
int gpy12, gpy13, gpy23; |
88 |
int bpy12, bpy13, bpy23; |
int bpy12, bpy13, bpy23; |
89 |
|
|
90 |
|
CHECK_ALLOCATION(line = malloc(d->xsize * d->bytes_per_pixel)); |
91 |
|
|
92 |
if (y2 > y3) { |
if (y2 > y3) { |
93 |
tmp = x2; x2 = x3; x3 = tmp; |
tmp = x2; x2 = x3; x3 = tmp; |
94 |
tmp = y2; y2 = y3; y3 = tmp; |
tmp = y2; y2 = y3; y3 = tmp; |
206 |
} |
} |
207 |
|
|
208 |
|
|
209 |
/* |
DEVICE_ACCESS(ps2_gif) |
|
* dev_ps2_gif_access(): |
|
|
*/ |
|
|
int dev_ps2_gif_access(struct cpu *cpu, struct memory *mem, |
|
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
210 |
{ |
{ |
211 |
int i; |
unsigned int i; |
212 |
struct gif_data *d = extra; |
struct gif_data *d = extra; |
213 |
|
|
214 |
if (relative_addr + len > DEV_PS2_GIF_LENGTH) |
if (relative_addr + len > DEV_PS2_GIF_LENGTH) |
238 |
/* |
/* |
239 |
* NetBSD and Linux: |
* NetBSD and Linux: |
240 |
* |
* |
241 |
* [ gif write to addr 0x0 (len=608): |
* [ gif write to addr 0x0 (len=608): |
242 |
* 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, |
* 04 00 00 00 00 00 00 10, 0e 00 00 00 00 00 00 00, |
243 |
* 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, |
* 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, 53 00 00 00 00 00 00 00, 20 80 00 00 00 00 00 08, 00 00 00 00 00 00 00 00, |
* 00 00 00 00 00 00 00 00, 51 00 00 00 00 00 00 00, |
245 |
* 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, |
* 08 00 00 00 16 00 00 00, 52 00 00 00 00 00 00 00, |
246 |
* 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, |
* 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 |
/* |
/* |
269 |
* d->bytes_per_pixel; |
* d->bytes_per_pixel; |
270 |
int addr = (24 + y*xsize) * 4; |
int addr = (24 + y*xsize) * 4; |
271 |
for (x=0; x<xsize; x++) { |
for (x=0; x<xsize; x++) { |
272 |
/* There are three bytes (r,g,b) at data[addr + 0] .. [addr + 2]. |
/* There are three bytes (r,g,b) at |
273 |
TODO: This should be translated to a direct update of the framebuffer. */ |
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, |
dev_fb_access(d->cpu, d->cpu->mem, |
278 |
fb_addr, data + addr, 3, MEM_WRITE, d->vfb_data); |
fb_addr, data + addr, 3, MEM_WRITE, |
279 |
|
d->vfb_data); |
280 |
|
|
281 |
fb_addr += d->bytes_per_pixel; |
fb_addr += d->bytes_per_pixel; |
282 |
addr += 4; |
addr += 4; |
283 |
} |
} |
284 |
} |
} |
285 |
} else if (data[0] == 0x04 && data[1] == 0x80 && len == 0x50) { /* blockcopy */ |
} 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; |
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); |
x_source = data[8*4 + 0] + ((data[8*4 + 1]) << 8); |
289 |
y_source = data[8*4 + 2] + ((data[8*4 + 3]) << 8); |
y_source = data[8*4 + 2] + ((data[8*4 + 3]) << 8); |
292 |
x_size = data[12*4 + 0] + ((data[12*4 + 1]) << 8); |
x_size = data[12*4 + 0] + ((data[12*4 + 1]) << 8); |
293 |
y_size = data[13*4 + 0] + ((data[13*4 + 1]) << 8); |
y_size = data[13*4 + 0] + ((data[13*4 + 1]) << 8); |
294 |
|
|
295 |
/* debug("[ gif: blockcopy (%i,%i) -> (%i,%i), size=(%i,%i) ]\n", |
/* debug("[ gif: blockcopy (%i,%i) -> (%i,%i), size=" |
296 |
x_source,y_source, x_dest,y_dest, x_size,y_size); */ |
"(%i,%i) ]\n", x_source,y_source, x_dest,y_dest, |
297 |
|
x_size,y_size); */ |
298 |
framebuffer_blockcopyfill(d->vfb_data, 0, 0,0,0, x_dest,y_dest, |
|
299 |
x_dest + x_size - 1, y_dest + y_size - 1, x_source, y_source); |
framebuffer_blockcopyfill(d->vfb_data, 0, 0,0,0, |
300 |
} else if (data[8] == 0x10 && data[9] == 0x55 && len == 48) { /* Linux "clear": */ |
x_dest, y_dest, x_dest + x_size - 1, y_dest + |
301 |
/* This is used by linux to clear the lowest 16 pixels of the framebuffer. */ |
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; |
int xbase, ybase, xend, yend; |
306 |
|
|
307 |
xbase = (data[8*4 + 0] + (data[8*4 + 1] << 8)) / 16; |
xbase = (data[8*4 + 0] + (data[8*4 + 1] << 8)) / 16; |
309 |
xend = (data[8*5 + 0] + (data[8*5 + 1] << 8)) / 16; |
xend = (data[8*5 + 0] + (data[8*5 + 1] << 8)) / 16; |
310 |
yend = (data[8*5 + 2] + (data[8*5 + 3] << 8)) / 16; |
yend = (data[8*5 + 2] + (data[8*5 + 3] << 8)) / 16; |
311 |
|
|
312 |
/* debug("[ gif: linux \"clear\" (%i,%i)-(%i,%i) ]\n", xbase,ybase, xend,yend); */ |
/* 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, xbase,ybase, xend-1,yend-1, 0,0); |
framebuffer_blockcopyfill(d->vfb_data, 1, 0,0,0, |
316 |
} else if (data[0] == 0x07 && data[1] == 0x80 && len == 128) { /* NetBSD "output cursor": */ |
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; |
int xbase, ybase, xend, yend, x, y; |
320 |
|
|
321 |
xbase = (data[20*4 + 0] + (data[20*4 + 1] << 8)) / 16; |
xbase = (data[20*4 + 0] + (data[20*4 + 1] << 8)) / 16; |
323 |
xend = (data[28*4 + 0] + (data[28*4 + 1] << 8)) / 16; |
xend = (data[28*4 + 0] + (data[28*4 + 1] << 8)) / 16; |
324 |
yend = (data[28*4 + 2] + (data[28*4 + 3] << 8)) / 16; |
yend = (data[28*4 + 2] + (data[28*4 + 3] << 8)) / 16; |
325 |
|
|
326 |
/* debug("[ gif: NETBSD cursor at (%i,%i)-(%i,%i) ]\n", xbase, ybase, xend, yend); */ |
/* debug("[ gif: NETBSD cursor at (%i,%i)-(%i,%i) ]\n", |
327 |
|
xbase, ybase, xend, yend); */ |
328 |
|
|
329 |
/* Output the cursor to framebuffer memory: */ |
/* Output the cursor to framebuffer memory: */ |
330 |
|
|
331 |
for (y=ybase; y<=yend; y++) |
for (y=ybase; y<=yend; y++) |
332 |
for (x=xbase; x<=xend; x++) { |
for (x=xbase; x<=xend; x++) { |
333 |
int fb_addr = (x + y * d->xsize) * d->bytes_per_pixel; |
int fb_addr = (x + y * d->xsize) * |
334 |
|
d->bytes_per_pixel; |
335 |
unsigned char pixels[3]; |
unsigned char pixels[3]; |
336 |
|
|
337 |
dev_fb_access(d->cpu, d->cpu->mem, |
dev_fb_access(d->cpu, d->cpu->mem, |
346 |
fb_addr, pixels, sizeof(pixels), |
fb_addr, pixels, sizeof(pixels), |
347 |
MEM_WRITE, d->vfb_data); |
MEM_WRITE, d->vfb_data); |
348 |
} |
} |
349 |
} else if (data[0] == 0x01 && data[1] == 0x00 && len == 80) { /* Linux "output cursor": */ |
} else if (data[0] == 0x01 && data[1] == 0x00 && len == 80) { |
350 |
|
/* Linux "output cursor": */ |
351 |
int xbase, ybase, xend, yend, x, y; |
int xbase, ybase, xend, yend, x, y; |
352 |
|
|
353 |
xbase = (data[7*8 + 0] + (data[7*8 + 1] << 8)) / 16; |
xbase = (data[7*8 + 0] + (data[7*8 + 1] << 8)) / 16; |
355 |
xend = (data[8*8 + 0] + (data[8*8 + 1] << 8)) / 16; |
xend = (data[8*8 + 0] + (data[8*8 + 1] << 8)) / 16; |
356 |
yend = (data[8*8 + 2] + (data[8*8 + 3] << 8)) / 16; |
yend = (data[8*8 + 2] + (data[8*8 + 3] << 8)) / 16; |
357 |
|
|
358 |
debug("[ gif: LINUX cursor at (%i,%i)-(%i,%i) ]\n", xbase, ybase, xend, yend); |
debug("[ gif: LINUX cursor at (%i,%i)-(%i,%i) ]\n", |
359 |
|
xbase, ybase, xend, yend); |
360 |
|
|
361 |
/* Output the cursor to framebuffer memory: */ |
/* Output the cursor to framebuffer memory: */ |
362 |
|
|
363 |
for (y=ybase; y<=yend; y++) |
for (y=ybase; y<=yend; y++) |
364 |
for (x=xbase; x<=xend; x++) { |
for (x=xbase; x<=xend; x++) { |
365 |
int fb_addr = (x + y * d->xsize) * d->bytes_per_pixel; |
int fb_addr = (x + y * d->xsize) * |
366 |
|
d->bytes_per_pixel; |
367 |
unsigned char pixels[3]; |
unsigned char pixels[3]; |
368 |
|
|
369 |
dev_fb_access(d->cpu, d->cpu->mem, |
dev_fb_access(d->cpu, d->cpu->mem, |
379 |
MEM_WRITE, d->vfb_data); |
MEM_WRITE, d->vfb_data); |
380 |
} |
} |
381 |
} else { /* Unknown command: */ |
} else { /* Unknown command: */ |
382 |
fatal("[ gif write to addr 0x%x (len=%i):", (int)relative_addr, len); |
fatal("[ gif write to addr 0x%x (len=%i):", |
383 |
|
(int)relative_addr, len); |
384 |
for (i=0; i<len; i++) |
for (i=0; i<len; i++) |
385 |
fatal(" %02x", data[i]); |
fatal(" %02x", data[i]); |
386 |
fatal(" ]\n"); |
fatal(" ]\n"); |
398 |
* |
* |
399 |
* Attached to separate memory by devinit_ps2_gs(). |
* Attached to separate memory by devinit_ps2_gs(). |
400 |
*/ |
*/ |
401 |
int devinit_ps2_gif(struct devinit *devinit) |
DEVINIT(ps2_gif) |
402 |
{ |
{ |
403 |
struct gif_data *d; |
struct gif_data *d; |
404 |
|
|
405 |
d = malloc(sizeof(struct gif_data)); |
CHECK_ALLOCATION(d = malloc(sizeof(struct gif_data))); |
|
if (d == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
406 |
memset(d, 0, sizeof(struct gif_data)); |
memset(d, 0, sizeof(struct gif_data)); |
407 |
|
|
408 |
d->transparent_text = 0; |
d->transparent_text = 0; |
412 |
|
|
413 |
d->vfb_data = dev_fb_init(devinit->machine, devinit->machine->memory, |
d->vfb_data = dev_fb_init(devinit->machine, devinit->machine->memory, |
414 |
PS2_FB_ADDR, VFB_PLAYSTATION2, |
PS2_FB_ADDR, VFB_PLAYSTATION2, |
415 |
d->xsize, d->ysize, d->xsize, d->ysize, 24, "Playstation 2", 0); |
d->xsize, d->ysize, d->xsize, d->ysize, 24, "Playstation 2"); |
416 |
if (d->vfb_data == NULL) { |
if (d->vfb_data == NULL) { |
417 |
fprintf(stderr, "could not initialize fb, out of memory\n"); |
fprintf(stderr, "could not initialize fb, out of memory\n"); |
418 |
exit(1); |
exit(1); |
419 |
} |
} |
420 |
|
|
421 |
#if 0 |
#if 0 |
422 |
test_triangle(d, 300,50, 255,0,0, 50,150, 0,255,0, 600,400, 0,0,255); |
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, 500,470, 125,255,125); |
test_triangle(d, 310,210, 128,32,0, 175,410, 0,32,0, |
424 |
test_triangle(d, 100,450, 255,255,0, 250,370, 0,255,255, 400,470, 255,0,255); |
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 |
#endif |
428 |
|
|
429 |
memory_device_register(devinit->machine->memory, devinit->name, |
memory_device_register(devinit->machine->memory, devinit->name, |
430 |
devinit->addr, DEV_PS2_GIF_LENGTH, dev_ps2_gif_access, d, |
devinit->addr, DEV_PS2_GIF_LENGTH, dev_ps2_gif_access, d, |
431 |
MEM_DEFAULT, NULL); |
DM_DEFAULT, NULL); |
432 |
|
|
433 |
return 1; |
return 1; |
434 |
} |
} |