Search
lxdream.org :: lxdream/src/pvr2/pvr2mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/pvr2mem.c
changeset 310:00cd8897ad5e
prev309:e2750808d02c
next315:2d8ba198d62c
author nkeynes
date Mon Jan 22 11:45:37 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add methods to detwiddle directly out of vram64
file annotate diff log raw
1.1 --- a/src/pvr2/pvr2mem.c Sun Jan 21 11:29:17 2007 +0000
1.2 +++ b/src/pvr2/pvr2mem.c Mon Jan 22 11:45:37 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: pvr2mem.c,v 1.3 2007-01-21 11:29:17 nkeynes Exp $
1.6 + * $Id: pvr2mem.c,v 1.4 2007-01-22 11:45:37 nkeynes Exp $
1.7 *
1.8 * PVR2 (Video) VRAM handling routines (mainly for the 64-bit region)
1.9 *
1.10 @@ -162,8 +162,148 @@
1.11 banks[bank_flag]++;
1.12 bank_flag = !bank_flag;
1.13 }
1.14 + }
1.15 +}
1.16 +
1.17 +/**
1.18 + * @param dest Destination image buffer
1.19 + * @param banks Source data expressed as two bank pointers
1.20 + * @param offset Offset into banks[0] specifying where the next byte
1.21 + * to read is (0..3)
1.22 + * @param x1,y1 Destination coordinates
1.23 + * @param width Width of current destination block
1.24 + * @param image_width Total width of image (ie stride)
1.25 + */
1.26 +
1.27 +static void pvr2_vram64_detwiddle_8( uint8_t *dest, uint8_t *banks[2], int offset,
1.28 + int x1, int y1, int width, int image_width )
1.29 +{
1.30 + if( width == 2 ) {
1.31 + dest[y1*image_width + x1] = *banks[0]++;
1.32 + dest[(y1+1)*image_width + x1] = *banks[offset<3?0:1]++;
1.33 + dest[y1*image_width + x1 + 1] = *banks[offset<2?0:1]++;
1.34 + dest[(y1+1)*image_width + x1 + 1] = *banks[offset==0?0:1]++;
1.35 + uint8_t *tmp = banks[0]; /* swap banks */
1.36 + banks[0] = banks[1];
1.37 + banks[1] = tmp;
1.38 + } else {
1.39 + int subdivide = width >> 1;
1.40 + pvr2_vram64_detwiddle_8( dest, banks, offset, x1, y1, subdivide, image_width );
1.41 + pvr2_vram64_detwiddle_8( dest, banks, offset, x1, y1+subdivide, subdivide, image_width );
1.42 + pvr2_vram64_detwiddle_8( dest, banks, offset, x1+subdivide, y1, subdivide, image_width );
1.43 + pvr2_vram64_detwiddle_8( dest, banks, offset, x1+subdivide, y1+subdivide, subdivide, image_width );
1.44 }
1.45 -
1.46 +}
1.47 +
1.48 +/**
1.49 + * @param dest Destination image buffer
1.50 + * @param banks Source data expressed as two bank pointers
1.51 + * @param offset Offset into banks[0] specifying where the next word
1.52 + * to read is (0 or 1)
1.53 + * @param x1,y1 Destination coordinates
1.54 + * @param width Width of current destination block
1.55 + * @param image_width Total width of image (ie stride)
1.56 + */
1.57 +
1.58 +static void pvr2_vram64_detwiddle_16( uint16_t *dest, uint16_t *banks[2], int offset,
1.59 + int x1, int y1, int width, int image_width )
1.60 +{
1.61 + if( width == 2 ) {
1.62 + dest[y1*image_width + x1] = *banks[0]++;
1.63 + dest[(y1+1)*image_width + x1] = *banks[offset]++;
1.64 + dest[y1*image_width + x1 + 1] = *banks[1]++;
1.65 + dest[(y1+1)*image_width + x1 + 1] = *banks[offset^1]++;
1.66 + } else {
1.67 + int subdivide = width >> 1;
1.68 + pvr2_vram64_detwiddle_16( dest, banks, offset, x1, y1, subdivide, image_width );
1.69 + pvr2_vram64_detwiddle_16( dest, banks, offset, x1, y1+subdivide, subdivide, image_width );
1.70 + pvr2_vram64_detwiddle_16( dest, banks, offset, x1+subdivide, y1, subdivide, image_width );
1.71 + pvr2_vram64_detwiddle_16( dest, banks, offset, x1+subdivide, y1+subdivide, subdivide, image_width );
1.72 + }
1.73 +}
1.74 +
1.75 +/**
1.76 + * Read an image from 64-bit vram stored as twiddled 8-bit pixels. The
1.77 + * image is written out to the destination in detwiddled form.
1.78 + * @param dest destination buffer, which must be at least width*height in length
1.79 + * @param srcaddr source address in vram
1.80 + * @param width image width (must be a power of 2)
1.81 + * @param height image height (must be a power of 2)
1.82 + */
1.83 +void pvr2_vram64_read_twiddled_8( char *dest, sh4addr_t srcaddr, uint32_t width, uint32_t height )
1.84 +{
1.85 + int offset_flag = (srcaddr & 0x07);
1.86 + uint8_t *banks[2];
1.87 + uint8_t *wdest = (uint8_t*)dest;
1.88 + int i,j;
1.89 +
1.90 + srcaddr = srcaddr & 0x7FFFF8;
1.91 +
1.92 + banks[0] = (uint8_t *)(video_base + (srcaddr>>1));
1.93 + banks[1] = banks[0] + 0x400000;
1.94 + if( offset_flag & 0x04 ) { // If source is not 64-bit aligned, swap the banks
1.95 + uint8_t *tmp = banks[0];
1.96 + banks[0] = banks[1];
1.97 + banks[1] = tmp + 4;
1.98 + offset_flag &= 0x03;
1.99 + }
1.100 + banks[0] += offset_flag;
1.101 +
1.102 + if( width > height ) {
1.103 + for( i=0; i<width; i+=height ) {
1.104 + pvr2_vram64_detwiddle_8( wdest, banks, offset_flag, i, 0, height, width );
1.105 + }
1.106 + } else if( height > width ) {
1.107 + for( i=0; i<height; i+=width ) {
1.108 + pvr2_vram64_detwiddle_8( wdest, banks, offset_flag, 0, i, width, width );
1.109 + }
1.110 + } else if( width == 1 ) {
1.111 + *wdest = *banks[0];
1.112 + } else {
1.113 + pvr2_vram64_detwiddle_8( wdest, banks, offset_flag, 0, 0, width, width );
1.114 + }
1.115 +}
1.116 +
1.117 +/**
1.118 + * Read an image from 64-bit vram stored as twiddled 16-bit pixels. The
1.119 + * image is written out to the destination in detwiddled form.
1.120 + * @param dest destination buffer, which must be at least width*height*2 in length
1.121 + * @param srcaddr source address in vram (must be 16-bit aligned)
1.122 + * @param width image width (must be a power of 2)
1.123 + * @param height image height (must be a power of 2)
1.124 + */
1.125 +void pvr2_vram64_read_twiddled_16( char *dest, sh4addr_t srcaddr, uint32_t width, uint32_t height ) {
1.126 + int offset_flag = (srcaddr & 0x06) >> 1;
1.127 + uint16_t *banks[2];
1.128 + uint16_t *wdest = (uint16_t*)dest;
1.129 + int i,j;
1.130 +
1.131 + srcaddr = srcaddr & 0x7FFFF8;
1.132 +
1.133 + banks[0] = (uint16_t *)(video_base + (srcaddr>>1));
1.134 + banks[1] = banks[0] + 0x200000;
1.135 + if( offset_flag & 0x02 ) { // If source is not 64-bit aligned, swap the banks
1.136 + uint16_t *tmp = banks[0];
1.137 + banks[0] = banks[1];
1.138 + banks[1] = tmp + 2;
1.139 + offset_flag &= 0x01;
1.140 + }
1.141 + banks[0] += offset_flag;
1.142 +
1.143 +
1.144 + if( width > height ) {
1.145 + for( i=0; i<width; i+=height ) {
1.146 + pvr2_vram64_detwiddle_16( wdest, banks, offset_flag, i, 0, height, width );
1.147 + }
1.148 + } else if( height > width ) {
1.149 + for( i=0; i<height; i+=width ) {
1.150 + pvr2_vram64_detwiddle_16( wdest, banks, offset_flag, 0, i, width, width );
1.151 + }
1.152 + } else if( width == 1 ) {
1.153 + *wdest = *banks[0];
1.154 + } else {
1.155 + pvr2_vram64_detwiddle_16( wdest, banks, offset_flag, 0, 0, width, width );
1.156 + }
1.157 }
1.158
1.159 void pvr2_vram_write_invert( sh4addr_t destaddr, char *src, uint32_t length, uint32_t line_length )
.