]> 4ch.mooo.com Git - 16.git/blob - 16/cawat/ID_VW_A.ASM
d6376b25b6bcd0cd698ca7cf947ecf66cddf0b4a
[16.git] / 16 / cawat / ID_VW_A.ASM
1 ; Catacomb Armageddon Source Code\r
2 ; Copyright (C) 1993-2014 Flat Rock Software\r
3 ;\r
4 ; This program is free software; you can redistribute it and/or modify\r
5 ; it under the terms of the GNU General Public License as published by\r
6 ; the Free Software Foundation; either version 2 of the License, or\r
7 ; (at your option) any later version.\r
8 ;\r
9 ; This program is distributed in the hope that it will be useful,\r
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12 ; GNU General Public License for more details.\r
13 ;\r
14 ; You should have received a copy of the GNU General Public License along\r
15 ; with this program; if not, write to the Free Software Foundation, Inc.,\r
16 ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
17 \r
18 ; ID_VW_A.ASM\r
19 \r
20 IDEAL\r
21 MODEL   MEDIUM,C\r
22 \r
23 INCLUDE "ID_ASM.EQU"\r
24 \r
25 WAITFORVBL      =       1                       ; setting to 0 causes setscreen and waitvbl\r
26                                                         ; to skip waiting for VBL (for timing things)\r
27 \r
28 ;============================================================================\r
29 \r
30 DATASEG\r
31 \r
32 EXTRN   screenseg                       :WORD\r
33 EXTRN   drawofs                         :WORD\r
34 EXTRN   bufferofs                       :WORD\r
35 EXTRN   displayofs                      :WORD\r
36 EXTRN   drawofs                         :WORD\r
37 EXTRN   panadjust                       :WORD\r
38 EXTRN   ylookup                         :WORD\r
39 EXTRN   linewidth                       :WORD\r
40 EXTRN   grsegs                          :WORD\r
41 EXTRN   updateptr                       :WORD\r
42 EXTRN   blockstarts                     :WORD   ;offsets from drawofs for each update block\r
43 EXTRN   fontspace                       :WORD\r
44 EXTRN   fontnumber                      :WORD\r
45 \r
46 \r
47 planemask       db      ?\r
48 planenum        db      ?\r
49 screendest      dw      ?\r
50 linedelta       dw      ?\r
51 \r
52 LABEL shiftdata0 WORD\r
53 ;       dw 0\r
54 \r
55 if 1\r
56         dw     0,    1,    2,    3,    4,    5,    6,    7,    8,    9,   10,   11,   12,   13\r
57         dw    14,   15,   16,   17,   18,   19,   20,   21,   22,   23,   24,   25,   26,   27\r
58         dw    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,   38,   39,   40,   41\r
59         dw    42,   43,   44,   45,   46,   47,   48,   49,   50,   51,   52,   53,   54,   55\r
60         dw    56,   57,   58,   59,   60,   61,   62,   63,   64,   65,   66,   67,   68,   69\r
61         dw    70,   71,   72,   73,   74,   75,   76,   77,   78,   79,   80,   81,   82,   83\r
62         dw    84,   85,   86,   87,   88,   89,   90,   91,   92,   93,   94,   95,   96,   97\r
63         dw    98,   99,  100,  101,  102,  103,  104,  105,  106,  107,  108,  109,  110,  111\r
64         dw   112,  113,  114,  115,  116,  117,  118,  119,  120,  121,  122,  123,  124,  125\r
65         dw   126,  127,  128,  129,  130,  131,  132,  133,  134,  135,  136,  137,  138,  139\r
66         dw   140,  141,  142,  143,  144,  145,  146,  147,  148,  149,  150,  151,  152,  153\r
67         dw   154,  155,  156,  157,  158,  159,  160,  161,  162,  163,  164,  165,  166,  167\r
68         dw   168,  169,  170,  171,  172,  173,  174,  175,  176,  177,  178,  179,  180,  181\r
69         dw   182,  183,  184,  185,  186,  187,  188,  189,  190,  191,  192,  193,  194,  195\r
70         dw   196,  197,  198,  199,  200,  201,  202,  203,  204,  205,  206,  207,  208,  209\r
71         dw   210,  211,  212,  213,  214,  215,  216,  217,  218,  219,  220,  221,  222,  223\r
72         dw   224,  225,  226,  227,  228,  229,  230,  231,  232,  233,  234,  235,  236,  237\r
73         dw   238,  239,  240,  241,  242,  243,  244,  245,  246,  247,  248,  249,  250,  251\r
74         dw   252,  253,  254,  255\r
75 endif\r
76 \r
77 LABEL shiftdata1 WORD\r
78 ;       dw 0\r
79 \r
80 if 1\r
81         dw     0,32768,    1,32769,    2,32770,    3,32771,    4,32772,    5,32773,    6,32774\r
82         dw     7,32775,    8,32776,    9,32777,   10,32778,   11,32779,   12,32780,   13,32781\r
83         dw    14,32782,   15,32783,   16,32784,   17,32785,   18,32786,   19,32787,   20,32788\r
84         dw    21,32789,   22,32790,   23,32791,   24,32792,   25,32793,   26,32794,   27,32795\r
85         dw    28,32796,   29,32797,   30,32798,   31,32799,   32,32800,   33,32801,   34,32802\r
86         dw    35,32803,   36,32804,   37,32805,   38,32806,   39,32807,   40,32808,   41,32809\r
87         dw    42,32810,   43,32811,   44,32812,   45,32813,   46,32814,   47,32815,   48,32816\r
88         dw    49,32817,   50,32818,   51,32819,   52,32820,   53,32821,   54,32822,   55,32823\r
89         dw    56,32824,   57,32825,   58,32826,   59,32827,   60,32828,   61,32829,   62,32830\r
90         dw    63,32831,   64,32832,   65,32833,   66,32834,   67,32835,   68,32836,   69,32837\r
91         dw    70,32838,   71,32839,   72,32840,   73,32841,   74,32842,   75,32843,   76,32844\r
92         dw    77,32845,   78,32846,   79,32847,   80,32848,   81,32849,   82,32850,   83,32851\r
93         dw    84,32852,   85,32853,   86,32854,   87,32855,   88,32856,   89,32857,   90,32858\r
94         dw    91,32859,   92,32860,   93,32861,   94,32862,   95,32863,   96,32864,   97,32865\r
95         dw    98,32866,   99,32867,  100,32868,  101,32869,  102,32870,  103,32871,  104,32872\r
96         dw   105,32873,  106,32874,  107,32875,  108,32876,  109,32877,  110,32878,  111,32879\r
97         dw   112,32880,  113,32881,  114,32882,  115,32883,  116,32884,  117,32885,  118,32886\r
98         dw   119,32887,  120,32888,  121,32889,  122,32890,  123,32891,  124,32892,  125,32893\r
99         dw   126,32894,  127,32895\r
100 endif\r
101 \r
102 LABEL shiftdata2 WORD\r
103         dw     0,16384,32768,49152,    1,16385,32769,49153,    2,16386,32770,49154,    3,16387\r
104         dw 32771,49155,    4,16388,32772,49156,    5,16389,32773,49157,    6,16390,32774,49158\r
105         dw     7,16391,32775,49159,    8,16392,32776,49160,    9,16393,32777,49161,   10,16394\r
106         dw 32778,49162,   11,16395,32779,49163,   12,16396,32780,49164,   13,16397,32781,49165\r
107         dw    14,16398,32782,49166,   15,16399,32783,49167,   16,16400,32784,49168,   17,16401\r
108         dw 32785,49169,   18,16402,32786,49170,   19,16403,32787,49171,   20,16404,32788,49172\r
109         dw    21,16405,32789,49173,   22,16406,32790,49174,   23,16407,32791,49175,   24,16408\r
110         dw 32792,49176,   25,16409,32793,49177,   26,16410,32794,49178,   27,16411,32795,49179\r
111         dw    28,16412,32796,49180,   29,16413,32797,49181,   30,16414,32798,49182,   31,16415\r
112         dw 32799,49183,   32,16416,32800,49184,   33,16417,32801,49185,   34,16418,32802,49186\r
113         dw    35,16419,32803,49187,   36,16420,32804,49188,   37,16421,32805,49189,   38,16422\r
114         dw 32806,49190,   39,16423,32807,49191,   40,16424,32808,49192,   41,16425,32809,49193\r
115         dw    42,16426,32810,49194,   43,16427,32811,49195,   44,16428,32812,49196,   45,16429\r
116         dw 32813,49197,   46,16430,32814,49198,   47,16431,32815,49199,   48,16432,32816,49200\r
117         dw    49,16433,32817,49201,   50,16434,32818,49202,   51,16435,32819,49203,   52,16436\r
118         dw 32820,49204,   53,16437,32821,49205,   54,16438,32822,49206,   55,16439,32823,49207\r
119         dw    56,16440,32824,49208,   57,16441,32825,49209,   58,16442,32826,49210,   59,16443\r
120         dw 32827,49211,   60,16444,32828,49212,   61,16445,32829,49213,   62,16446,32830,49214\r
121         dw    63,16447,32831,49215\r
122 \r
123 LABEL shiftdata3 WORD\r
124 ;       dw 0\r
125 \r
126 if 1\r
127         dw     0, 8192,16384,24576,32768,40960,49152,57344,    1, 8193,16385,24577,32769,40961\r
128         dw 49153,57345,    2, 8194,16386,24578,32770,40962,49154,57346,    3, 8195,16387,24579\r
129         dw 32771,40963,49155,57347,    4, 8196,16388,24580,32772,40964,49156,57348,    5, 8197\r
130         dw 16389,24581,32773,40965,49157,57349,    6, 8198,16390,24582,32774,40966,49158,57350\r
131         dw     7, 8199,16391,24583,32775,40967,49159,57351,    8, 8200,16392,24584,32776,40968\r
132         dw 49160,57352,    9, 8201,16393,24585,32777,40969,49161,57353,   10, 8202,16394,24586\r
133         dw 32778,40970,49162,57354,   11, 8203,16395,24587,32779,40971,49163,57355,   12, 8204\r
134         dw 16396,24588,32780,40972,49164,57356,   13, 8205,16397,24589,32781,40973,49165,57357\r
135         dw    14, 8206,16398,24590,32782,40974,49166,57358,   15, 8207,16399,24591,32783,40975\r
136         dw 49167,57359,   16, 8208,16400,24592,32784,40976,49168,57360,   17, 8209,16401,24593\r
137         dw 32785,40977,49169,57361,   18, 8210,16402,24594,32786,40978,49170,57362,   19, 8211\r
138         dw 16403,24595,32787,40979,49171,57363,   20, 8212,16404,24596,32788,40980,49172,57364\r
139         dw    21, 8213,16405,24597,32789,40981,49173,57365,   22, 8214,16406,24598,32790,40982\r
140         dw 49174,57366,   23, 8215,16407,24599,32791,40983,49175,57367,   24, 8216,16408,24600\r
141         dw 32792,40984,49176,57368,   25, 8217,16409,24601,32793,40985,49177,57369,   26, 8218\r
142         dw 16410,24602,32794,40986,49178,57370,   27, 8219,16411,24603,32795,40987,49179,57371\r
143         dw    28, 8220,16412,24604,32796,40988,49180,57372,   29, 8221,16413,24605,32797,40989\r
144         dw 49181,57373,   30, 8222,16414,24606,32798,40990,49182,57374,   31, 8223,16415,24607\r
145         dw 32799,40991,49183,57375\r
146 endif\r
147 \r
148 LABEL shiftdata4 WORD\r
149         dw     0, 4096, 8192,12288,16384,20480,24576,28672,32768,36864,40960,45056,49152,53248\r
150         dw 57344,61440,    1, 4097, 8193,12289,16385,20481,24577,28673,32769,36865,40961,45057\r
151         dw 49153,53249,57345,61441,    2, 4098, 8194,12290,16386,20482,24578,28674,32770,36866\r
152         dw 40962,45058,49154,53250,57346,61442,    3, 4099, 8195,12291,16387,20483,24579,28675\r
153         dw 32771,36867,40963,45059,49155,53251,57347,61443,    4, 4100, 8196,12292,16388,20484\r
154         dw 24580,28676,32772,36868,40964,45060,49156,53252,57348,61444,    5, 4101, 8197,12293\r
155         dw 16389,20485,24581,28677,32773,36869,40965,45061,49157,53253,57349,61445,    6, 4102\r
156         dw  8198,12294,16390,20486,24582,28678,32774,36870,40966,45062,49158,53254,57350,61446\r
157         dw     7, 4103, 8199,12295,16391,20487,24583,28679,32775,36871,40967,45063,49159,53255\r
158         dw 57351,61447,    8, 4104, 8200,12296,16392,20488,24584,28680,32776,36872,40968,45064\r
159         dw 49160,53256,57352,61448,    9, 4105, 8201,12297,16393,20489,24585,28681,32777,36873\r
160         dw 40969,45065,49161,53257,57353,61449,   10, 4106, 8202,12298,16394,20490,24586,28682\r
161         dw 32778,36874,40970,45066,49162,53258,57354,61450,   11, 4107, 8203,12299,16395,20491\r
162         dw 24587,28683,32779,36875,40971,45067,49163,53259,57355,61451,   12, 4108, 8204,12300\r
163         dw 16396,20492,24588,28684,32780,36876,40972,45068,49164,53260,57356,61452,   13, 4109\r
164         dw  8205,12301,16397,20493,24589,28685,32781,36877,40973,45069,49165,53261,57357,61453\r
165         dw    14, 4110, 8206,12302,16398,20494,24590,28686,32782,36878,40974,45070,49166,53262\r
166         dw 57358,61454,   15, 4111, 8207,12303,16399,20495,24591,28687,32783,36879,40975,45071\r
167         dw 49167,53263,57359,61455\r
168 \r
169 LABEL shiftdata5 WORD\r
170 ;       dw 0\r
171 \r
172 if 1\r
173         dw     0, 2048, 4096, 6144, 8192,10240,12288,14336,16384,18432,20480,22528,24576,26624\r
174         dw 28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152,51200,53248,55296\r
175         dw 57344,59392,61440,63488,    1, 2049, 4097, 6145, 8193,10241,12289,14337,16385,18433\r
176         dw 20481,22529,24577,26625,28673,30721,32769,34817,36865,38913,40961,43009,45057,47105\r
177         dw 49153,51201,53249,55297,57345,59393,61441,63489,    2, 2050, 4098, 6146, 8194,10242\r
178         dw 12290,14338,16386,18434,20482,22530,24578,26626,28674,30722,32770,34818,36866,38914\r
179         dw 40962,43010,45058,47106,49154,51202,53250,55298,57346,59394,61442,63490,    3, 2051\r
180         dw  4099, 6147, 8195,10243,12291,14339,16387,18435,20483,22531,24579,26627,28675,30723\r
181         dw 32771,34819,36867,38915,40963,43011,45059,47107,49155,51203,53251,55299,57347,59395\r
182         dw 61443,63491,    4, 2052, 4100, 6148, 8196,10244,12292,14340,16388,18436,20484,22532\r
183         dw 24580,26628,28676,30724,32772,34820,36868,38916,40964,43012,45060,47108,49156,51204\r
184         dw 53252,55300,57348,59396,61444,63492,    5, 2053, 4101, 6149, 8197,10245,12293,14341\r
185         dw 16389,18437,20485,22533,24581,26629,28677,30725,32773,34821,36869,38917,40965,43013\r
186         dw 45061,47109,49157,51205,53253,55301,57349,59397,61445,63493,    6, 2054, 4102, 6150\r
187         dw  8198,10246,12294,14342,16390,18438,20486,22534,24582,26630,28678,30726,32774,34822\r
188         dw 36870,38918,40966,43014,45062,47110,49158,51206,53254,55302,57350,59398,61446,63494\r
189         dw     7, 2055, 4103, 6151, 8199,10247,12295,14343,16391,18439,20487,22535,24583,26631\r
190         dw 28679,30727,32775,34823,36871,38919,40967,43015,45063,47111,49159,51207,53255,55303\r
191         dw 57351,59399,61447,63495\r
192 endif\r
193 \r
194 LABEL shiftdata6 WORD\r
195         dw     0, 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216,10240,11264,12288,13312\r
196         dw 14336,15360,16384,17408,18432,19456,20480,21504,22528,23552,24576,25600,26624,27648\r
197         dw 28672,29696,30720,31744,32768,33792,34816,35840,36864,37888,38912,39936,40960,41984\r
198         dw 43008,44032,45056,46080,47104,48128,49152,50176,51200,52224,53248,54272,55296,56320\r
199         dw 57344,58368,59392,60416,61440,62464,63488,64512,    1, 1025, 2049, 3073, 4097, 5121\r
200         dw  6145, 7169, 8193, 9217,10241,11265,12289,13313,14337,15361,16385,17409,18433,19457\r
201         dw 20481,21505,22529,23553,24577,25601,26625,27649,28673,29697,30721,31745,32769,33793\r
202         dw 34817,35841,36865,37889,38913,39937,40961,41985,43009,44033,45057,46081,47105,48129\r
203         dw 49153,50177,51201,52225,53249,54273,55297,56321,57345,58369,59393,60417,61441,62465\r
204         dw 63489,64513,    2, 1026, 2050, 3074, 4098, 5122, 6146, 7170, 8194, 9218,10242,11266\r
205         dw 12290,13314,14338,15362,16386,17410,18434,19458,20482,21506,22530,23554,24578,25602\r
206         dw 26626,27650,28674,29698,30722,31746,32770,33794,34818,35842,36866,37890,38914,39938\r
207         dw 40962,41986,43010,44034,45058,46082,47106,48130,49154,50178,51202,52226,53250,54274\r
208         dw 55298,56322,57346,58370,59394,60418,61442,62466,63490,64514,    3, 1027, 2051, 3075\r
209         dw  4099, 5123, 6147, 7171, 8195, 9219,10243,11267,12291,13315,14339,15363,16387,17411\r
210         dw 18435,19459,20483,21507,22531,23555,24579,25603,26627,27651,28675,29699,30723,31747\r
211         dw 32771,33795,34819,35843,36867,37891,38915,39939,40963,41987,43011,44035,45059,46083\r
212         dw 47107,48131,49155,50179,51203,52227,53251,54275,55299,56323,57347,58371,59395,60419\r
213         dw 61443,62467,63491,64515\r
214 \r
215 LABEL shiftdata7 WORD\r
216 ;       dw 0\r
217 \r
218 if 1\r
219         dw     0,  512, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 4608, 5120, 5632, 6144, 6656\r
220         dw  7168, 7680, 8192, 8704, 9216, 9728,10240,10752,11264,11776,12288,12800,13312,13824\r
221         dw 14336,14848,15360,15872,16384,16896,17408,17920,18432,18944,19456,19968,20480,20992\r
222         dw 21504,22016,22528,23040,23552,24064,24576,25088,25600,26112,26624,27136,27648,28160\r
223         dw 28672,29184,29696,30208,30720,31232,31744,32256,32768,33280,33792,34304,34816,35328\r
224         dw 35840,36352,36864,37376,37888,38400,38912,39424,39936,40448,40960,41472,41984,42496\r
225         dw 43008,43520,44032,44544,45056,45568,46080,46592,47104,47616,48128,48640,49152,49664\r
226         dw 50176,50688,51200,51712,52224,52736,53248,53760,54272,54784,55296,55808,56320,56832\r
227         dw 57344,57856,58368,58880,59392,59904,60416,60928,61440,61952,62464,62976,63488,64000\r
228         dw 64512,65024,    1,  513, 1025, 1537, 2049, 2561, 3073, 3585, 4097, 4609, 5121, 5633\r
229         dw  6145, 6657, 7169, 7681, 8193, 8705, 9217, 9729,10241,10753,11265,11777,12289,12801\r
230         dw 13313,13825,14337,14849,15361,15873,16385,16897,17409,17921,18433,18945,19457,19969\r
231         dw 20481,20993,21505,22017,22529,23041,23553,24065,24577,25089,25601,26113,26625,27137\r
232         dw 27649,28161,28673,29185,29697,30209,30721,31233,31745,32257,32769,33281,33793,34305\r
233         dw 34817,35329,35841,36353,36865,37377,37889,38401,38913,39425,39937,40449,40961,41473\r
234         dw 41985,42497,43009,43521,44033,44545,45057,45569,46081,46593,47105,47617,48129,48641\r
235         dw 49153,49665,50177,50689,51201,51713,52225,52737,53249,53761,54273,54785,55297,55809\r
236         dw 56321,56833,57345,57857,58369,58881,59393,59905,60417,60929,61441,61953,62465,62977\r
237         dw 63489,64001,64513,65025\r
238 endif\r
239 \r
240 shifttabletable dw      shiftdata0,shiftdata1,shiftdata2,shiftdata3\r
241                 dw      shiftdata4,shiftdata5,shiftdata6,shiftdata7\r
242 \r
243 PUBLIC  shifttabletable\r
244 \r
245 \r
246 ;============================================================================\r
247 \r
248 CODESEG\r
249 \r
250 IFE GRMODE-CGAGR\r
251 INCLUDE "ID_VW_AC.ASM"\r
252 ENDIF\r
253 \r
254 IFE GRMODE-EGAGR\r
255 INCLUDE "ID_VW_AE.ASM"\r
256 ENDIF\r
257 \r
258 IFE GRMODE-VGAGR\r
259 INCLUDE "ID_VW_AV.ASM"\r
260 ENDIF\r
261 \r
262 ;============================================================================\r
263 ;\r
264 ;                           MISC VIDEO ROUTINES\r
265 ;\r
266 ;============================================================================\r
267 \r
268 ;========\r
269 ;\r
270 ; VW_WaitVBL (int number)\r
271 ;\r
272 ;========\r
273 \r
274 PROC    VW_WaitVBL number:WORD\r
275 PUBLIC  VW_WaitVBL\r
276 \r
277 if WAITFORVBL                           ; skip wait if profiling\r
278 \r
279         mov     dx,STATUS_REGISTER_1\r
280 \r
281         mov     cx,[number]\r
282 \r
283 waitvbl1:\r
284         in      al,dx\r
285         test    al,00001000b    ;look for vbl\r
286         jnz     waitvbl1\r
287 \r
288 waitvbl2:\r
289         in      al,dx\r
290         test    al,00001000b    ;look for vbl\r
291         jz      waitvbl2\r
292 \r
293         loop    waitvbl1\r
294 \r
295 endif\r
296 \r
297         ret\r
298 \r
299 ENDP\r
300 \r
301 \r
302 ;===========================================================================\r
303 \r
304 \r
305         MASM\r
306 ;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\r
307 ;\r
308 ; Name: VW_VideoID\r
309 ;\r
310 ; Function:     Detects the presence of various video subsystems\r
311 ;\r
312 ; int VideoID;\r
313 ;\r
314 ; Subsystem ID values:\r
315 ;        0  = (none)\r
316 ;        1  = MDA\r
317 ;        2  = CGA\r
318 ;        3  = EGA\r
319 ;        4  = MCGA\r
320 ;        5  = VGA\r
321 ;       80h = HGC\r
322 ;       81h = HGC+\r
323 ;       82h = Hercules InColor\r
324 ;\r
325 ;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\r
326 \r
327 ;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\r
328 ;\r
329 ; Equates\r
330 ;\r
331 ;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\r
332 VIDstruct       STRUC           ; corresponds to C data structure\r
333 \r
334 Video0Type      DB      ?       ; first subsystem type\r
335 Display0Type    DB      ?       ; display attached to first subsystem\r
336 \r
337 Video1Type      DB      ?       ; second subsystem type\r
338 Display1Type    DB      ?       ; display attached to second subsystem\r
339 \r
340 VIDstruct       ENDS\r
341 \r
342 \r
343 Device0 EQU     word ptr Video0Type[di]\r
344 Device1 EQU     word ptr Video1Type[di]\r
345 \r
346 \r
347 MDA     EQU     1       ; subsystem types\r
348 CGA     EQU     2\r
349 EGA     EQU     3\r
350 MCGA    EQU     4\r
351 VGA     EQU     5\r
352 HGC     EQU     80h\r
353 HGCPlus EQU     81h\r
354 InColor EQU     82h\r
355 \r
356 MDADisplay      EQU     1       ; display types\r
357 CGADisplay      EQU     2\r
358 EGAColorDisplay EQU     3\r
359 PS2MonoDisplay  EQU     4\r
360 PS2ColorDisplay EQU     5\r
361 \r
362 TRUE    EQU     1\r
363 FALSE   EQU     0\r
364 \r
365 ;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\r
366 ;\r
367 ; Program\r
368 ;\r
369 ;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\r
370 \r
371 Results VIDstruct <>    ;results go here!\r
372 \r
373 EGADisplays     DB      CGADisplay      ; 0000b, 0001b  (EGA switch values)\r
374         DB      EGAColorDisplay ; 0010b, 0011b\r
375         DB      MDADisplay      ; 0100b, 0101b\r
376         DB      CGADisplay      ; 0110b, 0111b\r
377         DB      EGAColorDisplay ; 1000b, 1001b\r
378         DB      MDADisplay      ; 1010b, 1011b\r
379 \r
380 DCCtable        DB      0,0     ; translate table for INT 10h func 1Ah\r
381         DB      MDA,MDADisplay\r
382         DB      CGA,CGADisplay\r
383         DB      0,0\r
384         DB      EGA,EGAColorDisplay\r
385         DB      EGA,MDADisplay\r
386         DB      0,0\r
387         DB      VGA,PS2MonoDisplay\r
388         DB      VGA,PS2ColorDisplay\r
389         DB      0,0\r
390         DB      MCGA,EGAColorDisplay\r
391         DB      MCGA,PS2MonoDisplay\r
392         DB      MCGA,PS2ColorDisplay\r
393 \r
394 TestSequence    DB      TRUE    ; this list of flags and addresses\r
395         DW      FindPS2 ;  determines the order in which this\r
396                         ;  program looks for the various\r
397 EGAflag DB      ?       ;  subsystems\r
398         DW      FindEGA\r
399 \r
400 CGAflag DB      ?\r
401         DW      FindCGA\r
402 \r
403 Monoflag        DB      ?\r
404         DW      FindMono\r
405 \r
406 NumberOfTests   EQU     ($-TestSequence)/3\r
407 \r
408 \r
409 PUBLIC  VW_VideoID\r
410 VW_VideoID      PROC\r
411 \r
412         push    bp      ; preserve caller registers\r
413         mov     bp,sp\r
414         push    ds\r
415         push    si\r
416         push    di\r
417 \r
418         push    cs\r
419         pop     ds\r
420         ASSUME  DS:@Code\r
421 \r
422 ; initialize the data structure that will contain the results\r
423 \r
424         lea     di,Results      ; DS:DI -> start of data structure\r
425 \r
426         mov     Device0,0       ; zero these variables\r
427         mov     Device1,0\r
428 \r
429 ; look for the various subsystems using the subroutines whose addresses are\r
430 ; tabulated in TestSequence; each subroutine sets flags in TestSequence\r
431 ; to indicate whether subsequent subroutines need to be called\r
432 \r
433         mov     byte ptr CGAflag,TRUE\r
434         mov     byte ptr EGAflag,TRUE\r
435         mov     byte ptr Monoflag,TRUE\r
436 \r
437         mov     cx,NumberOfTests\r
438         mov     si,offset TestSequence\r
439 \r
440 @@L01:  lodsb           ; AL := flag\r
441         test    al,al\r
442         lodsw           ; AX := subroutine address\r
443         jz      @@L02   ; skip subroutine if flag is false\r
444 \r
445         push    si\r
446         push    cx\r
447         call    ax      ; call subroutine to detect subsystem\r
448         pop     cx\r
449         pop     si\r
450 \r
451 @@L02:  loop    @@L01\r
452 \r
453 ; determine which subsystem is active\r
454 \r
455         call    FindActive\r
456 \r
457         mov     al,Results.Video0Type\r
458         mov     ah,0    ; was:  Results.Display0Type\r
459 \r
460         pop     di      ; restore caller registers and return\r
461         pop     si\r
462         pop     ds\r
463         mov     sp,bp\r
464         pop     bp\r
465         ret\r
466 \r
467 VW_VideoID      ENDP\r
468 \r
469 \r
470 ;\r
471 ; FindPS2\r
472 ;\r
473 ; This subroutine uses INT 10H function 1Ah to determine the video BIOS\r
474 ; Display Combination Code (DCC) for each video subsystem present.\r
475 ;\r
476 \r
477 FindPS2 PROC    near\r
478 \r
479         mov     ax,1A00h\r
480         int     10h     ; call video BIOS for info\r
481 \r
482         cmp     al,1Ah\r
483         jne     @@L13   ; exit if function not supported (i.e.,\r
484                         ;  no MCGA or VGA in system)\r
485 \r
486 ; convert BIOS DCCs into specific subsystems & displays\r
487 \r
488         mov     cx,bx\r
489         xor     bh,bh   ; BX := DCC for active subsystem\r
490 \r
491         or      ch,ch\r
492         jz      @@L11   ; jump if only one subsystem present\r
493 \r
494         mov     bl,ch   ; BX := inactive DCC\r
495         add     bx,bx\r
496         mov     ax,[bx+offset DCCtable]\r
497 \r
498         mov     Device1,ax\r
499 \r
500         mov     bl,cl\r
501         xor     bh,bh   ; BX := active DCC\r
502 \r
503 @@L11:  add     bx,bx\r
504         mov     ax,[bx+offset DCCtable]\r
505 \r
506         mov     Device0,ax\r
507 \r
508 ; reset flags for subsystems that have been ruled out\r
509 \r
510         mov     byte ptr CGAflag,FALSE\r
511         mov     byte ptr EGAflag,FALSE\r
512         mov     byte ptr Monoflag,FALSE\r
513 \r
514         lea     bx,Video0Type[di]  ; if the BIOS reported an MDA ...\r
515         cmp     byte ptr [bx],MDA\r
516         je      @@L12\r
517 \r
518         lea     bx,Video1Type[di]\r
519         cmp     byte ptr [bx],MDA\r
520         jne     @@L13\r
521 \r
522 @@L12:  mov     word ptr [bx],0    ; ... Hercules can't be ruled out\r
523         mov     byte ptr Monoflag,TRUE\r
524 \r
525 @@L13:  ret\r
526 \r
527 FindPS2 ENDP\r
528 \r
529 \r
530 ;\r
531 ; FindEGA\r
532 ;\r
533 ; Look for an EGA.  This is done by making a call to an EGA BIOS function\r
534 ;  which doesn't exist in the default (MDA, CGA) BIOS.\r
535 \r
536 FindEGA PROC    near    ; Caller:       AH = flags\r
537                         ; Returns:      AH = flags\r
538                         ;               Video0Type and\r
539                         ;                Display0Type updated\r
540 \r
541         mov     bl,10h  ; BL := 10h (return EGA info)\r
542         mov     ah,12h  ; AH := INT 10H function number\r
543         int     10h     ; call EGA BIOS for info\r
544                         ; if EGA BIOS is present,\r
545                         ;  BL <> 10H\r
546                         ;  CL = switch setting\r
547         cmp     bl,10h\r
548         je      @@L22   ; jump if EGA BIOS not present\r
549 \r
550         mov     al,cl\r
551         shr     al,1    ; AL := switches/2\r
552         mov     bx,offset EGADisplays\r
553         xlat            ; determine display type from switches\r
554         mov     ah,al   ; AH := display type\r
555         mov     al,EGA  ; AL := subystem type\r
556         call    FoundDevice\r
557 \r
558         cmp     ah,MDADisplay\r
559         je      @@L21   ; jump if EGA has a monochrome display\r
560 \r
561         mov     CGAflag,FALSE   ; no CGA if EGA has color display\r
562         jmp     short @@L22\r
563 \r
564 @@L21:  mov     Monoflag,FALSE  ; EGA has a mono display, so MDA and\r
565                         ;  Hercules are ruled out\r
566 @@L22:  ret\r
567 \r
568 FindEGA ENDP\r
569 \r
570 ;\r
571 ; FindCGA\r
572 ;\r
573 ; This is done by looking for the CGA's 6845 CRTC at I/O port 3D4H.\r
574 ;\r
575 FindCGA PROC    near    ; Returns:      VIDstruct updated\r
576 \r
577         mov     dx,3D4h ; DX := CRTC address port\r
578         call    Find6845\r
579         jc      @@L31   ; jump if not present\r
580 \r
581         mov     al,CGA\r
582         mov     ah,CGADisplay\r
583         call    FoundDevice\r
584 \r
585 @@L31:  ret\r
586 \r
587 FindCGA ENDP\r
588 \r
589 ;\r
590 ; FindMono\r
591 ;\r
592 ; This is done by looking for the MDA's 6845 CRTC at I/O port 3B4H.  If\r
593 ; a 6845 is found, the subroutine distinguishes between an MDA\r
594 ; and a Hercules adapter by monitoring bit 7 of the CRT Status byte.\r
595 ; This bit changes on Hercules adapters but does not change on an MDA.\r
596 ;\r
597 ; The various Hercules adapters are identified by bits 4 through 6 of\r
598 ; the CRT Status value:\r
599 ;\r
600 ; 000b = HGC\r
601 ; 001b = HGC+\r
602 ; 101b = InColor card\r
603 ;\r
604 \r
605 FindMono        PROC    near    ; Returns:      VIDstruct updated\r
606 \r
607         mov     dx,3B4h ; DX := CRTC address port\r
608         call    Find6845\r
609         jc      @@L44   ; jump if not present\r
610 \r
611         mov     dl,0BAh ; DX := 3BAh (status port)\r
612         in      al,dx\r
613         and     al,80h\r
614         mov     ah,al   ; AH := bit 7 (vertical sync on HGC)\r
615 \r
616         mov     cx,8000h        ; do this 32768 times\r
617 @@L41:  in      al,dx\r
618         and     al,80h  ; isolate bit 7\r
619         cmp     ah,al\r
620         loope   @@L41   ; wait for bit 7 to change\r
621         jne     @@L42   ; if bit 7 changed, it's a Hercules\r
622 \r
623         mov     al,MDA  ; if bit 7 didn't change, it's an MDA\r
624         mov     ah,MDADisplay\r
625         call    FoundDevice\r
626         jmp     short @@L44\r
627 \r
628 @@L42:  in      al,dx\r
629         mov     dl,al   ; DL := value from status port\r
630         and     dl,01110000b    ; mask bits 4 thru 6\r
631 \r
632         mov     ah,MDADisplay   ; assume it's a monochrome display\r
633 \r
634         mov     al,HGCPlus      ; look for an HGC+\r
635         cmp     dl,00010000b\r
636         je      @@L43   ; jump if it's an HGC+\r
637 \r
638         mov     al,HGC  ; look for an InColor card or HGC\r
639         cmp     dl,01010000b\r
640         jne     @@L43   ; jump if it's not an InColor card\r
641 \r
642         mov     al,InColor      ; it's an InColor card\r
643         mov     ah,EGAColorDisplay\r
644 \r
645 @@L43:  call    FoundDevice\r
646 \r
647 @@L44:  ret\r
648 \r
649 FindMono        ENDP\r
650 \r
651 ;\r
652 ; Find6845\r
653 ;\r
654 ; This routine detects the presence of the CRTC on a MDA, CGA or HGC.\r
655 ; The technique is to write and read register 0Fh of the chip (cursor\r
656 ; low).  If the same value is read as written, assume the chip is\r
657 ; present at the specified port addr.\r
658 ;\r
659 \r
660 Find6845        PROC    near    ; Caller:  DX = port addr\r
661                         ; Returns: cf set if not present\r
662         mov     al,0Fh\r
663         out     dx,al   ; select 6845 reg 0Fh (Cursor Low)\r
664         inc     dx\r
665         in      al,dx   ; AL := current Cursor Low value\r
666         mov     ah,al   ; preserve in AH\r
667         mov     al,66h  ; AL := arbitrary value\r
668         out     dx,al   ; try to write to 6845\r
669 \r
670         mov     cx,100h\r
671 @@L51:  loop    @@L51   ; wait for 6845 to respond\r
672 \r
673         in      al,dx\r
674         xchg    ah,al   ; AH := returned value\r
675                         ; AL := original value\r
676         out     dx,al   ; restore original value\r
677 \r
678         cmp     ah,66h  ; test whether 6845 responded\r
679         je      @@L52   ; jump if it did (cf is reset)\r
680 \r
681         stc             ; set carry flag if no 6845 present\r
682 \r
683 @@L52:  ret\r
684 \r
685 Find6845        ENDP\r
686 \r
687 \r
688 ;\r
689 ; FindActive\r
690 ;\r
691 ; This subroutine stores the currently active device as Device0.  The\r
692 ; current video mode determines which subsystem is active.\r
693 ;\r
694 \r
695 FindActive      PROC    near\r
696 \r
697         cmp     word ptr Device1,0\r
698         je      @@L63   ; exit if only one subsystem\r
699 \r
700         cmp     Video0Type[di],4        ; exit if MCGA or VGA present\r
701         jge     @@L63   ;  (INT 10H function 1AH\r
702         cmp     Video1Type[di],4        ;  already did the work)\r
703         jge     @@L63\r
704 \r
705         mov     ah,0Fh\r
706         int     10h     ; AL := current BIOS video mode\r
707 \r
708         and     al,7\r
709         cmp     al,7    ; jump if monochrome\r
710         je      @@L61   ;  (mode 7 or 0Fh)\r
711 \r
712         cmp     Display0Type[di],MDADisplay\r
713         jne     @@L63   ; exit if Display0 is color\r
714         jmp     short @@L62\r
715 \r
716 @@L61:  cmp     Display0Type[di],MDADisplay\r
717         je      @@L63   ; exit if Display0 is monochrome\r
718 \r
719 @@L62:  mov     ax,Device0      ; make Device0 currently active\r
720         xchg    ax,Device1\r
721         mov     Device0,ax\r
722 \r
723 @@L63:  ret\r
724 \r
725 FindActive      ENDP\r
726 \r
727 \r
728 ;\r
729 ; FoundDevice\r
730 ;\r
731 ; This routine updates the list of subsystems.\r
732 ;\r
733 \r
734 FoundDevice     PROC    near    ; Caller:    AH = display #\r
735                         ;            AL = subsystem #\r
736                         ; Destroys:  BX\r
737         lea     bx,Video0Type[di]\r
738         cmp     byte ptr [bx],0\r
739         je      @@L71   ; jump if 1st subsystem\r
740 \r
741         lea     bx,Video1Type[di]       ; must be 2nd subsystem\r
742 \r
743 @@L71:  mov     [bx],ax ; update list entry\r
744         ret\r
745 \r
746 FoundDevice     ENDP\r
747 \r
748 IDEAL\r
749 \r
750 \r
751 \r
752 END\r