/*
   Interrupt 9 Chainer. (Keyboard Handler)
   Compiles fine with DOS/4GW, will probably work with PMODE/W to.

   Kombat, IMMORTALS
*/

// Keyboard Scan Codes Definitions

// Upper F-Key Line

const char      scesc       = 1;
const char      scf1        = 59;
const char      scf2        = 60;
const char      scf3        = 61;
const char      scf4        = 62;
const char      scf5        = 63;
const char      scf6        = 64;
const char      scf7        = 65;
const char      scf8        = 66;
const char      scf9        = 67;
const char      scf10       = 68;
const char      scf11       = 87;
const char      scf12       = 88;
const char      scscrllock  = 70;

// Upper Row

const char      sctilde     = 41;
const char      sc1         = 2;
const char      sc2         = 3;
const char      sc3         = 4;
const char      sc4         = 5;
const char      sc5         = 6;
const char      sc6         = 7;
const char      sc7         = 8;
const char      sc8         = 9;
const char      sc9         = 10;
const char      sc0         = 11;
const char      scminus     = 12;
const char      scequal     = 13;
const char      scbackspace = 14;

// QWERTY Row

const char      sctab       = 15;
const char      scq         = 16;
const char      scw         = 17;
const char      sce         = 18;
const char      scr         = 19;
const char      sct         = 20;
const char      scy         = 21;
const char      scu         = 22;
const char      sci         = 23;
const char      sco         = 24;
const char      scp         = 25;
const char      scopensq    = 26;
const char      scclosesq   = 27;
const char      scenter     = 28;

// Home Row

const char      sccapslock  = 58;
const char      sca         = 30;
const char      scs         = 31;
const char      scd         = 32;
const char      scf         = 33;
const char      scg         = 34;
const char      sch         = 35;
const char      scj         = 36;
const char      sck         = 37;
const char      scl         = 38;
const char      scsemicolon = 39;
const char      scqoute     = 40;

// Bottom Key Row

const char      sclshift    = 42;
const char      scbackslash = 43;
const char      scz         = 44;
const char      scx         = 45;
const char      scc         = 46;
const char      scv         = 47;
const char      scb         = 48;
const char      scn         = 49;
const char      scm         = 50;
const char      sccomma     = 51;
const char      scperiod    = 52;
const char      scslash     = 53;
const char      scrshift    = 54;

// Spacebar Row

const char      scctrl      = 29;
const char      scalt       = 56;
const char      scspace     = 57;

// Numeric Keypad

const char      schome      = 71;
const char      scup        = 72;
const char      scpgup      = 73;
const char      scleft      = 75;
const char      sckey5      = 76;
const char      scright     = 77;
const char      scend       = 79;
const char      scdown      = 80;
const char      scpgdn      = 81;
const char      scnumlock   = 69;
const char      scgrayminus = 74;
const char      scgrayplus  = 78;
const char      scasterisk  = 55;
const char      scins       = 82;
const char      scdel       = 83;

// End of Scan-Code Constants

void DoSTI(void);
#pragma aux DoSTI = "sti" modify exact[];

void DoCLI(void);
#pragma aux DoCLI = "cli" modify exact[];

char key[128];

void (__interrupt __far *prev_int_9)();

void __interrupt __far keyb_rtn()
{
	char port60;

	port60 = inp(0x60);
	if (port60 < 128) key[port60] = 1;
	else
	key[port60-128] = 0;

	outp(0x20,0x20);
//   _chain_intr( prev_int_9 );
}

void install_keyb()
{
	prev_int_9 = _dos_getvect( 0x9 );
	_dos_setvect( 0x9, keyb_rtn );
}

void restore_keyb()
{
	_dos_setvect( 0x9, prev_int_9 );
}