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