
; Assembler: DevPac 2.14

; use Tab 11


TAG_USER		equ	$80000000
TAG_DONE		equ	0
WA_Left		equ	TAG_USER+100
WA_Top		equ	TAG_USER+101
WA_Width		equ	TAG_USER+102
WA_Height		equ	TAG_USER+103
WA_Flags		equ	TAG_USER+107
WA_Title		equ	TAG_USER+110
WA_ScreenTitle	equ	TAG_USER+111
WA_MinWidth	equ	TAG_USER+114
WA_MinHeight	equ	TAG_USER+115
WA_MaxWidth	equ	TAG_USER+116
WA_MaxHeight	equ	TAG_USER+117

	opt	o+,p+

*****  CLIPatch--Bootblock V1.1  *****

bootcode	dc.l	$444f5300		; DOS-Disk OFS
	dc.l	$00000000		; CheckSum
	dc.l	$00000370		; RootBlock pointer

; -----  Standart-DOS-Bootcode
	
.dos_boot	lea	exp_lib(pc),a1	; Standard OS2.0 code
	moveq	#37,d0
	jsr	-552(a6)		; _LVOOpenLibrary
	tst.l	d0
	beq.s	.no_explib
	move.l	d0,a1
	bset	#6,34(a1)
	jsr	-414(a6)		; _LVOCloseLibrary
.no_explib	lea	dos_lib(pc),a1
	jsr	-96(a6)		; _LVOFindResident
	tst.l	d0
	beq.s	.not_found
	move.l	d0,a0
	movea.l	22(a0),a0
	moveq	#0,d0
	bra.s	.own_boot
.not_found	moveq	#-1,d0	

; -----  KS-Version testen und entsprechenden Patch installieren
	
.own_boot	movem.l	d0-d7/a0-a6,-(sp)
	cmp.w	#37,$14(a6)	; eb_SoftVer
	blt.s	dos_13

; -----  OpenWindowTagList-Patch installieren (KS 2.0)

dos_20	move.l	#openwd_20_end-openwd_20,d0
	move.l	#$10000,d1
	jsr	-198(a6)		; _LVOAllocMem
	tst.l	d0
	beq.s	.no_mem
	move.l	d0,a5
	lea	int_lib(pc),a1
	moveq	#37,d0
	jsr	-552(a6)		; _LVOOpenLibrary
	move.l	d0,a1
	lea	oldopen_20(pc),a0
	move.l	-606+2(a1),(a0)	; alte Adresse sichern
	move.l	a5,-606+2(a1)	; und eigene eintragen
	lea	openwd_20(pc),a0
	move.l	#openwd_20_end-openwd_20-1,d0
.loop	move.b	(a0)+,(a5)+	; Code copieren
	dbra	d0,.loop
.no_mem	movem.l	(sp)+,d0-d7/a0-a6
	rts

; -----  OpenWindow-Patch installieren (KS 1.3)

dos_13	move.l	#openwd_13_end-openwd_13,d0
	move.l	#$10000,d1
	jsr	-198(a6)		; _LVOAllocMem
	tst.l	d0
	beq.s	.no_mem
	move.l	d0,a5
	lea	int_lib(pc),a1
	moveq	#33,d0
	jsr	-552(a6)		; _LVOOpenLibrary
	move.l	d0,a1
	lea	oldopen_13(pc),a0
	move.l	-204+2(a1),(a0)	; alte Adresse sichern
	move.l	a5,-204+2(a1)	; und eigene eintragen
	lea	openwd_13(pc),a0
	move.l	#openwd_13_end-openwd_13-1,d0
.loop	move.b	(a0)+,(a5)+	; Code copieren
	dbra	d0,.loop
.no_mem	movem.l	(sp)+,d0-d7/a0-a6
	rts

; -----  der OpenWindow-Patch
	
openwd_13	move.w	le_13(pc),(a0)	; Daten in NewWindow-Struktur
	move.w	te_13(pc),2(a0)	; eintragen
	move.w	width_13(pc),4(a0)
	move.w	height_13(pc),6(a0)
	move.l	flags_13(pc),$0e(a0)
	move.l	#0,$1a(a0)
	move.w	nwidth_13(pc),$26(a0)
	move.w	nheight_13(pc),$28(a0)
	move.w	xwidth_13(pc),$2a(a0)
	move.w	xheight_13(pc),$2c(a0)
	move.l	oldopen_13(pc),-204+2(a6)
	jsr	-204(a6)		; _LVOOpenWindow
	movem.l	d0/a0/a1/a2/a6,-(sp)
	move.l	d0,a0
	lea	wdtitle_13(pc),a1
	lea	sctitle_13(pc),a2
	jsr	-276(a6)		; _LVOSetWindowTitles
	movem.l	(sp)+,d0/a0/a1/a2/a6
	rts
	
oldopen_13	dc.l	0

le_13	dc.w	0
te_13	dc.w	0
width_13	dc.w	640
height_13	dc.w	256
flags_13	dc.l	1+2+4+16+4096	; glaub` ich
nwidth_13	dc.w	80
nheight_13	dc.w	64
xwidth_13	dc.w	-1
xheight_13	dc.w	-1
wdtitle_13	dc.b	"AmigaDOS",0,0
	dc.l	0,0,0,0,0,0,0,0,0,0
sctitle_13	dc.b	"Workbench Screen",0,0,0,0
	dc.l	0,0,0,0,0

openwd_13_end

; -----  der OpenWindowTagList-Patch

openwd_20	movem.l	d0/d1/a2/a3,-(sp)
	move.l	a1,a2
	lea	my_tags(pc),a3
	move.l	(a3)+,d1
.tag_loop	move.l	(a2)+,d0
	tst.l	d0
	beq.s	.all_done
	cmp.l	d0,d1
	beq.s	.tag_found
	adda.l	#4,a2
	bra.s	.tag_loop
.tag_found	move.l	(a3)+,(a2)+
	move.l	a1,a2
	move.l	(a3)+,d1
	tst.l	d1
	bne.s	.tag_loop
.all_done	movem.l	(sp)+,d0/d1/a2/a3
	move.l	oldopen_20(pc),-606+2(a6)
	jsr	-606(a6)		; _LVOOpenWindowTagList
	movem.l	d0/a0/a1/a2/a6,-(sp)
	move.l	d0,a0
	lea	wdtitle_20(pc),a1
	lea	sctitle_20(pc),a2
	jsr	-276(a6)		; _LVOSetWindowTitles
	movem.l	(sp)+,d0/a0/a1/a2/a6
	rts

oldopen_20	dc.l	0

my_tags	dc.l	WA_Left,0
	dc.l	WA_Top,0
	dc.l	WA_Width,640
	dc.l	WA_Height,256
	dc.l	WA_Flags,1+2+4+16+4069
	dc.l	WA_MinWidth,80
	dc.l	WA_MinHeight,64
	dc.l	WA_MaxWidth,-1
	dc.l	WA_MaxHeight,-1
	dc.l	TAG_DONE

wdtitle_20	dc.b	"AmigaDOS",0,0
	dc.l	0,0,0,0,0,0,0,0,0,0
sctitle_20	dc.b	"Workbench Screen",0,0,0,0
	dc.l	0,0,0,0,0

openwd_20_end

; -----  Konstanten, Variablen

exp_lib	dc.b	"expansion.library",0
dos_lib	dc.b	"dos.library",0
int_lib	dc.b	"intuition.library",0

bootcode_end

	end

