*****************************************************************************
* Project Details                                                           *
* ---------------                                                           *
* Project Name:    Delay                                                    *
* Project Version: 1                                                        *
* Copyright:       Anthony N Peck                                           *
* Date:            Sunday 21st May 1995                                     *
*                                                                           *
* Contact:                                                                  *
* 68 Woralul St                                                             *
* Waramanga ACT 2611                                                        *
* Australia                                                                 *
*                                                                           *
*****************************************************************************
* Summary                                                                   *
* -------                                                                   *
* This little program simply goes away and waits the specified time.  Like  *
* WAIT but a lot simpler!  Used in script files, it will enhance your love  *
* life and rid your house of pests.  The program, the source and in fact    *
* my warmest regards are all yours FOC.                                     *
*                                                                           *
* Usage: Delay <secs>                                                       *
*                                                                           *
*****************************************************************************

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

; 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
        Move.L  #$00,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:

; We test the parameter passed and 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   D1                 ; Clear D1
        Clr.L   D0                 ; Clear D0

1$      Clr.L   D0                 ; Clear D0
        Move.B  (A5)+,D0           ; Move the first parameter to D0
        Cmp.B   #LF,D0             ; Is it a LineFeed?
        Beq     GoTime             ; 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,D1            ; Multiply the previous entry by "10"
        Add     D0,D1              ; Add current number to D1
        Bra     1$                 ; And back for more digital fun...

GoTime:

        Tst.B   D1                 ; Test if we have a number!
        Beq     Error              ; Nope...I'm outta here ->
        Mulu    #$32,D1            ; Multiply number by ticks (50/sec)
        Calldos Delay              ; Call the Delay function

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        ; This is the message...
        Move.L  #SZMess,D3         ; ...plus the length of the message...
        Calldos Write              ; ..and write it  
        Bra     Close              ; I'm gone ->

_DosBase:  

        Dc.L    $1                 ; Memory for Dos Base
Dosname:

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

Message:

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

SZMess  = *-Message                ; Size of message

        END
