; BOUNCER.WAS Ver1.0 Bouncing Terminal Display

;* Written by:  Symantec ASPECT Assist                                       *
;*                                                                           *                                                                             
;* This script file will give the user the option of either capturing data   *
;* in half hour increments, or in 24 hour increments. The Capture file will  *
;* close after a predefined period of inactivity on the port.                *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************




;*****************************************************************************
;* MACRO DEFINITIONS                                                         *
;*****************************************************************************

#define CHAR 233                                       ; terminal character
#define TRAIL_LEN 47                                   ; trail length
#define TRAIL_SPEED 10                                 ; speed of trail
#define CURSR_DWN_RIGHT "Down_Right"
#define CURSR_DWN_LEFT "Down_Left"
#define CURSR_UP_RIGHT "Up right"
#define CURSR_UP_LEFT "Up Left"
#define TERM_MODE "This script runs in Terminal Mode." ; PW mode message
#define CHANGE_MODE "Would you like to change to Terminal Mode?"



;*****************************************************************************
;* GLOBAL VARIABLES                                                          *
;*****************************************************************************

integer giTrail_Row[TRAIL_LEN], giTrail_Col[TRAIL_LEN], giTrial_Len=TRAIL_LEN
integer giRow=0, giCol=0, giTrail_Count=TRAIL_LEN
integer giRow_Count=0, giCol_Count=0, giTrail_Count_Buf=giTrial_Len 
string gszEmulation


;*****************************************************************************
;*                                                                           *   
;* MAIN                                                                      * 
;* The main procedure calls 4 other procedures.  Each of these 4             *
;* procedures update the Terminal Window display depending on the cursor’s   *
;* direction of movement.                                                    *
;*                                                                           *
;* Globals: GITRIAL_LEN, GSZEMULATION                                        *
;* Calls: CLEAN_UP, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT                 *               
;*                                                                           * 
;*****************************************************************************

proc Main
string szCrsr_Dirction=CURSR_DWN_RIGHT

   PW_Mode_Change(0)                              ; check PW mode
   i0=giTrial_Len                                 ; set array buffer counter
   set aspect keys ON                             ; let ASPECT control keyboard
   when $KEYHIT call Clean_Up                     ; watch for keystroke
   when userexit call Clean_Up                    ; watch for user exit
   fetch terminal type gszEmulation               ; fetch current emulation
   set terminal type "ANSI BBS"                   ; set emulation to ANSI
   clear                                          ; clear screen
   while 1                                        ; loop forever

      switch szCrsr_Dirction                      ; compare cursor direction

         case CURSR_DWN_RIGHT                     ; cursor down and right
            szCrsr_Dirction=Down_Right()          ; update display
         endcase
         
         case CURSR_DWN_LEFT                      ; cursor down and left
            szCrsr_Dirction=Down_Left()           ; update display
         endcase
         
         case CURSR_UP_RIGHT                      ; cursor up and right
            szCrsr_Dirction=Up_Right()            ; update display
         endcase
         
         case CURSR_UP_LEFT                       ; cursor up and left
            szCrsr_Dirction=Up_Left()             ; update display
         endcase
      endswitch

   endwhile
endproc



;*****************************************************************************
;*                                                                           *
;* DOWN_RIGHT()                                                              *
;* Returns: String indicating cursor direction                               *
;*                                                                           *
;* The function DOWN_RIGHT updates screen display/cursor movement in the     *
;* Terminal Window.                                                          *
;*                                                                           *
;* Called by: Main                                                           *
;* Calls: WRITE_CHAR                                                         *
;* Modifies Globals: GIROW, GICOL                                            *
;*                                                                           *
;*****************************************************************************

func Down_Right : string

   while giRow<24 && giCol<79                     ; loop while cursor is in boundaries
      Write_Char(giRow, giCol)                    ; write character to screen
      if giRow<24 && giCol<79                     ; if location is withen boundaries
         ++giRow                                  ; increment row
         ++giCol                                  ; increment column
      endif
   endwhile

   if giRow==24                                   ; if cursor hit the bottom boundary
      return CURSR_UP_RIGHT                       ; bounce curser up and right
   endif
   
   if giCol==79                                   ; if cursor hit right boundary
      return CURSR_DWN_LEFT                       ; bounce cursor down and left
   endif
endfunc



;*****************************************************************************
;*                                                                           *
;* DOWN_LEFT()                                                               *
;* Returns: String indicating cursor direction                               *
;*                                                                           *
;* The function DOWN_LEFT updates screen display/cursor movement in the      *
;* Terminal Window.                                                          *
;*                                                                           *
;* Called by: Main                                                           *
;* Calls: WRITE_CHAR                                                         *
;* Modifies Globals: GIROW, GICOL                                            *
;*                                                                           *
;*****************************************************************************

func Down_Left : string

   while giRow<24 && giCol>0                      ; loop while cursor is in boundaries
      Write_Char(giRow, giCol)                    ; write character to screen
      if giRow<24 && giCol>0                      ; if location is withen boundaries
         ++giRow                                  ; increment row
         --giCol                                  ; decrement column
      endif
   endwhile

   if giRow==24                                   ; if cursor hit the bottom boundary
      return CURSR_UP_LEFT                        ; bounce cursor up and left
   endif

   if giCol==0                                    ; if cursor hit the left boundary
      return CURSR_DWN_RIGHT                      ; bounce cursor down and right
   endif
endfunc         



;*****************************************************************************
;*                                                                           *
;* UP_RIGHT()                                                                *
;* Returns: String indicating cursor direction                               *
;*                                                                           *
;* The function UP_RIGHT updates screen display/cursor movement in the       *
;* Terminal Window.                                                          *
;*                                                                           *
;* Called by: Main                                                           *
;* Calls: WRITE_CHAR                                                         *
;* Modifies Globals: GIROW, GICOL                                            *
;*                                                                           *
;*****************************************************************************

