; This bootblock installer is no virus...
; it is designed to patch the buserror vector while booting
; if you have the magic button and beermon is located on module
; or at $c00000, this is a good deal.

FindResident    = -96
AllocMem        =-198
FreeMem         =-210
FindTask        =-294
OldOpenLibrary  =-408
CloseLibrary    =-414
OpenDevice      =-444
CloseDevice     =-450
DoIO            =-456

Write           = -48
Output          = -60

run:	move.l 4.w,a6
	sub.l a4,a4		;pointer to memory buffer
	lea DiskIOReq(pc),a3
	moveq #0,d6		;errorflag
	move.l a7,d5
	moveq #1,d4		;disk open flag 0=ok

	moveq #0,d0
	lea dosname(pc),a1
	jsr OldOpenLibrary(a6)
	move.l d0,a5
	tst.l d0
	beq.l error
	move.l #$10003,d1
	move.l #1024,d0		;2 blocks: 2*512 byte
	jsr AllocMem(a6)
	tst.l d0
	beq.s shit
	move.l d0,a4

	moveq #0,d2		;chksum
	moveq #bootsize/4-1,d0
	move.l a4,a1		;the sick buffer
	lea bootstart(pc),a0
l0:	move.l (a0)+,d1
	move.l d1,(a1)+		;move the gore
	add.l d1,d2		;calc a bit
	bcc.s l1		;no jesus here
	addq.l #1,d2
l1:	dbf d0,l0

	not.l d2
	move.l d2,4(a4)		;chksum to buf
	sub.l a1,a1		;trackdiskport init
	jsr FindTask(a6)
	lea DiskPort(pc),a0
	move.l d0,16(a0)

	moveq #device,d0	;trackdiskdevice (df1)
	moveq #0,d1
	move.l a3,a1
	lea diskname(pc),a0
	jsr OpenDevice(a6)
	move.l d0,d4		;some error
	bne.s shit

	move.l a3,a1
	move.l a4,40(a1)	;diskbuf
	jsr DoIO(a6)
	tst.l d0
	bne.s shit

	move.l a3,a1
	move.w #4,28(a1)	;write the gore
	jsr DoIO(a6)
	tst.l d0
	bne.s shit

	move.l a3,a1
	move.w #9,28(a1)	;motor off
	clr.l 36(a1)
	jsr DoIO(a6)
	tst.l d0
	beq.s allesok

shit:	move.l d0,d6		;sick errors?
	lea fehler(pc),a0
	move.l a0,a1
	move.l a0,d3
l2:	tst.b (a0)+
	bne.s l2
	sub.l d3,a0
	move.l a0,d3
	subq.l #1,d3		;length
	move.l a1,d2		;text
	jsr Output(a5)
	move.l d0,d1		;filehandle
	jsr Write(a5)

allesok:move.l a5,a1
	jsr CloseLibrary(a6)

	move.l a4,d0
	beq.s l3
	move.l d0,a1
	move.l #1024,d0
	jsr FreeMem(a6)

l3:	tst.l d4
	bne.s l4
	move.l a3,a1
	jsr CloseDevice(a6)
l4:	move.l d6,d0
	move.l d5,a7
error:	rts

device = 1
bootstart:
	dc.b "DOS",0
	dc.l 0			;chksum
	dc.l 880		;root block

	lea $f00000,a1
	cmp.w #$1111,(a1)+	;any module with beermon?
	beq.s modf0
	lea $c00000,a1		;if not, he shall be here...
modf0:	move.l a1,$8.w
	
	lea $dff180,a1
	moveq #-1,d0
blink:	move.w d0,(a1)		;blinkabit
	dbf d0,blink
	clr.w (a1)

	lea dosname(pc),a1	;the reek of putreficaton
	jsr FindResident(a6)	;any dos at home?
	tst.l d0
	beq.s lb
	move.l d0,a0
	move.l 22(a0),a0
	moveq #0,d0
la:	rts
lb:	moveq #-1,d0
	bra.s la

DosName:dc.b "dos.library",0
	dc.b "this bootblock has been installed with  "
	dc.b "vomit and gore by BeerMacht "
	dc.w 0
bootend:
bootsize = bootend-bootstart

diskname:	dc.b "trackdisk.device",0
fehler:		dc.b "Disk in DF1: was NOT installed",$A,0
even

DiskPort:	dc.l 0		;0
		dc.l 0		;4
		dc.w $0400	;8
		dc.l 0		;10
		dc.b 0		;14
		dc.b 31		;15
		dc.l 0		;16	task ptr.
LH1:		dc.l LH2	;20
LH2:		dc.l 0		;24
		dc.l LH1	;28
		dc.b 0		;32
		dc.b 0		;33

DiskIOReq:	dc.l 0		;0
		dc.l 0		;4
		dc.b 5		;8
		dc.b 0		;9
		dc.l 0		;10
		dc.l DiskPort	;14
		dc.w 48		;18
		dc.l 0		;20
		dc.l 0		;24
		dc.w 3		;28 IO_CMD
		dc.w 0		;30
		dc.l 0		;32
		dc.l 1024	;36 IO_LENGTH
		dc.l 0		;40 IO_DATA
		dc.l 0		;44 IO_OFFSET
		dc.l 0
		dc.l 0

