]> 4ch.mooo.com Git - 16.git/blob - 16/tweak16/DETECT.CPP
cleaned up the repo from debugging watcom2 ^^
[16.git] / 16 / tweak16 / DETECT.CPP
1 /*\r
2  *      Mode detection:\r
3  *      ---------------\r
4  *      Currently incompatible with CGA and Hercules modes.\r
5  *              200-line CGA modes are detected as 100-line.\r
6  *              640x200x2 is detected as 16-color.\r
7  *              Hercules not supported at all.\r
8  *      Monochrome EGA/VGA modes are also *not* supported, due to use of\r
9  *              different port addresses.\r
10  *\r
11  *      Variables of interest:\r
12  *              hPixels, vPixels - the actual resolution of the mode, in characters\r
13  *                      in text modes, in pixels in graphics modes.\r
14  *              adrOffset - the number of addressable bytes between two vertically\r
15  *                      adjacent pixels, or words between two vertically adjacent\r
16  *                      characters in text mode.\r
17  *\r
18  */\r
19 \r
20 #include "detect.hpp"\r
21 #include "screen.hpp"\r
22 #include <dos.h>\r
23 #include <conio.h>\r
24 \r
25 \r
26 \r
27 void ModeInfo::detectFrom(RegisterTable &regTable)\r
28         {\r
29         Register *GCMode = regTable.getRegister(GRACON_ADDR, 0x05);\r
30         Register *GCMisc = regTable.getRegister(GRACON_ADDR, 0x06);\r
31         Register *ACMode = regTable.getRegister(ATTRCON_ADDR, 0x10);\r
32         Register *CRTChde = regTable.getRegister(CRTC_ADDR, 0x01);\r
33         Register *CRTCoflo = regTable.getRegister(CRTC_ADDR, 0x07);\r
34         Register *CRTCscan = regTable.getRegister(CRTC_ADDR, 0x09);\r
35         Register *CRTCvde = regTable.getRegister(CRTC_ADDR, 0x12);\r
36         Register *CRTCoffs = regTable.getRegister(CRTC_ADDR, 0x13);\r
37         Register *CRTCmode = regTable.getRegister(CRTC_ADDR, 0x17);\r
38         Register *SEQmmode = regTable.getRegister(SEQ_ADDR, 0x04);\r
39 \r
40         int temp;\r
41         switch ((*GCMode)(5,2))\r
42                 {\r
43                 case 0:\r
44                         colors = COLOR16;               // might also be COLOR2 !!!\r
45                         hPixelsPerClock = 8;\r
46                         break;\r
47                 case 1:\r
48                         colors = COLOR4;\r
49                         hPixelsPerClock = 16;\r
50                         break;\r
51                 case 2:\r
52                         colors = COLOR256;\r
53                         hPixelsPerClock = 4;\r
54                         break;\r
55                 }\r
56 \r
57         temp = (**GCMisc & 1 != 0);\r
58         if (temp == (**ACMode & 1 != 0))\r
59                 alphaGraph = temp ? GRAPHICS : ALPHA;\r
60         else\r
61                 alphaGraph = AG_CONFLICT;\r
62 \r
63         if (alphaGraph == ALPHA)\r
64                 hPixelsPerClock = 1;\r
65 \r
66         chain4 = (*SEQmmode)(3,1);\r
67         countBy2 = (*CRTCmode)(3,1);\r
68         adrOffset = **CRTCoffs * 2 * (countBy2+1);\r
69 \r
70         hClocks = **CRTChde + 1;\r
71         vClocks =\r
72                 (**CRTCvde | ((*CRTCoflo)(1,1) << 8) | ((*CRTCoflo)(6,1) << 9)) + 1;\r
73 \r
74         xres = hClocks * hPixelsPerClock;\r
75         vxresBytes = vxres = adrOffset * hPixelsPerClock;\r
76 \r
77         if (alphaGraph == ALPHA)\r
78                 vxresBytes *= 2;\r
79         else\r
80                 if (alphaGraph == GRAPHICS)\r
81                         if (colors == COLOR16)\r
82                                 vxresBytes /= 8;\r
83                         else\r
84                                 if (colors == COLOR256 && !chain4)\r
85                                         vxresBytes /= 4;\r
86 \r
87         lineClocks = (*CRTCscan)(0,4) + 1;\r
88         if ((*CRTCscan)(7,1) << 5)\r
89                 lineClocks *= 2;\r
90         yres = vClocks / lineClocks;\r
91         spareClocks = vClocks % lineClocks;\r
92         vyres = (alphaGraph == GRAPHICS ? 65536L : 32768L) / vxresBytes;\r
93     xpages = float(vxres)/xres;\r
94         ypages = float(vyres)/yres;\r
95         }\r
96 \r
97 \r
98 GraphicsAPI *ModeInfo::getGraphicsAPI()\r
99         {\r
100         if (alphaGraph == GRAPHICS)\r
101                 switch(colors)\r
102                         {\r
103                         case COLOR16:\r
104                                 return new Planar16(xres, yres, vxres);\r
105                         case COLOR256:\r
106                                 if (chain4)\r
107                                         return new Chained256(xres, yres, vxres);\r
108                                 else\r
109                                         return new Unchained256(xres, yres, vxres);\r
110                         }\r
111         return 0;\r
112         }\r
113 \r
114 void ModeInfo::show()\r
115         {\r
116         window(editWidth/2+2, editHeight-18, editWidth, editHeight-7);\r
117         clrscr();\r
118         textattr(INFO_COLOR);\r
119         cprintf("This seems to be a %d-color\n\r"\r
120                         "%s mode.\n\r\n\r"\r
121                         "Physical resolution: %d x %d\n\r"\r
122                         "Virtual resolution:  %d x %d\n\r\n\r"\r
123                         "Page resolution:     %3.1f x %3.1f",\r
124                         colors,\r
125                         alphaGraph==ALPHA ? "text" :\r
126                                 alphaGraph==GRAPHICS ? (chain4 ? "linear graphics" :\r
127                                                                                                  "planar graphics") :\r
128                                                                            "graph/text conflict",\r
129                         xres, yres,\r
130                         vxres, vyres,\r
131                         xpages, ypages\r
132                         );\r
133         window(1,1,editWidth,editHeight);\r
134         }\r
135 \r