
; Assembler: DevPac 2.14

; use Tab 11


*****  Password-Bootblock V1.0  *****

; -----  Vielen Dank an Frederic Thiesse für die Interrupt-Routine

bootcode	dc.l	$444f5300
	dc.l	$00000000
	dc.l	$00000370

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

.alloc_mem	move.l	#360+12+100+108,d0	; BitPlane+BitMap+RastPort+CopperList
	move.l	#$10002,d1
	jsr	-198(a6)		; _LVOAllocMem
	tst.l	d0
	beq	.dos_boot
	move.l	d0,d7

.open_gfx	lea	gfx_lib(pc),a1
	moveq	#33,d0
	jsr	-552(a6)		; _LVOOpenLibrary
	tst.l	d0
	beq	.free_mem
	move.l	d0,a6

	move.l	d7,a1
	adda.l	#360+12,a1
	jsr	-198(a6)		; _LVOInitRastPort

	move.l	d7,a0
	adda.l	#360,a0
	moveq	#1,d0
	move.l	#320,d1
	moveq	#9,d2
	jsr	-390(a6)		; _LVOInitBitMap

	move.l	d7,a0
	adda.l	#360+12,a0		; Strukturen verbinden
	move.l	d7,a1
	adda.l	#360,a1
	move.l	d7,a2
	move.l	a1,$04(a0)
	move.l	a2,$08(a1)

	move.l	d7,a1
	adda.l	#360+12,a1
	moveq	#52,d0
	moveq	#6,d1
	jsr	-240(a6)		; _LVOMove
	move.l	d7,a1
	adda.l	#360+12,a1
	lea	password(pc),a0
	moveq	#21,d0
	jsr	-60(a6)		; _LVOText

	moveq	#107,d0
	move.l	d7,a0
	adda.l	#360+12+100,a0
	move.l	a0,a2
	lea	coplist(pc),a1
.loop	move.b	(a1)+,(a0)+
	dbf	d0,.loop

	move.l	d7,d0
	move.w	d0,46(a2)		; BitPlane-Zeiger in
	swap	d0		; BPL1PTH / BPL1PTL
	move.w	d0,42(a2)		; schreiben (s.u.)

	lea	$dff000,a0
	move.l	a2,$080(a0)	; COP1LCH
	move.w	#0,$088(a0)	; COPJMP1
	move.w	#$8300,$096(a0)	; DMACON

; -----  über Interrupt die Daten von der Tastatur einlesen

	movem.l	d0-d7/a0-a6,-(sp)
	
	move.w	$dff01c,d0		; INTENAR (Interrupts aus)
	ori	#$8000,d0
	move.w	d0,d7
	move.w	#$7fff,$dff09a	; INTENA
	
	move.l	104,d6		; orig. Vektor sichern...
	lea	.get_key(pc),a0
	move.l	a0,104		; ...und eigenen eintragen
	
	move.w	#$c008,$dff09a	; INTENA (Interrupts an)
	move.l	key_count(pc),d1
	lea	key_table(pc),a4
