#include "doscmd.h"

u_long xms_vector;

int
int2f_43(struct sigcontext *sc)
{               

	switch (GET8L(sc->sc_eax)) {
	case 0x00:
		SET8L(sc->sc_eax, 0x80);
		break;
	case 0x10:
		PUTVEC(sc->sc_es, sc->sc_ebx, xms_vector);
		break;
	default:
		return (0);
	}
	return (1);
}

void
xms_entry(struct sigcontext *sc)
{

	switch (GET8H(sc->sc_eax)) {
	case 0x00:
		SET16(sc->sc_eax, 0x0300);
		SET16(sc->sc_ebx, 0x0001);
		SET16(sc->sc_edx, 0x0001);
		break;
	default:
		printf("XMS %02x\n", GET8H(sc->sc_eax));
		SET16(sc->sc_eax, 0);
		break;
	}
}

u_char xms_trampoline[] = {
	0xeb,	/* JMP 5 */
	0x03,
	0x90,	/* NOP */
	0x90,	/* NOP */
	0x90,	/* NOP */
	0xf4,	/* HLT */
	0xcb,	/* RETF */
};

void
xms_init(void)
{
	xms_vector = insert_generic_trampoline(
	    sizeof(xms_trampoline), xms_trampoline);
	register_callback(xms_vector + 5, xms_entry, "xms");
}
