;*; Updated on 13-Sep-89 at 7:01 AM by Steve Archuleta; edit time: 0:02:27
;*************************** AMUS Program Label ******************************
; Filename: BANNER.M68                                      Date: 09/13/89
; Category: UTIL         Hash Code: 161-642-316-160      Version: 1.0
; Initials:              Name: JEFF STUYVESANT
; Company:                                         Telephone #: 
; Related Files: 
; Min. Op. Sys.:                               Expertise Level: BEG
; Special: 
; Description: Allows user to create a scrolling banner on the screen. 
; Usage: BANNER window-size loop-count delay-factor string
; Note that string must be larger than window-size for banner to work.
;*****************************************************************************
;       BANNER.LIT
;       VER 1.0         8510.20
;       
;       PROPRIETARY PROGRAM MATERIAL
;
;       THIS MATERIAL IS THE PROPERTY OF JEFF STUYVESANT,
;       12307 PACIFIC AVE, APT 2,MAR VISTA, CALIF. ,90066
;       PERMISSION TO COPY AND USE IS GRANTED FOR 
;       NON-PROFIT USES ONLY.
;
;       Copyright (c) 1985 JEFF STUYVESANT
;
;
;       BANNER WILL TURN OFF THE CURSOR AND SCROLL THE MESSAGE AT PRESENT
;       LOCATION OF THE CURSOR.  IF ANY PARAMETER IS IN ERROR A MESSAGE
;       WILL BE DISPLAYED.
;
;       EX.
;
;       BANNER 15 5 20 THIS IS AN EXAMPLE
;              -- - -- -----------------
;               ^ ^  ^        ^
;               | |  |        +-----------> THE MESSAGE 
;               | |  +--------------------> RELATIVE DELAY FACTOR FORM 1 TO 100 (FAST TO SLOW)
;               | +-----------------------> LOOP COUNT (NUMBER OF REV'S)
;               +-------------------------> WINDOW SIZE (MUST BE EQUAL TO OR LESS THEN MESSAGE LENGTH)
;


        SEARCH  SYS
        SEARCH  SYSSYM
        SEARCH  TRM
        

        RADIX 8.
        
VMAJOR  =       1.
VMINOR  =       0.
VSUB    =       0.
VEDIT   =       0.
VWHO    =       0.

        PHDR    -1,0,PH$REE!PH$REU

BEGIN:

;       SET UP REGISTRERS
;
;       GIVEN A2=INPUT LINE STRING
;
;       GET WINDOW LENGTH FIRST

        BYP                                     ; BYPASS ANY BLANKS IN INPUT LINE
        GTDEC                                   ; GET A DECIMAL NUMBER THERE
        BPL     CONT                            ; IF NEG NO GOOD NUMBER
WINERR: MOV     #1,D1                           ; NO GOOD / MOV PARAMETER # ->D1
        JMP     ERROR$                          ; GOTO ERROR

CONT:   MOV     D1,D5                           ; SAVE WINDOW SIZE
        BEQ     WINERR                          ; IF WIN SIZE=0 NO GOOD
        CMPW    D5,#78.                         ; MAX SIZE=78
        BGT     WINERR                          ; IF WIN SIZE>78 -->WINERR
        

;       GET LOOP COUNT NEXT

        BYP                                     ; BYPASS THE NEXT BLANKS
        GTDEC                                   ; AND GET A DECIMAL NUMBER THERE
        BMI     15$                             ; IF NEG NO GOOD NUMBER
        MOV     D1,D3                           ; MOV ->D3
        BNE     20$                             ; IF #0 -->20$
15$:    MOVB    #2,D1                           ; =0 NO GOOD / MOV PARAMETER # ->D1
        JMP     ERROR$


;       GET DELAY FACTOR

20$:    BYP                                     ; BYPASS ANY BLANKS
        GTDEC                                   ; ANOTHER DECIMAL NUMBER
        BMI     25$                             ; IF NEG NO GOOD NUMBER
        MOV     D1,D0                           ; MOV ->D0
        BNE     30$                             ; IF #0 -->30$
25$:    MOVB    #3,D1                           ; =0 NO GOOD / MOV PARAMETER #->D1
        JMP     ERROR$

; THE BELOW CALCS A DELAY FACTER RESLITVE TO THE NUMBER OF CHARACTERS 
; IN THE ACTUAL STRING

30$:    CMPW    D0,#100.                        ; MAX 100 RELATIVE SCROLL COUNT
        BGT     25$                             ; BR IF GREATER THAN

        MOVW    #405.,D1                        ; SET BASE NUMBER
        MOVW    D5,D2                           ; SAVE # OF CHARACTERS
        MUL     D2,#5.                          ; MUL #23
        SUBW    D2,D1                           ; CALC RELATIVE VALUE
        MUL     D0,#20.                         ; CALC DELAY RELATIVE FACTOR
        ADDW    D1,D0                           ; CALC ACTUAL DELAY AS CLOCK TICKS

;       WORK ON STRING NEXT

STRING: BYP                                     ; SET A2= BASE ADDR OF STRING
        MOV     A2,A1                           ; SAVE BASE ADDR

10$:    LIN                                     ; CHK FOR EOL
        BEQ     20$
        INC     A2                              ; SKIP AHEAD
        BR      10$
20$:    SUB     #1,A2                           ; SUB ONE FOR ZERO INDEXED
        MOV     A2,D1                           ; MOV TO DATA REGISTER
        MOV     A2,A4                           ; SAVE END OF STRING
        SUB     A1,D1                           ; CALC STR LENGTH
        BNE     40$                             ; IF #0 OK
30$:    MOVB    #4,D1                           ; =0 NO GOOD / MOV PARAMETER # ->D1
        JMP     ERROR$
40$:    CMP     D5,D1                           ; CHK WINDOW LENGTH<= STRING LENGTH
        BGT     WINERR                          ; IF GREATER THAN NO GOOD

        MOV     A1,A2                           ; SET UP SHIFTING ADDR BASE

; THIS SECTION DOSE THE WORK
; TO START
;       A0= TEMP WORK REGISTER                  D0= DELAY (CLOCK TICKS)
;       A1= STRING BASE ADDR (CONSTANT)         D1= CHARACTER TO BE OUTPUT
;       A2=   "     "    "   (SHIFTING)         D2= CHARACTERS TO OUTPUT (QTY)
;       A3= PARAMETER BASE ADDR                 D3= LOOP COUNT
;       A4= STRING END ADDR                     D4= TEMP WORK REGISTER
;       A5=                                     D5= WINDOW LENGTH

        MOV     #29.+177400,D1                  ;TURN CURSOR OFF
        TCRT

PARTA:  MOV     A4,D2                           ; COPY STR END
        ADD     #1,D2                           ; ADD 1 FOR ZERO RELATIVE
        SUB     A2,D2                           ; CALC CHARACTERS LEFT IN STRING
        CMP     D5,D2                           ; CMP W/WINDOW SIZE
        BGE     10$                             ; IF WIN SIZE>CHAR LEFT
        MOV     D5,D2                           ; FORCE (WINDOW LENGTH) CHARACTERS OUTPUT ->D2

10$:    MOV     A2,A0                           ; SET A0=ADDR OF FIRST CHAR TO BE OUTPUT FOR SBR CALL
        MOV     D2,D4                           ; SET D4=CHAR COUNT FOR SBR CALL
        CALL    TYPWIN                          ; CALL SBR TO OUTPUT STRING
        CMP     D2,D5                           ; TEST FOR PARTIAL WINDOW PRINTED (IE CHAR OUTPUT< WINDOW SIZE)
        JGE     LOPEND                          ; IF GT OR EQ DO NEXT

; ONLY A PARTIAL WINDOW WAS OUTPUT NOW OUTPUT THE REST (WHICH IS AT THE BEGINING OF THE STRING)

        MOV     D5,D4                           ; GET COPY OF TRUE WINDOW LENGTH ->D4
        SUB     D2,D4                           ; SUBTRACT QTY OF CHAR ALREADY OUTPUT
                                                ; ->D4 =QTY OF CHAR REMAINING TO BE OUTPUT
        MOV     A1,A0                           ; SET A0=ADDR OF FIRST CHAR TO BE OUTPUT FOR SBR CALL
        CALL    TYPWIN                          ; CALL SBR TO OUTPUT STRING

LOPEND: CTRLC   ALLOVR                          ; TEST FOR ^C
        SLEEP   D0                              ; SLEEP FOR CLOCK TICKS IN D0
        CALL    BACKUP                          ; SBR TO POSITION CURSOR AT BEGINING OF WINDOW
        INC     A2                              ; INC SHIFTING STR BASE ADDR
        CMP     A2,A4                           ; CMP NEW TEMP BASE ADDR W/ STR END ADDR
        BLE     PARTA                           ; IF NEW STR BASE<=STR END DO IT AGAIN

RESET:  DEC     D3                              ; DEC LOOP COUNT
        BLE     ALLOVR                          ; IF LOOP COUNT=0 WE'RE FINISHED
        MOV     A1,A2                           ; RESET SHIFTING BASE=TRUE STRING BASE
        BR      PARTA                           ; DO ANOTHER LOOP

ALLOVR: MOV     #28.+177400,D1                  ; TURN CURSOR ON
        TCRT
        EXIT                                    ; WE ARE FINISHED GO BACK TO BASIC

; SBR TO OUTPUT A STRING INDEXED

WINLOP: MOVB    (A0)+,D1                        ; MOV CHAR TO BE OUTPUT TO D1
        TOUT                                    ; SPIT IT OUT
TYPWIN: DBF     D4,WINLOP                       ; DEC BRANCH COUNT / FINISH IF =0
        RTN                                     ; GO BACK

; SBR TO BACKUP TO BEGINING OF STRING

BACKUP: MOV     D5,D2                           ; SET BACKUP COUNT ->D2
        SUB     #1.,D2                          ; PRE-DEC FOR DBF

10$:    TTYI                                    ; OUTPUT #8 DECIMAL (LEFT ARROW)
        BYTE    8.,0
        DBF     D2,10$                          ; DEC BRANCH COUNT / FIN IF =0
        RTN

        ASCII   / Copyright (c) 1985 JEFF STUYVESANT/
        EVEN


; ERROR PRINTING RTN

ERROR$: TYPE    <Parameter #>
        DCVT    0,OT$TRM!OT$LSP!OT$TSP          ; OUTPUT PARAMETER # AS DECIMAL W/LEAD SP & TRAIL SP
        TYPE    <is in ERROR>
        CRLF
        CRLF    
        TYPECR  <    #1 = Window size>
        TYPECR  <    #2 = Loop Count>
        TYPECR  <    #3 = Delay Factor (1-100)>
        TYPECR  <    #4 = String>
ERR$:   SLEEP   #10000.                         ; INSURE THEY WILL SEE THIS MESSAGE
        EXIT

        END