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