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