home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
424.lha
/
EasyMouse
/
easymouse.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-29
|
20KB
|
760 lines
/***************************************************************************/
/* Programm : EasyMouse V1.0 (c)1989 Oliver Enseling */
/* Funktion : Screenblanker,SunMouse,usw. */
/* Version : 01.000 */
/* */
/* Autor Datum Kommentar */
/* Boller 10.7.89 Erstversion Beginn */
/* Boller 02.9.89 Erstversion testfertig für Lattice 5.02 */
/* Boller 05.10.89 noch im debugging */
/***************************************************************************/
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/devices.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxmacros.h>
#include <hardware/custom.h>
#include <hardware/dmabits.h>
#include <devices/inputevent.h>
#include <devices/input.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <proto/all.h>
#define DEUTSCH
#include "easymouse.i"
extern struct Custom far custom;
/* HotKeys + Qualifier Keys */
#define LEFT (0x4f | 0x80)
#define RIGHT (0x4e | 0x80)
#define UP (0x4c | 0x80)
#define DOWN (0x4d | 0x80)
#define Q (0x10 | 0x80)
#define F (0x23 | 0x80)
#define B (0x35 | 0x80)
#define A (0x20 | 0x80)
#define MINUS (0x3a | 0x80)
#define KOMMA (0x38 | 0x80)
#define PUNKT (0x39 | 0x80)
#define DEL (0x46 | 0x80)
#define LSHIFT 0x60
#define RSHIFT 0x61
#define CTRL 0x63
#define LALT 0x64
#define RALT 0x65
#define CAPS 0x62
#define COMMODORE 0x66
#define RAMIGA 0x67
/* Konstante Werte */
#define MY_QUALIFIER (IEQUALIFIER_LCOMMAND | IEQUALIFIER_LSHIFT)
#define OPTION_NAME "s:EasyMouse.config"
/* Struktur mit den veränderbaren Einstellungen des Programmes */
struct Options {
WORD MinMem, MouseDelay, ScreenDelay, MouseAccel,
MouseTresh, FrontClicks, WindowX, WindowY;
BOOL Flag_Click2Back, Flag_CollectQuals, Flag_AutoActivate, Flag_ClockFront,
Out_Time, Out_Mem, Out_Chip, Out_Fast;
} Options =
{
1, 4, 5, 3, 2, 1, 0, 0, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE
};
LONG MouseDelay[] =
{0x7fffffff, 1, 2, 3, 5, 10, 15, 30, 60};
LONG ScreenDelay[] =
{0x7fffffff, 30, 60, 120, 180, 300, 600, 900, 1800};
LONG MinMem[] =
{25 * 1024, 50 * 1024, 75 * 1024, 100 * 1024, 150 * 1024,
200 * 1024, 250 * 1024, 500 * 1025, 1024 * 1024};
BOOL EndIt = FALSE;
char OutputStr[80];
/* Menudefinition */
#include "menu.c"
/* globale Variablen zur Auswertung einer IntuiMessage */
ULONG class;
USHORT code, qualifier;
APTR iaddress;
struct IntuitionBase *IntuitionBase;
struct DOSLibrary *DOSBase;
struct LayersBase *LayersBase;
extern struct ExecBase *SysBase;
struct Window *Window;
struct NewWindow NW =
{0, 0, 500, 10, 0, 1, CLOSEWINDOW | MENUPICK, SMART_REFRESH, NULL, NULL,
(UBYTE *) "EasyMouse V1.0", NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN};
struct Screen *myscreen;
struct NewScreen NS =
{0, 0, 320, 200, 1, 1, 0, NULL, CUSTOMSCREEN | SCREENQUIET};
/* globale Vars */
LONG MouseTimer, ScreenTimer;
struct IOStdReq *InputBlock;
/*
* TestMsg: Testen, ob eine Message da ist und ggf Werte
* bereitstellen
*/
BOOL
TestMsg(win)
struct Window *win;
{
struct IntuiMessage *msg;
if (msg = (struct IntuiMessage *) GetMsg(win->UserPort)) {
class = msg->Class;
code = msg->Code;
iaddress = msg->IAddress;
ReplyMsg((struct Message *) msg);
return (TRUE);
}
return (FALSE);
}
/* GetDeviceBlock: Device-Block anlegen und initialisieren */
void *
GetDeviceBlock(size)
ULONG size;
{
struct MsgPort *device_port = NULL;
APTR device_request = NULL;
device_port = (struct MsgPort *) CreatePort(0L, 0L);
if (device_port == 0L)
return (NULL);
device_request = (APTR) CreateExtIO(device_port, size);
if (device_request == 0L) {
DeletePort(device_port);
return (NULL);
}
return (device_request);
}
/* FreeDeviceBlock: Device-Block freigeben */
void
FreeDeviceBlock(iorequest)
struct IORequest *iorequest;
{
if (iorequest != 0L) {
if (iorequest->io_Message.mn_ReplyPort != 0L)
DeletePort(iorequest->io_Message.mn_ReplyPort);
DeleteExtIO(iorequest);
}
}
/* Open_A_Device: Device öffnen */
BOOL
Open_A_Device(name, unit, device_request, flags, size)
char *name;
ULONG unit;
struct IORequest **device_request;
ULONG flags, size;
{
UWORD error;
if (size != 0L)
if (!(*device_request = GetDeviceBlock(size)))
return (FALSE);
error = OpenDevice(name, unit, *device_request, flags);
if (error != 0L) {
return (FALSE);
}
return (TRUE);
}
/* Close_A_Device: Device schließen und Device-Block freigeben */
void
Close_A_Device(iorequest)
struct IORequest *iorequest;
{
if (iorequest != 0L) {
if (iorequest->io_Message.mn_ReplyPort != 0L)
DeletePort(iorequest->io_Message.mn_ReplyPort);
if (iorequest->io_Device != 0L)
CloseDevice(iorequest);
DeleteExtIO(iorequest);
}
}
/* Do_Command: Device-Kommando ausführen */
void
Do_Command(deviceblock, command)
struct IORequest *deviceblock;
UWORD command;
{
deviceblock->io_Command = command;
DoIO(deviceblock);
}
struct Interrupt Input_Handler;
/* Input_AddHandler: Eigene C-Routine in Input-Handler einbinden */
void
Input_AddHandler(ireq, handler, data)
struct IOStdReq *ireq;
void *handler;
APTR data;
{
Input_Handler.is_Data = data;
Input_Handler.is_Code = handler;
Input_Handler.is_Node.ln_Pri = 51;
ireq->io_Data = (APTR) & Input_Handler;
Do_Command(ireq, (UWORD) IND_ADDHANDLER);
}
/* Input_RemHandler: Input-Handler ausschalten */
void
Input_RemHandler(ireq)
struct IOStdReq *ireq;
{
ireq->io_Data = (APTR) & Input_Handler;
Do_Command(ireq, (UWORD) IND_REMHANDLER);
}
/* CloseAll: Alles ordnungsgemäß schließen */
void
CloseAll(str)
register char *str;
{
char buffer[80];
if (str) {
if (IntuitionBase) {
strcpy(buffer + 3, str);
buffer[0] = 0;
buffer[1] = 40;
buffer[2] = 20;
DisplayAlert(RECOVERY_ALERT, buffer, 50L);
} else
puts(str);
}
if (InputBlock) {
Input_RemHandler(InputBlock);
Close_A_Device(InputBlock);
}
if (Window) {
ClearMenuStrip(Window);
CloseWindow(Window);
}
if (GfxBase)
CloseLibrary(GfxBase);
if (LayersBase)
CloseLibrary(LayersBase);
if (DOSBase)
CloseLibrary(DOSBase);
if (IntuitionBase)
CloseLibrary((struct Library *) IntuitionBase);
Exit(TRUE);
}
/* Optionen im Menu einstellen */
void
SetOptions()
{
MinMemSub[8 - Options.MinMem].Flags |= CHECKED;
MouseDelaySub[8 - Options.MouseDelay].Flags |= CHECKED;
ScreenDelaySub[8 - Options.ScreenDelay].Flags |= CHECKED;
MouseAccelSub[8 - Options.MouseAccel].Flags |= CHECKED;
MouseTreshSub[8 - Options.MouseTresh].Flags |= CHECKED;
FrontClicksSub[2 - Options.FrontClicks].Flags |= CHECKED;
if (Options.Flag_Click2Back)
Click2BackItem.Flags |= CHECKED;
if (Options.Flag_CollectQuals)
CollectQualsItem.Flags |= CHECKED;
if (Options.Flag_AutoActivate)
AutoActivateItem.Flags |= CHECKED;
if (Options.Flag_ClockFront)
ClockFrontItem.Flags |= CHECKED;
if (Options.Out_Time)
TimeSub.Flags |= CHECKED;
if (Options.Out_Mem)
MemSub.Flags |= CHECKED;
if (Options.Out_Chip)
ChipSub.Flags |= CHECKED;
if (Options.Out_Fast)
FastSub.Flags |= CHECKED;
}
/* Fenster schließen, an Werte aus Options anpassen und wieder öffnen */
void
SetWindow()
{
if (Window) {
Options.WindowX = Window->LeftEdge;
Options.WindowY = Window->TopEdge;
ClearMenuStrip(Window);
CloseWindow(Window);
}
NW.LeftEdge = Options.WindowX;
NW.TopEdge = Options.WindowY;
NW.Width = 38;
if (Options.Out_Time)
NW.Width += 15 * 8;
if (Options.Out_Mem)
NW.Width += 17 * 8;
if (Options.Out_Chip)
NW.Width += 13 * 8;
if (Options.Out_Fast)
NW.Width += 13 * 8;
NW.Width = max(NW.Width, 142);
NW.Flags = WINDOWCLOSE | WINDOWDRAG | SMART_REFRESH;
if (!Options.Flag_ClockFront) {
NW.Flags |= WINDOWDEPTH;
NW.Width += 52;
}
if (!(Window = OpenWindow(&NW)))
#ifdef DEUTSCH
CloseAll("EasyMouse kann kein Fenster öffnen !!!");
#else
CloseAll("Unable to open window\n");
#endif
SetMenuStrip(Window, &Menu1);
}
/* Window unter der Maus ermitteln */
struct Window *
MouseWindow()
{
SHORT x, y;
struct Layer_Info *li;
struct Layer *l;
li = &IntuitionBase->FirstScreen->LayerInfo;
x = IntuitionBase->FirstScreen->MouseX;
y = IntuitionBase->FirstScreen->MouseY;
l = WhichLayer(li, (LONG) x, (LONG) y);
return ((struct Window *) l->Window);
}
/* Bildschirm ein- und ausschalten */
void
BlackScreen()
{
if (myscreen == 0) {
myscreen = OpenScreen(&NS);
SetRGB4(&(myscreen->ViewPort), 0, 0, 0, 0);
}
OFF_DISPLAY
OFF_SPRITE
}
void
NormalScreen()
{
ON_DISPLAY
if (myscreen)
CloseScreen(myscreen);
myscreen = 0;
}
/* IHandler: Input-Handler */
struct InputEvent *__saveds __interrupt
IHandler()
{
struct InputEvent *masterevent = (struct InputEvent *) getreg(REG_A0), **event = &masterevent;
static ULONG extraquals;
static LONG nmics, nsecs, omics, osecs;
struct Window *w = MouseWindow();
struct Screen *s = IntuitionBase->FirstScreen;
ULONG ilock = LockIBase(0);
while (*event) {
USHORT iecode = (*event)->ie_Code, iequal = (*event)->ie_Qualifier, ieclass = (*event)->ie_Class;
static USHORT lastcode;
BOOL deleteevent = FALSE;
switch (ieclass) {
case IECLASS_RAWKEY:
if (iecode >= 0x80) {
if (iecode == lastcode | 0x80) {
deleteevent = TRUE;
lastcode = 0;
}
} else {
ScreenTimer = ScreenDelay[Options.ScreenDelay];
if (Options.Flag_CollectQuals) {
if (iecode >= LSHIFT && iecode <= RAMIGA) {
lastcode = iecode;
deleteevent = TRUE;
switch (iecode) {
case LSHIFT:
extraquals |= IEQUALIFIER_LSHIFT;
break;
case RSHIFT:
extraquals |= IEQUALIFIER_RSHIFT;
break;
case CTRL:
extraquals |= IEQUALIFIER_CONTROL;
break;
case LALT:
extraquals |= IEQUALIFIER_LALT;
break;
case RALT:
extraquals |= IEQUALIFIER_RALT;
break;
case COMMODORE:
extraquals |= IEQUALIFIER_LCOMMAND;
break;
case RAMIGA:
extraquals |= IEQUALIFIER_RCOMMAND;
break;
default:
lastcode = 0;
deleteevent = FALSE;
extraquals = NULL;
break;
}
} else {
iequal |= extraquals;
(*event)->ie_Qualifier |= extraquals;
extraquals = 0;
}
}
}
if ((iequal & MY_QUALIFIER) == MY_QUALIFIER) {
deleteevent = TRUE;
switch (iecode) {
case LEFT:
MoveWindow(w, -w->LeftEdge, 0);
break;
case RIGHT:
MoveWindow(w, s->Width - w->LeftEdge - w->Width, 0);
break;
case UP:
MoveWindow(w, 0, -w->TopEdge);
break;
case DOWN:
MoveWindow(w, 0, s->Height - w->TopEdge - w->Height);
break;
case F:
if (!(w->Flags & BACKDROP))
WindowToFront(w);
break;
case B:
WindowToBack(w);
break;
case A:
if (w = MouseWindow())
ActivateWindow(w);
break;
case Q:
EndIt = TRUE;
break;
case MINUS:
ScreenToBack(s);
break;
case KOMMA:
if (w->Flags & WINDOWSIZING)
SizeWindow(w, w->MinWidth - w->Width,
w->MinHeight - w->Height);
break;
case PUNKT:
if (w->Flags & WINDOWSIZING)
SizeWindow(w,
min(w->MaxWidth - w->Width,
s->Width - w->Width -
w->LeftEdge),
min(w->MaxHeight - w->Height,
s->Height - w->Height -
w->TopEdge));
break;
case DEL:
MouseTimer = ScreenTimer = 0;
} /* switch */
} /* if */
break;
/* Bei Mausbewegung Maus einschalten und Maustimer zurücksetzen */
/* evtl. ClickToFront/Back oder SunMouse + beschleunigen */
case IECLASS_RAWMOUSE:
MouseTimer = MouseDelay[Options.MouseDelay];
ScreenTimer = ScreenDelay[Options.ScreenDelay];
switch (iecode) {
case IECODE_RBUTTON:
if ((iequal & IEQUALIFIER_LEFTBUTTON) && Options.Flag_Click2Back)
if (w)
WindowToBack(w);
break;
case IECODE_LBUTTON:
if (w)
switch (Options.FrontClicks) {
case 1:
if (!(w->Flags & BACKDROP))
WindowToFront(w);
break;
case 2:
osecs = nsecs;
omics = nmics;
CurrentTime(&nsecs, &nmics);
if (DoubleClick(osecs, omics, nsecs, nmics))
if (!(w->Flags & BACKDROP))
WindowToFront(w);
} /* switch */
break;
case IECODE_NOBUTTON:
if ((abs((*event)->ie_X) > Options.MouseTresh) ||
(abs((*event)->ie_Y) > Options.MouseTresh)) {
(*event)->ie_X *= Options.MouseAccel;
(*event)->ie_Y *= Options.MouseAccel;
} /* if */
if (Options.Flag_AutoActivate)
if (!(iequal & IEQUALIFIER_LEFTBUTTON))
if (w != IntuitionBase->ActiveWindow)
ActivateWindow(w);
} /* switch */
break;
case IECLASS_TIMER:
if (((*event)->ie_TimeStamp.tv_micro % 10) == 0) {
MouseTimer--;
ScreenTimer--;
} /* if */
} /* switch */
if (ScreenTimer <= 0)
BlackScreen();
else
NormalScreen();
if (MouseTimer <= 0)
OFF_SPRITE
else
ON_SPRITE
if (deleteevent)
*event = (*event)->ie_NextEvent;
else
event = &((*event)->ie_NextEvent);
} /* while */
UnlockIBase(ilock);
return (masterevent);
} /* function */
/* OpenAll: Alles ordnungsgemäß öffnen */
void
OpenAll()
{
BPTR fh;
if (!(IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", 0L)))
#ifdef DEUTSCH
CloseAll("Intuition.Library kann nicht geöffnet werden !!!");
#else
CloseAll("Unable to open intuition.library\n");
#endif
if (!(DOSBase = (struct DOSLibrary *) OpenLibrary("dos.library", 0)))
#ifdef DEUTSCH
CloseAll("Dos.Library kann nicht geöffnet werden !!!");
#else
CloseAll("Unable to open dos.library\n");
#endif
if (!(LayersBase = (struct LayersBase *) OpenLibrary("layers.library", 0)))
#ifdef DEUTSCH
CloseAll("Layers.Library kann nicht geöffnet werden !!!");
#else
CloseAll("Unable to open layers.library\n");
#endif
if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0)))
#ifdef DEUTSCH
CloseAll("Graphics.Library kann nicht geöffnet werden !!!");
#else
CloseAll("Unable to open graphics.library\n");
#endif
if (fh = Open(OPTION_NAME, MODE_OLDFILE)) {
Read(fh, (char *) &Options, sizeof(Options));
Close(fh);
}
SetOptions();
SetWindow();
if (!(Open_A_Device("input.device", 0L, &InputBlock, 0L, sizeof(*InputBlock))))
#ifdef DEUTSCH
CloseAll("Input.Device kann nicht geöffnet werden !!!");
#else
CloseAll("Unable to open input.device\n");
#endif
Input_AddHandler(InputBlock, IHandler, NULL);
}
/*
* Main: Hauptprogramm,Menüabfrage,Update von Uhr- und
* Speicheranzeige
*/
void
main(argc, argv)
int argc;
char **argv;
{
LONG fast, chipmem, mem;
BPTR fh;
OpenAll();
MouseTimer = MouseDelay[Options.MouseDelay];
ScreenTimer = ScreenDelay[Options.ScreenDelay];
FOREVER
{
struct Window *w = IntuitionBase->ActiveWindow;
struct Screen *s = IntuitionBase->FirstScreen;
char buffer[40];
if (EndIt)
CloseAll(NULL);
Delay(50);
if (Options.Flag_ClockFront)
UpfrontLayer(&Window->WScreen->LayerInfo, Window->WLayer);
fast = AvailMem(MEMF_FAST);
chipmem = AvailMem(MEMF_CHIP);
mem = chipmem + fast;
OutputStr[0] = 0;
if (Options.Out_Time) {
long sec, mic;
CurrentTime(&sec, &mic);
#ifdef DEUTSCH
sprintf(buffer, " Zeit %2d:%2d:%2d ", sec / 3600 % 24, sec / 60 % 60, sec % 60);
#else
sprintf(buffer, " Time %2d:%2d:%2d ", sec / 3600 % 24, sec / 60 % 60, sec % 60);
#endif
strcat(OutputStr, buffer);
}
if (Options.Out_Mem) {
#ifdef DEUTSCH
sprintf(buffer, " Speicher %-7d", mem);
#else
sprintf(buffer, " Memory %-7d", mem);
#endif
strcat(OutputStr, buffer);
}
if (Options.Out_Chip) {
sprintf(buffer, " CHIP %-7d", chipmem);
strcat(OutputStr, buffer);
}
if (Options.Out_Fast) {
sprintf(buffer, " FAST %-7d ", fast);
strcat(OutputStr, buffer);
}
OutputText.FrontPen = mem < MinMem[Options.MinMem] ? 3 : 1;
PrintIText(Window->RPort, &OutputText,
Window->WScreen->ViewPort.Modes & HIRES ? 0 : -14, 0);
if (TestMsg(Window)) {
switch (class) {
case CLOSEWINDOW:
CloseAll(NULL);
case MENUPICK:
switch (MENUNUM(code)) {
case 0: /* Aktionen */
switch (ITEMNUM(code)) {
case 0: /* Display off */
ScreenTimer = 0;
break;
case 1: /* Screen2Back */
ScreenToBack(s);
break;
case 6: /* Window links */
WindowToFront(w);
MoveWindow(w, -w->LeftEdge, 0);
break;
case 7: /* Window rechts */
WindowToFront(w);
MoveWindow(w, s->Width - w->LeftEdge - w->Width, 0);
break;
case 8: /* Window oben */
WindowToFront(w);
MoveWindow(w, 0, -w->TopEdge);
break;
case 9: /* Window unten */
WindowToFront(w);
MoveWindow(w, 0, s->Height - w->TopEdge - w->Height);
break;
case 12: /* Ende */
CloseAll(NULL);
}
break;
case 1: /* Optionen */
switch (ITEMNUM(code)) {
case 1: /* Number of Clicks-To-Front */
if ((SUBNUM(code) >= 0) && (SUBNUM(code) <= 2))
Options.FrontClicks = SUBNUM(code);
break;
case 4: /* Mindestspeicher */
if ((SUBNUM(code) >= 0) && (SUBNUM(code) <= 8))
Options.MinMem = SUBNUM(code);
break;
case 5: /* Anzeige */
Options.Out_Time = TimeSub.Flags & CHECKED;
Options.Out_Mem = MemSub.Flags & CHECKED;
Options.Out_Chip = ChipSub.Flags & CHECKED;
Options.Out_Fast = FastSub.Flags & CHECKED;
break;
case 6: /* ScreenBlank */
if ((SUBNUM(code) >= 0) && (SUBNUM(code) <= 8))
Options.ScreenDelay = SUBNUM(code);
break;
case 7: /* N]ouseBlank */
if ((SUBNUM(code) >= 0) && (SUBNUM(code) <= 8))
Options.MouseDelay = SUBNUM(code);
break;
case 8: /* Mouse-Acceleration */
if ((SUBNUM(code) >= 0) && (SUBNUM(code) <= 8))
Options.MouseAccel = SUBNUM(code) + 1;
break;
case 9: /* Mouse-Acceleration-Treshhold
* */
if ((SUBNUM(code) >= 0) && (SUBNUM(code) <= 8))
Options.MouseTresh = SUBNUM(code);
break;
case 11: /* Save Options */
if (fh = Open(OPTION_NAME, MODE_NEWFILE)) {
Options.WindowX = Window->LeftEdge;
Options.WindowY = Window->TopEdge;
Write(fh, (char *) &Options, sizeof(Options));
Close(fh);
} else
DisplayBeep(NULL);
}
Options.Flag_Click2Back = Click2BackItem.Flags & CHECKED;
Options.Flag_CollectQuals = CollectQualsItem.Flags & CHECKED;
Options.Flag_AutoActivate = AutoActivateItem.Flags & CHECKED;
Options.Flag_ClockFront = ClockFrontItem.Flags & CHECKED;
SetWindow();
break;
}
break;
}
}
}
}