;THE TIMECIRCLE SELECTOR
;(C)1988 by Brian Postma
;To contact me write to
;P.O.Box 367
;7570 AJ Oldenzaal
;Holland
;or call : 05410-14763

start:	movem.l		d0-d7/a0-a6,-(a7)
	bsr		openlibs
	bsr		countit
	bsr		openscreen
	bsr		display
	bsr		initcop

	move.l		gfxbase,a0
	move.l		$32(a0),oldcop
	move.l		$6c,oldirq
	move.l		#newcop,$32(a0)
	move.l		#newirq,$6c

wait:	move.b		$dff007,d0
	add.b		d0,random
	move.b		$bfec01,d0
	cmpi.b		#119,d0
	beq		endwait
	cmpi.b		#103,d0
	bne		notup
	cmpi.b		#1,file
	beq		notup
	move.l		#-92,d0
	subq.b		#1,file
	bra		delay
notup:	cmpi.b		#101,d0
	bne		wait
	move.b		num,d1
	cmp.b		file,d1
	beq		wait
	move.l		#92,d0
	addq.b		#1,file

delay:	move.l		#19,d1
deloop:	add.l		d0,offset
	move.l		#$1ff,d2
waitamo:move.b		$dff007,d7
	add.b		d7,random
	dbra		d2,waitamo
	dbra		d1,deloop
	bra		wait

endwait:move.l		oldirq,$6c
	move.l		gfxbase,a0
	move.l		oldcop,$32(a0)
	bsr		closescreen
	bsr		closelibs
	move.b		file,$84
	movem.l		(a7)+,d0-d7/a0-a6
	move.w		#$f,$dff096
	rts

openlibs:
	move.l		4,a6
	jsr		-132(a6)	;Forbid
	lea		gfxname,a1
	jsr		-408(a6)	;Openlibrary
	move.l		d0,gfxbase
	lea		intname,a1
	jsr		-408(a6)
	move.l		d0,intbase
	lea		dosname,a1
	jsr		-408(a6)
	move.l		d0,dosbase
	rts

closelibs:
	move.l		4,a6
	move.l		dosbase,a1
	jsr		-414(a6)	;CloseLibrary
	move.l		gfxbase,a1
	jsr		-414(a6)
	move.l		intbase,a1
	jsr		-414(a6)
	jsr		-138(a6)	;Permit
	rts

countit:move.l		#0,d0
	lea		buffer,a0
coloop:	addq.l		#1,d0
find10:	cmpi.b		#10,(a0)+
	bne		find10
	cmpi.b		#34,(a0)+
	bne		coloop
	move.b		d0,num
	rts

initcop:lea		col1,a0
	lea		col2,a1
	lea		wav,a2
	lea		colors,a3
	move.l		#31,d0
	move.w		#$5007,d1
	move.w		#$e007,d2
	move.w		#$3001,d3
inloop:	move.w		d1,(a0)+
	move.w		d2,(a1)+
	move.w		d3,(a2)+
	move.l		#$fffe0180,(a0)+
	move.l		#$fffe0180,(a1)+
	move.l		#$fffe0102,(a2)+
	move.w		(a3),(a0)+
	move.w		(a3)+,(a1)+
	move.w		#0,(a2)+
	add.l		#$100,d1
	add.l		#$100,d2
	add.l		#$100,d3
	dbra		d0,inloop

	move.l		#plane1,d0
	lea		pl1,a0
	move.l		#plane1+46,d1
	move.w		d0,6(a0)
	swap		d0
	move.w		d0,2(a0)
	move.w		d1,14(a0)
	swap		d1
	move.w		d1,10(a0)
	rts

openscreen:
	move.l		intbase,a6
	lea		osargs,a0
	clr.l		d0
	move.b		num,d0
	mulu		#40,d0
	add.l		#192,d0		;Calculate Screenheight
	move.w		d0,6(a0)	;From number of files
	jsr		-198(a6)	;OpenScreen
	beq		alert

	move.l		d0,screenbase
	move.l		d0,a0
	move.l		$c0(a0),plane2	;PlanePointer
	add.l		#84,d0
	move.l		d0,a1		;Rastport
	move.l		#0,d0		;Color
	move.l		gfxbase,a6
	jsr		-234(a6)	;SetRast (CLS)

	move.l		#plane,d0
	move.l		#plane+50,d1
	lea		pl3,a0
	move.w		d0,6(a0)
	swap		d0		;Scroll Screen in
	move.w		d0,2(a0)	;CopperList
	move.w		d1,14(a0)
	swap		d1
	move.w		d1,10(a0)

	lea		stpl,a0
	move.l		#plane3,d0
	move.l		#plane4,d1
	move.w		d0,6(a0)
	move.w		d1,14(a0)
	swap		d0
	swap		d1		;And StarsScreen
	move.w		d0,2(a0)
	move.w		d1,10(a0)
	rts