func Up_Right : string

   while giRow>0 && giCol<79                      ; loop while cursor is in boundaries
      Write_Char(giRow, giCol)                    ; write character to screen
      if giRow>0 && giCol<79                      ; if location is withen boundaries
         --giRow                                  ; decrement row
         ++giCol                                  ; increment column
      endif
   endwhile

   if giRow==0                                    ; if cursor hit the top boundary
      return CURSR_DWN_RIGHT                      ; bounce cursor down and right
   endif
   if giCol==79                                   ; if cursor hit right boundary
      return CURSR_UP_LEFT                        ; bounce cursor up and left
   endif
endfunc
         


;*****************************************************************************
;*                                                                           *
;* UP_LEFT()                                                                 *
;* Returns: String indicating cursor direction                               *
;*                                                                           *
;* The function UP_LEFT updates screen display/cursor movement in the        *
;* Terminal Window.                                                          *
;*                                                                           *
;* Called by: Main                                                           *
;* Calls: WRITE_CHAR                                                         *
;* Modifies Globals: GIROW, GICOL                                            *
;*                                                                           *
;*****************************************************************************

func Up_Left : string

   while giRow>0 && giCol>0                       ; loop while cursor is in boundaries
      Write_Char(giRow, giCol)                    ; write character to screen
      if giRow>0 && giCol>0                       ; if location is withen boundaries
         --giRow                                  ; decrement row
         --giCol                                  ; decrement column
         if giRow==0 && giCol==0                  ; if cursor hit top left corner
             exitwhile                            ; fall out of loop
         endif
      endif         
   endwhile
   
   if giCol==0                                    ; if cursor hit the left boundary
      return CURSR_UP_RIGHT                       ; bounce cursor up and right
   endif   
   
   if giRow==0                                    ; if cursor hit the top boundary
      return CURSR_DWN_LEFT                       ; bounce cursor down and left
   endif   
endfunc



;*****************************************************************************
;*                                                                           *
;* WRITE_CHAR(integer, integer)                                              *
;*                                                                           *
;* The procedure WRITE_CHAR writes the leading character in the Terminal     *
;* Window and covers the trailing character with a space.                    *
;*                                                                           *
;* Called by: DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT                       *
;* Calls: None                                                               *
;* Modifies Globals: GITRAIL_COUNT_BUF, GITRAIL_ROW, GIROW_COUNT,            *
;*                   GITRAIL_COL, GICOL_COUNT, GITRIAL_LEN, GITRAIL_COUNT    *
;*                                                                           *
;*****************************************************************************

proc Write_Char
param integer giRow, giCol

   locate giRow giCol                             ; position curser

   if giTrail_Count_Buf                           ; if array buffer not full
      giTrail_Row[giRow_Count]=giRow              ; make record of row position
      giTrail_Col[giCol_Count]=giCol              ; make record of column position
      ++giRow_Count                               ; increment row element counter
      ++giCol_Count                               ; increment column element counter
      --giTrail_Count_Buf                         ; decrement initial buffer counter
      mspause TRAIL_SPEED
      mspause TRAIL_SPEED
      termwritec CHAR                             ; write character to Terminal
      return                                      ; exit procedure
   endif
   mspause TRAIL_SPEED
   termwritec CHAR                                ; write character to Terminal

   if i0==0                                       ; if all array elemtnet accessed
      i0=giTrial_Len                              ; reset array element pointer
   endif
   locate giTrail_Row[giTrial_Len-i0] giTrail_Col[giTrial_Len-i0]
                                                  ; position cursor
   mspause TRAIL_SPEED
   giTrail_Row[giTrail_Count-i0]=giRow            ; make record of row position
   giTrail_Col[giTrail_Count-i0]=giCol            ; make record of column position
   --i0                                           ; decrement array element pointer
   termwritec 32                                  ; write space to cover trail
endproc



;*****************************************************************************
;*                                                                           *
;* PW_MODE_CHANGE(integer)                                                   *
;*                                                                           *
;* The procedure PW_MODE_CHANGE checks the Mode that PW is in, and compares  *
;* it to the parameter.  If they are equal then PW is in the correct mode.   *
;* Otherwise it presents the user with a dialog box asking if they want to   *
;* change to the correct mode.                                               *
;*                                                                           *
;* Called by: MAIN                                                           *
;* Calls: CLEAN_UP                                                           *
;* Modifies Globals: None                                                    *
;*                                                                           *
;*****************************************************************************

proc PW_Mode_Change
param integer nMode
integer nResponse
integer Choice = 0

   i9=$PWMODE                                     ; get current mode
   if nMode != $PWMODE                            ; if not the correct PW mode
      beep                                        ; sound beep
                                                  ; display message
      sdlgmsgbox TERM_MODE CHANGE_MODE EXCLAMATION YESNO nResponse
      if nResponse == 6                           ; if user selected yes
         pwmode nMode                             ; change modes
      else                                        ; otherwise
         Clean_Up()                               ; exit script
      endif
   endif
endproc


;*****************************************************************************
;*                                                                           *
;* CLEAN_UP()                                                                *
;*                                                                           *
;* The procedure CLEAN_UP sets the emulation and mode to match what it they  *
;* were set at when this script was executed and then terminates.            *
;*                                                                           *
;* Called by: MAIN, PW_MODE_CHANGE                                           *
;* Calls: None                                                               *
;* Modifies Globals: None                                                    *
;*                                                                           *
;*****************************************************************************

proc Clean_Up

   set terminal type gszEmulation                 ; reset terminal emulation
   pwmode i9                                      ; reset mode
   exit
endproc