********************************************************************************
*
*       Program:        Relocate
*       Filename:       TestPar.a
*
*       Contents:       Tests parameter string stored in a0=Ptr and d0=Len
*                       and initializes SFname, DFname and Loc.
*
*       Language:       68000 Assembler
*
*       Author:         Johannes R. Geiss
*
*       Copyright:      Amigavisions
*
********************************************************************************


*------ Includes
        include 'xref.i'
        include 'call.i'
        include 'exec/types.i'
        include 'libraries/dos.i'


*------ Imports
        xref    Exit_Am
        xref    Print
        xref    DOSError
        xref    _exit


*------ Exports
        xdef    TestPar
        xdef    SFname
        xdef    DFname
        xdef    Loc


********************************************************************************

        SECTION TestPar

*------ TestPar procedure
*
* Input: a0.l Pointer to sVar
*        d0.l # of Arguments

TestPar addq.l  #4,a0
        move.l  (a0)+,SFname            ; get source & dest. Filename
        move.l  (a0)+,DFname
        move.l  (a0)+,Loc

        movea.l SFname,a0               ; info ?
        cmpi.b  #'?',(a0)
        bne.s   Cont1
        moveq.l #RETURN_OK,d0
Err1    move.l  d0,-(a7)
        bsr     DOSError
        movea.l #InfoT,a0
        bsr     Print
        bsr     _exit

Cont1   cmpi.b  #4,d0                   ; test syntax
        bcc.s   Cont2
        move.l  #ERROR_INVALID_COMPONENT_NAME,d0
        bra.s   Err1

Cont2   movea.l Loc,a0
        moveq.l #0,d2                   ; get location address
Loop3   move.b  (a0)+,d1
        beq.s   LEnd
        lsl.l   #4,d2
        subi.b  #'0',d1
        bcs     NoPar
        cmpi.b  #10,d1
        bcs.s   NumDig
        andi.b  #$df,d1
        subq.b  #7,d1
        bcs.s   NoPar
NumDig  cmpi.b  #$10,d1
        bcc.s   NoPar
        or.b    d1,d2
        bra.s   Loop3
LEnd    move.l  d2,Loc

        movea.l #Rel,a0                 ; init output
        bsr     Print
        rts

NoPar   movea.l #Synt,a0                ; output: Illegal hex...
        bsr     Print
        moveq.l #RETURN_ERROR,d0
        bra     Exit_Am


********************************************************************************

        section DATA

*------ Datafield
SFname  dc.l    0
DFname  dc.l    0
Loc     dc.l    0
InfoT   dc.b    $0a,$9b,'1;33mReloc V1.4',$9b,'0;33m Copyright (C) 1991/1999,'
        dc.b    ' Amigavisions/JOTD',$9b,'0m',$0a,$0a
        dc.b    'Usage: Reloc SFile DFile Loc',$0a
        dc.b    $09,'SFile: source fileanme,',$0a
        dc.b    $09,'DFile: destination fileanme,',$0a
        dc.b    $09,'Loc:   location address (hex).',$0a,$0a
        dc.b    $09,'Relocates an object file SFile to DFile at address Loc',$0a
        dc.b    $09,'(Order: CODE, DATA, BSS)',$0a,$0a,0
Synt    dc.b    'Illegal hexadecimal input',$0a,0
Rel     dc.b    'relocating...',0

        END
