home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d146
/
blanker2.lha
/
Blanker2
/
blanker2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-05-28
|
6KB
|
221 lines
/*
Blanker2 -- by Joe Hitchens
v1.27.88
A screen blanking program that turns the screen black after 90 seconds
of keyboard and mouse inactivity.
This program is PUBLIC DOMAIN.
Do me a favor though, and leave my name on it.
Usage: blanker2 [n]
n = number of seconds of inactivity after which blanking occurs.
if n is not given, a default of 90 is used.
NOTE: blanker2 need not be 'run'. It will install an event
handler and leave it behind when exiting.
Also, the CLI window it may have been run from can be
closed after installation.
Exit codes
0 Normal exit, everything went fine.
1 CreatePort() failed.
2 CreateStdIO() failed.
3 OpenDevice() on "input.device" failed.
4 Memory Allocation for Interrupt structure failed.
5 Memory Allocation for Blanker structure failed.
6 Memory Allocation for event handler code space failed.
Please report any bugs you may find to me, so that I can try to
fix them.
j.h. joe@sally.utexas.edu
*/
#include <stdio.h>
#include <exec/types.h>
#include <exec/ports.h>
#include <exec/memory.h>
#include <exec/io.h>
#include <exec/interrupts.h>
#include <devices/input.h>
#include <exec/devices.h>
#include <devices/inputevent.h>
#include <graphics/gfxmacros.h>
#include <hardware/custom.h>
extern struct MsgPort *CreatePort();
extern struct IOStdReq *CreateStdIO();
extern char *AllocMem();
extern int HandlerInterface();
#define DEFAULT_BLANKPOINT 900 /* This is 1/10's of seconds */
struct blanker {
long Class;
long Ticks;
long BlankPoint;
long Dark;
char Name[8];
};
/* ----------------------------------------
Actual entry point for event handler
---------------------------------------- */
#asm
public _HandlerInterface
_HandlerInterface:
movem.l a0/a1,-(a7) ;
bsr _myhandler ;go to the C language routine we provided
addq.l #8,a7 ;
rts
#endasm
struct InputEvent *
myhandler(ev, mydata)
register struct InputEvent *ev;
register struct blanker *mydata;
{
mydata->Class = ev->ie_Class;
if (mydata->Class == IECLASS_TIMER)
{
mydata->Ticks++;
if (mydata->Ticks >= mydata->BlankPoint)
{
custom.dmacon = BITCLR | DMAF_RASTER | DMAF_COPPER;
custom.color[0] = (UWORD) 0; /* turn out the lights ! */
mydata->Ticks = 0; /* reset counter */
mydata->Dark = 1; /* yes the lights are out */
}
return(ev);
}
if (mydata->Class == IECLASS_RAWMOUSE)
{
mydata->Ticks = 0;
if (mydata->Dark)
{
custom.dmacon = BITSET | DMAF_RASTER | DMAF_COPPER; /* lightson */
mydata->Dark = 0;
}
return(ev);
}
if (mydata->Class == IECLASS_RAWKEY)
{
mydata->Ticks = 0;
if (mydata->Dark)
{
custom.dmacon = BITSET | DMAF_RASTER | DMAF_COPPER; /* lightson */
mydata->Dark = 0;
}
return(ev);
}
return(ev);
}
/* ----------------------------------------
End of event handler code
---------------------------------------- */
main(argc, argv)
int argc;
char **argv;
{
struct MsgPort *inputDevPort; /* for opening input.device */
struct IOStdReq *inputRequestBlock; /* for opening input.device */
struct Interrupt *handlerStuff; /* for adding event handler */
long n; /* for calc'ing handler size */
long s; /* ticks till blanking */
struct blanker *p; /* ptr to handler's variables */
char *code; /* prt to handler's entry point */
if (argc > 1)
{
s = 10 * atoi(argv[1]);
if (s < 10)
{
s = 10;
}
}
else
{
s = DEFAULT_BLANKPOINT;
}
inputDevPort = CreatePort("Blanker-Loader", 0);
if (inputDevPort == NULL)
exit (1);
inputRequestBlock = CreateStdIO(inputDevPort);
if (inputRequestBlock == 0)
{
DeletePort(inputDevPort);
exit (2);
}
if (OpenDevice("input.device", 0, inputRequestBlock, 0))
{
DeleteStdIO(inputRequestBlock);
DeletePort(inputDevPort);
exit (3);
}
handlerStuff = (struct Interrupt *)
AllocMem (sizeof (struct Interrupt), MEMF_CLEAR);
if (handlerStuff == (struct Interrupt *) 0)
{
DeleteStdIO(inputRequestBlock);
DeletePort(inputDevPort);
exit (4);
}
/* alloc space for the private variable space used by event handler */
p = (struct blanker *)AllocMem (sizeof (struct blanker), MEMF_CLEAR);
if (p == 0)
{
DeleteStdIO(inputRequestBlock);
DeletePort(inputDevPort);
FreeMem (handlerStuff, sizeof (struct Interrupt));
exit (5);
}
p->Class = 0;
p->Ticks = 0;
p->BlankPoint = s;
p->Dark = 0;
strncpy (p->Name, "Blanker", 7);
n = (char *)main - (char *)HandlerInterface; /* size of handler code */
code = AllocMem (n, MEMF_CLEAR);
if (code == 0)
{
DeleteStdIO(inputRequestBlock);
DeletePort(inputDevPort);
FreeMem (handlerStuff, sizeof (struct Interrupt));
FreeMem (p, sizeof (struct blanker));
exit (6);
}
CopyMem (HandlerInterface, code, n); /* move handler code to safe spot */
handlerStuff->is_Data = (APTR) p; /* ptr to our variable space */
handlerStuff->is_Code = (VOID (*)())code; /* ptr to event handler code */
handlerStuff->is_Node.ln_Pri = 51; /* priority just above Intuition */
handlerStuff->is_Node.ln_Name = p->Name;
inputRequestBlock->io_Command = IND_ADDHANDLER;
inputRequestBlock->io_Data = (APTR) handlerStuff;
DoIO (inputRequestBlock); /* install our event handler */
CloseDevice (inputRequestBlock); /* close device and leave event */
DeleteStdIO (inputRequestBlock); /* handler in memory */
DeletePort (inputDevPort);
if (argc > 0)
{
printf(" -- Blanker2 -- by Joe Hitchens -- V1.27.88 --\n");
printf("Screen Blanks after %d sec's of mouse/key inactivity.\n",
s / 10);
}
}