' In its JUMPDISK appearance, this file is crunched. To decrunch it,
' see the DECRUNCH item on the ARTICLES MENU. This Basic source is made
' available to users who want to work with it. It is the source of the
' JumpBlanker progam in this same window. JumpBlanker is compiled by
' HiSoft Basic and does not require AmigaBASIC.
' -------------------------------------------------------------------------

  DEFINT a-y
  DEFSNG z
  RANDOMIZE TIMER 

'**** The folowing "GOTO" line lets you put your graphic routine at ****
'**** the start of the program listing for ease of customizing.     ****

GOTO ThePartAfterMyGraphicProgram

'************************************************************
'********************************* Put your program from here

MyGraphicProgram:                      '**** Essential name

  IF First=0 THEN
    First=1
    DIM J1$(40),J$(40),S$(1,1),X%(2),Y%(2),X2%(2),Y2%(2)
    DIM OldX%(2),OldY%(2),OldX2%(2),OldY2%(2)
    DIM SpdX%(2),SpdY%(2),SpdX1%(2),SpdY1%(2)
    DIM StoreX%(500),StoreY%(500)
    J1$="JUMPDISK": F$="Bounce.Title"
    IF FEXISTS (F$) THEN
      J1$=""
      OPEN F$ FOR INPUT AS 1
      WHILE NOT EOF(1)
        INPUT #1,A$
        J1$=J1$+A$
      WEND
      CLOSE 1
    END IF
 
    JLong=LEN(J1$): zJL=1/JLong 
    FOR I=1 TO JLong: J$(I)=MID$(J1$,I,1): NEXT
    First=1
  END IF
  
  SCREEN 2,320,200,4,1
  WINDOW 2,,,0+32+128,2
  PALETTE 0,0,0,0: PALETTE 2,.5,.5,.5
 
  vmin=1:     vmax=3:     xmin=0
  nColrs=16:  Colrmin=2:  Colrmax=nColrs-1
  Colr=3:     TD=7:       TW=1
  Xmax=WINDOW(2)-1: Ymax=WINDOW(3)-1  

  Elapsed=VAL(MID$(TIME$,5,1))
  Gap=400:     C=200:      C2=0
  Mode=1:      LT!=TIMER
  COLOR 3,,0

  GOSUB ReadEm
  FOR i=0 TO 500  
    LOCATE 22: ?"      JumpBlanker";
    COLOR 2: ?"  ŠJUMPDISK 1991"
    ?"       Press RIGHT button to change mode"
    COLOR i MOD 16+1,0: LOCATE 1
    IF K1&<>PEEK(Keys&) OR M1&<>PEEKL(Mice&) THEN SCREEN CLOSE 2: RETURN
  NEXT
 
'============================
   NoThingIsHappening=True              '**** Essential line #1
ReStart: 

  FOR i=0 TO ymax STEP 3: SCROLL(0,0)-(xmax,ymax),-3,-3: NEXT 
   
  FOR I=0 TO 1
    X%(I)=50+250*RND:   Y%(I)=30+150*RND
    X2%(I)=20+250*RND:  Y2%(I)=30+150*RND
Velocity:
    SpdX%(I)=20*RND-20*RND:  SpdY%(I)=10*RND-10*RND
    SpdX1%(I)=20*RND-20*RND: SpdY1%(I)=10*RND-10*RND
    IF ABS(SpdX1%(I))-1<1 OR ABS(SpdY1%(I))-1<1 THEN Velocity
  NEXT
LT!=TIMER

WHILE NoThingIsHappening=True        '**** Essential line #2

 IF TIMER-LT!>.5 THEN
   Mode=Mode+1: IF Mode=0 OR Mode>3 THEN Mode=1
   FOR i=0 TO ymax STEP 3: SCROLL(0,0)-(xmax,ymax),-3,-3: NEXT 
 END IF
 LT!=TIMER
 KN=0
