
*****************************************************************************
* 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                                                                 *
*                                                                           *
* E-Mail: Anthony.Peck@Radford.act.edu.au                                   *
*                                                                           *
*****************************************************************************
* Summary                                                                   *
* -------                                                                   *
*                                                                           *
* Usage: Delay <secs>                                                       *
*                                                                           *
* 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.                                     *
*                                                                           *
*****************************************************************************

; Some Quick equivalents...

ExecBase                = $04      ; Exec Base...ahem
LF                      = $0A      ; ASCII character (Line Feed) 
SZMess                  = $3C      ; 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
_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 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 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              ;

        END


