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