****************************************************************************
*  Programme : JAFVK.asm                                                   *
*  Usage     : JAFVK                                                       *
*  Version   : V3.00                                                       *
*  Date      : 30.01.1990 - 06.02.1990                                     *
*  Author    : Jörg Sixt                                                   *
*  Purpose   : - prints and deletes reset-vectors (latter only if you      *
*                really want to)                                           *
*              - looks out for the 'Revenge of the Lamer Exterminator'     *
*              - Checks its own length to warn you against link virus      *
*  Language  : A68K-Assembler,Blink from Fish 110                          *
*  Bugs      :                                                             *
****************************************************************************

             SECTION BEGIN,CODE

OWNLENGTH:   EQU      1372
* ^-- if you change the programme/length correct this constant
EXECBASE:    EQU      $4
OPENLIBRARY: EQU     -$228
CLOSELIBRARY: EQU    -$19E
OUTPUT:      EQU     -$3C
INPUT:       EQU     -$36
OPEN:        EQU     -$1E
CLOSE:       EQU     -$24
WRITE:       EQU     -$30
READ:        EQU     -$2A
EXAMINE:     EQU     -$66
LOCK:        EQU     -$54
UNLOCK:      EQU     -$5A
CSI:         EQU      $9B
SHAREDLOCK:  EQU     -$2
MODE_READWRITE: EQU    1005

* OPENLIB    LibName,LibBase,Errorlabel
OPENLIB:     MACRO
             lea      \1,a1
             moveq    #0,d0
             jsr      OPENLIBRARY(a6)
             move.l   d0,\2
             beq      \3
             ENDM
* CLOSELIB   LibBase
CLOSELIB:    MACRO
             move.l   \1,a1
             jsr      CLOSELIBRARY(a6)
             ENDM
* PRINT      BufferPtr,length
PRINT:       MACRO
             move.l   Outhandle,d1
             move.l   \1,d2
             move.l   \2,d3
             jsr      WRITE(a5)
             ENDM
* ASK        noLabel
ASK:         MACRO
             move.l   Inhandle,d1
             move.l   #Buffer,d2
             move.l   #2,d3
             jsr      READ(a5)
             cmp.b    #2,d0
             bne      \1
             move.b   #'y',d0
             cmp.b    Buffer,d0
             bne      \1
             ENDM

* Initialize variables
Begin:       move.l   EXECBASE,a6
             OPENLIB  Dosname,Dosbase,End
             move.l   Dosbase,a5
             jsr      INPUT(a5)
             move.l   d0,Inhandle
             beq      CloseDOS
             jsr      OUTPUT(a5)
             move.l   d0,Outhandle
             beq      CloseDOS
             PRINT    #Headline,#65

* PART I
* Displays and deletes reset-vectors
Vectors:     lea      firsta0,a0
             lea      VecOffset,a1
             moveq    #5,d0
* fetch reset vectors and turn them into a
* sedidecimal number
VecLoop:     move.w   (a1)+,d1
             move.l   0(a6,d1.w),d2
             beq.s    zero
             move.b   #1,Used
zero:        move.l   #7,d3
HexLoop:     rol.l    #4,d2
             move.b   d2,d4
             and.b    #$f,d4
             cmp.b    #9,d4
             ble.s    noadd
             add.b    #7,d4
noadd:       add.b    #48,d4
             move.b   d4,(a0)+
             dbf      d3,HexLoop
             adda.l   #33,a0
             dbf      d0,VecLoop
