Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1 | // VGA bios implementation |
| 2 | // |
| 3 | // Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2001-2008 the LGPL VGABios developers Team |
| 5 | // |
| 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
| 7 | |
| 8 | |
| 9 | // TODO: |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 10 | // * introduce "struct vregs", or add ebp to struct bregs. |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 11 | // * define structs for save/restore state |
| 12 | // * review correctness of converted asm by comparing with RBIL |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 13 | // * refactor redundant code into sub-functions |
| 14 | // * See if there is a method to the in/out stuff that can be encapsulated. |
| 15 | // * remove "biosfn" prefixes |
| 16 | // * don't hardcode 0xc000 |
| 17 | // * add defs for 0xa000/0xb800 |
| 18 | // * verify all funcs static |
| 19 | // |
Kevin O'Connor | 6ace78f | 2009-05-14 19:24:49 -0400 | [diff] [blame] | 20 | // * convert vbe/clext code |
| 21 | // |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 22 | // * separate code into separate files |
| 23 | // * extract hw code from bios interfaces |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 24 | |
| 25 | #include "bregs.h" // struct bregs |
| 26 | #include "biosvar.h" // GET_BDA |
| 27 | #include "util.h" // memset |
| 28 | #include "vgatables.h" // vga_modes |
| 29 | |
| 30 | // XXX |
| 31 | #define CONFIG_VBE 0 |
| 32 | #define CONFIG_CIRRUS 0 |
| 33 | |
| 34 | // XXX |
| 35 | #define DEBUG_VGA_POST 1 |
| 36 | #define DEBUG_VGA_10 3 |
| 37 | |
| 38 | #define SET_VGA(var, val) SET_FARVAR(0xc000, (var), (val)) |
| 39 | |
| 40 | |
| 41 | // =================================================================== |
| 42 | // |
| 43 | // Video Utils |
| 44 | // |
| 45 | // =================================================================== |
| 46 | |
| 47 | // ------------------------------------------------------------------- |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 48 | inline void |
| 49 | call16_vgaint(u32 eax, u32 ebx) |
| 50 | { |
| 51 | asm volatile( |
| 52 | "int $0x10\n" |
| 53 | "cli\n" |
| 54 | "cld" |
| 55 | : |
| 56 | : "a"(eax), "b"(ebx) |
| 57 | : "cc", "memory"); |
| 58 | } |
| 59 | |
| 60 | // XXX |
| 61 | inline void |
| 62 | memcpy16_far(u16 d_seg, void *d_far, u16 s_seg, const void *s_far, size_t len) |
| 63 | { |
| 64 | memcpy_far(d_seg, d_far, s_seg, s_far, len); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | // =================================================================== |
| 69 | // |
| 70 | // BIOS functions |
| 71 | // |
| 72 | // =================================================================== |
| 73 | |
| 74 | // ------------------------------------------------------------------- |
| 75 | static void |
| 76 | biosfn_perform_gray_scale_summing(u16 start, u16 count) |
| 77 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 78 | inb(VGAREG_ACTL_RESET); |
| 79 | outb(0x00, VGAREG_ACTL_ADDRESS); |
| 80 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 81 | int i; |
| 82 | for (i = start; i < start+count; i++) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 83 | // set read address and switch to read mode |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 84 | outb(i, VGAREG_DAC_READ_ADDRESS); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 85 | // get 6-bit wide RGB data values |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 86 | u8 r = inb(VGAREG_DAC_DATA); |
| 87 | u8 g = inb(VGAREG_DAC_DATA); |
| 88 | u8 b = inb(VGAREG_DAC_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 89 | |
| 90 | // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue ) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 91 | u16 intensity = ((77 * r + 151 * g + 28 * b) + 0x80) >> 8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 92 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 93 | if (intensity > 0x3f) |
| 94 | intensity = 0x3f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 95 | |
| 96 | // set write address and switch to write mode |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 97 | outb(i, VGAREG_DAC_WRITE_ADDRESS); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 98 | // write new intensity value |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 99 | outb(intensity & 0xff, VGAREG_DAC_DATA); |
| 100 | outb(intensity & 0xff, VGAREG_DAC_DATA); |
| 101 | outb(intensity & 0xff, VGAREG_DAC_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 102 | } |
| 103 | inb(VGAREG_ACTL_RESET); |
| 104 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 105 | } |
| 106 | |
| 107 | // ------------------------------------------------------------------- |
| 108 | static void |
| 109 | biosfn_set_cursor_shape(u8 CH, u8 CL) |
| 110 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 111 | CH &= 0x3f; |
| 112 | CL &= 0x1f; |
| 113 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 114 | u16 curs = (CH << 8) + CL; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 115 | SET_BDA(cursor_type, curs); |
| 116 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 117 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
| 118 | u16 cheight = GET_BDA(char_height); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 119 | if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 120 | if (CL != (CH + 1)) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 121 | CH = ((CH + 1) * cheight / 8) - 1; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 122 | else |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 123 | CH = ((CL + 1) * cheight / 8) - 2; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 124 | CL = ((CL + 1) * cheight / 8) - 1; |
| 125 | } |
| 126 | // CTRC regs 0x0a and 0x0b |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 127 | u16 crtc_addr = GET_BDA(crtc_address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 128 | outb(0x0a, crtc_addr); |
| 129 | outb(CH, crtc_addr + 1); |
| 130 | outb(0x0b, crtc_addr); |
| 131 | outb(CL, crtc_addr + 1); |
| 132 | } |
| 133 | |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 134 | static u16 |
| 135 | biosfn_get_cursor_shape(u8 page) |
| 136 | { |
| 137 | if (page > 7) |
| 138 | return 0; |
| 139 | // FIXME should handle VGA 14/16 lines |
| 140 | return GET_BDA(cursor_type); |
| 141 | } |
| 142 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 143 | // ------------------------------------------------------------------- |
| 144 | static void |
| 145 | biosfn_set_cursor_pos(u8 page, u16 cursor) |
| 146 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 147 | // Should not happen... |
| 148 | if (page > 7) |
| 149 | return; |
| 150 | |
| 151 | // Bios cursor pos |
| 152 | SET_BDA(cursor_pos[page], cursor); |
| 153 | |
| 154 | // Set the hardware cursor |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 155 | u8 current = GET_BDA(video_page); |
| 156 | if (page != current) |
| 157 | return; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 158 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 159 | // Get the dimensions |
| 160 | u16 nbcols = GET_BDA(video_cols); |
| 161 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 162 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 163 | u8 xcurs = cursor & 0x00ff; |
| 164 | u8 ycurs = (cursor & 0xff00) >> 8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 165 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 166 | // Calculate the address knowing nbcols nbrows and page num |
| 167 | u16 address = SCREEN_IO_START(nbcols, nbrows, page) + xcurs + ycurs * nbcols; |
| 168 | |
| 169 | // CRTC regs 0x0e and 0x0f |
| 170 | u16 crtc_addr = GET_BDA(crtc_address); |
| 171 | outb(0x0e, crtc_addr); |
| 172 | outb((address & 0xff00) >> 8, crtc_addr + 1); |
| 173 | outb(0x0f, crtc_addr); |
| 174 | outb(address & 0x00ff, crtc_addr + 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 177 | static u16 |
| 178 | biosfn_get_cursor_pos(u8 page) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 179 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 180 | if (page > 7) |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 181 | return 0; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 182 | // FIXME should handle VGA 14/16 lines |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 183 | return GET_BDA(cursor_pos[page]); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | // ------------------------------------------------------------------- |
| 187 | static void |
| 188 | biosfn_set_active_page(u8 page) |
| 189 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 190 | if (page > 7) |
| 191 | return; |
| 192 | |
| 193 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 194 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 195 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 196 | return; |
| 197 | |
| 198 | // Get pos curs pos for the right page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 199 | u16 cursor = biosfn_get_cursor_pos(page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 200 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 201 | u16 address; |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 202 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 203 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 204 | u16 nbcols = GET_BDA(video_cols); |
| 205 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 206 | |
| 207 | // Calculate the address knowing nbcols nbrows and page num |
| 208 | address = SCREEN_MEM_START(nbcols, nbrows, page); |
| 209 | SET_BDA(video_pagestart, address); |
| 210 | |
| 211 | // Start address |
| 212 | address = SCREEN_IO_START(nbcols, nbrows, page); |
| 213 | } else { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 214 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 215 | address = page * GET_GLOBAL(vparam_g->slength); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | // CRTC regs 0x0c and 0x0d |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 219 | u16 crtc_addr = GET_BDA(crtc_address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 220 | outb(0x0c, crtc_addr); |
| 221 | outb((address & 0xff00) >> 8, crtc_addr + 1); |
| 222 | outb(0x0d, crtc_addr); |
| 223 | outb(address & 0x00ff, crtc_addr + 1); |
| 224 | |
| 225 | // And change the BIOS page |
| 226 | SET_BDA(video_page, page); |
| 227 | |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 228 | dprintf(1, "Set active page %02x address %04x\n", page, address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 229 | |
| 230 | // Display the cursor, now the page is active |
| 231 | biosfn_set_cursor_pos(page, cursor); |
| 232 | } |
| 233 | |
| 234 | static void |
| 235 | biosfn_set_video_mode(u8 mode) |
| 236 | { // mode: Bit 7 is 1 if no clear screen |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 237 | if (CONFIG_CIRRUS) |
| 238 | cirrus_set_video_mode(mode); |
| 239 | |
| 240 | #ifdef VBE |
| 241 | if (vbe_has_vbe_display()) |
| 242 | dispi_set_enable(VBE_DISPI_DISABLED); |
| 243 | #endif |
| 244 | |
| 245 | // The real mode |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 246 | u8 noclearmem = mode & 0x80; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 247 | mode = mode & 0x7f; |
| 248 | |
| 249 | // find the entry in the video modes |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 250 | struct vgamode_s *vmode_g = find_vga_entry(mode); |
| 251 | dprintf(1, "mode search %02x found %p\n", mode, vmode_g); |
| 252 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 253 | return; |
| 254 | |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 255 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 256 | u16 twidth = GET_GLOBAL(vparam_g->twidth); |
| 257 | u16 theightm1 = GET_GLOBAL(vparam_g->theightm1); |
| 258 | u16 cheight = GET_GLOBAL(vparam_g->cheight); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 259 | |
| 260 | // Read the bios mode set control |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 261 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 262 | |
| 263 | // Then we know the number of lines |
| 264 | // FIXME |
| 265 | |
| 266 | // if palette loading (bit 3 of modeset ctl = 0) |
| 267 | if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 268 | outb(GET_GLOBAL(vmode_g->pelmask), VGAREG_PEL_MASK); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 269 | |
| 270 | // Set the whole dac always, from 0 |
| 271 | outb(0x00, VGAREG_DAC_WRITE_ADDRESS); |
| 272 | |
| 273 | // From which palette |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 274 | u8 *palette_g = GET_GLOBAL(vmode_g->dac); |
| 275 | u16 palsize = GET_GLOBAL(vmode_g->dacsize); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 276 | // Always 256*3 values |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 277 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 278 | for (i = 0; i < 0x0100; i++) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 279 | if (i <= palsize) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 280 | outb(GET_GLOBAL(palette_g[(i * 3) + 0]), VGAREG_DAC_DATA); |
| 281 | outb(GET_GLOBAL(palette_g[(i * 3) + 1]), VGAREG_DAC_DATA); |
| 282 | outb(GET_GLOBAL(palette_g[(i * 3) + 2]), VGAREG_DAC_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 283 | } else { |
| 284 | outb(0, VGAREG_DAC_DATA); |
| 285 | outb(0, VGAREG_DAC_DATA); |
| 286 | outb(0, VGAREG_DAC_DATA); |
| 287 | } |
| 288 | } |
| 289 | if ((modeset_ctl & 0x02) == 0x02) |
| 290 | biosfn_perform_gray_scale_summing(0x00, 0x100); |
| 291 | } |
| 292 | // Reset Attribute Ctl flip-flop |
| 293 | inb(VGAREG_ACTL_RESET); |
| 294 | |
| 295 | // Set Attribute Ctl |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 296 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 297 | for (i = 0; i <= 0x13; i++) { |
| 298 | outb(i, VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 299 | outb(GET_GLOBAL(vparam_g->actl_regs[i]), VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 300 | } |
| 301 | outb(0x14, VGAREG_ACTL_ADDRESS); |
| 302 | outb(0x00, VGAREG_ACTL_WRITE_DATA); |
| 303 | |
| 304 | // Set Sequencer Ctl |
| 305 | outb(0, VGAREG_SEQU_ADDRESS); |
| 306 | outb(0x03, VGAREG_SEQU_DATA); |
| 307 | for (i = 1; i <= 4; i++) { |
| 308 | outb(i, VGAREG_SEQU_ADDRESS); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 309 | outb(GET_GLOBAL(vparam_g->sequ_regs[i - 1]), VGAREG_SEQU_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | // Set Grafx Ctl |
| 313 | for (i = 0; i <= 8; i++) { |
| 314 | outb(i, VGAREG_GRDC_ADDRESS); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 315 | outb(GET_GLOBAL(vparam_g->grdc_regs[i]), VGAREG_GRDC_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | // Set CRTC address VGA or MDA |
| 319 | u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS; |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 320 | if (GET_GLOBAL(vmode_g->memmodel) == MTEXT) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 321 | crtc_addr = VGAREG_MDA_CRTC_ADDRESS; |
| 322 | |
| 323 | // Disable CRTC write protection |
| 324 | outw(0x0011, crtc_addr); |
| 325 | // Set CRTC regs |
| 326 | for (i = 0; i <= 0x18; i++) { |
| 327 | outb(i, crtc_addr); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 328 | outb(GET_GLOBAL(vparam_g->crtc_regs[i]), crtc_addr + 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | // Set the misc register |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 332 | outb(GET_GLOBAL(vparam_g->miscreg), VGAREG_WRITE_MISC_OUTPUT); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 333 | |
| 334 | // Enable video |
| 335 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 336 | inb(VGAREG_ACTL_RESET); |
| 337 | |
| 338 | if (noclearmem == 0x00) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 339 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
| 340 | memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0720, 32*1024); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 341 | } else { |
| 342 | if (mode < 0x0d) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 343 | memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 32*1024); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 344 | } else { |
| 345 | outb(0x02, VGAREG_SEQU_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 346 | u8 mmask = inb(VGAREG_SEQU_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 347 | outb(0x0f, VGAREG_SEQU_DATA); // all planes |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 348 | memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 64*1024); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 349 | outb(mmask, VGAREG_SEQU_DATA); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | // Set the BIOS mem |
| 354 | SET_BDA(video_mode, mode); |
| 355 | SET_BDA(video_cols, twidth); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 356 | SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 357 | SET_BDA(crtc_address, crtc_addr); |
| 358 | SET_BDA(video_rows, theightm1); |
| 359 | SET_BDA(char_height, cheight); |
| 360 | SET_BDA(video_ctl, (0x60 | noclearmem)); |
| 361 | SET_BDA(video_switches, 0xF9); |
| 362 | SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f); |
| 363 | |
| 364 | // FIXME We nearly have the good tables. to be reworked |
| 365 | SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now |
| 366 | SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table); |
| 367 | SET_BDA(video_savetable_seg, 0xc000); |
| 368 | |
| 369 | // FIXME |
| 370 | SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but... |
| 371 | SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but... |
| 372 | |
| 373 | // Set cursor shape |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 374 | if (GET_GLOBAL(vmode_g->class) == TEXT) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 375 | biosfn_set_cursor_shape(0x06, 0x07); |
| 376 | // Set cursor pos for page 0..7 |
| 377 | for (i = 0; i < 8; i++) |
| 378 | biosfn_set_cursor_pos(i, 0x0000); |
| 379 | |
| 380 | // Set active page 0 |
| 381 | biosfn_set_active_page(0x00); |
| 382 | |
| 383 | // Write the fonts in memory |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 384 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 385 | call16_vgaint(0x1104, 0); |
| 386 | call16_vgaint(0x1103, 0); |
| 387 | } |
| 388 | // Set the ints 0x1F and 0x43 |
| 389 | SET_IVT(0x1f, 0xC000, (u32)&vgafont8[128 * 8]); |
| 390 | |
| 391 | switch (cheight) { |
| 392 | case 8: |
| 393 | SET_IVT(0x43, 0xC000, (u32)vgafont8); |
| 394 | break; |
| 395 | case 14: |
| 396 | SET_IVT(0x43, 0xC000, (u32)vgafont14); |
| 397 | break; |
| 398 | case 16: |
| 399 | SET_IVT(0x43, 0xC000, (u32)vgafont16); |
| 400 | break; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | // ------------------------------------------------------------------- |
| 405 | static void |
| 406 | vgamem_copy_pl4(u8 xstart, u8 ysrc, u8 ydest, u8 cols, u8 nbcols, |
| 407 | u8 cheight) |
| 408 | { |
| 409 | u16 src = ysrc * cheight * nbcols + xstart; |
| 410 | u16 dest = ydest * cheight * nbcols + xstart; |
| 411 | outw(0x0105, VGAREG_GRDC_ADDRESS); |
| 412 | u8 i; |
| 413 | for (i = 0; i < cheight; i++) |
| 414 | memcpy_far(0xa000, (void*)(dest + i * nbcols) |
| 415 | , 0xa000, (void*)(src + i * nbcols), cols); |
| 416 | outw(0x0005, VGAREG_GRDC_ADDRESS); |
| 417 | } |
| 418 | |
| 419 | // ------------------------------------------------------------------- |
| 420 | static void |
| 421 | vgamem_fill_pl4(u8 xstart, u8 ystart, u8 cols, u8 nbcols, u8 cheight, |
| 422 | u8 attr) |
| 423 | { |
| 424 | u16 dest = ystart * cheight * nbcols + xstart; |
| 425 | outw(0x0205, VGAREG_GRDC_ADDRESS); |
| 426 | u8 i; |
| 427 | for (i = 0; i < cheight; i++) |
| 428 | memset_far(0xa000, (void*)(dest + i * nbcols), attr, cols); |
| 429 | outw(0x0005, VGAREG_GRDC_ADDRESS); |
| 430 | } |
| 431 | |
| 432 | // ------------------------------------------------------------------- |
| 433 | static void |
| 434 | vgamem_copy_cga(u8 xstart, u8 ysrc, u8 ydest, u8 cols, u8 nbcols, |
| 435 | u8 cheight) |
| 436 | { |
| 437 | u16 src = ((ysrc * cheight * nbcols) >> 1) + xstart; |
| 438 | u16 dest = ((ydest * cheight * nbcols) >> 1) + xstart; |
| 439 | u8 i; |
| 440 | for (i = 0; i < cheight; i++) |
| 441 | if (i & 1) |
| 442 | memcpy_far(0xb800, (void*)(0x2000 + dest + (i >> 1) * nbcols) |
| 443 | , 0xb800, (void*)(0x2000 + src + (i >> 1) * nbcols) |
| 444 | , cols); |
| 445 | else |
| 446 | memcpy_far(0xb800, (void*)(dest + (i >> 1) * nbcols) |
| 447 | , 0xb800, (void*)(src + (i >> 1) * nbcols), cols); |
| 448 | } |
| 449 | |
| 450 | // ------------------------------------------------------------------- |
| 451 | static void |
| 452 | vgamem_fill_cga(u8 xstart, u8 ystart, u8 cols, u8 nbcols, u8 cheight, |
| 453 | u8 attr) |
| 454 | { |
| 455 | u16 dest = ((ystart * cheight * nbcols) >> 1) + xstart; |
| 456 | u8 i; |
| 457 | for (i = 0; i < cheight; i++) |
| 458 | if (i & 1) |
| 459 | memset_far(0xb800, (void*)(0x2000 + dest + (i >> 1) * nbcols) |
| 460 | , attr, cols); |
| 461 | else |
| 462 | memset_far(0xb800, (void*)(dest + (i >> 1) * nbcols), attr, cols); |
| 463 | } |
| 464 | |
| 465 | // ------------------------------------------------------------------- |
| 466 | static void |
| 467 | biosfn_scroll(u8 nblines, u8 attr, u8 rul, u8 cul, u8 rlr, u8 clr, u8 page, |
| 468 | u8 dir) |
| 469 | { |
| 470 | // page == 0xFF if current |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 471 | if (rul > rlr) |
| 472 | return; |
| 473 | if (cul > clr) |
| 474 | return; |
| 475 | |
| 476 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 477 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 478 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 479 | return; |
| 480 | |
| 481 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 482 | u16 nbrows = GET_BDA(video_rows) + 1; |
| 483 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 484 | |
| 485 | // Get the current page |
| 486 | if (page == 0xFF) |
| 487 | page = GET_BDA(video_page); |
| 488 | |
| 489 | if (rlr >= nbrows) |
| 490 | rlr = nbrows - 1; |
| 491 | if (clr >= nbcols) |
| 492 | clr = nbcols - 1; |
| 493 | if (nblines > nbrows) |
| 494 | nblines = 0; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 495 | u8 cols = clr - cul + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 496 | |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 497 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 498 | // Compute the address |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 499 | void *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page)); |
Kevin O'Connor | a5288ff | 2009-05-13 22:25:24 -0400 | [diff] [blame] | 500 | dprintf(3, "Scroll, address %p (%d %d %02x)\n" |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 501 | , address_far, nbrows, nbcols, page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 502 | |
| 503 | if (nblines == 0 && rul == 0 && cul == 0 && rlr == nbrows - 1 |
| 504 | && clr == nbcols - 1) { |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 505 | memset16_far(GET_GLOBAL(vmode_g->sstart), address_far |
Kevin O'Connor | a5288ff | 2009-05-13 22:25:24 -0400 | [diff] [blame] | 506 | , (u16)attr * 0x100 + ' ', nbrows * nbcols * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 507 | } else { // if Scroll up |
| 508 | if (dir == SCROLL_UP) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 509 | u16 i; |
| 510 | for (i = rul; i <= rlr; i++) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 511 | if ((i + nblines > rlr) || (nblines == 0)) |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 512 | memset16_far(GET_GLOBAL(vmode_g->sstart) |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 513 | , address_far + (i * nbcols + cul) * 2 |
Kevin O'Connor | a5288ff | 2009-05-13 22:25:24 -0400 | [diff] [blame] | 514 | , (u16)attr * 0x100 + ' ', cols * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 515 | else |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 516 | memcpy16_far(GET_GLOBAL(vmode_g->sstart) |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 517 | , address_far + (i * nbcols + cul) * 2 |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 518 | , GET_GLOBAL(vmode_g->sstart) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 519 | , (void*)(((i + nblines) * nbcols + cul) * 2) |
Kevin O'Connor | a5288ff | 2009-05-13 22:25:24 -0400 | [diff] [blame] | 520 | , cols * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 521 | } else { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 522 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 523 | for (i = rlr; i >= rul; i--) { |
| 524 | if ((i < rul + nblines) || (nblines == 0)) |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 525 | memset16_far(GET_GLOBAL(vmode_g->sstart) |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 526 | , address_far + (i * nbcols + cul) * 2 |
Kevin O'Connor | a5288ff | 2009-05-13 22:25:24 -0400 | [diff] [blame] | 527 | , (u16)attr * 0x100 + ' ', cols * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 528 | else |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 529 | memcpy16_far(GET_GLOBAL(vmode_g->sstart) |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 530 | , address_far + (i * nbcols + cul) * 2 |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 531 | , GET_GLOBAL(vmode_g->sstart) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 532 | , (void*)(((i - nblines) * nbcols + cul) * 2) |
Kevin O'Connor | a5288ff | 2009-05-13 22:25:24 -0400 | [diff] [blame] | 533 | , cols * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 534 | if (i > rlr) |
| 535 | break; |
| 536 | } |
| 537 | } |
| 538 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 539 | return; |
| 540 | } |
| 541 | |
| 542 | // FIXME gfx mode not complete |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 543 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 544 | u8 cheight = GET_GLOBAL(vparam_g->cheight); |
| 545 | switch (GET_GLOBAL(vmode_g->memmodel)) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 546 | case PLANAR4: |
| 547 | case PLANAR1: |
| 548 | if (nblines == 0 && rul == 0 && cul == 0 && rlr == nbrows - 1 |
| 549 | && clr == nbcols - 1) { |
| 550 | outw(0x0205, VGAREG_GRDC_ADDRESS); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 551 | memset_far(GET_GLOBAL(vmode_g->sstart), 0, attr, |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 552 | nbrows * nbcols * cheight); |
| 553 | outw(0x0005, VGAREG_GRDC_ADDRESS); |
| 554 | } else { // if Scroll up |
| 555 | if (dir == SCROLL_UP) { |
| 556 | u16 i; |
| 557 | for (i = rul; i <= rlr; i++) |
| 558 | if ((i + nblines > rlr) || (nblines == 0)) |
| 559 | vgamem_fill_pl4(cul, i, cols, nbcols, cheight, |
| 560 | attr); |
| 561 | else |
| 562 | vgamem_copy_pl4(cul, i + nblines, i, cols, |
| 563 | nbcols, cheight); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 564 | } else { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 565 | u16 i; |
| 566 | for (i = rlr; i >= rul; i--) { |
| 567 | if ((i < rul + nblines) || (nblines == 0)) |
| 568 | vgamem_fill_pl4(cul, i, cols, nbcols, cheight, |
| 569 | attr); |
| 570 | else |
| 571 | vgamem_copy_pl4(cul, i, i - nblines, cols, |
| 572 | nbcols, cheight); |
| 573 | if (i > rlr) |
| 574 | break; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 575 | } |
| 576 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 577 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 578 | break; |
| 579 | case CGA: { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 580 | u8 bpp = GET_GLOBAL(vmode_g->pixbits); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 581 | if (nblines == 0 && rul == 0 && cul == 0 && rlr == nbrows - 1 |
| 582 | && clr == nbcols - 1) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 583 | memset_far(GET_GLOBAL(vmode_g->sstart), 0, attr, |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 584 | nbrows * nbcols * cheight * bpp); |
| 585 | } else { |
| 586 | if (bpp == 2) { |
| 587 | cul <<= 1; |
| 588 | cols <<= 1; |
| 589 | nbcols <<= 1; |
| 590 | } |
| 591 | // if Scroll up |
| 592 | if (dir == SCROLL_UP) { |
| 593 | u16 i; |
| 594 | for (i = rul; i <= rlr; i++) |
| 595 | if ((i + nblines > rlr) || (nblines == 0)) |
| 596 | vgamem_fill_cga(cul, i, cols, nbcols, cheight, |
| 597 | attr); |
| 598 | else |
| 599 | vgamem_copy_cga(cul, i + nblines, i, cols, |
| 600 | nbcols, cheight); |
| 601 | } else { |
| 602 | u16 i; |
| 603 | for (i = rlr; i >= rul; i--) { |
| 604 | if ((i < rul + nblines) || (nblines == 0)) |
| 605 | vgamem_fill_cga(cul, i, cols, nbcols, cheight, |
| 606 | attr); |
| 607 | else |
| 608 | vgamem_copy_cga(cul, i, i - nblines, cols, |
| 609 | nbcols, cheight); |
| 610 | if (i > rlr) |
| 611 | break; |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | break; |
| 616 | } |
| 617 | default: |
| 618 | dprintf(1, "Scroll in graphics mode\n"); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
| 622 | // ------------------------------------------------------------------- |
| 623 | static void |
| 624 | biosfn_read_char_attr(u8 page, u16 *car) |
| 625 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 626 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 627 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 628 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 629 | return; |
| 630 | |
| 631 | // Get the cursor pos for the page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 632 | u16 cursor = biosfn_get_cursor_pos(page); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 633 | u8 xcurs = cursor & 0x00ff; |
| 634 | u8 ycurs = (cursor & 0xff00) >> 8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 635 | |
| 636 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 637 | u16 nbrows = GET_BDA(video_rows) + 1; |
| 638 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 639 | |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 640 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 641 | // Compute the address |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 642 | u16 *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page) |
| 643 | + (xcurs + ycurs * nbcols) * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 644 | |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 645 | *car = GET_FARVAR(GET_GLOBAL(vmode_g->sstart), *address_far); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 646 | } else { |
| 647 | // FIXME gfx mode |
Kevin O'Connor | 6ace78f | 2009-05-14 19:24:49 -0400 | [diff] [blame] | 648 | dprintf(1, "Read char in graphics mode\n"); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | // ------------------------------------------------------------------- |
| 653 | static void |
| 654 | write_gfx_char_pl4(u8 car, u8 attr, u8 xcurs, u8 ycurs, u8 nbcols, |
| 655 | u8 cheight) |
| 656 | { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 657 | u8 *fdata_g; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 658 | switch (cheight) { |
| 659 | case 14: |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 660 | fdata_g = vgafont14; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 661 | break; |
| 662 | case 16: |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 663 | fdata_g = vgafont16; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 664 | break; |
| 665 | default: |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 666 | fdata_g = vgafont8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 667 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 668 | u16 addr = xcurs + ycurs * cheight * nbcols; |
| 669 | u16 src = car * cheight; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 670 | outw(0x0f02, VGAREG_SEQU_ADDRESS); |
| 671 | outw(0x0205, VGAREG_GRDC_ADDRESS); |
| 672 | if (attr & 0x80) |
| 673 | outw(0x1803, VGAREG_GRDC_ADDRESS); |
| 674 | else |
| 675 | outw(0x0003, VGAREG_GRDC_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 676 | u8 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 677 | for (i = 0; i < cheight; i++) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 678 | u8 *dest_far = (void*)(addr + i * nbcols); |
| 679 | u8 j; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 680 | for (j = 0; j < 8; j++) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 681 | u8 mask = 0x80 >> j; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 682 | outw((mask << 8) | 0x08, VGAREG_GRDC_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 683 | GET_FARVAR(0xa000, *dest_far); |
| 684 | if (GET_GLOBAL(fdata_g[src + i]) & mask) |
| 685 | SET_FARVAR(0xa000, *dest_far, attr & 0x0f); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 686 | else |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 687 | SET_FARVAR(0xa000, *dest_far, 0x00); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | outw(0xff08, VGAREG_GRDC_ADDRESS); |
| 691 | outw(0x0005, VGAREG_GRDC_ADDRESS); |
| 692 | outw(0x0003, VGAREG_GRDC_ADDRESS); |
| 693 | } |
| 694 | |
| 695 | // ------------------------------------------------------------------- |
| 696 | static void |
| 697 | write_gfx_char_cga(u8 car, u8 attr, u8 xcurs, u8 ycurs, u8 nbcols, u8 bpp) |
| 698 | { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 699 | u8 *fdata_g = vgafont8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 700 | u16 addr = (xcurs * bpp) + ycurs * 320; |
| 701 | u16 src = car * 8; |
| 702 | u8 i; |
| 703 | for (i = 0; i < 8; i++) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 704 | u8 *dest_far = (void*)(addr + (i >> 1) * 80); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 705 | if (i & 1) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 706 | dest_far += 0x2000; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 707 | u8 mask = 0x80; |
| 708 | if (bpp == 1) { |
| 709 | u8 data = 0; |
| 710 | if (attr & 0x80) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 711 | data = GET_FARVAR(0xb800, *dest_far); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 712 | u8 j; |
| 713 | for (j = 0; j < 8; j++) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 714 | if (GET_GLOBAL(fdata_g[src + i]) & mask) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 715 | if (attr & 0x80) |
| 716 | data ^= (attr & 0x01) << (7 - j); |
| 717 | else |
| 718 | data |= (attr & 0x01) << (7 - j); |
| 719 | } |
| 720 | mask >>= 1; |
| 721 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 722 | SET_FARVAR(0xb800, *dest_far, data); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 723 | } else { |
| 724 | while (mask > 0) { |
| 725 | u8 data = 0; |
| 726 | if (attr & 0x80) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 727 | data = GET_FARVAR(0xb800, *dest_far); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 728 | u8 j; |
| 729 | for (j = 0; j < 4; j++) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 730 | if (GET_GLOBAL(fdata_g[src + i]) & mask) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 731 | if (attr & 0x80) |
| 732 | data ^= (attr & 0x03) << ((3 - j) * 2); |
| 733 | else |
| 734 | data |= (attr & 0x03) << ((3 - j) * 2); |
| 735 | } |
| 736 | mask >>= 1; |
| 737 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 738 | SET_FARVAR(0xb800, *dest_far, data); |
| 739 | dest_far += 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | // ------------------------------------------------------------------- |
| 746 | static void |
| 747 | write_gfx_char_lin(u8 car, u8 attr, u8 xcurs, u8 ycurs, u8 nbcols) |
| 748 | { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 749 | u8 *fdata_g = vgafont8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 750 | u16 addr = xcurs * 8 + ycurs * nbcols * 64; |
| 751 | u16 src = car * 8; |
| 752 | u8 i; |
| 753 | for (i = 0; i < 8; i++) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 754 | u8 *dest_far = (void*)(addr + i * nbcols * 8); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 755 | u8 mask = 0x80; |
| 756 | u8 j; |
| 757 | for (j = 0; j < 8; j++) { |
| 758 | u8 data = 0x00; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 759 | if (GET_GLOBAL(fdata_g[src + i]) & mask) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 760 | data = attr; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 761 | SET_FARVAR(0xa000, dest_far[j], data); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 762 | mask >>= 1; |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | // ------------------------------------------------------------------- |
| 768 | static void |
| 769 | biosfn_write_char_attr(u8 car, u8 page, u8 attr, u16 count) |
| 770 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 771 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 772 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 773 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 774 | return; |
| 775 | |
| 776 | // Get the cursor pos for the page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 777 | u16 cursor = biosfn_get_cursor_pos(page); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 778 | u8 xcurs = cursor & 0x00ff; |
| 779 | u8 ycurs = (cursor & 0xff00) >> 8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 780 | |
| 781 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 782 | u16 nbrows = GET_BDA(video_rows) + 1; |
| 783 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 784 | |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 785 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 786 | // Compute the address |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 787 | void *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page) |
| 788 | + (xcurs + ycurs * nbcols) * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 789 | |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 790 | u16 dummy = ((u16)attr << 8) + car; |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 791 | memset16_far(GET_GLOBAL(vmode_g->sstart), address_far, dummy, count * 2); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 792 | return; |
| 793 | } |
| 794 | |
| 795 | // FIXME gfx mode not complete |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 796 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 797 | u8 cheight = GET_GLOBAL(vparam_g->cheight); |
| 798 | u8 bpp = GET_GLOBAL(vmode_g->pixbits); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 799 | while ((count-- > 0) && (xcurs < nbcols)) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 800 | switch (GET_GLOBAL(vmode_g->memmodel)) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 801 | case PLANAR4: |
| 802 | case PLANAR1: |
| 803 | write_gfx_char_pl4(car, attr, xcurs, ycurs, nbcols, |
| 804 | cheight); |
| 805 | break; |
| 806 | case CGA: |
| 807 | write_gfx_char_cga(car, attr, xcurs, ycurs, nbcols, bpp); |
| 808 | break; |
| 809 | case LINEAR8: |
| 810 | write_gfx_char_lin(car, attr, xcurs, ycurs, nbcols); |
| 811 | break; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 812 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 813 | xcurs++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
| 817 | // ------------------------------------------------------------------- |
| 818 | static void |
| 819 | biosfn_write_char_only(u8 car, u8 page, u8 attr, u16 count) |
| 820 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 821 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 822 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 823 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 824 | return; |
| 825 | |
| 826 | // Get the cursor pos for the page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 827 | u16 cursor = biosfn_get_cursor_pos(page); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 828 | u8 xcurs = cursor & 0x00ff; |
| 829 | u8 ycurs = (cursor & 0xff00) >> 8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 830 | |
| 831 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 832 | u16 nbrows = GET_BDA(video_rows) + 1; |
| 833 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 834 | |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 835 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 836 | // Compute the address |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 837 | u8 *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page) |
| 838 | + (xcurs + ycurs * nbcols) * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 839 | while (count-- > 0) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 840 | SET_FARVAR(GET_GLOBAL(vmode_g->sstart), *address_far, car); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 841 | address_far += 2; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 842 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 843 | return; |
| 844 | } |
| 845 | |
| 846 | // FIXME gfx mode not complete |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 847 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 848 | u8 cheight = GET_GLOBAL(vparam_g->cheight); |
| 849 | u8 bpp = GET_GLOBAL(vmode_g->pixbits); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 850 | while ((count-- > 0) && (xcurs < nbcols)) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 851 | switch (GET_GLOBAL(vmode_g->memmodel)) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 852 | case PLANAR4: |
| 853 | case PLANAR1: |
| 854 | write_gfx_char_pl4(car, attr, xcurs, ycurs, nbcols, |
| 855 | cheight); |
| 856 | break; |
| 857 | case CGA: |
| 858 | write_gfx_char_cga(car, attr, xcurs, ycurs, nbcols, bpp); |
| 859 | break; |
| 860 | case LINEAR8: |
| 861 | write_gfx_char_lin(car, attr, xcurs, ycurs, nbcols); |
| 862 | break; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 863 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 864 | xcurs++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 868 | // ------------------------------------------------------------------- |
| 869 | static void |
| 870 | biosfn_set_border_color(struct bregs *regs) |
| 871 | { |
| 872 | inb(VGAREG_ACTL_RESET); |
| 873 | outb(0x00, VGAREG_ACTL_ADDRESS); |
| 874 | u8 al = regs->bl & 0x0f; |
| 875 | if (al & 0x08) |
| 876 | al += 0x08; |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 877 | outb(al, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 878 | u8 bl = regs->bl & 0x10; |
| 879 | |
| 880 | int i; |
| 881 | for (i = 1; i < 4; i++) { |
| 882 | outb(i, VGAREG_ACTL_ADDRESS); |
| 883 | |
| 884 | al = inb(VGAREG_ACTL_READ_DATA); |
| 885 | al &= 0xef; |
| 886 | al |= bl; |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 887 | outb(al, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 888 | } |
| 889 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 890 | } |
| 891 | |
| 892 | static void |
| 893 | biosfn_set_palette(struct bregs *regs) |
| 894 | { |
| 895 | inb(VGAREG_ACTL_RESET); |
| 896 | u8 bl = regs->bl & 0x01; |
| 897 | int i; |
| 898 | for (i = 1; i < 4; i++) { |
| 899 | outb(i, VGAREG_ACTL_ADDRESS); |
| 900 | |
| 901 | u8 al = inb(VGAREG_ACTL_READ_DATA); |
| 902 | al &= 0xfe; |
| 903 | al |= bl; |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 904 | outb(al, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 905 | } |
| 906 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 907 | } |
| 908 | |
| 909 | // ------------------------------------------------------------------- |
| 910 | static void |
| 911 | biosfn_write_pixel(u8 BH, u8 AL, u16 CX, u16 DX) |
| 912 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 913 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 914 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 915 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 916 | return; |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 917 | if (GET_GLOBAL(vmode_g->class) == TEXT) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 918 | return; |
| 919 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 920 | u8 *addr_far, mask, attr, data; |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 921 | switch (GET_GLOBAL(vmode_g->memmodel)) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 922 | case PLANAR4: |
| 923 | case PLANAR1: |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 924 | addr_far = (void*)(CX / 8 + DX * GET_BDA(video_cols)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 925 | mask = 0x80 >> (CX & 0x07); |
| 926 | outw((mask << 8) | 0x08, VGAREG_GRDC_ADDRESS); |
| 927 | outw(0x0205, VGAREG_GRDC_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 928 | data = GET_FARVAR(0xa000, *addr_far); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 929 | if (AL & 0x80) |
| 930 | outw(0x1803, VGAREG_GRDC_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 931 | SET_FARVAR(0xa000, *addr_far, AL); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 932 | outw(0xff08, VGAREG_GRDC_ADDRESS); |
| 933 | outw(0x0005, VGAREG_GRDC_ADDRESS); |
| 934 | outw(0x0003, VGAREG_GRDC_ADDRESS); |
| 935 | break; |
| 936 | case CGA: |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 937 | if (GET_GLOBAL(vmode_g->pixbits) == 2) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 938 | addr_far = (void*)((CX >> 2) + (DX >> 1) * 80); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 939 | else |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 940 | addr_far = (void*)((CX >> 3) + (DX >> 1) * 80); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 941 | if (DX & 1) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 942 | addr_far += 0x2000; |
| 943 | data = GET_FARVAR(0xb800, *addr_far); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 944 | if (GET_GLOBAL(vmode_g->pixbits) == 2) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 945 | attr = (AL & 0x03) << ((3 - (CX & 0x03)) * 2); |
| 946 | mask = 0x03 << ((3 - (CX & 0x03)) * 2); |
| 947 | } else { |
| 948 | attr = (AL & 0x01) << (7 - (CX & 0x07)); |
| 949 | mask = 0x01 << (7 - (CX & 0x07)); |
| 950 | } |
| 951 | if (AL & 0x80) { |
| 952 | data ^= attr; |
| 953 | } else { |
| 954 | data &= ~mask; |
| 955 | data |= attr; |
| 956 | } |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 957 | SET_FARVAR(0xb800, *addr_far, data); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 958 | break; |
| 959 | case LINEAR8: |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 960 | addr_far = (void*)(CX + DX * (GET_BDA(video_cols) * 8)); |
| 961 | SET_FARVAR(0xa000, *addr_far, AL); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 962 | break; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
| 966 | // ------------------------------------------------------------------- |
| 967 | static void |
| 968 | biosfn_read_pixel(u8 BH, u16 CX, u16 DX, u16 *AX) |
| 969 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 970 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 971 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 972 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 973 | return; |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 974 | if (GET_GLOBAL(vmode_g->class) == TEXT) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 975 | return; |
| 976 | |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 977 | u8 *addr_far, mask, attr=0, data, i; |
| 978 | switch (GET_GLOBAL(vmode_g->memmodel)) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 979 | case PLANAR4: |
| 980 | case PLANAR1: |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 981 | addr_far = (void*)(CX / 8 + DX * GET_BDA(video_cols)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 982 | mask = 0x80 >> (CX & 0x07); |
| 983 | attr = 0x00; |
| 984 | for (i = 0; i < 4; i++) { |
| 985 | outw((i << 8) | 0x04, VGAREG_GRDC_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 986 | data = GET_FARVAR(0xa000, *addr_far) & mask; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 987 | if (data > 0) |
| 988 | attr |= (0x01 << i); |
| 989 | } |
| 990 | break; |
| 991 | case CGA: |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 992 | addr_far = (void*)((CX >> 2) + (DX >> 1) * 80); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 993 | if (DX & 1) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 994 | addr_far += 0x2000; |
| 995 | data = GET_FARVAR(0xb800, *addr_far); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 996 | if (GET_GLOBAL(vmode_g->pixbits) == 2) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 997 | attr = (data >> ((3 - (CX & 0x03)) * 2)) & 0x03; |
| 998 | else |
| 999 | attr = (data >> (7 - (CX & 0x07))) & 0x01; |
| 1000 | break; |
| 1001 | case LINEAR8: |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1002 | addr_far = (void*)(CX + DX * (GET_BDA(video_cols) * 8)); |
| 1003 | attr = GET_FARVAR(0xa000, *addr_far); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1004 | break; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1005 | } |
| 1006 | *AX = (*AX & 0xff00) | attr; |
| 1007 | } |
| 1008 | |
| 1009 | // ------------------------------------------------------------------- |
| 1010 | static void |
| 1011 | biosfn_write_teletype(u8 car, u8 page, u8 attr, u8 flag) |
| 1012 | { // flag = WITH_ATTR / NO_ATTR |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1013 | // special case if page is 0xff, use current page |
| 1014 | if (page == 0xff) |
| 1015 | page = GET_BDA(video_page); |
| 1016 | |
| 1017 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 1018 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 1019 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1020 | return; |
| 1021 | |
| 1022 | // Get the cursor pos for the page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 1023 | u16 cursor = biosfn_get_cursor_pos(page); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1024 | u8 xcurs = cursor & 0x00ff; |
| 1025 | u8 ycurs = (cursor & 0xff00) >> 8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1026 | |
| 1027 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1028 | u16 nbrows = GET_BDA(video_rows) + 1; |
| 1029 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1030 | |
| 1031 | switch (car) { |
| 1032 | case 7: |
| 1033 | //FIXME should beep |
| 1034 | break; |
| 1035 | |
| 1036 | case 8: |
| 1037 | if (xcurs > 0) |
| 1038 | xcurs--; |
| 1039 | break; |
| 1040 | |
| 1041 | case '\r': |
| 1042 | xcurs = 0; |
| 1043 | break; |
| 1044 | |
| 1045 | case '\n': |
| 1046 | ycurs++; |
| 1047 | break; |
| 1048 | |
| 1049 | case '\t': |
| 1050 | do { |
| 1051 | biosfn_write_teletype(' ', page, attr, flag); |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 1052 | cursor = biosfn_get_cursor_pos(page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1053 | xcurs = cursor & 0x00ff; |
| 1054 | ycurs = (cursor & 0xff00) >> 8; |
| 1055 | } while (xcurs % 8 == 0); |
| 1056 | break; |
| 1057 | |
| 1058 | default: |
| 1059 | |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 1060 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1061 | // Compute the address |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1062 | u8 *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, page) |
| 1063 | + (xcurs + ycurs * nbcols) * 2); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1064 | // Write the char |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 1065 | SET_FARVAR(GET_GLOBAL(vmode_g->sstart), address_far[0], car); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1066 | if (flag == WITH_ATTR) |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 1067 | SET_FARVAR(GET_GLOBAL(vmode_g->sstart), address_far[1], attr); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1068 | } else { |
| 1069 | // FIXME gfx mode not complete |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 1070 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 1071 | u8 cheight = GET_GLOBAL(vparam_g->cheight); |
| 1072 | u8 bpp = GET_GLOBAL(vmode_g->pixbits); |
| 1073 | switch (GET_GLOBAL(vmode_g->memmodel)) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1074 | case PLANAR4: |
| 1075 | case PLANAR1: |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 1076 | write_gfx_char_pl4(car, attr, xcurs, ycurs, nbcols, cheight); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1077 | break; |
| 1078 | case CGA: |
| 1079 | write_gfx_char_cga(car, attr, xcurs, ycurs, nbcols, bpp); |
| 1080 | break; |
| 1081 | case LINEAR8: |
| 1082 | write_gfx_char_lin(car, attr, xcurs, ycurs, nbcols); |
| 1083 | break; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | xcurs++; |
| 1087 | } |
| 1088 | |
| 1089 | // Do we need to wrap ? |
| 1090 | if (xcurs == nbcols) { |
| 1091 | xcurs = 0; |
| 1092 | ycurs++; |
| 1093 | } |
| 1094 | // Do we need to scroll ? |
| 1095 | if (ycurs == nbrows) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 1096 | if (GET_GLOBAL(vmode_g->class) == TEXT) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1097 | biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, page, |
| 1098 | SCROLL_UP); |
| 1099 | else |
| 1100 | biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, page, |
| 1101 | SCROLL_UP); |
| 1102 | ycurs -= 1; |
| 1103 | } |
| 1104 | // Set the cursor for the page |
| 1105 | cursor = ycurs; |
| 1106 | cursor <<= 8; |
| 1107 | cursor += xcurs; |
| 1108 | biosfn_set_cursor_pos(page, cursor); |
| 1109 | } |
| 1110 | |
| 1111 | // ------------------------------------------------------------------- |
| 1112 | static void |
| 1113 | biosfn_get_video_mode(struct bregs *regs) |
| 1114 | { |
| 1115 | regs->bh = GET_BDA(video_page); |
| 1116 | regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80); |
| 1117 | regs->ah = GET_BDA(video_cols); |
| 1118 | } |
| 1119 | |
| 1120 | // ------------------------------------------------------------------- |
| 1121 | static void |
| 1122 | biosfn_set_overscan_border_color(struct bregs *regs) |
| 1123 | { |
| 1124 | inb(VGAREG_ACTL_RESET); |
| 1125 | outb(0x11, VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 1126 | outb(regs->bh, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1127 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1128 | } |
| 1129 | |
| 1130 | // ------------------------------------------------------------------- |
| 1131 | static void |
| 1132 | biosfn_set_all_palette_reg(struct bregs *regs) |
| 1133 | { |
| 1134 | inb(VGAREG_ACTL_RESET); |
| 1135 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1136 | u8 *data_far = (u8*)(regs->dx + 0); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1137 | int i; |
| 1138 | for (i = 0; i < 0x10; i++) { |
| 1139 | outb(i, VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1140 | u8 val = GET_FARVAR(regs->es, *data_far); |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 1141 | outb(val, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1142 | data_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1143 | } |
| 1144 | outb(0x11, VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1145 | outb(GET_FARVAR(regs->es, *data_far), VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1146 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1147 | } |
| 1148 | |
| 1149 | // ------------------------------------------------------------------- |
| 1150 | static void |
| 1151 | biosfn_toggle_intensity(struct bregs *regs) |
| 1152 | { |
| 1153 | inb(VGAREG_ACTL_RESET); |
| 1154 | outb(0x10, VGAREG_ACTL_ADDRESS); |
| 1155 | u8 val = (inb(VGAREG_ACTL_READ_DATA) & 0x7f) | ((regs->bl & 0x01) << 3); |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 1156 | outb(val, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1157 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1158 | } |
| 1159 | |
| 1160 | // ------------------------------------------------------------------- |
| 1161 | void |
| 1162 | biosfn_set_single_palette_reg(u8 reg, u8 val) |
| 1163 | { |
| 1164 | inb(VGAREG_ACTL_RESET); |
| 1165 | outb(reg, VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 1166 | outb(val, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1167 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1168 | } |
| 1169 | |
| 1170 | // ------------------------------------------------------------------- |
| 1171 | u8 |
| 1172 | biosfn_get_single_palette_reg(u8 reg) |
| 1173 | { |
| 1174 | inb(VGAREG_ACTL_RESET); |
| 1175 | outb(reg, VGAREG_ACTL_ADDRESS); |
| 1176 | u8 v = inb(VGAREG_ACTL_READ_DATA); |
| 1177 | inb(VGAREG_ACTL_RESET); |
| 1178 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1179 | return v; |
| 1180 | } |
| 1181 | |
| 1182 | // ------------------------------------------------------------------- |
| 1183 | static void |
| 1184 | biosfn_read_overscan_border_color(struct bregs *regs) |
| 1185 | { |
| 1186 | inb(VGAREG_ACTL_RESET); |
| 1187 | outb(0x11, VGAREG_ACTL_ADDRESS); |
| 1188 | regs->bh = inb(VGAREG_ACTL_READ_DATA); |
| 1189 | inb(VGAREG_ACTL_RESET); |
| 1190 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1191 | } |
| 1192 | |
| 1193 | // ------------------------------------------------------------------- |
| 1194 | static void |
| 1195 | biosfn_get_all_palette_reg(struct bregs *regs) |
| 1196 | { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1197 | u8 *data_far = (u8*)(regs->dx + 0); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1198 | int i; |
| 1199 | for (i = 0; i < 0x10; i++) { |
| 1200 | inb(VGAREG_ACTL_RESET); |
| 1201 | outb(i, VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1202 | SET_FARVAR(regs->es, *data_far, inb(VGAREG_ACTL_READ_DATA)); |
| 1203 | data_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1204 | } |
| 1205 | inb(VGAREG_ACTL_RESET); |
| 1206 | outb(0x11, VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1207 | SET_FARVAR(regs->es, *data_far, inb(VGAREG_ACTL_READ_DATA)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1208 | inb(VGAREG_ACTL_RESET); |
| 1209 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1210 | } |
| 1211 | |
| 1212 | // ------------------------------------------------------------------- |
| 1213 | static void |
| 1214 | biosfn_set_single_dac_reg(struct bregs *regs) |
| 1215 | { |
| 1216 | outb(regs->bl, VGAREG_DAC_WRITE_ADDRESS); |
| 1217 | outb(regs->dh, VGAREG_DAC_DATA); |
| 1218 | outb(regs->ch, VGAREG_DAC_DATA); |
| 1219 | outb(regs->cl, VGAREG_DAC_DATA); |
| 1220 | } |
| 1221 | |
| 1222 | // ------------------------------------------------------------------- |
| 1223 | static void |
| 1224 | biosfn_set_all_dac_reg(struct bregs *regs) |
| 1225 | { |
| 1226 | outb(regs->bl, VGAREG_DAC_WRITE_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1227 | u8 *data_far = (u8*)(regs->dx + 0); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1228 | int count = regs->cx; |
| 1229 | while (count) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1230 | outb(GET_FARVAR(regs->es, *data_far), VGAREG_DAC_DATA); |
| 1231 | data_far++; |
| 1232 | outb(GET_FARVAR(regs->es, *data_far), VGAREG_DAC_DATA); |
| 1233 | data_far++; |
| 1234 | outb(GET_FARVAR(regs->es, *data_far), VGAREG_DAC_DATA); |
| 1235 | data_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1236 | count--; |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | // ------------------------------------------------------------------- |
| 1241 | static void |
| 1242 | biosfn_select_video_dac_color_page(struct bregs *regs) |
| 1243 | { |
| 1244 | inb(VGAREG_ACTL_RESET); |
| 1245 | outb(0x10, VGAREG_ACTL_ADDRESS); |
| 1246 | u8 val = inb(VGAREG_ACTL_READ_DATA); |
| 1247 | if (!(regs->bl & 0x01)) { |
| 1248 | val = (val & 0x7f) | (regs->bh << 7); |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 1249 | outb(val, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1250 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1251 | return; |
| 1252 | } |
| 1253 | inb(VGAREG_ACTL_RESET); |
| 1254 | outb(0x14, VGAREG_ACTL_ADDRESS); |
| 1255 | u8 bh = regs->bh; |
| 1256 | if (!(val & 0x80)) |
| 1257 | bh <<= 2; |
| 1258 | bh &= 0x0f; |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 1259 | outb(bh, VGAREG_ACTL_WRITE_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1260 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1261 | } |
| 1262 | |
| 1263 | // ------------------------------------------------------------------- |
| 1264 | static void |
| 1265 | biosfn_read_single_dac_reg(struct bregs *regs) |
| 1266 | { |
| 1267 | outb(regs->bl, VGAREG_DAC_READ_ADDRESS); |
| 1268 | regs->dh = inb(VGAREG_DAC_DATA); |
| 1269 | regs->ch = inb(VGAREG_DAC_DATA); |
| 1270 | regs->cl = inb(VGAREG_DAC_DATA); |
| 1271 | } |
| 1272 | |
| 1273 | // ------------------------------------------------------------------- |
| 1274 | static void |
| 1275 | biosfn_read_all_dac_reg(struct bregs *regs) |
| 1276 | { |
| 1277 | outb(regs->bl, VGAREG_DAC_READ_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1278 | u8 *data_far = (u8*)(regs->dx + 0); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1279 | int count = regs->cx; |
| 1280 | while (count) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1281 | SET_FARVAR(regs->es, *data_far, inb(VGAREG_DAC_DATA)); |
| 1282 | data_far++; |
| 1283 | SET_FARVAR(regs->es, *data_far, inb(VGAREG_DAC_DATA)); |
| 1284 | data_far++; |
| 1285 | SET_FARVAR(regs->es, *data_far, inb(VGAREG_DAC_DATA)); |
| 1286 | data_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1287 | count--; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | // ------------------------------------------------------------------- |
| 1292 | static void |
| 1293 | biosfn_set_pel_mask(struct bregs *regs) |
| 1294 | { |
| 1295 | outb(regs->bl, VGAREG_PEL_MASK); |
| 1296 | } |
| 1297 | |
| 1298 | // ------------------------------------------------------------------- |
| 1299 | static void |
| 1300 | biosfn_read_pel_mask(struct bregs *regs) |
| 1301 | { |
| 1302 | regs->bl = inb(VGAREG_PEL_MASK); |
| 1303 | } |
| 1304 | |
| 1305 | // ------------------------------------------------------------------- |
| 1306 | static void |
| 1307 | biosfn_read_video_dac_state(struct bregs *regs) |
| 1308 | { |
| 1309 | inb(VGAREG_ACTL_RESET); |
| 1310 | outb(0x10, VGAREG_ACTL_ADDRESS); |
| 1311 | u8 val1 = inb(VGAREG_ACTL_READ_DATA) >> 7; |
| 1312 | |
| 1313 | inb(VGAREG_ACTL_RESET); |
| 1314 | outb(0x14, VGAREG_ACTL_ADDRESS); |
| 1315 | u8 val2 = inb(VGAREG_ACTL_READ_DATA) & 0x0f; |
| 1316 | if (!(val1 & 0x01)) |
| 1317 | val2 >>= 2; |
| 1318 | |
| 1319 | inb(VGAREG_ACTL_RESET); |
| 1320 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 1321 | |
| 1322 | regs->bl = val1; |
| 1323 | regs->bh = val2; |
| 1324 | } |
| 1325 | |
| 1326 | // ------------------------------------------------------------------- |
| 1327 | static void |
| 1328 | get_font_access() |
| 1329 | { |
| 1330 | outw(0x0100, VGAREG_SEQU_ADDRESS); |
| 1331 | outw(0x0402, VGAREG_SEQU_ADDRESS); |
| 1332 | outw(0x0704, VGAREG_SEQU_ADDRESS); |
| 1333 | outw(0x0300, VGAREG_SEQU_ADDRESS); |
| 1334 | outw(0x0204, VGAREG_GRDC_ADDRESS); |
| 1335 | outw(0x0005, VGAREG_GRDC_ADDRESS); |
| 1336 | outw(0x0406, VGAREG_GRDC_ADDRESS); |
| 1337 | } |
| 1338 | |
| 1339 | static void |
| 1340 | release_font_access() |
| 1341 | { |
| 1342 | outw(0x0100, VGAREG_SEQU_ADDRESS); |
| 1343 | outw(0x0302, VGAREG_SEQU_ADDRESS); |
| 1344 | outw(0x0304, VGAREG_SEQU_ADDRESS); |
| 1345 | outw(0x0300, VGAREG_SEQU_ADDRESS); |
| 1346 | u16 v = inw(VGAREG_READ_MISC_OUTPUT); |
| 1347 | v = ((v & 0x01) << 10) | 0x0a06; |
| 1348 | outw(v, VGAREG_GRDC_ADDRESS); |
| 1349 | outw(0x0004, VGAREG_GRDC_ADDRESS); |
| 1350 | outw(0x1005, VGAREG_GRDC_ADDRESS); |
| 1351 | } |
| 1352 | |
| 1353 | static void |
| 1354 | set_scan_lines(u8 lines) |
| 1355 | { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1356 | u16 crtc_addr = GET_BDA(crtc_address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1357 | outb(0x09, crtc_addr); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1358 | u8 crtc_r9 = inb(crtc_addr + 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1359 | crtc_r9 = (crtc_r9 & 0xe0) | (lines - 1); |
| 1360 | outb(crtc_r9, crtc_addr + 1); |
| 1361 | if (lines == 8) |
| 1362 | biosfn_set_cursor_shape(0x06, 0x07); |
| 1363 | else |
| 1364 | biosfn_set_cursor_shape(lines - 4, lines - 3); |
| 1365 | SET_BDA(char_height, lines); |
| 1366 | outb(0x12, crtc_addr); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1367 | u16 vde = inb(crtc_addr + 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1368 | outb(0x07, crtc_addr); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1369 | u8 ovl = inb(crtc_addr + 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1370 | vde += (((ovl & 0x02) << 7) + ((ovl & 0x40) << 3) + 1); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1371 | u8 rows = vde / lines; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1372 | SET_BDA(video_rows, rows - 1); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1373 | u16 cols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1374 | SET_BDA(video_pagesize, rows * cols * 2); |
| 1375 | } |
| 1376 | |
| 1377 | static void |
| 1378 | biosfn_load_text_user_pat(u8 AL, u16 ES, u16 BP, u16 CX, u16 DX, u8 BL, |
| 1379 | u8 BH) |
| 1380 | { |
| 1381 | get_font_access(); |
| 1382 | u16 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11); |
| 1383 | u16 i; |
| 1384 | for (i = 0; i < CX; i++) { |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 1385 | void *src_far = (void*)(BP + i * BH); |
| 1386 | void *dest_far = (void*)(blockaddr + (DX + i) * 32); |
| 1387 | memcpy_far(0xA000, dest_far, ES, src_far, BH); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1388 | } |
| 1389 | release_font_access(); |
| 1390 | if (AL >= 0x10) |
| 1391 | set_scan_lines(BH); |
| 1392 | } |
| 1393 | |
| 1394 | static void |
| 1395 | biosfn_load_text_8_14_pat(u8 AL, u8 BL) |
| 1396 | { |
| 1397 | get_font_access(); |
| 1398 | u16 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11); |
| 1399 | u16 i; |
| 1400 | for (i = 0; i < 0x100; i++) { |
| 1401 | u16 src = i * 14; |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 1402 | void *dest_far = (void*)(blockaddr + i * 32); |
| 1403 | memcpy_far(0xA000, dest_far, 0xC000, &vgafont14[src], 14); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1404 | } |
| 1405 | release_font_access(); |
| 1406 | if (AL >= 0x10) |
| 1407 | set_scan_lines(14); |
| 1408 | } |
| 1409 | |
| 1410 | static void |
| 1411 | biosfn_load_text_8_8_pat(u8 AL, u8 BL) |
| 1412 | { |
| 1413 | get_font_access(); |
| 1414 | u16 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11); |
| 1415 | u16 i; |
| 1416 | for (i = 0; i < 0x100; i++) { |
| 1417 | u16 src = i * 8; |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 1418 | void *dest_far = (void*)(blockaddr + i * 32); |
| 1419 | memcpy_far(0xA000, dest_far, 0xC000, &vgafont8[src], 8); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1420 | } |
| 1421 | release_font_access(); |
| 1422 | if (AL >= 0x10) |
| 1423 | set_scan_lines(8); |
| 1424 | } |
| 1425 | |
| 1426 | // ------------------------------------------------------------------- |
| 1427 | static void |
| 1428 | biosfn_set_text_block_specifier(struct bregs *regs) |
| 1429 | { |
| 1430 | outw((regs->bl << 8) | 0x03, VGAREG_SEQU_ADDRESS); |
| 1431 | } |
| 1432 | |
| 1433 | // ------------------------------------------------------------------- |
| 1434 | static void |
| 1435 | biosfn_load_text_8_16_pat(u8 AL, u8 BL) |
| 1436 | { |
| 1437 | get_font_access(); |
| 1438 | u16 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11); |
| 1439 | u16 i; |
| 1440 | for (i = 0; i < 0x100; i++) { |
| 1441 | u16 src = i * 16; |
Kevin O'Connor | f94ec43 | 2009-05-16 17:37:23 -0400 | [diff] [blame] | 1442 | void *dest_far = (void*)(blockaddr + i * 32); |
| 1443 | memcpy_far(0xA000, dest_far, 0xC000, &vgafont16[src], 16); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1444 | } |
| 1445 | release_font_access(); |
| 1446 | if (AL >= 0x10) |
| 1447 | set_scan_lines(16); |
| 1448 | } |
| 1449 | |
| 1450 | // ------------------------------------------------------------------- |
| 1451 | static void |
| 1452 | biosfn_get_font_info(u8 BH, u16 *ES, u16 *BP, u16 *CX, u16 *DX) |
| 1453 | { |
| 1454 | switch (BH) { |
| 1455 | case 0x00: { |
| 1456 | u32 segoff = GET_IVT(0x1f).segoff; |
| 1457 | *ES = segoff >> 16; |
| 1458 | *BP = segoff; |
| 1459 | break; |
| 1460 | } |
| 1461 | case 0x01: { |
| 1462 | u32 segoff = GET_IVT(0x43).segoff; |
| 1463 | *ES = segoff >> 16; |
| 1464 | *BP = segoff; |
| 1465 | break; |
| 1466 | } |
| 1467 | case 0x02: |
| 1468 | *ES = 0xC000; |
| 1469 | *BP = (u32)vgafont14; |
| 1470 | break; |
| 1471 | case 0x03: |
| 1472 | *ES = 0xC000; |
| 1473 | *BP = (u32)vgafont8; |
| 1474 | break; |
| 1475 | case 0x04: |
| 1476 | *ES = 0xC000; |
| 1477 | *BP = (u32)vgafont8 + 128 * 8; |
| 1478 | break; |
| 1479 | case 0x05: |
| 1480 | *ES = 0xC000; |
| 1481 | *BP = (u32)vgafont14alt; |
| 1482 | break; |
| 1483 | case 0x06: |
| 1484 | *ES = 0xC000; |
| 1485 | *BP = (u32)vgafont16; |
| 1486 | break; |
| 1487 | case 0x07: |
| 1488 | *ES = 0xC000; |
| 1489 | *BP = (u32)vgafont16alt; |
| 1490 | break; |
| 1491 | default: |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 1492 | dprintf(1, "Get font info BH(%02x) was discarded\n", BH); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1493 | return; |
| 1494 | } |
| 1495 | // Set byte/char of on screen font |
| 1496 | *CX = GET_BDA(char_height) & 0xff; |
| 1497 | |
| 1498 | // Set Highest char row |
| 1499 | *DX = GET_BDA(video_rows); |
| 1500 | } |
| 1501 | |
| 1502 | // ------------------------------------------------------------------- |
| 1503 | static void |
| 1504 | biosfn_get_ega_info(struct bregs *regs) |
| 1505 | { |
| 1506 | regs->cx = GET_BDA(video_switches) & 0x0f; |
| 1507 | regs->ax = GET_BDA(crtc_address); |
| 1508 | if (regs->ax == VGAREG_MDA_CRTC_ADDRESS) |
| 1509 | regs->bx = 0x0103; |
| 1510 | else |
| 1511 | regs->bx = 0x0003; |
| 1512 | } |
| 1513 | |
| 1514 | // ------------------------------------------------------------------- |
| 1515 | static void |
| 1516 | biosfn_select_vert_res(struct bregs *regs) |
| 1517 | { |
| 1518 | u8 mctl = GET_BDA(modeset_ctl); |
| 1519 | u8 vswt = GET_BDA(video_switches); |
| 1520 | |
| 1521 | switch (regs->al) { |
| 1522 | case 0x00: |
| 1523 | // 200 lines |
| 1524 | mctl = (mctl & ~0x10) | 0x80; |
| 1525 | vswt = (vswt & ~0x0f) | 0x08; |
| 1526 | break; |
| 1527 | case 0x01: |
| 1528 | // 350 lines |
| 1529 | mctl &= ~0x90; |
| 1530 | vswt = (vswt & ~0x0f) | 0x09; |
| 1531 | break; |
| 1532 | case 0x02: |
| 1533 | // 400 lines |
| 1534 | mctl = (mctl & ~0x80) | 0x10; |
| 1535 | vswt = (vswt & ~0x0f) | 0x09; |
| 1536 | break; |
| 1537 | default: |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 1538 | dprintf(1, "Select vert res (%02x) was discarded\n", regs->al); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1539 | break; |
| 1540 | } |
| 1541 | SET_BDA(modeset_ctl, mctl); |
| 1542 | SET_BDA(video_switches, vswt); |
| 1543 | regs->ax = 0x1212; |
| 1544 | } |
| 1545 | |
| 1546 | static void |
| 1547 | biosfn_enable_default_palette_loading(struct bregs *regs) |
| 1548 | { |
| 1549 | u8 v = (regs->al & 0x01) << 3; |
| 1550 | u8 mctl = GET_BDA(video_ctl) & ~0x08; |
| 1551 | SET_BDA(video_ctl, mctl | v); |
| 1552 | regs->ax = 0x1212; |
| 1553 | } |
| 1554 | |
| 1555 | static void |
| 1556 | biosfn_enable_video_addressing(struct bregs *regs) |
| 1557 | { |
| 1558 | u8 v = ((regs->al << 1) & 0x02) ^ 0x02; |
| 1559 | u8 v2 = inb(VGAREG_READ_MISC_OUTPUT) & ~0x02; |
| 1560 | outb(v | v2, VGAREG_WRITE_MISC_OUTPUT); |
| 1561 | regs->ax = 0x1212; |
| 1562 | } |
| 1563 | |
| 1564 | |
| 1565 | static void |
| 1566 | biosfn_enable_grayscale_summing(struct bregs *regs) |
| 1567 | { |
| 1568 | u8 v = ((regs->al << 1) & 0x02) ^ 0x02; |
| 1569 | u8 v2 = GET_BDA(modeset_ctl) & ~0x02; |
| 1570 | SET_BDA(modeset_ctl, v | v2); |
| 1571 | regs->ax = 0x1212; |
| 1572 | } |
| 1573 | |
| 1574 | static void |
| 1575 | biosfn_enable_cursor_emulation(struct bregs *regs) |
| 1576 | { |
| 1577 | u8 v = (regs->al & 0x01) ^ 0x01; |
| 1578 | u8 v2 = GET_BDA(modeset_ctl) & ~0x01; |
| 1579 | SET_BDA(modeset_ctl, v | v2); |
| 1580 | regs->ax = 0x1212; |
| 1581 | } |
| 1582 | |
| 1583 | // ------------------------------------------------------------------- |
| 1584 | static void |
| 1585 | biosfn_write_string(u8 flag, u8 page, u8 attr, u16 count, u8 row, u8 col, |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1586 | u16 seg, u8 *offset_far) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1587 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1588 | // Read curs info for the page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 1589 | u16 oldcurs = biosfn_get_cursor_pos(page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1590 | |
| 1591 | // if row=0xff special case : use current cursor position |
| 1592 | if (row == 0xff) { |
| 1593 | col = oldcurs & 0x00ff; |
| 1594 | row = (oldcurs & 0xff00) >> 8; |
| 1595 | } |
| 1596 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1597 | u16 newcurs = row; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1598 | newcurs <<= 8; |
| 1599 | newcurs += col; |
| 1600 | biosfn_set_cursor_pos(page, newcurs); |
| 1601 | |
| 1602 | while (count-- != 0) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1603 | u8 car = GET_FARVAR(seg, *offset_far); |
| 1604 | offset_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1605 | if ((flag & 0x02) != 0) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1606 | attr = GET_FARVAR(seg, *offset_far); |
| 1607 | offset_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | biosfn_write_teletype(car, page, attr, WITH_ATTR); |
| 1611 | } |
| 1612 | |
| 1613 | // Set back curs pos |
| 1614 | if ((flag & 0x01) == 0) |
| 1615 | biosfn_set_cursor_pos(page, oldcurs); |
| 1616 | } |
| 1617 | |
| 1618 | // ------------------------------------------------------------------- |
| 1619 | static void |
| 1620 | biosfn_read_display_code(struct bregs *regs) |
| 1621 | { |
| 1622 | regs->bx = GET_BDA(dcc_index); |
| 1623 | regs->al = 0x1a; |
| 1624 | } |
| 1625 | |
| 1626 | static void |
| 1627 | biosfn_set_display_code(struct bregs *regs) |
| 1628 | { |
| 1629 | SET_BDA(dcc_index, regs->bl); |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 1630 | dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1631 | regs->al = 0x1a; |
| 1632 | } |
| 1633 | |
| 1634 | // ------------------------------------------------------------------- |
| 1635 | static void |
| 1636 | biosfn_read_state_info(u16 BX, u16 ES, u16 DI) |
| 1637 | { |
| 1638 | // Address of static functionality table |
| 1639 | SET_FARVAR(ES, *(u16*)(DI + 0x00), (u32)static_functionality); |
| 1640 | SET_FARVAR(ES, *(u16*)(DI + 0x02), 0xC000); |
| 1641 | |
| 1642 | // Hard coded copy from BIOS area. Should it be cleaner ? |
| 1643 | memcpy_far(ES, (void*)(DI + 0x04), SEG_BDA, (void*)0x49, 30); |
| 1644 | memcpy_far(ES, (void*)(DI + 0x22), SEG_BDA, (void*)0x84, 3); |
| 1645 | |
| 1646 | SET_FARVAR(ES, *(u8*)(DI + 0x25), GET_BDA(dcc_index)); |
| 1647 | SET_FARVAR(ES, *(u8*)(DI + 0x26), 0); |
| 1648 | SET_FARVAR(ES, *(u8*)(DI + 0x27), 16); |
| 1649 | SET_FARVAR(ES, *(u8*)(DI + 0x28), 0); |
| 1650 | SET_FARVAR(ES, *(u8*)(DI + 0x29), 8); |
| 1651 | SET_FARVAR(ES, *(u8*)(DI + 0x2a), 2); |
| 1652 | SET_FARVAR(ES, *(u8*)(DI + 0x2b), 0); |
| 1653 | SET_FARVAR(ES, *(u8*)(DI + 0x2c), 0); |
| 1654 | SET_FARVAR(ES, *(u8*)(DI + 0x31), 3); |
| 1655 | SET_FARVAR(ES, *(u8*)(DI + 0x32), 0); |
| 1656 | |
| 1657 | memset_far(ES, (void*)(DI + 0x33), 0, 13); |
| 1658 | } |
| 1659 | |
| 1660 | // ------------------------------------------------------------------- |
| 1661 | // ------------------------------------------------------------------- |
| 1662 | static u16 |
| 1663 | biosfn_read_video_state_size(u16 CX) |
| 1664 | { |
| 1665 | u16 size = 0; |
| 1666 | if (CX & 1) |
| 1667 | size += 0x46; |
| 1668 | if (CX & 2) |
| 1669 | size += (5 + 8 + 5) * 2 + 6; |
| 1670 | if (CX & 4) |
| 1671 | size += 3 + 256 * 3 + 1; |
| 1672 | return size; |
| 1673 | } |
| 1674 | |
| 1675 | static u16 |
| 1676 | biosfn_save_video_state(u16 CX, u16 ES, u16 BX) |
| 1677 | { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1678 | u16 crtc_addr = GET_BDA(crtc_address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1679 | if (CX & 1) { |
| 1680 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_SEQU_ADDRESS)); |
| 1681 | BX++; |
| 1682 | SET_FARVAR(ES, *(u8*)(BX+0), inb(crtc_addr)); |
| 1683 | BX++; |
| 1684 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_GRDC_ADDRESS)); |
| 1685 | BX++; |
| 1686 | inb(VGAREG_ACTL_RESET); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1687 | u16 ar_index = inb(VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1688 | SET_FARVAR(ES, *(u8*)(BX+0), ar_index); |
| 1689 | BX++; |
| 1690 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_READ_FEATURE_CTL)); |
| 1691 | BX++; |
| 1692 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1693 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1694 | for (i = 1; i <= 4; i++) { |
| 1695 | outb(i, VGAREG_SEQU_ADDRESS); |
| 1696 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_SEQU_DATA)); |
| 1697 | BX++; |
| 1698 | } |
| 1699 | outb(0, VGAREG_SEQU_ADDRESS); |
| 1700 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_SEQU_DATA)); |
| 1701 | BX++; |
| 1702 | |
| 1703 | for (i = 0; i <= 0x18; i++) { |
| 1704 | outb(i, crtc_addr); |
| 1705 | SET_FARVAR(ES, *(u8*)(BX+0), inb(crtc_addr + 1)); |
| 1706 | BX++; |
| 1707 | } |
| 1708 | |
| 1709 | for (i = 0; i <= 0x13; i++) { |
| 1710 | inb(VGAREG_ACTL_RESET); |
| 1711 | outb(i | (ar_index & 0x20), VGAREG_ACTL_ADDRESS); |
| 1712 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_ACTL_READ_DATA)); |
| 1713 | BX++; |
| 1714 | } |
| 1715 | inb(VGAREG_ACTL_RESET); |
| 1716 | |
| 1717 | for (i = 0; i <= 8; i++) { |
| 1718 | outb(i, VGAREG_GRDC_ADDRESS); |
| 1719 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_GRDC_DATA)); |
| 1720 | BX++; |
| 1721 | } |
| 1722 | |
| 1723 | SET_FARVAR(ES, *(u16*)(BX+0), crtc_addr); |
| 1724 | BX += 2; |
| 1725 | |
| 1726 | /* XXX: read plane latches */ |
| 1727 | SET_FARVAR(ES, *(u8*)(BX+0), 0); |
| 1728 | BX++; |
| 1729 | SET_FARVAR(ES, *(u8*)(BX+0), 0); |
| 1730 | BX++; |
| 1731 | SET_FARVAR(ES, *(u8*)(BX+0), 0); |
| 1732 | BX++; |
| 1733 | SET_FARVAR(ES, *(u8*)(BX+0), 0); |
| 1734 | BX++; |
| 1735 | } |
| 1736 | if (CX & 2) { |
| 1737 | SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_mode)); |
| 1738 | BX++; |
| 1739 | SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(video_cols)); |
| 1740 | BX += 2; |
| 1741 | SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(video_pagesize)); |
| 1742 | BX += 2; |
| 1743 | SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(crtc_address)); |
| 1744 | BX += 2; |
| 1745 | SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_rows)); |
| 1746 | BX++; |
| 1747 | SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(char_height)); |
| 1748 | BX += 2; |
| 1749 | SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_ctl)); |
| 1750 | BX++; |
| 1751 | SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_switches)); |
| 1752 | BX++; |
| 1753 | SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(modeset_ctl)); |
| 1754 | BX++; |
| 1755 | SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(cursor_type)); |
| 1756 | BX += 2; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1757 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1758 | for (i = 0; i < 8; i++) { |
| 1759 | SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(cursor_pos[i])); |
| 1760 | BX += 2; |
| 1761 | } |
| 1762 | SET_FARVAR(ES, *(u16*)(BX+0), GET_BDA(video_pagestart)); |
| 1763 | BX += 2; |
| 1764 | SET_FARVAR(ES, *(u8*)(BX+0), GET_BDA(video_page)); |
| 1765 | BX++; |
| 1766 | /* current font */ |
| 1767 | SET_FARVAR(ES, *(u16*)(BX+0), GET_FARVAR(0, *(u16*)(0x1f * 4))); |
| 1768 | BX += 2; |
| 1769 | SET_FARVAR(ES, *(u16*)(BX+0), GET_FARVAR(0, *(u16*)(0x1f * 4 + 2))); |
| 1770 | BX += 2; |
| 1771 | SET_FARVAR(ES, *(u16*)(BX+0), GET_FARVAR(0, *(u16*)(0x43 * 4))); |
| 1772 | BX += 2; |
| 1773 | SET_FARVAR(ES, *(u16*)(BX+0), GET_FARVAR(0, *(u16*)(0x43 * 4 + 2))); |
| 1774 | BX += 2; |
| 1775 | } |
| 1776 | if (CX & 4) { |
| 1777 | /* XXX: check this */ |
| 1778 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_DAC_STATE)); |
| 1779 | BX++; /* read/write mode dac */ |
| 1780 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_DAC_WRITE_ADDRESS)); |
| 1781 | BX++; /* pix address */ |
| 1782 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_PEL_MASK)); |
| 1783 | BX++; |
| 1784 | // Set the whole dac always, from 0 |
| 1785 | outb(0x00, VGAREG_DAC_WRITE_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1786 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1787 | for (i = 0; i < 256 * 3; i++) { |
| 1788 | SET_FARVAR(ES, *(u8*)(BX+0), inb(VGAREG_DAC_DATA)); |
| 1789 | BX++; |
| 1790 | } |
| 1791 | SET_FARVAR(ES, *(u8*)(BX+0), 0); |
| 1792 | BX++; /* color select register */ |
| 1793 | } |
| 1794 | return BX; |
| 1795 | } |
| 1796 | |
| 1797 | static u16 |
| 1798 | biosfn_restore_video_state(u16 CX, u16 ES, u16 BX) |
| 1799 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1800 | if (CX & 1) { |
| 1801 | // Reset Attribute Ctl flip-flop |
| 1802 | inb(VGAREG_ACTL_RESET); |
| 1803 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1804 | u16 crtc_addr = GET_FARVAR(ES, *(u16*)(BX + 0x40)); |
| 1805 | u16 addr1 = BX; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1806 | BX += 5; |
| 1807 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1808 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1809 | for (i = 1; i <= 4; i++) { |
| 1810 | outb(i, VGAREG_SEQU_ADDRESS); |
| 1811 | outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_SEQU_DATA); |
| 1812 | BX++; |
| 1813 | } |
| 1814 | outb(0, VGAREG_SEQU_ADDRESS); |
| 1815 | outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_SEQU_DATA); |
| 1816 | BX++; |
| 1817 | |
| 1818 | // Disable CRTC write protection |
| 1819 | outw(0x0011, crtc_addr); |
| 1820 | // Set CRTC regs |
| 1821 | for (i = 0; i <= 0x18; i++) { |
| 1822 | if (i != 0x11) { |
| 1823 | outb(i, crtc_addr); |
| 1824 | outb(GET_FARVAR(ES, *(u8*)(BX+0)), crtc_addr + 1); |
| 1825 | } |
| 1826 | BX++; |
| 1827 | } |
| 1828 | // select crtc base address |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1829 | u16 v = inb(VGAREG_READ_MISC_OUTPUT) & ~0x01; |
Kevin O'Connor | d9fc0a0 | 2009-05-07 22:00:25 -0400 | [diff] [blame] | 1830 | if (crtc_addr == VGAREG_VGA_CRTC_ADDRESS) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1831 | v |= 0x01; |
| 1832 | outb(v, VGAREG_WRITE_MISC_OUTPUT); |
| 1833 | |
| 1834 | // enable write protection if needed |
| 1835 | outb(0x11, crtc_addr); |
| 1836 | outb(GET_FARVAR(ES, *(u8*)(BX - 0x18 + 0x11)), crtc_addr + 1); |
| 1837 | |
| 1838 | // Set Attribute Ctl |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1839 | u16 ar_index = GET_FARVAR(ES, *(u8*)(addr1 + 0x03)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1840 | inb(VGAREG_ACTL_RESET); |
| 1841 | for (i = 0; i <= 0x13; i++) { |
| 1842 | outb(i | (ar_index & 0x20), VGAREG_ACTL_ADDRESS); |
| 1843 | outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_ACTL_WRITE_DATA); |
| 1844 | BX++; |
| 1845 | } |
| 1846 | outb(ar_index, VGAREG_ACTL_ADDRESS); |
| 1847 | inb(VGAREG_ACTL_RESET); |
| 1848 | |
| 1849 | for (i = 0; i <= 8; i++) { |
| 1850 | outb(i, VGAREG_GRDC_ADDRESS); |
| 1851 | outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_GRDC_DATA); |
| 1852 | BX++; |
| 1853 | } |
| 1854 | BX += 2; /* crtc_addr */ |
| 1855 | BX += 4; /* plane latches */ |
| 1856 | |
| 1857 | outb(GET_FARVAR(ES, *(u8*)(addr1+0)), VGAREG_SEQU_ADDRESS); |
| 1858 | addr1++; |
| 1859 | outb(GET_FARVAR(ES, *(u8*)(addr1+0)), crtc_addr); |
| 1860 | addr1++; |
| 1861 | outb(GET_FARVAR(ES, *(u8*)(addr1+0)), VGAREG_GRDC_ADDRESS); |
| 1862 | addr1++; |
| 1863 | addr1++; |
| 1864 | outb(GET_FARVAR(ES, *(u8*)(addr1+0)), crtc_addr - 0x4 + 0xa); |
| 1865 | addr1++; |
| 1866 | } |
| 1867 | if (CX & 2) { |
| 1868 | SET_BDA(video_mode, GET_FARVAR(ES, *(u8*)(BX+0))); |
| 1869 | BX++; |
| 1870 | SET_BDA(video_cols, GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1871 | BX += 2; |
| 1872 | SET_BDA(video_pagesize, GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1873 | BX += 2; |
| 1874 | SET_BDA(crtc_address, GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1875 | BX += 2; |
| 1876 | SET_BDA(video_rows, GET_FARVAR(ES, *(u8*)(BX+0))); |
| 1877 | BX++; |
| 1878 | SET_BDA(char_height, GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1879 | BX += 2; |
| 1880 | SET_BDA(video_ctl, GET_FARVAR(ES, *(u8*)(BX+0))); |
| 1881 | BX++; |
| 1882 | SET_BDA(video_switches, GET_FARVAR(ES, *(u8*)(BX+0))); |
| 1883 | BX++; |
| 1884 | SET_BDA(modeset_ctl, GET_FARVAR(ES, *(u8*)(BX+0))); |
| 1885 | BX++; |
| 1886 | SET_BDA(cursor_type, GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1887 | BX += 2; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1888 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1889 | for (i = 0; i < 8; i++) { |
| 1890 | SET_BDA(cursor_pos[i], GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1891 | BX += 2; |
| 1892 | } |
| 1893 | SET_BDA(video_pagestart, GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1894 | BX += 2; |
| 1895 | SET_BDA(video_page, GET_FARVAR(ES, *(u8*)(BX+0))); |
| 1896 | BX++; |
| 1897 | /* current font */ |
| 1898 | SET_IVT(0x1f, GET_FARVAR(ES, *(u16*)(BX+2)), GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1899 | BX += 4; |
| 1900 | SET_IVT(0x43, GET_FARVAR(ES, *(u16*)(BX+2)), GET_FARVAR(ES, *(u16*)(BX+0))); |
| 1901 | BX += 4; |
| 1902 | } |
| 1903 | if (CX & 4) { |
| 1904 | BX++; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1905 | u16 v = GET_FARVAR(ES, *(u8*)(BX+0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1906 | BX++; |
| 1907 | outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_PEL_MASK); |
| 1908 | BX++; |
| 1909 | // Set the whole dac always, from 0 |
| 1910 | outb(0x00, VGAREG_DAC_WRITE_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 1911 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1912 | for (i = 0; i < 256 * 3; i++) { |
| 1913 | outb(GET_FARVAR(ES, *(u8*)(BX+0)), VGAREG_DAC_DATA); |
| 1914 | BX++; |
| 1915 | } |
| 1916 | BX++; |
| 1917 | outb(v, VGAREG_DAC_WRITE_ADDRESS); |
| 1918 | } |
| 1919 | return BX; |
| 1920 | } |
| 1921 | |
| 1922 | |
| 1923 | /**************************************************************** |
| 1924 | * VGA int 10 handler |
| 1925 | ****************************************************************/ |
| 1926 | |
| 1927 | static void |
| 1928 | handle_1000(struct bregs *regs) |
| 1929 | { |
| 1930 | // XXX - inline |
| 1931 | biosfn_set_video_mode(regs->al); |
| 1932 | switch(regs->al & 0x7F) { |
| 1933 | case 6: |
| 1934 | regs->al = 0x3F; |
| 1935 | break; |
| 1936 | case 0: |
| 1937 | case 1: |
| 1938 | case 2: |
| 1939 | case 3: |
| 1940 | case 4: |
| 1941 | case 5: |
| 1942 | case 7: |
| 1943 | regs->al = 0x30; |
| 1944 | break; |
| 1945 | default: |
| 1946 | regs->al = 0x20; |
| 1947 | } |
| 1948 | } |
| 1949 | |
| 1950 | static void |
| 1951 | handle_1001(struct bregs *regs) |
| 1952 | { |
| 1953 | biosfn_set_cursor_shape(regs->ch, regs->cl); |
| 1954 | } |
| 1955 | |
| 1956 | static void |
| 1957 | handle_1002(struct bregs *regs) |
| 1958 | { |
| 1959 | biosfn_set_cursor_pos(regs->bh, regs->dx); |
| 1960 | } |
| 1961 | |
| 1962 | static void |
| 1963 | handle_1003(struct bregs *regs) |
| 1964 | { |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame^] | 1965 | regs->cx = biosfn_get_cursor_shape(regs->bh); |
| 1966 | regs->dx = biosfn_get_cursor_pos(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | // Read light pen pos (unimplemented) |
| 1970 | static void |
| 1971 | handle_1004(struct bregs *regs) |
| 1972 | { |
| 1973 | debug_stub(regs); |
| 1974 | regs->ax = regs->bx = regs->cx = regs->dx = 0; |
| 1975 | } |
| 1976 | |
| 1977 | static void |
| 1978 | handle_1005(struct bregs *regs) |
| 1979 | { |
| 1980 | biosfn_set_active_page(regs->al); |
| 1981 | } |
| 1982 | |
| 1983 | static void |
| 1984 | handle_1006(struct bregs *regs) |
| 1985 | { |
| 1986 | biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl |
| 1987 | , 0xFF, SCROLL_UP); |
| 1988 | } |
| 1989 | |
| 1990 | static void |
| 1991 | handle_1007(struct bregs *regs) |
| 1992 | { |
| 1993 | biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl |
| 1994 | , 0xFF, SCROLL_DOWN); |
| 1995 | } |
| 1996 | |
| 1997 | static void |
| 1998 | handle_1008(struct bregs *regs) |
| 1999 | { |
| 2000 | // XXX - inline |
| 2001 | biosfn_read_char_attr(regs->bh, ®s->ax); |
| 2002 | } |
| 2003 | |
| 2004 | static void |
| 2005 | handle_1009(struct bregs *regs) |
| 2006 | { |
| 2007 | // XXX - inline |
| 2008 | biosfn_write_char_attr(regs->al, regs->bh, regs->bl, regs->cx); |
| 2009 | } |
| 2010 | |
| 2011 | static void |
| 2012 | handle_100a(struct bregs *regs) |
| 2013 | { |
| 2014 | // XXX - inline |
| 2015 | biosfn_write_char_only(regs->al, regs->bh, regs->bl, regs->cx); |
| 2016 | } |
| 2017 | |
| 2018 | |
| 2019 | static void |
| 2020 | handle_100b00(struct bregs *regs) |
| 2021 | { |
| 2022 | // XXX - inline |
| 2023 | biosfn_set_border_color(regs); |
| 2024 | } |
| 2025 | |
| 2026 | static void |
| 2027 | handle_100b01(struct bregs *regs) |
| 2028 | { |
| 2029 | // XXX - inline |
| 2030 | biosfn_set_palette(regs); |
| 2031 | } |
| 2032 | |
| 2033 | static void |
| 2034 | handle_100bXX(struct bregs *regs) |
| 2035 | { |
| 2036 | debug_stub(regs); |
| 2037 | } |
| 2038 | |
| 2039 | static void |
| 2040 | handle_100b(struct bregs *regs) |
| 2041 | { |
| 2042 | switch (regs->bh) { |
| 2043 | case 0x00: handle_100b00(regs); break; |
| 2044 | case 0x01: handle_100b01(regs); break; |
| 2045 | default: handle_100bXX(regs); break; |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | |
| 2050 | static void |
| 2051 | handle_100c(struct bregs *regs) |
| 2052 | { |
| 2053 | // XXX - inline |
| 2054 | biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx); |
| 2055 | } |
| 2056 | |
| 2057 | static void |
| 2058 | handle_100d(struct bregs *regs) |
| 2059 | { |
| 2060 | // XXX - inline |
| 2061 | biosfn_read_pixel(regs->bh, regs->cx, regs->dx, ®s->ax); |
| 2062 | } |
| 2063 | |
| 2064 | static void |
| 2065 | handle_100e(struct bregs *regs) |
| 2066 | { |
| 2067 | // Ralf Brown Interrupt list is WRONG on bh(page) |
| 2068 | // We do output only on the current page ! |
| 2069 | biosfn_write_teletype(regs->al, 0xff, regs->bl, NO_ATTR); |
| 2070 | } |
| 2071 | |
| 2072 | static void |
| 2073 | handle_100f(struct bregs *regs) |
| 2074 | { |
| 2075 | // XXX - inline |
| 2076 | biosfn_get_video_mode(regs); |
| 2077 | } |
| 2078 | |
| 2079 | |
| 2080 | static void |
| 2081 | handle_101000(struct bregs *regs) |
| 2082 | { |
| 2083 | if (regs->bl > 0x14) |
| 2084 | return; |
| 2085 | biosfn_set_single_palette_reg(regs->bl, regs->bh); |
| 2086 | } |
| 2087 | |
| 2088 | static void |
| 2089 | handle_101001(struct bregs *regs) |
| 2090 | { |
| 2091 | // XXX - inline |
| 2092 | biosfn_set_overscan_border_color(regs); |
| 2093 | } |
| 2094 | |
| 2095 | static void |
| 2096 | handle_101002(struct bregs *regs) |
| 2097 | { |
| 2098 | // XXX - inline |
| 2099 | biosfn_set_all_palette_reg(regs); |
| 2100 | } |
| 2101 | |
| 2102 | static void |
| 2103 | handle_101003(struct bregs *regs) |
| 2104 | { |
| 2105 | // XXX - inline |
| 2106 | biosfn_toggle_intensity(regs); |
| 2107 | } |
| 2108 | |
| 2109 | static void |
| 2110 | handle_101007(struct bregs *regs) |
| 2111 | { |
| 2112 | if (regs->bl > 0x14) |
| 2113 | return; |
| 2114 | regs->bh = biosfn_get_single_palette_reg(regs->bl); |
| 2115 | } |
| 2116 | |
| 2117 | static void |
| 2118 | handle_101008(struct bregs *regs) |
| 2119 | { |
| 2120 | // XXX - inline |
| 2121 | biosfn_read_overscan_border_color(regs); |
| 2122 | } |
| 2123 | |
| 2124 | static void |
| 2125 | handle_101009(struct bregs *regs) |
| 2126 | { |
| 2127 | // XXX - inline |
| 2128 | biosfn_get_all_palette_reg(regs); |
| 2129 | } |
| 2130 | |
| 2131 | static void |
| 2132 | handle_101010(struct bregs *regs) |
| 2133 | { |
| 2134 | // XXX - inline |
| 2135 | biosfn_set_single_dac_reg(regs); |
| 2136 | } |
| 2137 | |
| 2138 | static void |
| 2139 | handle_101012(struct bregs *regs) |
| 2140 | { |
| 2141 | // XXX - inline |
| 2142 | biosfn_set_all_dac_reg(regs); |
| 2143 | } |
| 2144 | |
| 2145 | static void |
| 2146 | handle_101013(struct bregs *regs) |
| 2147 | { |
| 2148 | // XXX - inline |
| 2149 | biosfn_select_video_dac_color_page(regs); |
| 2150 | } |
| 2151 | |
| 2152 | static void |
| 2153 | handle_101015(struct bregs *regs) |
| 2154 | { |
| 2155 | // XXX - inline |
| 2156 | biosfn_read_single_dac_reg(regs); |
| 2157 | } |
| 2158 | |
| 2159 | static void |
| 2160 | handle_101017(struct bregs *regs) |
| 2161 | { |
| 2162 | // XXX - inline |
| 2163 | biosfn_read_all_dac_reg(regs); |
| 2164 | } |
| 2165 | |
| 2166 | static void |
| 2167 | handle_101018(struct bregs *regs) |
| 2168 | { |
| 2169 | // XXX - inline |
| 2170 | biosfn_set_pel_mask(regs); |
| 2171 | } |
| 2172 | |
| 2173 | static void |
| 2174 | handle_101019(struct bregs *regs) |
| 2175 | { |
| 2176 | // XXX - inline |
| 2177 | biosfn_read_pel_mask(regs); |
| 2178 | } |
| 2179 | |
| 2180 | static void |
| 2181 | handle_10101a(struct bregs *regs) |
| 2182 | { |
| 2183 | // XXX - inline |
| 2184 | biosfn_read_video_dac_state(regs); |
| 2185 | } |
| 2186 | |
| 2187 | static void |
| 2188 | handle_10101b(struct bregs *regs) |
| 2189 | { |
| 2190 | biosfn_perform_gray_scale_summing(regs->bx, regs->cx); |
| 2191 | } |
| 2192 | |
| 2193 | static void |
| 2194 | handle_1010XX(struct bregs *regs) |
| 2195 | { |
| 2196 | debug_stub(regs); |
| 2197 | } |
| 2198 | |
| 2199 | static void |
| 2200 | handle_1010(struct bregs *regs) |
| 2201 | { |
| 2202 | switch (regs->al) { |
| 2203 | case 0x00: handle_101000(regs); break; |
| 2204 | case 0x01: handle_101001(regs); break; |
| 2205 | case 0x02: handle_101002(regs); break; |
| 2206 | case 0x03: handle_101003(regs); break; |
| 2207 | case 0x07: handle_101007(regs); break; |
| 2208 | case 0x08: handle_101008(regs); break; |
| 2209 | case 0x09: handle_101009(regs); break; |
| 2210 | case 0x10: handle_101010(regs); break; |
| 2211 | case 0x12: handle_101012(regs); break; |
| 2212 | case 0x13: handle_101013(regs); break; |
| 2213 | case 0x15: handle_101015(regs); break; |
| 2214 | case 0x17: handle_101017(regs); break; |
| 2215 | case 0x18: handle_101018(regs); break; |
| 2216 | case 0x19: handle_101019(regs); break; |
| 2217 | case 0x1a: handle_10101a(regs); break; |
| 2218 | case 0x1b: handle_10101b(regs); break; |
| 2219 | default: handle_1010XX(regs); break; |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | |
| 2224 | static void |
| 2225 | handle_101100(struct bregs *regs) |
| 2226 | { |
| 2227 | // XXX - inline |
| 2228 | biosfn_load_text_user_pat(regs->al, regs->es, 0 // XXX - regs->bp |
| 2229 | , regs->cx, regs->dx, regs->bl, regs->bh); |
| 2230 | } |
| 2231 | |
| 2232 | static void |
| 2233 | handle_101101(struct bregs *regs) |
| 2234 | { |
| 2235 | // XXX - inline |
| 2236 | biosfn_load_text_8_14_pat(regs->al, regs->bl); |
| 2237 | } |
| 2238 | |
| 2239 | static void |
| 2240 | handle_101102(struct bregs *regs) |
| 2241 | { |
| 2242 | // XXX - inline |
| 2243 | biosfn_load_text_8_8_pat(regs->al, regs->bl); |
| 2244 | } |
| 2245 | |
| 2246 | static void |
| 2247 | handle_101103(struct bregs *regs) |
| 2248 | { |
| 2249 | // XXX - inline |
| 2250 | biosfn_set_text_block_specifier(regs); |
| 2251 | } |
| 2252 | |
| 2253 | static void |
| 2254 | handle_101104(struct bregs *regs) |
| 2255 | { |
| 2256 | // XXX - inline |
| 2257 | biosfn_load_text_8_16_pat(regs->al, regs->bl); |
| 2258 | } |
| 2259 | |
| 2260 | static void |
| 2261 | handle_101110(struct bregs *regs) |
| 2262 | { |
| 2263 | handle_101100(regs); |
| 2264 | } |
| 2265 | |
| 2266 | static void |
| 2267 | handle_101111(struct bregs *regs) |
| 2268 | { |
| 2269 | handle_101101(regs); |
| 2270 | } |
| 2271 | |
| 2272 | static void |
| 2273 | handle_101112(struct bregs *regs) |
| 2274 | { |
| 2275 | handle_101102(regs); |
| 2276 | } |
| 2277 | |
| 2278 | static void |
| 2279 | handle_101114(struct bregs *regs) |
| 2280 | { |
| 2281 | handle_101104(regs); |
| 2282 | } |
| 2283 | |
| 2284 | static void |
| 2285 | handle_101130(struct bregs *regs) |
| 2286 | { |
| 2287 | // XXX - inline |
| 2288 | biosfn_get_font_info(regs->bh, ®s->es, 0 // ®s->bp |
| 2289 | , ®s->cx, ®s->dx); |
| 2290 | } |
| 2291 | |
| 2292 | static void |
| 2293 | handle_1011XX(struct bregs *regs) |
| 2294 | { |
| 2295 | debug_stub(regs); |
| 2296 | } |
| 2297 | |
| 2298 | static void |
| 2299 | handle_1011(struct bregs *regs) |
| 2300 | { |
| 2301 | switch (regs->al) { |
| 2302 | case 0x00: handle_101100(regs); break; |
| 2303 | case 0x01: handle_101101(regs); break; |
| 2304 | case 0x02: handle_101102(regs); break; |
| 2305 | case 0x03: handle_101103(regs); break; |
| 2306 | case 0x04: handle_101104(regs); break; |
| 2307 | case 0x10: handle_101110(regs); break; |
| 2308 | case 0x11: handle_101111(regs); break; |
| 2309 | case 0x12: handle_101112(regs); break; |
| 2310 | case 0x14: handle_101114(regs); break; |
| 2311 | case 0x30: handle_101130(regs); break; |
| 2312 | default: handle_1011XX(regs); break; |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | |
| 2317 | static void |
| 2318 | handle_101210(struct bregs *regs) |
| 2319 | { |
| 2320 | // XXX - inline |
| 2321 | biosfn_get_ega_info(regs); |
| 2322 | } |
| 2323 | |
| 2324 | static void |
| 2325 | handle_101230(struct bregs *regs) |
| 2326 | { |
| 2327 | // XXX - inline |
| 2328 | biosfn_select_vert_res(regs); |
| 2329 | } |
| 2330 | |
| 2331 | static void |
| 2332 | handle_101231(struct bregs *regs) |
| 2333 | { |
| 2334 | // XXX - inline |
| 2335 | biosfn_enable_default_palette_loading(regs); |
| 2336 | } |
| 2337 | |
| 2338 | static void |
| 2339 | handle_101232(struct bregs *regs) |
| 2340 | { |
| 2341 | // XXX - inline |
| 2342 | biosfn_enable_video_addressing(regs); |
| 2343 | } |
| 2344 | |
| 2345 | static void |
| 2346 | handle_101233(struct bregs *regs) |
| 2347 | { |
| 2348 | // XXX - inline |
| 2349 | biosfn_enable_grayscale_summing(regs); |
| 2350 | } |
| 2351 | |
| 2352 | static void |
| 2353 | handle_101234(struct bregs *regs) |
| 2354 | { |
| 2355 | // XXX - inline |
| 2356 | biosfn_enable_cursor_emulation(regs); |
| 2357 | } |
| 2358 | |
| 2359 | static void |
| 2360 | handle_101235(struct bregs *regs) |
| 2361 | { |
| 2362 | debug_stub(regs); |
| 2363 | regs->al = 0x12; |
| 2364 | } |
| 2365 | |
| 2366 | static void |
| 2367 | handle_101236(struct bregs *regs) |
| 2368 | { |
| 2369 | debug_stub(regs); |
| 2370 | regs->al = 0x12; |
| 2371 | } |
| 2372 | |
| 2373 | static void |
| 2374 | handle_1012XX(struct bregs *regs) |
| 2375 | { |
| 2376 | debug_stub(regs); |
| 2377 | } |
| 2378 | |
| 2379 | static void |
| 2380 | handle_1012(struct bregs *regs) |
| 2381 | { |
| 2382 | switch (regs->bl) { |
| 2383 | case 0x10: handle_101210(regs); break; |
| 2384 | case 0x30: handle_101230(regs); break; |
| 2385 | case 0x31: handle_101231(regs); break; |
| 2386 | case 0x32: handle_101232(regs); break; |
| 2387 | case 0x33: handle_101233(regs); break; |
| 2388 | case 0x34: handle_101234(regs); break; |
| 2389 | case 0x35: handle_101235(regs); break; |
| 2390 | case 0x36: handle_101236(regs); break; |
| 2391 | default: handle_1012XX(regs); break; |
| 2392 | } |
| 2393 | |
| 2394 | // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae |
| 2395 | } |
| 2396 | |
| 2397 | |
| 2398 | static void |
| 2399 | handle_1013(struct bregs *regs) |
| 2400 | { |
| 2401 | // XXX - inline |
| 2402 | biosfn_write_string(regs->al, regs->bh, regs->bl, regs->cx |
| 2403 | , regs->dh, regs->dl, regs->es, 0); // regs->bp); |
| 2404 | } |
| 2405 | |
| 2406 | |
| 2407 | static void |
| 2408 | handle_101a00(struct bregs *regs) |
| 2409 | { |
| 2410 | // XXX - inline |
| 2411 | biosfn_read_display_code(regs); |
| 2412 | } |
| 2413 | |
| 2414 | static void |
| 2415 | handle_101a01(struct bregs *regs) |
| 2416 | { |
| 2417 | // XXX - inline |
| 2418 | biosfn_set_display_code(regs); |
| 2419 | } |
| 2420 | |
| 2421 | static void |
| 2422 | handle_101aXX(struct bregs *regs) |
| 2423 | { |
| 2424 | debug_stub(regs); |
| 2425 | } |
| 2426 | |
| 2427 | static void |
| 2428 | handle_101a(struct bregs *regs) |
| 2429 | { |
| 2430 | switch (regs->al) { |
| 2431 | case 0x00: handle_101a00(regs); break; |
| 2432 | case 0x01: handle_101a01(regs); break; |
| 2433 | default: handle_101aXX(regs); break; |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | |
| 2438 | static void |
| 2439 | handle_101b(struct bregs *regs) |
| 2440 | { |
| 2441 | // XXX - inline |
| 2442 | biosfn_read_state_info(regs->bx, regs->es, regs->di); |
| 2443 | regs->al = 0x1B; |
| 2444 | } |
| 2445 | |
| 2446 | |
| 2447 | static void |
| 2448 | handle_101c00(struct bregs *regs) |
| 2449 | { |
| 2450 | // XXX - inline |
| 2451 | regs->bx = biosfn_read_video_state_size(regs->cx); |
| 2452 | } |
| 2453 | |
| 2454 | static void |
| 2455 | handle_101c01(struct bregs *regs) |
| 2456 | { |
| 2457 | // XXX - inline |
| 2458 | biosfn_save_video_state(regs->cx, regs->es, regs->bx); |
| 2459 | } |
| 2460 | |
| 2461 | static void |
| 2462 | handle_101c02(struct bregs *regs) |
| 2463 | { |
| 2464 | // XXX - inline |
| 2465 | biosfn_restore_video_state(regs->cx, regs->es, regs->bx); |
| 2466 | } |
| 2467 | |
| 2468 | static void |
| 2469 | handle_101cXX(struct bregs *regs) |
| 2470 | { |
| 2471 | debug_stub(regs); |
| 2472 | } |
| 2473 | |
| 2474 | static void |
| 2475 | handle_101c(struct bregs *regs) |
| 2476 | { |
| 2477 | switch (regs->al) { |
| 2478 | case 0x00: handle_101c00(regs); break; |
| 2479 | case 0x01: handle_101c01(regs); break; |
| 2480 | case 0x02: handle_101c02(regs); break; |
| 2481 | default: handle_101cXX(regs); break; |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | |
| 2486 | static void |
| 2487 | handle_104f00(struct bregs *regs) |
| 2488 | { |
| 2489 | // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI); |
| 2490 | // XXX - OR cirrus_vesa_00h |
| 2491 | } |
| 2492 | |
| 2493 | static void |
| 2494 | handle_104f01(struct bregs *regs) |
| 2495 | { |
| 2496 | // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI); |
| 2497 | // XXX - OR cirrus_vesa_01h |
| 2498 | } |
| 2499 | |
| 2500 | static void |
| 2501 | handle_104f02(struct bregs *regs) |
| 2502 | { |
| 2503 | // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI); |
| 2504 | // XXX - OR cirrus_vesa_02h |
| 2505 | } |
| 2506 | |
| 2507 | static void |
| 2508 | handle_104f03(struct bregs *regs) |
| 2509 | { |
| 2510 | // XXX - vbe_biosfn_return_current_mode |
| 2511 | // XXX - OR cirrus_vesa_03h |
| 2512 | } |
| 2513 | |
| 2514 | static void |
| 2515 | handle_104f04(struct bregs *regs) |
| 2516 | { |
| 2517 | // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX); |
| 2518 | } |
| 2519 | |
| 2520 | static void |
| 2521 | handle_104f05(struct bregs *regs) |
| 2522 | { |
| 2523 | // XXX - vbe_biosfn_display_window_control |
| 2524 | // XXX - OR cirrus_vesa_05h |
| 2525 | } |
| 2526 | |
| 2527 | static void |
| 2528 | handle_104f06(struct bregs *regs) |
| 2529 | { |
| 2530 | // XXX - vbe_biosfn_set_get_logical_scan_line_length |
| 2531 | // XXX - OR cirrus_vesa_06h |
| 2532 | } |
| 2533 | |
| 2534 | static void |
| 2535 | handle_104f07(struct bregs *regs) |
| 2536 | { |
| 2537 | // XXX - vbe_biosfn_set_get_display_start |
| 2538 | // XXX - OR cirrus_vesa_07h |
| 2539 | } |
| 2540 | |
| 2541 | static void |
| 2542 | handle_104f08(struct bregs *regs) |
| 2543 | { |
| 2544 | // XXX - vbe_biosfn_set_get_dac_palette_format |
| 2545 | } |
| 2546 | |
| 2547 | static void |
| 2548 | handle_104f0a(struct bregs *regs) |
| 2549 | { |
| 2550 | // XXX - vbe_biosfn_return_protected_mode_interface |
| 2551 | } |
| 2552 | |
| 2553 | static void |
| 2554 | handle_104fXX(struct bregs *regs) |
| 2555 | { |
| 2556 | debug_stub(regs); |
| 2557 | regs->ax = 0x0100; |
| 2558 | } |
| 2559 | |
| 2560 | static void |
| 2561 | handle_104f(struct bregs *regs) |
| 2562 | { |
| 2563 | if (! CONFIG_VBE) { |
| 2564 | handle_104fXX(regs); |
| 2565 | return; |
| 2566 | } |
| 2567 | |
| 2568 | // XXX - check vbe_has_vbe_display()? |
| 2569 | |
| 2570 | switch (regs->al) { |
| 2571 | case 0x00: handle_104f00(regs); break; |
| 2572 | case 0x01: handle_104f01(regs); break; |
| 2573 | case 0x02: handle_104f02(regs); break; |
| 2574 | case 0x03: handle_104f03(regs); break; |
| 2575 | case 0x04: handle_104f04(regs); break; |
| 2576 | case 0x05: handle_104f05(regs); break; |
| 2577 | case 0x06: handle_104f06(regs); break; |
| 2578 | case 0x07: handle_104f07(regs); break; |
| 2579 | case 0x08: handle_104f08(regs); break; |
| 2580 | case 0x0a: handle_104f0a(regs); break; |
| 2581 | default: handle_104fXX(regs); break; |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | |
| 2586 | static void |
| 2587 | handle_10XX(struct bregs *regs) |
| 2588 | { |
| 2589 | debug_stub(regs); |
| 2590 | } |
| 2591 | |
| 2592 | // INT 10h Video Support Service Entry Point |
| 2593 | void VISIBLE16 |
| 2594 | handle_10(struct bregs *regs) |
| 2595 | { |
| 2596 | debug_enter(regs, DEBUG_VGA_10); |
| 2597 | switch (regs->ah) { |
| 2598 | case 0x00: handle_1000(regs); break; |
| 2599 | case 0x01: handle_1001(regs); break; |
| 2600 | case 0x02: handle_1002(regs); break; |
| 2601 | case 0x03: handle_1003(regs); break; |
| 2602 | case 0x04: handle_1004(regs); break; |
| 2603 | case 0x05: handle_1005(regs); break; |
| 2604 | case 0x06: handle_1006(regs); break; |
| 2605 | case 0x07: handle_1007(regs); break; |
| 2606 | case 0x08: handle_1008(regs); break; |
| 2607 | case 0x09: handle_1009(regs); break; |
| 2608 | case 0x0a: handle_100a(regs); break; |
| 2609 | case 0x0b: handle_100b(regs); break; |
| 2610 | case 0x0c: handle_100c(regs); break; |
| 2611 | case 0x0d: handle_100d(regs); break; |
| 2612 | case 0x0e: handle_100e(regs); break; |
| 2613 | case 0x0f: handle_100f(regs); break; |
| 2614 | case 0x10: handle_1010(regs); break; |
| 2615 | case 0x11: handle_1011(regs); break; |
| 2616 | case 0x12: handle_1012(regs); break; |
| 2617 | case 0x13: handle_1013(regs); break; |
| 2618 | case 0x1a: handle_101a(regs); break; |
| 2619 | case 0x1b: handle_101b(regs); break; |
| 2620 | case 0x1c: handle_101c(regs); break; |
| 2621 | case 0x4f: handle_104f(regs); break; |
| 2622 | default: handle_10XX(regs); break; |
| 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | |
| 2627 | /**************************************************************** |
| 2628 | * VGA post |
| 2629 | ****************************************************************/ |
| 2630 | |
| 2631 | static void |
| 2632 | init_bios_area() |
| 2633 | { |
| 2634 | // init detected hardware BIOS Area |
| 2635 | // set 80x25 color (not clear from RBIL but usual) |
| 2636 | u16 eqf = GET_BDA(equipment_list_flags); |
| 2637 | SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20); |
| 2638 | |
| 2639 | // Just for the first int10 find its children |
| 2640 | |
| 2641 | // the default char height |
| 2642 | SET_BDA(char_height, 0x10); |
| 2643 | |
| 2644 | // Clear the screen |
| 2645 | SET_BDA(video_ctl, 0x60); |
| 2646 | |
| 2647 | // Set the basic screen we have |
| 2648 | SET_BDA(video_switches, 0xf9); |
| 2649 | |
| 2650 | // Set the basic modeset options |
| 2651 | SET_BDA(modeset_ctl, 0x51); |
| 2652 | |
| 2653 | // Set the default MSR |
| 2654 | SET_BDA(video_msr, 0x09); |
| 2655 | } |
| 2656 | |
| 2657 | static void |
| 2658 | init_vga_card() |
| 2659 | { |
| 2660 | // switch to color mode and enable CPU access 480 lines |
| 2661 | outb(0xc3, VGAREG_WRITE_MISC_OUTPUT); |
| 2662 | // more than 64k 3C4/04 |
| 2663 | outb(0x04, VGAREG_SEQU_ADDRESS); |
| 2664 | outb(0x02, VGAREG_SEQU_DATA); |
| 2665 | } |
| 2666 | |
| 2667 | void VISIBLE16 |
| 2668 | vga_post(struct bregs *regs) |
| 2669 | { |
| 2670 | debug_enter(regs, DEBUG_VGA_POST); |
| 2671 | |
| 2672 | init_vga_card(); |
| 2673 | |
| 2674 | init_bios_area(); |
| 2675 | |
| 2676 | // vbe_init(); |
| 2677 | |
| 2678 | extern void entry_10(void); |
| 2679 | SET_IVT(0x10, 0xC000, (u32)entry_10); |
| 2680 | |
| 2681 | if (CONFIG_CIRRUS) |
| 2682 | cirrus_init(); |
| 2683 | |
| 2684 | // XXX - clear screen and display info |
| 2685 | |
| 2686 | // XXX: fill it |
| 2687 | SET_VGA(video_save_pointer_table[0], (u32)video_param_table); |
| 2688 | SET_VGA(video_save_pointer_table[1], 0xC000); |
| 2689 | |
| 2690 | // Fixup checksum |
| 2691 | extern u8 _rom_header_size, _rom_header_checksum; |
| 2692 | SET_VGA(_rom_header_checksum, 0); |
| 2693 | u8 sum = -checksum_far(0xC000, 0, _rom_header_size * 512); |
| 2694 | SET_VGA(_rom_header_checksum, sum); |
| 2695 | } |