1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
/*
* Under AmigaOS: gcc -noixemul GetVideoMode.c -o GetVideoMode
*
* Usage:
*
* GetVideoMode
* GetVideoMode NONAMEOK
* GetVideoMode <hexmodeid> ...
*/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <graphics/displayinfo.h>
#include <exec/execbase.h>
#include <string.h>
#include <stdio.h>
#define LOW 0
#define HIGH 1
struct VideoMode {
STRPTR name;
struct {
ULONG xres;
ULONG yres;
ULONG vxres;
ULONG vyres;
ULONG depth;
} geometry;
struct {
ULONG pixclock;
ULONG left;
ULONG right;
ULONG upper;
ULONG lower;
ULONG hslen;
ULONG vslen;
} timings;
struct {
ULONG hsync : 1;
ULONG vsync : 1;
ULONG csync : 1;
ULONG gsync : 1;
ULONG extsync : 1;
ULONG bcast : 1;
ULONG laced : 1;
ULONG dblscan : 1;
} options;
};
struct DisplayInfo DisplayInfo;
struct DimensionInfo DimensionInfo;
struct MonitorInfo MonitorInfo;
struct NameInfo NameInfo;
struct VideoMode VideoMode;
void GetVideoMode(ULONG id, BOOL nonameok)
{
ULONG colorclock_to_dotclock;
ULONG diwstrt_h, diwstop_h, diwstrt_v, diwstop_v;
ULONG hsstrt, hsstop, htotal, vsstrt, vsstop, vtotal;
if (!GetDisplayInfoData(NULL, (UBYTE *)&DisplayInfo, sizeof(DisplayInfo),
DTAG_DISP, id) ||
!GetDisplayInfoData(NULL, (UBYTE *)&DimensionInfo,
sizeof(DimensionInfo), DTAG_DIMS, id) ||
!GetDisplayInfoData(NULL, (UBYTE *)&MonitorInfo, sizeof(MonitorInfo),
DTAG_MNTR, id))
return;
if (GetDisplayInfoData(NULL, (UBYTE *)&NameInfo, sizeof(NameInfo), DTAG_NAME,
id))
VideoMode.name = NameInfo.Name;
else if (nonameok)
VideoMode.name = NULL;
else
return;
VideoMode.geometry.xres = DimensionInfo.Nominal.MaxX+1;
VideoMode.geometry.yres = DimensionInfo.Nominal.MaxY+1;
VideoMode.geometry.vxres = VideoMode.geometry.xres;
VideoMode.geometry.vyres = VideoMode.geometry.yres;
VideoMode.geometry.depth = DimensionInfo.MaxDepth < 2 ? 1 :
DimensionInfo.MaxDepth>>1;
VideoMode.options.hsync = MonitorInfo.Mspc->BeamCon0 & HSYNCTRUE ? HIGH : LOW;
VideoMode.options.vsync = MonitorInfo.Mspc->BeamCon0 & VSYNCTRUE ? HIGH : LOW;
VideoMode.options.csync = MonitorInfo.Mspc->BeamCon0 & CSYNCTRUE ? HIGH : LOW;
VideoMode.options.gsync = MonitorInfo.Mspc->BeamCon0 & GSYNCTRUE ? TRUE : FALSE;
VideoMode.options.extsync = FALSE;
VideoMode.options.laced = DisplayInfo.PropertyFlags & DIPF_IS_LACE ? TRUE : FALSE;
VideoMode.options.dblscan = DisplayInfo.PropertyFlags & DIPF_IS_SCANDBL ? TRUE : FALSE;
VideoMode.timings.pixclock = (double)DisplayInfo.PixelSpeed/35*25E9/
SysBase->ex_EClockFrequency;
switch (DisplayInfo.PixelSpeed) {
case 35:
VideoMode.timings.pixclock = 25E9/SysBase->ex_EClockFrequency;
colorclock_to_dotclock = 8;
break;
case 70:
VideoMode.timings.pixclock = 50E9/SysBase->ex_EClockFrequency;
colorclock_to_dotclock = 4;
break;
case 140:
VideoMode.timings.pixclock = 100E9/SysBase->ex_EClockFrequency;
colorclock_to_dotclock = 2;
break;
default:
printf("Unexpected pixel clock of %d ns\n", DisplayInfo.PixelSpeed);
return;
}
diwstrt_h = MonitorInfo.DefaultViewPosition.x*colorclock_to_dotclock>>1;
diwstrt_v = MonitorInfo.DefaultViewPosition.y;
hsstrt = MonitorInfo.Mspc->ms_Special->hsync.asi_Start*colorclock_to_dotclock;
hsstop = MonitorInfo.Mspc->ms_Special->hsync.asi_Stop*colorclock_to_dotclock;
htotal = (MonitorInfo.TotalColorClocks+1)*colorclock_to_dotclock;
vsstrt = MonitorInfo.Mspc->ms_Special->vsync.asi_Start/MonitorInfo.TotalColorClocks;
vsstop = MonitorInfo.Mspc->ms_Special->vsync.asi_Stop/MonitorInfo.TotalColorClocks;
vtotal = MonitorInfo.TotalRows+1;
if (VideoMode.options.laced) {
diwstrt_v <<= 1;
vsstrt <<= 1;
vsstop <<= 1;
vtotal <<= 1;
}
if (VideoMode.options.dblscan) {
diwstrt_v >>= 1;
vsstrt >>= 1;
vsstop >>= 1;
vtotal >>= 1;
}
diwstop_h = diwstrt_h+VideoMode.geometry.xres;
diwstop_v = diwstrt_v+VideoMode.geometry.yres;
if (MonitorInfo.Mspc->ms_Flags & MSF_REQUEST_SPECIAL) {
VideoMode.timings.left = diwstrt_h-hsstop;
VideoMode.timings.right = htotal+hsstrt-diwstop_h;
VideoMode.timings.upper = diwstrt_v-vsstop;
VideoMode.timings.lower = vtotal+vsstrt-diwstop_v;
VideoMode.timings.hslen = hsstop-hsstrt;
VideoMode.timings.vslen = vsstop-vsstrt;
VideoMode.options.bcast = FALSE;
} else {
/*
* Not yet implemented
*/
VideoMode.timings.left = 0;
VideoMode.timings.right = 0;
VideoMode.timings.upper = 0;
VideoMode.timings.lower = 0;
VideoMode.timings.hslen = 0;
VideoMode.timings.vslen = 0;
VideoMode.options.bcast = TRUE;
}
if (VideoMode.name)
printf("mode \"%.32s\"\n", VideoMode.name);
else
printf("mode \"0x%08x\"\n", id);
printf("\tgeometry %d %d %d %d %d\n", VideoMode.geometry.xres,
VideoMode.geometry.yres, VideoMode.geometry.vxres,
VideoMode.geometry.vyres, VideoMode.geometry.depth);
printf("\ttimings %d %d %d %d %d %d %d\n", VideoMode.timings.pixclock,
VideoMode.timings.left, VideoMode.timings.right,
VideoMode.timings.upper, VideoMode.timings.lower,
VideoMode.timings.hslen, VideoMode.timings.vslen);
if (VideoMode.options.hsync)
puts("\thsync high");
if (VideoMode.options.vsync)
puts("\tvsync high");
if (VideoMode.options.csync)
puts("\tcsync high");
if (VideoMode.options.extsync)
puts("\textsync true");
if (VideoMode.options.bcast)
puts("\tbcast true");
if (VideoMode.options.laced)
puts("\tlaced true");
if (VideoMode.options.dblscan)
puts("\tdouble true");
puts("endmode\n");
}
int main(void)
{
struct RDArgs *rdargs;
LONG args[] = {
NULL,
NULL
};
STRPTR *ids;
ULONG id;
if (!(rdargs = ReadArgs("ID/M,NONAMEOK/S", args, NULL)))
PrintFault(IoErr(), NULL);
else if (ids = (STRPTR *)args[0])
do {
sscanf(*ids++, "%x", &id);
GetVideoMode(id, 1);
} while (*ids);
else
for (id = INVALID_ID; (id = NextDisplayInfo(id)) != INVALID_ID;)
GetVideoMode(id, args[1]);
return 0;
}
|