osargs:	dc.w		0,0,384,0,1,1,0,0
	dc.l		0,0,0,0
		
closescreen:
	move.l		intbase,a6
	move.l		screenbase,a0
	jsr		-66(a6)		;CloseScreen
	rts

display:lea		title,a0
	lea		plane1,a1
	move.l		#1474,d0
	bsr		text

	lea		buffer,a4	
	move.l		#4324,d5	;Offset
	clr.l		d7		;How Many Times
	move.b		num,d7
	subq.l		#1,d7
disloop:move.l		#0,d6		;Count String Length
	lea		copy,a1		;And Copy to Buffer
copylo:	addq.l		#1,d6	
	move.b		(a4)+,(a1)+
	cmpi.b		#10,(a4)
	bne		copylo
	clr.b		(a1)		;End String With Null
	move.l		#24,d0		;Calculate Horizontal Offset
	sub.l		d6,d0
	add.l		d5,d0
	lea		copy,a0
	move.l		plane2,a1
	bsr		text
	add.l		#1840,d5
	addq.l		#1,a4
	dbra		d7,disloop
	rts

charheight = 16		; Height of 1 char in lines
charwidth = 2		; Width of 1 char in bytes
planes = 2		; Nr of Planes
charsproline = 20	; Chars pro line
linewidth = 40 		; Bytes pro line
charwidth2 = charwidth/2 ; Need this because SEKA doesn't know
			 ; the normal math rules...!!! (FUCK)

; Text Routine -> StringPointer in a0
;		  PlanePointer in a1
;		  Offset in d0

text:	movem.l		d0-d7/a0-a6,-(a7)
	bsr		waitblt
text2:	clr.w		d7
	move.b		(a0),d7
	cmpi.b		#32,d7
	beq		tspac
	cmpi.b		#160,d7
	bne		tnspace
tspac:	clr.w		d7
	move.w		#$0dcc,$dff040
	bra		tspace
tnspace:move.l		#font,d1
	sub.b		#48,d7
tddd:	cmpi.b		#charsproline,d7 
	blt		teerste
	add.l		#charheight*linewidth*planes,d1
	sub.b		#charsproline,d7
	bra		tddd
teerste:move.w		#$0dfc,$dff040	;BLTCON0
	btst		#0,d0
	beq		tspace
	move.w		#$8dfc,$dff040
tspace:	mulu		#charwidth,d7
	add.l		d1,d7
	move.l		d7,$dff050    	;SOURCE A
	move.l		a1,d7
	add.l		d0,d7
	move.l		d7,$dff054   	;DEST D
	move.l		d7,$dff04c
	move.l		#$ffff0000,$dff044	;MASK
	clr.w		$dff042		;BLTCON1
	move.w		#linewidth-charwidth-2,$dff064 ; MOD A
	move.w		#46-charwidth-2,$dff066	;MOD  D
	move.w		#46-charwidth-2,$dff062
	move.w		#charheight*planes*64 + charwidth,$dff058
	bsr		waitblt

	add.l		#charwidth,d0
	addq.l		#1,a0
	tst.b		(a0)
	bne		text2

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

waitblt:btst		#14,$dff002
	bne		waitblt
	rts

alert:	move.l		intbase,a6
	move.l		#0,d0
	lea		alertb,a0
	move.l		#$30,d1
	jsr		-90(a6)		;DisplayAlert
	move.l		(a7)+,d0
	movem.l		(a7)+,d0-d7/a0-a6
	rts

alertb:dc.b		0,240,20,"No Memory for Screen",0,0
even


newirq:	movem.l		d0-d7/a0-a6,-(a7)
	bsr		wavy
	bsr		stars
	bsr		hilite
	bsr		scroll
	bsr		stars2
	movem.l		(a7)+,d0-d7/a0-a6
	dc.w		$4ef9
oldirq:	dc.l		0

wavy:	subq.b		#1,count
	beq		doit
	rts
doit:	move.b		#2,count
	addq.w		#1,wpointer
	move.w		wpointer,d0
	lea		wdat,a0
	lea		wav,a1
	move.l		#31,d1
wavloop:and.w		#127,d0
	move.b		(a0,d0.w),7(a1)
	addq.l		#8,a1
	addq.w		#1,d0
	dbra		d1,wavloop
	rts

stars:	bsr		waitblt
	move.l		#plane3,a0
	move.w		#$0000,$dff042
	move.w		#$39f0,$dff040
	move.l		#$ffffffff,$dff044 ;Mask
	move.l		a0,$dff054
	move.l		a0,$dff050	   ;Start Adress
	clr.l		$dff064
	move.w		#%0010000000010111,$dff058
	move.l		#127,d3
	add.l		#45,a0
