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 | // * review correctness of converted asm by comparing with RBIL |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 11 | // * refactor redundant code into sub-functions |
| 12 | // * See if there is a method to the in/out stuff that can be encapsulated. |
| 13 | // * remove "biosfn" prefixes |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 14 | // * verify all funcs static |
| 15 | // |
Kevin O'Connor | 6ace78f | 2009-05-14 19:24:49 -0400 | [diff] [blame] | 16 | // * convert vbe/clext code |
| 17 | // |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 18 | // * extract hw code from bios interfaces |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 19 | |
| 20 | #include "bregs.h" // struct bregs |
| 21 | #include "biosvar.h" // GET_BDA |
| 22 | #include "util.h" // memset |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 23 | #include "vgatables.h" // find_vga_entry |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 24 | |
| 25 | // XXX |
| 26 | #define CONFIG_VBE 0 |
| 27 | #define CONFIG_CIRRUS 0 |
| 28 | |
| 29 | // XXX |
| 30 | #define DEBUG_VGA_POST 1 |
| 31 | #define DEBUG_VGA_10 3 |
| 32 | |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 33 | #define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val)) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 34 | |
| 35 | |
| 36 | // =================================================================== |
| 37 | // |
| 38 | // Video Utils |
| 39 | // |
| 40 | // =================================================================== |
| 41 | |
| 42 | // ------------------------------------------------------------------- |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 43 | inline void |
| 44 | call16_vgaint(u32 eax, u32 ebx) |
| 45 | { |
| 46 | asm volatile( |
| 47 | "int $0x10\n" |
| 48 | "cli\n" |
| 49 | "cld" |
| 50 | : |
| 51 | : "a"(eax), "b"(ebx) |
| 52 | : "cc", "memory"); |
| 53 | } |
| 54 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 55 | |
| 56 | // =================================================================== |
| 57 | // |
| 58 | // BIOS functions |
| 59 | // |
| 60 | // =================================================================== |
| 61 | |
| 62 | // ------------------------------------------------------------------- |
| 63 | static void |
| 64 | biosfn_perform_gray_scale_summing(u16 start, u16 count) |
| 65 | { |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 66 | vgahw_screen_disable(); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 67 | int i; |
| 68 | for (i = start; i < start+count; i++) { |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 69 | u8 rgb[3]; |
| 70 | vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 71 | |
| 72 | // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue ) |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 73 | u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 74 | if (intensity > 0x3f) |
| 75 | intensity = 0x3f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 76 | |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 77 | vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 78 | } |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 79 | vgahw_screen_enable(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | // ------------------------------------------------------------------- |
| 83 | static void |
| 84 | biosfn_set_cursor_shape(u8 CH, u8 CL) |
| 85 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 86 | CH &= 0x3f; |
| 87 | CL &= 0x1f; |
| 88 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 89 | u16 curs = (CH << 8) + CL; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 90 | SET_BDA(cursor_type, curs); |
| 91 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 92 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
| 93 | u16 cheight = GET_BDA(char_height); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 94 | if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 95 | if (CL != (CH + 1)) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 96 | CH = ((CH + 1) * cheight / 8) - 1; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 97 | else |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 98 | CH = ((CL + 1) * cheight / 8) - 2; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 99 | CL = ((CL + 1) * cheight / 8) - 1; |
| 100 | } |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 101 | vgahw_set_cursor_shape(CH, CL); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 104 | static u16 |
| 105 | biosfn_get_cursor_shape(u8 page) |
| 106 | { |
| 107 | if (page > 7) |
| 108 | return 0; |
| 109 | // FIXME should handle VGA 14/16 lines |
| 110 | return GET_BDA(cursor_type); |
| 111 | } |
| 112 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 113 | // ------------------------------------------------------------------- |
| 114 | static void |
| 115 | biosfn_set_cursor_pos(u8 page, u16 cursor) |
| 116 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 117 | // Should not happen... |
| 118 | if (page > 7) |
| 119 | return; |
| 120 | |
| 121 | // Bios cursor pos |
| 122 | SET_BDA(cursor_pos[page], cursor); |
| 123 | |
| 124 | // Set the hardware cursor |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 125 | u8 current = GET_BDA(video_page); |
| 126 | if (page != current) |
| 127 | return; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 128 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 129 | // Get the dimensions |
| 130 | u16 nbcols = GET_BDA(video_cols); |
| 131 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 132 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 133 | u8 xcurs = cursor & 0x00ff; |
| 134 | u8 ycurs = (cursor & 0xff00) >> 8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 135 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 136 | // Calculate the address knowing nbcols nbrows and page num |
| 137 | u16 address = SCREEN_IO_START(nbcols, nbrows, page) + xcurs + ycurs * nbcols; |
| 138 | |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 139 | vgahw_set_cursor_pos(address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 140 | } |
| 141 | |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 142 | u16 |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 143 | biosfn_get_cursor_pos(u8 page) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 144 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 145 | if (page > 7) |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 146 | return 0; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 147 | // FIXME should handle VGA 14/16 lines |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 148 | return GET_BDA(cursor_pos[page]); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | // ------------------------------------------------------------------- |
| 152 | static void |
| 153 | biosfn_set_active_page(u8 page) |
| 154 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 155 | if (page > 7) |
| 156 | return; |
| 157 | |
| 158 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 159 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 160 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 161 | return; |
| 162 | |
| 163 | // Get pos curs pos for the right page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 164 | u16 cursor = biosfn_get_cursor_pos(page); |
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 | u16 address; |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 167 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 168 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 169 | u16 nbcols = GET_BDA(video_cols); |
| 170 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 171 | |
| 172 | // Calculate the address knowing nbcols nbrows and page num |
| 173 | address = SCREEN_MEM_START(nbcols, nbrows, page); |
| 174 | SET_BDA(video_pagestart, address); |
| 175 | |
| 176 | // Start address |
| 177 | address = SCREEN_IO_START(nbcols, nbrows, page); |
| 178 | } else { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 179 | struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam); |
| 180 | address = page * GET_GLOBAL(vparam_g->slength); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 181 | } |
| 182 | |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 183 | vgahw_set_active_page(address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 184 | |
| 185 | // And change the BIOS page |
| 186 | SET_BDA(video_page, page); |
| 187 | |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 188 | dprintf(1, "Set active page %02x address %04x\n", page, address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 189 | |
| 190 | // Display the cursor, now the page is active |
| 191 | biosfn_set_cursor_pos(page, cursor); |
| 192 | } |
| 193 | |
| 194 | static void |
| 195 | biosfn_set_video_mode(u8 mode) |
| 196 | { // mode: Bit 7 is 1 if no clear screen |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 197 | if (CONFIG_CIRRUS) |
| 198 | cirrus_set_video_mode(mode); |
| 199 | |
Kevin O'Connor | 21079f4 | 2009-05-16 21:30:10 -0400 | [diff] [blame] | 200 | if (CONFIG_VBE) |
| 201 | if (vbe_has_vbe_display()) |
| 202 | dispi_set_enable(VBE_DISPI_DISABLED); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 203 | |
| 204 | // The real mode |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 205 | u8 noclearmem = mode & 0x80; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 206 | mode = mode & 0x7f; |
| 207 | |
| 208 | // find the entry in the video modes |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 209 | struct vgamode_s *vmode_g = find_vga_entry(mode); |
| 210 | dprintf(1, "mode search %02x found %p\n", mode, vmode_g); |
| 211 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 212 | return; |
| 213 | |
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 | u16 twidth = GET_GLOBAL(vparam_g->twidth); |
| 216 | u16 theightm1 = GET_GLOBAL(vparam_g->theightm1); |
| 217 | u16 cheight = GET_GLOBAL(vparam_g->cheight); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 218 | |
| 219 | // Read the bios mode set control |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 220 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 221 | |
| 222 | // Then we know the number of lines |
| 223 | // FIXME |
| 224 | |
| 225 | // if palette loading (bit 3 of modeset ctl = 0) |
| 226 | if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 227 | outb(GET_GLOBAL(vmode_g->pelmask), VGAREG_PEL_MASK); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 228 | |
| 229 | // Set the whole dac always, from 0 |
| 230 | outb(0x00, VGAREG_DAC_WRITE_ADDRESS); |
| 231 | |
| 232 | // From which palette |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 233 | u8 *palette_g = GET_GLOBAL(vmode_g->dac); |
Kevin O'Connor | 3c3c831 | 2009-05-17 16:16:29 -0400 | [diff] [blame] | 234 | u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 235 | // Always 256*3 values |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 236 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 237 | for (i = 0; i < 0x0100; i++) { |
Kevin O'Connor | 3c3c831 | 2009-05-17 16:16:29 -0400 | [diff] [blame] | 238 | if (i < palsize) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 239 | outb(GET_GLOBAL(palette_g[(i * 3) + 0]), VGAREG_DAC_DATA); |
| 240 | outb(GET_GLOBAL(palette_g[(i * 3) + 1]), VGAREG_DAC_DATA); |
| 241 | outb(GET_GLOBAL(palette_g[(i * 3) + 2]), VGAREG_DAC_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 242 | } else { |
| 243 | outb(0, VGAREG_DAC_DATA); |
| 244 | outb(0, VGAREG_DAC_DATA); |
| 245 | outb(0, VGAREG_DAC_DATA); |
| 246 | } |
| 247 | } |
| 248 | if ((modeset_ctl & 0x02) == 0x02) |
| 249 | biosfn_perform_gray_scale_summing(0x00, 0x100); |
| 250 | } |
| 251 | // Reset Attribute Ctl flip-flop |
| 252 | inb(VGAREG_ACTL_RESET); |
| 253 | |
| 254 | // Set Attribute Ctl |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 255 | u16 i; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 256 | for (i = 0; i <= 0x13; i++) { |
| 257 | outb(i, VGAREG_ACTL_ADDRESS); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 258 | 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] | 259 | } |
| 260 | outb(0x14, VGAREG_ACTL_ADDRESS); |
| 261 | outb(0x00, VGAREG_ACTL_WRITE_DATA); |
| 262 | |
| 263 | // Set Sequencer Ctl |
| 264 | outb(0, VGAREG_SEQU_ADDRESS); |
| 265 | outb(0x03, VGAREG_SEQU_DATA); |
| 266 | for (i = 1; i <= 4; i++) { |
| 267 | outb(i, VGAREG_SEQU_ADDRESS); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 268 | 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] | 269 | } |
| 270 | |
| 271 | // Set Grafx Ctl |
| 272 | for (i = 0; i <= 8; i++) { |
| 273 | outb(i, VGAREG_GRDC_ADDRESS); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 274 | outb(GET_GLOBAL(vparam_g->grdc_regs[i]), VGAREG_GRDC_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | // Set CRTC address VGA or MDA |
| 278 | u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS; |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 279 | if (GET_GLOBAL(vmode_g->memmodel) == MTEXT) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 280 | crtc_addr = VGAREG_MDA_CRTC_ADDRESS; |
| 281 | |
| 282 | // Disable CRTC write protection |
| 283 | outw(0x0011, crtc_addr); |
| 284 | // Set CRTC regs |
| 285 | for (i = 0; i <= 0x18; i++) { |
| 286 | outb(i, crtc_addr); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 287 | outb(GET_GLOBAL(vparam_g->crtc_regs[i]), crtc_addr + 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | // Set the misc register |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 291 | outb(GET_GLOBAL(vparam_g->miscreg), VGAREG_WRITE_MISC_OUTPUT); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 292 | |
| 293 | // Enable video |
| 294 | outb(0x20, VGAREG_ACTL_ADDRESS); |
| 295 | inb(VGAREG_ACTL_RESET); |
| 296 | |
| 297 | if (noclearmem == 0x00) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 298 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
| 299 | memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0720, 32*1024); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 300 | } else { |
| 301 | if (mode < 0x0d) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 302 | memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 32*1024); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 303 | } else { |
| 304 | outb(0x02, VGAREG_SEQU_ADDRESS); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 305 | u8 mmask = inb(VGAREG_SEQU_DATA); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 306 | outb(0x0f, VGAREG_SEQU_DATA); // all planes |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 307 | memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 64*1024); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 308 | outb(mmask, VGAREG_SEQU_DATA); |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | // Set the BIOS mem |
| 313 | SET_BDA(video_mode, mode); |
| 314 | SET_BDA(video_cols, twidth); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 315 | SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 316 | SET_BDA(crtc_address, crtc_addr); |
| 317 | SET_BDA(video_rows, theightm1); |
| 318 | SET_BDA(char_height, cheight); |
| 319 | SET_BDA(video_ctl, (0x60 | noclearmem)); |
| 320 | SET_BDA(video_switches, 0xF9); |
| 321 | SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f); |
| 322 | |
| 323 | // FIXME We nearly have the good tables. to be reworked |
| 324 | SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now |
| 325 | SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table); |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 326 | SET_BDA(video_savetable_seg, get_global_seg()); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 327 | |
| 328 | // FIXME |
| 329 | SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but... |
| 330 | SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but... |
| 331 | |
| 332 | // Set cursor shape |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 333 | if (GET_GLOBAL(vmode_g->class) == TEXT) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 334 | biosfn_set_cursor_shape(0x06, 0x07); |
| 335 | // Set cursor pos for page 0..7 |
| 336 | for (i = 0; i < 8; i++) |
| 337 | biosfn_set_cursor_pos(i, 0x0000); |
| 338 | |
| 339 | // Set active page 0 |
| 340 | biosfn_set_active_page(0x00); |
| 341 | |
| 342 | // Write the fonts in memory |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 343 | if (GET_GLOBAL(vmode_g->class) == TEXT) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 344 | call16_vgaint(0x1104, 0); |
| 345 | call16_vgaint(0x1103, 0); |
| 346 | } |
| 347 | // Set the ints 0x1F and 0x43 |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 348 | SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 349 | |
| 350 | switch (cheight) { |
| 351 | case 8: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 352 | SET_IVT(0x43, get_global_seg(), (u32)vgafont8); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 353 | break; |
| 354 | case 14: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 355 | SET_IVT(0x43, get_global_seg(), (u32)vgafont14); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 356 | break; |
| 357 | case 16: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 358 | SET_IVT(0x43, get_global_seg(), (u32)vgafont16); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // ------------------------------------------------------------------- |
| 364 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 365 | biosfn_write_teletype(u8 car, u8 page, u8 attr, u8 flag) |
| 366 | { // flag = WITH_ATTR / NO_ATTR |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 367 | // special case if page is 0xff, use current page |
| 368 | if (page == 0xff) |
| 369 | page = GET_BDA(video_page); |
| 370 | |
| 371 | // Get the mode |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 372 | struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode)); |
| 373 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 374 | return; |
| 375 | |
| 376 | // Get the cursor pos for the page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 377 | u16 cursor = biosfn_get_cursor_pos(page); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 378 | u8 xcurs = cursor & 0x00ff; |
| 379 | u8 ycurs = (cursor & 0xff00) >> 8; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 380 | |
| 381 | // Get the dimensions |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 382 | u16 nbrows = GET_BDA(video_rows) + 1; |
| 383 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 384 | |
| 385 | switch (car) { |
| 386 | case 7: |
| 387 | //FIXME should beep |
| 388 | break; |
| 389 | |
| 390 | case 8: |
| 391 | if (xcurs > 0) |
| 392 | xcurs--; |
| 393 | break; |
| 394 | |
| 395 | case '\r': |
| 396 | xcurs = 0; |
| 397 | break; |
| 398 | |
| 399 | case '\n': |
| 400 | ycurs++; |
| 401 | break; |
| 402 | |
| 403 | case '\t': |
| 404 | do { |
| 405 | biosfn_write_teletype(' ', page, attr, flag); |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 406 | cursor = biosfn_get_cursor_pos(page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 407 | xcurs = cursor & 0x00ff; |
| 408 | ycurs = (cursor & 0xff00) >> 8; |
| 409 | } while (xcurs % 8 == 0); |
| 410 | break; |
| 411 | |
| 412 | default: |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 413 | if (flag == WITH_ATTR) |
| 414 | biosfn_write_char_attr(car, page, attr, 1); |
| 415 | else |
| 416 | biosfn_write_char_only(car, page, attr, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 417 | xcurs++; |
| 418 | } |
| 419 | |
| 420 | // Do we need to wrap ? |
| 421 | if (xcurs == nbcols) { |
| 422 | xcurs = 0; |
| 423 | ycurs++; |
| 424 | } |
| 425 | // Do we need to scroll ? |
| 426 | if (ycurs == nbrows) { |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 427 | if (GET_GLOBAL(vmode_g->class) == TEXT) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 428 | biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, page, |
| 429 | SCROLL_UP); |
| 430 | else |
| 431 | biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, page, |
| 432 | SCROLL_UP); |
| 433 | ycurs -= 1; |
| 434 | } |
| 435 | // Set the cursor for the page |
| 436 | cursor = ycurs; |
| 437 | cursor <<= 8; |
| 438 | cursor += xcurs; |
| 439 | biosfn_set_cursor_pos(page, cursor); |
| 440 | } |
| 441 | |
| 442 | // ------------------------------------------------------------------- |
| 443 | static void |
| 444 | biosfn_get_video_mode(struct bregs *regs) |
| 445 | { |
| 446 | regs->bh = GET_BDA(video_page); |
| 447 | regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80); |
| 448 | regs->ah = GET_BDA(video_cols); |
| 449 | } |
| 450 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 451 | static void |
| 452 | set_scan_lines(u8 lines) |
| 453 | { |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 454 | vgahw_set_scan_lines(lines); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 455 | if (lines == 8) |
| 456 | biosfn_set_cursor_shape(0x06, 0x07); |
| 457 | else |
| 458 | biosfn_set_cursor_shape(lines - 4, lines - 3); |
| 459 | SET_BDA(char_height, lines); |
Kevin O'Connor | a0ecb05 | 2009-05-18 23:34:00 -0400 | [diff] [blame] | 460 | u16 vde = vgahw_get_vde(); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 461 | u8 rows = vde / lines; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 462 | SET_BDA(video_rows, rows - 1); |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 463 | u16 cols = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 464 | SET_BDA(video_pagesize, rows * cols * 2); |
| 465 | } |
| 466 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 467 | // ------------------------------------------------------------------- |
| 468 | static void |
| 469 | biosfn_get_font_info(u8 BH, u16 *ES, u16 *BP, u16 *CX, u16 *DX) |
| 470 | { |
| 471 | switch (BH) { |
| 472 | case 0x00: { |
| 473 | u32 segoff = GET_IVT(0x1f).segoff; |
| 474 | *ES = segoff >> 16; |
| 475 | *BP = segoff; |
| 476 | break; |
| 477 | } |
| 478 | case 0x01: { |
| 479 | u32 segoff = GET_IVT(0x43).segoff; |
| 480 | *ES = segoff >> 16; |
| 481 | *BP = segoff; |
| 482 | break; |
| 483 | } |
| 484 | case 0x02: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 485 | *ES = get_global_seg(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 486 | *BP = (u32)vgafont14; |
| 487 | break; |
| 488 | case 0x03: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 489 | *ES = get_global_seg(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 490 | *BP = (u32)vgafont8; |
| 491 | break; |
| 492 | case 0x04: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 493 | *ES = get_global_seg(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 494 | *BP = (u32)vgafont8 + 128 * 8; |
| 495 | break; |
| 496 | case 0x05: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 497 | *ES = get_global_seg(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 498 | *BP = (u32)vgafont14alt; |
| 499 | break; |
| 500 | case 0x06: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 501 | *ES = get_global_seg(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 502 | *BP = (u32)vgafont16; |
| 503 | break; |
| 504 | case 0x07: |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 505 | *ES = get_global_seg(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 506 | *BP = (u32)vgafont16alt; |
| 507 | break; |
| 508 | default: |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 509 | dprintf(1, "Get font info BH(%02x) was discarded\n", BH); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 510 | return; |
| 511 | } |
| 512 | // Set byte/char of on screen font |
| 513 | *CX = GET_BDA(char_height) & 0xff; |
| 514 | |
| 515 | // Set Highest char row |
| 516 | *DX = GET_BDA(video_rows); |
| 517 | } |
| 518 | |
| 519 | // ------------------------------------------------------------------- |
| 520 | static void |
| 521 | biosfn_get_ega_info(struct bregs *regs) |
| 522 | { |
| 523 | regs->cx = GET_BDA(video_switches) & 0x0f; |
| 524 | regs->ax = GET_BDA(crtc_address); |
| 525 | if (regs->ax == VGAREG_MDA_CRTC_ADDRESS) |
| 526 | regs->bx = 0x0103; |
| 527 | else |
| 528 | regs->bx = 0x0003; |
| 529 | } |
| 530 | |
| 531 | // ------------------------------------------------------------------- |
| 532 | static void |
| 533 | biosfn_select_vert_res(struct bregs *regs) |
| 534 | { |
| 535 | u8 mctl = GET_BDA(modeset_ctl); |
| 536 | u8 vswt = GET_BDA(video_switches); |
| 537 | |
| 538 | switch (regs->al) { |
| 539 | case 0x00: |
| 540 | // 200 lines |
| 541 | mctl = (mctl & ~0x10) | 0x80; |
| 542 | vswt = (vswt & ~0x0f) | 0x08; |
| 543 | break; |
| 544 | case 0x01: |
| 545 | // 350 lines |
| 546 | mctl &= ~0x90; |
| 547 | vswt = (vswt & ~0x0f) | 0x09; |
| 548 | break; |
| 549 | case 0x02: |
| 550 | // 400 lines |
| 551 | mctl = (mctl & ~0x80) | 0x10; |
| 552 | vswt = (vswt & ~0x0f) | 0x09; |
| 553 | break; |
| 554 | default: |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 555 | dprintf(1, "Select vert res (%02x) was discarded\n", regs->al); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 556 | break; |
| 557 | } |
| 558 | SET_BDA(modeset_ctl, mctl); |
| 559 | SET_BDA(video_switches, vswt); |
| 560 | regs->ax = 0x1212; |
| 561 | } |
| 562 | |
| 563 | static void |
| 564 | biosfn_enable_default_palette_loading(struct bregs *regs) |
| 565 | { |
| 566 | u8 v = (regs->al & 0x01) << 3; |
| 567 | u8 mctl = GET_BDA(video_ctl) & ~0x08; |
| 568 | SET_BDA(video_ctl, mctl | v); |
| 569 | regs->ax = 0x1212; |
| 570 | } |
| 571 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 572 | |
| 573 | static void |
| 574 | biosfn_enable_grayscale_summing(struct bregs *regs) |
| 575 | { |
| 576 | u8 v = ((regs->al << 1) & 0x02) ^ 0x02; |
| 577 | u8 v2 = GET_BDA(modeset_ctl) & ~0x02; |
| 578 | SET_BDA(modeset_ctl, v | v2); |
| 579 | regs->ax = 0x1212; |
| 580 | } |
| 581 | |
| 582 | static void |
| 583 | biosfn_enable_cursor_emulation(struct bregs *regs) |
| 584 | { |
| 585 | u8 v = (regs->al & 0x01) ^ 0x01; |
| 586 | u8 v2 = GET_BDA(modeset_ctl) & ~0x01; |
| 587 | SET_BDA(modeset_ctl, v | v2); |
| 588 | regs->ax = 0x1212; |
| 589 | } |
| 590 | |
| 591 | // ------------------------------------------------------------------- |
| 592 | static void |
| 593 | 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] | 594 | u16 seg, u8 *offset_far) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 595 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 596 | // Read curs info for the page |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 597 | u16 oldcurs = biosfn_get_cursor_pos(page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 598 | |
| 599 | // if row=0xff special case : use current cursor position |
| 600 | if (row == 0xff) { |
| 601 | col = oldcurs & 0x00ff; |
| 602 | row = (oldcurs & 0xff00) >> 8; |
| 603 | } |
| 604 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 605 | u16 newcurs = row; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 606 | newcurs <<= 8; |
| 607 | newcurs += col; |
| 608 | biosfn_set_cursor_pos(page, newcurs); |
| 609 | |
| 610 | while (count-- != 0) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 611 | u8 car = GET_FARVAR(seg, *offset_far); |
| 612 | offset_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 613 | if ((flag & 0x02) != 0) { |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 614 | attr = GET_FARVAR(seg, *offset_far); |
| 615 | offset_far++; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | biosfn_write_teletype(car, page, attr, WITH_ATTR); |
| 619 | } |
| 620 | |
| 621 | // Set back curs pos |
| 622 | if ((flag & 0x01) == 0) |
| 623 | biosfn_set_cursor_pos(page, oldcurs); |
| 624 | } |
| 625 | |
| 626 | // ------------------------------------------------------------------- |
| 627 | static void |
| 628 | biosfn_read_display_code(struct bregs *regs) |
| 629 | { |
| 630 | regs->bx = GET_BDA(dcc_index); |
| 631 | regs->al = 0x1a; |
| 632 | } |
| 633 | |
| 634 | static void |
| 635 | biosfn_set_display_code(struct bregs *regs) |
| 636 | { |
| 637 | SET_BDA(dcc_index, regs->bl); |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 638 | dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 639 | regs->al = 0x1a; |
| 640 | } |
| 641 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 642 | static void |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 643 | biosfn_save_bda_state(u16 seg, struct saveBDAstate *info) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 644 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 645 | SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode)); |
| 646 | SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols)); |
| 647 | SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize)); |
| 648 | SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address)); |
| 649 | SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows)); |
| 650 | SET_FARVAR(seg, info->char_height, GET_BDA(char_height)); |
| 651 | SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl)); |
| 652 | SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches)); |
| 653 | SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl)); |
| 654 | SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type)); |
| 655 | u16 i; |
| 656 | for (i=0; i<8; i++) |
| 657 | SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i])); |
| 658 | SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart)); |
| 659 | SET_FARVAR(seg, info->video_page, GET_BDA(video_page)); |
| 660 | /* current font */ |
| 661 | SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff); |
| 662 | SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 663 | } |
| 664 | |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 665 | static void |
| 666 | biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 667 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 668 | SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode)); |
| 669 | SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols)); |
| 670 | SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize)); |
| 671 | SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address)); |
| 672 | SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows)); |
| 673 | SET_BDA(char_height, GET_FARVAR(seg, info->char_height)); |
| 674 | SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl)); |
| 675 | SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches)); |
| 676 | SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl)); |
| 677 | SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type)); |
| 678 | u16 i; |
| 679 | for (i = 0; i < 8; i++) |
| 680 | SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i])); |
| 681 | SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart)); |
| 682 | SET_BDA(video_page, GET_FARVAR(seg, info->video_page)); |
| 683 | /* current font */ |
| 684 | SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg) |
| 685 | , GET_FARVAR(seg, info->font0_off)); |
| 686 | SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg) |
| 687 | , GET_FARVAR(seg, info->font1_off)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | |
| 691 | /**************************************************************** |
| 692 | * VGA int 10 handler |
| 693 | ****************************************************************/ |
| 694 | |
| 695 | static void |
| 696 | handle_1000(struct bregs *regs) |
| 697 | { |
| 698 | // XXX - inline |
| 699 | biosfn_set_video_mode(regs->al); |
| 700 | switch(regs->al & 0x7F) { |
| 701 | case 6: |
| 702 | regs->al = 0x3F; |
| 703 | break; |
| 704 | case 0: |
| 705 | case 1: |
| 706 | case 2: |
| 707 | case 3: |
| 708 | case 4: |
| 709 | case 5: |
| 710 | case 7: |
| 711 | regs->al = 0x30; |
| 712 | break; |
| 713 | default: |
| 714 | regs->al = 0x20; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | static void |
| 719 | handle_1001(struct bregs *regs) |
| 720 | { |
| 721 | biosfn_set_cursor_shape(regs->ch, regs->cl); |
| 722 | } |
| 723 | |
| 724 | static void |
| 725 | handle_1002(struct bregs *regs) |
| 726 | { |
| 727 | biosfn_set_cursor_pos(regs->bh, regs->dx); |
| 728 | } |
| 729 | |
| 730 | static void |
| 731 | handle_1003(struct bregs *regs) |
| 732 | { |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 733 | regs->cx = biosfn_get_cursor_shape(regs->bh); |
| 734 | regs->dx = biosfn_get_cursor_pos(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // Read light pen pos (unimplemented) |
| 738 | static void |
| 739 | handle_1004(struct bregs *regs) |
| 740 | { |
| 741 | debug_stub(regs); |
| 742 | regs->ax = regs->bx = regs->cx = regs->dx = 0; |
| 743 | } |
| 744 | |
| 745 | static void |
| 746 | handle_1005(struct bregs *regs) |
| 747 | { |
| 748 | biosfn_set_active_page(regs->al); |
| 749 | } |
| 750 | |
| 751 | static void |
| 752 | handle_1006(struct bregs *regs) |
| 753 | { |
| 754 | biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl |
| 755 | , 0xFF, SCROLL_UP); |
| 756 | } |
| 757 | |
| 758 | static void |
| 759 | handle_1007(struct bregs *regs) |
| 760 | { |
| 761 | biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl |
| 762 | , 0xFF, SCROLL_DOWN); |
| 763 | } |
| 764 | |
| 765 | static void |
| 766 | handle_1008(struct bregs *regs) |
| 767 | { |
| 768 | // XXX - inline |
| 769 | biosfn_read_char_attr(regs->bh, ®s->ax); |
| 770 | } |
| 771 | |
| 772 | static void |
| 773 | handle_1009(struct bregs *regs) |
| 774 | { |
| 775 | // XXX - inline |
| 776 | biosfn_write_char_attr(regs->al, regs->bh, regs->bl, regs->cx); |
| 777 | } |
| 778 | |
| 779 | static void |
| 780 | handle_100a(struct bregs *regs) |
| 781 | { |
| 782 | // XXX - inline |
| 783 | biosfn_write_char_only(regs->al, regs->bh, regs->bl, regs->cx); |
| 784 | } |
| 785 | |
| 786 | |
| 787 | static void |
| 788 | handle_100b00(struct bregs *regs) |
| 789 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 790 | vgahw_set_border_color(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | static void |
| 794 | handle_100b01(struct bregs *regs) |
| 795 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 796 | vgahw_set_palette(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | static void |
| 800 | handle_100bXX(struct bregs *regs) |
| 801 | { |
| 802 | debug_stub(regs); |
| 803 | } |
| 804 | |
| 805 | static void |
| 806 | handle_100b(struct bregs *regs) |
| 807 | { |
| 808 | switch (regs->bh) { |
| 809 | case 0x00: handle_100b00(regs); break; |
| 810 | case 0x01: handle_100b01(regs); break; |
| 811 | default: handle_100bXX(regs); break; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | |
| 816 | static void |
| 817 | handle_100c(struct bregs *regs) |
| 818 | { |
| 819 | // XXX - inline |
| 820 | biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx); |
| 821 | } |
| 822 | |
| 823 | static void |
| 824 | handle_100d(struct bregs *regs) |
| 825 | { |
| 826 | // XXX - inline |
| 827 | biosfn_read_pixel(regs->bh, regs->cx, regs->dx, ®s->ax); |
| 828 | } |
| 829 | |
| 830 | static void |
| 831 | handle_100e(struct bregs *regs) |
| 832 | { |
| 833 | // Ralf Brown Interrupt list is WRONG on bh(page) |
| 834 | // We do output only on the current page ! |
| 835 | biosfn_write_teletype(regs->al, 0xff, regs->bl, NO_ATTR); |
| 836 | } |
| 837 | |
| 838 | static void |
| 839 | handle_100f(struct bregs *regs) |
| 840 | { |
| 841 | // XXX - inline |
| 842 | biosfn_get_video_mode(regs); |
| 843 | } |
| 844 | |
| 845 | |
| 846 | static void |
| 847 | handle_101000(struct bregs *regs) |
| 848 | { |
| 849 | if (regs->bl > 0x14) |
| 850 | return; |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 851 | vgahw_set_single_palette_reg(regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static void |
| 855 | handle_101001(struct bregs *regs) |
| 856 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 857 | vgahw_set_overscan_border_color(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static void |
| 861 | handle_101002(struct bregs *regs) |
| 862 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 863 | vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | static void |
| 867 | handle_101003(struct bregs *regs) |
| 868 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 869 | vgahw_toggle_intensity(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static void |
| 873 | handle_101007(struct bregs *regs) |
| 874 | { |
| 875 | if (regs->bl > 0x14) |
| 876 | return; |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 877 | regs->bh = vgahw_get_single_palette_reg(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | static void |
| 881 | handle_101008(struct bregs *regs) |
| 882 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 883 | regs->bh = vgahw_get_overscan_border_color(regs); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static void |
| 887 | handle_101009(struct bregs *regs) |
| 888 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 889 | vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | static void |
| 893 | handle_101010(struct bregs *regs) |
| 894 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 895 | u8 rgb[3] = {regs->dh, regs->ch, regs->cl}; |
| 896 | vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static void |
| 900 | handle_101012(struct bregs *regs) |
| 901 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 902 | vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static void |
| 906 | handle_101013(struct bregs *regs) |
| 907 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 908 | vgahw_select_video_dac_color_page(regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static void |
| 912 | handle_101015(struct bregs *regs) |
| 913 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 914 | u8 rgb[3]; |
| 915 | vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1); |
| 916 | regs->dh = rgb[0]; |
| 917 | regs->ch = rgb[1]; |
| 918 | regs->cl = rgb[2]; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | static void |
| 922 | handle_101017(struct bregs *regs) |
| 923 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 924 | vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static void |
| 928 | handle_101018(struct bregs *regs) |
| 929 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 930 | vgahw_set_pel_mask(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | static void |
| 934 | handle_101019(struct bregs *regs) |
| 935 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 936 | regs->bl = vgahw_get_pel_mask(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | static void |
| 940 | handle_10101a(struct bregs *regs) |
| 941 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 942 | vgahw_read_video_dac_state(®s->bl, ®s->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static void |
| 946 | handle_10101b(struct bregs *regs) |
| 947 | { |
| 948 | biosfn_perform_gray_scale_summing(regs->bx, regs->cx); |
| 949 | } |
| 950 | |
| 951 | static void |
| 952 | handle_1010XX(struct bregs *regs) |
| 953 | { |
| 954 | debug_stub(regs); |
| 955 | } |
| 956 | |
| 957 | static void |
| 958 | handle_1010(struct bregs *regs) |
| 959 | { |
| 960 | switch (regs->al) { |
| 961 | case 0x00: handle_101000(regs); break; |
| 962 | case 0x01: handle_101001(regs); break; |
| 963 | case 0x02: handle_101002(regs); break; |
| 964 | case 0x03: handle_101003(regs); break; |
| 965 | case 0x07: handle_101007(regs); break; |
| 966 | case 0x08: handle_101008(regs); break; |
| 967 | case 0x09: handle_101009(regs); break; |
| 968 | case 0x10: handle_101010(regs); break; |
| 969 | case 0x12: handle_101012(regs); break; |
| 970 | case 0x13: handle_101013(regs); break; |
| 971 | case 0x15: handle_101015(regs); break; |
| 972 | case 0x17: handle_101017(regs); break; |
| 973 | case 0x18: handle_101018(regs); break; |
| 974 | case 0x19: handle_101019(regs); break; |
| 975 | case 0x1a: handle_10101a(regs); break; |
| 976 | case 0x1b: handle_10101b(regs); break; |
| 977 | default: handle_1010XX(regs); break; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | |
| 982 | static void |
| 983 | handle_101100(struct bregs *regs) |
| 984 | { |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 985 | biosfn_load_text_user_pat(regs->es, regs->bp |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 986 | , regs->cx, regs->dx, regs->bl, regs->bh); |
| 987 | } |
| 988 | |
| 989 | static void |
| 990 | handle_101101(struct bregs *regs) |
| 991 | { |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 992 | biosfn_load_text_8_14_pat(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | static void |
| 996 | handle_101102(struct bregs *regs) |
| 997 | { |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 998 | biosfn_load_text_8_8_pat(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static void |
| 1002 | handle_101103(struct bregs *regs) |
| 1003 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 1004 | vgahw_set_text_block_specifier(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | static void |
| 1008 | handle_101104(struct bregs *regs) |
| 1009 | { |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 1010 | biosfn_load_text_8_16_pat(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | static void |
| 1014 | handle_101110(struct bregs *regs) |
| 1015 | { |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 1016 | biosfn_load_text_user_pat(regs->es, regs->bp |
| 1017 | , regs->cx, regs->dx, regs->bl, regs->bh); |
| 1018 | set_scan_lines(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | static void |
| 1022 | handle_101111(struct bregs *regs) |
| 1023 | { |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 1024 | biosfn_load_text_8_14_pat(regs->bl); |
| 1025 | set_scan_lines(14); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static void |
| 1029 | handle_101112(struct bregs *regs) |
| 1030 | { |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 1031 | biosfn_load_text_8_8_pat(regs->bl); |
| 1032 | set_scan_lines(8); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | static void |
| 1036 | handle_101114(struct bregs *regs) |
| 1037 | { |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 1038 | biosfn_load_text_8_16_pat(regs->bl); |
| 1039 | set_scan_lines(16); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | static void |
| 1043 | handle_101130(struct bregs *regs) |
| 1044 | { |
| 1045 | // XXX - inline |
Kevin O'Connor | 99e08b7 | 2009-05-17 00:07:31 -0400 | [diff] [blame] | 1046 | biosfn_get_font_info(regs->bh, ®s->es, ®s->bp |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1047 | , ®s->cx, ®s->dx); |
| 1048 | } |
| 1049 | |
| 1050 | static void |
| 1051 | handle_1011XX(struct bregs *regs) |
| 1052 | { |
| 1053 | debug_stub(regs); |
| 1054 | } |
| 1055 | |
| 1056 | static void |
| 1057 | handle_1011(struct bregs *regs) |
| 1058 | { |
| 1059 | switch (regs->al) { |
| 1060 | case 0x00: handle_101100(regs); break; |
| 1061 | case 0x01: handle_101101(regs); break; |
| 1062 | case 0x02: handle_101102(regs); break; |
| 1063 | case 0x03: handle_101103(regs); break; |
| 1064 | case 0x04: handle_101104(regs); break; |
| 1065 | case 0x10: handle_101110(regs); break; |
| 1066 | case 0x11: handle_101111(regs); break; |
| 1067 | case 0x12: handle_101112(regs); break; |
| 1068 | case 0x14: handle_101114(regs); break; |
| 1069 | case 0x30: handle_101130(regs); break; |
| 1070 | default: handle_1011XX(regs); break; |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | |
| 1075 | static void |
| 1076 | handle_101210(struct bregs *regs) |
| 1077 | { |
| 1078 | // XXX - inline |
| 1079 | biosfn_get_ega_info(regs); |
| 1080 | } |
| 1081 | |
| 1082 | static void |
| 1083 | handle_101230(struct bregs *regs) |
| 1084 | { |
| 1085 | // XXX - inline |
| 1086 | biosfn_select_vert_res(regs); |
| 1087 | } |
| 1088 | |
| 1089 | static void |
| 1090 | handle_101231(struct bregs *regs) |
| 1091 | { |
| 1092 | // XXX - inline |
| 1093 | biosfn_enable_default_palette_loading(regs); |
| 1094 | } |
| 1095 | |
| 1096 | static void |
| 1097 | handle_101232(struct bregs *regs) |
| 1098 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 1099 | vgahw_enable_video_addressing(regs->al); |
| 1100 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | static void |
| 1104 | handle_101233(struct bregs *regs) |
| 1105 | { |
| 1106 | // XXX - inline |
| 1107 | biosfn_enable_grayscale_summing(regs); |
| 1108 | } |
| 1109 | |
| 1110 | static void |
| 1111 | handle_101234(struct bregs *regs) |
| 1112 | { |
| 1113 | // XXX - inline |
| 1114 | biosfn_enable_cursor_emulation(regs); |
| 1115 | } |
| 1116 | |
| 1117 | static void |
| 1118 | handle_101235(struct bregs *regs) |
| 1119 | { |
| 1120 | debug_stub(regs); |
| 1121 | regs->al = 0x12; |
| 1122 | } |
| 1123 | |
| 1124 | static void |
| 1125 | handle_101236(struct bregs *regs) |
| 1126 | { |
| 1127 | debug_stub(regs); |
| 1128 | regs->al = 0x12; |
| 1129 | } |
| 1130 | |
| 1131 | static void |
| 1132 | handle_1012XX(struct bregs *regs) |
| 1133 | { |
| 1134 | debug_stub(regs); |
| 1135 | } |
| 1136 | |
| 1137 | static void |
| 1138 | handle_1012(struct bregs *regs) |
| 1139 | { |
| 1140 | switch (regs->bl) { |
| 1141 | case 0x10: handle_101210(regs); break; |
| 1142 | case 0x30: handle_101230(regs); break; |
| 1143 | case 0x31: handle_101231(regs); break; |
| 1144 | case 0x32: handle_101232(regs); break; |
| 1145 | case 0x33: handle_101233(regs); break; |
| 1146 | case 0x34: handle_101234(regs); break; |
| 1147 | case 0x35: handle_101235(regs); break; |
| 1148 | case 0x36: handle_101236(regs); break; |
| 1149 | default: handle_1012XX(regs); break; |
| 1150 | } |
| 1151 | |
| 1152 | // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae |
| 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | static void |
| 1157 | handle_1013(struct bregs *regs) |
| 1158 | { |
| 1159 | // XXX - inline |
| 1160 | biosfn_write_string(regs->al, regs->bh, regs->bl, regs->cx |
Kevin O'Connor | 99e08b7 | 2009-05-17 00:07:31 -0400 | [diff] [blame] | 1161 | , regs->dh, regs->dl, regs->es, (void*)(regs->bp + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | |
| 1165 | static void |
| 1166 | handle_101a00(struct bregs *regs) |
| 1167 | { |
| 1168 | // XXX - inline |
| 1169 | biosfn_read_display_code(regs); |
| 1170 | } |
| 1171 | |
| 1172 | static void |
| 1173 | handle_101a01(struct bregs *regs) |
| 1174 | { |
| 1175 | // XXX - inline |
| 1176 | biosfn_set_display_code(regs); |
| 1177 | } |
| 1178 | |
| 1179 | static void |
| 1180 | handle_101aXX(struct bregs *regs) |
| 1181 | { |
| 1182 | debug_stub(regs); |
| 1183 | } |
| 1184 | |
| 1185 | static void |
| 1186 | handle_101a(struct bregs *regs) |
| 1187 | { |
| 1188 | switch (regs->al) { |
| 1189 | case 0x00: handle_101a00(regs); break; |
| 1190 | case 0x01: handle_101a01(regs); break; |
| 1191 | default: handle_101aXX(regs); break; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 1196 | struct funcInfo { |
| 1197 | u16 static_functionality_off; |
| 1198 | u16 static_functionality_seg; |
| 1199 | u8 bda_0x49[30]; |
| 1200 | u8 bda_0x84[3]; |
| 1201 | u8 dcc_index; |
| 1202 | u8 dcc_alt; |
| 1203 | u16 colors; |
| 1204 | u8 pages; |
| 1205 | u8 scan_lines; |
| 1206 | u8 primary_char; |
| 1207 | u8 secondar_char; |
| 1208 | u8 misc; |
| 1209 | u8 non_vga_mode; |
| 1210 | u8 reserved_2f[2]; |
| 1211 | u8 video_mem; |
| 1212 | u8 save_flags; |
| 1213 | u8 disp_info; |
| 1214 | u8 reserved_34[12]; |
| 1215 | }; |
| 1216 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1217 | static void |
| 1218 | handle_101b(struct bregs *regs) |
| 1219 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 1220 | u16 seg = regs->es; |
| 1221 | struct funcInfo *info = (void*)(regs->di+0); |
| 1222 | memset_far(seg, info, 0, sizeof(*info)); |
| 1223 | // Address of static functionality table |
| 1224 | SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality); |
| 1225 | SET_FARVAR(seg, info->static_functionality_seg, get_global_seg()); |
| 1226 | |
| 1227 | // Hard coded copy from BIOS area. Should it be cleaner ? |
| 1228 | memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30); |
| 1229 | memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3); |
| 1230 | |
| 1231 | SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index)); |
| 1232 | SET_FARVAR(seg, info->colors, 16); |
| 1233 | SET_FARVAR(seg, info->pages, 8); |
| 1234 | SET_FARVAR(seg, info->scan_lines, 2); |
| 1235 | SET_FARVAR(seg, info->video_mem, 3); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1236 | regs->al = 0x1B; |
| 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | static void |
| 1241 | handle_101c00(struct bregs *regs) |
| 1242 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 1243 | u16 flags = regs->cx; |
| 1244 | u16 size = 0; |
| 1245 | if (flags & 1) |
| 1246 | size += sizeof(struct saveVideoHardware); |
| 1247 | if (flags & 2) |
| 1248 | size += sizeof(struct saveBDAstate); |
| 1249 | if (flags & 4) |
| 1250 | size += sizeof(struct saveDACcolors); |
| 1251 | regs->bx = size; |
| 1252 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | static void |
| 1256 | handle_101c01(struct bregs *regs) |
| 1257 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 1258 | u16 flags = regs->cx; |
| 1259 | u16 seg = regs->es; |
| 1260 | void *data = (void*)(regs->bx+0); |
| 1261 | if (flags & 1) { |
| 1262 | vgahw_save_state(seg, data); |
| 1263 | data += sizeof(struct saveVideoHardware); |
| 1264 | } |
| 1265 | if (flags & 2) { |
| 1266 | biosfn_save_bda_state(seg, data); |
| 1267 | data += sizeof(struct saveBDAstate); |
| 1268 | } |
| 1269 | if (flags & 4) |
| 1270 | vgahw_save_dac_state(seg, data); |
| 1271 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | static void |
| 1275 | handle_101c02(struct bregs *regs) |
| 1276 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame^] | 1277 | u16 flags = regs->cx; |
| 1278 | u16 seg = regs->es; |
| 1279 | void *data = (void*)(regs->bx+0); |
| 1280 | if (flags & 1) { |
| 1281 | vgahw_restore_state(seg, data); |
| 1282 | data += sizeof(struct saveVideoHardware); |
| 1283 | } |
| 1284 | if (flags & 2) { |
| 1285 | biosfn_restore_bda_state(seg, data); |
| 1286 | data += sizeof(struct saveBDAstate); |
| 1287 | } |
| 1288 | if (flags & 4) |
| 1289 | vgahw_restore_dac_state(seg, data); |
| 1290 | regs->al = 0x1c; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | static void |
| 1294 | handle_101cXX(struct bregs *regs) |
| 1295 | { |
| 1296 | debug_stub(regs); |
| 1297 | } |
| 1298 | |
| 1299 | static void |
| 1300 | handle_101c(struct bregs *regs) |
| 1301 | { |
| 1302 | switch (regs->al) { |
| 1303 | case 0x00: handle_101c00(regs); break; |
| 1304 | case 0x01: handle_101c01(regs); break; |
| 1305 | case 0x02: handle_101c02(regs); break; |
| 1306 | default: handle_101cXX(regs); break; |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | |
| 1311 | static void |
| 1312 | handle_104f00(struct bregs *regs) |
| 1313 | { |
| 1314 | // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI); |
| 1315 | // XXX - OR cirrus_vesa_00h |
| 1316 | } |
| 1317 | |
| 1318 | static void |
| 1319 | handle_104f01(struct bregs *regs) |
| 1320 | { |
| 1321 | // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI); |
| 1322 | // XXX - OR cirrus_vesa_01h |
| 1323 | } |
| 1324 | |
| 1325 | static void |
| 1326 | handle_104f02(struct bregs *regs) |
| 1327 | { |
| 1328 | // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI); |
| 1329 | // XXX - OR cirrus_vesa_02h |
| 1330 | } |
| 1331 | |
| 1332 | static void |
| 1333 | handle_104f03(struct bregs *regs) |
| 1334 | { |
| 1335 | // XXX - vbe_biosfn_return_current_mode |
| 1336 | // XXX - OR cirrus_vesa_03h |
| 1337 | } |
| 1338 | |
| 1339 | static void |
| 1340 | handle_104f04(struct bregs *regs) |
| 1341 | { |
| 1342 | // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX); |
| 1343 | } |
| 1344 | |
| 1345 | static void |
| 1346 | handle_104f05(struct bregs *regs) |
| 1347 | { |
| 1348 | // XXX - vbe_biosfn_display_window_control |
| 1349 | // XXX - OR cirrus_vesa_05h |
| 1350 | } |
| 1351 | |
| 1352 | static void |
| 1353 | handle_104f06(struct bregs *regs) |
| 1354 | { |
| 1355 | // XXX - vbe_biosfn_set_get_logical_scan_line_length |
| 1356 | // XXX - OR cirrus_vesa_06h |
| 1357 | } |
| 1358 | |
| 1359 | static void |
| 1360 | handle_104f07(struct bregs *regs) |
| 1361 | { |
| 1362 | // XXX - vbe_biosfn_set_get_display_start |
| 1363 | // XXX - OR cirrus_vesa_07h |
| 1364 | } |
| 1365 | |
| 1366 | static void |
| 1367 | handle_104f08(struct bregs *regs) |
| 1368 | { |
| 1369 | // XXX - vbe_biosfn_set_get_dac_palette_format |
| 1370 | } |
| 1371 | |
| 1372 | static void |
| 1373 | handle_104f0a(struct bregs *regs) |
| 1374 | { |
| 1375 | // XXX - vbe_biosfn_return_protected_mode_interface |
| 1376 | } |
| 1377 | |
| 1378 | static void |
| 1379 | handle_104fXX(struct bregs *regs) |
| 1380 | { |
| 1381 | debug_stub(regs); |
| 1382 | regs->ax = 0x0100; |
| 1383 | } |
| 1384 | |
| 1385 | static void |
| 1386 | handle_104f(struct bregs *regs) |
| 1387 | { |
Kevin O'Connor | 99e08b7 | 2009-05-17 00:07:31 -0400 | [diff] [blame] | 1388 | if (! CONFIG_VBE || !vbe_has_vbe_display()) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1389 | handle_104fXX(regs); |
| 1390 | return; |
| 1391 | } |
| 1392 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1393 | switch (regs->al) { |
| 1394 | case 0x00: handle_104f00(regs); break; |
| 1395 | case 0x01: handle_104f01(regs); break; |
| 1396 | case 0x02: handle_104f02(regs); break; |
| 1397 | case 0x03: handle_104f03(regs); break; |
| 1398 | case 0x04: handle_104f04(regs); break; |
| 1399 | case 0x05: handle_104f05(regs); break; |
| 1400 | case 0x06: handle_104f06(regs); break; |
| 1401 | case 0x07: handle_104f07(regs); break; |
| 1402 | case 0x08: handle_104f08(regs); break; |
| 1403 | case 0x0a: handle_104f0a(regs); break; |
| 1404 | default: handle_104fXX(regs); break; |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | |
| 1409 | static void |
| 1410 | handle_10XX(struct bregs *regs) |
| 1411 | { |
| 1412 | debug_stub(regs); |
| 1413 | } |
| 1414 | |
| 1415 | // INT 10h Video Support Service Entry Point |
| 1416 | void VISIBLE16 |
| 1417 | handle_10(struct bregs *regs) |
| 1418 | { |
| 1419 | debug_enter(regs, DEBUG_VGA_10); |
| 1420 | switch (regs->ah) { |
| 1421 | case 0x00: handle_1000(regs); break; |
| 1422 | case 0x01: handle_1001(regs); break; |
| 1423 | case 0x02: handle_1002(regs); break; |
| 1424 | case 0x03: handle_1003(regs); break; |
| 1425 | case 0x04: handle_1004(regs); break; |
| 1426 | case 0x05: handle_1005(regs); break; |
| 1427 | case 0x06: handle_1006(regs); break; |
| 1428 | case 0x07: handle_1007(regs); break; |
| 1429 | case 0x08: handle_1008(regs); break; |
| 1430 | case 0x09: handle_1009(regs); break; |
| 1431 | case 0x0a: handle_100a(regs); break; |
| 1432 | case 0x0b: handle_100b(regs); break; |
| 1433 | case 0x0c: handle_100c(regs); break; |
| 1434 | case 0x0d: handle_100d(regs); break; |
| 1435 | case 0x0e: handle_100e(regs); break; |
| 1436 | case 0x0f: handle_100f(regs); break; |
| 1437 | case 0x10: handle_1010(regs); break; |
| 1438 | case 0x11: handle_1011(regs); break; |
| 1439 | case 0x12: handle_1012(regs); break; |
| 1440 | case 0x13: handle_1013(regs); break; |
| 1441 | case 0x1a: handle_101a(regs); break; |
| 1442 | case 0x1b: handle_101b(regs); break; |
| 1443 | case 0x1c: handle_101c(regs); break; |
| 1444 | case 0x4f: handle_104f(regs); break; |
| 1445 | default: handle_10XX(regs); break; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | /**************************************************************** |
| 1451 | * VGA post |
| 1452 | ****************************************************************/ |
| 1453 | |
| 1454 | static void |
| 1455 | init_bios_area() |
| 1456 | { |
| 1457 | // init detected hardware BIOS Area |
| 1458 | // set 80x25 color (not clear from RBIL but usual) |
| 1459 | u16 eqf = GET_BDA(equipment_list_flags); |
| 1460 | SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20); |
| 1461 | |
| 1462 | // Just for the first int10 find its children |
| 1463 | |
| 1464 | // the default char height |
| 1465 | SET_BDA(char_height, 0x10); |
| 1466 | |
| 1467 | // Clear the screen |
| 1468 | SET_BDA(video_ctl, 0x60); |
| 1469 | |
| 1470 | // Set the basic screen we have |
| 1471 | SET_BDA(video_switches, 0xf9); |
| 1472 | |
| 1473 | // Set the basic modeset options |
| 1474 | SET_BDA(modeset_ctl, 0x51); |
| 1475 | |
| 1476 | // Set the default MSR |
| 1477 | SET_BDA(video_msr, 0x09); |
| 1478 | } |
| 1479 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1480 | void VISIBLE16 |
| 1481 | vga_post(struct bregs *regs) |
| 1482 | { |
| 1483 | debug_enter(regs, DEBUG_VGA_POST); |
| 1484 | |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 1485 | vgahw_init(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1486 | |
| 1487 | init_bios_area(); |
| 1488 | |
Kevin O'Connor | 21079f4 | 2009-05-16 21:30:10 -0400 | [diff] [blame] | 1489 | if (CONFIG_VBE) |
| 1490 | vbe_init(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1491 | |
| 1492 | extern void entry_10(void); |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 1493 | SET_IVT(0x10, get_global_seg(), (u32)entry_10); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1494 | |
| 1495 | if (CONFIG_CIRRUS) |
| 1496 | cirrus_init(); |
| 1497 | |
| 1498 | // XXX - clear screen and display info |
| 1499 | |
| 1500 | // XXX: fill it |
| 1501 | SET_VGA(video_save_pointer_table[0], (u32)video_param_table); |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 1502 | SET_VGA(video_save_pointer_table[1], get_global_seg()); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1503 | |
| 1504 | // Fixup checksum |
| 1505 | extern u8 _rom_header_size, _rom_header_checksum; |
| 1506 | SET_VGA(_rom_header_checksum, 0); |
Kevin O'Connor | d113a99 | 2009-05-16 21:05:02 -0400 | [diff] [blame] | 1507 | u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1508 | SET_VGA(_rom_header_checksum, sum); |
| 1509 | } |