#include #include #include #include #include /* ** s s v - a S c r e e n S a V e r ** ** Copyright (C) 1986 By Perry S. Kivolowitz ** * The author grants permission for the non-commercial * distribution of this software provided that this * and other identifying information remains intact. ** * This software is provided "as-is" and carries * with it no explicit or implicit promise of support * by the author. Nor will the author be held liable * for any damages, real or imagined, which may * result from the use or abuse of this software. ** */ /* * This program is intended to be RUN from the * startup-sequence. It occupies a small amount of * memory and consumes very few cpu cycles. It will * attempt to detect some number of consecutive * minutes in which you haven't done anything at the * keyboard or mouse. ** * After some minutes, ssv will bring a dark screen * to the front and do some eye magic designed not * to hurt your monitor. From time to time, ssv will * bring your original screen to the front again just * to remind you what's running. ** * Clicking the left mouse button at any time * causes ssv to delete its screen and go back to * waiting for inactivity. If you want ssv to actually * EXIT - then click on the happy face which will * float around the screen. ** */ extern void *OpenLibrary(); extern struct Screen *OpenScreen(); extern struct Window *OpenWindow(); extern struct IntuiMessage *GetMsg(); extern struct Task *FindTask(); #define RPPtr; struct RastPort *; #define BMPtr; struct BitMap *; #define IBPtr; struct IntuitionBase *; #define GMEM ((MEMF_CHIP) | (MEMF_CLEAR)) #define NPTS 100 #define HAPPY_FACE 999 #define FACE_WIDTH 37L #define FACE_HEIGHT 21L #undef min #define min(a , b)((a) < (b) ? (a) : (b)) static char *Author = "Perry S. Kivolowitz"; static char *ILibrary = "intuition.library"; static char *GLibrary = "graphics.library"; struct IntuitionBase *IntuitionBase; struct GfxBase *GfxBase; struct Window *w = NULL; struct Screen *s = NULL; struct ViewPort *vp = NULL; struct RastPort *rp = NULL; static struct BitMap fbm; static int sleepy_time = 4 * 12; struct point { long x; long y; long dx; long dy; }; struct Gadget close_gadget = { NULL , 0 , 0 , FACE_WIDTH , FACE_HEIGHT , GADGHNONE | GADGIMAGE , GADGIMMEDIATE , BOOLGADGET , NULL , NULL , NULL , 0 , NULL , HAPPY_FACE , NULL }; struct NewScreen ns = { 0 , 0 , 640 , 200 , 1 , 0 , 0 , HIRES , CUSTOMSCREEN , NULL , NULL , NULL , NULL }; struct NewWindow nw = { 0 , 0 , 640 , 200 , 0 , 0 , MOUSEBUTTONS | GADGETDOWN | INACTIVEWINDOW , NOCAREREFRESH | ACTIVATE | BORDERLESS | BACKDROP , &close_gadget , NULL , NULL , NULL , NULL , 0 , 0 , 0 , 0 , CUSTOMSCREEN }; /* produced by GI from a DPaint brush file */ unsigned short happy_face[63] = { 0x0000,0x0000,0x0000, 0x000f,0xff80,0x0000, 0x00f8,0x00f8,0x0000, 0x0387,0xff0e,0x0000, 0x0e7f,0xfff3,0x8000, 0x19ff,0xfffc,0xc000, 0x37ff,0xffff,0x6000, 0x2fe3,0xfe3f,0xa000, 0x6fdf,0xffdf,0xb000, 0x5fbb,0xfeef,0xd000, 0x5fff,0xdfff,0xd000, 0x5fff,0xdfff,0xd000, 0x6fff,0xefff,0xb000, 0x2fbf,0x8fef,0xa000, 0x37df,0xffdf,0x6000, 0x19e3,0xfe3c,0xc000, 0x0e7c,0x01f3,0x8000, 0x0387,0xff0e,0x0000, 0x00f8,0x00f8,0x0000, 0x000f,0xff80,0x0000, 0x0000,0x0000,0x0000 }; main(argc , argv) char *argv[]; { int result = 0; if (argc > 1) sleepy_time = atoi (argv[1]) * 12; if (sleepy_time <= 0) sleepy_time = 6; IntuitionBase = (struct IntuitionBase *) OpenLibrary(ILibrary , 0L); GfxBase = (struct GfxBase *) OpenLibrary(GLibrary , 0L); init_happy_face(); if (IntuitionBase && GfxBase) { while (result != HAPPY_FACE) { wait_for_inactivity(); if (!(nw.Screen = s = OpenScreen(&ns)) || !(w = OpenWindow(&nw))) goto out; ShowTitle(s , 0L); set_pointers(); set_color_map(); while (1) { ScreenToFront(s); if (result = zoom()) break; ScreenToBack(s); Delay(300L); } CloseWindow(w); CloseScreen(s); } } out:if (GfxBase) CloseLibrary(GfxBase); if (IntuitionBase) CloseLibrary(IntuitionBase); } set_pointers() { vp = &w->WScreen->ViewPort; rp = &s->RastPort; } set_color_map() { SetRGB4(vp , 0L , 0L , 0L , 0L); SetRGB4(vp , 1L , 0L , 0L , 0L); SetRast(rp , 0L); SetDrMd(rp , COMPLEMENT); SetAPen(rp , 1L); } zoom() { unsigned long class; register struct point *p; struct point array[NPTS] , face_position; register struct point *end_point = &array[NPTS]; long red , green , blue; int style , loops; struct IntuiMessage *message; set_dots(array); set_face(&face_position); red = rand(9) + 5; green = rand(8) + 5; blue = rand(8) + 5; ramp_up(red , green , blue); for (style = 0; style < 2; style++) { loops = style == 0 ? 3500 : 2500; while (--loops) { if (message = GetMsg(w->UserPort)) { class = message->Class; ReplyMsg(message); break; } p = array + (loops & 3); if ((loops & 7) == 0) jerk_pointer(loops); WaitBOVP(vp); move_dots(0 , style , &face_position); while (p < end_point) { move_dots(1 , style , p); p += 4; } } if (message) break; } ramp_down(red , green , blue); SetRast(rp , 0L); if (message == NULL) return(0); return(class == GADGETDOWN ? HAPPY_FACE : 1); } /* * If you are not using MANX C or are using a version * of MANX which does not have RangeRand (undocumented * library call), simply replace this routine with one * that returns a random number between 0 and x - 1. */ rand(X) { long seconds , microseconds; CurrentTime(&seconds , µseconds); return((RangeRand((short) (1 << 15)) + 0xFFF & microseconds) % X); } ramp_up(red , green , blue) register long red , green , blue; { register long i; for (i = 0; i < 16; i++) { Delay(5L); SetRGB4(vp , 1L , min(i,red) , min(i,green) , min(i,blue)); } } ramp_down(red , green , blue) register red , green , blue; { register long i; for (i = 15; i >= 0; i--) { Delay(5L); SetRGB4(vp , 1L , min(i,red) , min(i,green) , min(i,blue)); } } set_face(p) register struct point *p; { close_gadget.LeftEdge = p->x = rand(580) + 20; close_gadget.TopEdge = p->y = rand(140) +20; p->dx = 2; p->dy = 1; BltBitMap(&fbm , 0L , 0L , w->RPort->BitMap , p->x , p->y, FACE_WIDTH , FACE_HEIGHT , 0x60L , 0xFFL , NULL); } set_dots(array) struct point array[]; { register struct point *p; register long i; for (i = 0, p = array; i < NPTS; i++ , p++) { do { p->x = rand(620) + 10; p->y = rand(180) + 10; } while (ReadPixel(rp , p->x , p->y) == 1); while (!(p->dx = rand(13) - 6)); while (!(p->dy = rand(13) - 6)); WritePixel(rp , p->x , p->y); } } move_dots(flag , style , p) register int flag , style; register struct point *p; { register long oldx , oldy; oldx = p->x; oldy = p->y; p->x += p->dx; p->y += p->dy; if ((p->x >= (flag ? 640 : 640 - FACE_WIDTH)) || (p->x < 0)) { p->x -= p->dx; p->dx = -p->dx; } if ((p->y >= (flag ? 200 : 200 - FACE_HEIGHT)) || (p->y <0 )) { p->y -= p->dy; p->dy = -p->dy; } if (flag) { if (style == 0) WritePixel(rp , oldx , oldy); WritePixel(rp , p->x , p->y); } else { BltBitMap(&fbm , 0L , 0L , w->RPort->BitMap , oldx , oldy, FACE_WIDTH , FACE_HEIGHT , 0x60L , 0xFFL , NULL); BltBitMap(&fbm , 0L , 0L , w->RPort->BitMap , p->x , p->y, FACE_WIDTH , FACE_HEIGHT , 0x60L , 0xFFL , NULL); close_gadget.TopEdge = p->y; close_gadget.LeftEdge = p->x; } } jerk_pointer(counter) int counter; { register long color_register = (counter % 3) + 17; register long red , green , blue; red = rand(10); green = rand(10); blue = rand(10); SetRGB4(vp , color_register , red , green , blue); } init_happy_face() { InitBitMap(&fbm , 1L , FACE_WIDTH , FACE_HEIGHT); fbm.Planes[0] = (PLANEPTR) happy_face; } long InputActivity() { register struct Task *p = FindTask("input.device"); register long return_value = 0; Forbid(); if (p) { return_value = (long) *(p->tc_SPReg - 2); } Permit(); return(return_value); } long TotalMem() { register unsigned long AvailMem(); register long availmem; Forbid(); availmem = AvailMem(MEMF_FAST); availmem += AvailMem(MEMF_CHIP); Permit(); return (availmem); } wait_for_inactivity() { register long available_memory , last_available_memory; register long repetitions = 0 , input_action , last_input_action; last_available_memory = TotalMem(); last_input_action = InputActivity(); while (repetitions < sleepy_time) { Delay(50L * 5L); available_memory = TotalMem(); input_action = InputActivity(); if ((last_available_memory != available_memory) || (last_input_action != input_action)) { last_available_memory = available_memory; last_input_action = input_action; repetitions = 0; } else repetitions++; } }