clr:	clr.b		(a0)
	add.l		#46,a0
	dbra		d3,clr
	bsr		waitblt

	move.b		random,d1
	and.l		#127,d1
	mulu		#46,d1
	add.l		#plane3,d1
	move.l		d1,a0
	or.b		#1,(a0)
	rts

stars2:	bsr		waitblt
	move.l		#plane4,a0
	move.l		#$59f00000,$dff040
	move.l		#$ffffffff,$dff044 ;Mask
	move.l		a0,$dff054
	move.l		a0,$dff050	   ;Start Adress
	clr.l		$dff064
	move.w		#%0010000000010111,$dff058
	move.l		#127,d3
	add.l		#45,a0
clr2:	clr.b		(a0)
	add.l		#46,a0
	dbra		d3,clr2
	bsr		waitblt

	move.b		random,d1
	and.l		#127,d1
	mulu		#46,d1
	add.l		#plane4,d1
	move.l		d1,a0
	or.b		#1,(a0)
	rts

hilite:	move.l		plane2,d0
	add.l		offset,d0
	lea		pl2,a0
	move.w		d0,6(a0)
	swap		d0		;Planes in
	move.w		d0,2(a0)	;Copperlist
	swap		d0
	add.l		#46,d0
	move.w		d0,14(a0)
	swap		d0
	move.w		d0,10(a0)
	rts

scroll: bsr		waitblt
	move.w		speed1,$dff040
	move.w		#0,$dff042
	move.l		#$ffffffff,$dff044
	move.l		#plane,d0
	move.l		d0,$dff054
	add.l		speed3,d0
	move.l		d0,$dff050
	clr.l		$dff064
	move.w		#charheight*64*planes+25,$dff058
	bsr		waitblt
noscr:	subq.b		#1,scrcount
	beq		newtext
	rts

newtext:move.b		speed2,scrcount
	addq.l		#1,stringpointer
	move.l		stringpointer,a0
	cmpi.b		#'z',(a0)
	bne		notend
	move.l		#string-1,stringpointer
	bra		newtext
notend:	move.l		stringpointer,a0
	clr.w		d0
	move.b		(a0),d0
	cmpi.b		#32,d0
	blt		newtext
	cmpi.b		#32,d0
	beq		nspace2
	cmpi.b		#160,d0
	bne		nspace
nspace2:clr.w		d0
	move.w		#$0900,$dff040
	bra		space
nspace:	move.l		#font,d1
	sub.b		#48,d0
	cmpi.b		#48,d0
	bgt		speedchange
ddd:	cmpi.b		#charsproline,d0 
	blt		eerste
	add.l		#charheight*linewidth*planes,d1
	sub.b		#charsproline,d0
	bra		ddd
eerste:	move.w		#$09f0,$dff040	;BLTCON0
space:	mulu		#charwidth,d0
	add.l		d1,d0
	move.l		d0,$dff050    	;SOURCE A
	move.l		#plane,d0
	add.l		#46,d0
	move.l		d0,$dff054   	;DEST D
	clr.w		$dff042		;BLTCON1
	move.w		#linewidth-charwidth,$dff064 ; MOD A
	move.l		#$ffffffff,$dff044	;MASK
	move.w		#50-charwidth,$dff066	;MOD  D
	move.w		#charheight*planes*64 + charwidth2,$dff058
	bsr		waitblt

	rts

speedchange:
	sub.b		#49,d0
	mulu		#3,d0
	lea		speedlist,a0
	move.b		(a0,d0.w),speed1
	move.b		2(a0,d0.w),d1
	ext.w		d1
	ext.l		d1
	move.l		d1,speed3
	move.b		1(a0,d0.w),speed2
	bra		newtext

speed3:		dc.l		2
speed1:		dc.w		$f9f0
speed2:		dc.b		16
scrcount:	dc.b		1

speedlist:	dc.b	$09,32,0 	; Speed a
		dc.b	$f9,16,2	; Speed b
		dc.b	$e9,8,2		; Speed c
		dc.b	$c9,4,2		; Speed d
		dc.b	$89,2,2		; Speed e
		dc.b	$09,1,2		; Speed f
		dc.b	$19,16,0	; Speed g
		dc.b	$29,8,0		; Speed h
		dc.b	$49,4,0		; Speed i
		dc.b	$89,2,0		; Speed j
		dc.b	$09,1,-2	; Speed k
	
even

font:	blk.b	3840,0

