
*****************************************************************************
* Project Details                                                           *
* ---------------                                                           *
* Project Name:    AIO                                                      *
* Project Version: 1                                                        *
* Copyright:       Anthony N Peck                                           *
* Date:            Sunday 28th May 1995                                     *
*                                                                           *
* Contact:                                                                  *
* 68 Woralul St                                                             *
* Waramanga ACT 2611                                                        *
* Australia                                                                 *
*                                                                           *
* E-Mail: Anthony.Peck@Radford.act.edu.au                                   *
*                                                                           *
*****************************************************************************
* Summary                                                                   *
* -------                                                                   *
*                                                                           *
* Usage: AIO <secs> <text>                                                  *
*                                                                           *
* This is a very unusual program in that it is a combination of existing    *
* tools, all of which are useful in certain types of script files.  It      *
* just so happens that I lusted (!) after a program that could display a    *
* message, wait a specified time, clear the screen and then return to the   *
* script.  AIO (All In One) does exactly this.  An example of this is as    *
* follows...                                                                *
*                                                                           *
*       AIO 5 Press Left Mouse Button to exit picture...                    *
*                                                                           *
* This would display the message for 5 seconds, then clear the screen.      *
* Without any text, AIO simply waits the specified time and then clears     *
* the screen. Without any arguments, it prints out the argument template.   *
*                                                                           *
* Leading spaces can be specified by enclosing the <text> in quotation      *
* marks.  For example...                                                    *
*                                                                           *
*       AIO 7 "     An elk in the hand is worth two in the bush"            *
*                                                                           *
* ...would output the text with the leading spaces as well.                 *
*                                                                           *
* The program, source code and my everlasting recidivism are yours FREE!    *
*                                                                           *
*****************************************************************************
                     
; Some quick equivalents...

ExecBase                = $04      ; Location of Exec Base!
LF                      = $0A      ; ASCII character (Line Feed) 
SZMess                  = $41      ; Size of error message
_LVOOpenlibrary         = -$0228   ; Exec function opens libraries
_LVOCloselibrary        = -$019E   ; Exec function closes libraries
_LVODelay               = -$C6     ; Dos function causes a delay
_LVOWrite               = -$30     ; Dos function writes
_LVOOutput              = -$3C     ; Dos function finds output handle

; A couple of macros...

EXEC            Macro
        MOVE.L  ExecBase,A6        ; Move Exec into a6
        JSR     _LVO\1(A6)         ; Add Library offset and call function
                Endm

CALLDOS         Macro
        MOVE.L  _DosBase,A6        ; Move Dos into a6
        JSR     _LVO\1(A6)         ; Add Library offset and call function
                Endm

Start:

; The actual program starts here.  The number of supplied parameters is
; found in D0 and the actual parameters are in a list at a location
; found in A0.

        SUBQ.B  #$01,D0            ; Subtract the program from the list
        MOVE.L  D0,D5              ; Move the number remaining to D5
        MOVE.L  A0,A5              ; Move the parameter address to A5

OpenDos:

        LEA     Dosname,A1         ; Load the dos library
        CLR.L   D0                 ; Any version will do
        EXEC    Openlibrary        ; Macro opens library
        BEQ     Exit               ; If there's a problem, close down
        MOVE.L  D0,_DosBase        ; Save the return address

TestParam:

; Here we test to see if we have a number and then convert it from
; ascii to hex

        TST.B   D5                 ; Test if we have any parameters
        BEQ     Error              ; If not then go write the message

        CLR.L   D4                 ; Clear D4 - the actual number
        CLR.L   D5                 ; Clear D5 - the counting register

1$      CLR.L   D0                 ; Clear D0
        MOVE.B  (A5)+,D0           ; Move the first parameter to D0
        CMP.B   #$20,D0            ; Is it a Space?
        BEQ     GoWrite            ; Yep, so finished and outta here ->
        SUB.B   #$30,D0            ; Subtract "0"
        CMP.B   #$0A,D0            ; Compare with the value "10"
        BCC     GoTime             ; Greater than zero, must be a char
        MULU    #$0A,D4            ; Multiply the previous entry by "10"
        ADD     D0,D4              ; Add current number to D4
        BRA     1$                 ; And back for more digital fun...

GoWrite:

; Now we move to the second parameter, which is the text to be "echoed"

        LEA     Echo,A2            ; Load the Echo memory to A2
1$      MOVE.B  (A5)+,D0           ; Move the parameter to D0
        CMP.B   #$22,D0            ; Is it a quote?
        BEQ     1$                 ; Yes! So get another character
        MOVE.B  D0,(A2)+           ; Move char to Echo and increment
        ADDQ.B  #$01,D5            ; Add 1 to counter
        CMP.B   #$50,D5            ; Are we at counter limit
        BEQ     GoTime             ; Yes! So we go ->
        CMP.B   #LF,D0             ; Is it a Line Feed?
        BEQ     GoTime             ; Yes! So we go ->
        BRA     1$                 ; Go back for more digital fun...

GoTime:

; Now we echo the message and wait the specified time

        TST.B   D4                 ; Test if we have a number!
        BEQ     Error              ; Nope...I'm outta here ->
        TST.B   D5                 ; Test if we have any letters
        BEQ     1$                 ; No so skip to timer
        CALLDOS Output             ; Call up the output handle
        MOVE.L  D0,D1              ; Move it to D1
        MOVE.L  #Echo,D2           ; Here's the message to echo
        MOVE.L  D5,D3              ; Here's the number of characters
        CALLDOS Write              ; Write it!
1$      MULU    #$32,D4            ; Multiply number by ticks (50/sec)
        MOVE.L  D4,D1              ; Move the number of seconds to D1
        CALLDOS Delay              ; Call the Delay function

        CALLDOS Output             ; Call the output function
        MOVE.L  D0,D1              ; Shift output handle to D1
        MOVE.L  #Clear,D2          ; Move in "Control L" (Clear character)
        MOVE.L  #$01,D3            ; Just the one thanx
        CALLDOS Write              ; ..and write it 

Close:

        MOVE.L   _DosBase,A1       ; Move dos base into a1
        EXEC     Closelibrary      ; Macro closes dos

Exit:

        CLR.L    D0                ; Clear D0
        RTS                        ; Return To System

Error:

        CALLDOS Output             ; Call the output function
        BEQ     Close              ; No can do so outta here ->
        MOVE.L  D0,D1              ; else shift output handle to D1
        MOVE.L  #Message,D2        ; Load Argument template...
        MOVE.L  #SZMess,D3         ; ...plus the length of the message...
        CALLDOS Write              ; ..and write it  
        BRA     Close              ; I'm gone ->

; Some memory allocations

_DosBase:  

        DS.L    $1                 ; Memory for Dos Base

Echo:

        DS.B    $50                ; Memory for user message - 80 chars

Clear:

        DC.B    $C                 ; Control L - the clear character

Dosname:

        DC.B    "dos.library",$00  ; dos library name

Message:

        DC.B    LF,"    "                  ;
        DC.B    "Usage: [33mAIO[0m"               ;
        DC.B    " <secs> <text> "          ; Text of message
        DC.B    "[32mA N Peck - 1995[0m"          ;
        DC.B    LF,LF                      ;

        END