Tripped:
  FOR I=0 TO 1
    OldX%(I)=X%(I):       OldY%(I)=Y%(I)
    OldX2%(I)=X2%(I):     OldY2%(I)=Y2%(I)
    X%(I)=X%(I)+SpdX%(I):  Y%(I)=Y%(I)+SpdY%(I)
   
    IF X%(I)<=2 OR X%(I)>=Xmax THEN
      IF X%(I)>Xmax THEN X%(I)=Xmax-2: SpdX%(I)=RND*-10-1
      IF X%(I)<=2 THEN X%(I)=2: SpdX%(I)=RND*10+1
      GOSUB NewColor
    END IF

    IF Y%(I)<=3 OR Y%(I)>=Ymax THEN      
      IF Y%(I)>=Ymax THEN Y%(I)=Ymax-2: SpdY%(I)=RND*-5-1
      IF Y%(I)<=3 THEN Y%(I)=4: SpdY%(I)=RND*5+1
      GOSUB NewColor
    END IF

    StoreX%(C+I)=X%(I):   StoreY%(C+I)=Y%(I)
    X2%(I)=StoreX%(C2+I): Y2%(I)=StoreY%(C2+I)
    
    C=C+2:   IF C>Gap THEN C=0
    C2=C2+2: IF C2>Gap THEN C2=0
  NEXT

  ON Mode GOTO Textit,Solid,Lines

Textit:
  ' *** TM=TextMode 0=print without surrounding square
  ' *** It is used as the additional parameter in COLOR command
  TM=0

  ' *** Find the distance between the lines end
  ' *** then divide it by the number of letters
  ' *** to be displayed.
  zXdif=(X%(1)-X%(0))*zJl:  zYdif=(Y%(1)-Y%(0))*zJl

  ' *** Determine which end of line is furthest toward
  ' *** left edge of screen so text reads left to right.
  IF zXdif<0 THEN TS=JLong:TE=1:St=-1: ELSE TS=1:TE=JLong:St=1

  ' *** Print characters in white for contrast, then in color
  FOR i=1 TO 2
    COLOR 1,,0: Txx=0
    IF i=2 THEN COLOR Colr2,,0
    FOR Tx=TS TO TE STEP St
      INCR Txx: PRINT PTAB(X%(0)+(zXdif*Txx),Y%(0)+(zYdif*Txx));J$(Tx);
    NEXT
  NEXT

  ' *** Does essentially the same as above routines, only in
  ' *** background color on character X & Y printed 200 cycles before.    
  zXdif=(X2%(1)-X2%(0))*zJl:  zYdif=(Y2%(1)-Y2%(0))*zJl
  IF zXdif<0 THEN TS=JLong:TE=1:St=-1: ELSE TS=1:TE=JLong:St=1
  COLOR 0,,0: Txx=0
  FOR Tx=TS TO TE STEP St
   INCR Txx: PRINT PTAB(X2%(0)+(zXdif*Txx),Y2%(0)+(zYdif*Txx));J$(Tx);
  NEXT
  
  GOTO Skipt

Solid:  
  COLOR Colr
  AREA(X%(0),Y%(0)):       AREA(X%(1),Y%(1))
  AREA(OldX%(1),OldY%(1)): AREA(OldX%(0),OldY%(0))
  AREAFILL
  
  COLOR 0
  AREA(X2%(0),Y2%(0)):       AREA(X2%(1),Y2%(1))
  AREA(OldX2%(1),OldY2%(1)): AREA(OldX2%(0),OldY2%(0))
  AREAFILL
  GOTO Skipt
 
Lines:
  COLOR Colr
  LINE(X%(0),Y%(0))-(X%(1),Y%(1))
  LINE(OldX%(1),OldY%(1))-(OldX%(0),OldY%(0))
  COLOR 0
  LINE(X2%(0),Y2%(0))-(X2%(1),Y2%(1))
  LINE(OldX2%(1),OldY2%(1))-(OldX2%(0),OldY2%(0))
  
Skipt:
  INCR ttt: IF ttt=15 THEN ttt=0: GOSUB Timing 
WEND
  SCREEN CLOSE 2
RETURN                                 '**** Reset to sleeping mode

NewColor:
  Colr=Colr+1: Colr2=RND*ColrMax+2.5
  IF Colr>ColrMax THEN Colr=3
 RETURN
 
