;	 S_INSTALL V1.0 SOURCE 

; Note: In case there are no parameters, i'll take B0

;  I recommend to assemble using opt O. (MasterSeka)
;  You can put your own program at Boot but don't make it
;  too long, as I'll write only 2 sectors. (DON'T change THAT!!!)
;  Also change the checksum !

;   Unchangeable program registers:
; D7 = Control
;   Bit 0-1   Two bits specifying unit
;	2     Noboot	; if not set, this means Normal 
;	3-31  Undefined
; A5 = BB startadress
; A6 = Execbase

moveq	#0,d7		; clear control
move.l	$4.w,a6
subq	#1,d0		; remove return
beq.s	NoParameters	; as it says

bclr	#5,(a0)		; capital letters (ie. 'n' gets 'N"')
cmp.b	#'B',(a0)
beq.s	Checkunit	; bit 2 is already cleared
cmp.b	#'N',(a0)
bne	error
addq	#4,d7		; set bit 2

CheckUnit:
move.w	(a0),d0
sub.b	#$30,d0		; ASCII 50 will be Unit 2
and.b	#3,d0
add.b	d0,d7

; If N2 THEN D7 = %110
 
NoParameters:
move.w	#1136,d0
move.l	#$10003,d1	; chip/public/clear
jsr	-198(a6)
move.l	d0,a5		; no check. (1136=0.2% of memory...)

move.l	#'DOS'*256,(a5)+; DOS goes 2 places left and to A5
btst	#2,d7
beq.s	Normal		; if DOS then goto Normal

bra.s	Abnormal	; else goto Abnormal

Normal:
lea	Boot(pc),a0
move.l	a5,a1
moveq	#length,d0

Looping:
move.w	(a0)+,(a1)+
dbra	d0,Looping

Abnormal:
subq	#4,a5		; reset BB-start
bra.s	WriteBB		; ready!

WriteBB:
move.l	a5,a4
add.l	#1024,a4	; in A4 is the replyport
move.l	a4,a3
add.l	#32,a3		; in A3 is the IOstdreq (or something...)

move.l	$4.w,a6
sub.l 	a1,a1		; This means ZERO...
jsr	-294(a6)
move.l	d0,16(a4)

move.l	a4,a1
jsr	-354(a6)

move.l 	a3,a1
move.l	d7,d0
and.b	#3,d0
clr.l	d1
lea	trd(pc),a0
jsr	-444(a6)
tst.l	d0
bne.s	error

move.l	a3,a1
move.l	a4,14(a1)
move	#3,28(a1)
move.l	a5,40(a1)
move.l	#1024,36(a1)
clr.l	44(a1)
jsr	-456(a6)

move.l	a3,a1
move	#4,28(a1)	;update
jsr	-456(a6)

move.l	a3,a1
move	#9,28(a1)
move.l	#0,36(a1)
jsr	-456(a6)

move.l	a4,a1
jsr	-360(a6)

move.l	a3,a1
jsr	-450(a6)

move.l	a5,a1
move.w	#1136,d0
jsr	-210(a6)	; ALWAYS freemem !!!!!

error:
clr.l	d0
rts

trd:	dc.b 'trackdisk.device',0

even
Boot:
dc.l	$c0200f19
dc.l	$370
lea	dn(pc),a1
jsr	-96(a6)
tst.l	d0
beq.s	TooBad
move.l	d0,a0
move.l	22(a0),a0
moveq	#0,d0
End:
rts

TooBad:
moveq	#-1,d0		; this is $ffffffff in one word !!!
bra.s	End		; stupid, but true, they go to rts.

dn:	dc.b 'dos.library',0
Bend:

length = Bend-Boot/2
