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