Timing:
  TD=TD+TW:IF TD<7 OR TD>180 THEN TW=-TW
  COLOR 1,3,1
  LINE(-1,TD-7)-STEP(330,9),0,b
  PRINT PTAB(0,TD);" ";TIME$;" "DATE$;" ";
  IF TD MOD 10>4 THEN
    ? BIN$(VAL(LEFT$(TIME$,2)));":"; BIN$(VAL(MID$(TIME$,4,2)));":"; BIN$(VAL(RIGHT$(TIME$,2)));"         ";
   ELSE
    ? "HexTime ";HEX$(VAL(LEFT$(TIME$,2)));":"; HEX$(VAL(MID$(TIME$,4,2)));":";HEX$(VAL(RIGHT$(TIME$,2)));"                    ";
  END IF
  COLOR,0 
 RETURN

'to here *****************************************************
'*************************************************************

ThePartAfterMyGraphicProgram:

  WINDOW 1,"-JumpBlanker-    ",(20,20)-(200,30),16+2+4+8,-1
  Keys&=12577793&    '**** HEX = BFEC01  *** AmigaBasic doesn't accept
  Mice&=14675978&    '**** HEX = DFF00A  *** big HEX numbers. Go figure.
  Often=2            '**** How many seconds of dormancy between PEEKs
  Waiting=5          '**** Length of time before your program is activated

   '**** You might want to set the "Waiting" before the blanker is    '****
   '**** activated by reading the number of seconds from a diskfile   '****
   '**** created and saved with a text editting program then removing '****
   '**** the "REM"s from the following three lines.                   '****

 OPEN "MBdelay" FOR INPUT AS (1)
   INPUT #1,Waiting
 CLOSE #1

  True=1
  False=0
  COLOR 1,3:CLS
  GOSUB TurnWaitingTimerOn
  GOSUB ReadEm  

'************************************************************************
'************************** HEART OF PROGRAM ****************************
'**** The "SLEEP" command allows Basic to use as little of the Amiga's
'**** time as possible, so other programs can run at near normal speed.

MainLoop:
  WHILE True = 1: SLEEP: WEND

'*********************** END OF HEART OF PROGRAM ************************
'************************************************************************

   '**** Check for activity since last we PEEKed at keys and mice ****
CheckMouseAndKeys:
  IF PEEK(Keys&)=K1& AND PEEKL(Mice&)=M1& THEN ET=ET+2 ELSE ET=0
  IF ET>=Waiting THEN GOSUB ActivateMyGraphicProgram: RETURN MainLoop 
  PRINT PTAB(10,8);DATE$;"  ";TIME$;"     ";
  GOSUB ReadEm
 RETURN

   '**** This awakens program from dormancy and activates your routine ****
   '**** then watches for activity which turns it off                  ****
ActivateMyGraphicProgram:
  TIMER OFF                 '**** Turn waiting timer off
                            '**** Then turn graphic screen timer on
  ON TIMER (1) GOSUB HasAnythingBeenTouched
  TIMER ON
  GOSUB ReadEm              '**** Record mouse and key positions
  GOSUB MyGraphicProgram    '**** Run your graphics routine until something happens
  TIMER OFF                 '**** Turn graphic screen timer off
  WINDOW 1                  '**** Direct printing to little window
  ET=0                      '**** Reset activities timer
  GOSUB TurnWaitingTimerOn  '**** Restart waiting timer
  GOSUB ReadEm              '**** Record mouse and key positions
 RETURN                     '**** Return to main loop

   '**** See if keys, mice or sticks have been used  ****
   '**** by PEEKing hardware locations.              ****
HasAnythingBeenTouched:
  IF K1&<>PEEK(Keys&) OR M1&<>PEEKL(Mice&) THEN NoThingIsHappening=False

ReadEm: K1&=PEEK(Keys&): M1&=PEEKL(Mice&): RETURN

   '**** Set timer checking for activity every "Often" seconds ****
TurnWaitingTimerOn:
  ON TIMER (Often) GOSUB CheckMouseAndKeys
  TIMER ON
 RETURN

