balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Toshiba TC6393XB I/O Controller. |
| 3 | * Found in Sharp Zaurus SL-6000 (tosa) or some |
| 4 | * Toshiba e-Series PDAs. |
| 5 | * |
| 6 | * FB support code. Based on G364 fb emulator |
| 7 | * |
Stefan Weil | bcc4e41 | 2011-12-02 10:30:41 +0100 | [diff] [blame] | 8 | * Copyright (c) 2007 Hervé Poussineau |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
aurel32 | fad6cb1 | 2009-01-04 22:05:52 +0000 | [diff] [blame] | 20 | * You should have received a copy of the GNU General Public License along |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 21 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #if BITS == 8 |
Paolo Bonzini | 2cdaca9 | 2014-01-31 14:47:33 +0000 | [diff] [blame] | 25 | # define SET_PIXEL(addr, color) (*(uint8_t *)addr = color) |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 26 | #elif BITS == 15 || BITS == 16 |
Paolo Bonzini | 2cdaca9 | 2014-01-31 14:47:33 +0000 | [diff] [blame] | 27 | # define SET_PIXEL(addr, color) (*(uint16_t *)addr = color) |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 28 | #elif BITS == 24 |
Paolo Bonzini | 2cdaca9 | 2014-01-31 14:47:33 +0000 | [diff] [blame] | 29 | # define SET_PIXEL(addr, color) \ |
| 30 | do { \ |
| 31 | addr[0] = color; \ |
| 32 | addr[1] = (color) >> 8; \ |
| 33 | addr[2] = (color) >> 16; \ |
| 34 | } while (0) |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 35 | #elif BITS == 32 |
Paolo Bonzini | 2cdaca9 | 2014-01-31 14:47:33 +0000 | [diff] [blame] | 36 | # define SET_PIXEL(addr, color) (*(uint32_t *)addr = color) |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 37 | #else |
| 38 | # error unknown bit depth |
| 39 | #endif |
| 40 | |
| 41 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 42 | static void glue(tc6393xb_draw_graphic, BITS)(TC6393xbState *s) |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 43 | { |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 44 | DisplaySurface *surface = qemu_console_surface(s->con); |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 45 | int i; |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 46 | uint16_t *data_buffer; |
| 47 | uint8_t *data_display; |
| 48 | |
pbrook | 4465449 | 2009-04-10 00:26:15 +0000 | [diff] [blame] | 49 | data_buffer = s->vram_ptr; |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 50 | data_display = surface_data(surface); |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 51 | for(i = 0; i < s->scr_height; i++) { |
| 52 | #if (BITS == 16) |
| 53 | memcpy(data_display, data_buffer, s->scr_width * 2); |
| 54 | data_buffer += s->scr_width; |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 55 | data_display += surface_stride(surface); |
balrog | 64b40bc | 2008-11-04 09:04:41 +0000 | [diff] [blame] | 56 | #else |
| 57 | int j; |
| 58 | for (j = 0; j < s->scr_width; j++, data_display += BITS / 8, data_buffer++) { |
| 59 | uint16_t color = *data_buffer; |
| 60 | uint32_t dest_color = glue(rgb_to_pixel, BITS)( |
| 61 | ((color & 0xf800) * 0x108) >> 11, |
| 62 | ((color & 0x7e0) * 0x41) >> 9, |
| 63 | ((color & 0x1f) * 0x21) >> 2 |
| 64 | ); |
| 65 | SET_PIXEL(data_display, dest_color); |
| 66 | } |
| 67 | #endif |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | #undef BITS |
| 72 | #undef SET_PIXEL |