Search
lxdream.org :: lxdream :: r310:00cd8897ad5e
lxdream 0.9.1
released Jun 29
Download Now
changeset310:00cd8897ad5e
parent309:e2750808d02c
child311:5be79c6b4367
authornkeynes
dateMon Jan 22 11:45:37 2007 +0000 (12 years ago)
Add methods to detwiddle directly out of vram64
src/pvr2/pvr2.h
src/pvr2/pvr2mem.c
1.1 --- a/src/pvr2/pvr2.h Sun Jan 21 11:29:17 2007 +0000
1.2 +++ b/src/pvr2/pvr2.h Mon Jan 22 11:45:37 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: pvr2.h,v 1.23 2007-01-21 11:28:43 nkeynes Exp $
1.6 + * $Id: pvr2.h,v 1.24 2007-01-22 11:45:37 nkeynes Exp $
1.7 *
1.8 * PVR2 (video chip) functions and macros.
1.9 *
1.10 @@ -129,6 +129,22 @@
1.11 void pvr2_vram64_read( char *dest, sh4addr_t src, uint32_t length );
1.12
1.13 /**
1.14 + * Read a twiddled image from interleaved memory address space (aka 64-bit address
1.15 + * space), writing the image to the destination buffer in detwiddled format.
1.16 + * Width and height must be powers of 2
1.17 + * This version reads 8-bit pixels.
1.18 + */
1.19 +void pvr2_vram64_read_twiddled_8( char *dest, sh4addr_t src, uint32_t width, uint32_t height );
1.20 +
1.21 +/**
1.22 + * Read a twiddled image from interleaved memory address space (aka 64-bit address
1.23 + * space), writing the image to the destination buffer in detwiddled format.
1.24 + * Width and height must be powers of 2, and src must be 16-bit aligned.
1.25 + * This version reads 16-bit pixels.
1.26 + */
1.27 +void pvr2_vram64_read_twiddled_16( char *dest, sh4addr_t src, uint32_t width, uint32_t height );
1.28 +
1.29 +/**
1.30 * Read an image from the interleaved memory address space (aka 64-bit address space)
1.31 * where the source and destination line sizes may differ. Note that both byte
1.32 * counts must be a multiple of 4, and the src address must be 32-bit aligned.
2.1 --- a/src/pvr2/pvr2mem.c Sun Jan 21 11:29:17 2007 +0000
2.2 +++ b/src/pvr2/pvr2mem.c Mon Jan 22 11:45:37 2007 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: pvr2mem.c,v 1.3 2007-01-21 11:29:17 nkeynes Exp $
2.6 + * $Id: pvr2mem.c,v 1.4 2007-01-22 11:45:37 nkeynes Exp $
2.7 *
2.8 * PVR2 (Video) VRAM handling routines (mainly for the 64-bit region)
2.9 *
2.10 @@ -162,8 +162,148 @@
2.11 banks[bank_flag]++;
2.12 bank_flag = !bank_flag;
2.13 }
2.14 + }
2.15 +}
2.16 +
2.17 +/**
2.18 + * @param dest Destination image buffer
2.19 + * @param banks Source data expressed as two bank pointers
2.20 + * @param offset Offset into banks[0] specifying where the next byte
2.21 + * to read is (0..3)
2.22 + * @param x1,y1 Destination coordinates
2.23 + * @param width Width of current destination block
2.24 + * @param image_width Total width of image (ie stride)
2.25 + */
2.26 +
2.27 +static void pvr2_vram64_detwiddle_8( uint8_t *dest, uint8_t *banks[2], int offset,
2.28 + int x1, int y1, int width, int image_width )
2.29 +{
2.30 + if( width == 2 ) {
2.31 + dest[y1*image_width + x1] = *banks[0]++;
2.32 + dest[(y1+1)*image_width + x1] = *banks[offset<3?0:1]++;
2.33 + dest[y1*image_width + x1 + 1] = *banks[offset<2?0:1]++;
2.34 + dest[(y1+1)*image_width + x1 + 1] = *banks[offset==0?0:1]++;
2.35 + uint8_t *tmp = banks[0]; /* swap banks */
2.36 + banks[0] = banks[1];
2.37 + banks[1] = tmp;
2.38 + } else {
2.39 + int subdivide = width >> 1;
2.40 + pvr2_vram64_detwiddle_8( dest, banks, offset, x1, y1, subdivide, image_width );
2.41 + pvr2_vram64_detwiddle_8( dest, banks, offset, x1, y1+subdivide, subdivide, image_width );
2.42 + pvr2_vram64_detwiddle_8( dest, banks, offset, x1+subdivide, y1, subdivide, image_width );
2.43 + pvr2_vram64_detwiddle_8( dest, banks, offset, x1+subdivide, y1+subdivide, subdivide, image_width );
2.44 }
2.45 -
2.46 +}
2.47 +
2.48 +/**
2.49 + * @param dest Destination image buffer
2.50 + * @param banks Source data expressed as two bank pointers
2.51 + * @param offset Offset into banks[0] specifying where the next word
2.52 + * to read is (0 or 1)
2.53 + * @param x1,y1 Destination coordinates
2.54 + * @param width Width of current destination block
2.55 + * @param image_width Total width of image (ie stride)
2.56 + */
2.57 +
2.58 +static void pvr2_vram64_detwiddle_16( uint16_t *dest, uint16_t *banks[2], int offset,
2.59 + int x1, int y1, int width, int image_width )
2.60 +{
2.61 + if( width == 2 ) {
2.62 + dest[y1*image_width + x1] = *banks[0]++;
2.63 + dest[(y1+1)*image_width + x1] = *banks[offset]++;
2.64 + dest[y1*image_width + x1 + 1] = *banks[1]++;
2.65 + dest[(y1+1)*image_width + x1 + 1] = *banks[offset^1]++;
2.66 + } else {
2.67 + int subdivide = width >> 1;
2.68 + pvr2_vram64_detwiddle_16( dest, banks, offset, x1, y1, subdivide, image_width );
2.69 + pvr2_vram64_detwiddle_16( dest, banks, offset, x1, y1+subdivide, subdivide, image_width );
2.70 + pvr2_vram64_detwiddle_16( dest, banks, offset, x1+subdivide, y1, subdivide, image_width );
2.71 + pvr2_vram64_detwiddle_16( dest, banks, offset, x1+subdivide, y1+subdivide, subdivide, image_width );
2.72 + }
2.73 +}
2.74 +
2.75 +/**
2.76 + * Read an image from 64-bit vram stored as twiddled 8-bit pixels. The
2.77 + * image is written out to the destination in detwiddled form.
2.78 + * @param dest destination buffer, which must be at least width*height in length
2.79 + * @param srcaddr source address in vram
2.80 + * @param width image width (must be a power of 2)
2.81 + * @param height image height (must be a power of 2)
2.82 + */
2.83 +void pvr2_vram64_read_twiddled_8( char *dest, sh4addr_t srcaddr, uint32_t width, uint32_t height )
2.84 +{
2.85 + int offset_flag = (srcaddr & 0x07);
2.86 + uint8_t *banks[2];
2.87 + uint8_t *wdest = (uint8_t*)dest;
2.88 + int i,j;
2.89 +
2.90 + srcaddr = srcaddr & 0x7FFFF8;
2.91 +
2.92 + banks[0] = (uint8_t *)(video_base + (srcaddr>>1));
2.93 + banks[1] = banks[0] + 0x400000;
2.94 + if( offset_flag & 0x04 ) { // If source is not 64-bit aligned, swap the banks
2.95 + uint8_t *tmp = banks[0];
2.96 + banks[0] = banks[1];
2.97 + banks[1] = tmp + 4;
2.98 + offset_flag &= 0x03;
2.99 + }
2.100 + banks[0] += offset_flag;
2.101 +
2.102 + if( width > height ) {
2.103 + for( i=0; i<width; i+=height ) {
2.104 + pvr2_vram64_detwiddle_8( wdest, banks, offset_flag, i, 0, height, width );
2.105 + }
2.106 + } else if( height > width ) {
2.107 + for( i=0; i<height; i+=width ) {
2.108 + pvr2_vram64_detwiddle_8( wdest, banks, offset_flag, 0, i, width, width );
2.109 + }
2.110 + } else if( width == 1 ) {
2.111 + *wdest = *banks[0];
2.112 + } else {
2.113 + pvr2_vram64_detwiddle_8( wdest, banks, offset_flag, 0, 0, width, width );
2.114 + }
2.115 +}
2.116 +
2.117 +/**
2.118 + * Read an image from 64-bit vram stored as twiddled 16-bit pixels. The
2.119 + * image is written out to the destination in detwiddled form.
2.120 + * @param dest destination buffer, which must be at least width*height*2 in length
2.121 + * @param srcaddr source address in vram (must be 16-bit aligned)
2.122 + * @param width image width (must be a power of 2)
2.123 + * @param height image height (must be a power of 2)
2.124 + */
2.125 +void pvr2_vram64_read_twiddled_16( char *dest, sh4addr_t srcaddr, uint32_t width, uint32_t height ) {
2.126 + int offset_flag = (srcaddr & 0x06) >> 1;
2.127 + uint16_t *banks[2];
2.128 + uint16_t *wdest = (uint16_t*)dest;
2.129 + int i,j;
2.130 +
2.131 + srcaddr = srcaddr & 0x7FFFF8;
2.132 +
2.133 + banks[0] = (uint16_t *)(video_base + (srcaddr>>1));
2.134 + banks[1] = banks[0] + 0x200000;
2.135 + if( offset_flag & 0x02 ) { // If source is not 64-bit aligned, swap the banks
2.136 + uint16_t *tmp = banks[0];
2.137 + banks[0] = banks[1];
2.138 + banks[1] = tmp + 2;
2.139 + offset_flag &= 0x01;
2.140 + }
2.141 + banks[0] += offset_flag;
2.142 +
2.143 +
2.144 + if( width > height ) {
2.145 + for( i=0; i<width; i+=height ) {
2.146 + pvr2_vram64_detwiddle_16( wdest, banks, offset_flag, i, 0, height, width );
2.147 + }
2.148 + } else if( height > width ) {
2.149 + for( i=0; i<height; i+=width ) {
2.150 + pvr2_vram64_detwiddle_16( wdest, banks, offset_flag, 0, i, width, width );
2.151 + }
2.152 + } else if( width == 1 ) {
2.153 + *wdest = *banks[0];
2.154 + } else {
2.155 + pvr2_vram64_detwiddle_16( wdest, banks, offset_flag, 0, 0, width, width );
2.156 + }
2.157 }
2.158
2.159 void pvr2_vram_write_invert( sh4addr_t destaddr, char *src, uint32_t length, uint32_t line_length )
.