bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU VGA Emulator templates |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 25 | static inline void vga_draw_glyph_line(uint8_t *d, uint32_t font_data, |
| 26 | uint32_t xorcol, uint32_t bgcol) |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 27 | { |
bellard | b1ba657 | 2003-09-16 21:47:08 +0000 | [diff] [blame] | 28 | ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol; |
| 29 | ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol; |
| 30 | ((uint32_t *)d)[2] = (-((font_data >> 5) & 1) & xorcol) ^ bgcol; |
| 31 | ((uint32_t *)d)[3] = (-((font_data >> 4) & 1) & xorcol) ^ bgcol; |
| 32 | ((uint32_t *)d)[4] = (-((font_data >> 3) & 1) & xorcol) ^ bgcol; |
| 33 | ((uint32_t *)d)[5] = (-((font_data >> 2) & 1) & xorcol) ^ bgcol; |
| 34 | ((uint32_t *)d)[6] = (-((font_data >> 1) & 1) & xorcol) ^ bgcol; |
| 35 | ((uint32_t *)d)[7] = (-((font_data >> 0) & 1) & xorcol) ^ bgcol; |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 38 | static void vga_draw_glyph8(uint8_t *d, int linesize, |
| 39 | const uint8_t *font_ptr, int h, |
| 40 | uint32_t fgcol, uint32_t bgcol) |
| 41 | { |
| 42 | uint32_t font_data, xorcol; |
| 43 | |
| 44 | xorcol = bgcol ^ fgcol; |
| 45 | do { |
| 46 | font_data = font_ptr[0]; |
| 47 | vga_draw_glyph_line(d, font_data, xorcol, bgcol); |
| 48 | font_ptr += 4; |
| 49 | d += linesize; |
| 50 | } while (--h); |
| 51 | } |
| 52 | |
| 53 | static void vga_draw_glyph16(uint8_t *d, int linesize, |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 54 | const uint8_t *font_ptr, int h, |
| 55 | uint32_t fgcol, uint32_t bgcol) |
| 56 | { |
| 57 | uint32_t font_data, xorcol; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 58 | |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 59 | xorcol = bgcol ^ fgcol; |
| 60 | do { |
| 61 | font_data = font_ptr[0]; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 62 | vga_draw_glyph_line(d, expand4to8[font_data >> 4], |
| 63 | xorcol, bgcol); |
| 64 | vga_draw_glyph_line(d + 32, expand4to8[font_data & 0x0f], |
| 65 | xorcol, bgcol); |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 66 | font_ptr += 4; |
| 67 | d += linesize; |
| 68 | } while (--h); |
| 69 | } |
| 70 | |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 71 | static void vga_draw_glyph9(uint8_t *d, int linesize, |
| 72 | const uint8_t *font_ptr, int h, |
| 73 | uint32_t fgcol, uint32_t bgcol, int dup9) |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 74 | { |
| 75 | uint32_t font_data, xorcol, v; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 76 | |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 77 | xorcol = bgcol ^ fgcol; |
| 78 | do { |
| 79 | font_data = font_ptr[0]; |
bellard | eccabc6 | 2004-04-07 20:31:38 +0000 | [diff] [blame] | 80 | ((uint32_t *)d)[0] = (-((font_data >> 7)) & xorcol) ^ bgcol; |
| 81 | ((uint32_t *)d)[1] = (-((font_data >> 6) & 1) & xorcol) ^ bgcol; |
| 82 | ((uint32_t *)d)[2] = (-((font_data >> 5) & 1) & xorcol) ^ bgcol; |
| 83 | ((uint32_t *)d)[3] = (-((font_data >> 4) & 1) & xorcol) ^ bgcol; |
| 84 | ((uint32_t *)d)[4] = (-((font_data >> 3) & 1) & xorcol) ^ bgcol; |
| 85 | ((uint32_t *)d)[5] = (-((font_data >> 2) & 1) & xorcol) ^ bgcol; |
| 86 | ((uint32_t *)d)[6] = (-((font_data >> 1) & 1) & xorcol) ^ bgcol; |
| 87 | v = (-((font_data >> 0) & 1) & xorcol) ^ bgcol; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 88 | ((uint32_t *)d)[7] = v; |
| 89 | if (dup9) |
bellard | 39cf780 | 2003-08-05 23:06:22 +0000 | [diff] [blame] | 90 | ((uint32_t *)d)[8] = v; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 91 | else |
bellard | 39cf780 | 2003-08-05 23:06:22 +0000 | [diff] [blame] | 92 | ((uint32_t *)d)[8] = bgcol; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 93 | font_ptr += 4; |
| 94 | d += linesize; |
| 95 | } while (--h); |
| 96 | } |
| 97 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 98 | /* |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 99 | * 4 color mode |
| 100 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 101 | static void *vga_draw_line2(VGACommonState *vga, uint8_t *d, |
| 102 | uint32_t addr, int width, int hpel) |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 103 | { |
| 104 | uint32_t plane_mask, *palette, data, v; |
| 105 | int x; |
| 106 | |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 107 | palette = vga->last_palette; |
| 108 | plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 109 | hpel &= 7; |
| 110 | if (hpel) { |
| 111 | width += 8; |
| 112 | d = vga->panning_buf; |
| 113 | } |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 114 | width >>= 3; |
| 115 | for(x = 0; x < width; x++) { |
Paolo Bonzini | 9b53b95 | 2014-12-29 14:43:42 +0100 | [diff] [blame] | 116 | data = vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 117 | data &= plane_mask; |
| 118 | v = expand2[GET_PLANE(data, 0)]; |
| 119 | v |= expand2[GET_PLANE(data, 2)] << 2; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 120 | ((uint32_t *)d)[0] = palette[v >> 12]; |
| 121 | ((uint32_t *)d)[1] = palette[(v >> 8) & 0xf]; |
| 122 | ((uint32_t *)d)[2] = palette[(v >> 4) & 0xf]; |
| 123 | ((uint32_t *)d)[3] = palette[(v >> 0) & 0xf]; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 124 | |
| 125 | v = expand2[GET_PLANE(data, 1)]; |
| 126 | v |= expand2[GET_PLANE(data, 3)] << 2; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 127 | ((uint32_t *)d)[4] = palette[v >> 12]; |
| 128 | ((uint32_t *)d)[5] = palette[(v >> 8) & 0xf]; |
| 129 | ((uint32_t *)d)[6] = palette[(v >> 4) & 0xf]; |
| 130 | ((uint32_t *)d)[7] = palette[(v >> 0) & 0xf]; |
| 131 | d += 32; |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 132 | addr += 4; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 133 | } |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 134 | return hpel ? vga->panning_buf + 4 * hpel : NULL; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 135 | } |
| 136 | |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 137 | #define PUT_PIXEL2(d, n, v) \ |
| 138 | ((uint32_t *)d)[2*(n)] = ((uint32_t *)d)[2*(n)+1] = (v) |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 139 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 140 | /* |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 141 | * 4 color mode, dup2 horizontal |
| 142 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 143 | static void *vga_draw_line2d2(VGACommonState *vga, uint8_t *d, |
| 144 | uint32_t addr, int width, int hpel) |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 145 | { |
| 146 | uint32_t plane_mask, *palette, data, v; |
| 147 | int x; |
| 148 | |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 149 | palette = vga->last_palette; |
| 150 | plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 151 | hpel &= 7; |
| 152 | if (hpel) { |
| 153 | width += 8; |
| 154 | d = vga->panning_buf; |
| 155 | } |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 156 | width >>= 3; |
| 157 | for(x = 0; x < width; x++) { |
Paolo Bonzini | 9b53b95 | 2014-12-29 14:43:42 +0100 | [diff] [blame] | 158 | data = vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 159 | data &= plane_mask; |
| 160 | v = expand2[GET_PLANE(data, 0)]; |
| 161 | v |= expand2[GET_PLANE(data, 2)] << 2; |
| 162 | PUT_PIXEL2(d, 0, palette[v >> 12]); |
| 163 | PUT_PIXEL2(d, 1, palette[(v >> 8) & 0xf]); |
| 164 | PUT_PIXEL2(d, 2, palette[(v >> 4) & 0xf]); |
| 165 | PUT_PIXEL2(d, 3, palette[(v >> 0) & 0xf]); |
| 166 | |
| 167 | v = expand2[GET_PLANE(data, 1)]; |
| 168 | v |= expand2[GET_PLANE(data, 3)] << 2; |
| 169 | PUT_PIXEL2(d, 4, palette[v >> 12]); |
| 170 | PUT_PIXEL2(d, 5, palette[(v >> 8) & 0xf]); |
| 171 | PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]); |
| 172 | PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]); |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 173 | d += 64; |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 174 | addr += 4; |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 175 | } |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 176 | return hpel ? vga->panning_buf + 8 * hpel : NULL; |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 177 | } |
| 178 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 179 | /* |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 180 | * 16 color mode |
| 181 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 182 | static void *vga_draw_line4(VGACommonState *vga, uint8_t *d, |
| 183 | uint32_t addr, int width, int hpel) |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 184 | { |
| 185 | uint32_t plane_mask, data, v, *palette; |
| 186 | int x; |
| 187 | |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 188 | palette = vga->last_palette; |
| 189 | plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 190 | hpel &= 7; |
| 191 | if (hpel) { |
| 192 | width += 8; |
| 193 | d = vga->panning_buf; |
| 194 | } |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 195 | width >>= 3; |
| 196 | for(x = 0; x < width; x++) { |
Paolo Bonzini | 9b53b95 | 2014-12-29 14:43:42 +0100 | [diff] [blame] | 197 | data = vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 198 | data &= plane_mask; |
| 199 | v = expand4[GET_PLANE(data, 0)]; |
| 200 | v |= expand4[GET_PLANE(data, 1)] << 1; |
| 201 | v |= expand4[GET_PLANE(data, 2)] << 2; |
| 202 | v |= expand4[GET_PLANE(data, 3)] << 3; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 203 | ((uint32_t *)d)[0] = palette[v >> 28]; |
| 204 | ((uint32_t *)d)[1] = palette[(v >> 24) & 0xf]; |
| 205 | ((uint32_t *)d)[2] = palette[(v >> 20) & 0xf]; |
| 206 | ((uint32_t *)d)[3] = palette[(v >> 16) & 0xf]; |
| 207 | ((uint32_t *)d)[4] = palette[(v >> 12) & 0xf]; |
| 208 | ((uint32_t *)d)[5] = palette[(v >> 8) & 0xf]; |
| 209 | ((uint32_t *)d)[6] = palette[(v >> 4) & 0xf]; |
| 210 | ((uint32_t *)d)[7] = palette[(v >> 0) & 0xf]; |
| 211 | d += 32; |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 212 | addr += 4; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 213 | } |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 214 | return hpel ? vga->panning_buf + 4 * hpel : NULL; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 215 | } |
| 216 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 217 | /* |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 218 | * 16 color mode, dup2 horizontal |
| 219 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 220 | static void *vga_draw_line4d2(VGACommonState *vga, uint8_t *d, |
| 221 | uint32_t addr, int width, int hpel) |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 222 | { |
| 223 | uint32_t plane_mask, data, v, *palette; |
| 224 | int x; |
| 225 | |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 226 | palette = vga->last_palette; |
| 227 | plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 228 | hpel &= 7; |
| 229 | if (hpel) { |
| 230 | width += 8; |
| 231 | d = vga->panning_buf; |
| 232 | } |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 233 | width >>= 3; |
| 234 | for(x = 0; x < width; x++) { |
Paolo Bonzini | 9b53b95 | 2014-12-29 14:43:42 +0100 | [diff] [blame] | 235 | data = vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 236 | data &= plane_mask; |
| 237 | v = expand4[GET_PLANE(data, 0)]; |
| 238 | v |= expand4[GET_PLANE(data, 1)] << 1; |
| 239 | v |= expand4[GET_PLANE(data, 2)] << 2; |
| 240 | v |= expand4[GET_PLANE(data, 3)] << 3; |
| 241 | PUT_PIXEL2(d, 0, palette[v >> 28]); |
| 242 | PUT_PIXEL2(d, 1, palette[(v >> 24) & 0xf]); |
| 243 | PUT_PIXEL2(d, 2, palette[(v >> 20) & 0xf]); |
| 244 | PUT_PIXEL2(d, 3, palette[(v >> 16) & 0xf]); |
| 245 | PUT_PIXEL2(d, 4, palette[(v >> 12) & 0xf]); |
| 246 | PUT_PIXEL2(d, 5, palette[(v >> 8) & 0xf]); |
| 247 | PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]); |
| 248 | PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]); |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 249 | d += 64; |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 250 | addr += 4; |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 251 | } |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 252 | return hpel ? vga->panning_buf + 8 * hpel : NULL; |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 253 | } |
| 254 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 255 | /* |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 256 | * 256 color mode, double pixels |
| 257 | * |
| 258 | * XXX: add plane_mask support (never used in standard VGA modes) |
| 259 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 260 | static void *vga_draw_line8d2(VGACommonState *vga, uint8_t *d, |
| 261 | uint32_t addr, int width, int hpel) |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 262 | { |
| 263 | uint32_t *palette; |
| 264 | int x; |
| 265 | |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 266 | palette = vga->last_palette; |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 267 | hpel = (hpel >> 1) & 3; |
Paolo Bonzini | 4d6c310 | 2014-12-29 14:46:59 +0100 | [diff] [blame] | 268 | |
| 269 | /* For 256 color modes, we can adjust the source address and write directly |
| 270 | * to the destination, even if horizontal pel panning is active. However, |
| 271 | * the loop below assumes that the address does not wrap in the middle of a |
| 272 | * plane. If that happens... |
| 273 | */ |
| 274 | if (addr + (width >> 3) * 4 < VGA_VRAM_SIZE) { |
| 275 | addr += hpel * 4; |
| 276 | hpel = 0; |
| 277 | } |
| 278 | |
| 279 | /* ... use the panning buffer as in planar modes. */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 280 | if (hpel) { |
| 281 | width += 8; |
| 282 | d = vga->panning_buf; |
| 283 | } |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 284 | width >>= 3; |
| 285 | for(x = 0; x < width; x++) { |
Paolo Bonzini | 9b53b95 | 2014-12-29 14:43:42 +0100 | [diff] [blame] | 286 | addr &= VGA_VRAM_SIZE - 1; |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 287 | PUT_PIXEL2(d, 0, palette[vga_read_byte(vga, addr + 0)]); |
| 288 | PUT_PIXEL2(d, 1, palette[vga_read_byte(vga, addr + 1)]); |
| 289 | PUT_PIXEL2(d, 2, palette[vga_read_byte(vga, addr + 2)]); |
| 290 | PUT_PIXEL2(d, 3, palette[vga_read_byte(vga, addr + 3)]); |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 291 | d += 32; |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 292 | addr += 4; |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 293 | } |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 294 | return hpel ? vga->panning_buf + 8 * hpel : NULL; |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 295 | } |
| 296 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 297 | /* |
bellard | 17b0018 | 2003-08-08 23:50:57 +0000 | [diff] [blame] | 298 | * standard 256 color mode |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 299 | * |
| 300 | * XXX: add plane_mask support (never used in standard VGA modes) |
| 301 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 302 | static void *vga_draw_line8(VGACommonState *vga, uint8_t *d, |
| 303 | uint32_t addr, int width, int hpel) |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 304 | { |
| 305 | uint32_t *palette; |
| 306 | int x; |
| 307 | |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 308 | palette = vga->last_palette; |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 309 | hpel = (hpel >> 1) & 3; |
| 310 | if (hpel) { |
| 311 | width += 8; |
| 312 | d = vga->panning_buf; |
| 313 | } |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 314 | width >>= 3; |
| 315 | for(x = 0; x < width; x++) { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 316 | ((uint32_t *)d)[0] = palette[vga_read_byte(vga, addr + 0)]; |
| 317 | ((uint32_t *)d)[1] = palette[vga_read_byte(vga, addr + 1)]; |
| 318 | ((uint32_t *)d)[2] = palette[vga_read_byte(vga, addr + 2)]; |
| 319 | ((uint32_t *)d)[3] = palette[vga_read_byte(vga, addr + 3)]; |
| 320 | ((uint32_t *)d)[4] = palette[vga_read_byte(vga, addr + 4)]; |
| 321 | ((uint32_t *)d)[5] = palette[vga_read_byte(vga, addr + 5)]; |
| 322 | ((uint32_t *)d)[6] = palette[vga_read_byte(vga, addr + 6)]; |
| 323 | ((uint32_t *)d)[7] = palette[vga_read_byte(vga, addr + 7)]; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 324 | d += 32; |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 325 | addr += 8; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 326 | } |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 327 | return hpel ? vga->panning_buf + 4 * hpel : NULL; |
bellard | e89f66e | 2003-08-04 23:30:47 +0000 | [diff] [blame] | 328 | } |
| 329 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 330 | /* |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 331 | * 15 bit color |
| 332 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 333 | static void *vga_draw_line15_le(VGACommonState *vga, uint8_t *d, |
| 334 | uint32_t addr, int width, int hpel) |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 335 | { |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 336 | int w; |
| 337 | uint32_t v, r, g, b; |
| 338 | |
| 339 | w = width; |
| 340 | do { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 341 | v = vga_read_word_le(vga, addr); |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 342 | r = (v >> 7) & 0xf8; |
| 343 | g = (v >> 2) & 0xf8; |
| 344 | b = (v << 3) & 0xf8; |
| 345 | ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b); |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 346 | addr += 2; |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 347 | d += 4; |
| 348 | } while (--w != 0); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 349 | return NULL; |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 350 | } |
| 351 | |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 352 | static void *vga_draw_line15_be(VGACommonState *vga, uint8_t *d, |
| 353 | uint32_t addr, int width, int hpel) |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 354 | { |
| 355 | int w; |
| 356 | uint32_t v, r, g, b; |
| 357 | |
| 358 | w = width; |
| 359 | do { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 360 | v = vga_read_word_be(vga, addr); |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 361 | r = (v >> 7) & 0xf8; |
| 362 | g = (v >> 2) & 0xf8; |
| 363 | b = (v << 3) & 0xf8; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 364 | ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b); |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 365 | addr += 2; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 366 | d += 4; |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 367 | } while (--w != 0); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 368 | return NULL; |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 369 | } |
| 370 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 371 | /* |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 372 | * 16 bit color |
| 373 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 374 | static void *vga_draw_line16_le(VGACommonState *vga, uint8_t *d, |
| 375 | uint32_t addr, int width, int hpel) |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 376 | { |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 377 | int w; |
| 378 | uint32_t v, r, g, b; |
| 379 | |
| 380 | w = width; |
| 381 | do { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 382 | v = vga_read_word_le(vga, addr); |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 383 | r = (v >> 8) & 0xf8; |
| 384 | g = (v >> 3) & 0xfc; |
| 385 | b = (v << 3) & 0xf8; |
| 386 | ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b); |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 387 | addr += 2; |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 388 | d += 4; |
| 389 | } while (--w != 0); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 390 | return NULL; |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 391 | } |
| 392 | |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 393 | static void *vga_draw_line16_be(VGACommonState *vga, uint8_t *d, |
| 394 | uint32_t addr, int width, int hpel) |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 395 | { |
| 396 | int w; |
| 397 | uint32_t v, r, g, b; |
| 398 | |
| 399 | w = width; |
| 400 | do { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 401 | v = vga_read_word_be(vga, addr); |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 402 | r = (v >> 8) & 0xf8; |
| 403 | g = (v >> 3) & 0xfc; |
| 404 | b = (v << 3) & 0xf8; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 405 | ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b); |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 406 | addr += 2; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 407 | d += 4; |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 408 | } while (--w != 0); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 409 | return NULL; |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 410 | } |
| 411 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 412 | /* |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 413 | * 24 bit color |
| 414 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 415 | static void *vga_draw_line24_le(VGACommonState *vga, uint8_t *d, |
| 416 | uint32_t addr, int width, int hpel) |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 417 | { |
| 418 | int w; |
| 419 | uint32_t r, g, b; |
| 420 | |
| 421 | w = width; |
| 422 | do { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 423 | b = vga_read_byte(vga, addr + 0); |
| 424 | g = vga_read_byte(vga, addr + 1); |
| 425 | r = vga_read_byte(vga, addr + 2); |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 426 | ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b); |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 427 | addr += 3; |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 428 | d += 4; |
| 429 | } while (--w != 0); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 430 | return NULL; |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 431 | } |
| 432 | |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 433 | static void *vga_draw_line24_be(VGACommonState *vga, uint8_t *d, |
| 434 | uint32_t addr, int width, int hpel) |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 435 | { |
| 436 | int w; |
| 437 | uint32_t r, g, b; |
| 438 | |
| 439 | w = width; |
| 440 | do { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 441 | r = vga_read_byte(vga, addr + 0); |
| 442 | g = vga_read_byte(vga, addr + 1); |
| 443 | b = vga_read_byte(vga, addr + 2); |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 444 | ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b); |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 445 | addr += 3; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 446 | d += 4; |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 447 | } while (--w != 0); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 448 | return NULL; |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 449 | } |
| 450 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 451 | /* |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 452 | * 32 bit color |
| 453 | */ |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 454 | static void *vga_draw_line32_le(VGACommonState *vga, uint8_t *d, |
| 455 | uint32_t addr, int width, int hpel) |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 456 | { |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 457 | int w; |
| 458 | uint32_t r, g, b; |
| 459 | |
| 460 | w = width; |
| 461 | do { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 462 | b = vga_read_byte(vga, addr + 0); |
| 463 | g = vga_read_byte(vga, addr + 1); |
| 464 | r = vga_read_byte(vga, addr + 2); |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 465 | ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b); |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 466 | addr += 4; |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 467 | d += 4; |
| 468 | } while (--w != 0); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 469 | return NULL; |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 470 | } |
| 471 | |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 472 | static void *vga_draw_line32_be(VGACommonState *vga, uint8_t *d, |
| 473 | uint32_t addr, int width, int hpel) |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 474 | { |
Benjamin Herrenschmidt | 46c3a8c | 2014-07-07 09:48:28 +1000 | [diff] [blame] | 475 | int w; |
| 476 | uint32_t r, g, b; |
| 477 | |
| 478 | w = width; |
| 479 | do { |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 480 | r = vga_read_byte(vga, addr + 1); |
| 481 | g = vga_read_byte(vga, addr + 2); |
| 482 | b = vga_read_byte(vga, addr + 3); |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 483 | ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b); |
Gerd Hoffmann | 3d90c62 | 2017-08-28 14:29:06 +0200 | [diff] [blame] | 484 | addr += 4; |
Benjamin Herrenschmidt | d2e043a | 2014-06-21 15:51:52 +1000 | [diff] [blame] | 485 | d += 4; |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 486 | } while (--w != 0); |
Paolo Bonzini | 973a724 | 2014-12-29 14:48:14 +0100 | [diff] [blame] | 487 | return NULL; |
bellard | d3079cd | 2006-05-10 22:17:36 +0000 | [diff] [blame] | 488 | } |