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