/*     
      TEXT SERVER . Magma 1.0 . 1996 . Sylvain HUET

         textpkg.c : routines de gestion de terminal texte
*/

#include "x/Version.h"
#include "x/scolplugin.h"


#include <stdio.h>
#include <string.h>


/*
#include <winuser.h>
#include <mmsystem.h>

#include "../kernel/include/kernel.h"
#include "../kernel/listlab.h"
#include "winscol.h"
*/

int SCOLGetUpdateRect(HWND h)
{
  return GetUpdateRect(h,NULL,TRUE);
}
int SCOLValidateRect(HWND h)
{
  ValidateRect(h,NULL);
  return 0;
}


int TMkeybdstate(mmachine m)
{
  int k;

  k=0;
  if (GetKeyState(VK_SHIFT)<0) k+=1;
  if (GetKeyState(VK_CONTROL)<0) k+=2;
  if (GetKeyState(VK_MENU)<0) k+=4;
  return MMpush(m,k*2);
}
int TMgetCursorPos(mmachine m)
{
  POINT p ;

  GetCursorPos(&p);
  if (MMpush(m,p.x*2)) return MERRMEM;
  if (MMpush(m,p.y*2)) return MERRMEM;
  if (MMpush(m,2*2)) return MERRMEM;
  return MBdeftab(m);
}

int MMjoystick(mmachine m)
{
	JOYINFO joy;
	int i;

	i=MMpull(m)>>1;
	if ((i<0)||(i>1)) return MMpush(m,NIL);
	if (i) i=JOYSTICKID2;
	else i=JOYSTICKID1;
	
	if (joyGetPos(i,&joy)!=JOYERR_NOERROR) return MMpush(m,NIL);
	if (MMpush(m,joy.wXpos<<1)) return MERRMEM;
	if (MMpush(m,joy.wYpos<<1)) return MERRMEM;
	if (MMpush(m,joy.wZpos<<1)) return MERRMEM;
	if (MMpush(m,joy.wButtons<<1)) return MERRMEM;
	if (MMpush(m,4*2)) return MERRMEM;
	return MBdeftab(m);
}

#define NDIVPKG 3
char* divname[NDIVPKG]=
{"_keybdstate","_GETscreenPos","_joystick"
};

int (*divfun[NDIVPKG])(mmachine m)=
{
 TMkeybdstate,TMgetCursorPos,MMjoystick
};

int divnarg[NDIVPKG]=
{0,0,1};

char* divtype[NDIVPKG]=
{"fun [] I","fun [] [I I]","fun [I] [I I I I]"
};



int SCOLloadDiv(mmachine m)
{
	return PKhardpak(m,"txtsys.pkg",NDIVPKG,divname,divfun,divnarg,divtype);
}