#include "X.h"
#define NEED_EVENTS
#include "Xproto.h"
#include "misc.h"
#include "window.h"
#include "windowstr.h"
#include "dix.h"
#include <dos.h>
#include "scrnintstr.h"
#include "gcstruct.h"
#include "servermd.h"
#include "pixmap.h"
#include "pixmapst.h"
#include "i8.h"
#include "afidata.h"

Bool
i8Close(index, pScreen)
int index;
ScreenPtr pScreen;
{
    struct hinit_data hinit_data;
    struct aifpb aifpb;

    aifpb.length = 0;
    if (i8priv.ai_funcs) {
	if (i8priv.task_buffer) {
	    hinit_data.length = 2;
	    hinit_data.task_seg = ((u_long)FP_SEG(i8priv.task_buffer) * 16 +
		FP_OFF(i8priv.task_buffer) + 15) / 16;
	    HSYNC(&hinit_data);
	    xfree(i8priv.task_buffer);
	    i8priv.task_buffer = 0;
	}
	HCLOSE(&aifpb);
	if (i8priv.saved_palette) {
	    HRPAL(i8priv.saved_palette);
	    xfree(i8priv.saved_palette);
	    i8priv.saved_palette = 0;
	}
	i8priv.ai_funcs = 0;
    }
    if (pScreen == 0)
	return FALSE;
    pScreen->devPrivate = 0;
    return TRUE;
}

i8SaveScreen(pScr, on)
ScreenPtr pScr;
int on;
{

	outp(0x3c4, 1);
	if (on == SCREEN_SAVER_OFF)
		outp(0x3c5, inp(0x3c5) & ~0x20);
	else
		outp(0x3c5, inp(0x3c5) | 0x20);
	return TRUE;
}

void
i8QueryBestSize(kind, pWidth, pHeight)
int kind;
unsigned short *pWidth, *pHeight;
{
	unsigned width, test;

	switch (kind) {
	    case CursorShape:
#ifdef DIRECT_CURSOR
		*pWidth = 16;
		*pHeight = 16;
#endif
		break;
	    case TileShape:
	    case StippleShape:
		width = *pWidth;
		if (width > 0) {
			/* Find the smallest power of two greater than
			 * width. */
			test = 1;
			while (test < width)
				test <<= 1;
			*pWidth = test;
		}
		break;
	}
}