wdat:	blk.b	80,$88
	dc.b	$88,$99,$99,$88,$77,$77,$88,$99
	dc.b	$aa,$aa,$99,$88,$77,$66,$66,$77
	dc.b	$88,$99,$aa,$bb,$bb,$aa,$99,$88
	dc.b	$77,$66,$55,$55,$66,$77,$88,$99
	dc.b	$aa,$aa,$99,$88,$77,$66,$66,$77
	dc.b	$88,$99,$99,$88,$77,$77,$88,$88

newcop:
	dc.w	$0120,$0000,$0122,$0000,$0096,$0020
	dc.w	$008e,$296a,$0090,$29fa,$0092,$0028
	dc.w	$0094,$00d8,$0100,$0000,$0180,$0000

pl1:	dc.w	$e0,0,$e2,0,$e4,0,$e6,0
	dc.w	$182,$eca,$184,$00f,$186,$08f
	dc.w	$10a,$02e,$0108,$02e

;Wavy Part
	dc.w	$3001,$fffe,$0100,$2000
wav:	blk.b	256,0
	dc.w	$5001,$fffe,$0100,$0000
col1:	blk.b	256,0

;Selector Part
	dc.w	$184,$f00,$186,$f80
	dc.w	$190,$000,$192,$bb0
	dc.w	$194,$ff0,$196,$ff0
pl2:	dc.w	$e0,0,$e2,0,$e8,0,$ea,0
stpl:	dc.w	$e4,0,$e6,0,$ec,0,$ee,0,$102,0
	dc.w	$108,$02e,$10a,$000

	dc.w	$7301,$fffe
	dc.w	$100,$4400
;HiLite
	dc.w	$9f07,$fffe,$180,$222
	dc.w	$a007,$fffe,$180,$333
	dc.w	$a107,$fffe,$180,$444
	dc.w	$a207,$fffe,$180,$555
	dc.w	$a307,$fffe,$180,$777
	dc.w	$a407,$fffe,$180,$999
	dc.w	$a507,$fffe,$180,$bbb
	dc.w	$a607,$fffe,$180,$ddd
	dc.w	$a707,$fffe,$180,$fff
	dc.w	$a807,$fffe,$180,$fff
	dc.w	$a907,$fffe,$180,$ddd
	dc.w	$aa07,$fffe,$180,$bbb
	dc.w	$ab07,$fffe,$180,$999
	dc.w	$ac07,$fffe,$180,$777
	dc.w	$ad07,$fffe,$180,$555
	dc.w	$ae07,$fffe,$180,$444
	dc.w	$af07,$fffe,$180,$333
	dc.w	$b007,$fffe,$180,$222
	dc.w	$b107,$fffe,$180,$000

	dc.w	$de01,$fffe,$100,$0000
col2:	blk.b	256,0

;Scroll Part
pl3:	dc.w	$e0,0,$e2,0,$e4,0,$e6,0
	dc.w	$184,$00f,$186,$08f
	dc.w	$ffdf,$fffe,$0801,$fffe
	dc.w	$100,$2000,$108,$36,$10a,$36

	dc.w	$1801,$fffe,$100,$0000
	dc.w	$ffff,$fffe
colors:	dc.w	0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
	dc.w	15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0

wpointer:	dc.w	0
oldcop:		dc.l	0
gfxbase: 	dc.l	0
intbase: 	dc.l	0
dosbase:	dc.l	0
handle:		dc.l	0
stringpointer:	dc.l	string-1
screenbase:	dc.l	0
plane2:		dc.l	0
offset:		dc.l	0

plane1:		blk.b	2944,0
plane:		blk.b	1800,0
plane3:		blk.b	5888,0
plane4:		blk.b	5888,0
		
gfxname:	dc.b	"graphics.library",0
intname:	dc.b	"intuition.library",0
dosname:	dc.b	"dos.library",0
title:		dc.b	"      TIMECIRCLE",0	;header max 22 chars
num:		dc.b	0
file:		dc.b	1
random:		dc.b	100
count:		dc.b	1

copy:		blk.b	32,0
even
buffer:	dc.b	"================",10
	dc.b	"=THE TIMECIRCLE=",10
	dc.b	"================",10
	dc.b	"A SELECTOR BY",10
	dc.b	"BRIAN POSTMA",10
	dc.b	"P:O:BOX 367",10
	dc.b	"7570 AJ OLDENZAAL",10
	dc.b	"HOLLAND",10
	dc.b	"TEL 05410=14763",10
	dc.b	34		;indicates end of filedata
string:	dc.b	"cTHE SCROLLTEXT ::: ;;; <<< === >>> ??? @@@    "
	dc.b	"z"		;indicates end of scrolltext

;some scrollcodes a = stand still, b-f forward speeds, g-k backward
;A-Z, 0-9 are available also
; ':' for '.' , ';' for ',' , '<' for '[' , '=' for '-'
; '>' for ']' , '?' for '!' and '@' for '?'
end:
