Received: from j.cc.purdue.edu by VM.CC.PURDUE.EDU ; Tue, 17 May 88 08:01:46 EST
Received: by j.cc.purdue.edu (5.54/1.14)
    id AA06359; Tue, 17 May 88 08:00:34 EST
Date: Tue, 17 May 88 08:00:34 EST
From: ain@j.cc.purdue.edu (Patrick White)
Message-Id: <8805171300.AA06359@j.cc.purdue.edu>
To: fys-ma@fintuvm.BITNET
Subject: comp.sources.amiga:   sources/amiga/volume4/blank2.src.sh
 
Newsgroups: comp.sources.amiga
Subject: blank2 (sources)
Keywords: blank2, uncompiled
Approved: ain@j.cc.purdue.edu    (Patrick White)
 
Program Name:    blank2  (sources)
Submitted by:    joe@ut-sally  (Joe Hitchens)
Summary:    Blanks screen after 90 sec. -- takes approx. 250 bytes.
Poster Boy:    Patrick White    (ain@j.cc.purdue.edu)
Archive Name:    sources/amiga/volume4/blank2.src.sh.Z
tested but uncompiled.
 
NOTES:
   Ran the binary -- it works, but didn't try compiling it.
 
 
-- Pat White   (co-moderator comp.sources/binaries.amiga)
ARPA/UUCP: j.cc.purdue.edu!ain  BITNET: PATWHITE@PURCCVM  PHONE: (317) 743-8421
U.S.  Mail:  320 Brown St. apt. 406,    West Lafayette, IN 47906
 
========================================
 
#    This is a shell archive.
#    Remove everything above and including the cut line.
#    Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#    Run the following text with /bin/sh to create:
#    readme
#    blanker2.c
# This archive created: Mon May 16 10:53:03 1988
# By:    Patrick White (PUCC Land, USA)
echo shar: extracting readme '(2149 characters)'
cat << \SHAR_EOF > readme
From: joe@vixen.uucp (Joe Hitchens)
 
    Blanker2 -- by Joe Hitchens -- v1.27.88
    A screen blanking program that turns the screen black after 90 seconds
    of keyboard and mouse inactivity.
    Adds a tiny event handler to the input.handler event stream and watches
    the events go by.  If it doesn't see a mouse or keyboard event after 900
    timer events (10 per second), it turns the screen black by turning off
    DMA for rasters and the copper.
    If run from the CLI, a message will be printed out saying how long
    the blank time is set to.
    If run from (my cool) icon, nothing will appear to happen, but 90
    seconds later you will be able to tell if it installed itself ok.
    This program cannot be removed once installed, so if you have a
    problem with it, all I can say is "Stop using it".
    I realize that it would be a lot nicer to have a true task running
    in the background and message ports between the handler and the task
    so the handler could be programmed and removed from the outside,
    but, I opted to not do this because as it is, Blanker2 will take up
    less than 256 bytes of ram, and doesn't require any more when it
    attempts to blank the screen (via opening black screens, etc.).
    It's tiny and it does the job.  I think that may be worth alot to
    most users.
 
    This program is PUBLIC DOMAIN.
    Do me a favor though, and leave my name on it so I can get a little
    recognition.
 
    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
 
SHAR_EOF
if test 2149 -ne "`wc -c readme`"
then
echo shar: error transmitting readme '(should have been 2149 characters)'
fi
echo shar: extracting blanker2.c '(6051 characters)'
cat << \SHAR_EOF > blanker2.c
/*
    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);
        }
    }
 
 
SHAR_EOF
if test 6051 -ne "`wc -c blanker2.c`"
then
echo shar: error transmitting blanker2.c '(should have been 6051 characters)'
fi
#    End of shell archive
exit 0
