Commit 0266f2c733911ca3f70e009e3230c790c800e524
1 parent
ea01e5fd
Fix MusicPal LCD on non-32 bpp displays or with -nographic.
Prevents an immediate segfault. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4252 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
38 additions
and
20 deletions
hw/musicpal.c
@@ -759,32 +759,50 @@ static uint8_t scale_lcd_color(uint8_t col) | @@ -759,32 +759,50 @@ static uint8_t scale_lcd_color(uint8_t col) | ||
759 | } | 759 | } |
760 | } | 760 | } |
761 | 761 | ||
762 | -static void set_lcd_pixel(musicpal_lcd_state *s, int x, int y, int col) | ||
763 | -{ | ||
764 | - int dx, dy; | ||
765 | - | ||
766 | - for (dy = 0; dy < 3; dy++) | ||
767 | - for (dx = 0; dx < 3; dx++) { | ||
768 | - s->ds->data[(x*3 + dx + (y*3 + dy) * 128*3) * 4 + 0] = | ||
769 | - scale_lcd_color(col); | ||
770 | - s->ds->data[(x*3 + dx + (y*3 + dy) * 128*3) * 4 + 1] = | ||
771 | - scale_lcd_color(col >> 8); | ||
772 | - s->ds->data[(x*3 + dx + (y*3 + dy) * 128*3) * 4 + 2] = | ||
773 | - scale_lcd_color(col >> 16); | ||
774 | - } | 762 | +#define SET_LCD_PIXEL(depth, type) \ |
763 | +static inline void glue(set_lcd_pixel, depth) \ | ||
764 | + (musicpal_lcd_state *s, int x, int y, type col) \ | ||
765 | +{ \ | ||
766 | + int dx, dy; \ | ||
767 | + type *pixel = &((type *) s->ds->data)[(y * 128 * 3 + x) * 3]; \ | ||
768 | +\ | ||
769 | + for (dy = 0; dy < 3; dy++, pixel += 127 * 3) \ | ||
770 | + for (dx = 0; dx < 3; dx++, pixel++) \ | ||
771 | + *pixel = col; \ | ||
775 | } | 772 | } |
773 | +SET_LCD_PIXEL(8, uint8_t) | ||
774 | +SET_LCD_PIXEL(16, uint16_t) | ||
775 | +SET_LCD_PIXEL(32, uint32_t) | ||
776 | + | ||
777 | +#include "pixel_ops.h" | ||
776 | 778 | ||
777 | static void lcd_refresh(void *opaque) | 779 | static void lcd_refresh(void *opaque) |
778 | { | 780 | { |
779 | musicpal_lcd_state *s = opaque; | 781 | musicpal_lcd_state *s = opaque; |
780 | - int x, y; | 782 | + int x, y, col; |
781 | 783 | ||
782 | - for (x = 0; x < 128; x++) | ||
783 | - for (y = 0; y < 64; y++) | ||
784 | - if (s->video_ram[x + (y/8)*128] & (1 << (y % 8))) | ||
785 | - set_lcd_pixel(s, x, y, MP_LCD_TEXTCOLOR); | ||
786 | - else | ||
787 | - set_lcd_pixel(s, x, y, 0); | 784 | + switch (s->ds->depth) { |
785 | + case 0: | ||
786 | + return; | ||
787 | +#define LCD_REFRESH(depth, func) \ | ||
788 | + case depth: \ | ||
789 | + col = func(scale_lcd_color((MP_LCD_TEXTCOLOR >> 16) & 0xff), \ | ||
790 | + scale_lcd_color((MP_LCD_TEXTCOLOR >> 8) & 0xff), \ | ||
791 | + scale_lcd_color(MP_LCD_TEXTCOLOR & 0xff)); \ | ||
792 | + for (x = 0; x < 128; x++) \ | ||
793 | + for (y = 0; y < 64; y++) \ | ||
794 | + if (s->video_ram[x + (y/8)*128] & (1 << (y % 8))) \ | ||
795 | + glue(set_lcd_pixel, depth)(s, x, y, col); \ | ||
796 | + else \ | ||
797 | + glue(set_lcd_pixel, depth)(s, x, y, 0); \ | ||
798 | + break; | ||
799 | + LCD_REFRESH(8, rgb_to_pixel8) | ||
800 | + LCD_REFRESH(16, rgb_to_pixel16) | ||
801 | + LCD_REFRESH(32, (s->ds->bgr ? rgb_to_pixel32bgr : rgb_to_pixel32)) | ||
802 | + default: | ||
803 | + cpu_abort(cpu_single_env, "unsupported colour depth %i\n", | ||
804 | + s->ds->depth); | ||
805 | + } | ||
788 | 806 | ||
789 | dpy_update(s->ds, 0, 0, 128*3, 64*3); | 807 | dpy_update(s->ds, 0, 0, 128*3, 64*3); |
790 | } | 808 | } |