/*
**	ForceBorder
**
**	Copyright ©1995, 1996 by Daniel Balster
**
*/

#include <exec/exec.h>
#include <dos/dos.h>
#include <utility/hooks.h>
#include <intuition/intuition.h>

#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>

#include <string.h>
#include <stdlib.h>

/****************************************************/
//#define DEBUG

#ifdef DEBUG
void kprintf(UBYTE *fmt,...);
#define bug kprintf
#define D(X) X
#else
#define D(X)
#endif

#define AllocStruct(X)	AllocVec(sizeof(struct X),MEMF_CLEAR|MEMF_PUBLIC)
#define FreeStruct(X)	if (X) FreeVec(X)

#define ifnot(expr)	if(!(expr))

typedef enum { false=0, true=~(false) } bool;
/****************************************************/

/* OpenWorkBench */
#define VEC -0xd2
#define LIB (struct Library*) IntuitionBase
/* OpenScreenTagList */
#define VEC2 -0x264
#define LIB2 (struct Library*) IntuitionBase

extern APTR NewVector;
extern APTR OldVector;
extern APTR NewVector2;
extern APTR OldVector2;

extern long __oslibversion = 37L;

static char vers[] = "$VER: ForceBorder 0.3 (8.2.96) ©1996 Daniel Balster";

#define TEMPL	"LEFT/N,RIGHT/N,TOP/N,BOTTOM/N"

struct {
	ULONG *left,*right,*top,*bottom;
} args = {0};


VOID __asm newfunc (register __a0 struct Screen *scr)
{
	if (args.left)		scr->WBorLeft	= *args.left;
	if (args.right)	scr->WBorRight	= *args.right;
	if (args.top)		scr->WBorTop	= *args.top;
	if (args.bottom)	scr->WBorBottom= *args.bottom;
}

int main ()
{
	struct RDArgs *rda;
	
	if (rda = ReadArgs(TEMPL,(LONG*)&args,NULL))
	{
		Disable();
		OldVector = SetFunction (LIB,VEC,(ULONG(*)())&(NewVector));
		OldVector2 = SetFunction (LIB2,VEC2,(ULONG(*)())&(NewVector2));
		CacheClearU();
		Enable();

		Wait (SIGBREAKF_CTRL_C);
		
		if (FindPort("SetMan"))
		{
			Disable();
			SetFunction (LIB,VEC,(ULONG(*)())(OldVector));
			SetFunction (LIB2,VEC2,(ULONG(*)())(OldVector2));
			CacheClearU();
			Enable();
		}
		else Wait(0);

		FreeArgs(rda);
	}
	else PrintFault(IoErr(),0);

	return 0;
}
