, , .



:

AH

4Fh

AL

10h

BL

02h

:

AL

4Fh - ;

AH

0, ,

1

BH

:

00h - ON ( )

01h - STANDBY ( )

02h - SUSPEND ( )

04h - OFF ( )

08h - REDUSED ON ( )

POWER, 7.3, VBE Power Management. POWER, , . , VBE Power Management, . .

7.3. POWER.CPP

#include <stdio.h>

#include <conio.h>

#include <dos.h>

//

void main(void);

int SetPowerState( unsigned char );

int GetPowerState( unsigned char* );

int AnalyseResult(union REGS);

int PowerCapabilities( unsigned char*, unsigned char*,

unsigned char*);

#define ON 0x00

#define OFF 0x04

#define STANDBY 0x01

#define SUSPEND 0x02

#define REDUCED 0x08

//===========================================================

//

//===========================================================

void main(void) {

int uiResult;

unsigned char ucMode, ucModes,

ucMinorVer, ucMajorVer;


//

uiResult =

PowerCapabilities(&ucModes, &ucMajorVer, &ucMinorVer);

printf("\n\n Copyright (C)Frolov G.V.,1995. "

"E-mail: frolov@glas.apc.org\n");

if(uiResult==0) {

printf("\ n VBE Power Management %d.%d",

(int)ucMajorVer, (int)ucMinorVer );

printf("\n :\n"

"STANDBY - %s\n"

"SUSPEND - %s\n"

"OFF - %s\n"

"REDUCED - %s\n",

(ucModes & STANDBY)? "" : "",

(ucModes & SUSPEND)? "" : "",

(ucModes & OFF)? "" : "",

(ucModes & REDUCED)? "" : ""

);

}

else if(uiResult < 0) {

printf("\n "

" " );

return;

}

else if(uiResult > 0) {

printf("\n "

"VBE Power Management" );

return;

}

//

uiResult = GetPowerState( &ucMode );

printf("\n GetPowerState %d",uiResult);

printf("\n GetPowerState = %x", ucMode );

printf("\n : %s\n",

(ucMode & STANDBY) ? "STANDBY" :



(ucMode & SUSPEND) ? "SUSPEND" :

(ucMode & OFF) ? "OFF" :

(ucMode & REDUCED) ? "REDUCED" : ""

);

printf("\n\ n "

" ( STANDBY)"

"\n " );

//

getch();

//

uiResult = SetPowerState(STANDBY);

printf("\n SetPowerState(STANDBY) "

" %d", uiResult );

//

getch();

//

uiResult = SetPowerState( ON );

printf("\n SetPowerState( ON ) "

" %d", uiResult );

return;

}

//===========================================================

// SetPowerState

//

//===========================================================

int

SetPowerState( unsigned char ucMode )

{

union REGS regs;

int iResult;

regs.h.ah = 0x4f;

regs.h.al = 0x10;

regs.h.bl = 0x01;

regs.h.bh = ucMode;

int86(0x10, &regs, &regs);

iResult = AnalyseResult(regs);

return iResult;

}

//===========================================================

// GetPowerState

//

//===========================================================

int

GetPowerState( unsigned char *ucMode )

{

union REGS regs;

int iResult;

regs.h.ah = 0x4f;

regs.h.al = 0x10;

regs.h.bl = 0x02;

int86(0x10, &regs, &regs);

*ucMode = regs.h.bh;

iResult = AnalyseResult(regs);

return iResult;

}

//===========================================================



// PowerCapabilities

//

//===========================================================

int

PowerCapabilities( unsigned char *ucModes,

unsigned char *ucMajorVer,

unsigned char *ucMinorVer)

{

union REGS regs;

struct SREGS segregs;

int iResult;

regs.h.ah = 0x4f;

regs.h.al = 0x10;

regs.h.bl = 0x00;

segregs.es = 0x00;

regs.x.di = 0x00;

int86x(0x10, &regs, &regs, &segregs);

*ucModes = regs.h.bh;

*ucMinorVer = regs.h.bl & 0x0F; //

*ucMajorVer = (regs.h.bl & 0xF0) >> 4; //

iResult = AnalyseResult(regs);

return iResult;

}

//===========================================================

// AnalyseResult

// ,

// Power VBE

//===========================================================

int

AnalyseResult(union REGS regs)

{

int iResult;

// VBE Power Management

if((regs.h.al == 0x4f) && (regs.h.ah == 0))

iResult = 0;

//

else if(regs.h.al != 0x4f)

iResult = -1;

//

else

iResult = 1;

return iResult;

}