************************************************************
* How to create this program:
*
* For normal executable:
* 1. Make sure BOOT_BLOCK is EQU'ed to 0.
* 2. From the AsmOne prompt type a<RETURN>.
* 3. Then type wo<RETURN>
*
* For a boot block:
* 1. Make sure BOOT_BLOCK is EQU'ed to 1.
* 2. From the AsmOne prompt type a<RETURN>.
* 3. Put the disk you want the boot block on in df0:.
* 4. Type ws<RETURN>.
* 5. Do the following sequence, as prompted:
*	RAM_PTR> Start
*	DISK_PTR> 0
*	LENGTH> 2
* 6. Now, type cc<RETURN>
* 7. Reboot to see the boot block!
************************************************************

BOOT_BLOCK	EQU	1		; 0 = normal exe, 1 = boot block
HEIGHT		EQU	9		; height of font, in rasters

************************************************************

WaitVblank	MACRO
.\@		move.l	2(a5),d0
		andi.l	#$3ff00,d0
		cmpi.l	#$0f000,d0
		bne.b	.\@
.\@1		move.l	2(a5),d0
		andi.l	#$3ff00,d0
		cmpi.l	#$0f000,d0
		beq.b	.\@1
		ENDM

************************************************************

 IFNE	BOOT_BLOCK
Start:
		dc.b	"DOS",0
		dc.l	0			; BB checksum goes here
		dc.l	$370			; root block
 ELSE
		section	thpt,code_c
 ENDIF 

		movem.l	d1-d7/a1-a6,-(sp)	; save all registers
		lea	scroll_pad(pc),a1	; where we scroll
		moveq	#125,d0			; counter
.1:		clr.l	(a1)+			; clear the scroll pad
		dbf	d0,.1			;   since we just stomp on
						;   memory like a bunch of
						;   turds.

		lea	mapptrs+2(pc),a0	; our clist bmap ptrs
		lea	scroll_pad(pc),a1	; our screen
		move.l	a1,d0
		move.w	d0,4(a0)		; low word
		swap	d0
		move.w	d0,(a0)			; high word

		lea	$dff002,a5		; Custom chip base + 2
		move.w	#$81c0,$96-2(a5)	; enable blitter, copper,
						;   and bitplane DMS
		tst.b	(a5)			; wait for the blitter
.11:		btst.b	#6,(a5)
		bne.b	.11

 IFEQ BOOT_BLOCK
		move.w	$1c-2(a5),d0		; save old int bits
		or.w	d0,INTSave
 ENDIF
		lea	Copper(pc),a0		; our copper
		move.l	a0,$80-2(a5)		; install it

		lea	ScrollTextPtr(pc),a4
		move.l	a2,(a4)
		lea	scrolls(pc),a6

		moveq	#0,d2
		move.l	#$19f00002,d3		; bltcon0 & bltcon1
		moveq	#-1,d4			; bltfwm & bltlwm
		moveq	#$3c,d6
		moveq	#$32,d7

		movem.l	d3/d4,$40-2(a5)		; preload these into their
		move.l	d2,$64-2(a5)		;   blit regs and they never
						;   change! ;^)
		lea	scroll_pad+(HEIGHT*48)(pc),a2

MouseWait:	WaitVblank			; wait for the vblank

		tst.w	(a6)			; scroll count = 0?
		bgt.w	move_it			; nope.
		move.w	#8,(a6)			; reset to 8

		move.l	(a4),a3			; pointer to scroll text
		tst.b	(a3)			; end of text?
		bne.s	nextchar		; nope.
		lea	ScrollText(pc),a3	; reload
nextchar:	moveq	#0,d0			; clear
		move.b	(a3)+,d0		; fetch the character
		move.l	a3,(a4)			; save new pointer

		lea	scroll_pad+46(pc),a1
		lea	Font-32(pc,d0.w),a0	; this finds our char. in the
						;   font, too.
		moveq	#HEIGHT,d0		; how many lines in font
.1:		move.b	(a0),(a1)		; copy byte
		adda.w	d6,a0			; next line in font
		adda.w	d7,a1			; next line on screen
		dbf	d0,.1			; loop!

move_it:	move.l	a2,a0			; copy for the cool movem!
		movem.l	a0/a2,$50-2(a5)		; src/dest
 		move.w	#(64*HEIGHT)+24,$58-2(a5) ; bltsize

		subq.w	#1,(a6)			; dec scroll count

		btst.b	#6,$bfe001		; wait for left mouse button
		bne.w	MouseWait		; loop!

*************
 IFEQ BOOT_BLOCK
		move.w	INTSave(pc),$1c-2(a5)	; restor old int bits.
 ENDIF

		movea.l	4.w,a6			; exec base
		lea	GfxName(pc),a1		; "graphics.library"
		jsr	-$198(a6)		; OldOpenLibrary()
		move.l	d0,a1			; ptr to gfx
		move.l	$26(a1),$80-2(a5)	; reinstall old sys clist
		jsr	-$19e(a6)		; CloseLibrary()

		lea	DosName(pc),a1		; pointer to lib. name
		jsr	-$60(a6)		; FindResident()
		tst.l	d0			; did we find it?
		beq.b	.no_dos			; nope.
		move.l	d0,a0			; put in a0
		move.l	$16(a0),a0		; this is what we really need
		moveq	#0,d0			; clear
.end:		movem.l	(a7)+,d1-d7/a1-a6	; restore other regs.
		rts				; Done

.no_dos:	moveq	#-1,d0			; error code
		bra.b	.end			; out

***********************************************************	

scrolls:	dc.w	8

Font:		incbin	'ackfont.raw'

DosName:	dc.b	'dos.library',0
GfxName:	dc.b	'graphics.library',0

ScrollText:	DC.B	" YEAH! A BOOTBLOCK SCROLLER! TOO COOL, EH? "
		DC.B	"CONTACT ME AT: EPSILON   P.O.B. 1914    "
		DC.B	"BEAVERTON, OR  97075-1914    U.S.A.   ",0
		even
	
Copper:	dc.w	$0100,$0200,$0102,$0000,$0104,$0000,$0108,$0004
	dc.w	$0180,$0000,$0182,$0fff,$008e,$2c6a,$0090,$f4fc,$0092,$0028
	dc.w	$0094,$00d8
	dc.w	$8a0f,$fffe,$0180,$0f00,$8b0f,$fffe,$0180,$0800
	dc.w	$8c0f,$fffe,$0100,$1200
mapptrs:dc.w	$00e0,$0000,$00e2,$0000
	dc.w	$950f,$fffe,$0180,$0f00,$0100,$0000,$960f,$fffe,$0180,$0000
	dc.l	-2,-2

blat:
 IFEQ	BOOT_BLOCK
ScrollTextPtr:	dc.l	ScrollText
INTSave:	dc.w	$c000
		ds.b	12*42
scroll_pad:	ds.b	12*42
		ds.b	12*42
 ELSE
ScrollTextPtr	EQU	blat
scroll_pad	EQU	blat+(12*42)
 ENDIF	
