[comp.os.msdos.programmer] Querying screen mode with int 10h, function 0fh

anicolao@watcgl.waterloo.edu (Alex Nicolaou) (05/06/91)

 Ok, this is a simple problem, but I cannot seem to get my 
program to work correctly. I am trying to get the value for
the current screen mode out of my graphics card. It works when
I'm in an EGA mode, but in CGA mode kills the screen. 
 Please help by giving me a suggestion that works!

Here is the program:

/**** program ****/
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
 
union REGS iReg, oReg;
struct SREGS segregs;
 
main()
{
	int mode;
	/* if you try EGA EGAHI this program will suddenly
 	 * work! */
	int gdriver = CGA,
	    gmode = CGAHI;
 
	initgraph(&gdriver, &gmode, "");
 
	/* draw a line to prove to myself that the video mode is
	 * correct 						*/
	moveto(0, getmaxy());
	lineto(getmaxx(), 0);
	/* make the user press return to go to next stage */
	getchar();
 
	/* use int 10h function 0fh to get video mode */
	iReg.x.ax = 0x000f;
	/* if you comment out this line, the code works, except
	 * of course you don't have the screen mode */
	int86x(0x10, &iReg, &oReg, &segregs);
	/* save the mode */
	mode = oReg.h.al&0x007f;
 
	moveto(0,0);
	lineto(getmaxx(), getmaxy());
 
	getchar();
	closegraph();
}

/*** end of program ***/

Thanks for any help!

alex