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