; LetterWriter
; (C)1990 by Brian Postma
; J.v.Hartenstraat 51
; 7576VX Oldenzaal (NL)
; Tel:05410-14763

start:	movem.l		d0-d7/a0-a6,-(a7)
	bsr		initcop		;Setup Copperlist
	move.l		4,a6
	jsr		-132(a6)	;No Multitasking
	lea		gfxname,a1	;Name of graphics library
	move.l		4,a6		;Execbase
	jsr		-408(a6)	;Open Library
	move.l		d0,gfxbase	;Rememer graphics base
	lea		intname,a1	;Name of intuition lib.
	jsr		-408(a6)	;Open Library
	move.l		d0,intbase	;Remember intuition base
	move.l		intbase,a6
	lea		osargs,a0	;Pointer to newscreen struct.
	jsr		-198(a6)	;Open Screen
	move.l		d0,screenbase	;Pointer to screen struct
	beq		quit		;Could I open it ??
	add.l		#84,d0		;Screenbase+84
	move.l		d0,rastport	;Is Rastport
	move.l		gfxbase,a6	
	move.l		rastport,a1
	clr.l		d0		;Color=0
	jsr		-234(a6)	;Setrast->Clear Screen
	move.l		screenbase,a0
	move.l		192(a0),d0	;Pointer to first bitplane
	move.l		d0,d1
	add.l		#40*2,d0
	move.w		d1,planes+14
	move.w		d0,planes+6	;Low word in copperlist
	swap		d1
	swap		d0
	move.w		d1,planes+10
	move.w		d0,planes+2	;High word in copperlist
	move.l		gfxbase,a0	;gfxbase+$32=pointer to clist
	move.l		$32(a0),oldcop	;save old copperlist
	move.l		#newcop,$32(a0)	;My own copperlist
	move.l		$6c,oldirq	;Save old VBL irq pointer
	move.l		#newirq,$6c	;my VBL interrupt
wait:	btst		#6,$bfe001	;Left mouse button pressed ??
	bne		wait		;No !!
	move.l		oldirq,$6c	;Restore interrupt
	move.l		gfxbase,a0	;restore
	move.l		oldcop,$32(a1)	;old copperlist
	move.l		intbase,a6
	move.l		screenbase,a0
	jsr		-66(a6)		;Close the screen
quit:	move.l		4,a6
	jsr		-138(a6)	;Multitasking on
	movem.l		(a7)+,d0-d7/a0-a6
	rts

initcop:move.l		#$2d01fffe,d1
	move.l		#$2ddffffe,d2
	move.l		#255,d7		;256 lines
	lea		copper,a0
icloop1:move.l		d1,(a0)+
	move.l		#$018200ff,(a0)+
	move.l		d2,(a0)+
	add.l		#$01000000,d2
	add.l		#$01000000,d1
	dbra		d7,icloop1
	rts

newirq:	movem.l		d0-d7/a0-a6,-(a7);Save regs
	bsr		letter
	bsr		cycle
	movem.l		(a7)+,d0-d7/a0-a6;Restore regs
	dc.w		$4ef9		;Code for 'JUMP'
oldirq:	dc.l		0		;Jump to oldirq


cycle:	subq.b		#1,cyclecount
	beq		letsgo
	rts
letsgo:	move.b		#3,cyclecount
	lea		colors,a2
	move.l		#255,d7		;256 datas
	lea		copper,a1
	move.w		colpointer,d1
	addq.w		#2,colpointer
cycloop:addq.w		#2,d1
	and.w		#63,d1
	move.w		(a2,d1.w),6(a1)
	add.l		#12,a1
	dbra		d7,cycloop
	rts

letter:	subq.b		#1,scrcount
	beq		action
	rts
action:	move.b		#4,scrcount
	move.l		gfxbase,a6
	move.l		rastport,a1
	moveq		#0,d0
	jsr		-342(a6)	;SetAPen -> Color #0
	move.l		x,d0		;x top
	move.l		y,d1		;y top
	move.l		d0,d2
	addq.l		#8,d2		;x bottom
	move.l		d1,d3
	addq.l		#7,d3		;y bottom
	move.l		rastport,a1
	jsr		-306(a6)	;Rectfill
	move.l		rastport,a1
	moveq		#1,d0
	jsr		-342(a6)	;SetAPen -> Color #1
newtext:move.l		stringpointer,a0
	move.b		(a0),d0
	cmpi.b		#2,d0		;2=Code for delay
	bne		nodel
	move.b		#120,scrcount
	bra		nochar
nodel:	cmpi.b		#10,d0
	bne		notlf
	add.l		#10,y
	move.l		#0,x
	bsr		checkscroll
	bra		nochar
