Commit 21206a104f86a27c69ed95cead1f69f6da33e77e
1 parent
094eed6c
more correct display functions
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2149 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
56 additions
and
12 deletions
hw/tcx.c
| ... | ... | @@ -34,11 +34,55 @@ typedef struct TCXState { |
| 34 | 34 | ram_addr_t vram_offset; |
| 35 | 35 | uint16_t width, height; |
| 36 | 36 | uint8_t r[256], g[256], b[256]; |
| 37 | + uint32_t palette[256]; | |
| 37 | 38 | uint8_t dac_index, dac_state; |
| 38 | 39 | } TCXState; |
| 39 | 40 | |
| 40 | 41 | static void tcx_screen_dump(void *opaque, const char *filename); |
| 41 | 42 | |
| 43 | +/* XXX: unify with vga draw line functions */ | |
| 44 | +static inline unsigned int rgb_to_pixel8(unsigned int r, unsigned int g, unsigned b) | |
| 45 | +{ | |
| 46 | + return ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6); | |
| 47 | +} | |
| 48 | + | |
| 49 | +static inline unsigned int rgb_to_pixel15(unsigned int r, unsigned int g, unsigned b) | |
| 50 | +{ | |
| 51 | + return ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3); | |
| 52 | +} | |
| 53 | + | |
| 54 | +static inline unsigned int rgb_to_pixel16(unsigned int r, unsigned int g, unsigned b) | |
| 55 | +{ | |
| 56 | + return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); | |
| 57 | +} | |
| 58 | + | |
| 59 | +static inline unsigned int rgb_to_pixel32(unsigned int r, unsigned int g, unsigned b) | |
| 60 | +{ | |
| 61 | + return (r << 16) | (g << 8) | b; | |
| 62 | +} | |
| 63 | + | |
| 64 | +static void update_palette_entries(TCXState *s, int start, int end) | |
| 65 | +{ | |
| 66 | + int i; | |
| 67 | + for(i = start; i < end; i++) { | |
| 68 | + switch(s->ds->depth) { | |
| 69 | + default: | |
| 70 | + case 8: | |
| 71 | + s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]); | |
| 72 | + break; | |
| 73 | + case 15: | |
| 74 | + s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]); | |
| 75 | + break; | |
| 76 | + case 16: | |
| 77 | + s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]); | |
| 78 | + break; | |
| 79 | + case 32: | |
| 80 | + s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]); | |
| 81 | + break; | |
| 82 | + } | |
| 83 | + } | |
| 84 | +} | |
| 85 | + | |
| 42 | 86 | static void tcx_draw_line32(TCXState *s1, uint8_t *d, |
| 43 | 87 | const uint8_t *s, int width) |
| 44 | 88 | { |
| ... | ... | @@ -47,14 +91,11 @@ static void tcx_draw_line32(TCXState *s1, uint8_t *d, |
| 47 | 91 | |
| 48 | 92 | for(x = 0; x < width; x++) { |
| 49 | 93 | val = *s++; |
| 50 | - *d++ = s1->b[val]; | |
| 51 | - *d++ = s1->g[val]; | |
| 52 | - *d++ = s1->r[val]; | |
| 53 | - d++; | |
| 94 | + *((uint32_t *)d)++ = s1->palette[val]; | |
| 54 | 95 | } |
| 55 | 96 | } |
| 56 | 97 | |
| 57 | -static void tcx_draw_line24(TCXState *s1, uint8_t *d, | |
| 98 | +static void tcx_draw_line16(TCXState *s1, uint8_t *d, | |
| 58 | 99 | const uint8_t *s, int width) |
| 59 | 100 | { |
| 60 | 101 | int x; |
| ... | ... | @@ -62,9 +103,7 @@ static void tcx_draw_line24(TCXState *s1, uint8_t *d, |
| 62 | 103 | |
| 63 | 104 | for(x = 0; x < width; x++) { |
| 64 | 105 | val = *s++; |
| 65 | - *d++ = s1->b[val]; | |
| 66 | - *d++ = s1->g[val]; | |
| 67 | - *d++ = s1->r[val]; | |
| 106 | + *((uint16_t *)d)++ = s1->palette[val]; | |
| 68 | 107 | } |
| 69 | 108 | } |
| 70 | 109 | |
| ... | ... | @@ -76,8 +115,7 @@ static void tcx_draw_line8(TCXState *s1, uint8_t *d, |
| 76 | 115 | |
| 77 | 116 | for(x = 0; x < width; x++) { |
| 78 | 117 | val = *s++; |
| 79 | - /* XXX translate between palettes? */ | |
| 80 | - *d++ = val; | |
| 118 | + *d++ = s1->palette[val]; | |
| 81 | 119 | } |
| 82 | 120 | } |
| 83 | 121 | |
| ... | ... | @@ -106,8 +144,9 @@ static void tcx_update_display(void *opaque) |
| 106 | 144 | case 32: |
| 107 | 145 | f = tcx_draw_line32; |
| 108 | 146 | break; |
| 109 | - case 24: | |
| 110 | - f = tcx_draw_line24; | |
| 147 | + case 15: | |
| 148 | + case 16: | |
| 149 | + f = tcx_draw_line16; | |
| 111 | 150 | break; |
| 112 | 151 | default: |
| 113 | 152 | case 8: |
| ... | ... | @@ -201,6 +240,7 @@ static int tcx_load(QEMUFile *f, void *opaque, int version_id) |
| 201 | 240 | qemu_get_buffer(f, s->b, 256); |
| 202 | 241 | qemu_get_8s(f, &s->dac_index); |
| 203 | 242 | qemu_get_8s(f, &s->dac_state); |
| 243 | + update_palette_entries(s, 0, 256); | |
| 204 | 244 | return 0; |
| 205 | 245 | } |
| 206 | 246 | |
| ... | ... | @@ -213,6 +253,7 @@ static void tcx_reset(void *opaque) |
| 213 | 253 | memset(s->g, 0, 256); |
| 214 | 254 | memset(s->b, 0, 256); |
| 215 | 255 | s->r[255] = s->g[255] = s->b[255] = 255; |
| 256 | + update_palette_entries(s, 0, 256); | |
| 216 | 257 | memset(s->vram, 0, MAXX*MAXY); |
| 217 | 258 | cpu_physical_memory_reset_dirty(s->vram_offset, s->vram_offset + MAXX*MAXY, |
| 218 | 259 | VGA_DIRTY_FLAG); |
| ... | ... | @@ -240,14 +281,17 @@ static void tcx_dac_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
| 240 | 281 | switch (s->dac_state) { |
| 241 | 282 | case 0: |
| 242 | 283 | s->r[s->dac_index] = val >> 24; |
| 284 | + update_palette_entries(s, s->dac_index, s->dac_index + 1); | |
| 243 | 285 | s->dac_state++; |
| 244 | 286 | break; |
| 245 | 287 | case 1: |
| 246 | 288 | s->g[s->dac_index] = val >> 24; |
| 289 | + update_palette_entries(s, s->dac_index, s->dac_index + 1); | |
| 247 | 290 | s->dac_state++; |
| 248 | 291 | break; |
| 249 | 292 | case 2: |
| 250 | 293 | s->b[s->dac_index] = val >> 24; |
| 294 | + update_palette_entries(s, s->dac_index, s->dac_index + 1); | |
| 251 | 295 | default: |
| 252 | 296 | s->dac_state = 0; |
| 253 | 297 | break; | ... | ... |