*****************************************************************************
* 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                                                                 *
*                                                                           *
*****************************************************************************
* Summary                                                                   *
* -------                                                                   *
* 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.   *
*                                                                           *
* The program, source code and my everlasting recidivism are yours FREE!    *
*                                                                           *
* Usage: AIO <secs> <text>                                                  *
*                                                                           *
*****************************************************************************
                     
; Some Quick equivalents...

ExecBase                = $04      ; Exec Base...ahem
LF                      = $0A      ; ASCII character (Line Feed) 
_LVOOpenlibrary         = -$0228   ; Exec function opens libraries
_LVOCloselibrary        = -$019e   ; Exec function closes libraries
_LVODelay               = -$c6     ; Dos function causes a delay
_LVOWrite               = -$30     ; Dos function
_LVOOutput              = -$3C     ; Dos function

; 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...

        Subq.B  #$01,D0            ; Subtract the first parameter
        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

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                      ;

SZMess  = *-Message                        ; Size of message

        END
