blob: 1756adef0b9ec203cfe3fd9cacc4b5a71b6ab99a [file] [log] [blame]
Kevin O'Connor4ad2d102012-01-14 23:20:05 -05001// Standard VGA mode information.
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04002//
3// Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2001-2008 the LGPL VGABios developers Team
5//
6// This file may be distributed under the terms of the GNU LGPLv3 license.
7
Kevin O'Connore1e000b2011-12-31 03:30:40 -05008#include "vgabios.h" // struct VideoParamTableEntry_s
Kevin O'Connor5727c292009-05-16 17:29:32 -04009#include "biosvar.h" // GET_GLOBAL
Kevin O'Connorf3760372011-12-23 22:41:08 -050010#include "util.h" // memcpy_far
Kevin O'Connoraad3b692012-01-14 23:15:40 -050011#include "stdvga.h" // stdvga_find_mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040012
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040013
Kevin O'Connor5727c292009-05-16 17:29:32 -040014/****************************************************************
Kevin O'Connoraad3b692012-01-14 23:15:40 -050015 * Video mode register definitions
Kevin O'Connor5727c292009-05-16 17:29:32 -040016 ****************************************************************/
17
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040018/* Mono */
Kevin O'Connor5727c292009-05-16 17:29:32 -040019static u8 palette0[] VAR16 = {
Kevin O'Connora959aa12009-05-25 00:12:18 -040020 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
21 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
22 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
23 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
24 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
25 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
26 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f,
27 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f,
28 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
29 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
30 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
31 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
32 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
33 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a, 0x2a,0x2a,0x2a,
34 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f,
35 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f, 0x3f,0x3f,0x3f
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040036};
37
Kevin O'Connor5727c292009-05-16 17:29:32 -040038static u8 palette1[] VAR16 = {
Kevin O'Connora959aa12009-05-25 00:12:18 -040039 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
40 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
41 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
42 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
43 0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
44 0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f,
45 0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
46 0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f,
47 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
48 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
49 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
50 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
51 0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
52 0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f,
53 0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
54 0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040055};
56
Kevin O'Connor5727c292009-05-16 17:29:32 -040057static u8 palette2[] VAR16 = {
Kevin O'Connora959aa12009-05-25 00:12:18 -040058 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
59 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x2a,0x00, 0x2a,0x2a,0x2a,
60 0x00,0x00,0x15, 0x00,0x00,0x3f, 0x00,0x2a,0x15, 0x00,0x2a,0x3f,
61 0x2a,0x00,0x15, 0x2a,0x00,0x3f, 0x2a,0x2a,0x15, 0x2a,0x2a,0x3f,
62 0x00,0x15,0x00, 0x00,0x15,0x2a, 0x00,0x3f,0x00, 0x00,0x3f,0x2a,
63 0x2a,0x15,0x00, 0x2a,0x15,0x2a, 0x2a,0x3f,0x00, 0x2a,0x3f,0x2a,
64 0x00,0x15,0x15, 0x00,0x15,0x3f, 0x00,0x3f,0x15, 0x00,0x3f,0x3f,
65 0x2a,0x15,0x15, 0x2a,0x15,0x3f, 0x2a,0x3f,0x15, 0x2a,0x3f,0x3f,
66 0x15,0x00,0x00, 0x15,0x00,0x2a, 0x15,0x2a,0x00, 0x15,0x2a,0x2a,
67 0x3f,0x00,0x00, 0x3f,0x00,0x2a, 0x3f,0x2a,0x00, 0x3f,0x2a,0x2a,
68 0x15,0x00,0x15, 0x15,0x00,0x3f, 0x15,0x2a,0x15, 0x15,0x2a,0x3f,
69 0x3f,0x00,0x15, 0x3f,0x00,0x3f, 0x3f,0x2a,0x15, 0x3f,0x2a,0x3f,
70 0x15,0x15,0x00, 0x15,0x15,0x2a, 0x15,0x3f,0x00, 0x15,0x3f,0x2a,
71 0x3f,0x15,0x00, 0x3f,0x15,0x2a, 0x3f,0x3f,0x00, 0x3f,0x3f,0x2a,
72 0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
73 0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040074};
75
Kevin O'Connor5727c292009-05-16 17:29:32 -040076static u8 palette3[] VAR16 = {
Kevin O'Connora959aa12009-05-25 00:12:18 -040077 0x00,0x00,0x00, 0x00,0x00,0x2a, 0x00,0x2a,0x00, 0x00,0x2a,0x2a,
78 0x2a,0x00,0x00, 0x2a,0x00,0x2a, 0x2a,0x15,0x00, 0x2a,0x2a,0x2a,
79 0x15,0x15,0x15, 0x15,0x15,0x3f, 0x15,0x3f,0x15, 0x15,0x3f,0x3f,
80 0x3f,0x15,0x15, 0x3f,0x15,0x3f, 0x3f,0x3f,0x15, 0x3f,0x3f,0x3f,
81 0x00,0x00,0x00, 0x05,0x05,0x05, 0x08,0x08,0x08, 0x0b,0x0b,0x0b,
82 0x0e,0x0e,0x0e, 0x11,0x11,0x11, 0x14,0x14,0x14, 0x18,0x18,0x18,
83 0x1c,0x1c,0x1c, 0x20,0x20,0x20, 0x24,0x24,0x24, 0x28,0x28,0x28,
84 0x2d,0x2d,0x2d, 0x32,0x32,0x32, 0x38,0x38,0x38, 0x3f,0x3f,0x3f,
85 0x00,0x00,0x3f, 0x10,0x00,0x3f, 0x1f,0x00,0x3f, 0x2f,0x00,0x3f,
86 0x3f,0x00,0x3f, 0x3f,0x00,0x2f, 0x3f,0x00,0x1f, 0x3f,0x00,0x10,
87 0x3f,0x00,0x00, 0x3f,0x10,0x00, 0x3f,0x1f,0x00, 0x3f,0x2f,0x00,
88 0x3f,0x3f,0x00, 0x2f,0x3f,0x00, 0x1f,0x3f,0x00, 0x10,0x3f,0x00,
89 0x00,0x3f,0x00, 0x00,0x3f,0x10, 0x00,0x3f,0x1f, 0x00,0x3f,0x2f,
90 0x00,0x3f,0x3f, 0x00,0x2f,0x3f, 0x00,0x1f,0x3f, 0x00,0x10,0x3f,
91 0x1f,0x1f,0x3f, 0x27,0x1f,0x3f, 0x2f,0x1f,0x3f, 0x37,0x1f,0x3f,
92 0x3f,0x1f,0x3f, 0x3f,0x1f,0x37, 0x3f,0x1f,0x2f, 0x3f,0x1f,0x27,
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040093
Kevin O'Connora959aa12009-05-25 00:12:18 -040094 0x3f,0x1f,0x1f, 0x3f,0x27,0x1f, 0x3f,0x2f,0x1f, 0x3f,0x37,0x1f,
95 0x3f,0x3f,0x1f, 0x37,0x3f,0x1f, 0x2f,0x3f,0x1f, 0x27,0x3f,0x1f,
96 0x1f,0x3f,0x1f, 0x1f,0x3f,0x27, 0x1f,0x3f,0x2f, 0x1f,0x3f,0x37,
97 0x1f,0x3f,0x3f, 0x1f,0x37,0x3f, 0x1f,0x2f,0x3f, 0x1f,0x27,0x3f,
98 0x2d,0x2d,0x3f, 0x31,0x2d,0x3f, 0x36,0x2d,0x3f, 0x3a,0x2d,0x3f,
99 0x3f,0x2d,0x3f, 0x3f,0x2d,0x3a, 0x3f,0x2d,0x36, 0x3f,0x2d,0x31,
100 0x3f,0x2d,0x2d, 0x3f,0x31,0x2d, 0x3f,0x36,0x2d, 0x3f,0x3a,0x2d,
101 0x3f,0x3f,0x2d, 0x3a,0x3f,0x2d, 0x36,0x3f,0x2d, 0x31,0x3f,0x2d,
102 0x2d,0x3f,0x2d, 0x2d,0x3f,0x31, 0x2d,0x3f,0x36, 0x2d,0x3f,0x3a,
103 0x2d,0x3f,0x3f, 0x2d,0x3a,0x3f, 0x2d,0x36,0x3f, 0x2d,0x31,0x3f,
104 0x00,0x00,0x1c, 0x07,0x00,0x1c, 0x0e,0x00,0x1c, 0x15,0x00,0x1c,
105 0x1c,0x00,0x1c, 0x1c,0x00,0x15, 0x1c,0x00,0x0e, 0x1c,0x00,0x07,
106 0x1c,0x00,0x00, 0x1c,0x07,0x00, 0x1c,0x0e,0x00, 0x1c,0x15,0x00,
107 0x1c,0x1c,0x00, 0x15,0x1c,0x00, 0x0e,0x1c,0x00, 0x07,0x1c,0x00,
108 0x00,0x1c,0x00, 0x00,0x1c,0x07, 0x00,0x1c,0x0e, 0x00,0x1c,0x15,
109 0x00,0x1c,0x1c, 0x00,0x15,0x1c, 0x00,0x0e,0x1c, 0x00,0x07,0x1c,
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400110
Kevin O'Connora959aa12009-05-25 00:12:18 -0400111 0x0e,0x0e,0x1c, 0x11,0x0e,0x1c, 0x15,0x0e,0x1c, 0x18,0x0e,0x1c,
112 0x1c,0x0e,0x1c, 0x1c,0x0e,0x18, 0x1c,0x0e,0x15, 0x1c,0x0e,0x11,
113 0x1c,0x0e,0x0e, 0x1c,0x11,0x0e, 0x1c,0x15,0x0e, 0x1c,0x18,0x0e,
114 0x1c,0x1c,0x0e, 0x18,0x1c,0x0e, 0x15,0x1c,0x0e, 0x11,0x1c,0x0e,
115 0x0e,0x1c,0x0e, 0x0e,0x1c,0x11, 0x0e,0x1c,0x15, 0x0e,0x1c,0x18,
116 0x0e,0x1c,0x1c, 0x0e,0x18,0x1c, 0x0e,0x15,0x1c, 0x0e,0x11,0x1c,
117 0x14,0x14,0x1c, 0x16,0x14,0x1c, 0x18,0x14,0x1c, 0x1a,0x14,0x1c,
118 0x1c,0x14,0x1c, 0x1c,0x14,0x1a, 0x1c,0x14,0x18, 0x1c,0x14,0x16,
119 0x1c,0x14,0x14, 0x1c,0x16,0x14, 0x1c,0x18,0x14, 0x1c,0x1a,0x14,
120 0x1c,0x1c,0x14, 0x1a,0x1c,0x14, 0x18,0x1c,0x14, 0x16,0x1c,0x14,
121 0x14,0x1c,0x14, 0x14,0x1c,0x16, 0x14,0x1c,0x18, 0x14,0x1c,0x1a,
122 0x14,0x1c,0x1c, 0x14,0x1a,0x1c, 0x14,0x18,0x1c, 0x14,0x16,0x1c,
123 0x00,0x00,0x10, 0x04,0x00,0x10, 0x08,0x00,0x10, 0x0c,0x00,0x10,
124 0x10,0x00,0x10, 0x10,0x00,0x0c, 0x10,0x00,0x08, 0x10,0x00,0x04,
125 0x10,0x00,0x00, 0x10,0x04,0x00, 0x10,0x08,0x00, 0x10,0x0c,0x00,
126 0x10,0x10,0x00, 0x0c,0x10,0x00, 0x08,0x10,0x00, 0x04,0x10,0x00,
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400127
Kevin O'Connora959aa12009-05-25 00:12:18 -0400128 0x00,0x10,0x00, 0x00,0x10,0x04, 0x00,0x10,0x08, 0x00,0x10,0x0c,
129 0x00,0x10,0x10, 0x00,0x0c,0x10, 0x00,0x08,0x10, 0x00,0x04,0x10,
130 0x08,0x08,0x10, 0x0a,0x08,0x10, 0x0c,0x08,0x10, 0x0e,0x08,0x10,
131 0x10,0x08,0x10, 0x10,0x08,0x0e, 0x10,0x08,0x0c, 0x10,0x08,0x0a,
132 0x10,0x08,0x08, 0x10,0x0a,0x08, 0x10,0x0c,0x08, 0x10,0x0e,0x08,
133 0x10,0x10,0x08, 0x0e,0x10,0x08, 0x0c,0x10,0x08, 0x0a,0x10,0x08,
134 0x08,0x10,0x08, 0x08,0x10,0x0a, 0x08,0x10,0x0c, 0x08,0x10,0x0e,
135 0x08,0x10,0x10, 0x08,0x0e,0x10, 0x08,0x0c,0x10, 0x08,0x0a,0x10,
136 0x0b,0x0b,0x10, 0x0c,0x0b,0x10, 0x0d,0x0b,0x10, 0x0f,0x0b,0x10,
137 0x10,0x0b,0x10, 0x10,0x0b,0x0f, 0x10,0x0b,0x0d, 0x10,0x0b,0x0c,
138 0x10,0x0b,0x0b, 0x10,0x0c,0x0b, 0x10,0x0d,0x0b, 0x10,0x0f,0x0b,
139 0x10,0x10,0x0b, 0x0f,0x10,0x0b, 0x0d,0x10,0x0b, 0x0c,0x10,0x0b,
140 0x0b,0x10,0x0b, 0x0b,0x10,0x0c, 0x0b,0x10,0x0d, 0x0b,0x10,0x0f,
141 0x0b,0x10,0x10, 0x0b,0x0f,0x10, 0x0b,0x0d,0x10, 0x0b,0x0c,0x10,
142 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00,
143 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400144};
145
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500146static u8 sequ_01[] VAR16 = { 0x08, 0x03, 0x00, 0x02 };
147static u8 crtc_01[] VAR16 = {
148 0x2d, 0x27, 0x28, 0x90, 0x2b, 0xa0, 0xbf, 0x1f,
149 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
150 0x9c, 0x8e, 0x8f, 0x14, 0x1f, 0x96, 0xb9, 0xa3,
151 0xff };
152static u8 actl_01[] VAR16 = {
153 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
154 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
155 0x0c, 0x00, 0x0f, 0x08 };
156static u8 grdc_01[] VAR16 = {
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x0f, 0xff };
158static u8 sequ_03[] VAR16 = { 0x00, 0x03, 0x00, 0x02 };
159static u8 crtc_03[] VAR16 = {
160 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
161 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
162 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
163 0xff };
164static u8 sequ_04[] VAR16 = { 0x09, 0x03, 0x00, 0x02 };
165static u8 crtc_04[] VAR16 = {
166 0x2d, 0x27, 0x28, 0x90, 0x2b, 0x80, 0xbf, 0x1f,
167 0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168 0x9c, 0x8e, 0x8f, 0x14, 0x00, 0x96, 0xb9, 0xa2,
169 0xff };
170static u8 actl_04[] VAR16 = {
171 0x00, 0x13, 0x15, 0x17, 0x02, 0x04, 0x06, 0x07,
172 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
173 0x01, 0x00, 0x03, 0x00 };
174static u8 grdc_04[] VAR16 = {
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0f, 0x0f, 0xff };
176static u8 sequ_06[] VAR16 = { 0x01, 0x01, 0x00, 0x06 };
177static u8 crtc_06[] VAR16 = {
178 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
179 0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180 0x9c, 0x8e, 0x8f, 0x28, 0x00, 0x96, 0xb9, 0xc2,
181 0xff };
182static u8 actl_06[] VAR16 = {
183 0x00, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
184 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
185 0x01, 0x00, 0x01, 0x00 };
186static u8 grdc_06[] VAR16 = {
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0f, 0xff };
188static u8 crtc_07[] VAR16 = {
189 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
190 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
191 0x9c, 0x8e, 0x8f, 0x28, 0x0f, 0x96, 0xb9, 0xa3,
192 0xff };
193static u8 actl_07[] VAR16 = {
194 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
195 0x10, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
196 0x0e, 0x00, 0x0f, 0x08 };
197static u8 grdc_07[] VAR16 = {
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0a, 0x0f, 0xff };
199static u8 sequ_0d[] VAR16 = { 0x09, 0x0f, 0x00, 0x06 };
200static u8 crtc_0d[] VAR16 = {
201 0x2d, 0x27, 0x28, 0x90, 0x2b, 0x80, 0xbf, 0x1f,
202 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203 0x9c, 0x8e, 0x8f, 0x14, 0x00, 0x96, 0xb9, 0xe3,
204 0xff };
205static u8 actl_0d[] VAR16 = {
206 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
207 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
208 0x01, 0x00, 0x0f, 0x00 };
209static u8 grdc_0d[] VAR16 = {
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff };
211static u8 sequ_0e[] VAR16 = { 0x01, 0x0f, 0x00, 0x06 };
212static u8 crtc_0e[] VAR16 = {
213 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
214 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215 0x9c, 0x8e, 0x8f, 0x28, 0x00, 0x96, 0xb9, 0xe3,
216 0xff };
217static u8 crtc_0f[] VAR16 = {
218 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
219 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
220 0x83, 0x85, 0x5d, 0x28, 0x0f, 0x63, 0xba, 0xe3,
221 0xff };
222static u8 actl_0f[] VAR16 = {
223 0x00, 0x08, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
224 0x00, 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
225 0x01, 0x00, 0x01, 0x00 };
226static u8 actl_10[] VAR16 = {
227 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
228 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
229 0x01, 0x00, 0x0f, 0x00 };
230static u8 crtc_11[] VAR16 = {
231 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e,
232 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0xea, 0x8c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
234 0xff };
235static u8 actl_11[] VAR16 = {
236 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f,
237 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f,
238 0x01, 0x00, 0x0f, 0x00 };
239static u8 sequ_13[] VAR16 = { 0x01, 0x0f, 0x00, 0x0e };
240static u8 crtc_13[] VAR16 = {
241 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
242 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x9c, 0x8e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3,
244 0xff };
245static u8 actl_13[] VAR16 = {
246 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
247 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
248 0x41, 0x00, 0x0f, 0x00 };
249static u8 grdc_13[] VAR16 = {
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f, 0xff };
251static u8 crtc_6A[] VAR16 = {
252 0x7f, 0x63, 0x63, 0x83, 0x6b, 0x1b, 0x72, 0xf0,
253 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x59, 0x8d, 0x57, 0x32, 0x00, 0x57, 0x73, 0xe3,
255 0xff };
256
Kevin O'Connor5727c292009-05-16 17:29:32 -0400257#define PAL(x) x, sizeof(x)
Kevin O'Connor5727c292009-05-16 17:29:32 -0400258
Kevin O'Connorf98bbf02012-01-27 23:09:02 -0500259struct stdvga_mode_s {
260 u16 mode;
261 struct vgamode_s info;
262
263 u8 pelmask;
264 u8 *dac;
265 u16 dacsize;
266 u8 *sequ_regs;
267 u8 miscreg;
268 u8 *crtc_regs;
269 u8 *actl_regs;
270 u8 *grdc_regs;
271};
272
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500273static struct stdvga_mode_s vga_modes[] VAR16 = {
274 //mode { model tx ty bpp cw ch sstart }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500275 // pelm dac sequ misc crtc actl grdc
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500276 {0x00, { MM_TEXT, 40, 25, 4, 9, 16, SEG_CTEXT }
Kevin O'Connord4398ad2012-01-01 12:32:53 -0500277 , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500278 {0x01, { MM_TEXT, 40, 25, 4, 9, 16, SEG_CTEXT }
Kevin O'Connord4398ad2012-01-01 12:32:53 -0500279 , 0xFF, PAL(palette2), sequ_01, 0x67, crtc_01, actl_01, grdc_01},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500280 {0x02, { MM_TEXT, 80, 25, 4, 9, 16, SEG_CTEXT }
Kevin O'Connord4398ad2012-01-01 12:32:53 -0500281 , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500282 {0x03, { MM_TEXT, 80, 25, 4, 9, 16, SEG_CTEXT }
Kevin O'Connord4398ad2012-01-01 12:32:53 -0500283 , 0xFF, PAL(palette2), sequ_03, 0x67, crtc_03, actl_01, grdc_01},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500284 {0x04, { MM_CGA, 320, 200, 2, 8, 8, SEG_CTEXT }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500285 , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500286 {0x05, { MM_CGA, 320, 200, 2, 8, 8, SEG_CTEXT }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500287 , 0xFF, PAL(palette1), sequ_04, 0x63, crtc_04, actl_04, grdc_04},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500288 {0x06, { MM_CGA, 640, 200, 1, 8, 8, SEG_CTEXT }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500289 , 0xFF, PAL(palette1), sequ_06, 0x63, crtc_06, actl_06, grdc_06},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500290 {0x07, { MM_TEXT, 80, 25, 4, 9, 16, SEG_MTEXT }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500291 , 0xFF, PAL(palette0), sequ_03, 0x66, crtc_07, actl_07, grdc_07},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500292 {0x0D, { MM_PLANAR, 320, 200, 4, 8, 8, SEG_GRAPH }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500293 , 0xFF, PAL(palette1), sequ_0d, 0x63, crtc_0d, actl_0d, grdc_0d},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500294 {0x0E, { MM_PLANAR, 640, 200, 4, 8, 8, SEG_GRAPH }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500295 , 0xFF, PAL(palette1), sequ_0e, 0x63, crtc_0e, actl_0d, grdc_0d},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500296 {0x0F, { MM_PLANAR, 640, 350, 1, 8, 14, SEG_GRAPH }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500297 , 0xFF, PAL(palette0), sequ_0e, 0xa3, crtc_0f, actl_0f, grdc_0d},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500298 {0x10, { MM_PLANAR, 640, 350, 4, 8, 14, SEG_GRAPH }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500299 , 0xFF, PAL(palette2), sequ_0e, 0xa3, crtc_0f, actl_10, grdc_0d},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500300 {0x11, { MM_PLANAR, 640, 480, 1, 8, 16, SEG_GRAPH }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500301 , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_11, grdc_0d},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500302 {0x12, { MM_PLANAR, 640, 480, 4, 8, 16, SEG_GRAPH }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500303 , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_11, actl_10, grdc_0d},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500304 {0x13, { MM_PACKED, 320, 200, 8, 8, 8, SEG_GRAPH }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500305 , 0xFF, PAL(palette3), sequ_13, 0x63, crtc_13, actl_13, grdc_13},
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500306 {0x6A, { MM_PLANAR, 800, 600, 4, 8, 16, SEG_GRAPH }
Kevin O'Connor0c7d4d02011-12-23 21:20:09 -0500307 , 0xFF, PAL(palette2), sequ_0e, 0xe3, crtc_6A, actl_10, grdc_0d},
Kevin O'Connor5727c292009-05-16 17:29:32 -0400308};
309
Kevin O'Connoraad3b692012-01-14 23:15:40 -0500310
311/****************************************************************
312 * Mode functions
313 ****************************************************************/
314
Kevin O'Connorf98bbf02012-01-27 23:09:02 -0500315static int
316is_stdvga_mode(struct vgamode_s *vmode_g)
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500317{
318 return (vmode_g >= &vga_modes[0].info
319 && vmode_g <= &vga_modes[ARRAY_SIZE(vga_modes)-1].info);
320}
321
Kevin O'Connor5727c292009-05-16 17:29:32 -0400322struct vgamode_s *
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500323stdvga_find_mode(int mode)
Kevin O'Connor5727c292009-05-16 17:29:32 -0400324{
325 int i;
326 for (i = 0; i < ARRAY_SIZE(vga_modes); i++) {
Kevin O'Connor10dff3d2012-01-09 19:19:44 -0500327 struct stdvga_mode_s *stdmode_g = &vga_modes[i];
328 if (GET_GLOBAL(stdmode_g->mode) == mode)
329 return &stdmode_g->info;
Kevin O'Connor5727c292009-05-16 17:29:32 -0400330 }
331 return NULL;
332}
Kevin O'Connoraad3b692012-01-14 23:15:40 -0500333
334void
Kevin O'Connorf98bbf02012-01-27 23:09:02 -0500335stdvga_list_modes(u16 seg, u16 *dest, u16 *last)
336{
Christian Gmeinera1a32832012-09-01 17:12:55 +0200337 int i;
338 for (i = 0; i < ARRAY_SIZE(vga_modes); i++) {
339 struct stdvga_mode_s *stdmode_g = &vga_modes[i];
340 u16 mode = GET_GLOBAL(stdmode_g->mode);
341 if (mode == 0xffff)
342 continue;
343 SET_FARVAR(seg, *dest, mode);
344 dest++;
345 }
346
Kevin O'Connorf98bbf02012-01-27 23:09:02 -0500347 SET_FARVAR(seg, *dest, 0xffff);
348}
349
350void
Kevin O'Connoraad3b692012-01-14 23:15:40 -0500351stdvga_build_video_param(void)
352{
353 static u8 parammodes[] VAR16 = {
354 0, 0, 0, 0, 0x04, 0x05, 0x06, 0x07,
355 0, 0, 0, 0, 0, 0x0d, 0x0e, 0,
356 0, 0x0f, 0x10, 0, 0, 0, 0, 0x01,
357 0x03, 0x07, 0x11, 0x12, 0x13
358 };
359
360 int i;
361 for (i=0; i<ARRAY_SIZE(parammodes); i++) {
362 int mode = GET_GLOBAL(parammodes[i]);
363 if (! mode)
364 continue;
365 struct VideoParam_s *vparam_g = &video_param_table[i];
366 struct vgamode_s *vmode_g = stdvga_find_mode(mode);
367 if (!vmode_g)
368 continue;
369 int width = GET_GLOBAL(vmode_g->width);
370 int height = GET_GLOBAL(vmode_g->height);
371 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
372 int cheight = GET_GLOBAL(vmode_g->cheight);
373 if (memmodel == MM_TEXT) {
374 SET_VGA(vparam_g->twidth, width);
375 SET_VGA(vparam_g->theightm1, height-1);
376 } else {
377 int cwidth = GET_GLOBAL(vmode_g->cwidth);
378 SET_VGA(vparam_g->twidth, width / cwidth);
379 SET_VGA(vparam_g->theightm1, (height / cheight) - 1);
380 }
381 SET_VGA(vparam_g->cheight, cheight);
382 SET_VGA(vparam_g->slength, calc_page_size(memmodel, width, height));
383 struct stdvga_mode_s *stdmode_g = container_of(
384 vmode_g, struct stdvga_mode_s, info);
385 memcpy_far(get_global_seg(), vparam_g->sequ_regs
386 , get_global_seg(), GET_GLOBAL(stdmode_g->sequ_regs)
387 , ARRAY_SIZE(vparam_g->sequ_regs));
388 SET_VGA(vparam_g->miscreg, GET_GLOBAL(stdmode_g->miscreg));
389 memcpy_far(get_global_seg(), vparam_g->crtc_regs
390 , get_global_seg(), GET_GLOBAL(stdmode_g->crtc_regs)
391 , ARRAY_SIZE(vparam_g->crtc_regs));
392 memcpy_far(get_global_seg(), vparam_g->actl_regs
393 , get_global_seg(), GET_GLOBAL(stdmode_g->actl_regs)
394 , ARRAY_SIZE(vparam_g->actl_regs));
395 memcpy_far(get_global_seg(), vparam_g->grdc_regs
396 , get_global_seg(), GET_GLOBAL(stdmode_g->grdc_regs)
397 , ARRAY_SIZE(vparam_g->grdc_regs));
398 }
399}
Kevin O'Connor69b01cb2012-01-14 23:25:24 -0500400
401void
402stdvga_override_crtc(int mode, u8 *crtc)
403{
404 struct vgamode_s *vmode_g = stdvga_find_mode(mode);
405 if (!vmode_g)
406 return;
407 struct stdvga_mode_s *stdmode_g = container_of(
408 vmode_g, struct stdvga_mode_s, info);
409 SET_VGA(stdmode_g->crtc_regs, crtc);
410}
Kevin O'Connorf98bbf02012-01-27 23:09:02 -0500411
412static void
413clear_screen(struct vgamode_s *vmode_g)
414{
415 switch (GET_GLOBAL(vmode_g->memmodel)) {
416 case MM_TEXT:
417 memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0720, 32*1024);
418 break;
419 case MM_CGA:
420 memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 32*1024);
421 break;
422 default:
423 // XXX - old code gets/sets/restores sequ register 2 to 0xf -
424 // but it should always be 0xf anyway.
425 memset16_far(GET_GLOBAL(vmode_g->sstart), 0, 0x0000, 64*1024);
426 }
427}
428
429int
430stdvga_set_mode(struct vgamode_s *vmode_g, int flags)
431{
432 if (! is_stdvga_mode(vmode_g)) {
433 warn_internalerror();
434 return -1;
435 }
436 struct stdvga_mode_s *stdmode_g = container_of(
437 vmode_g, struct stdvga_mode_s, info);
438
439 // if palette loading (bit 3 of modeset ctl = 0)
440 if (!(flags & MF_NOPALETTE)) { // Set the PEL mask
441 stdvga_pelmask_write(GET_GLOBAL(stdmode_g->pelmask));
442
443 // From which palette
444 u8 *palette_g = GET_GLOBAL(stdmode_g->dac);
445 u16 palsize = GET_GLOBAL(stdmode_g->dacsize) / 3;
446
447 // Always 256*3 values
448 stdvga_dac_write(get_global_seg(), palette_g, 0, palsize);
449 int i;
450 for (i = palsize; i < 0x0100; i++) {
451 static u8 rgb[3] VAR16;
452 stdvga_dac_write(get_global_seg(), rgb, i, 1);
453 }
454
455 if (flags & MF_GRAYSUM)
456 stdvga_perform_gray_scale_summing(0x00, 0x100);
457 }
458
459 // Set Attribute Ctl
460 u8 *regs = GET_GLOBAL(stdmode_g->actl_regs);
461 int i;
462 for (i = 0; i <= 0x13; i++)
463 stdvga_attr_write(i, GET_GLOBAL(regs[i]));
464 stdvga_attr_write(0x14, 0x00);
465
466 // Set Sequencer Ctl
467 stdvga_sequ_write(0x00, 0x03);
468 regs = GET_GLOBAL(stdmode_g->sequ_regs);
469 for (i = 1; i <= 4; i++)
470 stdvga_sequ_write(i, GET_GLOBAL(regs[i - 1]));
471
472 // Set Grafx Ctl
473 regs = GET_GLOBAL(stdmode_g->grdc_regs);
474 for (i = 0; i <= 8; i++)
475 stdvga_grdc_write(i, GET_GLOBAL(regs[i]));
476
477 // Set CRTC address VGA or MDA
478 u8 miscreg = GET_GLOBAL(stdmode_g->miscreg);
479 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
480 if (!(miscreg & 1))
481 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
482
483 // Disable CRTC write protection
484 stdvga_crtc_write(crtc_addr, 0x11, 0x00);
485 // Set CRTC regs
486 regs = GET_GLOBAL(stdmode_g->crtc_regs);
487 for (i = 0; i <= 0x18; i++)
488 stdvga_crtc_write(crtc_addr, i, GET_GLOBAL(regs[i]));
489
490 // Set the misc register
491 stdvga_misc_write(miscreg);
492
493 // Enable video
494 stdvga_attrindex_write(0x20);
495
496 // Clear screen
497 if (!(flags & MF_NOCLEARMEM))
498 clear_screen(vmode_g);
499
500 // Write the fonts in memory
501 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
502 if (memmodel == MM_TEXT)
503 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, 0, 16);
504
505 return 0;
506}