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

Diff of /trunk/src/devices/dev_ps2_gif.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 21 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  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:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_ps2_gif.c,v 1.30 2005/11/13 00:14:09 debug Exp $   *  $Id: dev_ps2_gif.c,v 1.33 2006/02/09 20:02:59 debug Exp $
29   *     *  
30   *  Playstation 2 "gif" graphics device.   *  Playstation 2 "gif" graphics device.
31   *   *
# Line 207  void test_triangle(struct gif_data *d, Line 207  void test_triangle(struct gif_data *d,
207  /*  /*
208   *  dev_ps2_gif_access():   *  dev_ps2_gif_access():
209   */   */
210  int dev_ps2_gif_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(ps2_gif)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
211  {  {
212          int i;          unsigned int i;
213          struct gif_data *d = extra;          struct gif_data *d = extra;
214    
215          if (relative_addr + len > DEV_PS2_GIF_LENGTH)          if (relative_addr + len > DEV_PS2_GIF_LENGTH)
# Line 241  int dev_ps2_gif_access(struct cpu *cpu, Line 239  int dev_ps2_gif_access(struct cpu *cpu,
239                          /*                          /*
240                           *  NetBSD and Linux:                           *  NetBSD and Linux:
241                           *                           *
242                           *      [ gif write to addr 0x0 (len=608):                           *  [ gif write to addr 0x0 (len=608):
243                           *       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,
244                           *       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,
245                           *       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,
246                           *       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,
247                           *       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,
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                          /*                          /*
# Line 267  int dev_ps2_gif_access(struct cpu *cpu, Line 270  int dev_ps2_gif_access(struct cpu *cpu,
270                                      * d->bytes_per_pixel;                                      * d->bytes_per_pixel;
271                                  int addr = (24 + y*xsize) * 4;                                  int addr = (24 + y*xsize) * 4;
272                                  for (x=0; x<xsize; x++) {                                  for (x=0; x<xsize; x++) {
273                                          /*  There are three bytes (r,g,b) at data[addr + 0] .. [addr + 2].                                          /*  There are three bytes (r,g,b) at
274                                              TODO: This should be translated to a direct update of the framebuffer.  */                                              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,                                          dev_fb_access(d->cpu, d->cpu->mem,
279                                              fb_addr, data + addr, 3, MEM_WRITE, d->vfb_data);                                              fb_addr, data + addr, 3, MEM_WRITE,
280                                                d->vfb_data);
281    
282                                          fb_addr += d->bytes_per_pixel;                                          fb_addr += d->bytes_per_pixel;
283                                          addr += 4;                                          addr += 4;
284                                  }                                  }
285                          }                          }
286                  } else if (data[0] == 0x04 && data[1] == 0x80 && len == 0x50) {                 /*  blockcopy  */                  } 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;                          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);                          x_source = data[8*4 + 0] + ((data[8*4 + 1]) << 8);
290                          y_source = data[8*4 + 2] + ((data[8*4 + 3]) << 8);                          y_source = data[8*4 + 2] + ((data[8*4 + 3]) << 8);
# Line 286  int dev_ps2_gif_access(struct cpu *cpu, Line 293  int dev_ps2_gif_access(struct cpu *cpu,
293                          x_size   = data[12*4 + 0] + ((data[12*4 + 1]) << 8);                          x_size   = data[12*4 + 0] + ((data[12*4 + 1]) << 8);
294                          y_size   = data[13*4 + 0] + ((data[13*4 + 1]) << 8);                          y_size   = data[13*4 + 0] + ((data[13*4 + 1]) << 8);
295    
296                          /*  debug("[ gif: blockcopy (%i,%i) -> (%i,%i), size=(%i,%i) ]\n",                          /*  debug("[ gif: blockcopy (%i,%i) -> (%i,%i), size="
297                              x_source,y_source, x_dest,y_dest, x_size,y_size);  */                              "(%i,%i) ]\n", x_source,y_source, x_dest,y_dest,
298                                x_size,y_size);  */
299                          framebuffer_blockcopyfill(d->vfb_data, 0, 0,0,0, x_dest,y_dest,  
300                              x_dest + x_size - 1, y_dest + y_size - 1, x_source, y_source);                          framebuffer_blockcopyfill(d->vfb_data, 0, 0,0,0,
301                  } else if (data[8] == 0x10 && data[9] == 0x55 && len == 48) {                   /*  Linux "clear":  */                              x_dest, y_dest, x_dest + x_size - 1, y_dest +
302                          /*  This is used by linux to clear the lowest 16 pixels of the framebuffer.  */                              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;                          int xbase, ybase, xend, yend;
307    
308                          xbase = (data[8*4 + 0] + (data[8*4 + 1] << 8)) / 16;                          xbase = (data[8*4 + 0] + (data[8*4 + 1] << 8)) / 16;
# Line 300  int dev_ps2_gif_access(struct cpu *cpu, Line 310  int dev_ps2_gif_access(struct cpu *cpu,
310                          xend  = (data[8*5 + 0] + (data[8*5 + 1] << 8)) / 16;                          xend  = (data[8*5 + 0] + (data[8*5 + 1] << 8)) / 16;
311                          yend  = (data[8*5 + 2] + (data[8*5 + 3] << 8)) / 16;                          yend  = (data[8*5 + 2] + (data[8*5 + 3] << 8)) / 16;
312    
313                          /*  debug("[ gif: linux \"clear\" (%i,%i)-(%i,%i) ]\n", xbase,ybase, xend,yend);  */                          /*  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, xbase,ybase, xend-1,yend-1, 0,0);                          framebuffer_blockcopyfill(d->vfb_data, 1, 0,0,0,
317                  } else if (data[0] == 0x07 && data[1] == 0x80 && len == 128) {                  /*  NetBSD "output cursor":  */                              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;                          int xbase, ybase, xend, yend, x, y;
321    
322                          xbase = (data[20*4 + 0] + (data[20*4 + 1] << 8)) / 16;                          xbase = (data[20*4 + 0] + (data[20*4 + 1] << 8)) / 16;
# Line 311  int dev_ps2_gif_access(struct cpu *cpu, Line 324  int dev_ps2_gif_access(struct cpu *cpu,
324                          xend  = (data[28*4 + 0] + (data[28*4 + 1] << 8)) / 16;                          xend  = (data[28*4 + 0] + (data[28*4 + 1] << 8)) / 16;
325                          yend  = (data[28*4 + 2] + (data[28*4 + 3] << 8)) / 16;                          yend  = (data[28*4 + 2] + (data[28*4 + 3] << 8)) / 16;
326    
327                          /*  debug("[ gif: NETBSD cursor at (%i,%i)-(%i,%i) ]\n", xbase, ybase, xend, yend);  */                          /*  debug("[ gif: NETBSD cursor at (%i,%i)-(%i,%i) ]\n",
328                                xbase, ybase, xend, yend);  */
329    
330                          /*  Output the cursor to framebuffer memory:  */                          /*  Output the cursor to framebuffer memory:  */
331    
332                          for (y=ybase; y<=yend; y++)                          for (y=ybase; y<=yend; y++)
333                                  for (x=xbase; x<=xend; x++) {                                  for (x=xbase; x<=xend; x++) {
334                                          int fb_addr = (x + y * d->xsize) * d->bytes_per_pixel;                                          int fb_addr = (x + y * d->xsize) *
335                                                d->bytes_per_pixel;
336                                          unsigned char pixels[3];                                          unsigned char pixels[3];
337    
338                                          dev_fb_access(d->cpu, d->cpu->mem,                                          dev_fb_access(d->cpu, d->cpu->mem,
# Line 332  int dev_ps2_gif_access(struct cpu *cpu, Line 347  int dev_ps2_gif_access(struct cpu *cpu,
347                                              fb_addr, pixels, sizeof(pixels),                                              fb_addr, pixels, sizeof(pixels),
348                                              MEM_WRITE, d->vfb_data);                                              MEM_WRITE, d->vfb_data);
349                                  }                                  }
350                  } else if (data[0] == 0x01 && data[1] == 0x00 && len == 80) {                   /*  Linux "output cursor":  */                  } else if (data[0] == 0x01 && data[1] == 0x00 && len == 80) {
351                            /*  Linux "output cursor":  */
352                          int xbase, ybase, xend, yend, x, y;                          int xbase, ybase, xend, yend, x, y;
353    
354                          xbase = (data[7*8 + 0] + (data[7*8 + 1] << 8)) / 16;                          xbase = (data[7*8 + 0] + (data[7*8 + 1] << 8)) / 16;
# Line 340  int dev_ps2_gif_access(struct cpu *cpu, Line 356  int dev_ps2_gif_access(struct cpu *cpu,
356                          xend  = (data[8*8 + 0] + (data[8*8 + 1] << 8)) / 16;                          xend  = (data[8*8 + 0] + (data[8*8 + 1] << 8)) / 16;
357                          yend  = (data[8*8 + 2] + (data[8*8 + 3] << 8)) / 16;                          yend  = (data[8*8 + 2] + (data[8*8 + 3] << 8)) / 16;
358    
359                          debug("[ gif: LINUX cursor at (%i,%i)-(%i,%i) ]\n", xbase, ybase, xend, yend);                          debug("[ gif: LINUX cursor at (%i,%i)-(%i,%i) ]\n",
360                                xbase, ybase, xend, yend);
361    
362                          /*  Output the cursor to framebuffer memory:  */                          /*  Output the cursor to framebuffer memory:  */
363    
364                          for (y=ybase; y<=yend; y++)                          for (y=ybase; y<=yend; y++)
365                                  for (x=xbase; x<=xend; x++) {                                  for (x=xbase; x<=xend; x++) {
366                                          int fb_addr = (x + y * d->xsize) * d->bytes_per_pixel;                                          int fb_addr = (x + y * d->xsize) *
367                                                d->bytes_per_pixel;
368                                          unsigned char pixels[3];                                          unsigned char pixels[3];
369    
370                                          dev_fb_access(d->cpu, d->cpu->mem,                                          dev_fb_access(d->cpu, d->cpu->mem,
# Line 362  int dev_ps2_gif_access(struct cpu *cpu, Line 380  int dev_ps2_gif_access(struct cpu *cpu,
380                                              MEM_WRITE, d->vfb_data);                                              MEM_WRITE, d->vfb_data);
381                                  }                                  }
382                  } else {                /*  Unknown command:  */                  } else {                /*  Unknown command:  */
383                          fatal("[ gif write to addr 0x%x (len=%i):", (int)relative_addr, len);                          fatal("[ gif write to addr 0x%x (len=%i):",
384                                (int)relative_addr, len);
385                          for (i=0; i<len; i++)                          for (i=0; i<len; i++)
386                                  fatal(" %02x", data[i]);                                  fatal(" %02x", data[i]);
387                          fatal(" ]\n");                          fatal(" ]\n");
# Line 380  int dev_ps2_gif_access(struct cpu *cpu, Line 399  int dev_ps2_gif_access(struct cpu *cpu,
399   *   *
400   *  Attached to separate memory by devinit_ps2_gs().   *  Attached to separate memory by devinit_ps2_gs().
401   */   */
402  int devinit_ps2_gif(struct devinit *devinit)  DEVINIT(ps2_gif)
403  {  {
404          struct gif_data *d;          struct gif_data *d;
405    
# Line 405  int devinit_ps2_gif(struct devinit *devi Line 424  int devinit_ps2_gif(struct devinit *devi
424          }          }
425    
426  #if 0  #if 0
427          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);
428          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,
429          test_triangle(d,  100,450, 255,255,0,  250,370, 0,255,255,  400,470, 255,0,255);              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  #endif
433    
434          memory_device_register(devinit->machine->memory, devinit->name,          memory_device_register(devinit->machine->memory, devinit->name,

Legend:
Removed from v.21  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26