.key_loop	btst	#0,d5		; Wurde Taste gedrückt ?
	beq.s	.key_loop
	move.b	d4,d0		; RAW-Code holen
	bclr	#0,d5
	move.b	(a4),d2
	cmp.b	d2,d0		; War`s die richtige Taste ?
	bne.s	.key_loop		; nö
	adda.l	#1,a4		; jau
	dbra	d1,.key_loop

	move.w	#$7fff,$dff09a	; INTENA (Interrupts aus)
	move.l	d6,104		; orig. Int-Vektor eintragen
	move.w	d7,$dff09a		; INTENA (Interrupts an)

	movem.l	(sp)+,d0-d7/a0-a6

; -----  orig. CopperList eintragen, ordentlich beenden & Standartboot
	
	move.l	d7,a1
	adda.l	#360+12,a1
	moveq	#52,d0
	moveq	#6,d1
	jsr	-240(a6)		; _LVOMove
	move.l	d7,a1
	adda.l	#360+12,a1
	lea	ok_pw(pc),a0
	moveq	#21,d0
	jsr	-60(a6)		; _LVOText

	move.l	d7,a0
	adda.l	#360+12+100,a0
	move.l	a0,a2
	move.w	#$0040,50(a0)	; COLOR00 (dunkelgrün)
	move.w	#$00f0,54(a0)	; COLOR01 (knallgrün)
	
	lea	$dff000,a0
	move.l	a2,$080(a0)	; COP1LCH
	move.w	#0,$088(a0)

	move.w	#$ffff,d0
	move.w	#$000a,d1
.wait	nop
	dbra.w	d0,.wait
	dbra.w	d1,.wait

	move.l	$26(a6),$080(a0)	; COP1LCH
	move.w	#0,$088(a0)

.close_gfx	move.l	a6,a1
	move.l	4.w,a6
	jsr	-414(a6)		; _LVOCloseLibrary

.free_mem	move.l	d7,a1
	move.l	#360+12+100+108,d0
	jsr	-210(a6)		; _LVOFreeMem

	jsr	-138(a6)		; _LVOPermit

; -----  Standart DOS-Bootcode

.dos_boot	lea	exp_lib(pc),a1
	moveq	#37,d0
	jsr	-552(a6)		; _LVOOpenLibrary
	tst.l	d0
	beq.s	.no_explib
	movea.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
	movea.l	d0,a0
	movea.l	22(a0),a0
	moveq	#0,d0
	rts
.not_found	moveq	#-1,d0
	rts

; -----  Interrupt-Routine

.get_key	move.l	d0,-(a7)
	move.w	#8,$dff09c		; INTREQ
	btst	#3,$bfed01		; CIA-A ICR
	bne.s	.get_key2
	move.b	$bfec01,d0		; CIA-A SP -> Tastencode holen
	ror.b	#1,d0		; und RAW-Code berechnen
	eori.b	#$ff,d0
	bmi.s	.get_key1		; Taste losgelassen ?
	btst	#0,d5		; Schon Code gespeichert ?
	bne.s	.get_key1
	move.b	d0,d4		; Code speichern
	bset	#0,d5
.get_key1	move.b	#$ff,$bfec01	; CIA-A SP (Tastaturleitung auf 0)
	bset	#6,$bfee01		; CIA-A CRA
	bclr	#6,$bfee01		; CIA-A CRA
.get_key2	move.b	$bfed01,d0		; CIA-A ICR
	move.l	(a7)+,d0
	rte

; ----- wenn eine falsche Taste gedrückt wurde...

.wrong_key	movem.l	(sp)+,d0-d7/a0-a6

	move.l	d7,a1
	adda.l	#360+12,a1
	moveq	#52,d0
	moveq	#6,d1
	jsr	-240(a6)		; _LVOMove
	move.l	d7,a1
	adda.l	#360+12,a1
	lea	wrong_pw(pc),a0
	moveq	#21,d0
	jsr	-60(a6)		; _LVOText

	move.l	d7,a0
	adda.l	#360+12+100,a0
	move.l	a0,a2
	move.w	#$0400,50(a0)	; COLOR00 (dunkelrot)
	move.w	#$0f00,54(a0)	; COLOR01 (knallrot)
	
	lea	$dff000,a0
	move.l	a2,$080(a0)	; COP1LCH
	move.w	#0,$088(a0)

.wait4ever	bra.s	.wait4ever

; ----- CopperList, Variablen & Konstanten

coplist	dc.w	$2001,$fffe
	dc.w	$0100		; BPLCON0
	dc.w	$0200
	dc.w	$008e		; DIWSTRT
	dc.w	$0581
	dc.w	$0090		; DIWSTOP
	dc.w	$40c1
	dc.w	$0092		; DDFSTRT
	dc.w	$0038
	dc.w	$0094		; DDFSTOP
	dc.w	$00d0
	dc.w	$0102		; BPLCON1
	dc.w	$0000
	dc.w	$0104		; BPLCON2
	dc.w	$0024
	dc.w	$0108		; BPL1MOD
	dc.w	$0000
	dc.w	$010a		; BPL2MOD
	dc.w	$0000
	dc.w	$00e0		; BPL1PTH
	dc.w	0		; wird während Boot gefüllt (s.o.)
	dc.w	$00e2		; BPL1PTL
	dc.w	0		; wird während Boot gefüllt (s.o.)
	dc.w	$182		; COLOR01
	dc.w	$0fff
	dc.w	$180		; COLOR00
	dc.w	$0000
	dc.w	$a10f,$fffe
	dc.w	$0100		; BPLCON0
	dc.w	$1200
	dc.w	$a90f,$fffe
	dc.w	$0100		; BPLCON0
	dc.w	$0200
	dc.w	$af0f		; Zeile
	dc.w	$fffe
	dc.l	$fffffffe		; End der CopperList
	
coplist_end


password	dc.b	"Enter Disk`s Password",0
wrong_pw	dc.b	"Wrong. I do not boot.",0
ok_pw	dc.b	"  OK. Booting now... ",0

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

key_count	dc.l	3		; zum Test das Passwort
key_table	dc.b	$26,$12,$36,$21	; "jens"

bootcode_end

	end

