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
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
20 #include "detect.hpp"
\r
21 #include "screen.hpp"
\r
27 void ModeInfo::detectFrom(RegisterTable ®Table)
\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
41 switch ((*GCMode)(5,2))
\r
44 colors = COLOR16; // might also be COLOR2 !!!
\r
45 hPixelsPerClock = 8;
\r
49 hPixelsPerClock = 16;
\r
53 hPixelsPerClock = 4;
\r
57 temp = (**GCMisc & 1 != 0);
\r
58 if (temp == (**ACMode & 1 != 0))
\r
59 alphaGraph = temp ? GRAPHICS : ALPHA;
\r
61 alphaGraph = AG_CONFLICT;
\r
63 if (alphaGraph == ALPHA)
\r
64 hPixelsPerClock = 1;
\r
66 chain4 = (*SEQmmode)(3,1);
\r
67 countBy2 = (*CRTCmode)(3,1);
\r
68 adrOffset = **CRTCoffs * 2 * (countBy2+1);
\r
70 hClocks = **CRTChde + 1;
\r
72 (**CRTCvde | ((*CRTCoflo)(1,1) << 8) | ((*CRTCoflo)(6,1) << 9)) + 1;
\r
74 xres = hClocks * hPixelsPerClock;
\r
75 vxresBytes = vxres = adrOffset * hPixelsPerClock;
\r
77 if (alphaGraph == ALPHA)
\r
80 if (alphaGraph == GRAPHICS)
\r
81 if (colors == COLOR16)
\r
84 if (colors == COLOR256 && !chain4)
\r
87 lineClocks = (*CRTCscan)(0,4) + 1;
\r
88 if ((*CRTCscan)(7,1) << 5)
\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
98 GraphicsAPI *ModeInfo::getGraphicsAPI()
\r
100 if (alphaGraph == GRAPHICS)
\r
104 return new Planar16(xres, yres, vxres);
\r
107 return new Chained256(xres, yres, vxres);
\r
109 return new Unchained256(xres, yres, vxres);
\r
114 void ModeInfo::show()
\r
116 window(editWidth/2+2, editHeight-18, editWidth, editHeight-7);
\r
118 textattr(INFO_COLOR);
\r
119 cprintf("This seems to be a %d-color\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
125 alphaGraph==ALPHA ? "text" :
\r
126 alphaGraph==GRAPHICS ? (chain4 ? "linear graphics" :
\r
127 "planar graphics") :
\r
128 "graph/text conflict",
\r
133 window(1,1,editWidth,editHeight);
\r