
; Assembler: DevPac 2.14

; use Tab 11

; *****  Revision History  *****
;
;	V1.0	testet auf NTSC- / PAL-Display
;		testet Vectoren Cool, Cold, KickMemPtr,
;		KickTagPtr, KickCheckSumPtr
;		 --> einer ungleich NULL --> rote CopperList
;		 --> alle NULL --> grüne CopperList
;	V1.1	wie 1.0
;		statt roter CopperList ein Alert, der die
;		Werte als Hex anzeigt
;	V1.2	wie V1.1, aber Code optimiert


	opt	o+,p+

; *****  MemTest-Bootblock V1.2  *****

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	

; -----  MemTest-Routine
	
.own_boot	movem.l	d0-d7/a0-a6,-(sp)
	cmp.b	#50,530(a6)	; NTSC-Display ?? (PAL -> 50Hz)
	bne	.softreset
	cmp.l	#0,42(a6)		; ColdCapture
	bne	.vecs_bad
	cmp.l	#0,46(a6)		; CoolCapture
	bne	.vecs_bad
	cmp.l	#0,546(a6)		; KickMemPtr
	bne	.vecs_bad
	cmp.l	#0,550(a6)		; KickTagPtr
	bne	.vecs_bad
	cmp.l	#0,554(a6)		; KickCheckSumPtr
	bne	.vecs_bad

; -----  grüne CopperListe ausgeben, warten und BB beenden

.vecs_ok	move.l	#cop_end-cop_start,d0
	moveq	#2,d1
	jsr	-198(a6)		; _LVOAllocMem
	lea	cop_adress(pc),a0
	move.l	d0,(a0)
	beq.s	.back_1
	lea	cop_start(pc),a0
	move.l	cop_adress(pc),a1
	move.l	#cop_end-cop_start-1,d0
.cl_copy	move.b	(a0)+,(a1)+
	dbf	d0,.cl_copy
	jsr	-132(a6)		; _LVOForbid
	lea	$dff000,a5
	move.w	#$03a0,$96(a5)	; DMACON
	move.l	cop_adress(pc),$80(a5) ; COP1LCH
	move.w	#0,$88(a5)		; COPJMP1
	move.w	#$8280,$96(a5)	; DMACON
	moveq	#$c,d1
	move.l	#$ffff,d0
.wait_loop	nop			; Warteschleife (Polling)
	dbra	d0,.wait_loop
	dbra	d1,.wait_loop
	lea	gfx_lib(pc),a1
	moveq	#33,d0
	jsr	-552(a6)		; _LVOOpenLibrary
	move.l	d0,a4
	move.l	38(a4),$80(a5)	; COP1LCH
	move.w	#0,$88(a5)		; COPJMP1
	move.w	#$83e0,$96(a5)	; DMACON
	jsr	-138(a6)		; _LVOPermit
	move.l	cop_adress(pc),a1
	move.l	#cop_end-cop_start,d0
	jsr	-210(a6)		; _LVOFreeMem
.back_1	movem.l	(sp)+,d0-d7/a0-a6
	rts

; -----  Alert mit Meldung & Vektoren ausgeben

.vecs_bad	lea	bad_text(pc),a1
	adda.l	#71,a1
	move.l	42(a6),d0		; ColdCapture
	bsr	.bbbin2hex
	adda.l	#36,a1
	move.l	46(a6),d0		; CoolCapture
	bsr	.bbbin2hex
	adda.l	#27,a1
	move.l	546(a6),d0		; KickMemPtr
	bsr	.bbbin2hex
	adda.l	#36,a1
	move.l	550(a6),d0		; KickTagPtr
	bsr	.bbbin2hex
	adda.l	#33,a1
	move.l	554(a6),d0		; KickCheckSumPtr
	bsr	.bbbin2hex
	adda.l	#35,a1
	move.l	300(a6),d0		; ResModules
	bsr	.bbbin2hex

	lea	int_lib(pc),a1
	moveq	#33,d0
	jsr	-552(a6)		; _LVOOpenLibrary
	move.l	d0,a6
	beq.s	.back_2
	lea	bad_text(pc),a0
	moveq	#1,d0
	moveq	#95,d1
	jsr	-90(a6)		; _LVODisplayAlert
	cmp.l	#0,d0
	beq.s	.coldreset
	move.l	a6,a1
	move.l	4.w,a6
	jsr	-414(a6)		; _LVOCloseLibrary
.back_2	movem.l	(sp)+,d0-d7/a0-a6
	rts

; -----  ColdReset ausführen 

.coldreset	move.l	4.w,a6
	jsr	-132(a6)		; _LVOForbid

	move.l	#0,38(a6)		; Exec_ChkBase
	move.l	#0,42(a6)		; ColdCapture
	move.l	#0,46(a6)		; CoolCapture
	move.l	#0,82(a6)		; Exec_ChkSum
	move.l	#0,300(a6)		; ResModules
	move.l	#0,546(a6)		; KickMemPtr
	move.l	#0,550(a6)		; KickTagPtr
	move.l	#0,554(a6)		; KickCheckSumPtr
	
; -----  Soft-Reset ausführen 
	
.softreset	jsr	-150(a6)		; _LVOSuperState
	move.l	#$fc0002,$20.w
	movea.l	#$f80002,a0
	reset			; reservierter Befehl (SuperVisor)
	jmp	(a0)		; an Reset-Routine springen

; -----  Bin -> Hex Konvertieren der Werte in d0.l nach a1

.bbbin2hex	adda.l	#8,a1
	lea	hextab(pc),a0
	moveq	#7,d1
.loop	move.l	d0,d2
	and.l	#15,d2
	move.b	(a0,d2),-(a1)
	lsr.l	#4,d0
	dbra	d1,.loop
	rts

; -----  CopperList

cop_start	dc.w	$180,$00d0		; hellgrün
	dc.w	$7007,$fffe
	dc.w	$180,$0080		; grün
	dc.w	$d00d,$fffe
	dc.w	$180,$0040		; dunkelgrün
	dc.w	$ffff,$fffe
cop_end

; -----  Variablen/Konstanen

cop_adress	dc.l	0

hextab	dc.b	"0123456789ABCDEF"

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

bad_text	dc.b	0,128,15
	dc.b	"Some of your Vectors are not pointing to zero !!"
	dc.b	0,$ff,0,80,40
	dc.b	"ColdCapture:                        CoolCapture:           "
	dc.b	0,$ff,0,80,50
	dc.b	"KickMemPtr:                         KickTagPtr:            "
	dc.b	0,$ff,0,80,60
	dc.b	"KickCheckSumPtr:                    ResModulesBase:           "
	dc.b	0,$ff,0,24,85
	dc.b	"* [LMB] to continue *                               * [RMB] to ColdReset *"
	dc.b	0,0

	dc.b	0,"** MemTest V1.2 - 1993 by Jens Troeger **"

bootcode_end

	end