* Prints vectors and asks whether the
* vectors are to be deleted (only if
* they aren't already zero) or not
             PRINT    #VecText,#246
             move.b   Used,d0
             beq      KillRLE
             PRINT    #DelVecMess,#32
             ASK      #KillRLE
             lea      VecOffset,a1
             move.l   #5,d0
ZeroLoop:    move.w   (a1)+,d1
             move.l   #0,0(a6,d1.w)
             dbf.s    d0,ZeroLoop

* The following part checks the existence
* of the 'Revenge of the Lamer Exterminator'
* (=RLE)  ^              ^     ^
KillRLE:     move.l   #sssName,d1
             move.l   #MODE_READWRITE,d2
             jsr      OPEN(a5)
             move.l   d0,sssHandle
             beq      openError

             move.l   sssHandle,d1
             move.l   #Buffer,d2
             move.l   #5,d3
             jsr      READ(a5)

             lea      RLE,a0
             lea      Buffer,a1
             move.l   #4,d0
CompareLoop: cmpm.b   (a0)+,(a1)+
             bne.s    sssClose
             dbf.s    d0,CompareLoop

             PRINT    #RLEMess,#95
             bsr.s    sssClose
             move.l   #30,d0
             rts

sssClose:    move.l   sssHandle,d1
             jsr      CLOSE(a5)

* Am I too long ?? Could be one of these
* damned link virus
CheckLength: move.l   #OwnName,d1
             move.l   #SHAREDLOCK,d2
             jsr      LOCK(a5)
             move.l   d0,-(a7)
             beq      lockError

             move.l   (a7),d1
             move.l   #VecOffset,d2
             jsr      EXAMINE(a5)
             tst.l    d0
             beq      examError

             lea      VecOffset,a0
             move.l   124(a0),d0
             cmp.l    #OWNLENGTH,d0
             beq      UnLockMe
             PRINT    #LinkVirMess,#57
UnLockMe:    move.l   (a7)+,d1
             jsr      UNLOCK(a5)

* A happy end, but not for the virus-community
CloseDOS:    CLOSELIB Dosbase
End:         move.l   #0,d0
             rts

* Error-handle routines
openError:   PRINT    #openErrMess,#29
             bra      CheckLength
lockError:   PRINT    #lockErrMess,#26
             move.l   (a7)+,d1
             bra      CloseDOS
examError:   PRINT    #lockErrMess,#26
             bra      UnLockMe

             SECTION  VARS,BSS
             even
Dosbase:     ds.l     1
Outhandle:   ds.l     1
Inhandle:    ds.l     1
sssHandle:   ds.l     1
Buffer:      ds.b     5
Used:        ds.b     1

             SECTION  CONST,DATA
             even
Dosname:     dc.b     'dos.library',0
             even

VecOffset:   dc.w     42,46,50,546,550,554
VecText:     dc.b     CSI,'1;33;40mColdCapture  ',CSI,'0;31;40m$'
firsta0:     dc.b     '00000000',10
             dc.b     CSI,'1;33;40mCoolCapture  ',CSI,'0;31;40m$00000000',10
             dc.b     CSI,'1;33;40mWarmCapture  ',CSI,'0;31;40m$00000000',10
             dc.b     CSI,'1;33;40mKickMemPtr   ',CSI,'0;31;40m$00000000',10
             dc.b     CSI,'1;33;40mKickTagPtr   ',CSI,'0;31;40m$00000000',10
             dc.b     CSI,'1;33;40mKickCheckSum ',CSI,'0;31;40m$00000000',10
Headline:    dc.b     CSI,'3;32;40mJAFVK V3.00 by Jörg Sixt (c) by s.a.s. in 1990',CSI,'0;33;40m',10
DelVecMess:  dc.b     'Shall I delete the vectors?(y/n)'
sssName:     dc.b     'S:Startup-Sequence',0
RLE:         dc.b     $A0,$A0,$A0,$A0,$A0,0
RLEMess:     dc.b     'This Disk is infected with the "Revenge of the',10
             dc.b     'Lamer Exterminator". Use "KillRLE" to kill him.',10
OwnName:     dc.b     'C:JAFVK',0
LinkVirMess: dc.b     'I`ve grown larger!!',10
             dc.b     'I may be infected with a link virus.',10
openErrMess: dc.b     'Can`t open startup-sequence!',10
lockErrMess: dc.b     'Can`t determine my length',10
             END
