Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1 | // VGA bios implementation |
| 2 | // |
Kevin O'Connor | dab0a74 | 2013-12-03 11:50:49 -0500 | [diff] [blame] | 3 | // Copyright (C) 2009-2013 Kevin O'Connor <kevin@koconnor.net> |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 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 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 8 | #include "biosvar.h" // GET_BDA |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 9 | #include "bregs.h" // struct bregs |
Kevin O'Connor | e91ec7c | 2012-01-14 16:30:49 -0500 | [diff] [blame] | 10 | #include "clext.h" // clext_1012 |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 11 | #include "config.h" // CONFIG_* |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 12 | #include "output.h" // dprintf |
Kevin O'Connor | 2e57c81 | 2013-09-14 22:29:32 -0400 | [diff] [blame] | 13 | #include "std/vbe.h" // VBE_RETURN_STATUS_FAILED |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 14 | #include "stdvga.h" // stdvga_set_cursor_shape |
Kevin O'Connor | fa9c66a | 2013-09-14 19:10:40 -0400 | [diff] [blame] | 15 | #include "string.h" // memset_far |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 16 | #include "vgabios.h" // calc_page_size |
| 17 | #include "vgahw.h" // vgahw_set_mode |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 18 | |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 19 | |
| 20 | /**************************************************************** |
| 21 | * Helper functions |
| 22 | ****************************************************************/ |
| 23 | |
Kevin O'Connor | 3876b53 | 2012-01-24 00:07:44 -0500 | [diff] [blame] | 24 | // Return the bits per pixel in system memory for a given mode. |
| 25 | int |
| 26 | vga_bpp(struct vgamode_s *vmode_g) |
| 27 | { |
| 28 | switch (GET_GLOBAL(vmode_g->memmodel)) { |
| 29 | case MM_TEXT: |
| 30 | return 16; |
| 31 | case MM_PLANAR: |
| 32 | return 1; |
| 33 | } |
| 34 | u8 depth = GET_GLOBAL(vmode_g->depth); |
| 35 | if (depth > 8) |
| 36 | return ALIGN(depth, 8); |
| 37 | return depth; |
| 38 | } |
| 39 | |
Kevin O'Connor | 83047be | 2012-01-07 18:27:19 -0500 | [diff] [blame] | 40 | u16 |
| 41 | calc_page_size(u8 memmodel, u16 width, u16 height) |
| 42 | { |
| 43 | switch (memmodel) { |
| 44 | case MM_TEXT: |
| 45 | return ALIGN(width * height * 2, 2*1024); |
| 46 | case MM_CGA: |
| 47 | return 16*1024; |
| 48 | default: |
| 49 | return ALIGN(width * height / 8, 8*1024); |
| 50 | } |
| 51 | } |
| 52 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 53 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 54 | set_cursor_shape(u8 start, u8 end) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 55 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 56 | start &= 0x3f; |
| 57 | end &= 0x1f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 58 | |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 59 | u16 curs = (start << 8) + end; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 60 | SET_BDA(cursor_type, curs); |
| 61 | |
Kevin O'Connor | efbf4d6 | 2014-02-09 11:50:21 -0500 | [diff] [blame] | 62 | if (!CONFIG_VGA_STDVGA_PORTS) |
| 63 | return; |
| 64 | |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 65 | u8 modeset_ctl = GET_BDA(modeset_ctl); |
| 66 | u16 cheight = GET_BDA(char_height); |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 67 | if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) { |
| 68 | if (end != (start + 1)) |
| 69 | start = ((start + 1) * cheight / 8) - 1; |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 70 | else |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 71 | start = ((end + 1) * cheight / 8) - 2; |
| 72 | end = ((end + 1) * cheight / 8) - 1; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 73 | } |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 74 | stdvga_set_cursor_shape(start, end); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 75 | } |
| 76 | |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 77 | static u16 |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 78 | get_cursor_shape(u8 page) |
Kevin O'Connor | 0818e1a | 2009-05-16 18:00:19 -0400 | [diff] [blame] | 79 | { |
| 80 | if (page > 7) |
| 81 | return 0; |
| 82 | // FIXME should handle VGA 14/16 lines |
| 83 | return GET_BDA(cursor_type); |
| 84 | } |
| 85 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 86 | static void |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 87 | set_cursor_pos(struct cursorpos cp) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 88 | { |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 89 | u8 page = cp.page, x = cp.x, y = cp.y; |
| 90 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 91 | // Should not happen... |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 92 | if (page > 7) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 93 | return; |
| 94 | |
| 95 | // Bios cursor pos |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 96 | SET_BDA(cursor_pos[page], (y << 8) | x); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 97 | |
Kevin O'Connor | efbf4d6 | 2014-02-09 11:50:21 -0500 | [diff] [blame] | 98 | if (!CONFIG_VGA_STDVGA_PORTS) |
| 99 | return; |
| 100 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 101 | // Set the hardware cursor |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 102 | u8 current = GET_BDA(video_page); |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 103 | if (cp.page != current) |
Kevin O'Connor | dd2be77 | 2009-05-16 15:41:23 -0400 | [diff] [blame] | 104 | return; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 105 | |
Kevin O'Connor | 83047be | 2012-01-07 18:27:19 -0500 | [diff] [blame] | 106 | // Calculate the memory address |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 107 | int address = (GET_BDA(video_pagesize) * page |
| 108 | + (x + y * GET_BDA(video_cols)) * 2); |
Kevin O'Connor | 1692007 | 2012-01-27 22:59:46 -0500 | [diff] [blame] | 109 | stdvga_set_cursor_pos(address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 112 | static struct cursorpos |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 113 | get_cursor_pos(u8 page) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 114 | { |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 115 | if (page == 0xff) |
| 116 | // special case - use current page |
| 117 | page = GET_BDA(video_page); |
| 118 | if (page > 7) { |
| 119 | struct cursorpos cp = { 0, 0, 0xfe }; |
| 120 | return cp; |
| 121 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 122 | // FIXME should handle VGA 14/16 lines |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 123 | u16 xy = GET_BDA(cursor_pos[page]); |
| 124 | struct cursorpos cp = {xy, xy>>8, page}; |
| 125 | return cp; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 128 | static void |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 129 | set_active_page(u8 page) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 130 | { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 131 | if (page > 7) |
| 132 | return; |
| 133 | |
| 134 | // Get the mode |
Kevin O'Connor | 4a73f93 | 2012-01-21 11:08:35 -0500 | [diff] [blame] | 135 | struct vgamode_s *vmode_g = get_current_mode(); |
Kevin O'Connor | 5727c29 | 2009-05-16 17:29:32 -0400 | [diff] [blame] | 136 | if (!vmode_g) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 137 | return; |
| 138 | |
Kevin O'Connor | 4c85a26 | 2012-02-12 11:50:52 -0500 | [diff] [blame] | 139 | // Get cursor pos for the given page |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 140 | struct cursorpos cp = get_cursor_pos(page); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 141 | |
Kevin O'Connor | 83047be | 2012-01-07 18:27:19 -0500 | [diff] [blame] | 142 | // Calculate memory address of start of page |
Kevin O'Connor | d61fc53 | 2012-01-27 20:37:45 -0500 | [diff] [blame] | 143 | int address = GET_BDA(video_pagesize) * page; |
| 144 | vgahw_set_displaystart(vmode_g, address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 145 | |
| 146 | // And change the BIOS page |
Kevin O'Connor | 83047be | 2012-01-07 18:27:19 -0500 | [diff] [blame] | 147 | SET_BDA(video_pagestart, address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 148 | SET_BDA(video_page, page); |
| 149 | |
Kevin O'Connor | a12c215 | 2009-05-13 22:06:16 -0400 | [diff] [blame] | 150 | dprintf(1, "Set active page %02x address %04x\n", page, address); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 151 | |
| 152 | // Display the cursor, now the page is active |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 153 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 154 | } |
| 155 | |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 156 | static void |
| 157 | set_scan_lines(u8 lines) |
| 158 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 159 | stdvga_set_scan_lines(lines); |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 160 | if (lines == 8) |
| 161 | set_cursor_shape(0x06, 0x07); |
| 162 | else |
| 163 | set_cursor_shape(lines - 4, lines - 3); |
| 164 | SET_BDA(char_height, lines); |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 165 | u16 vde = stdvga_get_vde(); |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 166 | u8 rows = vde / lines; |
| 167 | SET_BDA(video_rows, rows - 1); |
| 168 | u16 cols = GET_BDA(video_cols); |
Kevin O'Connor | 83047be | 2012-01-07 18:27:19 -0500 | [diff] [blame] | 169 | SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows)); |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
| 173 | /**************************************************************** |
| 174 | * Character writing |
| 175 | ****************************************************************/ |
| 176 | |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 177 | // Write a character to the screen and calculate new cursor position. |
| 178 | static void |
| 179 | write_char(struct cursorpos *pcp, struct carattr ca) |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 180 | { |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 181 | vgafb_write_char(*pcp, ca); |
| 182 | pcp->x++; |
| 183 | // Do we need to wrap ? |
| 184 | if (pcp->x == GET_BDA(video_cols)) { |
| 185 | pcp->x = 0; |
| 186 | pcp->y++; |
| 187 | } |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // Write a character to the screen at a given position. Implement |
| 191 | // special characters and scroll the screen if necessary. |
| 192 | static void |
| 193 | write_teletype(struct cursorpos *pcp, struct carattr ca) |
| 194 | { |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 195 | switch (ca.car) { |
| 196 | case 7: |
| 197 | //FIXME should beep |
| 198 | break; |
| 199 | case 8: |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 200 | if (pcp->x > 0) |
| 201 | pcp->x--; |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 202 | break; |
| 203 | case '\r': |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 204 | pcp->x = 0; |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 205 | break; |
| 206 | case '\n': |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 207 | pcp->y++; |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 208 | break; |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 209 | default: |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 210 | write_char(pcp, ca); |
| 211 | break; |
Kevin O'Connor | 2e86c6a | 2009-05-31 20:43:06 -0400 | [diff] [blame] | 212 | } |
| 213 | |
Kevin O'Connor | 82221b2 | 2009-05-26 00:20:40 -0400 | [diff] [blame] | 214 | // Do we need to scroll ? |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 215 | u16 nbrows = GET_BDA(video_rows); |
| 216 | if (pcp->y > nbrows) { |
| 217 | pcp->y--; |
Kevin O'Connor | 7fd2af6 | 2014-03-20 21:16:28 -0400 | [diff] [blame] | 218 | |
| 219 | struct vgamode_s *vmode_g = get_current_mode(); |
| 220 | if (!vmode_g) |
| 221 | return; |
| 222 | |
| 223 | struct cursorpos dest = {0, 0, pcp->page}; |
| 224 | struct cursorpos src = {0, 1, pcp->page}; |
| 225 | struct cursorpos size = {GET_BDA(video_cols), nbrows}; |
| 226 | vgafb_move_chars(vmode_g, dest, src, size); |
| 227 | |
| 228 | struct cursorpos clr = {0, nbrows, pcp->page}; |
| 229 | struct carattr attr = {' ', 0, 0}; |
| 230 | struct cursorpos clrsize = {GET_BDA(video_cols), 1}; |
| 231 | vgafb_clear_chars(vmode_g, clr, attr, clrsize); |
Kevin O'Connor | 82221b2 | 2009-05-26 00:20:40 -0400 | [diff] [blame] | 232 | } |
Kevin O'Connor | 82221b2 | 2009-05-26 00:20:40 -0400 | [diff] [blame] | 233 | } |
| 234 | |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 235 | |
| 236 | /**************************************************************** |
| 237 | * Save and restore bda state |
| 238 | ****************************************************************/ |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 239 | |
Kevin O'Connor | 20dc419 | 2014-02-05 20:52:25 -0500 | [diff] [blame] | 240 | struct saveBDAstate { |
| 241 | u8 bda_0x49[28]; |
| 242 | u8 bda_0x84[6]; |
| 243 | u16 vbe_mode; |
| 244 | struct segoff_s font0; |
| 245 | struct segoff_s font1; |
| 246 | }; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 247 | |
Kevin O'Connor | 20dc419 | 2014-02-05 20:52:25 -0500 | [diff] [blame] | 248 | int |
| 249 | bda_save_restore(int cmd, u16 seg, void *data) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 250 | { |
Kevin O'Connor | 20dc419 | 2014-02-05 20:52:25 -0500 | [diff] [blame] | 251 | if (!(cmd & SR_BDA)) |
| 252 | return 0; |
| 253 | struct saveBDAstate *info = data; |
| 254 | if (cmd & SR_SAVE) { |
| 255 | memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49 |
| 256 | , sizeof(info->bda_0x49)); |
| 257 | memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84 |
| 258 | , sizeof(info->bda_0x84)); |
| 259 | SET_FARVAR(seg, info->vbe_mode, GET_BDA(vbe_mode)); |
| 260 | SET_FARVAR(seg, info->font0, GET_IVT(0x1f)); |
| 261 | SET_FARVAR(seg, info->font1, GET_IVT(0x43)); |
| 262 | } |
| 263 | if (cmd & SR_RESTORE) { |
| 264 | memcpy_far(SEG_BDA, (void*)0x49, seg, info->bda_0x49 |
| 265 | , sizeof(info->bda_0x49)); |
| 266 | memcpy_far(SEG_BDA, (void*)0x84, seg, info->bda_0x84 |
| 267 | , sizeof(info->bda_0x84)); |
| 268 | SET_BDA(vbe_mode, GET_FARVAR(seg, info->vbe_mode)); |
| 269 | SET_IVT(0x1f, GET_FARVAR(seg, info->font0)); |
| 270 | SET_IVT(0x43, GET_FARVAR(seg, info->font1)); |
| 271 | } |
| 272 | return sizeof(*info); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 273 | } |
| 274 | |
Kevin O'Connor | 4a73f93 | 2012-01-21 11:08:35 -0500 | [diff] [blame] | 275 | |
| 276 | /**************************************************************** |
| 277 | * Mode setting |
| 278 | ****************************************************************/ |
| 279 | |
| 280 | struct vgamode_s * |
| 281 | get_current_mode(void) |
| 282 | { |
Kevin O'Connor | e6bc4c1 | 2012-01-21 11:26:37 -0500 | [diff] [blame] | 283 | return vgahw_find_mode(GET_BDA(vbe_mode) & ~MF_VBEFLAGS); |
Kevin O'Connor | 4a73f93 | 2012-01-21 11:08:35 -0500 | [diff] [blame] | 284 | } |
| 285 | |
Kevin O'Connor | 821d6b4 | 2011-12-31 18:19:22 -0500 | [diff] [blame] | 286 | // Setup BDA after a mode switch. |
Kevin O'Connor | e6bc4c1 | 2012-01-21 11:26:37 -0500 | [diff] [blame] | 287 | int |
| 288 | vga_set_mode(int mode, int flags) |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 289 | { |
Kevin O'Connor | e6bc4c1 | 2012-01-21 11:26:37 -0500 | [diff] [blame] | 290 | dprintf(1, "set VGA mode %x\n", mode); |
| 291 | struct vgamode_s *vmode_g = vgahw_find_mode(mode); |
| 292 | if (!vmode_g) |
| 293 | return VBE_RETURN_STATUS_FAILED; |
| 294 | |
| 295 | int ret = vgahw_set_mode(vmode_g, flags); |
| 296 | if (ret) |
| 297 | return ret; |
| 298 | |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 299 | // Set the BIOS mem |
Kevin O'Connor | 80da87d | 2012-01-02 11:13:14 -0500 | [diff] [blame] | 300 | int width = GET_GLOBAL(vmode_g->width); |
| 301 | int height = GET_GLOBAL(vmode_g->height); |
Kevin O'Connor | 83047be | 2012-01-07 18:27:19 -0500 | [diff] [blame] | 302 | u8 memmodel = GET_GLOBAL(vmode_g->memmodel); |
Kevin O'Connor | 80da87d | 2012-01-02 11:13:14 -0500 | [diff] [blame] | 303 | int cheight = GET_GLOBAL(vmode_g->cheight); |
Kevin O'Connor | e6bc4c1 | 2012-01-21 11:26:37 -0500 | [diff] [blame] | 304 | if (mode < 0x100) |
| 305 | SET_BDA(video_mode, mode); |
| 306 | else |
| 307 | SET_BDA(video_mode, 0xff); |
| 308 | SET_BDA(vbe_mode, mode | (flags & MF_VBEFLAGS)); |
Kevin O'Connor | 83047be | 2012-01-07 18:27:19 -0500 | [diff] [blame] | 309 | if (memmodel == MM_TEXT) { |
Kevin O'Connor | 80da87d | 2012-01-02 11:13:14 -0500 | [diff] [blame] | 310 | SET_BDA(video_cols, width); |
| 311 | SET_BDA(video_rows, height-1); |
| 312 | SET_BDA(cursor_type, 0x0607); |
| 313 | } else { |
| 314 | int cwidth = GET_GLOBAL(vmode_g->cwidth); |
| 315 | SET_BDA(video_cols, width / cwidth); |
| 316 | SET_BDA(video_rows, (height / cheight) - 1); |
| 317 | SET_BDA(cursor_type, 0x0000); |
| 318 | } |
Kevin O'Connor | 83047be | 2012-01-07 18:27:19 -0500 | [diff] [blame] | 319 | SET_BDA(video_pagesize, calc_page_size(memmodel, width, height)); |
Kevin O'Connor | efbf4d6 | 2014-02-09 11:50:21 -0500 | [diff] [blame] | 320 | SET_BDA(crtc_address, CONFIG_VGA_STDVGA_PORTS ? stdvga_get_crtc() : 0); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 321 | SET_BDA(char_height, cheight); |
Kevin O'Connor | 821d6b4 | 2011-12-31 18:19:22 -0500 | [diff] [blame] | 322 | SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 323 | SET_BDA(video_switches, 0xF9); |
| 324 | SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f); |
Kevin O'Connor | cecbc5d | 2011-12-31 17:24:11 -0500 | [diff] [blame] | 325 | int i; |
| 326 | for (i=0; i<8; i++) |
| 327 | SET_BDA(cursor_pos[i], 0x0000); |
| 328 | SET_BDA(video_pagestart, 0x0000); |
| 329 | SET_BDA(video_page, 0x00); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 330 | |
| 331 | // FIXME We nearly have the good tables. to be reworked |
| 332 | 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] | 333 | SET_BDA(video_savetable |
Kevin O'Connor | 815e447 | 2011-12-21 09:05:32 -0500 | [diff] [blame] | 334 | , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 335 | |
| 336 | // FIXME |
| 337 | SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but... |
| 338 | SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but... |
| 339 | |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 340 | // Set the ints 0x1F and 0x43 |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 341 | SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8])); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 342 | |
| 343 | switch (cheight) { |
| 344 | case 8: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 345 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 346 | break; |
| 347 | case 14: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 348 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 349 | break; |
| 350 | case 16: |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 351 | SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16)); |
Kevin O'Connor | 85ea07e | 2009-05-25 09:41:07 -0400 | [diff] [blame] | 352 | break; |
| 353 | } |
Kevin O'Connor | e6bc4c1 | 2012-01-21 11:26:37 -0500 | [diff] [blame] | 354 | |
| 355 | return 0; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 356 | } |
| 357 | |
Kevin O'Connor | 821d6b4 | 2011-12-31 18:19:22 -0500 | [diff] [blame] | 358 | |
| 359 | /**************************************************************** |
| 360 | * VGA int 10 handler |
| 361 | ****************************************************************/ |
| 362 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 363 | static void |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 364 | handle_1000(struct bregs *regs) |
| 365 | { |
Kevin O'Connor | 5108c69 | 2011-12-31 19:13:45 -0500 | [diff] [blame] | 366 | int mode = regs->al & 0x7f; |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 367 | |
| 368 | // Set regs->al |
| 369 | if (mode > 7) |
| 370 | regs->al = 0x20; |
| 371 | else if (mode == 6) |
| 372 | regs->al = 0x3f; |
| 373 | else |
| 374 | regs->al = 0x30; |
| 375 | |
Kevin O'Connor | b7b9293 | 2013-03-09 13:04:47 -0500 | [diff] [blame] | 376 | int flags = MF_LEGACY | (GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM)); |
Kevin O'Connor | 5108c69 | 2011-12-31 19:13:45 -0500 | [diff] [blame] | 377 | if (regs->al & 0x80) |
Kevin O'Connor | 821d6b4 | 2011-12-31 18:19:22 -0500 | [diff] [blame] | 378 | flags |= MF_NOCLEARMEM; |
| 379 | |
Kevin O'Connor | e6bc4c1 | 2012-01-21 11:26:37 -0500 | [diff] [blame] | 380 | vga_set_mode(mode, flags); |
Julian Pidancet | 87879e2 | 2011-12-19 05:08:00 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 384 | handle_1001(struct bregs *regs) |
| 385 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 386 | set_cursor_shape(regs->ch, regs->cl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static void |
| 390 | handle_1002(struct bregs *regs) |
| 391 | { |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 392 | struct cursorpos cp = {regs->dl, regs->dh, regs->bh}; |
| 393 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static void |
| 397 | handle_1003(struct bregs *regs) |
| 398 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 399 | regs->cx = get_cursor_shape(regs->bh); |
Kevin O'Connor | 918b156 | 2009-05-25 11:05:18 -0400 | [diff] [blame] | 400 | struct cursorpos cp = get_cursor_pos(regs->bh); |
| 401 | regs->dl = cp.x; |
| 402 | regs->dh = cp.y; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | // Read light pen pos (unimplemented) |
| 406 | static void |
| 407 | handle_1004(struct bregs *regs) |
| 408 | { |
| 409 | debug_stub(regs); |
| 410 | regs->ax = regs->bx = regs->cx = regs->dx = 0; |
| 411 | } |
| 412 | |
| 413 | static void |
| 414 | handle_1005(struct bregs *regs) |
| 415 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 416 | set_active_page(regs->al); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static void |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 420 | verify_scroll(struct bregs *regs, int dir) |
| 421 | { |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 422 | u8 ulx = regs->cl, uly = regs->ch, lrx = regs->dl, lry = regs->dh; |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 423 | u16 nbrows = GET_BDA(video_rows) + 1; |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 424 | if (lry >= nbrows) |
| 425 | lry = nbrows - 1; |
Kevin O'Connor | c3e1587 | 2009-05-31 01:37:54 -0400 | [diff] [blame] | 426 | u16 nbcols = GET_BDA(video_cols); |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 427 | if (lrx >= nbcols) |
| 428 | lrx = nbcols - 1; |
Kevin O'Connor | 7fd2af6 | 2014-03-20 21:16:28 -0400 | [diff] [blame] | 429 | int wincols = lrx - ulx + 1, winrows = lry - uly + 1; |
| 430 | if (wincols <= 0 || winrows <= 0) |
Kevin O'Connor | c3e1587 | 2009-05-31 01:37:54 -0400 | [diff] [blame] | 431 | return; |
| 432 | |
Kevin O'Connor | 7fd2af6 | 2014-03-20 21:16:28 -0400 | [diff] [blame] | 433 | struct vgamode_s *vmode_g = get_current_mode(); |
| 434 | if (!vmode_g) |
| 435 | return; |
Kevin O'Connor | c3e1587 | 2009-05-31 01:37:54 -0400 | [diff] [blame] | 436 | |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 437 | u8 page = GET_BDA(video_page); |
Kevin O'Connor | 7fd2af6 | 2014-03-20 21:16:28 -0400 | [diff] [blame] | 438 | int clearlines = regs->al, movelines = winrows - clearlines; |
| 439 | if (!clearlines || movelines <= 0) { |
| 440 | // Clear whole area. |
| 441 | struct cursorpos clr = {ulx, uly, page}; |
| 442 | struct carattr attr = {' ', regs->bh, 1}; |
| 443 | struct cursorpos clrsize = {wincols, winrows}; |
| 444 | vgafb_clear_chars(vmode_g, clr, attr, clrsize); |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | if (dir > 0) { |
| 449 | // Normal scroll |
| 450 | struct cursorpos dest = {ulx, uly, page}; |
| 451 | struct cursorpos src = {ulx, uly + clearlines, page}; |
| 452 | struct cursorpos size = {wincols, movelines}; |
| 453 | vgafb_move_chars(vmode_g, dest, src, size); |
| 454 | |
| 455 | struct cursorpos clr = {ulx, uly + movelines, page}; |
| 456 | struct carattr attr = {' ', regs->bh, 1}; |
| 457 | struct cursorpos clrsize = {wincols, clearlines}; |
| 458 | vgafb_clear_chars(vmode_g, clr, attr, clrsize); |
| 459 | } else { |
| 460 | // Scroll down |
| 461 | struct cursorpos dest = {ulx, uly + clearlines, page}; |
| 462 | struct cursorpos src = {ulx, uly, page}; |
| 463 | struct cursorpos size = {wincols, movelines}; |
| 464 | vgafb_move_chars(vmode_g, dest, src, size); |
| 465 | |
| 466 | struct cursorpos clr = {ulx, uly, page}; |
| 467 | struct carattr attr = {' ', regs->bh, 1}; |
| 468 | struct cursorpos clrsize = {wincols, clearlines}; |
| 469 | vgafb_clear_chars(vmode_g, clr, attr, clrsize); |
| 470 | } |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 474 | handle_1006(struct bregs *regs) |
| 475 | { |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 476 | verify_scroll(regs, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | static void |
| 480 | handle_1007(struct bregs *regs) |
| 481 | { |
Kevin O'Connor | 217f2bc | 2009-05-31 00:46:47 -0400 | [diff] [blame] | 482 | verify_scroll(regs, -1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | static void |
| 486 | handle_1008(struct bregs *regs) |
| 487 | { |
Kevin O'Connor | d3b3815 | 2009-05-26 00:05:37 -0400 | [diff] [blame] | 488 | struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh)); |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 489 | regs->al = ca.car; |
| 490 | regs->ah = ca.attr; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 491 | } |
| 492 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 493 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 494 | handle_1009(struct bregs *regs) |
| 495 | { |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 496 | struct carattr ca = {regs->al, regs->bl, 1}; |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 497 | struct cursorpos cp = get_cursor_pos(regs->bh); |
| 498 | int count = regs->cx; |
| 499 | while (count--) |
| 500 | write_char(&cp, ca); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 501 | } |
| 502 | |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 503 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 504 | handle_100a(struct bregs *regs) |
| 505 | { |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 506 | struct carattr ca = {regs->al, regs->bl, 0}; |
Kevin O'Connor | 0910dde | 2014-02-08 16:43:30 -0500 | [diff] [blame] | 507 | struct cursorpos cp = get_cursor_pos(regs->bh); |
| 508 | int count = regs->cx; |
| 509 | while (count--) |
| 510 | write_char(&cp, ca); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | |
| 514 | static void |
| 515 | handle_100b00(struct bregs *regs) |
| 516 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 517 | stdvga_set_border_color(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static void |
| 521 | handle_100b01(struct bregs *regs) |
| 522 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 523 | stdvga_set_palette(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static void |
| 527 | handle_100bXX(struct bregs *regs) |
| 528 | { |
| 529 | debug_stub(regs); |
| 530 | } |
| 531 | |
| 532 | static void |
| 533 | handle_100b(struct bregs *regs) |
| 534 | { |
Kevin O'Connor | efbf4d6 | 2014-02-09 11:50:21 -0500 | [diff] [blame] | 535 | if (!CONFIG_VGA_STDVGA_PORTS) { |
| 536 | handle_100bXX(regs); |
| 537 | return; |
| 538 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 539 | switch (regs->bh) { |
| 540 | case 0x00: handle_100b00(regs); break; |
| 541 | case 0x01: handle_100b01(regs); break; |
| 542 | default: handle_100bXX(regs); break; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | |
| 547 | static void |
| 548 | handle_100c(struct bregs *regs) |
| 549 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 550 | // XXX - page (regs->bh) is unused |
| 551 | vgafb_write_pixel(regs->al, regs->cx, regs->dx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | static void |
| 555 | handle_100d(struct bregs *regs) |
| 556 | { |
Kevin O'Connor | 227a2bb | 2009-05-31 22:00:20 -0400 | [diff] [blame] | 557 | // XXX - page (regs->bh) is unused |
| 558 | regs->al = vgafb_read_pixel(regs->cx, regs->dx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 559 | } |
| 560 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 561 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 562 | handle_100e(struct bregs *regs) |
| 563 | { |
| 564 | // Ralf Brown Interrupt list is WRONG on bh(page) |
| 565 | // We do output only on the current page ! |
Kevin O'Connor | 0926241 | 2009-05-25 11:44:11 -0400 | [diff] [blame] | 566 | struct carattr ca = {regs->al, regs->bl, 0}; |
Kevin O'Connor | 116a044 | 2009-05-26 00:47:32 -0400 | [diff] [blame] | 567 | struct cursorpos cp = get_cursor_pos(0xff); |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 568 | write_teletype(&cp, ca); |
Kevin O'Connor | 116a044 | 2009-05-26 00:47:32 -0400 | [diff] [blame] | 569 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static void |
| 573 | handle_100f(struct bregs *regs) |
| 574 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 575 | regs->bh = GET_BDA(video_page); |
| 576 | regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80); |
| 577 | regs->ah = GET_BDA(video_cols); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | |
| 581 | static void |
| 582 | handle_101000(struct bregs *regs) |
| 583 | { |
| 584 | if (regs->bl > 0x14) |
| 585 | return; |
Kevin O'Connor | 3471fdb | 2012-01-14 19:02:43 -0500 | [diff] [blame] | 586 | stdvga_attr_write(regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | static void |
| 590 | handle_101001(struct bregs *regs) |
| 591 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 592 | stdvga_set_overscan_border_color(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static void |
| 596 | handle_101002(struct bregs *regs) |
| 597 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 598 | stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | static void |
| 602 | handle_101003(struct bregs *regs) |
| 603 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 604 | stdvga_toggle_intensity(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static void |
| 608 | handle_101007(struct bregs *regs) |
| 609 | { |
| 610 | if (regs->bl > 0x14) |
| 611 | return; |
Kevin O'Connor | 3471fdb | 2012-01-14 19:02:43 -0500 | [diff] [blame] | 612 | regs->bh = stdvga_attr_read(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static void |
| 616 | handle_101008(struct bregs *regs) |
| 617 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 618 | regs->bh = stdvga_get_overscan_border_color(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static void |
| 622 | handle_101009(struct bregs *regs) |
| 623 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 624 | stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0)); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 625 | } |
| 626 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 627 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 628 | handle_101010(struct bregs *regs) |
| 629 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 630 | u8 rgb[3] = {regs->dh, regs->ch, regs->cl}; |
Kevin O'Connor | 3471fdb | 2012-01-14 19:02:43 -0500 | [diff] [blame] | 631 | stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | static void |
| 635 | handle_101012(struct bregs *regs) |
| 636 | { |
Kevin O'Connor | 3471fdb | 2012-01-14 19:02:43 -0500 | [diff] [blame] | 637 | stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | static void |
| 641 | handle_101013(struct bregs *regs) |
| 642 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 643 | stdvga_select_video_dac_color_page(regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 644 | } |
| 645 | |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 646 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 647 | handle_101015(struct bregs *regs) |
| 648 | { |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 649 | u8 rgb[3]; |
Kevin O'Connor | 3471fdb | 2012-01-14 19:02:43 -0500 | [diff] [blame] | 650 | stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1); |
Kevin O'Connor | 8bc059e | 2009-05-17 21:19:36 -0400 | [diff] [blame] | 651 | regs->dh = rgb[0]; |
| 652 | regs->ch = rgb[1]; |
| 653 | regs->cl = rgb[2]; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static void |
| 657 | handle_101017(struct bregs *regs) |
| 658 | { |
Kevin O'Connor | 3471fdb | 2012-01-14 19:02:43 -0500 | [diff] [blame] | 659 | stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static void |
| 663 | handle_101018(struct bregs *regs) |
| 664 | { |
Kevin O'Connor | 3471fdb | 2012-01-14 19:02:43 -0500 | [diff] [blame] | 665 | stdvga_pelmask_write(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static void |
| 669 | handle_101019(struct bregs *regs) |
| 670 | { |
Kevin O'Connor | 3471fdb | 2012-01-14 19:02:43 -0500 | [diff] [blame] | 671 | regs->bl = stdvga_pelmask_read(); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | static void |
| 675 | handle_10101a(struct bregs *regs) |
| 676 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 677 | stdvga_read_video_dac_state(®s->bl, ®s->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | static void |
| 681 | handle_10101b(struct bregs *regs) |
| 682 | { |
Kevin O'Connor | 821d6b4 | 2011-12-31 18:19:22 -0500 | [diff] [blame] | 683 | stdvga_perform_gray_scale_summing(regs->bx, regs->cx); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static void |
| 687 | handle_1010XX(struct bregs *regs) |
| 688 | { |
| 689 | debug_stub(regs); |
| 690 | } |
| 691 | |
| 692 | static void |
| 693 | handle_1010(struct bregs *regs) |
| 694 | { |
Kevin O'Connor | efbf4d6 | 2014-02-09 11:50:21 -0500 | [diff] [blame] | 695 | if (!CONFIG_VGA_STDVGA_PORTS) { |
| 696 | handle_1010XX(regs); |
| 697 | return; |
| 698 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 699 | switch (regs->al) { |
| 700 | case 0x00: handle_101000(regs); break; |
| 701 | case 0x01: handle_101001(regs); break; |
| 702 | case 0x02: handle_101002(regs); break; |
| 703 | case 0x03: handle_101003(regs); break; |
| 704 | case 0x07: handle_101007(regs); break; |
| 705 | case 0x08: handle_101008(regs); break; |
| 706 | case 0x09: handle_101009(regs); break; |
| 707 | case 0x10: handle_101010(regs); break; |
| 708 | case 0x12: handle_101012(regs); break; |
| 709 | case 0x13: handle_101013(regs); break; |
| 710 | case 0x15: handle_101015(regs); break; |
| 711 | case 0x17: handle_101017(regs); break; |
| 712 | case 0x18: handle_101018(regs); break; |
| 713 | case 0x19: handle_101019(regs); break; |
| 714 | case 0x1a: handle_10101a(regs); break; |
| 715 | case 0x1b: handle_10101b(regs); break; |
| 716 | default: handle_1010XX(regs); break; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | |
| 721 | static void |
| 722 | handle_101100(struct bregs *regs) |
| 723 | { |
Kevin O'Connor | 2bec7d6 | 2011-12-31 04:31:16 -0500 | [diff] [blame] | 724 | stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx |
| 725 | , regs->dx, regs->bl, regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | static void |
| 729 | handle_101101(struct bregs *regs) |
| 730 | { |
Kevin O'Connor | 2bec7d6 | 2011-12-31 04:31:16 -0500 | [diff] [blame] | 731 | 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] | 732 | } |
| 733 | |
| 734 | static void |
| 735 | handle_101102(struct bregs *regs) |
| 736 | { |
Kevin O'Connor | 2bec7d6 | 2011-12-31 04:31:16 -0500 | [diff] [blame] | 737 | 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] | 738 | } |
| 739 | |
| 740 | static void |
| 741 | handle_101103(struct bregs *regs) |
| 742 | { |
Kevin O'Connor | 88ca741 | 2011-12-31 04:24:20 -0500 | [diff] [blame] | 743 | stdvga_set_text_block_specifier(regs->bl); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static void |
| 747 | handle_101104(struct bregs *regs) |
| 748 | { |
Kevin O'Connor | 2bec7d6 | 2011-12-31 04:31:16 -0500 | [diff] [blame] | 749 | 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] | 750 | } |
| 751 | |
| 752 | static void |
| 753 | handle_101110(struct bregs *regs) |
| 754 | { |
Kevin O'Connor | 2bec7d6 | 2011-12-31 04:31:16 -0500 | [diff] [blame] | 755 | stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx |
| 756 | , regs->dx, regs->bl, regs->bh); |
Kevin O'Connor | c0c7df6 | 2009-05-17 18:11:33 -0400 | [diff] [blame] | 757 | set_scan_lines(regs->bh); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static void |
| 761 | handle_101111(struct bregs *regs) |
| 762 | { |
Kevin O'Connor | 2bec7d6 | 2011-12-31 04:31:16 -0500 | [diff] [blame] | 763 | 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] | 764 | set_scan_lines(14); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static void |
| 768 | handle_101112(struct bregs *regs) |
| 769 | { |
Kevin O'Connor | 2bec7d6 | 2011-12-31 04:31:16 -0500 | [diff] [blame] | 770 | 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] | 771 | set_scan_lines(8); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | static void |
| 775 | handle_101114(struct bregs *regs) |
| 776 | { |
Kevin O'Connor | 2bec7d6 | 2011-12-31 04:31:16 -0500 | [diff] [blame] | 777 | 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] | 778 | set_scan_lines(16); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static void |
Paolo Bonzini | 4bd8aeb | 2013-01-10 13:41:36 +0100 | [diff] [blame] | 782 | handle_101120(struct bregs *regs) |
| 783 | { |
| 784 | SET_IVT(0x1f, SEGOFF(regs->es, regs->bp)); |
| 785 | } |
| 786 | |
| 787 | void |
| 788 | load_gfx_font(u16 seg, u16 off, u8 height, u8 bl, u8 dl) |
| 789 | { |
| 790 | u8 rows; |
| 791 | |
| 792 | SET_IVT(0x43, SEGOFF(seg, off)); |
| 793 | switch(bl) { |
| 794 | case 0: |
| 795 | rows = dl; |
| 796 | break; |
| 797 | case 1: |
| 798 | rows = 14; |
| 799 | break; |
| 800 | case 3: |
| 801 | rows = 43; |
| 802 | break; |
| 803 | case 2: |
| 804 | default: |
| 805 | rows = 25; |
| 806 | break; |
| 807 | } |
| 808 | SET_BDA(video_rows, rows - 1); |
| 809 | SET_BDA(char_height, height); |
| 810 | } |
| 811 | |
| 812 | static void |
| 813 | handle_101121(struct bregs *regs) |
| 814 | { |
| 815 | load_gfx_font(regs->es, regs->bp, regs->cx, regs->bl, regs->dl); |
| 816 | } |
| 817 | |
| 818 | static void |
| 819 | handle_101122(struct bregs *regs) |
| 820 | { |
| 821 | load_gfx_font(get_global_seg(), (u32)vgafont14, 14, regs->bl, regs->dl); |
| 822 | } |
| 823 | |
| 824 | static void |
| 825 | handle_101123(struct bregs *regs) |
| 826 | { |
| 827 | load_gfx_font(get_global_seg(), (u32)vgafont8, 8, regs->bl, regs->dl); |
| 828 | } |
| 829 | |
| 830 | static void |
| 831 | handle_101124(struct bregs *regs) |
| 832 | { |
| 833 | load_gfx_font(get_global_seg(), (u32)vgafont16, 16, regs->bl, regs->dl); |
| 834 | } |
| 835 | |
| 836 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 837 | handle_101130(struct bregs *regs) |
| 838 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 839 | switch (regs->bh) { |
| 840 | case 0x00: { |
Kevin O'Connor | c9d3c2d | 2010-01-01 12:53:32 -0500 | [diff] [blame] | 841 | struct segoff_s so = GET_IVT(0x1f); |
| 842 | regs->es = so.seg; |
| 843 | regs->bp = so.offset; |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 844 | break; |
| 845 | } |
| 846 | case 0x01: { |
Kevin O'Connor | c9d3c2d | 2010-01-01 12:53:32 -0500 | [diff] [blame] | 847 | struct segoff_s so = GET_IVT(0x43); |
| 848 | regs->es = so.seg; |
| 849 | regs->bp = so.offset; |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 850 | break; |
| 851 | } |
| 852 | case 0x02: |
| 853 | regs->es = get_global_seg(); |
| 854 | regs->bp = (u32)vgafont14; |
| 855 | break; |
| 856 | case 0x03: |
| 857 | regs->es = get_global_seg(); |
| 858 | regs->bp = (u32)vgafont8; |
| 859 | break; |
| 860 | case 0x04: |
| 861 | regs->es = get_global_seg(); |
| 862 | regs->bp = (u32)vgafont8 + 128 * 8; |
| 863 | break; |
| 864 | case 0x05: |
| 865 | regs->es = get_global_seg(); |
| 866 | regs->bp = (u32)vgafont14alt; |
| 867 | break; |
| 868 | case 0x06: |
| 869 | regs->es = get_global_seg(); |
| 870 | regs->bp = (u32)vgafont16; |
| 871 | break; |
| 872 | case 0x07: |
| 873 | regs->es = get_global_seg(); |
| 874 | regs->bp = (u32)vgafont16alt; |
| 875 | break; |
| 876 | default: |
| 877 | dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh); |
| 878 | return; |
| 879 | } |
| 880 | // Set byte/char of on screen font |
| 881 | regs->cx = GET_BDA(char_height) & 0xff; |
| 882 | |
| 883 | // Set Highest char row |
Kevin O'Connor | 4c85a26 | 2012-02-12 11:50:52 -0500 | [diff] [blame] | 884 | regs->dl = GET_BDA(video_rows); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | static void |
| 888 | handle_1011XX(struct bregs *regs) |
| 889 | { |
| 890 | debug_stub(regs); |
| 891 | } |
| 892 | |
| 893 | static void |
| 894 | handle_1011(struct bregs *regs) |
| 895 | { |
Kevin O'Connor | efbf4d6 | 2014-02-09 11:50:21 -0500 | [diff] [blame] | 896 | if (CONFIG_VGA_STDVGA_PORTS) { |
| 897 | switch (regs->al) { |
| 898 | case 0x00: handle_101100(regs); break; |
| 899 | case 0x01: handle_101101(regs); break; |
| 900 | case 0x02: handle_101102(regs); break; |
| 901 | case 0x03: handle_101103(regs); break; |
| 902 | case 0x04: handle_101104(regs); break; |
| 903 | case 0x10: handle_101110(regs); break; |
| 904 | case 0x11: handle_101111(regs); break; |
| 905 | case 0x12: handle_101112(regs); break; |
| 906 | case 0x14: handle_101114(regs); break; |
| 907 | } |
| 908 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 909 | switch (regs->al) { |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 910 | case 0x30: handle_101130(regs); break; |
Paolo Bonzini | 4bd8aeb | 2013-01-10 13:41:36 +0100 | [diff] [blame] | 911 | case 0x20: handle_101120(regs); break; |
| 912 | case 0x21: handle_101121(regs); break; |
| 913 | case 0x22: handle_101122(regs); break; |
| 914 | case 0x23: handle_101123(regs); break; |
| 915 | case 0x24: handle_101124(regs); break; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 916 | default: handle_1011XX(regs); break; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | |
| 921 | static void |
| 922 | handle_101210(struct bregs *regs) |
| 923 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 924 | u16 crtc_addr = GET_BDA(crtc_address); |
| 925 | if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS) |
| 926 | regs->bx = 0x0103; |
| 927 | else |
| 928 | regs->bx = 0x0003; |
| 929 | regs->cx = GET_BDA(video_switches) & 0x0f; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | static void |
| 933 | handle_101230(struct bregs *regs) |
| 934 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 935 | u8 mctl = GET_BDA(modeset_ctl); |
| 936 | u8 vswt = GET_BDA(video_switches); |
| 937 | switch (regs->al) { |
| 938 | case 0x00: |
| 939 | // 200 lines |
| 940 | mctl = (mctl & ~0x10) | 0x80; |
| 941 | vswt = (vswt & ~0x0f) | 0x08; |
| 942 | break; |
| 943 | case 0x01: |
| 944 | // 350 lines |
| 945 | mctl &= ~0x90; |
| 946 | vswt = (vswt & ~0x0f) | 0x09; |
| 947 | break; |
| 948 | case 0x02: |
| 949 | // 400 lines |
| 950 | mctl = (mctl & ~0x80) | 0x10; |
| 951 | vswt = (vswt & ~0x0f) | 0x09; |
| 952 | break; |
| 953 | default: |
| 954 | dprintf(1, "Select vert res (%02x) was discarded\n", regs->al); |
| 955 | break; |
| 956 | } |
| 957 | SET_BDA(modeset_ctl, mctl); |
| 958 | SET_BDA(video_switches, vswt); |
| 959 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | static void |
| 963 | handle_101231(struct bregs *regs) |
| 964 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 965 | u8 v = (regs->al & 0x01) << 3; |
| 966 | u8 mctl = GET_BDA(video_ctl) & ~0x08; |
| 967 | SET_BDA(video_ctl, mctl | v); |
| 968 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | static void |
| 972 | handle_101232(struct bregs *regs) |
| 973 | { |
Kevin O'Connor | efbf4d6 | 2014-02-09 11:50:21 -0500 | [diff] [blame] | 974 | if (CONFIG_VGA_STDVGA_PORTS) { |
| 975 | stdvga_enable_video_addressing(regs->al); |
| 976 | regs->al = 0x12; |
| 977 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | static void |
| 981 | handle_101233(struct bregs *regs) |
| 982 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 983 | u8 v = ((regs->al << 1) & 0x02) ^ 0x02; |
| 984 | u8 v2 = GET_BDA(modeset_ctl) & ~0x02; |
| 985 | SET_BDA(modeset_ctl, v | v2); |
| 986 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | static void |
| 990 | handle_101234(struct bregs *regs) |
| 991 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 992 | u8 v = (regs->al & 0x01) ^ 0x01; |
| 993 | u8 v2 = GET_BDA(modeset_ctl) & ~0x01; |
| 994 | SET_BDA(modeset_ctl, v | v2); |
| 995 | regs->al = 0x12; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static void |
| 999 | handle_101235(struct bregs *regs) |
| 1000 | { |
| 1001 | debug_stub(regs); |
| 1002 | regs->al = 0x12; |
| 1003 | } |
| 1004 | |
| 1005 | static void |
| 1006 | handle_101236(struct bregs *regs) |
| 1007 | { |
| 1008 | debug_stub(regs); |
| 1009 | regs->al = 0x12; |
| 1010 | } |
| 1011 | |
| 1012 | static void |
| 1013 | handle_1012XX(struct bregs *regs) |
| 1014 | { |
| 1015 | debug_stub(regs); |
| 1016 | } |
| 1017 | |
| 1018 | static void |
| 1019 | handle_1012(struct bregs *regs) |
| 1020 | { |
Kevin O'Connor | e91ec7c | 2012-01-14 16:30:49 -0500 | [diff] [blame] | 1021 | if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) { |
| 1022 | clext_1012(regs); |
| 1023 | return; |
| 1024 | } |
| 1025 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 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 | } |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 1040 | // Write string |
Kevin O'Connor | 0ad77f0 | 2009-05-31 20:46:43 -0400 | [diff] [blame] | 1041 | static void noinline |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1042 | handle_1013(struct bregs *regs) |
| 1043 | { |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 1044 | struct cursorpos cp; |
| 1045 | if (regs->dh == 0xff) |
| 1046 | // if row=0xff special case : use current cursor position |
| 1047 | cp = get_cursor_pos(regs->bh); |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 1048 | else |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 1049 | cp = (struct cursorpos) {regs->dl, regs->dh, regs->bh}; |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 1050 | |
Kevin O'Connor | 6ee837b | 2012-02-13 20:09:02 -0500 | [diff] [blame] | 1051 | u16 count = regs->cx; |
| 1052 | u8 *offset_far = (void*)(regs->bp + 0); |
| 1053 | u8 attr = regs->bl; |
| 1054 | while (count--) { |
| 1055 | u8 car = GET_FARVAR(regs->es, *offset_far); |
| 1056 | offset_far++; |
| 1057 | if (regs->al & 2) { |
| 1058 | attr = GET_FARVAR(regs->es, *offset_far); |
| 1059 | offset_far++; |
| 1060 | } |
| 1061 | |
| 1062 | struct carattr ca = {car, attr, 1}; |
| 1063 | write_teletype(&cp, ca); |
| 1064 | } |
| 1065 | |
| 1066 | if (regs->al & 1) |
Kevin O'Connor | afb287d | 2009-05-31 21:15:33 -0400 | [diff] [blame] | 1067 | set_cursor_pos(cp); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | static void |
| 1072 | handle_101a00(struct bregs *regs) |
| 1073 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 1074 | regs->bx = GET_BDA(dcc_index); |
| 1075 | regs->al = 0x1a; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | static void |
| 1079 | handle_101a01(struct bregs *regs) |
| 1080 | { |
Kevin O'Connor | e713204 | 2009-05-25 00:10:35 -0400 | [diff] [blame] | 1081 | SET_BDA(dcc_index, regs->bl); |
| 1082 | dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh); |
| 1083 | regs->al = 0x1a; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | static void |
| 1087 | handle_101aXX(struct bregs *regs) |
| 1088 | { |
| 1089 | debug_stub(regs); |
| 1090 | } |
| 1091 | |
| 1092 | static void |
| 1093 | handle_101a(struct bregs *regs) |
| 1094 | { |
| 1095 | switch (regs->al) { |
| 1096 | case 0x00: handle_101a00(regs); break; |
| 1097 | case 0x01: handle_101a01(regs); break; |
| 1098 | default: handle_101aXX(regs); break; |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | |
Kevin O'Connor | efb4523 | 2012-01-14 22:55:11 -0500 | [diff] [blame] | 1103 | static u8 static_functionality[0x10] VAR16 = { |
| 1104 | /* 0 */ 0xff, // All modes supported #1 |
| 1105 | /* 1 */ 0xe0, // All modes supported #2 |
| 1106 | /* 2 */ 0x0f, // All modes supported #3 |
| 1107 | /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved |
| 1108 | /* 7 */ 0x07, // 200, 350, 400 scan lines |
| 1109 | /* 8 */ 0x02, // mamimum number of visible charsets in text mode |
| 1110 | /* 9 */ 0x08, // total number of charset blocks in text mode |
| 1111 | /* a */ 0xe7, // Change to add new functions |
| 1112 | /* b */ 0x0c, // Change to add new functions |
| 1113 | /* c */ 0x00, // reserved |
| 1114 | /* d */ 0x00, // reserved |
| 1115 | /* e */ 0x00, // Change to add new functions |
| 1116 | /* f */ 0x00 // reserved |
| 1117 | }; |
| 1118 | |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1119 | struct funcInfo { |
Kevin O'Connor | 87dfad3 | 2011-12-23 21:18:49 -0500 | [diff] [blame] | 1120 | struct segoff_s static_functionality; |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1121 | u8 bda_0x49[30]; |
| 1122 | u8 bda_0x84[3]; |
| 1123 | u8 dcc_index; |
| 1124 | u8 dcc_alt; |
| 1125 | u16 colors; |
| 1126 | u8 pages; |
| 1127 | u8 scan_lines; |
| 1128 | u8 primary_char; |
| 1129 | u8 secondar_char; |
| 1130 | u8 misc; |
| 1131 | u8 non_vga_mode; |
| 1132 | u8 reserved_2f[2]; |
| 1133 | u8 video_mem; |
| 1134 | u8 save_flags; |
| 1135 | u8 disp_info; |
| 1136 | u8 reserved_34[12]; |
Kevin O'Connor | f5ec1e0 | 2014-02-05 18:49:44 -0500 | [diff] [blame] | 1137 | } PACKED; |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1138 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1139 | static void |
| 1140 | handle_101b(struct bregs *regs) |
| 1141 | { |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1142 | u16 seg = regs->es; |
| 1143 | struct funcInfo *info = (void*)(regs->di+0); |
| 1144 | memset_far(seg, info, 0, sizeof(*info)); |
| 1145 | // Address of static functionality table |
Kevin O'Connor | 87dfad3 | 2011-12-23 21:18:49 -0500 | [diff] [blame] | 1146 | SET_FARVAR(seg, info->static_functionality |
| 1147 | , SEGOFF(get_global_seg(), (u32)static_functionality)); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1148 | |
| 1149 | // Hard coded copy from BIOS area. Should it be cleaner ? |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 1150 | memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49 |
| 1151 | , sizeof(info->bda_0x49)); |
| 1152 | memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84 |
| 1153 | , sizeof(info->bda_0x84)); |
Kevin O'Connor | ca66864 | 2009-05-21 23:06:08 -0400 | [diff] [blame] | 1154 | |
| 1155 | SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index)); |
| 1156 | SET_FARVAR(seg, info->colors, 16); |
| 1157 | SET_FARVAR(seg, info->pages, 8); |
| 1158 | SET_FARVAR(seg, info->scan_lines, 2); |
| 1159 | SET_FARVAR(seg, info->video_mem, 3); |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1160 | regs->al = 0x1B; |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1165 | handle_101c(struct bregs *regs) |
| 1166 | { |
Kevin O'Connor | 9f857fc | 2012-02-04 11:59:02 -0500 | [diff] [blame] | 1167 | u16 seg = regs->es; |
| 1168 | void *data = (void*)(regs->bx+0); |
| 1169 | u16 states = regs->cx; |
Kevin O'Connor | 20dc419 | 2014-02-05 20:52:25 -0500 | [diff] [blame] | 1170 | u8 cmd = regs->al; |
| 1171 | if (states & ~0x07 || cmd > 2) |
Kevin O'Connor | 9f857fc | 2012-02-04 11:59:02 -0500 | [diff] [blame] | 1172 | goto fail; |
Kevin O'Connor | 20dc419 | 2014-02-05 20:52:25 -0500 | [diff] [blame] | 1173 | int ret = vgahw_save_restore(states | (cmd<<8), seg, data); |
| 1174 | if (ret < 0) |
| 1175 | goto fail; |
| 1176 | if (cmd == 0) |
Kevin O'Connor | 9f857fc | 2012-02-04 11:59:02 -0500 | [diff] [blame] | 1177 | regs->bx = ret / 64; |
Kevin O'Connor | 9f857fc | 2012-02-04 11:59:02 -0500 | [diff] [blame] | 1178 | regs->al = 0x1c; |
| 1179 | fail: |
| 1180 | return; |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1181 | } |
| 1182 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1183 | static void |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 1184 | handle_10XX(struct bregs *regs) |
| 1185 | { |
| 1186 | debug_stub(regs); |
| 1187 | } |
| 1188 | |
| 1189 | // INT 10h Video Support Service Entry Point |
| 1190 | void VISIBLE16 |
| 1191 | handle_10(struct bregs *regs) |
| 1192 | { |
| 1193 | debug_enter(regs, DEBUG_VGA_10); |
| 1194 | switch (regs->ah) { |
| 1195 | case 0x00: handle_1000(regs); break; |
| 1196 | case 0x01: handle_1001(regs); break; |
| 1197 | case 0x02: handle_1002(regs); break; |
| 1198 | case 0x03: handle_1003(regs); break; |
| 1199 | case 0x04: handle_1004(regs); break; |
| 1200 | case 0x05: handle_1005(regs); break; |
| 1201 | case 0x06: handle_1006(regs); break; |
| 1202 | case 0x07: handle_1007(regs); break; |
| 1203 | case 0x08: handle_1008(regs); break; |
| 1204 | case 0x09: handle_1009(regs); break; |
| 1205 | case 0x0a: handle_100a(regs); break; |
| 1206 | case 0x0b: handle_100b(regs); break; |
| 1207 | case 0x0c: handle_100c(regs); break; |
| 1208 | case 0x0d: handle_100d(regs); break; |
| 1209 | case 0x0e: handle_100e(regs); break; |
| 1210 | case 0x0f: handle_100f(regs); break; |
| 1211 | case 0x10: handle_1010(regs); break; |
| 1212 | case 0x11: handle_1011(regs); break; |
| 1213 | case 0x12: handle_1012(regs); break; |
| 1214 | case 0x13: handle_1013(regs); break; |
| 1215 | case 0x1a: handle_101a(regs); break; |
| 1216 | case 0x1b: handle_101b(regs); break; |
| 1217 | case 0x1c: handle_101c(regs); break; |
| 1218 | case 0x4f: handle_104f(regs); break; |
| 1219 | default: handle_10XX(regs); break; |
| 1220 | } |
| 1221 | } |