From bf6e0cd9d1b9b45d1ae0c2e48ac666aecc2fcf4a Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Sun, 5 Apr 2009 12:13:58 +0000 Subject: ZXBox: Clean up display init. Saves ~1KB on colour targets, and 4KB (coldfire)... >6KB (SH1) for greyscale targets, due to no longer using floating point math. * Name the 2bpp display routines correctly. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20621 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/zxbox/SOURCES | 7 ++- apps/plugins/zxbox/zxvid_16bpp.c | 57 ++++++++--------- apps/plugins/zxbox/zxvid_2bpp.c | 117 +++++++++++++++++++++++++++++++++++ apps/plugins/zxbox/zxvid_4bpp.c | 130 --------------------------------------- apps/plugins/zxbox/zxvid_grey.c | 40 +++++------- 5 files changed, 164 insertions(+), 187 deletions(-) create mode 100644 apps/plugins/zxbox/zxvid_2bpp.c delete mode 100644 apps/plugins/zxbox/zxvid_4bpp.c diff --git a/apps/plugins/zxbox/SOURCES b/apps/plugins/zxbox/SOURCES index ae0307135f..489a3c0613 100644 --- a/apps/plugins/zxbox/SOURCES +++ b/apps/plugins/zxbox/SOURCES @@ -27,6 +27,11 @@ z80_step.c z80optab.c zxbox.c zxbox_keyb.c +#ifdef HAVE_LCD_COLOR zxvid_16bpp.c -zxvid_4bpp.c +#else +#if LCD_DEPTH == 2 +zxvid_2bpp.c +#endif zxvid_grey.c +#endif diff --git a/apps/plugins/zxbox/zxvid_16bpp.c b/apps/plugins/zxbox/zxvid_16bpp.c index 336e1c2447..4a05c69f97 100644 --- a/apps/plugins/zxbox/zxvid_16bpp.c +++ b/apps/plugins/zxbox/zxvid_16bpp.c @@ -1,48 +1,46 @@ #include "zxvid_com.h" -#if LCD_DEPTH > 4 /* screen routines for color targets */ -/* -use for slightly different colors -#define N0 0x04 -#define N1 0x34 - -#define B0 0x08 -#define B1 0x3F -*/ - #define N0 0x00 #define N1 0xC0 - #define B0 0x00 #define B1 0xFF -struct rgb norm_colors[COLORNUM]={ - {0,0,0},{N0,N0,N1},{N1,N0,N0},{N1,N0,N1}, - {N0,N1,N0},{N0,N1,N1},{N1,N1,N0},{N1,N1,N1}, - - {0,0,0},{B0,B0,B1},{B1,B0,B0},{B1,B0,B1}, - {B0,B1,B0},{B0,B1,B1},{B1,B1,B0},{B1,B1,B1} +#define IN0 (0xFF-N0) +#define IN1 (0xFF-N1) +#define IB0 (0xFF-B0) +#define IB1 (0xFF-B1) + +static const fb_data _16bpp_colors[32] = { + /* normal */ + LCD_RGBPACK(N0, N0, N0), LCD_RGBPACK(N0, N0, N1), + LCD_RGBPACK(N1, N0, N0), LCD_RGBPACK(N1, N0, N1), + LCD_RGBPACK(N0, N1, N0), LCD_RGBPACK(N0, N1, N1), + LCD_RGBPACK(N1, N1, N0), LCD_RGBPACK(N1, N1, N1), + LCD_RGBPACK(B0, B0, B0), LCD_RGBPACK(B0, B0, B1), + LCD_RGBPACK(B1, B0, B0), LCD_RGBPACK(B1, B0, B1), + LCD_RGBPACK(B0, B1, B0), LCD_RGBPACK(B0, B1, B1), + LCD_RGBPACK(B1, B1, B0), LCD_RGBPACK(B1, B1, B1), + /* inverted */ + LCD_RGBPACK(IN0, IN0, IN0), LCD_RGBPACK(IN0, IN0, IN1), + LCD_RGBPACK(IN1, IN0, IN0), LCD_RGBPACK(IN1, IN0, IN1), + LCD_RGBPACK(IN0, IN1, IN0), LCD_RGBPACK(IN0, IN1, IN1), + LCD_RGBPACK(IN1, IN1, IN0), LCD_RGBPACK(IN1, IN1, IN1), + LCD_RGBPACK(IB0, IB0, IB0), LCD_RGBPACK(IB0, IB0, IB1), + LCD_RGBPACK(IB1, IB0, IB0), LCD_RGBPACK(IB1, IB0, IB1), + LCD_RGBPACK(IB0, IB1, IB0), LCD_RGBPACK(IB0, IB1, IB1), + LCD_RGBPACK(IB1, IB1, IB0), LCD_RGBPACK(IB1, IB1, IB1), }; - -/* since emulator uses array of bytes for screen representation - * short 16b colors won't fit there */ -short _16bpp_colors[16] IBSS_ATTR; - void init_spect_scr(void) { int i; + int offset = settings.invert_colors ? 16 : 0; for(i = 0; i < 16; i++) - sp_colors[i] = i; - for(i = 0; i < 16; i++) - _16bpp_colors[i] = LCD_RGBPACK(norm_colors[i].r,norm_colors[i].g,norm_colors[i].b); - if ( settings.invert_colors ){ - for ( i = 0 ; i < 16 ; i++ ) - _16bpp_colors[i] = 0xFFFFFF - _16bpp_colors[i]; - } + sp_colors[i] = i + offset; + sp_image = (char *) &image_array; spscr_init_mask_color(); spscr_init_line_pointers(HEIGHT); @@ -97,4 +95,3 @@ void update_screen(void) } -#endif /* HAVE_LCD_COLOR */ diff --git a/apps/plugins/zxbox/zxvid_2bpp.c b/apps/plugins/zxbox/zxvid_2bpp.c new file mode 100644 index 0000000000..0a4519e0ac --- /dev/null +++ b/apps/plugins/zxbox/zxvid_2bpp.c @@ -0,0 +1,117 @@ +#include "zxvid_com.h" + +#ifndef USE_GREY +/* screen routines for greyscale targets not using greyscale lib */ + +#if LCD_PIXELFORMAT == HORIZONTAL_PACKING +#define FB_WIDTH ((LCD_WIDTH+3)/4) +fb_data pixmask[4] ICONST_ATTR = { + 0xC0, 0x30, 0x0C, 0x03 +}; +#elif LCD_PIXELFORMAT == VERTICAL_PACKING +fb_data pixmask[4] ICONST_ATTR = { + 0x03, 0x0C, 0x30, 0xC0 +}; +#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED +fb_data pixmask[8] ICONST_ATTR = { + 0x0101, 0x0202, 0x0404, 0x0808, 0x1010, 0x2020, 0x4040, 0x8080 +}; +fb_data pixval[4] ICONST_ATTR = { + 0x0000, 0x0001, 0x0100, 0x0101 +}; +#endif + +static const unsigned char graylevels[16] = { + 0, 1, 1, 1, 2, 2, 3, 3, + 0, 1, 1, 1, 2, 2, 3, 3 +}; + +void init_spect_scr(void) +{ + int i; + unsigned mask = settings.invert_colors ? 0 : 3; + + for(i = 0; i < 16; i++) + sp_colors[i] = graylevels[i] ^ mask; + + sp_image = (char *) &image_array; + spscr_init_mask_color(); + spscr_init_line_pointers(HEIGHT); + +} +void update_screen(void) +{ + char str[80]; + + fb_data *frameb; + int y=0; + int x=0; + unsigned char* image; + int srcx, srcy=0; /* x / y coordinates in source image */ + image = sp_image + ( (Y_OFF)*(WIDTH) ) + X_OFF; + unsigned mask; +#if LCD_PIXELFORMAT == HORIZONTAL_PACKING + for(y = 0; y < LCD_HEIGHT; y++) + { + frameb = rb->lcd_framebuffer + (y) * FB_WIDTH; + srcx = 0; /* reset our x counter before each row... */ + for(x = 0; x < LCD_WIDTH; x++) + { + mask = ~pixmask[x & 3]; + frameb[x >> 2] = (frameb[x >> 2] & mask) | ((image[(srcx>>16)]&0x3) << ((3-(x & 3 )) * 2 )); + srcx += X_STEP; /* move through source image */ + } + srcy += Y_STEP; /* move through the source image... */ + image += (srcy>>16)*WIDTH; /* and possibly to the next row. */ + srcy &= 0xffff; /* set up the y-coordinate between 0 and 1 */ + } +#elif LCD_PIXELFORMAT == VERTICAL_PACKING + int shift; + for(y = 0; y < LCD_HEIGHT; y++) + { + frameb = rb->lcd_framebuffer + (y/4) * LCD_WIDTH; + srcx = 0; /* reset our x counter before each row... */ + shift = ((y & 3 ) * 2 ); + mask = ~pixmask[y & 3]; + for(x = 0; x < LCD_WIDTH; x++) + { + frameb[x] = (frameb[x] & mask) | ((image[(srcx>>16)]&0x3) << shift ); + srcx += X_STEP; /* move through source image */ + } + srcy += Y_STEP; /* move through the source image... */ + image += (srcy>>16)*WIDTH; /* and possibly to the next row. */ + srcy &= 0xffff; /* set up the y-coordinate between 0 and 1 */ + } +#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED + int shift; + for(y = 0; y < LCD_HEIGHT; y++) + { + frameb = rb->lcd_framebuffer + (y/8) * LCD_WIDTH; + srcx = 0; /* reset our x counter before each row... */ + shift = (y & 7); + mask = ~pixmask[y & 7]; + for(x = 0; x < LCD_WIDTH; x++) + { + frameb[x] = (frameb[x] & mask) | (pixval[image[(srcx>>16)]&0x3] << shift ); + srcx += X_STEP; /* move through source image */ + } + srcy += Y_STEP; /* move through the source image... */ + image += (srcy>>16)*WIDTH; /* and possibly to the next row. */ + srcy &= 0xffff; /* set up the y-coordinate between 0 and 1 */ + } +#endif + + if ( settings.showfps ) { + int percent=0; + int TPF = HZ/50;/* ticks per frame */ + if ((*rb->current_tick-start_time) > TPF ) + percent = 100*video_frames/((*rb->current_tick-start_time)/TPF); + rb->snprintf(str,sizeof(str),"%d %%",percent); + rb->lcd_putsxy(0,0,str); + } + + + rb -> lcd_update(); +} + +#endif /* !USE_GREY */ diff --git a/apps/plugins/zxbox/zxvid_4bpp.c b/apps/plugins/zxbox/zxvid_4bpp.c deleted file mode 100644 index 1d9902e125..0000000000 --- a/apps/plugins/zxbox/zxvid_4bpp.c +++ /dev/null @@ -1,130 +0,0 @@ -#include "zxvid_com.h" - -#if !defined USE_GREY && LCD_DEPTH < 4 -/* screen routines for greyscale targets not using greyscale lib */ - -#if LCD_PIXELFORMAT == HORIZONTAL_PACKING -#define FB_WIDTH ((LCD_WIDTH+3)/4) -fb_data pixmask[4] ICONST_ATTR = { - 0xC0, 0x30, 0x0C, 0x03 -}; -#elif LCD_PIXELFORMAT == VERTICAL_PACKING -fb_data pixmask[4] ICONST_ATTR = { - 0x03, 0x0C, 0x30, 0xC0 -}; -#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED -fb_data pixmask[8] ICONST_ATTR = { - 0x0101, 0x0202, 0x0404, 0x0808, 0x1010, 0x2020, 0x4040, 0x8080 -}; -fb_data pixval[4] ICONST_ATTR = { - 0x0000, 0x0001, 0x0100, 0x0101 -}; -#endif - -void init_spect_scr(void) -{ - sp_colors[0] = 0;/* BLACK ? */ - sp_colors[1] = 1;/* BLUE ? */ - sp_colors[2] = 1;/* RED ? */ - sp_colors[3] = 1;/* MAGENTA ? */ - sp_colors[4] = 2;/* GREEN ? */ - sp_colors[5] = 2;/* CYAN ? */ - sp_colors[6] = 3;/* YELLOW ? */ - sp_colors[7] = 3;/* WHITE ? */ - - /* same but 'light/bright' colors */ - sp_colors[8] = 0; - sp_colors[9] = 1; - sp_colors[10] = 1; - sp_colors[11] = 1; - sp_colors[12] = 2; - sp_colors[13] = 2; - sp_colors[14] = 3; - sp_colors[15] = 3; - - if ( !settings.invert_colors ){ - int i; - for ( i = 0 ; i < 16 ; i++ ) - sp_colors[i] = 3 - sp_colors[i]; - } - sp_image = (char *) &image_array; - spscr_init_mask_color(); - spscr_init_line_pointers(HEIGHT); - -} -void update_screen(void) -{ - char str[80]; - - fb_data *frameb; - int y=0; - int x=0; - unsigned char* image; - int srcx, srcy=0; /* x / y coordinates in source image */ - image = sp_image + ( (Y_OFF)*(WIDTH) ) + X_OFF; - unsigned mask; -#if LCD_PIXELFORMAT == HORIZONTAL_PACKING - for(y = 0; y < LCD_HEIGHT; y++) - { - frameb = rb->lcd_framebuffer + (y) * FB_WIDTH; - srcx = 0; /* reset our x counter before each row... */ - for(x = 0; x < LCD_WIDTH; x++) - { - mask = ~pixmask[x & 3]; - frameb[x >> 2] = (frameb[x >> 2] & mask) | ((image[(srcx>>16)]&0x3) << ((3-(x & 3 )) * 2 )); - srcx += X_STEP; /* move through source image */ - } - srcy += Y_STEP; /* move through the source image... */ - image += (srcy>>16)*WIDTH; /* and possibly to the next row. */ - srcy &= 0xffff; /* set up the y-coordinate between 0 and 1 */ - } -#elif LCD_PIXELFORMAT == VERTICAL_PACKING - int shift; - for(y = 0; y < LCD_HEIGHT; y++) - { - frameb = rb->lcd_framebuffer + (y/4) * LCD_WIDTH; - srcx = 0; /* reset our x counter before each row... */ - shift = ((y & 3 ) * 2 ); - mask = ~pixmask[y & 3]; - for(x = 0; x < LCD_WIDTH; x++) - { - frameb[x] = (frameb[x] & mask) | ((image[(srcx>>16)]&0x3) << shift ); - srcx += X_STEP; /* move through source image */ - } - srcy += Y_STEP; /* move through the source image... */ - image += (srcy>>16)*WIDTH; /* and possibly to the next row. */ - srcy &= 0xffff; /* set up the y-coordinate between 0 and 1 */ - } -#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED - int shift; - for(y = 0; y < LCD_HEIGHT; y++) - { - frameb = rb->lcd_framebuffer + (y/8) * LCD_WIDTH; - srcx = 0; /* reset our x counter before each row... */ - shift = (y & 7); - mask = ~pixmask[y & 7]; - for(x = 0; x < LCD_WIDTH; x++) - { - frameb[x] = (frameb[x] & mask) | (pixval[image[(srcx>>16)]&0x3] << shift ); - srcx += X_STEP; /* move through source image */ - } - srcy += Y_STEP; /* move through the source image... */ - image += (srcy>>16)*WIDTH; /* and possibly to the next row. */ - srcy &= 0xffff; /* set up the y-coordinate between 0 and 1 */ - } -#endif - - if ( settings.showfps ) { - int percent=0; - int TPF = HZ/50;/* ticks per frame */ - if ((*rb->current_tick-start_time) > TPF ) - percent = 100*video_frames/((*rb->current_tick-start_time)/TPF); - rb->snprintf(str,sizeof(str),"%d %%",percent); - rb->lcd_putsxy(0,0,str); - } - - - rb -> lcd_update(); -} - -#endif diff --git a/apps/plugins/zxbox/zxvid_grey.c b/apps/plugins/zxbox/zxvid_grey.c index de9cd97874..d713eba4b5 100644 --- a/apps/plugins/zxbox/zxvid_grey.c +++ b/apps/plugins/zxbox/zxvid_grey.c @@ -1,40 +1,28 @@ #include "zxvid_com.h" -#if !defined HAVE_LCD_COLOR && defined USE_GREY -/* -use for slightly different colors -#define N0 0x04 -#define N1 0x34 -#define B0 0x08 -#define B1 0x3F -*/ +#ifdef USE_GREY -/* these ones are the same as for color targets ... may be tweak for greyscale? */ #define N0 0x00 -#define N1 0xAA - -#define B0 0x55 +#define N1 0xC0 +#define B0 0x00 #define B1 0xFF -static unsigned char graybuffer[LCD_HEIGHT*LCD_WIDTH] IBSS_ATTR; /* off screen buffer */ -struct rgb norm_colors[COLORNUM]={ - {0,0,0},{N0,N0,N1},{N1,N0,N0},{N1,N0,N1}, - {N0,N1,N0},{N0,N1,N1},{N1,N1,N0},{N1,N1,N1}, +static unsigned char graybuffer[LCD_HEIGHT*LCD_WIDTH] IBSS_ATTR; /* off screen buffer */ - {0x15,0x15,0x15},{B0,B0,B1},{B1,B0,B0},{B1,B0,B1}, - {B0,B1,B0},{B0,B1,B1},{B1,B1,B0},{B1,B1,B1} +static const unsigned char graylevels[16] = { + N0, (6*N0+1*N1)/7, (5*N0+2*N1)/7, (4*N0+3*N1)/7, + (3*N0+4*N1)/7, (2*N0+5*N1)/7, (1*N0+6*N1)/7, N1, + B0, (6*B0+1*B1)/7, (5*B0+2*B1)/7, (4*B0+3*B1)/7, + (3*B0+4*B1)/7, (2*B0+5*B1)/7, (1*B0+6*B1)/7, B1 }; void init_spect_scr(void) { int i; + unsigned mask = settings.invert_colors ? 0xFF : 0; + for(i = 0; i < 16; i++) - sp_colors[i] = 0.3*norm_colors[i].r + 0.59*norm_colors[i].g + 0.11*norm_colors[i].b; - if ( settings.invert_colors ){ - int i; - for ( i = 0 ; i < 16 ; i++ ) - sp_colors[i] = 255 - sp_colors[i]; - } + sp_colors[i] = graylevels[i] ^ mask; sp_image = (char *) &image_array; spscr_init_mask_color(); @@ -52,7 +40,7 @@ void update_screen(void) int srcx, srcy=0; /* x / y coordinates in source image */ image = sp_image + ( (Y_OFF)*(WIDTH) ) + X_OFF; unsigned char* buf_ptr; - buf_ptr = (unsigned char*) &graybuffer; + buf_ptr = graybuffer; for(y = 0; y < LCD_HEIGHT; y++) { srcx = 0; /* reset our x counter before each row... */ @@ -94,4 +82,4 @@ void update_screen(void) } -#endif +#endif /* USE_GREY */ -- cgit v1.2.3