MCPcopy Create free account
hub / github.com/NetHack/NetHack / vesa_detect

Function vesa_detect

sys/msdos/vidvesa.c:1345–1529  ·  view source on GitHub ↗

* This will verify the existence of a VGA adapter on the machine. * Video function call 0x4F00 returns 0x004F in AX if successful, and * returns a VbeInfoBlock describing the features of the VESA BIOS. */

Source from the content-addressed store, hash-verified

1343 * returns a VbeInfoBlock describing the features of the VESA BIOS.
1344 */
1345int
1346vesa_detect(void)
1347{
1348 int vbe_info_sel = -1; /* custodial */
1349 int vbe_info_seg;
1350 struct VbeInfoBlock vbe_info;
1351 __dpmi_regs regs;
1352 unsigned long mode_addr;
1353 struct ModeInfoBlock mode_info;
1354 const char *mode_str;
1355
1356 vbe_info_seg = __dpmi_allocate_dos_memory(
1357 (sizeof(vbe_info) + 15) / 16,
1358 &vbe_info_sel);
1359 if (vbe_info_seg < 0) goto error;
1360
1361 /* Request VBE 2.0 information if it is available */
1362 memset(&vbe_info, 0, sizeof(vbe_info));
1363 memcpy(vbe_info.VbeSignature, "VBE2", 4);
1364 dosmemput(&vbe_info, sizeof(vbe_info), vbe_info_seg * 16L);
1365
1366 /* Request VESA BIOS information */
1367 memset(&regs, 0, sizeof(regs));
1368 regs.x.ax = 0x4F00;
1369 regs.x.di = 0;
1370 regs.x.es = vbe_info_seg;
1371 (void) __dpmi_int(VIDEO_BIOS, &regs);
1372
1373 /* Check for successful completion of function: is VESA BIOS present? */
1374 if (regs.x.ax != 0x004F) goto error;
1375 dosmemget(vbe_info_seg * 16L, sizeof(vbe_info), &vbe_info);
1376 if (memcmp(vbe_info.VbeSignature, "VESA", 4) != 0) goto error;
1377
1378 /* Get the address of the mode list */
1379 /* The mode list may be within the DOS memory area allocated above.
1380 That area must remain allocated and must not be rewritten until
1381 we're done here. */
1382 mode_addr = (vbe_info.VideoModePtr >> 16) * 16L
1383 + (vbe_info.VideoModePtr & 0xFFFF);
1384
1385 /* Allow the user to select a specific mode */
1386 mode_str = nh_getenv("NH_DISPLAY_MODE");
1387 if (mode_str != NULL) {
1388 char *end;
1389 unsigned long num = strtoul(mode_str, &end, 16);
1390 if (*end == '\0') {
1391 /* Can we select this mode? */
1392 if (vesa_GetModeInfo(num, &mode_info)
1393 && mode_info.XResolution >= 640
1394 && mode_info.YResolution >= 480
1395 && mode_info.BitsPerPixel >= 8) {
1396 vesa_mode = num & 0x47FF;
1397 }
1398 }
1399 if (vesa_mode == 0xFFFF)
1400 mode_str = NULL;
1401 }
1402

Callers 2

assign_videoFunction · 0.85
vesa_InitFunction · 0.85

Calls 6

memcmpFunction · 0.85
vesa_GetModeInfoFunction · 0.85
get_paletteFunction · 0.85
vesa_FindModeFunction · 0.85
vesa_map_frame_bufferFunction · 0.85
nh_getenvFunction · 0.50

Tested by

no test coverage detected