notlf:	cmpi.b		#1,d0		;1 = code for clrscreen
	bne		notclr
	move.l		gfxbase,a6
	moveq		#0,d0
	move.l		rastport,a1
	jsr		-234(a6)	;ClearScreen
	move.l		#4,y		;cursor home
	clr.l		x
	bra		nochar
notclr:	move.l		rastport,a1
	move.l		x,d0
	move.w		d0,36(a1)	;Write X Coord in Rastport
	move.l		y,d1
	addq.w		#6,d1
	move.w		d1,38(a1)	;Write Y Coord in Rastport
	move.l		stringpointer,a0
	moveq		#1,d0		;num of chars
	move.l		gfxbase,a6
	move.l		rastport,a1
	jsr		-60(a6)		;WriteChar
	add.l		#10,x
	cmpi.l		#320,x
	blt		nochar
	add.l		#10,y
	clr.l		x
	bsr		checkscroll
nochar:	move.l		x,d0		;x top
	move.l		y,d1		;y top
	move.l		d0,d2
	addq.l		#8,d2		;x bottom
	move.l		d1,d3
	addq.l		#7,d3		;y bottom
	move.l		rastport,a1
	move.l		gfxbase,a6
	jsr		-306(a6)	;Rectfill
	addq.l		#1,stringpointer
	cmpi.l		#endstring,stringpointer
	bne		notend
	move.l		#string,stringpointer
notend:	rts

checkscroll:
	cmpi.l		#254,y
	blt		noscrol
	move.l		gfxbase,a6
	move.l		rastport,a1
	moveq		#0,d0		;dx
	moveq		#10,d1		;dy 10 lines up
	moveq		#0,d2		;Min x
	moveq		#0,d3		;Min y
	move.l		#319,d4		;Max x
	move.l		#255,d5		;Max y
	jsr		-396(a6)	;ScrollRaster
	sub.l		#10,y
noscrol:rts

colors:	dc.w	$77f,$88f,$99f,$aaf,$bbf,$ccf,$ddf,$eef
	dc.w	$fff,$fee,$fdd,$fcc,$fbb,$faa,$f99,$f88
	dc.w	$f77,$f88,$f99,$faa,$fbb,$fcc,$fdd,$fee
	dc.w	$fff,$eef,$ddf,$ccf,$bbf,$aaf,$99f,$88f

newcop:	dc.w	$0092,$0038,$0094,$00d0	;DFFSTART,DFFSTOP->OverScan
	dc.w	$008e,$2d6a,$0090,$2dfa	;DIWSTART,DIWSTOP
	dc.w	$0108,$0000,$010a,$0000	;BPL1MOD,BPL2MOD
	dc.w	$0096,$0020,$0100,$0000	;Sprites off,planes off
	dc.w	$0180,$0000,$0182,$0fff	;Colors
	dc.w	$0192,$0444
planes:	dc.w	$00e0,$0000,$00e2,$0000	;Plane1 low,high word
	dc.w	$00e4,$0000,$00e6,$0000	;Plane2 Low,high word
	dc.w	$0100,$2400,$0102,$0020	;Plane1+2, double playfield
copper:	blk.b	3*4*256,0		;space for data
	dc.w	$ffff,$fffe		;Wait till end

osargs:	dc.w	0,0,320,264		;x-min,y-min,width,height
	dc.w	1			;depth 1 bitplane
	dc.b	0,1			;detailpen,blockpen
	dc.w	0,15			;viewmodes,type=customscreen
	dc.l	textattr,0		;textattr,title=none
	dc.l	0,0			;gadgets,bitmap
textattr:
	dc.l	fontname		;Fontname
	dc.w	9			;fontsize
	dc.b	0			;Style=normal
	dc.b	1			;flags=romfont

x:		dc.l	0
y:		dc.l	4
oldcop:		dc.l	0
gfxbase:	dc.l	0
intbase:	dc.l	0
rastport:	dc.l	0
screenbase:	dc.l	0
stringpointer:	dc.l	string
colpointer:	dc.w	0
intname:	dc.b	"intuition.library",0
gfxname:	dc.b	"graphics.library",0
fontname:	dc.b	"topaz.font",0
cyclecount:	dc.b	1
scrcount:	dc.b	1

string:
 DC.B	1,10,10,10,10,10,10
 DC.B	"    *** THE TIMECIRCLE ***",10,10
 DC.B	"           PRESENTS",10,10
 DC.B	"       THE LETTERWRITER",10
 DC.B	"       ~~~~~~~~~~~~~~~~",10,10
 DC.B	"    WRITTEN BY BRIAN POSTMA",10,10
 DC.B	2,1,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
 dc.b	"SCROLLIT UP",10,10,10,10,10,10,10,10,10,10,10
 DC.B	10,10,10,10,10,10,10,10,10,10,10,10,10,10
endstring:
; Mirror Mirror on the wall, who is the lamest of the all ??
; The Cardinals, who else !!     (THE TIMECIRCLE IN 1990)
